Major speedup of iPod nano 2G. Part 7: Disable reading FIFO state in YUV blitting...
[kugel-rb.git] / tools / thumb-cc.py
blob1015284447bc77440d480038dfe49e195597d8ac
1 #!/usr/bin/python
2 # -*- coding: utf8 -*-
3 # __________ __ ___.
4 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
5 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 # \/ \/ \/ \/ \/
10 # Copyright © 2010 Rafaël Carré <rafael.carre@gmail>
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 2
15 # of the License, or (at your option) any later version.
17 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 # KIND, either express or implied.
21 import sys
22 import os
23 import subprocess
24 import tempfile
27 def run_gcc(args):
28 os.execv(args[0], args) # run real gcc
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
39 def try_thumb(args, output):
40 thumb_args = args + ['-mthumb']
41 thumb_args[thumb_args.index('-o') + 1] = output
42 thumb_gcc = subprocess.Popen(thumb_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
43 (stdout, stderr) = thumb_gcc.communicate()
45 if thumb_gcc.returncode != 0: # building failed
46 return False
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
55 ##### main
58 args=sys.argv[1:] # remove script path
60 for opt in ['-E', '-MM', '-v', '--version']:
61 if opt in args:
62 run_gcc(args)
64 output = get_output(args)
65 split = output.rsplit('.o', 1)
67 if len(split) == 1: # output doesn't end in .o
68 run_gcc(args)
70 dirname = os.path.dirname(output)
71 thumb_output = tempfile.mktemp(suffix='.o', prefix=split[0], dir=dirname)
73 args.append('-mthumb-interwork')
75 if try_thumb(args, thumb_output):
76 os.rename(thumb_output, output)
77 sys.exit(0)
78 else:
79 #sys.stderr.write('skipped ' + os.path.basename(output) + '\n')
80 run_gcc(args)