2 # Copyright © 2012 Jamie Zawinski <jwz@jwz.org>
4 # Permission to use, copy, modify, distribute, and sell this software and its
5 # documentation for any purpose is hereby granted without fee, provided that
6 # the above copyright notice appear in all copies and that both that
7 # copyright notice and this permission notice appear in supporting
8 # documentation. No representations are made about the suitability of this
9 # software for any purpose. It is provided "as is" without express or
12 # Generates a .h file that lists all the function tables we use, because
13 # CFBundleGetDataPointerForName doesn't work in "Archive" builds.
14 # What a crock of shit.
16 # There's no real way to integrate this into the Xcode build system, so
17 # run this manually each time a new saver is added to the iOS app.
19 # Created: 14-Jul-2012.
22 #use diagnostics; # Fails on some MacOS 10.5 systems
25 my $progname = $0; $progname =~ s@.*/@@g;
26 my $version = q{ $Revision: 1.1 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/;
31 my ($app_dir, $outfile) = @_;
33 opendir (my $dh, $app_dir) || error ("$app_dir: $!");
34 print STDERR "$progname: scanning $app_dir...\n" if ($verbose > 1);
37 foreach (sort (readdir ($dh))) {
38 next unless (m/^(.*)\.xml$/);
43 my $suf = 'xscreensaver_function_table';
45 my $body = "extern struct $suf";
46 foreach my $s (@names) {
47 $body .= "\n *${s}_${suf},";
52 "static NSDictionary *make_function_tables_dict(void)\n{\n" .
53 " return\n [NSDictionary dictionaryWithObjectsAndKeys:\n");
54 foreach my $s (@names) {
55 $body .= "\t[NSValue valueWithPointer:&${s}_${suf}], @\"${s}\",\n";
57 $body .= ("\tnil];\n" .
61 if (open (my $in, '<', $outfile)) {
62 local $/ = undef; # read entire file
67 if ($obody eq $body) {
68 print STDERR "$progname: $outfile: unchanged\n" if ($verbose > 1);
70 my $file_tmp = "$outfile.tmp";
71 open (my $out, '>', $file_tmp) || error ("$file_tmp: $!");
72 print $out $body || error ("$file_tmp: $!");
73 close $out || error ("$file_tmp: $!");
75 if (!rename ("$file_tmp", "$outfile")) {
77 error ("mv \"$file_tmp\" \"$outfile\": $!");
79 print STDERR "$progname: wrote $outfile\n" if ($verbose);
86 print STDERR "$progname: $err\n";
91 print STDERR "usage: $progname [--verbose] program.app output.h\n";
98 while ($_ = $ARGV[0]) {
100 if (m/^--?verbose$/s) { $verbose++; }
101 elsif (m/^-v+$/) { $verbose += length($_)-1; }
102 elsif (m/^--?q(uiet)?$/s) { $verbose = 0; }
103 elsif (m/^-/s) { usage(); }
104 elsif (! $app) { $app = $_; }
105 elsif (! $out) { $out = $_; }
108 usage() unless ($out && $app);
109 build_h ($app, $out);