From f79e9c2d22345eeb0c721a8cf5375101d33dc4c9 Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <e.dolstra@tudelft.nl>
Date: Wed, 21 Apr 2004 10:54:46 +0000
Subject: [PATCH] * Do initialise state (the DB etc.) when doing a `make
 install',   unless `--disable-init-state' is passed to configure.

---
 Makefile.am               | 13 +++++++++++++
 configure.ac              |  5 +++++
 nix.spec.in               |  1 -
 src/nix-store/Makefile.am |  7 -------
 4 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index cb5040135..720279460 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -10,3 +10,16 @@ rpm: nix.spec dist
 
 relname:
 	echo -n $(distdir) > relname
+
+install-data-local: init-state
+
+if INIT_STATE
+init-state:
+	$(INSTALL) -d $(DESTDIR)$(localstatedir)/nix
+	$(INSTALL) -d $(DESTDIR)$(localstatedir)/nix/db
+	$(INSTALL) -d $(DESTDIR)$(localstatedir)/log/nix
+	$(INSTALL) -d $(DESTDIR)$(prefix)/store
+#	$(bindir)/nix-store --init
+else
+init-state:
+endif
\ No newline at end of file
diff --git a/configure.ac b/configure.ac
index 1c42194c1..df9e8249a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -114,6 +114,11 @@ AC_SUBST(aterm_include)
 
 AC_CHECK_LIB(pthread, pthread_mutex_init)
 
+AC_ARG_ENABLE(init-state, AC_HELP_STRING([--disable-init-state],
+  [do not initialise DB etc. in `make install']),
+  init_state=$enableval, init_state=yes)
+AM_CONDITIONAL(INIT_STATE, test "$init_state" = "yes")
+
 AM_CONFIG_HEADER([config.h])
 AC_CONFIG_FILES([Makefile
    externals/Makefile
diff --git a/nix.spec.in b/nix.spec.in
index 81344ffdd..41765aa6c 100644
--- a/nix.spec.in
+++ b/nix.spec.in
@@ -25,7 +25,6 @@ make
 %install
 rm -rf $RPM_BUILD_ROOT
 make DESTDIR=$RPM_BUILD_ROOT install
-(cd src/nix-store && make DESTDIR=$RPM_BUILD_ROOT init-state-local)
 strip $RPM_BUILD_ROOT/%{_prefix}/bin/* || true
 
 %clean
diff --git a/src/nix-store/Makefile.am b/src/nix-store/Makefile.am
index 588d645eb..c1fda12b5 100644
--- a/src/nix-store/Makefile.am
+++ b/src/nix-store/Makefile.am
@@ -11,10 +11,3 @@ main.o: help.txt.hh
 
 AM_CXXFLAGS = \
  -I.. ${bdb_include} $(aterm_include) -I../libutil -I../libstore -I../libmain
-
-init-state-local:
-	$(INSTALL) -d $(DESTDIR)$(localstatedir)/nix
-	$(INSTALL) -d $(DESTDIR)$(localstatedir)/nix/db
-	$(INSTALL) -d $(DESTDIR)$(localstatedir)/log/nix
-	$(INSTALL) -d $(DESTDIR)$(prefix)/store
-#	$(bindir)/nix-store --init