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