blob: 00c7897d4040cee707506c6de94a561a7637d033 [file] [log] [blame]
duke6e45e102007-12-01 00:00:00 +00001#
dcubedb896fcf2012-04-03 12:57:47 -07002# Copyright (c) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
duke6e45e102007-12-01 00:00:00 +00003# 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
ohair2283b9d2010-05-25 15:58:33 -07007# published by the Free Software Foundation. Oracle designates this
duke6e45e102007-12-01 00:00:00 +00008# particular file as subject to the "Classpath" exception as provided
ohair2283b9d2010-05-25 15:58:33 -07009# by Oracle in the LICENSE file that accompanied this code.
duke6e45e102007-12-01 00:00:00 +000010#
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#
ohair2283b9d2010-05-25 15:58:33 -070021# 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.
duke6e45e102007-12-01 00:00:00 +000024#
25
26#
27# Generic makefile for building shared libraries.
28#
29
30# WARNING: This file is shared with other workspaces.
31# So when it includes other files, it must use JDK_TOPDIR.
32#
33
34include $(JDK_TOPDIR)/make/common/Classes.gmk
35
36#
37# It is important to define these *after* including Classes.gmk
38# in order to override the values defined inthat makefile.
39#
40
41ifeq ($(LIBRARY), fdlibm)
42ifeq ($(PLATFORM),windows)
43ACTUAL_LIBRARY_NAME = $(LIB_PREFIX)$(LIBRARY).$(FDDLIBM_SUFFIX)
44ACTUAL_LIBRARY_DIR = $(OBJDIR)
45else # PLATFORM
46ACTUAL_LIBRARY_NAME = $(LIB_PREFIX)$(LIBRARY).$(ARCH).$(FDDLIBM_SUFFIX)
47ACTUAL_LIBRARY_DIR = $(OBJDIR)
48endif #PLATFORM
49else # LIBRARY
50ACTUAL_LIBRARY_NAME = $(LIB_PREFIX)$(LIBRARY).$(LIBRARY_SUFFIX)
51ACTUAL_LIBRARY_DIR = $(LIB_LOCATION)
52endif
53ACTUAL_LIBRARY = $(ACTUAL_LIBRARY_DIR)/$(ACTUAL_LIBRARY_NAME)
54
55library:: $(ACTUAL_LIBRARY)
56
57FILES_o = $(patsubst %.c, %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_c))))
58FILES_o += $(patsubst %.s, %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_s))))
59FILES_o += $(patsubst %.cpp, %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_cpp))))
60
michaelm5ac8c152012-03-06 20:34:38 +000061ifeq ($(PLATFORM), macosx)
62FILES_o += $(patsubst %.m, %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_objc))))
63FILES_o += $(patsubst %.mm, %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_objcpp))))
64
65INCREMENTAL_BUILD=false
66
67endif # PLATFORM
68
duke6e45e102007-12-01 00:00:00 +000069ifeq ($(INCREMENTAL_BUILD),true)
70FILES_d = $(patsubst %.c, %.$(DEPEND_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_c))))
71FILES_d += $(patsubst %.cpp, %.$(DEPEND_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_cpp))))
72endif # INCREMENTAL_BUILD
73
74ifeq ($(PLATFORM),solaris)
75# List of all lint files, one for each .c file (only for C)
76FILES_ln = $(patsubst %.c, %.$(LINT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_c))))
77endif
78
79#
80# C++ libraries must be linked with CC.
81#
82ifdef CPLUSPLUSLIBRARY
83LINKER=$(LINK.cc)
84else
85LINKER=$(LINK.c)
86endif
87
duke6e45e102007-12-01 00:00:00 +000088$(ACTUAL_LIBRARY):: $(INIT) $(TEMPDIR) $(LIBDIR) $(BINDIR) $(EXTDIR) classheaders
dholmes2f37b892011-03-22 18:56:16 -040089 @$(ECHO) Building lib:$(ACTUAL_LIBRARY)
duke6e45e102007-12-01 00:00:00 +000090#
91# COMPILE_APPROACH: Different approaches to compile up the native object
92# files as quickly as possible.
93# The setting of parallel works best on Unix, batch on Windows.
94#
95
96COMPILE_FILES_o = $(OBJDIR)/.files_compiled
97$(COMPILE_FILES_o): $(FILES_d) $(FILES_o)
98 @$(ECHO) "$<" >> $@
99clean::
100 $(RM) $(COMPILE_FILES_o)
101
102#
103# COMPILE_APPROACH=parallel: Will trigger compilations (just compilations) to
104# happen in parallel. Greatly decreases Unix build time, even on single CPU
105# machines, more so on multiple CPU machines. Default is 2 compiles
106# at a time, but can be adjusted with ALT_PARALLEL_COMPILE_JOBS.
107# Note that each .d file will also be dependent on it's .o file, see
108# Rules.gmk.
109# Note this does not depend on Rules.gmk to work like batch (below)
110# and this technique doesn't seem to help Windows build time nor does
111# it work very well, it's possible the Windows Visual Studio compilers
112# don't work well in a parallel situation, this needs investigation.
113#
114
115ifeq ($(COMPILE_APPROACH),parallel)
116
117.PHONY: library_parallel_compile
118
119library_parallel_compile:
120 @$(ECHO) "Begin parallel compiles: $(shell $(PWD))"
121 @$(MAKE) -j $(PARALLEL_COMPILE_JOBS) $(COMPILE_FILES_o)
122 @$(ECHO) "Done with parallel compiles: $(shell $(PWD))"
123
124$(ACTUAL_LIBRARY):: library_parallel_compile
125
126endif
127
128#
129# COMPILE_APPROACH=batch: Will trigger compilations (just compilations) to
130# happen in batch mode. Greatly decreases Windows build time.
131# See logic in Rules.gmk for how compiles happen, the $(MAKE) in
132# library_batch_compile below triggers the actions in Rules.gmk.
133# Note that each .d file will also be dependent on it's .o file, see
134# Rules.gmk.
135#
136ifeq ($(COMPILE_APPROACH),batch)
137
138.PHONY: library_batch_compile
139
140library_batch_compile:
141 @$(ECHO) "Begin BATCH compiles: $(shell $(PWD))"
142 $(MAKE) $(COMPILE_FILES_o)
143 $(MAKE) batch_compile
144 @$(ECHO) "Done with BATCH compiles: $(shell $(PWD))"
145 $(MAKE) COMPILE_APPROACH=normal $(COMPILE_FILES_o)
146
147$(ACTUAL_LIBRARY):: library_batch_compile
148
149endif
150
151ifeq ($(PLATFORM), windows)
152
153#
154# Library building rules.
155#
156
157$(LIBRARY).lib:: $(OBJDIR)
158
159ifeq ($(LIBRARY), fdlibm)
160$(ACTUAL_LIBRARY):: $(OBJDIR)/$(LIBRARY).lib
161
162$(OBJDIR)/$(LIBRARY).lib:: $(OBJDIR)/$(LIBRARY).lcf
163 @$(prep-target)
164 $(LIBEXE) -NODEFAULTLIB:MSVCRT -out:$@ -nologo \
165 @$(OBJDIR)/$(LIBRARY).lcf $(OTHER_LCF) $(LDLIBS_COMMON)
166else # LIBRARY
167# build it into $(OBJDIR) so that the other generated files get put
168# there, then copy just the DLL (and MAP file) to the requested directory.
169#
dcubedb896fcf2012-04-03 12:57:47 -0700170ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
171 MAP_OPTION="-map:$(OBJDIR)/$(LIBRARY).map"
172endif
173
duke6e45e102007-12-01 00:00:00 +0000174$(ACTUAL_LIBRARY):: $(OBJDIR)/$(LIBRARY).lcf
175 @$(prep-target)
176 @$(MKDIR) -p $(OBJDIR)
177 $(LINK) -dll -out:$(OBJDIR)/$(@F) \
dcubedb896fcf2012-04-03 12:57:47 -0700178 $(MAP_OPTION) \
duke6e45e102007-12-01 00:00:00 +0000179 $(LFLAGS) @$(OBJDIR)/$(LIBRARY).lcf \
chegar38b5a832011-10-24 21:03:41 +0100180 $(OTHER_LCF) $(LDLIBS)
duke6e45e102007-12-01 00:00:00 +0000181 $(CP) $(OBJDIR)/$(@F) $@
ohair67e0bbf2011-01-05 14:28:58 -0800182 @$(call binary_file_verification,$@)
dcubedb896fcf2012-04-03 12:57:47 -0700183ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
duke6e45e102007-12-01 00:00:00 +0000184 $(CP) $(OBJDIR)/$(LIBRARY).map $(@D)
185 $(CP) $(OBJDIR)/$(LIBRARY).pdb $(@D)
dcubedb896fcf2012-04-03 12:57:47 -0700186endif
duke6e45e102007-12-01 00:00:00 +0000187
188endif # LIBRARY
189
190$(OBJDIR)/$(LIBRARY).lcf: $(OBJDIR)/$(LIBRARY).res $(COMPILE_FILES_o) $(FILES_m)
191 @$(prep-target)
192 @$(MKDIR) -p $(TEMPDIR)
193 @$(ECHO) $(FILES_o) > $@
194ifndef LOCAL_RESOURCE_FILE
195 @$(ECHO) $(OBJDIR)/$(LIBRARY).res >> $@
196endif
197 @$(ECHO) Created $@
198
herrick43e2a0c2009-06-12 14:56:32 -0400199# JDK name required here
200RC_FLAGS += /D "JDK_FNAME=$(LIBRARY).dll" \
201 /D "JDK_INTERNAL_NAME=$(LIBRARY)" \
202 /D "JDK_FTYPE=0x2L"
duke6e45e102007-12-01 00:00:00 +0000203
204$(OBJDIR)/$(LIBRARY).res: $(VERSIONINFO_RESOURCE)
205ifndef LOCAL_RESOURCE_FILE
206 @$(prep-target)
207 $(RC) $(RC_FLAGS) $(CC_OBJECT_OUTPUT_FLAG)$(@) $(VERSIONINFO_RESOURCE)
208endif
209
210#
211# Install a .lib file if required.
212#
213ifeq ($(INSTALL_DOT_LIB), true)
214$(ACTUAL_LIBRARY):: $(LIBDIR)/$(LIBRARY).lib
215
216clean::
217 -$(RM) $(LIBDIR)/$(LIBRARY).lib
218
219$(LIBDIR)/$(LIBRARY).lib:: $(OBJDIR)/$(LIBRARY).lib
220 $(install-file)
221
222$(LIBDIR)/$(LIBRARY).dll:: $(OBJDIR)/$(LIBRARY).dll
223 $(install-file)
224
225endif # INSTALL_DOT_LIB
226
227else # PLATFORM
228
229#
230# On Solaris, use mcs to write the version into the comment section of
231# the shared library. On other platforms set this to false at the
232# make command line.
233#
michaelm5ac8c152012-03-06 20:34:38 +0000234
235ifneq ($(PLATFORM), macosx)
236 ARFLAGS = -r
237endif
238
duke6e45e102007-12-01 00:00:00 +0000239$(ACTUAL_LIBRARY):: $(COMPILE_FILES_o) $(FILES_m) $(FILES_reorder)
240 @$(prep-target)
ohair850fb252008-07-30 19:40:57 -0700241 @$(ECHO) "STATS: LIBRARY=$(LIBRARY), PRODUCT=$(PRODUCT), OPTIMIZATION_LEVEL=$(OPTIMIZATION_LEVEL)"
duke6e45e102007-12-01 00:00:00 +0000242 @$(ECHO) "Rebuilding $@ because of $?"
243ifeq ($(LIBRARY), fdlibm)
michaelm5ac8c152012-03-06 20:34:38 +0000244 $(AR) $(ARFLAGS) $@ $(FILES_o)
duke6e45e102007-12-01 00:00:00 +0000245else # LIBRARY
246 $(LINKER) $(SHARED_LIBRARY_FLAG) -o $@ $(FILES_o) $(LDLIBS)
ohair67e0bbf2011-01-05 14:28:58 -0800247 @$(call binary_file_verification,$@)
duke6e45e102007-12-01 00:00:00 +0000248ifeq ($(WRITE_LIBVERSION),true)
249 $(MCS) -d -a "$(FULL_VERSION)" $@
250endif # WRITE_LIBVERSION
251endif # LIBRARY
252
253endif # PLATFORM
254
255#
256# Cross check all linted files against each other
257#
258ifeq ($(PLATFORM),solaris)
259lint.errors : $(FILES_ln)
260 $(LINT.c) $(FILES_ln) $(LDLIBS)
261endif
262
duke6e45e102007-12-01 00:00:00 +0000263#
264# Class libraries with JNI native methods get a include to the package.
265#
266ifdef PACKAGE
267vpath %.c $(PLATFORM_SRC)/native/$(PKGDIR)
268vpath %.c $(SHARE_SRC)/native/$(PKGDIR)
269OTHER_INCLUDES += -I$(SHARE_SRC)/native/common -I$(PLATFORM_SRC)/native/common
270OTHER_INCLUDES += -I$(SHARE_SRC)/native/$(PKGDIR) \
271 -I$(PLATFORM_SRC)/native/$(PKGDIR)
272endif
273
274#
275# Clean/clobber rules
276#
277clean::
278 $(RM) -r $(ACTUAL_LIBRARY)
279
280clobber:: clean
281
282#
283# INCREMENTAL_BUILD means that this workspace will be built over and over
284# possibly incrementally. This means tracking the object file dependencies
285# on include files so that sources get re-compiled when the include files
286# change. When building from scratch and doing a one time build (like
287# release engineering or nightly builds) set INCREMENTAL_BUILD=false.
288#
289
290ifeq ($(INCREMENTAL_BUILD),true)
291
292#
293# Workaround: gnumake sometimes says files is empty when it shouldn't
294# was: files := $(foreach file, $(wildcard $(OBJDIR)/*.$(DEPEND_SUFFIX)), $(file))
295#
296files := $(shell $(LS) $(OBJDIR)/*.$(DEPEND_SUFFIX) 2>/dev/null)
297
298#
299# Only include these files if we have any.
300#
301ifneq ($(strip $(files)),)
302
303include $(files)
304
305endif # files
306
307endif # INCREMENTAL_BUILD
308
309#
310# Default dependencies
311#
312
313all: build
314
315build: library
316
317debug:
318 $(MAKE) VARIANT=DBG build
319
320fastdebug:
321 $(MAKE) VARIANT=DBG FASTDEBUG=true build
322
323openjdk:
324 $(MAKE) OPENJDK=true build
325
mchung3baa2d62010-01-07 08:14:48 -0800326FORCE:
327
duke6e45e102007-12-01 00:00:00 +0000328.PHONY: all build debug fastdebug
329