From http://www.jwz.org/xscreensaver/xscreensaver-5.36.tar.gz
[xscreensaver] / OSX / Makefile
1 # XScreenSaver for MacOS X, Copyright (c) 2006-2015 by Jamie Zawinski.
2
3 XCODE_APP = /Applications/Xcode.app
4
5 # To build savers that will run on MacOS 10.6 and 10.7, Xcode 5.0.2 must
6 # be used (as that's the latest version of Xcode that ships with a version
7 # of clang that implements "-fobjc-gc").  However, Xcode 5.0.2 will not
8 # launch on MacOS 10.11 or later.
9 #
10 # XCODE_APP = /Applications/Xcode-5.0.2.app
11
12 TARGETS    = All Savers
13 ARCH       = -arch i386 -arch x86_64 ONLY_ACTIVE_ARCH=NO
14 CERT       = 'Developer ID Installer: Jamie Zawinski (4627ATJELP)'
15 PKGID      = org.jwz.xscreensaver
16 THUMBDIR   = build/screenshots
17 XCODEBUILD = $(XCODE_APP)/Contents/Developer/usr/bin/xcodebuild
18 SETFILE    = $(XCODE_APP)/Contents/Developer/Tools/SetFile
19 SETICON    = ./seticon.pl
20
21 default: release
22 all: debug release
23
24 clean:
25         -rm -rf build
26 #       $(XCODEBUILD) -target "$(TARGETS)" clean
27
28 distclean:
29         -rm -f config.status config.cache config.log \
30           *.bak *.rej TAGS *~ "#"*
31         -rm -rf autom4te*.cache
32         -rm -rf build Sparkle.framework
33
34 distdepend:: Sparkle.framework
35 distdepend:: update_plist_version
36
37 debug: distdepend
38         $(XCODEBUILD) $(ARCH) -target "$(TARGETS)" -configuration Debug   build
39
40 release:: distdepend
41         $(XCODEBUILD) $(ARCH) -target "$(TARGETS)" -configuration Release build
42
43 release:: check_versions
44
45 Sparkle.framework:
46         unzip ../archive/Sparkle.framework-2013-12-04.zip
47
48 # Download and resize images from jwz.org.
49 # This saves us having to include 4MB of images in the tar file
50 # that will only be used by a vast minority of people building
51 # from source.
52 # update-info-plist.pl runs this as needed.
53 # Might be better to do this with curl, since that is installed by default.
54
55 URL = https://www.jwz.org/xscreensaver/screenshots/
56 WGET = wget -q -U xscreensaver-build-osx
57 CVT  = -thumbnail '200x150^' -gravity center -extent 200x150 \
58      \( +clone  -alpha extract \
59         -draw 'fill black polygon 0,0 0,6 6,0 fill white circle 6,6 6,0' \
60         \( +clone -flip \) -compose Multiply -composite \
61         \( +clone -flop \) -compose Multiply -composite \
62      \) -alpha off -compose CopyOpacity -composite \
63     -colorspace sRGB \
64     -strip \
65     -quality 95 \
66     +dither -colors 128
67
68 $(THUMBDIR)/%.png:
69         @\
70         FILE1=`echo "$@" | sed 's!^.*/\([^/]*\)\.png$$!\1.jpg!'` ;      \
71         FILE2="$@" ;                                                    \
72         TMP="$$FILE2".tmp ;                                             \
73         URL="$(URL)$$FILE1" ;                                           \
74         URL2="$(URL)retired/$$FILE1" ;                                  \
75         if [ ! -d $(THUMBDIR) ]; then mkdir -p $(THUMBDIR) ; fi ;       \
76         rm -f "$$FILE2" "$$TMP" ;                                       \
77         set +e ;                                                        \
78         echo "downloading $$URL..." ;                                   \
79         $(WGET) -O"$$TMP" "$$URL" ;                                     \
80         if [ ! -s "$$TMP" ]; then                                       \
81           echo "downloading $$URL2..." ;                                \
82           $(WGET) -O"$$TMP" "$$URL2" ;                                  \
83         fi ;                                                            \
84         if [ ! -s "$$TMP" ]; then                                       \
85           rm -f "$$TMP" ;                                               \
86           echo "failed: $$URL" ;                                        \
87           exit 1 ;                                                      \
88         fi ;                                                            \
89         rm -f "$$FILE2" ;                                               \
90         convert jpg:- $(CVT) "$$FILE2" < "$$TMP" ;                      \
91         if [ ! -s "$$FILE2" ]; then                                     \
92           echo "$$FILE2 failed" >&2 ;                                   \
93           rm -f "$$FILE2" "$$TMP" ;                                     \
94           exit 1 ;                                                      \
95         else                                                            \
96           rm -f "$$TMP" ;                                               \
97         fi
98
99
100 check_versions:
101         @\
102   SRC=../utils/version.h ;                                              \
103   V=`sed -n 's/[^0-9]*\([0-9]\.[0-9][^. ]*\).*/\1/p' $$SRC` ;           \
104   DIR=build/Release ;                                                   \
105   RESULT=0 ;                                                            \
106   for S in $$DIR/*.{saver,app} ; do                                     \
107    for P in $$S/Contents/Info.plist ; do                                \
108      V2=`plutil -convert xml1 -o - "$$P" |                              \
109          perl -0000 -n -e                                               \
110         'm@<key>CFBundleVersion</key>\s*<string>(.*?)</string>@si       \
111          && print $$1'` ;                                               \
112      if [ "$$V2" != "$$V" ] ; then                                      \
113        echo "Wrong version: $$S ($$V2)" ;                               \
114        RESULT=1 ;                                                       \
115      fi ;                                                               \
116    done ;                                                               \
117   done ;                                                                \
118   if [ "$$RESULT" = 0 ]; then echo "Versions match ($$V2)" ; fi ;       \
119   exit $$RESULT
120
121
122 check_gc:
123         @\
124   DIR="build/Release" ;                                                 \
125   RESULT=0 ;                                                            \
126   for S in "$$DIR/"*.saver ; do                                         \
127    SS=`echo "$$S" | sed -e 's@^.*/@@' -e 's/.saver$$//'` ;              \
128    D="$$S/Contents/MacOS/$$SS" ;                                        \
129    V=`otool -s __DATA __objc_imageinfo "$$D"                            \
130       | grep ' 00 02 00 '` ;                                            \
131    if [ -z "$$V" ]; then                                                \
132      echo "$$S does not have GC enabled" ;                              \
133      RESULT=1 ;                                                         \
134    fi ;                                                                 \
135   done ;                                                                \
136                                                                         \
137   for D in "$$DIR"/webcollage-helper                                    \
138            "$$DIR"/*.saver/Contents/*/webcollage-helper                 \
139            "$$DIR"/*.app/Contents/*/XScreenSaverUpdater                 \
140    ; do                                                                 \
141    V=`otool -s __DATA __objc_imageinfo "$$D"                            \
142       | grep ' 00 02 00 '` ;                                            \
143    if [ ! -z "$$V" ]; then                                              \
144      echo "$$D has GC enabled" ;                                        \
145      RESULT=1 ;                                                         \
146    fi ;                                                                 \
147   done ;                                                                \
148                                                                         \
149   if [ "$$RESULT" = 0 ]; then echo "GC enabled" ; fi ;                  \
150   exit $$RESULT
151
152
153 check_coretext:
154         @\
155   DIR="build/Release" ;                                                 \
156   RESULT=0 ;                                                            \
157   for S in "$$DIR/"*.{saver,app} ; do                                   \
158    SS=`echo "$$S" | sed -e 's@^.*/@@' -e 's/[.][a-z]*$$//'` ;           \
159    D="$$S/Contents/MacOS/$$SS" ;                                        \
160    FF=`otool -l "$$D"                                                   \
161       | fgrep '/CoreText.framework/'                                    \
162       | sed -n 's/^ *name \([^ ]*\).*$$/\1/p'` ;                        \
163    if [ -z "$$FF" ] ; then                                              \
164      echo "$$S not linked with CoreText" >/dev/null ;                   \
165    else                                                                 \
166      OK=`echo "$$FF" | fgrep -v '/ApplicationServices.framework/'` ;    \
167      if [ ! -z "$$OK" ]; then                                           \
168        echo "$$S is linked with the wrong CoreText: $$FF" ;             \
169        RESULT=1 ;                                                       \
170      else                                                               \
171        echo "$$S linked right: $$FF" >/dev/null ;                       \
172      fi ;                                                               \
173    fi ;                                                                 \
174   done ;                                                                \
175   if [ "$$RESULT" = 0 ]; then echo "CoreText linked correctly" ; fi ;   \
176   exit $$RESULT
177
178
179 # Arrrrgh
180 ios-function-table.m::
181         @./build-fntable.pl build/Debug-iphonesimulator/XScreenSaver.app $@
182
183
184 echo_tarfiles:
185         @echo `( find .                                                 \
186           \( \( -name '.??*' -o -name build -o -name CVS -o -name '*~*' \
187              -o -name 'jwz.*' -o -name 'Screen Savers'                  \
188              -o -name xscreensaver.xcodeproj \)                         \
189              -prune \)                                                  \
190           -o \( -type f -o -type l \) -print ;                          \
191           echo xscreensaver.xcodeproj/project.pbxproj )                 \
192         | sed 's@^\./@@'                                                \
193         | sort`
194
195 update_plist_version:
196         @                                                                     \
197   SRC=../utils/version.h ;                                                    \
198   V=`sed -n 's/[^0-9]*\([0-9]\.[0-9][^. ]*\).*/\1/p' $$SRC` ;                 \
199   T=/tmp/xs.$$$$ ;                                                            \
200   for S in *.plist ; do                                                       \
201     /bin/echo -n "Updating version number in $$S to \"$$V\"... " ;            \
202     KEYS="CFBundleVersion|CFBundleShortVersionString|CFBundleLongVersionString|CFBundleGetInfoString|NSHumanReadableCopyright" ; \
203     perl -0777 -pne                                                           \
204       "s@(<key>($$KEYS)</key>\s*<string>)[^<>]+(</string>)@\$${1}$$V\$${3}@g" \
205       < $$S > $$T ;                                                           \
206     if cmp -s $$S $$T ; then                                                  \
207       echo "unchanged." ;                                                     \
208     else                                                                      \
209       cat $$T > $$S ;                                                         \
210       echo "done." ;                                                          \
211     fi ;                                                                      \
212   done ;                                                                      \
213   rm $$T
214
215
216 updates.xml::
217         ./updates.pl xscreensaver ../README ../archive ~/www/xscreensaver
218         @$(MAKE) test_sig
219
220 test_sig::
221         @                                                                   \
222   U=../utils/version.h ;                                                    \
223   V=`sed -n 's/[^0-9]*\([0-9]\.[0-9][^. ;]*\).*/\1/p' < $$U` ;              \
224   BASE="xscreensaver-$$V" ;                                                 \
225   OUTDIR="../archive" ;                                                     \
226   DMG="$$OUTDIR/$$BASE.dmg" ;                                               \
227   SIG=`sed -n 's/^.*dsaSignature="\(.*\)".*/\1/p' updates.xml` ;            \
228   PUB="sparkle_dsa_pub.pem" ;                                               \
229   NN="t.$$$$" ;                                                             \
230   SIGB=/tmp/$$NN.sig ;                                                      \
231   HASH=/tmp/$$NN.hash ;                                                     \
232   rm -f "$$SIGB" "$$HASH" ;                                                 \
233   echo "$$SIG " | base64 -D  > "$$SIGB" ;                                   \
234   set -e ;                                                                  \
235   for OPENSSL in /usr/bin/openssl /opt/local/bin/openssl ; do               \
236     $$OPENSSL dgst -sha1 -binary  < "$$DMG"  > "$$HASH" ;                   \
237     /bin/echo -n "$$OPENSSL     `$$OPENSSL version`:    " ;                 \
238     $$OPENSSL dgst -dss1 -verify "$$PUB" -signature "$$SIGB" "$$HASH" ;     \
239   done ;                                                                    \
240   rm -f "$$SIGB" "$$HASH" ;                                                 \
241
242
243 build/Release/installer.pkg: installer.rtf installer.xml installer.sh installer.png ../utils/version.h
244         @\
245   set -e ;                                                              \
246   SRC=../utils/version.h ;                                              \
247   V=`sed -n 's/[^0-9]*\([0-9]\.[0-9][^. ]*\).*/\1/p' $$SRC` ;           \
248                                                                         \
249   DIST="installer.xml" ;                                                \
250   STAGE="build/Release/pkg_stage" ;                                     \
251   FINAL="$@" ;                                                          \
252   UNSIGNED="$$STAGE/contents.pkg" ;                                     \
253   PRODUCT="$$STAGE/product_unsigned.pkg" ;                              \
254   SCRIPTS="$$STAGE/scripts" ;                                           \
255   RES="$$STAGE/resources" ;                                             \
256                                                                         \
257   set -x ;                                                              \
258   rm -rf "$$STAGE" ;                                                    \
259   mkdir -p "$$SCRIPTS" "$$RES" ;                                        \
260                                                                         \
261   cp -p installer.sh "$$SCRIPTS/preinstall" ;                           \
262   cp -p installer.png "$$RES/background.png" ;                          \
263   cp -p installer.rtf "$$RES/welcome.rtf" ;                             \
264                                                                         \
265   pkgbuild --identifier "$(PKGID)" --version "$$V"                      \
266            --scripts "$$SCRIPTS" --nopayload "$$UNSIGNED" ;             \
267                                                                         \
268   productbuild --distribution "$$DIST" --resources "$$RES"              \
269                --package-path "$$STAGE" --version "$$V" "$$PRODUCT" ;   \
270                                                                         \
271   productsign --sign $(CERT) "$$PRODUCT" "$$FINAL" ;                    \
272   spctl --assess --verbose=4 --type install "$$FINAL" ;                 \
273                                                                         \
274   rm -rf "$$STAGE" ;                                                    \
275
276
277 # -format UDBZ saves 4% (~1.2 MB) over UDZO.
278 dmg:: distdepend
279 dmg:: check_versions check_coretext
280 #dmg:: check_gc
281 dmg:: build/Release/installer.pkg
282 dmg::
283         @                                                                     \
284   set -e ;                                                                    \
285   SRC=../utils/version.h ;                                                    \
286   V=`sed -n 's/[^0-9]*\([0-9]\.[0-9][^. ]*\).*/\1/p' $$SRC` ;                 \
287   TMPDIR="build" ;                                                            \
288   SRC="build/Release" ;                                                       \
289   EXTRAS=../../xdaliclock/OSX/build/Release/*.saver ;                         \
290   BASE="xscreensaver-$$V" ;                                                   \
291   OUTDIR="../archive" ;                                                       \
292   DMG="$$OUTDIR/$$BASE.dmg" ;                                                 \
293   TMPDMG="$$TMPDIR/tmp.dmg" ;                                                 \
294   VOLNAME="XScreenSaver $$V" ;                                                \
295   STAGE="$$TMPDIR/dmg_stage" ;                                                \
296   DST="$$STAGE/Screen Savers" ;                                               \
297   PKG="$$STAGE/Install Everything.pkg" ;                                      \
298   rm -f "$$DMG" ;                                                             \
299   rm -rf "$$STAGE" ;                                                          \
300   echo + mkdir -p "$$DST" ;                                                   \
301          mkdir -p "$$DST" ;                                                   \
302                                                                               \
303   retired=`perl -0 -ne                                                        \
304      's/\\\\\\n//g; m/^RETIRED_EXES\s*=\s*(.*)$$/m && print "$$1\n"'          \
305       ../hacks/Makefile.in ;                                                  \
306       perl -0 -ne                                                             \
307      's/\\\\\\n//g; m/^RETIRED_GL_EXES\s*=\s*(.*)$$/m && print "$$1\n"'       \
308       ../hacks/glx/Makefile.in ;                                              \
309      echo xscreensaver ;                                                      \
310      echo savertester` ;                                                      \
311                                                                               \
312   for f in $$SRC/*.{saver,app} $$EXTRAS ; do                                  \
313    f2=`basename "$$f"` ;                                                      \
314    ok=yes ;                                                                   \
315    ff=`echo $$f | perl -e '$$_=<>; s@^.*/(.*)\..*$$@\L$$1@; print'`;          \
316    for r in $$retired ; do                                                    \
317     if [ "$$ff" = "$$r" ]; then ok=no ; fi ;                                  \
318    done ;                                                                     \
319    if [ "$$ff" = testx11 ]; then ok=no ; fi ;                                 \
320    if [ "$$f2" = "XScreenSaverUpdater.app" ]; then                            \
321     DST_HACK="XScreenSaver.updater" ;                                         \
322     echo + tar ... "$$DST/$$DST_HACK" ;                                       \
323     ( cd $$SRC ; tar -czf - "$$f2" ) > "$$DST/$$DST_HACK" ;                   \
324    elif [ "$$ok" = yes ]; then                                                \
325     echo + cp -pR "$$f" "$$DST/" ;                                            \
326            cp -pR "$$f" "$$DST/" ;                                            \
327    else                                                                       \
328     echo skipping "$$f" ;                                                     \
329    fi ;                                                                       \
330   done ;                                                                      \
331                                                                               \
332   set -x ;                                                                    \
333   cp -p bindist.rtf "$$STAGE/Read Me.rtf" ;                                   \
334   cp -p build/Release/installer.pkg "$$PKG" ;                                 \
335   cp -p bindist-DS_Store "$$STAGE/.DS_Store" ;                                \
336   cp -p bindist.webloc "$$STAGE/" ;                                           \
337   cp -p XScreenSaverDMG.icns "$$STAGE/.VolumeIcon.icns" ;                     \
338   ${SETFILE} -a C "$$STAGE" ;                                                 \
339   ${SETFILE} -a E "$$STAGE"/*.{rtf,pkg,webloc} ;                              \
340   $(SETICON) -d ../../xdaliclock/OSX/daliclockSaver.icns                      \
341                 "$$DST/DaliClock.saver" ;                                     \
342   $(SETICON) -d XScreenSaverFolder.icns "$$DST" ;                             \
343   $(SETICON) -d XScreenSaver.icns "$$DST"/*.saver ;                           \
344   $(SETICON) -d SaverRunner.icns "$$DST"/*.app ;                              \
345   $(SETICON) -d XScreenSaverWebloc.icns "$$STAGE"/*.webloc ;                  \
346   $(SETICON) -d XScreenSaverPkg.icns "$$STAGE"/*.pkg ;                        \
347   mv "$$STAGE/bindist.webloc" "$$STAGE/Get the iPhone:iPad Version.webloc" ;  \
348                                                                               \
349   set +x ;                                                                    \
350   echo "Checking signatures..." ;                                             \
351   spctl --assess --type install "$$PKG" ;                                     \
352   spctl --assess --type execute "$$SRC/XScreenSaverUpdater.app" ;             \
353   spctl --assess --type execute "$$DST/"*.app ;                               \
354   spctl --assess --type install "$$DST/"*.saver ;                             \
355   set -x ;                                                                    \
356                                                                               \
357   hdiutil makehybrid -quiet -ov -hfs -hfs-volume-name "$$VOLNAME"             \
358     -hfs-openfolder "$$STAGE" "$$STAGE" -o "$$TMPDMG" ;                       \
359   rm -rf "$$STAGE" ;                                                          \
360                                                                               \
361   hdiutil convert -quiet -ov -format UDBZ -imagekey zlib-level=9              \
362     "$$TMPDMG" -o "$$DMG" ;                                                   \
363   xattr -w com.apple.quarantine "0000;00000000;;" "$$DMG" ;                   \
364   rm -f "$$TMPDMG" ;                                                          \
365   ls -ldhgF "$$DMG"
366
367
368 # When debugging, sometimes I have to reset the preferences for all
369 # the savers.  Also I like FPS to be turned on, and them all to be
370 # pointed at the same image directory.
371 #
372 show_prefs::
373         @cd build/Debug ;                                                     \
374         for f in *.saver ; do                                                 \
375           f=`echo "$$f" | sed 's/\..*//'` ;                                   \
376           echo "########################## $$f" ;                             \
377           defaults -currentHost read org.jwz.xscreensaver."$$f" 2>&- ;        \
378         done ;                                                                \
379         for f in Apple2 Phosphor updater ; do                                 \
380           echo "########################## $$f" ;                             \
381           defaults read org.jwz.xscreensaver."$$f" 2>&- ;                     \
382         done
383
384 reset_prefs::
385         @cd build/Debug ;                                                     \
386         W1='defaults' ;                                                       \
387         W2="$$W1 -currentHost write" ;                                        \
388         img='~/Pictures/Screensaver' ;                                        \
389         for f in *.saver ; do                                                 \
390           name=`echo "$$f" | sed 's/\..*//'` ;                                \
391           echo "########################## $$name" ;                          \
392           domain="org.jwz.xscreensaver" ;                                     \
393           dd="$$domain.$$name" ;                                              \
394           $$W1 -currentHost delete "$$dd" 2>&- ;                              \
395           $$W2 "$$dd" doFPS -bool true ;                                      \
396           if [ -f $$f/Contents/Resources/xscreensaver-text ] ; then           \
397             $$W2 "$$dd" textMode url ;                                        \
398           fi ;                                                                \
399           if [ -f $$f/Contents/Resources/xscreensaver-getimage-file ] ; then  \
400             $$W2 "$$dd" chooseRandomImages -bool true ;                       \
401             $$W2 "$$dd" grabDesktopImages -bool false ;                       \
402             $$W2 "$$dd" imageDirectory "$$img" ;                              \
403           fi ;                                                                \
404           if ( strings "$$f/Contents/MacOS/$$name" |                          \
405                 grep NSOpenGLContext >/dev/null ) ; then                      \
406             $$W2 "$$dd" multiSample -bool true ;                              \
407           fi ;                                                                \
408         done ;                                                                \
409                                                                               \
410         $$W1 delete "$$domain.Apple2" 2>&- ;                                  \
411         $$W1 delete "$$domain.Phosphor" 2>&- ;                                \
412         $$W1 delete "$$domain.updater" 2>&- ;                                 \
413         $$W1 write  "$$domain.updater" SUScheduledCheckIntervalKey 86400;     \
414                                                                               \
415         $$W2 "$$domain.BoxFit" grab -bool true ;                              \
416         $$W2 "$$domain.FlipFlop" textured -bool true ;                        \
417         $$W2 "$$domain.GLSlideshow" titles -bool true ;                       \
418         $$W2 "$$domain.Photopile" titles -bool true ;                         \
419         $$W2 "$$domain.SkyTentacles" mode cel ;                               \
420         $$W2 "$$domain.Sonar" ping                                            \
421           '/etc/hosts,$$HOME/.ssh/known_hosts,$$HOME/.ssh/known_hosts2' ;     \
422         $$W2 "$$domain.XMatrix" matrixFont small ;                            \
423         $$W2 "$$domain.XMatrix" textMode literal ;                            \
424         $$W2 "$$domain.XMatrix" textLiteral "MONKEY BUTTER" ;                 \
425
426 # defaults -currentHost write org.jwz.xscreensaver.FontGlide debugMetrics -bool true
427 # defaults -currentHost write org.jwz.xscreensaver.StarWars debug -bool true
428 # defaults -currentHost write org.jwz.xscreensaver.StarWars textMode file
429 # defaults -currentHost write org.jwz.xscreensaver.StarWars textFile ~/src/xscreensaver/hacks/glx/zalgo.txt