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