< prev index next >

make/common/JavaCompilation.gmk

Print this page




 365         $(MKDIR) -p $$(@D)
 366         export LC_ALL=C ; $(CAT) $$< \
 367             | $(SED) -e 's/\([^\\]\):/\1\\:/g' -e 's/\([^\\]\)=/\1\\=/g' \
 368                 -e 's/\([^\\]\)!/\1\\!/g' -e 's/#.*/#/g' \
 369             | $(SED) -f "$(SRC_ROOT)/make/common/support/unicode2x.sed" \
 370             | $(SED) -e '/^#/d' -e '/^$$$$/d' \
 371                 -e :a -e '/\\$$$$/N; s/\\\n//; ta' \
 372                 -e 's/^[        ]*//;s/[        ]*$$$$//' \
 373                 -e 's/\\=/=/' \
 374             | $(SORT) > $$@
 375         $(CHMOD) -f ug+w $$@
 376 
 377   # And do not forget this target
 378   $1_ALL_COPY_CLEAN_TARGETS += $$($1_BIN)$$($2_TARGET)
 379 endef
 380 
 381 define remove_string
 382   $2 := $$(subst $1,,$$($2))
 383 endef
 384 
 385 define replace_space_with_pathsep
 386   $1:=$(subst $(SPACE),$(PATH_SEP),$(strip $(patsubst %,%,$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 #   JAVAC_SOURCE_PATH_OVERRIDE:=This forces an explicit -sourcepath to javac instead of the complete
 412 #       source roots from SRC. This is sometimes needed when compiling specific subsets of the source.
 413 #   HEADERS:=path to directory where all generated c-headers are written.
 414 #   DEPENDS:=Extra dependecy
 415 #   DISABLE_SJAVAC:=Explicitly disable the use of sjavac for this compilation unit.
 416 define SetupJavaCompilation
 417   $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompilation, please update JavaCompilation.gmk))
 418   $(call EvalDebugWrapper,$(strip $1),$(call SetupJavaCompilationInner,$(strip $1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)))
 419 endef
 420 
 421 define SetupJavaCompilationInner
 422   $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
 423   $(call LogSetupMacroEntry,SetupJavaCompilation($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
 424   $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompilation, please update JavaCompilation.gmk))
 425 
 426   # Extract the info from the java compiler setup.
 427   $1_JVM := $$($$($1_SETUP)_JVM)
 428   $1_JAVAC := $$($$($1_SETUP)_JAVAC)
 429   $1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS)
 430   ifeq ($$($1_JAVAC),)
 431     $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP))
 432   endif


 506     # Clean these explicitly
 507     $1_ALL_CLEANS += $$($1_CLEAN_FILES)
 508     # Copy and clean must also respect filters.
 509     ifneq (,$$($1_INCLUDES))
 510       $1_ALL_CLEANS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_CLEANS))
 511     endif
 512     ifneq (,$$($1_EXCLUDES))
 513       $1_ALL_CLEANS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_CLEANS))
 514     endif
 515     ifneq (,$$($1_EXCLUDE_FILES))
 516       $1_ALL_CLEANS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_CLEANS))
 517     endif
 518     ifneq (,$$($1_ALL_CLEANS))
 519       # Yep, there are files to be copied and cleaned!
 520       $1_ALL_COPY_CLEAN_TARGETS:=
 521           $$(foreach i,$$($1_ALL_CLEANS),$$(eval $$(call add_file_to_clean,$1,$$i)))
 522       # Now we can depend on $$($1_ALL_COPY_CLEAN_TARGETS) to copy all files!
 523     endif
 524   endif
 525 
 526   # Prep the source paths.
 527   ifneq ($$($1_JAVAC_SOURCE_PATH_OVERRIDE),)
 528     $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_JAVAC_SOURCE_PATH_OVERRIDE)))
 529   else
 530     $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_SRC)))
 531   endif
 532 
 533   # Create a sed expression to remove the source roots and to replace / with .
 534   # and remove .java at the end.
 535   $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g'
 536 
 537   ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes)
 538     ifneq (,$$($1_HEADERS))
 539       $1_HEADERS_ARG := -h $$($1_HEADERS)
 540     endif
 541 
 542     # Using sjavac to compile.
 543     $1_COMPILE_TARGETS := $$($1_BIN)/_the.$1_batch
 544 
 545     # Create SJAVAC variable form JAVAC variable. Expects $1_JAVAC to be
 546     # "bootclasspathprepend -cp .../javac.jar com.sun.tools.javac.Main"
 547     # and javac is simply replaced with sjavac.
 548     $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC))
 549 
 550     # Set the $1_REMOTE to spawn a background javac server.
 551     $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC))))
 552 


 595                   for f in `ls $$($1_HEADERS).$1.tmp`; do \
 596                     if [ ! -f "$$($1_HEADERS)/$$$$f" ] \
 597                         || [ "`$(DIFF) $$($1_HEADERS)/$$$$f $$($1_HEADERS).$1.tmp/$$$$f`" != "" ]; then \
 598                     $(CP) -f $$($1_HEADERS).$1.tmp/$$$$f $$($1_HEADERS)/$$$$f; \
 599                   fi; \
 600                   done; \
 601                 fi
 602                 $(RM) -r $$($1_HEADERS).$1.tmp
 603                 $(TOUCH) $$@
 604 
 605       $1_HEADER_TARGETS := $$($1_HEADERS)/_the.$1_headers
 606     endif
 607 
 608     # When not using sjavac, pass along all sources to javac using an @file.
 609     $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS)
 610         $(MKDIR) -p $$(@D)
 611         $(RM) $$($1_BIN)/_the.$1_batch $$($1_BIN)/_the.$1_batch.tmp
 612         $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp)
 613         $(ECHO) Compiling `$(WC) $$($1_BIN)/_the.$1_batch.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files for $1
 614         ($$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) \
 615             -implicit:none -sourcepath "$$($1_SRCROOTSC)" \
 616             -d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_BIN)/_the.$1_batch.tmp && \
 617         $(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch)
 618 
 619   endif
 620 
 621   # Add all targets to main variable
 622   $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_COMPILE_TARGETS) \
 623       $$($1_HEADER_TARGETS)
 624 
 625   # Check if a jar file was specified, then setup the rules for the jar.
 626   ifneq (,$$($1_JAR))
 627     # If no suffixes was explicitly set for this jar file.
 628     # Use class and the cleaned/copied properties file suffixes as the default
 629     # for the types of files to be put into the jar.
 630     ifeq (,$$($1_SUFFIXES))
 631       $1_SUFFIXES:=.class $$($1_CLEAN) $$($1_COPY)
 632     endif
 633 
 634     $$(eval $$(call SetupArchive,ARCHIVE_$1,$$($1), \
 635         SRCS:=$$($1_BIN), \




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




 385 # Setup make rules for compiling Java source code to class files and/or a
 386 # resulting jar file.
 387 #
 388 # Parameter 1 is the name of the rule. This name is used as variable prefix,
 389 # and the targets generated are listed in a variable by that name.
 390 #
 391 # Remaining parameters are named arguments. These include:
 392 #   SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC
 393 #   JVM:=path to ..bin/java
 394 #   ADD_JAVAC_FLAGS:=javac flags to append to the default ones.
 395 #   SRC:=one or more directories to search for sources
 396 #   BIN:=store classes here
 397 #   INCLUDES:=myapp.foo means will only compile java files in myapp.foo or any of its sub-packages.
 398 #   EXCLUDES:=myapp.foo means will do not compile java files in myapp.foo or any of its sub-packages.
 399 #   COPY:=.prp means copy all prp files to the corresponding package in BIN.
 400 #   COPY_FILES:=myapp/foo/setting.txt means copy this file over to the package myapp/foo
 401 #   CLEAN:=.properties means copy and clean all properties file to the corresponding package in BIN.
 402 #   CLEAN_FILES:=myapp/foo/setting.txt means clean this file over to the package myapp/foo
 403 #   SRCZIP:=Create a src.zip based on the found sources and copied files.
 404 #   INCLUDE_FILES:="com/sun/SolarisFoobar.java" means only compile this file!
 405 #   EXCLUDE_FILES:="com/sun/SolarisFoobar.java" means do not compile this particular file!
 406 #       "SolarisFoobar.java" means do not compile SolarisFoobar, wherever it is found.


 407 #   HEADERS:=path to directory where all generated c-headers are written.
 408 #   DEPENDS:=Extra dependecy
 409 #   DISABLE_SJAVAC:=Explicitly disable the use of sjavac for this compilation unit.
 410 define SetupJavaCompilation
 411   $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompilation, please update JavaCompilation.gmk))
 412   $(call EvalDebugWrapper,$(strip $1),$(call SetupJavaCompilationInner,$(strip $1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)))
 413 endef
 414 
 415 define SetupJavaCompilationInner
 416   $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
 417   $(call LogSetupMacroEntry,SetupJavaCompilation($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
 418   $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompilation, please update JavaCompilation.gmk))
 419 
 420   # Extract the info from the java compiler setup.
 421   $1_JVM := $$($$($1_SETUP)_JVM)
 422   $1_JAVAC := $$($$($1_SETUP)_JAVAC)
 423   $1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS)
 424   ifeq ($$($1_JAVAC),)
 425     $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP))
 426   endif


 500     # Clean these explicitly
 501     $1_ALL_CLEANS += $$($1_CLEAN_FILES)
 502     # Copy and clean must also respect filters.
 503     ifneq (,$$($1_INCLUDES))
 504       $1_ALL_CLEANS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_CLEANS))
 505     endif
 506     ifneq (,$$($1_EXCLUDES))
 507       $1_ALL_CLEANS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_CLEANS))
 508     endif
 509     ifneq (,$$($1_EXCLUDE_FILES))
 510       $1_ALL_CLEANS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_CLEANS))
 511     endif
 512     ifneq (,$$($1_ALL_CLEANS))
 513       # Yep, there are files to be copied and cleaned!
 514       $1_ALL_COPY_CLEAN_TARGETS:=
 515           $$(foreach i,$$($1_ALL_CLEANS),$$(eval $$(call add_file_to_clean,$1,$$i)))
 516       # Now we can depend on $$($1_ALL_COPY_CLEAN_TARGETS) to copy all files!
 517     endif
 518   endif
 519 







 520   # Create a sed expression to remove the source roots and to replace / with .
 521   # and remove .java at the end.
 522   $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g'
 523 
 524   ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes)
 525     ifneq (,$$($1_HEADERS))
 526       $1_HEADERS_ARG := -h $$($1_HEADERS)
 527     endif
 528 
 529     # Using sjavac to compile.
 530     $1_COMPILE_TARGETS := $$($1_BIN)/_the.$1_batch
 531 
 532     # Create SJAVAC variable form JAVAC variable. Expects $1_JAVAC to be
 533     # "bootclasspathprepend -cp .../javac.jar com.sun.tools.javac.Main"
 534     # and javac is simply replaced with sjavac.
 535     $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC))
 536 
 537     # Set the $1_REMOTE to spawn a background javac server.
 538     $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC))))
 539 


 582                   for f in `ls $$($1_HEADERS).$1.tmp`; do \
 583                     if [ ! -f "$$($1_HEADERS)/$$$$f" ] \
 584                         || [ "`$(DIFF) $$($1_HEADERS)/$$$$f $$($1_HEADERS).$1.tmp/$$$$f`" != "" ]; then \
 585                     $(CP) -f $$($1_HEADERS).$1.tmp/$$$$f $$($1_HEADERS)/$$$$f; \
 586                   fi; \
 587                   done; \
 588                 fi
 589                 $(RM) -r $$($1_HEADERS).$1.tmp
 590                 $(TOUCH) $$@
 591 
 592       $1_HEADER_TARGETS := $$($1_HEADERS)/_the.$1_headers
 593     endif
 594 
 595     # When not using sjavac, pass along all sources to javac using an @file.
 596     $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS)
 597         $(MKDIR) -p $$(@D)
 598         $(RM) $$($1_BIN)/_the.$1_batch $$($1_BIN)/_the.$1_batch.tmp
 599         $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp)
 600         $(ECHO) Compiling `$(WC) $$($1_BIN)/_the.$1_batch.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files for $1
 601         ($$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) \
 602             -implicit:none \
 603             -d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_BIN)/_the.$1_batch.tmp && \
 604         $(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch)
 605 
 606   endif
 607 
 608   # Add all targets to main variable
 609   $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_COMPILE_TARGETS) \
 610       $$($1_HEADER_TARGETS)
 611 
 612   # Check if a jar file was specified, then setup the rules for the jar.
 613   ifneq (,$$($1_JAR))
 614     # If no suffixes was explicitly set for this jar file.
 615     # Use class and the cleaned/copied properties file suffixes as the default
 616     # for the types of files to be put into the jar.
 617     ifeq (,$$($1_SUFFIXES))
 618       $1_SUFFIXES:=.class $$($1_CLEAN) $$($1_COPY)
 619     endif
 620 
 621     $$(eval $$(call SetupArchive,ARCHIVE_$1,$$($1), \
 622         SRCS:=$$($1_BIN), \


< prev index next >