blob: 3e4318ecd2323120d8ecf4c093ec842936b2113b [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#
182$(ACTUAL_LIBRARY):: $(OBJDIR)/$(LIBRARY).lcf
183 @$(prep-target)
184 @$(MKDIR) -p $(OBJDIR)
185 $(LINK) -dll -out:$(OBJDIR)/$(@F) \
186 -map:$(OBJDIR)/$(LIBRARY).map \
187 $(LFLAGS) @$(OBJDIR)/$(LIBRARY).lcf \
188 $(OTHER_LCF) $(JAVALIB) $(LDLIBS)
189 $(CP) $(OBJDIR)/$(@F) $@
190 $(CP) $(OBJDIR)/$(LIBRARY).map $(@D)
191 $(CP) $(OBJDIR)/$(LIBRARY).pdb $(@D)
192
193endif # LIBRARY
194
195$(OBJDIR)/$(LIBRARY).lcf: $(OBJDIR)/$(LIBRARY).res $(COMPILE_FILES_o) $(FILES_m)
196 @$(prep-target)
197 @$(MKDIR) -p $(TEMPDIR)
198 @$(ECHO) $(FILES_o) > $@
199ifndef LOCAL_RESOURCE_FILE
200 @$(ECHO) $(OBJDIR)/$(LIBRARY).res >> $@
201endif
202 @$(ECHO) Created $@
203
204# J2SE name required here
205RC_FLAGS += /D "J2SE_FNAME=$(LIBRARY).dll" \
206 /D "J2SE_INTERNAL_NAME=$(LIBRARY)" \
207 /D "J2SE_FTYPE=0x2L"
208
209$(OBJDIR)/$(LIBRARY).res: $(VERSIONINFO_RESOURCE)
210ifndef LOCAL_RESOURCE_FILE
211 @$(prep-target)
212 $(RC) $(RC_FLAGS) $(CC_OBJECT_OUTPUT_FLAG)$(@) $(VERSIONINFO_RESOURCE)
213endif
214
215#
216# Install a .lib file if required.
217#
218ifeq ($(INSTALL_DOT_LIB), true)
219$(ACTUAL_LIBRARY):: $(LIBDIR)/$(LIBRARY).lib
220
221clean::
222 -$(RM) $(LIBDIR)/$(LIBRARY).lib
223
224$(LIBDIR)/$(LIBRARY).lib:: $(OBJDIR)/$(LIBRARY).lib
225 $(install-file)
226
227$(LIBDIR)/$(LIBRARY).dll:: $(OBJDIR)/$(LIBRARY).dll
228 $(install-file)
229
230endif # INSTALL_DOT_LIB
231
232else # PLATFORM
233
234#
235# On Solaris, use mcs to write the version into the comment section of
236# the shared library. On other platforms set this to false at the
237# make command line.
238#
239$(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)
244 $(AR) -r $@ $(FILES_o)
245else # LIBRARY
246 $(LINKER) $(SHARED_LIBRARY_FLAG) -o $@ $(FILES_o) $(LDLIBS)
247ifeq ($(WRITE_LIBVERSION),true)
248 $(MCS) -d -a "$(FULL_VERSION)" $@
249endif # WRITE_LIBVERSION
250endif # LIBRARY
251
252endif # PLATFORM
253
254#
255# Cross check all linted files against each other
256#
257ifeq ($(PLATFORM),solaris)
258lint.errors : $(FILES_ln)
259 $(LINT.c) $(FILES_ln) $(LDLIBS)
260endif
261
262else # COMPILE_IT
263
264# OpenJDK rule is first so any lib is preferentially copied from that location.
265ifndef USE_BINARY_PLUG_LIBRARY
266
267# In this case we are just copying the file.
268ifneq ($(LIBRARY), fdlibm)
269# Copies in the file from the JDK_IMPORT_PATH area
270$(ACTUAL_LIBRARY_DIR)/%: $(JDK_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/%
271 $(install-import-file)
272$(ACTUAL_LIBRARY_DIR)/%: $(JDK_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/native_threads/%
273 $(install-import-file)
274$(ACTUAL_LIBRARY_DIR)/%: $(JDK_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/headless/%
275 $(install-import-file)
276$(ACTUAL_LIBRARY_DIR)/%: $(JDK_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/xawt/%
277 $(install-import-file)
278else # fdlibm
279$(ACTUAL_LIBRARY_DIR)/%:
280 $(prep-target)
281endif # fdlibm
282
283endif # USE_BINARY_PLUG_LIBRARY
284
285endif # COMPILE_IT
286
287#
288# Class libraries with JNI native methods get a include to the package.
289#
290ifdef PACKAGE
291vpath %.c $(PLATFORM_SRC)/native/$(PKGDIR)
292vpath %.c $(SHARE_SRC)/native/$(PKGDIR)
293OTHER_INCLUDES += -I$(SHARE_SRC)/native/common -I$(PLATFORM_SRC)/native/common
294OTHER_INCLUDES += -I$(SHARE_SRC)/native/$(PKGDIR) \
295 -I$(PLATFORM_SRC)/native/$(PKGDIR)
296endif
297
298#
299# Clean/clobber rules
300#
301clean::
302 $(RM) -r $(ACTUAL_LIBRARY)
303
304clobber:: clean
305
306#
307# INCREMENTAL_BUILD means that this workspace will be built over and over
308# possibly incrementally. This means tracking the object file dependencies
309# on include files so that sources get re-compiled when the include files
310# change. When building from scratch and doing a one time build (like
311# release engineering or nightly builds) set INCREMENTAL_BUILD=false.
312#
313
314ifeq ($(INCREMENTAL_BUILD),true)
315
316#
317# Workaround: gnumake sometimes says files is empty when it shouldn't
318# was: files := $(foreach file, $(wildcard $(OBJDIR)/*.$(DEPEND_SUFFIX)), $(file))
319#
320files := $(shell $(LS) $(OBJDIR)/*.$(DEPEND_SUFFIX) 2>/dev/null)
321
322#
323# Only include these files if we have any.
324#
325ifneq ($(strip $(files)),)
326
327include $(files)
328
329endif # files
330
331endif # INCREMENTAL_BUILD
332
333#
334# Default dependencies
335#
336
337all: build
338
339build: library
340
341debug:
342 $(MAKE) VARIANT=DBG build
343
344fastdebug:
345 $(MAKE) VARIANT=DBG FASTDEBUG=true build
346
347openjdk:
348 $(MAKE) OPENJDK=true build
349
350.PHONY: all build debug fastdebug
351