From 2c6aa8035e0368f5041ea2759f6fd85f56d96463 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 23 Jan 2004 19:29:03 +0000 Subject: [PATCH] Do compilation of multiple files. --- mad | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/mad b/mad index 299a8a4..6aedb79 100755 --- 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 -- 2.43.0