]> thyrsus.com Git - mad.git/commitdiff
Now we generate actual code.
authorEric S. Raymond <esr@thyrsus,com>
Fri, 23 Jan 2004 18:56:14 +0000 (18:56 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Fri, 23 Jan 2004 18:56:14 +0000 (18:56 +0000)
mad

diff --git a/mad b/mad
index 14a1a8df2b83a46797b48c6913118b452130a93a..299a8a4dfb6dc608902664ede677f2d9181b69bb 100755 (executable)
--- a/mad
+++ b/mad
@@ -536,7 +536,7 @@ def generate(out):
     out.write('}\n')
 
 if __name__ == '__main__':
-    import getopt
+    import os, getopt
     mad_debug = 0
     (options, arguments) = getopt.getopt(sys.argv[1:], "d:")
     for (opt, val) in options:
@@ -574,9 +574,16 @@ if __name__ == '__main__':
     if arguments == ['-']:
         generate(sys.stdout)
     elif len(arguments) == 1:
-        out = open(arguments[0][:-4] + ".c", "w")
+        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")
         sys.exit(1)