- building one RPM builds the rest, prevent make -j from running two
[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.19 2006/03/08 21:25:46 mlhuang 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 endif
27         cvs -d $(CVSROOT) checkout -r $(TAG) -p $(SPEC) >> $@
28
29 #
30 # Parse spec file into Makefile fragment
31 #
32
33 MK := tmp/$(package).mk
34
35 parseSpec: CFLAGS := -g -Wall
36
37 parseSpec: LDFLAGS := -lrpm -lrpmbuild
38
39 $(MK): $(SPECFILE) parseSpec .rpmmacros
40         mkdir -p tmp
41         ./parseSpec $(SPECFILE) > $@
42
43 # Defines SOURCES, SRPM, RPMS
44 include $(MK)
45
46 #
47 # Generate tarball(s)
48 #
49
50 # Get rid of any extensions
51 stripext = \
52 $(patsubst %.tar.bz2,%, \
53 $(patsubst %.tar.gz,%, \
54 $(patsubst %.tgz,%, \
55 $(patsubst %.zip,%, \
56 $(patsubst %.tar,%,$(1))))))
57
58 SOURCEDIRS := $(call stripext,$(SOURCES))
59
60 SOURCES/$(MODULE):
61         mkdir -p SOURCES
62         cd SOURCES && cvs -d $(CVSROOT) export -r $(TAG) $(MODULE)
63
64 # Make a hard-linked copy of the exported directory for each Source
65 # defined in the spec file. However, our convention is that there
66 # should be only one Source file and one CVS module per RPM. It's okay
67 # if the CVS module consists of multiple directories, as long as the
68 # spec file knows what's going on.
69 $(SOURCEDIRS): SOURCES/$(MODULE)
70         cp -rl $< $@
71
72 .SECONDARY: SOURCES/$(MODULE) $(SOURCEDIRS)
73
74 # Generate tarballs
75 SOURCES/%.tar.bz2: SOURCES/%
76         tar cpjf $@ -C SOURCES $*
77
78 SOURCES/%.tar.gz: SOURCES/%
79         tar cpzf $@ -C SOURCES $*
80
81 SOURCES/%.tgz: SOURCES/%
82         tar cpzf $@ -C SOURCES $*
83
84 SOURCES/%.zip: SOURCES/%
85         cd SOURCES && zip -r ../$@ $*
86
87 SOURCES/%.tar: SOURCES/%
88         tar cpf $@ -C SOURCES $*
89
90 #
91 # Build
92 #
93
94 all: $(RPMS) $(SRPM)
95
96 # Build RPMS
97 $(RPMS): $(SPECFILE) $(SOURCES) .rpmmacros
98         mkdir -p BUILD RPMS
99         $(RPMBUILD) $(RPMFLAGS) -bb $<
100
101 # Make the rest of the RPMS depend on the first one since building one
102 # builds them all.
103 ifneq ($(words $(RPMS)),1)
104 $(wordlist 2,$(words $(RPMS)),$(RPMS)): $(firstword $(RPMS))
105 endif
106
107 # Build SRPM
108 $(SRPM): $(SPECFILE) $(SOURCES) .rpmmacros
109         mkdir -p SRPMS
110         rpmbuild $(RPMFLAGS) -bs $<
111
112 # Base rpmbuild in the current directory
113 .rpmmacros:
114         echo "%_topdir $(HOME)" > $@
115         echo "%_tmppath $(HOME)/tmp" >> $@
116
117 # Remove files generated by this package
118 clean:
119         rm -rf \
120         $(RPMS) $(SRPM) \
121         $(patsubst SOURCES/%,BUILD/%,$(SOURCEDIRS)) \
122         $(SOURCES) $(SOURCEDIRS) SOURCES/$(MODULE) \
123         $(MK) $(SPECFILE) \
124         tmp
125
126 .PHONY: all clean