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.2 2004/04/07 22:37:50 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/^%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' >> $@
61 SPECS/$(notdir $(SPEC)).in:
63 cvs -d $(CVSROOT) checkout -r $(TAG) -p $(SPEC) > $@
72 Source0 := $(notdir $(Source0))
74 # Add tarball to the list of sources
75 SOURCES += SOURCES/$(Source0)
77 # Get rid of .tar.bz2 or .tar.gz or .tgz
78 Base0 := $(basename $(basename $(Source0)))
83 cd SOURCES && cvs -d $(CVSROOT) export -r $(INITIAL) -d $(Base0) $(MODULE)
85 .SECONDARY: $(SOURCES)/$(Base0)
88 SOURCES/$(Base0).tar.bz2: SOURCES/$(Base0)
89 tar cpjf $@ -C SOURCES $(Base0)
91 SOURCES/$(Base0).tar.gz SOURCES/$(Base0).tgz: SOURCES/$(Base0)
92 tar cpzf $@ -C SOURCES $(Base0)
94 SOURCES/$(Base0).tar: SOURCES/$(Base0)
95 tar cpf $@ -C SOURCES $(Base0)
101 define PATCH_template
103 # In case the spec file did not explicitly list the PatchSet
104 ifeq ($$(origin Patch$(1)),undefined)
105 Patch$(1) := $(1).patch.bz2
109 Patch$(1) := $(notdir $$(Patch$(1)))
111 # Add patch to the list of sources
112 SOURCES += SOURCES/$$(Patch$(1))
114 # Generate uncompressed patch
115 SOURCES/$$(patsubst %.gz,%,$$(patsubst %.bz2,%,$$(Patch$(1)))):
117 cvsps --cvs-direct --root $(CVSROOT) -g -s $(1) $(MODULE) > $$@
129 # Generate rules to generate patches
130 $(foreach n,$(PATCHES),$(eval $(call PATCH_template,$(n))))
137 # Define date for untagged builds
138 DATE := $(shell date +%Y.%m.%d)
142 SPECS/$(notdir $(SPEC)): SPECS/$(notdir $(SPEC)).in
145 # Define date for untagged builds
146 echo "%define date $(DATE)" >> $@
148 # Rewrite patch sections of spec file
150 next if /^Patch.*/; \
151 next if /^%patch.*/; \
153 if (/^Source.*/) { $(foreach n,$(PATCHES),print "Patch$(n): $(Patch$(n))\n";) } \
154 if (/^%setup.*/) { $(foreach n,$(PATCHES),print "%patch$(n) -p1\n";) } \
161 NVR := $(shell rpmquery $(RPMFLAGS) $(if $(DATE),--define "date $(DATE)") --specfile SPECS/$(notdir $(SPEC)).in | head -1)
162 ARCH := $(shell rpm $(RPMFLAGS) --showrc | sed -ne 's/^build arch[ ]*:[ ]*\(.*\)/\1/p')
164 all: RPMS/$(ARCH)/$(NVR).$(ARCH).rpm SRPMS/$(NVR).src.rpm
167 RPMS/$(ARCH)/$(NVR).$(ARCH).rpm: SPECS/$(notdir $(SPEC)) $(SOURCES) .rpmmacros
169 rpmbuild $(RPMFLAGS) -bb $<
172 SRPMS/$(NVR).src.rpm: SPECS/$(notdir $(SPEC)) $(SOURCES) .rpmmacros
174 rpmbuild $(RPMFLAGS) -bs $<
176 # Base rpmbuild in the current directory
178 echo "%_topdir $(HOME)" > $@