2 # Copyright © 2012-2018 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.6 $' =~ m/\s(\d[.\d]+)\s/s);
30 # List of savers not included in the iOS build.
41 # Parse the RETIRED_EXES variable from the Makefiles to populate %disable.
42 # Duplicated in ../hacks/munge-ad.pl.
44 sub parse_makefiles() {
45 foreach my $mf ( "../hacks/Makefile.in", "../hacks/glx/Makefile.in" ) {
46 open (my $in, '<', $mf) || error ("$mf: $!");
47 print STDERR "$progname: reading $mf\n" if ($verbose > 1);
48 local $/ = undef; # read entire file
53 my ($var) = ($body =~ m/^RETIRED_EXES\s*=\s*(.*)$/mi);
54 my ($var2) = ($body =~ m/^RETIRED_GL_EXES\s*=\s*(.*)$/mi);
55 error ("no RETIRED_EXES in $mf") unless $var;
56 $var .= " $var2" if $var2;
57 foreach my $hack (split (/\s+/, $var)) {
69 my @schemes = glob('xscreensaver.xcodeproj/xcuserdata/' .
70 '*.xcuserdatad/xcschemes/*.xcscheme');
71 error ("no scheme files") unless (@schemes);
75 foreach my $s (@schemes) {
76 open (my $in, '<', $s) || error ("$s: $!");
77 local $/ = undef; # read entire file
80 my ($name) = ($body =~ m@BuildableName *= *"([^\"<>]+?)\.saver"@s);
83 if ($disable{$name}) {
84 print STDERR "$progname: skipping $name\n" if ($verbose > 1);
87 print STDERR "$progname: found $name\n" if ($verbose > 1);
91 my @names = sort (keys %names);
92 error ("too few names") if (@names < 100);
94 my $suf = 'xscreensaver_function_table';
96 my $body = ("/* Generated file, do not edit.\n" .
97 " Created: " . localtime() . " by $progname $version.\n" .
100 "#import <Foundation/Foundation.h>\n" .
101 "#import <UIKit/UIKit.h>\n" .
103 "extern NSDictionary *make_function_table_dict(void);\n" .
106 $body .= "extern struct $suf";
107 foreach my $s (@names, 'testx11') {
108 $body .= "\n ${s}_${suf},";
110 $body =~ s/,\s*$/;/s;
114 return "\t[NSValue valueWithPointer:&${s}_${suf}], @\"${s}\",\n";
118 "NSDictionary *make_function_table_dict(void)\n{\n" .
119 " return\n [NSDictionary dictionaryWithObjectsAndKeys:\n" .
121 "#if defined(APPLE2_ONLY)\n" .
122 " " . line('apple2', $suf) .
123 "#elif defined(PHOSPHOR_ONLY)\n" .
124 " " . line('phosphor', $suf) .
125 "#elif defined(TESTX11_ONLY)\n" .
126 " " . line('testx11', $suf) .
128 foreach my $s (@names) { $body .= line($s, $suf); }
129 $body .= ("#endif\n" .
134 if (open (my $in, '<', $outfile)) {
135 local $/ = undef; # read entire file
140 # strip comments/date for diff.
141 my ($body2, $obody2) = ($body, $obody);
142 foreach ($body2, $obody2) { s@/\*.*?\*/@@gs; }
144 if ($body2 eq $obody2) {
145 print STDERR "$progname: $outfile: unchanged\n" if ($verbose > 1);
147 my $file_tmp = "$outfile.tmp";
148 open (my $out, '>', $file_tmp) || error ("$file_tmp: $!");
149 print $out $body || error ("$file_tmp: $!");
150 close $out || error ("$file_tmp: $!");
152 if (!rename ("$file_tmp", "$outfile")) {
154 error ("mv \"$file_tmp\" \"$outfile\": $!");
156 print STDERR "$progname: wrote $outfile\n" if ($verbose);
163 print STDERR "$progname: $err\n";
168 print STDERR "usage: $progname [--verbose] output.c\n";
175 while ($_ = $ARGV[0]) {
177 if (m/^--?verbose$/s) { $verbose++; }
178 elsif (m/^-v+$/) { $verbose += length($_)-1; }
179 elsif (m/^--?q(uiet)?$/s) { $verbose = 0; }
180 elsif (m/^-/s) { usage(); }
181 elsif (! $out) { $out = $_; }
184 usage() unless ($out);