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