common/makefiles/MakeHelpers.gmk
changeset 20363 fa7663fc5d50
parent 16583 f29d60d73e42
equal deleted inserted replaced
20362:5f8289bfda3e 20363:fa7663fc5d50
    24 #
    24 #
    25 
    25 
    26 ################################################################
    26 ################################################################
    27 #
    27 #
    28 # This file contains helper functions for the top-level Makefile that does
    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 
    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.)
    30 # file is ju to avoid cluttering the top-level Makefile.)
    31 #
    31 #
    32 ################################################################
    32 ################################################################
    33 
    33 
    34 ifndef _MAKEHELPERS_GMK
    34 ifndef _MAKEHELPERS_GMK
    47 
    47 
    48 # Store the build times in this directory.
    48 # Store the build times in this directory.
    49 BUILDTIMESDIR=$(OUTPUT_ROOT)/tmp/buildtimes
    49 BUILDTIMESDIR=$(OUTPUT_ROOT)/tmp/buildtimes
    50 
    50 
    51 # Global targets are possible to run either with or without a SPEC. The prototypical
    51 # Global targets are possible to run either with or without a SPEC. The prototypical
    52 # global target is "help". 
    52 # global target is "help".
    53 global_targets=help jprt% bridgeBuild
    53 global_targets=help jprt% bridgeBuild
    54 
    54 
    55 ##############################
    55 ##############################
    56 # Functions
    56 # Functions
    57 ##############################
    57 ##############################
    58 
    58 
    59 define CheckEnvironment
    59 define CheckEnvironment
    60     # Find all environment or command line variables that begin with ALT.
    60         # Find all environment or command line variables that begin with ALT.
    61     $(if $(list_alt_overrides),
    61 	$(if $(list_alt_overrides),
    62         @$(PRINTF) "\nWARNING: You have the following ALT_ variables set:\n"
    62 	  @$(PRINTF) "\nWARNING: You have the following ALT_ variables set:\n"
    63     @$(PRINTF) "$(foreach var,$(list_alt_overrides),$(var)=$$$(var))\n"
    63 	  @$(PRINTF) "$(foreach var,$(list_alt_overrides),$(var)=$$$(var))\n"
    64     @$(PRINTF) "ALT_ variables are deprecated and will be ignored. Please clean your environment.\n\n"
    64 	  @$(PRINTF) "ALT_ variables are deprecated and will be ignored. Please clean your environment.\n\n"
    65     )
    65 	)
    66 endef
    66 endef
    67 
    67 
    68 ### Functions for timers
    68 ### Functions for timers
    69 
    69 
    70 # Record starting time for build of a sub repository.
    70 # Record starting time for build of a sub repository.
    71 define RecordStartTime
    71 define RecordStartTime
    72     $(MKDIR) -p $(BUILDTIMESDIR)
    72 	$(MKDIR) -p $(BUILDTIMESDIR)
    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
    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
    74     $(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_start_$1_human_readable
    74 	$(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_start_$1_human_readable
    75 endef
    75 endef
    76 
    76 
    77 # Record ending time and calculate the difference and store it in a
    77 # Record ending time and calculate the difference and store it in a
    78 # easy to read format. Handles builds that cross midnight. Expects
    78 # easy to read format. Handles builds that cross midnight. Expects
    79 # that a build will never take 24 hours or more. 
    79 # that a build will never take 24 hours or more.
    80 define RecordEndTime
    80 define RecordEndTime
    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
    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
    82     $(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_end_$1_human_readable
    82 	$(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_end_$1_human_readable
    83     $(ECHO) `$(CAT) $(BUILDTIMESDIR)/build_time_start_$1` `$(CAT) $(BUILDTIMESDIR)/build_time_end_$1` $1 | \
    83 	$(ECHO) `$(CAT) $(BUILDTIMESDIR)/build_time_start_$1` `$(CAT) $(BUILDTIMESDIR)/build_time_end_$1` $1 | \
    84         $(NAWK) '{ F=$$7; T=$$14; if (F > T) { T+=3600*24 }; D=T-F; H=int(D/3600); \
    84 	    $(NAWK) '{ F=$$7; T=$$14; if (F > T) { T+=3600*24 }; D=T-F; H=int(D/3600); \
    85         M=int((D-H*3600)/60); S=D-H*3600-M*60; printf("%02d:%02d:%02d %s\n",H,M,S,$$15); }' \
    85 	    M=int((D-H*3600)/60); S=D-H*3600-M*60; printf("%02d:%02d:%02d %s\n",H,M,S,$$15); }' \
    86         > $(BUILDTIMESDIR)/build_time_diff_$1
    86 	    > $(BUILDTIMESDIR)/build_time_diff_$1
    87 endef
    87 endef
    88 
    88 
    89 # Find all build_time_* files and print their contents in a list sorted
    89 # Find all build_time_* files and print their contents in a list sorted
    90 # on the name of the sub repository.
    90 # on the name of the sub repository.
    91 define ReportBuildTimes
    91 define ReportBuildTimes
    92     $(BUILD_LOG_WRAPPER) $(PRINTF) -- "----- Build times -------\nStart %s\nEnd   %s\n%s\n%s\n-------------------------\n" \
    92 	$(BUILD_LOG_WRAPPER) $(PRINTF) -- "----- Build times -------\nStart %s\nEnd   %s\n%s\n%s\n-------------------------\n" \
    93         "`$(CAT) $(BUILDTIMESDIR)/build_time_start_TOTAL_human_readable`" \
    93 	    "`$(CAT) $(BUILDTIMESDIR)/build_time_start_TOTAL_human_readable`" \
    94         "`$(CAT) $(BUILDTIMESDIR)/build_time_end_TOTAL_human_readable`" \
    94 	    "`$(CAT) $(BUILDTIMESDIR)/build_time_end_TOTAL_human_readable`" \
    95         "`$(LS) $(BUILDTIMESDIR)/build_time_diff_* | $(GREP) -v _TOTAL | $(XARGS) $(CAT) | $(SORT) -k 2`" \
    95 	    "`$(LS) $(BUILDTIMESDIR)/build_time_diff_* | $(GREP) -v _TOTAL | $(XARGS) $(CAT) | $(SORT) -k 2`" \
    96         "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_TOTAL`"
    96 	    "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_TOTAL`"
    97 endef
    97 endef
    98 
    98 
    99 define ResetAllTimers
    99 define ResetAllTimers
   100     $$(shell $(MKDIR) -p $(BUILDTIMESDIR) &&  $(RM) $(BUILDTIMESDIR)/build_time_*)
   100   $$(shell $(MKDIR) -p $(BUILDTIMESDIR) && $(RM) $(BUILDTIMESDIR)/build_time_*)
   101 endef
   101 endef
   102 
   102 
   103 define StartGlobalTimer
   103 define StartGlobalTimer
   104     $(call RecordStartTime,TOTAL)
   104 	$(call RecordStartTime,TOTAL)
   105 endef
   105 endef
   106 
   106 
   107 define StopGlobalTimer
   107 define StopGlobalTimer
   108     $(call RecordEndTime,TOTAL)
   108 	$(call RecordEndTime,TOTAL)
   109 endef
   109 endef
   110 
   110 
   111 ### Functions for managing makefile structure (start/end of makefile and individual targets)
   111 ### Functions for managing makefile structure (start/end of makefile and individual targets)
   112 
   112 
   113 # Do not indent this function, this will add whitespace at the start which the caller won't handle
   113 # Do not indent this function, this will add whitespace at the start which the caller won't handle
   121 endef
   121 endef
   122 
   122 
   123 # Check if the current target is the final target, as specified by
   123 # Check if the current target is the final target, as specified by
   124 # the user on the command line. If so, call AtRootMakeEnd.
   124 # the user on the command line. If so, call AtRootMakeEnd.
   125 define CheckIfMakeAtEnd
   125 define CheckIfMakeAtEnd
   126     # Check if the current target is the last goal
   126         # Check if the current target is the last goal
   127     $(if $(filter $@,$(call LastGoal)),$(call AtMakeEnd))
   127 	$(if $(filter $@,$(call LastGoal)),$(call AtMakeEnd))
   128     # If the target is 'foo-only', check if our goal was stated as 'foo'
   128         # If the target is 'foo-only', check if our goal was stated as 'foo'
   129     $(if $(filter $@,$(call LastGoal)-only),$(call AtMakeEnd))
   129 	$(if $(filter $@,$(call LastGoal)-only),$(call AtMakeEnd))
   130 endef
   130 endef
   131 
   131 
   132 # Hook to be called when starting to execute a top-level target
   132 # Hook to be called when starting to execute a top-level target
   133 define TargetEnter
   133 define TargetEnter
   134     $(BUILD_LOG_WRAPPER) $(PRINTF) "## Starting $(patsubst %-only,%,$@)\n"
   134 	$(BUILD_LOG_WRAPPER) $(PRINTF) "## Starting $(patsubst %-only,%,$@)\n"
   135     $(call RecordStartTime,$(patsubst %-only,%,$@))
   135 	$(call RecordStartTime,$(patsubst %-only,%,$@))
   136 endef
   136 endef
   137 
   137 
   138 # Hook to be called when finish executing a top-level target
   138 # Hook to be called when finish executing a top-level target
   139 define TargetExit
   139 define TargetExit
   140     $(call RecordEndTime,$(patsubst %-only,%,$@))
   140 	$(call RecordEndTime,$(patsubst %-only,%,$@))
   141     $(BUILD_LOG_WRAPPER) $(PRINTF) "## Finished $(patsubst %-only,%,$@) (build time %s)\n\n" \
   141 	$(BUILD_LOG_WRAPPER) $(PRINTF) "## Finished $(patsubst %-only,%,$@) (build time %s)\n\n" \
   142         "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_$(patsubst %-only,%,$@) | $(CUT) -f 1 -d ' '`"
   142 	    "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_$(patsubst %-only,%,$@) | $(CUT) -f 1 -d ' '`"
   143     $(call CheckIfMakeAtEnd)
   143 	$(call CheckIfMakeAtEnd)
   144 endef
   144 endef
   145 
   145 
   146 # Hook to be called as the very first thing when running a normal build
   146 # Hook to be called as the very first thing when running a normal build
   147 define AtMakeStart
   147 define AtMakeStart
   148     $(if $(findstring --jobserver,$(MAKEFLAGS)),$(error make -j is not supported, use make JOBS=n))
   148 	$(if $(findstring --jobserver,$(MAKEFLAGS)),$(error make -j is not supported, use make JOBS=n))
   149     $(call CheckEnvironment)
   149 	$(call CheckEnvironment)
   150     @$(PRINTF) $(LOG_INFO) "Running make as '$(MAKE) $(MFLAGS) $(MAKE_ARGS)'\n"
   150 	@$(PRINTF) $(LOG_INFO) "Running make as '$(MAKE) $(MFLAGS) $(MAKE_ARGS)'\n"
   151     @$(PRINTF) "Building $(PRODUCT_NAME) for target '$(call GetRealTarget)' in configuration '$(CONF_NAME)'\n\n"
   151 	@$(PRINTF) "Building $(PRODUCT_NAME) for target '$(call GetRealTarget)' in configuration '$(CONF_NAME)'\n\n"
   152     $(call StartGlobalTimer)
   152 	$(call StartGlobalTimer)
   153 endef
   153 endef
   154 
   154 
   155 # Hook to be called as the very last thing for targets that are "top level" targets
   155 # Hook to be called as the very last thing for targets that are "top level" targets
   156 define AtMakeEnd
   156 define AtMakeEnd
   157     [ -f $(SJAVAC_SERVER_DIR)/server.port ] && echo Stopping sjavac server && $(TOUCH) $(SJAVAC_SERVER_DIR)/server.port.stop; true
   157 	[ -f $(SJAVAC_SERVER_DIR)/server.port ] && echo Stopping sjavac server && $(TOUCH) $(SJAVAC_SERVER_DIR)/server.port.stop; true
   158     $(call StopGlobalTimer)
   158 	$(call StopGlobalTimer)
   159     $(call ReportBuildTimes)
   159 	$(call ReportBuildTimes)
   160     @$(PRINTF) "Finished building $(PRODUCT_NAME) for target '$(call GetRealTarget)'\n"
   160 	@$(PRINTF) "Finished building $(PRODUCT_NAME) for target '$(call GetRealTarget)'\n"
   161     $(call CheckEnvironment)
   161 	$(call CheckEnvironment)
   162 endef
   162 endef
   163 
   163 
   164 ### Functions for parsing and setting up make options from command-line
   164 ### Functions for parsing and setting up make options from command-line
   165 
   165 
   166 define FatalError
   166 define FatalError
   167     # If the user specificed a "global" target (e.g. 'help'), do not exit but continue running
   167   # If the user specificed a "global" target (e.g. 'help'), do not exit but continue running
   168     $$(if $$(filter-out $(global_targets),$$(call GetRealTarget)),$$(error Cannot continue))
   168   $$(if $$(filter-out $(global_targets),$$(call GetRealTarget)),$$(error Cannot continue))
   169 endef
   169 endef
   170 
   170 
   171 define ParseLogLevel
   171 define ParseLogLevel
   172     ifeq ($$(origin VERBOSE),undefined)
   172   ifeq ($$(origin VERBOSE),undefined)
   173         # Setup logging according to LOG (but only if VERBOSE is not given)
   173     # Setup logging according to LOG (but only if VERBOSE is not given)
   174 
   174 
   175         # If the "nofile" argument is given, act on it and strip it away
   175     # If the "nofile" argument is given, act on it and strip it away
   176         ifneq ($$(findstring nofile,$$(LOG)),)
   176     ifneq ($$(findstring nofile,$$(LOG)),)
   177           # Reset the build log wrapper, regardless of other values
   177       # Reset the build log wrapper, regardless of other values
   178           override BUILD_LOG_WRAPPER=
   178       override BUILD_LOG_WRAPPER=
   179           # COMMA is defined in spec.gmk, but that is not included yet
   179       # COMMA is defined in spec.gmk, but that is not included yet
   180           COMMA=,
   180       COMMA=,
   181           # First try to remove ",nofile" if it exists
   181       # First try to remove ",nofile" if it exists
   182           LOG_STRIPPED1=$$(subst $$(COMMA)nofile,,$$(LOG))
   182       LOG_STRIPPED1=$$(subst $$(COMMA)nofile,,$$(LOG))
   183           # Otherwise just remove "nofile"
   183       # Otherwise just remove "nofile"
   184           LOG_STRIPPED2=$$(subst nofile,,$$(LOG_STRIPPED1))
   184       LOG_STRIPPED2=$$(subst nofile,,$$(LOG_STRIPPED1))
   185           # We might have ended up with a leading comma. Remove it
   185       # We might have ended up with a leading comma. Remove it
   186           LOG_STRIPPED3=$$(strip $$(patsubst $$(COMMA)%,%,$$(LOG_STRIPPED2)))
   186       LOG_STRIPPED3=$$(strip $$(patsubst $$(COMMA)%,%,$$(LOG_STRIPPED2)))
   187           LOG_LEVEL:=$$(LOG_STRIPPED3)
   187       LOG_LEVEL:=$$(LOG_STRIPPED3)
       
   188     else
       
   189       LOG_LEVEL:=$$(LOG)
       
   190     endif
       
   191 
       
   192     ifeq ($$(LOG_LEVEL),)
       
   193       # Set LOG to "warn" as default if not set (and no VERBOSE given)
       
   194       override LOG_LEVEL=warn
       
   195     endif
       
   196     ifeq ($$(LOG_LEVEL),warn)
       
   197       VERBOSE=-s
       
   198     else ifeq ($$(LOG_LEVEL),info)
       
   199       VERBOSE=-s
       
   200     else ifeq ($$(LOG_LEVEL),debug)
       
   201       VERBOSE=
       
   202     else ifeq ($$(LOG_LEVEL),trace)
       
   203       VERBOSE=
       
   204     else
       
   205       $$(info Error: LOG must be one of: warn, info, debug or trace.)
       
   206       $$(eval $$(call FatalError))
       
   207     endif
       
   208   else
       
   209     # Provide resonable interpretations of LOG_LEVEL if VERBOSE is given.
       
   210     ifeq ($(VERBOSE),)
       
   211       LOG_LEVEL:=debug
       
   212     else
       
   213       LOG_LEVEL:=warn
       
   214     endif
       
   215     ifneq ($$(LOG),)
       
   216       # We have both a VERBOSE and a LOG argument. This is OK only if this is a repeated call by ourselves,
       
   217       # but complain if this is the top-level make call.
       
   218       ifeq ($$(MAKELEVEL),0)
       
   219         $$(info Cannot use LOG=$$(LOG) and VERBOSE=$$(VERBOSE) at the same time. Choose one.)
       
   220         $$(eval $$(call FatalError))
       
   221       endif
       
   222     endif
       
   223   endif
       
   224 endef
       
   225 
       
   226 define ParseConfAndSpec
       
   227   ifneq ($$(filter-out $(global_targets),$$(call GetRealTarget)),)
       
   228     # If we only have global targets, no need to bother with SPEC or CONF
       
   229     ifneq ($$(origin SPEC),undefined)
       
   230       # We have been given a SPEC, check that it works out properly
       
   231       ifeq ($$(wildcard $$(SPEC)),)
       
   232         $$(info Cannot locate spec.gmk, given by SPEC=$$(SPEC))
       
   233         $$(eval $$(call FatalError))
       
   234       endif
       
   235       ifneq ($$(origin CONF),undefined)
       
   236         # We also have a CONF argument. This is OK only if this is a repeated call by ourselves,
       
   237         # but complain if this is the top-level make call.
       
   238         ifeq ($$(MAKELEVEL),0)
       
   239           $$(info Cannot use CONF=$$(CONF) and SPEC=$$(SPEC) at the same time. Choose one.)
       
   240           $$(eval $$(call FatalError))
       
   241         endif
       
   242       endif
       
   243       # ... OK, we're satisfied, we'll use this SPEC later on
       
   244     else
       
   245       # Find all spec.gmk files in the build output directory
       
   246       output_dir=$$(root_dir)/build
       
   247       all_spec_files=$$(wildcard $$(output_dir)/*/spec.gmk)
       
   248       ifeq ($$(all_spec_files),)
       
   249         $$(info No configurations found for $$(root_dir)! Please run configure to create a configuration.)
       
   250         $$(eval $$(call FatalError))
       
   251       endif
       
   252       # Extract the configuration names from the path
       
   253       all_confs=$$(patsubst %/spec.gmk,%,$$(patsubst $$(output_dir)/%,%,$$(all_spec_files)))
       
   254 
       
   255       ifneq ($$(origin CONF),undefined)
       
   256         # User have given a CONF= argument.
       
   257         ifeq ($$(CONF),)
       
   258           # If given CONF=, match all configurations
       
   259           matching_confs=$$(strip $$(all_confs))
   188         else
   260         else
   189           LOG_LEVEL:=$$(LOG)
   261           # Otherwise select those that contain the given CONF string
       
   262           matching_confs=$$(strip $$(foreach var,$$(all_confs),$$(if $$(findstring $$(CONF),$$(var)),$$(var))))
   190         endif
   263         endif
   191 
   264         ifeq ($$(matching_confs),)
   192         ifeq ($$(LOG_LEVEL),)
   265           $$(info No configurations found matching CONF=$$(CONF))
   193             # Set LOG to "warn" as default if not set (and no VERBOSE given)
   266           $$(info Available configurations:)
   194             override LOG_LEVEL=warn
   267           $$(foreach var,$$(all_confs),$$(info * $$(var)))
       
   268           $$(eval $$(call FatalError))
       
   269         else
       
   270           ifeq ($$(words $$(matching_confs)),1)
       
   271             $$(info Building '$$(matching_confs)' (matching CONF=$$(CONF)))
       
   272           else
       
   273             $$(info Building target '$(call GetRealTarget)' in the following configurations (matching CONF=$$(CONF)):)
       
   274             $$(foreach var,$$(matching_confs),$$(info * $$(var)))
       
   275           endif
   195         endif
   276         endif
   196         ifeq ($$(LOG_LEVEL),warn)
   277 
   197             VERBOSE=-s
   278         # Create a SPEC definition. This will contain the path to one or more spec.gmk files.
   198         else ifeq ($$(LOG_LEVEL),info)
   279         SPEC=$$(addsuffix /spec.gmk,$$(addprefix $$(output_dir)/,$$(matching_confs)))
   199             VERBOSE=-s
   280       else
   200         else ifeq ($$(LOG_LEVEL),debug)
   281         # No CONF or SPEC given, check the available configurations
   201             VERBOSE=
   282         ifneq ($$(words $$(all_spec_files)),1)
   202         else ifeq ($$(LOG_LEVEL),trace)
   283           $$(info No CONF given, but more than one configuration found in $$(output_dir).)
   203             VERBOSE=
   284           $$(info Available configurations:)
   204         else
   285           $$(foreach var,$$(all_confs),$$(info * $$(var)))
   205             $$(info Error: LOG must be one of: warn, info, debug or trace.)
   286           $$(info Please retry building with CONF=<config pattern> (or SPEC=<specfile>))
   206             $$(eval $$(call FatalError))
   287           $$(eval $$(call FatalError))
   207         endif
   288         endif
   208     else
   289 
   209         # Provide resonable interpretations of LOG_LEVEL if VERBOSE is given.
   290         # We found exactly one configuration, use it
   210         ifeq ($(VERBOSE),)
   291         SPEC=$$(strip $$(all_spec_files))
   211             LOG_LEVEL:=debug
   292       endif
   212         else
   293     endif
   213             LOG_LEVEL:=warn
   294   endif
   214         endif
       
   215         ifneq ($$(LOG),)
       
   216             # We have both a VERBOSE and a LOG argument. This is OK only if this is a repeated call by ourselves,
       
   217             # but complain if this is the top-level make call.
       
   218             ifeq ($$(MAKELEVEL),0)
       
   219                 $$(info Cannot use LOG=$$(LOG) and VERBOSE=$$(VERBOSE) at the same time. Choose one.)
       
   220                 $$(eval $$(call FatalError))
       
   221             endif
       
   222         endif
       
   223     endif
       
   224 endef
       
   225 
       
   226 define ParseConfAndSpec
       
   227     ifneq ($$(filter-out $(global_targets),$$(call GetRealTarget)),)
       
   228         # If we only have global targets, no need to bother with SPEC or CONF
       
   229         ifneq ($$(origin SPEC),undefined)
       
   230             # We have been given a SPEC, check that it works out properly
       
   231             ifeq ($$(wildcard $$(SPEC)),)
       
   232                 $$(info Cannot locate spec.gmk, given by SPEC=$$(SPEC))
       
   233                 $$(eval $$(call FatalError))
       
   234             endif
       
   235             ifneq ($$(origin CONF),undefined)
       
   236                 # We also have a CONF argument. This is OK only if this is a repeated call by ourselves,
       
   237                 # but complain if this is the top-level make call.
       
   238                 ifeq ($$(MAKELEVEL),0)
       
   239                     $$(info Cannot use CONF=$$(CONF) and SPEC=$$(SPEC) at the same time. Choose one.)
       
   240                     $$(eval $$(call FatalError))
       
   241                 endif
       
   242             endif
       
   243             # ... OK, we're satisfied, we'll use this SPEC later on
       
   244         else
       
   245             # Find all spec.gmk files in the build output directory
       
   246             output_dir=$$(root_dir)/build
       
   247             all_spec_files=$$(wildcard $$(output_dir)/*/spec.gmk)
       
   248             ifeq ($$(all_spec_files),)
       
   249                 $$(info No configurations found for $$(root_dir)! Please run configure to create a configuration.)
       
   250                 $$(eval $$(call FatalError))
       
   251             endif
       
   252             # Extract the configuration names from the path
       
   253             all_confs=$$(patsubst %/spec.gmk,%,$$(patsubst $$(output_dir)/%,%,$$(all_spec_files)))
       
   254 
       
   255             ifneq ($$(origin CONF),undefined)
       
   256                 # User have given a CONF= argument.
       
   257                 ifeq ($$(CONF),)
       
   258                     # If given CONF=, match all configurations
       
   259                     matching_confs=$$(strip $$(all_confs))
       
   260                 else
       
   261                     # Otherwise select those that contain the given CONF string
       
   262                     matching_confs=$$(strip $$(foreach var,$$(all_confs),$$(if $$(findstring $$(CONF),$$(var)),$$(var))))
       
   263                 endif
       
   264                 ifeq ($$(matching_confs),)
       
   265                     $$(info No configurations found matching CONF=$$(CONF))
       
   266                     $$(info Available configurations:)
       
   267                     $$(foreach var,$$(all_confs),$$(info * $$(var)))
       
   268                     $$(eval $$(call FatalError))
       
   269                 else
       
   270                     ifeq ($$(words $$(matching_confs)),1)
       
   271                         $$(info Building '$$(matching_confs)' (matching CONF=$$(CONF)))
       
   272                     else
       
   273                         $$(info Building target '$(call GetRealTarget)' in the following configurations (matching CONF=$$(CONF)):)
       
   274                         $$(foreach var,$$(matching_confs),$$(info * $$(var)))
       
   275                     endif
       
   276                 endif
       
   277 
       
   278                 # Create a SPEC definition. This will contain the path to one or more spec.gmk files.
       
   279                 SPEC=$$(addsuffix /spec.gmk,$$(addprefix $$(output_dir)/,$$(matching_confs)))
       
   280             else
       
   281                 # No CONF or SPEC given, check the available configurations
       
   282                 ifneq ($$(words $$(all_spec_files)),1)
       
   283                     $$(info No CONF given, but more than one configuration found in $$(output_dir).)
       
   284                     $$(info Available configurations:)
       
   285                     $$(foreach var,$$(all_confs),$$(info * $$(var)))
       
   286                     $$(info Please retry building with CONF=<config pattern> (or SPEC=<specfile>))
       
   287                     $$(eval $$(call FatalError))
       
   288                 endif
       
   289 
       
   290                 # We found exactly one configuration, use it
       
   291                 SPEC=$$(strip $$(all_spec_files))
       
   292             endif
       
   293         endif
       
   294     endif
       
   295 endef
   295 endef
   296 
   296 
   297 ### Convenience functions from Main.gmk
   297 ### Convenience functions from Main.gmk
   298 
   298 
   299 # Cleans the component given as $1
   299 # Cleans the component given as $1
   300 define CleanComponent
   300 define CleanComponent
   301     @$(PRINTF) "Cleaning $1 build artifacts ..."
   301 	@$(PRINTF) "Cleaning $1 build artifacts ..."
   302     @($(CD) $(OUTPUT_ROOT) && $(RM) -r $1)
   302 	@($(CD) $(OUTPUT_ROOT) && $(RM) -r $1)
   303     @$(PRINTF) " done\n"
   303 	@$(PRINTF) " done\n"
   304 endef
   304 endef
   305 
   305 
   306 endif # _MAKEHELPERS_GMK
   306 endif # _MAKEHELPERS_GMK