2 # PlanetLab RPM generation
4 # Mark Huang <mlhuang@cs.princeton.edu>
5 # Copyright (C) 2003-2006 The Trustees of Princeton University
7 # $Id: Rules.mk,v 1.35 2007/08/22 14:41:32 mef Exp $
10 # Base rpmbuild in the current directory
11 export HOME := $(shell pwd)
12 export CVSROOT CVS_RSH
18 SPECFILE := SPECS/$(notdir $(SPEC))
22 echo "%define pldistro $(PLDISTRO)" > $@
24 # Define date for untagged builds
25 echo "%define date $(shell date +%Y.%m.%d)" >> $@
27 # Define cvstag for tagged builds
28 echo "%define cvstag $(TAG)" >> $@
30 $(if $($(package)-SVNPATH),\
31 svn cat $($(package)-SVNPATH)/$(SPEC) >> $@,\
32 cvs -d $(CVSROOT) checkout -r $(TAG) -p $(SPEC) >> $@)
36 # Parse spec file into Makefile fragment
39 MK := tmp/$(package).mk
41 parseSpec: CFLAGS := -g -Wall -D_GNU_SOURCE
43 parseSpec: LDFLAGS := -lrpm -lrpmbuild
45 $(MK): $(SPECFILE) parseSpec .rpmmacros
47 ./parseSpec $(RPMFLAGS) $(SPECFILE) > $@
49 # Defines SOURCES, SRPM, RPMS
56 # Get rid of any extensions
58 $(patsubst %.tar.bz2,%, \
59 $(patsubst %.tar.gz,%, \
62 $(patsubst %.tar,%,$(1))))))
64 SOURCEDIRS := $(call stripext,$(SOURCES))
66 # Thierry - Jan 29 2007
67 # Allow different modules to have different CVSROOT
68 # and/or to be extracted from their SVNPATH
70 # is there a single module ? to mimick cvs export -d behaviour
71 MULTI_MODULE := $(word 2,$(MODULE))
72 ifeq "$(MULTI_MODULE)" ""
73 # single module: do as before
76 $(if $($(package)-SVNPATH),\
77 cd SOURCES && svn export $($(package)-SVNPATH) $(package),\
78 cd SOURCES && cvs -d $(CVSROOT) export -r $(TAG) -d $(package) $(MODULE))
80 # multiple modules : iterate
82 mkdir -p SOURCES/$(package) && cd SOURCES/$(package) && (\
83 $(foreach module,$(MODULE),\
84 $(if $($(module)-SVNPATH), \
85 svn export $($(module)-SVNPATH) $(module);, \
86 cvs -d $(if $($(module)-CVSROOT),$($(module)-CVSROOT),$(CVSROOT)) export -r $(TAG) $(module);\
90 # Make a hard-linked copy of the exported directory for each Source
91 # defined in the spec file. However, our convention is that there
92 # should be only one Source file and one CVS module per RPM. It's okay
93 # if the CVS module consists of multiple directories, as long as the
94 # spec file knows what's going on.
95 $(SOURCEDIRS): SOURCES/$(package)
98 .SECONDARY: SOURCES/$(package) $(SOURCEDIRS)
101 SOURCES/%.tar.bz2: SOURCES/%
102 tar cpjf $@ -C SOURCES $*
104 SOURCES/%.tar.gz: SOURCES/%
105 tar cpzf $@ -C SOURCES $*
107 SOURCES/%.tgz: SOURCES/%
108 tar cpzf $@ -C SOURCES $*
110 SOURCES/%.zip: SOURCES/%
111 cd SOURCES && zip -r ../$@ $*
113 SOURCES/%.tar: SOURCES/%
114 tar cpf $@ -C SOURCES $*
123 $(RPMS): $(SPECFILE) $(SOURCES) .rpmbuild.sh
125 $(RPMBUILD) $(RPMFLAGS) -bb $<
127 # Make the rest of the RPMS depend on the first one since building one
129 ifneq ($(words $(RPMS)),1)
130 $(wordlist 2,$(words $(RPMS)),$(RPMS)): $(firstword $(RPMS))
134 $(SRPM): $(SPECFILE) $(SOURCES) .rpmbuild.sh
136 $(RPMBUILD) $(RPMFLAGS) -bs $<
138 # Base rpmbuild in the current directory
140 echo "%_topdir $(HOME)" > $@
141 echo "%_tmppath $(HOME)/tmp" >> $@
144 echo "# GENERATED BY Rules.mk" > $@
145 echo 'export HOME=$(PWD)' >> $@
146 echo "# There must be a more clever way to pass all args to rpmbuild!" >> $@
147 echo 'rpmbuild $$1 $$2 $$3 $$4 $$5 $$6' >> $@
148 chmod 755 .rpmbuild.sh
150 # Remove files generated by this package
154 $(patsubst SOURCES/%,BUILD/%,$(SOURCEDIRS)) \
155 $(SOURCES) $(SOURCEDIRS) SOURCES/$(package) \
160 #################### convenience, for debugging only
161 # make +foo : prints the value of $(foo)
162 # make ++foo : idem but verbose, i.e. foo=$(foo)
163 ++%: varname=$(subst +,,$@)
165 @echo $(varname)=$($(varname))
166 +%: varname=$(subst +,,$@)