# # Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License version 2 only, as # published by the Free Software Foundation. Oracle designates this # particular file as subject to the "Classpath" exception as provided # by Oracle in the LICENSE file that accompanied this code. # # This code is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # version 2 for more details (a copy is included in the LICENSE file that # accompanied this code). # # You should have received a copy of the GNU General Public License version # 2 along with this work; if not, write to the Free Software Foundation, # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. # # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA # or visit www.oracle.com if you need additional information or have any # questions. # # When you read this source. Remember that $(sort ...) has the side effect # of removing duplicates. It is actually this side effect that is # desired whenever sort is used below! ifeq (,$(_MAKEBASE_GMK)) $(error You must include MakeBase.gmk prior to including NativeCompilation.gmk) endif ifeq ($(COMPILER_TYPE),CC) COMPILING_MSG=echo $(LOG_INFO) "Compiling $(notdir $1) (for $(notdir $2))" LINKING_MSG=echo $(LOG_INFO) "Linking $1" LINKING_EXE_MSG=echo $(LOG_INFO) "Linking executable $1" ARCHIVING_MSG=echo $(LOG_INFO) "Archiving $1" else COMPILING_MSG= LINKING_MSG= LINKING_EXE_MSG= ARCHIVING_MSG= endif define add_native_source # param 1 = BUILD_MYPACKAGE # parma 2 = the source file name (..../alfa.c or .../beta.cpp) # param 3 = the bin dir that stores all .o (.obj) and .d files. # param 4 = the c flags to the compiler # param 5 = the c compiler # param 6 = the c++ flags to the compiler # param 7 = the c++ compiler # param 8 = the flags to the assembler ifneq (,$$(filter %.c,$2)) # Compile as a C file $1_$2_FLAGS=$4 $$($1_$(notdir $2)_CFLAGS) -DTHIS_FILE='"$$( $$@ endif endif # mapfile doesnt seem to be implemented on macosx (yet??) ifneq ($(OPENJDK_TARGET_OS),macosx) ifneq ($(OPENJDK_TARGET_OS),windows) $1_REAL_MAPFILE:=$$($1_MAPFILE) ifneq (,$$($1_REORDER)) $1_REAL_MAPFILE:=$$($1_OBJECT_DIR)/mapfile $$($1_REAL_MAPFILE) : $$($1_MAPFILE) $$($1_REORDER) $$(MKDIR) -p $$(@D) $$(CP) $$($1_MAPFILE) $$@.tmp $$(SED) -e 's=OUTPUTDIR=$$($1_OBJECT_DIR)=' $$($1_REORDER) >> $$@.tmp $$(MV) $$@.tmp $$@ endif endif endif # Pickup extra OPENJDK_TARGET_OS_API and/or OPENJDK_TARGET_OS dependent variables # for LDFLAGS and LDFLAGS_SUFFIX $1_EXTRA_LDFLAGS:=$$($1_LDFLAGS_$(OPENJDK_TARGET_OS_API)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS)) $1_EXTRA_LDFLAGS_SUFFIX:=$$($1_LDFLAGS_SUFFIX_$(OPENJDK_TARGET_OS_API)) $$($1_LDFLAGS_SUFFIX_$(OPENJDK_TARGET_OS)) ifneq (,$$($1_REAL_MAPFILE)) $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE)) endif $1 := $$($1_TARGET) ifneq (,$$($1_LIBRARY)) # Generating a dynamic library. $1_EXTRA_LDFLAGS+=$$(call SET_SHARED_LIBRARY_NAME,$$($1_BASENAME)) ifeq ($(OPENJDK_TARGET_OS), windows) $1_EXTRA_LDFLAGS+="-implib:$$($1_OBJECT_DIR)/$$($1_LIBRARY).lib" endif $1_EXTRA_LDFLAGS_SUFFIX += $(GLOBAL_LDFLAGS_SUFFIX) ifneq (,$$($1_DEBUG_SYMBOLS)) ifeq ($(ENABLE_DEBUG_SYMBOLS), true) ifeq ($(OPENJDK_TARGET_OS), windows) $1_EXTRA_LDFLAGS+="-pdb:$$($1_OBJECT_DIR)/$$($1_LIBRARY).pdb" \ "-map:$$($1_OBJECT_DIR)/$$($1_LIBRARY).map" endif ifneq ($$($1_OUTPUT_DIR),$$($1_OBJECT_DIR)) $$($1_OUTPUT_DIR)/% : $$($1_OBJECT_DIR)/% $(CP) $$< $$@ endif ifeq ($(OPENJDK_TARGET_OS), solaris) # gobjcopy crashes on "empty" section headers with the SHF_ALLOC flag set. # Use $(FIX_EMPTY_SEC_HDR_FLAGS) to clear the SHF_ALLOC flag (if set) from # empty section headers until a fixed $(OBJCOPY) is available. # An empty section header has sh_addr == 0 and sh_size == 0. # This problem has only been seen on Solaris X64, but we call this tool # on all Solaris builds just in case. # # $(OBJCOPY) --add-gnu-debuglink=... corrupts SUNW_* sections. # Use $(ADD_GNU_DEBUGLINK) until a fixed $(OBJCOPY) is available. $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo : $$($1_TARGET) \ $(FIX_EMPTY_SEC_HDR_FLAGS) $(ADD_GNU_DEBUGLINK) $(RM) $$@ $(FIX_EMPTY_SEC_HDR_FLAGS) $(LOG_INFO) $$< $(OBJCOPY) --only-keep-debug $$< $$@ $(CD) $$(@D) && $(ADD_GNU_DEBUGLINK) $(LOG_INFO) $$(@F) $$< else # not solaris $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo : $$($1_TARGET) $(RM) $$@ $(OBJCOPY) --only-keep-debug $$< $$@ $(CD) $$(@D) && $(OBJCOPY) --add-gnu-debuglink=$$(@F) $$< endif # Touch to not retrigger rule on rebuild $(TOUCH) $$@ ifeq ($(ZIP_DEBUGINFO_FILES), true) $1 += $$($1_OUTPUT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).diz ifeq ($(OPENJDK_TARGET_OS), windows) $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).diz : $$($1_TARGET) $(CD) $$($1_OBJECT_DIR) \ && $(ZIP) -q $$@ $$($1_LIBRARY).map $$($1_LIBRARY).pdb else $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).diz : $$($1_TARGET) \ $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo $(CD) $$($1_OBJECT_DIR) \ && $(ZIP) -q $$@ $$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo endif else ifeq ($(OPENJDK_TARGET_OS), windows) $1 += $$($1_OUTPUT_DIR)/$$($1_LIBRARY).map \ $$($1_OUTPUT_DIR)/$$($1_LIBRARY).pdb else $1 += $$($1_OUTPUT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo endif endif endif endif $$($1_TARGET) : $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_REAL_MAPFILE) $$(call LINKING_MSG,$$($1_BASENAME)) $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $(LD_OUT_OPTION)$$@ \ $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_LDFLAGS_SUFFIX) \ $$($1_EXTRA_LDFLAGS_SUFFIX) endif ifneq (,$$($1_STATIC_LIBRARY)) # Generating a static library, ie object file archive. $$($1_TARGET) : $$($1_EXPECTED_OBJS) $$($1_RES) $$(call ARCHIVING_MSG,$$($1_LIBRARY)) $(AR) $$($1_AR_FLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_EXPECTED_OBJS) \ $$($1_RES) $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX) endif ifneq (,$$($1_PROGRAM)) # A executable binary has been specified, setup the target for it. ifneq (,$$($1_DEBUG_SYMBOLS)) ifeq ($(ENABLE_DEBUG_SYMBOLS), true) ifeq ($(OPENJDK_TARGET_OS), windows) $1_EXTRA_LDFLAGS+="-pdb:$$($1_OBJECT_DIR)/$$($1_PROGRAM).pdb" \ "-map:$$($1_OBJECT_DIR)/$$($1_PROGRAM).map" endif ifneq ($$($1_OUTPUT_DIR),$$($1_OBJECT_DIR)) $$($1_OUTPUT_DIR)/% : $$($1_OBJECT_DIR)/% $(CP) $$< $$@ endif ifeq ($(OPENJDK_TARGET_OS), solaris) # gobjcopy crashes on "empty" section headers with the SHF_ALLOC flag set. # Use $(FIX_EMPTY_SEC_HDR_FLAGS) to clear the SHF_ALLOC flag (if set) from # empty section headers until a fixed $(OBJCOPY) is available. # An empty section header has sh_addr == 0 and sh_size == 0. # This problem has only been seen on Solaris X64, but we call this tool # on all Solaris builds just in case. # # $(OBJCOPY) --add-gnu-debuglink=... corrupts SUNW_* sections. # Use $(ADD_GNU_DEBUGLINK) until a fixed $(OBJCOPY) is available. $$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo : $$($1_TARGET) \ $(FIX_EMPTY_SEC_HDR_FLAGS) $(ADD_GNU_DEBUGLINK) $(RM) $$@ $(FIX_EMPTY_SEC_HDR_FLAGS) $(LOG_INFO) $$< $(OBJCOPY) --only-keep-debug $$< $$@ $(CD) $$(@D) && $(ADD_GNU_DEBUGLINK) $(LOG_INFO) $$(@F) $$< else # not solaris $$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo : $$($1_TARGET) $(RM) $$@ $(OBJCOPY) --only-keep-debug $$< $$@ $(CD) $$(@D) && $(OBJCOPY) --add-gnu-debuglink=$$(@F) $$< endif $(TOUCH) $$@ ifeq ($(ZIP_DEBUGINFO_FILES), true) $1 += $$($1_OUTPUT_DIR)/$$($1_PROGRAM).diz ifeq ($(OPENJDK_TARGET_OS), windows) $$($1_OBJECT_DIR)/$$($1_PROGRAM).diz : $$($1_TARGET) $(CD) $$($1_OBJECT_DIR) \ && $(ZIP) -q $$@ $$($1_PROGRAM).map $$($1_PROGRAM).pdb else $$($1_OBJECT_DIR)/$$(PROGRAM_PREFIX)$$($1_PROGRAM).diz : $$($1_TARGET) \ $$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo $(CD) $$($1_OBJECT_DIR) \ && $(ZIP) -q $$@ $$($1_PROGRAM).debuginfo endif else ifeq ($(OPENJDK_TARGET_OS), windows) $1 += $$($1_OUTPUT_DIR)/$$($1_PROGRAM).map \ $$($1_OUTPUT_DIR)/$$($1_PROGRAM).pdb else $1 += $$($1_OUTPUT_DIR)/$$($1_PROGRAM).debuginfo endif endif endif endif $1_EXTRA_LDFLAGS_SUFFIX += $(GLOBAL_LDFLAGS_SUFFIX) $$($1_TARGET) : $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_GEN_MANIFEST) $$(call LINKING_EXE_MSG,$$($1_BASENAME)) $$($1_LDEXE) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $(EXE_OUT_OPTION)$$($1_TARGET) \ $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_LDFLAGS_SUFFIX) \ $$($1_EXTRA_LDFLAGS_SUFFIX) ifneq (,$$($1_GEN_MANIFEST)) $(MT) -nologo -manifest $$($1_GEN_MANIFEST) -outputresource:$$@;#1 endif endif endef