< prev index next >

make/common/JavaCompilation.gmk

Print this page




 304           if [ -s $$($1_DELETESS_FILE) ]; then \
 305             $(ECHO) "  deleting" `$(WC) -l $$($1_DELETESS_FILE) | $(AWK) '{ print $$$$1 }'` files && \
 306             $(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \
 307           fi $$(NEWLINE) \
 308           $$($1_UPDATE_CONTENTS) true $$(NEWLINE) \
 309           $$($1_JARINDEX) && true )
 310 
 311   # Add jar to target list
 312   $1 += $$($1_JAR)
 313 endef
 314 
 315 
 316 define add_file_to_copy
 317   # param 1 = BUILD_MYPACKAGE
 318   # parma 2 = The source file to copy.
 319   $2_TARGET:=$2
 320   # Remove the source prefix.
 321   $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
 322   # To allow for automatic overrides, do not create a rule for a target file that
 323   # already has one
 324   ifeq ($$(findstring $$($2_TARGET), $$($1_COPY_LIST)), )
 325     $1_COPY_LIST += $$($2_TARGET)
 326     # Now we can setup the depency that will trigger the copying.
 327     $$($1_BIN)$$($2_TARGET) : $2
 328         $(MKDIR) -p $$(@D)
 329         $(CP) $$< $$@
 330         $(CHMOD) -f ug+w $$@
 331 
 332     # And do not forget this target
 333     $1_ALL_COPY_TARGETS += $$($1_BIN)$$($2_TARGET)
 334   endif
 335 endef
 336 
 337 
 338 # This macro is used only for properties files that are to be
 339 # copied over to the classes directory in cleaned form:
 340 # Previously this was inconsistently done in different repositories.
 341 # This is the new clean standard. Though it is to be superseded by
 342 # a standard annotation processor from with sjavac.
 343 #
 344 # An empty echo ensures that the input to sed always ends with a newline.
 345 # Certain implementations (e.g. Solaris) will skip the last line without


 348 # The sed expression does this:
 349 # 1. Add a backslash before any :, = or ! that do not have a backslash already.
 350 # 2. Apply the file unicode2x.sed which does a whole bunch of \u00XX to \xXX
 351 #    conversions.
 352 # 3. Delete all lines starting with #.
 353 # 4. Delete empty lines.
 354 # 5. Append lines ending with \ with the next line.
 355 # 6. Remove leading and trailing white space. Note that tabs must be explicit
 356 #    as sed on macosx does not understand '\t'.
 357 # 7. Replace the first \= with just =.
 358 # 8. Finally it's all sorted to create a stable output.
 359 #
 360 # It is assumed that = is the character used for separating names and values.
 361 define add_file_to_clean
 362   # param 1 = BUILD_MYPACKAGE
 363   # parma 2 = The source file to copy and clean.
 364   $2_TARGET:=$2
 365   # Remove the source prefix.
 366   $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
 367   # Now we can setup the depency that will trigger the copying.
 368   $$($1_BIN)$$($2_TARGET) : $2




 369         $(MKDIR) -p $$(@D)
 370         export LC_ALL=C ; ( $(CAT) $$< && $(ECHO) "" ) \
 371             | $(SED) -e 's/\([^\\]\):/\1\\:/g' -e 's/\([^\\]\)=/\1\\=/g' \
 372                 -e 's/\([^\\]\)!/\1\\!/g' -e 's/^[      ]*#.*/#/g' \
 373             | $(SED) -f "$(SRC_ROOT)/make/common/support/unicode2x.sed" \
 374             | $(SED) -e '/^#/d' -e '/^$$$$/d' \
 375                 -e :a -e '/\\$$$$/N; s/\\\n//; ta' \
 376                 -e 's/^[        ]*//;s/[        ]*$$$$//' \
 377                 -e 's/\\=/=/' \
 378             | $(SORT) > $$@
 379         $(CHMOD) -f ug+w $$@
 380 
 381   # And do not forget this target
 382   $1_ALL_COPY_CLEAN_TARGETS += $$($1_BIN)$$($2_TARGET)

 383 endef
 384 
 385 define remove_string
 386   $2 := $$(subst $1,,$$($2))
 387 endef
 388 
 389 # Setup make rules for compiling Java source code to class files and/or a
 390 # resulting jar file.
 391 #
 392 # Parameter 1 is the name of the rule. This name is used as variable prefix,
 393 # and the targets generated are listed in a variable by that name.
 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)))
 436   $$(call MakeDir,$$($1_BIN))
 437   # Add all source roots to the find cache since we are likely going to run find
 438   # on these more than once. The cache will only be updated if necessary.
 439   $$(eval $$(call FillCacheFind,$$($1_SRC)))
 440   # Find all files in the source trees. Preserve order of source roots for overrides to
 441   # work correctly. CacheFind does not preserve order so need to call it for each root.
 442   $1_ALL_SRCS += $$(filter-out $(OVR_SRCS),$$(foreach s,$$($1_SRC),$$(call CacheFind,$$(s))))
 443   # Extract the java files.
 444   ifneq ($$($1_EXCLUDE_FILES),)
 445     $1_EXCLUDE_FILES_PATTERN:=$$(addprefix %,$$($1_EXCLUDE_FILES))
 446   endif
 447   $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$(filter %.java,$$($1_ALL_SRCS)))
 448   ifneq ($$($1_INCLUDE_FILES),)
 449     $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES)))
 450     $1_SRCS := $$(filter $$($1_INCLUDE_FILES), $$($1_SRCS))
 451   endif
 452 
 453   # Now we have a list of all java files to compile: $$($1_SRCS)
 454 
 455   # Create the corresponding smart javac wrapper command line.
 456   $1_SJAVAC_ARGS:=$$(addprefix -x ,$$(addsuffix /*,$$($1_EXCLUDES))) \
 457       $$(addprefix -i ,$$(addsuffix /*,$$($1_INCLUDES))) \
 458       $$(addprefix -xf *,$$(strip $$($1_EXCLUDE_FILES))) \
 459       $$(addprefix -if *,$$(strip $$($1_INCLUDE_FILES))) \
 460       -src "$$(subst $$(SPACE),$$(PATH_SEP),$$(strip $$($1_SRC)))"
 461 
 462   # Prepend the source/bin path to the filter expressions.
 463   ifneq ($$($1_INCLUDES),)
 464     $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES))))
 465     $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS))
 466   endif
 467   ifneq ($$($1_EXCLUDES),)
 468     $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
 469     $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS))
 470   endif



















 471 
 472   # All files below META-INF are always copied.
 473   $1_ALL_COPIES := $$(filter $$(addsuffix /META-INF%,$$($1_SRC)),$$($1_ALL_SRCS))
 474   # Find all files to be copied from source to bin.
 475   ifneq (,$$($1_COPY)$$($1_COPY_FILES))
 476     # Search for all files to be copied.
 477     $1_ALL_COPIES += $$(filter $$(addprefix %,$$($1_COPY)),$$($1_ALL_SRCS))
 478     # Copy these explicitly
 479     $1_ALL_COPIES += $$($1_COPY_FILES)
 480   endif
 481   # Copy must also respect filters.
 482   ifneq (,$$($1_INCLUDES))
 483     $1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES))
 484   endif
 485   ifneq (,$$($1_EXCLUDES))
 486     $1_ALL_COPIES := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_COPIES))
 487   endif
 488   ifneq (,$$($1_EXCLUDE_FILES))
 489     $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES))
 490   endif




 304           if [ -s $$($1_DELETESS_FILE) ]; then \
 305             $(ECHO) "  deleting" `$(WC) -l $$($1_DELETESS_FILE) | $(AWK) '{ print $$$$1 }'` files && \
 306             $(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \
 307           fi $$(NEWLINE) \
 308           $$($1_UPDATE_CONTENTS) true $$(NEWLINE) \
 309           $$($1_JARINDEX) && true )
 310 
 311   # Add jar to target list
 312   $1 += $$($1_JAR)
 313 endef
 314 
 315 
 316 define add_file_to_copy
 317   # param 1 = BUILD_MYPACKAGE
 318   # parma 2 = The source file to copy.
 319   $2_TARGET:=$2
 320   # Remove the source prefix.
 321   $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
 322   # To allow for automatic overrides, do not create a rule for a target file that
 323   # already has one
 324   ifneq ($$($1_COPY_$$($2_TARGET)), 1)
 325     $1_COPY_$$($2_TARGET) := 1
 326     # Now we can setup the depency that will trigger the copying.
 327     $$($1_BIN)$$($2_TARGET) : $2
 328         $(MKDIR) -p $$(@D)
 329         $(CP) $$< $$@
 330         $(CHMOD) -f ug+w $$@
 331 
 332     # And do not forget this target
 333     $1_ALL_COPY_TARGETS += $$($1_BIN)$$($2_TARGET)
 334   endif
 335 endef
 336 
 337 
 338 # This macro is used only for properties files that are to be
 339 # copied over to the classes directory in cleaned form:
 340 # Previously this was inconsistently done in different repositories.
 341 # This is the new clean standard. Though it is to be superseded by
 342 # a standard annotation processor from with sjavac.
 343 #
 344 # An empty echo ensures that the input to sed always ends with a newline.
 345 # Certain implementations (e.g. Solaris) will skip the last line without


 348 # The sed expression does this:
 349 # 1. Add a backslash before any :, = or ! that do not have a backslash already.
 350 # 2. Apply the file unicode2x.sed which does a whole bunch of \u00XX to \xXX
 351 #    conversions.
 352 # 3. Delete all lines starting with #.
 353 # 4. Delete empty lines.
 354 # 5. Append lines ending with \ with the next line.
 355 # 6. Remove leading and trailing white space. Note that tabs must be explicit
 356 #    as sed on macosx does not understand '\t'.
 357 # 7. Replace the first \= with just =.
 358 # 8. Finally it's all sorted to create a stable output.
 359 #
 360 # It is assumed that = is the character used for separating names and values.
 361 define add_file_to_clean
 362   # param 1 = BUILD_MYPACKAGE
 363   # parma 2 = The source file to copy and clean.
 364   $2_TARGET:=$2
 365   # Remove the source prefix.
 366   $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
 367   # Now we can setup the depency that will trigger the copying.
 368   # To allow for automatic overrides, do not create a rule for a target file that
 369   # already has one
 370   ifneq ($$($1_CLEAN_$$($2_TARGET)), 1)
 371     $1_CLEAN_$$($2_TARGET) := 1
 372     $$($1_BIN)$$($1_MODULE_SUBDIR)$$($2_TARGET) : $2
 373         $(MKDIR) -p $$(@D)
 374         export LC_ALL=C ; ( $(CAT) $$< && $(ECHO) "" ) \
 375             | $(SED) -e 's/\([^\\]\):/\1\\:/g' -e 's/\([^\\]\)=/\1\\=/g' \
 376                 -e 's/\([^\\]\)!/\1\\!/g' -e 's/^[      ]*#.*/#/g' \
 377             | $(SED) -f "$(SRC_ROOT)/make/common/support/unicode2x.sed" \
 378             | $(SED) -e '/^#/d' -e '/^$$$$/d' \
 379                 -e :a -e '/\\$$$$/N; s/\\\n//; ta' \
 380                 -e 's/^[        ]*//;s/[        ]*$$$$//' \
 381                 -e 's/\\=/=/' \
 382             | $(SORT) > $$@
 383         $(CHMOD) -f ug+w $$@
 384 
 385     # And do not forget this target
 386     $1_ALL_COPY_CLEAN_TARGETS += $$($1_BIN)$$($2_TARGET)
 387   endif
 388 endef
 389 
 390 define remove_string
 391   $2 := $$(subst $1,,$$($2))
 392 endef
 393 
 394 # Setup make rules for compiling Java source code to class files and/or a
 395 # resulting jar file.
 396 #
 397 # Parameter 1 is the name of the rule. This name is used as variable prefix,
 398 # and the targets generated are listed in a variable by that name.
 399 #
 400 # Remaining parameters are named arguments. These include:
 401 #   SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC
 402 #   JVM:=path to ..bin/java
 403 #   ADD_JAVAC_FLAGS:=javac flags to append to the default ones.
 404 #   SRC:=one or more directories to search for sources. The order of the source roots
 405 #        is significant. The first found file of a certain name has priority.
 406 #   BIN:=store classes here
 407 #   INCLUDES:=myapp.foo means will only compile java files in myapp.foo or any of its sub-packages.
 408 #   EXCLUDES:=myapp.foo means will do not compile java files in myapp.foo or any of its sub-packages.
 409 #   COPY:=.prp means copy all prp files to the corresponding package in BIN.
 410 #   COPY_FILES:=myapp/foo/setting.txt means copy this file over to the package myapp/foo
 411 #   CLEAN:=.properties means copy and clean all properties file to the corresponding package in BIN.
 412 #   CLEAN_FILES:=myapp/foo/setting.txt means clean this file over to the package myapp/foo
 413 #   SRCZIP:=Create a src.zip based on the found sources and copied files.
 414 #   INCLUDE_FILES:="com/sun/SolarisFoobar.java" means only compile this file!
 415 #   EXCLUDE_FILES:="com/sun/SolarisFoobar.java" means do not compile this particular file!
 416 #       "SolarisFoobar.java" means do not compile SolarisFoobar, wherever it is found.
 417 #   HEADERS:=path to directory where all generated c-headers are written.
 418 #   DEPENDS:=Extra dependecy
 419 #   DISABLE_SJAVAC:=Explicitly disable the use of sjavac for this compilation unit.
 420 SetupJavaCompilation = $(NamedParamsMacroTemplate)
 421 define SetupJavaCompilationBody
 422 
 423   # Verify arguments
 424   ifeq ($$($1_BIN),)
 425     $$(error Must specify BIN (in $1))
 426   endif
 427 
 428   # Extract the info from the java compiler setup.
 429   $1_JVM := $$($$($1_SETUP)_JVM)
 430   $1_JAVAC := $$($$($1_SETUP)_JAVAC)
 431   $1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS)
 432   ifeq ($$($1_JAVAC),)
 433     $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP))
 434   endif
 435   $1_SJAVAC_PORTFILE := $$($$($1_SETUP)_SJAVAC_PORTFILE)
 436   $1_SERVER_JVM := $$($$($1_SETUP)_SERVER_JVM)
 437 
 438   # Handle addons and overrides.
 439   $1_SRC:=$$(call ADD_SRCS,$$($1_SRC))
 440   # Make sure the dirs exist.
 441   $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory >$$d<)))
 442   $$(call MakeDir,$$($1_BIN))
 443   # Add all source roots to the find cache since we are likely going to run find
 444   # on these more than once. The cache will only be updated if necessary.
 445   $$(eval $$(call FillCacheFind,$$($1_SRC)))
 446   # Find all files in the source trees. Preserve order of source roots for overrides to
 447   # work correctly. CacheFind does not preserve order so need to call it for each root.
 448   $1_ALL_SRCS += $$(filter-out $(OVR_SRCS),$$(foreach s,$$($1_SRC),$$(call CacheFind,$$(s))))
 449   # Extract the java files.
 450   ifneq ($$($1_EXCLUDE_FILES),)
 451     $1_EXCLUDE_FILES_PATTERN:=$$(addprefix %,$$($1_EXCLUDE_FILES))
 452   endif
 453   $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$(filter %.java,$$($1_ALL_SRCS)))
 454   ifneq ($$($1_INCLUDE_FILES),)
 455     $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES)))
 456     $1_SRCS := $$(filter $$($1_INCLUDE_FILES), $$($1_SRCS))
 457   endif
 458 









 459   # Prepend the source/bin path to the filter expressions.
 460   ifneq ($$($1_INCLUDES),)
 461     $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES))))
 462     $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS))
 463   endif
 464   ifneq ($$($1_EXCLUDES),)
 465     $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
 466     $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS))
 467   endif
 468 
 469   # Remove duplicate source files by keeping the first found of each duplicate.
 470   # This allows for automatic overrides with custom or platform specific versions
 471   # source files.
 472   #
 473   # For the smart javac wrapper case, add each removed file to an extra exclude
 474   # file list to prevent sjavac from finding duplicate sources.
 475   $1_SRCS := $$(strip $$(foreach s, $$($1_SRCS), \
 476       $$(eval relative_src := $$(call remove-prefixes, $$($1_SRC), $$(s))) \
 477       $$(if $$($1_$$(relative_src)), \
 478         $$(eval $1_SJAVAC_EXCLUDE_FILES += $$(s)), \
 479         $$(eval $1_$$(relative_src) := 1) $$(s))))
 480 
 481  # Create the corresponding smart javac wrapper command line.
 482   $1_SJAVAC_ARGS:=$$(addprefix -x ,$$(addsuffix /*,$$($1_EXCLUDES))) \
 483       $$(addprefix -i ,$$(addsuffix /*,$$($1_INCLUDES))) \
 484       $$(addprefix -xf *,$$(strip $$($1_EXCLUDE_FILES) $$($1_SJAVAC_EXCLUDE_FILES))) \
 485       $$(addprefix -if *,$$(strip $$($1_INCLUDE_FILES))) \
 486       -src "$$(subst $$(SPACE),$$(PATH_SEP),$$(strip $$($1_SRC)))"
 487 
 488   # All files below META-INF are always copied.
 489   $1_ALL_COPIES := $$(filter $$(addsuffix /META-INF%,$$($1_SRC)),$$($1_ALL_SRCS))
 490   # Find all files to be copied from source to bin.
 491   ifneq (,$$($1_COPY)$$($1_COPY_FILES))
 492     # Search for all files to be copied.
 493     $1_ALL_COPIES += $$(filter $$(addprefix %,$$($1_COPY)),$$($1_ALL_SRCS))
 494     # Copy these explicitly
 495     $1_ALL_COPIES += $$($1_COPY_FILES)
 496   endif
 497   # Copy must also respect filters.
 498   ifneq (,$$($1_INCLUDES))
 499     $1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES))
 500   endif
 501   ifneq (,$$($1_EXCLUDES))
 502     $1_ALL_COPIES := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_COPIES))
 503   endif
 504   ifneq (,$$($1_EXCLUDE_FILES))
 505     $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES))
 506   endif


< prev index next >