make/common/MakeBase.gmk
author ihse
Thu, 17 Oct 2019 10:35:18 +0200
changeset 58663 11a574b352d0
parent 55292 f4b2d5b83ebf
child 58679 9c3209ff7550
permissions -rw-r--r--
8223998: Missing MakeDir in ExecuteWithLog Reviewed-by: tbell, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12258
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
     1
#
53484
8c296eedfb04 8217730: Split up MakeBase.gmk
ihse
parents: 52186
diff changeset
     2
# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
12258
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
     3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
     4
#
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
     5
# This code is free software; you can redistribute it and/or modify it
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
     6
# under the terms of the GNU General Public License version 2 only, as
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
     7
# published by the Free Software Foundation.  Oracle designates this
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
     8
# particular file as subject to the "Classpath" exception as provided
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
     9
# by Oracle in the LICENSE file that accompanied this code.
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    10
#
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    11
# This code is distributed in the hope that it will be useful, but WITHOUT
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    13
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    14
# version 2 for more details (a copy is included in the LICENSE file that
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    15
# accompanied this code).
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    16
#
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    17
# You should have received a copy of the GNU General Public License version
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    18
# 2 along with this work; if not, write to the Free Software Foundation,
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    20
#
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    21
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    22
# or visit www.oracle.com if you need additional information or have any
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    23
# questions.
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    24
#
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    25
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    26
################################################################
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    27
#
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    28
# Setup common utility functions.
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    29
#
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    30
################################################################
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    31
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    32
ifndef _MAKEBASE_GMK
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    33
_MAKEBASE_GMK := 1
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    34
29662
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    35
ifeq ($(wildcard $(SPEC)),)
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    36
  $(error MakeBase.gmk needs SPEC set to a proper spec.gmk)
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    37
endif
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    38
29861
cb5d893c3282 8077814: Add .DELETE_ON_ERROR to makefiles
erikj
parents: 29662
diff changeset
    39
# By defining this pseudo target, make will automatically remove targets
cb5d893c3282 8077814: Add .DELETE_ON_ERROR to makefiles
erikj
parents: 29662
diff changeset
    40
# if their recipe fails so that a rebuild is automatically triggered on the
cb5d893c3282 8077814: Add .DELETE_ON_ERROR to makefiles
erikj
parents: 29662
diff changeset
    41
# next make invocation.
cb5d893c3282 8077814: Add .DELETE_ON_ERROR to makefiles
erikj
parents: 29662
diff changeset
    42
.DELETE_ON_ERROR:
29662
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    43
32460
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    44
################################################################################
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    45
# Definitions for special characters
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    46
################################################################################
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    47
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    48
# When calling macros, the spaces between arguments are
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    49
# often semantically important! Sometimes we need to subst
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    50
# spaces and commas, therefore we need the following macros.
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    51
X:=
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    52
SPACE:=$(X) $(X)
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    53
COMMA:=,
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    54
DOLLAR:=$$
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    55
HASH:=\#
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    56
LEFT_PAREN:=(
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    57
RIGHT_PAREN:=)
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    58
SQUOTE:='
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    59
#'
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    60
DQUOTE:="
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    61
#"
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    62
define NEWLINE
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    63
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    64
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    65
endef
9e9bffb3029a 8065912: Better handling of classpath in build-infra
ihse
parents: 32344
diff changeset
    66
54380
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
    67
# Certain features only work in newer version of GNU Make. The build will still
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
    68
# function in 3.81, but will be less performant.
32807
20386e6d858f 8136385: Various build speed improvements for windows
erikj
parents: 32553
diff changeset
    69
ifeq (4.0, $(firstword $(sort 4.0 $(MAKE_VERSION))))
20386e6d858f 8136385: Various build speed improvements for windows
erikj
parents: 32553
diff changeset
    70
  HAS_FILE_FUNCTION := true
49270
f6ad4d73c834 8199884: JDK-8199749 broke build with make 3.81
erikj
parents: 49244
diff changeset
    71
  CORRECT_FUNCTION_IN_RECIPE_EVALUATION := true
54380
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
    72
  RWILDCARD_WORKS := true
32807
20386e6d858f 8136385: Various build speed improvements for windows
erikj
parents: 32553
diff changeset
    73
endif
20386e6d858f 8136385: Various build speed improvements for windows
erikj
parents: 32553
diff changeset
    74
29662
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    75
53484
8c296eedfb04 8217730: Split up MakeBase.gmk
ihse
parents: 52186
diff changeset
    76
# For convenience, MakeBase.gmk continues to include these separate files, at
8c296eedfb04 8217730: Split up MakeBase.gmk
ihse
parents: 52186
diff changeset
    77
# least for now.
30095
0034766ccb09 8079344: Allow custom or platform specific java source to automatically override shared source
erikj
parents: 29866
diff changeset
    78
53484
8c296eedfb04 8217730: Split up MakeBase.gmk
ihse
parents: 52186
diff changeset
    79
include $(TOPDIR)/make/common/Utils.gmk
8c296eedfb04 8217730: Split up MakeBase.gmk
ihse
parents: 52186
diff changeset
    80
include $(TOPDIR)/make/common/MakeIO.gmk
8c296eedfb04 8217730: Split up MakeBase.gmk
ihse
parents: 52186
diff changeset
    81
include $(TOPDIR)/make/common/CopyFiles.gmk
29662
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    82
53484
8c296eedfb04 8217730: Split up MakeBase.gmk
ihse
parents: 52186
diff changeset
    83
################################################################################
8c296eedfb04 8217730: Split up MakeBase.gmk
ihse
parents: 52186
diff changeset
    84
# Functions for timers
8c296eedfb04 8217730: Split up MakeBase.gmk
ihse
parents: 52186
diff changeset
    85
################################################################################
29662
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    86
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    87
# Store the build times in this directory.
47253
92fd0e04e0e1 8187544: Replace BUILD_OUTPUT and OUTPUT_ROOT with OUTPUTDIR
ihse
parents: 47217
diff changeset
    88
BUILDTIMESDIR=$(OUTPUTDIR)/make-support/build-times
29662
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    89
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    90
# Record starting time for build of a sub repository.
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    91
define RecordStartTime
35008
ef0cd710989f 8146403: Windows build can be faster
erikj
parents: 34596
diff changeset
    92
	$(DATE) '+%Y %m %d %H %M %S' | $(NAWK) '{ print $$1,$$2,$$3,$$4,$$5,$$6,($$4*3600+$$5*60+$$6) }' > $(BUILDTIMESDIR)/build_time_start_$(strip $1) && \
29662
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    93
	$(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_start_$(strip $1)_human_readable
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    94
endef
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    95
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    96
# Record ending time and calculate the difference and store it in a
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    97
# easy to read format. Handles builds that cross midnight. Expects
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    98
# that a build will never take 24 hours or more.
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
    99
define RecordEndTime
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   100
	$(DATE) '+%Y %m %d %H %M %S' | $(NAWK) '{ print $$1,$$2,$$3,$$4,$$5,$$6,($$4*3600+$$5*60+$$6) }' > $(BUILDTIMESDIR)/build_time_end_$(strip $1)
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   101
	$(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_end_$(strip $1)_human_readable
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   102
	$(ECHO) `$(CAT) $(BUILDTIMESDIR)/build_time_start_$(strip $1)` `$(CAT) $(BUILDTIMESDIR)/build_time_end_$(strip $1)` $1 | \
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   103
	    $(NAWK) '{ F=$$7; T=$$14; if (F > T) { T+=3600*24 }; D=T-F; H=int(D/3600); \
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   104
	    M=int((D-H*3600)/60); S=D-H*3600-M*60; printf("%02d:%02d:%02d %s\n",H,M,S,$$15); }' \
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   105
	    > $(BUILDTIMESDIR)/build_time_diff_$(strip $1)
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   106
endef
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   107
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   108
# Hook to be called when starting to execute a top-level target
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   109
define TargetEnter
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   110
	$(PRINTF) "## Starting $(patsubst %-only,%,$@)\n"
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   111
	$(call RecordStartTime,$(patsubst %-only,%,$@))
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   112
endef
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   113
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   114
# Hook to be called when finish executing a top-level target
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   115
define TargetExit
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   116
	$(call RecordEndTime,$(patsubst %-only,%,$@))
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   117
	$(PRINTF) "## Finished $(patsubst %-only,%,$@) (build time %s)\n\n" \
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   118
	    "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_$(patsubst %-only,%,$@) | $(CUT) -f 1 -d ' '`"
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   119
endef
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   120
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents: 23984
diff changeset
   121
################################################################################
42282
faf3b6722c44 8031567: Better model for storing source revision information
ihse
parents: 42134
diff changeset
   122
faf3b6722c44 8031567: Better model for storing source revision information
ihse
parents: 42134
diff changeset
   123
# A file containing a way to uniquely identify the source code revision that
faf3b6722c44 8031567: Better model for storing source revision information
ihse
parents: 42134
diff changeset
   124
# the build was created from
faf3b6722c44 8031567: Better model for storing source revision information
ihse
parents: 42134
diff changeset
   125
SOURCE_REVISION_TRACKER := $(SUPPORT_OUTPUTDIR)/src-rev/source-revision-tracker
faf3b6722c44 8031567: Better model for storing source revision information
ihse
parents: 42134
diff changeset
   126
faf3b6722c44 8031567: Better model for storing source revision information
ihse
parents: 42134
diff changeset
   127
# Locate all hg repositories included in the forest, as absolute paths
39110
712f29ba8708 8136771: Implement the license-swap logic as a make target
erikj
parents: 37972
diff changeset
   128
FindAllReposAbs = \
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 45369
diff changeset
   129
    $(strip $(sort $(dir $(filter-out $(TOPDIR)/build/%, $(wildcard \
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 45369
diff changeset
   130
        $(addprefix $(TOPDIR)/, .hg */.hg */*/.hg */*/*/.hg */*/*/*/.hg) \
51676
5a1be00ea4f6 8210283: Support git as an SCM alternative in the build
erikj
parents: 51069
diff changeset
   131
        $(addprefix $(TOPDIR)/, .git */.git */*/.git */*/*/.git */*/*/*/.git) \
39110
712f29ba8708 8136771: Implement the license-swap logic as a make target
erikj
parents: 37972
diff changeset
   132
    )))))
712f29ba8708 8136771: Implement the license-swap logic as a make target
erikj
parents: 37972
diff changeset
   133
42282
faf3b6722c44 8031567: Better model for storing source revision information
ihse
parents: 42134
diff changeset
   134
# Locate all hg repositories included in the forest, as relative paths
39110
712f29ba8708 8136771: Implement the license-swap logic as a make target
erikj
parents: 37972
diff changeset
   135
FindAllReposRel = \
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 45369
diff changeset
   136
    $(strip $(subst $(TOPDIR)/,.,$(patsubst $(TOPDIR)/%/, %, $(FindAllReposAbs))))
12801
948f8ad66ee7 7170079: Adjustments to build-infra makefiles
erikj
parents: 12258
diff changeset
   137
35008
ef0cd710989f 8146403: Windows build can be faster
erikj
parents: 34596
diff changeset
   138
################################################################################
ef0cd710989f 8146403: Windows build can be faster
erikj
parents: 34596
diff changeset
   139
12801
948f8ad66ee7 7170079: Adjustments to build-infra makefiles
erikj
parents: 12258
diff changeset
   140
define SetupLogging
44465
26fabd8abee9 8177770: Need more precise control on build system logging
asemenyuk
parents: 44027
diff changeset
   141
  ifeq ($$(LOG_PROFILE_TIMES_FILE), true)
26fabd8abee9 8177770: Need more precise control on build system logging
asemenyuk
parents: 44027
diff changeset
   142
    ifeq ($$(IS_GNU_TIME), yes)
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 45369
diff changeset
   143
      SHELL :=  $$(BASH) $$(TOPDIR)/make/scripts/shell-profiler.sh \
44465
26fabd8abee9 8177770: Need more precise control on build system logging
asemenyuk
parents: 44027
diff changeset
   144
                gnutime $$(TIME) \
47253
92fd0e04e0e1 8187544: Replace BUILD_OUTPUT and OUTPUT_ROOT with OUTPUTDIR
ihse
parents: 47217
diff changeset
   145
                $$(OUTPUTDIR)/build-profile.log $$(SHELL)
44465
26fabd8abee9 8177770: Need more precise control on build system logging
asemenyuk
parents: 44027
diff changeset
   146
    else ifneq ($$(FLOCK), )
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 45369
diff changeset
   147
      SHELL :=  $$(BASH) $$(TOPDIR)/make/scripts/shell-profiler.sh \
44465
26fabd8abee9 8177770: Need more precise control on build system logging
asemenyuk
parents: 44027
diff changeset
   148
                flock $$(FLOCK) \
47253
92fd0e04e0e1 8187544: Replace BUILD_OUTPUT and OUTPUT_ROOT with OUTPUTDIR
ihse
parents: 47217
diff changeset
   149
                $$(OUTPUTDIR)/build-profile.log $$(SHELL)
44465
26fabd8abee9 8177770: Need more precise control on build system logging
asemenyuk
parents: 44027
diff changeset
   150
    endif
26fabd8abee9 8177770: Need more precise control on build system logging
asemenyuk
parents: 44027
diff changeset
   151
  endif
26fabd8abee9 8177770: Need more precise control on build system logging
asemenyuk
parents: 44027
diff changeset
   152
29662
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   153
  ifeq ($$(LOG_LEVEL), trace)
44465
26fabd8abee9 8177770: Need more precise control on build system logging
asemenyuk
parents: 44027
diff changeset
   154
    SHELL_NO_RECURSE := $$(SHELL)
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   155
    # Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   156
    # For each target executed, will print
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   157
    # Building <TARGET> (from <FIRST PREREQUISITE>) (<ALL NEWER PREREQUISITES> newer)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   158
    # but with a limit of 20 on <ALL NEWER PREREQUISITES>, to avoid cluttering logs too much
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   159
    # (and causing a crash on Cygwin).
44465
26fabd8abee9 8177770: Need more precise control on build system logging
asemenyuk
parents: 44027
diff changeset
   160
    SHELL = $$(warning $$(if $$@,Building $$@,Running shell command) $$(if $$<, (from $$<))$$(if $$?, ($$(wordlist 1, 20, $$?) $$(if $$(wordlist 21, 22, $$?), ... [in total $$(words $$?) files]) newer)))$$(SHELL_NO_RECURSE) -x
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   161
  endif
44465
26fabd8abee9 8177770: Need more precise control on build system logging
asemenyuk
parents: 44027
diff changeset
   162
55292
f4b2d5b83ebf 8217739: Cannot reuse java.base UnixConstants.java from target in BuildJDK when cross compiling
erikj
parents: 55166
diff changeset
   163
  # The LOG_PREFIX is set for sub recursive calls like buildjdk and bootcycle.
35444
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   164
  # The warn level can never be turned off
55292
f4b2d5b83ebf 8217739: Cannot reuse java.base UnixConstants.java from target in BuildJDK when cross compiling
erikj
parents: 55166
diff changeset
   165
  LogWarn = $$(info $(LOG_PREFIX)$$(strip $$1))
29662
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   166
  LOG_WARN :=
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   167
  ifneq ($$(findstring $$(LOG_LEVEL), info debug trace),)
55292
f4b2d5b83ebf 8217739: Cannot reuse java.base UnixConstants.java from target in BuildJDK when cross compiling
erikj
parents: 55166
diff changeset
   168
    LogInfo = $$(info $(LOG_PREFIX)$$(strip $$1))
29662
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   169
    LOG_INFO :=
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   170
  else
34596
e8328ce5b64e 8142907: Integration of minor fixes from the build-infra project
ihse
parents: 33394
diff changeset
   171
    LogInfo =
29662
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   172
    LOG_INFO := > /dev/null
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   173
  endif
29662
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   174
  ifneq ($$(findstring $$(LOG_LEVEL), debug trace),)
55292
f4b2d5b83ebf 8217739: Cannot reuse java.base UnixConstants.java from target in BuildJDK when cross compiling
erikj
parents: 55166
diff changeset
   175
    LogDebug = $$(info $(LOG_PREFIX)$$(strip $$1))
29662
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   176
    LOG_DEBUG :=
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   177
  else
34596
e8328ce5b64e 8142907: Integration of minor fixes from the build-infra project
ihse
parents: 33394
diff changeset
   178
    LogDebug =
29662
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   179
    LOG_DEBUG := > /dev/null
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   180
  endif
29662
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   181
  ifneq ($$(findstring $$(LOG_LEVEL), trace),)
55292
f4b2d5b83ebf 8217739: Cannot reuse java.base UnixConstants.java from target in BuildJDK when cross compiling
erikj
parents: 55166
diff changeset
   182
    LogTrace = $$(info $(LOG_PREFIX)$$(strip $$1))
29662
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   183
    LOG_TRACE :=
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   184
  else
34596
e8328ce5b64e 8142907: Integration of minor fixes from the build-infra project
ihse
parents: 33394
diff changeset
   185
    LogTrace =
29662
78c47f0002c3 8076060: Improve make bootstrap process
ihse
parents: 29312
diff changeset
   186
    LOG_TRACE := > /dev/null
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   187
  endif
12801
948f8ad66ee7 7170079: Adjustments to build-infra makefiles
erikj
parents: 12258
diff changeset
   188
endef
948f8ad66ee7 7170079: Adjustments to build-infra makefiles
erikj
parents: 12258
diff changeset
   189
948f8ad66ee7 7170079: Adjustments to build-infra makefiles
erikj
parents: 12258
diff changeset
   190
# Make sure logging is setup for everyone that includes MakeBase.gmk.
948f8ad66ee7 7170079: Adjustments to build-infra makefiles
erikj
parents: 12258
diff changeset
   191
$(eval $(call SetupLogging))
948f8ad66ee7 7170079: Adjustments to build-infra makefiles
erikj
parents: 12258
diff changeset
   192
29312
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   193
################################################################################
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   194
49024
953b3fd36b08 8196997: VS2017 The non-Standard std::tr1 namespace and TR1-only machinery are deprecated and will be removed
lfoltan
parents: 48078
diff changeset
   195
MAX_PARAMS := 36
29312
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   196
PARAM_SEQUENCE := $(call sequence, 2, $(MAX_PARAMS))
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   197
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   198
# Template for creating a macro taking named parameters. To use it, assign the
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   199
# template to a variable with the name you want for your macro, using '='
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   200
# assignment. Then define a macro body with the suffix "Body". The Body macro
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   201
# should take 1 parameter which should be a unique string for that invocation
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   202
# of the macro.
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   203
# Ex:
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   204
# SetupFoo = $(NamedParamsMacroTemplate)
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   205
# define SetupFooBody
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   206
#   # do something
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   207
#   # access parameters as $$($1_BAR)
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   208
# endef
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   209
# Call it like this
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   210
# $(eval $(call SetupFoo, BUILD_SOMETHING, \
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   211
#     BAR := some parameter value, \
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   212
# ))
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   213
define NamedParamsMacroTemplate
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   214
  $(if $($(MAX_PARAMS)),$(error Internal makefile error: \
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   215
      Too many named arguments to macro, please update MAX_PARAMS in MakeBase.gmk))
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   216
  # Iterate over 2 3 4... and evaluate the named parameters with $1_ as prefix
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   217
  $(foreach i,$(PARAM_SEQUENCE), $(if $(strip $($i)),\
43044
6ff517127736 8171932: unresolved macro in javadoc command
erikj
parents: 42983
diff changeset
   218
    $(strip $1)_$(strip $(call EscapeHash, $(call DoubleDollar, $($i))))$(NEWLINE)))
29312
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   219
  # Debug print all named parameter names and values
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   220
  $(if $(findstring $(LOG_LEVEL),debug trace), \
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   221
    $(info $0 $(strip $1) $(foreach i,$(PARAM_SEQUENCE), \
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   222
      $(if $(strip $($i)),$(NEWLINE) $(strip [$i] $(if $(filter $(LOG_LEVEL), trace), \
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   223
        $($i), $(wordlist 1, 20, $($(i))) $(if $(word 21, $($(i))), ...)))))))
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   224
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   225
  $(if $(DEBUG_$(strip $1)),
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   226
    $(info -------- <<< Begin expansion of $(strip $1)) \
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   227
    $(info $(call $(0)Body,$(strip $1))) \
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   228
    $(info -------- >>> End expansion of $(strip $1)) \
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   229
  )
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   230
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   231
  $(call $(0)Body,$(strip $1))
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   232
endef
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   233
29312
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   234
################################################################################
47751
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   235
# Make directory without forking mkdir if not needed.
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   236
#
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   237
# If a directory with an encoded space is provided, the wildcard function
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   238
# sometimes returns false answers (typically if the dir existed when the
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   239
# makefile was parsed, but was deleted by a previous rule). In that case, always
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   240
# call mkdir regardless of what wildcard says.
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   241
#
35008
ef0cd710989f 8146403: Windows build can be faster
erikj
parents: 34596
diff changeset
   242
# 1: List of directories to create
28600
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   243
MakeDir = \
35444
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   244
    $(strip \
47751
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   245
        $(eval MakeDir_dirs_to_make := $(strip $(foreach d, $1, \
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   246
          $(if $(findstring ?, $d), '$(call DecodeSpace, $d)', \
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   247
            $(if $(wildcard $d), , $d) \
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   248
          ) \
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   249
        ))) \
35444
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   250
        $(if $(MakeDir_dirs_to_make), $(shell $(MKDIR) -p $(MakeDir_dirs_to_make))) \
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   251
    )
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   252
47751
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   253
# Make directory for target file. Should handle spaces in filenames. Just
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   254
# calling $(call MakeDir $(@D)) will not work if the directory contains a space
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   255
# and the target file already exists. In that case, the target file will have
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   256
# its wildcard ? resolved and the $(@D) will evaluate each space separated dir
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   257
# part on its own.
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   258
MakeTargetDir = \
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   259
    $(call MakeDir, $(dir $(call EncodeSpace, $@)))
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   260
29312
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   261
################################################################################
47334
09d386ddaa42 8189095: Import JMC from artifactory using Jib and main makefiles
erikj
parents: 47314
diff changeset
   262
# All install-file and related macros automatically call DecodeSpace when needed.
29312
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   263
53683
48ff68e2fe5c 8218431: Improved platform checking in makefiles
ihse
parents: 53484
diff changeset
   264
ifeq ($(call isTargetOs, solaris), true)
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   265
  # On Solaris, if the target is a symlink and exists, cp won't overwrite.
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   266
  # Cp has to operate in recursive mode to allow for -P flag, to preserve soft links. If the
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   267
  # name of the target file differs from the source file, rename after copy.
23168
d20a4165e3d2 8036948: Solaris builds broken by fix for 8036611: Cleanup of handling of properties ...
erikj
parents: 21759
diff changeset
   268
  # If the source and target parent directories are the same, recursive copy doesn't work
d20a4165e3d2 8036948: Solaris builds broken by fix for 8036611: Cleanup of handling of properties ...
erikj
parents: 21759
diff changeset
   269
  # so we fall back on regular copy, which isn't preserving symlinks.
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   270
  define install-file
47751
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   271
	$(call MakeTargetDir)
47348
504e70cd64ad 8189324: install-file macro no longer handles files with $ in them
erikj
parents: 47334
diff changeset
   272
	$(RM) '$(call DecodeSpace, $@)'
49205
d1a19a08389a 8199428: install-file macro fails on filenames with space on Solaris
erikj
parents: 49067
diff changeset
   273
	if [ '$(call DecodeSpace, $(dir $(call EncodeSpace, $@)))' != \
47348
504e70cd64ad 8189324: install-file macro no longer handles files with $ in them
erikj
parents: 47334
diff changeset
   274
	    '$(call DecodeSpace, $(dir $(call EncodeSpace, $<)))' ]; then \
49205
d1a19a08389a 8199428: install-file macro fails on filenames with space on Solaris
erikj
parents: 49067
diff changeset
   275
	  $(CP) -f -r -P '$(call DecodeSpace, $<)' \
d1a19a08389a 8199428: install-file macro fails on filenames with space on Solaris
erikj
parents: 49067
diff changeset
   276
	      '$(call DecodeSpace, $(dir $(call EncodeSpace, $@)))'; \
d1a19a08389a 8199428: install-file macro fails on filenames with space on Solaris
erikj
parents: 49067
diff changeset
   277
	  if [ '$(call DecodeSpace, $(notdir $(call EncodeSpace, $@)))' != \
47348
504e70cd64ad 8189324: install-file macro no longer handles files with $ in them
erikj
parents: 47334
diff changeset
   278
	      '$(call DecodeSpace, $(notdir $(call EncodeSpace, $(<))))' ]; then \
49205
d1a19a08389a 8199428: install-file macro fails on filenames with space on Solaris
erikj
parents: 49067
diff changeset
   279
	    $(MV) '$(call DecodeSpace, $(dir $(call EncodeSpace, $@))/$(notdir $(call EncodeSpace, $<)))' \
d1a19a08389a 8199428: install-file macro fails on filenames with space on Solaris
erikj
parents: 49067
diff changeset
   280
	        '$(call DecodeSpace, $@)'; \
23168
d20a4165e3d2 8036948: Solaris builds broken by fix for 8036611: Cleanup of handling of properties ...
erikj
parents: 21759
diff changeset
   281
	  fi; \
d20a4165e3d2 8036948: Solaris builds broken by fix for 8036611: Cleanup of handling of properties ...
erikj
parents: 21759
diff changeset
   282
	else \
47348
504e70cd64ad 8189324: install-file macro no longer handles files with $ in them
erikj
parents: 47334
diff changeset
   283
	  if [ -L '$(call DecodeSpace, $<)' ]; then \
23168
d20a4165e3d2 8036948: Solaris builds broken by fix for 8036611: Cleanup of handling of properties ...
erikj
parents: 21759
diff changeset
   284
	    $(ECHO) "Source file is a symlink and target is in the same directory: $< $@" ; \
d20a4165e3d2 8036948: Solaris builds broken by fix for 8036611: Cleanup of handling of properties ...
erikj
parents: 21759
diff changeset
   285
	    exit 1; \
d20a4165e3d2 8036948: Solaris builds broken by fix for 8036611: Cleanup of handling of properties ...
erikj
parents: 21759
diff changeset
   286
	  fi; \
47348
504e70cd64ad 8189324: install-file macro no longer handles files with $ in them
erikj
parents: 47334
diff changeset
   287
	  $(CP) -f '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'; \
23168
d20a4165e3d2 8036948: Solaris builds broken by fix for 8036611: Cleanup of handling of properties ...
erikj
parents: 21759
diff changeset
   288
	fi
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   289
  endef
53683
48ff68e2fe5c 8218431: Improved platform checking in makefiles
ihse
parents: 53484
diff changeset
   290
else ifeq ($(call isTargetOs, macosx), true)
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   291
  # On mac, extended attributes sometimes creep into the source files, which may later
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   292
  # cause the creation of ._* files which confuses testing. Clear these with xattr if
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   293
  # set. Some files get their write permissions removed after being copied to the
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   294
  # output dir. When these are copied again to images, xattr would fail. By only clearing
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   295
  # attributes when they are present, failing on this is avoided.
37972
e1fa5c2e62a0 8136777: Introduce bundle targets
erikj
parents: 37770
diff changeset
   296
  #
e1fa5c2e62a0 8136777: Introduce bundle targets
erikj
parents: 37770
diff changeset
   297
  # If copying a soft link to a directory, need to delete the target first to avoid
e1fa5c2e62a0 8136777: Introduce bundle targets
erikj
parents: 37770
diff changeset
   298
  # weird errors.
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   299
  define install-file
47751
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   300
	$(call MakeTargetDir)
47348
504e70cd64ad 8189324: install-file macro no longer handles files with $ in them
erikj
parents: 47334
diff changeset
   301
	$(RM) '$(call DecodeSpace, $@)'
48912
01237b276b8b 8198318: Make build comparisons clean again
ihse
parents: 48078
diff changeset
   302
        # Work around a weirdness with cp on Macosx. When copying a symlink, if
01237b276b8b 8198318: Make build comparisons clean again
ihse
parents: 48078
diff changeset
   303
        # the target of the link is write protected (e.g. 444), cp will add
01237b276b8b 8198318: Make build comparisons clean again
ihse
parents: 48078
diff changeset
   304
        # write permission for the user on the target file (644). Avoid this by
01237b276b8b 8198318: Make build comparisons clean again
ihse
parents: 48078
diff changeset
   305
        # using ln to create a new link instead.
01237b276b8b 8198318: Make build comparisons clean again
ihse
parents: 48078
diff changeset
   306
	if [ -h '$(call DecodeSpace, $<)' ]; then \
01237b276b8b 8198318: Make build comparisons clean again
ihse
parents: 48078
diff changeset
   307
	  $(LN) -s "`$(READLINK) '$(call DecodeSpace, $<)'`" '$(call DecodeSpace, $@)'; \
01237b276b8b 8198318: Make build comparisons clean again
ihse
parents: 48078
diff changeset
   308
	else \
01237b276b8b 8198318: Make build comparisons clean again
ihse
parents: 48078
diff changeset
   309
	  $(CP) -fRP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'; \
01237b276b8b 8198318: Make build comparisons clean again
ihse
parents: 48078
diff changeset
   310
	fi
01237b276b8b 8198318: Make build comparisons clean again
ihse
parents: 48078
diff changeset
   311
	if [ -n "`$(XATTR) -ls '$(call DecodeSpace, $@)'`" ]; then \
01237b276b8b 8198318: Make build comparisons clean again
ihse
parents: 48078
diff changeset
   312
	  $(XATTR) -cs '$(call DecodeSpace, $@)'; \
01237b276b8b 8198318: Make build comparisons clean again
ihse
parents: 48078
diff changeset
   313
	fi
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   314
  endef
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   315
else
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   316
  define install-file
47751
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   317
	$(call MakeTargetDir)
47348
504e70cd64ad 8189324: install-file macro no longer handles files with $ in them
erikj
parents: 47334
diff changeset
   318
	$(CP) -fP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 18425
diff changeset
   319
  endef
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   320
endif
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   321
42425
57cde06ae8d6 8141590: Cannot build Zero with devkit
erikj
parents: 42282
diff changeset
   322
# Variant of install file that does not preserve symlinks
57cde06ae8d6 8141590: Cannot build Zero with devkit
erikj
parents: 42282
diff changeset
   323
define install-file-nolink
47751
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   324
	$(call MakeTargetDir)
47348
504e70cd64ad 8189324: install-file macro no longer handles files with $ in them
erikj
parents: 47334
diff changeset
   325
	$(CP) -f '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'
42425
57cde06ae8d6 8141590: Cannot build Zero with devkit
erikj
parents: 42282
diff changeset
   326
endef
57cde06ae8d6 8141590: Cannot build Zero with devkit
erikj
parents: 42282
diff changeset
   327
29312
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   328
################################################################################
41658
14de1ab85d25 8062810: Examine src.zip in JDK image and decide if source classes should be organized by module
erikj
parents: 41260
diff changeset
   329
# link-file-* works similarly to install-file but creates a symlink instead.
14de1ab85d25 8062810: Examine src.zip in JDK image and decide if source classes should be organized by module
erikj
parents: 41260
diff changeset
   330
# There are two versions, either creating a relative or an absolute link. Be
14de1ab85d25 8062810: Examine src.zip in JDK image and decide if source classes should be organized by module
erikj
parents: 41260
diff changeset
   331
# careful when using this on Windows since the symlink created is only valid in
14de1ab85d25 8062810: Examine src.zip in JDK image and decide if source classes should be organized by module
erikj
parents: 41260
diff changeset
   332
# the unix emulation environment.
14de1ab85d25 8062810: Examine src.zip in JDK image and decide if source classes should be organized by module
erikj
parents: 41260
diff changeset
   333
define link-file-relative
47751
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   334
	$(call MakeTargetDir)
47348
504e70cd64ad 8189324: install-file macro no longer handles files with $ in them
erikj
parents: 47334
diff changeset
   335
	$(RM) '$(call DecodeSpace, $@)'
504e70cd64ad 8189324: install-file macro no longer handles files with $ in them
erikj
parents: 47334
diff changeset
   336
	$(LN) -s '$(call DecodeSpace, $(call RelativePath, $<, $(@D)))' '$(call DecodeSpace, $@)'
41658
14de1ab85d25 8062810: Examine src.zip in JDK image and decide if source classes should be organized by module
erikj
parents: 41260
diff changeset
   337
endef
41260
4f71f07b30d1 8150736: Excessive disk space used by build system
erikj
parents: 40241
diff changeset
   338
41658
14de1ab85d25 8062810: Examine src.zip in JDK image and decide if source classes should be organized by module
erikj
parents: 41260
diff changeset
   339
define link-file-absolute
47751
f7e430cbfe34 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents: 47715
diff changeset
   340
	$(call MakeTargetDir)
47348
504e70cd64ad 8189324: install-file macro no longer handles files with $ in them
erikj
parents: 47334
diff changeset
   341
	$(RM) '$(call DecodeSpace, $@)'
504e70cd64ad 8189324: install-file macro no longer handles files with $ in them
erikj
parents: 47334
diff changeset
   342
	$(LN) -s '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'
41658
14de1ab85d25 8062810: Examine src.zip in JDK image and decide if source classes should be organized by module
erikj
parents: 41260
diff changeset
   343
endef
41260
4f71f07b30d1 8150736: Excessive disk space used by build system
erikj
parents: 40241
diff changeset
   344
4f71f07b30d1 8150736: Excessive disk space used by build system
erikj
parents: 40241
diff changeset
   345
################################################################################
29312
f3f859137ce6 8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents: 29304
diff changeset
   346
54380
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   347
# Recursive wildcard function. Walks down directories recursively and matches
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   348
# files with the search patterns. Patterns use standard file wildcards (* and
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   349
# ?).
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   350
#
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   351
# $1 - Directories to start search in
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   352
# $2 - Search patterns
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   353
rwildcard = \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   354
    $(strip \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   355
        $(foreach d, \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   356
          $(patsubst %/,%,$(sort $(dir $(wildcard $(addsuffix /*/*, $(strip $1)))))), \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   357
          $(call rwildcard,$d,$2) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   358
        ) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   359
        $(call DoubleDollar, $(wildcard $(foreach p, $2, $(addsuffix /$(strip $p), $(strip $1))))) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   360
    )
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   361
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   362
# Find non directories using recursive wildcard function. This function may
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   363
# be used directly when a small amount of directories is expected to be
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   364
# searched and caching is not expected to be of use.
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   365
#
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   366
# $1 - Directory to start search in
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   367
# $2 - Optional search patterns, defaults to '*'.
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   368
WildcardFindFiles = \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   369
    $(sort $(strip \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   370
        $(eval WildcardFindFiles_result := $(call rwildcard,$(patsubst %/,%,$1),$(if $(strip $2),$2,*))) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   371
        $(filter-out $(patsubst %/,%,$(sort $(dir $(WildcardFindFiles_result)))), \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   372
            $(WildcardFindFiles_result) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   373
        ) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   374
    ))
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   375
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   376
# Find non directories using the find utility in the shell. Safe to call for
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   377
# non existing directories, or directories containing wildcards.
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   378
#
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   379
# Files containing space will get spaces replaced with ? because GNU Make
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   380
# cannot handle lists of files with space in them. By using ?, make will match
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   381
# the wildcard to space in many situations so we don't need to replace back
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   382
# to space on every use. While not a complete solution it does allow some uses
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   383
# of FindFiles to function with spaces in file names, including for
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   384
# SetupCopyFiles. Unfortunately this does not work for WildcardFindFiles so
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   385
# if files with spaces are anticipated, use ShellFindFiles directly.
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   386
#
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   387
# $1 - Directories to start search in.
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   388
# $2 - Optional search patterns, empty means find everything. Patterns use
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   389
#      standard file wildcards (* and ?) and should not be quoted.
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   390
# $3 - Optional options to find.
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   391
ShellFindFiles = \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   392
    $(if $(wildcard $1), \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   393
      $(sort \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   394
          $(shell $(FIND) $3 $(patsubst %/,%,$(wildcard $1)) \( -type f -o -type l \) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   395
              $(if $(strip $2), -a \( -name "$(firstword $2)" \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   396
              $(foreach p, $(filter-out $(firstword $2), $2), -o -name "$(p)") \)) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   397
              | $(TR) ' ' '?' \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   398
          ) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   399
      ) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   400
    )
15051
d32ad37472e6 8005540: build-infra: Improve incremental build speed on windows by caching find results
erikj
parents: 14279
diff changeset
   401
54380
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   402
# Find non directories using the method most likely to work best for the
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   403
# current build host
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   404
#
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   405
# $1 - Directory to start search in
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   406
# $2 - Optional search patterns, defaults to '*'.
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   407
ifeq ($(OPENJDK_BUILD_OS)-$(RWILDCARD_WORKS), windows-true)
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   408
  DirectFindFiles = $(WildcardFindFiles)
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   409
else
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   410
  DirectFindFiles = $(ShellFindFiles)
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   411
endif
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents: 23984
diff changeset
   412
54380
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   413
# Finds files using a cache that is populated by FillFindCache below. If any of
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   414
# the directories given have not been cached, DirectFindFiles is used for
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   415
# everything. Caching is especially useful in Cygwin, where file finds are very
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   416
# costly.
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   417
#
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   418
# $1 - Directories to start search in.
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   419
# $2 - Optional search patterns. If used, no caching is done.
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   420
CacheFindFiles_CACHED_DIRS :=
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   421
CacheFindFiles_CACHED_FILES :=
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   422
CacheFindFiles = \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   423
    $(if $2, \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   424
      $(call DirectFindFiles, $1, $2) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   425
    , \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   426
      $(if $(filter-out $(addsuffix /%, $(CacheFindFiles_CACHED_DIRS)) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   427
          $(CacheFindFiles_CACHED_DIRS), $1), \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   428
        $(call DirectFindFiles, $1) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   429
      , \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   430
        $(filter $(addsuffix /%,$(patsubst %/,%,$1)) $1,$(CacheFindFiles_CACHED_FILES)) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   431
      ) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   432
    )
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   433
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   434
# Explicitly adds files to the find cache used by CacheFindFiles.
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   435
#
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   436
# $1 - Directories to start search in
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   437
FillFindCache = \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   438
    $(eval CacheFindFiles_NEW_DIRS := $$(filter-out $$(addsuffix /%,\
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   439
        $$(CacheFindFiles_CACHED_DIRS)) $$(CacheFindFiles_CACHED_DIRS), $1)) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   440
    $(if $(CacheFindFiles_NEW_DIRS), \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   441
      $(eval CacheFindFiles_CACHED_DIRS += $$(patsubst %/,%,$$(CacheFindFiles_NEW_DIRS))) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   442
      $(eval CacheFindFiles_CACHED_FILES := $$(sort $$(CacheFindFiles_CACHED_FILES) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   443
          $$(call DirectFindFiles, $$(CacheFindFiles_NEW_DIRS)))) \
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   444
    )
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   445
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   446
# Findfiles is the default macro that should be used to find files in the file
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   447
# system. This function does not always support files with spaces in the names.
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   448
# If files with spaces are anticipated, use ShellFindFiles directly.
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   449
#
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   450
# $1 - Directories to start search in.
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   451
# $2 - Optional search patterns, empty means find everything. Patterns use
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   452
#      standard file wildcards (* and ?) and should not be quoted.
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   453
ifeq ($(DISABLE_CACHE_FIND), true)
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   454
  FindFiles = $(DirectFindFiles)
23170
51e606ecede5 8037281: Improve CacheFind and enable on all platforms
erikj
parents: 23169
diff changeset
   455
else
54380
e297c7bb6469 8189861: Refactor CacheFind
erikj
parents: 53829
diff changeset
   456
  FindFiles = $(CacheFindFiles)
23170
51e606ecede5 8037281: Improve CacheFind and enable on all platforms
erikj
parents: 23169
diff changeset
   457
endif
15051
d32ad37472e6 8005540: build-infra: Improve incremental build speed on windows by caching find results
erikj
parents: 14279
diff changeset
   458
d32ad37472e6 8005540: build-infra: Improve incremental build speed on windows by caching find results
erikj
parents: 14279
diff changeset
   459
################################################################################
44027
3a3050924db2 8176084: Developer-friendly run-test facility
ihse
parents: 43173
diff changeset
   460
# FixPath
3a3050924db2 8176084: Developer-friendly run-test facility
ihse
parents: 43173
diff changeset
   461
#
3a3050924db2 8176084: Developer-friendly run-test facility
ihse
parents: 43173
diff changeset
   462
# On Windows, converts a path from cygwin/unix style (e.g. /bin/foo) into
3a3050924db2 8176084: Developer-friendly run-test facility
ihse
parents: 43173
diff changeset
   463
# "mixed mode" (e.g. c:/cygwin/bin/foo). On other platforms, return the path
3a3050924db2 8176084: Developer-friendly run-test facility
ihse
parents: 43173
diff changeset
   464
# unchanged.
3a3050924db2 8176084: Developer-friendly run-test facility
ihse
parents: 43173
diff changeset
   465
# This is normally not needed since we use the FIXPATH prefix for command lines,
3a3050924db2 8176084: Developer-friendly run-test facility
ihse
parents: 43173
diff changeset
   466
# but might be needed in certain circumstances.
53683
48ff68e2fe5c 8218431: Improved platform checking in makefiles
ihse
parents: 53484
diff changeset
   467
ifeq ($(call isTargetOs, windows), true)
44027
3a3050924db2 8176084: Developer-friendly run-test facility
ihse
parents: 43173
diff changeset
   468
  FixPath = \
3a3050924db2 8176084: Developer-friendly run-test facility
ihse
parents: 43173
diff changeset
   469
      $(shell $(CYGPATH) -m $1)
3a3050924db2 8176084: Developer-friendly run-test facility
ihse
parents: 43173
diff changeset
   470
else
3a3050924db2 8176084: Developer-friendly run-test facility
ihse
parents: 43173
diff changeset
   471
  FixPath = \
3a3050924db2 8176084: Developer-friendly run-test facility
ihse
parents: 43173
diff changeset
   472
      $1
3a3050924db2 8176084: Developer-friendly run-test facility
ihse
parents: 43173
diff changeset
   473
endif
3a3050924db2 8176084: Developer-friendly run-test facility
ihse
parents: 43173
diff changeset
   474
3a3050924db2 8176084: Developer-friendly run-test facility
ihse
parents: 43173
diff changeset
   475
################################################################################
55166
2ae056696b15 8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents: 54380
diff changeset
   476
# FixPathList
2ae056696b15 8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents: 54380
diff changeset
   477
#
2ae056696b15 8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents: 54380
diff changeset
   478
# On Windows, converts a cygwin/unix style path list (colon-separated) into
2ae056696b15 8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents: 54380
diff changeset
   479
# the native format (mixed mode, semicolon-separated). On other platforms,
2ae056696b15 8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents: 54380
diff changeset
   480
# return the path list unchanged.
2ae056696b15 8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents: 54380
diff changeset
   481
################################################################################
2ae056696b15 8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents: 54380
diff changeset
   482
ifeq ($(call isTargetOs, windows), true)
2ae056696b15 8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents: 54380
diff changeset
   483
  FixPathList = \
2ae056696b15 8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents: 54380
diff changeset
   484
      $(subst @,$(SPACE),$(subst $(SPACE),;,$(foreach entry,$(subst :,$(SPACE),\
2ae056696b15 8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents: 54380
diff changeset
   485
      $(subst $(SPACE),@,$(strip $1))),$(call FixPath, $(entry)))))
2ae056696b15 8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents: 54380
diff changeset
   486
else
2ae056696b15 8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents: 54380
diff changeset
   487
  FixPathList = \
2ae056696b15 8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents: 54380
diff changeset
   488
      $1
2ae056696b15 8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents: 54380
diff changeset
   489
endif
2ae056696b15 8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents: 54380
diff changeset
   490
2ae056696b15 8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents: 54380
diff changeset
   491
################################################################################
28600
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   492
# DependOnVariable
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   493
#
29156
bd932374081c 8072842: Add support for building native JTReg tests
ihse
parents: 28906
diff changeset
   494
# This macro takes a variable name and puts the value in a file only if the
bd932374081c 8072842: Add support for building native JTReg tests
ihse
parents: 28906
diff changeset
   495
# value has changed since last. The name of the file is returned. This can be
28600
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   496
# used to create rule dependencies on make variable values. The following
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   497
# example would get rebuilt if the value of SOME_VAR was changed:
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   498
#
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   499
# path/to/some-file: $(call DependOnVariable, SOME_VAR)
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   500
#         echo $(SOME_VAR) > $@
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   501
#
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   502
# Note that leading and trailing white space in the value is ignored.
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   503
#
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   504
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   505
# Defines the sub directory structure to store variable value file in
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   506
DependOnVariableDirName = \
36506
17612cee3530 8142968: Module System implementation
alanb
parents: 36169
diff changeset
   507
    $(strip $(addsuffix $(if $(MODULE),/$(MODULE)), \
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 45369
diff changeset
   508
        $(subst $(TOPDIR)/,, $(if $(filter /%, $(firstword $(MAKEFILE_LIST))), \
28600
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   509
          $(firstword $(MAKEFILE_LIST)), \
36506
17612cee3530 8142968: Module System implementation
alanb
parents: 36169
diff changeset
   510
          $(CURDIR)/$(firstword $(MAKEFILE_LIST))))))
28600
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   511
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   512
# Defines the name of the file to store variable value in. Generates a name
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   513
# unless parameter 2 is given.
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   514
# Param 1 - Name of variable
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   515
# Param 2 - (optional) name of file to store value in
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   516
DependOnVariableFileName = \
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   517
    $(strip $(if $(strip $2), $2, \
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   518
      $(MAKESUPPORT_OUTPUTDIR)/vardeps/$(DependOnVariableDirName)/$(strip $1).vardeps))
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   519
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   520
# Does the actual work with parameters stripped.
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   521
# If the file exists AND the contents is the same as the variable, do nothing
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   522
# else print a new file.
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   523
# Always returns the name of the file where the value was printed.
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   524
# Param 1 - Name of variable
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   525
# Param 2 - (optional) name of file to store value in
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   526
DependOnVariableHelper = \
32807
20386e6d858f 8136385: Various build speed improvements for windows
erikj
parents: 32553
diff changeset
   527
    $(strip \
20386e6d858f 8136385: Various build speed improvements for windows
erikj
parents: 32553
diff changeset
   528
        $(eval -include $(call DependOnVariableFileName, $1, $2)) \
20386e6d858f 8136385: Various build speed improvements for windows
erikj
parents: 32553
diff changeset
   529
        $(if $(call equals, $(strip $($1)), $(strip $($1_old))),,\
20386e6d858f 8136385: Various build speed improvements for windows
erikj
parents: 32553
diff changeset
   530
          $(call MakeDir, $(dir $(call DependOnVariableFileName, $1, $2))) \
20386e6d858f 8136385: Various build speed improvements for windows
erikj
parents: 32553
diff changeset
   531
          $(if $(findstring $(LOG_LEVEL), trace), \
20386e6d858f 8136385: Various build speed improvements for windows
erikj
parents: 32553
diff changeset
   532
              $(info NewVariable $1: >$(strip $($1))<) \
20386e6d858f 8136385: Various build speed improvements for windows
erikj
parents: 32553
diff changeset
   533
              $(info OldVariable $1: >$(strip $($1_old))<)) \
42134
bbcdb49521b1 8169860: Clean up and unify the refactored Javadoc generation
ihse
parents: 41875
diff changeset
   534
          $(call WriteFile, $1_old:=$(call DoubleDollar,$(call EscapeHash,$($1))), \
33054
bcb9f5ea5761 8140484: Vardeps broken when variable value contains '$'
erikj
parents: 32812
diff changeset
   535
              $(call DependOnVariableFileName, $1, $2))) \
32807
20386e6d858f 8136385: Various build speed improvements for windows
erikj
parents: 32553
diff changeset
   536
        $(call DependOnVariableFileName, $1, $2) \
20386e6d858f 8136385: Various build speed improvements for windows
erikj
parents: 32553
diff changeset
   537
    )
28600
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   538
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   539
# Main macro
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   540
# Param 1 - Name of variable
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   541
# Param 2 - (optional) name of file to store value in
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   542
DependOnVariable = \
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   543
    $(call DependOnVariableHelper,$(strip $1),$(strip $2))
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   544
35444
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   545
# LogCmdlines is only intended to be used by ExecuteWithLog
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   546
ifeq ($(LOG_CMDLINES), true)
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   547
  LogCmdlines = $(info $(strip $1))
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   548
else
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   549
  LogCmdlines =
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   550
endif
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   551
28600
09dd1740f176 8069261: Create make dependencies on make variable values
erikj
parents: 27595
diff changeset
   552
################################################################################
35444
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   553
# ExecuteWithLog will run a command and log the output appropriately. This is
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   554
# meant to be used by commands that do "real" work, like a compilation.
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   555
# The output is stored in a specified log file, which is displayed at the end
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   556
# of the build in case of failure. The  command line itself is stored in a file,
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   557
# and also logged to stdout if the LOG=cmdlines option has been given.
32344
0b288e0efcfa 8062618: Create a build failure summary at end of build log
ihse
parents: 31312
diff changeset
   558
#
39607
ace2c0283dce 8158629: bash >(...) construct still causes race conditions
erikj
parents: 39110
diff changeset
   559
# NOTE: If the command redirects stdout, the caller needs to wrap it in a
ace2c0283dce 8158629: bash >(...) construct still causes race conditions
erikj
parents: 39110
diff changeset
   560
# subshell (by adding parentheses around it), otherwise the redirect to the
ace2c0283dce 8158629: bash >(...) construct still causes race conditions
erikj
parents: 39110
diff changeset
   561
# subshell tee process will create a race condition where the target file may
ace2c0283dce 8158629: bash >(...) construct still causes race conditions
erikj
parents: 39110
diff changeset
   562
# not be fully written when the make recipe is done.
ace2c0283dce 8158629: bash >(...) construct still causes race conditions
erikj
parents: 39110
diff changeset
   563
#
35444
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   564
# Param 1 - The path to base the name of the log file / command line file on
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   565
# Param 2 - The command to run
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   566
ExecuteWithLog = \
58663
11a574b352d0 8223998: Missing MakeDir in ExecuteWithLog
ihse
parents: 55292
diff changeset
   567
  $(call LogCmdlines, Executing: [$(strip $2)]) \
11a574b352d0 8223998: Missing MakeDir in ExecuteWithLog
ihse
parents: 55292
diff changeset
   568
  $(call MakeDir, $(dir $(strip $1)) $(MAKESUPPORT_OUTPUTDIR)/failure-logs) \
35444
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   569
  $(call WriteFile, $2, $(strip $1).cmdline) \
51069
d5d5f6658b12 8207001: *.obj.log files get truncated causing unreliable incremental builds on Windows
erikj
parents: 50590
diff changeset
   570
  ( $(RM) $(strip $1).log && $(strip $2) > >($(TEE) -a $(strip $1).log) 2> >($(TEE) -a $(strip $1).log >&2) || \
35444
4d323e794486 8148655: LOG=cmdlines and other build-infra fixes
ihse
parents: 35370
diff changeset
   571
      ( exitcode=$(DOLLAR)? && \
47253
92fd0e04e0e1 8187544: Replace BUILD_OUTPUT and OUTPUT_ROOT with OUTPUTDIR
ihse
parents: 47217
diff changeset
   572
      $(CP) $(strip $1).log $(MAKESUPPORT_OUTPUTDIR)/failure-logs/$(subst /,_,$(patsubst $(OUTPUTDIR)/%,%,$(strip $1))).log && \
92fd0e04e0e1 8187544: Replace BUILD_OUTPUT and OUTPUT_ROOT with OUTPUTDIR
ihse
parents: 47217
diff changeset
   573
      $(CP) $(strip $1).cmdline $(MAKESUPPORT_OUTPUTDIR)/failure-logs/$(subst /,_,$(patsubst $(OUTPUTDIR)/%,%,$(strip $1))).cmdline && \
39607
ace2c0283dce 8158629: bash >(...) construct still causes race conditions
erikj
parents: 39110
diff changeset
   574
      exit $(DOLLAR)exitcode ) )
32344
0b288e0efcfa 8062618: Create a build failure summary at end of build log
ihse
parents: 31312
diff changeset
   575
0b288e0efcfa 8062618: Create a build failure summary at end of build log
ihse
parents: 31312
diff changeset
   576
################################################################################
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents: 23984
diff changeset
   577
98ce0879ab4c 8054834: Modular Source Code
chegar
parents: 23984
diff changeset
   578
# Hook to include the corresponding custom file, if present.
47314
743814386712 8188814: Simplify IncludeCustomExtension
ihse
parents: 47253
diff changeset
   579
$(eval $(call IncludeCustomExtension, common/MakeBase.gmk))
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents: 23984
diff changeset
   580
12258
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
   581
endif # _MAKEBASE_GMK