common/makefiles/JavaCompilation.gmk

Tue, 18 Sep 2012 11:29:16 -0700

author
ohair
date
Tue, 18 Sep 2012 11:29:16 -0700
changeset 478
2ba6f4da4bf3
parent 458
c8d320b48626
child 494
e64f2cb57d05
permissions
-rw-r--r--

7197849: Update new build-infra makefiles
Reviewed-by: ihse, erikj, ohrstrom, tbell

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

mercurial