2 # PlanetLab RPM generation
4 # Copyright (c) 2003 The Trustees of Princeton University (Trustees).
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/or other materials provided
17 # with the distribution.
19 # * Neither the name of the copyright holder nor the names of its
20 # contributors may be used to endorse or promote products derived
21 # from this software without specific prior written permission.
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TRUSTEES OR
27 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 # $Id: Makerules,v 1.9 2004/08/11 21:41:16 mlh-pl_rpm Exp $
38 # Base cvsps and rpmbuild in the current directory
39 export HOME := $(shell pwd)
40 export CVSROOT CVS_RSH
43 # Parse spec file template
46 MK := SPECS/$(patsubst %.spec,%.mk,$(notdir $(SPEC)))
48 $(MK): SPECS/$(notdir $(SPEC)).in
49 # Substitute '$' for '%' and 'name := value' for '%define name value' or 'name: value'
52 -e 's/%\([[:alnum:]]\+\)/$${\1}/g' \
53 -e 's/^$${define}[ ]*\([^ ]*\)[ ]*\([^ ]*\)/\1 := \2/p' \
54 -e 's/^\([^ ]*\):[ ]*\([^ ]*\)/\1 := \2/p' \
56 ifneq ($(INITIAL),$(TAG))
57 # Get list of PatchSets
58 cvsps --cvs-direct --root $(CVSROOT) -r $(INITIAL) $(if $(TAG:HEAD=),-r $(TAG)) $(MODULE) | \
59 sed -ne 's|^PatchSet[ ]*\([0-9]*\)|PATCHES += \1|p' >> $@
60 ifeq ($(shell echo $(MAKE_VERSION) | awk '{ print ($$1 < 3.80) }'),1)
61 # make-3.80 can use $(eval) instead (see below)
62 cvsps --cvs-direct --root $(CVSROOT) -r $(INITIAL) $(if $(TAG:HEAD=),-r $(TAG)) $(MODULE) | \
67 SPECS/$(notdir $(SPEC)).in:
69 cvs -d $(CVSROOT) checkout -r $(TAG) -p $(SPEC) > $@
78 Source0 := $(notdir $(if $(Source),$(Source),$(Source0)))
80 # Add tarball to the list of sources
81 SOURCES += SOURCES/$(Source0)
83 # Get rid of .tar.bz2 or .tar.gz or .tgz
84 Base0 := $(basename $(basename $(Source0)))
89 cd SOURCES && cvs -d $(CVSROOT) export -r $(INITIAL) -d $(Base0) $(MODULE)
91 .SECONDARY: $(SOURCES)/$(Base0)
94 SOURCES/$(Base0).tar.bz2: SOURCES/$(Base0)
95 tar cpjf $@ -C SOURCES $(Base0)
97 SOURCES/$(Base0).tar.gz SOURCES/$(Base0).tgz: SOURCES/$(Base0)
98 tar cpzf $@ -C SOURCES $(Base0)
100 SOURCES/$(Base0).tar: SOURCES/$(Base0)
101 tar cpf $@ -C SOURCES $(Base0)
107 define PATCH_template
109 # In case the spec file did not explicitly list the PatchSet
110 ifeq ($$(origin Patch$(1)),undefined)
111 Patch$(1) := $$(package)-$(1).patch.bz2
115 Patch$(1) := $$(notdir $$(Patch$(1)))
117 # Add patch to the list of sources
118 SOURCES += SOURCES/$$(Patch$(1))
120 # Generate uncompressed patch
121 SOURCES/$$(patsubst %.gz,%,$$(patsubst %.bz2,%,$$(Patch$(1)))):
123 cvsps --cvs-direct --root $$(CVSROOT) -g -s $(1) $$(MODULE) > $$@
135 # Generate rules to generate patches (make-3.80 and above expands this)
136 $(foreach n,$(PATCHES),$(eval $(call PATCH_template,$(n))))
143 # Define date for untagged builds
144 DATE := $(shell date +%Y.%m.%d)
148 SPECS/$(notdir $(SPEC)): SPECS/$(notdir $(SPEC)).in
151 # Define date for untagged builds
152 echo "%define date $(DATE)" >> $@
154 # Rewrite patch sections of spec file
156 next if /^Patch.*/; \
157 next if /^%patch.*/; \
159 if (/^Source.*/) { $(foreach n,$(PATCHES),print "Patch$(n): $(Patch$(n))\n";) } \
160 if (/^%setup.*/) { $(foreach n,$(PATCHES),print "%patch$(n) -p1\n";) } \
168 RPMFLAGS += --define "date $(DATE)"
170 NVR := $(shell rpmquery $(RPMFLAGS) --specfile SPECS/$(notdir $(SPEC)).in 2>/dev/null | head -1)
171 ARCH := $(shell rpmquery $(RPMFLAGS) --queryformat '%{ARCH}\n' --specfile SPECS/$(notdir $(SPEC)).in 2>/dev/null | head -1)
173 all: RPMS/$(ARCH)/$(NVR).$(ARCH).rpm SRPMS/$(NVR).src.rpm
176 RPMS/$(ARCH)/$(NVR).$(ARCH).rpm: SPECS/$(notdir $(SPEC)) $(SOURCES) .rpmmacros
178 rpmbuild $(RPMFLAGS) -bb $<
181 SRPMS/$(NVR).src.rpm: SPECS/$(notdir $(SPEC)) $(SOURCES) .rpmmacros
183 rpmbuild $(RPMFLAGS) -bs $<
185 # Base rpmbuild in the current directory
187 echo "%_topdir $(HOME)" > $@
189 # Remove files generated by this package
193 RPMS/$(ARCH)/$(NVR).$(ARCH).rpm \
194 SOURCES/$(Base0)* SOURCES/$(package)* \
195 SPECS/$(notdir $(SPEC)).in SPECS/$(notdir $(SPEC)) $(MK) \
196 SRPMS/$(NVR).src.rpm \
197 .cvsps/$(subst /,#,$(CVSROOT)/$(MODULE))