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