ZipArchive.gmk revision 2335:108814a7bae0
1219820Sjeff# 2219820Sjeff# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. 3219820Sjeff# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4219820Sjeff# 5299653Shselasky# This code is free software; you can redistribute it and/or modify it 6289577Shselasky# under the terms of the GNU General Public License version 2 only, as 7219820Sjeff# published by the Free Software Foundation. Oracle designates this 8219820Sjeff# particular file as subject to the "Classpath" exception as provided 9219820Sjeff# by Oracle in the LICENSE file that accompanied this code. 10219820Sjeff# 11219820Sjeff# This code is distributed in the hope that it will be useful, but WITHOUT 12219820Sjeff# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13219820Sjeff# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14219820Sjeff# version 2 for more details (a copy is included in the LICENSE file that 15219820Sjeff# accompanied this code). 16219820Sjeff# 17219820Sjeff# You should have received a copy of the GNU General Public License version 18219820Sjeff# 2 along with this work; if not, write to the Free Software Foundation, 19219820Sjeff# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20219820Sjeff# 21219820Sjeff# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22219820Sjeff# or visit www.oracle.com if you need additional information or have any 23219820Sjeff# questions. 24219820Sjeff# 25219820Sjeff 26219820Sjeffifndef _ZIP_ARCHIVE_GMK 27219820Sjeff_ZIP_ARCHIVE_GMK := 1 28219820Sjeff 29289644Shselaskyifeq (,$(_MAKEBASE_GMK)) 30289644Shselasky $(error You must include MakeBase.gmk prior to including ZipArchive.gmk) 31219820Sjeffendif 32219820Sjeff 33219820Sjeff# Setup make rules for creating a zip archive. 34219820Sjeff# 35219820Sjeff# Parameter 1 is the name of the rule. This name is used as variable prefix, 36219820Sjeff# and the targets generated are listed in a variable by that name. 37219820Sjeff# 38219820Sjeff# Remaining parameters are named arguments. These include: 39219820Sjeff# SRC 40219820Sjeff# ZIP 41219820Sjeff# INCLUDES 42219820Sjeff# INCLUDE_FILES 43323214Srlibby# EXCLUDES 44323214Srlibby# EXCLUDE_FILES 45219820Sjeff# SUFFIXES 46219820Sjeff# EXTRA_DEPS 47219820Sjeff# ZIP_OPTIONS extra options to pass to zip 48323214SrlibbySetupZipArchive = $(NamedParamsMacroTemplate) 49323214Srlibbydefine SetupZipArchiveBody 50219820Sjeff 51219820Sjeff # To avoid running find over too large sets of files, which causes make to crash 52219820Sjeff # on some configurations (cygwin), use INCLUDES and INCLUDE_FILES to build a set 53299653Shselasky # of directories to run find in, if available. 54219820Sjeff ifneq ($$($1_INCLUDES)$$($1_INCLUDE_FILES),) 55334766Shselasky $1_FIND_LIST := $$(wildcard $$(foreach i,$$($1_SRC), \ 56219820Sjeff $$(addprefix $$i/,$$($1_INCLUDES) $$($1_INCLUDE_FILES)))) 57219820Sjeff else 58219820Sjeff $1_FIND_LIST := $$($1_SRC) 59299653Shselasky endif 60329959Shselasky 61329959Shselasky # Find all files in the source tree. 62328653Shselasky $1_ALL_SRCS := $$(call not-containing,_the.,$$(call CacheFind,$$($1_FIND_LIST))) 63328653Shselasky 64328653Shselasky # Filter on suffixes if set 65219820Sjeff ifneq ($$($1_SUFFIXES),) 66219820Sjeff $1_ALL_SRCS := $$(filter $$(addprefix %, $$($1_SUFFIXES)), $$($1_ALL_SRCS)) 67219820Sjeff endif 68330856Shselasky 69299653Shselasky ifneq ($$($1_INCLUDES),) 70219820Sjeff ifneq ($$($1_SUFFIXES),) 71219820Sjeff $1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES), \ 72219820Sjeff $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$$s$(DQUOTE),$$($1_INCLUDES)))) 73219820Sjeff else 74219820Sjeff $1_ZIP_INCLUDES := $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_INCLUDES))) 75219820Sjeff endif 76330856Shselasky else 77289577Shselasky ifneq ($$($1_SUFFIXES),) 78289577Shselasky $1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES), \ 79219820Sjeff $$(addprefix -i$(SPACE)$(DQUOTE),*$$s$(DQUOTE))) 80289577Shselasky endif 81289577Shselasky endif 82289577Shselasky ifneq ($$($1_INCLUDE_FILES),) 83289577Shselasky $1_ZIP_INCLUDES += $$(addprefix -i$(SPACE),$$($1_INCLUDE_FILES)) 84299653Shselasky endif 85299653Shselasky ifneq ($$($1_EXCLUDES),) 86299653Shselasky $1_ZIP_EXCLUDES := $$(addprefix -x$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_EXCLUDES))) 87292537Shselasky $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) 88331756Semaste $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_SRCS)) 89292537Shselasky endif 90292537Shselasky ifneq ($$($1_EXCLUDE_FILES),) 91292537Shselasky # Cannot precompute ZIP_EXCLUDE_FILES as it is dependent on which src root is being 92292537Shselasky # zipped at the moment. 93292537Shselasky $1_SRC_EXCLUDE_FILES := $$(addprefix %, $$($1_EXCLUDE_FILES)) $$($1_EXCLUDE_FILES) 94292537Shselasky $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDE_FILES), $$($1_ALL_SRCS)) 95292537Shselasky endif 96322498Shselasky 97322498Shselasky # Use a slightly shorter name for logging, but with enough path to identify this zip. 98322498Shselasky $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_ZIP)) 99322498Shselasky 100292537Shselasky # Now $1_ALL_SRCS should contain all sources that are going to be put into the zip. 101292537Shselasky # I.e. the zip -i and -x options should match the filtering done in the makefile. 102292537Shselasky # Explicitly excluded files can be given with absolute path. The patsubst solution 103299653Shselasky # isn't perfect but the likelyhood of an absolute path to match something in a src 104299653Shselasky # dir is very small. 105299653Shselasky # If zip has nothing to do, it returns 12 and would fail the build. Check for 12 106299653Shselasky # and only fail if it's not. 107299653Shselasky $$($1_ZIP) : $$($1_ALL_SRCS) $$($1_EXTRA_DEPS) 108219820Sjeff $(MKDIR) -p $$(@D) 109 $(ECHO) Updating $$($1_NAME) 110 $$(foreach i,$$($1_SRC),(cd $$i && $(ZIPEXE) -qru $$($1_ZIP_OPTIONS) $$@ . $$($1_ZIP_INCLUDES) \ 111 $$($1_ZIP_EXCLUDES) -x \*_the.\* \ 112 $$(addprefix -x$(SPACE), $$(patsubst $$i/%,%, $$($1_EXCLUDE_FILES))) \ 113 || test "$$$$?" = "12" )$$(NEWLINE)) true 114 $(TOUCH) $$@ 115 116 # Add zip to target list 117 $1 += $$($1_ZIP) 118endef 119 120endif # _ZIP_ARCHIVE_GMK 121