common/makefiles/MakeHelpers.gmk

Tue, 18 Sep 2012 11:29:16 -0700

author
ohair
date
Tue, 18 Sep 2012 11:29:16 -0700
changeset 478
2ba6f4da4bf3
parent 459
3156dff953b1
child 494
e64f2cb57d05
permissions
-rw-r--r--

7197849: Update new build-infra makefiles
Reviewed-by: ihse, erikj, ohrstrom, tbell

     1 #
     2 # Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
     3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4 #
     5 # This code is free software; you can redistribute it and/or modify it
     6 # under the terms of the GNU General Public License version 2 only, as
     7 # published by the Free Software Foundation.  Oracle designates this
     8 # particular file as subject to the "Classpath" exception as provided
     9 # by Oracle in the LICENSE file that accompanied this code.
    10 #
    11 # This code is distributed in the hope that it will be useful, but WITHOUT
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14 # version 2 for more details (a copy is included in the LICENSE file that
    15 # accompanied this code).
    16 #
    17 # You should have received a copy of the GNU General Public License version
    18 # 2 along with this work; if not, write to the Free Software Foundation,
    19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20 #
    21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22 # or visit www.oracle.com if you need additional information or have any
    23 # questions.
    24 #
    26 ################################################################
    27 #
    28 # This file contains helper functions for the top-level Makefile that does
    29 # not depend on the spec.gmk file having been read. (The purpose of this 
    30 # file is ju to avoid cluttering the top-level Makefile.)
    31 #
    32 ################################################################
    34 ifndef _MAKEHELPERS_GMK
    35 _MAKEHELPERS_GMK := 1
    37 ##############################
    38 # Stuff to run at include time
    39 ##############################
    41 # Find out which variables were passed explicitely on the make command line. These
    42 # will be passed on to sub-makes, overriding spec.gmk settings.
    43 MAKE_ARGS=$(foreach var,$(subst =command,,$(filter %=command,$(foreach var,$(.VARIABLES),$(var)=$(firstword $(origin $(var)))))),$(var)=$($(var)))
    45 list_alt_overrides_with_origins=$(filter ALT_%=environment ALT_%=command,$(foreach var,$(.VARIABLES),$(var)=$(firstword $(origin $(var)))))
    46 list_alt_overrides=$(subst =command,,$(subst =environment,,$(list_alt_overrides_with_origins)))
    48 ##############################
    49 # Functions
    50 ##############################
    52 define fatal-error
    53     # If the user specificed a "global" target (e.g. 'help'), do not exit but continue running
    54     $$(if $$(findstring help,$$(MAKECMDGOALS)),,$$(error Cannot continue))
    55 endef
    57 define ParseLogLevel
    58     ifeq ($$(origin VERBOSE),undefined)
    59         # Setup logging according to LOG (but only if VERBOSE is not given)
    61        # If the "nofile" argument is given, act on it and strip it away
    62         ifneq ($$(findstring nofile,$$(LOG)),)
    63           # Reset the build log wrapper, regardless of other values
    64           override BUILD_LOG_WRAPPER=
    65           # COMMA is defined in spec.gmk, but that is not included yet
    66           COMMA=,
    67           # First try to remove ",nofile" if it exists
    68           LOG_STRIPPED1=$$(subst $$(COMMA)nofile,,$$(LOG))
    69           # Otherwise just remove "nofile"
    70           LOG_STRIPPED2=$$(subst nofile,,$$(LOG_STRIPPED1))
    71           # We might have ended up with a leading comma. Remove it
    72           LOG_STRIPPED3=$$(strip $$(patsubst $$(COMMA)%,%,$$(LOG_STRIPPED2)))
    73           override LOG:=$$(LOG_STRIPPED3)
    74         endif
    76         ifeq ($$(LOG),)
    77             # Set LOG to "warn" as default if not set (and no VERBOSE given)
    78             override LOG=warn
    79         endif
    80         ifeq ($$(LOG),warn)
    81             VERBOSE=-s
    82         else ifeq ($$(LOG),info)
    83             VERBOSE=
    84         else ifeq ($$(LOG),debug)
    85             VERBOSE=
    86         else ifeq ($$(LOG),trace)
    87             VERBOSE=-d -p
    88         else
    89             $$(info Error: LOG must be one of: warn, info, debug or trace.)
    90             $$(eval $$(call fatal-error))
    91         endif
    92     else
    93         ifneq ($$(LOG),)
    94             # We have both a VERBOSE and a LOG argument. This is OK only if this is a repeated call by ourselves,
    95             # but complain if this is the top-level make call.
    96             ifeq ($$(MAKELEVEL),0)
    97                 $$(info Cannot use LOG=$$(LOG) and VERBOSE=$$(VERBOSE) at the same time. Choose one.)
    98                 $$(eval $$(call fatal-error))
    99             endif
   100         endif
   101     endif
   102 endef
   104 # TODO: Fix duplication in MakeBase.gmk
   105 define SetupLogging
   106     ifneq ($(findstring $(LOG),debug trace),)
   107         # Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make
   108         OLD_SHELL:=$$(SHELL)
   109         SHELL = $$(warning Building $$@$$(if $$<, (from $$<))$(if $$?, ($$? newer)))$$(OLD_SHELL) -x
   110     endif
   111 endef
   113 define ParseConfAndSpec
   114     ifneq ($$(origin SPEC),undefined)
   115         # We have been given a SPEC, check that it works out properly
   116         ifeq ($$(wildcard $$(SPEC)),)
   117             $$(info Cannot locate spec.gmk, given by SPEC=$$(SPEC))
   118             $$(eval $$(call fatal-error))
   119         endif
   120         ifneq ($$(origin CONF),undefined)
   121             # We also have a CONF argument. This is OK only if this is a repeated call by ourselves,
   122             # but complain if this is the top-level make call.
   123             ifeq ($$(MAKELEVEL),0)
   124                 $$(info Cannot use CONF=$$(CONF) and SPEC=$$(SPEC) at the same time. Choose one.)
   125                 $$(eval $$(call fatal-error))
   126             endif
   127         endif
   128         # ... OK, we're satisfied, we'll use this SPEC later on
   129     else
   130         # Find all spec.gmk files in the build output directory
   131         output_dir=$$(root_dir)/build
   132         all_spec_files=$$(wildcard $$(output_dir)/*/spec.gmk)
   133         ifeq ($$(all_spec_files),)
   134             $$(info No configurations found for $$(root_dir)! Please run configure to create a configuration.)
   135             $$(eval $$(call fatal-error))
   136         endif
   137         # Extract the configuration names from the path
   138         all_confs=$$(patsubst %/spec.gmk,%,$$(patsubst $$(output_dir)/%,%,$$(all_spec_files)))
   140         ifneq ($$(origin CONF),undefined)
   141             # User have given a CONF= argument.
   142             ifeq ($$(CONF),)
   143                 # If given CONF=, match all configurations
   144                 matching_confs=$$(strip $$(all_confs))
   145             else
   146                 # Otherwise select those that contain the given CONF string
   147                 matching_confs=$$(strip $$(foreach var,$$(all_confs),$$(if $$(findstring $$(CONF),$$(var)),$$(var))))
   148             endif
   149             ifeq ($$(matching_confs),)
   150                 $$(info No configurations found matching CONF=$$(CONF))
   151                 $$(info Available configurations:)
   152                 $$(foreach var,$$(all_confs),$$(info * $$(var)))
   153                 $$(eval $$(call fatal-error))
   154             else
   155                 ifeq ($$(words $$(matching_confs)),1)
   156                     $$(info Building '$$(matching_confs)' (matching CONF=$$(CONF)))
   157                 else
   158                     $$(info Building the following configurations (matching CONF=$$(CONF)):)
   159                     $$(foreach var,$$(matching_confs),$$(info * $$(var)))
   160                 endif
   161             endif
   163             # Create a SPEC definition. This will contain the path to one or more spec.gmk files.
   164             SPEC=$$(addsuffix /spec.gmk,$$(addprefix $$(output_dir)/,$$(matching_confs)))
   165         else
   166             # No CONF or SPEC given, check the available configurations
   167             ifneq ($$(words $$(all_spec_files)),1)
   168                 $$(info No CONF or SPEC given, but more than one spec.gmk found in $$(output_dir).)
   169                 $$(info Available configurations:)
   170                 $$(foreach var,$$(all_confs),$$(info * $$(var)))
   171                 $$(info Please retry building with CONF=<config> or SPEC=<specfile>)
   172                 $$(eval $$(call fatal-error))
   173             endif
   175             # We found exactly one configuration, use it
   176             SPEC=$$(strip $$(all_spec_files))
   177         endif
   178     endif
   179 endef
   181 define CheckEnvironment
   182     # Find all environment or command line variables that begin with ALT.
   183     $(if $(list_alt_overrides),
   184         @$(PRINTF) "\nWARNING: You have the following ALT_ variables set:\n"
   185     @$(PRINTF) "$(foreach var,$(list_alt_overrides),$(var)=$$$(var))\n"
   186     @$(PRINTF) "ALT_ variables are deprecated and will be ignored. Please clean your environment.\n\n"
   187     )
   188 endef
   190 define PrintStartMessage
   191     $(if $(VERBOSE),,@$(ECHO) Running make as $(MAKE) $(MFLAGS) $(MAKE_ARGS))
   192     $(call CheckEnvironment)
   193     @$(ECHO) "Building OpenJDK for target $(if $(MAKECMDGOALS),'$(MAKECMDGOALS)','all') in configuration '$(CONF_NAME)'"
   194 endef
   196 define PrintEndMessage
   197     @$(ECHO) "Finished building OpenJDK for target '$@'"
   198     $(call CheckEnvironment)
   199 endef
   201 # Cleans the component given as $1
   202 define CleanComponent
   203     @$(PRINTF) "Cleaning $1 build artifacts ..."
   204     @($(CD) $(OUTPUT_ROOT) && $(RM) -r $1)
   205     @$(PRINTF) " done\n"
   206 endef
   208 endif # _MAKEHELPERS_GMK

mercurial