about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-02-01T15·41+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-02-01T15·41+0100
commit2f9bb5c7e744ddca3fbe5576e520a3e80c106c55 (patch)
tree7a3d5d57a460aa87a8f8b58d46102ca339e97770 /src
parentc5ba08133370f98de722c978bda3b446721985de (diff)
parent6dca72006aa9b1cf2f226bb5b538e744fcab976f (diff)
Merge branch 'make'
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am3
-rw-r--r--src/boost/Makefile.am8
-rw-r--r--src/boost/format/Makefile.am12
-rw-r--r--src/boost/format/local.mk7
-rw-r--r--src/bsdiff-4.3/Makefile.am13
-rw-r--r--src/bsdiff-4.3/local.mk11
-rw-r--r--src/libexpr/Makefile.am40
-rw-r--r--src/libexpr/eval.cc23
-rw-r--r--src/libexpr/eval.hh14
-rw-r--r--src/libexpr/local.mk24
-rw-r--r--src/libexpr/nixexpr.hh3
-rw-r--r--src/libexpr/parser.y4
-rw-r--r--src/libexpr/primops.cc1
-rw-r--r--src/libexpr/value.hh4
-rw-r--r--src/libmain/Makefile.am11
-rw-r--r--src/libmain/local.mk11
-rw-r--r--src/libmain/shared.cc20
-rw-r--r--src/libstore/Makefile.am33
-rw-r--r--src/libstore/build.cc5
-rw-r--r--src/libstore/gc.cc2
-rw-r--r--src/libstore/globals.cc2
-rw-r--r--src/libstore/local.mk28
-rw-r--r--src/libutil/Makefile.am18
-rw-r--r--src/libutil/local.mk15
-rw-r--r--src/nix-daemon/Makefile.am12
-rw-r--r--src/nix-daemon/local.mk9
-rw-r--r--src/nix-env/Makefile.am12
-rw-r--r--src/nix-env/local.mk7
-rw-r--r--src/nix-env/user-env.cc2
-rw-r--r--src/nix-hash/Makefile.am8
-rw-r--r--src/nix-hash/local.mk7
-rw-r--r--src/nix-instantiate/Makefile.am10
-rw-r--r--src/nix-instantiate/local.mk7
-rw-r--r--src/nix-log2xml/Makefile.am17
-rw-r--r--src/nix-log2xml/local.mk8
-rw-r--r--src/nix-store/Makefile.am12
-rw-r--r--src/nix-store/local.mk9
37 files changed, 179 insertions, 253 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
deleted file mode 100644
index a5e411b9ed6e..000000000000
--- a/src/Makefile.am
+++ /dev/null
@@ -1,3 +0,0 @@
-SUBDIRS = boost libutil libstore libmain nix-store nix-hash \
- libexpr nix-instantiate nix-env nix-daemon \
- nix-log2xml bsdiff-4.3
diff --git a/src/boost/Makefile.am b/src/boost/Makefile.am
deleted file mode 100644
index 8b5aa25fb5bd..000000000000
--- a/src/boost/Makefile.am
+++ /dev/null
@@ -1,8 +0,0 @@
-SUBDIRS = format
-
-nobase_pkginclude_HEADERS = assert.hpp checked_delete.hpp format.hpp \
- shared_ptr.hpp weak_ptr.hpp throw_exception.hpp \
- enable_shared_from_this.hpp \
- detail/shared_count.hpp detail/workaround.hpp
-
-pkgincludedir = ${includedir}/nix/boost
diff --git a/src/boost/format/Makefile.am b/src/boost/format/Makefile.am
deleted file mode 100644
index 13e23d315da8..000000000000
--- a/src/boost/format/Makefile.am
+++ /dev/null
@@ -1,12 +0,0 @@
-pkglib_LTLIBRARIES = libformat.la
-
-libformat_la_SOURCES = format_implementation.cc free_funcs.cc \
- parsing.cc 
-
-pkginclude_HEADERS = exceptions.hpp feed_args.hpp format_class.hpp \
- format_fwd.hpp group.hpp internals.hpp internals_fwd.hpp \
- macros_default.hpp
-
-pkgincludedir = ${includedir}/nix/boost/format
-
-AM_CXXFLAGS = -Wall -I$(srcdir)/../..
diff --git a/src/boost/format/local.mk b/src/boost/format/local.mk
new file mode 100644
index 000000000000..3776eff382fe
--- /dev/null
+++ b/src/boost/format/local.mk
@@ -0,0 +1,7 @@
+libraries += libformat
+
+libformat_NAME = libnixformat
+
+libformat_DIR := $(d)
+
+libformat_SOURCES := $(wildcard $(d)/*.cc)
diff --git a/src/bsdiff-4.3/Makefile.am b/src/bsdiff-4.3/Makefile.am
deleted file mode 100644
index 62315333a76a..000000000000
--- a/src/bsdiff-4.3/Makefile.am
+++ /dev/null
@@ -1,13 +0,0 @@
-EXTRA_DIST = compat-include
-
-libexec_PROGRAMS = bsdiff bspatch
-
-bsdiff_SOURCES = bsdiff.c
-
-bsdiff_LDADD = -lbz2
-
-bspatch_SOURCES = bspatch.c
-
-bspatch_LDADD = -lbz2
-
-AM_CFLAGS = -O3 ${bsddiff_compat_include}
diff --git a/src/bsdiff-4.3/local.mk b/src/bsdiff-4.3/local.mk
new file mode 100644
index 000000000000..c957ceab0c0f
--- /dev/null
+++ b/src/bsdiff-4.3/local.mk
@@ -0,0 +1,11 @@
+programs += bsdiff bspatch
+
+bsdiff_DIR := $(d)
+bsdiff_SOURCES := $(d)/bsdiff.c
+bsdiff_LDFLAGS = -lbz2 $(bsddiff_compat_include)
+bsdiff_INSTALL_DIR = $(libexecdir)/nix
+
+bspatch_DIR := $(d)
+bspatch_SOURCES := $(d)/bspatch.c
+bspatch_LDFLAGS = -lbz2 $(bsddiff_compat_include)
+bspatch_INSTALL_DIR = $(libexecdir)/nix
diff --git a/src/libexpr/Makefile.am b/src/libexpr/Makefile.am
deleted file mode 100644
index 7edbe77157d8..000000000000
--- a/src/libexpr/Makefile.am
+++ /dev/null
@@ -1,40 +0,0 @@
-pkglib_LTLIBRARIES = libexpr.la
-
-libexpr_la_SOURCES = \
- nixexpr.cc eval.cc primops.cc lexer-tab.cc parser-tab.cc \
- get-drvs.cc attr-path.cc value-to-xml.cc value-to-json.cc \
- common-opts.cc names.cc
-
-pkginclude_HEADERS = \
- nixexpr.hh eval.hh eval-inline.hh lexer-tab.hh parser-tab.hh \
- get-drvs.hh attr-path.hh value-to-xml.hh value-to-json.hh \
- common-opts.hh names.hh symbol-table.hh value.hh
-
-libexpr_la_LIBADD = ../libutil/libutil.la ../libstore/libstore.la \
- ../boost/format/libformat.la @BDW_GC_LIBS@
-
-BUILT_SOURCES = \
- parser-tab.hh lexer-tab.hh parser-tab.cc lexer-tab.cc
-
-EXTRA_DIST = lexer.l parser.y
-
-AM_CXXFLAGS = \
- -I$(srcdir)/.. \
- -I$(srcdir)/../libutil -I$(srcdir)/../libstore
-
-
-# Parser generation.
-
-parser-tab.cc parser-tab.hh: parser.y
-	$(bison) -v -o parser-tab.cc $(srcdir)/parser.y -d
-
-lexer-tab.cc lexer-tab.hh: lexer.l
-	$(flex) --outfile lexer-tab.cc --header-file=lexer-tab.hh $(srcdir)/lexer.l 
-
-
-# SDF stuff (not built by default).
-nix.tbl: nix.sdf
-	sdf2table -m Nix -s -i nix.sdf -o nix.tbl
-
-test.ast: test.nix nix.tbl
-	sglri -p nix.tbl -i test.nix -o test.ast
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 3d8ee9934016..2087c7c43ffb 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -129,7 +129,15 @@ string showType(const Value & v)
 }
 
 
-Symbol getName(const AttrName & name, EvalState & state, Env & env) {
+/* Called when the Boehm GC runs out of memory. */
+static void * oomHandler(size_t requested)
+{
+    /* Convert this to a proper C++ exception. */
+    throw std::bad_alloc();
+}
+
+
+static Symbol getName(const AttrName & name, EvalState & state, Env & env) {
     if (name.symbol.set()) {
         return name.symbol;
     } else {
@@ -168,8 +176,16 @@ EvalState::EvalState()
     countCalls = getEnv("NIX_COUNT_CALLS", "0") != "0";
 
 #if HAVE_BOEHMGC
-    static bool gcInitialised = true;
-    if (gcInitialised) {
+    static bool gcInitialised = false;
+    if (!gcInitialised) {
+
+        /* Initialise the Boehm garbage collector.  This isn't
+           necessary on most platforms, but for portability we do it
+           anyway. */
+        GC_INIT();
+
+        GC_oom_fn = oomHandler;
+
         /* Set the initial heap size to something fairly big (25% of
            physical RAM, up to a maximum of 384 MiB) so that in most
            cases we don't need to garbage collect at all.  (Collection
@@ -193,6 +209,7 @@ EvalState::EvalState()
             debug(format("setting initial heap size to %1% bytes") % size);
             GC_expand_hp(size);
         }
+
         gcInitialised = true;
     }
 #endif
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index 45ab423c18a1..5ae5a1e3cf24 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -82,8 +82,6 @@ void copyContext(const Value & v, PathSet & context);
    paths. */
 typedef std::map<Path, Path> SrcToStore;
 
-struct EvalState;
-
 
 std::ostream & operator << (std::ostream & str, const Value & v);
 
@@ -216,9 +214,9 @@ private:
 
     inline Value * lookupVar(Env * env, const ExprVar & var, bool noEval);
 
-    friend class ExprVar;
-    friend class ExprAttrs;
-    friend class ExprLet;
+    friend struct ExprVar;
+    friend struct ExprAttrs;
+    friend struct ExprLet;
 
     Expr * parse(const char * text, const Path & path,
         const Path & basePath, StaticEnv & staticEnv);
@@ -278,9 +276,9 @@ private:
     typedef std::map<Pos, unsigned int> AttrSelects;
     AttrSelects attrSelects;
 
-    friend class ExprOpUpdate;
-    friend class ExprOpConcatLists;
-    friend class ExprSelect;
+    friend struct ExprOpUpdate;
+    friend struct ExprOpConcatLists;
+    friend struct ExprSelect;
     friend void prim_getAttr(EvalState & state, Value * * args, Value & v);
 };
 
diff --git a/src/libexpr/local.mk b/src/libexpr/local.mk
new file mode 100644
index 000000000000..431f84b0999e
--- /dev/null
+++ b/src/libexpr/local.mk
@@ -0,0 +1,24 @@
+libraries += libexpr
+
+libexpr_NAME = libnixexpr
+
+libexpr_DIR := $(d)
+
+libexpr_SOURCES := $(wildcard $(d)/*.cc) $(d)/lexer-tab.cc $(d)/parser-tab.cc
+
+libexpr_LIBS = libutil libstore libformat
+
+# The dependency on libgc must be propagated (i.e. meaning that
+# programs/libraries that use libexpr must explicitly pass -lgc),
+# because inline functions in libexpr's header files call libgc.
+libexpr_LDFLAGS_PROPAGATED = $(BDW_GC_LIBS)
+
+$(d)/parser-tab.cc $(d)/parser-tab.hh: $(d)/parser.y
+	$(trace-gen) bison -v -o $(libexpr_DIR)/parser-tab.cc $< -d
+
+$(d)/lexer-tab.cc $(d)/lexer-tab.hh: $(d)/lexer.l
+	$(trace-gen) flex --outfile $(libexpr_DIR)/lexer-tab.cc --header-file=$(libexpr_DIR)/lexer-tab.hh $<
+
+clean-files += $(d)/parser-tab.cc $(d)/parser-tab.hh $(d)/lexer-tab.cc $(d)/lexer-tab.hh
+
+dist-files += $(d)/parser-tab.cc $(d)/parser-tab.hh $(d)/lexer-tab.cc $(d)/lexer-tab.hh
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh
index bc6993477c48..7586fffb83d4 100644
--- a/src/libexpr/nixexpr.hh
+++ b/src/libexpr/nixexpr.hh
@@ -48,7 +48,7 @@ std::ostream & operator << (std::ostream & str, const Pos & pos);
 
 struct Env;
 struct Value;
-struct EvalState;
+class EvalState;
 struct StaticEnv;
 struct Expr;
 
@@ -71,6 +71,7 @@ string showAttrPath(const AttrPath & attrPath);
 
 struct Expr
 {
+    virtual ~Expr() { };
     virtual void show(std::ostream & str);
     virtual void bindVars(const StaticEnv & env);
     virtual void eval(EvalState & state, Env & env, Value & v);
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index 55a42fcaba9f..8a084fea0697 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -252,7 +252,7 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * err
   nix::Formals * formals;
   nix::Formal * formal;
   nix::NixInt n;
-  char * id; // !!! -> Symbol
+  const char * id; // !!! -> Symbol
   char * path;
   char * uri;
   std::vector<nix::AttrName> * attrNames;
@@ -414,7 +414,7 @@ expr_simple
 string_parts
   : STR
   | string_parts_interpolated { $$ = new ExprConcatStrings(true, $1); }
-  | { $$ = new ExprString(data->symbols.create("")) }
+  | { $$ = new ExprString(data->symbols.create("")); }
   ;
 
 string_parts_interpolated
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 4f836e279425..ca316f08af13 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -1322,6 +1322,7 @@ void EvalState::createBaseEnv()
     /* Add a wrapper around the derivation primop that computes the
        `drvPath' and `outPath' attributes lazily. */
     string path = findFile("nix/derivation.nix");
+    assert(!path.empty());
     sDerivationNix = symbols.create(path);
     evalFile(path, v);
     addConstant("derivation", v);
diff --git a/src/libexpr/value.hh b/src/libexpr/value.hh
index 982582793419..2feb2f9492ca 100644
--- a/src/libexpr/value.hh
+++ b/src/libexpr/value.hh
@@ -22,13 +22,13 @@ typedef enum {
 } ValueType;
 
 
-struct Bindings;
+class Bindings;
 struct Env;
 struct Expr;
 struct ExprLambda;
 struct PrimOp;
 struct PrimOp;
-struct Symbol;
+class Symbol;
 
 
 typedef long NixInt;
diff --git a/src/libmain/Makefile.am b/src/libmain/Makefile.am
deleted file mode 100644
index 75b9d83dcf73..000000000000
--- a/src/libmain/Makefile.am
+++ /dev/null
@@ -1,11 +0,0 @@
-pkglib_LTLIBRARIES = libmain.la
-
-libmain_la_SOURCES = shared.cc stack.cc
-
-libmain_la_LIBADD = ../libstore/libstore.la @BDW_GC_LIBS@
-
-pkginclude_HEADERS = shared.hh
-
-AM_CXXFLAGS = \
- -I$(srcdir)/.. -I$(srcdir)/../libutil \
- -I$(srcdir)/../libstore
diff --git a/src/libmain/local.mk b/src/libmain/local.mk
new file mode 100644
index 000000000000..71a07d1979ab
--- /dev/null
+++ b/src/libmain/local.mk
@@ -0,0 +1,11 @@
+libraries += libmain
+
+libmain_NAME = libnixmain
+
+libmain_DIR := $(d)
+
+libmain_SOURCES := $(wildcard $(d)/*.cc)
+
+libmain_LIBS = libstore libutil libformat
+
+libmain_ALLOW_UNDEFINED = 1
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index 999b5023802c..fb70cb076732 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -15,10 +15,6 @@
 #include <unistd.h>
 #include <signal.h>
 
-#if HAVE_BOEHMGC
-#include <gc/gc.h>
-#endif
-
 
 namespace nix {
 
@@ -236,14 +232,6 @@ static void initAndRun(int argc, char * * argv)
 }
 
 
-/* Called when the Boehm GC runs out of memory. */
-static void * oomHandler(size_t requested)
-{
-    /* Convert this to a proper C++ exception. */
-    throw std::bad_alloc();
-}
-
-
 void showManPage(const string & name)
 {
     string cmd = "man " + name;
@@ -273,14 +261,6 @@ int main(int argc, char * * argv)
 
     std::ios::sync_with_stdio(false);
 
-#if HAVE_BOEHMGC
-    /* Initialise the Boehm garbage collector.  This isn't necessary
-       on most platforms, but for portability we do it anyway. */
-    GC_INIT();
-
-    GC_oom_fn = oomHandler;
-#endif
-
     try {
         try {
             initAndRun(argc, argv);
diff --git a/src/libstore/Makefile.am b/src/libstore/Makefile.am
deleted file mode 100644
index 3dfb1e0c3a24..000000000000
--- a/src/libstore/Makefile.am
+++ /dev/null
@@ -1,33 +0,0 @@
-pkglib_LTLIBRARIES = libstore.la
-
-libstore_la_SOURCES = \
-  store-api.cc local-store.cc remote-store.cc derivations.cc build.cc misc.cc \
-  globals.cc references.cc pathlocks.cc gc.cc \
-  optimise-store.cc
-
-pkginclude_HEADERS = \
-  store-api.hh local-store.hh remote-store.hh derivations.hh misc.hh \
-  globals.hh references.hh pathlocks.hh \
-  worker-protocol.hh
-
-libstore_la_LIBADD = ../libutil/libutil.la ../boost/format/libformat.la @SQLITE3_LIBS@ -lbz2
-
-EXTRA_DIST = schema.sql
-
-AM_CXXFLAGS = -Wall \
- -I$(srcdir)/.. -I$(srcdir)/../libutil \
- -DNIX_STORE_DIR=\"$(storedir)\" \
- -DNIX_DATA_DIR=\"$(datadir)\" \
- -DNIX_STATE_DIR=\"$(localstatedir)/nix\" \
- -DNIX_LOG_DIR=\"$(localstatedir)/log/nix\" \
- -DNIX_CONF_DIR=\"$(sysconfdir)/nix\" \
- -DNIX_LIBEXEC_DIR=\"$(libexecdir)\" \
- -DNIX_BIN_DIR=\"$(bindir)\" \
- -DNIX_VERSION=\"$(VERSION)\" \
- -I$(srcdir)/.. -I$(srcdir)/../libutil \
- -I$(srcdir)/../libstore
-
-local-store.lo: schema.sql.hh
-
-%.sql.hh: %.sql
-	sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/' < $< > $@ || (rm $@ && exit 1)
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 4329d9a22b95..1b379752fa0e 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -75,12 +75,9 @@ using std::map;
 static string pathNullDevice = "/dev/null";
 
 
-static const uid_t rootUserId = 0;
-
-
 /* Forward definition. */
 class Worker;
-class HookInstance;
+struct HookInstance;
 
 
 /* A pointer to a goal. */
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index d212259f3b66..79bd7d56b3fe 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -22,8 +22,6 @@ static string gcLockName = "gc.lock";
 static string tempRootsDir = "temproots";
 static string gcRootsDir = "gcroots";
 
-static const int defaultGcLevel = 1000;
-
 
 /* Acquire the global GC lock.  This is used to prevent new Nix
    processes from starting after the temporary root files have been
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index 1ecc629cb55f..68add1982f43 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -212,7 +212,7 @@ Settings::SettingsMap Settings::getOverrides()
 }
 
 
-const string nixVersion = NIX_VERSION;
+const string nixVersion = PACKAGE_VERSION;
 
 
 }
diff --git a/src/libstore/local.mk b/src/libstore/local.mk
new file mode 100644
index 000000000000..2dddce740dcc
--- /dev/null
+++ b/src/libstore/local.mk
@@ -0,0 +1,28 @@
+libraries += libstore
+
+libstore_NAME = libnixstore
+
+libstore_DIR := $(d)
+
+libstore_SOURCES := $(wildcard $(d)/*.cc)
+
+libstore_LIBS = libutil libformat
+
+libstore_LDFLAGS = -lsqlite3 -lbz2
+
+libstore_CXXFLAGS = \
+ -DNIX_STORE_DIR=\"$(storedir)\" \
+ -DNIX_DATA_DIR=\"$(datadir)\" \
+ -DNIX_STATE_DIR=\"$(localstatedir)/nix\" \
+ -DNIX_LOG_DIR=\"$(localstatedir)/log/nix\" \
+ -DNIX_CONF_DIR=\"$(sysconfdir)/nix\" \
+ -DNIX_LIBEXEC_DIR=\"$(libexecdir)\" \
+ -DNIX_BIN_DIR=\"$(bindir)\" \
+ -DPACKAGE_VERSION=\"$(PACKAGE_VERSION)\"
+
+$(d)/local-store.cc: $(d)/schema.sql.hh
+
+%.sql.hh: %.sql
+	$(trace-gen) sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/' < $< > $@ || (rm $@ && exit 1)
+
+clean-files += $(d)/schema.sql.hh
diff --git a/src/libutil/Makefile.am b/src/libutil/Makefile.am
deleted file mode 100644
index 0c4073e66eab..000000000000
--- a/src/libutil/Makefile.am
+++ /dev/null
@@ -1,18 +0,0 @@
-pkglib_LTLIBRARIES = libutil.la
-
-libutil_la_SOURCES = util.cc hash.cc serialise.cc \
-  archive.cc xml-writer.cc affinity.cc
-
-libutil_la_LIBADD = ../boost/format/libformat.la
-
-pkginclude_HEADERS = util.hh hash.hh serialise.hh \
-  archive.hh xml-writer.hh types.hh affinity.hh
-
-if !HAVE_OPENSSL
-libutil_la_SOURCES += \
- md5.c md5.h sha1.c sha1.h sha256.c sha256.h md32_common.h
-else
-libutil_la_LIBADD += @OPENSSL_LIBS@
-endif
-
-AM_CXXFLAGS = -Wall -I$(srcdir)/..
diff --git a/src/libutil/local.mk b/src/libutil/local.mk
new file mode 100644
index 000000000000..8af2e78d9ce4
--- /dev/null
+++ b/src/libutil/local.mk
@@ -0,0 +1,15 @@
+libraries += libutil
+
+libutil_NAME = libnixutil
+
+libutil_DIR := $(d)
+
+libutil_SOURCES := $(wildcard $(d)/*.cc)
+
+ifeq ($(HAVE_OPENSSL), 1)
+  libutil_LDFLAGS = $(OPENSSL_LIBS)
+else
+  libutil_SOURCES += $(d)/md5.c $(d)/sha1.c $(d)/sha256.c
+endif
+
+libutil_LIBS = libformat
diff --git a/src/nix-daemon/Makefile.am b/src/nix-daemon/Makefile.am
deleted file mode 100644
index b8e9f4a064ad..000000000000
--- a/src/nix-daemon/Makefile.am
+++ /dev/null
@@ -1,12 +0,0 @@
-bin_PROGRAMS = nix-daemon
-
-nix_daemon_SOURCES = nix-daemon.cc
-nix_daemon_LDADD = ../libmain/libmain.la ../libstore/libstore.la ../libutil/libutil.la \
- ../boost/format/libformat.la
-
-AM_CXXFLAGS = \
- -I$(srcdir)/.. -I$(srcdir)/../libutil \
- -I$(srcdir)/../libstore -I$(srcdir)/../libmain
-
-install-exec-local:
-	ln -sf nix-daemon $(DESTDIR)$(bindir)/nix-worker
diff --git a/src/nix-daemon/local.mk b/src/nix-daemon/local.mk
new file mode 100644
index 000000000000..db071a3f7c7e
--- /dev/null
+++ b/src/nix-daemon/local.mk
@@ -0,0 +1,9 @@
+programs += nix-daemon
+
+nix-daemon_DIR := $(d)
+
+nix-daemon_SOURCES := $(d)/nix-daemon.cc
+
+nix-daemon_LIBS = libmain libstore libutil libformat
+
+$(eval $(call install-symlink, nix-daemon, $(bindir)/nix-worker))
diff --git a/src/nix-env/Makefile.am b/src/nix-env/Makefile.am
deleted file mode 100644
index 4d3bd111d719..000000000000
--- a/src/nix-env/Makefile.am
+++ /dev/null
@@ -1,12 +0,0 @@
-bin_PROGRAMS = nix-env
-
-nix_env_SOURCES = nix-env.cc profiles.cc profiles.hh user-env.cc user-env.hh
-
-nix_env_LDADD = ../libmain/libmain.la ../libexpr/libexpr.la \
- ../libstore/libstore.la ../libutil/libutil.la \
- ../boost/format/libformat.la
-
-AM_CXXFLAGS = \
- -I$(srcdir)/.. \
- -I$(srcdir)/../libutil -I$(srcdir)/../libstore \
- -I$(srcdir)/../libexpr -I$(srcdir)/../libmain -I../libexpr
diff --git a/src/nix-env/local.mk b/src/nix-env/local.mk
new file mode 100644
index 000000000000..e80719cd76f7
--- /dev/null
+++ b/src/nix-env/local.mk
@@ -0,0 +1,7 @@
+programs += nix-env
+
+nix-env_DIR := $(d)
+
+nix-env_SOURCES := $(wildcard $(d)/*.cc)
+
+nix-env_LIBS = libexpr libmain libstore libutil libformat
diff --git a/src/nix-env/user-env.cc b/src/nix-env/user-env.cc
index c2dab4f0c757..3a73f2647a6b 100644
--- a/src/nix-env/user-env.cc
+++ b/src/nix-env/user-env.cc
@@ -1,5 +1,5 @@
+#include "user-env.hh"
 #include "util.hh"
-#include "get-drvs.hh"
 #include "derivations.hh"
 #include "store-api.hh"
 #include "globals.hh"
diff --git a/src/nix-hash/Makefile.am b/src/nix-hash/Makefile.am
deleted file mode 100644
index ef7bb8423980..000000000000
--- a/src/nix-hash/Makefile.am
+++ /dev/null
@@ -1,8 +0,0 @@
-bin_PROGRAMS = nix-hash
-
-nix_hash_SOURCES = nix-hash.cc
-nix_hash_LDADD = ../libmain/libmain.la ../libstore/libstore.la ../libutil/libutil.la \
- ../boost/format/libformat.la
-
-AM_CXXFLAGS = \
- -I$(srcdir)/.. -I$(srcdir)/../libutil -I$(srcdir)/../libstore -I$(srcdir)/../libmain
diff --git a/src/nix-hash/local.mk b/src/nix-hash/local.mk
new file mode 100644
index 000000000000..7c290ca8466e
--- /dev/null
+++ b/src/nix-hash/local.mk
@@ -0,0 +1,7 @@
+programs += nix-hash
+
+nix-hash_DIR := $(d)
+
+nix-hash_SOURCES := $(d)/nix-hash.cc
+
+nix-hash_LIBS = libmain libstore libutil libformat
diff --git a/src/nix-instantiate/Makefile.am b/src/nix-instantiate/Makefile.am
deleted file mode 100644
index 96978f36c5ae..000000000000
--- a/src/nix-instantiate/Makefile.am
+++ /dev/null
@@ -1,10 +0,0 @@
-bin_PROGRAMS = nix-instantiate
-
-nix_instantiate_SOURCES = nix-instantiate.cc
-nix_instantiate_LDADD = ../libmain/libmain.la ../libexpr/libexpr.la \
- ../libstore/libstore.la ../libutil/libutil.la \
- ../boost/format/libformat.la
-
-AM_CXXFLAGS = \
- -I$(srcdir)/.. -I$(srcdir)/../libutil -I$(srcdir)/../libstore \
- -I$(srcdir)/../libexpr -I$(srcdir)/../libmain -I../libexpr
diff --git a/src/nix-instantiate/local.mk b/src/nix-instantiate/local.mk
new file mode 100644
index 000000000000..7d1bc5ec9dfb
--- /dev/null
+++ b/src/nix-instantiate/local.mk
@@ -0,0 +1,7 @@
+programs += nix-instantiate
+
+nix-instantiate_DIR := $(d)
+
+nix-instantiate_SOURCES := $(d)/nix-instantiate.cc
+
+nix-instantiate_LIBS = libexpr libmain libstore libutil libformat
diff --git a/src/nix-log2xml/Makefile.am b/src/nix-log2xml/Makefile.am
deleted file mode 100644
index c538fda08014..000000000000
--- a/src/nix-log2xml/Makefile.am
+++ /dev/null
@@ -1,17 +0,0 @@
-bin_PROGRAMS = nix-log2xml
-
-nix_log2xml_SOURCES = log2xml.cc
-
-%.xml: %.log nix-log2xml
-	./nix-log2xml < $< > $@
-
-%.html: %.xml mark-errors.xsl log2html.xsl
-	$(xsltproc) mark-errors.xsl $< | $(xsltproc) log2html.xsl - > $@
-
-LOG2HTML = $(srcdir)/mark-errors.xsl $(srcdir)/log2html.xsl $(srcdir)/treebits.js
-
-EXTRA_DIST = $(LOG2HTML)
-
-install-data-local:
-	$(INSTALL) -d $(DESTDIR)$(datadir)/nix/log2html
-	$(INSTALL_DATA) $(LOG2HTML) $(DESTDIR)$(datadir)/nix/log2html
diff --git a/src/nix-log2xml/local.mk b/src/nix-log2xml/local.mk
new file mode 100644
index 000000000000..46eb2e02ca64
--- /dev/null
+++ b/src/nix-log2xml/local.mk
@@ -0,0 +1,8 @@
+programs += nix-log2xml
+
+nix-log2xml_DIR := $(d)
+
+nix-log2xml_SOURCES := $(d)/log2xml.cc
+
+$(foreach file, mark-errors.xsl log2html.xsl treebits.js, \
+  $(eval $(call install-data-in, $(d)/$(file), $(datadir)/nix/log2html)))
diff --git a/src/nix-store/Makefile.am b/src/nix-store/Makefile.am
deleted file mode 100644
index fca9eff7cde8..000000000000
--- a/src/nix-store/Makefile.am
+++ /dev/null
@@ -1,12 +0,0 @@
-bin_PROGRAMS = nix-store
-
-nix_store_SOURCES =			\
-  nix-store.cc dotgraph.cc dotgraph.hh	\
-  xmlgraph.cc xmlgraph.hh
-
-nix_store_LDADD = ../libmain/libmain.la ../libstore/libstore.la ../libutil/libutil.la \
- ../boost/format/libformat.la -lbz2
-
-AM_CXXFLAGS = \
- -I$(srcdir)/.. -I$(srcdir)/../libutil \
- -I$(srcdir)/../libstore -I$(srcdir)/../libmain
diff --git a/src/nix-store/local.mk b/src/nix-store/local.mk
new file mode 100644
index 000000000000..7f93e4c19196
--- /dev/null
+++ b/src/nix-store/local.mk
@@ -0,0 +1,9 @@
+programs += nix-store
+
+nix-store_DIR := $(d)
+
+nix-store_SOURCES := $(wildcard $(d)/*.cc)
+
+nix-store_LIBS = libmain libstore libutil libformat
+
+nix-store_LDFLAGS = -lbz2