1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
#
# Copyright (c) 2011, 2022, 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.
#
ifndef _ZIP_ARCHIVE_GMK
_ZIP_ARCHIVE_GMK := 1
# Depends on build tools for MakeZipReproducible
include ../ToolsJdk.gmk
ifeq (,$(_MAKEBASE_GMK))
$(error You must include MakeBase.gmk prior to including ZipArchive.gmk)
endif
# Setup make rules for creating a zip archive.
#
# Parameter 1 is the name of the rule. This name is used as variable prefix,
# and the targets generated are listed in a variable by that name.
#
# Remaining parameters are named arguments. These include:
# SRC
# ZIP
# INCLUDES
# INCLUDE_FILES
# EXCLUDES
# EXCLUDE_FILES
# EXCLUDE_PATTERNS - Patterns with at most one % wildcard matching filenames
# and not directories.
# EXCLUDE_PATTERNS_$dir - Exclude patterns just like above but specific to one
# src dir
# SUFFIXES
# EXTRA_DEPS
# FOLLOW_SYMLINKS - Set to explicitly follow symlinks. Affects performance of
# finding files.
# ZIP_OPTIONS extra options to pass to zip
# REPRODUCIBLE set to false to disable the step that makes zip reproducible
SetupZipArchive = $(NamedParamsMacroTemplate)
define SetupZipArchiveBody
# Create a version $1_SRC with a guaranteed trailing slash
$1_SRC_SLASH := $$(addsuffix /, $$(patsubst %/, %, $$($1_SRC)))
# To avoid running find over too large sets of files, which causes make to crash
# on some configurations (cygwin), use INCLUDES and INCLUDE_FILES to build a set
# of directories to run find in, if available.
ifneq ($$($1_INCLUDES)$$($1_INCLUDE_FILES),)
$1_FIND_LIST := $$(wildcard $$(foreach s,$$($1_SRC_SLASH), \
$$(addprefix $$s,$$($1_INCLUDES) $$($1_INCLUDE_FILES))))
else
$1_FIND_LIST := $$($1_SRC_SLASH)
endif
# Find all files in the source tree.
# If asked to, follow symlinks in this find since that is what zip does. To do
# this, we need to call ShellFindFiles directly.
ifeq ($$($1_FOLLOW_SYMLINKS), true)
$1_ALL_SRCS := $$(call not-containing,_the.,$$(call ShellFindFiles,$$($1_FIND_LIST), , -L))
else
$1_ALL_SRCS := $$(call not-containing,_the.,$$(call FindFiles,$$($1_FIND_LIST)))
endif
# Filter on suffixes if set
ifneq ($$($1_SUFFIXES),)
$1_ALL_SRCS := $$(filter $$(addprefix %, $$($1_SUFFIXES)), $$($1_ALL_SRCS))
endif
ifneq ($$($1_INCLUDES),)
ifneq ($$($1_SUFFIXES),)
$1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES), \
$$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$$s$(DQUOTE),$$($1_INCLUDES))))
else
$1_ZIP_INCLUDES := $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_INCLUDES)))
endif
else
ifneq ($$($1_SUFFIXES),)
$1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES), \
$$(addprefix -i$(SPACE)$(DQUOTE),*$$s$(DQUOTE)))
endif
endif
ifneq ($$($1_INCLUDE_FILES),)
$1_ZIP_INCLUDES += $$(addprefix -i$(SPACE),$$($1_INCLUDE_FILES))
endif
ifneq ($$($1_EXCLUDES),)
$1_ZIP_EXCLUDES := $$(addprefix -x$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_EXCLUDES)))
$1_SRC_EXCLUDES := $$(foreach s,$$($1_SRC_SLASH),$$(addprefix $$s,$$(addsuffix /%,$$($1_EXCLUDES))))
$1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_SRCS))
endif
ifneq ($$($1_EXCLUDE_FILES),)
$1_SRC_EXCLUDE_FILES := $$(addprefix %, $$($1_EXCLUDE_FILES)) $$($1_EXCLUDE_FILES)
$1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDE_FILES), $$($1_ALL_SRCS))
$$(foreach s, $$($1_SRC_SLASH), \
$$(eval $1_ZIP_EXCLUDES_$$s += \
$$(addprefix -x$$(SPACE), $$(patsubst $$s%,%, $$($1_EXCLUDE_FILES))) \
) \
)
endif
ifneq ($$($1_EXCLUDE_PATTERNS), )
$1_ALL_SRCS := $$(filter-out $$($1_EXCLUDE_PATTERNS), $$($1_ALL_SRCS))
$1_ZIP_EXCLUDES += $$(addprefix -x$(SPACE), $$(subst %,\*,$$($1_EXCLUDE_PATTERNS)))
endif
# Rewrite src dir specific exclude patterns to zip excludes
$$(foreach s, $$($1_SRC_SLASH), \
$$(if $$($1_EXCLUDE_PATTERNS_$$s), \
$$(eval $1_ZIP_EXCLUDES_$$s += \
$$(addprefix -x$$(SPACE), $$(subst %,\*,$$($1_EXCLUDE_PATTERNS_$$s))) \
) \
) \
)
ifeq ($$($1_REPRODUCIBLE), )
$1_REPRODUCIBLE := true
endif
# Use a slightly shorter name for logging, but with enough path to identify this zip.
$1_NAME:=$$(subst $$(OUTPUTDIR)/,,$$($1_ZIP))
# Now $1_ALL_SRCS should contain all sources that are going to be put into the zip.
# I.e. the zip -i and -x options should match the filtering done in the makefile.
# Explicitly excluded files can be given with absolute path. The patsubst solution
# isn't perfect but the likelihood of an absolute path to match something in a src
# dir is very small.
# If zip has nothing to do, it returns 12 and would fail the build. Check for 12
# and only fail if it's not.
# For reproducible builds set the zip access & modify times to SOURCE_DATE_EPOCH
# by using a ziptmp folder to generate final zip from using MakeZipReproducible.
$$($1_ZIP) : $$($1_ALL_SRCS) $$($1_EXTRA_DEPS)
$$(call LogWarn, Updating $$($1_NAME))
$$(call MakeTargetDir)
# Find duplicate file names in the SRC and generate excludes for all
# instances that should not be included. Run this rather expensive
# calculation as part of the recipe to avoid running it when nothing
# needs to be rebuilt. The drawback is that we cannot exclude these
# files from the make prerequisites list, but the number of files is
# usually small so a very rare unnecessary rebuild is worth it.
# (The inner most foreach here is used instead of eval to declare a
# local variable.)
$$(foreach root, $$($1_SRC_SLASH), \
$$(foreach file, $$(filter $$(root)%, $$($1_ALL_SRCS)), \
$$(foreach relfile, $$(patsubst $$(root)%, %, $$(file)), \
$$(if $$($1_relfiles_$$(call DoubleDollar, $$(relfile))), \
$$(eval $1_ZIP_EXCLUDES_$$(root) += -x $$(relfile)) \
, \
$$(eval $1_relfiles_$$(call DoubleDollar, $$(relfile)) := 1) \
) \
) \
) \
)
$$(foreach s,$$($1_SRC_SLASH), $$(call ExecuteWithLog, \
$$(SUPPORT_OUTPUTDIR)/zip/$$(patsubst $$(OUTPUTDIR)/%,%, $$@), \
(cd $$s && $(ZIPEXE) -qru $$($1_ZIP_OPTIONS) $$@ . \
$$($1_ZIP_INCLUDES) $$($1_ZIP_EXCLUDES) -x \*_the.\* \
$$($1_ZIP_EXCLUDES_$$s) \
|| test "$$$$?" = "12" \
))$$(NEWLINE) \
) true
ifeq ($$($1_REPRODUCIBLE), true)
$$(call ExecuteWithLog, \
$$(SUPPORT_OUTPUTDIR)/makezipreproducible/$$(patsubst $$(OUTPUTDIR)/%,%, $$@), \
($(RM) $$(SUPPORT_OUTPUTDIR)/ziptmp/$1/tmp.zip && \
$(MKDIR) -p $$(SUPPORT_OUTPUTDIR)/ziptmp/$1 && \
$(TOOL_MAKEZIPREPRODUCIBLE) -f $$(SUPPORT_OUTPUTDIR)/ziptmp/$1/tmp.zip \
-t $(SOURCE_DATE_EPOCH) $$@ && \
$(RM) $$@ && \
$(MV) $$(SUPPORT_OUTPUTDIR)/ziptmp/$1/tmp.zip $$@ \
))
endif
$(TOUCH) $$@
# Add zip to target list
$1 += $$($1_ZIP)
endef
endif # _ZIP_ARCHIVE_GMK
|