common/makefiles/JavaCompilation.gmk

Thu, 08 Nov 2012 12:24:35 +0100

author
ohrstrom
date
Thu, 08 Nov 2012 12:24:35 +0100
changeset 505
8bbc72864a41
parent 502
ed9e5635fc80
child 507
f2ac4d0edaae
permissions
-rw-r--r--

8003161: small fixes to re-enable new build system
Reviewed-by: dholmes, alanb, erikj

ohair@425 1 #
ohair@425 2 # Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
ohair@425 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@425 4 #
ohair@425 5 # This code is free software; you can redistribute it and/or modify it
ohair@425 6 # under the terms of the GNU General Public License version 2 only, as
ohair@425 7 # published by the Free Software Foundation. Oracle designates this
ohair@425 8 # particular file as subject to the "Classpath" exception as provided
ohair@425 9 # by Oracle in the LICENSE file that accompanied this code.
ohair@425 10 #
ohair@425 11 # This code is distributed in the hope that it will be useful, but WITHOUT
ohair@425 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@425 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@425 14 # version 2 for more details (a copy is included in the LICENSE file that
ohair@425 15 # accompanied this code).
ohair@425 16 #
ohair@425 17 # You should have received a copy of the GNU General Public License version
ohair@425 18 # 2 along with this work; if not, write to the Free Software Foundation,
ohair@425 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@425 20 #
ohair@425 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@425 22 # or visit www.oracle.com if you need additional information or have any
ohair@425 23 # questions.
ohair@425 24 #
ohair@425 25
ohair@478 26 # This makefile is much simpler now that it can use the smart javac wrapper
ohair@478 27 # for dependency tracking between java packages and incremental compiles.
ohair@478 28 # It could be even more simple if we added support for incremental jar updates
ohair@478 29 # directly from the smart javac wrapper.
ohair@478 30
ohair@478 31 # Cleaning/copying properties here is not a good solution. The properties
ohair@478 32 # should be cleaned/copied by a annotation processor in sjavac.
ohair@478 33
ohair@425 34 # When you read this source. Remember that $(sort ...) has the side effect
ohair@425 35 # of removing duplicates. It is actually this side effect that is
ohair@425 36 # desired whenever sort is used below!
ohair@425 37
ohair@425 38 ifeq (,$(_MAKEBASE_GMK))
ohair@425 39 $(error You must include MakeBase.gmk prior to including JavaCompilation.gmk)
ohair@425 40 endif
ohair@425 41
ohair@425 42 FALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST
ohair@425 43
ohair@425 44 define SetupJavaCompiler
ohair@425 45 # param 1 is for example BOOT_JAVAC or NEW_JAVAC
ohair@425 46 # This is the name later used to decide which java compiler to use.
ohair@425 47 # param 2-9 are named args.
ohair@425 48 # JVM:=The jvm used to run the javac/javah command
ohair@425 49 # JAVAC:=The javac jar and bootstrap classpath changes, or just bin/javac if JVM is left out
ohair@425 50 # FLAGS:=Flags to be supplied to javac
ohair@425 51 # SERVER_DIR:=Use a javac server (-XDserver) and store the server related files here
ohair@425 52 # SERVER_JVM:=Use this JVM for the server. Defaults to the JVM above.
ohair@494 53 $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
ohair@494 54 $(call LogSetupMacroEntry,SetupJavaCompiler($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
ohair@494 55 $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompiler, please update JavaCompilation.gmk))
ohair@425 56
ohair@494 57 # The port file contains the tcp/ip on which the server listens
ohair@494 58 # and the cookie necessary to talk to the server.
ohair@494 59 $1_SJAVAC_PORTFILE:=$$($1_SERVER_DIR)/server.port
ohair@494 60 # You can use a different JVM to run the background javac server.
ohair@494 61 ifeq ($$($1_SERVER_JVM),)
ohair@494 62 # It defaults to the same JVM that is used to start the javac command.
ohair@494 63 $1_SERVER_JVM:=$$($1_JVM)
ohair@425 64 endif
ohair@425 65 endef
ohair@425 66
ohair@425 67 define SetupArchive
ohair@425 68 # param 1 is for example ARCHIVE_MYPACKAGE
ohair@425 69 # param 2 are the dependecies
ohair@425 70 # param 3,4,5,6,7,8,9 are named args.
ohair@425 71 # SRCS:=List of directories in where to find files to add to archive
ohair@425 72 # SUFFIXES:=File suffixes to include in jar
ohair@425 73 # INCLUDES:=List of directories/packages in SRCS that should be included
ohair@425 74 # EXCLUDES:=List of directories/packages in SRCS that should be excluded
ohair@425 75 # EXCLUDE_FILES:=List of files in SRCS that should be excluded
ohair@425 76 # EXTRA_FILES:=List of files in SRCS that should be included regardless of suffix match.
ohair@425 77 # JAR:=Jar file to create
ohair@425 78 # MANIFEST:=Optional manifest file template.
ohair@425 79 # JARMAIN:=Optional main class to add to manifest
ohair@478 80 # JARINDEX:=true means generate the index in the jar file.
ohair@425 81 # SKIP_METAINF:=Set to prevent contents of an META-INF directory to be automatically
ohair@425 82 # added to the archive.
ohair@425 83 # EXTRA_MANIFEST_ATTR:=Extra attribute to add to manifest.
erikj@458 84 # CHECK_COMPRESS_JAR Check the COMPRESS_JAR variable
ohair@494 85
ohair@494 86 # NOTE: $2 is dependencies, not a named argument!
ohair@494 87 $(foreach i,3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
ohair@494 88 $(call LogSetupMacroEntry,SetupArchive($1),<dependencies>,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
ohair@494 89 $(if $(findstring $(LOG),debug trace), $(info *[2] <dependencies> = $(strip $2)))
erikj@458 90 $(if $(16),$(error Internal makefile error: Too many arguments to SetupArchive, please update JavaCompilation.gmk))
ohair@425 91
ohair@425 92 $1_JARMAIN:=$(strip $$($1_JARMAIN))
ohair@425 93 $1_JARNAME:=$$(notdir $$($1_JAR))
ohair@425 94 $1_MANIFEST_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_manifest
ohair@425 95 $1_DELETESS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletess
ohair@425 96 $1_DELETES_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletes
ohair@425 97 $1_BIN:=$$(dir $$($1_JAR))
erikj@445 98
ohair@425 99 ifeq (,$$($1_SUFFIXES))
ohair@425 100 # No suffix was set, default to classes.
ohair@425 101 $1_SUFFIXES:=.class
ohair@425 102 endif
ohair@425 103 # Convert suffixes to a find expression
ohair@425 104 $1_FIND_PATTERNS:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES))
erikj@445 105 # On windows, a lot of includes/excludes risk making the command line too long, so
erikj@445 106 # writing the grep patterns to files.
ohair@425 107 ifneq (,$$($1_INCLUDES))
erikj@445 108 $1_GREP_INCLUDE_PATTERNS:=$$(foreach src,$$($1_SRCS),\
erikj@445 109 $$(addprefix $$(src)/,$$($1_INCLUDES)))
ohair@494 110 # If there are a lot of include patterns, output to file to shorten command lines
ohair@494 111 ifeq ($$(word 20,$$($1_GREP_INCLUDE_PATTERNS)),)
ohair@494 112 $1_GREP_INCLUDES:=| $(GREP) $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_INCLUDE_PATTERNS))
ohair@494 113 else
ohrstrom@505 114 $$(shell $(MKDIR) -p $$($1_BIN) && $(RM) $$($1_BIN)/_the.$$($1_JARNAME)_include)
ohair@494 115 $$(eval $$(call ListPathsSafelyNow,$1_GREP_INCLUDE_PATTERNS,\n, \
erikj@445 116 >> $$($1_BIN)/_the.$$($1_JARNAME)_include))
ohair@494 117 $1_GREP_INCLUDES:=| $(GREP) -f $$($1_BIN)/_the.$$($1_JARNAME)_include
ohair@494 118 endif
ohair@425 119 endif
ohair@425 120 ifneq (,$$($1_EXCLUDES)$$($1_EXCLUDE_FILES))
erikj@445 121 $1_GREP_EXCLUDE_PATTERNS:=$$(foreach src,$$($1_SRCS),$$(addprefix $$(src)/,\
erikj@445 122 $$($1_EXCLUDES) $$($1_EXCLUDE_FILES)))
ohair@494 123 # If there are a lot of include patterns, output to file to shorten command lines
ohair@494 124 ifeq ($$(word 20,$$($1_GREP_EXCLUDE_PATTERNS)),)
ohair@494 125 $1_GREP_EXCLUDES:=| $(GREP) -v $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_EXCLUDE_PATTERNS))
ohair@494 126 else
ohrstrom@505 127 $$(shell $(MKDIR) -p $$($1_BIN) && $(RM) $$($1_BIN)/_the.$$($1_JARNAME)_exclude)
ohair@494 128 $$(eval $$(call ListPathsSafelyNow,$1_GREP_EXCLUDE_PATTERNS,\n, \
erikj@445 129 >> $$($1_BIN)/_the.$$($1_JARNAME)_exclude))
ohair@494 130 $1_GREP_EXCLUDES:=| $(GREP) -v -f $$($1_BIN)/_the.$$($1_JARNAME)_exclude
ohair@494 131 endif
ohair@425 132 endif
ohair@425 133
ohair@478 134 # Check if this jar needs to have its index generated.
erikj@445 135 ifneq (,$$($1_JARINDEX))
erikj@445 136 $1_JARINDEX = (cd $$(dir $$@) && $(JAR) -i $$(notdir $$@))
erikj@445 137 else
erikj@445 138 $1_JARINDEX = true
erikj@445 139 endif
erikj@445 140 # When this macro is run in the same makefile as the java compilation, dependencies are transfered
erikj@445 141 # in make variables. When the macro is run in a different makefile than the java compilation, the
erikj@445 142 # dependencies need to be found in the filesystem.
ohair@478 143 ifneq (,$2)
ohair@478 144 $1_DEPS:=$2
ohair@478 145 else
ohair@494 146 # The subst of \ is needed because $ has to be escaped with \ in EXTRA_FILES for the command
ohair@494 147 # lines, but not here for use in make dependencies.
ohair@494 148 $1_DEPS:=$$(shell $(FIND) $$($1_SRCS) -type f -a \( $$($1_FIND_PATTERNS) \) \
ohair@494 149 $$($1_GREP_INCLUDES) $$($1_GREP_EXCLUDES)) \
ohair@494 150 $$(subst \,,$$(foreach src,$$($1_SRCS),$$(addprefix $$(src)/,$$($1_EXTRA_FILES))))
ohair@478 151 ifeq (,$$($1_SKIP_METAINF))
ohair@494 152 $1_DEPS+=$$(shell $(FIND) $$(addsuffix /META-INF,$$($1_SRCS)) -type f 2> /dev/null))
ohair@478 153 endif
erikj@445 154 endif
erikj@445 155
ohair@425 156 # Utility macros, to make the shell script receipt somewhat easier to dechipher.
ohair@425 157
ohair@425 158 # The capture contents macro finds all files (matching the patterns, typically
ohair@425 159 # .class and .prp) that are newer than the jar-file, ie the new content to be put into the jar.
ohair@494 160 $1_CAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS),\
ohair@494 161 (($(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) -a -newer $$@ $$($1_GREP_INCLUDES) \
ohair@494 162 $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/||g' &&\
ohair@494 163 $(ECHO) $$(subst $$(src)/,,$$($1_EXTRA_FILES))) > \
ohair@494 164 $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE))
ohair@425 165 # The capture metainf macro finds all files below the META-INF directory that are newer than the jar-file.
ohair@425 166 ifeq (,$$($1_SKIP_METAINF))
ohair@494 167 $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 ) $$(NEWLINE))
ohair@425 168 endif
ohair@425 169 # The capture deletes macro finds all deleted files and concatenates them. The resulting file
ohair@425 170 # tells us what to remove from the jar-file.
ohair@494 171 $1_CAPTURE_DELETES=$$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.deleted -newer $$@ -exec $(SED) 's|$$(src)||g' \{\} >> $$($1_DELETES_FILE) \;) $$(NEWLINE))
ohair@425 172 # The update contents macro updates the jar file with the previously capture contents.
ohair@425 173 $1_UPDATE_CONTENTS=$$(foreach src,$$($1_SRCS),\
ohair@425 174 (cd $$(src) && \
ohair@425 175 if [ -s _the.$$($1_JARNAME)_contents ]; then \
ohair@425 176 $(ECHO) " updating" `$(WC) -l _the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'` files && \
ohair@478 177 $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @_the.$$($1_JARNAME)_contents; \
ohair@494 178 fi) $$(NEWLINE))
ohair@425 179 # The s-variants of the above macros are used when the jar is created from scratch.
ohair@425 180 $1_SCAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS),\
erikj@445 181 (($(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) \
ohair@494 182 $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/||g' &&\
ohair@494 183 $$(subst $$(src)/,,$(ECHO) $$($1_EXTRA_FILES))) > \
ohair@494 184 $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE))
erikj@445 185
ohair@425 186 ifeq (,$$($1_SKIP_METAINF))
ohair@425 187 $1_SCAPTURE_METAINF=$$(foreach src,$$($1_SRCS),\
erikj@445 188 ($(FIND) $$(src)/META-INF -type f 2> /dev/null | $(SED) 's|$$(src)/||g' >> \
ohair@494 189 $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE))
ohair@425 190 endif
ohair@425 191 $1_SUPDATE_CONTENTS=$$(foreach src,$$($1_SRCS),\
ohair@494 192 (cd $$(src) && $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE))
erikj@445 193
ohair@425 194 # Use a slightly shorter name for logging, but with enough path to identify this jar.
ohair@425 195 $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_JAR))
erikj@458 196
erikj@458 197 ifneq (,$$($1_CHECK_COMPRESS_JAR))
erikj@458 198 $1_JAR_CREATE_OPTIONS := c0fm
ohair@478 199 $1_JAR_UPDATE_OPTIONS := u0f
erikj@458 200 ifeq ($(COMPRESS_JARS), true)
erikj@458 201 $1_JAR_CREATE_OPTIONS := cfm
ohair@478 202 $1_JAR_UPDATE_OPTIONS := uf
erikj@458 203 endif
erikj@458 204 else
erikj@458 205 $1_JAR_CREATE_OPTIONS := cfm
ohair@478 206 $1_JAR_UPDATE_OPTIONS := uf
erikj@458 207 endif
erikj@458 208
ohair@425 209 # Here is the rule that creates/updates the jar file.
ohair@478 210 $$($1_JAR) : $$($1_DEPS)
ohair@425 211 $(MKDIR) -p $$($1_BIN)
ohair@494 212 $$(if $$($1_MANIFEST),\
ohair@425 213 $(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \
ohair@494 214 -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE) \
ohair@494 215 ,\
ohair@494 216 $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE))
ohair@494 217 $$(if $$($1_JARMAIN),$(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE))
ohair@494 218 $$(if $$($1_EXTRA_MANIFEST_ATTR),$(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE))
ohair@494 219 $$(if $$(wildcard $$@),\
ohair@494 220 $(ECHO) Modifying $$($1_NAME) $$(NEWLINE)\
ohair@478 221 $$($1_CAPTURE_CONTENTS) \
ohair@478 222 $$($1_CAPTURE_METAINF) \
ohair@494 223 $(RM) $$($1_DELETES_FILE) $$(NEWLINE)\
ohair@478 224 $$($1_CAPTURE_DELETES) \
ohair@494 225 $(CAT) $$($1_DELETES_FILE) > $$($1_DELETESS_FILE) $$(NEWLINE)\
ohair@478 226 if [ -s $$($1_DELETESS_FILE) ]; then \
ohair@478 227 $(ECHO) " deleting" `$(WC) -l $$($1_DELETESS_FILE) | $(AWK) '{ print $$$$1 }'` files && \
ohair@478 228 $(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \
ohair@494 229 fi $$(NEWLINE) \
ohair@494 230 $$($1_UPDATE_CONTENTS) true $$(NEWLINE) \
ohair@494 231 $$($1_JARINDEX) && true \
ohair@494 232 ,\
ohair@494 233 $(ECHO) Creating $$($1_NAME) && $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \
ohair@425 234 $$($1_SCAPTURE_CONTENTS) \
ohair@425 235 $$($1_SCAPTURE_METAINF) \
ohair@425 236 $$($1_SUPDATE_CONTENTS) \
ohair@494 237 $$($1_JARINDEX) && true )
ohair@425 238
ohair@425 239 endef
ohair@425 240
ohair@425 241 define SetupZipArchive
ohair@425 242 # param 1 is for example ZIP_MYSOURCE
ohair@425 243 # param 2,3,4,5,6,7,8,9 are named args.
erikj@445 244 # SRC,ZIP,INCLUDES,EXCLUDES,EXCLUDE_FILES,SUFFIXES,EXTRA_DEPS
ohair@494 245 $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
ohair@494 246 $(call LogSetupMacroEntry,SetupZipArchive($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
ohair@494 247 $(if $(16),$(error Internal makefile error: Too many arguments to SetupZipArchive, please update JavaCompilation.gmk))
ohair@425 248
ohair@425 249 # Find all files in the source tree.
erikj@445 250 $1_SUFFIX_FILTER := $$(patsubst %,-o -name $(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES))
erikj@445 251 $1_ALL_SRCS := $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i -type f -a ! -name "_the.*" \( -name FALSE_DUMMY $$($1_SUFFIX_FILTER) \) ))
ohair@425 252
ohair@425 253 ifneq ($$($1_INCLUDES),)
ohair@425 254 $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES))))
erikj@445 255 ifneq ($$($1_SUFFIXES),)
erikj@445 256 $1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES),\
erikj@445 257 $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$$s$(DQUOTE),$$($1_INCLUDES))))
erikj@445 258 else
erikj@445 259 $1_ZIP_INCLUDES := $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_INCLUDES)))
erikj@445 260 endif
ohair@425 261 $1_ALL_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_SRCS))
ohair@425 262 endif
ohair@425 263 ifneq ($$($1_EXCLUDES),)
ohair@425 264 $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
ohair@425 265 $1_ZIP_EXCLUDES := $$(addprefix -x$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_EXCLUDES)))
ohair@494 266 $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_SRCS))
ohair@425 267 endif
ohair@425 268
ohair@425 269 # Use a slightly shorter name for logging, but with enough path to identify this zip.
ohair@425 270 $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_ZIP))
ohair@425 271
ohair@425 272 # Now $1_ALL_SRCS should contain all sources that are going to be put into the zip.
ohair@425 273 # I.e. the zip -i and -x options should match the filtering done in the makefile.
ohair@425 274 # Explicitly excluded files can be given with absolute path. The patsubst solution
ohair@425 275 # isn't perfect but the likelyhood of an absolute path to match something in a src
ohair@425 276 # dir is very small.
erikj@445 277 $$($1_ZIP) : $$($1_ALL_SRCS) $$($1_EXTRA_DEPS)
ohair@425 278 $(MKDIR) -p $$(@D)
ohair@425 279 $(ECHO) Updating $$($1_NAME)
ohair@494 280 $$(foreach i,$$($1_SRC),(cd $$i && $(ZIP) -qru $$@ . $$($1_ZIP_INCLUDES) $$($1_ZIP_EXCLUDES) -x \*_the.\* $$(addprefix -x$(SPACE),$$(patsubst $$i/%,%,$$($1_EXCLUDE_FILES))))$$(NEWLINE)) true
ohair@425 281 $(TOUCH) $$@
ohair@425 282 endef
ohair@425 283
ohair@425 284 define add_file_to_copy
ohair@425 285 # param 1 = BUILD_MYPACKAGE
ohair@425 286 # parma 2 = The source file to copy.
ohair@425 287 $2_TARGET:=$2
ohair@425 288 # Remove the source prefix.
ohair@425 289 $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
ohair@425 290 # Now we can setup the depency that will trigger the copying.
ohair@425 291 $$($1_BIN)$$($2_TARGET) : $2
ohair@425 292 $(MKDIR) -p $$(@D)
ohair@425 293 $(CP) $$< $$@
ohair@425 294 $(CHMOD) -f ug+w $$@
ohair@425 295
ohair@425 296 # And do not forget this target
ohair@425 297 $1_ALL_COPY_TARGETS += $$($1_BIN)$$($2_TARGET)
ohair@425 298 endef
ohair@425 299
ohair@425 300
ohair@425 301 # This macro is used only for properties files that are to be
ohair@425 302 # copied over to the classes directory in cleaned form:
ohair@425 303 # Previously this was inconsistently done in different repositories.
ohair@478 304 # This is the new clean standard. Though it is to be superseded by
ohair@478 305 # a standard annotation processor from with sjavac.
ohair@425 306 define add_file_to_copy_and_clean
ohair@425 307 # param 1 = BUILD_MYPACKAGE
ohair@425 308 # parma 2 = The source file to copy and clean.
ohair@425 309 $2_TARGET:=$2
ohair@425 310 # Remove the source prefix.
ohair@425 311 $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
ohair@425 312 # Now we can setup the depency that will trigger the copying.
ohair@425 313 $$($1_BIN)$$($2_TARGET) : $2
ohair@425 314 $(MKDIR) -p $$(@D)
ohair@425 315 $(CAT) $$< | $(SED) -e 's/\([^\\]\):/\1\\:/g' -e 's/\([^\\]\)=/\1\\=/g' -e 's/#.*/#/g' \
ohair@494 316 | $(SED) -f "$(SRC_ROOT)/common/makefiles/support/unicode2x.sed" \
ohair@425 317 | $(SED) -e '/^#/d' -e '/^$$$$/d' \
ohair@425 318 -e :a -e '/\\$$$$/N; s/\\\n//; ta' \
ohair@425 319 -e 's/^[ \t]*//;s/[ \t]*$$$$//' \
erikj@445 320 -e 's/\\=/=/' | LANG=C $(SORT) > $$@
ohair@425 321 $(CHMOD) -f ug+w $$@
ohair@425 322
ohair@425 323 # And do not forget this target
ohair@425 324 $1_ALL_COPY_CLEAN_TARGETS += $$($1_BIN)$$($2_TARGET)
ohair@425 325 endef
ohair@425 326
ohair@425 327 define remove_string
ohair@425 328 $2 := $$(subst $1,,$$($2))
ohair@425 329 endef
ohair@425 330
ohair@425 331 define replace_space_with_pathsep
ohair@425 332 $1:=$(subst $(SPACE),$(PATH_SEP),$(strip $(patsubst %,%,$2)))
ohair@425 333 endef
ohair@425 334
ohair@425 335 define SetupJavaCompilation
ohair@425 336 # param 1 is for example BUILD_MYPACKAGE
ohair@425 337 # param 2,3,4,5,6,7,8 are named args.
ohair@425 338 # SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC
ohair@425 339 # JVM:=path to ..bin/java
ohair@425 340 # ADD_JAVAC_FLAGS:=javac flags to append to the default ones.
ohair@425 341 # SRC:=one or more directories to search for sources
ohair@425 342 # BIN:=store classes here
ohair@425 343 # INCLUDES:=myapp.foo means will only compile java files in myapp.foo or any of its sub-packages.
ohair@425 344 # EXCLUDES:=myapp.foo means will do not compile java files in myapp.foo or any of its sub-packages.
ohair@425 345 # COPY:=.prp means copy all prp files to the corresponding package in BIN.
ohair@425 346 # CLEAN:=.properties means copy and clean all properties file to the corresponding package in BIN.
ohair@425 347 # COPY_FILES:=myapp/foo/setting.txt means copy this file over to the package myapp/foo
ohair@425 348 # SRCZIP:=Create a src.zip based on the found sources and copied files.
ohair@425 349 # INCLUDE_FILES:="com/sun/SolarisFoobar.java" means only compile this file!
ohair@425 350 # EXCLUDE_FILES:="com/sun/SolarisFoobar.java" means do not compile this particular file!
ohair@425 351 # "SolarisFoobar.java" means do not compile SolarisFoobar, wherever it is found.
ohair@425 352 # JAVAC_SOURCE_PATH_UGLY_OVERRIDE:=Don't use this. This forces an explicit -sourcepath to javac.
ohair@425 353 # Its only here until we cleanup some nasty source code pasta in the jdk.
ohair@425 354 # HEADERS:=path to directory where all generated c-headers are written.
erikj@445 355 # DEPENDS:=Extra dependecy
ohair@494 356 $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
ohair@494 357 $(call LogSetupMacroEntry,SetupJavaCompilation($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
ohair@494 358 $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompilation, please update JavaCompilation.gmk))
ohair@425 359
ohair@478 360 # Extract the info from the java compiler setup.
ohair@478 361 $1_JVM := $$($$($1_SETUP)_JVM)
ohair@478 362 $1_JAVAC := $$($$($1_SETUP)_JAVAC)
ohair@478 363 $1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS)
ohair@478 364 ifeq ($$($1_JAVAC),)
ohair@425 365 $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP))
ohair@425 366 endif
ohair@494 367 $1_SJAVAC_PORTFILE := $$($$($1_SETUP)_SJAVAC_PORTFILE)
ohair@494 368 $1_SERVER_JVM := $$($$($1_SETUP)_SERVER_JVM)
ohair@425 369
ohair@478 370 # Handle addons and overrides.
ohair@478 371 $1_SRC:=$$(call ADD_SRCS,$$($1_SRC))
ohair@478 372 # Make sure the dirs exist.
ohair@494 373 $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory $$d)))
ohair@494 374 $$(eval $$(call MakeDir,$$($1_BIN)))
ohair@478 375 # Find all files in the source trees.
ohair@494 376 $1_ALL_SRCS := $$(filter-out $(OVR_SRCS),$$(shell $(FIND) $$($1_SRC) -type f))
ohair@478 377 # Extract the java files.
ohair@478 378 ifneq ($$($1_EXCLUDE_FILES),)
ohair@478 379 $1_EXCLUDE_FILES_PATTERN:=$$(addprefix %,$$($1_EXCLUDE_FILES))
ohair@478 380 endif
ohair@478 381 $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$(filter %.java,$$($1_ALL_SRCS)))
ohair@478 382 ifneq ($$($1_INCLUDE_FILES),)
ohair@478 383 $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES)))
ohair@478 384 $1_SRCS := $$(filter $$($1_INCLUDE_FILES), $$($1_SRCS))
ohair@478 385 endif
ohair@425 386
ohair@478 387 # Now we have a list of all java files to compile: $$($1_SRCS)
ohair@425 388
ohair@478 389 # Create the corresponding smart javac wrapper command line.
ohair@478 390 $1_SJAVAC_ARGS:=$$(addprefix -x ,$$(addsuffix .*,$$(subst /,.,$$($1_EXCLUDES)))) \
ohair@478 391 $$(addprefix -i ,$$(addsuffix .*,$$(subst /,.,$$($1_INCLUDES)))) \
ohair@478 392 $$(addprefix -xf *,$$(strip $$($1_EXCLUDE_FILES))) \
ohair@478 393 $$(addprefix -if *,$$(strip $$($1_INCLUDE_FILES))) \
ohair@478 394 -src "$$(subst $$(SPACE),$$(PATH_SEP),$$(strip $$($1_SRC)))"
erikj@458 395
ohair@478 396 # Prepend the source/bin path to the filter expressions.
ohair@478 397 ifneq ($$($1_INCLUDES),)
ohair@478 398 $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES))))
ohair@478 399 $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS))
ohair@478 400 endif
ohair@478 401 ifneq ($$($1_EXCLUDES),)
ohair@478 402 $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
ohair@478 403 $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS))
ohair@478 404 endif
ohair@425 405
ohair@478 406 # Find all files to be copied from source to bin.
ohair@478 407 ifneq (,$$($1_COPY))
ohair@478 408 # Rewrite list of patterns into a find statement.
ohair@478 409 $1_COPY_PATTERN:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_COPY))
ohair@478 410 # Search for all files to be copied.
ohair@494 411 $1_ALL_COPIES := $$(filter $$(addprefix %,$$($1_COPY)),$$($1_ALL_SRCS))
ohair@478 412 # Copy these explicitly
ohair@478 413 $1_ALL_COPIES += $$($1_COPY_FILES)
ohair@478 414 # Copy must also respect filters.
ohair@478 415 ifneq (,$$($1_INCLUDES))
ohair@478 416 $1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES))
ohair@478 417 endif
ohair@478 418 ifneq (,$$($1_EXCLUDES))
ohair@478 419 $1_ALL_COPIES := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_COPIES))
ohair@478 420 endif
ohair@478 421 ifneq (,$$($1_EXCLUDE_FILES))
ohair@478 422 $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES))
ohair@478 423 endif
ohair@478 424 # All files below META-INF are always copied.
ohair@494 425 $1_ALL_COPIES += $$(filter $$(addsuffix /META-INF%,$$($1_SRC)),$$($1_ALL_SRCS))
ohair@478 426 ifneq (,$$($1_ALL_COPIES))
ohair@478 427 # Yep, there are files to be copied!
ohair@478 428 $1_ALL_COPY_TARGETS:=
ohair@478 429 $$(foreach i,$$($1_ALL_COPIES),$$(eval $$(call add_file_to_copy,$1,$$i)))
ohair@478 430 # Now we can depend on $$($1_ALL_COPY_TARGETS) to copy all files!
ohair@478 431 endif
ohair@425 432 endif
ohair@478 433
ohair@478 434 # Find all property files to be copied and cleaned from source to bin.
ohair@478 435 ifneq (,$$($1_CLEAN))
ohair@478 436 # Rewrite list of patterns into a find statement.
ohair@478 437 $1_CLEAN_PATTERN:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_CLEAN))
ohair@478 438 # Search for all files to be copied.
ohair@494 439 $1_ALL_CLEANS := $$(filter $$(addprefix %,$$($1_CLEAN)),$$($1_ALL_SRCS))
ohair@478 440 # Copy and clean must also respect filters.
ohair@478 441 ifneq (,$$($1_INCLUDES))
ohair@478 442 $1_ALL_CLEANS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_CLEANS))
ohair@478 443 endif
ohair@478 444 ifneq (,$$($1_EXCLUDES))
ohair@478 445 $1_ALL_CLEANS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_CLEANS))
ohair@478 446 endif
ohair@478 447 ifneq (,$$($1_EXCLUDE_FILES))
ohair@478 448 $1_ALL_CLEANS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_CLEANS))
ohair@478 449 endif
ohair@478 450 ifneq (,$$($1_ALL_CLEANS))
ohair@478 451 # Yep, there are files to be copied and cleaned!
ohair@478 452 $1_ALL_COPY_CLEAN_TARGETS:=
ohair@478 453 $$(foreach i,$$($1_ALL_CLEANS),$$(eval $$(call add_file_to_copy_and_clean,$1,$$i)))
ohair@478 454 # Now we can depend on $$($1_ALL_COPY_CLEAN_TARGETS) to copy all files!
ohair@478 455 endif
ohair@425 456 endif
ohair@425 457
ohair@425 458 # Prep the source paths.
ohair@425 459 ifneq ($$($1_JAVAC_SOURCE_PATH_UGLY_OVERRIDE),)
ohair@425 460 $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_JAVAC_SOURCE_PATH_UGLY_OVERRIDE)))
ohair@425 461 else
ohair@425 462 $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_SRC)))
ohair@425 463 endif
ohair@425 464
ohair@425 465 # Create a sed expression to remove the source roots and to replace / with .
ohair@425 466 # and remove .java at the end.
ohair@425 467 $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g'
ohair@425 468
ohair@478 469 ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes)
ohair@494 470 ifneq (,$$($1_HEADERS))
ohair@494 471 $1_HEADERS_ARG := -h $$($1_HEADERS)
ohair@494 472 endif
ohair@494 473
ohair@478 474 # Using sjavac to compile.
ohair@478 475 $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/javac_state
ohair@425 476
ohair@494 477 # Create SJAVAC variable,
ohair@494 478 # expects $1_JAVAC to be "bootclasspathprepend -jar ...javac.jar"
ohair@494 479 # and it is rewritten into "bootclasspathprepend com.sun.tools.sjavac.Main"
ohair@494 480 $1_SJAVAC:=$$(word 1,$$($1_JAVAC)) -cp $$(word 3,$$($1_JAVAC)) com.sun.tools.sjavac.Main
ohair@494 481
ohair@494 482 # Set the $1_REMOTE to spawn a background javac server.
erikj@502 483 $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC))))
ohair@494 484
ohair@478 485 $$($1_BIN)/javac_state: $$($1_SRCS) $$($1_DEPENDS)
ohair@478 486 $(MKDIR) -p $$(@D)
ohair@478 487 $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.batch.tmp)
ohair@478 488 $(ECHO) Compiling $1
erikj@502 489 ($$($1_JVM) $$($1_SJAVAC) \
erikj@502 490 $$($1_REMOTE) \
erikj@502 491 -j $(NUM_CORES) \
ohair@494 492 --permit-unidentified-artifacts \
ohair@494 493 --permit-sources-without-package \
ohair@494 494 --compare-found-sources $$($1_BIN)/_the.batch.tmp \
erikj@502 495 --log=$(LOG) \
erikj@502 496 $$($1_SJAVAC_ARGS) \
ohair@478 497 $$($1_FLAGS) \
erikj@502 498 $$($1_HEADERS_ARG) \
erikj@502 499 -d $$($1_BIN) && \
erikj@502 500 $(MV) $$($1_BIN)/_the.batch.tmp $$($1_BIN)/_the.batch)
ohair@478 501 else
ohair@478 502 # Using plain javac to batch compile everything.
ohair@478 503 $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/_the.batch
ohair@425 504
ohair@494 505 # When buliding in batch, put headers in a temp dir to filter out those that actually
ohair@494 506 # changed before copying them to the real header dir.
ohair@494 507 ifneq (,$$($1_HEADERS))
ohair@494 508 $1_HEADERS_ARG := -h $$($1_HEADERS).tmp
ohair@494 509
ohair@494 510 $$($1_HEADERS)/_the.headers: $$($1_BIN)/_the.batch
ohair@494 511 $(MKDIR) -p $$(@D)
ohair@494 512 for f in `ls $$($1_HEADERS).tmp`; do \
ohair@494 513 if [ ! -f "$$($1_HEADERS)/$$$$f" ] || [ "`$(DIFF) $$($1_HEADERS)/$$$$f $$($1_HEADERS).tmp/$$$$f`" != "" ]; then \
ohair@494 514 $(CP) -f $$($1_HEADERS).tmp/$$$$f $$($1_HEADERS)/$$$$f; \
ohair@494 515 fi; \
ohair@494 516 done
ohair@494 517 $(RM) -r $$($1_HEADERS).tmp
ohair@494 518 $(TOUCH) $$@
ohair@494 519
ohair@494 520 $1 += $$($1_HEADERS)/_the.headers
ohair@494 521 endif
ohair@494 522
ohair@478 523 # When not using sjavac, pass along all sources to javac using an @file.
ohair@478 524 $$($1_BIN)/_the.batch: $$($1_SRCS) $$($1_DEPENDS)
ohair@478 525 $(MKDIR) -p $$(@D)
ohair@478 526 $(RM) $$($1_BIN)/_the.batch $$($1_BIN)/_the.batch.tmp
ohair@478 527 $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.batch.tmp)
ohair@478 528 $(ECHO) Compiling `$(WC) $$($1_BIN)/_the.batch.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files for $1
ohair@478 529 ($$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) \
ohair@478 530 -implicit:none -sourcepath "$$($1_SRCROOTSC)" \
ohair@478 531 -d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_BIN)/_the.batch.tmp && \
ohair@478 532 $(MV) $$($1_BIN)/_the.batch.tmp $$($1_BIN)/_the.batch)
ohair@494 533
ohair@425 534 endif
ohair@425 535
ohair@478 536 # Check if a jar file was specified, then setup the rules for the jar.
ohair@478 537 ifneq (,$$($1_JAR))
ohair@478 538 # If no suffixes was explicitly set for this jar file.
ohair@478 539 # Use class and the cleaned/copied properties file suffixes as the default
ohair@478 540 # for the types of files to be put into the jar.
ohair@478 541 ifeq (,$$($1_SUFFIXES))
ohair@478 542 $1_SUFFIXES:=.class $$($1_CLEAN) $$($1_COPY)
ohair@478 543 endif
ohair@425 544
ohair@478 545 $$(eval $$(call SetupArchive,ARCHIVE_$1,$$($1),\
ohair@478 546 SRCS:=$$($1_BIN),\
ohair@478 547 SUFFIXES:=$$($1_SUFFIXES),\
ohair@478 548 EXCLUDE:=$$($1_EXCLUDES),\
ohair@478 549 INCLUDES:=$$($1_INCLUDES),\
ohair@478 550 EXTRA_FILES:=$$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS),\
ohair@478 551 JAR:=$$($1_JAR),\
ohair@478 552 JARMAIN:=$$($1_JARMAIN),\
ohair@478 553 MANIFEST:=$$($1_MANIFEST),\
ohair@478 554 EXTRA_MANIFEST_ATTR:=$$($1_EXTRA_MANIFEST_ATTR),\
ohair@478 555 JARINDEX:=$$($1_JARINDEX),\
ohair@478 556 HEADERS:=$$($1_HEADERS),\
ohair@478 557 SETUP:=$$($1_SETUP)))
ohair@478 558 endif
ohair@478 559
ohair@478 560 # Check if a srczip was specified, then setup the rules for the srczip.
ohair@478 561 ifneq (,$$($1_SRCZIP))
ohair@478 562 $$(eval $$(call SetupZipArchive,ARCHIVE_$1,\
ohair@425 563 SRC:=$$($1_SRC),\
ohair@425 564 ZIP:=$$($1_SRCZIP),\
ohair@425 565 INCLUDES:=$$($1_INCLUDES),\
ohair@425 566 EXCLUDES:=$$($1_EXCLUDES),\
ohair@425 567 EXCLUDE_FILES:=$$($1_EXCLUDE_FILES)))
ohair@478 568 endif
ohair@425 569
ohair@425 570 endef

mercurial