--- RUNME.orig	2014-06-02 12:58:23.000000000 -0500
+++ RUNME	2014-06-03 03:41:31.000000000 -0500
@@ -103,6 +103,7 @@
 ARCH=`arch`
 cat Makefile.base | sed '/DO NOT DELETE/,$d' | sed "s/^TARGET_FATDISK=.*/TARGET_FATDISK=fatdisk.$ARCH/g" > Makefile.tmp
 mv Makefile.tmp Makefile
+mkdir .o
 makedepend *.c -p .o/ 2>/dev/null
 if [ $? -ne 0 ]
 then
@@ -119,6 +122,17 @@
 echo "GCC_COMPILER_WARNINGS=-Wall -fmessage-length=0 -Wno-trigraphs -Wmissing-prototypes -Wreturn-type -Wparentheses -Wswitch -Wno-unused-parameter -Wunused-variable -Wunused-value # AUTOGEN" >> .Makefile
 echo "GXX_COMPILER_WARNINGS=-Wall -fmessage-length=0 -Wno-trigraphs -Wreturn-type -Wparentheses -Wswitch -Wno-unused-parameter -Wunused-variable -Wunused-value # AUTOGEN" >> .Makefile
 
+if [ -n "$CC" ]
+then
+    $CC -E -dM -x c /dev/null | grep -q __clang__
+    if [ $? -eq 0 ]
+    then
+        echo "COMPILER_WARNINGS=\$(CLANG_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
+    else
+        echo "COMPILER_WARNINGS=\$(GCC_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
+    fi
+    echo "CC=$CC # AUTOGEN" >> .Makefile
+else
 `clang --version >/dev/null 2>/dev/null`
 if [ $? -eq 0 ]
 then
@@ -162,11 +176,14 @@
 	fi
     fi
 fi
+fi
 
 echo "    " >> .Makefile
 echo "EXE=$EXE # AUTOGEN" >> .Makefile
-echo "LDLIBS=$LDLIBS # AUTOGEN" >> .Makefile
-echo "CFLAGS=\$(COMPILER_FLAGS) \$(COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
+echo "EXTRA_CFLAGS=$CFLAGS # AUTOGEN" >> .Makefile
+echo "EXTRA_LDFLAGS=$LDFLAGS # AUTOGEN" >> .Makefile
+echo "LDLIBS=$LDLIBS \$(EXTRA_LDFLAGS) # AUTOGEN" >> .Makefile
+echo "CFLAGS=\$(COMPILER_FLAGS) \$(COMPILER_WARNINGS) \$(EXTRA_CFLAGS) # AUTOGEN" >> .Makefile
 
 cat Makefile | grep -v AUTOGEN | grep -v "^    $" >> .Makefile
 
@@ -183,6 +200,8 @@
     exit 1
 fi
 
+exit
+
 log_info "Cleaning"
 make clean | sed 's/^/  /g'
 
