2 # Thierry Parmentelat - INRIA Sophia Antipolis
8 # this extracts all specfiles and computes .mk from specfiles
9 # you need to specify PLDISTRO here if relevant - see below
11 # for more info on how to invoke this stuff
13 #################### (fedora) distributions
15 # (*) as of nov. 2007, myplc-devel is deprecated
16 # (*) instead, we create a fresh vserver that holds required tools (see e.g. planetlab-devel.lst)
17 # (*) the build uses the current fedora version as a target for the produced images
18 # (*) so you simply need to create a fedora 8 build image for building fedora-8 images
20 #################### (planetlab) distributions
22 # (*) see README-pldistros.txt
23 # (*) then you need to run
24 # make stage1=true PLDISTRO=onelab
27 # This build deals with 3 kinds of objects
29 # (*) packages are named upon the RPM name; they are mostly lowercase
30 # Add a package to ALL if you want it built as part of the default set.
31 # (*) modules are named after the subversion or git tree; we would wish to keep
32 # these names lowercase as far as possible
33 # (*) rpms are named in the spec files. A package typically defines several rpms;
34 # rpms are used for defining DEPEND-DEVEL-RPMS. See also package.rpmnames
36 # in simple cases, one package uses one module (in which case using the same name sounds right)
37 # but others might need several modules (e.g. image-creation packages like bootstrapfs need
38 # bootstrapfs and build); in this case the FIRST ONE is used for locating the specfile
40 #################### packages
41 # basics: how to build a package - you need to define the following variables
44 # a package needs one or several modules to build; the first one is used for
45 # some special purposes, like locating the specfile
47 # the package's specfile; this is relative to the FIRST module in package-MODULES
51 # (*) package-DEPEND-PACKAGES
52 # a set of (obviously local) *packages* that this package depends on, e.g.
53 # bootstrapfs-DEPEND-PACKAGES += kernel
54 # this impacts the order of the build
55 # (*) package-DEVEL-RPMS
56 # a set of stock rpms that this package needs at build-time
57 # this can also be set in config.<distro>/devel.pkgs or config.planetlab/devel.pkgs as appropriate
58 # (*) package-DEPEND-DEVEL-RPMS
59 # a set of local *rpms* that the build will rpm-install before building <package>
60 # the build will attempt to uninstall those once the package is built, this is not fatal though
61 # this is intended to denote local rpms, i.e. ones that are results of our own build
62 # stock rpms should be mentioned in DEVEL-RPMS or in devel.pkgs as described above
63 # (*) package-DEPEND-DEVEL-RPMS-UPDATES
64 # like package-DEPEND-DEVEL-RPMS but for crucial packages (like autoconf) that only need an update from our build
65 # rpms in this area will *not* be uninstalled after the target is made, because that would ruin the build vm for good
66 # (*) package-DEPEND-FILES
67 # a set of files that the package depends on - and that make needs to know about
68 # if this contains RPMS/yumgroups.xml, then the toplevel RPMS's index
69 # is refreshed with createrepo prior to running rpmbuild
70 # (*) package-SPECVARS
71 # space-separated list of spec variable definitions, where you can reference make variables that
72 # belong to packages defined BEFORE the current one
73 # note: you should use = to define these (as opposed to :=)
74 # e.g. mydriver-SPECVARS = foo=$(kernel-rpm-release)
75 # would let you use the %release from the kernel's package when rpmbuild'ing mydriver
77 # (*) package-RPMFLAGS: Miscellaneous RPM flags
78 # this is passed to rpmbuild, as well as to spec2make for "exporting" various rpm variable
79 # to make; beware that some features, like --with=debug or --define 'foo bar' are not
80 # well handled by spec2make as of this writing, which can cause issues.
81 # hopefully this will be fixed...
82 # (*) package-BUILD-FROM-SRPM: set this to any non-empty value,
83 # if your package is able to produce a source rpm.
84 # In this case the build will first invoke 'make srpm', and then rebuild binaries from that
85 # (*) package-RPMDATE: set this to any non-empty value to get the rpm package's release field hold the current date
86 # this is useful for container packages, like e.g. bootstrapfs or vserver, that contains much more than the
89 #################### modules
90 # Required information about the various modules (set this in e.g. planetlab-tags.mk)
94 # the complete path where this module lies;
95 # you can specify the trunk or a given tag with this variable
99 # which by analogy with svn revision scheme, is expected to be <url>@<tag>
101 #################### automatic variables
103 # the build defines some make variables that are extracted from spec files
104 # to inspect those, see for example
105 # (*) $ make ulogd-pkginfo
106 # to see the list f variables attached to a given package
107 # (*) $ make kernel-devel-rpminfo
108 # to see the list of variables attached to a given rpm
112 # exported to spec files as plrelease
113 PLANETLAB_RELEASE = 5.2
118 # minimal compat with macos, just so this does not complain
119 HOSTARCH := $(shell uname -i 2> /dev/null || uname -m 2> /dev/null)
120 DISTRO := $(shell ./getdistro.sh)
121 RELEASE := $(shell ./getrelease.sh)
122 DISTRONAME := $(shell ./getdistroname.sh)
123 RPM-INSTALL-DEVEL := rpm --force -Uvh
124 # uninstall -- cannot force rpm -e
125 # need to ignore result, kernel-headers cannot be uninstalled as glibc depends on it
126 RPM-UNINSTALL-DEVEL := rpm -e
127 YUM-INSTALL-DEVEL := yum -y install
129 #################### Makefile
135 PLDISTRO := planetlab
138 ########## envfrompreviousrun.mk holds PLDISTRO and others - it is generated at stage1 (see below)
140 include envfrompreviousrun.mk
143 # when re-running the nightly build after failure, we need to gather the former values
144 # do this by running make stage1=skip +PLDISTRO
145 ifeq "$(stage1)" "skip"
146 include envfrompreviousrun.mk
149 #################### include onelab.mk
150 # describes the set of components
151 PLDISTROCONTENTS := $(PLDISTRO).mk
152 include $(PLDISTROCONTENTS)
154 #################### include <pldistro>-tags.mk
155 # describes where to fetch components
156 ifeq "$(PLDISTROTAGS)" ""
157 PLDISTROTAGS := $(PLDISTRO)-tags.mk
159 include $(PLDISTROTAGS)
161 # this used to be set in the -tags.mk files, but that turned out to require
162 # error-prone duplicate changes
163 # so now the nightly build script sets this to what it is currently using
164 # in case we run this manually, i.e. if build-GITPATH is not set
165 ifeq "$(build-GITPATH)" ""
166 build-GITPATH := $(shell git config remote.origin.url)
169 #################### pldistros that are defined remotely
171 define remote_pldistro_fetch_svn
172 $(1).config.SVNPATH := $(shell grep -v "^#" config.$(1).svnpath)
173 config.$(1): config.$(1).svnpath
174 @echo "Fetching (svn) details for remote pldistro $(1)"
175 svn export $$($(1).config.SVNPATH) config.$(1)
179 define remote_pldistro_fetch_git
180 $(1).config.GITPATH := $(shell grep -v "^#" config.$(1).gitpath)
181 $(1).config.gitrepo := $$(firstword $$(subst @, ,$$($(1).config.GITPATH)))
182 $(1).config.gittag := $$(word 2,$$(subst @, ,$$($(1).config.GITPATH)))
183 $(1).config.gittag := $$(if $$($(1).config.gittag),$$($(1).config.gittag),master)
184 config.$(1): GITPATH=$(shell grep -v "^#" config.$(1).gitpath)
185 config.$(1): config.$(1).gitpath
186 @echo "Fetching (git) details for remote pldistro $(1)"
188 git $(GITTAG) archive --remote=$$($(1).config.gitrepo) $$($(1).config.gittag) | tar -C config.$(1) -xf -
193 define remote_pldistro
194 $(1).mk: config.$(1)/$(1).mk
195 @echo 'creating $(1) from config.$(1)'
196 cp config.$(1)/$(1).mk $(1).mk
198 $(2).mk: config.$(1)/$(2).mk
199 @echo 'creating $(2) tags from config.$(1)'
200 cp config.$(1)/$(2).mk $(2).mk
202 config.$(1)/$(1).mk: config.$(1)
203 config.$(1)/$(2).mk: config.$(1)
205 DISTCLEANS += $(1).mk $(2).mk config.$(1)
206 $(eval $(call remote_pldistro_fetch_$(3),$(1)))
209 $(eval $(call remote_pldistro,wextoolbox,wextoolbox-tags,git))
210 $(eval $(call remote_pldistro,wexlxc,wexlxc-tags,git))
212 ########## stage1 and stage1iter
213 # extract specs and compute .mk files by running
215 # entering stage1, we compute all the spec files
216 # then we use stage1iter to compute the .mk iteratively,
217 # ensuring that the n-1 first makefiles are loaded when creating the n-th one
218 # when stage1iter is set, it is supposed to be an index (starting at 1) in $(ALL)
220 ALLMKS := $(foreach package, $(ALL), MAKE/$(package).mk)
222 ### stage1iter : need some arithmetic, see
223 # http://www.cmcrossroads.com/articles/ask-mr.-make/learning-gnu-make-functions-with-arithmetic.html
224 ifneq "$(stage1iter)" ""
225 # the first n packages
226 packages := $(wordlist 1,$(words $(stage1iter)),$(ALL))
228 package := $(word $(words $(packages)),$(packages))
229 # the n-1 first packages
230 stage1iter_1 := $(wordlist 2,$(words $(stage1iter)),$(stage1iter))
231 previous := $(wordlist 1,$(words $(stage1iter_1)),$(ALL))
232 previousmks := $(foreach package,$(previous),MAKE/$(package).mk)
233 include $(previousmks)
236 @echo "========== stage1iter : $(package)"
237 # @echo "stage1iter : included .mk files : $(previousmks)"
238 all: $($(package).specpath)
239 all: MAKE/$(package).mk
245 @echo "========== stage1"
248 # specs and makes are done sequentially by stage1iter
251 arg=""; for n in $(ALL) ; do arg="$$arg x"; $(MAKE) --no-print-directory stage1iter="$$arg"; done
254 ### once .mks are OK, you can run make normally
261 # mention $(ALL) here rather than rpms
262 # this is because the inter-package dependencies are expressed like
263 # util-vserver: util-python
269 ### yumgroups.xml : compute from all known .pkgs files
272 ./yumgroups.sh $(PLDISTRO) > $@
274 createrepo = createrepo --quiet -g yumgroups.xml RPMS/
276 repo: RPMS/yumgroups.xml
283 # * we always use the first module's location (SVNPATH/GITPATH) to extract the spec file
284 # * no matter what SCM is used, SPEC should hold a relative path from the module's root
286 define stage1_package_vars
287 $(1).module := $(firstword $($(1)-MODULES))
288 $(1).specpath := SPECS/$(notdir $($(1)-SPEC))
289 $(1).moduledir := MODULES/$$($(1).module)
290 $(1).codespec := MODULES/$$($(1).module)/$($(1)-SPEC)
291 $(1).spec2makeflags := $(if $($(1)-WHITELIST-RPMS),--whitelist-rpms $($(1)-WHITELIST-RPMS),)
294 $(foreach package, $(ALL), $(eval $(call stage1_package_vars,$(package))))
296 # compute all modules
297 ALL.modules := build tests
298 $(foreach package,$(ALL), $(eval ALL.modules+=$($(package)-MODULES)))
299 ALL.modules:=$(sort $(ALL.modules))
301 # extract revision from -SVNPATH or tag from -GITPATH
302 define stage1_module_vars
303 ifneq "$($(1)-SVNPATH)" ""
304 $(1)-SVNPATH := $(strip $($(1)-SVNPATH))
305 $(1)-SCMPATH := $(strip $($(1)-SVNPATH))
307 $(1)-GITPATH := $$(strip $$($(1)-GITPATH))
308 $(1)-SCMPATH := $$(strip $$($(1)-GITPATH))
309 $(1).gitrepo := $$(firstword $$(subst @, ,$$($(1)-GITPATH)))
310 $(1).gittag := $$(word 2,$$(subst @, ,$$($(1)-GITPATH)))
311 $(1).gittag := $$(if $$($(1).gittag),$$($(1).gittag),master)
315 $(foreach module,$(ALL.modules), $(eval $(call stage1_module_vars,$(module))))
318 # for each package, compute whether we need to set date
319 # the heuristic is that we mention the date as part of the rpm release flag if
320 # (*) the package has requested it by setting package-RPMDATE (container packages should do that)
321 # (*) or SVNPATH contains 'trunk' or 'branches'
322 # (*) or GITPATH has no '@' (trunk)
323 # (*) or GITPATH contains a '@', and the gittag part has no '-' (this is to tell a tag from a branch..)
325 define package_hasdate
326 $(1).has-date = $(if $($(1)-RPMDATE),yes, \
327 $(if $($($(1).module)-SVNPATH), \
328 $(if $(findstring /trunk,$($($(1).module)-SVNPATH)),yes, \
329 $(if $(findstring /branches,$($($(1).module)-SVNPATH)),yes,)), \
330 $(if $(not $($($(1).module).gittag)), yes,\
331 $(if $(findstring -,$($($(1).module).gittag)),,yes))))
334 $(foreach package, $(ALL), $(eval $(call package_hasdate,$(package))))
336 ### the common header for generated specfiles
337 # useful when trying new specfiles manually
339 (echo -n "# Generated by planetlab build on " ; date) > $@
340 echo "%define distro $(DISTRO)" >> $@
341 echo "%define distrorelease $(RELEASE)" >> $@
342 echo "%define distroname $(DISTRONAME)" >> $@
343 echo "%define pldistro $(PLDISTRO)" >> $@
344 echo "%define plrelease $(PLANETLAB_RELEASE)" >> $@
345 echo "# use MD5 and gzip for binary and source files" >> $@
346 echo "%global _binary_filedigest_algorithm 1" >> $@
347 echo "%global _source_filedigest_algorithm 1" >> $@
348 echo "%global _source_payload w9.gzdio" >> $@
349 echo "%global _binary_payload w9.gzdio" >> $@
351 ### make up spec file - extract module first
353 $($(1).specpath): header.spec $($(1).codespec)
355 cat header.spec > $($(1).specpath)
356 echo "%define SCMURL $($($(1).module)-SCMPATH)" >> $($(1).specpath)
357 $(if $($(1).has-date),echo "%define date $(shell date +%Y.%m.%d)" >> $($(1).specpath),)
358 $(if $($(1)-SPECVARS), \
359 $(foreach line,$($(1)-SPECVARS), \
360 echo "%define" $(word 1,$(subst =, ,$(line))) "$(word 2,$(subst =, ,$(line)))" >> $($(1).specpath) ;))
361 echo "# included from $($(1)-SPEC)" >> $($(1).specpath)
362 cat $($(1).codespec) >> $($(1).specpath)
364 $($(1).codespec): $($(1).moduledir)
368 $(foreach package,$(ALL),$(eval $(call target_spec,$(package))))
370 ### module extraction
371 define target_extract_module
373 @(echo -n "XXXXXXXXXXXXXXX -- BEG MODULE $(1) : $@ " ; date)
376 $(if $($(1)-SVNPATH),\
377 svn export $($(1)-SVNPATH) $(1),\
378 mkdir $(1) ; (git archive --remote=$($(1).gitrepo) $($(1).gittag) | tar -C $(1) -xf - ) \
379 || { rm -rf $(1); false; } )
380 @(echo -n "XXXXXXXXXXXXXXX -- END MODULE $(1) : $@ " ; date)
382 $(1)-module: MODULES/$(1)
386 $(foreach module,$(ALL.modules),$(eval $(call target_extract_module,$(module))))
389 # use this makefile to extract tests rather than extracting manually in vbuild-nightly
399 # Base rpmbuild in the current directory
400 # issues on fedora 8 : see the following posts
401 # http://forums.fedoraforum.org/showthread.php?t=39625 - and more specifically post#6
402 # https://www.redhat.com/archives/fedora-devel-list/2007-November/msg00171.html
404 FAKEROOT=/longbuildroot
405 PWD=$(shell /bin/pwd)
406 ifeq "$(PWD)" "$(REALROOT)"
407 export HOME := $(FAKEROOT)
409 export HOME := $(PWD)
412 ifeq "$(shell pwd)" "/build"
413 rm -f $(FAKEROOT) ; ln -s $(REALROOT) $(FAKEROOT)
416 echo "%_topdir $(HOME)" >> $@
417 echo "%_tmppath $(HOME)/tmp" >> $@
418 echo "%__spec_install_pre %{___build_pre}" >> $@
419 ./getrpmmacros.sh >> $@
421 ### this utility allows to extract various info from a spec file
422 ### and to define them in makefiles
423 # use the C code where it works as it's the original one, use the python code otherwise
424 spec2make: spec2make.c
425 $(CC) -g -Wall $< -o $@ -lrpm -lrpmbuild -lrpmio -lpopt || ln -s spec2make.py $@
427 ### run spec2make on the spec file and include the result
428 # usage: spec2make package
429 # with old rpms (f8&c5) and too recent specfiles (the kernel), we need a patch to spec2make
430 # so when <package-NEEDSPECK2MAKEHACK is set, we run spec2make with the --hack flag
432 MAKE/$(1).mk: $($(1).specpath) spec2make .rpmmacros
434 ./spec2make $($(1).spec2makeflags) $($(1)-RPMFLAGS) $($(1).specpath) $(1) > MAKE/$(1).mk || { rm MAKE/$(1).mk; exit 1; }
437 $(foreach package,$(ALL),$(eval $(call target_mk,$(package))))
439 # stores env variables in a file
440 # this is done at stage1. later run wont get confused
441 SAVED_VARS=PLDISTRO PLDISTROTAGS build-GITPATH PERSONALITY MAILTO BASE WEBPATH TESTBUILDURL WEBROOT
442 # also remember variable settings in alias, like sfa-GITPATH=git://git.f-lab.fr/sfa.git@generic
443 # but don't save stage1
444 ASSIGNS=$(foreach chunk,$(MAKEFLAGS),$(if $(findstring =,$(chunk)),$(if $(findstring stage1,$(chunk)),,$(chunk)),))
445 envfrompreviousrun.mk:
446 @echo "# do not edit" > $@
447 @$(foreach var,$(SAVED_VARS),echo "$(var):=$($(var))" >> $@ ;)
448 @$(foreach chunk,$(ASSIGNS),echo "override $(chunk)" | sed -e s,=,:=, >> $@;)
449 @echo "# do not edit" > aliases
450 @echo -n "alias m=\"make " >> aliases
451 @$(foreach var,$(SAVED_VARS),echo -n " $(var)=$($(var))" >> aliases ;)
452 @echo -n $(ASSIGNS) >> aliases
453 @echo "\"" >> aliases
454 @echo "alias m1=\"m stage1=true\"" >> aliases
456 envfrompreviousrun: envfrompreviousrun.mk
457 .PHONY: envfrompreviousrun
459 # always refresh this
460 all: envfrompreviousrun
462 #################### regular make
464 define stage2_variables
465 ### devel dependencies
466 $(1).rpmbuild = $(RPMBUILD) $($(1)-RPMFLAGS)
467 $(1).all-devel-rpm-paths := $(foreach rpm,$($(1)-DEPEND-DEVEL-RPMS) $($(1)-DEPEND-DEVEL-RPMS-UPDATES),$($(rpm).rpm-path))
468 $(1).depend-devel-packages := $(sort $(foreach rpm,$($(1)-DEPEND-DEVEL-RPMS),$($(rpm).package)))
469 ALL-DEVEL-RPMS += $($(1)-DEPEND-DEVEL-RPMS)
472 $(foreach package,$(ALL),$(eval $(call stage2_variables,$(package))))
473 ALL-DEVEL-RPMS := $(sort $(ALL-DEVEL-RPMS))
476 ### pack sources into tarballs
477 ALLTARBALLS:= $(foreach package, $(ALL), $($(package).tarballs))
478 tarballs: $(ALLTARBALLS)
479 @echo $(words $(ALLTARBALLS)) source tarballs OK
482 SOURCES/%.tar.bz2: SOURCES/%
483 tar chpjf $@ -C SOURCES $*
485 SOURCES/%.tar.gz: SOURCES/%
486 tar chpzf $@ -C SOURCES $*
488 SOURCES/%.tgz: SOURCES/%
489 tar chpzf $@ -C SOURCES $*
492 URLS/%: url=$(subst @colon@,:,$(subst @slash@,/,$(notdir $@)))
493 URLS/%: basename=$(notdir $(url))
495 echo curl $(url) -o SOURCES/$(basename)
498 ### the directory SOURCES/<package>-<version> is made
499 # with a (set of) copy -rl from MODULES/<module>
500 # the former is $(package.source)
501 ALLSOURCES:=$(foreach package, $(ALL), $($(package).source))
502 # so that make does not use the rule below directly for creating the tarball files
503 .SECONDARY: $(ALLSOURCES)
505 sources: $(ALLSOURCES)
506 @echo $(words $(ALLSOURCES)) versioned source trees OK
509 # argument is a package
510 # do things differently if multiple modules are mentioned (sigh..)
511 define target_copy_link_modules_sources
512 $($(1).source): $(foreach module,$($(1)-MODULES),MODULES/$(module))
513 $(if $(word 2,$($(1)-MODULES)),\
514 mkdir -p $($(1).source) && $(foreach module,$($(1)-MODULES), cp -rl MODULES/$(module) $($(1).source)/$(module);) ,\
515 mkdir -p SOURCES && cp -rl MODULES/$($(1)-MODULES) $($(1).source))
518 $(foreach package,$(ALL),$(eval $(call target_copy_link_modules_sources,$(package))))
521 ALLMODULES:=$(foreach module, $(ALL.modules), MODULES/$(module))
522 .SECONDARY: $(ALLMODULES)
523 modules: $(ALLMODULES)
524 @echo $(words $(ALLMODULES)) modules OK "(fetched from scm)"
528 ALLSRPMS:=$(foreach package,$(ALL),$($(package).srpm))
530 @echo $(words $(ALLSRPMS)) source rpms OK
534 # install the DEVEL-RPMS rpms if defined
535 define handle_stock_devel_rpms_pre
536 $(if $($(1)-DEVEL-RPMS), echo "Installing for $(1)-DEVEL-RPMS" ; $(YUM-INSTALL-DEVEL) $($(1)-DEVEL-RPMS))
539 ### these macro handles the DEPEND-DEVEL-RPMS and DEPEND-DEVEL-RPMS-UPDATES tags for a given package
540 # before building : rpm-install DEPEND-DEVEL-RPMS
541 define handle_local_devel_rpms_pre
542 $(if $($(1).all-devel-rpm-paths), echo "Installing for $(1)-DEPEND-DEVEL-RPMS" ; $(RPM-INSTALL-DEVEL) $($(1).all-devel-rpm-paths))
545 define handle_local_devel_rpms_post
546 -$(if $($(1)-DEPEND-DEVEL-RPMS), echo "Unstalling for $(1)-DEPEND-DEVEL-RPMS" ; $(RPM-UNINSTALL-DEVEL) $($(1)-DEPEND-DEVEL-RPMS))
549 # usage: target_source_rpm package
550 define target_source_rpm
551 ifeq "$($(1)-BUILD-FROM-SRPM)" ""
552 $($(1).srpm): $($(1).specpath) .rpmmacros $($(1).tarballs)
553 mkdir -p BUILD SRPMS tmp
554 @(echo -n "XXXXXXXXXXXXXXX -- BEG SRPM $(1) (using SOURCES) " ; date)
555 $(call handle_stock_devel_rpms_pre,$(1))
556 $(call handle_local_devel_rpms_pre,$(1))
557 $($(1).rpmbuild) -bs $($(1).specpath)
558 $(call handle_local_devel_rpms_post,$(1))
559 @(echo -n "XXXXXXXXXXXXXXX -- END SRPM $(1) " ; date)
561 $($(1).srpm): $($(1).specpath) .rpmmacros $($(1).source)
562 mkdir -p BUILD SRPMS tmp
563 @(echo -n "XXXXXXXXXXXXXXX -- BEG SRPM $(1) (using make srpm) " ; date)
564 $(call handle_stock_devel_rpms_pre,$(1))
565 $(call handle_local_devel_rpms_pre,$(1))
566 make -C $($(1).source) srpm SPECFILE=$(HOME)/$($(1).specpath) EXPECTED_SRPM=$(notdir $($(1).srpm)) && \
567 rm -f SRPMS/$(notdir $($(1).srpm)) && \
568 ln $($(1).source)/$(notdir $($(1).srpm)) SRPMS/$(notdir $($(1).srpm))
569 $(call handle_local_devel_rpms_post,$(1))
570 @(echo -n "XXXXXXXXXXXXXXX -- END SRPM $(1) " ; date)
574 $(foreach package,$(ALL),$(eval $(call target_source_rpm,$(package))))
576 ### binary rpms are made from source rpm
577 ALLRPMS:=$(foreach package,$(ALL),$($(package).rpms))
578 # same as above, mention $(ALL) and not $(ALLRPMS)
580 @echo $(words $(ALLRPMS)) binary rpms OK
583 # use tmp dirs when building binary rpm so make remains idempotent
584 # otherwise SOURCES/ or SPEC gets touched again - which leads to rebuilding
585 RPM-USE-TMP-DIRS = --define "_sourcedir $(HOME)/tmp" --define "_specdir $(HOME)/tmp"
586 RPM-USE-COMPILE-DIRS = --define "_sourcedir $(HOME)/COMPILE" --define "_specdir $(HOME)/COMPILE"
588 # usage: build_binary_rpm package
589 # xxx hacky - invoke createrepo if DEPEND-FILES mentions RPMS/yumgroups.xml
590 define target_binary_rpm
591 $($(1).rpms): $($(1).srpm)
593 @(echo -n "XXXXXXXXXXXXXXX -- BEG RPM $(1) " ; date)
594 $(if $(findstring RPMS/yumgroups.xml,$($(1)-DEPEND-FILES)), $(createrepo) , )
595 $(call handle_stock_devel_rpms_pre,$(1))
596 $(call handle_local_devel_rpms_pre,$(1))
597 $($(1).rpmbuild) --rebuild $(RPM-USE-TMP-DIRS) $($(1).srpm)
598 $(call handle_local_devel_rpms_post,$(1))
599 @(echo -n "XXXXXXXXXXXXXXX -- END RPM $(1) " ; date)
600 # for manual use only - in case we need to investigate the results of an rpmbuild
601 $(1)-compile: $($(1).srpm)
603 @(echo -n "XXXXXXXXXXXXXXX -- BEG compile $(1) " ; date)
604 $(if $(findstring RPMS/yumgroups.xml,$($(1)-DEPEND-FILES)), $(createrepo) , )
605 $(call handle_stock_devel_rpms_pre,$(1))
606 $(call handle_local_devel_rpms_pre,$(1))
607 $($(1).rpmbuild) --recompile $(RPM-USE-TMP-DIRS) $($(1).srpm)
608 $(call handle_local_devel_rpms_post,$(1))
609 @(echo -n "XXXXXXXXXXXXXXX -- END compile $(1) " ; date)
613 $(foreach package,$(ALL),$(eval $(call target_binary_rpm,$(package))))
615 # e.g. make proper -> does propers rpms
616 # usage shorthand_target package
617 define target_shorthand
620 $(1)-spec: $($(1)-SPEC)
624 $(1)-tarball: $($(1).tarballs)
627 $(1)-source: $($(1).source)
628 $(1)-rpms: $($(1).rpms)
630 $(1)-srpm: $($(1).srpm)
634 $(foreach package,$(ALL),$(eval $(call target_shorthand,$(package))))
636 ### file dependencies
637 define package_depends_on_file
642 define target_dependfiles
643 $(foreach file,$($(1)-DEPEND-FILES),$(eval $(call package_depends_on_file,$(1),$(file))))
646 $(foreach package,$(ALL),$(eval $(call target_dependfiles,$(package))))
648 ### package dependencies
649 define package_depends_on_package
652 $($(1).srpm):$($(2).rpms)
655 define target_depends
656 $(foreach package,$($(1)-DEPEND-PACKAGES) $($(1).depend-devel-packages),$(eval $(call package_depends_on_package,$(1),$(package))))
659 $(foreach package,$(ALL),$(eval $(call target_depends,$(package))))
662 # very rough for now (one module per package), targets only sfa for now
663 # the general idea here is, changing the specfile (for version number and all) is enough, and this
664 # gets passed to "make debian" in the module
665 # PREFIX: at one point we had passed PREFIX=/usr to this 'make debian'
666 # however it turned out we could manage this some other way (see manifold)
667 # so I'm reverting to simplicity
669 $(1)-debian: $(1)-tarball
671 rsync -a MODULES/$(1)/ DEBIAN/$(1)/
672 make -C DEBIAN/$(1) "RPMTARBALL=$(HOME)/$($(1).tarballs)" "RPMVERSION=$($(1).rpm-version)" "RPMRELEASE=$($(1).rpm-release)" "RPMNAME=$($(1).rpm-name)" debian
675 $(foreach package,$(ALL),$(eval $(call target_debian,$(package))))
678 # usage: target_clean package
681 $(foreach module,$($(1)-MODULES),rm -rf MODULES/$(module);)
682 .PHONY: $(1)-clean-modules
683 CLEANS += $(1)-clean-modules
685 rm -rf $($(1).source)
686 .PHONY: $(1)-clean-source
687 CLEANS += $(1)-clean-source
689 rm -rf $($(1).tarballs)
690 .PHONY: $(1)-clean-tarball
691 CLEANS += $(1)-clean-tarball
693 rm -rf BUILD/$(notdir $($(1).source))
694 CLEANS += $(1)-clean-build
697 .PHONY: $(1)-clean-rpms
698 CLEANS += $(1)-clean-rpms
701 .PHONY: $(1)-clean-srpm
702 CLEANS += $(1)-clean-srpm
705 .PHONY: $(1)-clean-srpm
706 CLEANS += $(1)-clean-srpm
707 $(1)-codeclean: $(1)-clean-source $(1)-clean-tarball $(1)-clean-build $(1)-clean-rpms $(1)-clean-srpm $(1)-clean-debian
708 $(1)-clean: $(1)-clean-modules $(1)-codeclean
709 .PHONY: $(1)-codeclean $(1)-clean
711 rm -rf $($(1).specpath)
712 .PHONY: $(1)-clean-spec
715 .PHONY: $(1)-clean-make
716 $(1)-distclean: $(1)-distclean1 $(1)-distclean2
717 $(1)-distclean1: $(1)-clean-spec $(1)-clean-make
718 $(1)-distclean2: $(1)-clean
719 .PHONY: $(1)-distclean $(1)-distclean1 $(1)-distclean2
722 $(foreach package,$(ALL),$(eval $(call target_clean,$(package))))
730 @echo Available clean targets
733 ### brute force clean
735 rm -rf envfrompreviousrun.mk .rpmmacros spec2make header.spec SPECS MAKE $(DISTCLEANS)
737 rm -rf MODULES SOURCES BUILD BUILDROOT RPMS SRPMS tmp
738 distclean: distclean1 distclean2
739 .PHONY: distclean1 distclean2 distclean
742 -$(RPM-UNINSTALL-DEVEL) $(ALL-DEVEL-RPMS)
745 # gather build information for the 'About' page
746 # when run from crontab, INIT_CWD not properly set (says /root ..)
747 # so, the nightly build passes BASE here
748 # also store BASE in .base for any post-processing purposes
750 @echo 'Creating myplc-release'
752 echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx build info" >> $@
753 $(MAKE) --no-print-directory version-build >> $@
754 echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx svn info" >> $@
755 $(MAKE) --no-print-directory version-tags >> $@
756 echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx rpm info" >> $@
757 $(MAKE) --no-print-directory version-rpms >> $@
758 @echo $(BASE) > .base
761 @echo -n 'Build build-date: ' ; date '+%Y.%m.%d'
762 @echo -n 'Build build-time: ' ; date '+%H:%M-%Z'
763 @echo -n 'Build build-hostname: ' ; hostname
764 @echo "Build build-base: $(BASE)"
765 @echo "Build planetlab-distro: $(PLDISTRO)"
766 @echo "Build planetlab-tags: $(PLDISTROTAGS)"
767 @echo "Build target-arch: $(HOSTARCH)"
768 @echo "Build target-distro: $(DISTRO)"
769 @echo "Build target-distroname: $(DISTRONAME)"
770 @echo "Build target-release: $(RELEASE)"
771 @echo "Build target-personality: $(PERSONALITY)"
775 VFORMAT="%30s := %s\n"
776 define print_tag_target
778 @$(if $($(1)-SVNPATH),\
779 printf $(VFORMAT) $(1)-SVNPATH "$($(1)-SVNPATH)",\
780 printf $(VFORMAT) $(1)-GITPATH "$($(1)-GITPATH)" )
783 $(foreach module,$(ALL.modules), $(eval $(call print_tag_target,$(module))))
785 version-tags: $(foreach module, $(ALL.modules), $(module)-version-tag)
787 RFORMAT="%20s :: version=%s release=%s\n"
788 define rpm_version_target
790 @printf $(RFORMAT) $($(1).rpm-name) $($(1).rpm-version) $($(1).rpm-release)
791 version-rpms: $(1)-version-rpm
794 $(foreach package,$(sort $(ALL)), $(eval $(call rpm_version_target,$(package))))
796 versions: myplc-release version-build version-tags version-rpms
797 .PHONY: versions version-build version-rpms version-tags
799 #################### package info
800 PKGKEYS := tarballs source srpm rpms rpmnames rpm-release rpm-name rpm-version rpm-subversion
801 %-pkginfo: package=$(subst -pkginfo,,$@)
803 @$(foreach key,$(PKGKEYS),echo "$(package).$(key)=$($(package).$(key))";)
805 RPMKEYS := rpm-path package
806 %-rpminfo: rpm=$(subst -rpminfo,,$@)
808 @$(foreach key,$(RPMKEYS),echo "$(rpm).$(key)=$($(rpm).$(key))";)
810 #################### various lists - designed to run with stage1=true
812 @$(foreach package,$(ALL), echo package=$(package) ref_module=$($(package).module) modules=$($(package)-MODULES) rpmnames=$($(package).rpmnames); )
815 @$(foreach module,$(ALL.modules), echo module=$(module) \
816 $(if $($(module)-SVNPATH),svnpath=$($(module)-SVNPATH),gitpath=$($(module)-GITPATH)) ; )
819 @$(foreach module,$(ALL.modules), \
820 $(if $($(module)-BRANCH),echo module=$(module) branch=$($(module)-BRANCH);))
823 @$(foreach module,$(ALL.modules), \
824 $(if $($(module)-GITPATH), \
825 $(if $($(module)-BRANCH), \
826 echo $(module):$($(module)-BRANCH); , \
828 $(if $($(module)-BRANCH), \
829 echo $(module):$($(module)-BRANCH); , \
832 info: info-packages info-modules info-branches
834 .PHONY: info info-packages info-modules info-branches module-tools
837 @$(foreach package,$(ALL),$(if $(subst x1,,x$(words $($(package)-MODULES))), echo p=$(package) mods=$($(package)-MODULES) ;))
838 .PHONY: show-multi-modules
841 @echo "********** Run make in two stages:"
843 @echo "make stage1=true PLDISTRO=onelab"
844 @echo " -> extracts all spec files in SPECS/ and mk files in MAKE/"
845 @echo " as well as save PLDISTRO for subsequent runs"
847 @echo "********** Then you can use the following targets"
849 @echo " rebuilds everything"
850 @echo 'make util-vserver'
851 @echo " makes the RPMS related to util-vserver"
852 @echo " equivalent to 'make util-vserver-rpms'"
854 @echo "********** Or, vertically - step-by-step for a given package"
855 @echo 'make util-vserver-source'
856 @echo " creates source link in SOURCES/util-vserver-<version>"
857 @echo 'make util-vserver-tarball'
858 @echo " creates source tarball in SOURCES/util-vserver-<version>.<tarextension>"
859 @echo 'make util-vserver-srpm'
860 @echo " build source rpm in SRPMS/"
861 @echo 'make util-vserver-rpms'
862 @echo " build rpm(s) in RPMS/"
864 @echo "********** Or, horizontally, reach a step for all known packages"
866 @echo 'make tarballs'
870 @echo "********** Manual targets"
871 @echo "make package-compile"
872 @echo " The regular process uses rpmbuild --rebuild, that performs"
873 @echo " a compilation directory cleanup upon completion. If you need to investigate"
874 @echo " the intermediate compilation directory, use the -compile targets"
875 @echo "********** Cleaning examples"
877 @echo " removes the files made by make"
878 @echo "make distclean"
879 @echo " brute-force cleaning, removes entire directories - requires a new stage1"
880 @echo "make develclean"
881 @echo " rpm-uninstalls all devel packages installed during build"
883 @echo "make iptables-distclean"
884 @echo " deep clean for a given package"
885 @echo "make iptables-codeclean"
886 @echo " run this if you've made a local/manual change in the MODULES area for iptables"
888 @echo "make util-vserver-clean"
889 @echo " removes codebase, source, tarball, build, rpm and srpm for util-vserver"
890 @echo "make util-vserver-clean-modules"
891 @echo " and so on for source, tarball, build, rpm and srpm"
893 @echo "********** Info examples"
895 @echo " Displays the value of a given variable (here ALL)"
896 @echo " with only a single plus sign only the value is displayed"
898 @echo " is equivalent to make packages modules branches"
899 @echo " provides various info on these objects"
900 @echo "make ulogd-pkginfo"
901 @echo " Displays know attributes of a package"
902 @echo "make kernel-devel-rpminfo"
903 @echo " Displays know attributes of an rpm"
904 @echo "make stage1=true PLDISTROTAGS=planetlab-tags-4.2.mk packages modules branches module-tools"
905 @echo " Lists mentioned items - module-tools is used in modules.update"
907 @echo "********** Known pakages are"
910 #################### convenience, for debugging only
911 # make +foo : prints the value of $(foo)
912 # make ++foo : idem but verbose, i.e. foo=$(foo)
913 ++%: varname=$(subst +,,$@)
915 @echo "$(varname)=$($(varname))"
916 +%: varname=$(subst +,,$@)
918 @echo "$($(varname))"