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