4 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
5 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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.
28 os
.execv(args
[0], args
) # run real gcc
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
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
)
58 args
=sys
.argv
[1:] # remove script path
60 for opt
in ['-E', '-MM', '-v', '--version']:
64 output
= get_output(args
)
65 split
= output
.rsplit('.o', 1)
67 if len(split
) == 1: # output doesn't end in .o
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
)
79 #sys.stderr.write('skipped ' + os.path.basename(output) + '\n')