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