make/StripBinaries.gmk
author brutisso
Thu, 28 Jan 2016 10:18:45 +0100
changeset 35873 96fb98b25b13
parent 35008 ef0cd710989f
child 35747 aeaa6d0101a8
permissions -rw-r--r--
Merge

#
# Copyright (c) 2014, 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.
ALL_CMDS_SRC := $(filter-out %.bc %.debuginfo %.diz %.map %.pdb, \
    $(shell $(FIND) $(SUPPORT_OUTPUTDIR)/modules_cmds -type f -o -type l))
COPY_CMDS_SRC := $(filter $(NO_STRIP_CMDS_FILTER), $(ALL_CMDS_SRC))
STRIP_CMDS_SRC := $(filter-out $(NO_STRIP_CMDS_FILTER), $(ALL_CMDS_SRC))

# 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 \
        -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 -type f -o -type l))

$(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)