2012-04-10 15:18:28 +00:00
|
|
|
#
|
|
|
|
# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
|
|
|
|
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
#
|
|
|
|
# This code is free software; you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU General Public License version 2 only, as
|
|
|
|
# published by the Free Software Foundation. Oracle designates this
|
|
|
|
# particular file as subject to the "Classpath" exception as provided
|
|
|
|
# by Oracle in the LICENSE file that accompanied this code.
|
|
|
|
#
|
|
|
|
# This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
# version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
# accompanied this code).
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License version
|
|
|
|
# 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
# or visit www.oracle.com if you need additional information or have any
|
|
|
|
# questions.
|
|
|
|
#
|
|
|
|
|
2012-09-18 18:29:16 +00:00
|
|
|
# This makefile is much simpler now that it can use the smart javac wrapper
|
|
|
|
# for dependency tracking between java packages and incremental compiles.
|
|
|
|
# It could be even more simple if we added support for incremental jar updates
|
|
|
|
# directly from the smart javac wrapper.
|
|
|
|
|
|
|
|
# Cleaning/copying properties here is not a good solution. The properties
|
|
|
|
# should be cleaned/copied by a annotation processor in sjavac.
|
|
|
|
|
2012-04-10 15:18:28 +00:00
|
|
|
# When you read this source. Remember that $(sort ...) has the side effect
|
|
|
|
# of removing duplicates. It is actually this side effect that is
|
|
|
|
# desired whenever sort is used below!
|
|
|
|
|
|
|
|
ifeq (,$(_MAKEBASE_GMK))
|
|
|
|
$(error You must include MakeBase.gmk prior to including JavaCompilation.gmk)
|
|
|
|
endif
|
|
|
|
|
|
|
|
FALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST
|
|
|
|
|
|
|
|
define SetupJavaCompiler
|
|
|
|
# param 1 is for example BOOT_JAVAC or NEW_JAVAC
|
|
|
|
# This is the name later used to decide which java compiler to use.
|
|
|
|
# param 2-9 are named args.
|
|
|
|
# JVM:=The jvm used to run the javac/javah command
|
|
|
|
# JAVAC:=The javac jar and bootstrap classpath changes, or just bin/javac if JVM is left out
|
|
|
|
# FLAGS:=Flags to be supplied to javac
|
|
|
|
# SERVER_DIR:=Use a javac server (-XDserver) and store the server related files here
|
|
|
|
# SERVER_JVM:=Use this JVM for the server. Defaults to the JVM above.
|
|
|
|
$(if $2,$1_$(strip $2))
|
|
|
|
$(if $3,$1_$(strip $3))
|
|
|
|
$(if $4,$1_$(strip $4))
|
|
|
|
$(if $5,$1_$(strip $5))
|
|
|
|
$(if $6,$1_$(strip $6))
|
|
|
|
$(if $7,$1_$(strip $7))
|
|
|
|
$(if $8,$1_$(strip $8))
|
|
|
|
$(if $9,$1_$(strip $9))
|
2012-07-03 23:11:12 +00:00
|
|
|
$(if $(10),$(error Internal makefile error: Too many arguments to SetupJavaCompiler, please update JavaCompilation.gmk))
|
2012-04-10 15:18:28 +00:00
|
|
|
|
2012-09-18 18:29:16 +00:00
|
|
|
ifeq ($$(ENABLE_SJAVAC),yes)
|
|
|
|
# The port file contains the tcp/ip on which the server listens
|
|
|
|
# and the cookie necessary to talk to the server.
|
|
|
|
$1_JAVAC_PORTFILE:=$$($1_SERVER_DIR)/server.port
|
|
|
|
# You can use a different JVM to run the background javac server.
|
|
|
|
ifeq ($$($1_SERVER_JVM),)
|
|
|
|
# It defaults to the same JVM that is used to start the javac command.
|
|
|
|
$1_SERVER_JVM:=$$($1_JVM)
|
2012-04-10 15:18:28 +00:00
|
|
|
endif
|
2012-09-18 18:29:16 +00:00
|
|
|
# Set the $1_REMOTE to spawn a background javac server.
|
|
|
|
$1_REMOTE:=-XDserver:portfile=$$($1_JAVAC_PORTFILE),poolsize=$(SJAVAC_SERVER_CORES),id=$1,javac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_JAVAC))))
|
2012-04-10 15:18:28 +00:00
|
|
|
endif
|
|
|
|
endef
|
|
|
|
|
|
|
|
define SetupArchive
|
|
|
|
# param 1 is for example ARCHIVE_MYPACKAGE
|
|
|
|
# param 2 are the dependecies
|
|
|
|
# param 3,4,5,6,7,8,9 are named args.
|
|
|
|
# SRCS:=List of directories in where to find files to add to archive
|
|
|
|
# SUFFIXES:=File suffixes to include in jar
|
|
|
|
# INCLUDES:=List of directories/packages in SRCS that should be included
|
|
|
|
# EXCLUDES:=List of directories/packages in SRCS that should be excluded
|
|
|
|
# EXCLUDE_FILES:=List of files in SRCS that should be excluded
|
|
|
|
# EXTRA_FILES:=List of files in SRCS that should be included regardless of suffix match.
|
|
|
|
# JAR:=Jar file to create
|
|
|
|
# MANIFEST:=Optional manifest file template.
|
|
|
|
# JARMAIN:=Optional main class to add to manifest
|
2012-09-18 18:29:16 +00:00
|
|
|
# JARINDEX:=true means generate the index in the jar file.
|
2012-04-10 15:18:28 +00:00
|
|
|
# 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.
|
2012-07-03 23:11:12 +00:00
|
|
|
# CHECK_COMPRESS_JAR Check the COMPRESS_JAR variable
|
2012-04-10 15:18:28 +00:00
|
|
|
$(if $3,$1_$(strip $3))
|
|
|
|
$(if $4,$1_$(strip $4))
|
|
|
|
$(if $5,$1_$(strip $5))
|
|
|
|
$(if $6,$1_$(strip $6))
|
|
|
|
$(if $7,$1_$(strip $7))
|
|
|
|
$(if $8,$1_$(strip $8))
|
|
|
|
$(if $9,$1_$(strip $9))
|
|
|
|
$(if $(10),$1_$(strip $(10)))
|
|
|
|
$(if $(11),$1_$(strip $(11)))
|
|
|
|
$(if $(12),$1_$(strip $(12)))
|
|
|
|
$(if $(13),$1_$(strip $(13)))
|
|
|
|
$(if $(14),$1_$(strip $(14)))
|
2012-06-08 03:25:06 +00:00
|
|
|
$(if $(15),$1_$(strip $(15)))
|
2012-07-03 23:11:12 +00:00
|
|
|
$(if $(16),$(error Internal makefile error: Too many arguments to SetupArchive, please update JavaCompilation.gmk))
|
2012-04-10 15:18:28 +00:00
|
|
|
|
|
|
|
$1_JARMAIN:=$(strip $$($1_JARMAIN))
|
|
|
|
$1_JARNAME:=$$(notdir $$($1_JAR))
|
|
|
|
$1_MANIFEST_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_manifest
|
|
|
|
$1_DELETESS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletess
|
|
|
|
$1_DELETES_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletes
|
|
|
|
$1_BIN:=$$(dir $$($1_JAR))
|
2012-06-08 03:25:06 +00:00
|
|
|
|
2012-04-10 15:18:28 +00:00
|
|
|
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))
|
2012-06-08 03:25:06 +00:00
|
|
|
# On windows, a lot of includes/excludes risk making the command line too long, so
|
|
|
|
# writing the grep patterns to files.
|
2012-04-10 15:18:28 +00:00
|
|
|
ifneq (,$$($1_INCLUDES))
|
2012-06-08 03:25:06 +00:00
|
|
|
$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
|
2012-04-10 15:18:28 +00:00
|
|
|
endif
|
|
|
|
ifneq (,$$($1_EXCLUDES)$$($1_EXCLUDE_FILES))
|
2012-06-08 03:25:06 +00:00
|
|
|
$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
|
2012-04-10 15:18:28 +00:00
|
|
|
endif
|
|
|
|
|
2012-09-18 18:29:16 +00:00
|
|
|
# Check if this jar needs to have its index generated.
|
2012-06-08 03:25:06 +00:00
|
|
|
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.
|
2012-09-18 18:29:16 +00:00
|
|
|
ifneq (,$2)
|
|
|
|
$1_DEPS:=$2
|
|
|
|
else
|
|
|
|
$1_DEPS:=$$(foreach src,$$($1_SRCS),$$(shell ($(FIND) $$(src) -type f \
|
2012-06-08 03:25:06 +00:00
|
|
|
-a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) \
|
2012-09-18 18:29:16 +00:00
|
|
|
$$($1_GREP_EXCLUDES) && $(ECHO) $$(addprefix $$(src)/,$$($1_EXTRA_FILES)))))
|
|
|
|
ifeq (,$$($1_SKIP_METAINF))
|
|
|
|
$1_DEPS+=$$(foreach src,$$($1_SRCS),$$(shell $(FIND) $$(src)/META-INF -type f 2> /dev/null))
|
|
|
|
endif
|
2012-06-08 03:25:06 +00:00
|
|
|
endif
|
|
|
|
|
2012-04-10 15:18:28 +00:00
|
|
|
# Utility macros, to make the shell script receipt somewhat easier to dechipher.
|
|
|
|
|
|
|
|
# The capture contents macro finds all files (matching the patterns, typically
|
|
|
|
# .class and .prp) that are newer than the jar-file, ie the new content to be put into the jar.
|
|
|
|
$1_CAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS),(($(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) -a -newer $$@ $$($1_GREP_INCLUDES) $$($1_GREP_EXCLUDES) && $(ECHO) $$($1_EXTRA_FILES)) | $(SED) 's|$$(src)/||g' > $$(src)/_the.$$($1_JARNAME)_contents) && )
|
|
|
|
# The capture metainf macro finds all files below the META-INF directory that are newer than the jar-file.
|
|
|
|
ifeq (,$$($1_SKIP_METAINF))
|
|
|
|
$1_CAPTURE_METAINF =$$(foreach src,$$($1_SRCS),($(FIND) $$(src)/META-INF -type f -a -newer $$@ 2> /dev/null | $(SED) 's|$$(src)/||g' >> $$(src)/_the.$$($1_JARNAME)_contents ) && )
|
|
|
|
endif
|
|
|
|
# The capture deletes macro finds all deleted files and concatenates them. The resulting file
|
|
|
|
# tells us what to remove from the jar-file.
|
|
|
|
$1_CAPTURE_DELETES=$$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.deleted -newer $$@ -exec $(SED) 's|$$(src)||g' \{\} >> $$($1_DELETES_FILE) \;) &&)
|
|
|
|
# The update contents macro updates the jar file with the previously capture contents.
|
|
|
|
$1_UPDATE_CONTENTS=$$(foreach src,$$($1_SRCS),\
|
|
|
|
(cd $$(src) && \
|
|
|
|
if [ -s _the.$$($1_JARNAME)_contents ]; then \
|
|
|
|
$(ECHO) " updating" `$(WC) -l _the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'` files && \
|
2012-09-18 18:29:16 +00:00
|
|
|
$(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @_the.$$($1_JARNAME)_contents; \
|
2012-04-10 15:18:28 +00:00
|
|
|
fi) &&)
|
|
|
|
# The s-variants of the above macros are used when the jar is created from scratch.
|
|
|
|
$1_SCAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS),\
|
2012-06-08 03:25:06 +00:00
|
|
|
(($(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) && )
|
|
|
|
|
2012-04-10 15:18:28 +00:00
|
|
|
ifeq (,$$($1_SKIP_METAINF))
|
|
|
|
$1_SCAPTURE_METAINF=$$(foreach src,$$($1_SRCS),\
|
2012-06-08 03:25:06 +00:00
|
|
|
($(FIND) $$(src)/META-INF -type f 2> /dev/null | $(SED) 's|$$(src)/||g' >> \
|
|
|
|
$$(src)/_the.$$($1_JARNAME)_contents) && )
|
2012-04-10 15:18:28 +00:00
|
|
|
endif
|
|
|
|
$1_SUPDATE_CONTENTS=$$(foreach src,$$($1_SRCS),\
|
2012-09-18 18:29:16 +00:00
|
|
|
(cd $$(src) && $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$(src)/_the.$$($1_JARNAME)_contents) &&)
|
|
|
|
|
2012-04-10 15:18:28 +00:00
|
|
|
# Use a slightly shorter name for logging, but with enough path to identify this jar.
|
|
|
|
$1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_JAR))
|
2012-07-03 23:11:12 +00:00
|
|
|
|
|
|
|
ifneq (,$$($1_CHECK_COMPRESS_JAR))
|
|
|
|
$1_JAR_CREATE_OPTIONS := c0fm
|
2012-09-18 18:29:16 +00:00
|
|
|
$1_JAR_UPDATE_OPTIONS := u0f
|
2012-07-03 23:11:12 +00:00
|
|
|
ifeq ($(COMPRESS_JARS), true)
|
|
|
|
$1_JAR_CREATE_OPTIONS := cfm
|
2012-09-18 18:29:16 +00:00
|
|
|
$1_JAR_UPDATE_OPTIONS := uf
|
2012-07-03 23:11:12 +00:00
|
|
|
endif
|
|
|
|
else
|
|
|
|
$1_JAR_CREATE_OPTIONS := cfm
|
2012-09-18 18:29:16 +00:00
|
|
|
$1_JAR_UPDATE_OPTIONS := uf
|
2012-07-03 23:11:12 +00:00
|
|
|
endif
|
|
|
|
|
2012-04-10 15:18:28 +00:00
|
|
|
# Here is the rule that creates/updates the jar file.
|
2012-09-18 18:29:16 +00:00
|
|
|
$$($1_JAR) : $$($1_DEPS)
|
2012-04-10 15:18:28 +00:00
|
|
|
$(MKDIR) -p $$($1_BIN)
|
|
|
|
if [ -n "$$($1_MANIFEST)" ]; then \
|
|
|
|
$(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \
|
|
|
|
-e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE); \
|
|
|
|
else \
|
|
|
|
$(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE); \
|
|
|
|
fi
|
2012-06-08 03:25:06 +00:00
|
|
|
if [ -n "$$(strip $$($1_JARMAIN))" ]; then \
|
|
|
|
$(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE); \
|
|
|
|
fi
|
2012-04-10 15:18:28 +00:00
|
|
|
if [ -n "$$($1_EXTRA_MANIFEST_ATTR)" ]; then \
|
2012-06-08 03:25:06 +00:00
|
|
|
$(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE); \
|
2012-04-10 15:18:28 +00:00
|
|
|
fi
|
|
|
|
+if [ -s $$@ ]; then \
|
2012-09-18 18:29:16 +00:00
|
|
|
$(ECHO) Modifying $$($1_NAME) && \
|
|
|
|
$$($1_CAPTURE_CONTENTS) \
|
|
|
|
$$($1_CAPTURE_METAINF) \
|
|
|
|
$(RM) $$($1_DELETES_FILE) && \
|
|
|
|
$$($1_CAPTURE_DELETES) \
|
|
|
|
$(CAT) $$($1_DELETES_FILE) > $$($1_DELETESS_FILE) && \
|
|
|
|
if [ -s $$($1_DELETESS_FILE) ]; then \
|
|
|
|
$(ECHO) " deleting" `$(WC) -l $$($1_DELETESS_FILE) | $(AWK) '{ print $$$$1 }'` files && \
|
|
|
|
$(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \
|
|
|
|
fi && \
|
|
|
|
$$($1_UPDATE_CONTENTS) true && \
|
|
|
|
$$($1_JARINDEX) && true ; \
|
2012-04-10 15:18:28 +00:00
|
|
|
else \
|
2012-07-03 23:11:12 +00:00
|
|
|
$(ECHO) Creating $$($1_NAME) && $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) && \
|
2012-04-10 15:18:28 +00:00
|
|
|
$$($1_SCAPTURE_CONTENTS) \
|
|
|
|
$$($1_SCAPTURE_METAINF) \
|
|
|
|
$$($1_SUPDATE_CONTENTS) \
|
2012-09-18 18:29:16 +00:00
|
|
|
$$($1_JARINDEX) && true ; \
|
2012-04-10 15:18:28 +00:00
|
|
|
fi;
|
|
|
|
|
|
|
|
endef
|
|
|
|
|
|
|
|
define SetupZipArchive
|
|
|
|
# param 1 is for example ZIP_MYSOURCE
|
|
|
|
# param 2,3,4,5,6,7,8,9 are named args.
|
2012-06-08 03:25:06 +00:00
|
|
|
# SRC,ZIP,INCLUDES,EXCLUDES,EXCLUDE_FILES,SUFFIXES,EXTRA_DEPS
|
2012-04-10 15:18:28 +00:00
|
|
|
$(if $2,$1_$(strip $2))
|
|
|
|
$(if $3,$1_$(strip $3))
|
|
|
|
$(if $4,$1_$(strip $4))
|
|
|
|
$(if $5,$1_$(strip $5))
|
|
|
|
$(if $6,$1_$(strip $6))
|
|
|
|
$(if $7,$1_$(strip $7))
|
|
|
|
$(if $8,$1_$(strip $8))
|
|
|
|
$(if $9,$1_$(strip $9))
|
2012-07-03 23:11:12 +00:00
|
|
|
$(if $(10),$(error Internal makefile error: Too many arguments to SetupZipArchive, please update JavaCompilation.gmk))
|
2012-04-10 15:18:28 +00:00
|
|
|
|
|
|
|
# Find all files in the source tree.
|
2012-06-08 03:25:06 +00:00
|
|
|
$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) \) ))
|
2012-04-10 15:18:28 +00:00
|
|
|
|
|
|
|
ifneq ($$($1_INCLUDES),)
|
|
|
|
$1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES))))
|
2012-06-08 03:25:06 +00:00
|
|
|
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
|
2012-04-10 15:18:28 +00:00
|
|
|
$1_ALL_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_SRCS))
|
|
|
|
endif
|
|
|
|
ifneq ($$($1_EXCLUDES),)
|
|
|
|
$1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
|
|
|
|
$1_ZIP_EXCLUDES := $$(addprefix -x$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_EXCLUDES)))
|
2012-09-18 18:29:16 +00:00
|
|
|
$1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRC))
|
2012-04-10 15:18:28 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
# Use a slightly shorter name for logging, but with enough path to identify this zip.
|
|
|
|
$1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_ZIP))
|
|
|
|
|
|
|
|
# Now $1_ALL_SRCS should contain all sources that are going to be put into the zip.
|
|
|
|
# I.e. the zip -i and -x options should match the filtering done in the makefile.
|
|
|
|
# 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.
|
2012-06-08 03:25:06 +00:00
|
|
|
$$($1_ZIP) : $$($1_ALL_SRCS) $$($1_EXTRA_DEPS)
|
2012-04-10 15:18:28 +00:00
|
|
|
$(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
|
|
|
|
$(TOUCH) $$@
|
|
|
|
endef
|
|
|
|
|
|
|
|
define add_file_to_copy
|
|
|
|
# param 1 = BUILD_MYPACKAGE
|
|
|
|
# parma 2 = The source file to copy.
|
|
|
|
$2_TARGET:=$2
|
|
|
|
# Remove the source prefix.
|
|
|
|
$$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
|
|
|
|
# Now we can setup the depency that will trigger the copying.
|
|
|
|
$$($1_BIN)$$($2_TARGET) : $2
|
|
|
|
$(MKDIR) -p $$(@D)
|
|
|
|
$(CP) $$< $$@
|
|
|
|
$(CHMOD) -f ug+w $$@
|
|
|
|
|
|
|
|
# And do not forget this target
|
|
|
|
$1_ALL_COPY_TARGETS += $$($1_BIN)$$($2_TARGET)
|
|
|
|
endef
|
|
|
|
|
|
|
|
|
|
|
|
# This macro is used only for properties files that are to be
|
|
|
|
# copied over to the classes directory in cleaned form:
|
|
|
|
# Previously this was inconsistently done in different repositories.
|
2012-09-18 18:29:16 +00:00
|
|
|
# This is the new clean standard. Though it is to be superseded by
|
|
|
|
# a standard annotation processor from with sjavac.
|
2012-04-10 15:18:28 +00:00
|
|
|
define add_file_to_copy_and_clean
|
|
|
|
# param 1 = BUILD_MYPACKAGE
|
|
|
|
# parma 2 = The source file to copy and clean.
|
|
|
|
$2_TARGET:=$2
|
|
|
|
# Remove the source prefix.
|
|
|
|
$$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
|
|
|
|
# Now we can setup the depency that will trigger the copying.
|
|
|
|
$$($1_BIN)$$($2_TARGET) : $2
|
|
|
|
$(MKDIR) -p $$(@D)
|
|
|
|
$(CAT) $$< | $(SED) -e 's/\([^\\]\):/\1\\:/g' -e 's/\([^\\]\)=/\1\\=/g' -e 's/#.*/#/g' \
|
2012-09-18 18:29:16 +00:00
|
|
|
| $(SED) -f "$(SRC_ROOT)/common/bin/unicode2x.sed" \
|
2012-04-10 15:18:28 +00:00
|
|
|
| $(SED) -e '/^#/d' -e '/^$$$$/d' \
|
|
|
|
-e :a -e '/\\$$$$/N; s/\\\n//; ta' \
|
|
|
|
-e 's/^[ \t]*//;s/[ \t]*$$$$//' \
|
2012-06-08 03:25:06 +00:00
|
|
|
-e 's/\\=/=/' | LANG=C $(SORT) > $$@
|
2012-04-10 15:18:28 +00:00
|
|
|
$(CHMOD) -f ug+w $$@
|
|
|
|
|
|
|
|
# And do not forget this target
|
|
|
|
$1_ALL_COPY_CLEAN_TARGETS += $$($1_BIN)$$($2_TARGET)
|
|
|
|
endef
|
|
|
|
|
|
|
|
define remove_string
|
|
|
|
$2 := $$(subst $1,,$$($2))
|
|
|
|
endef
|
|
|
|
|
|
|
|
define replace_space_with_pathsep
|
|
|
|
$1:=$(subst $(SPACE),$(PATH_SEP),$(strip $(patsubst %,%,$2)))
|
|
|
|
endef
|
|
|
|
|
|
|
|
define SetupJavaCompilation
|
|
|
|
# param 1 is for example BUILD_MYPACKAGE
|
|
|
|
# param 2,3,4,5,6,7,8 are named args.
|
|
|
|
# SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC
|
|
|
|
# JVM:=path to ..bin/java
|
|
|
|
# ADD_JAVAC_FLAGS:=javac flags to append to the default ones.
|
|
|
|
# SRC:=one or more directories to search for sources
|
|
|
|
# BIN:=store classes here
|
|
|
|
# INCLUDES:=myapp.foo means will only compile java files in myapp.foo or any of its sub-packages.
|
|
|
|
# EXCLUDES:=myapp.foo means will do not compile java files in myapp.foo or any of its sub-packages.
|
|
|
|
# COPY:=.prp means copy all prp files to the corresponding package in BIN.
|
|
|
|
# CLEAN:=.properties means copy and clean all properties file to the corresponding package in BIN.
|
|
|
|
# COPY_FILES:=myapp/foo/setting.txt means copy this file over to the package myapp/foo
|
|
|
|
# SRCZIP:=Create a src.zip based on the found sources and copied files.
|
|
|
|
# INCLUDE_FILES:="com/sun/SolarisFoobar.java" means only compile this file!
|
|
|
|
# EXCLUDE_FILES:="com/sun/SolarisFoobar.java" means do not compile this particular file!
|
|
|
|
# "SolarisFoobar.java" means do not compile SolarisFoobar, wherever it is found.
|
|
|
|
# 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.
|
2012-06-08 03:25:06 +00:00
|
|
|
# DEPENDS:=Extra dependecy
|
2012-04-10 15:18:28 +00:00
|
|
|
$(if $2,$1_$(strip $2))
|
|
|
|
$(if $3,$1_$(strip $3))
|
|
|
|
$(if $4,$1_$(strip $4))
|
|
|
|
$(if $5,$1_$(strip $5))
|
|
|
|
$(if $6,$1_$(strip $6))
|
|
|
|
$(if $7,$1_$(strip $7))
|
|
|
|
$(if $8,$1_$(strip $8))
|
|
|
|
$(if $9,$1_$(strip $9))
|
|
|
|
$(if $(10),$1_$(strip $(10)))
|
|
|
|
$(if $(11),$1_$(strip $(11)))
|
|
|
|
$(if $(12),$1_$(strip $(12)))
|
|
|
|
$(if $(13),$1_$(strip $(13)))
|
|
|
|
$(if $(14),$1_$(strip $(14)))
|
2012-07-03 23:11:12 +00:00
|
|
|
$(if $(15),$(error Internal makefile error: Too many arguments to SetupJavaCompilation, please update JavaCompilation.gmk))
|
2012-04-10 15:18:28 +00:00
|
|
|
|
2012-09-18 18:29:16 +00:00
|
|
|
# Extract the info from the java compiler setup.
|
|
|
|
$1_REMOTE := $$($$($1_SETUP)_REMOTE)
|
|
|
|
$1_JVM := $$($$($1_SETUP)_JVM)
|
|
|
|
$1_JAVAC := $$($$($1_SETUP)_JAVAC)
|
|
|
|
$1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS)
|
|
|
|
ifeq ($$($1_JAVAC),)
|
2012-04-10 15:18:28 +00:00
|
|
|
$$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP))
|
|
|
|
endif
|
|
|
|
|
2012-09-18 18:29:16 +00:00
|
|
|
# Handle addons and overrides.
|
|
|
|
$1_SRC:=$$(call ADD_SRCS,$$($1_SRC))
|
|
|
|
# Make sure the dirs exist.
|
|
|
|
$$(shell $(MKDIR) -p $$($1_SRC) $$($1_BIN))
|
|
|
|
# Find all files in the source trees.
|
|
|
|
$1_ALL_SRCS := $$(filter-out $(OVR_SRCS),$$(foreach i,$$($1_SRC),$$(shell $(FIND) $$i -type f)))
|
|
|
|
# Extract the java files.
|
|
|
|
ifneq ($$($1_EXCLUDE_FILES),)
|
|
|
|
$1_EXCLUDE_FILES_PATTERN:=$$(addprefix %,$$($1_EXCLUDE_FILES))
|
2012-04-10 15:18:28 +00:00
|
|
|
endif
|
2012-09-18 18:29:16 +00:00
|
|
|
$1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$(filter %.java,$$($1_ALL_SRCS)))
|
|
|
|
ifneq ($$($1_INCLUDE_FILES),)
|
|
|
|
$1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES)))
|
|
|
|
$1_SRCS := $$(filter $$($1_INCLUDE_FILES), $$($1_SRCS))
|
2012-04-10 15:18:28 +00:00
|
|
|
endif
|
|
|
|
|
2012-09-18 18:29:16 +00:00
|
|
|
# Now we have a list of all java files to compile: $$($1_SRCS)
|
|
|
|
|
|
|
|
# Create the corresponding smart javac wrapper command line.
|
|
|
|
$1_SJAVAC_ARGS:=$$(addprefix -x ,$$(addsuffix .*,$$(subst /,.,$$($1_EXCLUDES)))) \
|
|
|
|
$$(addprefix -i ,$$(addsuffix .*,$$(subst /,.,$$($1_INCLUDES)))) \
|
|
|
|
$$(addprefix -xf *,$$(strip $$($1_EXCLUDE_FILES))) \
|
|
|
|
$$(addprefix -if *,$$(strip $$($1_INCLUDE_FILES))) \
|
|
|
|
-src "$$(subst $$(SPACE),$$(PATH_SEP),$$(strip $$($1_SRC)))"
|
|
|
|
|
|
|
|
# Prepend the source/bin path to the filter expressions.
|
|
|
|
ifneq ($$($1_INCLUDES),)
|
|
|
|
$1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES))))
|
|
|
|
$1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS))
|
2012-04-10 15:18:28 +00:00
|
|
|
endif
|
2012-09-18 18:29:16 +00:00
|
|
|
ifneq ($$($1_EXCLUDES),)
|
|
|
|
$1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
|
|
|
|
$1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS))
|
2012-04-10 15:18:28 +00:00
|
|
|
endif
|
2012-09-18 18:29:16 +00:00
|
|
|
|
|
|
|
# Find all files to be copied from source to bin.
|
|
|
|
ifneq (,$$($1_COPY))
|
|
|
|
# Rewrite list of patterns into a find statement.
|
|
|
|
$1_COPY_PATTERN:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_COPY))
|
|
|
|
# Search for all files to be copied.
|
|
|
|
$1_ALL_COPIES := $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i \( $$($1_COPY_PATTERN) \) -a -type f))
|
|
|
|
# Copy these explicitly
|
|
|
|
$1_ALL_COPIES += $$($1_COPY_FILES)
|
|
|
|
# Copy must also respect filters.
|
|
|
|
ifneq (,$$($1_INCLUDES))
|
|
|
|
$1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES))
|
|
|
|
endif
|
|
|
|
ifneq (,$$($1_EXCLUDES))
|
|
|
|
$1_ALL_COPIES := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_COPIES))
|
|
|
|
endif
|
|
|
|
ifneq (,$$($1_EXCLUDE_FILES))
|
|
|
|
$1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES))
|
|
|
|
endif
|
|
|
|
# All files below META-INF are always copied.
|
|
|
|
$1_ALL_COPIES += $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i/META-INF -type f 2> /dev/null))
|
|
|
|
ifneq (,$$($1_ALL_COPIES))
|
|
|
|
# Yep, there are files to be copied!
|
|
|
|
$1_ALL_COPY_TARGETS:=
|
|
|
|
$$(foreach i,$$($1_ALL_COPIES),$$(eval $$(call add_file_to_copy,$1,$$i)))
|
|
|
|
# Now we can depend on $$($1_ALL_COPY_TARGETS) to copy all files!
|
|
|
|
endif
|
2012-04-10 15:18:28 +00:00
|
|
|
endif
|
|
|
|
|
2012-09-18 18:29:16 +00:00
|
|
|
# Find all property files to be copied and cleaned from source to bin.
|
|
|
|
ifneq (,$$($1_CLEAN))
|
|
|
|
# Rewrite list of patterns into a find statement.
|
|
|
|
$1_CLEAN_PATTERN:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_CLEAN))
|
|
|
|
# Search for all files to be copied.
|
|
|
|
$1_ALL_CLEANS := $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i \( $$($1_CLEAN_PATTERN) \) -a -type f))
|
|
|
|
# Copy and clean must also respect filters.
|
|
|
|
ifneq (,$$($1_INCLUDES))
|
|
|
|
$1_ALL_CLEANS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_CLEANS))
|
|
|
|
endif
|
|
|
|
ifneq (,$$($1_EXCLUDES))
|
|
|
|
$1_ALL_CLEANS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_CLEANS))
|
|
|
|
endif
|
|
|
|
ifneq (,$$($1_EXCLUDE_FILES))
|
|
|
|
$1_ALL_CLEANS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_CLEANS))
|
|
|
|
endif
|
|
|
|
ifneq (,$$($1_ALL_CLEANS))
|
|
|
|
# Yep, there are files to be copied and cleaned!
|
|
|
|
$1_ALL_COPY_CLEAN_TARGETS:=
|
|
|
|
$$(foreach i,$$($1_ALL_CLEANS),$$(eval $$(call add_file_to_copy_and_clean,$1,$$i)))
|
|
|
|
# Now we can depend on $$($1_ALL_COPY_CLEAN_TARGETS) to copy all files!
|
|
|
|
endif
|
|
|
|
endif
|
2012-04-10 15:18:28 +00:00
|
|
|
|
|
|
|
# Prep the source paths.
|
|
|
|
ifneq ($$($1_JAVAC_SOURCE_PATH_UGLY_OVERRIDE),)
|
|
|
|
$$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_JAVAC_SOURCE_PATH_UGLY_OVERRIDE)))
|
|
|
|
else
|
|
|
|
$$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_SRC)))
|
|
|
|
endif
|
|
|
|
|
2012-06-08 03:25:06 +00:00
|
|
|
ifneq (,$$($1_HEADERS))
|
2012-09-18 18:29:16 +00:00
|
|
|
$1_HEADERS_ARG := -h $$($1_HEADERS)
|
2012-06-08 03:25:06 +00:00
|
|
|
endif
|
|
|
|
|
2012-04-10 15:18:28 +00:00
|
|
|
# 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'
|
|
|
|
|
2012-09-18 18:29:16 +00:00
|
|
|
ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes)
|
|
|
|
# Using sjavac to compile.
|
|
|
|
$1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/javac_state
|
2012-04-10 15:18:28 +00:00
|
|
|
|
2012-09-18 18:29:16 +00:00
|
|
|
$$($1_BIN)/javac_state: $$($1_SRCS) $$($1_DEPENDS)
|
|
|
|
$(MKDIR) -p $$(@D)
|
|
|
|
$$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.batch.tmp)
|
|
|
|
$(ECHO) Compiling $1
|
|
|
|
$$($1_JVM) $$(word 1,$$($1_JAVAC)) com.sun.tools.sjavac.Main \
|
|
|
|
$$($1_REMOTE) $$($1_SJAVAC_ARGS) --permit-unidentified-artifacts -mfl $$($1_BIN)/_the.batch.tmp \
|
|
|
|
$$($1_FLAGS) \
|
|
|
|
-implicit:none -d $$($1_BIN) $$($1_HEADERS_ARG)
|
|
|
|
else
|
|
|
|
# Using plain javac to batch compile everything.
|
|
|
|
$1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/_the.batch
|
2012-04-10 15:18:28 +00:00
|
|
|
|
2012-09-18 18:29:16 +00:00
|
|
|
# When not using sjavac, pass along all sources to javac using an @file.
|
|
|
|
$$($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 for $1
|
|
|
|
($$($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)
|
2012-04-10 15:18:28 +00:00
|
|
|
endif
|
|
|
|
|
2012-09-18 18:29:16 +00:00
|
|
|
# Check if a jar file was specified, then setup the rules for the jar.
|
|
|
|
ifneq (,$$($1_JAR))
|
|
|
|
# If no suffixes was explicitly set for this jar file.
|
|
|
|
# Use class and the cleaned/copied properties file suffixes as the default
|
|
|
|
# for the types of files to be put into the jar.
|
|
|
|
ifeq (,$$($1_SUFFIXES))
|
|
|
|
$1_SUFFIXES:=.class $$($1_CLEAN) $$($1_COPY)
|
|
|
|
endif
|
|
|
|
|
|
|
|
$$(eval $$(call SetupArchive,ARCHIVE_$1,$$($1),\
|
|
|
|
SRCS:=$$($1_BIN),\
|
|
|
|
SUFFIXES:=$$($1_SUFFIXES),\
|
|
|
|
EXCLUDE:=$$($1_EXCLUDES),\
|
|
|
|
INCLUDES:=$$($1_INCLUDES),\
|
|
|
|
EXTRA_FILES:=$$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS),\
|
|
|
|
JAR:=$$($1_JAR),\
|
|
|
|
JARMAIN:=$$($1_JARMAIN),\
|
|
|
|
MANIFEST:=$$($1_MANIFEST),\
|
|
|
|
EXTRA_MANIFEST_ATTR:=$$($1_EXTRA_MANIFEST_ATTR),\
|
|
|
|
JARINDEX:=$$($1_JARINDEX),\
|
|
|
|
HEADERS:=$$($1_HEADERS),\
|
|
|
|
SETUP:=$$($1_SETUP)))
|
|
|
|
endif
|
2012-04-10 15:18:28 +00:00
|
|
|
|
2012-09-18 18:29:16 +00:00
|
|
|
# Check if a srczip was specified, then setup the rules for the srczip.
|
|
|
|
ifneq (,$$($1_SRCZIP))
|
|
|
|
$$(eval $$(call SetupZipArchive,ARCHIVE_$1,\
|
2012-04-10 15:18:28 +00:00
|
|
|
SRC:=$$($1_SRC),\
|
|
|
|
ZIP:=$$($1_SRCZIP),\
|
|
|
|
INCLUDES:=$$($1_INCLUDES),\
|
|
|
|
EXCLUDES:=$$($1_EXCLUDES),\
|
|
|
|
EXCLUDE_FILES:=$$($1_EXCLUDE_FILES)))
|
2012-09-18 18:29:16 +00:00
|
|
|
endif
|
2012-04-10 15:18:28 +00:00
|
|
|
|
|
|
|
endef
|