1 # |
|
2 # Copyright (c) 1995, 2011, 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 # 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 |
|
34 include $(JDK_TOPDIR)/makefiles/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 |
|
41 ifeq ($(LIBRARY), fdlibm) |
|
42 ifeq ($(PLATFORM),windows) |
|
43 ACTUAL_LIBRARY_NAME = $(LIB_PREFIX)$(LIBRARY).$(FDDLIBM_SUFFIX) |
|
44 ACTUAL_LIBRARY_DIR = $(OBJDIR) |
|
45 else # PLATFORM |
|
46 ACTUAL_LIBRARY_NAME = $(LIB_PREFIX)$(LIBRARY).$(ARCH).$(FDDLIBM_SUFFIX) |
|
47 ACTUAL_LIBRARY_DIR = $(OBJDIR) |
|
48 endif #PLATFORM |
|
49 else # LIBRARY |
|
50 ACTUAL_LIBRARY_NAME = $(LIB_PREFIX)$(LIBRARY).$(LIBRARY_SUFFIX) |
|
51 ACTUAL_LIBRARY_DIR = $(LIB_LOCATION) |
|
52 endif |
|
53 ACTUAL_LIBRARY = $(ACTUAL_LIBRARY_DIR)/$(ACTUAL_LIBRARY_NAME) |
|
54 |
|
55 library:: $(ACTUAL_LIBRARY) |
|
56 |
|
57 FILES_o = $(patsubst %.c, %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_c)))) |
|
58 FILES_o += $(patsubst %.s, %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_s)))) |
|
59 FILES_o += $(patsubst %.cpp, %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_cpp)))) |
|
60 |
|
61 ifeq ($(PLATFORM), macosx) |
|
62 FILES_o += $(patsubst %.m, %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_objc)))) |
|
63 FILES_o += $(patsubst %.mm, %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_objcpp)))) |
|
64 |
|
65 INCREMENTAL_BUILD=false |
|
66 |
|
67 endif # PLATFORM |
|
68 |
|
69 ifeq ($(INCREMENTAL_BUILD),true) |
|
70 FILES_d = $(patsubst %.c, %.$(DEPEND_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_c)))) |
|
71 FILES_d += $(patsubst %.cpp, %.$(DEPEND_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_cpp)))) |
|
72 endif # INCREMENTAL_BUILD |
|
73 |
|
74 ifeq ($(PLATFORM),solaris) |
|
75 # List of all lint files, one for each .c file (only for C) |
|
76 FILES_ln = $(patsubst %.c, %.$(LINT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_c)))) |
|
77 endif |
|
78 |
|
79 LINK.cc = $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) |
|
80 LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) |
|
81 |
|
82 # |
|
83 # C++ libraries must be linked with CC. |
|
84 # |
|
85 ifdef CPLUSPLUSLIBRARY |
|
86 LINKER=$(LINK.cc) |
|
87 else |
|
88 LINKER=$(LINK.c) |
|
89 endif |
|
90 |
|
91 $(ACTUAL_LIBRARY):: $(INIT) $(TEMPDIR) $(LIBDIR) $(BINDIR) $(EXTDIR) classheaders |
|
92 @$(ECHO) Building lib:$(ACTUAL_LIBRARY) |
|
93 # |
|
94 # COMPILE_APPROACH: Different approaches to compile up the native object |
|
95 # files as quickly as possible. |
|
96 # The setting of parallel works best on Unix, batch on Windows. |
|
97 # |
|
98 |
|
99 COMPILE_FILES_o = $(OBJDIR)/.files_compiled |
|
100 $(COMPILE_FILES_o): $(FILES_d) $(FILES_o) |
|
101 @$(ECHO) "$<" >> $@ |
|
102 clean:: |
|
103 $(RM) $(COMPILE_FILES_o) |
|
104 |
|
105 # |
|
106 # COMPILE_APPROACH=parallel: Will trigger compilations (just compilations) to |
|
107 # happen in parallel. Greatly decreases Unix build time, even on single CPU |
|
108 # machines, more so on multiple CPU machines. Default is 2 compiles |
|
109 # at a time, but can be adjusted with ALT_PARALLEL_COMPILE_JOBS. |
|
110 # Note that each .d file will also be dependent on it's .o file, see |
|
111 # Rules.gmk. |
|
112 # Note this does not depend on Rules.gmk to work like batch (below) |
|
113 # and this technique doesn't seem to help Windows build time nor does |
|
114 # it work very well, it's possible the Windows Visual Studio compilers |
|
115 # don't work well in a parallel situation, this needs investigation. |
|
116 # |
|
117 |
|
118 ifeq ($(COMPILE_APPROACH),parallel) |
|
119 |
|
120 .PHONY: library_parallel_compile |
|
121 |
|
122 library_parallel_compile: |
|
123 @$(ECHO) "Begin parallel compiles: $(shell $(PWD))" |
|
124 $(MAKE) -j $(PARALLEL_COMPILE_JOBS) $(COMPILE_FILES_o) |
|
125 @$(ECHO) "Done with parallel compiles: $(shell $(PWD))" |
|
126 |
|
127 $(ACTUAL_LIBRARY):: library_parallel_compile |
|
128 |
|
129 endif |
|
130 |
|
131 # |
|
132 # COMPILE_APPROACH=batch: Will trigger compilations (just compilations) to |
|
133 # happen in batch mode. Greatly decreases Windows build time. |
|
134 # See logic in Rules.gmk for how compiles happen, the $(MAKE) in |
|
135 # library_batch_compile below triggers the actions in Rules.gmk. |
|
136 # Note that each .d file will also be dependent on it's .o file, see |
|
137 # Rules.gmk. |
|
138 # |
|
139 ifeq ($(COMPILE_APPROACH),batch) |
|
140 |
|
141 .PHONY: library_batch_compile |
|
142 |
|
143 library_batch_compile: |
|
144 @$(ECHO) "Begin BATCH compiles: $(shell $(PWD))" |
|
145 $(MAKE) $(COMPILE_FILES_o) |
|
146 $(MAKE) batch_compile |
|
147 @$(ECHO) "Done with BATCH compiles: $(shell $(PWD))" |
|
148 $(MAKE) COMPILE_APPROACH=normal $(COMPILE_FILES_o) |
|
149 |
|
150 $(ACTUAL_LIBRARY):: library_batch_compile |
|
151 |
|
152 endif |
|
153 |
|
154 ifeq ($(PLATFORM), windows) |
|
155 |
|
156 # |
|
157 # Library building rules. |
|
158 # |
|
159 |
|
160 $(LIBRARY).lib:: $(OBJDIR) |
|
161 |
|
162 ifeq ($(LIBRARY), fdlibm) |
|
163 $(ACTUAL_LIBRARY):: $(OBJDIR)/$(LIBRARY).lib |
|
164 |
|
165 $(OBJDIR)/$(LIBRARY).lib:: $(OBJDIR)/$(LIBRARY).lcf |
|
166 @$(prep-target) |
|
167 $(AR) -NODEFAULTLIB:MSVCRT -out:$@ -nologo \ |
|
168 @$(OBJDIR)/$(LIBRARY).lcf $(OTHER_LCF) $(LDLIBS_COMMON) |
|
169 else # LIBRARY |
|
170 # build it into $(OBJDIR) so that the other generated files get put |
|
171 # there, then copy just the DLL (and MAP file) to the requested directory. |
|
172 # |
|
173 $(ACTUAL_LIBRARY):: $(OBJDIR)/$(LIBRARY).lcf |
|
174 @$(prep-target) |
|
175 @$(MKDIR) -p $(OBJDIR) |
|
176 $(LD) -dll -out:$(OBJDIR)/$(@F) \ |
|
177 -map:$(OBJDIR)/$(LIBRARY).map \ |
|
178 $(LFLAGS) @$(OBJDIR)/$(LIBRARY).lcf \ |
|
179 $(OTHER_LCF) $(LDLIBS) |
|
180 $(CP) $(OBJDIR)/$(@F) $@ |
|
181 @$(call binary_file_verification,$@) |
|
182 $(CP) $(OBJDIR)/$(LIBRARY).map $(@D) |
|
183 $(CP) $(OBJDIR)/$(LIBRARY).pdb $(@D) |
|
184 |
|
185 endif # LIBRARY |
|
186 |
|
187 $(OBJDIR)/$(LIBRARY).lcf: $(OBJDIR)/$(LIBRARY).res $(COMPILE_FILES_o) $(FILES_m) |
|
188 @$(prep-target) |
|
189 @$(MKDIR) -p $(TEMPDIR) |
|
190 @$(ECHO) $(FILES_o) > $@ |
|
191 ifndef LOCAL_RESOURCE_FILE |
|
192 @$(ECHO) $(OBJDIR)/$(LIBRARY).res >> $@ |
|
193 endif |
|
194 @$(ECHO) Created $@ |
|
195 |
|
196 # JDK name required here |
|
197 RC_FLAGS += /D "JDK_FNAME=$(LIBRARY).dll" \ |
|
198 /D "JDK_INTERNAL_NAME=$(LIBRARY)" \ |
|
199 /D "JDK_FTYPE=0x2L" |
|
200 |
|
201 $(OBJDIR)/$(LIBRARY).res: $(VERSIONINFO_RESOURCE) |
|
202 ifndef LOCAL_RESOURCE_FILE |
|
203 @$(prep-target) |
|
204 $(RC) $(RC_FLAGS) $(CC_OBJECT_OUTPUT_FLAG)$(@) $(VERSIONINFO_RESOURCE) |
|
205 endif |
|
206 |
|
207 # |
|
208 # Install a .lib file if required. |
|
209 # |
|
210 ifeq ($(INSTALL_DOT_LIB), true) |
|
211 $(ACTUAL_LIBRARY):: $(LIBDIR)/$(LIBRARY).lib |
|
212 |
|
213 clean:: |
|
214 -$(RM) $(LIBDIR)/$(LIBRARY).lib |
|
215 |
|
216 $(LIBDIR)/$(LIBRARY).lib:: $(OBJDIR)/$(LIBRARY).lib |
|
217 $(install-file) |
|
218 |
|
219 $(LIBDIR)/$(LIBRARY).dll:: $(OBJDIR)/$(LIBRARY).dll |
|
220 $(install-file) |
|
221 |
|
222 endif # INSTALL_DOT_LIB |
|
223 |
|
224 else # PLATFORM |
|
225 |
|
226 # |
|
227 # On Solaris, use mcs to write the version into the comment section of |
|
228 # the shared library. On other platforms set this to false at the |
|
229 # make command line. |
|
230 # |
|
231 |
|
232 ifneq ($(PLATFORM), macosx) |
|
233 ARFLAGS = -r |
|
234 endif |
|
235 |
|
236 $(ACTUAL_LIBRARY):: $(COMPILE_FILES_o) $(FILES_m) $(FILES_reorder) |
|
237 @$(prep-target) |
|
238 @$(ECHO) "STATS: LIBRARY=$(LIBRARY), PRODUCT=$(PRODUCT), OPTIMIZATION_LEVEL=$(OPTIMIZATION_LEVEL)" |
|
239 @$(ECHO) "Rebuilding $@ because of $?" |
|
240 ifeq ($(LIBRARY), fdlibm) |
|
241 $(AR) $(ARFLAGS) $@ $(FILES_o) |
|
242 else # LIBRARY |
|
243 $(LINKER) $(SHARED_LIBRARY_FLAG) -o $@ $(FILES_o) $(LDLIBS) |
|
244 @$(call binary_file_verification,$@) |
|
245 ifeq ($(WRITE_LIBVERSION),true) |
|
246 $(MCS) -d -a "$(FULL_VERSION)" $@ |
|
247 endif # WRITE_LIBVERSION |
|
248 endif # LIBRARY |
|
249 |
|
250 endif # PLATFORM |
|
251 |
|
252 # |
|
253 # Cross check all linted files against each other |
|
254 # |
|
255 ifeq ($(PLATFORM),solaris) |
|
256 lint.errors : $(FILES_ln) |
|
257 $(LINT.c) $(FILES_ln) $(LDLIBS) |
|
258 endif |
|
259 |
|
260 # |
|
261 # Class libraries with JNI native methods get a include to the package. |
|
262 # |
|
263 ifdef PACKAGE |
|
264 vpath %.c $(PLATFORM_SRC)/native/$(PKGDIR) |
|
265 vpath %.c $(SHARE_SRC)/native/$(PKGDIR) |
|
266 OTHER_INCLUDES += -I$(SHARE_SRC)/native/common -I$(PLATFORM_SRC)/native/common |
|
267 OTHER_INCLUDES += -I$(SHARE_SRC)/native/$(PKGDIR) \ |
|
268 -I$(PLATFORM_SRC)/native/$(PKGDIR) |
|
269 endif |
|
270 |
|
271 # |
|
272 # Clean/clobber rules |
|
273 # |
|
274 clean:: |
|
275 $(RM) -r $(ACTUAL_LIBRARY) |
|
276 |
|
277 clobber:: clean |
|
278 |
|
279 # |
|
280 # INCREMENTAL_BUILD means that this workspace will be built over and over |
|
281 # possibly incrementally. This means tracking the object file dependencies |
|
282 # on include files so that sources get re-compiled when the include files |
|
283 # change. When building from scratch and doing a one time build (like |
|
284 # release engineering or nightly builds) set INCREMENTAL_BUILD=false. |
|
285 # |
|
286 |
|
287 ifeq ($(INCREMENTAL_BUILD),true) |
|
288 |
|
289 # |
|
290 # Workaround: gnumake sometimes says files is empty when it shouldn't |
|
291 # was: files := $(foreach file, $(wildcard $(OBJDIR)/*.$(DEPEND_SUFFIX)), $(file)) |
|
292 # |
|
293 files := $(shell $(LS) $(OBJDIR)/*.$(DEPEND_SUFFIX) 2>/dev/null) |
|
294 |
|
295 # |
|
296 # Only include these files if we have any. |
|
297 # |
|
298 ifneq ($(strip $(files)),) |
|
299 |
|
300 include $(files) |
|
301 |
|
302 endif # files |
|
303 |
|
304 endif # INCREMENTAL_BUILD |
|
305 |
|
306 # |
|
307 # Default dependencies |
|
308 # |
|
309 |
|
310 all: build |
|
311 |
|
312 build: library |
|
313 |
|
314 debug: |
|
315 $(MAKE) VARIANT=DBG build |
|
316 |
|
317 fastdebug: |
|
318 $(MAKE) VARIANT=DBG FASTDEBUG=true build |
|
319 |
|
320 openjdk: |
|
321 $(MAKE) OPENJDK=true build |
|
322 |
|
323 FORCE: |
|
324 |
|
325 .PHONY: all build debug fastdebug |
|
326 |
|