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