pass parseSpec
[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.24 2006/07/24 19:23:57 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 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 SOURCES/$(package):
64         mkdir -p SOURCES
65         cd SOURCES && cvs -d $(CVSROOT) export -r $(TAG) -d $(package) $(MODULE)
66
67 # Make a hard-linked copy of the exported directory for each Source
68 # defined in the spec file. However, our convention is that there
69 # should be only one Source file and one CVS module per RPM. It's okay
70 # if the CVS module consists of multiple directories, as long as the
71 # spec file knows what's going on.
72 $(SOURCEDIRS): SOURCES/$(package)
73         cp -rl $< $@
74
75 .SECONDARY: SOURCES/$(package) $(SOURCEDIRS)
76
77 # Generate tarballs
78 SOURCES/%.tar.bz2: SOURCES/%
79         tar cpjf $@ -C SOURCES $*
80
81 SOURCES/%.tar.gz: SOURCES/%
82         tar cpzf $@ -C SOURCES $*
83
84 SOURCES/%.tgz: SOURCES/%
85         tar cpzf $@ -C SOURCES $*
86
87 SOURCES/%.zip: SOURCES/%
88         cd SOURCES && zip -r ../$@ $*
89
90 SOURCES/%.tar: SOURCES/%
91         tar cpf $@ -C SOURCES $*
92
93 #
94 # Build
95 #
96
97 all: $(RPMS) $(SRPM)
98
99 # Build RPMS
100 $(RPMS): $(SPECFILE) $(SOURCES) .rpmmacros
101         mkdir -p BUILD RPMS
102         $(RPMBUILD) $(RPMFLAGS) -bb $<
103
104 # Make the rest of the RPMS depend on the first one since building one
105 # builds them all.
106 ifneq ($(words $(RPMS)),1)
107 $(wordlist 2,$(words $(RPMS)),$(RPMS)): $(firstword $(RPMS))
108 endif
109
110 # Build SRPM
111 $(SRPM): $(SPECFILE) $(SOURCES) .rpmmacros
112         mkdir -p SRPMS
113         rpmbuild $(RPMFLAGS) -bs $<
114
115 # Base rpmbuild in the current directory
116 .rpmmacros:
117         echo "%_topdir $(HOME)" > $@
118         echo "%_tmppath $(HOME)/tmp" >> $@
119
120 # Remove files generated by this package
121 clean:
122         rm -rf \
123         $(RPMS) $(SRPM) \
124         $(patsubst SOURCES/%,BUILD/%,$(SOURCEDIRS)) \
125         $(SOURCES) $(SOURCEDIRS) SOURCES/$(package) \
126         $(MK) $(SPECFILE)
127
128 .PHONY: all clean