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