Index: driver/Makefile.in
===================================================================
--- driver/Makefile.in	(revision a539fc3160f56f4694967a0d08b3cb4c7696376e)
+++ driver/Makefile.in	(revision b4f8808d54aaa8b4ea7ffa142e012fe33696f7b0)
@@ -201,4 +201,5 @@
 CCDEPMODE = @CCDEPMODE@
 CFACC = @CFACC@
+CFACC_INSTALL = @CFACC_INSTALL@
 CFACPP = @CFACPP@
 CFA_BACKEND_CC = @CFA_BACKEND_CC@
Index: driver/cfa.cc
===================================================================
--- driver/cfa.cc	(revision a539fc3160f56f4694967a0d08b3cb4c7696376e)
+++ driver/cfa.cc	(revision b4f8808d54aaa8b4ea7ffa142e012fe33696f7b0)
@@ -15,10 +15,11 @@
 
 #include <iostream>
-#include <cstdio>										// perror
-#include <cstdlib>										// putenv, exit
-#include <unistd.h>										// execvp
-#include <string>										// STL version
-#include <string.h>										// strcmp
-#include <algorithm>									// find
+#include <cstdio>      // perror
+#include <cstdlib>     // putenv, exit
+#include <climits>     // PATH_MAX
+#include <unistd.h>    // execvp
+#include <string>      // STL version
+#include <string.h>    // strcmp
+#include <algorithm>   // find
 
 #include <sys/types.h>
@@ -35,5 +36,6 @@
 // #define __DEBUG_H__
 
-static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );		// "N__=" suffix
+// "N__=" suffix
+static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );
 
 void Putenv( char * argv[], string arg ) {
@@ -57,5 +59,6 @@
 }
 
-bool suffix( const string & arg ) {						// check if string has suffix
+// check if string has suffix
+bool suffix( const string & arg ) {
 	enum { NumSuffixes = 3 };
 	static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" };
@@ -76,4 +79,41 @@
 static inline string dir(const string & path) {
 	return path.substr(0, path.find_last_of('/'));
+}
+
+// Different path modes
+enum PathMode {
+	Installed,     // cfa is installed, use prefix
+	BuildTree,     // cfa is in the tree, use source and build tree
+	Distributed    // cfa is distributed, use build tree for includes and executable directory for .cfs
+};
+
+// Get path mode from /proc
+PathMode FromProc() {
+	std::string abspath;
+	abspath.resize(PATH_MAX);
+
+	// get executable path from /proc/self/exe
+	ssize_t size = readlink("/proc/self/exe", const_cast<char*>(abspath.c_str()), abspath.size());
+	if(size <= 0) {
+		std::cerr << "Error could not evaluate absolute path from /proc/self/exe" << std::endl;
+		std::cerr << "Failed with " << std::strerror(errno) << std::endl;
+		std::exit(1);
+	}
+
+	// Trim extra characters
+	abspath.resize(size);
+
+	// Are we installed
+	if(abspath.rfind(CFA_BINDIR  , 0) == 0) { return Installed; }
+
+	// Is this the build tree
+	if(abspath.rfind(TOP_BUILDDIR, 0) == 0) { return BuildTree; }
+
+	// Does this look like distcc
+	if(abspath.find("/.cfadistcc/") != std::string::npos) { return Distributed; }
+
+	// None of the above? Give up since we don't know where the prelude or include directories are
+	std::cerr << "Cannot find required files from excutable path " << abspath << std::endl;
+	std::exit(1);
 }
 
@@ -113,8 +153,8 @@
 	bool m32 = false;									// -m32 flag
 	bool m64 = false;									// -m64 flag
-	bool intree = false;								// build in tree
 	bool compiling_libs = false;
-	bool disttree = false;
 	int o_file = 0;										// -o filename position
+
+	PathMode path = FromProc();
 
 	const char *args[argc + 100];						// cfa command line values, plus some space for additional flags
@@ -171,8 +211,4 @@
 			} else if ( arg == "-no-include-stdhdr" ) {
 				noincstd_flag = true;					// strip the no-include-stdhdr flag
-			} else if ( arg == "-in-tree" ) {
-				intree = true;
-			} else if ( arg == "-dist-tree" ) {
-				disttree = true;
 			} else if ( arg == "-cfalib") {
 				compiling_libs = true;
@@ -283,18 +319,29 @@
 
 	// add the CFA include-library paths, which allow direct access to header files without directory qualification
-	if ( ! intree ) {
+	string libbase;
+	switch(path) {
+	case Installed:
 		args[nargs++] = "-I" CFA_INCDIR;
-		if ( ! noincstd_flag ) {						// do not use during build
+		// do not use during build
+		if ( ! noincstd_flag ) {
 			args[nargs++] = "-I" CFA_INCDIR "stdhdr";
 		} // if
 		args[nargs++] = "-I" CFA_INCDIR "concurrency";
 		args[nargs++] = "-I" CFA_INCDIR "containers";
-	} else {
+		libbase = CFA_LIBDIR;
+		break;
+	case BuildTree:
+	case Distributed:
 		args[nargs++] = "-I" TOP_SRCDIR "libcfa/src";
-		if ( ! noincstd_flag ) {						// do not use during build
+		// do not use during build
+		if ( ! noincstd_flag ) {
 			args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/stdhdr";
 		} // if
 		args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/concurrency";
 		args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/containers";
+
+		libbase = TOP_BUILDDIR "libcfa/";
+
+		break;
 	} // if
 
@@ -302,11 +349,4 @@
 	args[nargs++] = "-imacros";
 	args[nargs++] = "stdbool.h";
-
-	string libbase;
-	if ( ! intree ) {
-		libbase = CFA_LIBDIR;
-	} else {
-		libbase = TOP_BUILDDIR "libcfa/";
-	} // if
 
 	if( compiling_libs ) {
@@ -326,5 +366,5 @@
 	string libdir = libbase + arch + "-" + config;
 
-	if (!disttree) {
+	if (path != Distributed) {
 		if ( ! nolib && ! dirExists( libdir ) ) {
 			cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl;
@@ -344,10 +384,8 @@
 	} // if
 
-	if(disttree) {
-		Putenv( argv, "--prelude-dir=" + dir(argv[0]) );
-	} else if(intree) {
-		Putenv( argv, "--prelude-dir=" + libdir + "/prelude" );
-	} else {
-		Putenv( argv, "--prelude-dir=" + libdir );
+	switch(path) {
+	case Installed   : Putenv( argv, "--prelude-dir=" + libdir ); break;
+	case BuildTree   : Putenv( argv, "--prelude-dir=" + libdir + "/prelude" ); break;
+	case Distributed : Putenv( argv, "--prelude-dir=" + dir(argv[0]) ); break;
 	}
 
@@ -365,6 +403,6 @@
 
 		// include the cfa library in case it is needed
-		args[nargs++] = ( *new string( string("-L" ) + libdir + (intree ? "/src/.libs" : "")) ).c_str();
-		args[nargs++] = ( *new string( string("-Wl,-rpath," ) + libdir + (intree ? "/src/.libs" : "")) ).c_str();
+		args[nargs++] = ( *new string( string("-L" ) + libdir + (path != Installed ? "/src/.libs" : "")) ).c_str();
+		args[nargs++] = ( *new string( string("-Wl,-rpath," ) + libdir + (path != Installed ? "/src/.libs" : "")) ).c_str();
 		args[nargs++] = "-Wl,--push-state,--as-needed";
 		args[nargs++] = "-lcfathread";
@@ -410,10 +448,8 @@
 
 	if ( bprefix.length() == 0 ) {
-		if(disttree) {
-			bprefix = dir(argv[0]);
-		} else if(intree) {
-			bprefix = srcdriverdir;
-		} else {
-			bprefix = installlibdir;
+		switch(path) {
+		case Installed   : bprefix = installlibdir; break;
+		case BuildTree   : bprefix = srcdriverdir ; break;
+		case Distributed : bprefix = dir(argv[0]) ; break;
 		}
 		if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/';
