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