diff options
author | Rafaël Carré <rafael.carre@gmail.com> | 2011-05-18 20:04:20 +0000 |
---|---|---|
committer | Rafaël Carré <rafael.carre@gmail.com> | 2011-05-18 20:04:20 +0000 |
commit | 9b6910c348fd9870d63e9d0736717f00bb2fbdf6 (patch) | |
tree | 6fd7dce073d2cb2a93082fd38152f73ee81d3a1f | |
parent | 7eb0db250cc1cfe54d7c061e7ffa65b34a058c1d (diff) | |
download | rockbox-9b6910c348fd9870d63e9d0736717f00bb2fbdf6.tar.gz rockbox-9b6910c348fd9870d63e9d0736717f00bb2fbdf6.zip |
thumb-cc.py: simplify
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29897 a1c6a512-1295-4272-9138-f99709370657
-rwxr-xr-x | tools/thumb-cc.py | 70 |
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 | |||
21 | import sys | ||
22 | import os | ||
23 | import subprocess | ||
24 | import tempfile | ||
25 | |||
26 | |||
27 | def run_gcc(args): | ||
28 | os.execv(args[0], args) # run real gcc | ||
29 | |||
30 | def 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 | ||
39 | def try_thumb(args, output): | 20 | from sys import argv, stderr, stdout |
40 | thumb_args = args + ['-mthumb'] | 21 | from subprocess import Popen, PIPE |
41 | thumb_args[thumb_args.index('-o') + 1] = output | 22 | from 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 | 24 | args = 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 | |||
58 | args=sys.argv[1:] # remove script path | ||
59 | 25 | ||
60 | for opt in ['-E', '-MM', '-v', '--version']: | 26 | for 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 | |||
64 | output = get_output(args) | ||
65 | split = output.rsplit('.o', 1) | ||
66 | 29 | ||
67 | if len(split) == 1: # output doesn't end in .o | 30 | if '-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 | ||
70 | dirname = os.path.dirname(output) | 34 | args.append('-mthumb-interwork') # thumb-interwork is required |
71 | thumb_output = tempfile.mktemp(suffix='.o', prefix=split[0], dir=dirname) | 35 | gcc = Popen(args + ['-mthumb'], stdout=PIPE, stderr=PIPE) |
36 | (out, err) = gcc.communicate() | ||
72 | 37 | ||
73 | args.append('-mthumb-interwork') | 38 | if gcc.returncode != 0: # thumb failed, try outputting arm |
39 | execv(args[0], args) | ||
74 | 40 | ||
75 | if try_thumb(args, thumb_output): | 41 | stdout.write(out) |
76 | os.rename(thumb_output, output) | 42 | stderr.write(err) |
77 | sys.exit(0) | ||
78 | else: | ||
79 | #sys.stderr.write('skipped ' + os.path.basename(output) + '\n') | ||
80 | run_gcc(args) | ||