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