fix default build from svn info
[build.git] / Makefile
1 #
2 # Thierry Parmentelat - INRIA Sophia Antipolis 
3 #
4 ### $Id$
5
6 ####################
7 # invocation:
8 #
9 # (*) make stage1=true
10 #     this extracts all specfiles and computes .mk from specfiles
11 #     you need to specify PLDISTRO here if relevant - see below
12 # (*) make help
13 #     for more info on how to invoke this stuff
14 #
15 #################### (fedora) distributions
16 #
17 # (*) as of nov. 2007, myplc-devel is deprecated
18 # (*) instead, we create a fresh vserver that holds required tools (see e.g. planetlab-devel.lst)
19 # (*) the build uses the current fedora version as a target for the produced images
20 # (*) so you simply need to create a fedora 8 build image for building fedora-8 images 
21 #     
22 #################### (planetlab) distributions
23 #
24 # (*) see README-pldistros.txt
25 # (*) then you need to run 
26 #     make stage1=true PLDISTRO=onelab
27 #
28 #################### 
29 # This build deals with 3 kinds of objects
30
31 # (*) packages are named upon the RPM name; they are mostly lowercase
32 #     Add a package to ALL if you want it built as part of the default set.
33 # (*) modules are named after the subversion tree; as of this writing their names 
34 #     are mostly mixed case like MyPLC or VserverReference
35 # (*) rpms are named in the spec files. A package typically defines several rpms;
36 #     rpms are used for defining DEPEND-DEVEL-RPMS. See also package.rpmnames
37
38 #################### packages
39 # basics: how to build a package - you need/may define the following variables
40
41 # (*) package-MODULES
42 #     a package needs one or several modules to build. 
43 #     to this end, define 
44 # (*) package-SPEC
45 #     the package's specfile; this is relative to the FIRST module in package-MODULES
46 #     see 'codebase' below
47 #
48 # Optional:
49 #
50 # (*) package-SPECVARS
51 #     space-separated list of spec variable definitions, where you can reference make variable that relate to 
52 #     packages defined BEFORE the current one (note: you should use = - as opposed to := - to define these)
53 #     e.g. mydriver-SPECVARS = foo=$(kernel-rpm-release) 
54 #     would let you use the %release from the kernel's package when rpmbuild'ing mydriver - see automatic below
55 # (*) package-DEPEND-PACKAGES
56 #     a set of *packages* that this package depends on
57 # (*) package-DEPEND-DEVEL-RPMS
58 #     a set of *rpms* that the build will rpm-install before building <package>
59 # (*) package-DEPEND-FILES
60 #     a set of files that the package depends on - and that make needs to know about
61 #     if this contains RPMS/yumgroups.xml, then the toplevel RPMS's index 
62 #     is refreshed with createrepo prior to running rpmbuild
63 # (*) package-RPMFLAGS: Miscellaneous RPM flags
64 # (*) package-RPMBUILD: If not rpmbuild - mostly used for sudo'ing rpmbuild
65 # (*) package-BUILD-FROM-SRPM: set this to any non-empty value, if your package is able to produce 
66 #     a source rpms by running 'make srpm'
67 # (*) package-RPMDATE: set this to any non-empty value to get the rpm package's release field hold the current date
68 #     this is useful for container packages, like e.g. bootstrapfs or vserver, that contains much more than the
69 #     correspondng module
70 #
71 #################### modules
72 # Required information about the various modules (set this in e.g. planetlab-tags.mk)
73 #
74 # (*) module-SVNPATH
75 #     the complete path where this module lies; 
76 #     you can specify the trunk or a given tag with this variable
77
78 # OR if the module is managed under cvs (will be obsoleted)
79
80 # (*) module-CVSROOT
81 # (*) module-TAG
82 #
83 #################### automatic variables
84 #
85 # the build defines some make variables that are extracted from spec files
86 # see for example
87 # (*)  $ make ulogd-pkginfo
88 #        to see the list f variables attached to a given package
89 # (*)  $ make kernel-devel-rpminfo
90 #        to see the list of variables attached to a given rpm
91 #
92 ####################
93
94 # exported to spec files as plrelease
95 PLANETLAB_RELEASE = 4.2
96
97 #
98 # Default values
99 #
100 # minimal compat with macos, just so this does not complain 
101 HOSTARCH := $(shell uname -i 2> /dev/null || uname -m 2> /dev/null)
102 DISTRO := $(shell ./getdistro.sh)
103 RELEASE := $(shell ./getrelease.sh)
104 DISTRONAME := $(shell ./getdistroname.sh)
105 RPM-INSTALL-DEVEL := rpm --force -Uvh
106 # cannot force rpm -e
107 RPM-UNINSTALL-DEVEL := rpm -e
108
109 #################### Makefile
110 # Default target
111 all:
112 .PHONY:all
113
114 ### default values
115 PLDISTRO := planetlab
116 RPMBUILD := rpmbuild
117 export CVS_RSH := ssh
118
119 ########## pldistro.mk holds PLDISTRO - it is generated at stage1 (see below)
120 ifeq "$(stage1)" ""
121 include pldistro.mk
122 endif
123
124 #################### include onelab.mk
125 # describes the set of components
126 PLDISTROCONTENTS := $(PLDISTRO).mk
127 include $(PLDISTROCONTENTS)
128
129 #################### include <pldistro>-tags.mk
130 # describes where to fetch components, and the related tags if using cvs
131 PLDISTROTAGS := $(PLDISTRO)-tags.mk
132 include $(PLDISTROTAGS)
133
134 # this used to be set in the -tags.mk files, but that turned out to require
135 # error-prone duplicate changes 
136 # so now the nightly build script sets this to what it is currently using
137 # we set a default in case we run the build manually:
138 # if the local directory was svn checked out, then use the corresponding URL
139 svn-info-url-line := $(shell svn info 2> /dev/null | grep URL:)
140 default-build-SVNPATH := $(lastword $(svn-info-url-line))
141 # otherwise, use this hard-coded default
142 ifeq "$(default-build-SVNPATH)" ""
143 default-build-SVNPATH := http://svn.planet-lab.org/svn/build/trunk
144 endif
145 # use default if necessary
146 build-SVNPATH ?= $(default-build-SVNPATH)
147
148 ########## stage1 and stage1iter
149 # extract specs and compute .mk files by running 
150 # make stage1=true
151 # entering stage1, we compute all the spec files
152 # then we use stage1iter to compute the .mk iteratively, 
153 # ensuring that the n-1 first makefiles are loaded when creating the n-th one
154 # when stage1iter is set, it is supposed to be an index (starting at 1) in $(ALL)
155
156 ALLMKS := $(foreach package, $(ALL), MAKE/$(package).mk)
157
158 ### stage1iter : need some arithmetic, see
159 # http://www.cmcrossroads.com/articles/ask-mr.-make/learning-gnu-make-functions-with-arithmetic.html
160 ifneq "$(stage1iter)" ""
161 # the first n packages
162 packages := $(wordlist 1,$(words $(stage1iter)),$(ALL))
163 # the n-th package
164 package := $(word $(words $(packages)),$(packages))
165 # the n-1 first packages
166 stage1iter_1 := $(wordlist 2,$(words $(stage1iter)),$(stage1iter))
167 previous := $(wordlist 1,$(words $(stage1iter_1)),$(ALL))
168 previousmks := $(foreach package,$(previous),MAKE/$(package).mk)
169 include $(previousmks)
170 all: verbose
171 verbose:
172         @echo "========== stage1iter : $(package)"
173 #       @echo "stage1iter : included .mk files : $(previousmks)"
174 all: $($(package).specpath)
175 all: MAKE/$(package).mk
176 else
177 ### stage1
178 ifneq "$(stage1)" ""
179 all : verbose
180 verbose :
181         @echo "========== stage1"
182 all : spec2make
183 all : .rpmmacros
184 # specs and makes are done sequentially by stage1iter
185 all : stage1iter
186 stage1iter:
187         arg=""; for n in $(ALL) ; do arg="$$arg x"; $(MAKE) --no-print-directory stage1iter="$$arg"; done
188 ### regular make
189 else
190 ### once .mks are OK, you can run make normally
191 include $(ALLMKS)
192 #all : tarballs
193 #all : sources
194 #all : codebases
195 #all : rpms
196 #all : srpms
197 # mention $(ALL) here rather than rpms 
198 # this is because the inter-package dependencies are expressed like
199 # util-vserver: util-python
200 all: rpms
201 all: repo
202 endif
203 endif
204
205 ### yumgroups.xml : compute from all known .pkgs files
206 RPMS/yumgroups.xml: 
207         mkdir -p RPMS
208         ./yumgroups.sh $(PLDISTRO) > $@
209
210 createrepo = createrepo --quiet -g yumgroups.xml RPMS/ 
211
212 repo: RPMS/yumgroups.xml
213         $(createrepo)
214
215 .PHONY: repo
216
217 ####################
218 # notes: 
219 # * to make configuration easier, we always use the first module's
220 # definitions (CVSROOT,TAG, or SVNPATH) to extract the spec file
221 # * for the same reason, in case cvs is used, the first module name is added to 
222 # $(package)-SPEC - otherwise the cvs modules have to define spec as 
223 # <module>/<module>.spec while svn modules just define it as <module>.spec
224 #
225 define stage1_variables
226 $(1).spec = $(notdir $($(1)-SPEC))
227 $(1).specpath = SPECS/$(1).spec
228 $(1).module = $(firstword $($(1)-MODULES))
229 $(1)-SVNPATH = $(strip $($(1)-SVNPATH))
230 endef
231
232 $(foreach package, $(ALL), $(eval $(call stage1_variables,$(package))))
233
234 #
235 # for each package, compute whether we need to set date 
236 # the heuristic is that we mention the date as part of the rpm release flag if
237 # (*) the package has requested it by setting package-RPMDATE (container packages should do that)
238 # (*) or SVNPATH contains 'trunk' or 'branches' 
239
240 define package_hasdate
241 $(1).has-date = $(if $($(1)-RPMDATE),yes, \
242                   $(if $($($(1).module)-SVNPATH), \
243                      $(if $(findstring /trunk,$($($(1).module)-SVNPATH)),yes, \
244                         $(if $(findstring /branches,$($($(1).module)-SVNPATH)),yes,)), \
245                      $(if $(findstring HEAD,$($($(1).module)-TAG)),yes,)))
246 endef
247
248 $(foreach package, $(ALL), $(eval $(call package_hasdate,$(package))))
249
250 ### the common header for generated specfiles
251 # useful when trying new specfiles manually
252 header.spec:
253         (echo -n "# Generated by planetlab build from $($(1)-SPEC) on " ; date) > $@
254         echo "%define distro $(DISTRO)" >> $@
255         echo "%define distrorelease $(RELEASE)" >> $@
256         echo "%define distroname $(DISTRONAME)" >> $@
257         echo "%define pldistro $(PLDISTRO)" >> $@
258         echo "%define plrelease $(PLANETLAB_RELEASE)" >> $@
259
260 ### extract spec file from scm
261 define target_spec
262 $($(1).specpath): header.spec
263         mkdir -p SPECS
264         cat header.spec > $($(1).specpath)
265         $(if $($(1).has-date),echo "%define date $(shell date +%Y.%m.%d)" >> $($(1).specpath),)
266         $(if $($(1)-SPECVARS), \
267           $(foreach line,$($(1)-SPECVARS), \
268             echo "%define" $(word 1,$(subst =, ,$(line))) "$(word 2,$(subst =, ,$(line)))" >> $($(1).specpath) ;))
269         echo "# included from $($(1)-SPEC)" >> $($(1).specpath)
270         $(if $($($(1).module)-SVNPATH),\
271           svn cat $($($(1).module)-SVNPATH)/$($(1)-SPEC) >> $($(1).specpath) || rm $($(1).specpath),\
272           cvs -d $($($(1).module)-CVSROOT) checkout \
273               -r $($($(1).module)-TAG) \
274               -p $($(1).module)/$($(1)-SPEC) >> $($(1).specpath))
275 endef
276
277 $(foreach package,$(ALL),$(eval $(call target_spec,$(package))))
278
279 ###
280 # Base rpmbuild in the current directory
281 # issues on fedora 8 : see the following posts
282 # http://forums.fedoraforum.org/showthread.php?t=39625 - and more specifically post#6
283 # https://www.redhat.com/archives/fedora-devel-list/2007-November/msg00171.html
284 REALROOT=/build
285 FAKEROOT=/longbuildroot
286 PWD=$(shell /bin/pwd)
287 ifeq "$(PWD)" "$(REALROOT)"
288 export HOME := $(FAKEROOT)
289 else
290 export HOME := $(PWD)
291 endif
292 .rpmmacros:
293 ifeq "$(shell pwd)" "/build"
294         rm -f $(FAKEROOT) ; ln -s $(REALROOT) $(FAKEROOT)
295 endif
296         rm -f $@ 
297         echo "%_topdir $(HOME)" >> $@
298         echo "%_tmppath $(HOME)/tmp" >> $@
299         ./getrpmmacros.sh >> $@
300
301 ### this utility allows to extract various info from a spec file
302 ### and to define them in makefiles
303 spec2make: spec2make.c
304         $(CC) -g -Wall $< -o $@ -lrpm -lrpmbuild
305
306 ### run spec2make on the spec file and include the result
307 # usage: spec2make package
308 define target_mk
309 MAKE/$(1).mk: $($(1).specpath) spec2make .rpmmacros
310         mkdir -p MAKE
311         ./spec2make $($(1)-RPMFLAGS) $($(1).specpath) $(1) > MAKE/$(1).mk
312         @if [ -z MAKE/$(1).mk ] ; then rm MAKE/$(1).mk ; exit 1 ; fi
313 endef
314
315 $(foreach package,$(ALL),$(eval $(call target_mk,$(package))))
316
317 # stores PLDISTRO in a file
318 # this is done at stage1. later run wont get confused
319 pldistro.mk:
320         echo "PLDISTRO:=$(PLDISTRO)" > $@
321         echo "PLDISTROTAGS:=$(PLDISTROTAGS)" >> $@
322
323 savepldistro: pldistro.mk
324 .PHONY: savepldistro
325
326 # always refresh this
327 all: savepldistro
328
329 #################### regular make
330
331 define stage2_variables
332 ### devel dependencies
333 $(1).rpmbuild = $(if $($(1)-RPMBUILD),$($(1)-RPMBUILD),$(RPMBUILD)) $($(1)-RPMFLAGS)
334 $(1).all-devel-rpm-paths := $(foreach rpm,$($(1)-DEPEND-DEVEL-RPMS),$($(rpm).rpm-path))
335 $(1).depend-devel-packages := $(sort $(foreach rpm,$($(1)-DEPEND-DEVEL-RPMS),$($(rpm).package)))
336 ALL-DEVEL-RPMS += $($(1)-DEPEND-DEVEL-RPMS)
337 endef
338
339 $(foreach package,$(ALL),$(eval $(call stage2_variables,$(package))))
340 ALL-DEVEL-RPMS := $(sort $(ALL-DEVEL-RPMS))
341
342
343 ### pack sources into tarballs
344 ALLTARBALLS:= $(foreach package, $(ALL), $($(package).tarballs))
345 tarballs: $(ALLTARBALLS)
346         @echo $(words $(ALLTARBALLS)) source tarballs OK
347 .PHONY: tarballs
348
349 SOURCES/%.tar.bz2: SOURCES/%
350         tar chpjf $@ -C SOURCES $*
351
352 SOURCES/%.tar.gz: SOURCES/%
353         tar chpzf $@ -C SOURCES $*
354
355 SOURCES/%.tgz: SOURCES/%
356         tar chpzf $@ -C SOURCES $*
357
358 ##
359 URLS/%: url=$(subst @colon@,:,$(subst @slash@,/,$(notdir $@)))
360 URLS/%: basename=$(notdir $(url))
361 URLS/%: 
362         echo curl $(url) -o SOURCES/$(basename)
363         touch $@
364
365 ### the directory SOURCES/<package>-<version> is made 
366 # with a copy -rl from CODEBASES/<package>
367 # the former is $(package.source) and the latter is $(package.codebase)
368 ALLSOURCES:=$(foreach package, $(ALL), $($(package).source))
369 # so that make does not use the rule below directly for creating the tarball files
370 .SECONDARY: $(ALLSOURCES)
371
372 sources: $(ALLSOURCES)
373         @echo $(words $(ALLSOURCES)) versioned source trees OK
374 .PHONY: sources
375
376 define target_link_codebase_sources
377 $($(1).source): $($(1).codebase) ; mkdir -p SOURCES ; cp -rl $($(1).codebase) $($(1).source)
378 endef
379
380 $(foreach package,$(ALL),$(eval $(call target_link_codebase_sources,$(package))))
381
382 ### codebase extraction
383 ALLCODEBASES:=$(foreach package, $(ALL), $($(package).codebase))
384 # so that make does not use the rule below directly for creating the tarball files
385 .SECONDARY: $(ALLCODEBASES)
386
387 codebases : $(ALLCODEBASES)
388         @echo $(words $(ALLCODEBASES)) codebase OK
389 .PHONY: codebases
390
391 ### extract codebase 
392 # usage: extract_single_module package 
393 define extract_single_module
394         mkdir -p CODEBASES
395         $(if $($($(1).module)-SVNPATH), cd CODEBASES && svn export $($($(1).module)-SVNPATH) $(1), cd CODEBASES && cvs -d $($($(1).module)-CVSROOT) export -r $($($(1).module)-TAG) -d $(1) $($(1).module))
396 endef
397
398 # usage: extract_multi_module package 
399 define extract_multi_module
400         mkdir -p CODEBASES/$(1) && cd CODEBASES/$(1) && (\
401         $(foreach m,$($(1)-MODULES), $(if $($(m)-SVNPATH), svn export $($(m)-SVNPATH) $(m);, cvs -d $($(m)-CVSROOT) export -r $($(m)-TAG) $(m);)))
402 endef
403
404 CODEBASES/%: package=$(notdir $@)
405 CODEBASES/%: multi_module=$(word 2,$($(package)-MODULES))
406 CODEBASES/%: 
407         @(echo -n "XXXXXXXXXXXXXXX -- BEG CODEBASE $(package) : $@ " ; date)
408         $(if $(multi_module),\
409           $(call extract_multi_module,$(package)),\
410           $(call extract_single_module,$(package)))
411         @(echo -n "XXXXXXXXXXXXXXX -- END CODEBASE $(package) : $@ " ; date)
412
413 ### source rpms
414 ALLSRPMS:=$(foreach package,$(ALL),$($(package).srpm))
415 srpms: $(ALLSRPMS)
416         @echo $(words $(ALLSRPMS)) source rpms OK
417 .PHONY: srpms
418
419 # usage: target_source_rpm package
420 # select upon the package name, whether it contains srpm or not
421 define target_source_rpm 
422 ifeq "$($(1)-BUILD-FROM-SRPM)" ""
423 $($(1).srpm): $($(1).specpath) .rpmmacros $($(1).tarballs) 
424         mkdir -p BUILD SRPMS tmp
425         @(echo -n "XXXXXXXXXXXXXXX -- BEG SRPM $(1) (using SOURCES) " ; date)
426         $(if $($(1).all-devel-rpm-paths), $(RPM-INSTALL-DEVEL) $($(1).all-devel-rpm-paths))
427         $($(1).rpmbuild) -bs $($(1).specpath)
428         $(if $($(1)-DEPEND-DEVEL-RPMS), $(RPM-UNINSTALL-DEVEL) $($(1)-DEPEND-DEVEL-RPMS))
429         @(echo -n "XXXXXXXXXXXXXXX -- END SRPM $(1) " ; date)
430 else
431 $($(1).srpm): $($(1).specpath) .rpmmacros $($(1).codebase)
432         mkdir -p BUILD SRPMS tmp
433         @(echo -n "XXXXXXXXXXXXXXX -- BEG SRPM $(1) (using make srpm) " ; date)
434         $(if $($(1).all-devel-rpm-paths), $(RPM-INSTALL-DEVEL) $($(1).all-devel-rpm-paths))
435         make -C $($(1).codebase) srpm SPECFILE=$(HOME)/$($(1).specpath) && \
436            rm -f SRPMS/$(notdir $($(1).srpm)) && \
437            ln $($(1).codebase)/$(notdir $($(1).srpm)) SRPMS/$(notdir $($(1).srpm)) 
438         $(if $($(1)-DEPEND-DEVEL-RPMS), $(RPM-UNINSTALL-DEVEL) $($(1)-DEPEND-DEVEL-RPMS))
439         @(echo -n "XXXXXXXXXXXXXXX -- END SRPM $(1) " ; date)
440 endif
441 endef
442
443 $(foreach package,$(ALL),$(eval $(call target_source_rpm,$(package))))
444
445 ### binary rpms are made from source rpm
446 ALLRPMS:=$(foreach package,$(ALL),$($(package).rpms))
447 # same as above, mention $(ALL) and not $(ALLRPMS)
448 rpms: $(ALLRPMS)
449         @echo $(words $(ALLRPMS)) binary rpms OK
450 .PHONY: rpms
451
452 # use tmp dirs when building binary rpm so make remains idempotent 
453 # otherwise SOURCES/ or SPEC gets touched again - which leads to rebuilding
454 RPM-USE-TMP-DIRS = --define "_sourcedir $(HOME)/tmp" --define "_specdir $(HOME)/tmp"
455 RPM-USE-COMPILE-DIRS = --define "_sourcedir $(HOME)/COMPILE" --define "_specdir $(HOME)/COMPILE"
456
457 # usage: build_binary_rpm package
458 # xxx hacky - invoke createrepo if DEPEND-FILES mentions RPMS/yumgroups.xml
459 define target_binary_rpm 
460 $($(1).rpms): $($(1).srpm)
461         mkdir -p RPMS tmp
462         @(echo -n "XXXXXXXXXXXXXXX -- BEG RPM $(1) " ; date)
463         $(if $(findstring RPMS/yumgroups.xml,$($(1)-DEPEND-FILES)), $(createrepo) , )
464         $(if $($(1).all-devel-rpm-paths), $(RPM-INSTALL-DEVEL) $($(1).all-devel-rpm-paths))
465         $($(1).rpmbuild) --rebuild $(RPM-USE-TMP-DIRS) $($(1).srpm)
466         $(if $($(1)-DEPEND-DEVEL-RPMS), $(RPM-UNINSTALL-DEVEL) $($(1)-DEPEND-DEVEL-RPMS))
467         @(echo -n "XXXXXXXXXXXXXXX -- END RPM $(1) " ; date)
468 # for manual use only - in case we need to investigate the results of an rpmbuild
469 $(1)-compile: $($(1).srpm)
470         mkdir -p COMPILE tmp
471         @(echo -n "XXXXXXXXXXXXXXX -- BEG compile $(1) " ; date)
472         $(if $(findstring RPMS/yumgroups.xml,$($(1)-DEPEND-FILES)), $(createrepo) , )
473         $(if $($(1).all-devel-rpm-paths), $(RPM-INSTALL-DEVEL) $($(1).all-devel-rpm-paths))
474         $($(1).rpmbuild) --recompile $(RPM-USE-TMP-DIRS) $($(1).srpm)
475         $(if $($(1)-DEPEND-DEVEL-RPMS), $(RPM-UNINSTALL-DEVEL) $($(1)-DEPEND-DEVEL-RPMS))
476         @(echo -n "XXXXXXXXXXXXXXX -- END compile $(1) " ; date)
477 .PHONY: $(1)-compile
478 endef
479
480 $(foreach package,$(ALL),$(eval $(call target_binary_rpm,$(package))))
481 ### shorthand target
482 # e.g. make proper -> does propers rpms
483 # usage shorthand_target package
484 define target_shorthand 
485 $(1): $($(1).rpms)
486 .PHONY: $(1)
487 $(1)-spec: $($(1)-SPEC)
488 .PHONY: $(1)-spec
489 $(1)-mk: $($(1)-MK)
490 .PHONY: $(1)-mk
491 $(1)-tarball: $($(1).tarballs)
492 .PHONY: $(1)-tarball
493 $(1)-codebase: $($(1).codebase)
494 .PHONY: $(1)-source
495 $(1)-source: $($(1).source)
496 .PHONY: $(1)-codebase
497 $(1)-rpms: $($(1).rpms)
498 .PHONY: $(1)-rpms
499 $(1)-srpm: $($(1).srpm)
500 .PHONY: $(1)-srpm
501 endef
502
503 $(foreach package,$(ALL),$(eval $(call target_shorthand,$(package))))
504
505 ### file dependencies
506 define package_depends_on_file
507 $(1):$(2)
508 $($(1).srpm):$(2)
509 endef
510
511 define target_dependfiles
512 $(foreach file,$($(1)-DEPEND-FILES),$(eval $(call package_depends_on_file,$(1),$(file))))
513 endef
514
515 $(foreach package,$(ALL),$(eval $(call target_dependfiles,$(package))))
516
517 ### package dependencies
518 define package_depends_on_package
519 $(1):$(2)
520 $(1):$($(2).rpms)
521 $($(1).srpm):$($(2).rpms)
522 endef
523
524 define target_depends
525 $(foreach package,$($(1)-DEPEND-PACKAGES) $($(1).depend-devel-packages),$(eval $(call package_depends_on_package,$(1),$(package))))
526 endef
527
528 $(foreach package,$(ALL),$(eval $(call target_depends,$(package))))
529
530 ### clean target
531 # usage: target_clean package
532 define target_clean
533 $(1)-clean-codebase:
534         rm -rf $($(1).codebase)
535 .PHONY: $(1)-clean-codebase
536 CLEANS += $(1)-clean-codebase
537 $(1)-clean-source:
538         rm -rf $($(1).source)
539 .PHONY: $(1)-clean-source
540 CLEANS += $(1)-clean-source
541 $(1)-clean-tarball:
542         rm -rf $($(1).tarballs)
543 .PHONY: $(1)-clean-tarball
544 CLEANS += $(1)-clean-tarball
545 $(1)-clean-build:
546         rm -rf BUILD/$(notdir $($(1).source))
547 CLEANS += $(1)-clean-build
548 $(1)-clean-rpms:
549         rm -rf $($(1).rpms)
550 .PHONY: $(1)-clean-rpms
551 CLEANS += $(1)-clean-rpms
552 $(1)-clean-srpm:
553         rm -rf $($(1).srpm)
554 .PHONY: $(1)-clean-srpm
555 CLEANS += $(1)-clean-srpm
556 $(1)-codeclean: $(1)-clean-source $(1)-clean-tarball $(1)-clean-build $(1)-clean-rpms $(1)-clean-srpm
557 $(1)-clean: $(1)-clean-codebase $(1)-codeclean
558 .PHONY: $(1)-codeclean $(1)-clean 
559 $(1)-clean-spec:
560         rm -rf $($(1).specpath)
561 .PHONY: $(1)-clean-spec
562 $(1)-clean-make:
563         rm -rf MAKE/$(1).mk
564 .PHONY: $(1)-clean-make
565 $(1)-distclean: $(1)-distclean1 $(1)-distclean2
566 $(1)-distclean1: $(1)-clean-spec $(1)-clean-make
567 $(1)-distclean2: $(1)-clean
568 .PHONY: $(1)-distclean $(1)-distclean1 $(1)-distclean2
569 endef
570
571 $(foreach package,$(ALL),$(eval $(call target_clean,$(package))))
572
573 ### clean precisely
574 clean:
575         $(MAKE) $(CLEANS)
576 .PHONY: clean
577
578 clean-help:
579         @echo Available clean targets
580         @echo $(CLEANS)
581
582 ### brute force clean
583 distclean1:
584         rm -rf pldistro.mk .rpmmacros spec2make header.spec SPECS MAKE 
585 distclean2:
586         rm -rf CODEBASES SOURCES BUILD RPMS SRPMS tmp
587 distclean: distclean1 distclean2
588 .PHONY: distclean1 distclean2 distclean
589
590 develclean:
591         $(RPM-UNINSTALL-DEVEL) $(ALL-DEVEL-RPMS)
592
593 ####################
594 # gather build information for the 'About' page
595 # when run from crontab, INIT_CWD not properly set (says /root ..)
596 # so, the nightly build passes NIGHTLY_BASE here
597 # also store the nightly_base in .base for any post-processing purposes
598 myplc-release:
599         @echo 'Creating myplc-release'
600         rm -f $@
601         echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx build info" >> $@
602         $(MAKE) --no-print-directory version-build >> $@
603         echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx svn info" >> $@
604         $(MAKE) --no-print-directory version-svns >> $@
605         echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx rpm info" >> $@
606         $(MAKE) --no-print-directory version-rpms >> $@
607         @echo $(NIGHTLY_BASE) > .base
608
609 version-build:
610         @echo -n 'Build build-date: ' ; date '+%Y.%m.%d'
611         @echo -n 'Build build-time: ' ; date '+%H:%M-%Z'
612         @echo -n 'Build build-hostname: ' ; hostname
613         @echo    "Build build-base: $(NIGHTLY_BASE)"
614         @echo    "Build planetlab-distro: $(PLDISTRO)"
615         @echo    "Build planetlab-tags: $(PLDISTROTAGS)"
616         @echo -n 'Build planetlab-tagsid: ' ; fgrep '$$''Id' $(PLDISTROTAGS)
617         @echo    "Build target-arch: $(HOSTARCH)"
618         @echo    "Build target-distro: $(DISTRO)"
619         @echo    "Build target-distroname: $(DISTRONAME)"
620         @echo    "Build target-release: $(RELEASE)"     
621         @echo    "Build target-personality: $(NIGHTLY_PERSONALITY)"     
622
623 #################### 
624 # for a given module
625 VFORMAT="%30s := %s\n"
626 define svn_version_target
627 $(1)-version-svn:
628         @$(if $($(1)-SVNPATH),\
629            printf $(VFORMAT) $(1)-SVNPATH "$($(1)-SVNPATH)",\
630            printf $(VFORMAT) $(1)-CVSROOT "$($(1)-CVSROOT)" ; printf $(VFORMAT) $(1)-TAG "$($(1)-TAG)")
631 endef
632
633 # compute all modules
634 ALL-MODULES :=
635 $(foreach package,$(ALL), $(eval ALL-MODULES+=$($(package)-MODULES)))
636 ALL-MODULES:=$(sort $(ALL-MODULES))
637
638 $(foreach module,$(ALL-MODULES), $(eval $(call svn_version_target,$(module))))
639
640 version-svns: $(foreach module, $(ALL-MODULES), $(module)-version-svn)
641
642 RFORMAT="%20s :: version=%s release=%s\n"
643 define rpm_version_target
644 $(1)-version-rpm:
645         @printf $(RFORMAT) $($(1).rpm-name) $($(1).rpm-version) $($(1).rpm-release)
646 version-rpms: $(1)-version-rpm
647 endef
648
649 $(foreach package,$(sort $(ALL)), $(eval $(call rpm_version_target,$(package))))
650
651 versions: myplc-release version-build version-svns version-rpms
652 .PHONY: versions version-build version-rpms version-svns
653
654 #################### package info
655 PKGKEYS := tarballs source codebase srpm rpms rpmnames rpm-release rpm-name rpm-version rpm-subversion
656 %-pkginfo: package=$(subst -pkginfo,,$@)
657 %-pkginfo: 
658         @$(foreach key,$(PKGKEYS),echo "$(package).$(key)=$($(package).$(key))";)
659 ## rpm info
660 RPMKEYS := rpm-path package
661 %-rpminfo: rpm=$(subst -rpminfo,,$@)
662 %-rpminfo: 
663         @$(foreach key,$(RPMKEYS),echo "$(rpm).$(key)=$($(rpm).$(key))";)
664
665 #################### various lists - designed to run with stage1=true
666 packages:
667         @$(foreach package,$(ALL), echo package=$(package) ref_module=$($(package).module) modules=$($(package)-MODULES) rpmnames=$($(package).rpmnames); )
668
669 modules:
670         @$(foreach module,$(ALL-MODULES), echo module=$(module) svnpath=$($(module)-SVNPATH); )
671
672 branches:
673         @$(foreach module,$(ALL-MODULES), \
674           $(if $($(module)-SVNBRANCH),echo module=$(module) branch=$($(module)-SVNBRANCH);))
675
676 module-tools:
677         @$(foreach module,$(ALL-MODULES), \
678          $(if $($(module)-SVNPATH), \
679           $(if $($(module)-SVNBRANCH), \
680              echo $(module):$($(module)-SVNBRANCH); , \
681              echo $(module); )))
682
683 info: packages modules branches 
684
685 .PHONY: info packages modules branches module-tools
686
687 ####################
688 testsvnpath:
689         @$(if $(TESTS_SVNPATH), echo $(TESTS_SVNPATH) > $@, \
690         echo "http://svn.planet-lab.org/svn/tests/trunk" > $@)
691
692 ####################
693 help:
694         @echo "********** Run make in two stages:"
695         @echo ""
696         @echo "make stage1=true PLDISTRO=onelab"
697         @echo " -> extracts all spec files in SPECS/ and mk files in MAKE/"
698         @echo "    as well as save PLDISTRO for subsequent runs"
699         @echo ""
700         @echo "********** Then you can use the following targets"
701         @echo 'make'
702         @echo "  rebuilds everything"
703         @echo 'make util-vserver'
704         @echo "  makes the RPMS related to util-vserver"
705         @echo "  equivalent to 'make util-vserver-rpms'"
706         @echo ""
707         @echo "********** Or, vertically - step-by-step for a given package"
708         @echo 'make util-vserver-codebase'
709         @echo "  performs codebase extraction in CODEBASES/util-vserver"
710         @echo 'make util-vserver-source'
711         @echo "  creates source link in SOURCES/util-vserver-<version>"
712         @echo 'make util-vserver-tarball'
713         @echo "  creates source tarball in SOURCES/util-vserver-<version>.<tarextension>"
714         @echo 'make util-vserver-srpm'
715         @echo "  build source rpm in SRPMS/"
716         @echo 'make util-vserver-rpms'
717         @echo "  build rpm(s) in RPMS/"
718         @echo ""
719         @echo "********** Or, horizontally, reach a step for all known packages"
720         @echo 'make codebases'
721         @echo 'make sources'
722         @echo 'make tarballs'
723         @echo 'make srpms'
724         @echo 'make rpms'
725         @echo ""
726         @echo "********** Manual targets"
727         @echo "make package-compile"
728         @echo "  The regular process uses rpmbuild --rebuild, that performs"
729         @echo "  a compilation directory cleanup upon completion. If you need to investigate"
730         @echo "  the intermediate compilation directory, use the -compile targets"
731         @echo "********** Cleaning examples"
732         @echo "make clean"
733         @echo "  removes the files made by make"
734         @echo "make distclean"
735         @echo "  brute-force cleaning, removes entire directories - requires a new stage1"
736         @echo "make develclean"
737         @echo "  rpm-uninstalls all devel packages installed during build"
738         @echo ""
739         @echo "make iptables-distclean"
740         @echo "  deep clean for a given package"
741         @echo "make iptables-codeclean"
742         @echo "  run this if you've made a change in the CODEBASES area for iptables"
743         @echo ""
744         @echo "make util-vserver-clean"
745         @echo "  removes codebase, source, tarball, build, rpm and srpm for util-vserver"
746         @echo "make util-vserver-clean-codebase"
747         @echo "  and so on for source, tarball, build, rpm and srpm"
748         @echo ""
749         @echo "********** Info examples"
750         @echo "make ++ALL"
751         @echo "  Displays the value of a given variable (here ALL)"
752         @echo "  with only a single plus sign only the value is displayed"
753         @echo "make info"
754         @echo "  is equivalent to make packages modules branches"
755         @echo "  provides various info on these objects"
756         @echo "make ulogd-pkginfo"
757         @echo "  Displays know attributes of a package"
758         @echo "make kernel-devel-rpminfo"
759         @echo "  Displays know attributes of an rpm"
760         @echo "make stage1=true PLDISTROTAGS=planetlab-tags-4.2.mk packages modules branches module-tools"
761         @echo "  Lists mentioned items - module-tools is used in modules.update"
762         @echo ""
763         @echo "********** Known pakages are"
764         @echo "$(ALL)"
765
766 #################### convenience, for debugging only
767 # make +foo : prints the value of $(foo)
768 # make ++foo : idem but verbose, i.e. foo=$(foo)
769 ++%: varname=$(subst +,,$@)
770 ++%:
771         @echo "$(varname)=$($(varname))"
772 +%: varname=$(subst +,,$@)
773 +%:
774         @echo "$($(varname))"