2 # Copyright © 2012-2014 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 .c 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) = ('$Revision: 1.3 $' =~ m/\s(\d[.\d]+)\s/s);
30 # List of savers not included in the iOS build.
39 # Parse the RETIRED_EXES variable from the Makefiles to populate %disable.
40 # Duplicated in ../hacks/munge-ad.pl.
42 sub parse_makefiles() {
43 foreach my $mf ( "hacks/Makefile.in", "hacks/glx/Makefile.in" ) {
44 open (my $in, '<', $mf) || error ("$mf: $!");
45 print STDERR "$progname: reading $mf\n" if ($verbose > 1);
46 local $/ = undef; # read entire file
51 my ($var) = ($body =~ m/^RETIRED_EXES\s*=\s*(.*)$/mi);
52 my ($var2) = ($body =~ m/^RETIRED_GL_EXES\s*=\s*(.*)$/mi);
53 error ("no RETIRED_EXES in $mf") unless $var;
54 $var .= " $var2" if $var2;
55 foreach my $hack (split (/\s+/, $var)) {
67 my @schemes = glob('xscreensaver.xcodeproj/xcuserdata/' .
68 '*.xcuserdatad/xcschemes/*.xcscheme');
69 error ("no scheme files") unless (@schemes);
73 foreach my $s (@schemes) {
74 open (my $in, '<', $s) || error ("$s: $!");
75 local $/ = undef; # read entire file
78 my ($name) = ($body =~ m@BuildableName *= *"([^\"<>]+?)\.saver"@s);
81 if ($disable{$name}) {
82 print STDERR "$progname: skipping $name\n" if ($verbose > 1);
85 print STDERR "$progname: found $name\n" if ($verbose > 1);
89 my @names = sort (keys %names);
90 error ("too few names") if (@names < 100);
92 my $suf = 'xscreensaver_function_table';
94 my $body = ("/* Generated file, do not edit.\n" .
95 " Created: " . localtime() . " by $progname $version.\n" .
98 "#import <Foundation/Foundation.h>\n" .
99 "#import <UIKit/UIKit.h>\n" .
101 "extern NSDictionary *make_function_table_dict(void);\n" .
104 $body .= "extern struct $suf";
105 foreach my $s (@names) {
106 $body .= "\n *${s}_${suf},";
108 $body =~ s/,\s*$/;/s;
112 return "\t[NSValue valueWithPointer:&${s}_${suf}], @\"${s}\",\n";
116 "NSDictionary *make_function_table_dict(void)\n{\n" .
117 " return\n [NSDictionary dictionaryWithObjectsAndKeys:\n" .
119 "#if defined(APPLE2_ONLY)\n" .
120 " " . line('apple2', $suf) .
121 "#elif defined(PHOSPHOR_ONLY)\n" .
122 " " . line('phosphor', $suf) .
124 foreach my $s (@names) { $body .= line($s, $suf); }
125 $body .= ("#endif\n" .
130 if (open (my $in, '<', $outfile)) {
131 local $/ = undef; # read entire file
136 # strip comments/date for diff.
137 my ($body2, $obody2) = ($body, $obody);
138 foreach ($body2, $obody2) { s@/\*.*?\*/@@gs; }
140 if ($body2 eq $obody2) {
141 print STDERR "$progname: $outfile: unchanged\n" if ($verbose > 1);
143 my $file_tmp = "$outfile.tmp";
144 open (my $out, '>', $file_tmp) || error ("$file_tmp: $!");
145 print $out $body || error ("$file_tmp: $!");
146 close $out || error ("$file_tmp: $!");
148 if (!rename ("$file_tmp", "$outfile")) {
150 error ("mv \"$file_tmp\" \"$outfile\": $!");
152 print STDERR "$progname: wrote $outfile\n" if ($verbose);
159 print STDERR "$progname: $err\n";
164 print STDERR "usage: $progname [--verbose] output.c\n";
171 while ($_ = $ARGV[0]) {
173 if (m/^--?verbose$/s) { $verbose++; }
174 elsif (m/^-v+$/) { $verbose += length($_)-1; }
175 elsif (m/^--?q(uiet)?$/s) { $verbose = 0; }
176 elsif (m/^-/s) { usage(); }
177 elsif (! $out) { $out = $_; }
180 usage() unless ($out);