make/StripBinaries.gmk
author goetz
Thu, 07 Jul 2016 16:21:45 +0200
changeset 40128 e635645d2a8a
parent 36506 17612cee3530
permissions -rw-r--r--
8160974: [TESTBUG] Mark more headful tests with @key headful. Reviewed-by: serb, simonis

#
# Copyright (c) 2014, 2016, 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.
#

default: all

include $(SPEC)
include MakeBase.gmk

# Hook to include the corresponding custom file, if present.
$(eval $(call IncludeCustomExtension, , StripBinaries.gmk))

################################################################################
# Copy native libraries and executables to a secondary location to strip them
# and filter out files that shouldn't go into the image.

MODULES_CMDS_STRIPPED := $(SUPPORT_OUTPUTDIR)/modules_cmds-stripped
MODULES_LIBS_STRIPPED := $(SUPPORT_OUTPUTDIR)/modules_libs-stripped

ifneq ($(STRIP), )
  define StripRecipe
	$(call LogInfo, Stripping $(patsubst $(OUTPUT_ROOT)/%,%,$<))
	$(call MakeDir, $(@D))
	$(CP) $< $@.tmp
	$(CHMOD) u+w $@.tmp
	$(STRIP) $(STRIPFLAGS) $@.tmp
	$(CHMOD) go-w $@.tmp
	$(MV) $@.tmp $@
  endef
else
  define StripRecipe
    $(call install-file)
  endef
endif

NO_STRIP_CMDS_FILTER += %.cgi

# Don't include debug info for executables.
ifneq ($(wildcard $(SUPPORT_OUTPUTDIR)/modules_cmds/$(MODULE)), )
  # OS X stores symbol information in a .dylib file inside a .dSYM directory -
  # that file should not be stripped, so we prune the tree at the .dSYM directory.
  ALL_CMDS_SRC := $(filter-out %.bc %.debuginfo %.diz %.map %.pdb, \
      $(shell $(FIND) $(SUPPORT_OUTPUTDIR)/modules_cmds/$(MODULE) \( -type f -o -type l \) \
      -print -o -name "*.dSYM" -prune))
  COPY_CMDS_SRC := $(filter $(NO_STRIP_CMDS_FILTER), $(ALL_CMDS_SRC))
  STRIP_CMDS_SRC := $(filter-out $(NO_STRIP_CMDS_FILTER), $(ALL_CMDS_SRC))
endif

ifneq ($(wildcard $(SUPPORT_OUTPUTDIR)/modules_libs/$(MODULE)), )
  # OS X stores symbol information in a .dylib file inside a .dSYM directory -
  # that file should not be stripped, so we prune the tree at the .dSYM directory.
  # Example: support/modules_libs/java.base/libjsig.dylib.dSYM/Contents/Resources/DWARF/libjsig.dylib
  STRIP_LIBS_SRC := \
      $(shell $(FIND) $(SUPPORT_OUTPUTDIR)/modules_libs/$(MODULE) \
        -name '*$(SHARED_LIBRARY_SUFFIX)' -type f -print -o -name "*.dSYM" -prune)

  # Make sure symbolic links are copied and not stripped.
  COPY_LIBS_SRC := \
      $(filter-out $(STRIP_LIBS_SRC), \
      $(shell $(FIND) $(SUPPORT_OUTPUTDIR)/modules_libs/$(MODULE) -type f -o -type l))
endif

$(eval $(call SetupCopyFiles,STRIP_MODULES_CMDS, \
    SRC := $(SUPPORT_OUTPUTDIR)/modules_cmds, \
    DEST := $(MODULES_CMDS_STRIPPED), \
    FILES := $(STRIP_CMDS_SRC), \
    MACRO := StripRecipe))

$(eval $(call SetupCopyFiles,COPY_MODULES_CMDS, \
    SRC := $(SUPPORT_OUTPUTDIR)/modules_cmds, \
    DEST := $(MODULES_CMDS_STRIPPED), \
    FILES := $(COPY_CMDS_SRC)))

$(eval $(call SetupCopyFiles,STRIP_MODULES_LIBS, \
    SRC := $(SUPPORT_OUTPUTDIR)/modules_libs, \
    DEST := $(MODULES_LIBS_STRIPPED), \
    FILES := $(STRIP_LIBS_SRC), \
    MACRO := StripRecipe))

$(eval $(call SetupCopyFiles,COPY_MODULES_LIBS, \
    SRC := $(SUPPORT_OUTPUTDIR)/modules_libs, \
    DEST := $(MODULES_LIBS_STRIPPED), \
    FILES := $(COPY_LIBS_SRC)))

TARGETS += $(STRIP_MODULES_CMDS) $(COPY_MODULES_CMDS) \
    $(STRIP_MODULES_LIBS) $(COPY_MODULES_LIBS)

all: $(TARGETS)