bd5d15dfc39aee4384fe89c4eb278af89a813c69
[xscreensaver] / android / Makefile
1 # XScreenSaver for Android
2
3 export TERM=dumb
4 GRADLE = ./gradlew
5
6 default:: debug
7 all:: release
8
9 clean::
10         $(GRADLE) clean
11
12 distdepend::
13
14 # Set this to the set of platforms you want to compile for in debug mode.
15 # E.g., if you are running an x86 emulator, there's no point in compiling
16 # for a dozen other platforms.  Release builds override this to "all".
17 #
18 export APP_ABI = all
19
20
21 # TODO:
22 # check_versions:
23
24
25 # These hacks have interdependencies with others, so we can't build without
26 # including them or there are link errors:
27 #
28 ANDROID_BASE_HACKS=             \
29         apple2                  \
30         bubble3d                \
31         pacman                  \
32         polyhedra               \
33         sonar                   \
34         sproingies              \
35
36 # These are the ones that currently work, at least to some degree:
37 #
38 export ANDROID_HACKS=           \
39         $(ANDROID_BASE_HACKS)   \
40         abstractile             \
41         anemone                 \
42         anemotaxis              \
43         antmaze                 \
44         antspotlight            \
45         apollonian              \
46         atlantis                \
47         attraction              \
48         atunnel                 \
49         binaryring              \
50         blaster                 \
51         blinkbox                \
52         blocktube               \
53         boing                   \
54         bouboule                \
55         bouncingcow             \
56         boxed                   \
57         boxfit                  \
58         braid                   \
59         bsod                    \
60         cage                    \
61         ccurve                  \
62         celtic                  \
63         circuit                 \
64         cloudlife               \
65         companioncube           \
66         compass                 \
67         coral                   \
68         crackberg               \
69         crumbler                \
70         crystal                 \
71         cube21                  \
72         cubenetic               \
73         cubestack               \
74         cubestorm               \
75         cubetwist               \
76         cubicgrid               \
77         cwaves                  \
78         cynosure                \
79         dangerball              \
80         decayscreen             \
81         deco                    \
82         deluxe                  \
83         demon                   \
84         discoball               \
85         discrete                \
86         distort                 \
87         dnalogo                 \
88         drift                   \
89         dymaxionmap             \
90         energystream            \
91         engine                  \
92         epicycle                \
93         eruption                \
94         euler2d                 \
95         fadeplot                \
96         fiberlamp               \
97         fireworkx               \
98         flame                   \
99         flipflop                \
100         flow                    \
101         fluidballs              \
102         flyingtoasters          \
103         fuzzyflakes             \
104         galaxy                  \
105         gears                   \
106         geodesic                \
107         geodesicgears           \
108         gflux                   \
109         glblur                  \
110         glcells                 \
111         glhanoi                 \
112         glknots                 \
113         glmatrix                \
114         glplanet                \
115         glschool                \
116         glsnake                 \
117         gltext                  \
118         goop                    \
119         grav                    \
120         greynetic               \
121         halo                    \
122         helix                   \
123         hexadrop                \
124         hexstrut                \
125         hilbert                 \
126         hopalong                \
127         hypertorus              \
128         hypnowheel              \
129         ifs                     \
130         imsmap                  \
131         interaggregate          \
132         interference            \
133         intermomentary          \
134         jigsaw                  \
135         julia                   \
136         kaleidescope            \
137         kaleidocycle            \
138         klein                   \
139         kumppa                  \
140         lament                  \
141         lavalite                \
142         loop                    \
143         m6502                   \
144         maze                    \
145         maze3d                  \
146         memscroller             \
147         menger                  \
148         metaballs               \
149         mirrorblob              \
150         moebius                 \
151         moebiusgears            \
152         moire                   \
153         moire2                  \
154         morph3d                 \
155         mountain                \
156         munch                   \
157         nerverot                \
158         noof                    \
159         noseguy                 \
160         peepers                 \
161         penetrate               \
162         penrose                 \
163         petri                   \
164         piecewise               \
165         pinion                  \
166         pipes                   \
167         polytopes               \
168         pong                    \
169         popsquares              \
170         projectiveplane         \
171         providence              \
172         pulsar                  \
173         pyro                    \
174         quasicrystal            \
175         raverhoop               \
176         razzledazzle            \
177         rd-bomb                 \
178         ripples                 \
179         rocks                   \
180         romanboy                \
181         rorschach               \
182         rotzoomer               \
183         rubik                   \
184         rubikblocks             \
185         sballs                  \
186         shadebobs               \
187         sierpinski              \
188         sierpinski3d            \
189         skytentacles            \
190         slidescreen             \
191         slip                    \
192         spheremonics            \
193         splitflap               \
194         splodesic               \
195         squiral                 \
196         stairs                  \
197         stonerview              \
198         strange                 \
199         substrate               \
200         superquadrics           \
201         surfaces                \
202         swirl                   \
203         tangram                 \
204         thornbird               \
205         timetunnel              \
206         topblock                \
207         triangle                \
208         tronbit                 \
209         truchet                 \
210         twang                   \
211         unknownpleasures        \
212         vermiculate             \
213         vigilance               \
214         voronoi                 \
215         wander                  \
216         whirlwindwarp           \
217         winduprobot             \
218         wormhole                \
219         xflame                  \
220         xjack                   \
221         xlyap                   \
222         xrayswarm               \
223         xspirograph             \
224
225
226 # These don't work well enough to turn on by default:
227 #
228 ANDROID_TODO=                   \
229         antinspect              \
230         barcode                 \
231         blitspin                \
232         bumps                   \
233         carousel                \
234         cityflow                \
235         endgame                 \
236         esper                   \
237         flipscreen3d            \
238         fliptext                \
239         fontglide               \
240         gleidescope             \
241         glslideshow             \
242         halftone                \
243         jigglypuff              \
244         juggler3d               \
245         molecule                \
246         pedal                   \
247         phosphor                \
248         photopile               \
249         polyominoes             \
250         qix                     \
251         queens                  \
252         speedmine               \
253         spotlight               \
254         starfish                \
255         starwars                \
256         tessellimage            \
257         testx11                 \
258         unicrud                 \
259         xanalogtv               \
260         xmatrix                 \
261         zoom                    \
262
263
264 # Download and resize images from jwz.org.
265 # This saves us having to include 4MB of images in the tar file
266 # that will only be used by a vast minority of people building
267 # from source.
268 # Android actually wants these to be 160x160 but our source is 200x150.
269
270 URL = https://www.jwz.org/xscreensaver/screenshots/
271 WGET = wget -q -U xscreensaver-build-android
272 CVT  = -thumbnail '150x150^' -gravity center -extent 150x150 \
273      \( +clone  -alpha extract \
274         -draw 'fill black polygon 0,0 0,15 15,0 fill white circle 15,15 15,0' \
275         \( +clone -flip \) -compose Multiply -composite \
276         \( +clone -flop \) -compose Multiply -composite \
277      \) -alpha off -compose CopyOpacity -composite \
278     -colorspace sRGB \
279     -strip \
280     -quality 95 \
281     +dither -colors 128
282
283 # If we are making the m6502 hack, create the header file for Android
284 m6502.h::
285         @for h in $(ANDROID_HACKS) ; do \
286                 if [ $${h} = "m6502" ] ; then \
287                         echo "Making $${h} header ..."; \
288                         ../hacks/m6502.sh ../hacks/m6502.h ../hacks/images/m6502/*.asm ; \
289                         echo "Made $${h} header"; \
290                 fi; \
291         done
292
293 xscreensaver/res/drawable/%.png:
294         @\
295         FILE1=`echo "$@" | sed 's!^.*/\([^/]*\)\.png$$!\1.jpg!'` ;      \
296         FILE2="$@" ;                                                    \
297         FILE1=`echo "$$FILE1" | sed s/rdbomb/rd-bomb/` ;                \
298         FILE2=`echo "$$FILE2" | sed s/rd-bomb/rdbomb/` ;                \
299         URL="$(URL)$$FILE1" ;                                           \
300         echo "converting $$URL..." ;                                    \
301         rm -f "$$FILE2" ;                                               \
302         $(WGET) -O- "$$URL" |                                           \
303         convert jpg:- $(CVT) "$$FILE2" ;                                \
304         if [ ! -s "$$FILE2" ]; then                                     \
305           echo "$$FILE2 failed" >&2 ;                                   \
306           exit 1 ;                                                      \
307         fi
308
309 thumbs::
310         @for f in $(ANDROID_HACKS) $(ANDROID_TODO) ; do                 \
311           $(MAKE) xscreensaver/res/drawable/$$f.png ;                   \
312         done
313
314 clean_thumbs::
315         @\
316         for f in $(ANDROID_HACKS) $(ANDROID_TODO) ; do                  \
317           rm -f xscreensaver/res/drawable/$$f.png ;                     \
318         done
319
320 distclean:: clean_thumbs clean
321
322
323 EXTRA_TARFILES = xscreensaver/res/drawable/thumbnail.png \
324
325 echo_tarfiles:
326         @FILES=`find . $(EXTRA_TARFILES) \( \(  \
327                    -name .DS_Store              \
328                 -o -name '*~'                   \
329                 -o -name '*.jks'                \
330                 -o -name '*.keystore'           \
331                 -o -name '*_dream.xml'          \
332                 -o -name '*_settings.xml'       \
333                 -o -name '*_wallpaper.xml'      \
334                 -o -name AndroidManifest.xml    \
335                 -o -name strings.xml            \
336                 -o -name settings.xml           \
337                 -o -name attrs.xml              \
338                 -o -name .gitignore             \
339                 -o -name .gradle                \
340                 -o -name drawable               \
341                 -o -name build                  \
342                 -o -name gen                    \
343                 -o -name libs                   \
344                 -o -name obj                    \
345                 \) -prune \)                    \
346                 -o \( \( -type f -o -type l \)  \
347                       -print \)                 \
348                 | sed 's@^\./@@'                \
349                 | sort` ;                       \
350         echo $$FILES
351
352 images_png_h:
353         cd ../hacks/images && $(MAKE)
354
355 run_check::
356         ../hacks/check-configs.pl --build-android $(ANDROID_HACKS)
357
358 debug:: m6502.h run_check images_png_h
359         $(GRADLE) assembleDebug
360 release:: m6502.h run_check images_png_h
361         export APP_ABI=all ; \
362         $(GRADLE) assembleRelease
363
364
365 KEYSTORE = xscreensaver.jks
366 $(KEYSTORE):
367         keytool -genkey -v -keystore $@ \
368         -alias xscreensaver -keyalg RSA -keysize 2048 -validity 10000
369
370 APK_DIR       = xscreensaver/build/outputs/apk/
371 APK_UNSIGNED  = $(APK_DIR)xscreensaver-release-unsigned.apk
372 APK_UNALIGNED = $(APK_DIR)xscreensaver-release-unaligned.apk
373 APK_SIGNED    = $(APK_DIR)xscreensaver-release.apk
374
375   TOOLDIR = $(shell ls -d $$HOME/Library/Android/sdk/build-tools/* | tail -1)
376  ZIPALIGN = $(TOOLDIR)/zipalign
377 JARSIGNER = jarsigner
378
379 sign_release::
380         cp -p $(APK_UNSIGNED) $(APK_UNALIGNED)
381         $(JARSIGNER) -verbose -sigalg SHA1withRSA -digestalg SHA1 \
382                      -keystore $(KEYSTORE) $(APK_UNALIGNED) xscreensaver
383         rm -f $(APK_SIGNED)
384         $(ZIPALIGN) -v 4 $(APK_UNALIGNED) $(APK_SIGNED)
385         rm -f $(APK_UNALIGNED)
386         $(JARSIGNER) -verify -verbose -certs $(APK_SIGNED)
387         @ls -lF $(APK_SIGNED)
388
389 apk:: release
390         @\
391   VERS=`sed -n 's/[^0-9]*\([0-9]\.[0-9][^. ]*\).*/\1/p' ../utils/version.h` ; \
392   HEAD="xscreensaver-$$VERS" ;                                                \
393   if [ ! -s $(APK_SIGNED) -o $(APK_UNSIGNED) -nt $(APK_SIGNED) ]; then  \
394     $(MAKE) sign_release ;                                              \
395   fi ;                                                                  \
396   set -x ;                                                              \
397   cp -p $(APK_SIGNED) ../archive/$$HEAD.apk
398
399
400 ## #### Pare it down for faster debugging...
401 #export APP_ABI = armeabi-v7a
402 #export APP_ABI = x86
403 #
404 #export ANDROID_HACKS=          \
405 #       $(ANDROID_BASE_HACKS)   \
406 #  bsod                         \
407 #  apollonian                   \
408 #  engine                       \
409 #  dnalogo                      \
410 #  twang                        \
411 #  memscroller                  \
412 #  phosphor                     \
413 #  discoball                    \
414 #  cubetwist                    \
415 #  cubestack                    \
416 #  splodesic                    \