26 ifndef _JAR_ARCHIVE_GMK
27 _JAR_ARCHIVE_GMK := 1
28
29 ifeq (,$(_MAKEBASE_GMK))
30 $(error You must include MakeBase.gmk prior to including JarArchive.gmk)
31 endif
32
33 FALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST
34
35 # Setup make rules for creating a jar archive.
36 #
37 # Parameter 1 is the name of the rule. This name is used as variable prefix,
38 # and the targets generated are listed in a variable by that name.
39 #
40 # Remaining parameters are named arguments. These include:
41 # DEPENDENCIES:=List of dependencies for the jar target. If left empty,
42 # dependencies are calculated automatically from the source files found.
43 # For this to work, the source files must exist when the makefile is
44 # parsed.
45 # SRCS:=List of directories in where to find files to add to archive
46 # SUFFIXES:=File suffixes to include in jar
47 # INCLUDES:=List of directories/packages in SRCS that should be included
48 # EXCLUDES:=List of directories/packages in SRCS that should be excluded
49 # EXCLUDE_FILES:=List of files in SRCS that should be excluded
50 # EXTRA_FILES:=List of files in SRCS that should be included regardless of suffix match.
51 # JAR:=Jar file to create
52 # MANIFEST:=Optional manifest file template.
53 # JARMAIN:=Optional main class to add to manifest
54 # JARINDEX:=true means generate the index in the jar file.
55 # SKIP_METAINF:=Set to prevent contents of an META-INF directory to be automatically
56 # added to the archive.
57 # EXTRA_MANIFEST_ATTR:=Extra attribute to add to manifest.
58 # CHECK_COMPRESS_JAR Check the COMPRESS_JAR variable
59 # JAR_CMD:=Optionally override the jar command to use when creating the archive.
60 SetupJarArchive = $(NamedParamsMacroTemplate)
61 define SetupJarArchiveBody
62
63 $1_JARMAIN:=$(strip $$($1_JARMAIN))
64 $1_JARNAME:=$$(notdir $$($1_JAR))
65 $1_MANIFEST_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_manifest
66 $1_DELETESS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletess
67 $1_DELETES_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletes
68 $1_BIN:=$$(dir $$($1_JAR))
69 $$(call SetIfEmpty, $1_JAR_CMD, $$(JAR))
70
71 ifeq (,$$($1_SUFFIXES))
72 # No suffix was set, default to classes.
73 $1_SUFFIXES:=.class
74 endif
75 # Convert suffixes to a find expression
76 $1_FIND_PATTERNS:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES))
77 # On windows, a lot of includes/excludes risk making the command line too long, so
78 # writing the grep patterns to files.
79 # Grep returns 1 if nothing is matched. Do not fail the build for this.
80 ifneq (,$$($1_INCLUDES))
81 $1_GREP_INCLUDE_PATTERNS:=$$(call EscapeDollar, \
82 $$(foreach src,$$($1_SRCS), $$(addprefix $$(src)/,$$($1_INCLUDES))))
83 # If there are a lot of include patterns, output to file to shorten command lines
84 ifeq ($$(word 20,$$($1_GREP_INCLUDE_PATTERNS)),)
85 $1_GREP_INCLUDES:=| ( $(GREP) $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_INCLUDE_PATTERNS)) \
86 || test "$$$$?" = "1" )
87 else
88 $1_GREP_INCLUDE_OUTPUT = \
214
215 # Use a slightly shorter name for logging, but with enough path to identify this jar.
216 $1_NAME:=$$(subst $$(OUTPUTDIR)/,,$$($1_JAR))
217
218 ifneq (,$$($1_CHECK_COMPRESS_JAR))
219 $1_JAR_CREATE_OPTIONS := c0fm
220 $1_JAR_UPDATE_OPTIONS := u0f
221 ifeq ($(COMPRESS_JARS), true)
222 $1_JAR_CREATE_OPTIONS := cfm
223 $1_JAR_UPDATE_OPTIONS := uf
224 endif
225 else
226 $1_JAR_CREATE_OPTIONS := cfm
227 $1_JAR_UPDATE_OPTIONS := uf
228 endif
229
230 # Include all variables of significance in the vardeps file
231 $1_VARDEPS := $$($1_JAR_CMD) $$($1_JAR_CREATE_OPTIONS) $$($1_MANIFEST) \
232 $$($1_JARMAIN) $$($1_EXTRA_MANIFEST_ATTR) $$($1_ORIG_DEPS) $$($1_SRCS) \
233 $$($1_INCLUDES) $$($1_EXCLUDES) $$($1_EXCLUDE_FILES) $$($1_EXTRA_FILES)
234 $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$(dir $$($1_JAR))_the.$$($1_JARNAME).vardeps)
235
236 # Here is the rule that creates/updates the jar file.
237 $$($1_JAR) : $$($1_DEPENDENCIES) $$($1_MANIFEST) $$($1_VARDEPS_FILE)
238 $$(call MakeTargetDir)
239 $$($1_GREP_INCLUDE_OUTPUT)
240 $$($1_GREP_EXCLUDE_OUTPUT)
241 # If the vardeps file is part of the newer prereq list, it means that
242 # either the jar file does not exist, or we need to recreate it from
243 # from scratch anyway since a simple update will not catch all the
244 # potential changes.
245 $$(if $$(filter $$($1_VARDEPS_FILE) $$($1_MANIFEST), $$?), \
246 $$(if $$($1_MANIFEST), \
247 $(CP) $$($1_MANIFEST) $$($1_MANIFEST_FILE) $$(NEWLINE) \
248 , \
249 $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE) $$(NEWLINE)) \
250 $$(if $$($1_JARMAIN), \
251 $(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \
252 $$(if $$($1_EXTRA_MANIFEST_ATTR), \
253 $(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \
254 $(ECHO) Creating $$($1_NAME) $$(NEWLINE) \
255 $$($1_JAR_CMD) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \
256 $$($1_SCAPTURE_CONTENTS) \
257 $$($1_SCAPTURE_METAINF) \
258 $$($1_SUPDATE_CONTENTS) \
|
26 ifndef _JAR_ARCHIVE_GMK
27 _JAR_ARCHIVE_GMK := 1
28
29 ifeq (,$(_MAKEBASE_GMK))
30 $(error You must include MakeBase.gmk prior to including JarArchive.gmk)
31 endif
32
33 FALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST
34
35 # Setup make rules for creating a jar archive.
36 #
37 # Parameter 1 is the name of the rule. This name is used as variable prefix,
38 # and the targets generated are listed in a variable by that name.
39 #
40 # Remaining parameters are named arguments. These include:
41 # DEPENDENCIES:=List of dependencies for the jar target. If left empty,
42 # dependencies are calculated automatically from the source files found.
43 # For this to work, the source files must exist when the makefile is
44 # parsed.
45 # SRCS:=List of directories in where to find files to add to archive
46 # BIN:=Directory where to store build control files
47 # SUFFIXES:=File suffixes to include in jar
48 # INCLUDES:=List of directories/packages in SRCS that should be included
49 # EXCLUDES:=List of directories/packages in SRCS that should be excluded
50 # EXCLUDE_FILES:=List of files in SRCS that should be excluded
51 # EXTRA_FILES:=List of files in SRCS that should be included regardless of suffix match.
52 # JAR:=Jar file to create
53 # MANIFEST:=Optional manifest file template.
54 # JARMAIN:=Optional main class to add to manifest
55 # JARINDEX:=true means generate the index in the jar file.
56 # SKIP_METAINF:=Set to prevent contents of an META-INF directory to be automatically
57 # added to the archive.
58 # EXTRA_MANIFEST_ATTR:=Extra attribute to add to manifest.
59 # CHECK_COMPRESS_JAR Check the COMPRESS_JAR variable
60 # JAR_CMD:=Optionally override the jar command to use when creating the archive.
61 SetupJarArchive = $(NamedParamsMacroTemplate)
62 define SetupJarArchiveBody
63
64 $1_JARMAIN:=$(strip $$($1_JARMAIN))
65 $1_JARNAME:=$$(notdir $$($1_JAR))
66 $1_JAR_OUTPUT_DIR := $$(patsubst %/, %, $$(dir $$($1_JAR)))
67 $$(call SetIfEmpty, $1_BIN, $$($1_JAR_OUTPUT_DIR))
68 $1_MANIFEST_FILE:=$$($1_BIN)/_the.$$($1_JARNAME)_manifest
69 $1_DELETESS_FILE:=$$($1_BIN)/_the.$$($1_JARNAME)_deletess
70 $1_DELETES_FILE:=$$($1_BIN)/_the.$$($1_JARNAME)_deletes
71 $$(call SetIfEmpty, $1_JAR_CMD, $$(JAR))
72
73 ifeq (,$$($1_SUFFIXES))
74 # No suffix was set, default to classes.
75 $1_SUFFIXES:=.class
76 endif
77 # Convert suffixes to a find expression
78 $1_FIND_PATTERNS:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES))
79 # On windows, a lot of includes/excludes risk making the command line too long, so
80 # writing the grep patterns to files.
81 # Grep returns 1 if nothing is matched. Do not fail the build for this.
82 ifneq (,$$($1_INCLUDES))
83 $1_GREP_INCLUDE_PATTERNS:=$$(call EscapeDollar, \
84 $$(foreach src,$$($1_SRCS), $$(addprefix $$(src)/,$$($1_INCLUDES))))
85 # If there are a lot of include patterns, output to file to shorten command lines
86 ifeq ($$(word 20,$$($1_GREP_INCLUDE_PATTERNS)),)
87 $1_GREP_INCLUDES:=| ( $(GREP) $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_INCLUDE_PATTERNS)) \
88 || test "$$$$?" = "1" )
89 else
90 $1_GREP_INCLUDE_OUTPUT = \
216
217 # Use a slightly shorter name for logging, but with enough path to identify this jar.
218 $1_NAME:=$$(subst $$(OUTPUTDIR)/,,$$($1_JAR))
219
220 ifneq (,$$($1_CHECK_COMPRESS_JAR))
221 $1_JAR_CREATE_OPTIONS := c0fm
222 $1_JAR_UPDATE_OPTIONS := u0f
223 ifeq ($(COMPRESS_JARS), true)
224 $1_JAR_CREATE_OPTIONS := cfm
225 $1_JAR_UPDATE_OPTIONS := uf
226 endif
227 else
228 $1_JAR_CREATE_OPTIONS := cfm
229 $1_JAR_UPDATE_OPTIONS := uf
230 endif
231
232 # Include all variables of significance in the vardeps file
233 $1_VARDEPS := $$($1_JAR_CMD) $$($1_JAR_CREATE_OPTIONS) $$($1_MANIFEST) \
234 $$($1_JARMAIN) $$($1_EXTRA_MANIFEST_ATTR) $$($1_ORIG_DEPS) $$($1_SRCS) \
235 $$($1_INCLUDES) $$($1_EXCLUDES) $$($1_EXCLUDE_FILES) $$($1_EXTRA_FILES)
236 $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$($1_BIN)/_the.$$($1_JARNAME).vardeps)
237
238 # Here is the rule that creates/updates the jar file.
239 $$($1_JAR) : $$($1_DEPENDENCIES) $$($1_MANIFEST) $$($1_VARDEPS_FILE)
240 $$(call MakeTargetDir)
241 $$(call MakeDir, $$($1_BIN))
242 $$($1_GREP_INCLUDE_OUTPUT)
243 $$($1_GREP_EXCLUDE_OUTPUT)
244 # If the vardeps file is part of the newer prereq list, it means that
245 # either the jar file does not exist, or we need to recreate it from
246 # from scratch anyway since a simple update will not catch all the
247 # potential changes.
248 $$(if $$(filter $$($1_VARDEPS_FILE) $$($1_MANIFEST), $$?), \
249 $$(if $$($1_MANIFEST), \
250 $(CP) $$($1_MANIFEST) $$($1_MANIFEST_FILE) $$(NEWLINE) \
251 , \
252 $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE) $$(NEWLINE)) \
253 $$(if $$($1_JARMAIN), \
254 $(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \
255 $$(if $$($1_EXTRA_MANIFEST_ATTR), \
256 $(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \
257 $(ECHO) Creating $$($1_NAME) $$(NEWLINE) \
258 $$($1_JAR_CMD) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \
259 $$($1_SCAPTURE_CONTENTS) \
260 $$($1_SCAPTURE_METAINF) \
261 $$($1_SUPDATE_CONTENTS) \
|