summaryrefslogtreecommitdiff
path: root/tools/thumb-cc.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/thumb-cc.py')
-rwxr-xr-xtools/thumb-cc.py70
1 files changed, 16 insertions, 54 deletions
diff --git a/tools/thumb-cc.py b/tools/thumb-cc.py
index 1015284447..2c83474695 100755
--- a/tools/thumb-cc.py
+++ b/tools/thumb-cc.py
@@ -7,7 +7,7 @@
7# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8# \/ \/ \/ \/ \/ 8# \/ \/ \/ \/ \/
9# 9#
10# Copyright © 2010 Rafaël Carré <rafael.carre@gmail> 10# Copyright © 2010-2011 Rafaël Carré <rafael.carre@gmail>
11# 11#
12# This program is free software; you can redistribute it and/or 12# This program is free software; you can redistribute it and/or
13# modify it under the terms of the GNU General Public License 13# modify it under the terms of the GNU General Public License
@@ -16,65 +16,27 @@
16# 16#
17# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18# KIND, either express or implied. 18# KIND, either express or implied.
19#
20
21import sys
22import os
23import subprocess
24import tempfile
25
26
27def run_gcc(args):
28 os.execv(args[0], args) # run real gcc
29
30def get_output(args):
31 output = False
32 for i in args:
33 if output == True:
34 return i
35 elif i == '-o':
36 output = True
37
38 19
39def try_thumb(args, output): 20from sys import argv, stderr, stdout
40 thumb_args = args + ['-mthumb'] 21from subprocess import Popen, PIPE
41 thumb_args[thumb_args.index('-o') + 1] = output 22from os import execv
42 thumb_gcc = subprocess.Popen(thumb_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
43 (stdout, stderr) = thumb_gcc.communicate()
44 23
45 if thumb_gcc.returncode != 0: # building failed 24args = argv[1:] # remove script path
46 return False
47
48 # building with thumb succeeded, show our output
49 #sys.stderr.write(bytes.decode(stderr))
50 #sys.stdout.write(bytes.decode(stdout))
51 sys.stderr.write(stderr)
52 sys.stdout.write(stdout)
53 return True
54
55##### main
56
57
58args=sys.argv[1:] # remove script path
59 25
60for opt in ['-E', '-MM', '-v', '--version']: 26for opt in ['-E', '-MM', '-v', '--version']:
61 if opt in args: 27 if opt in args:
62 run_gcc(args) 28 execv(args[0], args) # not actually compiling
63
64output = get_output(args)
65split = output.rsplit('.o', 1)
66 29
67if len(split) == 1: # output doesn't end in .o 30if '-o' in args and args.index('-o') < len(args) - 1:
68 run_gcc(args) 31 if len(args[args.index('-o') + 1].rsplit('.o', 1)) == 1:
32 execv(args[0], args) # output doesn't end in .o
69 33
70dirname = os.path.dirname(output) 34args.append('-mthumb-interwork') # thumb-interwork is required
71thumb_output = tempfile.mktemp(suffix='.o', prefix=split[0], dir=dirname) 35gcc = Popen(args + ['-mthumb'], stdout=PIPE, stderr=PIPE)
36(out, err) = gcc.communicate()
72 37
73args.append('-mthumb-interwork') 38if gcc.returncode != 0: # thumb failed, try outputting arm
39 execv(args[0], args)
74 40
75if try_thumb(args, thumb_output): 41stdout.write(out)
76 os.rename(thumb_output, output) 42stderr.write(err)
77 sys.exit(0)
78else:
79 #sys.stderr.write('skipped ' + os.path.basename(output) + '\n')
80 run_gcc(args)