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