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