make/MakeHelpers.gmk
author iignatyev
Tue, 16 Dec 2014 02:14:11 +0300
changeset 28198 1e41fbf783e3
parent 27602 236555ddac42
child 28356 3b985eeacb08
permissions -rw-r--r--
8065279: Remove testlibrary_tests from compact profile in jtreg Reviewed-by: kvn Contributed-by: dmitrij.pochepko@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13133
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
     1
#
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
     2
# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
     3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
     4
#
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
     5
# This code is free software; you can redistribute it and/or modify it
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
     6
# under the terms of the GNU General Public License version 2 only, as
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
     7
# published by the Free Software Foundation.  Oracle designates this
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
     8
# particular file as subject to the "Classpath" exception as provided
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
     9
# by Oracle in the LICENSE file that accompanied this code.
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    10
#
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    11
# This code is distributed in the hope that it will be useful, but WITHOUT
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    13
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    14
# version 2 for more details (a copy is included in the LICENSE file that
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    15
# accompanied this code).
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    16
#
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    17
# You should have received a copy of the GNU General Public License version
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    18
# 2 along with this work; if not, write to the Free Software Foundation,
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    20
#
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    21
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    22
# or visit www.oracle.com if you need additional information or have any
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    23
# questions.
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    24
#
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    25
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    26
################################################################
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    27
#
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    28
# This file contains helper functions for the top-level Makefile that does
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    29
# not depend on the spec.gmk file having been read. (The purpose of this
13133
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    30
# file is ju to avoid cluttering the top-level Makefile.)
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    31
#
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    32
################################################################
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    33
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    34
ifndef _MAKEHELPERS_GMK
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    35
_MAKEHELPERS_GMK := 1
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    36
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    37
##############################
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    38
# Stuff to run at include time
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    39
##############################
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    40
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    41
# Find out which variables were passed explicitely on the make command line. These
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    42
# will be passed on to sub-makes, overriding spec.gmk settings.
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents: 22031
diff changeset
    43
MAKE_ARGS=$(foreach var,$(subst =command,,$(filter %=command,$(foreach var,$(.VARIABLES),$(var)=$(firstword $(origin $(var)))))),$(var)="$($(var))")
13133
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    44
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    45
list_alt_overrides_with_origins=$(filter ALT_%=environment ALT_%=command,$(foreach var,$(.VARIABLES),$(var)=$(firstword $(origin $(var)))))
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    46
list_alt_overrides=$(subst =command,,$(subst =environment,,$(list_alt_overrides_with_origins)))
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    47
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    48
# Store the build times in this directory.
27560
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
    49
BUILDTIMESDIR=$(OUTPUT_ROOT)/make-support/build-times
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    50
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    51
# Global targets are possible to run either with or without a SPEC. The prototypical
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    52
# global target is "help".
22031
ae288cbb4c28 8029797: Let jprt run configure when building
erikj
parents: 21905
diff changeset
    53
global_targets=help
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    54
13133
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    55
##############################
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    56
# Functions
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    57
##############################
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
    58
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    59
define CheckEnvironment
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    60
        # Find all environment or command line variables that begin with ALT.
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    61
	$(if $(list_alt_overrides),
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    62
	  @$(PRINTF) "\nWARNING: You have the following ALT_ variables set:\n"
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    63
	  @$(PRINTF) "$(foreach var,$(list_alt_overrides),$(var)=$$$(var))\n"
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    64
	  @$(PRINTF) "ALT_ variables are deprecated and will be ignored. Please clean your environment.\n\n"
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    65
	)
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    66
endef
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    67
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    68
### Functions for timers
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    69
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    70
# Record starting time for build of a sub repository.
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    71
define RecordStartTime
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    72
	$(MKDIR) -p $(BUILDTIMESDIR)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    73
	$(DATE) '+%Y %m %d %H %M %S' | $(NAWK) '{ print $$1,$$2,$$3,$$4,$$5,$$6,($$4*3600+$$5*60+$$6) }' > $(BUILDTIMESDIR)/build_time_start_$1
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    74
	$(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_start_$1_human_readable
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    75
endef
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    76
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    77
# Record ending time and calculate the difference and store it in a
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    78
# easy to read format. Handles builds that cross midnight. Expects
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    79
# that a build will never take 24 hours or more.
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    80
define RecordEndTime
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    81
	$(DATE) '+%Y %m %d %H %M %S' | $(NAWK) '{ print $$1,$$2,$$3,$$4,$$5,$$6,($$4*3600+$$5*60+$$6) }' > $(BUILDTIMESDIR)/build_time_end_$1
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    82
	$(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_end_$1_human_readable
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    83
	$(ECHO) `$(CAT) $(BUILDTIMESDIR)/build_time_start_$1` `$(CAT) $(BUILDTIMESDIR)/build_time_end_$1` $1 | \
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    84
	    $(NAWK) '{ F=$$7; T=$$14; if (F > T) { T+=3600*24 }; D=T-F; H=int(D/3600); \
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    85
	    M=int((D-H*3600)/60); S=D-H*3600-M*60; printf("%02d:%02d:%02d %s\n",H,M,S,$$15); }' \
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    86
	    > $(BUILDTIMESDIR)/build_time_diff_$1
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    87
endef
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    88
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    89
# Find all build_time_* files and print their contents in a list sorted
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    90
# on the name of the sub repository.
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    91
define ReportBuildTimes
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    92
	$(BUILD_LOG_WRAPPER) $(PRINTF) -- "----- Build times -------\nStart %s\nEnd   %s\n%s\n%s\n-------------------------\n" \
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    93
	    "`$(CAT) $(BUILDTIMESDIR)/build_time_start_TOTAL_human_readable`" \
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    94
	    "`$(CAT) $(BUILDTIMESDIR)/build_time_end_TOTAL_human_readable`" \
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    95
	    "`$(LS) $(BUILDTIMESDIR)/build_time_diff_* | $(GREP) -v _TOTAL | $(XARGS) $(CAT) | $(SORT) -k 2`" \
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
    96
	    "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_TOTAL`"
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    97
endef
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    98
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
    99
define ResetAllTimers
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   100
  $$(shell $(MKDIR) -p $(BUILDTIMESDIR) && $(RM) $(BUILDTIMESDIR)/build_time_*)
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   101
endef
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   102
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   103
define StartGlobalTimer
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   104
	$(call RecordStartTime,TOTAL)
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   105
endef
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   106
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   107
define StopGlobalTimer
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   108
	$(call RecordEndTime,TOTAL)
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   109
endef
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   110
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   111
### Functions for managing makefile structure (start/end of makefile and individual targets)
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   112
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   113
# Do not indent this function, this will add whitespace at the start which the caller won't handle
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   114
define GetRealTarget
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents: 22031
diff changeset
   115
$(strip $(if $(findstring main-wrapper, $(MAKECMDGOALS)), $(MAIN_TARGETS), \
98ce0879ab4c 8054834: Modular Source Code
chegar
parents: 22031
diff changeset
   116
    $(if $(MAKECMDGOALS),$(MAKECMDGOALS),default)))
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   117
endef
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   118
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   119
# Do not indent this function, this will add whitespace at the start which the caller won't handle
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   120
define LastGoal
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   121
$(strip $(lastword $(call GetRealTarget)))
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   122
endef
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   123
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   124
# Check if the current target is the final target, as specified by
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   125
# the user on the command line. If so, call AtRootMakeEnd.
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   126
define CheckIfMakeAtEnd
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   127
        # Check if the current target is the last goal
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   128
	$(if $(filter $@,$(call LastGoal)),$(call AtMakeEnd))
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   129
        # If the target is 'foo-only', check if our goal was stated as 'foo'
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   130
	$(if $(filter $@,$(call LastGoal)-only),$(call AtMakeEnd))
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   131
endef
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   132
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   133
# Hook to be called when starting to execute a top-level target
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   134
define TargetEnter
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents: 22031
diff changeset
   135
	$(PRINTF) "## Starting $(patsubst %-only,%,$@)\n"
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   136
	$(call RecordStartTime,$(patsubst %-only,%,$@))
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   137
endef
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   138
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   139
# Hook to be called when finish executing a top-level target
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   140
define TargetExit
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   141
	$(call RecordEndTime,$(patsubst %-only,%,$@))
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents: 22031
diff changeset
   142
	$(PRINTF) "## Finished $(patsubst %-only,%,$@) (build time %s)\n\n" \
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   143
	    "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_$(patsubst %-only,%,$@) | $(CUT) -f 1 -d ' '`"
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   144
endef
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   145
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   146
# Hook to be called as the very first thing when running a normal build
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   147
define AtMakeStart
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   148
	$(if $(findstring --jobserver,$(MAKEFLAGS)),$(error make -j is not supported, use make JOBS=n))
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   149
	$(call CheckEnvironment)
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents: 22031
diff changeset
   150
	$(BUILD_LOG_WRAPPER) $(PRINTF) $(LOG_INFO) "Running make as '$(MAKE) $(MFLAGS) $(MAKE_ARGS)'\n"
98ce0879ab4c 8054834: Modular Source Code
chegar
parents: 22031
diff changeset
   151
	$(BUILD_LOG_WRAPPER) $(PRINTF) "Building $(PRODUCT_NAME) for target '$(call GetRealTarget)' in configuration '$(CONF_NAME)'\n\n"
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   152
	$(call StartGlobalTimer)
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   153
endef
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   154
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   155
# Hook to be called as the very last thing for targets that are "top level" targets
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   156
define AtMakeEnd
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   157
	[ -f $(SJAVAC_SERVER_DIR)/server.port ] && echo Stopping sjavac server && $(TOUCH) $(SJAVAC_SERVER_DIR)/server.port.stop; true
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   158
	$(call StopGlobalTimer)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   159
	$(call ReportBuildTimes)
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents: 22031
diff changeset
   160
	@$(PRINTF) "\nFinished building $(PRODUCT_NAME) for target '$(call GetRealTarget)'\n"
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   161
	$(call CheckEnvironment)
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   162
endef
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   163
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   164
### Functions for parsing and setting up make options from command-line
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   165
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   166
define FatalError
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   167
  # If the user specificed a "global" target (e.g. 'help'), do not exit but continue running
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   168
  $$(if $$(filter-out $(global_targets),$$(call GetRealTarget)),$$(error Cannot continue))
13133
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
   169
endef
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
   170
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
   171
define ParseLogLevel
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   172
  ifeq ($$(origin VERBOSE),undefined)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   173
    # Setup logging according to LOG (but only if VERBOSE is not given)
14379
b449aa34783e 8003274: build-infra: Makefile changes needed for sjavac
tbell
parents: 14111
diff changeset
   174
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   175
    # If the "nofile" argument is given, act on it and strip it away
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   176
    ifneq ($$(findstring nofile,$$(LOG)),)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   177
      # Reset the build log wrapper, regardless of other values
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   178
      override BUILD_LOG_WRAPPER=
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   179
      # COMMA is defined in spec.gmk, but that is not included yet
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   180
      COMMA=,
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   181
      # First try to remove ",nofile" if it exists
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   182
      LOG_STRIPPED1=$$(subst $$(COMMA)nofile,,$$(LOG))
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   183
      # Otherwise just remove "nofile"
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   184
      LOG_STRIPPED2=$$(subst nofile,,$$(LOG_STRIPPED1))
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   185
      # We might have ended up with a leading comma. Remove it
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   186
      LOG_STRIPPED3=$$(strip $$(patsubst $$(COMMA)%,%,$$(LOG_STRIPPED2)))
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   187
      LOG_LEVEL:=$$(LOG_STRIPPED3)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   188
    else
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   189
      LOG_LEVEL:=$$(LOG)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   190
    endif
13697
5262b00bc10c 7197849: Update new build-infra makefiles
ohair
parents: 13133
diff changeset
   191
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   192
    ifeq ($$(LOG_LEVEL),)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   193
      # Set LOG to "warn" as default if not set (and no VERBOSE given)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   194
      override LOG_LEVEL=warn
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   195
    endif
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   196
    ifeq ($$(LOG_LEVEL),warn)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   197
      VERBOSE=-s
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   198
    else ifeq ($$(LOG_LEVEL),info)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   199
      VERBOSE=-s
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   200
    else ifeq ($$(LOG_LEVEL),debug)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   201
      VERBOSE=
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   202
    else ifeq ($$(LOG_LEVEL),trace)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   203
      VERBOSE=
13133
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
   204
    else
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   205
      $$(info Error: LOG must be one of: warn, info, debug or trace.)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   206
      $$(eval $$(call FatalError))
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   207
    endif
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   208
  else
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   209
    # Provide resonable interpretations of LOG_LEVEL if VERBOSE is given.
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   210
    ifeq ($(VERBOSE),)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   211
      LOG_LEVEL:=debug
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   212
    else
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   213
      LOG_LEVEL:=warn
13133
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
   214
    endif
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   215
    ifneq ($$(LOG),)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   216
      # We have both a VERBOSE and a LOG argument. This is OK only if this is a repeated call by ourselves,
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   217
      # but complain if this is the top-level make call.
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   218
      ifeq ($$(MAKELEVEL),0)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   219
        $$(info Cannot use LOG=$$(LOG) and VERBOSE=$$(VERBOSE) at the same time. Choose one.)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   220
        $$(eval $$(call FatalError))
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   221
      endif
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   222
    endif
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   223
  endif
13133
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
   224
endef
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
   225
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
   226
define ParseConfAndSpec
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   227
  ifneq ($$(filter-out $(global_targets),$$(call GetRealTarget)),)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   228
    # If we only have global targets, no need to bother with SPEC or CONF
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   229
    ifneq ($$(origin SPEC),undefined)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   230
      # We have been given a SPEC, check that it works out properly
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   231
      ifneq ($$(origin CONF),undefined)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   232
        # We also have a CONF argument. This is OK only if this is a repeated call by ourselves,
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   233
        # but complain if this is the top-level make call.
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   234
        ifeq ($$(MAKELEVEL),0)
27595
cff167b3bfa2 8065914: Various improvements and cleanup of build system
ihse
parents: 27000
diff changeset
   235
          $$(info Error: Cannot use CONF=$$(CONF) and SPEC=$$(SPEC) at the same time. Choose one.)
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   236
          $$(eval $$(call FatalError))
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   237
        endif
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   238
      endif
27595
cff167b3bfa2 8065914: Various improvements and cleanup of build system
ihse
parents: 27000
diff changeset
   239
      ifeq ($$(wildcard $$(SPEC)),)
cff167b3bfa2 8065914: Various improvements and cleanup of build system
ihse
parents: 27000
diff changeset
   240
        $$(info Error: Cannot locate spec.gmk, given by SPEC=$$(SPEC).)
cff167b3bfa2 8065914: Various improvements and cleanup of build system
ihse
parents: 27000
diff changeset
   241
        $$(eval $$(call FatalError))
cff167b3bfa2 8065914: Various improvements and cleanup of build system
ihse
parents: 27000
diff changeset
   242
      endif
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   243
      # ... OK, we're satisfied, we'll use this SPEC later on
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   244
    else
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   245
      # Find all spec.gmk files in the build output directory
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   246
      output_dir=$$(root_dir)/build
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   247
      all_spec_files=$$(wildcard $$(output_dir)/*/spec.gmk)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   248
      ifeq ($$(all_spec_files),)
27595
cff167b3bfa2 8065914: Various improvements and cleanup of build system
ihse
parents: 27000
diff changeset
   249
        $$(info Error: No configurations found for $$(root_dir).)
cff167b3bfa2 8065914: Various improvements and cleanup of build system
ihse
parents: 27000
diff changeset
   250
        $$(info Please run 'bash configure' to create a configuration.)
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   251
        $$(eval $$(call FatalError))
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   252
      endif
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   253
      # Extract the configuration names from the path
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   254
      all_confs=$$(patsubst %/spec.gmk,%,$$(patsubst $$(output_dir)/%,%,$$(all_spec_files)))
13133
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
   255
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   256
      ifneq ($$(origin CONF),undefined)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   257
        # User have given a CONF= argument.
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   258
        ifeq ($$(CONF),)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   259
          # If given CONF=, match all configurations
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   260
          matching_confs=$$(strip $$(all_confs))
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   261
        else
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   262
          # Otherwise select those that contain the given CONF string
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   263
          matching_confs=$$(strip $$(foreach var,$$(all_confs),$$(if $$(findstring $$(CONF),$$(var)),$$(var))))
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   264
        endif
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   265
        ifeq ($$(matching_confs),)
27595
cff167b3bfa2 8065914: Various improvements and cleanup of build system
ihse
parents: 27000
diff changeset
   266
          $$(info Error: No configurations found matching CONF=$$(CONF).)
cff167b3bfa2 8065914: Various improvements and cleanup of build system
ihse
parents: 27000
diff changeset
   267
          $$(info Available configurations in $$(output_dir):)
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   268
          $$(foreach var,$$(all_confs),$$(info * $$(var)))
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   269
          $$(eval $$(call FatalError))
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   270
        else
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   271
          ifeq ($$(words $$(matching_confs)),1)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   272
            $$(info Building '$$(matching_confs)' (matching CONF=$$(CONF)))
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   273
          else
27595
cff167b3bfa2 8065914: Various improvements and cleanup of build system
ihse
parents: 27000
diff changeset
   274
            $$(info Building target '$(call GetRealTarget)' in these configurations (matching CONF=$$(CONF)):)
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   275
            $$(foreach var,$$(matching_confs),$$(info * $$(var)))
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   276
          endif
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   277
        endif
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   278
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   279
        # Create a SPEC definition. This will contain the path to one or more spec.gmk files.
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   280
        SPEC=$$(addsuffix /spec.gmk,$$(addprefix $$(output_dir)/,$$(matching_confs)))
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   281
      else
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   282
        # No CONF or SPEC given, check the available configurations
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   283
        ifneq ($$(words $$(all_spec_files)),1)
27595
cff167b3bfa2 8065914: Various improvements and cleanup of build system
ihse
parents: 27000
diff changeset
   284
          $$(info Error: No CONF given, but more than one configuration found.)
cff167b3bfa2 8065914: Various improvements and cleanup of build system
ihse
parents: 27000
diff changeset
   285
          $$(info Available configurations in $$(output_dir):)
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   286
          $$(foreach var,$$(all_confs),$$(info * $$(var)))
27595
cff167b3bfa2 8065914: Various improvements and cleanup of build system
ihse
parents: 27000
diff changeset
   287
          $$(info Please retry building with CONF=<config pattern> (or SPEC=<specfile>).)
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   288
          $$(eval $$(call FatalError))
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   289
        endif
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   290
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   291
        # We found exactly one configuration, use it
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   292
        SPEC=$$(strip $$(all_spec_files))
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   293
      endif
13133
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
   294
    endif
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   295
  endif
13133
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
   296
endef
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
   297
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 13697
diff changeset
   298
### Convenience functions from Main.gmk
13133
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
   299
27560
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   300
# Cleans the dir given as $1
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   301
define CleanDir
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents: 22031
diff changeset
   302
	@$(PRINTF) "Cleaning $(strip $1) build artifacts ..."
20363
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   303
	@($(CD) $(OUTPUT_ROOT) && $(RM) -r $1)
fa7663fc5d50 8001931: The new build system whitespace cleanup
ihse
parents: 16583
diff changeset
   304
	@$(PRINTF) " done\n"
13697
5262b00bc10c 7197849: Update new build-infra makefiles
ohair
parents: 13133
diff changeset
   305
endef
5262b00bc10c 7197849: Update new build-infra makefiles
ohair
parents: 13133
diff changeset
   306
27560
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   307
define Clean-gensrc
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   308
	@$(PRINTF) "Cleaning gensrc $(if $1,for $(strip $1) )..."
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   309
	@$(RM) -r $(SUPPORT_OUTPUTDIR)/gensrc/$(strip $1)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   310
	@$(RM) -r $(SUPPORT_OUTPUTDIR)/gensrc_no_docs/$(strip $1)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   311
	@$(PRINTF) " done\n"
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   312
endef
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   313
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   314
define Clean-java
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   315
	@$(PRINTF) "Cleaning java $(if $1,for $(strip $1) )..."
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   316
	@$(RM) -r $(JDK_OUTPUTDIR)/modules/$(strip $1)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   317
	@$(RM) -r $(SUPPORT_OUTPUTDIR)/misc/$(strip $1)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   318
	@$(PRINTF) " done\n"
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   319
	@$(PRINTF) "Cleaning headers $(if $1,for $(strip $1)) ..."
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   320
	@$(RM) -r $(SUPPORT_OUTPUTDIR)/headers/$(strip $1)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   321
	@$(PRINTF) " done\n"
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   322
endef
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   323
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   324
define Clean-native
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   325
	@$(PRINTF) "Cleaning native $(if $1,for $(strip $1) )..."
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   326
	@$(RM) -r $(SUPPORT_OUTPUTDIR)/native/$(strip $1)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   327
	@$(RM) -r $(SUPPORT_OUTPUTDIR)/modules_libs/$(strip $1)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   328
	@$(RM) -r $(SUPPORT_OUTPUTDIR)/modules_libs-stripped/$(strip $1)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   329
	@$(RM) -r $(SUPPORT_OUTPUTDIR)/modules_cmds/$(strip $1)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   330
	@$(RM) -r $(SUPPORT_OUTPUTDIR)/modules_cmds-stripped/$(strip $1)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   331
	@$(PRINTF) " done\n"
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   332
endef
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   333
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   334
define Clean-include
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   335
	@$(PRINTF) "Cleaning include $(if $1,for $(strip $1) )..."
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   336
	@$(RM) -r $(SUPPORT_OUTPUTDIR)/modules_include/$(strip $1)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   337
	@$(PRINTF) " done\n"
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   338
endef
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   339
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   340
define CleanModule
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   341
  $(call Clean-gensrc, $1)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   342
  $(call Clean-java, $1)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   343
  $(call Clean-native, $1)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   344
  $(call Clean-include, $1)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   345
endef
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   346
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   347
26116
f051bd253364 8055095: Improve "do nothing" incremental build performance after modularized source code integration
erikj
parents: 25854
diff changeset
   348
################################################################################
f051bd253364 8055095: Improve "do nothing" incremental build performance after modularized source code integration
erikj
parents: 25854
diff changeset
   349
27560
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   350
MAKE_TOPDIR_LIST := $(JDK_TOPDIR) $(CORBA_TOPDIR) $(LANGTOOLS_TOPDIR)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   351
MAKE_MAKEDIR_LIST := make
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   352
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   353
# Helper macro for DeclareRecipesForPhase
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   354
# Declare a recipe for calling the module and phase specific makefile.
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   355
# If there are multiple makefiles to call, create a rule for each topdir
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   356
# that contains a makefile with the target $module-$suffix-$repodir, 
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   357
# (i.e: java.base-gensrc-jdk)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   358
# Normally there is only one makefile, and the target will just be
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   359
# $module-$suffix
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   360
# Param 1: Name of list to add targets to
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   361
# Param 2: Module name
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   362
# Param 3: Topdir
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   363
define DeclareRecipeForModuleMakefile
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   364
  ifeq ($$($1_MULTIPLE_MAKEFILES), true)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   365
    $2-$$($1_TARGET_SUFFIX): $2-$$($1_TARGET_SUFFIX)-$$(notdir $3)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   366
    $1 += $2-$$($1_TARGET_SUFFIX)-$$(notdir $3)
26116
f051bd253364 8055095: Improve "do nothing" incremental build performance after modularized source code integration
erikj
parents: 25854
diff changeset
   367
27560
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   368
    $2-$$($1_TARGET_SUFFIX)-$$(notdir $3):
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   369
  else
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   370
    $2-$$($1_TARGET_SUFFIX):
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   371
  endif
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   372
	$(ECHO) $(LOG_INFO) "Building $$@"
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   373
        ifeq ($$($1_USE_WRAPPER), true)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   374
	  +($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) \
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   375
	      -f ModuleWrapper.gmk \
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   376
	          $$(addprefix -I, $$(wildcard $$(addprefix $3/, $(MAKE_MAKEDIR_LIST)) \
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   377
	          $$(addsuffix /$$($1_MAKE_SUBDIR), $$(addprefix $3/, $(MAKE_MAKEDIR_LIST))))) \
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   378
	          MODULE=$2 MAKEFILE_PREFIX=$$($1_FILE_PREFIX))
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   379
        else
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   380
	  +($(CD) $$(dir $$(firstword $$(wildcard $$(patsubst %, \
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   381
	          $3/%/$$($1_MAKE_SUBDIR)/$$($1_FILE_PREFIX)-$2.gmk, $(MAKE_MAKEDIR_LIST))))) \
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   382
	    && $(MAKE) $(MAKE_ARGS) \
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   383
	          -f $$($1_FILE_PREFIX)-$2.gmk \
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   384
	          $$(addprefix -I, $$(wildcard $$(addprefix $3/, $(MAKE_MAKEDIR_LIST)) \
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   385
	          $$(addsuffix /$3, $$(addprefix $3/, $(MAKE_MAKEDIR_LIST))))) \
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   386
	          MODULE=$2)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   387
        endif
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   388
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   389
endef
26116
f051bd253364 8055095: Improve "do nothing" incremental build performance after modularized source code integration
erikj
parents: 25854
diff changeset
   390
27560
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   391
# Helper macro for DeclareRecipesForPhase
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   392
# Param 1: Name of list to add targets to
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   393
# Param 2: Module name
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   394
define DeclareRecipesForPhaseAndModule
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   395
  $1_$2_TOPDIRS := $$(strip $$(sort $$(foreach d, $(MAKE_TOPDIR_LIST), \
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   396
      $$(patsubst $$d/%, $$d, $$(filter $$d/%, \
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   397
          $$(wildcard $$(patsubst %, %/$$($1_MAKE_SUBDIR)/$$($1_FILE_PREFIX)-$2.gmk, \
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   398
          $$(foreach s, $(MAKE_MAKEDIR_LIST), \
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   399
              $$(addsuffix /$$s, $(MAKE_TOPDIR_LIST))))))))))
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   400
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   401
  # Only declare recipes if there are makefiles to call
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   402
  ifneq ($$($1_$2_TOPDIRS), )
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   403
    $$(foreach d, $$($1_$2_TOPDIRS), \
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   404
        $$(eval $$(call DeclareRecipeForModuleMakefile,$1,$2,$$d)))
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   405
    $1 += $2-$$($1_TARGET_SUFFIX)
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   406
    $1_MODULES += $2
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   407
  endif
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   408
endef
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   409
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   410
# Declare recipes for a specific module and build phase if there are makefiles
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   411
# present for the specific combination.
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   412
# Param 1: Name of list to add targets to
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   413
# Named params:
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   414
# TARGET_SUFFIX : Suffix of target to create for recipe
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   415
# MAKE_SUBDIR : Subdir for this build phase
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   416
# FILE_PREFIX : File prefix for this build phase
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   417
# USE_WRAPPER : Set to true to use ModuleWrapper.gmk
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   418
# CHECK_MODULES : List of modules to try
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   419
# MULTIPLE_MAKEFILES : Set to true to handle makefils for the same module in
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   420
#                      phase in multiple repos
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   421
# Exported variables:
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   422
# $1_MODULES : All modules that had rules generated
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   423
# $1_TARGETS : All targets generated
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   424
define DeclareRecipesForPhase
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   425
  $(foreach i,2 3 4 5 6 7, $(if $($i),$(strip $1)_$(strip $($i)))$(NEWLINE))
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   426
  $(if $(8),$(error Internal makefile error: Too many arguments to \
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   427
      DeclareRecipesForPhase, please update MakeHelper.gmk))
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   428
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   429
  $$(foreach m, $$($(strip $1)_CHECK_MODULES), \
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   430
      $$(eval $$(call DeclareRecipesForPhaseAndModule,$(strip $1),$$m)))
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   431
adc258b13e2c 8049367: Modular Run-Time Images
chegar
parents: 27000
diff changeset
   432
  $(strip $1)_TARGETS := $$($(strip $1))
26116
f051bd253364 8055095: Improve "do nothing" incremental build performance after modularized source code integration
erikj
parents: 25854
diff changeset
   433
endef
f051bd253364 8055095: Improve "do nothing" incremental build performance after modularized source code integration
erikj
parents: 25854
diff changeset
   434
f051bd253364 8055095: Improve "do nothing" incremental build performance after modularized source code integration
erikj
parents: 25854
diff changeset
   435
################################################################################
f051bd253364 8055095: Improve "do nothing" incremental build performance after modularized source code integration
erikj
parents: 25854
diff changeset
   436
13133
701e61c32ece 7182051: Update of latest build-infra Makefiles (missing files)
erikj
parents:
diff changeset
   437
endif # _MAKEHELPERS_GMK