219 SetupCompileNativeFile = $(NamedParamsMacroTemplate)
220 define SetupCompileNativeFileBody
221 $1_FILENAME := $$(notdir $$($1_FILE))
222
223 # The target file to be generated.
224 $1_OBJ := $$($$($1_BASE)_OBJECT_DIR)/$$(call replace_with_obj_extension, \
225 $$($1_FILENAME))
226
227 # Generate the corresponding compile_commands.json fragment.
228 $1_OBJ_JSON = $$(MAKESUPPORT_OUTPUTDIR)/compile-commands/$$(subst /,_,$$(subst \
229 $$(OUTPUTDIR)/,,$$($1_OBJ))).json
230 $$($1_BASE)_ALL_OBJS_JSON += $$($1_OBJ_JSON)
231
232 # Only continue if this object file hasn't been processed already. This lets
233 # the first found source file override any other with the same name.
234 ifeq ($$($1_OBJ_PROCESSED), )
235 $1_OBJ_PROCESSED := true
236 # This is the definite source file to use for $1_FILENAME.
237 $1_SRC_FILE := $$($1_FILE)
238
239 ifneq ($$($1_DEFINE_THIS_FILE), false)
240 ifneq ($$($$($1_BASE)_DEFINE_THIS_FILE), false)
241 $1_THIS_FILE = -DTHIS_FILE='"$$($1_FILENAME)"'
242 endif
243 endif
244
245 ifeq ($$($1_OPTIMIZATION), )
246 $1_OPT_CFLAGS := $$($$($1_BASE)_OPT_CFLAGS)
247 $1_OPT_CXXFLAGS := $$($$($1_BASE)_OPT_CXXFLAGS)
248 else
249 ifeq ($$($1_OPTIMIZATION), NONE)
250 $1_OPT_CFLAGS := $(C_O_FLAG_NONE)
251 $1_OPT_CXXFLAGS := $(CXX_O_FLAG_NONE)
252 else ifeq ($$($1_OPTIMIZATION), LOW)
253 $1_OPT_CFLAGS := $(C_O_FLAG_NORM)
254 $1_OPT_CXXFLAGS := $(CXX_O_FLAG_NORM)
255 else ifeq ($$($1_OPTIMIZATION), HIGH)
256 $1_OPT_CFLAGS := $(C_O_FLAG_HI)
257 $1_OPT_CXXFLAGS := $(CXX_O_FLAG_HI)
258 else ifeq ($$($1_OPTIMIZATION), HIGHEST)
259 $1_OPT_CFLAGS := $(C_O_FLAG_HIGHEST)
260 $1_OPT_CXXFLAGS := $(CXX_O_FLAG_HIGHEST)
261 else ifeq ($$($1_OPTIMIZATION), HIGHEST_JVM)
262 $1_OPT_CFLAGS := $(C_O_FLAG_HIGHEST_JVM)
263 $1_OPT_CXXFLAGS := $(CXX_O_FLAG_HIGHEST_JVM)
355 # Create a dependency target file from the dependency file.
356 # Solution suggested by http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
357 ifneq ($$($1_DEPS_FILE), )
358 $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_DEPS_FILE) > $$($1_DEPS_TARGETS_FILE)
359 endif
360 else
361 # The Visual Studio compiler lacks a feature for generating make
362 # dependencies, but by setting -showIncludes, all included files are
363 # printed. These are filtered out and parsed into make dependences.
364 #
365 # Keep as much as possible on one execution line for best performance
366 # on Windows. No need to save exit code from compilation since
367 # pipefail is always active on Windows.
368 $$(call ExecuteWithLog, $$@, \
369 $$($1_COMPILER) -showIncludes $$($1_COMPILE_OPTIONS)) \
370 | $(TR) -d '\r' | $(GREP) -v -e "^Note: including file:" \
371 -e "^$$($1_FILENAME)$$$$" || test "$$$$?" = "1" ; \
372 $(ECHO) $$@: \\ > $$($1_DEPS_FILE) ; \
373 $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_OBJ).log \
374 | $(SORT) -u >> $$($1_DEPS_FILE) ; \
375 $(ECHO) >> $$($1_DEPS_FILE) ; \
376 $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_DEPS_FILE) > $$($1_DEPS_TARGETS_FILE)
377 endif
378 endif
379 endef
380
381 # Setup make rules for creating a native binary (a shared library or an
382 # executable).
383 #
384 # Parameter 1 is the name of the rule. This name is used as variable prefix,
385 # and the targets generated are listed in a variable by that name.
386 #
387 # Remaining parameters are named arguments. These include:
388 # NAME The base name for the resulting binary, excluding decorations (like *.exe)
389 # TYPE Type of binary (EXECUTABLE, LIBRARY or STATIC_LIBRARY). Default is LIBRARY.
390 # SUFFIX Override the default suffix for the output file
391 # TOOLCHAIN Name of toolchain setup to use. Defaults to TOOLCHAIN_DEFAULT.
392 # SRC one or more directory roots to scan for C/C++ files.
393 # CFLAGS the compiler flags to be used, used both for C and C++.
394 # CXXFLAGS the compiler flags to be used for c++, if set overrides CFLAGS.
395 # LDFLAGS the linker flags to be used, used both for C and C++.
396 # LIBS the libraries to link to
397 # ARFLAGS the archiver flags to be used
398 # OBJECT_DIR the directory where we store the object files
399 # OUTPUT_DIR the directory where the resulting binary is put
400 # INCLUDES only pick source from these directories
401 # EXCLUDES do not pick source from these directories
402 # INCLUDE_FILES only compile exactly these files!
403 # EXCLUDE_FILES with these names
404 # EXCLUDE_PATTERN exclude files matching any of these substrings
405 # EXTRA_FILES List of extra files not in any of the SRC dirs
406 # EXTRA_OBJECT_FILES List of extra object files to include when linking
407 # EXTRA_DEPS List of extra dependencies to be added to each compiled file
408 # VERSIONINFO_RESOURCE Input file for RC. Setting this implies that RC will be run
409 # RC_FLAGS flags for RC.
410 # EMBED_MANIFEST if true, embed manifest on Windows.
411 # MAPFILE mapfile
412 # REORDER reorder file
413 # USE_MAPFILE_FOR_SYMBOLS if true and this is a STATIC_BUILD, just copy the
414 # mapfile for the output symbols file
415 # CC the compiler to use, default is $(CC)
416 # LD the linker to use, default is $(LD)
417 # OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST, HIGHEST_JVM, SIZE
418 # DISABLED_WARNINGS_<toolchain> Disable the given warnings for the specified toolchain
419 # DISABLED_WARNINGS_C_<toolchain> Disable the given warnings for the specified toolchain
420 # when compiling C code
421 # DISABLED_WARNINGS_CXX_<toolchain> Disable the given warnings for the specified
422 # toolchain when compiling C++ code
423 # STRIP_SYMBOLS Set to false to override global strip policy and always leave
424 # symbols in the binary, if the toolchain allows for it
425 # DEBUG_SYMBOLS Set to false to disable generation of debug symbols
426 # COPY_DEBUG_SYMBOLS Set to false to override global setting of debug symbol copying
427 # ZIP_EXTERNAL_DEBUG_SYMBOLS Set to false to override global setting of debug symbol
428 # zipping
429 # STRIPFLAGS Optionally change the flags given to the strip command
430 # PRECOMPILED_HEADER Header file to use as precompiled header
431 # PRECOMPILED_HEADER_EXCLUDE List of source files that should not use PCH
432 # DEFINE_THIS_FILE Set to false to not set the THIS_FILE preprocessor macro
433 #
434 # After being called, some variables are exported from this macro, all prefixed
435 # with parameter 1 followed by a '_':
436 # TARGET The library or executable created by the macro
437 # TARGET_DEPS All prerequisites for the target calculated by the macro
438 # ALL_OBJS All object files
439 # IMPORT_LIBRARY The import library created for a shared library on Windows
440 SetupNativeCompilation = $(NamedParamsMacroTemplate)
441 define SetupNativeCompilationBody
442
443 # If type is unspecified, default to LIBRARY
444 ifeq ($$($1_TYPE), )
445 $1_TYPE := LIBRARY
446 endif
447
448 # If we're doing a static build and producing a library
449 # force it to be a static library and remove the -l libraries
450 ifeq ($(STATIC_BUILD), true)
451 ifeq ($$($1_TYPE), LIBRARY)
452 $1_TYPE := STATIC_LIBRARY
494 $1_NOSUFFIX := $$($1_PREFIX)$$($1_NAME)
495 $1_SAFE_NAME := $$(strip $$(subst /,_, $1))
496
497 # Need to make sure TARGET is first on list
498 $1 := $$($1_TARGET)
499
500 # Setup the toolchain to be used
501 $$(call SetIfEmpty, $1_TOOLCHAIN, TOOLCHAIN_DEFAULT)
502 $$(call SetIfEmpty, $1_CC, $$($$($1_TOOLCHAIN)_CC))
503 $$(call SetIfEmpty, $1_CXX, $$($$($1_TOOLCHAIN)_CXX))
504 $$(call SetIfEmpty, $1_LD, $$($$($1_TOOLCHAIN)_LD))
505 $$(call SetIfEmpty, $1_AR, $$($$($1_TOOLCHAIN)_AR))
506 $$(call SetIfEmpty, $1_AS, $$($$($1_TOOLCHAIN)_AS))
507 $$(call SetIfEmpty, $1_MT, $$($$($1_TOOLCHAIN)_MT))
508 $$(call SetIfEmpty, $1_RC, $$($$($1_TOOLCHAIN)_RC))
509 $$(call SetIfEmpty, $1_OBJCOPY, $$($$($1_TOOLCHAIN)_OBJCOPY))
510 $$(call SetIfEmpty, $1_STRIP, $$($$($1_TOOLCHAIN)_STRIP))
511 $$(call SetIfEmpty, $1_SYSROOT_CFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_CFLAGS))
512 $$(call SetIfEmpty, $1_SYSROOT_LDFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_LDFLAGS))
513
514 # Make sure the dirs exist.
515 $$(call MakeDir, $$($1_OBJECT_DIR) $$($1_OUTPUT_DIR))
516 $$(foreach d, $$($1_SRC), $$(if $$(wildcard $$d), , \
517 $$(error SRC specified to SetupNativeCompilation $1 contains missing directory $$d)))
518
519 $1_SRCS_RAW := $$(call FindFiles, $$($1_SRC))
520 # Order src files according to the order of the src dirs
521 $1_SRCS := $$(foreach d, $$($1_SRC), $$(filter $$d%, $$($1_SRCS_RAW)))
522 $1_SRCS := $$(filter $$(NATIVE_SOURCE_EXTENSIONS), $$($1_SRCS))
523 # Extract the C/C++ files.
524 ifneq ($$($1_EXCLUDE_PATTERNS), )
525 # We must not match the exclude pattern against the src root(s).
526 $1_SRCS_WITHOUT_ROOTS := $$($1_SRCS)
527 $$(foreach i, $$($1_SRC), $$(eval $1_SRCS_WITHOUT_ROOTS := $$(patsubst \
528 $$i/%,%, $$($1_SRCS_WITHOUT_ROOTS))))
529 $1_ALL_EXCLUDE_FILES := $$(call containing, $$($1_EXCLUDE_PATTERNS), \
530 $$($1_SRCS_WITHOUT_ROOTS))
531 endif
532 ifneq ($$($1_EXCLUDE_FILES), )
533 $1_ALL_EXCLUDE_FILES += $$($1_EXCLUDE_FILES)
534 endif
535 ifneq ($$($1_ALL_EXCLUDE_FILES), )
690 # Track variable changes for all variables that affect the compilation command
691 # lines for all object files in this setup. This includes at least all the
692 # variables used in the call to add_native_source below.
693 $1_COMPILE_VARDEPS := $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $$($1_SYSROOT_CFLAGS) \
694 $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) $$($1_OPT_CFLAGS) $$($1_OPT_CXXFLAGS) \
695 $$($1_CC) $$($1_CXX) $$($1_AS) $$($1_ASFLAGS)
696 $1_COMPILE_VARDEPS_FILE := $$(call DependOnVariable, $1_COMPILE_VARDEPS, \
697 $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).comp.vardeps)
698
699 ifneq ($$($1_PRECOMPILED_HEADER), )
700 ifeq ($(USE_PRECOMPILED_HEADER), true)
701 ifeq ($(TOOLCHAIN_TYPE), microsoft)
702 $1_PCH_FILE := $$($1_OBJECT_DIR)/$1.pch
703 $1_GENERATED_PCH_SRC := $$($1_OBJECT_DIR)/$1_pch.cpp
704 $1_GENERATED_PCH_OBJ := $$($1_OBJECT_DIR)/$1_pch.obj
705
706 $$(eval $$(call SetupCompileNativeFile, $1_$$(notdir $$($1_GENERATED_PCH_SRC)), \
707 FILE := $$($1_GENERATED_PCH_SRC), \
708 BASE := $1, \
709 EXTRA_CXXFLAGS := -Fp$$($1_PCH_FILE) -Yc$$(notdir $$($1_PRECOMPILED_HEADER)), \
710 DEFINE_THIS_FILE := false, \
711 ))
712
713 $1_USE_PCH_FLAGS := \
714 -Fp$$($1_PCH_FILE) -Yu$$(notdir $$($1_PRECOMPILED_HEADER))
715
716 $$($1_ALL_OBJS): $$($1_GENERATED_PCH_OBJ)
717
718 # Explicitly add the pch obj file first to ease comparing to old
719 # hotspot build.
720 $1_ALL_OBJS := $$($1_GENERATED_PCH_OBJ) $$($1_ALL_OBJS)
721
722 $$($1_GENERATED_PCH_SRC):
723 $(ECHO) "#include \"$$(notdir $$($1_PRECOMPILED_HEADER))\"" > $$@
724
725 else ifneq ($(findstring $(TOOLCHAIN_TYPE), gcc clang), )
726 ifeq ($(TOOLCHAIN_TYPE), gcc)
727 $1_PCH_FILE := $$($1_OBJECT_DIR)/precompiled/$$(notdir $$($1_PRECOMPILED_HEADER)).gch
728 $1_USE_PCH_FLAGS := -I$$($1_OBJECT_DIR)/precompiled
729 else ifeq ($(TOOLCHAIN_TYPE), clang)
730 $1_PCH_FILE := $$($1_OBJECT_DIR)/precompiled/$$(notdir $$($1_PRECOMPILED_HEADER)).pch
827 $$(call LogInfo, Compiling resource $$(notdir $$($1_VERSIONINFO_RESOURCE)) (for $$($1_BASENAME)))
828 $$(call MakeDir, $$(@D) $$($1_OBJECT_DIR))
829 $$(call ExecuteWithLog, $$@, \
830 $$($1_RC) $$($1_RC_FLAGS) $$($1_SYSROOT_CFLAGS) $(CC_OUT_OPTION)$$@ \
831 $$($1_VERSIONINFO_RESOURCE) 2>&1 )
832 # Windows RC compiler does not support -showIncludes, so we mis-use CL
833 # for this. Filter out RC specific arguments that are unknown to CL.
834 # For some unknown reason, in this case CL actually outputs the show
835 # includes to stderr so need to redirect it to hide the output from the
836 # main log.
837 $$(call ExecuteWithLog, $$($1_RES_DEPS_FILE).obj, \
838 $$($1_CC) $$(filter-out -l%, $$($1_RC_FLAGS)) \
839 $$($1_SYSROOT_CFLAGS) -showIncludes -nologo -TC \
840 $(CC_OUT_OPTION)$$($1_RES_DEPS_FILE).obj -P -Fi$$($1_RES_DEPS_FILE).pp \
841 $$($1_VERSIONINFO_RESOURCE)) 2>&1 \
842 | $(TR) -d '\r' | $(GREP) -v -e "^Note: including file:" \
843 -e "^$$(notdir $$($1_VERSIONINFO_RESOURCE))$$$$" || test "$$$$?" = "1" ; \
844 $(ECHO) $$($1_RES): \\ > $$($1_RES_DEPS_FILE) ; \
845 $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_RES_DEPS_FILE).obj.log \
846 >> $$($1_RES_DEPS_FILE) ; \
847 $(ECHO) >> $$($1_RES_DEPS_FILE) ;\
848 $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_RES_DEPS_FILE) \
849 > $$($1_RES_DEPS_TARGETS_FILE)
850 endif
851 endif
852
853 ifneq ($(DISABLE_MAPFILES), true)
854 $1_REAL_MAPFILE := $$($1_MAPFILE)
855 ifeq ($(call isTargetOs, windows), false)
856 ifneq ($$($1_REORDER), )
857 $1_REAL_MAPFILE := $$($1_OBJECT_DIR)/mapfile
858
859 $$($1_REAL_MAPFILE) : $$($1_MAPFILE) $$($1_REORDER)
860 $$(call MakeDir, $$(@D))
861 $$(CP) $$($1_MAPFILE) $$@.tmp
862 $$(SED) -e 's=OUTPUTDIR=$$($1_OBJECT_DIR)=' $$($1_REORDER) >> $$@.tmp
863 $$(MV) $$@.tmp $$@
864 endif
865 endif
866 endif
867
868 # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables
869 # for LDFLAGS and LIBS
870 $1_EXTRA_LDFLAGS += $$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS))
871 $1_EXTRA_LIBS += $$($1_LIBS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LIBS_$(OPENJDK_TARGET_OS))
872 ifneq ($$($1_REAL_MAPFILE), )
873 $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE))
874 endif
875
876 ifneq ($$($1_COPY_DEBUG_SYMBOLS), false)
877 $1_COPY_DEBUG_SYMBOLS := $(COPY_DEBUG_SYMBOLS)
878 endif
879
880 ifneq ($$($1_ZIP_EXTERNAL_DEBUG_SYMBOLS), false)
881 $1_ZIP_EXTERNAL_DEBUG_SYMBOLS := $(ZIP_EXTERNAL_DEBUG_SYMBOLS)
882 endif
883
884 ifeq ($$($1_COPY_DEBUG_SYMBOLS), true)
885 ifneq ($$($1_DEBUG_SYMBOLS), false)
886 # Only copy debug symbols for dynamic libraries and programs.
887 ifneq ($$($1_TYPE), STATIC_LIBRARY)
888 # Generate debuginfo files.
889 ifeq ($(call isTargetOs, windows), true)
890 $1_EXTRA_LDFLAGS += -debug "-pdb:$$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).pdb" \
891 "-map:$$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).map"
892 $1_DEBUGINFO_FILES := $$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).pdb \
893 $$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).map
894
895 else ifeq ($(call isTargetOs, linux solaris), true)
896 $1_DEBUGINFO_FILES := $$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).debuginfo
897 # Setup the command line creating debuginfo files, to be run after linking.
898 # It cannot be run separately since it updates the original target file
899 $1_CREATE_DEBUGINFO_CMDS := \
900 $$($1_OBJCOPY) --only-keep-debug $$($1_TARGET) $$($1_DEBUGINFO_FILES) $$(NEWLINE) \
901 $(CD) $$($1_OUTPUT_DIR) && \
902 $$($1_OBJCOPY) --add-gnu-debuglink=$$($1_DEBUGINFO_FILES) $$($1_TARGET)
903
904 else ifeq ($(call isTargetOs, macosx), true)
905 $1_DEBUGINFO_FILES := \
906 $$($1_OUTPUT_DIR)/$$($1_BASENAME).dSYM/Contents/Info.plist \
907 $$($1_OUTPUT_DIR)/$$($1_BASENAME).dSYM/Contents/Resources/DWARF/$$($1_BASENAME)
908 $1_CREATE_DEBUGINFO_CMDS := \
909 $(DSYMUTIL) --out $$($1_OUTPUT_DIR)/$$($1_BASENAME).dSYM $$($1_TARGET)
910 endif
911
912 # Since the link rule creates more than one file that we want to track,
913 # we have to use some tricks to get make to cooperate. To properly
914 # trigger downstream dependants of $$($1_DEBUGINFO_FILES), we must have
915 # a recipe in the rule below. To avoid rerunning the recipe every time
916 # have it touch the target. If a debuginfo file is deleted by something
917 # external, explicitly delete the TARGET to trigger a rebuild of both.
918 ifneq ($$(wildcard $$($1_DEBUGINFO_FILES)), $$($1_DEBUGINFO_FILES))
919 $$(call LogDebug, Deleting $$($1_BASENAME) because debuginfo files are missing)
920 $$(shell $(RM) $$($1_TARGET))
921 endif
922 $$($1_DEBUGINFO_FILES): $$($1_TARGET)
923 $$(if $$(CORRECT_FUNCTION_IN_RECIPE_EVALUATION), \
924 $$(if $$(wildcard $$@), , $$(error $$@ was not created for $$<)) \
925 )
926 $(TOUCH) $$@
927
928 $1 += $$($1_DEBUGINFO_FILES)
929
930 ifeq ($$($1_ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
931 $1_DEBUGINFO_ZIP := $$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).diz
932 $1 += $$($1_DEBUGINFO_ZIP)
933
934 # The dependency on TARGET is needed for debuginfo files
935 # to be rebuilt properly.
936 $$($1_DEBUGINFO_ZIP): $$($1_DEBUGINFO_FILES) $$($1_TARGET)
937 $(CD) $$($1_OUTPUT_DIR) && \
938 $(ZIPEXE) -q -r $$@ $$(subst $$($1_OUTPUT_DIR)/,, $$($1_DEBUGINFO_FILES))
939
940 endif
941 endif # !STATIC_LIBRARY
942 endif # $1_DEBUG_SYMBOLS != false
943 endif # COPY_DEBUG_SYMBOLS
944
945 # Unless specifically set, stripping should only happen if symbols are also
946 # being copied.
947 $$(call SetIfEmpty, $1_STRIP_SYMBOLS, $$($1_COPY_DEBUG_SYMBOLS))
948
949 ifneq ($$($1_STRIP_SYMBOLS), false)
950 ifneq ($$($1_STRIP), )
951 # Default to using the global STRIPFLAGS. Allow for overriding with an empty value
952 $1_STRIPFLAGS ?= $(STRIPFLAGS)
953 $1_STRIP_CMD := $$($1_STRIP) $$($1_STRIPFLAGS) $$($1_TARGET)
954 endif
955 endif
956
957 ifeq ($$($1_TYPE), STATIC_LIBRARY)
958 $1_VARDEPS := $$($1_AR) $$($1_ARFLAGS) $$($1_LIBS) \
959 $$($1_EXTRA_LIBS)
960 $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
961 $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
962
963 # Generating a static library, ie object file archive.
964 ifeq ($(STATIC_BUILD), true)
965 ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
966 STATIC_MAPFILE_DEP := $$($1_MAPFILE)
967 endif
968 endif
969
970 $1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_VARDEPS_FILE) $$(STATIC_MAPFILE_DEP)
971
972 $$($1_TARGET): $$($1_TARGET_DEPS)
973 $$(call LogInfo, Building static library $$($1_BASENAME))
974 $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
975 $$($1_AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_ALL_OBJS) \
976 $$($1_RES))
977 ifeq ($(STATIC_BUILD), true)
978 ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
979 $(CP) $$($1_MAPFILE) $$(@D)/$$(basename $$(@F)).symbols
980 else
981 $(GetSymbols)
982 endif
983 endif
984 else
985 # A shared dynamic library or an executable binary has been specified
986 ifeq ($$($1_TYPE), LIBRARY)
987 # Generating a dynamic library.
988 $1_EXTRA_LDFLAGS += $$(call SET_SHARED_LIBRARY_NAME,$$($1_BASENAME))
989
990 # Create loadmap on AIX. Helps in diagnosing some problems.
991 ifneq ($(COMPILER_BINDCMD_FILE_FLAG), )
992 $1_EXTRA_LDFLAGS += $(COMPILER_BINDCMD_FILE_FLAG)$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).loadmap
993 endif
1055 $1_LINK_OBJS_RELATIVE := true
1056 $1_ALL_OBJS_RELATIVE := $$(patsubst $$(OUTPUTDIR)/%, %, $$($1_ALL_OBJS))
1057 endif
1058 endif
1059 endif
1060
1061 $1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_MANIFEST) \
1062 $$($1_REAL_MAPFILE) $$($1_VARDEPS_FILE)
1063
1064 $$($1_TARGET): $$($1_TARGET_DEPS)
1065 ifneq ($$($1_OBJ_FILE_LIST), )
1066 ifeq ($$($1_LINK_OBJS_RELATIVE), true)
1067 $$(eval $$(call ListPathsSafely, $1_ALL_OBJS_RELATIVE, $$($1_OBJ_FILE_LIST)))
1068 else
1069 $$(eval $$(call ListPathsSafely, $1_ALL_OBJS, $$($1_OBJ_FILE_LIST)))
1070 endif
1071 endif
1072 # Keep as much as possible on one execution line for best performance
1073 # on Windows
1074 $$(call LogInfo, Linking $$($1_BASENAME))
1075 ifeq ($(call isTargetOs, windows), true)
1076 $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
1077 $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
1078 $(LD_OUT_OPTION)$$($1_TARGET) $$($1_LD_OBJ_ARG) $$($1_RES) $$(GLOBAL_LIBS) \
1079 $$($1_LIBS) $$($1_EXTRA_LIBS)) \
1080 | $(GREP) -v "^ Creating library .*\.lib and object .*\.exp" || \
1081 test "$$$$?" = "1" ; \
1082 $$($1_CREATE_DEBUGINFO_CMDS)
1083 $$($1_STRIP_CMD)
1084 else
1085 $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
1086 $$(if $$($1_LINK_OBJS_RELATIVE), $$(CD) $$(OUTPUTDIR) ; ) \
1087 $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
1088 $(LD_OUT_OPTION)$$($1_TARGET) $$($1_LD_OBJ_ARG) $$($1_RES) $$(GLOBAL_LIBS) \
1089 $$($1_LIBS) $$($1_EXTRA_LIBS)) ; \
1090 $$($1_CREATE_DEBUGINFO_CMDS)
1091 $$($1_STRIP_CMD)
1092 endif
1093 ifeq ($(call isTargetOs, windows), true)
1094 ifneq ($$($1_MANIFEST), )
1095 $$($1_MT) -nologo -manifest $$($1_MANIFEST) -identity:"$$($1_NAME).exe, version=$$($1_MANIFEST_VERSION)" -outputresource:$$@;#1
|
219 SetupCompileNativeFile = $(NamedParamsMacroTemplate)
220 define SetupCompileNativeFileBody
221 $1_FILENAME := $$(notdir $$($1_FILE))
222
223 # The target file to be generated.
224 $1_OBJ := $$($$($1_BASE)_OBJECT_DIR)/$$(call replace_with_obj_extension, \
225 $$($1_FILENAME))
226
227 # Generate the corresponding compile_commands.json fragment.
228 $1_OBJ_JSON = $$(MAKESUPPORT_OUTPUTDIR)/compile-commands/$$(subst /,_,$$(subst \
229 $$(OUTPUTDIR)/,,$$($1_OBJ))).json
230 $$($1_BASE)_ALL_OBJS_JSON += $$($1_OBJ_JSON)
231
232 # Only continue if this object file hasn't been processed already. This lets
233 # the first found source file override any other with the same name.
234 ifeq ($$($1_OBJ_PROCESSED), )
235 $1_OBJ_PROCESSED := true
236 # This is the definite source file to use for $1_FILENAME.
237 $1_SRC_FILE := $$($1_FILE)
238
239 ifneq ($$($1_DISABLE_THIS_FILE_DEFINE), true)
240 $1_THIS_FILE = -DTHIS_FILE='"$$($1_FILENAME)"'
241 endif
242
243 ifeq ($$($1_OPTIMIZATION), )
244 $1_OPT_CFLAGS := $$($$($1_BASE)_OPT_CFLAGS)
245 $1_OPT_CXXFLAGS := $$($$($1_BASE)_OPT_CXXFLAGS)
246 else
247 ifeq ($$($1_OPTIMIZATION), NONE)
248 $1_OPT_CFLAGS := $(C_O_FLAG_NONE)
249 $1_OPT_CXXFLAGS := $(CXX_O_FLAG_NONE)
250 else ifeq ($$($1_OPTIMIZATION), LOW)
251 $1_OPT_CFLAGS := $(C_O_FLAG_NORM)
252 $1_OPT_CXXFLAGS := $(CXX_O_FLAG_NORM)
253 else ifeq ($$($1_OPTIMIZATION), HIGH)
254 $1_OPT_CFLAGS := $(C_O_FLAG_HI)
255 $1_OPT_CXXFLAGS := $(CXX_O_FLAG_HI)
256 else ifeq ($$($1_OPTIMIZATION), HIGHEST)
257 $1_OPT_CFLAGS := $(C_O_FLAG_HIGHEST)
258 $1_OPT_CXXFLAGS := $(CXX_O_FLAG_HIGHEST)
259 else ifeq ($$($1_OPTIMIZATION), HIGHEST_JVM)
260 $1_OPT_CFLAGS := $(C_O_FLAG_HIGHEST_JVM)
261 $1_OPT_CXXFLAGS := $(CXX_O_FLAG_HIGHEST_JVM)
353 # Create a dependency target file from the dependency file.
354 # Solution suggested by http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
355 ifneq ($$($1_DEPS_FILE), )
356 $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_DEPS_FILE) > $$($1_DEPS_TARGETS_FILE)
357 endif
358 else
359 # The Visual Studio compiler lacks a feature for generating make
360 # dependencies, but by setting -showIncludes, all included files are
361 # printed. These are filtered out and parsed into make dependences.
362 #
363 # Keep as much as possible on one execution line for best performance
364 # on Windows. No need to save exit code from compilation since
365 # pipefail is always active on Windows.
366 $$(call ExecuteWithLog, $$@, \
367 $$($1_COMPILER) -showIncludes $$($1_COMPILE_OPTIONS)) \
368 | $(TR) -d '\r' | $(GREP) -v -e "^Note: including file:" \
369 -e "^$$($1_FILENAME)$$$$" || test "$$$$?" = "1" ; \
370 $(ECHO) $$@: \\ > $$($1_DEPS_FILE) ; \
371 $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_OBJ).log \
372 | $(SORT) -u >> $$($1_DEPS_FILE) ; \
373 $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_DEPS_FILE) > $$($1_DEPS_TARGETS_FILE)
374 endif
375 endif
376 endef
377
378 # Setup make rules for creating a native binary (a shared library or an
379 # executable).
380 #
381 # Parameter 1 is the name of the rule. This name is used as variable prefix,
382 # and the targets generated are listed in a variable by that name.
383 #
384 # Remaining parameters are named arguments. These include:
385 # NAME The base name for the resulting binary, excluding decorations (like *.exe)
386 # TYPE Type of binary (EXECUTABLE, LIBRARY or STATIC_LIBRARY). Default is LIBRARY.
387 # SUFFIX Override the default suffix for the output file
388 # TOOLCHAIN Name of toolchain setup to use. Defaults to TOOLCHAIN_DEFAULT.
389 # SRC one or more directory roots to scan for C/C++ files.
390 # CFLAGS the compiler flags to be used, used both for C and C++.
391 # CXXFLAGS the compiler flags to be used for c++, if set overrides CFLAGS.
392 # LDFLAGS the linker flags to be used, used both for C and C++.
393 # LIBS the libraries to link to
394 # ARFLAGS the archiver flags to be used
395 # OBJECT_DIR the directory where we store the object files
396 # OUTPUT_DIR the directory where the resulting binary is put
397 # SYMBOLS_DIR the directory where the debug symbols are put, defaults to OUTPUT_DIR
398 # INCLUDES only pick source from these directories
399 # EXCLUDES do not pick source from these directories
400 # INCLUDE_FILES only compile exactly these files!
401 # EXCLUDE_FILES with these names
402 # EXCLUDE_PATTERN exclude files matching any of these substrings
403 # EXTRA_FILES List of extra files not in any of the SRC dirs
404 # EXTRA_OBJECT_FILES List of extra object files to include when linking
405 # EXTRA_DEPS List of extra dependencies to be added to each compiled file
406 # VERSIONINFO_RESOURCE Input file for RC. Setting this implies that RC will be run
407 # RC_FLAGS flags for RC.
408 # EMBED_MANIFEST if true, embed manifest on Windows.
409 # MAPFILE mapfile
410 # REORDER reorder file
411 # USE_MAPFILE_FOR_SYMBOLS if true and this is a STATIC_BUILD, just copy the
412 # mapfile for the output symbols file
413 # CC the compiler to use, default is $(CC)
414 # LD the linker to use, default is $(LD)
415 # OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST, HIGHEST_JVM, SIZE
416 # DISABLED_WARNINGS_<toolchain> Disable the given warnings for the specified toolchain
417 # DISABLED_WARNINGS_C_<toolchain> Disable the given warnings for the specified toolchain
418 # when compiling C code
419 # DISABLED_WARNINGS_CXX_<toolchain> Disable the given warnings for the specified
420 # toolchain when compiling C++ code
421 # STRIP_SYMBOLS Set to false to override global strip policy and always leave
422 # symbols in the binary, if the toolchain allows for it
423 # DEBUG_SYMBOLS Set to false to disable generation of debug symbols
424 # COPY_DEBUG_SYMBOLS Set to false to override global setting of debug symbol copying
425 # ZIP_EXTERNAL_DEBUG_SYMBOLS Set to false to override global setting of debug symbol
426 # zipping
427 # STRIPFLAGS Optionally change the flags given to the strip command
428 # PRECOMPILED_HEADER Header file to use as precompiled header
429 # PRECOMPILED_HEADER_EXCLUDE List of source files that should not use PCH
430 #
431 # After being called, some variables are exported from this macro, all prefixed
432 # with parameter 1 followed by a '_':
433 # TARGET The library or executable created by the macro
434 # TARGET_DEPS All prerequisites for the target calculated by the macro
435 # ALL_OBJS All object files
436 # IMPORT_LIBRARY The import library created for a shared library on Windows
437 SetupNativeCompilation = $(NamedParamsMacroTemplate)
438 define SetupNativeCompilationBody
439
440 # If type is unspecified, default to LIBRARY
441 ifeq ($$($1_TYPE), )
442 $1_TYPE := LIBRARY
443 endif
444
445 # If we're doing a static build and producing a library
446 # force it to be a static library and remove the -l libraries
447 ifeq ($(STATIC_BUILD), true)
448 ifeq ($$($1_TYPE), LIBRARY)
449 $1_TYPE := STATIC_LIBRARY
491 $1_NOSUFFIX := $$($1_PREFIX)$$($1_NAME)
492 $1_SAFE_NAME := $$(strip $$(subst /,_, $1))
493
494 # Need to make sure TARGET is first on list
495 $1 := $$($1_TARGET)
496
497 # Setup the toolchain to be used
498 $$(call SetIfEmpty, $1_TOOLCHAIN, TOOLCHAIN_DEFAULT)
499 $$(call SetIfEmpty, $1_CC, $$($$($1_TOOLCHAIN)_CC))
500 $$(call SetIfEmpty, $1_CXX, $$($$($1_TOOLCHAIN)_CXX))
501 $$(call SetIfEmpty, $1_LD, $$($$($1_TOOLCHAIN)_LD))
502 $$(call SetIfEmpty, $1_AR, $$($$($1_TOOLCHAIN)_AR))
503 $$(call SetIfEmpty, $1_AS, $$($$($1_TOOLCHAIN)_AS))
504 $$(call SetIfEmpty, $1_MT, $$($$($1_TOOLCHAIN)_MT))
505 $$(call SetIfEmpty, $1_RC, $$($$($1_TOOLCHAIN)_RC))
506 $$(call SetIfEmpty, $1_OBJCOPY, $$($$($1_TOOLCHAIN)_OBJCOPY))
507 $$(call SetIfEmpty, $1_STRIP, $$($$($1_TOOLCHAIN)_STRIP))
508 $$(call SetIfEmpty, $1_SYSROOT_CFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_CFLAGS))
509 $$(call SetIfEmpty, $1_SYSROOT_LDFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_LDFLAGS))
510
511 $$(foreach d, $$($1_SRC), $$(if $$(wildcard $$d), , \
512 $$(error SRC specified to SetupNativeCompilation $1 contains missing directory $$d)))
513
514 $1_SRCS_RAW := $$(call FindFiles, $$($1_SRC))
515 # Order src files according to the order of the src dirs
516 $1_SRCS := $$(foreach d, $$($1_SRC), $$(filter $$d%, $$($1_SRCS_RAW)))
517 $1_SRCS := $$(filter $$(NATIVE_SOURCE_EXTENSIONS), $$($1_SRCS))
518 # Extract the C/C++ files.
519 ifneq ($$($1_EXCLUDE_PATTERNS), )
520 # We must not match the exclude pattern against the src root(s).
521 $1_SRCS_WITHOUT_ROOTS := $$($1_SRCS)
522 $$(foreach i, $$($1_SRC), $$(eval $1_SRCS_WITHOUT_ROOTS := $$(patsubst \
523 $$i/%,%, $$($1_SRCS_WITHOUT_ROOTS))))
524 $1_ALL_EXCLUDE_FILES := $$(call containing, $$($1_EXCLUDE_PATTERNS), \
525 $$($1_SRCS_WITHOUT_ROOTS))
526 endif
527 ifneq ($$($1_EXCLUDE_FILES), )
528 $1_ALL_EXCLUDE_FILES += $$($1_EXCLUDE_FILES)
529 endif
530 ifneq ($$($1_ALL_EXCLUDE_FILES), )
685 # Track variable changes for all variables that affect the compilation command
686 # lines for all object files in this setup. This includes at least all the
687 # variables used in the call to add_native_source below.
688 $1_COMPILE_VARDEPS := $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $$($1_SYSROOT_CFLAGS) \
689 $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) $$($1_OPT_CFLAGS) $$($1_OPT_CXXFLAGS) \
690 $$($1_CC) $$($1_CXX) $$($1_AS) $$($1_ASFLAGS)
691 $1_COMPILE_VARDEPS_FILE := $$(call DependOnVariable, $1_COMPILE_VARDEPS, \
692 $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).comp.vardeps)
693
694 ifneq ($$($1_PRECOMPILED_HEADER), )
695 ifeq ($(USE_PRECOMPILED_HEADER), true)
696 ifeq ($(TOOLCHAIN_TYPE), microsoft)
697 $1_PCH_FILE := $$($1_OBJECT_DIR)/$1.pch
698 $1_GENERATED_PCH_SRC := $$($1_OBJECT_DIR)/$1_pch.cpp
699 $1_GENERATED_PCH_OBJ := $$($1_OBJECT_DIR)/$1_pch.obj
700
701 $$(eval $$(call SetupCompileNativeFile, $1_$$(notdir $$($1_GENERATED_PCH_SRC)), \
702 FILE := $$($1_GENERATED_PCH_SRC), \
703 BASE := $1, \
704 EXTRA_CXXFLAGS := -Fp$$($1_PCH_FILE) -Yc$$(notdir $$($1_PRECOMPILED_HEADER)), \
705 DISABLE_THIS_FILE_DEFINE := true, \
706 ))
707
708 $1_USE_PCH_FLAGS := \
709 -Fp$$($1_PCH_FILE) -Yu$$(notdir $$($1_PRECOMPILED_HEADER))
710
711 $$($1_ALL_OBJS): $$($1_GENERATED_PCH_OBJ)
712
713 # Explicitly add the pch obj file first to ease comparing to old
714 # hotspot build.
715 $1_ALL_OBJS := $$($1_GENERATED_PCH_OBJ) $$($1_ALL_OBJS)
716
717 $$($1_GENERATED_PCH_SRC):
718 $(ECHO) "#include \"$$(notdir $$($1_PRECOMPILED_HEADER))\"" > $$@
719
720 else ifneq ($(findstring $(TOOLCHAIN_TYPE), gcc clang), )
721 ifeq ($(TOOLCHAIN_TYPE), gcc)
722 $1_PCH_FILE := $$($1_OBJECT_DIR)/precompiled/$$(notdir $$($1_PRECOMPILED_HEADER)).gch
723 $1_USE_PCH_FLAGS := -I$$($1_OBJECT_DIR)/precompiled
724 else ifeq ($(TOOLCHAIN_TYPE), clang)
725 $1_PCH_FILE := $$($1_OBJECT_DIR)/precompiled/$$(notdir $$($1_PRECOMPILED_HEADER)).pch
822 $$(call LogInfo, Compiling resource $$(notdir $$($1_VERSIONINFO_RESOURCE)) (for $$($1_BASENAME)))
823 $$(call MakeDir, $$(@D) $$($1_OBJECT_DIR))
824 $$(call ExecuteWithLog, $$@, \
825 $$($1_RC) $$($1_RC_FLAGS) $$($1_SYSROOT_CFLAGS) $(CC_OUT_OPTION)$$@ \
826 $$($1_VERSIONINFO_RESOURCE) 2>&1 )
827 # Windows RC compiler does not support -showIncludes, so we mis-use CL
828 # for this. Filter out RC specific arguments that are unknown to CL.
829 # For some unknown reason, in this case CL actually outputs the show
830 # includes to stderr so need to redirect it to hide the output from the
831 # main log.
832 $$(call ExecuteWithLog, $$($1_RES_DEPS_FILE).obj, \
833 $$($1_CC) $$(filter-out -l%, $$($1_RC_FLAGS)) \
834 $$($1_SYSROOT_CFLAGS) -showIncludes -nologo -TC \
835 $(CC_OUT_OPTION)$$($1_RES_DEPS_FILE).obj -P -Fi$$($1_RES_DEPS_FILE).pp \
836 $$($1_VERSIONINFO_RESOURCE)) 2>&1 \
837 | $(TR) -d '\r' | $(GREP) -v -e "^Note: including file:" \
838 -e "^$$(notdir $$($1_VERSIONINFO_RESOURCE))$$$$" || test "$$$$?" = "1" ; \
839 $(ECHO) $$($1_RES): \\ > $$($1_RES_DEPS_FILE) ; \
840 $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_RES_DEPS_FILE).obj.log \
841 >> $$($1_RES_DEPS_FILE) ; \
842 $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_RES_DEPS_FILE) \
843 > $$($1_RES_DEPS_TARGETS_FILE)
844 endif
845 endif
846
847 ifneq ($(DISABLE_MAPFILES), true)
848 $1_REAL_MAPFILE := $$($1_MAPFILE)
849 ifeq ($(call isTargetOs, windows), false)
850 ifneq ($$($1_REORDER), )
851 $1_REAL_MAPFILE := $$($1_OBJECT_DIR)/mapfile
852
853 $$($1_REAL_MAPFILE) : $$($1_MAPFILE) $$($1_REORDER)
854 $$(call MakeDir, $$(@D))
855 $$(CP) $$($1_MAPFILE) $$@.tmp
856 $$(SED) -e 's=OUTPUTDIR=$$($1_OBJECT_DIR)=' $$($1_REORDER) >> $$@.tmp
857 $$(MV) $$@.tmp $$@
858 endif
859 endif
860 endif
861
862 # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables
863 # for LDFLAGS and LIBS
864 $1_EXTRA_LDFLAGS += $$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS))
865 $1_EXTRA_LIBS += $$($1_LIBS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LIBS_$(OPENJDK_TARGET_OS))
866 ifneq ($$($1_REAL_MAPFILE), )
867 $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE))
868 endif
869
870 ifneq ($$($1_COPY_DEBUG_SYMBOLS), false)
871 $1_COPY_DEBUG_SYMBOLS := $(COPY_DEBUG_SYMBOLS)
872 endif
873
874 ifneq ($$($1_ZIP_EXTERNAL_DEBUG_SYMBOLS), false)
875 $1_ZIP_EXTERNAL_DEBUG_SYMBOLS := $(ZIP_EXTERNAL_DEBUG_SYMBOLS)
876 endif
877
878 ifeq ($$($1_COPY_DEBUG_SYMBOLS), true)
879 ifneq ($$($1_DEBUG_SYMBOLS), false)
880 $$(call SetIfEmpty, $1_SYMBOLS_DIR, $$($1_OUTPUT_DIR))
881 # Only copy debug symbols for dynamic libraries and programs.
882 ifneq ($$($1_TYPE), STATIC_LIBRARY)
883 # Generate debuginfo files.
884 ifeq ($(call isTargetOs, windows), true)
885 $1_EXTRA_LDFLAGS += -debug "-pdb:$$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).pdb" \
886 "-map:$$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).map"
887 $1_DEBUGINFO_FILES := $$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).pdb \
888 $$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).map
889
890 else ifeq ($(call isTargetOs, linux solaris), true)
891 $1_DEBUGINFO_FILES := $$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).debuginfo
892 # Setup the command line creating debuginfo files, to be run after linking.
893 # It cannot be run separately since it updates the original target file
894 $1_CREATE_DEBUGINFO_CMDS := \
895 $$($1_OBJCOPY) --only-keep-debug $$($1_TARGET) $$($1_DEBUGINFO_FILES) $$(NEWLINE) \
896 $(CD) $$($1_SYMBOLS_DIR) && \
897 $$($1_OBJCOPY) --add-gnu-debuglink=$$($1_DEBUGINFO_FILES) $$($1_TARGET)
898
899 else ifeq ($(call isTargetOs, macosx), true)
900 $1_DEBUGINFO_FILES := \
901 $$($1_SYMBOLS_DIR)/$$($1_BASENAME).dSYM/Contents/Info.plist \
902 $$($1_SYMBOLS_DIR)/$$($1_BASENAME).dSYM/Contents/Resources/DWARF/$$($1_BASENAME)
903 $1_CREATE_DEBUGINFO_CMDS := \
904 $(DSYMUTIL) --out $$($1_SYMBOLS_DIR)/$$($1_BASENAME).dSYM $$($1_TARGET)
905 endif
906
907 # Since the link rule creates more than one file that we want to track,
908 # we have to use some tricks to get make to cooperate. To properly
909 # trigger downstream dependants of $$($1_DEBUGINFO_FILES), we must have
910 # a recipe in the rule below. To avoid rerunning the recipe every time
911 # have it touch the target. If a debuginfo file is deleted by something
912 # external, explicitly delete the TARGET to trigger a rebuild of both.
913 ifneq ($$(wildcard $$($1_DEBUGINFO_FILES)), $$($1_DEBUGINFO_FILES))
914 $$(call LogDebug, Deleting $$($1_BASENAME) because debuginfo files are missing)
915 $$(shell $(RM) $$($1_TARGET))
916 endif
917 $$($1_DEBUGINFO_FILES): $$($1_TARGET)
918 $$(if $$(CORRECT_FUNCTION_IN_RECIPE_EVALUATION), \
919 $$(if $$(wildcard $$@), , $$(error $$@ was not created for $$<)) \
920 )
921 $(TOUCH) $$@
922
923 $1 += $$($1_DEBUGINFO_FILES)
924
925 ifeq ($$($1_ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
926 $1_DEBUGINFO_ZIP := $$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).diz
927 $1 += $$($1_DEBUGINFO_ZIP)
928
929 # The dependency on TARGET is needed for debuginfo files
930 # to be rebuilt properly.
931 $$($1_DEBUGINFO_ZIP): $$($1_DEBUGINFO_FILES) $$($1_TARGET)
932 $(CD) $$($1_SYMBOLS_DIR) && \
933 $(ZIPEXE) -q -r $$@ $$(subst $$($1_SYMBOLS_DIR)/,, $$($1_DEBUGINFO_FILES))
934
935 endif
936 endif # !STATIC_LIBRARY
937 endif # $1_DEBUG_SYMBOLS != false
938 endif # COPY_DEBUG_SYMBOLS
939
940 # Unless specifically set, stripping should only happen if symbols are also
941 # being copied.
942 $$(call SetIfEmpty, $1_STRIP_SYMBOLS, $$($1_COPY_DEBUG_SYMBOLS))
943
944 ifneq ($$($1_STRIP_SYMBOLS), false)
945 ifneq ($$($1_STRIP), )
946 # Default to using the global STRIPFLAGS. Allow for overriding with an empty value
947 $1_STRIPFLAGS ?= $(STRIPFLAGS)
948 $1_STRIP_CMD := $$($1_STRIP) $$($1_STRIPFLAGS) $$($1_TARGET)
949 endif
950 endif
951
952 ifeq ($$($1_TYPE), STATIC_LIBRARY)
953 $1_VARDEPS := $$($1_AR) $$($1_ARFLAGS) $$($1_LIBS) \
954 $$($1_EXTRA_LIBS)
955 $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
956 $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
957
958 # Generating a static library, ie object file archive.
959 ifeq ($(STATIC_BUILD), true)
960 ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
961 STATIC_MAPFILE_DEP := $$($1_MAPFILE)
962 endif
963 endif
964
965 $1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_VARDEPS_FILE) $$(STATIC_MAPFILE_DEP)
966
967 $$($1_TARGET): $$($1_TARGET_DEPS)
968 $$(call LogInfo, Building static library $$($1_BASENAME))
969 $$(call MakeDir, $$($1_OUTPUT_DIR) $$($1_SYMBOLS_DIR))
970 $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
971 $$($1_AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_ALL_OBJS) \
972 $$($1_RES))
973 ifeq ($(STATIC_BUILD), true)
974 ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
975 $(CP) $$($1_MAPFILE) $$(@D)/$$(basename $$(@F)).symbols
976 else
977 $(GetSymbols)
978 endif
979 endif
980 else
981 # A shared dynamic library or an executable binary has been specified
982 ifeq ($$($1_TYPE), LIBRARY)
983 # Generating a dynamic library.
984 $1_EXTRA_LDFLAGS += $$(call SET_SHARED_LIBRARY_NAME,$$($1_BASENAME))
985
986 # Create loadmap on AIX. Helps in diagnosing some problems.
987 ifneq ($(COMPILER_BINDCMD_FILE_FLAG), )
988 $1_EXTRA_LDFLAGS += $(COMPILER_BINDCMD_FILE_FLAG)$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).loadmap
989 endif
1051 $1_LINK_OBJS_RELATIVE := true
1052 $1_ALL_OBJS_RELATIVE := $$(patsubst $$(OUTPUTDIR)/%, %, $$($1_ALL_OBJS))
1053 endif
1054 endif
1055 endif
1056
1057 $1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_MANIFEST) \
1058 $$($1_REAL_MAPFILE) $$($1_VARDEPS_FILE)
1059
1060 $$($1_TARGET): $$($1_TARGET_DEPS)
1061 ifneq ($$($1_OBJ_FILE_LIST), )
1062 ifeq ($$($1_LINK_OBJS_RELATIVE), true)
1063 $$(eval $$(call ListPathsSafely, $1_ALL_OBJS_RELATIVE, $$($1_OBJ_FILE_LIST)))
1064 else
1065 $$(eval $$(call ListPathsSafely, $1_ALL_OBJS, $$($1_OBJ_FILE_LIST)))
1066 endif
1067 endif
1068 # Keep as much as possible on one execution line for best performance
1069 # on Windows
1070 $$(call LogInfo, Linking $$($1_BASENAME))
1071 $$(call MakeDir, $$($1_OUTPUT_DIR) $$($1_SYMBOLS_DIR))
1072 ifeq ($(call isTargetOs, windows), true)
1073
1074 $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
1075 $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
1076 $(LD_OUT_OPTION)$$($1_TARGET) $$($1_LD_OBJ_ARG) $$($1_RES) $$(GLOBAL_LIBS) \
1077 $$($1_LIBS) $$($1_EXTRA_LIBS)) \
1078 | $(GREP) -v "^ Creating library .*\.lib and object .*\.exp" || \
1079 test "$$$$?" = "1" ; \
1080 $$($1_CREATE_DEBUGINFO_CMDS)
1081 $$($1_STRIP_CMD)
1082 else
1083 $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
1084 $$(if $$($1_LINK_OBJS_RELATIVE), $$(CD) $$(OUTPUTDIR) ; ) \
1085 $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
1086 $(LD_OUT_OPTION)$$($1_TARGET) $$($1_LD_OBJ_ARG) $$($1_RES) $$(GLOBAL_LIBS) \
1087 $$($1_LIBS) $$($1_EXTRA_LIBS)) ; \
1088 $$($1_CREATE_DEBUGINFO_CMDS)
1089 $$($1_STRIP_CMD)
1090 endif
1091 ifeq ($(call isTargetOs, windows), true)
1092 ifneq ($$($1_MANIFEST), )
1093 $$($1_MT) -nologo -manifest $$($1_MANIFEST) -identity:"$$($1_NAME).exe, version=$$($1_MANIFEST_VERSION)" -outputresource:$$@;#1
|