]> thyrsus.com Git - mad.git/commitdiff
Do compilation of multiple files.
authorEric S. Raymond <esr@thyrsus,com>
Fri, 23 Jan 2004 19:29:03 +0000 (19:29 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Fri, 23 Jan 2004 19:29:03 +0000 (19:29 +0000)
mad

diff --git a/mad b/mad
index 299a8a4dfb6dc608902664ede677f2d9181b69bb..6aedb7959253cfae6354dc36ae75d36280b79256 100755 (executable)
--- a/mad
+++ b/mad
@@ -176,7 +176,7 @@ def p_print_format0(t):
 ## R
 def p_remark1(t):
     'statement : COMMENT STRING'
-    t[0] = ('remark', t[2])
+    t[0] = ('remark', t[2][1:-1])
 
 def p_remark2(t):
     'statement : COMMENT'
@@ -538,10 +538,16 @@ def generate(out):
 if __name__ == '__main__':
     import os, getopt
     mad_debug = 0
-    (options, arguments) = getopt.getopt(sys.argv[1:], "d:")
+    binary = True
+    target = None
+    (options, arguments) = getopt.getopt(sys.argv[1:], "cd:o:")
     for (opt, val) in options:
-        if opt == '-d':
+        if opt == '-c':
+            binary = False
+        elif opt == '-d':
             mad_debug = int(val)
+        elif opt == '-o':
+            target = val
 
     if len(arguments) == 0:
         arguments = ['-']
@@ -573,19 +579,21 @@ if __name__ == '__main__':
     # Generate code
     if arguments == ['-']:
         generate(sys.stdout)
-    elif len(arguments) == 1:
-        stem = arguments[0][:-4]
-        out = open(stem + ".c", "w")
-        generate(out)
-        out.close()
-        compile = "cc %s.c -lm -o %s" % (stem, stem)
-        if os.system(compile) == 0:
-            os.remove(stem + ".c")
-        else:
-            print "Compilation failed"
-        out.close()
-    else:
-        sys.stderr.write("mad: multiple file args are not yet supported\n")
+    elif not target and len(arguments) > 1:
+        sys.stderr.write("mad: -o is required with multiple sourcefiles.\n")
         sys.exit(1)
+    else:
+        if not target:
+            target = arguments[0][:-4]
+        for file in arguments:
+            stem = file[:-4]
+            out = open(stem + ".c", "w")
+            generate(out)
+            out.close()
+        srclist = " ".join(map(lambda x: x[:-4] + ".c", arguments))
+        if binary:
+            compile = "cc %s -lm -o %s" % (srclist, target)
+            if os.system(compile) == 0:
+                os.system("rm -f " + srclist)
 
 # end