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)" >> $@
38 cvs -d $(if $($(package)-CVSROOT),$($(package)-CVSROOT),$(CVSROOT)) checkout -r $(TAG) -p $(_MAINMODULE)/$(SPEC) >> $@; \
42 svn cat $(if $($(package)-SVNPATAH),$($(package)-SVNPATH),$(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 && (\
85 $(if $(CVSROOT), cvs -d $(if $($(package)-CVSROOT),$($(package)-CVSROOT),$(CVSROOT)) export -r $(TAG) -d $(package) $(MODULE);) \
86 $(if $(SVNPATH), svn export $(if $($(package)-SVNPATH),$($(package)-SVNPATH),$(SVNPATH))/$(MODULE)/$(TAG) $(package) ;) \
89 # multiple modules : iterate
91 mkdir -p SOURCES/$(package) && cd SOURCES/$(package) && (\
92 $(foreach module,$(MODULE),\
93 $(if $(CVSROOT), cvs -d $(if $($(module)-CVSROOT),$($(module)-CVSROOT),$(CVSROOT)) export -r $(TAG) $(module);)\
94 $(if $(SVNPATH), svn export $(if $($(module)-SVNPATH),$($(module)-SVNPATH),$(SVNPATH))/$(module)/$(TAG) $(module);)\
99 # Make a hard-linked copy of the exported directory for each Source
100 # defined in the spec file. However, our convention is that there
101 # should be only one Source file and one CVS module per RPM. It's okay
102 # if the CVS module consists of multiple directories, as long as the
103 # spec file knows what's going on.
104 $(SOURCEDIRS): SOURCES/$(package)
107 .SECONDARY: SOURCES/$(package) $(SOURCEDIRS)
110 SOURCES/%.tar.bz2: SOURCES/%
111 tar cpjf $@ -C SOURCES $*
113 SOURCES/%.tar.gz: SOURCES/%
114 tar cpzf $@ -C SOURCES $*
116 SOURCES/%.tgz: SOURCES/%
117 tar cpzf $@ -C SOURCES $*
119 SOURCES/%.zip: SOURCES/%
120 cd SOURCES && zip -r ../$@ $*
122 SOURCES/%.tar: SOURCES/%
123 tar cpf $@ -C SOURCES $*
132 $(RPMS): $(SPECFILE) $(SOURCES)
134 $(RPMBUILD) $(RPMFLAGS) -bb $<
136 # Make the rest of the RPMS depend on the first one since building one
138 ifneq ($(words $(RPMS)),1)
139 $(wordlist 2,$(words $(RPMS)),$(RPMS)): $(firstword $(RPMS))
143 $(SRPM): $(SPECFILE) $(SOURCES)
145 $(RPMBUILD) $(RPMFLAGS) -bs $<
147 # Base rpmbuild in the current directory
149 echo "%_topdir $(HOME)" > $@
150 echo "%_tmppath $(HOME)/tmp" >> $@
152 # Remove files generated by this package
156 $(patsubst SOURCES/%,BUILD/%,$(SOURCEDIRS)) \
157 $(SOURCES) $(SOURCEDIRS) SOURCES/$(package) \
162 #################### convenience, for debugging only
163 # make +foo : prints the value of $(foo)
164 # make ++foo : idem but verbose, i.e. foo=$(foo)
165 ++%: varname=$(subst +,,$@)
167 @echo $(varname)=$($(varname))
168 +%: varname=$(subst +,,$@)