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