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