Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
[fw/altos] / altosdroid / Makefile.am
1 if ANDROID
2 all_target=bin/AltosDroid-debug.apk
3 if ANDROID_RELEASE
4 all_target+=bin/AltosDroid-release.apk
5 endif
6 else
7 all_target=
8 endif
9
10 SDK=$(ANDROID_SDK)
11 SDK_TARGET=$(shell sed -ne 's/^target=//p' project.properties)
12
13 DX=$(SDK)/platform-tools/dx
14 ADB=$(SDK)/platform-tools/adb
15 AAPT=$(SDK)/platform-tools/aapt
16 APKBUILDER=$(SDK)/tools/apkbuilder
17 ZIPALIGN_A=$(SDK)/tools/zipalign
18 ZIPALIGN_B=$(SDK)/build-tools/*/zipalign
19
20 JAVA_SRC_DIR=src/org/altusmetrum/AltosDroid
21 EXT_LIBDIR=libs
22 DRAWABLE_DIR=res/drawable
23 ALTOSLIB_SRCDIR=../altoslib
24 ALTOSLIB_JAR=altoslib_$(ALTOSLIB_VERSION).jar
25
26 ALTOSLIB=$(EXT_LIBDIR)/$(ALTOSLIB_JAR)
27
28 SUPPORT_V4_SRCDIR=$(SDK)/extras/android/support/v4
29 SUPPORT_V4_JAR=android-support-v4.jar
30
31 SUPPORT_V4=$(EXT_LIBDIR)/$(SUPPORT_V4_JAR)
32
33 GOOGLE_PLAY_SERVICES_LIB_SRCDIR=$(SDK)/extras/google/google_play_services/libproject
34 GOOGLE_PLAY_SERVICES_LIB=google-play-services_lib
35
36 JAVA_SRC=$(JAVA_SRC_DIR)/*.java $(JAVA_SRC_DIR)/BuildInfo.java
37
38 DRAWABLES=\
39     $(DRAWABLE_DIR)/redled.png \
40     $(DRAWABLE_DIR)/greenled.png \
41     $(DRAWABLE_DIR)/grayled.png
42
43 SRC=$(JAVA_SRC) $(DRAWABLES)
44
45 all: $(all_target)
46
47 .NOTPARALLEL:
48
49 $(EXT_LIBDIR):
50         mkdir -p $(EXT_LIBDIR)
51
52 $(ALTOSLIB): $(EXT_LIBDIR) $(ALTOSLIB_SRCDIR)/$(ALTOSLIB_JAR)
53         cd $(EXT_LIBDIR) && ln -sf $(shell echo $(EXT_LIBDIR) | sed 's|[^/]\+|..|g')/$(ALTOSLIB_SRCDIR)/$(ALTOSLIB_JAR) .
54
55 $(SUPPORT_V4): $(EXT_LIBDIR) $(SUPPORT_V4_SRCDIR)/$(SUPPORT_V4_JAR)
56         cd $(EXT_LIBDIR) && ln -sf $(SUPPORT_V4_SRCDIR)/$(SUPPORT_V4_JAR) .
57
58 $(GOOGLE_PLAY_SERVICES_LIB): $(GOOGLE_PLAY_SERVICES_LIB_SRCDIR)/$(GOOGLE_PLAY_SERVICES_LIB)
59         cp -a $(GOOGLE_PLAY_SERVICES_LIB_SRCDIR)/$(GOOGLE_PLAY_SERVICES_LIB) .
60         cd $(GOOGLE_PLAY_SERVICES_LIB) && $(SDK)/tools/android update project --target $(SDK_TARGET) --path .
61
62 $(JAVA_SRC_DIR)/BuildInfo.java: $(filter-out $(JAVA_SRC_DIR)/BuildInfo.java,$(shell echo $(JAVA_SRC)))
63         ./buildinfo.sh
64
65 $(DRAWABLE_DIR)/%.png: ../icon/%.png
66         cd $(DRAWABLE_DIR) && ln -sf $(shell echo $(DRAWABLE_DIR) | sed 's|[^/]\+|..|g')/$< .
67
68 if ANDROID
69 install-release: bin/AltosDroid-release.apk
70         $(ADB) install -r bin/AltosDroid-release.apk
71
72 install-debug: bin/AltosDroid-debug.apk
73         $(ADB) install -r bin/AltosDroid-debug.apk
74
75 bin/AltosDroid-debug.apk: $(SRC) $(ALTOSLIB) $(SUPPORT_V4) $(GOOGLE_PLAY_SERVICES_LIB)
76         ant debug
77
78 bin/AltosDroid-release-unsigned.apk: $(SRC) $(ALTOSLIB) $(SUPPORT_V4) $(GOOGLE_PLAY_SERVICES_LIB)
79         ant release
80
81 bin/AltosDroid-release.apk: bin/AltosDroid-release-unsigned.apk
82         jarsigner -sigalg SHA1withDSA -digestalg SHA1 \
83            -keystore ~/altusmetrumllc/google-play-release.keystore \
84            -storepass:file ~/altusmetrumllc/google-play-passphrase \
85            -signedjar bin/AltosDroid-release-signed.apk \
86            bin/AltosDroid-release-unsigned.apk AltosDroid
87         if [ -f $(ZIPALIGN_A) ]; then \
88                 $(ZIPALIGN_A) -f 4 \
89                    bin/AltosDroid-release-signed.apk \
90                    bin/AltosDroid-release.apk; \
91         else \
92                 $(ZIPALIGN_B) -f 4 \
93                    bin/AltosDroid-release-signed.apk \
94                    bin/AltosDroid-release.apk; \
95         fi
96
97 release: bin/AltosDroid-release.apk
98
99 clean-local: $(GOOGLE_PLAY_SERVICES_LIB)
100         ant clean
101         rm -f $(JAVA_SRC_DIR)/BuildInfo.java
102         rm -f $(DRAWABLES)
103         rm -rf $(EXT_LIBDIR)
104         rm -rf $(GOOGLE_PLAY_SERVICES_LIB)
105
106 else
107
108 clean-local:
109
110 endif
111
112 clean: clean-local