michael@0: # -*- makefile -*- michael@0: # vim:set ts=8 sw=8 sts=8 noet: michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: # You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: ifndef INCLUDED_JAVA_BUILD_MK #{ michael@0: michael@0: ifdef JAVAFILES #{ michael@0: GENERATED_DIRS += classes michael@0: michael@0: export:: classes michael@0: classes: $(call mkdir_deps,classes) michael@0: endif #} JAVAFILES michael@0: michael@0: michael@0: ifdef ANDROID_APK_NAME #{ michael@0: android_res_dirs := $(addprefix $(srcdir)/,$(or $(ANDROID_RES_DIRS),res)) michael@0: _ANDROID_RES_FLAG := $(addprefix -S ,$(android_res_dirs)) michael@0: _ANDROID_ASSETS_FLAG := $(addprefix -A ,$(ANDROID_ASSETS_DIR)) michael@0: android_manifest := $(or $(ANDROID_MANIFEST_FILE),AndroidManifest.xml) michael@0: michael@0: GENERATED_DIRS += classes michael@0: michael@0: classes.dex: $(call mkdir_deps,classes) michael@0: classes.dex: R.java michael@0: classes.dex: $(ANDROID_APK_NAME).ap_ michael@0: classes.dex: $(ANDROID_EXTRA_JARS) michael@0: classes.dex: $(JAVAFILES) michael@0: $(JAVAC) $(JAVAC_FLAGS) -d classes $(filter %.java,$^) \ michael@0: $(if $(strip $(ANDROID_EXTRA_JARS)),-classpath $(subst $(NULL) ,:,$(strip $(ANDROID_EXTRA_JARS)))) michael@0: $(DX) --dex --output=$@ classes $(ANDROID_EXTRA_JARS) michael@0: michael@0: # R.java and $(ANDROID_APK_NAME).ap_ are both produced by aapt. To michael@0: # save an aapt invocation, we produce them both at the same time. The michael@0: # trailing semi-colon defines an empty recipe; defining no recipe at michael@0: # all causes Make to treat the target differently, in a way that michael@0: # defeats our dependencies. michael@0: michael@0: R.java: .aapt.deps ; michael@0: $(ANDROID_APK_NAME).ap_: .aapt.deps ; michael@0: michael@0: # This uses the fact that Android resource directories list all michael@0: # resource files one subdirectory below the parent resource directory. michael@0: android_res_files := $(wildcard $(addsuffix /*,$(wildcard $(addsuffix /*,$(android_res_dirs))))) michael@0: michael@0: .aapt.deps: $(android_manifest) $(android_res_files) $(wildcard $(ANDROID_ASSETS_DIR)) michael@0: @$(TOUCH) $@ michael@0: $(AAPT) package -f -M $< -I $(ANDROID_SDK)/android.jar $(_ANDROID_RES_FLAG) $(_ANDROID_ASSETS_FLAG) \ michael@0: -J ${@D} \ michael@0: -F $(ANDROID_APK_NAME).ap_ michael@0: michael@0: $(ANDROID_APK_NAME)-unsigned-unaligned.apk: $(ANDROID_APK_NAME).ap_ classes.dex michael@0: cp $< $@ michael@0: $(ZIP) -0 $@ classes.dex michael@0: michael@0: $(ANDROID_APK_NAME)-unaligned.apk: $(ANDROID_APK_NAME)-unsigned-unaligned.apk michael@0: cp $< $@ michael@0: $(DEBUG_JARSIGNER) $@ michael@0: michael@0: $(ANDROID_APK_NAME).apk: $(ANDROID_APK_NAME)-unaligned.apk michael@0: $(ZIPALIGN) -f -v 4 $< $@ michael@0: michael@0: GARBAGE += \ michael@0: R.java \ michael@0: classes.dex \ michael@0: $(ANDROID_APK_NAME).ap_ \ michael@0: $(ANDROID_APK_NAME)-unsigned-unaligned.apk \ michael@0: $(ANDROID_APK_NAME)-unaligned.apk \ michael@0: $(ANDROID_APK_NAME).apk \ michael@0: $(NULL) michael@0: michael@0: JAVA_CLASSPATH := $(ANDROID_SDK)/android.jar michael@0: michael@0: # Include Android specific java flags, instead of what's in rules.mk. michael@0: include $(topsrcdir)/config/android-common.mk michael@0: endif #} ANDROID_APK_NAME michael@0: michael@0: michael@0: ifdef JAVA_JAR_TARGETS #{ michael@0: # Arg 1: Output target name with .jar suffix, like jars/jarfile.jar. michael@0: # Intermediate class files are generated in jars/jarfile-classes. michael@0: # Arg 2: Java sources list. We use VPATH and $^ so sources can be michael@0: # relative to $(srcdir) or $(CURDIR). michael@0: # Arg 3: List of extra jars to link against. We do not use VPATH so michael@0: # jars must be relative to $(CURDIR). michael@0: # Arg 4: Additional JAVAC_FLAGS. michael@0: michael@0: # Note: Proguard fails when stale .class files corresponding to michael@0: # removed inner classes are present in the object directory. These michael@0: # stale class files get packaged into the .jar file, which then gets michael@0: # processed by Proguard. To work around this, we always delete any michael@0: # existing jarfile-classes directory and start fresh. michael@0: michael@0: define java_jar_template michael@0: $(1): $(2) $(3) michael@0: $$(REPORT_BUILD) michael@0: @$$(RM) -rf $(1:.jar=)-classes michael@0: @$$(NSINSTALL) -D $(1:.jar=)-classes michael@0: @$$(if $$(filter-out .,$$(@D)),$$(NSINSTALL) -D $$(@D)) michael@0: $$(JAVAC) $$(JAVAC_FLAGS)\ michael@0: $(4)\ michael@0: -d $(1:.jar=)-classes\ michael@0: $(if $(strip $(3)),-classpath $(subst $(NULL) ,:,$(strip $(3))))\ michael@0: $$(filter %.java,$$^) michael@0: $$(JAR) cMf $$@ -C $(1:.jar=)-classes . michael@0: michael@0: GARBAGE += $(1) michael@0: michael@0: GARBAGE_DIRS += $(1:.jar=)-classes michael@0: endef michael@0: michael@0: $(foreach jar,$(JAVA_JAR_TARGETS),\ michael@0: $(if $($(jar)_DEST),,$(error Missing $(jar)_DEST))\ michael@0: $(if $($(jar)_JAVAFILES) $($(jar)_PP_JAVAFILES),,$(error Must provide at least one of $(jar)_JAVAFILES and $(jar)_PP_JAVAFILES))\ michael@0: $(eval $(call java_jar_template,$($(jar)_DEST),$($(jar)_JAVAFILES) $($(jar)_PP_JAVAFILES),$($(jar)_EXTRA_JARS),$($(jar)_JAVAC_FLAGS)))\ michael@0: ) michael@0: endif #} JAVA_JAR_TARGETS michael@0: michael@0: michael@0: INCLUDED_JAVA_BUILD_MK := 1 michael@0: michael@0: endif #} INCLUDED_JAVA_BUILD_MK