diff --git a/Makefile b/Makefile
index a5c06ccd9f626628818f605b0842712d0531d3bf..6f6254bbf86cf4a53f3574b200c7bdce8a3173f0 100644
--- 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
diff --git a/src/Makefile b/src/Makefile
index 0ba0c8f8808e216e2b37854f5a7bb967e1f87fbc..aefd67b0cd6d2062b25944545fb29de1f4bff5f7 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -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
index 0000000000000000000000000000000000000000..063bbd7b54e66341c9e5c75badc6d9cd251151ec
--- /dev/null
+++ b/src/Version.hs.in
@@ -0,0 +1,6 @@
+module Version
+    (
+      version -- ^ the version of the tree
+    ) where
+
+version = "(htools) version %ver%"
diff --git a/src/hbal.hs b/src/hbal.hs
index fac037d50d2723ff951658826c567c0c9fb32744..7b98d19400b7f41dc4a5ba045c2ab5e42ff59a1a 100644
--- a/src/hbal.hs
+++ b/src/hbal.hs
@@ -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 ()