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