17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
18 # |
18 # |
19 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
19 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 # or visit www.oracle.com if you need additional information or have any |
20 # or visit www.oracle.com if you need additional information or have any |
21 # questions. |
21 # questions. |
22 # |
22 # |
23 # |
23 # |
24 |
24 |
25 #------------------------------------------------------------------------ |
25 #------------------------------------------------------------------------ |
26 # CC, CXX & AS |
26 # CC, CXX & AS |
27 |
27 |
60 # prints the numbers (e.g. "2.95", "3.2.1") |
60 # prints the numbers (e.g. "2.95", "3.2.1") |
61 CC_VER_MAJOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f1) |
61 CC_VER_MAJOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f1) |
62 CC_VER_MINOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f2) |
62 CC_VER_MINOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f2) |
63 endif |
63 endif |
64 |
64 |
65 |
|
66 ifeq ($(USE_CLANG), true) |
65 ifeq ($(USE_CLANG), true) |
67 # Clang has precompiled headers support by default, but the user can switch |
66 # Clang has precompiled headers support by default, but the user can switch |
68 # it off by using 'USE_PRECOMPILED_HEADER=0'. |
67 # it off by using 'USE_PRECOMPILED_HEADER=0'. |
69 ifdef LP64 |
68 ifdef LP64 |
70 ifeq ($(USE_PRECOMPILED_HEADER),) |
69 ifeq ($(USE_PRECOMPILED_HEADER),) |
102 # There are some files which don't like precompiled headers |
101 # There are some files which don't like precompiled headers |
103 # The following files are build with 'OPT_CFLAGS/NOOPT' (-O0) in the opt build. |
102 # The following files are build with 'OPT_CFLAGS/NOOPT' (-O0) in the opt build. |
104 # But Clang doesn't support a precompiled header which was compiled with -O3 |
103 # But Clang doesn't support a precompiled header which was compiled with -O3 |
105 # to be used in a compilation unit which uses '-O0'. We could also prepare an |
104 # to be used in a compilation unit which uses '-O0'. We could also prepare an |
106 # extra '-O0' PCH file for the opt build and use it here, but it's probably |
105 # extra '-O0' PCH file for the opt build and use it here, but it's probably |
107 # not worth the effoert as long as only two files need this special handling. |
106 # not worth the effort as long as only two files need this special handling. |
108 PCH_FLAG/loopTransform.o = $(PCH_FLAG/NO_PCH) |
107 PCH_FLAG/loopTransform.o = $(PCH_FLAG/NO_PCH) |
109 PCH_FLAG/sharedRuntimeTrig.o = $(PCH_FLAG/NO_PCH) |
108 PCH_FLAG/sharedRuntimeTrig.o = $(PCH_FLAG/NO_PCH) |
110 PCH_FLAG/sharedRuntimeTrans.o = $(PCH_FLAG/NO_PCH) |
109 PCH_FLAG/sharedRuntimeTrans.o = $(PCH_FLAG/NO_PCH) |
111 |
110 |
112 endif |
111 endif |
224 WARNING_FLAGS += -Wconversion |
223 WARNING_FLAGS += -Wconversion |
225 endif |
224 endif |
226 endif |
225 endif |
227 |
226 |
228 CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(WARNING_FLAGS) |
227 CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(WARNING_FLAGS) |
|
228 |
229 # Special cases |
229 # Special cases |
230 CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@)) |
230 CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@)) |
231 |
231 |
232 # The flags to use for an Optimized g++ build |
232 # optimization control flags (Used by fastdebug and release variants) |
|
233 OPT_CFLAGS/NOOPT=-O0 |
|
234 ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 8 \) \))" "1" |
|
235 # Allow basic optimizations which don't distrupt debugging. (Principally dead code elimination) |
|
236 OPT_CFLAGS/DEBUG=-Og |
|
237 else |
|
238 # Allow no optimizations. |
|
239 OPT_CFLAGS/DEBUG=-O0 |
|
240 endif |
233 OPT_CFLAGS/SIZE=-Os |
241 OPT_CFLAGS/SIZE=-Os |
234 OPT_CFLAGS/SPEED=-O3 |
242 OPT_CFLAGS/SPEED=-O3 |
|
243 |
|
244 OPT_CFLAGS_DEFAULT ?= SPEED |
235 |
245 |
236 # Hotspot uses very unstrict aliasing turn this optimization off |
246 # Hotspot uses very unstrict aliasing turn this optimization off |
237 # This option is added to CFLAGS rather than OPT_CFLAGS |
247 # This option is added to CFLAGS rather than OPT_CFLAGS |
238 # so that OPT_CFLAGS overrides get this option too. |
248 # so that OPT_CFLAGS overrides get this option too. |
239 CFLAGS += -fno-strict-aliasing |
249 CFLAGS += -fno-strict-aliasing |
240 |
|
241 OPT_CFLAGS_DEFAULT ?= SPEED |
|
242 |
250 |
243 ifdef OPT_CFLAGS |
251 ifdef OPT_CFLAGS |
244 ifneq ("$(origin OPT_CFLAGS)", "command line") |
252 ifneq ("$(origin OPT_CFLAGS)", "command line") |
245 $(error " Use OPT_EXTRAS instead of OPT_CFLAGS to add extra flags to OPT_CFLAGS.") |
253 $(error " Use OPT_EXTRAS instead of OPT_CFLAGS to add extra flags to OPT_CFLAGS.") |
246 endif |
254 endif |
247 endif |
255 endif |
248 |
256 |
249 OPT_CFLAGS = $(OPT_CFLAGS/$(OPT_CFLAGS_DEFAULT)) $(OPT_EXTRAS) |
257 OPT_CFLAGS = $(OPT_CFLAGS/$(OPT_CFLAGS_DEFAULT)) $(OPT_EXTRAS) |
250 |
258 |
251 # The gcc compiler segv's on ia64 when compiling bytecodeInterpreter.cpp |
259 # The gcc compiler segv's on ia64 when compiling bytecodeInterpreter.cpp |
252 # if we use expensive-optimizations |
260 # if we use expensive-optimizations |
253 ifeq ($(BUILDARCH), ia64) |
261 ifeq ($(BUILDARCH), ia64) |
254 OPT_CFLAGS += -fno-expensive-optimizations |
262 OPT_CFLAGS += -fno-expensive-optimizations |
255 endif |
263 endif |
256 |
264 |
257 OPT_CFLAGS/NOOPT=-O0 |
|
258 |
|
259 # Work around some compiler bugs. |
265 # Work around some compiler bugs. |
260 ifeq ($(USE_CLANG), true) |
266 ifeq ($(USE_CLANG), true) |
261 ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 2), 1) |
267 ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 2), 1) |
262 OPT_CFLAGS/loopTransform.o += $(OPT_CFLAGS/NOOPT) |
268 OPT_CFLAGS/loopTransform.o += $(OPT_CFLAGS/NOOPT) |
263 endif |
269 endif |
269 endif |
275 endif |
270 |
276 |
271 # Flags for generating make dependency flags. |
277 # Flags for generating make dependency flags. |
272 DEPFLAGS = -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d) |
278 DEPFLAGS = -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d) |
273 ifeq ($(USE_CLANG),) |
279 ifeq ($(USE_CLANG),) |
274 ifneq ("${CC_VER_MAJOR}", "2") |
280 ifneq ($(CC_VER_MAJOR), 2) |
275 DEPFLAGS += -fpch-deps |
281 DEPFLAGS += -fpch-deps |
276 endif |
282 endif |
277 endif |
283 endif |
278 |
284 |
279 #------------------------------------------------------------------------ |
285 #------------------------------------------------------------------------ |
280 # Linker flags |
286 # Linker flags |
281 |
287 |
282 # statically link libstdc++.so, work with gcc but ignored by g++ |
288 # statically link libstdc++.so, work with gcc but ignored by g++ |
283 STATIC_STDCXX = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic |
289 STATIC_STDCXX = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic |
284 |
290 |
|
291 # Enable linker optimization |
|
292 LFLAGS += -Xlinker -O1 |
|
293 |
285 ifeq ($(USE_CLANG),) |
294 ifeq ($(USE_CLANG),) |
286 # statically link libgcc and/or libgcc_s, libgcc does not exist before gcc-3.x. |
295 STATIC_LIBGCC += -static-libgcc |
287 ifneq ("${CC_VER_MAJOR}", "2") |
296 |
288 STATIC_LIBGCC += -static-libgcc |
297 ifneq (, findstring(debug,$(BUILD_FLAVOR))) |
|
298 # for relocations read-only |
|
299 LFLAGS += -Xlinker -z -Xlinker relro |
|
300 |
|
301 ifeq ($(BUILD_FLAVOR), debug) |
|
302 # disable incremental relocations linking |
|
303 LFLAGS += -Xlinker -z -Xlinker now |
|
304 endif |
289 endif |
305 endif |
290 |
306 |
291 ifeq ($(BUILDARCH), ia64) |
307 ifeq ($(BUILDARCH), ia64) |
292 LFLAGS += -Wl,-relax |
308 LFLAGS += -Wl,-relax |
293 endif |
309 endif |
294 endif |
310 |
295 |
|
296 # Enable linker optimization |
|
297 LFLAGS += -Xlinker -O1 |
|
298 |
|
299 ifeq ($(USE_CLANG),) |
|
300 # If this is a --hash-style=gnu system, use --hash-style=both |
311 # If this is a --hash-style=gnu system, use --hash-style=both |
301 # The gnu .hash section won't work on some Linux systems like SuSE 10. |
312 # The gnu .hash section won't work on some Linux systems like SuSE 10. |
302 _HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | grep -- '--hash-style=gnu') |
313 _HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | grep -- '--hash-style=gnu') |
303 ifneq ($(_HAS_HASH_STYLE_GNU),) |
314 ifneq ($(_HAS_HASH_STYLE_GNU),) |
304 LDFLAGS_HASH_STYLE = -Wl,--hash-style=both |
315 LDFLAGS_HASH_STYLE = -Wl,--hash-style=both |
331 # too big object files and speed the build up a little bit |
342 # too big object files and speed the build up a little bit |
332 # (see http://llvm.org/bugs/show_bug.cgi?id=7554) |
343 # (see http://llvm.org/bugs/show_bug.cgi?id=7554) |
333 CFLAGS += -flimit-debug-info |
344 CFLAGS += -flimit-debug-info |
334 endif |
345 endif |
335 |
346 |
|
347 ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 8 \) \))" "1" |
|
348 # Allow basic optimizations which don't distrupt debugging. (Principally dead code elimination) |
|
349 DEBUG_CFLAGS=-Og |
|
350 else |
|
351 # Allow no optimizations. |
|
352 DEBUG_CFLAGS=-O0 |
|
353 endif |
|
354 |
336 # DEBUG_BINARIES uses full -g debug information for all configs |
355 # DEBUG_BINARIES uses full -g debug information for all configs |
337 ifeq ($(DEBUG_BINARIES), true) |
356 ifeq ($(DEBUG_BINARIES), true) |
338 CFLAGS += -g |
357 CFLAGS += -g |
339 else |
358 else |
340 DEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH)) |
359 DEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH)) |
350 |
369 |
351 OPT_CFLAGS += $(OPT_CFLAGS/$(BUILDARCH)) |
370 OPT_CFLAGS += $(OPT_CFLAGS/$(BUILDARCH)) |
352 ifeq ($(OPT_CFLAGS/$(BUILDARCH)),) |
371 ifeq ($(OPT_CFLAGS/$(BUILDARCH)),) |
353 OPT_CFLAGS += -g |
372 OPT_CFLAGS += -g |
354 endif |
373 endif |
|
374 endif |
|
375 endif |
|
376 |
|
377 ifeq ($(USE_CLANG),) |
|
378 # Enable bounds checking. |
|
379 # _FORTIFY_SOURCE appears in GCC 4.0+ |
|
380 ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) )" "1" |
|
381 # compile time size bounds checks |
|
382 FASTDEBUG_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 |
|
383 |
|
384 # and runtime size bounds checks and paranoid stack smashing checks. |
|
385 DEBUG_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-all --param ssp-buffer-size=1 |
355 endif |
386 endif |
356 endif |
387 endif |
357 |
388 |
358 # If we are building HEADLESS, pass on to VM |
389 # If we are building HEADLESS, pass on to VM |
359 # so it can set the java.awt.headless property |
390 # so it can set the java.awt.headless property |