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 #
  25 
  26 # This must be the first rule
  27 default: all
  28 
  29 # Find out which variables were passed explicitely on the make command line. These
  30 # will be passed on to sub-makes, overriding spec.gmk settings.
  31 MAKE_ARGS=$(foreach var,$(subst =command,,$(filter %=command,$(foreach var,$(.VARIABLES),$(var)=$(firstword $(origin $(var)))))),$(var)=$($(var)))
  32 
  33 define fatal-error
  34     # If the user specificed a "global" target (e.g. 'help'), do not exit but continue running
  35     $$(if $$(findstring help,$$(MAKECMDGOALS)),,$$(error Cannot continue))
  36 endef
  37 
  38 ifeq ($(origin VERBOSE),undefined)
  39     # Setup logging according to LOG (but only if VERBOSE is not given)
  40     ifeq ($(LOG),)
  41         # Set LOG to "warn" as default if not set (and no VERBOSE given)
  42         LOG=warn
  43     endif
  44     ifeq ($(LOG),warn)
  45         VERBOSE=-s
  46     else ifeq ($(LOG),info)
  47         VERBOSE=
  48     else ifeq ($(LOG),debug)
  49         VERBOSE=
  50     else ifeq ($(LOG),trace)
  51         VERBOSE=-d -p
  52     else
  53         $(info Error: LOG must be one of: warn, info, debug or trace.)
  54         $(eval $(call fatal-error))
  55     endif
  56 else
  57     ifneq ($(LOG),)
  58         # We have both a VERBOSE and a LOG argument. This is OK only if this is a repeated call by ourselves,
  59         # but complain if this is the top-level make call.
  60         ifeq ($(MAKELEVEL),0)
  61             $(info Cannot use LOG=$(LOG) and VERBOSE=$(VERBOSE) at the same time. Choose one.)
  62             $(eval $(call fatal-error))
  63         endif
  64     endif
  65 endif
  66 
  67 # TODO: Fix duplication in MakeBase.gmk
  68 define SetupLogging
  69     ifneq ($(findstring $(LOG),debug trace),)
  70         # Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make
  71         OLD_SHELL:=$$(SHELL)
  72         SHELL = $$(warning Building $$@$$(if $$<, (from $$<))$(if $$?, ($$? newer)))$$(OLD_SHELL) -x
  73     endif
  74 endef
  75 
  76 $(eval $(call SetupLogging))
  77 
  78 # Find all environment or command line variables that begin with ALT.
  79 list_alt_overrides_with_origins = $(filter ALT_%=environment ALT_%=command,$(foreach var,$(.VARIABLES),$(var)=$(firstword $(origin $(var)))))
  80 list_alt_overrides=$(subst =command,,$(subst =environment,,$(list_alt_overrides_with_origins)))
  81 
  82 ifeq ($(filter /%,$(lastword $(MAKEFILE_LIST))),)
  83     makefile_path=$(CURDIR)/$(lastword $(MAKEFILE_LIST))
  84 else
  85     makefile_path=$(lastword $(MAKEFILE_LIST))
  86 endif
  87 root_dir=$(patsubst %/common/makefiles/Makefile,%,$(makefile_path))
  88 output_dir=$(root_dir)/build
  89 
  90 ifneq ($(origin SPEC),undefined)
  91     # We have been given a SPEC, check that it works out properly
  92     ifeq ($(wildcard $(SPEC)),)
  93         $(info Cannot locate spec.gmk, given by SPEC=$(SPEC))
  94         $(eval $(call fatal-error))
  95     endif
  96     ifneq ($(origin CONF),undefined)
  97         # We also have a CONF argument. This is OK only if this is a repeated call by ourselves,
  98         # but complain if this is the top-level make call.
  99         ifeq ($(MAKELEVEL),0)
 100             $(info Cannot use CONF=$(CONF) and SPEC=$(SPEC) at the same time. Choose one.)
 101             $(eval $(call fatal-error))
 102         endif
 103     endif
 104     # ... OK, we're satisfied, we'll use this SPEC later on
 105 else
 106     # Find all spec.gmk files in the build output directory
 107     all_spec_files=$(wildcard $(output_dir)/*/spec.gmk)
 108     ifeq ($(all_spec_files),)
 109         $(info No configurations found for $(root_dir)! Please run configure to create a configuration.)
 110         $(eval $(call fatal-error))
 111     endif
 112     # Extract the configuration names from the path
 113     all_confs=$(patsubst %/spec.gmk,%,$(patsubst $(output_dir)/%,%,$(all_spec_files)))
 114 
 115     ifneq ($(origin CONF),undefined)
 116         # User have given a CONF= argument.
 117         ifeq ($(CONF),)
 118             # If given CONF=, match all configurations
 119             matching_confs=$(strip $(all_confs))
 120         else
 121             # Otherwise select those that contain the given CONF string
 122             matching_confs=$(strip $(foreach var,$(all_confs),$(if $(findstring $(CONF),$(var)),$(var))))
 123         endif
 124         ifeq ($(matching_confs),)
 125             $(info No configurations found matching CONF=$(CONF))
 126             $(info Available configurations:)
 127             $(foreach var,$(all_confs),$(info * $(var)))
 128             $(eval $(call fatal-error))
 129         else
 130             ifeq ($(words $(matching_confs)),1)
 131                 $(info Building '$(matching_confs)' (matching CONF=$(CONF)))
 132             else
 133                 $(info Building the following configurations (matching CONF=$(CONF)):)
 134                 $(foreach var,$(matching_confs),$(info * $(var)))
 135             endif
 136         endif
 137 
 138         # Create a SPEC definition. This will contain the path to one or more spec.gmk files.
 139         SPEC=$(addsuffix /spec.gmk,$(addprefix $(output_dir)/,$(matching_confs)))
 140     else
 141         # No CONF or SPEC given, check the available configurations
 142         ifneq ($(words $(all_spec_files)),1)
 143             $(info No CONF or SPEC given, but more than one spec.gmk found in $(output_dir).)
 144             $(info Available configurations:)
 145             $(foreach var,$(all_confs),$(info * $(var)))
 146             $(info Please retry building with CONF=<config> or SPEC=<specfile>)
 147             $(eval $(call fatal-error))
 148         endif
 149 
 150         # We found exactly one configuration, use it
 151         SPEC=$(strip $(all_spec_files))
 152     endif
 153 endif
 154 
 155 ifneq ($(words $(SPEC)),1)
 156 # We have multiple configurations to build, call make repeatedly
 157 all jdk hotspot jaxws jaxp corba langtools install images packages clean dist-clean:
 158         @$(foreach spec,$(SPEC),($(MAKE) -f $(makefile_path) SPEC=$(spec) $(VERBOSE) VERBOSE=$(VERBOSE) $@ $(MAKE_ARGS)) &&) true
 159 
 160 .PHONY: all jdk hotspot jaxws jaxp corba langtools install images packages clean dist-clean
 161 
 162 else
 163 # This is the main part of the Makefile, for the normal case with SPEC specifying a single existing spec.gmk file.
 164 
 165 # Now load the spec
 166 -include $(SPEC)
 167 
 168 # Load the vital tools for all the makefiles. 
 169 -include $(SRC_ROOT)/common/makefiles/MakeBase.gmk
 170 
 171 # Remove any build.log from a previous run
 172 ifneq (,$(BUILD_LOG))
 173     $(shell $(RM) $(BUILD_LOG))
 174 endif
 175 
 176 # Remove any javac server logs and port files. This
 177 # prevents a new make run to reuse the previous servers.
 178 ifneq (,$(JAVAC_SERVERS))
 179     $(shell mkdir -p $(JAVAC_SERVERS) && rm -rf $(JAVAC_SERVERS)/*)
 180 endif
 181 # Reset the build timers.
 182 $(eval $(call ResetTimers))
 183 # Clean out any notifications from the previous build.
 184 $(shell find $(OUTPUT_ROOT) -name "_the.*.notify" $(FIND_DELETE))
 185 
 186 # If make was called explicitely with -j, don't add a -j ourself to sub-makes, since
 187 # this will be inherited automatically by make. Otherwise use our default for sub-makes.
 188 # The -j in MAKEFLAGS is only visible when executing a recipe, hence this macro.
 189 define GetMakeJobFlag
 190     $(if $(findstring -j,$(MAKEFLAGS)),,-j$(NUM_CORES))
 191 endef
 192 
 193 define CheckEnvironment
 194     $(if $(list_alt_overrides),
 195         @$(PRINTF) "\nWARNING: You have the following ALT_ variables set:\n"
 196     @$(PRINTF) "$(foreach var,$(list_alt_overrides),$(var)=$$$(var))\n"
 197     @$(PRINTF) "ALT_ variables are deprecated and will be ignored. Please clean your environment.\n"
 198     )
 199 endef
 200 
 201 define PrintStartMessage
 202     $(if $(VERBOSE),,@$(ECHO) Running make as $(MAKE) $(MFLAGS) $(MAKE_ARGS))
 203     $(call CheckEnvironment)
 204     @$(ECHO) "Building OpenJDK for target $(if $(MAKECMDGOALS),'$(MAKECMDGOALS)','all') in configuration '$(CONF_NAME)'"
 205 endef
 206 
 207 define PrintEndMessage
 208     @$(ECHO) "Finished building OpenJDK for target '$@'"
 209     $(call CheckEnvironment)
 210 endef
 211 
 212 all: jdk
 213         @$(if $(JAVAC_SERVERS),rm -rf $(JAVAC_SERVERS)/*.port)
 214         @$(call AtRootMakeEnd)
 215 
 216 langtools: start-make
 217         @$(call MakeStart,langtools,all)
 218         @($(CD) $(LANGTOOLS_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(LANGTOOLS_MAKE_ARGS) $(MAKE_ARGS))
 219         @$(call MakeFinish,langtools,all)
 220 
 221 corba: langtools
 222         @$(call MakeStart,corba,all)
 223         @($(CD) $(CORBA_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(CORBA_MAKE_ARGS) $(MAKE_ARGS))
 224         @$(call MakeFinish,corba,all)
 225 
 226 jaxp: langtools
 227         @$(call MakeStart,jaxp,all)
 228         @($(CD) $(JAXP_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(CORBA_MAKE_ARGS) $(MAKE_ARGS))
 229         @$(call MakeFinish,jaxp,all)
 230 
 231 jaxws: langtools jaxp
 232         @$(call MakeStart,jaxws,all)
 233         @($(CD) $(JAXWS_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(CORBA_MAKE_ARGS) $(MAKE_ARGS))
 234         @$(call MakeFinish,jaxws,all)
 235 
 236 hotspot: langtools
 237         @$(call MakeStart,hotspot,all)
 238         @($(CD) $(HOTSPOT_TOPDIR)/make && $(BUILD_LOG_WRAPPER) $(MAKE) -j1 $(HOTSPOT_MAKE_ARGS) $(MAKE_ARGS))
 239         @$(call MakeFinish,hotspot,all)
 240 
 241 jdk: langtools corba jaxp jaxws hotspot
 242         @$(call MakeStart,jdk,all)
 243         @($(CD) $(JDK_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(JDK_MAKE_ARGS) $(MAKE_ARGS))
 244         @$(call MakeFinish,jdk,all)
 245 
 246 images install packages: source-tips start-make jdk langtools corba jaxp jaxws hotspot
 247         @$(call MakeStart,jdk-images,$@)
 248         @($(CD) $(JDK_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(JDK_MAKE_ARGS) $(MAKE_ARGS) $@)
 249         @$(call MakeFinish,jdk-images,$@)
 250         @$(if $(JAVAC_SERVERS),rm -rf $(JAVAC_SERVERS)/*.port)
 251         @$(call AtRootMakeEnd)
 252 
 253 old-images: source-tips start-make jdk langtools corba jaxp jaxws hotspot
 254         @$(call MakeStart,jdk-old-images,$@)
 255         @($(CD) $(JDK_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(JDK_MAKE_ARGS) $(MAKE_ARGS) $@)
 256         @$(call MakeFinish,old-jdk-images,$@)
 257         @$(if $(JAVAC_SERVERS),rm -rf $(JAVAC_SERVERS)/*.port)
 258         @$(call AtRootMakeEnd)
 259 
 260 start-make:
 261         @$(call AtRootMakeStart)
 262 
 263 .PHONY: jdk hotspot jaxws jaxp corba langtools install images packages start-make
 264 
 265 test: start-make
 266         @$(call MakeStart,test,$(if $(TEST),$(TEST),all))
 267         @($(CD) $(SRC_ROOT)/test && $(BUILD_LOG_WRAPPER) $(MAKE) MAKEFLAGS= -j1 PRODUCT_HOME=$(OUTPUT_ROOT)/jdk JPRT_JAVA_HOME=$(OUTPUT_ROOT)/jdk ALT_OUTPUTDIR=$(OUTPUT_ROOT) $(TEST)) || true
 268         @$(call MakeFinish,test,$(if $(TEST),$(TEST),all))
 269         @$(call AtRootMakeEnd)
 270 .PHONY: test
 271 
 272 
 273 # Stores the tips for each repository. This file is be used when constructing the jdk image and can be
 274 # used to track the exact sources used to build that image.
 275 source-tips: $(OUTPUT_ROOT)/source_tips
 276 $(OUTPUT_ROOT)/source_tips: FRC
 277         @$(MKDIR) -p $(@D)
 278         @$(RM) $@
 279         @$(call GetSourceTips)
 280 
 281 
 282 # Remove everything, except the output from configure.
 283 clean:
 284         @(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`)
 285         @$(ECHO) Cleaned everything except the build configuration.
 286 .PHONY: clean
 287 
 288 # Remove everything, you have to rerun configure.
 289 dist-clean:
 290         @$(RM) -r $(OUTPUT_ROOT)
 291         @$(ECHO) Cleaned everything, you will have to re-run configure.
 292 .PHONY: dist-clean
 293 
 294 clean-jdk:
 295         @(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 | \
 296                                grep -v langtools | grep -v corba | grep -v jaxp | grep -v jaxws | grep -v hotspot`)
 297         @$(ECHO) "Cleaned jdk build artifacts (but not langtools,corba,jaxp,jaxws,hotspot nor the build configuration)"
 298 .PHONY: clean
 299 
 300 endif
 301 
 302 # Here are "global" targets, i.e. targets that can be executed without specifying a single configuration.
 303 # If you addd more global targets, please update the fatal-error macro.
 304 
 305 help:
 306         $(info )
 307         $(info OpenJDK Makefile help)
 308         $(info =====================)
 309         $(info )
 310         $(info Common make targets)
 311         $(info .  make [all]            # Compile all code but do not create images)
 312         $(info .  make images           # Create complete j2sdk and j2re images)
 313         $(info .  make install          # Install the generated images locally)
 314         $(info .  make clean            # Remove all files generated by make, but not those generated by configure)
 315         $(info .  make dist-clean       # Remove all files generated by both make and configure)
 316         $(info .  make help             # Give some help on using make)
 317         $(info .  make test             # Run tests, default is all tests (see TEST below))
 318         $(info )
 319         $(info Useful make variables)
 320         $(info .  make CONF=            # Build all configurations (note, assignment is empty))
 321         $(info .  make CONF=<substring> # Build the configuration(s) with a name matching the given substring)
 322         $(info )
 323         $(info .  make LOG=<loglevel>   # Change loglevel from warn (default) to the given loglevel)
 324         $(info .                        # Available loglevels are: warn, info, debug and trace)
 325         $(info .                        # To see executed command lines, use LOG=info)
 326         $(info )
 327         $(info .  make test TEST=<test> # Only run the given test or tests, e.g.)
 328         $(info .                        # make test TEST="jdk_lang jdk_net")
 329         $(info )
 330 .PHONY: help
 331 FRC: # Force target