make/common/NativeCompilation.gmk
changeset 27560 adc258b13e2c
parent 25882 bd4315f0084b
child 27602 236555ddac42
--- a/make/common/NativeCompilation.gmk	Tue Nov 18 15:25:13 2014 -0800
+++ b/make/common/NativeCompilation.gmk	Wed Dec 03 14:20:21 2014 +0000
@@ -450,13 +450,11 @@
             $1_DEBUGINFO_FILES := $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).pdb \
                 $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).map
 
-            # This dependency dance ensures that windows debug info files get rebuilt
-            # properly if deleted.
-            $$($1_TARGET): $$($1_DEBUGINFO_FILES)
-            $$($1_DEBUGINFO_FILES): $$($1_EXPECTED_OBJS)
-
           else ifeq ($(OPENJDK_TARGET_OS), solaris)
             $1_DEBUGINFO_FILES := $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).debuginfo
+            # Setup the command line creating debuginfo files, to be run after linking.
+            # It cannot be run separately since it updates the original target file
+            #
             # 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.
@@ -466,29 +464,34 @@
             #
             # $(OBJCOPY) --add-gnu-debuglink=... corrupts SUNW_* sections.
             # Use $(ADD_GNU_DEBUGLINK) until a fixed $(OBJCOPY) is available.
-            $$($1_DEBUGINFO_FILES): $$($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) $$<
-			$(TOUCH) $$@
+            $1_CREATE_DEBUGINFO_CMDS := \
+                $(FIX_EMPTY_SEC_HDR_FLAGS) $(LOG_INFO) $$($1_TARGET) $$(NEWLINE) \
+                $(OBJCOPY) --only-keep-debug $$($1_TARGET) $$($1_DEBUGINFO_FILES) $$(NEWLINE) \
+                $(CD) $$($1_OUTPUT_DIR) && \
+                    $(ADD_GNU_DEBUGLINK) $(LOG_INFO) $$($1_DEBUGINFO_FILES) $$($1_TARGET)
+            $1_DEBUGINFO_EXTRA_DEPS := $(FIX_EMPTY_SEC_HDR_FLAGS) $(ADD_GNU_DEBUGLINK)
 
           else ifeq ($(OPENJDK_TARGET_OS), linux)
             $1_DEBUGINFO_FILES := $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).debuginfo
-            $$($1_DEBUGINFO_FILES): $$($1_TARGET)
-			$(RM) $$@
-			$(OBJCOPY) --only-keep-debug $$< $$@
-			$(CD) $$(@D) && $(OBJCOPY) --add-gnu-debuglink=$$(@F) $$<
-			$(TOUCH) $$@
+            # Setup the command line creating debuginfo files, to be run after linking.
+            # It cannot be run separately since it updates the original target file
+            $1_CREATE_DEBUGINFO_CMDS := \
+                $(OBJCOPY) --only-keep-debug $$($1_TARGET) $$($1_DEBUGINFO_FILES) $$(NEWLINE) \
+                $(CD) $$($1_OUTPUT_DIR) && \
+                    $(OBJCOPY) --add-gnu-debuglink=$$($1_DEBUGINFO_FILES) $$($1_TARGET)
 
           endif # No MacOS X support
 
+          # This dependency dance ensures that debug info files get rebuilt
+          # properly if deleted.
+          $$($1_TARGET): $$($1_DEBUGINFO_FILES)
+          $$($1_DEBUGINFO_FILES): $$($1_EXPECTED_OBJS)
+
           ifeq ($(ZIP_DEBUGINFO_FILES), true)
             $1_DEBUGINFO_ZIP := $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).diz
             $1 += $$(subst $$($1_OBJECT_DIR),$$($1_OUTPUT_DIR),$$($1_DEBUGINFO_ZIP))
 
-            # The dependency on TARGET is needed on windows for debuginfo files
+            # The dependency on TARGET is needed for debuginfo files
             # to be rebuilt properly.
             $$($1_DEBUGINFO_ZIP): $$($1_DEBUGINFO_FILES) $$($1_TARGET)
 		$(CD) $$($1_OBJECT_DIR) \
@@ -504,29 +507,31 @@
 
   ifneq (,$$($1_LIBRARY))
     # Generating a dynamic library.
-    $1_EXTRA_LDFLAGS+=$$(call SET_SHARED_LIBRARY_NAME,$$($1_BASENAME))
+    $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"
+      $1_EXTRA_LDFLAGS += "-implib:$$($1_OBJECT_DIR)/$$($1_LIBRARY).lib"
     endif
 
     $1_EXTRA_LDFLAGS_SUFFIX += $(GLOBAL_LDFLAGS_SUFFIX)
 
-    $$($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)
-        # Touch target to make sure it has a later time stamp than the debug
-        # symbol files to avoid unnecessary relinking on rebuild.
-        ifeq ($(OPENJDK_TARGET_OS), windows)
-	  $(TOUCH) $$@
-        endif
+    $$($1_TARGET): $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_REAL_MAPFILE) \
+        $$($1_DEBUGINFO_EXTRA_DEPS)
+		$$(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)
+		$$($1_CREATE_DEBUGINFO_CMDS)
+                # Touch target to make sure it has a later time stamp than the debug
+                # symbol files to avoid unnecessary relinking on rebuild.
+                ifeq ($(OPENJDK_TARGET_OS), windows)
+		  $(TOUCH) $$@
+                endif
 
   endif
 
   ifneq (,$$($1_STATIC_LIBRARY))
     # Generating a static library, ie object file archive.
-    $$($1_TARGET) : $$($1_EXPECTED_OBJS) $$($1_RES)
+    $$($1_TARGET): $$($1_EXPECTED_OBJS) $$($1_RES)
 	$$(call ARCHIVING_MSG,$$($1_LIBRARY))
 	$(AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_EXPECTED_OBJS) \
 	    $$($1_RES) $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX)
@@ -536,26 +541,28 @@
     # A executable binary has been specified, setup the target for it.
     $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
-        # This only works if the openjdk_codesign identity is present on the system. Let
-        # silently fail otherwise.
-        ifneq (,$(CODESIGN))
-          ifneq (,$$($1_CODESIGN))
-	    $(CODESIGN) -s openjdk_codesign $$@
-          endif
-        endif
-        # Touch target to make sure it has a later time stamp than the debug
-        # symbol files to avoid unnecessary relinking on rebuild.
-        ifeq ($(OPENJDK_TARGET_OS), windows)
-	  $(TOUCH) $$@
-        endif
+    $$($1_TARGET): $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_GEN_MANIFEST) \
+        $$($1_DEBUGINFO_EXTRA_DEPS)
+		$$(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
+                # This only works if the openjdk_codesign identity is present on the system. Let
+                # silently fail otherwise.
+                ifneq (,$(CODESIGN))
+                  ifneq (,$$($1_CODESIGN))
+		    $(CODESIGN) -s openjdk_codesign $$@
+                  endif
+                endif
+		$$($1_CREATE_DEBUGINFO_CMDS)
+                # Touch target to make sure it has a later time stamp than the debug
+                # symbol files to avoid unnecessary relinking on rebuild.
+                ifeq ($(OPENJDK_TARGET_OS), windows)
+		  $(TOUCH) $$@
+                endif
 
   endif
 endef