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 # When you read this source. Remember that $(sort ...) has the side effect
27 # of removing duplicates. It is actually this side effect that is
28 # desired whenever sort is used below!
29
30 ifndef _NATIVE_COMPILATION_GMK
31 _NATIVE_COMPILATION_GMK := 1
32
33 ifeq (,$(_MAKEBASE_GMK))
34 $(error You must include MakeBase.gmk prior to including NativeCompilation.gmk)
35 endif
36
37 ################################################################################
38 # Define a native toolchain configuration that can be used by
39 # SetupNativeCompilation calls
40 #
41 # Parameter 1 is the name of the toolchain definition
42 #
43 # Remaining parameters are named arguments:
44 # EXTENDS - Optional parent definition to get defaults from
45 # CC - The C compiler
46 # CXX - The C++ compiler
47 # LD - The Linker
48 # AR - Static linker
49 # AS - Assembler
50 # MT - Windows MT tool
51 # RC - Windows RC tool
52 # STRIP - The tool to use for stripping debug symbols
53 # SYSROOT_CFLAGS - Compiler flags for using the specific sysroot
54 # SYSROOT_LDFLAGS - Linker flags for using the specific sysroot
55 DefineNativeToolchain = $(NamedParamsMacroTemplate)
56 define DefineNativeToolchainBody
57 # If extending another definition, get default values from that,
258 # PROGRAM the resulting exec file
259 # INCLUDES only pick source from these directories
260 # EXCLUDES do not pick source from these directories
261 # INCLUDE_FILES only compile exactly these files!
262 # EXCLUDE_FILES with these names
263 # EXTRA_FILES List of extra files not in any of the SRC dirs
264 # VERSIONINFO_RESOURCE Input file for RC. Setting this implies that RC will be run
265 # RC_FLAGS flags for RC.
266 # MAPFILE mapfile
267 # REORDER reorder file
268 # DEBUG_SYMBOLS add debug symbols (if configured on)
269 # CC the compiler to use, default is $(CC)
270 # LD the linker to use, default is $(LD)
271 # OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST
272 # DISABLED_WARNINGS_<toolchain> Disable the given warnings for the specified toolchain
273 # STRIP_SYMBOLS Set to true to strip the final binary if the toolchain allows for it
274 # STRIPFLAGS Optionally change the flags given to the strip command
275 SetupNativeCompilation = $(NamedParamsMacroTemplate)
276 define SetupNativeCompilationBody
277
278 ifneq (,$$($1_BIN))
279 $$(error BIN has been replaced with OBJECT_DIR)
280 endif
281
282 ifneq (,$$($1_LIB))
283 $$(error LIB has been replaced with LIBRARY)
284 endif
285
286 ifneq (,$$($1_EXE))
287 $$(error EXE has been replaced with PROGRAM)
288 endif
289
290 ifneq (,$$($1_LIBRARY))
291 ifeq (,$$($1_OUTPUT_DIR))
292 $$(error LIBRARY requires OUTPUT_DIR)
293 endif
294
295 ifneq ($$($1_LIBRARY),$(basename $$($1_LIBRARY)))
296 $$(error directory of LIBRARY should be specified using OUTPUT_DIR)
297 endif
479 ifdef OPENJDK
480 # Always add debug symbols
481 $1_EXTRA_CFLAGS+=$(CFLAGS_DEBUG_SYMBOLS)
482 $1_EXTRA_CXXFLAGS+=$(CXXFLAGS_DEBUG_SYMBOLS)
483 else
484 # Programs don't get the debug symbols added in the old build. It's not clear if
485 # this is intentional.
486 ifeq ($$($1_PROGRAM),)
487 $1_EXTRA_CFLAGS+=$(CFLAGS_DEBUG_SYMBOLS)
488 $1_EXTRA_CXXFLAGS+=$(CXXFLAGS_DEBUG_SYMBOLS)
489 endif
490 endif
491 endif
492 endif
493
494 ifneq (,$$($1_REORDER))
495 $1_EXTRA_CFLAGS += $$(C_FLAG_REORDER)
496 $1_EXTRA_CXXFLAGS += $$(CXX_FLAG_REORDER)
497 endif
498
499 # Pick up disabled warnings, if possible on this platform.
500 ifneq ($(DISABLE_WARNING_PREFIX),)
501 $1_EXTRA_CFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)))
502 $1_EXTRA_CXXFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)))
503 endif
504
505 # Check if warnings should be considered errors.
506 # Pick first binary and toolchain specific, then binary specific, then general setting.
507 ifeq ($$($1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE)),)
508 ifeq ($$($1_WARNINGS_AS_ERRORS),)
509 $1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE) := $$(WARNINGS_AS_ERRORS)
510 else
511 $1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE) := $$($1_WARNINGS_AS_ERRORS)
512 endif
513 endif
514
515 ifeq ($$($1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE)), true)
516 $1_EXTRA_CFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS)
517 $1_EXTRA_CXXFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS)
518 endif
709 $$($1_STRIP_CMD)
710 # Touch target to make sure it has a later time stamp than the debug
711 # symbol files to avoid unnecessary relinking on rebuild.
712 ifeq ($(OPENJDK_TARGET_OS), windows)
713 $(TOUCH) $$@
714 endif
715
716 endif
717
718 ifneq (,$$($1_STATIC_LIBRARY))
719 $1_VARDEPS := $$($1_AR) $$($1_ARFLAGS) $$($1_LDFLAGS_SUFFIX) \
720 $$($1_EXTRA_LDFLAGS_SUFFIX)
721 $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
722 $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
723
724 # Generating a static library, ie object file archive.
725 $$($1_TARGET): $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_VARDEPS_FILE)
726 $(ECHO) $(LOG_INFO) "Archiving $$($1_STATIC_LIBRARY)"
727 $(call LogFailures, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link.log, $$($1_SAFE_NAME)_link, \
728 $$($1_AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_EXPECTED_OBJS) \
729 $$($1_RES) $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX))
730 endif
731
732 ifneq (,$$($1_PROGRAM))
733 # A executable binary has been specified, setup the target for it.
734 $1_EXTRA_LDFLAGS_SUFFIX += $(GLOBAL_LDFLAGS_SUFFIX)
735
736 $1_VARDEPS := $$($1_LD) $$($1_SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \
737 $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX) $$($1_MT) \
738 $$($1_CODESIGN) $$($1_CREATE_DEBUGINFO_CMDS) $$($1_MANIFEST_VERSION) \
739 $$($1_STRIP_CMD)
740 $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
741 $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
742
743 $$($1_TARGET): $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_MANIFEST) \
744 $$($1_VARDEPS_FILE)
745 $(ECHO) $(LOG_INFO) "Linking executable $$($1_BASENAME)" ; \
746 $(call LogFailures, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link.log, $$($1_SAFE_NAME)_link, \
747 $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
748 $(EXE_OUT_OPTION)$$($1_TARGET) \
749 $$($1_EXPECTED_OBJS) $$($1_RES) \
|
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 # When you read this source. Remember that $(sort ...) has the side effect
27 # of removing duplicates. It is actually this side effect that is
28 # desired whenever sort is used below!
29
30 ifndef _NATIVE_COMPILATION_GMK
31 _NATIVE_COMPILATION_GMK := 1
32
33 ifeq (,$(_MAKEBASE_GMK))
34 $(error You must include MakeBase.gmk prior to including NativeCompilation.gmk)
35 endif
36
37 ################################################################################
38 # Create exported symbols file for static libraries
39 ################################################################################
40
41 # get the exported symbols from mapfiles and if there
42 # is no mapfile, get them from the archive
43 define GetSymbols
44 $(RM) $$(@D)/$$(basename $$(@F)).symbols; \
45 if [ ! -z $$($1_MAPFILE) -a -e $$($1_MAPFILE) ]; then \
46 $(ECHO) "Getting symbols from mapfile $$($1_MAPFILE)"; \
47 $(AWK) '/global:/','/local:/' $$($1_MAPFILE) | \
48 $(SED) -e 's/#.*//;s/global://;s/local://;s/\;//;s/^[ ]*/_/;/^_$$$$/d' | \
49 $(EGREP) -v "JNI_OnLoad|JNI_OnUnload|Agent_OnLoad|Agent_OnUnload|Agent_OnAttach" > \
50 $$(@D)/$$(basename $$(@F)).symbols || true; \
51 $(NM) $$($1_TARGET) | $(GREP) " T " | \
52 $(EGREP) "JNI_OnLoad|JNI_OnUnload|Agent_OnLoad|Agent_OnUnload|Agent_OnAttach" | \
53 $(CUT) -d ' ' -f 3 >> $$(@D)/$$(basename $$(@F)).symbols || true;\
54 else \
55 $(ECHO) "Getting symbols from nm"; \
56 $(NM) -m $$($1_TARGET) | $(GREP) "__TEXT" | \
57 $(EGREP) -v "non-external|private extern|__TEXT,__eh_frame" | \
58 $(SED) -e 's/.* //' > $$(@D)/$$(basename $$(@F)).symbols; \
59 fi
60 endef
61
62 ################################################################################
63 # Define a native toolchain configuration that can be used by
64 # SetupNativeCompilation calls
65 #
66 # Parameter 1 is the name of the toolchain definition
67 #
68 # Remaining parameters are named arguments:
69 # EXTENDS - Optional parent definition to get defaults from
70 # CC - The C compiler
71 # CXX - The C++ compiler
72 # LD - The Linker
73 # AR - Static linker
74 # AS - Assembler
75 # MT - Windows MT tool
76 # RC - Windows RC tool
77 # STRIP - The tool to use for stripping debug symbols
78 # SYSROOT_CFLAGS - Compiler flags for using the specific sysroot
79 # SYSROOT_LDFLAGS - Linker flags for using the specific sysroot
80 DefineNativeToolchain = $(NamedParamsMacroTemplate)
81 define DefineNativeToolchainBody
82 # If extending another definition, get default values from that,
283 # PROGRAM the resulting exec file
284 # INCLUDES only pick source from these directories
285 # EXCLUDES do not pick source from these directories
286 # INCLUDE_FILES only compile exactly these files!
287 # EXCLUDE_FILES with these names
288 # EXTRA_FILES List of extra files not in any of the SRC dirs
289 # VERSIONINFO_RESOURCE Input file for RC. Setting this implies that RC will be run
290 # RC_FLAGS flags for RC.
291 # MAPFILE mapfile
292 # REORDER reorder file
293 # DEBUG_SYMBOLS add debug symbols (if configured on)
294 # CC the compiler to use, default is $(CC)
295 # LD the linker to use, default is $(LD)
296 # OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST
297 # DISABLED_WARNINGS_<toolchain> Disable the given warnings for the specified toolchain
298 # STRIP_SYMBOLS Set to true to strip the final binary if the toolchain allows for it
299 # STRIPFLAGS Optionally change the flags given to the strip command
300 SetupNativeCompilation = $(NamedParamsMacroTemplate)
301 define SetupNativeCompilationBody
302
303 # If we're doing a static build and producing a library
304 # force it to be a static library and remove the -l libraries
305 ifeq ($(STATIC_BUILD), true)
306 ifneq ($$($1_LIBRARY),)
307 $1_STATIC_LIBRARY := $$($1_LIBRARY)
308 $1_LIBRARY :=
309 endif
310 endif
311
312 ifneq (,$$($1_BIN))
313 $$(error BIN has been replaced with OBJECT_DIR)
314 endif
315
316 ifneq (,$$($1_LIB))
317 $$(error LIB has been replaced with LIBRARY)
318 endif
319
320 ifneq (,$$($1_EXE))
321 $$(error EXE has been replaced with PROGRAM)
322 endif
323
324 ifneq (,$$($1_LIBRARY))
325 ifeq (,$$($1_OUTPUT_DIR))
326 $$(error LIBRARY requires OUTPUT_DIR)
327 endif
328
329 ifneq ($$($1_LIBRARY),$(basename $$($1_LIBRARY)))
330 $$(error directory of LIBRARY should be specified using OUTPUT_DIR)
331 endif
513 ifdef OPENJDK
514 # Always add debug symbols
515 $1_EXTRA_CFLAGS+=$(CFLAGS_DEBUG_SYMBOLS)
516 $1_EXTRA_CXXFLAGS+=$(CXXFLAGS_DEBUG_SYMBOLS)
517 else
518 # Programs don't get the debug symbols added in the old build. It's not clear if
519 # this is intentional.
520 ifeq ($$($1_PROGRAM),)
521 $1_EXTRA_CFLAGS+=$(CFLAGS_DEBUG_SYMBOLS)
522 $1_EXTRA_CXXFLAGS+=$(CXXFLAGS_DEBUG_SYMBOLS)
523 endif
524 endif
525 endif
526 endif
527
528 ifneq (,$$($1_REORDER))
529 $1_EXTRA_CFLAGS += $$(C_FLAG_REORDER)
530 $1_EXTRA_CXXFLAGS += $$(CXX_FLAG_REORDER)
531 endif
532
533 # Pass the library name for static JNI library naming
534 ifneq ($$($1_STATIC_LIBRARY),)
535 $1_EXTRA_CFLAGS += -DLIBRARY_NAME=$$($1_STATIC_LIBRARY)
536 $1_EXTRA_CXXFLAGS += -DLIBRARY_NAME=$$($1_STATIC_LIBRARY)
537 endif
538
539 # Pick up disabled warnings, if possible on this platform.
540 ifneq ($(DISABLE_WARNING_PREFIX),)
541 $1_EXTRA_CFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)))
542 $1_EXTRA_CXXFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)))
543 endif
544
545 # Check if warnings should be considered errors.
546 # Pick first binary and toolchain specific, then binary specific, then general setting.
547 ifeq ($$($1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE)),)
548 ifeq ($$($1_WARNINGS_AS_ERRORS),)
549 $1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE) := $$(WARNINGS_AS_ERRORS)
550 else
551 $1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE) := $$($1_WARNINGS_AS_ERRORS)
552 endif
553 endif
554
555 ifeq ($$($1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE)), true)
556 $1_EXTRA_CFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS)
557 $1_EXTRA_CXXFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS)
558 endif
749 $$($1_STRIP_CMD)
750 # Touch target to make sure it has a later time stamp than the debug
751 # symbol files to avoid unnecessary relinking on rebuild.
752 ifeq ($(OPENJDK_TARGET_OS), windows)
753 $(TOUCH) $$@
754 endif
755
756 endif
757
758 ifneq (,$$($1_STATIC_LIBRARY))
759 $1_VARDEPS := $$($1_AR) $$($1_ARFLAGS) $$($1_LDFLAGS_SUFFIX) \
760 $$($1_EXTRA_LDFLAGS_SUFFIX)
761 $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
762 $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
763
764 # Generating a static library, ie object file archive.
765 $$($1_TARGET): $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_VARDEPS_FILE)
766 $(ECHO) $(LOG_INFO) "Archiving $$($1_STATIC_LIBRARY)"
767 $(call LogFailures, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link.log, $$($1_SAFE_NAME)_link, \
768 $$($1_AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_EXPECTED_OBJS) \
769 $$($1_RES))
770 ifeq ($(STATIC_BUILD), true)
771 $(GetSymbols)
772 endif
773 endif
774
775 ifneq (,$$($1_PROGRAM))
776 # A executable binary has been specified, setup the target for it.
777 $1_EXTRA_LDFLAGS_SUFFIX += $(GLOBAL_LDFLAGS_SUFFIX)
778
779 $1_VARDEPS := $$($1_LD) $$($1_SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \
780 $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX) $$($1_MT) \
781 $$($1_CODESIGN) $$($1_CREATE_DEBUGINFO_CMDS) $$($1_MANIFEST_VERSION) \
782 $$($1_STRIP_CMD)
783 $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
784 $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
785
786 $$($1_TARGET): $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_MANIFEST) \
787 $$($1_VARDEPS_FILE)
788 $(ECHO) $(LOG_INFO) "Linking executable $$($1_BASENAME)" ; \
789 $(call LogFailures, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link.log, $$($1_SAFE_NAME)_link, \
790 $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
791 $(EXE_OUT_OPTION)$$($1_TARGET) \
792 $$($1_EXPECTED_OBJS) $$($1_RES) \
|