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.7 2004/04/14 18:05:30 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'
51 -e 's/%\([[:alnum:]]*\)/$${\1}/g' \
52 -e 's/^$${define}[ ]*\([^ ]*\)[ ]*\([^ ]*\)/\1 := \2/p' \
53 -e 's/^\([^ ]*\):[ ]*\([^ ]*\)/\1 := \2/p' \
55 ifneq ($(INITIAL),$(TAG))
56 # Get list of PatchSets
57 cvsps --cvs-direct --root $(CVSROOT) -r $(INITIAL) $(if $(TAG:HEAD=),-r $(TAG)) $(MODULE) | \
58 sed -ne 's|^PatchSet[ ]*\([0-9]*\)|PATCHES += \1|p' >> $@
59 ifeq ($(shell echo $(MAKE_VERSION) | awk '{ print ($$1 < 3.80) }'),1)
60 # make-3.80 can use $(eval) instead (see below)
61 cvsps --cvs-direct --root $(CVSROOT) -r $(INITIAL) $(if $(TAG:HEAD=),-r $(TAG)) $(MODULE) | \
66 SPECS/$(notdir $(SPEC)).in:
68 cvs -d $(CVSROOT) checkout -r $(TAG) -p $(SPEC) > $@
77 Source0 := $(notdir $(if $(Source),$(Source),$(Source0)))
79 # Add tarball to the list of sources
80 SOURCES += SOURCES/$(Source0)
82 # Get rid of .tar.bz2 or .tar.gz or .tgz
83 Base0 := $(basename $(basename $(Source0)))
88 cd SOURCES && cvs -d $(CVSROOT) export -r $(INITIAL) -d $(Base0) $(MODULE)
90 .SECONDARY: $(SOURCES)/$(Base0)
93 SOURCES/$(Base0).tar.bz2: SOURCES/$(Base0)
94 tar cpjf $@ -C SOURCES $(Base0)
96 SOURCES/$(Base0).tar.gz SOURCES/$(Base0).tgz: SOURCES/$(Base0)
97 tar cpzf $@ -C SOURCES $(Base0)
99 SOURCES/$(Base0).tar: SOURCES/$(Base0)
100 tar cpf $@ -C SOURCES $(Base0)
106 define PATCH_template
108 # In case the spec file did not explicitly list the PatchSet
109 ifeq ($$(origin Patch$(1)),undefined)
110 Patch$(1) := $$(package)-$(1).patch.bz2
114 Patch$(1) := $$(notdir $$(Patch$(1)))
116 # Add patch to the list of sources
117 SOURCES += SOURCES/$$(Patch$(1))
119 # Generate uncompressed patch
120 SOURCES/$$(patsubst %.gz,%,$$(patsubst %.bz2,%,$$(Patch$(1)))):
122 cvsps --cvs-direct --root $$(CVSROOT) -g -s $(1) $$(MODULE) > $$@
134 # Generate rules to generate patches (make-3.80 and above expands this)
135 $(foreach n,$(PATCHES),$(eval $(call PATCH_template,$(n))))
142 # Define date for untagged builds
143 DATE := $(shell date +%Y.%m.%d)
147 SPECS/$(notdir $(SPEC)): SPECS/$(notdir $(SPEC)).in
150 # Define date for untagged builds
151 echo "%define date $(DATE)" >> $@
153 # Rewrite patch sections of spec file
155 next if /^Patch.*/; \
156 next if /^%patch.*/; \
158 if (/^Source.*/) { $(foreach n,$(PATCHES),print "Patch$(n): $(Patch$(n))\n";) } \
159 if (/^%setup.*/) { $(foreach n,$(PATCHES),print "%patch$(n) -p1\n";) } \
166 RPMFLAGS += $(if $(DATE),--define "date $(DATE)")
167 NVR := $(shell rpmquery $(RPMFLAGS) --specfile SPECS/$(notdir $(SPEC)).in 2>/dev/null | head -1)
168 ARCH := $(shell rpmquery $(RPMFLAGS) --queryformat '%{ARCH}\n' --specfile SPECS/$(notdir $(SPEC)).in 2>/dev/null | head -1)
170 all: RPMS/$(ARCH)/$(NVR).$(ARCH).rpm SRPMS/$(NVR).src.rpm
173 RPMS/$(ARCH)/$(NVR).$(ARCH).rpm: SPECS/$(notdir $(SPEC)) $(SOURCES) .rpmmacros
175 rpmbuild $(RPMFLAGS) -bb $<
178 SRPMS/$(NVR).src.rpm: SPECS/$(notdir $(SPEC)) $(SOURCES) .rpmmacros
180 rpmbuild $(RPMFLAGS) -bs $<
182 # Base rpmbuild in the current directory
184 echo "%_topdir $(HOME)" > $@
186 # Remove files generated by this package
190 RPMS/$(ARCH)/$(NVR).$(ARCH).rpm \
191 SOURCES/$(Base0)* SOURCES/$(package)* \
192 SPECS/$(notdir $(SPEC)).in SPECS/$(notdir $(SPEC)) $(MK) \
193 SRPMS/$(NVR).src.rpm \
194 .cvsps/$(subst /,#,$(CVSROOT)/$(MODULE))