+ my $icon = ($app_dir =~ m/\.saver$/ ? 'XScreenSaver' : 'SaverRunner');
+ $icon = "$app_dir/../../../$icon.icns";
+ my @cmd = ("$app_dir/../../../seticon.pl", "-d", $icon, $app_dir);
+ print STDERR "$progname: exec: " . join(' ', @cmd) . "\n"
+ if ($verbose > 1);
+ system (@cmd);
+}
+
+
+sub set_thumb($) {
+ my ($app_dir) = @_;
+
+ return unless ($app_dir =~ m@\.saver/?$@s);
+
+ my $name = $app_dir;
+ $name =~ s@^.*/@@s;
+ $name =~ s@\..*?$@@s;
+ $name = lc($name);
+
+ $name = 'rd-bomb' if ($name eq 'rdbomb'); # sigh
+
+ if (! -f "$thumbdir/$name.png") {
+ system ("make", "$thumbdir/$name.png");
+ my $exit = $? >> 8;
+ exit ($exit) if $exit;
+ error ("unable to download $name.png")
+ unless (-f "$thumbdir/$name.png");
+ }
+
+ $app_dir =~ s@/+$@@s;
+ $app_dir .= "/Contents/Resources";
+ error ("$app_dir does not exist") unless (-d $app_dir);
+
+ system ("cp", "-p", "$thumbdir/$name.png", "$app_dir/thumbnail.png");
+ my $exit = $? >> 8;
+ exit ($exit) if $exit;
+}
+
+
+sub enable_gc($) {
+ my ($app_dir) = @_;
+
+ return unless ($app_dir =~ m@\.saver/?$@s);
+ my ($dir, $name) = ($app_dir =~ m@^(.*)/([^/]+)\.saver$@s);
+ error ("unparsable: $app_dir") unless $name;
+ my $exe = "$app_dir/Contents/MacOS/$name";
+ my @cmd = ("$dir/enable_gc", $exe);
+ print STDERR "$progname: exec: " . join(' ', @cmd) . "\n"
+ if ($verbose > 1);
+ system (@cmd);
+ my $exit = $? >> 8;
+ exit ($exit) if $exit;
+}
+
+
+sub fix_coretext($) {
+ my ($app_dir) = @_;
+
+ # In MacOS 10.8, they moved CoreText.framework from
+ # /System/Library/Frameworks/ApplicationServices.framework/Frameworks/
+ # to /System/Library/Frameworks/ which means that executables compiled
+ # on 10.8 and newer won't run on 10.7 and older because they can't find
+ # the library. Fortunately, 10.8 and later leave a symlink behind, so
+ # the old location still works. So we need our executables to contain
+ # an LC_LOAD_DYLIB pointing at the old directory instead of the new
+ # one.
+ #
+ return if ($app_dir =~ m@-iphone@s);
+ my ($dir, $name) = ($app_dir =~ m@^(.*)/([^/]+)\.(app|saver)$@s);
+ error ("unparsable: $app_dir") unless $name;
+ my $exe = "$app_dir/Contents/MacOS/$name";
+
+ my $new = ("/System/Library/Frameworks/CoreText.framework/" .
+ "Versions/A/CoreText");
+ my $old = ("/System/Library/Frameworks/ApplicationServices.framework/" .
+ "Frameworks/CoreText.framework/Versions/A/CoreText");
+ my @cmd = ("install_name_tool", "-change", $new, $old, $exe);