]> git.mdlowis.com Git - proto/acc.git/commitdiff
reworked logic to scan all args at once and to generate include file dynamically
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 31 Jan 2019 04:21:57 +0000 (23:21 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 31 Jan 2019 04:21:57 +0000 (23:21 -0500)
acc

diff --git a/acc b/acc
index b554f11f8831c7469d95f39c9ce7a929f2eb5955..d632baf5461494b2d927d158f3d9a12256650f4b 100755 (executable)
--- a/acc
+++ b/acc
@@ -1,24 +1,11 @@
 #!/bin/bash
 
-# predclare our variables
+# predeclare our variables
 declare -a objects
 declare -a libpaths
 declare -a libraries
-target=a.out
 compile=false
 
-# is this a compilation step or a link step?
-if [ "x$1" = "x-c" ]; then
-    shift;
-    compile=true
-fi
-
-# what's the name of our target?
-if [ "x$1" = "x-o" ]; then
-    target=$2
-    shift; shift
-fi
-
 # scan the rest of the options for lib paths, libs and objects
 for i do
     case "$i" in
@@ -27,9 +14,23 @@ for i do
 
         -L*) # Add libpaths to the search list
             libpaths+=("$i") ;;
+
+        -c) # Mark this as compilation only
+            compile=true ;;
     esac
 done
 
-# print what we have so far
-echo "libpaths:" ${libpaths[*]}
-echo "objects:" ${objects[*]}
+# generate the autolib include file
+gendir="/tmp/$USER"
+genfile="autolib.h"
+if [[ ! -f "$gendir/$genfile" ]]; then
+    mkdir -p "$gendir"
+    printf '%s' "#define AUTOLIB(n) int __autolib_##n = 1" > "/tmp/$USER/autobuild.h"
+fi
+
+# execute the compiler
+if $compile; then
+    echo cc -include "$gendir/$genfile" "$@"
+else
+    echo cc "$@"
+fi