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