oops - reverting accidental checkin
[build.git] / Rules.mk
1 #
2 # PlanetLab RPM generation
3 #
4 # Mark Huang <mlhuang@cs.princeton.edu>
5 # Copyright (C) 2003-2006 The Trustees of Princeton University
6 #
7 # $Id: Rules.mk,v 1.27 2007/01/29 19:18:45 thierry Exp $
8 #
9
10 # Base rpmbuild in the current directory
11 export HOME := $(shell pwd)
12 export CVSROOT CVS_RSH
13
14 #
15 # Create spec file
16 #
17
18 SPECFILE := SPECS/$(notdir $(SPEC))
19
20 $(SPECFILE):
21         mkdir -p SPECS
22         echo "%define pldistro $(PLDISTRO)" > $@
23 ifeq ($(TAG),HEAD)
24         # Define date for untagged builds
25         echo "%define date $(shell date +%Y.%m.%d)" >> $@
26 else
27         # Define cvstag for tagged builds
28         echo "%define cvstag $(TAG)" >> $@
29 endif
30         cvs -d $(CVSROOT) checkout -r $(TAG) -p $(SPEC) >> $@
31
32 #
33 # Parse spec file into Makefile fragment
34 #
35
36 MK := tmp/$(package).mk
37
38 parseSpec: CFLAGS := -g -Wall
39
40 parseSpec: LDFLAGS := -lrpm -lrpmbuild
41
42 $(MK): $(SPECFILE) parseSpec .rpmmacros
43         mkdir -p tmp
44         ./parseSpec $(RPMFLAGS) $(SPECFILE) > $@
45
46 # Defines SOURCES, SRPM, RPMS
47 include $(MK)
48
49 #
50 # Generate tarball(s)
51 #
52
53 # Get rid of any extensions
54 stripext = \
55 $(patsubst %.tar.bz2,%, \
56 $(patsubst %.tar.gz,%, \
57 $(patsubst %.tgz,%, \
58 $(patsubst %.zip,%, \
59 $(patsubst %.tar,%,$(1))))))
60
61 SOURCEDIRS := $(call stripext,$(SOURCES))
62
63 # Thierry - Jan 29 2007
64 # Allow different modules to have  different CVSROOT's
65 #
66 # is there a single module ? to mimick cvs export -d behaviour
67 MULTI_MODULE := $(word 2,$(MODULE))
68 ifeq "$(MULTI_MODULE)" ""
69 # single module: do as before
70 SOURCES/$(package):
71         mkdir -p SOURCES
72         cd SOURCES && cvs -d $(CVSROOT) export -r $(TAG) -d $(package) $(MODULE)
73 else
74 # multiple modules : iterate 
75 SOURCES/$(package):
76         mkdir -p SOURCES/$(package) && cd SOURCES/$(package) && (\
77         $(foreach module,$(MODULE),\
78           cvs -d $(if $($(module)-CVSROOT),$($(module)-CVSROOT),$(CVSROOT)) export -r $(TAG)  $(module);\
79          ))
80 endif
81
82 # Make a hard-linked copy of the exported directory for each Source
83 # defined in the spec file. However, our convention is that there
84 # should be only one Source file and one CVS module per RPM. It's okay
85 # if the CVS module consists of multiple directories, as long as the
86 # spec file knows what's going on.
87 $(SOURCEDIRS): SOURCES/$(package)
88         cp -rl $< $@
89
90 .SECONDARY: SOURCES/$(package) $(SOURCEDIRS)
91
92 # Generate tarballs
93 SOURCES/%.tar.bz2: SOURCES/%
94         tar cpjf $@ -C SOURCES $*
95
96 SOURCES/%.tar.gz: SOURCES/%
97         tar cpzf $@ -C SOURCES $*
98
99 SOURCES/%.tgz: SOURCES/%
100         tar cpzf $@ -C SOURCES $*
101
102 SOURCES/%.zip: SOURCES/%
103         cd SOURCES && zip -r ../$@ $*
104
105 SOURCES/%.tar: SOURCES/%
106         tar cpf $@ -C SOURCES $*
107
108 #
109 # Build
110 #
111
112 all: $(RPMS) $(SRPM)
113
114 # Build RPMS
115 $(RPMS): $(SPECFILE) $(SOURCES)
116         mkdir -p BUILD RPMS
117         $(RPMBUILD) $(RPMFLAGS) -bb $<
118
119 # Make the rest of the RPMS depend on the first one since building one
120 # builds them all.
121 ifneq ($(words $(RPMS)),1)
122 $(wordlist 2,$(words $(RPMS)),$(RPMS)): $(firstword $(RPMS))
123 endif
124
125 # Build SRPM
126 $(SRPM): $(SPECFILE) $(SOURCES)
127         mkdir -p SRPMS
128         rpmbuild $(RPMFLAGS) -bs $<
129
130 # Base rpmbuild in the current directory
131 .rpmmacros:
132         echo "%_topdir $(HOME)" > $@
133         echo "%_tmppath $(HOME)/tmp" >> $@
134
135 # Remove files generated by this package
136 clean:
137         rm -rf \
138         $(RPMS) $(SRPM) \
139         $(patsubst SOURCES/%,BUILD/%,$(SOURCEDIRS)) \
140         $(SOURCES) $(SOURCEDIRS) SOURCES/$(package) \
141         $(MK) $(SPECFILE)
142
143 .PHONY: all clean
144
145 #################### convenience, for debugging only
146 # make +foo : prints the value of $(foo)
147 # make ++foo : idem but verbose, i.e. foo=$(foo)
148 ++%: varname=$(subst +,,$@)
149 ++%:
150         @echo $(varname)=$($(varname))
151 +%: varname=$(subst +,,$@)
152 +%:
153         @echo $($(varname))