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