renumbering to 4.3
[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 #     this is intended to denote local rpms, i.e. ones that are results of our own build
60 #     stock rpms should be mentioned in config.planetlab/devel.pkgs
61 # (*) package-DEPEND-FILES
62 #     a set of files that the package depends on - and that make needs to know about
63 #     if this contains RPMS/yumgroups.xml, then the toplevel RPMS's index 
64 #     is refreshed with createrepo prior to running rpmbuild
65 # (*) package-RPMFLAGS: Miscellaneous RPM flags
66 # (*) package-RPMBUILD: If not rpmbuild - mostly used for sudo'ing rpmbuild
67 # (*) package-BUILD-FROM-SRPM: set this to any non-empty value, if your package is able to produce 
68 #     a source rpms by running 'make srpm'
69 # (*) package-RPMDATE: set this to any non-empty value to get the rpm package's release field hold the current date
70 #     this is useful for container packages, like e.g. bootstrapfs or vserver, that contains much more than the
71 #     correspondng module
72 #
73 #################### modules
74 # Required information about the various modules (set this in e.g. planetlab-tags.mk)
75 #
76 # (*) module-SVNPATH
77 #     the complete path where this module lies; 
78 #     you can specify the trunk or a given tag with this variable
79
80 # OR if the module is managed under cvs (will be obsoleted)
81
82 # (*) module-CVSROOT
83 # (*) module-TAG
84 #
85 #################### automatic variables
86 #
87 # the build defines some make variables that are extracted from spec files
88 # see for example
89 # (*)  $ make ulogd-pkginfo
90 #        to see the list f variables attached to a given package
91 # (*)  $ make kernel-devel-rpminfo
92 #        to see the list of variables attached to a given rpm
93 #
94 ####################
95
96 # exported to spec files as plrelease
97 PLANETLAB_RELEASE = 4.3
98
99 #
100 # Default values
101 #
102 # minimal compat with macos, just so this does not complain 
103 HOSTARCH := $(shell uname -i 2> /dev/null || uname -m 2> /dev/null)
104 DISTRO := $(shell ./getdistro.sh)
105 RELEASE := $(shell ./getrelease.sh)
106 DISTRONAME := $(shell ./getdistroname.sh)
107 RPM-INSTALL-DEVEL := rpm --force -Uvh
108 # uninstall -- cannot force rpm -e
109 # need to ignore result, kernel-headers cannot be uninstalled as glibc depends on it
110 RPM-UNINSTALL-DEVEL := rpm -e
111
112 REMOTE-PLDISTROS="gnuradio"
113
114 #################### Makefile
115 # Default target
116 all:
117 .PHONY:all
118
119 ### default values
120 PLDISTRO := planetlab
121 RPMBUILD := rpmbuild
122 export CVS_RSH := ssh
123
124 ########## savedpldistro.mk holds PLDISTRO - it is generated at stage1 (see below)
125 ifeq "$(stage1)" ""
126 include savedpldistro.mk
127 endif
128
129 # when re-running the nightly build after failure, we need to gather the former values
130 # do this by running make stage1=skip +PLDISTRO
131 ifeq "$(stage1)" "skip"
132 include savedpldistro.mk
133 endif
134
135 #################### include onelab.mk
136 # describes the set of components
137 PLDISTROCONTENTS := $(PLDISTRO).mk
138 include $(PLDISTROCONTENTS)
139
140 #################### include <pldistro>-tags.mk
141 # describes where to fetch components, and the related tags if using cvs
142 PLDISTROTAGS := $(PLDISTRO)-tags.mk
143 include $(PLDISTROTAGS)
144
145 # this used to be set in the -tags.mk files, but that turned out to require
146 # error-prone duplicate changes 
147 # so now the nightly build script sets this to what it is currently using
148 # we set a default in case we run the build manually:
149 # if the local directory was svn checked out, then use the corresponding URL
150 svn-info-url-line := $(shell svn info 2> /dev/null | grep URL:)
151 default-build-SVNPATH := $(lastword $(svn-info-url-line))
152 # otherwise, use this hard-coded default
153 ifeq "$(default-build-SVNPATH)" ""
154 default-build-SVNPATH := http://svn.planet-lab.org/svn/build/trunk
155 endif
156 # use default if necessary
157 build-SVNPATH ?= $(default-build-SVNPATH)
158
159 ####################
160 define remote_pldistro
161 $(1).mk: config.$(1)/$(1).mk
162         @echo 'creating $(1) from config subdir'
163         cp config.$(1)/$(1).mk $(1).mk
164
165 $(2).mk: config.$(1)/$(2).mk
166         @echo 'creating $(1) tags from config subdir'
167         cp config.$(1)/$(2).mk $(2).mk
168
169 config.$(1)/$(1).mk: config.$(1)
170 config.$(1)/$(2).mk: config.$(1)
171
172 config.$(1): config.$(1).svnpath
173         @echo "Fetching details for pldistro $(1)"
174         svn export $(shell grep -v "^#" config.$(1).svnpath) config.$(1)
175
176 DISTCLEANS += $(1).mk $(2).mk config.$(1)
177
178 endef
179
180 $(eval $(call remote_pldistro,gnuradio,gnuradio-tags))
181
182 ########## stage1 and stage1iter
183 # extract specs and compute .mk files by running 
184 # make stage1=true
185 # entering stage1, we compute all the spec files
186 # then we use stage1iter to compute the .mk iteratively, 
187 # ensuring that the n-1 first makefiles are loaded when creating the n-th one
188 # when stage1iter is set, it is supposed to be an index (starting at 1) in $(ALL)
189
190 ALLMKS := $(foreach package, $(ALL), MAKE/$(package).mk)
191
192 ### stage1iter : need some arithmetic, see
193 # http://www.cmcrossroads.com/articles/ask-mr.-make/learning-gnu-make-functions-with-arithmetic.html
194 ifneq "$(stage1iter)" ""
195 # the first n packages
196 packages := $(wordlist 1,$(words $(stage1iter)),$(ALL))
197 # the n-th package
198 package := $(word $(words $(packages)),$(packages))
199 # the n-1 first packages
200 stage1iter_1 := $(wordlist 2,$(words $(stage1iter)),$(stage1iter))
201 previous := $(wordlist 1,$(words $(stage1iter_1)),$(ALL))
202 previousmks := $(foreach package,$(previous),MAKE/$(package).mk)
203 include $(previousmks)
204 all: verbose
205 verbose:
206         @echo "========== stage1iter : $(package)"
207 #       @echo "stage1iter : included .mk files : $(previousmks)"
208 all: $($(package).specpath)
209 all: MAKE/$(package).mk
210 else
211 ### stage1
212 ifneq "$(stage1)" ""
213 all : verbose
214 verbose :
215         @echo "========== stage1"
216 all : spec2make
217 all : .rpmmacros
218 # specs and makes are done sequentially by stage1iter
219 all : stage1iter
220 stage1iter:
221         arg=""; for n in $(ALL) ; do arg="$$arg x"; $(MAKE) --no-print-directory stage1iter="$$arg"; done
222 ### regular make
223 else
224 ### once .mks are OK, you can run make normally
225 include $(ALLMKS)
226 #all : tarballs
227 #all : sources
228 #all : codebases
229 #all : rpms
230 #all : srpms
231 # mention $(ALL) here rather than rpms 
232 # this is because the inter-package dependencies are expressed like
233 # util-vserver: util-python
234 all: rpms
235 all: repo
236 endif
237 endif
238
239 ### yumgroups.xml : compute from all known .pkgs files
240 RPMS/yumgroups.xml: 
241         mkdir -p RPMS
242         ./yumgroups.sh $(PLDISTRO) > $@
243
244 createrepo = createrepo --quiet -g yumgroups.xml RPMS/ 
245
246 repo: RPMS/yumgroups.xml
247         $(createrepo)
248
249 .PHONY: repo
250
251 ####################
252 # notes: 
253 # * to make configuration easier, we always use the first module's
254 # definitions (CVSROOT,TAG, or SVNPATH) to extract the spec file
255 # * for the same reason, in case cvs is used, the first module name is added to 
256 # $(package)-SPEC - otherwise the cvs modules have to define spec as 
257 # <module>/<module>.spec while svn modules just define it as <module>.spec
258 #
259 define stage1_variables
260 $(1).spec = $(notdir $($(1)-SPEC))
261 $(1).specpath = SPECS/$(1).spec
262 $(1).module = $(firstword $($(1)-MODULES))
263 $(1)-SVNPATH = $(strip $($(1)-SVNPATH))
264 endef
265
266 $(foreach package, $(ALL), $(eval $(call stage1_variables,$(package))))
267
268 #
269 # for each package, compute whether we need to set date 
270 # the heuristic is that we mention the date as part of the rpm release flag if
271 # (*) the package has requested it by setting package-RPMDATE (container packages should do that)
272 # (*) or SVNPATH contains 'trunk' or 'branches' 
273
274 define package_hasdate
275 $(1).has-date = $(if $($(1)-RPMDATE),yes, \
276                   $(if $($($(1).module)-SVNPATH), \
277                      $(if $(findstring /trunk,$($($(1).module)-SVNPATH)),yes, \
278                         $(if $(findstring /branches,$($($(1).module)-SVNPATH)),yes,)), \
279                      $(if $(findstring HEAD,$($($(1).module)-TAG)),yes,)))
280 endef
281
282 $(foreach package, $(ALL), $(eval $(call package_hasdate,$(package))))
283
284 ### the common header for generated specfiles
285 # useful when trying new specfiles manually
286 header.spec:
287         (echo -n "# Generated by planetlab build from $($(1)-SPEC) on " ; date) > $@
288         echo "%define distro $(DISTRO)" >> $@
289         echo "%define distrorelease $(RELEASE)" >> $@
290         echo "%define distroname $(DISTRONAME)" >> $@
291         echo "%define pldistro $(PLDISTRO)" >> $@
292         echo "%define plrelease $(PLANETLAB_RELEASE)" >> $@
293
294 ### extract spec file from scm
295 define target_spec
296 $($(1).specpath): header.spec
297         mkdir -p SPECS
298         cat header.spec > $($(1).specpath)
299         $(if $($(1).has-date),echo "%define date $(shell date +%Y.%m.%d)" >> $($(1).specpath),)
300         $(if $($(1)-SPECVARS), \
301           $(foreach line,$($(1)-SPECVARS), \
302             echo "%define" $(word 1,$(subst =, ,$(line))) "$(word 2,$(subst =, ,$(line)))" >> $($(1).specpath) ;))
303         echo "# included from $($(1)-SPEC)" >> $($(1).specpath)
304         $(if $($($(1).module)-SVNPATH),\
305           svn cat $($($(1).module)-SVNPATH)/$($(1)-SPEC) >> $($(1).specpath) || rm $($(1).specpath),\
306           cvs -d $($($(1).module)-CVSROOT) checkout \
307               -r $($($(1).module)-TAG) \
308               -p $($(1).module)/$($(1)-SPEC) >> $($(1).specpath))
309 endef
310
311 $(foreach package,$(ALL),$(eval $(call target_spec,$(package))))
312
313 ###
314 # Base rpmbuild in the current directory
315 # issues on fedora 8 : see the following posts
316 # http://forums.fedoraforum.org/showthread.php?t=39625 - and more specifically post#6
317 # https://www.redhat.com/archives/fedora-devel-list/2007-November/msg00171.html
318 REALROOT=/build
319 FAKEROOT=/longbuildroot
320 PWD=$(shell /bin/pwd)
321 ifeq "$(PWD)" "$(REALROOT)"
322 export HOME := $(FAKEROOT)
323 else
324 export HOME := $(PWD)
325 endif
326 .rpmmacros:
327 ifeq "$(shell pwd)" "/build"
328         rm -f $(FAKEROOT) ; ln -s $(REALROOT) $(FAKEROOT)
329 endif
330         rm -f $@ 
331         echo "%_topdir $(HOME)" >> $@
332         echo "%_tmppath $(HOME)/tmp" >> $@
333         ./getrpmmacros.sh >> $@
334
335 ### this utility allows to extract various info from a spec file
336 ### and to define them in makefiles
337 spec2make: spec2make.c
338         $(CC) -g -Wall $< -o $@ -lrpm -lrpmbuild
339
340 ### run spec2make on the spec file and include the result
341 # usage: spec2make package
342 define target_mk
343 MAKE/$(1).mk: $($(1).specpath) spec2make .rpmmacros
344         mkdir -p MAKE
345         ./spec2make $($(1)-RPMFLAGS) $($(1).specpath) $(1) > MAKE/$(1).mk || { rm MAKE/$(1).mk; exit 1; }
346 endef
347
348 $(foreach package,$(ALL),$(eval $(call target_mk,$(package))))
349
350 # stores PLDISTRO in a file
351 # this is done at stage1. later run wont get confused
352 savedpldistro.mk:
353         echo "PLDISTRO:=$(PLDISTRO)" > $@
354         echo "PLDISTROTAGS:=$(PLDISTROTAGS)" >> $@
355         echo "build-SVNPATH:=$(build-SVNPATH)" >> $@
356         echo "PERSONALITY:=$(PERSONALITY)" >> $@
357         echo "MAILTO:=$(MAILTO)" >> $@
358         echo "BASE:=$(BASE)" >> $@
359
360 savedpldistro: savedpldistro.mk
361 .PHONY: savedpldistro
362
363 # always refresh this
364 all: savedpldistro
365
366 #################### regular make
367
368 define stage2_variables
369 ### devel dependencies
370 $(1).rpmbuild = $(if $($(1)-RPMBUILD),$($(1)-RPMBUILD),$(RPMBUILD)) $($(1)-RPMFLAGS)
371 $(1).all-devel-rpm-paths := $(foreach rpm,$($(1)-DEPEND-DEVEL-RPMS),$($(rpm).rpm-path))
372 $(1).depend-devel-packages := $(sort $(foreach rpm,$($(1)-DEPEND-DEVEL-RPMS),$($(rpm).package)))
373 ALL-DEVEL-RPMS += $($(1)-DEPEND-DEVEL-RPMS)
374 endef
375
376 $(foreach package,$(ALL),$(eval $(call stage2_variables,$(package))))
377 ALL-DEVEL-RPMS := $(sort $(ALL-DEVEL-RPMS))
378
379
380 ### pack sources into tarballs
381 ALLTARBALLS:= $(foreach package, $(ALL), $($(package).tarballs))
382 tarballs: $(ALLTARBALLS)
383         @echo $(words $(ALLTARBALLS)) source tarballs OK
384 .PHONY: tarballs
385
386 SOURCES/%.tar.bz2: SOURCES/%
387         tar chpjf $@ -C SOURCES $*
388
389 SOURCES/%.tar.gz: SOURCES/%
390         tar chpzf $@ -C SOURCES $*
391
392 SOURCES/%.tgz: SOURCES/%
393         tar chpzf $@ -C SOURCES $*
394
395 ##
396 URLS/%: url=$(subst @colon@,:,$(subst @slash@,/,$(notdir $@)))
397 URLS/%: basename=$(notdir $(url))
398 URLS/%: 
399         echo curl $(url) -o SOURCES/$(basename)
400         touch $@
401
402 ### the directory SOURCES/<package>-<version> is made 
403 # with a copy -rl from CODEBASES/<package>
404 # the former is $(package.source) and the latter is $(package.codebase)
405 ALLSOURCES:=$(foreach package, $(ALL), $($(package).source))
406 # so that make does not use the rule below directly for creating the tarball files
407 .SECONDARY: $(ALLSOURCES)
408
409 sources: $(ALLSOURCES)
410         @echo $(words $(ALLSOURCES)) versioned source trees OK
411 .PHONY: sources
412
413 define target_link_codebase_sources
414 $($(1).source): $($(1).codebase) ; mkdir -p SOURCES ; cp -rl $($(1).codebase) $($(1).source)
415 endef
416
417 $(foreach package,$(ALL),$(eval $(call target_link_codebase_sources,$(package))))
418
419 ### codebase extraction
420 ALLCODEBASES:=$(foreach package, $(ALL), $($(package).codebase))
421 # so that make does not use the rule below directly for creating the tarball files
422 .SECONDARY: $(ALLCODEBASES)
423
424 codebases : $(ALLCODEBASES)
425         @echo $(words $(ALLCODEBASES)) codebase OK
426 .PHONY: codebases
427
428 ### extract codebase 
429 # usage: extract_single_module package 
430 define extract_single_module
431         mkdir -p CODEBASES
432         $(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))
433 endef
434
435 # usage: extract_multi_module package 
436 define extract_multi_module
437         mkdir -p CODEBASES/$(1) && cd CODEBASES/$(1) && (\
438         $(foreach m,$($(1)-MODULES), $(if $($(m)-SVNPATH), svn export $($(m)-SVNPATH) $(m);, cvs -d $($(m)-CVSROOT) export -r $($(m)-TAG) $(m);)))
439 endef
440
441 CODEBASES/%: package=$(notdir $@)
442 CODEBASES/%: multi_module=$(word 2,$($(package)-MODULES))
443 CODEBASES/%: 
444         @(echo -n "XXXXXXXXXXXXXXX -- BEG CODEBASE $(package) : $@ " ; date)
445         $(if $(multi_module),\
446           $(call extract_multi_module,$(package)),\
447           $(call extract_single_module,$(package)))
448         @(echo -n "XXXXXXXXXXXXXXX -- END CODEBASE $(package) : $@ " ; date)
449
450 ### source rpms
451 ALLSRPMS:=$(foreach package,$(ALL),$($(package).srpm))
452 srpms: $(ALLSRPMS)
453         @echo $(words $(ALLSRPMS)) source rpms OK
454 .PHONY: srpms
455
456 # usage: target_source_rpm package
457 define target_source_rpm 
458 ifeq "$($(1)-BUILD-FROM-SRPM)" ""
459 $($(1).srpm): $($(1).specpath) .rpmmacros $($(1).tarballs) 
460         mkdir -p BUILD SRPMS tmp
461         @(echo -n "XXXXXXXXXXXXXXX -- BEG SRPM $(1) (using SOURCES) " ; date)
462         $(if $($(1).all-devel-rpm-paths), $(RPM-INSTALL-DEVEL) $($(1).all-devel-rpm-paths))
463         $($(1).rpmbuild) -bs $($(1).specpath)
464         -$(if $($(1)-DEPEND-DEVEL-RPMS), $(RPM-UNINSTALL-DEVEL) $($(1)-DEPEND-DEVEL-RPMS))
465         @(echo -n "XXXXXXXXXXXXXXX -- END SRPM $(1) " ; date)
466 else
467 $($(1).srpm): $($(1).specpath) .rpmmacros $($(1).codebase)
468         mkdir -p BUILD SRPMS tmp
469         @(echo -n "XXXXXXXXXXXXXXX -- BEG SRPM $(1) (using make srpm) " ; date)
470         $(if $($(1).all-devel-rpm-paths), $(RPM-INSTALL-DEVEL) $($(1).all-devel-rpm-paths))
471         make -C $($(1).codebase) srpm SPECFILE=$(HOME)/$($(1).specpath) && \
472            rm -f SRPMS/$(notdir $($(1).srpm)) && \
473            ln $($(1).codebase)/$(notdir $($(1).srpm)) SRPMS/$(notdir $($(1).srpm)) 
474         -$(if $($(1)-DEPEND-DEVEL-RPMS), $(RPM-UNINSTALL-DEVEL) $($(1)-DEPEND-DEVEL-RPMS))
475         @(echo -n "XXXXXXXXXXXXXXX -- END SRPM $(1) " ; date)
476 endif
477 endef
478
479 $(foreach package,$(ALL),$(eval $(call target_source_rpm,$(package))))
480
481 ### binary rpms are made from source rpm
482 ALLRPMS:=$(foreach package,$(ALL),$($(package).rpms))
483 # same as above, mention $(ALL) and not $(ALLRPMS)
484 rpms: $(ALLRPMS)
485         @echo $(words $(ALLRPMS)) binary rpms OK
486 .PHONY: rpms
487
488 # use tmp dirs when building binary rpm so make remains idempotent 
489 # otherwise SOURCES/ or SPEC gets touched again - which leads to rebuilding
490 RPM-USE-TMP-DIRS = --define "_sourcedir $(HOME)/tmp" --define "_specdir $(HOME)/tmp"
491 RPM-USE-COMPILE-DIRS = --define "_sourcedir $(HOME)/COMPILE" --define "_specdir $(HOME)/COMPILE"
492
493 # usage: build_binary_rpm package
494 # xxx hacky - invoke createrepo if DEPEND-FILES mentions RPMS/yumgroups.xml
495 define target_binary_rpm 
496 $($(1).rpms): $($(1).srpm)
497         mkdir -p RPMS tmp
498         @(echo -n "XXXXXXXXXXXXXXX -- BEG RPM $(1) " ; date)
499         $(if $(findstring RPMS/yumgroups.xml,$($(1)-DEPEND-FILES)), $(createrepo) , )
500         $(if $($(1).all-devel-rpm-paths), $(RPM-INSTALL-DEVEL) $($(1).all-devel-rpm-paths))
501         $($(1).rpmbuild) --rebuild $(RPM-USE-TMP-DIRS) $($(1).srpm)
502         -$(if $($(1)-DEPEND-DEVEL-RPMS), $(RPM-UNINSTALL-DEVEL) $($(1)-DEPEND-DEVEL-RPMS))
503         @(echo -n "XXXXXXXXXXXXXXX -- END RPM $(1) " ; date)
504 # for manual use only - in case we need to investigate the results of an rpmbuild
505 $(1)-compile: $($(1).srpm)
506         mkdir -p COMPILE tmp
507         @(echo -n "XXXXXXXXXXXXXXX -- BEG compile $(1) " ; date)
508         $(if $(findstring RPMS/yumgroups.xml,$($(1)-DEPEND-FILES)), $(createrepo) , )
509         $(if $($(1).all-devel-rpm-paths), $(RPM-INSTALL-DEVEL) $($(1).all-devel-rpm-paths))
510         $($(1).rpmbuild) --recompile $(RPM-USE-TMP-DIRS) $($(1).srpm)
511         -$(if $($(1)-DEPEND-DEVEL-RPMS), $(RPM-UNINSTALL-DEVEL) $($(1)-DEPEND-DEVEL-RPMS))
512         @(echo -n "XXXXXXXXXXXXXXX -- END compile $(1) " ; date)
513 .PHONY: $(1)-compile
514 endef
515
516 $(foreach package,$(ALL),$(eval $(call target_binary_rpm,$(package))))
517 ### shorthand target
518 # e.g. make proper -> does propers rpms
519 # usage shorthand_target package
520 define target_shorthand 
521 $(1): $($(1).rpms)
522 .PHONY: $(1)
523 $(1)-spec: $($(1)-SPEC)
524 .PHONY: $(1)-spec
525 $(1)-mk: $($(1)-MK)
526 .PHONY: $(1)-mk
527 $(1)-tarball: $($(1).tarballs)
528 .PHONY: $(1)-tarball
529 $(1)-codebase: $($(1).codebase)
530 .PHONY: $(1)-source
531 $(1)-source: $($(1).source)
532 .PHONY: $(1)-codebase
533 $(1)-rpms: $($(1).rpms)
534 .PHONY: $(1)-rpms
535 $(1)-srpm: $($(1).srpm)
536 .PHONY: $(1)-srpm
537 endef
538
539 $(foreach package,$(ALL),$(eval $(call target_shorthand,$(package))))
540
541 ### file dependencies
542 define package_depends_on_file
543 $(1):$(2)
544 $($(1).srpm):$(2)
545 endef
546
547 define target_dependfiles
548 $(foreach file,$($(1)-DEPEND-FILES),$(eval $(call package_depends_on_file,$(1),$(file))))
549 endef
550
551 $(foreach package,$(ALL),$(eval $(call target_dependfiles,$(package))))
552
553 ### package dependencies
554 define package_depends_on_package
555 $(1):$(2)
556 $(1):$($(2).rpms)
557 $($(1).srpm):$($(2).rpms)
558 endef
559
560 define target_depends
561 $(foreach package,$($(1)-DEPEND-PACKAGES) $($(1).depend-devel-packages),$(eval $(call package_depends_on_package,$(1),$(package))))
562 endef
563
564 $(foreach package,$(ALL),$(eval $(call target_depends,$(package))))
565
566 ### clean target
567 # usage: target_clean package
568 define target_clean
569 $(1)-clean-codebase:
570         rm -rf $($(1).codebase)
571 .PHONY: $(1)-clean-codebase
572 CLEANS += $(1)-clean-codebase
573 $(1)-clean-source:
574         rm -rf $($(1).source)
575 .PHONY: $(1)-clean-source
576 CLEANS += $(1)-clean-source
577 $(1)-clean-tarball:
578         rm -rf $($(1).tarballs)
579 .PHONY: $(1)-clean-tarball
580 CLEANS += $(1)-clean-tarball
581 $(1)-clean-build:
582         rm -rf BUILD/$(notdir $($(1).source))
583 CLEANS += $(1)-clean-build
584 $(1)-clean-rpms:
585         rm -rf $($(1).rpms)
586 .PHONY: $(1)-clean-rpms
587 CLEANS += $(1)-clean-rpms
588 $(1)-clean-srpm:
589         rm -rf $($(1).srpm)
590 .PHONY: $(1)-clean-srpm
591 CLEANS += $(1)-clean-srpm
592 $(1)-codeclean: $(1)-clean-source $(1)-clean-tarball $(1)-clean-build $(1)-clean-rpms $(1)-clean-srpm
593 $(1)-clean: $(1)-clean-codebase $(1)-codeclean
594 .PHONY: $(1)-codeclean $(1)-clean 
595 $(1)-clean-spec:
596         rm -rf $($(1).specpath)
597 .PHONY: $(1)-clean-spec
598 $(1)-clean-make:
599         rm -rf MAKE/$(1).mk
600 .PHONY: $(1)-clean-make
601 $(1)-distclean: $(1)-distclean1 $(1)-distclean2
602 $(1)-distclean1: $(1)-clean-spec $(1)-clean-make
603 $(1)-distclean2: $(1)-clean
604 .PHONY: $(1)-distclean $(1)-distclean1 $(1)-distclean2
605 endef
606
607 $(foreach package,$(ALL),$(eval $(call target_clean,$(package))))
608
609 ### clean precisely
610 clean:
611         $(MAKE) $(CLEANS)
612 .PHONY: clean
613
614 clean-help:
615         @echo Available clean targets
616         @echo $(CLEANS)
617
618 ### brute force clean
619 distclean1:
620         rm -rf savedpldistro.mk .rpmmacros spec2make header.spec SPECS MAKE $(DISTCLEANS)
621 distclean2:
622         rm -rf CODEBASES SOURCES BUILD RPMS SRPMS tmp
623 distclean: distclean1 distclean2
624 .PHONY: distclean1 distclean2 distclean
625
626 develclean:
627         -$(RPM-UNINSTALL-DEVEL) $(ALL-DEVEL-RPMS)
628
629 ####################
630 # gather build information for the 'About' page
631 # when run from crontab, INIT_CWD not properly set (says /root ..)
632 # so, the nightly build passes BASE here
633 # also store BASE in .base for any post-processing purposes
634 myplc-release:
635         @echo 'Creating myplc-release'
636         rm -f $@
637         echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx build info" >> $@
638         $(MAKE) --no-print-directory version-build >> $@
639         echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx svn info" >> $@
640         $(MAKE) --no-print-directory version-svns >> $@
641         echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx rpm info" >> $@
642         $(MAKE) --no-print-directory version-rpms >> $@
643         @echo $(BASE) > .base
644
645 version-build:
646         @echo -n 'Build build-date: ' ; date '+%Y.%m.%d'
647         @echo -n 'Build build-time: ' ; date '+%H:%M-%Z'
648         @echo -n 'Build build-hostname: ' ; hostname
649         @echo    "Build build-base: $(BASE)"
650         @echo    "Build planetlab-distro: $(PLDISTRO)"
651         @echo    "Build planetlab-tags: $(PLDISTROTAGS)"
652         @echo -n 'Build planetlab-tagsid: ' ; fgrep '$$''Id' $(PLDISTROTAGS)
653         @echo    "Build target-arch: $(HOSTARCH)"
654         @echo    "Build target-distro: $(DISTRO)"
655         @echo    "Build target-distroname: $(DISTRONAME)"
656         @echo    "Build target-release: $(RELEASE)"     
657         @echo    "Build target-personality: $(PERSONALITY)"     
658
659 #################### 
660 # for a given module
661 VFORMAT="%30s := %s\n"
662 define svn_version_target
663 $(1)-version-svn:
664         @$(if $($(1)-SVNPATH),\
665            printf $(VFORMAT) $(1)-SVNPATH "$($(1)-SVNPATH)",\
666            printf $(VFORMAT) $(1)-CVSROOT "$($(1)-CVSROOT)" ; printf $(VFORMAT) $(1)-TAG "$($(1)-TAG)")
667 endef
668
669 # compute all modules
670 ALL-MODULES :=
671 $(foreach package,$(ALL), $(eval ALL-MODULES+=$($(package)-MODULES)))
672 ALL-MODULES:=$(sort $(ALL-MODULES))
673
674 $(foreach module,$(ALL-MODULES), $(eval $(call svn_version_target,$(module))))
675
676 version-svns: $(foreach module, $(ALL-MODULES), $(module)-version-svn)
677
678 RFORMAT="%20s :: version=%s release=%s\n"
679 define rpm_version_target
680 $(1)-version-rpm:
681         @printf $(RFORMAT) $($(1).rpm-name) $($(1).rpm-version) $($(1).rpm-release)
682 version-rpms: $(1)-version-rpm
683 endef
684
685 $(foreach package,$(sort $(ALL)), $(eval $(call rpm_version_target,$(package))))
686
687 versions: myplc-release version-build version-svns version-rpms
688 .PHONY: versions version-build version-rpms version-svns
689
690 #################### package info
691 PKGKEYS := tarballs source codebase srpm rpms rpmnames rpm-release rpm-name rpm-version rpm-subversion
692 %-pkginfo: package=$(subst -pkginfo,,$@)
693 %-pkginfo: 
694         @$(foreach key,$(PKGKEYS),echo "$(package).$(key)=$($(package).$(key))";)
695 ## rpm info
696 RPMKEYS := rpm-path package
697 %-rpminfo: rpm=$(subst -rpminfo,,$@)
698 %-rpminfo: 
699         @$(foreach key,$(RPMKEYS),echo "$(rpm).$(key)=$($(rpm).$(key))";)
700
701 #################### various lists - designed to run with stage1=true
702 packages:
703         @$(foreach package,$(ALL), echo package=$(package) ref_module=$($(package).module) modules=$($(package)-MODULES) rpmnames=$($(package).rpmnames); )
704
705 modules:
706         @$(foreach module,$(ALL-MODULES), echo module=$(module) svnpath=$($(module)-SVNPATH); )
707
708 branches:
709         @$(foreach module,$(ALL-MODULES), \
710           $(if $($(module)-SVNBRANCH),echo module=$(module) branch=$($(module)-SVNBRANCH);))
711
712 module-tools:
713         @$(foreach module,$(ALL-MODULES), \
714          $(if $($(module)-SVNPATH), \
715           $(if $($(module)-SVNBRANCH), \
716              echo $(module):$($(module)-SVNBRANCH); , \
717              echo $(module); )))
718
719 info: packages modules branches 
720
721 .PHONY: info packages modules branches module-tools
722
723 ####################
724 tests_svnpath:
725         @$(if $(TESTS_SVNPATH), echo $(TESTS_SVNPATH) > $@, \
726         echo "http://svn.planet-lab.org/svn/tests/trunk" > $@)
727
728
729 ####################
730 help:
731         @echo "********** Run make in two stages:"
732         @echo ""
733         @echo "make stage1=true PLDISTRO=onelab"
734         @echo " -> extracts all spec files in SPECS/ and mk files in MAKE/"
735         @echo "    as well as save PLDISTRO for subsequent runs"
736         @echo ""
737         @echo "********** Then you can use the following targets"
738         @echo 'make'
739         @echo "  rebuilds everything"
740         @echo 'make util-vserver'
741         @echo "  makes the RPMS related to util-vserver"
742         @echo "  equivalent to 'make util-vserver-rpms'"
743         @echo ""
744         @echo "********** Or, vertically - step-by-step for a given package"
745         @echo 'make util-vserver-codebase'
746         @echo "  performs codebase extraction in CODEBASES/util-vserver"
747         @echo 'make util-vserver-source'
748         @echo "  creates source link in SOURCES/util-vserver-<version>"
749         @echo 'make util-vserver-tarball'
750         @echo "  creates source tarball in SOURCES/util-vserver-<version>.<tarextension>"
751         @echo 'make util-vserver-srpm'
752         @echo "  build source rpm in SRPMS/"
753         @echo 'make util-vserver-rpms'
754         @echo "  build rpm(s) in RPMS/"
755         @echo ""
756         @echo "********** Or, horizontally, reach a step for all known packages"
757         @echo 'make codebases'
758         @echo 'make sources'
759         @echo 'make tarballs'
760         @echo 'make srpms'
761         @echo 'make rpms'
762         @echo ""
763         @echo "********** Manual targets"
764         @echo "make package-compile"
765         @echo "  The regular process uses rpmbuild --rebuild, that performs"
766         @echo "  a compilation directory cleanup upon completion. If you need to investigate"
767         @echo "  the intermediate compilation directory, use the -compile targets"
768         @echo "********** Cleaning examples"
769         @echo "make clean"
770         @echo "  removes the files made by make"
771         @echo "make distclean"
772         @echo "  brute-force cleaning, removes entire directories - requires a new stage1"
773         @echo "make develclean"
774         @echo "  rpm-uninstalls all devel packages installed during build"
775         @echo ""
776         @echo "make iptables-distclean"
777         @echo "  deep clean for a given package"
778         @echo "make iptables-codeclean"
779         @echo "  run this if you've made a change in the CODEBASES area for iptables"
780         @echo ""
781         @echo "make util-vserver-clean"
782         @echo "  removes codebase, source, tarball, build, rpm and srpm for util-vserver"
783         @echo "make util-vserver-clean-codebase"
784         @echo "  and so on for source, tarball, build, rpm and srpm"
785         @echo ""
786         @echo "********** Info examples"
787         @echo "make ++ALL"
788         @echo "  Displays the value of a given variable (here ALL)"
789         @echo "  with only a single plus sign only the value is displayed"
790         @echo "make info"
791         @echo "  is equivalent to make packages modules branches"
792         @echo "  provides various info on these objects"
793         @echo "make ulogd-pkginfo"
794         @echo "  Displays know attributes of a package"
795         @echo "make kernel-devel-rpminfo"
796         @echo "  Displays know attributes of an rpm"
797         @echo "make stage1=true PLDISTROTAGS=planetlab-tags-4.2.mk packages modules branches module-tools"
798         @echo "  Lists mentioned items - module-tools is used in modules.update"
799         @echo ""
800         @echo "********** Known pakages are"
801         @echo "$(ALL)"
802
803 #################### convenience, for debugging only
804 # make +foo : prints the value of $(foo)
805 # make ++foo : idem but verbose, i.e. foo=$(foo)
806 ++%: varname=$(subst +,,$@)
807 ++%:
808         @echo "$(varname)=$($(varname))"
809 +%: varname=$(subst +,,$@)
810 +%:
811         @echo "$($(varname))"