switch to git for plcapi -- refresh module names for module-tools -a & the pending...
[build.git] / Makefile
index 4a1c17b..c9bd923 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,6 @@
 #
 # Thierry Parmentelat - INRIA Sophia Antipolis 
 #
-### $Id$
-### $URL$
-# 
 ####################
 # invocation:
 #
@@ -116,9 +113,6 @@ RPM-INSTALL-DEVEL := rpm --force -Uvh
 RPM-UNINSTALL-DEVEL := rpm -e
 YUM-INSTALL-DEVEL := yum -y install
 
-# see also below
-REMOTE-PLDISTROS="wextoolbox"
-
 #################### Makefile
 # Default target
 all:
@@ -154,41 +148,58 @@ include $(PLDISTROTAGS)
 # this used to be set in the -tags.mk files, but that turned out to require
 # error-prone duplicate changes 
 # so now the nightly build script sets this to what it is currently using
-# we set a default in case we run the build manually:
-# if the local directory was svn checked out, then use the corresponding URL
-svn-info-url-line := $(shell svn info 2> /dev/null | grep URL:)
-default-build-SVNPATH := $(lastword $(svn-info-url-line))
-# otherwise, use this hard-coded default
-ifeq "$(default-build-SVNPATH)" ""
-default-build-SVNPATH := http://svn.planet-lab.org/svn/build/trunk
+# in case we run this manually, i.e. if neither build-SVNPATH nor build-GITPATH is set
+ifeq "$(build-SVNPATH)$(build-GITPATH)" ""
+build-GITPATH-local := $(shell git config remote.origin.url)
+ifneq "$(build-GITPATH-local)" ""
+build-GITPATH := $(build-GITPATH-local)
+else
+build-SVNPATH := $(lastword $(shell svn info 2> /dev/null | grep URL:))
+endif
 endif
-# use default if necessary
-build-SVNPATH ?= $(default-build-SVNPATH)
 
-####################
+#################### pldistros that are defined remotely
+# fetching with svn
+define remote_pldistro_fetch_svn
+$(1).config.SVNPATH := $(shell grep -v "^#" config.$(1).svnpath)
+config.$(1): config.$(1).svnpath
+       @echo "Fetching (svn) details for remote pldistro $(1)"
+       svn export $$($(1).config.SVNPATH) config.$(1)
+endef
+
+FOO=@
+# fetching with git
+define remote_pldistro_fetch_git
+$(1).config.GITPATH := $(shell grep -v "^#" config.$(1).gitpath)
+$(1).config.gitrepo := $$(firstword $$(subst @, ,$$($(1).config.GITPATH)))
+$(1).config.gittag := $$(word 2,$$(subst @, ,$$($(1).config.GITPATH)))
+$(1).config.gittag := $$(if $$($(1).config.gittag),$$($(1).config.gittag),master)
+config.$(1): GITPATH=$(shell grep -v "^#" config.$(1).gitpath)
+config.$(1): config.$(1).gitpath
+       @echo "Fetching (git) details for remote pldistro $(1)"
+       mkdir -p config.$(1)
+       git $(GITTAG) archive --remote=$$($(1).config.gitrepo) $$($(1).config.gittag) | tar -C config.$(1) -xf -
+endef
+
+
+# put it together
 define remote_pldistro
 $(1).mk: config.$(1)/$(1).mk
-       @echo 'creating $(1) from config subdir'
+       @echo 'creating $(1) from config.$(1)'
        cp config.$(1)/$(1).mk $(1).mk
 
 $(2).mk: config.$(1)/$(2).mk
-       @echo 'creating $(1) tags from config subdir'
+       @echo 'creating $(2) tags from config.$(1)'
        cp config.$(1)/$(2).mk $(2).mk
 
 config.$(1)/$(1).mk: config.$(1)
 config.$(1)/$(2).mk: config.$(1)
 
-config.$(1): config.$(1).svnpath
-       @echo "Fetching details for pldistro $(1)"
-       svn export $(shell grep -v "^#" config.$(1).svnpath) config.$(1)
-
 DISTCLEANS += $(1).mk $(2).mk config.$(1)
-
+$(eval $(call remote_pldistro_fetch_$(3),$(1)))
 endef
 
-# somehow this does not work, handle manually instead
-#$(foreach distro, $(REMOTE-PLDISTROS), $(eval $(call remote_pldistro,$(distro),$(distro)-tags)))
-$(eval $(call remote_pldistro,wextoolbox,wextoolbox-tags))
+$(eval $(call remote_pldistro,wextoolbox,wextoolbox-tags,git))
 
 ########## stage1 and stage1iter
 # extract specs and compute .mk files by running 
@@ -267,25 +278,26 @@ repo: RPMS/yumgroups.xml
 define stage1_package_vars
 $(1).module := $(firstword $($(1)-MODULES))
 $(1).specpath := SPECS/$(notdir $($(1)-SPEC))
-$(1).moduledir := MODULES/$(firstword $($(1)-MODULES))
-$(1).codespec := MODULES/$(firstword $($(1)-MODULES))/$($(1)-SPEC)
+$(1).moduledir := MODULES/$$($(1).module)
+$(1).codespec := MODULES/$$($(1).module)/$($(1)-SPEC)
 endef
 
 $(foreach package, $(ALL), $(eval $(call stage1_package_vars,$(package))))
 
 # compute all modules
-ALL.modules :=
+ALL.modules := build tests
 $(foreach package,$(ALL), $(eval ALL.modules+=$($(package)-MODULES)))
 ALL.modules:=$(sort $(ALL.modules))
 
 # extract revision from -SVNPATH or tag from -GITPATH
 define stage1_module_vars
-ifeq "$($(1)-SVNPATH)" ""
-$(1)-GITPATH := $(strip $($(1)-GITPATH))
-$(1).gitrepo := $(firstword $(subst @, ,$($(1)-GITPATH)))
-$(1).gittag := $(word 2,$(subst @, ,$($(1)-GITPATH)))
-else
+ifneq "$($(1)-SVNPATH)" ""
 $(1)-SVNPATH := $(strip $($(1)-SVNPATH))
+else
+$(1)-GITPATH := $$(strip $$($(1)-GITPATH))
+$(1).gitrepo := $$(firstword $$(subst @, ,$$($(1)-GITPATH)))
+$(1).gittag := $$(word 2,$$(subst @, ,$$($(1)-GITPATH)))
+$(1).gittag := $$(if $$($(1).gittag),$$($(1).gittag),master)
 endif
 endef
 
@@ -296,13 +308,16 @@ $(foreach module,$(ALL.modules), $(eval $(call stage1_module_vars,$(module))))
 # the heuristic is that we mention the date as part of the rpm release flag if
 # (*) the package has requested it by setting package-RPMDATE (container packages should do that)
 # (*) or SVNPATH contains 'trunk' or 'branches' 
+# (*) or GITPATH has no '@' (trunk) 
+# (*) or GITPATH contains a '@', and the gittag part has no '-' (this is to tell a tag from a branch..)
 # 
 define package_hasdate
 $(1).has-date = $(if $($(1)-RPMDATE),yes, \
                   $(if $($($(1).module)-SVNPATH), \
                     $(if $(findstring /trunk,$($($(1).module)-SVNPATH)),yes, \
                        $(if $(findstring /branches,$($($(1).module)-SVNPATH)),yes,)), \
-                    $(if $(findstring HEAD,$($($(1).module)-TAG)),yes,)))
+                    $(if $(not $($($(1).module).gittag)), yes,\
+                       $(if $(findstring -,$($($(1).module).gittag)),,yes))))
 endef
 
 $(foreach package, $(ALL), $(eval $(call package_hasdate,$(package))))
@@ -335,6 +350,7 @@ $($(1).specpath): header.spec $($(1).codespec)
        cat $($(1).codespec) >> $($(1).specpath)
 
 $($(1).codespec): $($(1).moduledir)
+
 endef
 
 $(foreach package,$(ALL),$(eval $(call target_spec,$(package))))
@@ -342,18 +358,26 @@ $(foreach package,$(ALL),$(eval $(call target_spec,$(package))))
 ### module extraction
 define target_extract_module
 MODULES/$(1):
-       @(echo -n "XXXXXXXXXXXXXXX -- BEG MODULE $(module) : $@ " ; date)
+       @(echo -n "XXXXXXXXXXXXXXX -- BEG MODULE $(1) : $@ " ; date)
        mkdir -p MODULES
-       cd MODULES && $(if $($(1)-SVNPATH),\
+       cd MODULES && \
+       $(if $($(1)-SVNPATH),\
          svn export $($(1)-SVNPATH) $(1),\
-         git clone $($(1).gitrepo) $(1); \
-         $(if $($(1).gittag), cd $(1); git checkout "$($(1).gittag)"; cd -; ,) \
-         rm -rf $(1)/.git )
-       @(echo -n "XXXXXXXXXXXXXXX -- END MODULE $(module) : $@ " ; date)
+         mkdir $(1) ; (git archive --remote=$($(1).gitrepo) $($(1).gittag) | tar -C $(1) -xf - ) \
+          || { rm -rf $(1); false; } )
+       @(echo -n "XXXXXXXXXXXXXXX -- END MODULE $(1) : $@ " ; date)
+
+$(1)-module: MODULES/$(1)
+.PHONY: $(1)-module
 endef
 
 $(foreach module,$(ALL.modules),$(eval $(call target_extract_module,$(module))))
 
+### the tests area
+# use this makefile to extract tests rather than extracting manually in vbuild-nightly
+tests-clean:
+       rm -rf MODULES/tests
+.PHONY: tests-clean
 
 ###
 # Base rpmbuild in the current directory
@@ -381,7 +405,7 @@ endif
 ### this utility allows to extract various info from a spec file
 ### and to define them in makefiles
 spec2make: spec2make.c
-       $(CC) -g -Wall $< -o $@ -lrpm -lrpmbuild
+       $(CC) -g -Wall $< -o $@ -lrpm -lrpmbuild -lrpmio -lpopt
 
 ### run spec2make on the spec file and include the result
 # usage: spec2make package
@@ -676,7 +700,7 @@ myplc-release:
        echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx build info" >> $@
        $(MAKE) --no-print-directory version-build >> $@
        echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx svn info" >> $@
-       $(MAKE) --no-print-directory version-svns >> $@
+       $(MAKE) --no-print-directory version-tags >> $@
        echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx rpm info" >> $@
        $(MAKE) --no-print-directory version-rpms >> $@
        @echo $(BASE) > .base
@@ -688,7 +712,6 @@ version-build:
        @echo    "Build build-base: $(BASE)"
        @echo    "Build planetlab-distro: $(PLDISTRO)"
        @echo    "Build planetlab-tags: $(PLDISTROTAGS)"
-       @echo -n 'Build planetlab-tagsid: ' ; fgrep '$$''Id' $(PLDISTROTAGS)
        @echo    "Build target-arch: $(HOSTARCH)"
        @echo    "Build target-distro: $(DISTRO)"
        @echo    "Build target-distroname: $(DISTRONAME)"
@@ -698,16 +721,16 @@ version-build:
 #################### 
 # for a given module
 VFORMAT="%30s := %s\n"
-define svn_version_target
-$(1)-version-svn:
+define print_tag_target
+$(1)-version-tag:
        @$(if $($(1)-SVNPATH),\
           printf $(VFORMAT) $(1)-SVNPATH "$($(1)-SVNPATH)",\
-          printf $(VFORMAT) $(1)-CVSROOT "$($(1)-CVSROOT)" ; printf $(VFORMAT) $(1)-TAG "$($(1)-TAG)")
+          printf $(VFORMAT) $(1)-GITPATH "$($(1)-GITPATH)" )
 endef
 
-$(foreach module,$(ALL.modules), $(eval $(call svn_version_target,$(module))))
+$(foreach module,$(ALL.modules), $(eval $(call print_tag_target,$(module))))
 
-version-svns: $(foreach module, $(ALL.modules), $(module)-version-svn)
+version-tags: $(foreach module, $(ALL.modules), $(module)-version-tag)
 
 RFORMAT="%20s :: version=%s release=%s\n"
 define rpm_version_target
@@ -718,8 +741,8 @@ endef
 
 $(foreach package,$(sort $(ALL)), $(eval $(call rpm_version_target,$(package))))
 
-versions: myplc-release version-build version-svns version-rpms
-.PHONY: versions version-build version-rpms version-svns
+versions: myplc-release version-build version-tags version-rpms
+.PHONY: versions version-build version-rpms version-tags
 
 #################### package info
 PKGKEYS := tarballs source srpm rpms rpmnames rpm-release rpm-name rpm-version rpm-subversion
@@ -737,29 +760,27 @@ info-packages:
        @$(foreach package,$(ALL), echo package=$(package) ref_module=$($(package).module) modules=$($(package)-MODULES) rpmnames=$($(package).rpmnames); )
 
 info-modules:
-       @$(foreach module,$(ALL.modules), echo module=$(module) svnpath=$($(module)-SVNPATH); )
+       @$(foreach module,$(ALL.modules), echo module=$(module) \
+          $(if $($(module)-SVNPATH),svnpath=$($(module)-SVNPATH),gitpath=$($(module)-GITPATH)) ; )
 
 info-branches:
        @$(foreach module,$(ALL.modules), \
-         $(if $($(module)-SVNBRANCH),echo module=$(module) branch=$($(module)-SVNBRANCH);))
+         $(if $($(module)-BRANCH),echo module=$(module) branch=$($(module)-BRANCH);))
 
 module-tools:
        @$(foreach module,$(ALL.modules), \
-        $(if $($(module)-SVNPATH), \
-         $(if $($(module)-SVNBRANCH), \
-            echo $(module):$($(module)-SVNBRANCH); , \
+        $(if $($(module)-GITPATH), \
+         $(if $($(module)-BRANCH), \
+            echo $(module):$($(module)-BRANCH); , \
+            echo $(module); ), \
+         $(if $($(module)-BRANCH), \
+            echo $(module):$($(module)-BRANCH); , \
             echo $(module); )))
 
 info: info-packages info-modules info-branches 
 
 .PHONY: info info-packages info-modules info-branches module-tools
 
-####################
-tests_svnpath:
-       @$(if $(tests-SVNPATH), echo $(tests-SVNPATH) > $@, \
-       echo "http://svn.planet-lab.org/svn/tests/trunk" > $@)
-
-
 ####################
 help:
        @echo "********** Run make in two stages:"