commit 5293052e3888c9aaf3916fec9ca614ddcf268bbe
Author: Nikos Skalkotos <skalkoto@grnet.gr>
Date:   Fri Jul 22 12:29:16 2011 +0300

    Fix autotools building system
    
     * A part of the building system is rewritten. The common.sh file
     shouldn't be created during the execution of the configuration script.
     In this phase, directory output variables are not expanded. Variables
     like `@dataroodir@' are expanded to `${prefix}/share', not
     `/usr/local/share' making the file unusable. As the official autoconf
     manual prescribes, we shoud let `make' manage the replacement of those
     variables in shell scripts and other files.
    
     * Add a -f option in the ln command that created the link of
     variants.list in os-dir. Without this, `make install' creates an error
     if the link is already present.
    
     * Correct the default path messages in configure's --with-foo options
    
     * Prefix ${srcdir}/ in all dist_ files to make the package support
     seperated builds (run the configure script from a different directory).

diff --git a/Makefile.am b/Makefile.am
index bb7e93f..b8b29e4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,33 +1,50 @@
-osdir=$(OS_DIR)/$(OS_NAME)
 customdir=${sysconfdir}/ganeti/instance-image/hooks
 configdir=${sysconfdir}/ganeti/instance-image
 variantsdir=${sysconfdir}/ganeti/instance-image/variants
 networksdir=${sysconfdir}/ganeti/instance-image/networks
 overlaysdir=${sysconfdir}/ganeti/instance-image/overlays
-toolsdir=$(OS_DIR)/$(OS_NAME)/tools
+toolsdir=${osdir}/${osname}/tools
 
-dist_os_SCRIPTS = create import export rename verify
-dist_tools_SCRIPTS = tools/*
-dist_os_DATA = ganeti_api_version parameters.list
-dist_config_DATA = variants.list
+dist_os_SCRIPTS = ${srcdir}/create ${srcdir}/import ${srcdir}/export ${srcdir}/rename ${srcdir}/verify
+dist_tools_SCRIPTS = ${srcdir}/tools/*
+dist_os_DATA = ${srcdir}/ganeti_api_version ${srcdir}/parameters.list
+dist_config_DATA = ${srcdir}/variants.list
 os_DATA = common.sh
 
-dist_custom_DATA = example/hooks/*
+dist_custom_DATA = ${srcdir}/example/hooks/*
 
-dist_doc_DATA = COPYING NEWS README
+dist_doc_DATA = ${srcdir}/COPYING ${srcdir}/NEWS ${srcdir}/README
 
 EXTRA_DIST = common.sh.in defaults
 
-common.sh: common.sh.in 
+edit = sed \
+	   -e 's|@sysconfdir[@]|$(sysconfdir)|g' \
+	   -e 's|@localstatedir[@]|$(localstatedir)|g' \
+	   -e 's|@osdir[@]|$(osdir)|g' \
+	   -e 's|@osname[@]|$(osname)|g' \
+	   -e 's|@AWK[@]|$(AWK)|g' \
+	   -e 's|@MKDIR_P[@]|$(MKDIR_P)|g' \
+	   -e 's|@DUMP[@]|$(DUMP)|g' \
+	   -e 's|@LOSETUP[@]|$(LOSETUP)|g' \
+	   -e 's|@KPARTX[@]|$(KPARTX)|g' \
+	   -e 's|@SFDISK[@]|$(SFDISK)|g' \
+	   -e 's|@QEMU_IMG[@]|$(QEMU_IMG)|g'
+
+common.sh: $(srcdir)/common.sh.in Makefile
+	rm -f $@ $@.tmp
+	srcdir=''; \
+		   test -f ./$@.in || srcdir=$(srcdir)/; \
+		   $(edit) $${srcdir}$@.in >$@.tmp
+	mv $@.tmp $@
 
 install-exec-local:
-	@mkdir_p@ "$(DESTDIR)$(osdir)"
+	@mkdir_p@ "$(DESTDIR)$(osdir)/$(osname)"
 	@mkdir_p@ "$(DESTDIR)$(variantsdir)"
 	@mkdir_p@ "$(DESTDIR)$(networksdir)/subnets"
 	@mkdir_p@ "$(DESTDIR)$(networksdir)/instances"
 	@mkdir_p@ "$(DESTDIR)$(overlaysdir)"
 	@mkdir_p@ "$(DESTDIR)$(localstatedir)/cache/ganeti-instance-image"
 	touch "$(DESTDIR)$(variantsdir)/default.conf"
-	ln -s $(DESTDIR)$(configdir)/variants.list $(DESTDIR)$(osdir)/variants.list
+	ln -fs $(DESTDIR)$(configdir)/variants.list $(DESTDIR)$(osdir)/variants.list
 
 CLEANFILES = common.sh
diff --git a/common.sh.in b/common.sh.in
index 70e2ccb..921d3a3 100644
--- a/common.sh.in
+++ b/common.sh.in
@@ -18,12 +18,12 @@
 # 02110-1301, USA.
 
 AWK="@AWK@"
+MKDIR_P="@MKDIR_P@"
 DUMP="@DUMP@"
 LOSETUP="@LOSETUP@"
 KPARTX="@KPARTX@"
 SFDISK="@SFDISK@"
 QEMU_IMG="@QEMU_IMG@"
-MKDIR_P="@MKDIR_P@"
 
 CLEANUP=( )
 
@@ -442,7 +442,7 @@ fi
 : ${OVERLAYS_DIR:="@sysconfdir@/ganeti/instance-image/overlays"}
 : ${IMAGE_DIR:="@localstatedir@/cache/ganeti-instance-image"}
 : ${IMAGE_DEBUG:="no"}
-: ${TOOLS_DIR:="@OS_DIR@/@OS_NAME@/tools"}
+: ${TOOLS_DIR:="@osdir@/@osname@/tools"}
 
 SCRIPT_NAME=$(basename $0)
 KERNEL_PATH="$INSTANCE_HV_kernel_path"
diff --git a/configure.ac b/configure.ac
index 40eae6a..a276b73 100644
--- a/configure.ac
+++ b/configure.ac
@@ -10,27 +10,27 @@ AM_INIT_AUTOMAKE([1.9 foreign tar-ustar -Wall -Wno-portability])
 AC_ARG_WITH([os-dir],
   [AS_HELP_STRING([--with-os-dir=DIR],
     [top-level OS directory under which to install]
-    [ (default is $datadir/ganeti/os)]
+    [ [DATADIR/ganeti/os]]
   )],
   [os_dir="$withval"],
   [os_dir="$datadir/ganeti/os"])
-AC_SUBST(OS_DIR, $os_dir)
+AC_SUBST(osdir, $os_dir)
 
 # --with-os-name=...
 AC_ARG_WITH([os-name],
   [AS_HELP_STRING([--with-os-name=OSNAME],
     [the name of the OS provider which will be the directory to install its files]
-    [ (default is image)]
+    [ [image]]
   )],
   [os_name="$withval"],
   [os_name="image"])
-AC_SUBST(OS_NAME, $os_name)
+AC_SUBST(osname, $os_name)
 
 # --with-default-dir=...
 AC_ARG_WITH([default-dir],
   [AS_HELP_STRING([--with-default-dir=DIR],
     [top-level default config directory under which to install]
-    [ (default is $sysconfdir/default)]
+    [ [SYSCONFDIR/default]]
   )],
   [default_dir="$withval"],
   [default_dir="$sysconfdir/default"])
@@ -69,7 +69,6 @@ fi
 
 AC_CONFIG_FILES([
     Makefile
-    common.sh
 ])
 
 AC_OUTPUT
