2013-01-26 00:22:13 +04:00
|
|
|
# -*- makefile -*-
|
|
|
|
# vim:set ts=8 sw=8 sts=8 noet:
|
|
|
|
#
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
# You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
ifndef INCLUDED_JAVA_BUILD_MK #{
|
|
|
|
|
|
|
|
ifdef JAVAFILES #{
|
|
|
|
GENERATED_DIRS += classes
|
2013-03-19 23:34:59 +04:00
|
|
|
|
|
|
|
export:: classes
|
|
|
|
classes: $(call mkdir_deps,classes)
|
2013-10-01 23:43:30 +04:00
|
|
|
endif #} JAVAFILES
|
|
|
|
|
2015-08-31 23:35:05 +03:00
|
|
|
default_bootclasspath_jars := \
|
|
|
|
$(ANDROID_SDK)/android.jar \
|
|
|
|
$(NULL)
|
|
|
|
|
|
|
|
default_classpath_jars := \
|
|
|
|
$(NULL)
|
|
|
|
|
|
|
|
# Turn a possibly empty list of JAR files into a Java classpath, like a.jar:b.jar.
|
|
|
|
# Arg 1: Possibly empty list of JAR files.
|
|
|
|
define classpath_template
|
|
|
|
$(subst $(NULL) ,:,$(strip $(1)))
|
|
|
|
endef
|
2013-10-01 23:43:30 +04:00
|
|
|
|
|
|
|
ifdef ANDROID_APK_NAME #{
|
2015-08-19 22:34:58 +03:00
|
|
|
$(if $(ANDROID_APK_PACKAGE),,$(error Missing ANDROID_APK_PACKAGE with ANDROID_APK_NAME))
|
|
|
|
|
2015-08-10 23:18:32 +03:00
|
|
|
android_res_dirs := $(or $(ANDROID_RES_DIRS),$(srcdir)/res)
|
2013-12-12 09:20:07 +04:00
|
|
|
_ANDROID_RES_FLAG := $(addprefix -S ,$(android_res_dirs))
|
2015-08-12 21:04:03 +03:00
|
|
|
_ANDROID_ASSETS_FLAG := $(if $(ANDROID_ASSETS_DIRS),$(addprefix -A ,$(ANDROID_ASSETS_DIRS)))
|
2014-02-25 11:18:47 +04:00
|
|
|
android_manifest := $(or $(ANDROID_MANIFEST_FILE),AndroidManifest.xml)
|
2013-10-01 23:43:30 +04:00
|
|
|
|
2015-08-19 22:34:58 +03:00
|
|
|
GENERATED_DIRS += classes generated
|
|
|
|
|
|
|
|
generated_r_java := generated/$(subst .,/,$(ANDROID_APK_PACKAGE))/R.java
|
2013-10-01 23:43:30 +04:00
|
|
|
|
|
|
|
classes.dex: $(call mkdir_deps,classes)
|
2015-08-19 22:34:58 +03:00
|
|
|
classes.dex: $(generated_r_java)
|
2013-10-01 23:43:30 +04:00
|
|
|
classes.dex: $(ANDROID_APK_NAME).ap_
|
2015-08-31 23:35:05 +03:00
|
|
|
classes.dex: $(default_classpath_jars) $(ANDROID_CLASSPATH_JARS)
|
|
|
|
classes.dex: $(default_bootclasspath_jars) $(ANDROID_BOOTCLASSPATH_JARS) $(ANDROID_EXTRA_JARS)
|
2013-10-01 23:43:30 +04:00
|
|
|
classes.dex: $(JAVAFILES)
|
2014-02-25 06:24:45 +04:00
|
|
|
$(JAVAC) $(JAVAC_FLAGS) -d classes $(filter %.java,$^) \
|
2015-08-31 23:35:05 +03:00
|
|
|
$(addprefix -bootclasspath ,$(call classpath_template,$(default_bootclasspath_jars) $(ANDROID_BOOTCLASSPATH_JARS))) \
|
|
|
|
$(addprefix -classpath ,$(call classpath_template,$(default_classpath_jars) $(ANDROID_CLASSPATH_JARS) $(ANDROID_EXTRA_JARS)))
|
2013-10-01 23:43:30 +04:00
|
|
|
$(DX) --dex --output=$@ classes $(ANDROID_EXTRA_JARS)
|
|
|
|
|
|
|
|
# R.java and $(ANDROID_APK_NAME).ap_ are both produced by aapt. To
|
Bug 979388 - Make aapt invocation rebuild R.java. r=glandium
This commit adds an empty recipe to dependencies of .aapt.deps, which
forces the appropriate gecko-R.jar rebuild. This is because Make treats
targets with no recipe at all differently than targets with an empty
recipe, in a way that defeats our dependencies.
What appeared to be happening is the following:
Touch a resource. On the next build, .aapt.deps is stale, so aapt is
invoked, which generates R.java, and we touch .aapt.deps.
Now R.java depends on .aapt.deps, but this does not appear to force Make
to consider targets that depend on R.java to be stale. A target that
depends on R.java (such as gecko-R.jar) itself compares timestamps and
finds that gecko-R.jar is newer than R.java (from the previous build),
and this comparison appears to happen before aapt is invoked. So even
though .aapt.deps is seen to be stale, and by transitivity R.java is
stale, this does not mark gecko-R.jar as stale. The timestamp check
between R.java and gecko-R.jar appears to happen *before* aapt is
invoked.
On the second build following the update, the R.java generated in the
previous build is newer than gecko-R.jar, triggering the observed
rebuild of gecko-R.jar.
2014-03-13 04:22:27 +04:00
|
|
|
# save an aapt invocation, we produce them both at the same time. The
|
|
|
|
# trailing semi-colon defines an empty recipe; defining no recipe at
|
|
|
|
# all causes Make to treat the target differently, in a way that
|
|
|
|
# defeats our dependencies.
|
2013-10-01 23:43:30 +04:00
|
|
|
|
2015-08-19 22:34:58 +03:00
|
|
|
$(generated_r_java): .aapt.deps ;
|
Bug 979388 - Make aapt invocation rebuild R.java. r=glandium
This commit adds an empty recipe to dependencies of .aapt.deps, which
forces the appropriate gecko-R.jar rebuild. This is because Make treats
targets with no recipe at all differently than targets with an empty
recipe, in a way that defeats our dependencies.
What appeared to be happening is the following:
Touch a resource. On the next build, .aapt.deps is stale, so aapt is
invoked, which generates R.java, and we touch .aapt.deps.
Now R.java depends on .aapt.deps, but this does not appear to force Make
to consider targets that depend on R.java to be stale. A target that
depends on R.java (such as gecko-R.jar) itself compares timestamps and
finds that gecko-R.jar is newer than R.java (from the previous build),
and this comparison appears to happen before aapt is invoked. So even
though .aapt.deps is seen to be stale, and by transitivity R.java is
stale, this does not mark gecko-R.jar as stale. The timestamp check
between R.java and gecko-R.jar appears to happen *before* aapt is
invoked.
On the second build following the update, the R.java generated in the
previous build is newer than gecko-R.jar, triggering the observed
rebuild of gecko-R.jar.
2014-03-13 04:22:27 +04:00
|
|
|
$(ANDROID_APK_NAME).ap_: .aapt.deps ;
|
2013-10-01 23:43:30 +04:00
|
|
|
|
2013-12-12 09:20:07 +04:00
|
|
|
# This uses the fact that Android resource directories list all
|
|
|
|
# resource files one subdirectory below the parent resource directory.
|
|
|
|
android_res_files := $(wildcard $(addsuffix /*,$(wildcard $(addsuffix /*,$(android_res_dirs)))))
|
|
|
|
|
2015-08-15 04:13:11 +03:00
|
|
|
# An extra package like org.example.app generates dependencies like:
|
|
|
|
# generated/org/example/app/R.java: .aapt.deps ;
|
|
|
|
# classes.dex: generated/org/example/app/R.java
|
|
|
|
# GARBAGE: generated/org/example/app/R.java
|
|
|
|
$(foreach extra_package,$(ANDROID_EXTRA_PACKAGES), \
|
|
|
|
$(eval generated/$(subst .,/,$(extra_package))/R.java: .aapt.deps ;) \
|
|
|
|
$(eval classes.dex: generated/$(subst .,/,$(extra_package))/R.java) \
|
|
|
|
$(eval GARBAGE: generated/$(subst .,/,$(extra_package))/R.java) \
|
|
|
|
)
|
|
|
|
|
|
|
|
# aapt flag -m: 'make package directories under location specified by -J'.
|
|
|
|
# The --extra-package list is colon separated.
|
2015-08-12 21:04:03 +03:00
|
|
|
.aapt.deps: $(android_manifest) $(android_res_files) $(wildcard $(ANDROID_ASSETS_DIRS))
|
Bug 979388 - Make aapt invocation rebuild R.java. r=glandium
This commit adds an empty recipe to dependencies of .aapt.deps, which
forces the appropriate gecko-R.jar rebuild. This is because Make treats
targets with no recipe at all differently than targets with an empty
recipe, in a way that defeats our dependencies.
What appeared to be happening is the following:
Touch a resource. On the next build, .aapt.deps is stale, so aapt is
invoked, which generates R.java, and we touch .aapt.deps.
Now R.java depends on .aapt.deps, but this does not appear to force Make
to consider targets that depend on R.java to be stale. A target that
depends on R.java (such as gecko-R.jar) itself compares timestamps and
finds that gecko-R.jar is newer than R.java (from the previous build),
and this comparison appears to happen before aapt is invoked. So even
though .aapt.deps is seen to be stale, and by transitivity R.java is
stale, this does not mark gecko-R.jar as stale. The timestamp check
between R.java and gecko-R.jar appears to happen *before* aapt is
invoked.
On the second build following the update, the R.java generated in the
previous build is newer than gecko-R.jar, triggering the observed
rebuild of gecko-R.jar.
2014-03-13 04:22:27 +04:00
|
|
|
@$(TOUCH) $@
|
2013-10-01 23:43:30 +04:00
|
|
|
$(AAPT) package -f -M $< -I $(ANDROID_SDK)/android.jar $(_ANDROID_RES_FLAG) $(_ANDROID_ASSETS_FLAG) \
|
2015-08-19 22:34:58 +03:00
|
|
|
--custom-package $(ANDROID_APK_PACKAGE) \
|
|
|
|
--non-constant-id \
|
|
|
|
--auto-add-overlay \
|
2015-08-15 04:13:11 +03:00
|
|
|
$(if $(ANDROID_EXTRA_PACKAGES),--extra-packages $(subst $(NULL) ,:,$(strip $(ANDROID_EXTRA_PACKAGES)))) \
|
|
|
|
$(if $(ANDROID_EXTRA_RES_DIRS),$(addprefix -S ,$(ANDROID_EXTRA_RES_DIRS))) \
|
2015-08-19 22:34:58 +03:00
|
|
|
-m \
|
|
|
|
-J ${@D}/generated \
|
2013-10-01 23:43:30 +04:00
|
|
|
-F $(ANDROID_APK_NAME).ap_
|
|
|
|
|
|
|
|
$(ANDROID_APK_NAME)-unsigned-unaligned.apk: $(ANDROID_APK_NAME).ap_ classes.dex
|
|
|
|
cp $< $@
|
|
|
|
$(ZIP) -0 $@ classes.dex
|
|
|
|
|
|
|
|
$(ANDROID_APK_NAME)-unaligned.apk: $(ANDROID_APK_NAME)-unsigned-unaligned.apk
|
|
|
|
cp $< $@
|
|
|
|
$(DEBUG_JARSIGNER) $@
|
|
|
|
|
|
|
|
$(ANDROID_APK_NAME).apk: $(ANDROID_APK_NAME)-unaligned.apk
|
2015-08-19 22:34:58 +03:00
|
|
|
$(ZIPALIGN) -f 4 $< $@
|
2013-10-01 23:43:30 +04:00
|
|
|
|
|
|
|
GARBAGE += \
|
2015-08-19 22:34:58 +03:00
|
|
|
$(generated_r_java) \
|
2013-10-01 23:43:30 +04:00
|
|
|
classes.dex \
|
|
|
|
$(ANDROID_APK_NAME).ap_ \
|
|
|
|
$(ANDROID_APK_NAME)-unsigned-unaligned.apk \
|
|
|
|
$(ANDROID_APK_NAME)-unaligned.apk \
|
|
|
|
$(ANDROID_APK_NAME).apk \
|
|
|
|
$(NULL)
|
|
|
|
|
|
|
|
# Include Android specific java flags, instead of what's in rules.mk.
|
|
|
|
include $(topsrcdir)/config/android-common.mk
|
|
|
|
endif #} ANDROID_APK_NAME
|
2013-01-26 00:22:13 +04:00
|
|
|
|
2013-10-10 04:05:36 +04:00
|
|
|
|
|
|
|
ifdef JAVA_JAR_TARGETS #{
|
|
|
|
# Arg 1: Output target name with .jar suffix, like jars/jarfile.jar.
|
|
|
|
# Intermediate class files are generated in jars/jarfile-classes.
|
|
|
|
# Arg 2: Java sources list. We use VPATH and $^ so sources can be
|
|
|
|
# relative to $(srcdir) or $(CURDIR).
|
|
|
|
# Arg 3: List of extra jars to link against. We do not use VPATH so
|
|
|
|
# jars must be relative to $(CURDIR).
|
|
|
|
# Arg 4: Additional JAVAC_FLAGS.
|
2014-02-11 21:55:47 +04:00
|
|
|
|
|
|
|
# Note: Proguard fails when stale .class files corresponding to
|
|
|
|
# removed inner classes are present in the object directory. These
|
|
|
|
# stale class files get packaged into the .jar file, which then gets
|
|
|
|
# processed by Proguard. To work around this, we always delete any
|
|
|
|
# existing jarfile-classes directory and start fresh.
|
|
|
|
|
2013-10-10 04:05:36 +04:00
|
|
|
define java_jar_template
|
2015-08-31 23:35:05 +03:00
|
|
|
$(1): $(2) $(3) $(default_bootclasspath_jars) $(default_classpath_jars)
|
2013-10-10 04:05:36 +04:00
|
|
|
$$(REPORT_BUILD)
|
2014-02-11 21:55:47 +04:00
|
|
|
@$$(RM) -rf $(1:.jar=)-classes
|
2013-10-10 04:05:36 +04:00
|
|
|
@$$(NSINSTALL) -D $(1:.jar=)-classes
|
2013-10-10 04:14:20 +04:00
|
|
|
@$$(if $$(filter-out .,$$(@D)),$$(NSINSTALL) -D $$(@D))
|
2013-10-10 04:05:36 +04:00
|
|
|
$$(JAVAC) $$(JAVAC_FLAGS)\
|
2015-08-31 23:35:05 +03:00
|
|
|
$(4)\
|
2013-10-10 04:05:36 +04:00
|
|
|
-d $(1:.jar=)-classes\
|
2015-08-31 23:35:05 +03:00
|
|
|
$(addprefix -bootclasspath ,$(call classpath_template,$(default_bootclasspath_jars)))\
|
|
|
|
$(addprefix -classpath ,$(call classpath_template,$(default_classpath_jars) $(3)))\
|
2013-10-10 04:05:36 +04:00
|
|
|
$$(filter %.java,$$^)
|
|
|
|
$$(JAR) cMf $$@ -C $(1:.jar=)-classes .
|
|
|
|
|
|
|
|
GARBAGE += $(1)
|
|
|
|
|
|
|
|
GARBAGE_DIRS += $(1:.jar=)-classes
|
|
|
|
endef
|
|
|
|
|
|
|
|
$(foreach jar,$(JAVA_JAR_TARGETS),\
|
|
|
|
$(if $($(jar)_DEST),,$(error Missing $(jar)_DEST))\
|
2014-03-05 20:57:09 +04:00
|
|
|
$(if $($(jar)_JAVAFILES) $($(jar)_PP_JAVAFILES),,$(error Must provide at least one of $(jar)_JAVAFILES and $(jar)_PP_JAVAFILES))\
|
2014-02-11 18:35:12 +04:00
|
|
|
$(eval $(call java_jar_template,$($(jar)_DEST),$($(jar)_JAVAFILES) $($(jar)_PP_JAVAFILES),$($(jar)_EXTRA_JARS),$($(jar)_JAVAC_FLAGS)))\
|
2013-10-10 04:05:36 +04:00
|
|
|
)
|
|
|
|
endif #} JAVA_JAR_TARGETS
|
|
|
|
|
|
|
|
|
2013-01-26 00:22:13 +04:00
|
|
|
INCLUDED_JAVA_BUILD_MK := 1
|
|
|
|
|
|
|
|
endif #} INCLUDED_JAVA_BUILD_MK
|