< prev index next >

make/common/NativeCompilation.gmk

Print this page


   1 #
   2 # Copyright (c) 2011, 2018, 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


 373 
 374 # Setup make rules for creating a native binary (a shared library or an
 375 # executable).
 376 #
 377 # Parameter 1 is the name of the rule. This name is used as variable prefix,
 378 # and the targets generated are listed in a variable by that name.
 379 #
 380 # Remaining parameters are named arguments. These include:
 381 #   NAME The base name for the resulting binary, excluding decorations (like *.exe)
 382 #   TYPE Type of binary (EXECUTABLE, LIBRARY or STATIC_LIBRARY). Default is LIBRARY.
 383 #   SUFFIX Override the default suffix for the output file
 384 #   TOOLCHAIN Name of toolchain setup to use. Defaults to TOOLCHAIN_DEFAULT.
 385 #   SRC one or more directory roots to scan for C/C++ files.
 386 #   CFLAGS the compiler flags to be used, used both for C and C++.
 387 #   CXXFLAGS the compiler flags to be used for c++, if set overrides CFLAGS.
 388 #   LDFLAGS the linker flags to be used, used both for C and C++.
 389 #   LIBS the libraries to link to
 390 #   ARFLAGS the archiver flags to be used
 391 #   OBJECT_DIR the directory where we store the object files
 392 #   OUTPUT_DIR the directory where the resulting binary is put

 393 #   INCLUDES only pick source from these directories
 394 #   EXCLUDES do not pick source from these directories
 395 #   INCLUDE_FILES only compile exactly these files!
 396 #   EXCLUDE_FILES with these names
 397 #   EXCLUDE_PATTERN exclude files matching any of these substrings
 398 #   EXTRA_FILES List of extra files not in any of the SRC dirs
 399 #   EXTRA_OBJECT_FILES List of extra object files to include when linking
 400 #   EXTRA_DEPS List of extra dependencies to be added to each compiled file
 401 #   VERSIONINFO_RESOURCE Input file for RC. Setting this implies that RC will be run
 402 #   RC_FLAGS flags for RC.
 403 #   EMBED_MANIFEST if true, embed manifest on Windows.
 404 #   MAPFILE mapfile
 405 #   REORDER reorder file
 406 #   USE_MAPFILE_FOR_SYMBOLS if true and this is a STATIC_BUILD, just copy the
 407 #       mapfile for the output symbols file
 408 #   CC the compiler to use, default is $(CC)
 409 #   LD the linker to use, default is $(LD)
 410 #   OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST, HIGHEST_JVM, SIZE
 411 #   DISABLED_WARNINGS_<toolchain> Disable the given warnings for the specified toolchain
 412 #   DISABLED_WARNINGS_C_<toolchain> Disable the given warnings for the specified toolchain


 483 
 484   $1_BASENAME := $$($1_PREFIX)$$($1_NAME)$$($1_SUFFIX)
 485   $1_TARGET := $$($1_OUTPUT_DIR)/$$($1_BASENAME)
 486   $1_NOSUFFIX := $$($1_PREFIX)$$($1_NAME)
 487   $1_SAFE_NAME := $$(strip $$(subst /,_, $1))
 488 
 489   # Setup the toolchain to be used
 490   $$(call SetIfEmpty, $1_TOOLCHAIN, TOOLCHAIN_DEFAULT)
 491   $$(call SetIfEmpty, $1_CC, $$($$($1_TOOLCHAIN)_CC))
 492   $$(call SetIfEmpty, $1_CXX, $$($$($1_TOOLCHAIN)_CXX))
 493   $$(call SetIfEmpty, $1_LD, $$($$($1_TOOLCHAIN)_LD))
 494   $$(call SetIfEmpty, $1_AR, $$($$($1_TOOLCHAIN)_AR))
 495   $$(call SetIfEmpty, $1_AS, $$($$($1_TOOLCHAIN)_AS))
 496   $$(call SetIfEmpty, $1_MT, $$($$($1_TOOLCHAIN)_MT))
 497   $$(call SetIfEmpty, $1_RC, $$($$($1_TOOLCHAIN)_RC))
 498   $$(call SetIfEmpty, $1_OBJCOPY, $$($$($1_TOOLCHAIN)_OBJCOPY))
 499   $$(call SetIfEmpty, $1_STRIP, $$($$($1_TOOLCHAIN)_STRIP))
 500   $$(call SetIfEmpty, $1_SYSROOT_CFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_CFLAGS))
 501   $$(call SetIfEmpty, $1_SYSROOT_LDFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_LDFLAGS))
 502 
 503   # Make sure the dirs exist.
 504   $$(call MakeDir, $$($1_OBJECT_DIR) $$($1_OUTPUT_DIR))
 505   $$(foreach d, $$($1_SRC), $$(if $$(wildcard $$d), , \
 506       $$(error SRC specified to SetupNativeCompilation $1 contains missing directory $$d)))
 507 
 508   # Find all files in the source trees. Preserve order.
 509   $1_SRCS := $$(foreach s, $$($1_SRC), $$(call CacheFind, $$(s)))
 510   $1_SRCS := $$(filter $$(NATIVE_SOURCE_EXTENSIONS), $$($1_SRCS))
 511   # Extract the C/C++ files.
 512   ifneq ($$($1_EXCLUDE_PATTERNS), )
 513     # We must not match the exclude pattern against the src root(s).
 514     $1_SRCS_WITHOUT_ROOTS := $$($1_SRCS)
 515     $$(foreach i, $$($1_SRC), $$(eval $1_SRCS_WITHOUT_ROOTS := $$(patsubst \
 516         $$i/%,%, $$($1_SRCS_WITHOUT_ROOTS))))
 517     $1_ALL_EXCLUDE_FILES :=  $$(call containing, $$($1_EXCLUDE_PATTERNS), \
 518         $$($1_SRCS_WITHOUT_ROOTS))
 519   endif
 520   ifneq ($$($1_EXCLUDE_FILES), )
 521     $1_ALL_EXCLUDE_FILES += $$($1_EXCLUDE_FILES)
 522   endif
 523   ifneq ($$($1_ALL_EXCLUDE_FILES), )
 524     $1_EXCLUDE_FILES_PAT := $$($1_ALL_EXCLUDE_FILES) \


 825   # for LDFLAGS and LIBS
 826   $1_EXTRA_LDFLAGS += $$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS))
 827   $1_EXTRA_LIBS += $$($1_LIBS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LIBS_$(OPENJDK_TARGET_OS))
 828   ifneq ($$($1_REAL_MAPFILE), )
 829     $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE))
 830   endif
 831 
 832   # Need to make sure TARGET is first on list
 833   $1 := $$($1_TARGET)
 834 
 835   ifneq ($$($1_COPY_DEBUG_SYMBOLS), false)
 836     $1_COPY_DEBUG_SYMBOLS := $(COPY_DEBUG_SYMBOLS)
 837   endif
 838 
 839   ifneq ($$($1_ZIP_EXTERNAL_DEBUG_SYMBOLS), false)
 840     $1_ZIP_EXTERNAL_DEBUG_SYMBOLS := $(ZIP_EXTERNAL_DEBUG_SYMBOLS)
 841   endif
 842 
 843   ifeq ($$($1_COPY_DEBUG_SYMBOLS), true)
 844     ifneq ($$($1_DEBUG_SYMBOLS), false)

 845       # Only copy debug symbols for dynamic libraries and programs.
 846       ifneq ($$($1_TYPE), STATIC_LIBRARY)
 847         # Generate debuginfo files.
 848         ifeq ($(OPENJDK_TARGET_OS), windows)
 849           $1_EXTRA_LDFLAGS += -debug "-pdb:$$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).pdb" \
 850               "-map:$$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).map"
 851           $1_DEBUGINFO_FILES := $$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).pdb \
 852               $$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).map
 853 
 854         else ifneq ($(findstring $(OPENJDK_TARGET_OS), linux solaris), )
 855           $1_DEBUGINFO_FILES := $$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).debuginfo
 856           # Setup the command line creating debuginfo files, to be run after linking.
 857           # It cannot be run separately since it updates the original target file
 858           $1_CREATE_DEBUGINFO_CMDS := \
 859               $$($1_OBJCOPY) --only-keep-debug $$($1_TARGET) $$($1_DEBUGINFO_FILES) $$(NEWLINE) \
 860               $(CD) $$($1_OUTPUT_DIR) && \
 861                   $$($1_OBJCOPY) --add-gnu-debuglink=$$($1_DEBUGINFO_FILES) $$($1_TARGET)
 862 
 863         else ifeq ($(OPENJDK_TARGET_OS), macosx)
 864           $1_DEBUGINFO_FILES := \
 865               $$($1_OUTPUT_DIR)/$$($1_BASENAME).dSYM/Contents/Info.plist \
 866               $$($1_OUTPUT_DIR)/$$($1_BASENAME).dSYM/Contents/Resources/DWARF/$$($1_BASENAME)
 867           $1_CREATE_DEBUGINFO_CMDS := \
 868               $(DSYMUTIL) --out $$($1_OUTPUT_DIR)/$$($1_BASENAME).dSYM $$($1_TARGET)
 869         endif # OPENJDK_TARGET_OS
 870 
 871         # Since the link rule creates more than one file that we want to track,
 872         # we have to use some tricks to get make to cooperate. To properly
 873         # trigger downstream dependants of $$($1_DEBUGINFO_FILES), we must have
 874         # a recipe in the rule below. To avoid rerunning the recipe every time
 875         # have it touch the target. If a debuginfo file is deleted by something
 876         # external, explicitly delete the TARGET to trigger a rebuild of both.
 877         ifneq ($$(wildcard $$($1_DEBUGINFO_FILES)), $$($1_DEBUGINFO_FILES))
 878           $$(call LogDebug, Deleting $$($1_BASENAME) because debuginfo files are missing)
 879           $$(shell $(RM) $$($1_TARGET))
 880         endif
 881         $$($1_DEBUGINFO_FILES): $$($1_TARGET)
 882                 $$(if $$(CORRECT_FUNCTION_IN_RECIPE_EVALUATION), \
 883                   $$(if $$(wildcard $$@), , $$(error $$@ was not created for $$<)) \
 884                 )
 885                 $(TOUCH) $$@
 886 
 887         $1 += $$($1_DEBUGINFO_FILES)
 888 
 889         ifeq ($$($1_ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
 890           $1_DEBUGINFO_ZIP := $$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).diz
 891           $1 += $$($1_DEBUGINFO_ZIP)
 892 
 893           # The dependency on TARGET is needed for debuginfo files
 894           # to be rebuilt properly.
 895           $$($1_DEBUGINFO_ZIP): $$($1_DEBUGINFO_FILES) $$($1_TARGET)
 896                 $(CD) $$($1_OUTPUT_DIR) && \
 897                     $(ZIPEXE) -q -r $$@ $$(subst $$($1_OUTPUT_DIR)/,, $$($1_DEBUGINFO_FILES))
 898 
 899         endif
 900        endif # !STATIC_LIBRARY
 901     endif # $1_DEBUG_SYMBOLS != false
 902   endif # COPY_DEBUG_SYMBOLS
 903 
 904   # Unless specifically set, stripping should only happen if symbols are also
 905   # being copied.
 906   $$(call SetIfEmpty, $1_STRIP_SYMBOLS, $$($1_COPY_DEBUG_SYMBOLS))
 907 
 908   ifneq ($$($1_STRIP_SYMBOLS), false)
 909     ifneq ($$($1_STRIP), )
 910       # Default to using the global STRIPFLAGS. Allow for overriding with an empty value
 911       $1_STRIPFLAGS ?= $(STRIPFLAGS)
 912       $1_STRIP_CMD := $$($1_STRIP) $$($1_STRIPFLAGS) $$($1_TARGET)
 913     endif
 914   endif
 915 
 916   ifeq ($$($1_TYPE), STATIC_LIBRARY)
 917     $1_VARDEPS := $$($1_AR) $$($1_ARFLAGS) $$($1_LIBS) \
 918         $$($1_EXTRA_LIBS)
 919     $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
 920         $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
 921 
 922     # Generating a static library, ie object file archive.
 923     ifeq ($(STATIC_BUILD), true)
 924       ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
 925         STATIC_MAPFILE_DEP := $$($1_MAPFILE)
 926       endif
 927     endif
 928 
 929     $1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_VARDEPS_FILE) $$(STATIC_MAPFILE_DEP)
 930 
 931     $$($1_TARGET): $$($1_TARGET_DEPS)
 932         $$(call LogInfo, Building static library $$($1_BASENAME))

 933         $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
 934             $$($1_AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_ALL_OBJS) \
 935                 $$($1_RES))
 936         ifeq ($(STATIC_BUILD), true)
 937           ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
 938             $(CP) $$($1_MAPFILE) $$(@D)/$$(basename $$(@F)).symbols
 939           else
 940             $(GetSymbols)
 941           endif
 942         endif
 943   else
 944     # A shared dynamic library or an executable binary has been specified
 945     ifeq ($$($1_TYPE), LIBRARY)
 946       # Generating a dynamic library.
 947       $1_EXTRA_LDFLAGS += $$(call SET_SHARED_LIBRARY_NAME,$$($1_BASENAME))
 948 
 949       # Create loadmap on AIX. Helps in diagnosing some problems.
 950       ifneq ($(COMPILER_BINDCMD_FILE_FLAG), )
 951         $1_EXTRA_LDFLAGS += $(COMPILER_BINDCMD_FILE_FLAG)$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).loadmap
 952       endif


1015           $1_LINK_OBJS_RELATIVE := true
1016           $1_ALL_OBJS_RELATIVE := $$(patsubst $$(OUTPUTDIR)/%, %, $$($1_ALL_OBJS))
1017         endif
1018       endif
1019     endif
1020 
1021     $1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_MANIFEST) \
1022         $$($1_REAL_MAPFILE) $$($1_VARDEPS_FILE)
1023 
1024     $$($1_TARGET): $$($1_TARGET_DEPS)
1025                 ifneq ($$($1_OBJ_FILE_LIST), )
1026                   ifeq ($$($1_LINK_OBJS_RELATIVE), true)
1027                     $$(eval $$(call ListPathsSafely, $1_ALL_OBJS_RELATIVE, $$($1_OBJ_FILE_LIST)))
1028                   else
1029                     $$(eval $$(call ListPathsSafely, $1_ALL_OBJS, $$($1_OBJ_FILE_LIST)))
1030                   endif
1031                 endif
1032                 # Keep as much as possible on one execution line for best performance
1033                 # on Windows
1034                 $$(call LogInfo, Linking $$($1_BASENAME))

1035                 ifeq ($(OPENJDK_TARGET_OS), windows)
1036                   $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
1037                       $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
1038                           $(LD_OUT_OPTION)$$($1_TARGET) $$($1_LD_OBJ_ARG) $$($1_RES) $$(GLOBAL_LIBS) \
1039                           $$($1_LIBS) $$($1_EXTRA_LIBS)) \
1040                       | $(GREP) -v "^   Creating library .*\.lib and object .*\.exp" || \
1041                           test "$$$$?" = "1" ; \
1042                   $$($1_CREATE_DEBUGINFO_CMDS)
1043                   $$($1_STRIP_CMD)
1044                 else
1045                   $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
1046                       $$(if $$($1_LINK_OBJS_RELATIVE), $$(CD) $$(OUTPUTDIR) ; ) \
1047                       $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
1048                           $(LD_OUT_OPTION)$$($1_TARGET) $$($1_LD_OBJ_ARG) $$($1_RES) $$(GLOBAL_LIBS) \
1049                           $$($1_LIBS) $$($1_EXTRA_LIBS)) ; \
1050                   $$($1_CREATE_DEBUGINFO_CMDS)
1051                   $$($1_STRIP_CMD)
1052                 endif
1053                 ifeq ($(OPENJDK_TARGET_OS), windows)
1054                   ifneq ($$($1_MANIFEST), )
   1 #
   2 # Copyright (c) 2011, 2019, 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


 373 
 374 # Setup make rules for creating a native binary (a shared library or an
 375 # executable).
 376 #
 377 # Parameter 1 is the name of the rule. This name is used as variable prefix,
 378 # and the targets generated are listed in a variable by that name.
 379 #
 380 # Remaining parameters are named arguments. These include:
 381 #   NAME The base name for the resulting binary, excluding decorations (like *.exe)
 382 #   TYPE Type of binary (EXECUTABLE, LIBRARY or STATIC_LIBRARY). Default is LIBRARY.
 383 #   SUFFIX Override the default suffix for the output file
 384 #   TOOLCHAIN Name of toolchain setup to use. Defaults to TOOLCHAIN_DEFAULT.
 385 #   SRC one or more directory roots to scan for C/C++ files.
 386 #   CFLAGS the compiler flags to be used, used both for C and C++.
 387 #   CXXFLAGS the compiler flags to be used for c++, if set overrides CFLAGS.
 388 #   LDFLAGS the linker flags to be used, used both for C and C++.
 389 #   LIBS the libraries to link to
 390 #   ARFLAGS the archiver flags to be used
 391 #   OBJECT_DIR the directory where we store the object files
 392 #   OUTPUT_DIR the directory where the resulting binary is put
 393 #   SYMBOLS_DIR the directory where the debug symbols are put, defaults to OUTPUT_DIR
 394 #   INCLUDES only pick source from these directories
 395 #   EXCLUDES do not pick source from these directories
 396 #   INCLUDE_FILES only compile exactly these files!
 397 #   EXCLUDE_FILES with these names
 398 #   EXCLUDE_PATTERN exclude files matching any of these substrings
 399 #   EXTRA_FILES List of extra files not in any of the SRC dirs
 400 #   EXTRA_OBJECT_FILES List of extra object files to include when linking
 401 #   EXTRA_DEPS List of extra dependencies to be added to each compiled file
 402 #   VERSIONINFO_RESOURCE Input file for RC. Setting this implies that RC will be run
 403 #   RC_FLAGS flags for RC.
 404 #   EMBED_MANIFEST if true, embed manifest on Windows.
 405 #   MAPFILE mapfile
 406 #   REORDER reorder file
 407 #   USE_MAPFILE_FOR_SYMBOLS if true and this is a STATIC_BUILD, just copy the
 408 #       mapfile for the output symbols file
 409 #   CC the compiler to use, default is $(CC)
 410 #   LD the linker to use, default is $(LD)
 411 #   OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST, HIGHEST_JVM, SIZE
 412 #   DISABLED_WARNINGS_<toolchain> Disable the given warnings for the specified toolchain
 413 #   DISABLED_WARNINGS_C_<toolchain> Disable the given warnings for the specified toolchain


 484 
 485   $1_BASENAME := $$($1_PREFIX)$$($1_NAME)$$($1_SUFFIX)
 486   $1_TARGET := $$($1_OUTPUT_DIR)/$$($1_BASENAME)
 487   $1_NOSUFFIX := $$($1_PREFIX)$$($1_NAME)
 488   $1_SAFE_NAME := $$(strip $$(subst /,_, $1))
 489 
 490   # Setup the toolchain to be used
 491   $$(call SetIfEmpty, $1_TOOLCHAIN, TOOLCHAIN_DEFAULT)
 492   $$(call SetIfEmpty, $1_CC, $$($$($1_TOOLCHAIN)_CC))
 493   $$(call SetIfEmpty, $1_CXX, $$($$($1_TOOLCHAIN)_CXX))
 494   $$(call SetIfEmpty, $1_LD, $$($$($1_TOOLCHAIN)_LD))
 495   $$(call SetIfEmpty, $1_AR, $$($$($1_TOOLCHAIN)_AR))
 496   $$(call SetIfEmpty, $1_AS, $$($$($1_TOOLCHAIN)_AS))
 497   $$(call SetIfEmpty, $1_MT, $$($$($1_TOOLCHAIN)_MT))
 498   $$(call SetIfEmpty, $1_RC, $$($$($1_TOOLCHAIN)_RC))
 499   $$(call SetIfEmpty, $1_OBJCOPY, $$($$($1_TOOLCHAIN)_OBJCOPY))
 500   $$(call SetIfEmpty, $1_STRIP, $$($$($1_TOOLCHAIN)_STRIP))
 501   $$(call SetIfEmpty, $1_SYSROOT_CFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_CFLAGS))
 502   $$(call SetIfEmpty, $1_SYSROOT_LDFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_LDFLAGS))
 503 


 504   $$(foreach d, $$($1_SRC), $$(if $$(wildcard $$d), , \
 505       $$(error SRC specified to SetupNativeCompilation $1 contains missing directory $$d)))
 506 
 507   # Find all files in the source trees. Preserve order.
 508   $1_SRCS := $$(foreach s, $$($1_SRC), $$(call CacheFind, $$(s)))
 509   $1_SRCS := $$(filter $$(NATIVE_SOURCE_EXTENSIONS), $$($1_SRCS))
 510   # Extract the C/C++ files.
 511   ifneq ($$($1_EXCLUDE_PATTERNS), )
 512     # We must not match the exclude pattern against the src root(s).
 513     $1_SRCS_WITHOUT_ROOTS := $$($1_SRCS)
 514     $$(foreach i, $$($1_SRC), $$(eval $1_SRCS_WITHOUT_ROOTS := $$(patsubst \
 515         $$i/%,%, $$($1_SRCS_WITHOUT_ROOTS))))
 516     $1_ALL_EXCLUDE_FILES :=  $$(call containing, $$($1_EXCLUDE_PATTERNS), \
 517         $$($1_SRCS_WITHOUT_ROOTS))
 518   endif
 519   ifneq ($$($1_EXCLUDE_FILES), )
 520     $1_ALL_EXCLUDE_FILES += $$($1_EXCLUDE_FILES)
 521   endif
 522   ifneq ($$($1_ALL_EXCLUDE_FILES), )
 523     $1_EXCLUDE_FILES_PAT := $$($1_ALL_EXCLUDE_FILES) \


 824   # for LDFLAGS and LIBS
 825   $1_EXTRA_LDFLAGS += $$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS))
 826   $1_EXTRA_LIBS += $$($1_LIBS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LIBS_$(OPENJDK_TARGET_OS))
 827   ifneq ($$($1_REAL_MAPFILE), )
 828     $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE))
 829   endif
 830 
 831   # Need to make sure TARGET is first on list
 832   $1 := $$($1_TARGET)
 833 
 834   ifneq ($$($1_COPY_DEBUG_SYMBOLS), false)
 835     $1_COPY_DEBUG_SYMBOLS := $(COPY_DEBUG_SYMBOLS)
 836   endif
 837 
 838   ifneq ($$($1_ZIP_EXTERNAL_DEBUG_SYMBOLS), false)
 839     $1_ZIP_EXTERNAL_DEBUG_SYMBOLS := $(ZIP_EXTERNAL_DEBUG_SYMBOLS)
 840   endif
 841 
 842   ifeq ($$($1_COPY_DEBUG_SYMBOLS), true)
 843     ifneq ($$($1_DEBUG_SYMBOLS), false)
 844       $$(call SetIfEmpty, $1_SYMBOLS_DIR, $$($1_OUTPUT_DIR))
 845       # Only copy debug symbols for dynamic libraries and programs.
 846       ifneq ($$($1_TYPE), STATIC_LIBRARY)
 847         # Generate debuginfo files.
 848         ifeq ($(OPENJDK_TARGET_OS), windows)
 849           $1_EXTRA_LDFLAGS += -debug "-pdb:$$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).pdb" \
 850               "-map:$$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).map"
 851           $1_DEBUGINFO_FILES := $$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).pdb \
 852               $$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).map
 853 
 854         else ifneq ($(findstring $(OPENJDK_TARGET_OS), linux solaris), )
 855           $1_DEBUGINFO_FILES := $$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).debuginfo
 856           # Setup the command line creating debuginfo files, to be run after linking.
 857           # It cannot be run separately since it updates the original target file
 858           $1_CREATE_DEBUGINFO_CMDS := \
 859               $$($1_OBJCOPY) --only-keep-debug $$($1_TARGET) $$($1_DEBUGINFO_FILES) $$(NEWLINE) \
 860               $(CD) $$($1_SYMBOLS_DIR) && \
 861                   $$($1_OBJCOPY) --add-gnu-debuglink=$$($1_DEBUGINFO_FILES) $$($1_TARGET)
 862 
 863         else ifeq ($(OPENJDK_TARGET_OS), macosx)
 864           $1_DEBUGINFO_FILES := \
 865               $$($1_SYMBOLS_DIR)/$$($1_BASENAME).dSYM/Contents/Info.plist \
 866               $$($1_SYMBOLS_DIR)/$$($1_BASENAME).dSYM/Contents/Resources/DWARF/$$($1_BASENAME)
 867           $1_CREATE_DEBUGINFO_CMDS := \
 868               $(DSYMUTIL) --out $$($1_SYMBOLS_DIR)/$$($1_BASENAME).dSYM $$($1_TARGET)
 869         endif # OPENJDK_TARGET_OS
 870 
 871         # Since the link rule creates more than one file that we want to track,
 872         # we have to use some tricks to get make to cooperate. To properly
 873         # trigger downstream dependants of $$($1_DEBUGINFO_FILES), we must have
 874         # a recipe in the rule below. To avoid rerunning the recipe every time
 875         # have it touch the target. If a debuginfo file is deleted by something
 876         # external, explicitly delete the TARGET to trigger a rebuild of both.
 877         ifneq ($$(wildcard $$($1_DEBUGINFO_FILES)), $$($1_DEBUGINFO_FILES))
 878           $$(call LogDebug, Deleting $$($1_BASENAME) because debuginfo files are missing)
 879           $$(shell $(RM) $$($1_TARGET))
 880         endif
 881         $$($1_DEBUGINFO_FILES): $$($1_TARGET)
 882                 $$(if $$(CORRECT_FUNCTION_IN_RECIPE_EVALUATION), \
 883                   $$(if $$(wildcard $$@), , $$(error $$@ was not created for $$<)) \
 884                 )
 885                 $(TOUCH) $$@
 886 
 887         $1 += $$($1_DEBUGINFO_FILES)
 888 
 889         ifeq ($$($1_ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
 890           $1_DEBUGINFO_ZIP := $$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).diz
 891           $1 += $$($1_DEBUGINFO_ZIP)
 892 
 893           # The dependency on TARGET is needed for debuginfo files
 894           # to be rebuilt properly.
 895           $$($1_DEBUGINFO_ZIP): $$($1_DEBUGINFO_FILES) $$($1_TARGET)
 896                 $(CD) $$($1_SYMBOLS_DIR) && \
 897                     $(ZIPEXE) -q -r $$@ $$(subst $$($1_SYMBOLS_DIR)/,, $$($1_DEBUGINFO_FILES))
 898 
 899         endif
 900        endif # !STATIC_LIBRARY
 901     endif # $1_DEBUG_SYMBOLS != false
 902   endif # COPY_DEBUG_SYMBOLS
 903 
 904   # Unless specifically set, stripping should only happen if symbols are also
 905   # being copied.
 906   $$(call SetIfEmpty, $1_STRIP_SYMBOLS, $$($1_COPY_DEBUG_SYMBOLS))
 907 
 908   ifneq ($$($1_STRIP_SYMBOLS), false)
 909     ifneq ($$($1_STRIP), )
 910       # Default to using the global STRIPFLAGS. Allow for overriding with an empty value
 911       $1_STRIPFLAGS ?= $(STRIPFLAGS)
 912       $1_STRIP_CMD := $$($1_STRIP) $$($1_STRIPFLAGS) $$($1_TARGET)
 913     endif
 914   endif
 915 
 916   ifeq ($$($1_TYPE), STATIC_LIBRARY)
 917     $1_VARDEPS := $$($1_AR) $$($1_ARFLAGS) $$($1_LIBS) \
 918         $$($1_EXTRA_LIBS)
 919     $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
 920         $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
 921 
 922     # Generating a static library, ie object file archive.
 923     ifeq ($(STATIC_BUILD), true)
 924       ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
 925         STATIC_MAPFILE_DEP := $$($1_MAPFILE)
 926       endif
 927     endif
 928 
 929     $1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_VARDEPS_FILE) $$(STATIC_MAPFILE_DEP)
 930 
 931     $$($1_TARGET): $$($1_TARGET_DEPS)
 932         $$(call LogInfo, Building static library $$($1_BASENAME))
 933         $$(call MakeDir, $$($1_OUTPUT_DIR) $$($1_SYMBOLS_DIR))
 934         $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
 935             $$($1_AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_ALL_OBJS) \
 936                 $$($1_RES))
 937         ifeq ($(STATIC_BUILD), true)
 938           ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
 939             $(CP) $$($1_MAPFILE) $$(@D)/$$(basename $$(@F)).symbols
 940           else
 941             $(GetSymbols)
 942           endif
 943         endif
 944   else
 945     # A shared dynamic library or an executable binary has been specified
 946     ifeq ($$($1_TYPE), LIBRARY)
 947       # Generating a dynamic library.
 948       $1_EXTRA_LDFLAGS += $$(call SET_SHARED_LIBRARY_NAME,$$($1_BASENAME))
 949 
 950       # Create loadmap on AIX. Helps in diagnosing some problems.
 951       ifneq ($(COMPILER_BINDCMD_FILE_FLAG), )
 952         $1_EXTRA_LDFLAGS += $(COMPILER_BINDCMD_FILE_FLAG)$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).loadmap
 953       endif


1016           $1_LINK_OBJS_RELATIVE := true
1017           $1_ALL_OBJS_RELATIVE := $$(patsubst $$(OUTPUTDIR)/%, %, $$($1_ALL_OBJS))
1018         endif
1019       endif
1020     endif
1021 
1022     $1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_MANIFEST) \
1023         $$($1_REAL_MAPFILE) $$($1_VARDEPS_FILE)
1024 
1025     $$($1_TARGET): $$($1_TARGET_DEPS)
1026                 ifneq ($$($1_OBJ_FILE_LIST), )
1027                   ifeq ($$($1_LINK_OBJS_RELATIVE), true)
1028                     $$(eval $$(call ListPathsSafely, $1_ALL_OBJS_RELATIVE, $$($1_OBJ_FILE_LIST)))
1029                   else
1030                     $$(eval $$(call ListPathsSafely, $1_ALL_OBJS, $$($1_OBJ_FILE_LIST)))
1031                   endif
1032                 endif
1033                 # Keep as much as possible on one execution line for best performance
1034                 # on Windows
1035                 $$(call LogInfo, Linking $$($1_BASENAME))
1036                 $$(call MakeDir, $$($1_OUTPUT_DIR) $$($1_SYMBOLS_DIR))
1037                 ifeq ($(OPENJDK_TARGET_OS), windows)
1038                   $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
1039                       $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
1040                           $(LD_OUT_OPTION)$$($1_TARGET) $$($1_LD_OBJ_ARG) $$($1_RES) $$(GLOBAL_LIBS) \
1041                           $$($1_LIBS) $$($1_EXTRA_LIBS)) \
1042                       | $(GREP) -v "^   Creating library .*\.lib and object .*\.exp" || \
1043                           test "$$$$?" = "1" ; \
1044                   $$($1_CREATE_DEBUGINFO_CMDS)
1045                   $$($1_STRIP_CMD)
1046                 else
1047                   $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
1048                       $$(if $$($1_LINK_OBJS_RELATIVE), $$(CD) $$(OUTPUTDIR) ; ) \
1049                       $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
1050                           $(LD_OUT_OPTION)$$($1_TARGET) $$($1_LD_OBJ_ARG) $$($1_RES) $$(GLOBAL_LIBS) \
1051                           $$($1_LIBS) $$($1_EXTRA_LIBS)) ; \
1052                   $$($1_CREATE_DEBUGINFO_CMDS)
1053                   $$($1_STRIP_CMD)
1054                 endif
1055                 ifeq ($(OPENJDK_TARGET_OS), windows)
1056                   ifneq ($$($1_MANIFEST), )
< prev index next >