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