ZipArchive.gmk revision 1233:86ff430e9a2b
1184610Salfred# 2184610Salfred# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. 3184610Salfred# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4184610Salfred# 5184610Salfred# This code is free software; you can redistribute it and/or modify it 6184610Salfred# under the terms of the GNU General Public License version 2 only, as 7184610Salfred# published by the Free Software Foundation. Oracle designates this 8184610Salfred# particular file as subject to the "Classpath" exception as provided 9184610Salfred# by Oracle in the LICENSE file that accompanied this code. 10184610Salfred# 11184610Salfred# This code is distributed in the hope that it will be useful, but WITHOUT 12184610Salfred# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13184610Salfred# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14184610Salfred# version 2 for more details (a copy is included in the LICENSE file that 15184610Salfred# accompanied this code). 16184610Salfred# 17184610Salfred# You should have received a copy of the GNU General Public License version 18184610Salfred# 2 along with this work; if not, write to the Free Software Foundation, 19184610Salfred# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20184610Salfred# 21184610Salfred# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22184610Salfred# or visit www.oracle.com if you need additional information or have any 23184610Salfred# questions. 24184610Salfred# 25184610Salfred 26184610Salfredifndef _ZIP_ARCHIVE_GMK 27184610Salfred_ZIP_ARCHIVE_GMK := 1 28184610Salfred 29184610Salfredifeq (,$(_MAKEBASE_GMK)) 30184610Salfred $(error You must include MakeBase.gmk prior to including ZipArchive.gmk) 31184610Salfredendif 32246122Shselasky 33246122Shselasky# Setup make rules for creating a zip archive. 34246122Shselasky# 35194677Sthompsa# Parameter 1 is the name of the rule. This name is used as variable prefix, 36194677Sthompsa# and the targets generated are listed in a variable by that name. 37194677Sthompsa# 38194677Sthompsa# Remaining parameters are named arguments. These include: 39194677Sthompsa# SRC 40194677Sthompsa# ZIP 41194677Sthompsa# INCLUDES 42194677Sthompsa# INCLUDE_FILES 43194677Sthompsa# EXCLUDES 44194677Sthompsa# EXCLUDE_FILES 45194677Sthompsa# SUFFIXES 46194677Sthompsa# EXTRA_DEPS 47194677Sthompsa# ZIP_OPTIONS extra options to pass to zip 48194677Sthompsadefine SetupZipArchive 49194677Sthompsa $(if $(16),$(error Internal makefile error: Too many arguments to SetupZipArchive, please update ZipArchive.gmk)) 50194677Sthompsa $(call EvalDebugWrapper,$(strip $1),$(call SetupZipArchiveInner,$(strip $1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))) 51194677Sthompsaendef 52194677Sthompsa 53194677Sthompsadefine SetupZipArchiveInner 54188942Sthompsa $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $(strip $($i)),$1_$(strip $($i)))$(NEWLINE)) 55223467Shselasky $(call LogSetupMacroEntry,SetupZipArchive($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)) 56194677Sthompsa $(if $(16),$(error Internal makefile error: Too many arguments to SetupZipArchive, please update JavaCompilation.gmk)) 57194677Sthompsa 58194677Sthompsa # To avoid running find over too large sets of files, which causes make to crash 59194677Sthompsa # on some configurations (cygwin), use INCLUDES and INCLUDE_FILES to build a set 60188942Sthompsa # of directories to run find in, if available. 61188942Sthompsa ifneq ($$($1_INCLUDES)$$($1_INCLUDE_FILES),) 62194677Sthompsa $1_FIND_LIST := $$(wildcard $$(foreach i,$$($1_SRC), \ 63188942Sthompsa $$(addprefix $$i/,$$($1_INCLUDES) $$($1_INCLUDE_FILES)))) 64188942Sthompsa else 65188942Sthompsa $1_FIND_LIST := $$($1_SRC) 66184610Salfred endif 67194677Sthompsa 68194677Sthompsa # Find all files in the source tree. 69194677Sthompsa $1_ALL_SRCS := $$(call not-containing,_the.,$$(call CacheFind,$$($1_FIND_LIST))) 70188942Sthompsa 71188942Sthompsa # Filter on suffixes if set 72250207Shselasky ifneq ($$($1_SUFFIXES),) 73188942Sthompsa $1_ALL_SRCS := $$(filter $$(addprefix %, $$($1_SUFFIXES)), $$($1_ALL_SRCS)) 74246122Shselasky endif 75184610Salfred 76188942Sthompsa ifneq ($$($1_INCLUDES),) 77188942Sthompsa ifneq ($$($1_SUFFIXES),) 78184610Salfred $1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES), \ 79184610Salfred $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$$s$(DQUOTE),$$($1_INCLUDES)))) 80184610Salfred else 81194228Sthompsa $1_ZIP_INCLUDES := $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_INCLUDES))) 82194228Sthompsa endif 83192984Sthompsa endif 84194228Sthompsa ifneq ($$($1_INCLUDE_FILES),) 85192984Sthompsa $1_ZIP_INCLUDES += $$(addprefix -i$(SPACE),$$($1_INCLUDE_FILES)) 86194228Sthompsa endif 87192984Sthompsa ifneq ($$($1_EXCLUDES),) 88194228Sthompsa $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) 89192984Sthompsa $1_ZIP_EXCLUDES := $$(addprefix -x$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_EXCLUDES))) 90194228Sthompsa $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_SRCS)) 91185948Sthompsa endif 92194228Sthompsa 93192984Sthompsa # Use a slightly shorter name for logging, but with enough path to identify this zip. 94194228Sthompsa $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_ZIP)) 95185948Sthompsa 96194228Sthompsa # Now $1_ALL_SRCS should contain all sources that are going to be put into the zip. 97192984Sthompsa # I.e. the zip -i and -x options should match the filtering done in the makefile. 98194228Sthompsa # Explicitly excluded files can be given with absolute path. The patsubst solution 99194228Sthompsa # isn't perfect but the likelyhood of an absolute path to match something in a src 100194228Sthompsa # dir is very small. 101194228Sthompsa # If zip has nothing to do, it returns 12 and would fail the build. Check for 12 102185948Sthompsa # and only fail if it's not. 103194228Sthompsa $$($1_ZIP) : $$($1_ALL_SRCS) $$($1_EXTRA_DEPS) 104185948Sthompsa $(MKDIR) -p $$(@D) 105194228Sthompsa $(ECHO) Updating $$($1_NAME) 106205030Sthompsa $$(foreach i,$$($1_SRC),(cd $$i && $(ZIP) -qru $$($1_ZIP_OPTIONS) $$@ . $$($1_ZIP_INCLUDES) $$($1_ZIP_EXCLUDES) -x \*_the.\* $$(addprefix -x$(SPACE),$$(patsubst $$i/%,%,$$($1_EXCLUDE_FILES))) || test "$$$$?" = "12" )$$(NEWLINE)) true 107194228Sthompsa $(TOUCH) $$@ 108194228Sthompsa 109192984Sthompsa # Add zip to target list 110194228Sthompsa $1 += $$($1_ZIP) 111185948Sthompsaendef 112194228Sthompsa 113184610Salfredendif # _ZIP_ARCHIVE_GMK 114184610Salfred