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