--- a/common/makefiles/JavaCompilation.gmk Wed Jul 05 18:12:32 2017 +0200
+++ b/common/makefiles/JavaCompilation.gmk Thu Jun 07 20:25:06 2012 -0700
@@ -126,8 +126,7 @@
# JAR:=Jar file to create
# MANIFEST:=Optional manifest file template.
# JARMAIN:=Optional main class to add to manifest
- # SETUP:=The Java(h) compiler setup, needed to run javah.
- # HEADERS:=Directory to put headers in
+ # JARINDEX :=
# SKIP_METAINF:=Set to prevent contents of an META-INF directory to be automatically
# added to the archive.
# EXTRA_MANIFEST_ATTR:=Extra attribute to add to manifest.
@@ -143,9 +142,8 @@
$(if $(12),$1_$(strip $(12)))
$(if $(13),$1_$(strip $(13)))
$(if $(14),$1_$(strip $(14)))
+ $(if $(15),$1_$(strip $(15)))
- $1_JVM := $$($$($1_SETUP)_JVM)
- $1_JAVAH := $$($$($1_SETUP)_JAVAH)
$1_JARMAIN:=$(strip $$($1_JARMAIN))
$1_JARNAME:=$$(notdir $$($1_JAR))
$1_MANIFEST_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_manifest
@@ -155,19 +153,46 @@
$1_NATIVEAPI_NOTIFICATIONS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_native_notifications
$1_NATIVEAPI_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_native
$1_BIN:=$$(dir $$($1_JAR))
+
ifeq (,$$($1_SUFFIXES))
# No suffix was set, default to classes.
$1_SUFFIXES:=.class
endif
# Convert suffixes to a find expression
$1_FIND_PATTERNS:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES))
+ # On windows, a lot of includes/excludes risk making the command line too long, so
+ # writing the grep patterns to files.
ifneq (,$$($1_INCLUDES))
- $1_GREP_INCLUDES:=| $(GREP) $$(foreach src,$$($1_SRCS),$$(addprefix -e$(SPACE)$$(src)/,$$($1_INCLUDES)))
+ $1_GREP_INCLUDE_PATTERNS:=$$(foreach src,$$($1_SRCS),\
+ $$(addprefix $$(src)/,$$($1_INCLUDES)))
+ $$(eval $$(call ListPathsSafelyNow,$1_GREP_INCLUDE_PATTERNS,\n, \
+ >> $$($1_BIN)/_the.$$($1_JARNAME)_include))
+ $1_GREP_INCLUDES:=| $(GREP) -f $$($1_BIN)/_the.$$($1_JARNAME)_include
endif
ifneq (,$$($1_EXCLUDES)$$($1_EXCLUDE_FILES))
- $1_GREP_EXCLUDES:=| $(GREP) -v $$(foreach src,$$($1_SRCS),$$(addprefix -e$(SPACE)$$(src)/,$$($1_EXCLUDES) $$($1_EXCLUDE_FILES)))
+ $1_GREP_EXCLUDE_PATTERNS:=$$(foreach src,$$($1_SRCS),$$(addprefix $$(src)/,\
+ $$($1_EXCLUDES) $$($1_EXCLUDE_FILES)))
+ $$(eval $$(call ListPathsSafelyNow,$1_GREP_EXCLUDE_PATTERNS,\n, \
+ >> $$($1_BIN)/_the.$$($1_JARNAME)_exclude))
+ $1_GREP_EXCLUDES:=| $(GREP) -v -f $$($1_BIN)/_the.$$($1_JARNAME)_exclude
endif
+ ifneq (,$$($1_JARINDEX))
+ $1_JARINDEX = (cd $$(dir $$@) && $(JAR) -i $$(notdir $$@))
+ else
+ $1_JARINDEX = true
+ endif
+ # When this macro is run in the same makefile as the java compilation, dependencies are transfered
+ # in make variables. When the macro is run in a different makefile than the java compilation, the
+ # dependencies need to be found in the filesystem.
+ $1_ALL_SRCS:=$$(foreach src,$$($1_SRCS),$$(shell ($(FIND) $$(src) -type f \
+ -a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) \
+ $$($1_GREP_EXCLUDES) && $(ECHO) $$($1_EXTRA_FILES))))
+ ifeq (,$$($1_SKIP_METAINF))
+ $1_ALL_SRCS+=$$(foreach src,$$($1_SRCS),$$(shell $(FIND) $$(src)/META-INF -type f 2> /dev/null))
+ endif
+
+
# Utility macros, to make the shell script receipt somewhat easier to dechipher.
# The capture contents macro finds all files (matching the patterns, typically
@@ -187,15 +212,6 @@
(cd $$(src) && \
$(FIND) . -name _the.package.api.notify -exec dirname \{\} \; >> $$($1_PUBAPI_NOTIFICATIONS_FILE) ; \
true) &&)
- # The capture nativeapi macro scans for native api change notificiations. If such notifications are
- # found, then we will run javah on the changed classes. It also collects all classes with native methods
- # to be used to find out which classes no longer has native methods, to trigger deletion of those .h files.
- $1_CAPTURE_NATIVEAPI=$$(foreach src,$$($1_SRCS),\
- (cd $$(src) && \
- $(FIND) . -name _the.package.native.notify | $(SED) 's/package.native.notify/package.native/' | \
- $(XARGS) $(CAT) | $(GREP) '^TYPE ' | $(SED) 's/.*TYPE //' >> $$($1_NATIVEAPI_NOTIFICATIONS_FILE) ; \
- $(FIND) . -name _the.package.native -exec $(CAT) \{\} \; | $(SED) -n 's/^TYPE //p' >> $$($1_NATIVEAPI_FILE) ; \
- true) &&)
# The update contents macro updates the jar file with the previously capture contents.
$1_UPDATE_CONTENTS=$$(foreach src,$$($1_SRCS),\
(cd $$(src) && \
@@ -205,13 +221,18 @@
fi) &&)
# The s-variants of the above macros are used when the jar is created from scratch.
$1_SCAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS),\
- (($(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) $$($1_GREP_EXCLUDES) && $(ECHO) $$($1_EXTRA_FILES)) | $(SED) 's|$$(src)/||g' > $$(src)/_the.$$($1_JARNAME)_contents) && )
+ (($(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) \
+ $$($1_GREP_EXCLUDES) && $(ECHO) $$($1_EXTRA_FILES)) | $(SED) 's|$$(src)/||g' > \
+ $$(src)/_the.$$($1_JARNAME)_contents) && )
+
ifeq (,$$($1_SKIP_METAINF))
$1_SCAPTURE_METAINF=$$(foreach src,$$($1_SRCS),\
- ($(FIND) $$(src)/META-INF -type f 2> /dev/null | $(SED) 's|$$(src)/||g' >> $$(src)/_the.$$($1_JARNAME)_contents) && )
+ ($(FIND) $$(src)/META-INF -type f 2> /dev/null | $(SED) 's|$$(src)/||g' >> \
+ $$(src)/_the.$$($1_JARNAME)_contents) && )
endif
$1_SUPDATE_CONTENTS=$$(foreach src,$$($1_SRCS),\
(cd $$(src) && $(JAR) uf $$@ @$$(src)/_the.$$($1_JARNAME)_contents) &&)
+
# The TOUCH macro is used to make sure all timestamps are identical for package files and the pubapi files.
# If we do not do this, we get random recompilations, the next time we run make, since the order of package building is random,
# ie independent of package --dependes on-> public api of another package. This is of course
@@ -223,7 +244,7 @@
# Use a slightly shorter name for logging, but with enough path to identify this jar.
$1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_JAR))
# Here is the rule that creates/updates the jar file.
- $$($1_JAR) : $2
+ $$($1_JAR) : $2 $$($1_ALL_SRC)
$(MKDIR) -p $$($1_BIN)
if [ -n "$$($1_MANIFEST)" ]; then \
$(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \
@@ -231,9 +252,11 @@
else \
$(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE); \
fi
- $(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE)
+ if [ -n "$$(strip $$($1_JARMAIN))" ]; then \
+ $(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE); \
+ fi
if [ -n "$$($1_EXTRA_MANIFEST_ATTR)" ]; then \
- $(ECHO) "$$($1_EXTRA_MANIFEST_ATTR)" >> $$($1_MANIFEST_FILE); \
+ $(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE); \
fi
+if [ -s $$@ ]; then \
$(RM) -r $$($1_PUBAPI_NOTIFICATIONS_FILE) && \
@@ -255,20 +278,8 @@
$(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \
fi && \
$$($1_UPDATE_CONTENTS) true && \
+ $$($1_JARINDEX) && \
$$($1_TOUCH_API_FILES) true && \
- $(RM) -r $$($1_NATIVEAPI_NOTIFICATIONS_FILE) $$($1_NATIVEAPI_FILE) && \
- $$($1_CAPTURE_NATIVEAPI) true && \
- if [ "x$$($1_JAVAH)" != "x" ] && [ -s $$($1_NATIVEAPI_NOTIFICATIONS_FILE) ]; then \
- $(ECHO) Native api change detected in: && $(CAT) $$($1_NATIVEAPI_NOTIFICATIONS_FILE) && \
- $$($1_JVM) $$($1_JAVAH) "-Xbootclasspath/p:$$($1_JAR)" -d $$($1_HEADERS) @$$($1_NATIVEAPI_NOTIFICATIONS_FILE) ; \
- fi && \
- $(TOUCH) $$($1_NATIVEAPI_FILE)_prev ; \
- ($(GREP) -xvf $$($1_NATIVEAPI_FILE) $$($1_NATIVEAPI_FILE)_prev > $$($1_NATIVEAPI_FILE)_deleted; true) && \
- $(CP) $$($1_NATIVEAPI_FILE) $$($1_NATIVEAPI_FILE)_prev && \
- if [ -s $$($1_NATIVEAPI_FILE)_deleted ]; then \
- $(ECHO) Native methods dropped from classes: && $(CAT) $$($1_NATIVEAPI_FILE)_deleted && \
- $(RM) `$(CAT) $$($1_NATIVEAPI_FILE)_deleted | $(SED) -e 's|\.|_|g' -e 's|.*|$$($1_HEADERS)/&.h $$($1_HEADERS)/&_*|'` ; \
- fi && \
$$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.api.notify $(FIND_DELETE); true) &&) true ; \
fi ; \
else \
@@ -276,15 +287,9 @@
$$($1_SCAPTURE_CONTENTS) \
$$($1_SCAPTURE_METAINF) \
$$($1_SUPDATE_CONTENTS) \
+ $$($1_JARINDEX) && \
$$($1_TOUCH_API_FILES) true && \
$(RM) -r $$($1_NATIVEAPI_NOTIFICATIONS_FILE) $$($1_NATIVEAPI_FILE) && \
- $$($1_CAPTURE_NATIVEAPI) true && \
- if [ "x$$($1_JAVAH)" != "x" ] && [ -s $$($1_NATIVEAPI_FILE) ]; then \
- $(ECHO) Generating native api headers for `$(CAT) $$($1_NATIVEAPI_FILE) | $(WC) -l` classes && \
- $(RM) $$($1_HEADERS)/*.h && \
- $$($1_JVM) $$($1_JAVAH) "-Xbootclasspath/p:$$($1_JAR)" -d $$($1_HEADERS) @$$($1_NATIVEAPI_FILE) && \
- $(CP) $$($1_NATIVEAPI_FILE) $$($1_NATIVEAPI_FILE)_prev ; \
- fi && \
$$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name "*.notify" $(FIND_DELETE); true) &&) true ; \
fi;
@@ -297,7 +302,7 @@
define SetupZipArchive
# param 1 is for example ZIP_MYSOURCE
# param 2,3,4,5,6,7,8,9 are named args.
- # SRC,ZIP,INCLUDES,EXCLUDES,EXCLUDE_FILES
+ # SRC,ZIP,INCLUDES,EXCLUDES,EXCLUDE_FILES,SUFFIXES,EXTRA_DEPS
$(if $2,$1_$(strip $2))
$(if $3,$1_$(strip $3))
$(if $4,$1_$(strip $4))
@@ -308,11 +313,17 @@
$(if $9,$1_$(strip $9))
# Find all files in the source tree.
- $1_ALL_SRCS := $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i -type f -a ! -name "_the.*"))
+ $1_SUFFIX_FILTER := $$(patsubst %,-o -name $(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES))
+ $1_ALL_SRCS := $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i -type f -a ! -name "_the.*" \( -name FALSE_DUMMY $$($1_SUFFIX_FILTER) \) ))
ifneq ($$($1_INCLUDES),)
$1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES))))
- $1_ZIP_INCLUDES := $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_INCLUDES)))
+ ifneq ($$($1_SUFFIXES),)
+ $1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES),\
+ $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$$s$(DQUOTE),$$($1_INCLUDES))))
+ else
+ $1_ZIP_INCLUDES := $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_INCLUDES)))
+ endif
$1_ALL_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_SRCS))
endif
ifneq ($$($1_EXCLUDES),)
@@ -329,7 +340,7 @@
# Explicitly excluded files can be given with absolute path. The patsubst solution
# isn't perfect but the likelyhood of an absolute path to match something in a src
# dir is very small.
- $$($1_ZIP) : $$($1_ALL_SRCS)
+ $$($1_ZIP) : $$($1_ALL_SRCS) $$($1_EXTRA_DEPS)
$(MKDIR) -p $$(@D)
$(ECHO) Updating $$($1_NAME)
$$(foreach i,$$($1_SRC),(cd $$i && $(ZIP) -qru $$@ . $$($1_ZIP_INCLUDES) $$($1_ZIP_EXCLUDES) -x \*_the.\* $$(addprefix -x$(SPACE),$$(patsubst $$i/%,%,$$($1_EXCLUDE_FILES)))) ;) true
@@ -472,7 +483,7 @@
| $(SED) -e '/^#/d' -e '/^$$$$/d' \
-e :a -e '/\\$$$$/N; s/\\\n//; ta' \
-e 's/^[ \t]*//;s/[ \t]*$$$$//' \
- -e 's/\\=/=/' | LANG=C sort > $$@
+ -e 's/\\=/=/' | LANG=C $(SORT) > $$@
$(CHMOD) -f ug+w $$@
# And do not forget this target
@@ -623,6 +634,7 @@
# JAVAC_SOURCE_PATH_UGLY_OVERRIDE:=Don't use this. This forces an explicit -sourcepath to javac.
# Its only here until we cleanup some nasty source code pasta in the jdk.
# HEADERS:=path to directory where all generated c-headers are written.
+ # DEPENDS:=Extra dependecy
$(if $2,$1_$(strip $2))
$(if $3,$1_$(strip $3))
$(if $4,$1_$(strip $4))
@@ -650,9 +662,6 @@
$1_JAVAC := $$($$($1_SETUP)_JAVAC)
$1_JAVAH := $$($$($1_SETUP)_JAVAH)
$1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS)
-ifeq (,$$($1_HEADERS))
- $1_HEADERS := $$($1_BIN)
-endif
# Handle addons and overrides.
$1_SRC:=$$(call ADD_SRCS,$$($1_SRC))
@@ -776,24 +785,21 @@
$$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_SRC)))
endif
+ ifneq (,$$($1_HEADERS))
+ $1_HEADERS_ARG := -h $$($1_HEADERS)
+ endif
+
# Create a sed expression to remove the source roots and to replace / with .
# and remove .java at the end.
$1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g'
# Here is the batch rules that depends on all the sources.
- $$($1_BIN)/_the.batch: $$($1_SRCS)
+ $$($1_BIN)/_the.batch: $$($1_SRCS) $$($1_DEPENDS)
$(MKDIR) -p $$(@D)
$(RM) $$($1_BIN)/_the.batch $$($1_BIN)/_the.batch.tmp
$$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.batch.tmp)
$(ECHO) Compiling `$(WC) $$($1_BIN)/_the.batch.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files in batch $1
- ($$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) -implicit:none -sourcepath "$$($1_SRCROOTSC)" -d $$($1_BIN) @$$($1_BIN)/_the.batch.tmp && \
- $$(if $$($1_JAVAH),\
- $(CAT) $$($1_BIN)/_the.batch.tmp | $(XARGS) $(GREP) -E "[[:space:]]native[[:space:]]|@GenerateNativeHeader" |\
- $(GREP) -v '*' | $(GREP) -v '//' | $(CUT) -f 1 -d ':' | $(SORT) -u |\
- $(SED) $$($1_REWRITE_INTO_CLASSES) > $$($1_BIN)/_the.batch.natives && \
- if test -s $$($1_BIN)/_the.batch.natives; then \
- $$($1_JVM) $$($1_JAVAH) "-Xbootclasspath/p:$$($1_BIN)" -d $$($1_HEADERS) @$$($1_BIN)/_the.batch.natives ; \
- fi &&) \
+ ($$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) -implicit:none -sourcepath "$$($1_SRCROOTSC)" -d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_BIN)/_the.batch.tmp && \
$(MV) $$($1_BIN)/_the.batch.tmp $$($1_BIN)/_the.batch)
else
# Ok, we have a modern javac server running!
@@ -868,6 +874,7 @@
JARMAIN:=$$($1_JARMAIN),\
MANIFEST:=$$($1_MANIFEST),\
EXTRA_MANIFEST_ATTR:=$$($1_EXTRA_MANIFEST_ATTR),\
+ JARINDEX:=$$($1_JARINDEX),\
HEADERS:=$$($1_HEADERS),\
SETUP:=$$($1_SETUP)))
endif