add support for DEPENDDEVELRPMS
[build.git] / Makefile
1 #
2 # Thierry Parmentelat - INRIA Sophia Antipolis 
3 #
4 ### $Id$
5
6 ####################
7 # invokation:
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 mimick 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 moslty 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 mixedcase 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 *rpm* 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 endif
197 endif
198
199 ####################
200 # gather build information for the 'About' page
201 SOURCES/myplc-release:
202         @echo 'Creating myplc-release'
203         mkdir -p SOURCES
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 ####################
214 # notes: 
215 # * to make configuration easier, we always use the first module's
216 # definitions (CVSROOT,TAG, or SVNPATH) to extract the spec file
217 # * for the same reason, in case cvs is used, the first module name is added to 
218 # $(package)-SPEC - otherwise the cvs modules have to define spec as 
219 # <module>/<module>.spec while svn modules just define it as <module>.spec
220 #
221 define stage1_variables
222 $(1)_spec = $(notdir $($(1)-SPEC))
223 $(1)_specpath = CODESPECS/$(notdir $($(1)-SPEC))
224 $(1)_module = $(firstword $($(1)-MODULES))
225 endef
226
227 $(foreach package, $(ALL), $(eval $(call stage1_variables,$(package))))
228
229 #
230 # for each package, compute whether we need to set date (i.e. whether we use the trunk)
231 # the myplc package is forced to have a date, because it is more convenient
232 # (we cannot bump its number everytime something changes in the system)
233
234 define package_hasdate
235 $(1)_hasdate = $(if $(subst myplc,,$(1)), \
236                   $(if $($(1)-SVNPATH),\
237                      $(if $(findstring /trunk,$($(1)-SVNPATH)),yes,),\
238                      $(if $(findstring HEAD,$($(1)-TAG)),yes,)), \
239                 yes)
240 endef
241
242 $(foreach package, $(ALL), $(eval $(call package_hasdate,$(package))))
243
244 ### extract spec file from scm
245 # usage: extract_spec_file package 
246 # see early releases for comments on other possible implementations
247 # cannot use variables in such rules, we need to inline everything, sigh
248 define target_spec
249 $($(1)_specpath):
250         mkdir -p CODESPECS
251         (echo -n "# Generated by planetlab build from $($(1)-SPEC) on " ; date) > $($(1)_specpath)
252         echo "%define distroname $(DISTRO)" >> $($(1)_specpath)
253         echo "%define distrorelease $(RELEASE)" >> $($(1)_specpath)
254         echo "%define pldistro $(PLDISTRO)" >> $($(1)_specpath)
255         $(if $($(1)_hasdate),echo "%define date $(shell date +%Y.%m.%d)" >> $($(1)_specpath),)
256         echo "# included from codebase specfile" >> $($(1)_specpath)
257         $(if $($(1)-SPECVARS), \
258           $(foreach line,$($(1)-SPECVARS), \
259             echo "%define" $(word 1,$(subst =, ,$(line))) "$(word 2,$(subst =, ,$(line)))" >> $($(1)_specpath) ;))
260         $(if $($($(1)_module)-SVNPATH),\
261           svn cat $($($(1)_module)-SVNPATH)/$($(1)-SPEC) >> $($(1)_specpath),\
262           cvs -d $($($(1)_module)-CVSROOT) checkout \
263               -r $($($(1)_module)-TAG) \
264               -p $($(1)_module)/$($(1)-SPEC) >> $($(1)_specpath))
265         @if [ -z $($(1)_specpath) ] ; then rm $($(1)_specpath) ; exit 1 ; fi
266 endef
267
268 $(foreach package,$(ALL),$(eval $(call target_spec,$(package))))
269
270 ### this utility allows to extract various info from a spec file
271 ### and to define them in makefiles
272 spec2make: spec2make.c
273         $(CC) -g -Wall $< -o $@ -lrpm -lrpmbuild
274
275 # Base rpmbuild in the current directory
276 # trying a longer topdir 
277 # http://forums.fedoraforum.org/showthread.php?t=39625
278 # and more specifically post#6
279 # hard-wired for now 
280 export HOME := /building
281 .rpmmacros:
282         rm -f /building ; ln -s /build /building
283         rm -f $@ 
284         echo "%_topdir $(HOME)" >> $@
285         echo "%_tmppath $(HOME)/tmp" >> $@
286         echo "%_netsharedpath /proc:/dev/pts" >> $@
287         echo "%_install_langs C:de:en:es:fr" >> $@
288
289 ### run spec2make on the spec file and include the result
290 # usage: spec2make package
291 define target_mk
292 MAKE/$(1).mk: $($(1)_specpath) spec2make .rpmmacros
293         mkdir -p MAKE
294         ./spec2make $($(1)-RPMFLAGS) $($(1)_specpath) $(1) > MAKE/$(1).mk
295         @if [ -z MAKE/$(1).mk ] ; then rm MAKE/$(1).mk ; exit 1 ; fi
296 endef
297
298 $(foreach package,$(ALL),$(eval $(call target_mk,$(package))))
299
300 # stores PLDISTRO in a file
301 # this is done at stage1. later run wont get confused
302 pldistro.mk:
303         echo "PLDISTRO:=$(PLDISTRO)" > $@
304         echo "PLDISTROTAGS:=$(PLDISTROTAGS)" >> $@
305
306 savepldistro: pldistro.mk
307 .PHONY: savepldistro
308
309 # always refresh this
310 all: savepldistro
311
312 ####################
313 ### pack sources into tarballs
314 ALLTARBALLS:= $(foreach package, $(ALL), $($(package)-TARBALLS))
315 tarballs: $(ALLTARBALLS)
316         @echo $(words $(ALLTARBALLS)) source tarballs OK
317 .PHONY: tarballs
318
319 SOURCES/%.tar.bz2: SOURCES/%
320         tar chpjf $@ -C SOURCES $*
321
322 SOURCES/%.tar.gz: SOURCES/%
323         tar chpzf $@ -C SOURCES $*
324
325 SOURCES/%.tgz: SOURCES/%
326         tar chpzf $@ -C SOURCES $*
327
328 ##
329 URLS/%: url=$(subst @colon@,:,$(subst @slash@,/,$(notdir $@)))
330 URLS/%: basename=$(notdir $(url))
331 URLS/%: 
332         echo curl $(url) -o SOURCES/$(basename)
333         touch $@
334
335 ### the directory SOURCES/<package>-<version> is made 
336 # with a copy -rl from CODEBASES/<package>
337 # the former is $(package-SOURCE) and the latter is $(package-CODEBASE)
338 ALLSOURCES:=$(foreach package, $(ALL), $($(package)-SOURCE))
339 # so that make does not use the rule below directly for creating the tarball files
340 .SECONDARY: $(ALLSOURCES)
341
342 sources: $(ALLSOURCES)
343         @echo $(words $(ALLSOURCES)) versioned source trees OK
344 .PHONY: sources
345
346 define target_link_codebase_sources
347 $($(1)-SOURCE): $($(1)-CODEBASE) ; mkdir -p SOURCES ; cp -rl $($(1)-CODEBASE) $($(1)-SOURCE)
348 endef
349
350 $(foreach package,$(ALL),$(eval $(call target_link_codebase_sources,$(package))))
351
352 ### codebase extraction
353 ALLCODEBASES:=$(foreach package, $(ALL), $($(package)-CODEBASE))
354 # so that make does not use the rule below directly for creating the tarball files
355 .SECONDARY: $(ALLCODEBASES)
356
357 codebases : $(ALLCODEBASES)
358         @echo $(words $(ALLCODEBASES)) codebase OK
359 .PHONY: codebases
360
361 ### extract codebase 
362 # usage: extract_single_module package 
363 define extract_single_module
364         mkdir -p CODEBASES
365         $(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))
366 endef
367
368 # usage: extract_multi_module package 
369 define extract_multi_module
370         mkdir -p CODEBASES/$(1) && cd CODEBASES/$(1) && (\
371         $(foreach m,$($(1)-MODULES), $(if $($(m)-SVNPATH), svn export $($(m)-SVNPATH) $(m);, cvs -d $($(m)-CVSROOT) export -r $($(m)-TAG) $(m);)))
372 endef
373
374 CODEBASES/%: package=$(notdir $@)
375 CODEBASES/%: multi_module=$(word 2,$($(package)-MODULES))
376 CODEBASES/%: 
377         @(echo -n "XXXXXXXXXXXXXXX -- BEG CODEBASE $(package) : $@ " ; date)
378         $(if $(multi_module),\
379           $(call extract_multi_module,$(package)),\
380           $(call extract_single_module,$(package)))
381         @(echo -n "XXXXXXXXXXXXXXX -- END CODEBASE $(package) : $@ " ; date)
382
383 ### source rpms
384 ALLSRPMS:=$(foreach package,$(ALL),$($(package)-SRPM))
385 srpms: $(ALLSRPMS)
386         @echo $(words $(ALLSRPMS)) source rpms OK
387 .PHONY: srpms
388
389 # usage: target_source_rpm package
390 # select upon the package name, whether it contains srpm or not
391 define target_source_rpm 
392 ifeq "$(subst srpm,,$(1))" "$(1)"
393 $($(1)-SRPM): $($(1)_specpath) .rpmmacros $($(1)-TARBALLS) 
394         mkdir -p BUILD SRPMS tmp
395         @(echo -n "XXXXXXXXXXXXXXX -- BEG SRPM $(1) " ; date)
396         -$(foreach devel,$($(1)-DEPENDDEVELS), $(if $($(devel)-DEVEL-RPMS),rpm -Uvh $($(devel)-DEVEL-RPMS);))
397         -$(foreach rpm,$($(1)-DEPENDDEVELRPMS), rpm -Uvh $($(rpm)-RPM-PATH);)
398         $(if $($(1)-RPMBUILD),\
399           $($(1)-RPMBUILD) $($(1)-RPMFLAGS) -bs $($(1)_specpath),
400           $(RPMBUILD) $($(1)-RPMFLAGS) -bs $($(1)_specpath))    
401         @(echo -n "XXXXXXXXXXXXXXX -- END SRPM $(1) " ; date)
402 else
403 $($(1)-SRPM): $($(1)_specpath) .rpmmacros $($(1)-CODEBASE)
404         mkdir -p BUILD SRPMS tmp
405         @(echo -n "XXXXXXXXXXXXXXX -- BEG SRPM $(1) (using make srpm) " ; date)
406         -$(foreach devel,$($(1)-DEPENDDEVELS), $(if $($(devel)-DEVEL-RPMS),rpm -Uvh $($(devel)-DEVEL-RPMS);))
407         -$(foreach rpm,$($(1)-DEPENDDEVELRPMS), rpm -Uvh $($(rpm)-RPM-PATH);)
408         make -C $($(1)-CODEBASE) srpm && \
409            rm -f SRPMS/$(notdir $($(1)-SRPM)) && \
410            ln $($(1)-CODEBASE)/$(notdir $($(1)-SRPM)) SRPMS/$(notdir $($(1)-SRPM)) 
411         @(echo -n "XXXXXXXXXXXXXXX -- END SRPM $(1) " ; date)
412 endif
413 endef
414
415 $(foreach package,$(ALL),$(eval $(call target_source_rpm,$(package))))
416
417 ### rpmbuild invokation
418 ALLRPMS:=$(foreach package,$(ALL),$($(package)-RPMS))
419 # same as above, mention $(ALL) and not $(ALLRPMS)
420 rpms: $(ALLRPMS)
421         @echo $(words $(ALLRPMS)) binary rpms OK
422 .PHONY: rpms
423
424 # usage: build_binary_rpm package
425 # xxx hacky - invoke createrepo if DEPENDFILES mentions RPMS/yumgroups.xml
426 define target_binary_rpm 
427 $($(1)-RPMS): $($(1)-SRPM)
428         mkdir -p BUILD RPMS SPECS tmp
429         @(echo -n "XXXXXXXXXXXXXXX -- BEG RPM $(1) " ; date)
430         $(if $(findstring RPMS/yumgroups.xml,$($(1)-DEPENDFILES)), createrepo --quiet -g yumgroups.xml RPMS/ , )
431         $(if $($(1)-RPMBUILD),\
432           $($(1)-RPMBUILD) $($(1)-RPMFLAGS) --rebuild $($(1)-SRPM), \
433           $(RPMBUILD)  $($(1)-RPMFLAGS) --rebuild $($(1)-SRPM))
434         @(echo -n "XXXXXXXXXXXXXXX -- END RPM $(1) " ; date)
435 endef
436
437 $(foreach package,$(ALL),$(eval $(call target_binary_rpm,$(package))))
438
439 ### RPMS/yumgroups.xml
440 ifndef YUMGROUPS
441 YUMGROUPS := groups/$(PLDISTRO).xml
442 endif
443 RPMS/yumgroups.xml: $(YUMGROUPS)
444         install -D -m 644 $(YUMGROUPS) $@
445
446 ### shorthand target
447 # e.g. make proper -> does propers rpms
448 # usage shorthand_target package
449 define target_shorthand 
450 $(1): $($(package)-RPMS)
451 .PHONY: $(1)
452 $(1)-spec: $($(package)-SPEC)
453 .PHONY: $(1)-spec
454 $(1)-mk: $($(package)-MK)
455 .PHONY: $(1)-mk
456 $(1)-tarball: $($(package)-TARBALLS)
457 .PHONY: $(1)-tarball
458 $(1)-codebase: $($(package)-CODEBASE)
459 .PHONY: $(1)-source
460 $(1)-source: $($(package)-SOURCE)
461 .PHONY: $(1)-codebase
462 $(1)-rpms: $($(package)-RPMS)
463 .PHONY: $(1)-rpms
464 $(1)-srpm: $($(package)-SRPM)
465 .PHONY: $(1)-srpm
466 endef
467
468 $(foreach package,$(ALL),$(eval $(call target_shorthand,$(package))))
469
470 ### dependencies
471 define package_depends_on_file
472 $(1):$(2)
473 $($(1)-RPMS):$(2)
474 endef
475
476 define target_dependfiles
477 $(foreach file,$($(1)-DEPENDFILES),$(eval $(call package_depends_on_file,$(1),$(file))))
478 endef
479
480 define package_depends_on_package
481 $(1):$(2)
482 $(1):$($(2)-RPMS)
483 $($(1)-RPMS):$($(2)-RPMS)
484 endef
485
486 define target_depends
487 $(foreach package,$($(1)-DEPENDS) $($(1)-DEPENDDEVELS),$(eval $(call package_depends_on_package,$(1),$(package))))
488 endef
489
490 $(foreach package,$(ALL),$(eval $(call target_depends,$(package))))
491 $(foreach package,$(ALL),$(eval $(call target_dependfiles,$(package))))
492
493 ### clean target
494 # usage: target_clean package
495 define target_clean
496 $(1)-clean-codebase:
497         rm -rf $($(1)-CODEBASE)
498 .PHONY: $(1)-clean-codebase
499 CLEANS += $(1)-clean-codebase
500 $(1)-clean-source:
501         rm -rf $($(1)-SOURCE)
502 .PHONY: $(1)-clean-source
503 CLEANS += $(1)-clean-source
504 $(1)-clean-tarball:
505         rm -rf $($(1)-TARBALLS)
506 .PHONY: $(1)-clean-tarball
507 CLEANS += $(1)-clean-tarball
508 $(1)-clean-build:
509         rm -rf BUILD/$(notdir $($(1)-SOURCE))
510 CLEANS += $(1)-clean-build
511 $(1)-clean-rpms:
512         rm -rf $($(1)-RPMS)
513 .PHONY: $(1)-clean-rpms
514 CLEANS += $(1)-clean-rpms
515 $(1)-clean-srpm:
516         rm -rf $($(1)-SRPM)
517 .PHONY: $(1)-clean-srpm
518 CLEANS += $(1)-clean-srpm
519 $(1)-clean: $(1)-clean-codebase $(1)-clean-source $(1)-clean-tarball $(1)-clean-build $(1)-clean-rpms $(1)-clean-srpm
520 .PHONY: $(1)-clean
521 endef
522
523 $(foreach package,$(ALL),$(eval $(call target_clean,$(package))))
524
525 ### clean precisely
526 clean:
527         $(MAKE) $(CLEANS)
528 .PHONY: clean
529
530 clean-help:
531         @echo Available clean targets
532         @echo $(CLEANS)
533
534 ### brute force clean
535 distclean1:
536         rm -rf pldistro.mk .rpmmacros spec2make CODESPECS MAKE 
537 distclean2:
538         rm -rf CODEBASES SOURCES BUILD RPMS SRPMS SPECS tmp
539 distclean: distclean1 distclean2
540 .PHONY: distclean1 distclean2 distclean
541
542 # xxx tmp - I cannot use this on my mac for local testing
543 ISMACOS=$(findstring Darwin,$(shell uname))
544 ifneq "$(ISMACOS)" ""
545 #################### produce reliable version information
546 # for a given module
547 VFORMAT="%30s := %s\n"
548 define print_version
549 $(1)-version:
550         @$(if $($(1)-SVNPATH),\
551            printf $(VFORMAT) $(1)-SVNPATH "$($(1)-SVNPATH)",\
552            printf $(VFORMAT) $(1)-CVSROOT "$($(1)-CVSROOT)" ; printf $(VFORMAT) $(1)-TAG "$($(1)-TAG)")
553 endef
554
555 # compute all modules
556 ALL-MODULES :=
557 $(foreach package,$(ALL), $(eval ALL-MODULES+=$($(package)-MODULES)))
558 ALL-MODULES:=$(sort $(ALL-MODULES))
559
560 $(foreach module,$(ALL-MODULES), $(eval $(call print_version,$(module))))
561
562 versions: $(foreach module, $(ALL-MODULES), $(module)-version)
563 else
564 versions:
565         @echo "warning : the 'versions' target is not supported on macos"
566 endif
567
568 #################### include install Makefile
569 # the default is to use the distro-dependent install file
570 # however the main distro file can redefine PLDISTROINSTALL
571 ifndef PLDISTROINSTALL
572 PLDISTROINSTALL := $(PLDISTRO)-install.mk
573 endif
574 # only if present
575 -include $(PLDISTROINSTALL)
576
577 ####################
578 help:
579         @echo "Known pakages are"
580         @echo "  $(ALL)"
581         @echo "Run make in two stages:"
582         @echo ""
583         @echo "make stage1=true PLDISTRO=onelab"
584         @echo " -> extracts all spec files in CODESPECS/ and mk files in MAKE/"
585         @echo "    as well as save PLDISTRO for subsequent runs"
586         @echo ""
587         @echo "Then you can use the following targets"
588         @echo '$ make'
589         @echo "  rebuilds everything"
590         @echo '$ make util-vserver'
591         @echo "  makes the RPMS related to util-vserver"
592         @echo "  equivalent to 'make util-vserver-rpms'"
593         @echo ""
594         @echo "Or, vertically - step-by-step for a given package"
595         @echo '$ make util-vserver-codebase'
596         @echo "  performs codebase extraction in CODEBASES/util-vserver"
597         @echo '$ make util-vserver-source'
598         @echo "  creates source link in SOURCES/util-vserver-<version>"
599         @echo '$ make util-vserver-tarball'
600         @echo "  creates source tarball in SOURCES/util-vserver-<version>.<tarextension>"
601         @echo '$ make util-vserver-rpms'
602         @echo "  build rpm(s) in RPMS/"
603         @echo '$ make util-vserver-srpm'
604         @echo "  build source rpm in SRPMS/"
605         @echo ""
606         @echo "Or, horizontally, reach a step for all known packages"
607         @echo '$ make codebases'
608         @echo '$ make sources'
609         @echo '$ make tarballs'
610         @echo '$ make rpms'
611         @echo '$ make srpms'
612         @echo ""
613         @echo "Cleaning examples"
614         @echo "$ make clean"
615         @echo "  removes the files made by make"
616         @echo "$ make distclean"
617         @echo "  brute-force cleaning, removes entire directories - requires a new stage1"
618         @echo "$ make util-vserver-clean"
619         @echo "  removes codebase, source, tarball, build, rpm and srpm for util-vserver"
620         @echo "$ make util-vserver-clean-codebase"
621         @echo "  and so on for source, tarball, build, rpm and srpm"
622
623 #################### convenience, for debugging only
624 # make +foo : prints the value of $(foo)
625 # make ++foo : idem but verbose, i.e. foo=$(foo)
626 ++%: varname=$(subst +,,$@)
627 ++%:
628         @echo "$(varname)=$($(varname))"
629 +%: varname=$(subst +,,$@)
630 +%:
631         @echo "$($(varname))"