First try to embed VCS id in binaries
authorIustin Pop <iustin@google.com>
Thu, 12 Mar 2009 19:31:57 +0000 (20:31 +0100)
committerIustin Pop <iustin@google.com>
Thu, 12 Mar 2009 19:31:57 +0000 (20:31 +0100)
This patch attempts to embed the VCS id in binaries, based on the way
other projects seem to do this.

Makefile
src/Makefile
src/Version.hs.in [new file with mode: 0644]
src/hbal.hs

index a5c06cc..6f6254b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ HDDIR = apidoc
 
 # Haskell rules
 
-all:
+all: version
        $(MAKE) -C src
 
 README.html: README
@@ -15,17 +15,26 @@ doc: README.html
        mkdir -p $(HDDIR)/src
        cp hscolour.css $(HDDIR)/src
        for file in $(HSRCS); do \
-        HsColour -css -anchor \
-        $$file > $(HDDIR)/src/`basename $$file .hs`.html ; \
-    done
+               HsColour -css -anchor \
+               $$file > $(HDDIR)/src/`basename $$file .hs`.html ; \
+       done
        haddock --odir $(HDDIR) --html --ignore-all-exports \
-           -t htools -p haddock-prologue \
-        --source-module="src/%{MODULE/.//}.html" \
-        --source-entity="src/%{MODULE/.//}.html#%{NAME}" \
-           $(HSRCS)
+               -t htools -p haddock-prologue \
+               --source-module="src/%{MODULE/.//}.html" \
+               --source-entity="src/%{MODULE/.//}.html#%{NAME}" \
+               $(HSRCS)
 
 clean:
        rm -f *.o *.cmi *.cmo *.cmx *.old hn1 zn1 *.prof *.ps *.stat *.aux \
-        gmon.out *.hi README.html TAGS
+        gmon.out *.hi README.html TAGS version
 
-.PHONY : all doc clean hn1
+version:
+       git describe > $@
+
+dist: version
+       VN=$$(cat version|sed 's/^v//') ; \
+       ANAME="htools-$$VN.tar" ; \
+    git archive --format=tar --prefix=htools-$$VN/ HEAD > $$ANAME ; \
+       tar -r -f $$ANAME --transform="s,^,htools-$$VN/," version
+
+.PHONY : all doc clean hn1 dist
index 0ba0c8f..aefd67b 100644 (file)
@@ -1,13 +1,16 @@
 all: hn1 hbal
 
-hn1:
+hn1: Version.hs
        ghc --make -O2 -W hn1
 
-hbal:
+hbal: Version.hs
        ghc --make -O2 -W hbal
 
 clean:
        rm -f *.o *.old hn1 hbal *.prof *.ps *.stat *.aux \
-        *.hi README.html TAGS
+        *.hi README.html TAGS Version.hs
+
+Version.hs: Version.hs.in ../version
+       sed -e "s/%ver%/$$(cat ../version)/" < $< > $@
 
 .PHONY : all clean hn1 hbal
diff --git a/src/Version.hs.in b/src/Version.hs.in
new file mode 100644 (file)
index 0000000..063bbd7
--- /dev/null
@@ -0,0 +1,6 @@
+module Version
+    (
+      version -- ^ the version of the tree
+    ) where
+
+version = "(htools) version %ver%"
index fac037d..7b98d19 100644 (file)
@@ -16,6 +16,7 @@ import Text.Printf (printf)
 
 import qualified Container
 import qualified Cluster
+import qualified Version
 import Rapi
 import Utils
 
@@ -120,7 +121,8 @@ parseOpts argv =
           return (foldl (flip id) defaultOptions o, n)
       (_,_,errs) ->
           ioError (userError (concat errs ++ usageInfo header options))
-      where header = "Usage: hbal [OPTION...]"
+      where header = printf "hbal %s\nUsage: hbal [OPTION...]"
+                     Version.version
 
 -- | Main function.
 main :: IO ()