call gcc to compile and link jtlc-written C sources
This commit is contained in:
parent
581be4f10d
commit
905448378e
39
jtlc
39
jtlc
@ -3,6 +3,9 @@
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
import tempfile
|
||||
from subprocess import *
|
||||
import re
|
||||
|
||||
def main(argv):
|
||||
parser = argparse.ArgumentParser(prog = 'jtlc',
|
||||
@ -16,7 +19,43 @@ def main(argv):
|
||||
parser.add_argument('sources', metavar = 'source',
|
||||
nargs = '*', help = 'Input Source File')
|
||||
args = parser.parse_args(argv[1:])
|
||||
|
||||
if len(args.sources) < 1:
|
||||
sys.stderr.write(argv[0] + ': no input files\n')
|
||||
return 1
|
||||
|
||||
ofiles = []
|
||||
for s in args.sources:
|
||||
tf = tempfile.NamedTemporaryFile(suffix = '.c', delete = False)
|
||||
tfname = tf.name
|
||||
build(args, s, tf)
|
||||
tf.close()
|
||||
m = re.match('(.*)\.jtl', s)
|
||||
if m is not None:
|
||||
ofname = m.group(1) + '.o'
|
||||
else:
|
||||
ofname = s + '.o'
|
||||
do_compile(args, tfname, ofname)
|
||||
os.unlink(tfname)
|
||||
ofiles.append(ofname)
|
||||
|
||||
if not args.c:
|
||||
do_link(args, ofiles)
|
||||
|
||||
return 0
|
||||
|
||||
def build(args, source, dest):
|
||||
dest.write('hi\n')
|
||||
|
||||
def do_compile(args, source_fname, ofname):
|
||||
Popen(['gcc', '-o', ofname, '-c', source_fname]).wait()
|
||||
|
||||
def do_link(args, ofiles):
|
||||
cmd = ['gcc']
|
||||
if args.output_file is not None:
|
||||
cmd += ['-o', args.output_file]
|
||||
cmd += ofiles
|
||||
Popen(cmd).wait()
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
||||
|
Loading…
x
Reference in New Issue
Block a user