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.37 2007/09/10 22:24:20 mef Exp $
10 # Base rpmbuild in the current directory
11 export HOME := $(shell pwd)
12 export CVSROOT CVS_RSH
18 SPECFILE := SPECS/$(notdir $(SPEC))
19 MULTI_MODULE := $(word 2,$(MODULE))
20 # is there a single module ? to mimick cvs export -d behaviour
21 ifeq "$(MULTI_MODULE)" ""
22 _MAINMODULE := $(MODULE)
24 _MAINMODULE := $(firstword $(MODULE))
29 echo "%define pldistro $(PLDISTRO)" > $@
31 # Define date for untagged builds
32 echo "%define date $(shell date +%Y.%m.%d)" >> $@
34 # Define cvstag for tagged builds
35 echo "%define cvstag $(TAG)" >> $@
37 $(if $($(package)-CVSROOT), cvs -d $($(package)-CVSROOT) checkout -r $(TAG) -p $(_MAINMODULE)/$(SPEC) >> $@; ,\
38 $(if $($(package)-SVNPATH), svn cat $($(package)-SVNPATH)/$(_MAINMODULE)/$(TAG)/$(SPEC) >> $@; ,\
39 $(if $(CVSROOT), cvs -d $(CVSROOT) checkout -r $(TAG) -p $(_MAINMODULE)/$(SPEC) >> $@; ,\
40 $(if $(SVNPATH), svn cat $(SVNPATH)/$(_MAINMODULE)/$(TAG)/$(SPEC) >> $@; ) \
46 # Parse spec file into Makefile fragment
49 MK := tmp/$(package).mk
51 parseSpec: CFLAGS := -g -Wall -D_GNU_SOURCE
53 parseSpec: LDFLAGS := -lrpm -lrpmbuild
55 $(MK): $(SPECFILE) parseSpec .rpmmacros
57 ./parseSpec $(RPMFLAGS) $(SPECFILE) > $@
59 # Defines SOURCES, SRPM, RPMS
66 # Get rid of any extensions
68 $(patsubst %.tar.bz2,%, \
69 $(patsubst %.tar.gz,%, \
72 $(patsubst %.tar,%,$(1))))))
74 SOURCEDIRS := $(call stripext,$(SOURCES))
76 # Thierry - Jan 29 2007
77 # Allow different modules to have different CVSROOT
78 # and/or to be extracted from their SVNPATH
80 # is there a single module ? to mimick cvs export -d behaviour
81 ifeq "$(MULTI_MODULE)" ""
82 # single module: do as before
84 mkdir -p SOURCES && cd SOURCES && \
86 $(if $($(package)-CVSROOT), cvs -d $($(package)-CVSROOT) export -r $(TAG) -d $(package) $(MODULE); ,\
87 $(if $($(package)-SVNPATH), svn export $($(package)-SVNPATH)/$(MODULE)/$(TAG) $(package) ; ,\
88 $(if $(CVSROOT), cvs -d $(CVSROOT) export -r $(TAG) -d $(package) $(MODULE); ,\
89 $(if $(SVNPATH), svn export $(SVNPATH)/$(MODULE)/$(TAG) $(package) ;) \
95 # multiple modules : iterate
97 mkdir -p SOURCES/$(package) && cd SOURCES/$(package) && \
98 $(foreach module,$(MODULE),\
99 $(if $($(module)-CVSROOT), cvs -d $($(module)-CVSROOT) export -r $(TAG) -d $(module) $(module); ,\
100 $(if $($(module)-SVNPATH), svn export $($(module)-SVNPATH)/$(module)/$(TAG) $(module) ; ,\
101 $(if $(CVSROOT), cvs -d $(CVSROOT) export -r $(TAG) -d $(module) $(module); ,\
102 $(if $(SVNPATH), svn export $(SVNPATH)/$(module)/$(TAG) $(module) ;) \
109 # Make a hard-linked copy of the exported directory for each Source
110 # defined in the spec file. However, our convention is that there
111 # should be only one Source file and one CVS module per RPM. It's okay
112 # if the CVS module consists of multiple directories, as long as the
113 # spec file knows what's going on.
114 $(SOURCEDIRS): SOURCES/$(package)
117 .SECONDARY: SOURCES/$(package) $(SOURCEDIRS)
120 SOURCES/%.tar.bz2: SOURCES/%
121 tar cpjf $@ -C SOURCES $*
123 SOURCES/%.tar.gz: SOURCES/%
124 tar cpzf $@ -C SOURCES $*
126 SOURCES/%.tgz: SOURCES/%
127 tar cpzf $@ -C SOURCES $*
129 SOURCES/%.zip: SOURCES/%
130 cd SOURCES && zip -r ../$@ $*
132 SOURCES/%.tar: SOURCES/%
133 tar cpf $@ -C SOURCES $*
142 $(RPMS): $(SPECFILE) $(SOURCES)
144 $(RPMBUILD) $(RPMFLAGS) -bb $<
146 # Make the rest of the RPMS depend on the first one since building one
148 ifneq ($(words $(RPMS)),1)
149 $(wordlist 2,$(words $(RPMS)),$(RPMS)): $(firstword $(RPMS))
153 $(SRPM): $(SPECFILE) $(SOURCES)
155 $(RPMBUILD) $(RPMFLAGS) -bs $<
157 # Base rpmbuild in the current directory
159 echo "%_topdir $(HOME)" > $@
160 echo "%_tmppath $(HOME)/tmp" >> $@
162 # Remove files generated by this package
166 $(patsubst SOURCES/%,BUILD/%,$(SOURCEDIRS)) \
167 $(SOURCES) $(SOURCEDIRS) SOURCES/$(package) \
172 #################### convenience, for debugging only
173 # make +foo : prints the value of $(foo)
174 # make ++foo : idem but verbose, i.e. foo=$(foo)
175 ++%: varname=$(subst +,,$@)
177 @echo $(varname)=$($(varname))
178 +%: varname=$(subst +,,$@)