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