bytebeat_compiler.py: search for compiler, fix section names
and reformat
This commit is contained in:
parent
c6e126f2bd
commit
ca282d20c8
@ -4,9 +4,10 @@ if __name__ == "__main__":
|
|||||||
print(":: C bytebeat generator: compiler unit")
|
print(":: C bytebeat generator: compiler unit")
|
||||||
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from os import environ, makedirs
|
from os import environ, makedirs, name as os_name
|
||||||
from os.path import exists, join as path_join
|
from os.path import exists, join as path_join
|
||||||
from shlex import split as command_line_split
|
from shlex import split as command_line_split
|
||||||
|
from shutil import which
|
||||||
from sys import stdin, stdout, exit
|
from sys import stdin, stdout, exit
|
||||||
from typing import Dict, Union
|
from typing import Dict, Union
|
||||||
import re
|
import re
|
||||||
@ -87,6 +88,18 @@ preprocessor_bool = lambda value: "1" if value else "0"
|
|||||||
C_str_repr = lambda s: '"' + s.replace("\\", "\\\\").replace(r'"', r'\"') + '"'
|
C_str_repr = lambda s: '"' + s.replace("\\", "\\\\").replace(r'"', r'\"') + '"'
|
||||||
|
|
||||||
CC = fetch("CC")
|
CC = fetch("CC")
|
||||||
|
|
||||||
|
CC_SEARCH_LIST = [
|
||||||
|
"gcc",
|
||||||
|
"clang",
|
||||||
|
"tcc"
|
||||||
|
]
|
||||||
|
if os_name == "nt":
|
||||||
|
CC_SEARCH_LIST = [
|
||||||
|
"msc",
|
||||||
|
*CC_SEARCH_LIST
|
||||||
|
]
|
||||||
|
|
||||||
CFLAGS = fetch("CFLAGS")
|
CFLAGS = fetch("CFLAGS")
|
||||||
INPUT_FILE = fetch("INPUT_FILE")
|
INPUT_FILE = fetch("INPUT_FILE")
|
||||||
OUTPUT_FILE = fetch("OUTPUT_FILE")
|
OUTPUT_FILE = fetch("OUTPUT_FILE")
|
||||||
@ -113,6 +126,9 @@ DEFAULT_ARGS = {
|
|||||||
"no_return": False
|
"no_return": False
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_cmd_available = lambda cmd: which(cmd) is not None
|
||||||
|
is_cmd_unavailable = lambda cmd: which(cmd) is None
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = ArgumentParser(description=\
|
parser = ArgumentParser(description=\
|
||||||
"Substitutes supplied C (non-JavaScript!) bytebeat into the template, "
|
"Substitutes supplied C (non-JavaScript!) bytebeat into the template, "
|
||||||
@ -333,10 +349,28 @@ if __name__ == "__main__":
|
|||||||
"ansi_escape_codes_supported": ansi_escape_codes_supported
|
"ansi_escape_codes_supported": ansi_escape_codes_supported
|
||||||
}, read_file(PATHS["template"]), args.show_substituted_values))
|
}, read_file(PATHS["template"]), args.show_substituted_values))
|
||||||
|
|
||||||
# Compile by invoking the shell script
|
if is_cmd_unavailable(CC):
|
||||||
|
print(f"Compiler {CC} not available, searching:")
|
||||||
|
|
||||||
|
still_unavailable = True
|
||||||
|
for compiler in CC_SEARCH_LIST:
|
||||||
|
print(f"* Trying CC={compiler}", end="")
|
||||||
|
if is_cmd_available(compiler):
|
||||||
|
print(": OK")
|
||||||
|
CC = compiler
|
||||||
|
still_unavailable = False
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print()
|
||||||
|
|
||||||
|
if still_unavailable:
|
||||||
|
print("Could not find an available compiler. Please specify it by "
|
||||||
|
"setting\nenvironmental variable CC.")
|
||||||
|
exit(2)
|
||||||
|
|
||||||
|
# Compile
|
||||||
print("Compiling")
|
print("Compiling")
|
||||||
|
|
||||||
# Let the system execute aliases by calling os.system
|
|
||||||
command = [
|
command = [
|
||||||
CC,
|
CC,
|
||||||
*command_line_split(CFLAGS),
|
*command_line_split(CFLAGS),
|
||||||
@ -346,4 +380,5 @@ if __name__ == "__main__":
|
|||||||
"-I" + PATHS["include_directory"]
|
"-I" + PATHS["include_directory"]
|
||||||
]
|
]
|
||||||
print(" ".join(command), flush=True)
|
print(" ".join(command), flush=True)
|
||||||
|
|
||||||
exit(subprocess.run(command).returncode)
|
exit(subprocess.run(command).returncode)
|
||||||
|
Loading…
Reference in New Issue
Block a user