42 $(error You must include MakeBase.gmk prior to including JavaCompilation.gmk)
43 endif
44
45 # Java compilation needs SetupZipArchive if we're generating a source zip.
46 include ZipArchive.gmk
47
48 FALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST
49
50 # Setup make rules for defining a Java compiler, which is needed to compile
51 # Java code. This rule generates no output.
52 #
53 # Parameter 1 is the name of the compiler definition. This name needs to be
54 # passed to SetupJavaCompilation. This name is used as variable prefix.
55 #
56 # Remaining parameters are named arguments. These include:
57 # JVM:=The jvm used to run the javac/javah command
58 # JAVAC:=The javac jar and bootstrap classpath changes, or just bin/javac if JVM is left out
59 # FLAGS:=Flags to be supplied to javac
60 # SERVER_DIR:=Use a javac server (-XDserver) and store the server related files here
61 # SERVER_JVM:=Use this JVM for the server. Defaults to the JVM above.
62 define SetupJavaCompiler
63 $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompiler, please update JavaCompilation.gmk))
64 $(call EvalDebugWrapper,$(strip $1),$(call SetupJavaCompilerInner,$(strip $1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)))
65 endef
66
67 define SetupJavaCompilerInner
68 $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $(strip $($i)),$1_$(strip $($i)))$(NEWLINE))
69 $(call LogSetupMacroEntry,SetupJavaCompiler($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
70 $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompiler, please update JavaCompilation.gmk))
71
72 # The port file contains the tcp/ip on which the server listens
73 # and the cookie necessary to talk to the server.
74 $1_SJAVAC_PORTFILE:=$$($1_SERVER_DIR)/server.port
75 # You can use a different JVM to run the background javac server.
76 ifeq ($$($1_SERVER_JVM),)
77 # It defaults to the same JVM that is used to start the javac command.
78 $1_SERVER_JVM:=$$($1_JVM)
79 endif
80 endef
81
82 # Setup make rules for creating a jar archive.
83 #
84 # Parameter 1 is the name of the rule. This name is used as variable prefix,
85 # and the targets generated are listed in a variable by that name.
86 #
87 # Parameter 2 is a list of dependencies for the jar target. If left empty,
88 # dependencies are searched using SRCS, which should not be empty.
89 #
90 # Remaining parameters are named arguments. These include:
91 # SRCS:=List of directories in where to find files to add to archive
92 # SUFFIXES:=File suffixes to include in jar
93 # INCLUDES:=List of directories/packages in SRCS that should be included
94 # EXCLUDES:=List of directories/packages in SRCS that should be excluded
95 # EXCLUDE_FILES:=List of files in SRCS that should be excluded
96 # EXTRA_FILES:=List of files in SRCS that should be included regardless of suffix match.
97 # JAR:=Jar file to create
98 # MANIFEST:=Optional manifest file template.
99 # JARMAIN:=Optional main class to add to manifest
100 # JARINDEX:=true means generate the index in the jar file.
101 # SKIP_METAINF:=Set to prevent contents of an META-INF directory to be automatically
102 # added to the archive.
103 # EXTRA_MANIFEST_ATTR:=Extra attribute to add to manifest.
104 # CHECK_COMPRESS_JAR Check the COMPRESS_JAR variable
105 define SetupArchive
106 $(if $(16),$(error Internal makefile error: Too many arguments to SetupArchive, please update JavaCompilation.gmk))
107 $(call EvalDebugWrapper,$(strip $1),$(call SetupArchiveInner,$(strip $1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)))
108 endef
109
110 define SetupArchiveInner
111 # NOTE: $2 is dependencies, not a named argument!
112 $(foreach i,3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $(strip $($i)),$1_$(strip $($i)))$(NEWLINE))
113 $(call LogSetupMacroEntry,SetupArchive($1),<dependencies>,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
114 $(if $(findstring $(LOG_LEVEL),trace), $(info *[2] <dependencies> = $(strip $2)))
115 $(if $(16),$(error Internal makefile error: Too many arguments to SetupArchive, please update JavaCompilation.gmk))
116
117 $1_JARMAIN:=$(strip $$($1_JARMAIN))
118 $1_JARNAME:=$$(notdir $$($1_JAR))
119 $1_MANIFEST_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_manifest
120 $1_DELETESS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletess
121 $1_DELETES_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletes
122 $1_BIN:=$$(dir $$($1_JAR))
123
124 ifeq (,$$($1_SUFFIXES))
125 # No suffix was set, default to classes.
126 $1_SUFFIXES:=.class
127 endif
128 # Convert suffixes to a find expression
129 $1_FIND_PATTERNS:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES))
130 # On windows, a lot of includes/excludes risk making the command line too long, so
131 # writing the grep patterns to files.
132 # Grep returns 1 if nothing is matched. Do not fail the build for this.
133 ifneq (,$$($1_INCLUDES))
134 $1_GREP_INCLUDE_PATTERNS:=$$(call EscapeDollar, \
135 $$(foreach src,$$($1_SRCS), $$(addprefix $$(src)/,$$($1_INCLUDES))))
154 $1_GREP_EXCLUDES:=| ( $(GREP) -v $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_EXCLUDE_PATTERNS)) \
155 || test "$$$$?" = "1" )
156 else
157 $1_GREP_EXCLUDE_OUTPUT=$(RM) $$($1_BIN)/_the.$$($1_JARNAME)_exclude $$(NEWLINE) \
158 $$(call ListPathsSafely,$1_GREP_EXCLUDE_PATTERNS,\n, \
159 >> $$($1_BIN)/_the.$$($1_JARNAME)_exclude)
160 $1_GREP_EXCLUDES:=| ( $(GREP) -v -f $$($1_BIN)/_the.$$($1_JARNAME)_exclude \
161 || test "$$$$?" = "1" )
162 endif
163 endif
164
165 # Check if this jar needs to have its index generated.
166 ifneq (,$$($1_JARINDEX))
167 $1_JARINDEX = (cd $$(dir $$@) && $(JAR) -i $$(notdir $$@))
168 else
169 $1_JARINDEX = true
170 endif
171 # When this macro is run in the same makefile as the java compilation, dependencies are
172 # transfered in make variables. When the macro is run in a different makefile than the
173 # java compilation, the dependencies need to be found in the filesystem.
174 ifneq (,$2)
175 $1_DEPS:=$2
176 else
177 # Add all source roots to the find cache since we are likely going to run find
178 # on these more than once. The cache will only be updated if necessary.
179 $$(eval $$(call FillCacheFind, $$($1_FIND_LIST)))
180 $1_DEPS:=$$(filter $$(addprefix %,$$($1_SUFFIXES)), \
181 $$(call CacheFind,$$($1_SRCS)))
182 ifneq (,$$($1_GREP_INCLUDE_PATTERNS))
183 $1_DEPS:=$$(filter $$(addsuffix %,$$($1_GREP_INCLUDE_PATTERNS)),$$($1_DEPS))
184 endif
185 ifneq (,$$($1_GREP_EXCLUDE_PATTERNS))
186 $1_DEPS:=$$(filter-out $$(addsuffix %,$$($1_GREP_EXCLUDE_PATTERNS)),$$($1_DEPS))
187 endif
188 # Look for EXTRA_FILES in all SRCS dirs and as absolute paths.
189 $1_DEPS+=$$(wildcard $$(foreach src, $$($1_SRCS), \
190 $$(addprefix $$(src)/, $$($1_EXTRA_FILES))) $$($1_EXTRA_FILES))
191 ifeq (,$$($1_SKIP_METAINF))
192 $1_DEPS+=$$(call CacheFind,$$(wildcard $$(addsuffix /META-INF,$$($1_SRCS))))
193 endif
194 endif
195 # The dependency list should never be empty
196 ifeq ($$(strip $$($1_DEPS)), )
197 $$(warning No dependencies found for $1)
198 endif
199
200 # Utility macros, to make the shell script receipt somewhat easier to decipher.
201
202 # Capture extra files is the same for both CAPTURE_CONTENTS and SCAPTURE_CONTENTS so
203 # only define it once to avoid duplication.
204 # The list of extra files might be long, so need to use ListPathsSafely to print
205 # them out to a separte file. Then process the contents of that file to rewrite
206 # into -C <dir> <file> lines.
207 # The EXTRA_FILES_RESOLVED varible must be set in the macro so that it's evaluated
208 # in the recipe when the files are guaranteed to exist.
209 $1_CAPTURE_EXTRA_FILES=\
210 $(RM) $$($1_BIN)/_the.$$($1_JARNAME)_contents.extra $$(NEWLINE) \
211 $$(eval $1_EXTRA_FILES_RESOLVED:=$$(call DoubleDollar, $$(call DoubleDollar, \
212 $$(wildcard $$(foreach src, $$($1_SRCS), \
213 $$(addprefix $$(src)/, $$($1_EXTRA_FILES))) $$($1_EXTRA_FILES))))) \
214 $$(if $$($1_EXTRA_FILES_RESOLVED), \
215 $$(call ListPathsSafely,$1_EXTRA_FILES_RESOLVED,\n, \
216 >> $$($1_BIN)/_the.$$($1_JARNAME)_contents.extra) $$(NEWLINE) \
271 $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_JAR))
272
273 ifneq (,$$($1_CHECK_COMPRESS_JAR))
274 $1_JAR_CREATE_OPTIONS := c0fm
275 $1_JAR_UPDATE_OPTIONS := u0f
276 ifeq ($(COMPRESS_JARS), true)
277 $1_JAR_CREATE_OPTIONS := cfm
278 $1_JAR_UPDATE_OPTIONS := uf
279 endif
280 else
281 $1_JAR_CREATE_OPTIONS := cfm
282 $1_JAR_UPDATE_OPTIONS := uf
283 endif
284
285 # Include all variables of significance in the vardeps file
286 $1_VARDEPS := $(JAR) $$($1_JAR_CREATE_OPTIONS) $$($1_MANIFEST) $(RELEASE) $(COMPANY_NAME) \
287 $$($1_JARMAIN) $$($1_EXTRA_MANIFEST_ATTR)
288 $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$(dir $$($1_JAR))_the.$$($1_JARNAME).vardeps)
289
290 # Here is the rule that creates/updates the jar file.
291 $$($1_JAR) : $$($1_DEPS) $$($1_MANIFEST) $$($1_VARDEPS_FILE)
292 $(MKDIR) -p $$($1_BIN)
293 $$($1_GREP_INCLUDE_OUTPUT)
294 $$($1_GREP_EXCLUDE_OUTPUT)
295 # If the vardeps file is part of the newer prereq list, it means that
296 # either the jar file does not exist, or we need to recreate it from
297 # from scratch anyway since a simple update will not catch all the
298 # potential changes.
299 $$(if $$(filter $$($1_VARDEPS_FILE) $$($1_MANIFEST), $$?), \
300 $$(if $$($1_MANIFEST), \
301 $(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \
302 -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE) $$(NEWLINE) \
303 , \
304 $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE) $$(NEWLINE)) \
305 $$(if $$($1_JARMAIN), \
306 $(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \
307 $$(if $$($1_EXTRA_MANIFEST_ATTR), \
308 $(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \
309 $(ECHO) Creating $$($1_NAME) $$(NEWLINE) \
310 $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \
311 $$($1_SCAPTURE_CONTENTS) \
412 #
413 # Remaining parameters are named arguments. These include:
414 # SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC
415 # JVM:=path to ..bin/java
416 # ADD_JAVAC_FLAGS:=javac flags to append to the default ones.
417 # SRC:=one or more directories to search for sources
418 # BIN:=store classes here
419 # INCLUDES:=myapp.foo means will only compile java files in myapp.foo or any of its sub-packages.
420 # EXCLUDES:=myapp.foo means will do not compile java files in myapp.foo or any of its sub-packages.
421 # COPY:=.prp means copy all prp files to the corresponding package in BIN.
422 # COPY_FILES:=myapp/foo/setting.txt means copy this file over to the package myapp/foo
423 # CLEAN:=.properties means copy and clean all properties file to the corresponding package in BIN.
424 # CLEAN_FILES:=myapp/foo/setting.txt means clean this file over to the package myapp/foo
425 # SRCZIP:=Create a src.zip based on the found sources and copied files.
426 # INCLUDE_FILES:="com/sun/SolarisFoobar.java" means only compile this file!
427 # EXCLUDE_FILES:="com/sun/SolarisFoobar.java" means do not compile this particular file!
428 # "SolarisFoobar.java" means do not compile SolarisFoobar, wherever it is found.
429 # HEADERS:=path to directory where all generated c-headers are written.
430 # DEPENDS:=Extra dependecy
431 # DISABLE_SJAVAC:=Explicitly disable the use of sjavac for this compilation unit.
432 define SetupJavaCompilation
433 $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompilation, please update JavaCompilation.gmk))
434 $(call EvalDebugWrapper,$(strip $1),$(call SetupJavaCompilationInner,$(strip $1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)))
435 endef
436
437 define SetupJavaCompilationInner
438 $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $(strip $($i)),$1_$(strip $($i)))$(NEWLINE))
439 $(call LogSetupMacroEntry,SetupJavaCompilation($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
440 $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompilation, please update JavaCompilation.gmk))
441
442 # Verify arguments
443 ifeq ($$($1_BIN),)
444 $$(error Must specify BIN (in $1))
445 endif
446
447 # Extract the info from the java compiler setup.
448 $1_JVM := $$($$($1_SETUP)_JVM)
449 $1_JAVAC := $$($$($1_SETUP)_JAVAC)
450 $1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS)
451 ifeq ($$($1_JAVAC),)
452 $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP))
453 endif
454 $1_SJAVAC_PORTFILE := $$($$($1_SETUP)_SJAVAC_PORTFILE)
455 $1_SERVER_JVM := $$($$($1_SETUP)_SERVER_JVM)
456
457 # Handle addons and overrides.
458 $1_SRC:=$$(call ADD_SRCS,$$($1_SRC))
459 # Make sure the dirs exist.
460 $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory $$d)))
636 ($$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) \
637 -implicit:none \
638 -d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_BIN)/_the.$1_batch.tmp && \
639 $(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch)
640
641 endif
642
643 # Add all targets to main variable
644 $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_COMPILE_TARGETS) \
645 $$($1_HEADER_TARGETS)
646
647 # Check if a jar file was specified, then setup the rules for the jar.
648 ifneq (,$$($1_JAR))
649 # If no suffixes was explicitly set for this jar file.
650 # Use class and the cleaned/copied properties file suffixes as the default
651 # for the types of files to be put into the jar.
652 ifeq (,$$($1_SUFFIXES))
653 $1_SUFFIXES:=.class $$($1_CLEAN) $$($1_COPY)
654 endif
655
656 $$(eval $$(call SetupArchive,ARCHIVE_$1,$$($1), \
657 SRCS:=$$($1_BIN), \
658 SUFFIXES:=$$($1_SUFFIXES), \
659 EXCLUDE:=$$($1_EXCLUDES), \
660 INCLUDES:=$$($1_INCLUDES), \
661 EXTRA_FILES:=$$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS), \
662 JAR:=$$($1_JAR), \
663 JARMAIN:=$$($1_JARMAIN), \
664 MANIFEST:=$$($1_MANIFEST), \
665 EXTRA_MANIFEST_ATTR:=$$($1_EXTRA_MANIFEST_ATTR), \
666 JARINDEX:=$$($1_JARINDEX), \
667 HEADERS:=$$($1_HEADERS), \
668 SETUP:=$$($1_SETUP)))
669
670 # Add jar to target list
671 $1 += $$($1_JAR)
672 endif
673
674 # Check if a srczip was specified, then setup the rules for the srczip.
675 ifneq (,$$($1_SRCZIP))
676 $$(eval $$(call SetupZipArchive,ARCHIVE_$1, \
|
42 $(error You must include MakeBase.gmk prior to including JavaCompilation.gmk)
43 endif
44
45 # Java compilation needs SetupZipArchive if we're generating a source zip.
46 include ZipArchive.gmk
47
48 FALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST
49
50 # Setup make rules for defining a Java compiler, which is needed to compile
51 # Java code. This rule generates no output.
52 #
53 # Parameter 1 is the name of the compiler definition. This name needs to be
54 # passed to SetupJavaCompilation. This name is used as variable prefix.
55 #
56 # Remaining parameters are named arguments. These include:
57 # JVM:=The jvm used to run the javac/javah command
58 # JAVAC:=The javac jar and bootstrap classpath changes, or just bin/javac if JVM is left out
59 # FLAGS:=Flags to be supplied to javac
60 # SERVER_DIR:=Use a javac server (-XDserver) and store the server related files here
61 # SERVER_JVM:=Use this JVM for the server. Defaults to the JVM above.
62 SetupJavaCompiler = $(NamedParamsMacroTemplate)
63 define SetupJavaCompilerBody
64 # The port file contains the tcp/ip on which the server listens
65 # and the cookie necessary to talk to the server.
66 $1_SJAVAC_PORTFILE:=$$($1_SERVER_DIR)/server.port
67 # You can use a different JVM to run the background javac server.
68 ifeq ($$($1_SERVER_JVM),)
69 # It defaults to the same JVM that is used to start the javac command.
70 $1_SERVER_JVM:=$$($1_JVM)
71 endif
72 endef
73
74 # Setup make rules for creating a jar archive.
75 #
76 # Parameter 1 is the name of the rule. This name is used as variable prefix,
77 # and the targets generated are listed in a variable by that name.
78 #
79 # Remaining parameters are named arguments. These include:
80 # DEPENDENCIES:=List of dependencies for the jar target. If left empty,
81 # dependencies are calculated automatically from the source files found.
82 # For this to work, the source files must exist when the makefile is
83 # parsed.
84 # SRCS:=List of directories in where to find files to add to archive
85 # SUFFIXES:=File suffixes to include in jar
86 # INCLUDES:=List of directories/packages in SRCS that should be included
87 # EXCLUDES:=List of directories/packages in SRCS that should be excluded
88 # EXCLUDE_FILES:=List of files in SRCS that should be excluded
89 # EXTRA_FILES:=List of files in SRCS that should be included regardless of suffix match.
90 # JAR:=Jar file to create
91 # MANIFEST:=Optional manifest file template.
92 # JARMAIN:=Optional main class to add to manifest
93 # JARINDEX:=true means generate the index in the jar file.
94 # SKIP_METAINF:=Set to prevent contents of an META-INF directory to be automatically
95 # added to the archive.
96 # EXTRA_MANIFEST_ATTR:=Extra attribute to add to manifest.
97 # CHECK_COMPRESS_JAR Check the COMPRESS_JAR variable
98 SetupArchive = $(NamedParamsMacroTemplate)
99 define SetupArchiveBody
100
101 $1_JARMAIN:=$(strip $$($1_JARMAIN))
102 $1_JARNAME:=$$(notdir $$($1_JAR))
103 $1_MANIFEST_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_manifest
104 $1_DELETESS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletess
105 $1_DELETES_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletes
106 $1_BIN:=$$(dir $$($1_JAR))
107
108 ifeq (,$$($1_SUFFIXES))
109 # No suffix was set, default to classes.
110 $1_SUFFIXES:=.class
111 endif
112 # Convert suffixes to a find expression
113 $1_FIND_PATTERNS:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES))
114 # On windows, a lot of includes/excludes risk making the command line too long, so
115 # writing the grep patterns to files.
116 # Grep returns 1 if nothing is matched. Do not fail the build for this.
117 ifneq (,$$($1_INCLUDES))
118 $1_GREP_INCLUDE_PATTERNS:=$$(call EscapeDollar, \
119 $$(foreach src,$$($1_SRCS), $$(addprefix $$(src)/,$$($1_INCLUDES))))
138 $1_GREP_EXCLUDES:=| ( $(GREP) -v $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_EXCLUDE_PATTERNS)) \
139 || test "$$$$?" = "1" )
140 else
141 $1_GREP_EXCLUDE_OUTPUT=$(RM) $$($1_BIN)/_the.$$($1_JARNAME)_exclude $$(NEWLINE) \
142 $$(call ListPathsSafely,$1_GREP_EXCLUDE_PATTERNS,\n, \
143 >> $$($1_BIN)/_the.$$($1_JARNAME)_exclude)
144 $1_GREP_EXCLUDES:=| ( $(GREP) -v -f $$($1_BIN)/_the.$$($1_JARNAME)_exclude \
145 || test "$$$$?" = "1" )
146 endif
147 endif
148
149 # Check if this jar needs to have its index generated.
150 ifneq (,$$($1_JARINDEX))
151 $1_JARINDEX = (cd $$(dir $$@) && $(JAR) -i $$(notdir $$@))
152 else
153 $1_JARINDEX = true
154 endif
155 # When this macro is run in the same makefile as the java compilation, dependencies are
156 # transfered in make variables. When the macro is run in a different makefile than the
157 # java compilation, the dependencies need to be found in the filesystem.
158 ifeq ($$($1_DEPENDENCIES), )
159 # Add all source roots to the find cache since we are likely going to run find
160 # on these more than once. The cache will only be updated if necessary.
161 $$(eval $$(call FillCacheFind, $$($1_FIND_LIST)))
162 $1_DEPENDENCIES:=$$(filter $$(addprefix %,$$($1_SUFFIXES)), \
163 $$(call CacheFind,$$($1_SRCS)))
164 ifneq (,$$($1_GREP_INCLUDE_PATTERNS))
165 $1_DEPENDENCIES:=$$(filter $$(addsuffix %,$$($1_GREP_INCLUDE_PATTERNS)),$$($1_DEPENDENCIES))
166 endif
167 ifneq (,$$($1_GREP_EXCLUDE_PATTERNS))
168 $1_DEPENDENCIES:=$$(filter-out $$(addsuffix %,$$($1_GREP_EXCLUDE_PATTERNS)),$$($1_DEPENDENCIES))
169 endif
170 # Look for EXTRA_FILES in all SRCS dirs and as absolute paths.
171 $1_DEPENDENCIES+=$$(wildcard $$(foreach src, $$($1_SRCS), \
172 $$(addprefix $$(src)/, $$($1_EXTRA_FILES))) $$($1_EXTRA_FILES))
173 ifeq (,$$($1_SKIP_METAINF))
174 $1_DEPENDENCIES+=$$(call CacheFind,$$(wildcard $$(addsuffix /META-INF,$$($1_SRCS))))
175 endif
176 endif
177 # The dependency list should never be empty
178 ifeq ($$(strip $$($1_DEPENDENCIES)), )
179 $$(warning No dependencies found for $1)
180 endif
181
182 # Utility macros, to make the shell script receipt somewhat easier to decipher.
183
184 # Capture extra files is the same for both CAPTURE_CONTENTS and SCAPTURE_CONTENTS so
185 # only define it once to avoid duplication.
186 # The list of extra files might be long, so need to use ListPathsSafely to print
187 # them out to a separte file. Then process the contents of that file to rewrite
188 # into -C <dir> <file> lines.
189 # The EXTRA_FILES_RESOLVED varible must be set in the macro so that it's evaluated
190 # in the recipe when the files are guaranteed to exist.
191 $1_CAPTURE_EXTRA_FILES=\
192 $(RM) $$($1_BIN)/_the.$$($1_JARNAME)_contents.extra $$(NEWLINE) \
193 $$(eval $1_EXTRA_FILES_RESOLVED:=$$(call DoubleDollar, $$(call DoubleDollar, \
194 $$(wildcard $$(foreach src, $$($1_SRCS), \
195 $$(addprefix $$(src)/, $$($1_EXTRA_FILES))) $$($1_EXTRA_FILES))))) \
196 $$(if $$($1_EXTRA_FILES_RESOLVED), \
197 $$(call ListPathsSafely,$1_EXTRA_FILES_RESOLVED,\n, \
198 >> $$($1_BIN)/_the.$$($1_JARNAME)_contents.extra) $$(NEWLINE) \
253 $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_JAR))
254
255 ifneq (,$$($1_CHECK_COMPRESS_JAR))
256 $1_JAR_CREATE_OPTIONS := c0fm
257 $1_JAR_UPDATE_OPTIONS := u0f
258 ifeq ($(COMPRESS_JARS), true)
259 $1_JAR_CREATE_OPTIONS := cfm
260 $1_JAR_UPDATE_OPTIONS := uf
261 endif
262 else
263 $1_JAR_CREATE_OPTIONS := cfm
264 $1_JAR_UPDATE_OPTIONS := uf
265 endif
266
267 # Include all variables of significance in the vardeps file
268 $1_VARDEPS := $(JAR) $$($1_JAR_CREATE_OPTIONS) $$($1_MANIFEST) $(RELEASE) $(COMPANY_NAME) \
269 $$($1_JARMAIN) $$($1_EXTRA_MANIFEST_ATTR)
270 $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$(dir $$($1_JAR))_the.$$($1_JARNAME).vardeps)
271
272 # Here is the rule that creates/updates the jar file.
273 $$($1_JAR) : $$($1_DEPENDENCIES) $$($1_MANIFEST) $$($1_VARDEPS_FILE)
274 $(MKDIR) -p $$($1_BIN)
275 $$($1_GREP_INCLUDE_OUTPUT)
276 $$($1_GREP_EXCLUDE_OUTPUT)
277 # If the vardeps file is part of the newer prereq list, it means that
278 # either the jar file does not exist, or we need to recreate it from
279 # from scratch anyway since a simple update will not catch all the
280 # potential changes.
281 $$(if $$(filter $$($1_VARDEPS_FILE) $$($1_MANIFEST), $$?), \
282 $$(if $$($1_MANIFEST), \
283 $(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \
284 -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE) $$(NEWLINE) \
285 , \
286 $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE) $$(NEWLINE)) \
287 $$(if $$($1_JARMAIN), \
288 $(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \
289 $$(if $$($1_EXTRA_MANIFEST_ATTR), \
290 $(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \
291 $(ECHO) Creating $$($1_NAME) $$(NEWLINE) \
292 $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \
293 $$($1_SCAPTURE_CONTENTS) \
394 #
395 # Remaining parameters are named arguments. These include:
396 # SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC
397 # JVM:=path to ..bin/java
398 # ADD_JAVAC_FLAGS:=javac flags to append to the default ones.
399 # SRC:=one or more directories to search for sources
400 # BIN:=store classes here
401 # INCLUDES:=myapp.foo means will only compile java files in myapp.foo or any of its sub-packages.
402 # EXCLUDES:=myapp.foo means will do not compile java files in myapp.foo or any of its sub-packages.
403 # COPY:=.prp means copy all prp files to the corresponding package in BIN.
404 # COPY_FILES:=myapp/foo/setting.txt means copy this file over to the package myapp/foo
405 # CLEAN:=.properties means copy and clean all properties file to the corresponding package in BIN.
406 # CLEAN_FILES:=myapp/foo/setting.txt means clean this file over to the package myapp/foo
407 # SRCZIP:=Create a src.zip based on the found sources and copied files.
408 # INCLUDE_FILES:="com/sun/SolarisFoobar.java" means only compile this file!
409 # EXCLUDE_FILES:="com/sun/SolarisFoobar.java" means do not compile this particular file!
410 # "SolarisFoobar.java" means do not compile SolarisFoobar, wherever it is found.
411 # HEADERS:=path to directory where all generated c-headers are written.
412 # DEPENDS:=Extra dependecy
413 # DISABLE_SJAVAC:=Explicitly disable the use of sjavac for this compilation unit.
414 SetupJavaCompilation = $(NamedParamsMacroTemplate)
415 define SetupJavaCompilationBody
416
417 # Verify arguments
418 ifeq ($$($1_BIN),)
419 $$(error Must specify BIN (in $1))
420 endif
421
422 # Extract the info from the java compiler setup.
423 $1_JVM := $$($$($1_SETUP)_JVM)
424 $1_JAVAC := $$($$($1_SETUP)_JAVAC)
425 $1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS)
426 ifeq ($$($1_JAVAC),)
427 $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP))
428 endif
429 $1_SJAVAC_PORTFILE := $$($$($1_SETUP)_SJAVAC_PORTFILE)
430 $1_SERVER_JVM := $$($$($1_SETUP)_SERVER_JVM)
431
432 # Handle addons and overrides.
433 $1_SRC:=$$(call ADD_SRCS,$$($1_SRC))
434 # Make sure the dirs exist.
435 $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory $$d)))
611 ($$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) \
612 -implicit:none \
613 -d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_BIN)/_the.$1_batch.tmp && \
614 $(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch)
615
616 endif
617
618 # Add all targets to main variable
619 $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_COMPILE_TARGETS) \
620 $$($1_HEADER_TARGETS)
621
622 # Check if a jar file was specified, then setup the rules for the jar.
623 ifneq (,$$($1_JAR))
624 # If no suffixes was explicitly set for this jar file.
625 # Use class and the cleaned/copied properties file suffixes as the default
626 # for the types of files to be put into the jar.
627 ifeq (,$$($1_SUFFIXES))
628 $1_SUFFIXES:=.class $$($1_CLEAN) $$($1_COPY)
629 endif
630
631 $$(eval $$(call SetupArchive,ARCHIVE_$1, \
632 DEPENDENCIES:=$$($1), \
633 SRCS:=$$($1_BIN), \
634 SUFFIXES:=$$($1_SUFFIXES), \
635 EXCLUDE:=$$($1_EXCLUDES), \
636 INCLUDES:=$$($1_INCLUDES), \
637 EXTRA_FILES:=$$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS), \
638 JAR:=$$($1_JAR), \
639 JARMAIN:=$$($1_JARMAIN), \
640 MANIFEST:=$$($1_MANIFEST), \
641 EXTRA_MANIFEST_ATTR:=$$($1_EXTRA_MANIFEST_ATTR), \
642 JARINDEX:=$$($1_JARINDEX), \
643 HEADERS:=$$($1_HEADERS), \
644 SETUP:=$$($1_SETUP)))
645
646 # Add jar to target list
647 $1 += $$($1_JAR)
648 endif
649
650 # Check if a srczip was specified, then setup the rules for the srczip.
651 ifneq (,$$($1_SRCZIP))
652 $$(eval $$(call SetupZipArchive,ARCHIVE_$1, \
|