+RPMS/yumgroups.xml: $(YUMGROUPS)
+ install -D -m 644 $(YUMGROUPS) $@
+
+### shorthand target
+# e.g. make proper -> does propers rpms
+# usage shorthand_target package
+define target_shorthand
+$(1): $($(package)-RPM)
+.PHONY: $(1)
+$(1)-spec: $($(package)-SPEC)
+.PHONY: $(1)-spec
+$(1)-mk: $($(package)-MK)
+.PHONY: $(1)-mk
+$(1)-tarball: $($(package)-TARBALL)
+.PHONY: $(1)-tarball
+$(1)-codebase: $($(package)-CODEBASE)
+.PHONY: $(1)-source
+$(1)-source: $($(package)-SOURCE)
+.PHONY: $(1)-codebase
+$(1)-rpm: $($(package)-RPM)
+.PHONY: $(1)-rpm
+$(1)-srpm: $($(package)-SRPM)
+.PHONY: $(1)-srpm
+endef
+
+$(foreach package,$(ALL),$(eval $(call target_shorthand,$(package))))
+
+### dependencies
+define package_depends_on_file
+$(1):$(2)
+$($(1)-RPM):$(2)
+endef
+
+define target_dependfiles
+$(foreach file,$($(1)-DEPENDFILES),$(eval $(call package_depends_on_file,$(1),$(file))))
+endef
+
+define package_depends_on_package
+$(1):$(2)
+$(1):$($(2)-RPM)
+$($(1)-RPM):$($(2)-RPM)
+endef
+
+define target_depends
+$(foreach package,$($(1)-DEPENDS),$(eval $(call package_depends_on_package,$(1),$(package))))
+endef
+
+$(foreach package,$(ALL),$(eval $(call target_depends,$(package))))
+$(foreach package,$(ALL),$(eval $(call target_dependfiles,$(package))))
+
+
+### clean target
+# usage: target_clean package
+define target_clean
+$(1)-clean-codebase:
+ rm -rf $($(1)-CODEBASE)
+.PHONY: $(1)-clean-codebase
+CLEANS += $(1)-clean-codebase
+$(1)-clean-source:
+ rm -rf $($(1)-SOURCE)
+.PHONY: $(1)-clean-source
+CLEANS += $(1)-clean-source
+$(1)-clean-tarball:
+ rm -rf $($(1)-TARBALL)
+.PHONY: $(1)-clean-tarball
+CLEANS += $(1)-clean-tarball
+$(1)-clean-build:
+ rm -rf BUILD/$(notdir $($(1)-SOURCE))
+CLEANS += $(1)-clean-build
+$(1)-clean-rpm:
+ rm -rf $($(1)-RPM)
+.PHONY: $(1)-clean-rpm
+CLEANS += $(1)-clean-rpm
+$(1)-clean-srpm:
+ rm -rf $($(1)-SRPM)
+.PHONY: $(1)-clean-srpm
+CLEANS += $(1)-clean-srpm
+$(1)-clean: $(1)-clean-codebase $(1)-clean-source $(1)-clean-tarball $(1)-clean-build $(1)-clean-rpm $(1)-clean-srpm
+.PHONY: $(1)-clean
+endef
+
+$(foreach package,$(ALL),$(eval $(call target_clean,$(package))))
+
+### clean precisely
+clean:
+ $(MAKE) $(CLEANS)
+.PHONY: clean
+
+clean-help:
+ @echo Available clean targets
+ @echo $(CLEANS)
+
+### brute force clean
+distclean1:
+ rm -rf pldistro.mk .rpmmacros spec2make CODESPECS MAKE
+distclean2:
+ rm -rf CODEBASES SOURCES BUILD RPMS SRPMS SPECS tmp
+distclean: distclean1 distclean2
+.PHONY: distclean1 distclean2 distclean
+
+# xxx tmp - I cannot use this on my mac for local testing
+ISMACOS=$(findstring Darwin,$(shell uname))
+ifneq "$(ISMACOS)" ""
+#################### produce reliable version information
+# for a given module
+VFORMAT="%30s := %s\n"
+define print_version
+$(1)-version:
+ @$(if $($(1)-SVNPATH),\
+ printf $(VFORMAT) $(1)-SVNPATH "$($(1)-SVNPATH)",\
+ printf $(VFORMAT) $(1)-CVSROOT "$($(1)-CVSROOT)" ; printf $(VFORMAT) $(1)-TAG "$($(1)-TAG)")
+endef
+
+# compute all modules
+ALL-MODULES :=
+$(foreach package,$(ALL), $(eval ALL-MODULES+=$($(package)-MODULES)))
+ALL-MODULES:=$(sort $(ALL-MODULES))
+
+$(foreach module,$(ALL-MODULES), $(eval $(call print_version,$(module))))
+
+versions: $(foreach module, $(ALL-MODULES), $(module)-version)
+else
+versions:
+ @echo "warning : the 'versions' target is not supported on macos"
+endif
+
+#################### include install Makefile
+# the default is to use the distro-dependent install file
+# however the main distro file can redefine PLDISTROINSTALL
+ifndef PLDISTROINSTALL
+PLDISTROINSTALL := $(PLDISTRO)-install.mk
+endif
+# only if present
+-include $(PLDISTROINSTALL)
+
+####################
+help:
+ @echo "Known pakages are"
+ @echo " $(ALL)"
+ @echo "Run make in two stages:"
+ @echo ""
+ @echo "make stage1=true PLDISTRO=onelab"
+ @echo " -> extracts all spec files in CODESPECS/ and mk files in MAKE/"
+ @echo " as well as save PLDISTRO for subsequent runs"
+ @echo ""
+ @echo "Then you can use the following targets"
+ @echo '$ make'
+ @echo " rebuilds everything"
+ @echo '$ make util-vserver'
+ @echo " makes the RPMS related to util-vserver"
+ @echo " equivalent to 'make util-vserver-rpm'"
+ @echo ""
+ @echo "Or, vertically - step-by-step for a given package"
+ @echo '$ make util-vserver-codebase'
+ @echo " performs codebase extraction in CODEBASES/util-vserver"
+ @echo '$ make util-vserver-source'
+ @echo " creates source link in SOURCES/util-vserver-<version>"
+ @echo '$ make util-vserver-tarball'
+ @echo " creates source tarball in SOURCES/util-vserver-<version>.<tarextension>"
+ @echo '$ make util-vserver-rpm'
+ @echo " build rpm(s) in RPMS/"
+ @echo '$ make util-vserver-srpm'
+ @echo " build source rpm in SRPMS/"
+ @echo ""
+ @echo "Or, horizontally, reach a step for all known packages"
+ @echo '$ make codebases'
+ @echo '$ make sources'
+ @echo '$ make tarballs'
+ @echo '$ make rpms'
+ @echo '$ make srpms'
+ @echo ""
+ @echo "Cleaning examples"
+ @echo "$ make clean"
+ @echo " removes the files made by make"
+ @echo "$ make distclean"
+ @echo " brute-force cleaning, removes entire directories - requires a new stage1"
+ @echo "$ make util-vserver-clean"
+ @echo " removes codebase, source, tarball, build, rpm and srpm for util-vserver"
+ @echo "$ make util-vserver-clean-codebase"
+ @echo " and so on for source, tarball, build, rpm and srpm"
+
+#################### convenience, for debugging only
+# make +foo : prints the value of $(foo)
+# make ++foo : idem but verbose, i.e. foo=$(foo)
+++%: varname=$(subst +,,$@)
+++%:
+ @echo "$(varname)=$($(varname))"
++%: varname=$(subst +,,$@)
++%:
+ @echo "$($(varname))"