Makefile 13.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#
# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.  Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
# 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
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
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))
77 78 79 80

# 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)))
81 82 83 84 85

ifeq ($(filter /%,$(lastword $(MAKEFILE_LIST))),)
    makefile_path=$(CURDIR)/$(lastword $(MAKEFILE_LIST))
else
    makefile_path=$(lastword $(MAKEFILE_LIST))
86
endif
87 88
root_dir=$(patsubst %/common/makefiles/Makefile,%,$(makefile_path))
output_dir=$(root_dir)/build
89

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
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)))
114

115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
    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
137

138 139
        # 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)))
140
    else
141 142 143 144 145 146 147 148 149 150 151
        # 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))
152
    endif
153 154 155 156 157 158 159 160 161
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:
	@$(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

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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185

# Now load the spec
-include $(SPEC)

# Load the vital tools for all the makefiles. 
-include $(SRC_ROOT)/common/makefiles/MakeBase.gmk

# Remove any build.log from a previous run
ifneq (,$(BUILD_LOG))
    $(shell $(RM) $(BUILD_LOG))
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))

186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
# 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

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

212 213
all: jdk
	@$(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 220 221 222
	@$(call MakeFinish,langtools,all)

corba: langtools
	@$(call MakeStart,corba,all)
223
	@($(CD) $(CORBA_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(CORBA_MAKE_ARGS) $(MAKE_ARGS))
224 225 226 227
	@$(call MakeFinish,corba,all)

jaxp: langtools
	@$(call MakeStart,jaxp,all)
228
	@($(CD) $(JAXP_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(CORBA_MAKE_ARGS) $(MAKE_ARGS))
229 230 231 232
	@$(call MakeFinish,jaxp,all)

jaxws: langtools jaxp
	@$(call MakeStart,jaxws,all)
233
	@($(CD) $(JAXWS_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(CORBA_MAKE_ARGS) $(MAKE_ARGS))
234 235 236 237
	@$(call MakeFinish,jaxws,all)

hotspot: langtools
	@$(call MakeStart,hotspot,all)
238
	@($(CD) $(HOTSPOT_TOPDIR)/make && $(BUILD_LOG_WRAPPER) $(MAKE) -j1 $(HOTSPOT_MAKE_ARGS) $(MAKE_ARGS))
239 240 241 242
	@$(call MakeFinish,hotspot,all)

jdk: langtools corba jaxp jaxws hotspot
	@$(call MakeStart,jdk,all)
243
	@($(CD) $(JDK_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(JDK_MAKE_ARGS) $(MAKE_ARGS))
244 245
	@$(call MakeFinish,jdk,all)

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 250
	@$(call MakeFinish,jdk-images,$@)
	@$(if $(JAVAC_SERVERS),rm -rf $(JAVAC_SERVERS)/*.port)
251 252 253 254 255 256 257 258
	@$(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,$@)
	@$(if $(JAVAC_SERVERS),rm -rf $(JAVAC_SERVERS)/*.port)
	@$(call AtRootMakeEnd)
259

260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
start-make:
	@$(call AtRootMakeStart)

.PHONY: jdk hotspot jaxws jaxp corba langtools install images packages start-make

test: start-make
	@$(call MakeStart,test,$(if $(TEST),$(TEST),all))
	@($(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
	@$(call MakeFinish,test,$(if $(TEST),$(TEST),all))
	@$(call AtRootMakeEnd)
.PHONY: test


# Stores the tips for each repository. This file is be used when constructing the jdk image and can be
# used to track the exact sources used to build that image.
source-tips: $(OUTPUT_ROOT)/source_tips
$(OUTPUT_ROOT)/source_tips: FRC
	@$(MKDIR) -p $(@D)
	@$(RM) $@
	@$(call GetSourceTips)
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299


# 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`)
	@$(ECHO) Cleaned everything except the build configuration.
.PHONY: clean

# Remove everything, you have to rerun configure.
dist-clean:
	@$(RM) -r $(OUTPUT_ROOT)
	@$(ECHO) Cleaned everything, you will have to re-run configure.
.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 | \
                               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

300
endif
301

302 303
# Here are "global" targets, i.e. targets that can be executed without specifying a single configuration.
# If you addd more global targets, please update the fatal-error macro.
304

305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
help:
	$(info )
	$(info OpenJDK Makefile help)
	$(info =====================)
	$(info )
	$(info Common make targets)
	$(info .  make [all]            # Compile all code but do not create images)
	$(info .  make images           # Create complete j2sdk and j2re images)
	$(info .  make install          # Install the generated images locally)
	$(info .  make clean            # Remove all files generated by make, but not those generated by configure)
	$(info .  make dist-clean       # Remove all files generated by both make and configure)
	$(info .  make help             # Give some help on using make)
	$(info .  make test             # Run tests, default is all tests (see TEST below))
	$(info )
	$(info Useful make variables)
	$(info .  make CONF=            # Build all configurations (note, assignment is empty))
	$(info .  make CONF=<substring> # Build the configuration(s) with a name matching the given substring)
	$(info )
	$(info .  make LOG=<loglevel>   # Change loglevel from warn (default) to the given loglevel)
	$(info .                        # Available loglevels are: warn, info, debug and trace)
	$(info .                        # To see executed command lines, use LOG=info)
	$(info )
	$(info .  make test TEST=<test> # Only run the given test or tests, e.g.)
	$(info .                        # make test TEST="jdk_lang jdk_net")
	$(info )
.PHONY: help
FRC: # Force target