Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MorsGames
GitHub Repository: MorsGames/sm64plus
Path: blob/master/tools/asm_processor/build.py
7857 views
1
#!/usr/bin/env python3
2
import sys
3
import os
4
import shlex
5
import subprocess
6
import tempfile
7
8
dir_path = os.path.dirname(os.path.realpath(__file__))
9
asm_processor = ['python3', os.path.join(dir_path, "asm-processor.py")]
10
prelude = os.path.join(dir_path, "prelude.inc")
11
12
all_args = sys.argv[1:]
13
sep1 = all_args.index('--')
14
sep2 = all_args.index('--', sep1+1)
15
16
compiler = all_args[:sep1]
17
18
assembler = all_args[sep1+1:sep2]
19
assembler_sh = ' '.join(shlex.quote(x) for x in assembler)
20
21
compile_args = all_args[sep2+1:]
22
in_file = compile_args[-1]
23
out_ind = compile_args.index('-o')
24
out_file = compile_args[out_ind + 1]
25
del compile_args[-1]
26
del compile_args[out_ind + 1]
27
del compile_args[out_ind]
28
29
in_dir = os.path.split(os.path.realpath(in_file))[0]
30
opt_flags = [x for x in compile_args if x in ['-g', '-O2', '-O1', '-framepointer']]
31
32
preprocessed_file = tempfile.NamedTemporaryFile(prefix='preprocessed', suffix='.c')
33
34
subprocess.check_call(asm_processor + opt_flags + [in_file], stdout=preprocessed_file)
35
subprocess.check_call(compiler + compile_args + ['-I', in_dir, '-o', out_file, preprocessed_file.name])
36
subprocess.check_call(asm_processor + opt_flags + [in_file, '--post-process', out_file, '--assembler', assembler_sh, '--asm-prelude', prelude])
37
38