< prev index next >

make/common/NativeCompilation.gmk

Print this page


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


 170 # This pattern is used to transform a dependency file (.d) to a list
 171 # of make targets for dependent files (.d.targets)
 172 DEPENDENCY_TARGET_SED_PATTERN := \
 173     -e 's/\#.*//' \
 174     -e 's/^[^:]*: *//' \
 175     -e 's/ *\\$$$$//' \
 176     -e 's/^[     ]*//' \
 177     -e '/^$$$$/ d' \
 178     -e 's/$$$$/ :/' \
 179     #
 180 
 181 define add_native_source
 182   # param 1 = BUILD_MYPACKAGE
 183   # parma 2 = the source file name (..../alfa.c or .../beta.cpp)
 184   # param 3 = the bin dir that stores all .o (.obj) and .d files.
 185   # param 4 = the c flags to the compiler
 186   # param 5 = the c compiler
 187   # param 6 = the c++ flags to the compiler
 188   # param 7 = the c++ compiler
 189   # param 8 = the flags to the assembler





 190 
 191   ifneq (,$$(filter %.c,$2))
 192     # Compile as a C file
 193     $1_$2_FLAGS=$(CFLAGS_CCACHE) $4 $$($1_$(notdir $2)_CFLAGS) -DTHIS_FILE='"$$(<F)"' -c
 194     $1_$2_COMP=$5
 195     $1_$2_DEP_FLAG:=$(C_FLAG_DEPS)
 196   else ifneq (,$$(filter %.m,$2))
 197     # Compile as an Objective-C file
 198     $1_$2_FLAGS=-x objective-c $(CFLAGS_CCACHE) $4 $$($1_$(notdir $2)_CFLAGS) -DTHIS_FILE='"$$(<F)"' -c
 199     $1_$2_COMP=$5
 200     $1_$2_DEP_FLAG:=$(C_FLAG_DEPS)
 201   else ifneq (,$$(filter %.s %.S,$2))
 202     # Compile as assembler file
 203     $1_$2_FLAGS=$8 -DTHIS_FILE='"$$(<F)"'
 204     $1_$2_COMP=$(AS)
 205     $1_$2_DEP_FLAG:=
 206   else ifneq (,$$(filter %.cpp,$2)$$(filter %.cc,$2)$$(filter %.mm,$2))
 207     # Compile as a C++ or Objective-C++ file
 208     $1_$2_FLAGS=$(CFLAGS_CCACHE) $6 $$($1_$(notdir $2)_CXXFLAGS) -DTHIS_FILE='"$$(<F)"' -c
 209     $1_$2_COMP=$7
 210     $1_$2_DEP_FLAG:=$(CXX_FLAG_DEPS)
 211   else
 212     $$(error Internal error in NativeCompilation.gmk: no compiler for file $2)
 213   endif
 214   # Generate the .o (.obj) file name and place it in the bin dir.
 215   $1_$2_OBJ := $3/$$(call replace_with_obj_extension, $$(notdir $2))
 216   # Only continue if this object file hasn't been processed already. This lets the first found
 217   # source file override any other with the same name.
 218   ifeq (,$$(findstring $$($1_$2_OBJ),$$($1_OBJS_SO_FAR)))
 219     $1_OBJS_SO_FAR+=$$($1_$2_OBJ)
 220     ifeq (,$$(filter %.s %.S,$2))
 221       # And this is the dependency file for this obj file.
 222       $1_$2_DEP:=$$(patsubst %$(OBJ_SUFFIX),%.d,$$($1_$2_OBJ))
 223       # The dependency target file lists all dependencies as empty targets
 224       # to avoid make error "No rule to make target" for removed files
 225       $1_$2_DEP_TARGETS:=$$(patsubst %$(OBJ_SUFFIX),%.d.targets,$$($1_$2_OBJ))
 226 
 227       # Include previously generated dependency information. (if it exists)
 228       -include $$($1_$2_DEP)


 287 # Remaining parameters are named arguments. These include:
 288 #   TOOLCHAIN Name of toolchain setup to use. Defaults to TOOLCHAIN_DEFAULT.
 289 #   SRC one or more directory roots to scan for C/C++ files.
 290 #   CFLAGS the compiler flags to be used, used both for C and C++.
 291 #   CXXFLAGS the compiler flags to be used for c++, if set overrides CFLAGS.
 292 #   LDFLAGS the linker flags to be used, used both for C and C++.
 293 #   LIBS the libraries to link to
 294 #   ARFLAGS the archiver flags to be used
 295 #   OBJECT_DIR the directory where we store the object files
 296 #   LIBRARY the resulting library file
 297 #   PROGRAM the resulting exec file
 298 #   INCLUDES only pick source from these directories
 299 #   EXCLUDES do not pick source from these directories
 300 #   INCLUDE_FILES only compile exactly these files!
 301 #   EXCLUDE_FILES with these names
 302 #   EXCLUDE_PATTERN exclude files matching any of these substrings
 303 #   EXTRA_FILES List of extra files not in any of the SRC dirs
 304 #   EXTRA_OBJECT_FILES List of extra object files to include when linking
 305 #   VERSIONINFO_RESOURCE Input file for RC. Setting this implies that RC will be run
 306 #   RC_FLAGS flags for RC.

 307 #   MAPFILE mapfile
 308 #   REORDER reorder file


 309 #   CC the compiler to use, default is $(CC)
 310 #   LD the linker to use, default is $(LD)
 311 #   OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST
 312 #   DISABLED_WARNINGS_<toolchain> Disable the given warnings for the specified toolchain
 313 #   DISABLED_WARNINGS_C_<toolchain> Disable the given warnings for the specified toolchain
 314 #       when compiling C code
 315 #   DISABLED_WARNINGS_CXX_<toolchain> Disable the given warnings for the specified
 316 #       toolchain when compiling C++ code
 317 #   STRIP_SYMBOLS Set to true to strip the final binary if the toolchain allows for it
 318 #   DEBUG_SYMBOLS Set to false to disable generation of debug symbols
 319 #   STRIPFLAGS Optionally change the flags given to the strip command
 320 SetupNativeCompilation = $(NamedParamsMacroTemplate)
 321 define SetupNativeCompilationBody
 322 
 323   # If we're doing a static build and producing a library
 324   # force it to be a static library and remove the -l libraries
 325   ifeq ($(STATIC_BUILD), true)
 326     ifneq ($$($1_LIBRARY),)
 327       $1_STATIC_LIBRARY := $$($1_LIBRARY)
 328       $1_LIBRARY :=


 626                 'due to $$(words $$(filter-out %.vardeps, $$?)) file(s)', \
 627               $$(if $$(filter %.vardeps, $$?), 'due to makefile changes')))
 628         endif
 629         $(TOUCH) $$@
 630 
 631   # On windows we need to create a resource file
 632   ifeq ($(OPENJDK_TARGET_OS), windows)
 633     ifneq (,$$($1_VERSIONINFO_RESOURCE))
 634       $1_RES:=$$($1_OBJECT_DIR)/$$($1_BASENAME).res
 635       $1_RES_DEP:=$$($1_RES).d
 636       $1_RES_DEP_TARGETS:=$$($1_RES).d.targets
 637       -include $$($1_RES_DEP)
 638       -include $$($1_RES_DEP_TARGETS)
 639 
 640       $1_RES_VARDEPS := $$($1_RC) $$($1_RC_FLAGS)
 641       $1_RES_VARDEPS_FILE := $$(call DependOnVariable, $1_RES_VARDEPS, \
 642           $$($1_RES).vardeps)
 643 
 644       $$($1_RES): $$($1_VERSIONINFO_RESOURCE) $$($1_RES_VARDEPS_FILE)
 645                 $$(call LogInfo, Compiling resource $$(notdir $$($1_VERSIONINFO_RESOURCE)) (for $$(notdir $$($1_TARGET))))

 646                 $$($1_RC) $$($1_RC_FLAGS) $$($1_SYSROOT_CFLAGS) $(CC_OUT_OPTION)$$@ \
 647                     $$($1_VERSIONINFO_RESOURCE)
 648                 # Windows RC compiler does not support -showIncludes, so we mis-use CL for this.
 649                 $$($1_CC) $$($1_RC_FLAGS) $$($1_SYSROOT_CFLAGS) -showIncludes -nologo -TC \
 650                     $(CC_OUT_OPTION)$$($1_RES_DEP).obj $$($1_VERSIONINFO_RESOURCE) > $$($1_RES_DEP).raw 2>&1 || true ; \
 651                 $(ECHO) $$($1_RES): \\ > $$($1_RES_DEP) ; \
 652                 $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_RES_DEP).raw >> $$($1_RES_DEP) ; \
 653                 $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_RES_DEP) > $$($1_RES_DEP_TARGETS)
 654     endif
 655   endif
 656 
 657   # mapfile doesnt seem to be implemented on macosx (yet??)
 658   ifneq ($(OPENJDK_TARGET_OS),macosx)
 659     ifneq ($(OPENJDK_TARGET_OS),windows)
 660       $1_REAL_MAPFILE:=$$($1_MAPFILE)
 661       ifneq (,$$($1_REORDER))
 662         $1_REAL_MAPFILE:=$$($1_OBJECT_DIR)/mapfile
 663 
 664         $$($1_REAL_MAPFILE) : $$($1_MAPFILE) $$($1_REORDER)
 665                 $$(MKDIR) -p $$(@D)
 666                 $$(CP) $$($1_MAPFILE) $$@.tmp
 667                 $$(SED) -e 's=OUTPUTDIR=$$($1_OBJECT_DIR)=' $$($1_REORDER) >> $$@.tmp
 668                 $$(MV) $$@.tmp $$@
 669       endif
 670     endif
 671   endif
 672 
 673   # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables
 674   # for LDFLAGS and LIBS
 675   $1_EXTRA_LDFLAGS:=$$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS))
 676   $1_EXTRA_LIBS:=$$($1_LIBS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LIBS_$(OPENJDK_TARGET_OS))
 677   ifneq (,$$($1_REAL_MAPFILE))
 678     $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE))
 679   endif
 680 
 681   # Need to make sure TARGET is first on list
 682   $1 := $$($1_TARGET)
 683 
 684   ifeq ($(COPY_DEBUG_SYMBOLS), true)
 685     ifneq ($$($1_DEBUG_SYMBOLS), false)
 686       # Only copy debug symbols for dynamic libraries and programs.
 687       ifeq ($$($1_STATIC_LIBRARY), )
 688         ifneq ($$($1_OUTPUT_DIR), $$($1_OBJECT_DIR))
 689           # The dependency on TARGET is needed on windows for debuginfo files
 690           # to be rebuilt properly.
 691           $$($1_OUTPUT_DIR)/% : $$($1_OBJECT_DIR)/% $$($1_TARGET)
 692                 $(CP) $$< $$@

 693         endif
 694 
 695         # Generate debuginfo files.
 696         ifeq ($(OPENJDK_TARGET_OS), windows)
 697           $1_EXTRA_LDFLAGS += "-pdb:$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).pdb" \
 698               "-map:$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).map"
 699           $1_DEBUGINFO_FILES := $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).pdb \
 700               $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).map
 701           # No separate command is needed for debuginfo on windows, instead
 702           # touch target to make sure it has a later time stamp than the debug
 703           # symbol files to avoid unnecessary relinking on rebuild.
 704           $1_CREATE_DEBUGINFO_CMDS := $(TOUCH) $$($1_TARGET)
 705 
 706         else ifneq ($(findstring $(OPENJDK_TARGET_OS), linux solaris), )
 707           $1_DEBUGINFO_FILES := $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).debuginfo
 708           # Setup the command line creating debuginfo files, to be run after linking.
 709           # It cannot be run separately since it updates the original target file
 710           $1_CREATE_DEBUGINFO_CMDS := \
 711               $(OBJCOPY) --only-keep-debug $$($1_TARGET) $$($1_DEBUGINFO_FILES) $$(NEWLINE) \
 712               $(CD) $$($1_OUTPUT_DIR) && \


 798                   $$($1_CREATE_DEBUGINFO_CMDS)
 799                   $$($1_STRIP_CMD)
 800                 else
 801                   $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
 802                       $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
 803                       $(LD_OUT_OPTION)$$@ $$($1_LD_OBJ_ARG) $$($1_RES) $$($1_LIBS) \
 804                       $$($1_EXTRA_LIBS)) ; \
 805                   $$($1_CREATE_DEBUGINFO_CMDS)
 806                   $$($1_STRIP_CMD)
 807                 endif
 808 
 809   endif
 810 
 811   ifneq (,$$($1_STATIC_LIBRARY))
 812     $1_VARDEPS := $$($1_AR) $$($1_ARFLAGS) $$($1_LIBS) \
 813         $$($1_EXTRA_LIBS)
 814     $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
 815         $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
 816 
 817     # Generating a static library, ie object file archive.
 818     $$($1_TARGET): $$($1_ALL_OBJS) $$($1_RES) $$($1_VARDEPS_FILE)






 819         $$(call LogInfo, Archiving $$($1_STATIC_LIBRARY))
 820         $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
 821             $$($1_AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_ALL_OBJS) \
 822                 $$($1_RES))
 823         ifeq ($(STATIC_BUILD), true)



 824           $(GetSymbols)
 825         endif
 826   endif

 827 
 828   ifneq (,$$($1_PROGRAM))
 829     # A executable binary has been specified, setup the target for it.
 830     $1_EXTRA_LIBS += $(GLOBAL_LIBS)
 831 
 832     $1_VARDEPS := $$($1_LD) $$($1_SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \
 833         $$($1_LIBS) $$($1_EXTRA_LIBS) $$($1_MT) \
 834         $$($1_CODESIGN) $$($1_CREATE_DEBUGINFO_CMDS) $$($1_MANIFEST_VERSION) \
 835         $$($1_STRIP_CMD)
 836     $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
 837         $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)






 838 
 839     $$($1_TARGET): $$($1_ALL_OBJS) $$($1_RES) $$($1_MANIFEST) \
 840         $$($1_VARDEPS_FILE)
 841                 $$(call LogInfo, Linking executable $$($1_BASENAME))
 842                 $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
 843                     $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
 844                         $(EXE_OUT_OPTION)$$($1_TARGET) \
 845                         $$($1_ALL_OBJS) $$($1_RES) \
 846                         $$($1_LIBS) $$($1_EXTRA_LIBS))
 847                 ifeq ($(OPENJDK_TARGET_OS), windows)
 848                   ifneq ($$($1_MANIFEST), )
 849                     $$($1_MT) -nologo -manifest $$($1_MANIFEST) -identity:"$$($1_PROGRAM).exe, version=$$($1_MANIFEST_VERSION)" -outputresource:$$@;#1
 850                   endif
 851                 endif
 852                 # This only works if the openjdk_codesign identity is present on the system. Let
 853                 # silently fail otherwise.
 854                 ifneq (,$(CODESIGN))
 855                   ifneq (,$$($1_CODESIGN))
 856                     $(CODESIGN) -s openjdk_codesign $$@
 857                   endif
   1 #
   2 # Copyright (c) 2011, 2016, 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


 170 # This pattern is used to transform a dependency file (.d) to a list
 171 # of make targets for dependent files (.d.targets)
 172 DEPENDENCY_TARGET_SED_PATTERN := \
 173     -e 's/\#.*//' \
 174     -e 's/^[^:]*: *//' \
 175     -e 's/ *\\$$$$//' \
 176     -e 's/^[     ]*//' \
 177     -e '/^$$$$/ d' \
 178     -e 's/$$$$/ :/' \
 179     #
 180 
 181 define add_native_source
 182   # param 1 = BUILD_MYPACKAGE
 183   # parma 2 = the source file name (..../alfa.c or .../beta.cpp)
 184   # param 3 = the bin dir that stores all .o (.obj) and .d files.
 185   # param 4 = the c flags to the compiler
 186   # param 5 = the c compiler
 187   # param 6 = the c++ flags to the compiler
 188   # param 7 = the c++ compiler
 189   # param 8 = the flags to the assembler
 190   # param 9 = set to disable THIS_FILE
 191 
 192   ifeq ($9, )
 193     $1_$2_THIS_FILE = -DTHIS_FILE='"$$(<F)"'
 194   endif
 195 
 196   ifneq (,$$(filter %.c,$2))
 197     # Compile as a C file
 198     $1_$2_FLAGS=$(CFLAGS_CCACHE) $4 $$($1_$(notdir $2)_CFLAGS) $$($1_$2_THIS_FILE) -c
 199     $1_$2_COMP=$5
 200     $1_$2_DEP_FLAG:=$(C_FLAG_DEPS)
 201   else ifneq (,$$(filter %.m,$2))
 202     # Compile as an Objective-C file
 203     $1_$2_FLAGS=-x objective-c $(CFLAGS_CCACHE) $4 $$($1_$(notdir $2)_CFLAGS) $$($1_$2_THIS_FILE) -c
 204     $1_$2_COMP=$5
 205     $1_$2_DEP_FLAG:=$(C_FLAG_DEPS)
 206   else ifneq (,$$(filter %.s %.S,$2))
 207     # Compile as assembler file
 208     $1_$2_FLAGS=$8
 209     $1_$2_COMP=$(AS)
 210     $1_$2_DEP_FLAG:=
 211   else ifneq (,$$(filter %.cpp,$2)$$(filter %.cc,$2)$$(filter %.mm,$2))
 212     # Compile as a C++ or Objective-C++ file
 213     $1_$2_FLAGS=$(CFLAGS_CCACHE) $6 $$($1_$(notdir $2)_CXXFLAGS) $$($1_$2_THIS_FILE) -c
 214     $1_$2_COMP=$7
 215     $1_$2_DEP_FLAG:=$(CXX_FLAG_DEPS)
 216   else
 217     $$(error Internal error in NativeCompilation.gmk: no compiler for file $2)
 218   endif
 219   # Generate the .o (.obj) file name and place it in the bin dir.
 220   $1_$2_OBJ := $3/$$(call replace_with_obj_extension, $$(notdir $2))
 221   # Only continue if this object file hasn't been processed already. This lets the first found
 222   # source file override any other with the same name.
 223   ifeq (,$$(findstring $$($1_$2_OBJ),$$($1_OBJS_SO_FAR)))
 224     $1_OBJS_SO_FAR+=$$($1_$2_OBJ)
 225     ifeq (,$$(filter %.s %.S,$2))
 226       # And this is the dependency file for this obj file.
 227       $1_$2_DEP:=$$(patsubst %$(OBJ_SUFFIX),%.d,$$($1_$2_OBJ))
 228       # The dependency target file lists all dependencies as empty targets
 229       # to avoid make error "No rule to make target" for removed files
 230       $1_$2_DEP_TARGETS:=$$(patsubst %$(OBJ_SUFFIX),%.d.targets,$$($1_$2_OBJ))
 231 
 232       # Include previously generated dependency information. (if it exists)
 233       -include $$($1_$2_DEP)


 292 # Remaining parameters are named arguments. These include:
 293 #   TOOLCHAIN Name of toolchain setup to use. Defaults to TOOLCHAIN_DEFAULT.
 294 #   SRC one or more directory roots to scan for C/C++ files.
 295 #   CFLAGS the compiler flags to be used, used both for C and C++.
 296 #   CXXFLAGS the compiler flags to be used for c++, if set overrides CFLAGS.
 297 #   LDFLAGS the linker flags to be used, used both for C and C++.
 298 #   LIBS the libraries to link to
 299 #   ARFLAGS the archiver flags to be used
 300 #   OBJECT_DIR the directory where we store the object files
 301 #   LIBRARY the resulting library file
 302 #   PROGRAM the resulting exec file
 303 #   INCLUDES only pick source from these directories
 304 #   EXCLUDES do not pick source from these directories
 305 #   INCLUDE_FILES only compile exactly these files!
 306 #   EXCLUDE_FILES with these names
 307 #   EXCLUDE_PATTERN exclude files matching any of these substrings
 308 #   EXTRA_FILES List of extra files not in any of the SRC dirs
 309 #   EXTRA_OBJECT_FILES List of extra object files to include when linking
 310 #   VERSIONINFO_RESOURCE Input file for RC. Setting this implies that RC will be run
 311 #   RC_FLAGS flags for RC.
 312 #   EMBED_MANIFEST if true, embed manifest on Windows.
 313 #   MAPFILE mapfile
 314 #   REORDER reorder file
 315 #   USE_MAPFILE_FOR_SYMBOLS if true and this is a STATIC_BUILD, just copy the
 316 #       mapfile for the output symbols file
 317 #   CC the compiler to use, default is $(CC)
 318 #   LD the linker to use, default is $(LD)
 319 #   OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST
 320 #   DISABLED_WARNINGS_<toolchain> Disable the given warnings for the specified toolchain
 321 #   DISABLED_WARNINGS_C_<toolchain> Disable the given warnings for the specified toolchain
 322 #       when compiling C code
 323 #   DISABLED_WARNINGS_CXX_<toolchain> Disable the given warnings for the specified
 324 #       toolchain when compiling C++ code
 325 #   STRIP_SYMBOLS Set to true to strip the final binary if the toolchain allows for it
 326 #   DEBUG_SYMBOLS Set to false to disable generation of debug symbols
 327 #   STRIPFLAGS Optionally change the flags given to the strip command
 328 SetupNativeCompilation = $(NamedParamsMacroTemplate)
 329 define SetupNativeCompilationBody
 330 
 331   # If we're doing a static build and producing a library
 332   # force it to be a static library and remove the -l libraries
 333   ifeq ($(STATIC_BUILD), true)
 334     ifneq ($$($1_LIBRARY),)
 335       $1_STATIC_LIBRARY := $$($1_LIBRARY)
 336       $1_LIBRARY :=


 634                 'due to $$(words $$(filter-out %.vardeps, $$?)) file(s)', \
 635               $$(if $$(filter %.vardeps, $$?), 'due to makefile changes')))
 636         endif
 637         $(TOUCH) $$@
 638 
 639   # On windows we need to create a resource file
 640   ifeq ($(OPENJDK_TARGET_OS), windows)
 641     ifneq (,$$($1_VERSIONINFO_RESOURCE))
 642       $1_RES:=$$($1_OBJECT_DIR)/$$($1_BASENAME).res
 643       $1_RES_DEP:=$$($1_RES).d
 644       $1_RES_DEP_TARGETS:=$$($1_RES).d.targets
 645       -include $$($1_RES_DEP)
 646       -include $$($1_RES_DEP_TARGETS)
 647 
 648       $1_RES_VARDEPS := $$($1_RC) $$($1_RC_FLAGS)
 649       $1_RES_VARDEPS_FILE := $$(call DependOnVariable, $1_RES_VARDEPS, \
 650           $$($1_RES).vardeps)
 651 
 652       $$($1_RES): $$($1_VERSIONINFO_RESOURCE) $$($1_RES_VARDEPS_FILE)
 653                 $$(call LogInfo, Compiling resource $$(notdir $$($1_VERSIONINFO_RESOURCE)) (for $$(notdir $$($1_TARGET))))
 654                 $$(call ExecuteWithLog, $$@, \
 655                     $$($1_RC) $$($1_RC_FLAGS) $$($1_SYSROOT_CFLAGS) $(CC_OUT_OPTION)$$@ \
 656                     $$($1_VERSIONINFO_RESOURCE))
 657                 # Windows RC compiler does not support -showIncludes, so we mis-use CL for this.
 658                 $$($1_CC) $$($1_RC_FLAGS) $$($1_SYSROOT_CFLAGS) -showIncludes -nologo -TC \
 659                     $(CC_OUT_OPTION)$$($1_RES_DEP).obj $$($1_VERSIONINFO_RESOURCE) > $$($1_RES_DEP).raw 2>&1 || true ; \
 660                 $(ECHO) $$($1_RES): \\ > $$($1_RES_DEP) ; \
 661                 $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_RES_DEP).raw >> $$($1_RES_DEP) ; \
 662                 $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_RES_DEP) > $$($1_RES_DEP_TARGETS)
 663     endif
 664   endif
 665 
 666   ifneq ($(DISABLE_MAPFILES),true)
 667     $1_REAL_MAPFILE := $$($1_MAPFILE)
 668     ifneq ($(OPENJDK_TARGET_OS),windows)

 669       ifneq (,$$($1_REORDER))
 670         $1_REAL_MAPFILE := $$($1_OBJECT_DIR)/mapfile
 671 
 672         $$($1_REAL_MAPFILE) : $$($1_MAPFILE) $$($1_REORDER)
 673                 $$(MKDIR) -p $$(@D)
 674                 $$(CP) $$($1_MAPFILE) $$@.tmp
 675                 $$(SED) -e 's=OUTPUTDIR=$$($1_OBJECT_DIR)=' $$($1_REORDER) >> $$@.tmp
 676                 $$(MV) $$@.tmp $$@
 677       endif
 678     endif
 679   endif
 680 
 681   # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables
 682   # for LDFLAGS and LIBS
 683   $1_EXTRA_LDFLAGS:=$$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS))
 684   $1_EXTRA_LIBS:=$$($1_LIBS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LIBS_$(OPENJDK_TARGET_OS))
 685   ifneq (,$$($1_REAL_MAPFILE))
 686     $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE))
 687   endif
 688 
 689   # Need to make sure TARGET is first on list
 690   $1 := $$($1_TARGET)
 691 
 692   ifeq ($(COPY_DEBUG_SYMBOLS), true)
 693     ifneq ($$($1_DEBUG_SYMBOLS), false)
 694       # Only copy debug symbols for dynamic libraries and programs.
 695       ifeq ($$($1_STATIC_LIBRARY), )
 696         ifneq ($$($1_OUTPUT_DIR), $$($1_OBJECT_DIR))
 697           # The dependency on TARGET is needed on windows for debuginfo files
 698           # to be rebuilt properly.
 699           $$($1_OUTPUT_DIR)/% : $$($1_OBJECT_DIR)/% $$($1_TARGET)
 700                 # Use cp -r since on macosx, the dSYM is a directory
 701                 $(CP) -r $$< $$@
 702         endif
 703 
 704         # Generate debuginfo files.
 705         ifeq ($(OPENJDK_TARGET_OS), windows)
 706           $1_EXTRA_LDFLAGS += "-pdb:$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).pdb" \
 707               "-map:$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).map"
 708           $1_DEBUGINFO_FILES := $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).pdb \
 709               $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).map
 710           # No separate command is needed for debuginfo on windows, instead
 711           # touch target to make sure it has a later time stamp than the debug
 712           # symbol files to avoid unnecessary relinking on rebuild.
 713           $1_CREATE_DEBUGINFO_CMDS := $(TOUCH) $$($1_TARGET)
 714 
 715         else ifneq ($(findstring $(OPENJDK_TARGET_OS), linux solaris), )
 716           $1_DEBUGINFO_FILES := $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).debuginfo
 717           # Setup the command line creating debuginfo files, to be run after linking.
 718           # It cannot be run separately since it updates the original target file
 719           $1_CREATE_DEBUGINFO_CMDS := \
 720               $(OBJCOPY) --only-keep-debug $$($1_TARGET) $$($1_DEBUGINFO_FILES) $$(NEWLINE) \
 721               $(CD) $$($1_OUTPUT_DIR) && \


 807                   $$($1_CREATE_DEBUGINFO_CMDS)
 808                   $$($1_STRIP_CMD)
 809                 else
 810                   $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
 811                       $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
 812                       $(LD_OUT_OPTION)$$@ $$($1_LD_OBJ_ARG) $$($1_RES) $$($1_LIBS) \
 813                       $$($1_EXTRA_LIBS)) ; \
 814                   $$($1_CREATE_DEBUGINFO_CMDS)
 815                   $$($1_STRIP_CMD)
 816                 endif
 817 
 818   endif
 819 
 820   ifneq (,$$($1_STATIC_LIBRARY))
 821     $1_VARDEPS := $$($1_AR) $$($1_ARFLAGS) $$($1_LIBS) \
 822         $$($1_EXTRA_LIBS)
 823     $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
 824         $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
 825 
 826     # Generating a static library, ie object file archive.
 827     ifeq ($(STATIC_BUILD), true)
 828       ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
 829         STATIC_MAPFILE_DEP := $$($1_MAPFILE)
 830       endif
 831     endif
 832 
 833     $$($1_TARGET): $$($1_ALL_OBJS) $$($1_RES) $$($1_VARDEPS_FILE) $$(STATIC_MAPFILE_DEP)
 834         $$(call LogInfo, Archiving $$($1_STATIC_LIBRARY))
 835         $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
 836             $$($1_AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_ALL_OBJS) \
 837                 $$($1_RES))
 838         ifeq ($(STATIC_BUILD), true)
 839           ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
 840             $(CP) $$($1_MAPFILE) $$(@D)/$$(basename $$(@F)).symbols
 841           else
 842             $(GetSymbols)
 843           endif
 844         endif
 845   endif
 846 
 847   ifneq (,$$($1_PROGRAM))
 848     # A executable binary has been specified, setup the target for it.
 849     $1_EXTRA_LIBS += $(GLOBAL_LIBS)
 850 
 851     $1_VARDEPS := $$($1_LD) $$($1_SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \
 852         $$($1_LIBS) $$($1_EXTRA_LIBS) $$($1_MT) \
 853         $$($1_CODESIGN) $$($1_CREATE_DEBUGINFO_CMDS) $$($1_MANIFEST_VERSION) \
 854         $$($1_STRIP_CMD)
 855     $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
 856         $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
 857 
 858     ifeq ($(OPENJDK_TARGET_OS), windows)
 859       ifeq ($$($1_EMBED_MANIFEST), true)
 860         $1_EXTRA_LDFLAGS += -manifest:embed
 861       endif
 862     endif
 863 
 864     $$($1_TARGET): $$($1_ALL_OBJS) $$($1_RES) $$($1_MANIFEST) \
 865         $$($1_VARDEPS_FILE)
 866                 $$(call LogInfo, Linking executable $$($1_BASENAME))
 867                 $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
 868                     $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
 869                         $(EXE_OUT_OPTION)$$($1_TARGET) \
 870                         $$($1_ALL_OBJS) $$($1_RES) \
 871                         $$($1_LIBS) $$($1_EXTRA_LIBS))
 872                 ifeq ($(OPENJDK_TARGET_OS), windows)
 873                   ifneq ($$($1_MANIFEST), )
 874                     $$($1_MT) -nologo -manifest $$($1_MANIFEST) -identity:"$$($1_PROGRAM).exe, version=$$($1_MANIFEST_VERSION)" -outputresource:$$@;#1
 875                   endif
 876                 endif
 877                 # This only works if the openjdk_codesign identity is present on the system. Let
 878                 # silently fail otherwise.
 879                 ifneq (,$(CODESIGN))
 880                   ifneq (,$$($1_CODESIGN))
 881                     $(CODESIGN) -s openjdk_codesign $$@
 882                   endif
< prev index next >