30 # |
30 # |
31 ################################################################ |
31 ################################################################ |
32 |
32 |
33 ifndef _MAKEBASE_GMK |
33 ifndef _MAKEBASE_GMK |
34 _MAKEBASE_GMK := 1 |
34 _MAKEBASE_GMK := 1 |
|
35 |
|
36 ################################################################################ |
|
37 # This macro translates $ into \$ to protect the $ from expansion in the shell. |
|
38 # To make this macro resilient against already escaped strings, first remove |
|
39 # any present escapes before escaping so that no double escapes are added. |
|
40 EscapeDollar = $(subst $$,\$$,$(subst \$$,$$,$(strip $1))) |
|
41 |
|
42 ################################################################################ |
|
43 # This macro translates $ into $$ to protect the string from make itself. |
|
44 DoubleDollar = $(subst $$,$$$$,$(strip $1)) |
|
45 |
|
46 ################################################################################ |
35 |
47 |
36 # If the variable that you want to send to stdout for piping into a file or otherwise, |
48 # If the variable that you want to send to stdout for piping into a file or otherwise, |
37 # is potentially long, for example the a list of file paths, eg a list of all package directories. |
49 # is potentially long, for example the a list of file paths, eg a list of all package directories. |
38 # Then you need to use ListPathsSafely, which optimistically splits the output into several shell |
50 # Then you need to use ListPathsSafely, which optimistically splits the output into several shell |
39 # calls as well as use compression on recurrent file paths segments, to get around the potential |
51 # calls as well as use compression on recurrent file paths segments, to get around the potential |
55 $(if $(word $3,$($1)),$(eval $1_LPS$3:=$(call compress_paths,$(wordlist $3,$4,$($1))))) |
67 $(if $(word $3,$($1)),$(eval $1_LPS$3:=$(call compress_paths,$(wordlist $3,$4,$($1))))) |
56 endef |
68 endef |
57 |
69 |
58 define ListPathsSafely_Printf |
70 define ListPathsSafely_Printf |
59 $(if $(strip $($1_LPS$4)),$(if $(findstring $(LOG_LEVEL),trace),,@)printf \ |
71 $(if $(strip $($1_LPS$4)),$(if $(findstring $(LOG_LEVEL),trace),,@)printf \ |
60 -- "$(strip $($1_LPS$4))\n" | $(decompress_paths) $3) |
72 -- "$(strip $(call EscapeDollar, $($1_LPS$4)))\n" | $(decompress_paths) $3) |
61 endef |
73 endef |
62 |
74 |
63 # Receipt example: |
75 # Receipt example: |
64 # rm -f thepaths |
76 # rm -f thepaths |
65 # $(call ListPathsSafely,THEPATHS,\n, >> thepaths) |
77 # $(call ListPathsSafely,THEPATHS,\n, >> thepaths) |
408 $(MKDIR) -p $(@D) |
420 $(MKDIR) -p $(@D) |
409 $(CP) -fRP '$<' '$@' |
421 $(CP) -fRP '$<' '$@' |
410 if [ -n "`$(XATTR) -l '$@'`" ]; then $(XATTR) -c '$@'; fi |
422 if [ -n "`$(XATTR) -l '$@'`" ]; then $(XATTR) -c '$@'; fi |
411 endef |
423 endef |
412 else |
424 else |
|
425 # Running mkdir and cp in the same shell speeds up copy intensive tasks in Cygwin |
|
426 # significantly. |
413 define install-file |
427 define install-file |
414 $(MKDIR) -p $(@D) |
428 $(MKDIR) -p $(@D) && $(CP) -fP '$<' '$@' |
415 $(CP) -fP '$<' '$@' |
|
416 endef |
429 endef |
417 endif |
430 endif |
418 |
431 |
419 # Convenience functions for working around make's limitations with $(filter ). |
432 # Convenience functions for working around make's limitations with $(filter ). |
420 containing = $(foreach v,$2,$(if $(findstring $1,$v),$v)) |
433 containing = $(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),$v))) |
421 not-containing = $(foreach v,$2,$(if $(findstring $1,$v),,$v)) |
434 not-containing = $(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),,$v))) |
|
435 |
|
436 # Filter out duplicate sub strings while preserving order. Keeps the first occurance. |
|
437 uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) |
422 |
438 |
423 ifneq ($(DISABLE_CACHE_FIND), true) |
439 ifneq ($(DISABLE_CACHE_FIND), true) |
424 ################################################################################ |
440 ################################################################################ |
425 # In Cygwin, finds are very costly, both because of expensive forks and because |
441 # In Cygwin, finds are very costly, both because of expensive forks and because |
426 # of bad file system caching. Find is used extensively in $(shell) commands to |
442 # of bad file system caching. Find is used extensively in $(shell) commands to |
455 |
471 |
456 # Mimics find by looking in the cache if all of the directories have been cached. |
472 # Mimics find by looking in the cache if all of the directories have been cached. |
457 # Otherwise reverts to shell find. This is safe to call on all platforms, even if |
473 # Otherwise reverts to shell find. This is safe to call on all platforms, even if |
458 # cache is deactivated. |
474 # cache is deactivated. |
459 # |
475 # |
|
476 # $1 can be either a directory or a file. If it's a directory, make |
|
477 # sure we have exactly one trailing slash before the wildcard. |
460 # The extra - is needed when FIND_CACHE_DIRS is empty but should be harmless. |
478 # The extra - is needed when FIND_CACHE_DIRS is empty but should be harmless. |
461 # |
479 # |
462 # Param 1 - Dirs to find in |
480 # Param 1 - Dirs to find in |
463 # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression. |
481 # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression. |
464 define CacheFind |
482 define CacheFind |
465 $(if $(filter-out $(addsuffix /%,- $(FIND_CACHE_DIRS)) $(FIND_CACHE_DIRS),$1), \ |
483 $(if $(filter-out $(addsuffix /%,- $(FIND_CACHE_DIRS)) $(FIND_CACHE_DIRS),$1), \ |
466 $(shell $(FIND) $1 \( -type f -o -type l \) $2), \ |
484 $(shell $(FIND) $1 \( -type f -o -type l \) $2), \ |
467 $(filter $(addsuffix %,$1),$(FIND_CACHE))) |
485 $(filter $(addsuffix /%,$(patsubst %/,%,$1)) $1,$(FIND_CACHE))) |
468 endef |
486 endef |
|
487 |
469 else |
488 else |
470 # If CacheFind is disabled, just run the find command. |
489 # If CacheFind is disabled, just run the find command. |
471 # Param 1 - Dirs to find in |
490 # Param 1 - Dirs to find in |
472 # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression. |
491 # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression. |
473 define CacheFind |
492 define CacheFind |
475 endef |
494 endef |
476 endif |
495 endif |
477 |
496 |
478 ################################################################################ |
497 ################################################################################ |
479 |
498 |
|
499 define AddFileToCopy |
|
500 # Helper macro for SetupCopyFiles |
|
501 # 1 : Source file |
|
502 # 2 : Dest file |
|
503 # 3 : Variable to add targets to |
|
504 # 4 : Macro to call for copy operation |
|
505 |
|
506 $2: $1 |
|
507 $(ECHO) $(LOG_INFO) Copying $$(patsubst $(OUTPUT_ROOT)/%,%,$$@) |
|
508 $$($$(strip $4)) |
|
509 |
|
510 $3 += $2 |
|
511 endef |
|
512 |
|
513 define SetupCopyFiles |
|
514 # param 1 is for example COPY_MYFILES |
|
515 # param 2,3,4,5 are named args. |
|
516 # SRC : Source root dir |
|
517 # DEST : Dest root dir |
|
518 # FILES : List of files to copy with absolute paths, or path relative to SRC. Must be in SRC. |
|
519 # FLATTEN : Set to flatten the directory structure in the DEST dir. |
|
520 # MACRO : Optionally override the default macro used for making the copy. Default is 'install-file' |
|
521 $(foreach i,2 3 4 5 6, $(if $($i),$1_$(strip $($i)))$(NEWLINE)) |
|
522 $(call LogSetupMacroEntry,SetupCopyFiles($1),$2,$3,$4,$5,$6) |
|
523 $(if $(7),$(error Internal makefile error: Too many arguments to SetupCopyFiles)) |
|
524 |
|
525 ifeq ($$($1_MACRO), ) |
|
526 $1_MACRO := install-file |
|
527 endif |
|
528 |
|
529 $$(foreach f, $$(patsubst $$($1_SRC)/%,%,$$($1_FILES)), \ |
|
530 $$(eval $$(call AddFileToCopy, $$($1_SRC)/$$f, \ |
|
531 $$($1_DEST)/$$(if $$($1_FLATTEN),$$(notdir $$f),$$f), $1, $$($1_MACRO)))) |
|
532 |
|
533 endef |
|
534 |
|
535 ################################################################################ |
|
536 # Module list macros |
|
537 |
|
538 ALL_TOP_SRC_DIRS := \ |
|
539 $(JDK_TOPDIR)/src \ |
|
540 $(LANGTOOLS_TOPDIR)/src \ |
|
541 $(CORBA_TOPDIR)/src \ |
|
542 $(JAXP_TOPDIR)/src \ |
|
543 $(JAXWS_TOPDIR)/src \ |
|
544 $(NASHORN_TOPDIR)/src \ |
|
545 # |
|
546 |
|
547 # There are snmp classes in the open but they are not included in OpenJDK |
|
548 JAVA_MODULES_FILTER := jdk.snmp |
|
549 |
|
550 # Find all modules with java sources by looking in the source dirs |
|
551 define FindJavaModules |
|
552 $(filter-out $(JAVA_MODULES_FILTER), $(sort $(notdir \ |
|
553 $(patsubst %/,%, $(dir $(patsubst %/,%, $(dir $(patsubst %/,%, $(dir \ |
|
554 $(wildcard $(patsubst %,%/*/share/classes/*, $(ALL_TOP_SRC_DIRS)) \ |
|
555 $(patsubst %,%/*/$(OPENJDK_TARGET_OS_API_DIR)/classes/*, $(ALL_TOP_SRC_DIRS)) \ |
|
556 $(patsubst %,%/*/$(OPENJDK_TARGET_OS)/classes/*, $(ALL_TOP_SRC_DIRS)))))))))))) |
|
557 endef |
|
558 |
|
559 MODULES_LIST_FILE := $(SRC_ROOT)/make/common/modules.list |
|
560 |
|
561 # Param 1: Module to find deps for |
|
562 define FindDepsForModule |
|
563 $(if $(filter-out java.base, $1), java.base $(filter-out jdk.scripting.nashorn, $(filter-out java.base, $(wordlist 2, 100, $(shell $(GREP) '^$(strip $1):' $(MODULES_LIST_FILE)))))) |
|
564 endef |
|
565 |
|
566 # Find all modules with source for the target platform. |
|
567 define FindAllModules |
|
568 $(sort $(filter-out closed demo sample, $(notdir $(patsubst %/,%, $(dir \ |
|
569 $(wildcard $(patsubst %, %/*/share, $(ALL_TOP_SRC_DIRS)) \ |
|
570 $(patsubst %, %/*/$(OPENJDK_TARGET_OS), $(ALL_TOP_SRC_DIRS)) \ |
|
571 $(patsubst %, %/*/$(OPENJDK_TARGET_OS_API_DIR), $(ALL_TOP_SRC_DIRS)))))))) |
|
572 endef |
|
573 |
|
574 ################################################################################ |
|
575 |
|
576 MAKE_DIR_LIST := $(JDK_TOPDIR)/make |
|
577 |
|
578 # Find all modules that has a makefile for a certain build phase |
|
579 # Param 1: Make subdir to look in |
|
580 # Param 2: File prefix to look for |
|
581 FindModulesWithMakefileFor = $(sort $(foreach d, $(MAKE_DIR_LIST), \ |
|
582 $(patsubst $d/$(strip $1)/$(strip $2)-%.gmk,%, \ |
|
583 $(wildcard $d/$(strip $1)/$(strip $2)-*.gmk)))) |
|
584 |
|
585 # Declare a recipe for calling such a makefile |
|
586 # Param 1: Module name |
|
587 # Param 2: Suffix for rule |
|
588 # Param 3: Make subdir |
|
589 # Param 4: Makefile prefix |
|
590 define DeclareRecipeForModuleMakefile |
|
591 $$(strip $1)-$$(strip $2): |
|
592 +($(CD) $$(dir $$(firstword $$(wildcard $$(addsuffix /$$(strip $3)/$$(strip $4)-$$(strip $1).gmk, \ |
|
593 $(MAKE_DIR_LIST))))) \ |
|
594 && $(MAKE) $(MAKE_ARGS) \ |
|
595 -f $$(strip $4)-$$(strip $1).gmk \ |
|
596 $$(addprefix -I, $$(wildcard $(MAKE_DIR_LIST) \ |
|
597 $$(addsuffix /$$(strip $3), $(MAKE_DIR_LIST))))) |
|
598 endef |
|
599 |
|
600 ################################################################################ |
|
601 |
|
602 # Hook to include the corresponding custom file, if present. |
|
603 $(eval $(call IncludeCustomExtension, , common/MakeBase.gmk)) |
|
604 |
480 endif # _MAKEBASE_GMK |
605 endif # _MAKEBASE_GMK |