Index: driver/cfa.cc
===================================================================
--- driver/cfa.cc	(revision 534e4e460878f8a2e7d24b4a0413515e6acd1dae)
+++ driver/cfa.cc	(revision 37fe3525f53534b29c07f4f1204c5f779836d193)
@@ -21,4 +21,7 @@
 #include <string.h>										// strcmp
 
+#include <sys/types.h>
+#include <sys/stat.h>
+
 #include "Common/SemanticError.h"
 #include "config.h"										// configure info
@@ -66,4 +69,14 @@
 } // shuffle
 
+static inline bool dirExists(const string & path) {
+    struct stat info;
+    if(stat( path.c_str(), &info ) != 0)
+        return false;
+    else if(info.st_mode & S_IFDIR)
+        return true;
+    else
+        return false;
+} //dirExists
+
 
 #define str(s) #s
@@ -96,4 +109,7 @@
 	bool xflag = false;									// user supplied -x flag
 	bool debugging __attribute(( unused )) = false;		// -g flag
+	bool m32 = false;                                    // -m32 flag
+	bool m64 = false;                                    // -m64 flag
+	bool intree = false;
 
 	const char *args[argc + 100];						// cfa command line values, plus some space for additional flags
@@ -154,4 +170,7 @@
 			} else if ( arg == "-no-include-stdhdr" ) {
 				noincstd_flag = true;					// strip the no-include-stdhdr flag
+			} else if ( arg == "-in-tree" ) {
+				noincstd_flag = true;
+				intree = true;
 			} else if ( arg == "-compiler" ) {
 				// use the user specified compiler
@@ -258,4 +277,14 @@
 				libs[nlibs] = argv[i];
 				nlibs += 1;
+			} else if ( arg == "-m32" ) {
+				m32 = true;
+				m64 = false;
+				args[nargs] = argv[i];
+				nargs += 1;
+			} else if ( arg == "-m64" ) {
+				m64 = true;
+				m32 = false;
+				args[nargs] = argv[i];
+				nargs += 1;
 			} else {
 				// concatenate any other arguments
@@ -320,4 +349,28 @@
 	nargs += 1;
 
+	string libdir;
+	if( !intree ) {
+		const char * const arch = m32 ? CFA_32_CPU : (m64 ? CFA_64_CPU : CFA_DEFAULT_CPU);
+		const char * config = debug ? "debug": "nodebug";
+		libdir = string(CFA_LIBDIR) + arch + config;
+		if( !dirExists(libdir) ) {
+			cerr << argv[0] << " internal error, cannot find prelude directory." << endl;
+			cerr << "Was looking for " << libdir << endl;
+			libdir = string(CFA_LIBDIR) + arch + "nolib";
+		}
+
+		if( !dirExists(libdir) ) {
+			cerr << argv[0] << " internal error, cannot find prelude directory." << endl;
+			cerr << "Was looking for " << libdir << endl;
+			exit( EXIT_FAILURE );
+		}
+
+		args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir) ).c_str();
+		nargs += 1;
+	} else {
+		args[nargs] = "-D__CFA_FLAG__=-t";
+		nargs += 1;
+	}
+
 	if ( link ) {
 		args[nargs] = "-Xlinker";
@@ -335,11 +388,9 @@
 
 		// include the cfa library in case it's needed
-		args[nargs] = "-L" CFA_LIBDIR;
-		nargs += 1;
-		if ( debug ) {
-			args[nargs] = "-lcfa-d";
-		} else {
-			args[nargs] = "-lcfa";
-		} // if
+		if( !intree ) {
+			args[nargs] = ( *new string( string("-L" ) + libdir) ).c_str();
+			nargs += 1;
+		}
+		args[nargs] = "-lcfa";
 		nargs += 1;
 		args[nargs] = "-lpthread";
@@ -400,8 +451,8 @@
 	} // if
 
-    args[nargs] = "-Xlinker";							// used by backtrace
-    nargs += 1;
-    args[nargs] = "-export-dynamic";
-    nargs += 1;
+	args[nargs] = "-Xlinker";							// used by backtrace
+	nargs += 1;
+	args[nargs] = "-export-dynamic";
+	nargs += 1;
 
 	// execute the compilation command
