Main.gmk revision 1324:6bfd6ad07c7b
1#
2# Copyright (c) 2011, 2014, 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################################################################################
27# This is the main makefile containing most actual top level targets. It needs
28# to be called with a SPEC file defined.
29
30# Declare default target
31default:
32
33# Now load the spec
34include $(SPEC)
35
36include $(SRC_ROOT)/make/MakeHelpers.gmk
37
38# Load the vital tools for all the makefiles.
39include $(SRC_ROOT)/make/common/MakeBase.gmk
40include $(SRC_ROOT)/make/common/Modules.gmk
41
42# Declare ALL_TARGETS as an immediate variable. This variable is a list of all
43# valid top level targets. It's used to declare them all as PHONY and to
44# generate the -only targets.
45ALL_TARGETS :=
46
47# Hook to include the corresponding custom file, if present.
48$(eval $(call IncludeCustomExtension, , Main.gmk))
49
50# All modules for the current target platform.
51# Manually add jdk.hotspot.agent for now.
52ALL_MODULES := $(call FindAllModules) jdk.hotspot.agent
53
54################################################################################
55################################################################################
56#
57# Recipes for all targets. Only recipes, dependencies are declared later.
58#
59################################################################################
60
61################################################################################
62# Interim/build tools targets, compiling tools used during the build
63
64buildtools-langtools:
65	+($(CD) $(LANGTOOLS_TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Tools.gmk)
66
67interim-langtools:
68	+($(CD) $(LANGTOOLS_TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f CompileInterim.gmk)
69
70interim-corba:
71	+($(CD) $(CORBA_TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f CompileInterim.gmk)
72
73interim-rmic:
74	+($(CD) $(JDK_TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f CompileInterimRmic.gmk)
75
76buildtools-jdk:
77	+($(CD) $(JDK_TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Tools.gmk java-tools)
78
79ALL_TARGETS += buildtools-langtools interim-langtools interim-corba \
80    interim-rmic buildtools-jdk
81
82################################################################################
83# Special targets for certain modules
84
85import-hotspot:
86	+($(CD) $(JDK_TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Import.gmk)
87
88unpack-sec:
89	+($(CD) $(JDK_TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f UnpackSecurity.gmk)
90
91ALL_TARGETS += import-hotspot unpack-sec
92
93################################################################################
94# Gensrc targets, generating source before java compilation can be done
95$(eval $(call DeclareRecipesForPhase, GENSRC, \
96    TARGET_SUFFIX := gensrc, \
97    FILE_PREFIX := Gensrc, \
98    MAKE_SUBDIR := gensrc, \
99    CHECK_MODULES := $(ALL_MODULES), \
100    MULTIPLE_MAKEFILES := true))
101
102JDK_GENSRC_TARGETS := $(filter %-gensrc-jdk, $(GENSRC_TARGETS))
103LANGTOOLS_GENSRC_TARGETS := $(filter %-gensrc-langtools, $(GENSRC_TARGETS))
104CORBA_GENSRC_TARGETS := $(filter %-gensrc-corba, $(GENSRC_TARGETS))
105
106ALL_TARGETS += $(GENSRC_TARGETS)
107
108################################################################################
109# Generate data targets
110$(eval $(call DeclareRecipesForPhase, GENDATA, \
111    TARGET_SUFFIX := gendata, \
112    FILE_PREFIX := Gendata, \
113    MAKE_SUBDIR := gendata, \
114    CHECK_MODULES := $(ALL_MODULES), \
115    USE_WRAPPER := true))
116
117ALL_TARGETS += $(GENDATA_TARGETS)
118
119################################################################################
120# Copy files targets
121$(eval $(call DeclareRecipesForPhase, COPY, \
122    TARGET_SUFFIX := copy, \
123    FILE_PREFIX := Copy, \
124    MAKE_SUBDIR := copy, \
125    CHECK_MODULES := $(ALL_MODULES), \
126    USE_WRAPPER := true))
127
128ALL_TARGETS += $(COPY_TARGETS)
129
130################################################################################
131# Targets for compiling all java modules. Nashorn is treated separately.
132JAVA_MODULES := $(call FindJavaModules)
133JAVA_TARGETS := $(addsuffix -java, $(JAVA_MODULES))
134
135define DeclareCompileJavaRecipe
136  $1-java:
137	+($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f CompileJavaModules.gmk \
138	    $1 JAVA_MODULES=$1)
139endef
140
141$(foreach m, $(filter-out jdk.scripting.nashorn, $(JAVA_MODULES)), \
142    $(eval $(call DeclareCompileJavaRecipe,$m)))
143
144# Build nashorn. Needs to be compiled separately from the rest of the modules
145# due to nasgen.
146jdk.scripting.nashorn-java:
147	+($(CD) $(NASHORN_TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f BuildNashorn.gmk compile)
148
149ALL_TARGETS += $(JAVA_TARGETS)
150
151################################################################################
152# Targets for running rmic.
153$(eval $(call DeclareRecipesForPhase, RMIC, \
154    TARGET_SUFFIX := rmic, \
155    FILE_PREFIX := Rmic, \
156    MAKE_SUBDIR := rmic, \
157    CHECK_MODULES := $(ALL_MODULES)))
158
159ALL_TARGETS += $(RMIC_TARGETS)
160
161################################################################################
162# Targets for compiling native libraries
163$(eval $(call DeclareRecipesForPhase, LIBS, \
164    TARGET_SUFFIX := libs, \
165    FILE_PREFIX := Lib, \
166    MAKE_SUBDIR := lib, \
167    CHECK_MODULES := $(ALL_MODULES), \
168    USE_WRAPPER := true))
169
170ALL_TARGETS += $(LIBS_TARGETS)
171
172################################################################################
173# Targets for compiling native executables
174$(eval $(call DeclareRecipesForPhase, LAUNCHER, \
175    TARGET_SUFFIX := launchers, \
176    FILE_PREFIX := Launcher, \
177    MAKE_SUBDIR := launcher, \
178    CHECK_MODULES := $(ALL_MODULES), \
179    USE_WRAPPER := true))
180
181ALL_TARGETS += $(LAUNCHER_TARGETS)
182
183################################################################################
184# Build hotspot target
185
186ifeq ($(BUILD_HOTSPOT),true)
187  hotspot:
188	($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f HotspotWrapper.gmk)
189endif
190
191ALL_TARGETS += hotspot
192
193################################################################################
194# Build demos and samples targets
195
196demos:
197	+($(CD) $(JDK_TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f CompileDemos.gmk)
198
199samples:
200	+($(CD) $(JDK_TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f CopySamples.gmk)
201
202ALL_TARGETS += demos samples
203
204################################################################################
205# Image targets
206
207# Stores the tips for each repository. This file is be used when constructing the jdk image and can be
208# used to track the exact sources used to build that image.
209source-tips: $(SUPPORT_OUTPUTDIR)/source_tips
210$(SUPPORT_OUTPUTDIR)/source_tips: FRC
211	@$(MKDIR) -p $(@D)
212	@$(RM) $@
213	@$(call GetSourceTips)
214
215BOOTCYCLE_TARGET := product-images
216bootcycle-images:
217	@$(ECHO) Boot cycle build step 2: Building a new JDK image using previously built image
218	+$(MAKE) $(MAKE_ARGS) -f Main.gmk SPEC=$(dir $(SPEC))bootcycle-spec.gmk $(BOOTCYCLE_TARGET)
219
220zip-security:
221	+($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f ZipSecurity.gmk)
222
223zip-source:
224	+($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f ZipSource.gmk)
225
226strip-binaries:
227	+($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f StripBinaries.gmk)
228
229jrtfs-jar:
230	+($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f JrtfsJar.gmk)
231
232jimages:
233	+($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f Images.gmk jimages)
234
235profiles:
236	+($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f Images.gmk profiles)
237
238mac-bundles:
239	+($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f MacBundles.gmk)
240
241prepare-test-image:
242	$(MKDIR) -p $(TEST_IMAGE_DIR)
243	$(ECHO) > $(TEST_IMAGE_DIR)/Readme.txt 'JDK test image'
244
245ALL_TARGETS += source-tips bootcycle-images zip-security zip-source strip-binaries \
246    jrtfs-jar jimages profiles mac-bundles prepare-test-image
247
248################################################################################
249# Docs targets
250
251docs-javadoc:
252	+($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f Javadoc.gmk docs)
253
254docs-jvmtidoc:
255	+($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f Javadoc.gmk jvmtidocs)
256
257ALL_TARGETS += docs-javadoc docs-jvmtidoc
258
259################################################################################
260# Test target
261
262test:
263	($(CD) $(SRC_ROOT)/test && $(MAKE) $(MAKE_ARGS) -j1 -k MAKEFLAGS= \
264	    JT_HOME=$(JT_HOME) PRODUCT_HOME=$(JDK_IMAGE_DIR) \
265	    ALT_OUTPUTDIR=$(OUTPUT_ROOT) CONCURRENCY=$(JOBS) $(TEST)) || true
266
267test-make:
268	($(CD) $(SRC_ROOT)/test/make && $(MAKE) $(MAKE_ARGS) -f TestMake.gmk $(TEST_TARGET))
269
270ALL_TARGETS += test test-make
271
272################################################################################
273# Verification targets
274
275verify-modules:
276	@$(call TargetEnter)
277	+($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f CheckModules.gmk)
278	@$(call TargetExit)
279
280ALL_TARGETS += verify-modules
281
282################################################################################
283# Install targets
284
285install:
286	+($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f Install.gmk)
287
288ALL_TARGETS += install
289
290################################################################################
291#
292# Dependency declarations between targets.
293#
294# These are declared in two groups. First all dependencies between targets that
295# have recipes above as these dependencies may be disabled. Then the aggregator
296# targets that do not have recipes of their own, which will never have their
297# dependencies disabled.
298#
299################################################################################
300# Targets with recipes above
301
302# If running an *-only target, parallel execution and dependencies between
303# recipe targets are disabled. This makes it possible to run a select set of
304# recipe targets in order. It's the responsibility of the user to make sure
305# all prerequisites are fulfilled.
306ifneq ($(findstring -only, $(MAKECMDGOALS)), )
307  .NOTPARALLEL:
308else
309  $(LANGTOOLS_GENSRC_TARGETS): buildtools-langtools
310
311  interim-langtools: $(LANGTOOLS_GENSRC_TARGETS)
312
313  buildtools-jdk: interim-langtools
314
315  $(CORBA_GENSRC_TARGETS): interim-langtools
316
317  $(JDK_GENSRC_TARGETS): interim-langtools buildtools-jdk
318
319  interim-corba: $(CORBA_GENSRC_TARGETS)
320
321  $(GENDATA_TARGETS): interim-langtools buildtools-jdk
322
323  interim-rmic: interim-langtools
324
325  $(RMIC_TARGETS): interim-langtools interim-corba interim-rmic
326
327  import-hotspot: hotspot
328
329  $(LIBS_TARGETS): import-hotspot
330
331  $(LAUNCHER_TARGETS): java.base-libs
332
333  # The demos are currently linking to libjvm and libjava, just like all other
334  # jdk libs, even though they don't need to. To avoid warnings, make sure they
335  # aren't built until after libjava and libjvm are available to link to.
336  demos: $(JAVA_TARGETS)
337
338  # Declare dependency from <module>-java to <module>-gensrc
339  $(foreach m, $(GENSRC_MODULES), $(eval $m-java: $m-gensrc))
340
341  # Declare dependencies between java modules
342  $(foreach m, $(JAVA_MODULES), \
343      $(eval $m-java: $(addsuffix -java, $(filter $(JAVA_MODULES), \
344      $(call FindDepsForModule,$m)))))
345
346  # Declare dependencies between <module>-rmic to <module>-java
347  $(foreach m, $(RMIC_MODULES), $(eval $m-rmic: $m-java))
348
349  # Declare dependencies from <module>-lib to <module>-java
350  # Skip modules that do not have java source.
351  $(foreach m, $(filter $(JAVA_MODULES), $(LIBS_MODULES)), $(eval $m-libs: $m-java))
352
353  # Declare dependencies from all other <module>-lib to java.base-lib
354  $(foreach t, $(filter-out java.base-libs, $(LIBS_TARGETS)), \
355      $(eval $t: java.base-libs))
356  # Declare the special case dependency for jdk.deploy.osx where libosx
357  # links against libosxapp.
358  jdk.deploy.osx-libs: java.desktop-libs
359
360  # This dependency needs to be explicitly declared. jdk.jdi-gensrc generates a
361  # header file used by jdk.jdwp.agent-libs. The jdk.jdwp.agent-gensrc is a
362  # virtual target.
363  jdk.jdwp.agent-libs: jdk.jdwp.agent-gensrc
364
365  # Until the module system is in place, jdk.jdi-gensrc needs to combine service
366  # loader configuration with jdk.hotspot.agent so is dependent on importing
367  # hotspot.
368  jdk.jdi-gensrc-jdk: import-hotspot
369
370  # The swing beans need to have java base properly generated to avoid errors
371  # in javadoc.
372  java.desktop-gensrc-jdk: java.base-gensrc
373
374  # Explicitly add dependencies for special targets
375  java.base-java: unpack-sec
376
377  jdk.dev-gendata: java rmic
378
379  zip-security: java.base-java java.security.jgss-java java.security.jgss-libs \
380      $(filter jdk.crypto%, $(JAVA_TARGETS))
381
382  zip-source: gensrc rmic
383
384  strip-binaries: libs launchers gendata copy
385
386  jrtfs-jar: buildtools-jdk
387
388  jimages: exploded-image zip-source strip-binaries source-tips demos samples \
389      jrtfs-jar
390
391  profiles: exploded-image strip-binaries source-tips
392
393  mac-bundles: jimages
394
395  bootcycle-images: jimages
396
397  docs-javadoc: gensrc rmic
398
399  docs-jvmtidoc: hotspot
400
401  test: jimages
402
403  verify-modules: exploded-image
404
405  test-make: clean-test-make
406
407endif
408
409################################################################################
410# Virtual targets without recipes
411
412buildtools: buildtools-langtools interim-langtools interim-corba interim-rmic \
413    buildtools-jdk
414
415gensrc: $(GENSRC_TARGETS)
416
417gendata: $(GENDATA_TARGETS)
418
419copy: $(COPY_TARGETS)
420
421java: $(JAVA_TARGETS)
422
423rmic: $(RMIC_TARGETS)
424
425libs: $(LIBS_TARGETS)
426
427launchers: $(LAUNCHER_TARGETS)
428
429# Explicitly declare dependency for virtual target jdk.jdwp.agent-gensrc which
430# is actually handled by jdk.jdi-gensrc
431jdk.jdwp.agent-gensrc: jdk.jdi-gensrc
432
433# Declare dependencies from <module> to all the individual targets specific
434# to that module <module>-*.
435$(foreach m, $(GENSRC_MODULES), $(eval $m: $m-gensrc))
436$(foreach m, $(JAVA_MODULES), $(eval $m: $m-java))
437$(foreach m, $(GENDATA_MODULES), $(eval $m: $m-gendata))
438$(foreach m, $(RMIC_MODULES), $(eval $m: $m-rmic))
439$(foreach m, $(LIBS_MODULES), $(eval $m: $m-libs))
440$(foreach m, $(LAUNCHER_MODULES), $(eval $m: $m-launchers))
441$(foreach m, $(COPY_MODULES), $(eval $m: $m-copy))
442
443ALL_MODULE_TARGETS := $(sort $(GENSRC_MODULES) $(JAVA_MODULES) \
444    $(GENDATA_MODULES) $(LIBS_MODULES) $(LAUNCHER_MODULES) $(COPY_MODULES))
445
446# The "exploded image" is a locally runnable JDK in $(BUILD_OUTPUT)/jdk.
447exploded-image: $(ALL_MODULE_TARGETS)
448
449# The $(BUILD_OUTPUT)/images directory contain the resulting deliverables, 
450# and in line with this, our targets for creating these are named *-image[s].
451
452# This target builds the product images, e.g. the JRE and JDK image
453# (and possibly other, more specific versions)
454product-images: jimages demos samples zip-security verify-modules
455
456ifeq ($(OPENJDK_TARGET_OS), macosx)
457  product-images: mac-bundles
458endif
459
460# This target builds the documentation image
461docs-image: docs-javadoc docs-jvmtidoc
462
463# This target builds the test image
464test-image: prepare-test-image
465
466# all-images is the top-most target, it builds all our deliverables ("images").
467all-images: product-images test-image docs-image
468
469ALL_TARGETS += buildtools gensrc gendata copy java rmic libs launchers \
470    jdk.jdwp.agent-gensrc $(ALL_MODULE_TARGETS) exploded-image \
471    product-images docs-image test-image all-images
472
473################################################################################
474
475# Traditional targets typically run by users.
476# These can be considered aliases for the targets now named by a more
477# "modern" naming scheme.
478default: exploded-image
479jdk: exploded-image
480images: product-images
481docs: docs-image
482all: all-images
483
484ALL_TARGETS += default jdk images docs all
485
486################################################################################
487################################################################################
488#
489# Clean targets
490#
491################################################################################
492# Clean targets are automatically run serially by the Makefile calling this
493# file.
494
495CLEAN_DIRS += hotspot jdk bootcycle-build test buildtools support \
496    images make-support test-make
497CLEAN_DIR_TARGETS := $(addprefix clean-, $(CLEAN_DIRS))
498CLEAN_PHASES := gensrc java native include
499CLEAN_PHASE_TARGETS := $(addprefix clean-, $(CLEAN_PHASES))
500CLEAN_MODULE_TARGETS := $(addprefix clean-, $(ALL_MODULES))
501# Construct targets of the form clean-$module-$phase
502CLEAN_MODULE_PHASE_TARGETS := $(addprefix clean-, $(foreach m, $(ALL_MODULES), \
503    $(addprefix $m-, $(CLEAN_PHASES))))
504
505# Remove everything, except the output from configure.
506clean: $(CLEAN_DIR_TARGETS)
507	($(CD) $(OUTPUT_ROOT) && $(RM) -r source_tips build.log* build-trace*.log*)
508	$(ECHO) Cleaned all build artifacts.
509
510$(CLEAN_DIR_TARGETS):
511	$(call CleanDir,$(patsubst clean-%, %, $@))
512
513$(CLEAN_PHASE_TARGETS):
514	$(call Clean-$(patsubst clean-%,%, $@))
515
516$(CLEAN_MODULE_TARGETS):
517	$(call CleanModule,$(patsubst clean-%, %, $@))
518
519$(CLEAN_MODULE_PHASE_TARGETS):
520	$(call Clean-$(word 3, $(subst -,$(SPACE),$@)), \
521	    $(word 2, $(subst -,$(SPACE),$@)))
522
523# When removing the support dir, we must also remove jdk. Building classes has
524# the side effect of generating native headers. The headers end up in support
525# while classes and touch files end up in jdk.
526clean-support: clean-jdk
527
528clean-docs: clean-docstemp
529
530# Remove everything, including configure configuration.
531# If the output directory was created by configure and now becomes empty, remove it as well.
532dist-clean: clean
533	($(CD) $(OUTPUT_ROOT) && $(RM) -r *spec.gmk config.* configure-arguments \
534	    Makefile compare.sh tmp javacservers)
535	$(if $(filter $(CONF_NAME),$(notdir $(OUTPUT_ROOT))), \
536	  if test "x`$(LS) $(OUTPUT_ROOT)`" != x; then \
537	    $(ECHO) "Warning: Not removing non-empty configuration directory for '$(CONF_NAME)'" ; \
538	  else \
539	    ($(CD) $(SRC_ROOT) && $(ECHO) "Removing configuration directory for '$(CONF_NAME)'" \
540	        && $(RM) -r $(OUTPUT_ROOT)) \
541	  fi \
542	)
543	$(ECHO) Cleaned everything, you will have to re-run configure.
544
545ALL_TARGETS += clean dist-clean $(CLEAN_DIR_TARGETS) $(CLEAN_PHASE_TARGETS) \
546    $(CLEAN_MODULE_TARGETS) $(CLEAN_MODULE_PHASE_TARGETS)
547
548################################################################################
549
550# Setup a rule for SPEC file that fails if executed. This check makes sure the
551# configuration is up to date after changes to configure.
552ifeq ($(findstring reconfigure, $(MAKECMDGOALS)), )
553  $(SPEC): $(wildcard $(SRC_ROOT)/common/autoconf/*)
554	@$(ECHO) "ERROR: $(SPEC) is not up to date."
555	@$(ECHO) "Please rerun configure! Easiest way to do this is by running"
556	@$(ECHO) "'make reconfigure'."
557	@$(ECHO) "It may also be ignored by setting IGNORE_OLD_CONFIG=true"
558	@if test "x$(IGNORE_OLD_CONFIG)" != "xtrue"; then exit 1; fi
559endif
560
561# The reconfigure target is automatically run serially from everything else
562# by the Makefile calling this file.
563
564reconfigure:
565        ifneq ($(CONFIGURE_COMMAND_LINE), )
566	  @$(ECHO) "Re-running configure using arguments '$(CONFIGURE_COMMAND_LINE)'"
567        else
568	  @$(ECHO) "Re-running configure using default settings"
569        endif
570	@( cd $(OUTPUT_ROOT) && PATH="$(ORIGINAL_PATH)" \
571	    $(BASH) $(TOPDIR)/configure $(CONFIGURE_COMMAND_LINE) )
572
573ALL_TARGETS += reconfigure
574
575################################################################################
576# Declare *-only targets for each normal target
577$(foreach t, $(ALL_TARGETS), $(eval $(t)-only: $(t)))
578
579ALL_TARGETS += $(addsuffix -only, $(filter-out clean%, $(ALL_TARGETS)))
580
581################################################################################
582
583.PHONY: $(ALL_TARGETS)
584
585include $(SRC_ROOT)/make/Jprt.gmk
586
587FRC: # Force target
588