make sure createrepo gets called after all is done
[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 2 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
44 #################### packages
45 # basics: how to build a package - you need/may define the following variables
46
47 # (*) package-MODULES
48 #     a package needs one or several modules to build. 
49 #     to this end, define 
50 # (*) package-SPEC
51 #     the package's specfile; this is relative to the FIRST module in package-MODULES
52 #     see 'codebase' below
53 #
54 # Optional:
55 #
56 # (*) package-SPECVARS
57 #     space-separated list of spec variable definitions, where you can reference make variable that relate to 
58 #     packages defined BEFORE the current one (note: you should use = - as opposed to := - to define these)
59 #     e.g. mydriver-SPECVARS = foo=$(kernel-rpm-release) 
60 #     would let you use the %release from the kernel's package when rpmbuild'ing mydriver - see automatic below
61 # (*) package-DEPENDS
62 #     a set of *packages* that this package depends on
63 # (*) package-DEPENDDEVELS
64 #     a set of *packages* that the build will rpm-install the -devel variant before building <package>
65 # (*) package-DEPENDDEVELRPMS
66 #     a set of *rpms* that the build will rpm-install before building <package>
67 # (*) package-DEPENDFILES
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 the following make variables - these are extracted from spec files
89 # (*) package-TARBALLS : from the Source<n>: declaration
90 #     example: kernel-i386-TARBALLS = SOURCES/linux-2.6.20.tar.bz2
91 # (*) package-SOURCE : 
92 #     example: kernel-i386-SOURCE = SOURCES/linux-2.6.20
93 # (*) package-SRPM
94 #     example: kernel-i386-SRPM = SRPMS/kernel-2.6.20-1.2949.fc6.vs2.2.0.1.0.planetlab.src.rpm
95 # (*) package-RPMS
96 #     example: kernel-i386-RPMS = \
97 #       RPMS/i686/kernel-2.6.20-1.2949.fc6.vs2.2.0.1.0.planetlab.i686.rpm \
98 #       RPMS/i686/kernel-devel-2.6.20-1.2949.fc6.vs2.2.0.1.0.planetlab.i686.rpm \
99 #       RPMS/i686/kernel-vserver-2.6.20-1.2949.fc6.vs2.2.0.1.0.planetlab.i686.rpm \
100 #       RPMS/i686/kernel-debuginfo-2.6.20-1.2949.fc6.vs2.2.0.1.0.planetlab.i686.rpm
101 # (*) package-rpm-name
102 #     example: kernel-i386-rpm-name = kernel
103 # (*) package-rpm-release
104 #     example: kernel-i386-rpm-release = 1.2949.fc6.vs2.2.0.1.0.planetlab
105 # (*) package-version
106 #     example: kernel-i386-rpm-version = 2.6.20
107 # (*) package-subversion
108 #     example: myplc-rpm-subversion = 15
109 ####################
110
111 #
112 # Default values
113 #
114 HOSTARCH := $(shell uname -i)
115 DISTRO := $(shell ./getdistro.sh)
116 RELEASE := $(shell ./getrelease.sh)
117
118 #################### Makefile
119 # Default target
120 all:
121 .PHONY:all
122
123 ### default values
124 PLDISTRO := planetlab
125 RPMBUILD := rpmbuild
126 export CVS_RSH := ssh
127
128 ########## pldistro.mk holds PLDISTRO - it is generated at stage1 (see below)
129 ifeq "$(stage1)" ""
130 include pldistro.mk
131 endif
132
133 #################### include onelab.mk
134 # describes the set of components
135 PLDISTROCONTENTS := $(PLDISTRO).mk
136 include $(PLDISTROCONTENTS)
137
138 #################### include <pldistro>-tags.mk
139 # describes where to fetch components, and the related tags if using cvs
140 PLDISTROTAGS := $(PLDISTRO)-tags.mk
141 include $(PLDISTROTAGS)
142
143 ########## stage1 and stage2
144 # extract specs and compute .mk files by running 
145 # make stage1=true
146 # entering stage1, we compute all the spec files
147 # then we use stage2 to compute the .mk iteratively, 
148 # ensuring that the n-1 first makefiles are loaded when creating the n-th one
149 # when stage2 is set, it is supposed to be an index (starting at 1) in $(ALL)
150
151 ALLMKS := $(foreach package, $(ALL), MAKE/$(package).mk)
152
153 ### stage2 : need some arithmetic, see
154 # http://www.cmcrossroads.com/articles/ask-mr.-make/learning-gnu-make-functions-with-arithmetic.html
155 ifneq "$(stage2)" ""
156 # the first n packages
157 packages := $(wordlist 1,$(words $(stage2)),$(ALL))
158 # the n-th package
159 package := $(word $(words $(packages)),$(packages))
160 # the n-1 first packages
161 stage2_1 := $(wordlist 2,$(words $(stage2)),$(stage2))
162 previous := $(wordlist 1,$(words $(stage2_1)),$(ALL))
163 previousmks := $(foreach package,$(previous),MAKE/$(package).mk)
164 include $(previousmks)
165 all: verbose
166 verbose:
167         @echo "========== stage2 : $(package)"
168 #       @echo "stage2 : included .mk files : $(previousmks)"
169 all: $($(package)_specpath)
170 all: MAKE/$(package).mk
171 else
172 ### stage1
173 ifneq "$(stage1)" ""
174 all : verbose
175 verbose :
176         @echo "========== stage1"
177 all : spec2make
178 all : .rpmmacros
179 # specs and makes are done sequentially by stage2
180 all : stage2
181 stage2:
182         arg=""; for n in $(ALL) ; do arg="$$arg x"; $(MAKE) --no-print-directory stage2="$$arg"; done
183 ### regular make
184 else
185 ### once .mks are OK, you can run make normally
186 include $(ALLMKS)
187 #all : tarballs
188 #all : sources
189 #all : codebases
190 #all : rpms
191 #all : srpms
192 # mention $(ALL) here rather than rpms 
193 # this is because the inter-package dependencies are expressed like
194 # util-vserver: util-python
195 all: rpms
196 all: repo
197 endif
198 endif
199
200 ####################
201 # gather build information for the 'About' page
202 myplc-release:
203         @echo 'Creating myplc-release'
204         rm -f $@
205         (echo -n 'Build bdate: ' ; date '+%Y.%m.%d') >> $@
206         (echo -n 'Build btime: ' ; date '+%H:%M') >> $@
207         (echo -n 'Build hostname: ' ; hostname) >> $@
208         (echo -n 'Build location: ' ; pwd) >> $@
209         (echo -n 'Build tags file: ' ; fgrep '$$''Id' $(PLDISTROTAGS)) >> $@
210         echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx modules versions info" >> $@
211         $(MAKE) --no-print-directory versions >> $@
212
213 ### yumgroups.xml
214 # the source
215 ifndef YUMGROUPS
216 YUMGROUPS := groups/$(PLDISTRO).xml
217 endif
218
219 RPMS/yumgroups.xml: $(YUMGROUPS)
220         mkdir -p RPMS
221         install -D -m 644 $(YUMGROUPS) $@
222
223 createrepo = createrepo --quiet -g yumgroups.xml RPMS/ 
224
225 repo: RPMS/yumgroups.xml
226         $(createrepo)
227
228 .PHONY: repo
229
230 ####################
231 # notes: 
232 # * to make configuration easier, we always use the first module's
233 # definitions (CVSROOT,TAG, or SVNPATH) to extract the spec file
234 # * for the same reason, in case cvs is used, the first module name is added to 
235 # $(package)-SPEC - otherwise the cvs modules have to define spec as 
236 # <module>/<module>.spec while svn modules just define it as <module>.spec
237 #
238 define stage1_variables
239 $(1)_spec = $(notdir $($(1)-SPEC))
240 $(1)_specpath = CODESPECS/$(notdir $($(1)-SPEC))
241 $(1)_module = $(firstword $($(1)-MODULES))
242 endef
243
244 $(foreach package, $(ALL), $(eval $(call stage1_variables,$(package))))
245
246 #
247 # for each package, compute whether we need to set date (i.e. whether we use the trunk)
248 # the myplc package is forced to have a date, because it is more convenient
249 # (we cannot bump its number everytime something changes in the system)
250
251 define package_hasdate
252 $(1)_hasdate = $(if $(subst myplc,,$(1)), \
253                   $(if $($(1)-SVNPATH),\
254                      $(if $(findstring /trunk,$($(1)-SVNPATH)),yes,),\
255                      $(if $(findstring HEAD,$($(1)-TAG)),yes,)), \
256                 yes)
257 endef
258
259 $(foreach package, $(ALL), $(eval $(call package_hasdate,$(package))))
260
261 ### extract spec file from scm
262 # usage: extract_spec_file package 
263 # see early releases for comments on other possible implementations
264 # cannot use variables in such rules, we need to inline everything, sigh
265 define target_spec
266 $($(1)_specpath):
267         mkdir -p CODESPECS
268         (echo -n "# Generated by planetlab build from $($(1)-SPEC) on " ; date) > $($(1)_specpath)
269         echo "%define distroname $(DISTRO)" >> $($(1)_specpath)
270         echo "%define distrorelease $(RELEASE)" >> $($(1)_specpath)
271         echo "%define pldistro $(PLDISTRO)" >> $($(1)_specpath)
272         $(if $($(1)_hasdate),echo "%define date $(shell date +%Y.%m.%d)" >> $($(1)_specpath),)
273         echo "# included from codebase specfile" >> $($(1)_specpath)
274         $(if $($(1)-SPECVARS), \
275           $(foreach line,$($(1)-SPECVARS), \
276             echo "%define" $(word 1,$(subst =, ,$(line))) "$(word 2,$(subst =, ,$(line)))" >> $($(1)_specpath) ;))
277         $(if $($($(1)_module)-SVNPATH),\
278           svn cat $($($(1)_module)-SVNPATH)/$($(1)-SPEC) >> $($(1)_specpath),\
279           cvs -d $($($(1)_module)-CVSROOT) checkout \
280               -r $($($(1)_module)-TAG) \
281               -p $($(1)_module)/$($(1)-SPEC) >> $($(1)_specpath))
282         @if [ -z $($(1)_specpath) ] ; then rm $($(1)_specpath) ; exit 1 ; fi
283 endef
284
285 $(foreach package,$(ALL),$(eval $(call target_spec,$(package))))
286
287 ### this utility allows to extract various info from a spec file
288 ### and to define them in makefiles
289 spec2make: spec2make.c
290         $(CC) -g -Wall $< -o $@ -lrpm -lrpmbuild
291
292 # Base rpmbuild in the current directory
293 # trying a longer topdir 
294 # http://forums.fedoraforum.org/showthread.php?t=39625
295 # and more specifically post#6
296 # hard-wired for now 
297 export HOME := /building
298 .rpmmacros:
299         rm -f /building ; ln -s /build /building
300         rm -f $@ 
301         echo "%_topdir $(HOME)" >> $@
302         echo "%_tmppath $(HOME)/tmp" >> $@
303         echo "%_netsharedpath /proc:/dev/pts" >> $@
304         echo "%_install_langs C:de:en:es:fr" >> $@
305         echo "%_excludedocs yes" >> $@
306
307 ### run spec2make on the spec file and include the result
308 # usage: spec2make package
309 define target_mk
310 MAKE/$(1).mk: $($(1)_specpath) spec2make .rpmmacros
311         mkdir -p MAKE
312         ./spec2make $($(1)-RPMFLAGS) $($(1)_specpath) $(1) > MAKE/$(1).mk
313         @if [ -z MAKE/$(1).mk ] ; then rm MAKE/$(1).mk ; exit 1 ; fi
314 endef
315
316 $(foreach package,$(ALL),$(eval $(call target_mk,$(package))))
317
318 # stores PLDISTRO in a file
319 # this is done at stage1. later run wont get confused
320 pldistro.mk:
321         echo "PLDISTRO:=$(PLDISTRO)" > $@
322         echo "PLDISTROTAGS:=$(PLDISTROTAGS)" >> $@
323
324 savepldistro: pldistro.mk
325 .PHONY: savepldistro
326
327 # always refresh this
328 all: savepldistro
329
330 ####################
331 ### pack sources into tarballs
332 ALLTARBALLS:= $(foreach package, $(ALL), $($(package)-TARBALLS))
333 tarballs: $(ALLTARBALLS)
334         @echo $(words $(ALLTARBALLS)) source tarballs OK
335 .PHONY: tarballs
336
337 SOURCES/%.tar.bz2: SOURCES/%
338         tar chpjf $@ -C SOURCES $*
339
340 SOURCES/%.tar.gz: SOURCES/%
341         tar chpzf $@ -C SOURCES $*
342
343 SOURCES/%.tgz: SOURCES/%
344         tar chpzf $@ -C SOURCES $*
345
346 ##
347 URLS/%: url=$(subst @colon@,:,$(subst @slash@,/,$(notdir $@)))
348 URLS/%: basename=$(notdir $(url))
349 URLS/%: 
350         echo curl $(url) -o SOURCES/$(basename)
351         touch $@
352
353 ### the directory SOURCES/<package>-<version> is made 
354 # with a copy -rl from CODEBASES/<package>
355 # the former is $(package-SOURCE) and the latter is $(package-CODEBASE)
356 ALLSOURCES:=$(foreach package, $(ALL), $($(package)-SOURCE))
357 # so that make does not use the rule below directly for creating the tarball files
358 .SECONDARY: $(ALLSOURCES)
359
360 sources: $(ALLSOURCES)
361         @echo $(words $(ALLSOURCES)) versioned source trees OK
362 .PHONY: sources
363
364 define target_link_codebase_sources
365 $($(1)-SOURCE): $($(1)-CODEBASE) ; mkdir -p SOURCES ; cp -rl $($(1)-CODEBASE) $($(1)-SOURCE)
366 endef
367
368 $(foreach package,$(ALL),$(eval $(call target_link_codebase_sources,$(package))))
369
370 ### codebase extraction
371 ALLCODEBASES:=$(foreach package, $(ALL), $($(package)-CODEBASE))
372 # so that make does not use the rule below directly for creating the tarball files
373 .SECONDARY: $(ALLCODEBASES)
374
375 codebases : $(ALLCODEBASES)
376         @echo $(words $(ALLCODEBASES)) codebase OK
377 .PHONY: codebases
378
379 ### extract codebase 
380 # usage: extract_single_module package 
381 define extract_single_module
382         mkdir -p CODEBASES
383         $(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))
384 endef
385
386 # usage: extract_multi_module package 
387 define extract_multi_module
388         mkdir -p CODEBASES/$(1) && cd CODEBASES/$(1) && (\
389         $(foreach m,$($(1)-MODULES), $(if $($(m)-SVNPATH), svn export $($(m)-SVNPATH) $(m);, cvs -d $($(m)-CVSROOT) export -r $($(m)-TAG) $(m);)))
390 endef
391
392 CODEBASES/%: package=$(notdir $@)
393 CODEBASES/%: multi_module=$(word 2,$($(package)-MODULES))
394 CODEBASES/%: 
395         @(echo -n "XXXXXXXXXXXXXXX -- BEG CODEBASE $(package) : $@ " ; date)
396         $(if $(multi_module),\
397           $(call extract_multi_module,$(package)),\
398           $(call extract_single_module,$(package)))
399         @(echo -n "XXXXXXXXXXXXXXX -- END CODEBASE $(package) : $@ " ; date)
400
401 ### source rpms
402 ALLSRPMS:=$(foreach package,$(ALL),$($(package)-SRPM))
403 srpms: $(ALLSRPMS)
404         @echo $(words $(ALLSRPMS)) source rpms OK
405 .PHONY: srpms
406
407 # usage: target_source_rpm package
408 # select upon the package name, whether it contains srpm or not
409 define target_source_rpm 
410 ifeq "$(subst srpm,,$(1))" "$(1)"
411 $($(1)-SRPM): $($(1)_specpath) .rpmmacros $($(1)-TARBALLS) 
412         mkdir -p BUILD SRPMS tmp
413         @(echo -n "XXXXXXXXXXXXXXX -- BEG SRPM $(1) " ; date)
414         -$(foreach devel,$($(1)-DEPENDDEVELS), $(if $($(devel)-DEVEL-RPMS),rpm --force -Uvh $($(devel)-DEVEL-RPMS);))
415         -$(foreach rpm,$($(1)-DEPENDDEVELRPMS), rpm --force -Uvh $($(rpm)-RPM-PATH);)
416         $(if $($(1)-RPMBUILD),\
417           $($(1)-RPMBUILD) $($(1)-RPMFLAGS) -bs $($(1)_specpath),
418           $(RPMBUILD) $($(1)-RPMFLAGS) -bs $($(1)_specpath))    
419         @(echo -n "XXXXXXXXXXXXXXX -- END SRPM $(1) " ; date)
420 else
421 $($(1)-SRPM): $($(1)_specpath) .rpmmacros $($(1)-CODEBASE)
422         mkdir -p BUILD SRPMS tmp
423         @(echo -n "XXXXXXXXXXXXXXX -- BEG SRPM $(1) (using make srpm) " ; date)
424         -$(foreach devel,$($(1)-DEPENDDEVELS), $(if $($(devel)-DEVEL-RPMS),rpm --force -Uvh $($(devel)-DEVEL-RPMS);))
425         -$(foreach rpm,$($(1)-DEPENDDEVELRPMS), rpm --force -Uvh $($(rpm)-RPM-PATH);)
426         make -C $($(1)-CODEBASE) srpm && \
427            rm -f SRPMS/$(notdir $($(1)-SRPM)) && \
428            ln $($(1)-CODEBASE)/$(notdir $($(1)-SRPM)) SRPMS/$(notdir $($(1)-SRPM)) 
429         @(echo -n "XXXXXXXXXXXXXXX -- END SRPM $(1) " ; date)
430 endif
431 endef
432
433 $(foreach package,$(ALL),$(eval $(call target_source_rpm,$(package))))
434
435 ### rpmbuild invokation
436 ALLRPMS:=$(foreach package,$(ALL),$($(package)-RPMS))
437 # same as above, mention $(ALL) and not $(ALLRPMS)
438 rpms: $(ALLRPMS)
439         @echo $(words $(ALLRPMS)) binary rpms OK
440 .PHONY: rpms
441
442 # usage: build_binary_rpm package
443 # xxx hacky - invoke createrepo if DEPENDFILES mentions RPMS/yumgroups.xml
444 define target_binary_rpm 
445 $($(1)-RPMS): $($(1)-SRPM)
446         mkdir -p BUILD RPMS SPECS tmp
447         @(echo -n "XXXXXXXXXXXXXXX -- BEG RPM $(1) " ; date)
448         $(if $(findstring RPMS/yumgroups.xml,$($(1)-DEPENDFILES)), $(createrepo) , )
449         $(if $($(1)-RPMBUILD),\
450           $($(1)-RPMBUILD) $($(1)-RPMFLAGS) --rebuild --define "_sourcedir $(HOME)/tmp" $($(1)-SRPM), \
451           $(RPMBUILD)  $($(1)-RPMFLAGS) --rebuild --define "_sourcedir $(HOME)/tmp" $($(1)-SRPM))
452         @(echo -n "XXXXXXXXXXXXXXX -- END RPM $(1) " ; date)
453 endef
454
455 $(foreach package,$(ALL),$(eval $(call target_binary_rpm,$(package))))
456
457 ### shorthand target
458 # e.g. make proper -> does propers rpms
459 # usage shorthand_target package
460 define target_shorthand 
461 $(1): $($(package)-RPMS)
462 .PHONY: $(1)
463 $(1)-spec: $($(package)-SPEC)
464 .PHONY: $(1)-spec
465 $(1)-mk: $($(package)-MK)
466 .PHONY: $(1)-mk
467 $(1)-tarball: $($(package)-TARBALLS)
468 .PHONY: $(1)-tarball
469 $(1)-codebase: $($(package)-CODEBASE)
470 .PHONY: $(1)-source
471 $(1)-source: $($(package)-SOURCE)
472 .PHONY: $(1)-codebase
473 $(1)-rpms: $($(package)-RPMS)
474 .PHONY: $(1)-rpms
475 $(1)-srpm: $($(package)-SRPM)
476 .PHONY: $(1)-srpm
477 endef
478
479 $(foreach package,$(ALL),$(eval $(call target_shorthand,$(package))))
480
481 ### dependencies
482 define package_depends_on_file
483 $(1):$(2)
484 $($(1)-RPMS):$(2)
485 endef
486
487 define target_dependfiles
488 $(foreach file,$($(1)-DEPENDFILES),$(eval $(call package_depends_on_file,$(1),$(file))))
489 endef
490
491 define package_depends_on_package
492 $(1):$(2)
493 $(1):$($(2)-RPMS)
494 $($(1)-RPMS):$($(2)-RPMS)
495 endef
496
497 define target_depends
498 $(foreach package,$($(1)-DEPENDS) $($(1)-DEPENDDEVELS),$(eval $(call package_depends_on_package,$(1),$(package))))
499 endef
500
501 $(foreach package,$(ALL),$(eval $(call target_depends,$(package))))
502 $(foreach package,$(ALL),$(eval $(call target_dependfiles,$(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)-clean: $(1)-clean-codebase $(1)-clean-source $(1)-clean-tarball $(1)-clean-build $(1)-clean-rpms $(1)-clean-srpm
531 .PHONY: $(1)-clean
532 endef
533
534 $(foreach package,$(ALL),$(eval $(call target_clean,$(package))))
535
536 ### clean precisely
537 clean:
538         $(MAKE) $(CLEANS)
539 .PHONY: clean
540
541 clean-help:
542         @echo Available clean targets
543         @echo $(CLEANS)
544
545 ### brute force clean
546 distclean1:
547         rm -rf pldistro.mk .rpmmacros spec2make CODESPECS MAKE 
548 distclean2:
549         rm -rf CODEBASES SOURCES BUILD RPMS SRPMS SPECS tmp
550 distclean: distclean1 distclean2
551 .PHONY: distclean1 distclean2 distclean
552
553 # xxx tmp - I cannot use this on my mac for local testing
554 ISMACOS=$(findstring Darwin,$(shell uname))
555 ifneq "$(ISMACOS)" ""
556 #################### produce reliable version information
557 # for a given module
558 VFORMAT="%30s := %s\n"
559 define print_version
560 $(1)-version:
561         @$(if $($(1)-SVNPATH),\
562            printf $(VFORMAT) $(1)-SVNPATH "$($(1)-SVNPATH)",\
563            printf $(VFORMAT) $(1)-CVSROOT "$($(1)-CVSROOT)" ; printf $(VFORMAT) $(1)-TAG "$($(1)-TAG)")
564 endef
565
566 # compute all modules
567 ALL-MODULES :=
568 $(foreach package,$(ALL), $(eval ALL-MODULES+=$($(package)-MODULES)))
569 ALL-MODULES:=$(sort $(ALL-MODULES))
570
571 $(foreach module,$(ALL-MODULES), $(eval $(call print_version,$(module))))
572
573 versions: $(foreach module, $(ALL-MODULES), $(module)-version)
574 else
575 versions:
576         @echo "warning : the 'versions' target is not supported on macos"
577 endif
578
579 #################### include install Makefile
580 # the default is to use the distro-dependent install file
581 # however the main distro file can redefine PLDISTROINSTALL
582 ifndef PLDISTROINSTALL
583 PLDISTROINSTALL := $(PLDISTRO)-install.mk
584 endif
585 # only if present
586 -include $(PLDISTROINSTALL)
587
588 ####################
589 help:
590         @echo "Known pakages are"
591         @echo "  $(ALL)"
592         @echo "Run make in two stages:"
593         @echo ""
594         @echo "make stage1=true PLDISTRO=onelab"
595         @echo " -> extracts all spec files in CODESPECS/ and mk files in MAKE/"
596         @echo "    as well as save PLDISTRO for subsequent runs"
597         @echo ""
598         @echo "Then you can use the following targets"
599         @echo '$ make'
600         @echo "  rebuilds everything"
601         @echo '$ make util-vserver'
602         @echo "  makes the RPMS related to util-vserver"
603         @echo "  equivalent to 'make util-vserver-rpms'"
604         @echo ""
605         @echo "Or, vertically - step-by-step for a given package"
606         @echo '$ make util-vserver-codebase'
607         @echo "  performs codebase extraction in CODEBASES/util-vserver"
608         @echo '$ make util-vserver-source'
609         @echo "  creates source link in SOURCES/util-vserver-<version>"
610         @echo '$ make util-vserver-tarball'
611         @echo "  creates source tarball in SOURCES/util-vserver-<version>.<tarextension>"
612         @echo '$ make util-vserver-rpms'
613         @echo "  build rpm(s) in RPMS/"
614         @echo '$ make util-vserver-srpm'
615         @echo "  build source rpm in SRPMS/"
616         @echo ""
617         @echo "Or, horizontally, reach a step for all known packages"
618         @echo '$ make codebases'
619         @echo '$ make sources'
620         @echo '$ make tarballs'
621         @echo '$ make rpms'
622         @echo '$ make srpms'
623         @echo ""
624         @echo "Cleaning examples"
625         @echo "$ make clean"
626         @echo "  removes the files made by make"
627         @echo "$ make distclean"
628         @echo "  brute-force cleaning, removes entire directories - requires a new stage1"
629         @echo "$ make util-vserver-clean"
630         @echo "  removes codebase, source, tarball, build, rpm and srpm for util-vserver"
631         @echo "$ make util-vserver-clean-codebase"
632         @echo "  and so on for source, tarball, build, rpm and srpm"
633
634 #################### convenience, for debugging only
635 # make +foo : prints the value of $(foo)
636 # make ++foo : idem but verbose, i.e. foo=$(foo)
637 ++%: varname=$(subst +,,$@)
638 ++%:
639         @echo "$(varname)=$($(varname))"
640 +%: varname=$(subst +,,$@)
641 +%:
642         @echo "$($(varname))"