common/makefiles/Makefile
changeset 13132 bd88bb8dd3af
parent 12801 948f8ad66ee7
child 13697 5262b00bc10c
--- a/common/makefiles/Makefile	Wed Jul 05 18:14:56 2017 +0200
+++ b/common/makefiles/Makefile	Tue Jul 03 16:11:12 2012 -0700
@@ -26,241 +26,128 @@
 # This must be the first rule
 default: all
 
-# Find out which variables were passed explicitely on the make command line. These
-# will be passed on to sub-makes, overriding spec.gmk settings.
-MAKE_ARGS=$(foreach var,$(subst =command,,$(filter %=command,$(foreach var,$(.VARIABLES),$(var)=$(firstword $(origin $(var)))))),$(var)=$($(var)))
-
-define fatal-error
-    # If the user specificed a "global" target (e.g. 'help'), do not exit but continue running
-    $$(if $$(findstring help,$$(MAKECMDGOALS)),,$$(error Cannot continue))
-endef
-
-ifeq ($(origin VERBOSE),undefined)
-    # Setup logging according to LOG (but only if VERBOSE is not given)
-    ifeq ($(LOG),)
-        # Set LOG to "warn" as default if not set (and no VERBOSE given)
-        LOG=warn
-    endif
-    ifeq ($(LOG),warn)
-        VERBOSE=-s
-    else ifeq ($(LOG),info)
-        VERBOSE=
-    else ifeq ($(LOG),debug)
-        VERBOSE=
-    else ifeq ($(LOG),trace)
-        VERBOSE=-d -p
-    else
-        $(info Error: LOG must be one of: warn, info, debug or trace.)
-        $(eval $(call fatal-error))
-    endif
+# Locate this Makefile
+ifeq ($(filter /%,$(lastword $(MAKEFILE_LIST))),)
+    makefile_path:=$(CURDIR)/$(lastword $(MAKEFILE_LIST))
 else
-    ifneq ($(LOG),)
-        # We have both a VERBOSE and a LOG argument. This is OK only if this is a repeated call by ourselves,
-        # but complain if this is the top-level make call.
-        ifeq ($(MAKELEVEL),0)
-            $(info Cannot use LOG=$(LOG) and VERBOSE=$(VERBOSE) at the same time. Choose one.)
-            $(eval $(call fatal-error))
-        endif
-    endif
+    makefile_path:=$(lastword $(MAKEFILE_LIST))
 endif
-
-# TODO: Fix duplication in MakeBase.gmk
-define SetupLogging
-    ifneq ($(findstring $(LOG),debug trace),)
-        # Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make
-        OLD_SHELL:=$$(SHELL)
-        SHELL = $$(warning Building $$@$$(if $$<, (from $$<))$(if $$?, ($$? newer)))$$(OLD_SHELL) -x
-    endif
-endef
-
-$(eval $(call SetupLogging))
-
-# Find all environment or command line variables that begin with ALT.
-list_alt_overrides_with_origins = $(filter ALT_%=environment ALT_%=command,$(foreach var,$(.VARIABLES),$(var)=$(firstword $(origin $(var)))))
-list_alt_overrides=$(subst =command,,$(subst =environment,,$(list_alt_overrides_with_origins)))
-
-ifeq ($(filter /%,$(lastword $(MAKEFILE_LIST))),)
-    makefile_path=$(CURDIR)/$(lastword $(MAKEFILE_LIST))
-else
-    makefile_path=$(lastword $(MAKEFILE_LIST))
-endif
-root_dir=$(patsubst %/common/makefiles/Makefile,%,$(makefile_path))
-output_dir=$(root_dir)/build
+root_dir:=$(patsubst %/common/makefiles/Makefile,%,$(makefile_path))
 
-ifneq ($(origin SPEC),undefined)
-    # We have been given a SPEC, check that it works out properly
-    ifeq ($(wildcard $(SPEC)),)
-        $(info Cannot locate spec.gmk, given by SPEC=$(SPEC))
-        $(eval $(call fatal-error))
-    endif
-    ifneq ($(origin CONF),undefined)
-        # We also have a CONF argument. This is OK only if this is a repeated call by ourselves,
-        # but complain if this is the top-level make call.
-        ifeq ($(MAKELEVEL),0)
-            $(info Cannot use CONF=$(CONF) and SPEC=$(SPEC) at the same time. Choose one.)
-            $(eval $(call fatal-error))
-        endif
-    endif
-    # ... OK, we're satisfied, we'll use this SPEC later on
-else
-    # Find all spec.gmk files in the build output directory
-    all_spec_files=$(wildcard $(output_dir)/*/spec.gmk)
-    ifeq ($(all_spec_files),)
-        $(info No configurations found for $(root_dir)! Please run configure to create a configuration.)
-        $(eval $(call fatal-error))
-    endif
-    # Extract the configuration names from the path
-    all_confs=$(patsubst %/spec.gmk,%,$(patsubst $(output_dir)/%,%,$(all_spec_files)))
+# ... and then we can include our helper functions
+include $(dir $(makefile_path))/MakeHelpers.gmk
 
-    ifneq ($(origin CONF),undefined)
-        # User have given a CONF= argument.
-        ifeq ($(CONF),)
-            # If given CONF=, match all configurations
-            matching_confs=$(strip $(all_confs))
-        else
-            # Otherwise select those that contain the given CONF string
-            matching_confs=$(strip $(foreach var,$(all_confs),$(if $(findstring $(CONF),$(var)),$(var))))
-        endif
-        ifeq ($(matching_confs),)
-            $(info No configurations found matching CONF=$(CONF))
-            $(info Available configurations:)
-            $(foreach var,$(all_confs),$(info * $(var)))
-            $(eval $(call fatal-error))
-        else
-            ifeq ($(words $(matching_confs)),1)
-                $(info Building '$(matching_confs)' (matching CONF=$(CONF)))
-            else
-                $(info Building the following configurations (matching CONF=$(CONF)):)
-                $(foreach var,$(matching_confs),$(info * $(var)))
-            endif
-        endif
+$(eval $(call ParseLogLevel))
+$(eval $(call SetupLogging))
+$(eval $(call ParseConfAndSpec))
 
-        # Create a SPEC definition. This will contain the path to one or more spec.gmk files.
-        SPEC=$(addsuffix /spec.gmk,$(addprefix $(output_dir)/,$(matching_confs)))
-    else
-        # No CONF or SPEC given, check the available configurations
-        ifneq ($(words $(all_spec_files)),1)
-            $(info No CONF or SPEC given, but more than one spec.gmk found in $(output_dir).)
-            $(info Available configurations:)
-            $(foreach var,$(all_confs),$(info * $(var)))
-            $(info Please retry building with CONF=<config> or SPEC=<specfile>)
-            $(eval $(call fatal-error))
-        endif
-
-        # We found exactly one configuration, use it
-        SPEC=$(strip $(all_spec_files))
-    endif
+# Setup number of jobs to use. -jN is unfortunately not available for us to parse from the command line,
+# hence this workaround.
+ifeq ($(JOBS),)
+    JOBS=$(NUM_CORES)
 endif
 
 ifneq ($(words $(SPEC)),1)
-# We have multiple configurations to build, call make repeatedly
-all jdk hotspot jaxws jaxp corba langtools install images packages clean dist-clean:
+### We have multiple configurations to build, call make repeatedly
+all jdk hotspot jaxws jaxp corba langtools install images clean dist-clean:
 	@$(foreach spec,$(SPEC),($(MAKE) -f $(makefile_path) SPEC=$(spec) $(VERBOSE) VERBOSE=$(VERBOSE) $@ $(MAKE_ARGS)) &&) true
 
-.PHONY: all jdk hotspot jaxws jaxp corba langtools install images packages clean dist-clean
+.PHONY: all jdk hotspot jaxws jaxp corba langtools install images clean dist-clean
 
 else
-# This is the main part of the Makefile, for the normal case with SPEC specifying a single existing spec.gmk file.
+### This is the main part of the Makefile, for the normal case with SPEC specifying a single existing spec.gmk file.
 
 # Now load the spec
--include $(SPEC)
+include $(SPEC)
 
 # Load the vital tools for all the makefiles. 
--include $(SRC_ROOT)/common/makefiles/MakeBase.gmk
+include $(SRC_ROOT)/common/makefiles/MakeBase.gmk
 
-# Remove any build.log from a previous run
+### Clean up from previous run
+
+# Remove any build.log from a previous run, if they exist
 ifneq (,$(BUILD_LOG))
-    $(shell $(RM) $(BUILD_LOG))
+    ifneq (,$(BUILD_LOG_PREVIOUS))
+        # Rotate old log
+        $(shell $(RM) $(BUILD_LOG_PREVIOUS) 2> /dev/null)
+        $(shell $(MV) $(BUILD_LOG) $(BUILD_LOG_PREVIOUS) 2> /dev/null)
+    else
+        $(shell $(RM) $(BUILD_LOG) 2> /dev/null)
+    endif
 endif
-
 # Remove any javac server logs and port files. This
 # prevents a new make run to reuse the previous servers.
 ifneq (,$(JAVAC_SERVERS))
     $(shell mkdir -p $(JAVAC_SERVERS) && rm -rf $(JAVAC_SERVERS)/*)
 endif
-# Reset the build timers.
-$(eval $(call ResetTimers))
 # Clean out any notifications from the previous build.
 $(shell find $(OUTPUT_ROOT) -name "_the.*.notify" $(FIND_DELETE))
 
-# If make was called explicitely with -j, don't add a -j ourself to sub-makes, since
-# this will be inherited automatically by make. Otherwise use our default for sub-makes.
-# The -j in MAKEFLAGS is only visible when executing a recipe, hence this macro.
-define GetMakeJobFlag
-    $(if $(findstring -j,$(MAKEFLAGS)),,-j$(NUM_CORES))
-endef
+# Reset the build timers.
+$(eval $(call ResetTimers))
 
-define CheckEnvironment
-    $(if $(list_alt_overrides),
-        @$(PRINTF) "\nWARNING: You have the following ALT_ variables set:\n"
-    @$(PRINTF) "$(foreach var,$(list_alt_overrides),$(var)=$$$(var))\n"
-    @$(PRINTF) "ALT_ variables are deprecated and will be ignored. Please clean your environment.\n"
-    )
-endef
-
-define PrintStartMessage
-    $(if $(VERBOSE),,@$(ECHO) Running make as $(MAKE) $(MFLAGS) $(MAKE_ARGS))
-    $(call CheckEnvironment)
-    @$(ECHO) "Building OpenJDK for target $(if $(MAKECMDGOALS),'$(MAKECMDGOALS)','all') in configuration '$(CONF_NAME)'"
-endef
-
-define PrintEndMessage
-    @$(ECHO) "Finished building OpenJDK for target '$@'"
-    $(call CheckEnvironment)
-endef
+### Main targets
 
 all: jdk
 	@$(if $(JAVAC_SERVERS),rm -rf $(JAVAC_SERVERS)/*.port)
 	@$(call AtRootMakeEnd)
 
-langtools: start-make
+langtools: start-make langtools-only
+langtools-only:
 	@$(call MakeStart,langtools,all)
-	@($(CD) $(LANGTOOLS_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(LANGTOOLS_MAKE_ARGS) $(MAKE_ARGS))
+	@($(CD) $(LANGTOOLS_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) -j$(JOBS) $(MAKE_ARGS))
 	@$(call MakeFinish,langtools,all)
 
-corba: langtools
+corba: langtools corba-only
+corba-only:
 	@$(call MakeStart,corba,all)
-	@($(CD) $(CORBA_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(CORBA_MAKE_ARGS) $(MAKE_ARGS))
+	@($(CD) $(CORBA_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) -j$(JOBS) $(MAKE_ARGS))
 	@$(call MakeFinish,corba,all)
 
-jaxp: langtools
+jaxp: langtools jaxp-only
+jaxp-only:
 	@$(call MakeStart,jaxp,all)
-	@($(CD) $(JAXP_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(CORBA_MAKE_ARGS) $(MAKE_ARGS))
+	@($(CD) $(JAXP_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) -j$(JOBS) $(MAKE_ARGS))
 	@$(call MakeFinish,jaxp,all)
 
-jaxws: langtools jaxp
+jaxws: langtools jaxp jaxws-only
+jaxws-only:
 	@$(call MakeStart,jaxws,all)
-	@($(CD) $(JAXWS_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(CORBA_MAKE_ARGS) $(MAKE_ARGS))
+	@($(CD) $(JAXWS_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) -j$(JOBS) $(MAKE_ARGS))
 	@$(call MakeFinish,jaxws,all)
 
-hotspot: langtools
+hotspot: langtools hotspot-only
+hotspot-only:
 	@$(call MakeStart,hotspot,all)
 	@($(CD) $(HOTSPOT_TOPDIR)/make && $(BUILD_LOG_WRAPPER) $(MAKE) -j1 $(HOTSPOT_MAKE_ARGS) $(MAKE_ARGS))
 	@$(call MakeFinish,hotspot,all)
 
-jdk: langtools corba jaxp jaxws hotspot
+jdk: langtools corba jaxp jaxws hotspot jdk-only
+jdk-only:
 	@$(call MakeStart,jdk,all)
-	@($(CD) $(JDK_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(JDK_MAKE_ARGS) $(MAKE_ARGS))
+	@($(CD) $(JDK_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) -j$(JOBS) $(MAKE_ARGS))
 	@$(call MakeFinish,jdk,all)
 
-images install packages: source-tips start-make jdk langtools corba jaxp jaxws hotspot
+images: source-tips start-make jdk langtools corba jaxp jaxws hotspot images-only
+images-only:
 	@$(call MakeStart,jdk-images,$@)
-	@($(CD) $(JDK_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(JDK_MAKE_ARGS) $(MAKE_ARGS) $@)
+	@($(CD) $(JDK_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) -j$(JOBS) $(JDK_MAKE_ARGS) $(MAKE_ARGS) images)
 	@$(call MakeFinish,jdk-images,$@)
 	@$(if $(JAVAC_SERVERS),rm -rf $(JAVAC_SERVERS)/*.port)
 	@$(call AtRootMakeEnd)
 
-old-images: source-tips start-make jdk langtools corba jaxp jaxws hotspot
-	@$(call MakeStart,jdk-old-images,$@)
-	@($(CD) $(JDK_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(JDK_MAKE_ARGS) $(MAKE_ARGS) $@)
-	@$(call MakeFinish,old-jdk-images,$@)
+install: source-tips start-make jdk langtools corba jaxp jaxws hotspot install-only
+install-only:
+	@$(call MakeStart,jdk-images,$@)
+	@($(CD) $(JDK_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) -j$(JOBS) $(JDK_MAKE_ARGS) $(MAKE_ARGS) install)
+	@$(call MakeFinish,jdk-images,$@)
 	@$(if $(JAVAC_SERVERS),rm -rf $(JAVAC_SERVERS)/*.port)
 	@$(call AtRootMakeEnd)
 
 start-make:
 	@$(call AtRootMakeStart)
 
-.PHONY: jdk hotspot jaxws jaxp corba langtools install images packages start-make
+.PHONY: jdk hotspot jaxws jaxp corba langtools install images start-make
 
 test: start-make
 	@$(call MakeStart,test,$(if $(TEST),$(TEST),all))
@@ -281,7 +168,7 @@
 
 # Remove everything, except the output from configure.
 clean:
-	@(cd $(OUTPUT_ROOT) && $(RM) -r `$(LS) $(OUTPUT_ROOT) | grep -v spec.gmk | grep -v Makefile | grep -v config.status | grep -v config.log | grep -v config.h | grep -v configure-arguments | grep -v "localdevenv.*" | grep -v uncygdrive.exe`)
+	@(cd $(OUTPUT_ROOT) && $(RM) -r `$(LS) $(OUTPUT_ROOT) | grep -v spec.gmk | grep -v spec.sh | grep -v Makefile | grep -v config.status | grep -v config.log | grep -v config.h | grep -v configure-arguments | grep -v "localdevenv.*" | grep -v uncygdrive.exe`)
 	@$(ECHO) Cleaned everything except the build configuration.
 .PHONY: clean
 
@@ -292,7 +179,7 @@
 .PHONY: dist-clean
 
 clean-jdk:
-	@(cd $(OUTPUT_ROOT) && $(RM) -r `$(LS) $(OUTPUT_ROOT) | grep -v spec.gmk | grep -v Makefile | grep -v config.status | grep -v config.log |  grep -v config.h | grep -v configure-arguments | \
+	@(cd $(OUTPUT_ROOT) && $(RM) -r `$(LS) $(OUTPUT_ROOT) | grep -v spec.gmk | grep -v spec.sh | grep -v Makefile | grep -v config.status | grep -v config.log |  grep -v config.h | grep -v configure-arguments | \
                                grep -v langtools | grep -v corba | grep -v jaxp | grep -v jaxws | grep -v hotspot`)
 	@$(ECHO) "Cleaned jdk build artifacts (but not langtools,corba,jaxp,jaxws,hotspot nor the build configuration)"
 .PHONY: clean