blob: 22b9bc4f3241a42bd59a7a24cdec6fd50896d342 [file] [log] [blame]
duke6e45e102007-12-01 00:00:00 +00001#
xdono53d0f662008-10-02 19:58:32 -07002# Copyright 1995-2008 Sun Microsystems, Inc. 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
7# published by the Free Software Foundation. Sun designates this
8# particular file as subject to the "Classpath" exception as provided
9# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22# CA 95054 USA or visit www.sun.com if you need additional information or
23# have any questions.
24#
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
61ifeq ($(INCREMENTAL_BUILD),true)
62FILES_d = $(patsubst %.c, %.$(DEPEND_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_c))))
63FILES_d += $(patsubst %.cpp, %.$(DEPEND_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_cpp))))
64endif # INCREMENTAL_BUILD
65
66ifeq ($(PLATFORM),solaris)
67# List of all lint files, one for each .c file (only for C)
68FILES_ln = $(patsubst %.c, %.$(LINT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_c))))
69endif
70
71#
72# C++ libraries must be linked with CC.
73#
74ifdef CPLUSPLUSLIBRARY
75LINKER=$(LINK.cc)
76else
77LINKER=$(LINK.c)
78endif
79
80# FIXUP: unpack needs the zip .o files. So we must build zip?
81# or fix unpack makefile so it uses Program.gmk.
82ifneq ($(IMPORT_NATIVE_BINARIES),true)
83 COMPILE_IT=true
84else
85 ifeq ($(LIBRARY),zip)
86 COMPILE_IT=true
87 else
88 COMPILE_IT=false
89 endif
90endif
91
92# If a Makefile has specified a pre-compiled closed src lib, just copy it.
93ifdef USE_BINARY_PLUG_LIBRARY
94 COMPILE_IT=false
95endif
96
97# We either need to import (copy) libraries in, or build them
98ifeq ($(COMPILE_IT),true)
99
100$(ACTUAL_LIBRARY):: $(INIT) $(TEMPDIR) $(LIBDIR) $(BINDIR) $(EXTDIR) classheaders
101
102#
103# COMPILE_APPROACH: Different approaches to compile up the native object
104# files as quickly as possible.
105# The setting of parallel works best on Unix, batch on Windows.
106#
107
108COMPILE_FILES_o = $(OBJDIR)/.files_compiled
109$(COMPILE_FILES_o): $(FILES_d) $(FILES_o)
110 @$(ECHO) "$<" >> $@
111clean::
112 $(RM) $(COMPILE_FILES_o)
113
114#
115# COMPILE_APPROACH=parallel: Will trigger compilations (just compilations) to
116# happen in parallel. Greatly decreases Unix build time, even on single CPU
117# machines, more so on multiple CPU machines. Default is 2 compiles
118# at a time, but can be adjusted with ALT_PARALLEL_COMPILE_JOBS.
119# Note that each .d file will also be dependent on it's .o file, see
120# Rules.gmk.
121# Note this does not depend on Rules.gmk to work like batch (below)
122# and this technique doesn't seem to help Windows build time nor does
123# it work very well, it's possible the Windows Visual Studio compilers
124# don't work well in a parallel situation, this needs investigation.
125#
126
127ifeq ($(COMPILE_APPROACH),parallel)
128
129.PHONY: library_parallel_compile
130
131library_parallel_compile:
132 @$(ECHO) "Begin parallel compiles: $(shell $(PWD))"
133 @$(MAKE) -j $(PARALLEL_COMPILE_JOBS) $(COMPILE_FILES_o)
134 @$(ECHO) "Done with parallel compiles: $(shell $(PWD))"
135
136$(ACTUAL_LIBRARY):: library_parallel_compile
137
138endif
139
140#
141# COMPILE_APPROACH=batch: Will trigger compilations (just compilations) to
142# happen in batch mode. Greatly decreases Windows build time.
143# See logic in Rules.gmk for how compiles happen, the $(MAKE) in
144# library_batch_compile below triggers the actions in Rules.gmk.
145# Note that each .d file will also be dependent on it's .o file, see
146# Rules.gmk.
147#
148ifeq ($(COMPILE_APPROACH),batch)
149
150.PHONY: library_batch_compile
151
152library_batch_compile:
153 @$(ECHO) "Begin BATCH compiles: $(shell $(PWD))"
154 $(MAKE) $(COMPILE_FILES_o)
155 $(MAKE) batch_compile
156 @$(ECHO) "Done with BATCH compiles: $(shell $(PWD))"
157 $(MAKE) COMPILE_APPROACH=normal $(COMPILE_FILES_o)
158
159$(ACTUAL_LIBRARY):: library_batch_compile
160
161endif
162
163ifeq ($(PLATFORM), windows)
164
165#
166# Library building rules.
167#
168
169$(LIBRARY).lib:: $(OBJDIR)
170
171ifeq ($(LIBRARY), fdlibm)
172$(ACTUAL_LIBRARY):: $(OBJDIR)/$(LIBRARY).lib
173
174$(OBJDIR)/$(LIBRARY).lib:: $(OBJDIR)/$(LIBRARY).lcf
175 @$(prep-target)
176 $(LIBEXE) -NODEFAULTLIB:MSVCRT -out:$@ -nologo \
177 @$(OBJDIR)/$(LIBRARY).lcf $(OTHER_LCF) $(LDLIBS_COMMON)
178else # LIBRARY
179# build it into $(OBJDIR) so that the other generated files get put
180# there, then copy just the DLL (and MAP file) to the requested directory.
181#
tbellfc2a6fe2009-01-14 21:35:03 -0800182# In VS2005 or VS2008 the link command creates a .manifest file that we want
183# to insert into the linked artifact so we do not need to track it separately.
184# Use ";#2" for .dll and ";#1" for .exe in the MT command below:
duke6e45e102007-12-01 00:00:00 +0000185$(ACTUAL_LIBRARY):: $(OBJDIR)/$(LIBRARY).lcf
186 @$(prep-target)
187 @$(MKDIR) -p $(OBJDIR)
188 $(LINK) -dll -out:$(OBJDIR)/$(@F) \
189 -map:$(OBJDIR)/$(LIBRARY).map \
190 $(LFLAGS) @$(OBJDIR)/$(LIBRARY).lcf \
191 $(OTHER_LCF) $(JAVALIB) $(LDLIBS)
tbellfc2a6fe2009-01-14 21:35:03 -0800192ifdef MT
193 $(MT) /manifest $(OBJDIR)/$(@F).manifest /outputresource:$(OBJDIR)/$(@F);#2
194endif
duke6e45e102007-12-01 00:00:00 +0000195 $(CP) $(OBJDIR)/$(@F) $@
196 $(CP) $(OBJDIR)/$(LIBRARY).map $(@D)
197 $(CP) $(OBJDIR)/$(LIBRARY).pdb $(@D)
198
199endif # LIBRARY
200
201$(OBJDIR)/$(LIBRARY).lcf: $(OBJDIR)/$(LIBRARY).res $(COMPILE_FILES_o) $(FILES_m)
202 @$(prep-target)
203 @$(MKDIR) -p $(TEMPDIR)
204 @$(ECHO) $(FILES_o) > $@
205ifndef LOCAL_RESOURCE_FILE
206 @$(ECHO) $(OBJDIR)/$(LIBRARY).res >> $@
207endif
208 @$(ECHO) Created $@
209
herrick43e2a0c2009-06-12 14:56:32 -0400210# JDK name required here
211RC_FLAGS += /D "JDK_FNAME=$(LIBRARY).dll" \
212 /D "JDK_INTERNAL_NAME=$(LIBRARY)" \
213 /D "JDK_FTYPE=0x2L"
duke6e45e102007-12-01 00:00:00 +0000214
215$(OBJDIR)/$(LIBRARY).res: $(VERSIONINFO_RESOURCE)
216ifndef LOCAL_RESOURCE_FILE
217 @$(prep-target)
218 $(RC) $(RC_FLAGS) $(CC_OBJECT_OUTPUT_FLAG)$(@) $(VERSIONINFO_RESOURCE)
219endif
220
221#
222# Install a .lib file if required.
223#
224ifeq ($(INSTALL_DOT_LIB), true)
225$(ACTUAL_LIBRARY):: $(LIBDIR)/$(LIBRARY).lib
226
227clean::
228 -$(RM) $(LIBDIR)/$(LIBRARY).lib
229
230$(LIBDIR)/$(LIBRARY).lib:: $(OBJDIR)/$(LIBRARY).lib
231 $(install-file)
232
233$(LIBDIR)/$(LIBRARY).dll:: $(OBJDIR)/$(LIBRARY).dll
234 $(install-file)
235
236endif # INSTALL_DOT_LIB
237
238else # PLATFORM
239
240#
241# On Solaris, use mcs to write the version into the comment section of
242# the shared library. On other platforms set this to false at the
243# make command line.
244#
245$(ACTUAL_LIBRARY):: $(COMPILE_FILES_o) $(FILES_m) $(FILES_reorder)
246 @$(prep-target)
ohair850fb252008-07-30 19:40:57 -0700247 @$(ECHO) "STATS: LIBRARY=$(LIBRARY), PRODUCT=$(PRODUCT), OPTIMIZATION_LEVEL=$(OPTIMIZATION_LEVEL)"
duke6e45e102007-12-01 00:00:00 +0000248 @$(ECHO) "Rebuilding $@ because of $?"
249ifeq ($(LIBRARY), fdlibm)
250 $(AR) -r $@ $(FILES_o)
251else # LIBRARY
252 $(LINKER) $(SHARED_LIBRARY_FLAG) -o $@ $(FILES_o) $(LDLIBS)
253ifeq ($(WRITE_LIBVERSION),true)
254 $(MCS) -d -a "$(FULL_VERSION)" $@
255endif # WRITE_LIBVERSION
256endif # LIBRARY
257
258endif # PLATFORM
259
260#
261# Cross check all linted files against each other
262#
263ifeq ($(PLATFORM),solaris)
264lint.errors : $(FILES_ln)
265 $(LINT.c) $(FILES_ln) $(LDLIBS)
266endif
267
268else # COMPILE_IT
269
270# OpenJDK rule is first so any lib is preferentially copied from that location.
271ifndef USE_BINARY_PLUG_LIBRARY
272
273# In this case we are just copying the file.
274ifneq ($(LIBRARY), fdlibm)
275# Copies in the file from the JDK_IMPORT_PATH area
276$(ACTUAL_LIBRARY_DIR)/%: $(JDK_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/%
277 $(install-import-file)
278$(ACTUAL_LIBRARY_DIR)/%: $(JDK_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/native_threads/%
279 $(install-import-file)
280$(ACTUAL_LIBRARY_DIR)/%: $(JDK_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/headless/%
281 $(install-import-file)
282$(ACTUAL_LIBRARY_DIR)/%: $(JDK_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/xawt/%
283 $(install-import-file)
284else # fdlibm
285$(ACTUAL_LIBRARY_DIR)/%:
286 $(prep-target)
287endif # fdlibm
288
289endif # USE_BINARY_PLUG_LIBRARY
290
291endif # COMPILE_IT
292
293#
294# Class libraries with JNI native methods get a include to the package.
295#
296ifdef PACKAGE
297vpath %.c $(PLATFORM_SRC)/native/$(PKGDIR)
298vpath %.c $(SHARE_SRC)/native/$(PKGDIR)
299OTHER_INCLUDES += -I$(SHARE_SRC)/native/common -I$(PLATFORM_SRC)/native/common
300OTHER_INCLUDES += -I$(SHARE_SRC)/native/$(PKGDIR) \
301 -I$(PLATFORM_SRC)/native/$(PKGDIR)
302endif
303
304#
305# Clean/clobber rules
306#
307clean::
308 $(RM) -r $(ACTUAL_LIBRARY)
309
310clobber:: clean
311
312#
313# INCREMENTAL_BUILD means that this workspace will be built over and over
314# possibly incrementally. This means tracking the object file dependencies
315# on include files so that sources get re-compiled when the include files
316# change. When building from scratch and doing a one time build (like
317# release engineering or nightly builds) set INCREMENTAL_BUILD=false.
318#
319
320ifeq ($(INCREMENTAL_BUILD),true)
321
322#
323# Workaround: gnumake sometimes says files is empty when it shouldn't
324# was: files := $(foreach file, $(wildcard $(OBJDIR)/*.$(DEPEND_SUFFIX)), $(file))
325#
326files := $(shell $(LS) $(OBJDIR)/*.$(DEPEND_SUFFIX) 2>/dev/null)
327
328#
329# Only include these files if we have any.
330#
331ifneq ($(strip $(files)),)
332
333include $(files)
334
335endif # files
336
337endif # INCREMENTAL_BUILD
338
339#
340# Default dependencies
341#
342
343all: build
344
345build: library
346
347debug:
348 $(MAKE) VARIANT=DBG build
349
350fastdebug:
351 $(MAKE) VARIANT=DBG FASTDEBUG=true build
352
353openjdk:
354 $(MAKE) OPENJDK=true build
355
356.PHONY: all build debug fastdebug
357