Makefile.am: generate missing .version file

Change-Id: Id0cd2debf9b2d120c6dec1e534eefc4fe0a4210f
diff --git a/.gitignore b/.gitignore
index c8b1d06..20c6470 100644
--- a/.gitignore
+++ b/.gitignore
@@ -42,8 +42,11 @@
 tests/testsuite
 tests/testsuite.log
 
-# ignore debian files
+# git-version-gen magic
 .tarball-version
+.version
+
+# ignore debian files
 debian/autoreconf.after
 debian/autoreconf.before
 debian/files
diff --git a/Makefile.am b/Makefile.am
index 85e3c65..1f51db9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,10 @@
 AUTOMAKE_OPTIONS = foreign dist-bzip2 1.6
 
 SUBDIRS = include src doc tests contrib
+
+BUILT_SOURCES = $(top_srcdir)/.version
 EXTRA_DIST = \
+	     .version \
 	     README.md \
 	     contrib/osmo-pcu.spec.in \
 	     debian \
@@ -12,3 +15,8 @@
 	--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)
 
 @RELMAKE@
+
+$(top_srcdir)/.version:
+	echo $(VERSION) > $@-t && mv $@-t $@
+dist-hook:
+	echo $(VERSION) > $(distdir)/.tarball-version