Index: driver/Makefile.in
===================================================================
--- driver/Makefile.in	(revision 0bf5340a5746391f536eae5f3f11ca78878925ec)
+++ driver/Makefile.in	(revision c2051e106b97c83b3809b5b85c34a13861991d58)
@@ -231,4 +231,5 @@
 FGREP = @FGREP@
 GREP = @GREP@
+HAS_DISTCC = @HAS_DISTCC@
 HOST_FLAGS = @HOST_FLAGS@
 INSTALL = @INSTALL@
Index: driver/cfa.cc
===================================================================
--- driver/cfa.cc	(revision 0bf5340a5746391f536eae5f3f11ca78878925ec)
+++ driver/cfa.cc	(revision c2051e106b97c83b3809b5b85c34a13861991d58)
@@ -35,9 +35,9 @@
 //#define __DEBUG_H__
 
-
 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );		// "N__=" suffix
 
 void Putenv( char * argv[], string arg ) {
-	static int flags = 0;								// environment variables must have unique names
+	// environment variables must have unique names
+	static int flags = 0;
 
 	if ( putenv( (char *)( *new string( string( __CFA_FLAGPREFIX__ + to_string( flags++ ) + "__=" ) + arg ) ).c_str() ) ) {
@@ -47,8 +47,13 @@
 } // Putenv
 
-
-bool prefix( const string & arg, const string & pre ) {	// check if string has prefix
+// check if string has prefix
+bool prefix( const string & arg, const string & pre ) {
 	return arg.substr( 0, pre.size() ) == pre;
 } // prefix
+
+inline bool ends_with(const string & str, const string & sfix) {
+	if (sfix.size() > str.size()) return false;
+	return std::equal(str.rbegin(), str.rbegin() + sfix.size(), sfix.rbegin(), sfix.rend());
+}
 
 bool suffix( const string & arg ) {						// check if string has suffix
@@ -68,4 +73,8 @@
 	return (info.st_mode & S_IFDIR) != 0;
 } // dirExists
+
+static inline string dir(const string & path) {
+	return path.substr(0, path.find_last_of('/'));
+}
 
 
@@ -105,4 +114,6 @@
 	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
 
@@ -162,4 +173,8 @@
 			} else if ( arg == "-in-tree" ) {
 				intree = true;
+			} else if ( arg == "-dist-tree" ) {
+				disttree = true;
+			} else if ( arg == "-cfalib") {
+				compiling_libs = true;
 			} else if ( arg == "-compiler" ) {
 				// use the user specified compiler
@@ -293,4 +308,7 @@
 	} else {
 		libbase = TOP_BUILDDIR "libcfa/";
+	} // if
+
+	if( compiling_libs ) {
 		Putenv( argv, "-t" );
 	} // if
@@ -305,10 +323,33 @@
 	} // if
 
-	string libdir( libbase + arch + "-" + (nolib ? "nolib" : (debug ? "debug": "nodebug")) );
-	if ( ! dirExists( libdir ) ) {
-		cerr << argv[0] << " internal error, cannot find prelude directory " << libdir << endl;
-		exit( EXIT_FAILURE );
-	} // if
-
+	const char * config = nolib ? "nolib" : (debug ? "debug": "nodebug");
+	string libdir = libbase + arch + "-" + config;
+
+	if (!disttree) {
+		if ( ! nolib && ! dirExists( libdir ) ) {
+			cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl;
+			cerr << "Was looking for " << libdir << endl;
+			for(int i = 1; i < argc; i++) {
+				cerr << argv[i] << " ";
+			}
+			cerr << endl;
+			libdir = libbase + arch + "-" + "nolib";
+		} // if
+
+		if ( ! dirExists( libdir ) ) {
+			cerr << argv[0] << " internal error, cannot find prelude directory." << endl;
+			cerr << "Was looking for " << libdir << endl;
+			exit( EXIT_FAILURE );
+		} // if
+	} // 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) );
+	}
+	nargs += 1;
 	for ( int i = 0; i < nlibs; i += 1 ) {				// copy non-user libraries after all user libraries
 		args[nargs++] = libs[i];
@@ -371,5 +412,11 @@
 
 	if ( bprefix.length() == 0 ) {
-		bprefix = ! intree ? installlibdir : srcdriverdir;
+		if(disttree) {
+			bprefix = dir(argv[0]);
+		} else if(intree) {
+			bprefix = srcdriverdir;
+		} else {
+			bprefix = installlibdir;
+		}
 		if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/';
 		Putenv( argv, ( *new string( string("-B=") + bprefix ) ).c_str() );
@@ -415,9 +462,9 @@
 		cerr << " \"" << args[i] << "\"" << endl;
 	} // for
+	cerr << endl;
 	#endif // __DEBUG_H__
 
 	if ( ! quiet ) {
 		cerr << "CFA " << "Version " << Version << heading << endl;
-
 		if ( help ) {
 			cerr <<
