bytebeat_compiler.py: search for compiler, fix section names
and reformat
This commit is contained in:
parent
81bb2e80b4
commit
31244bd18d
@ -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 subprocess
|
import subprocess
|
||||||
@ -86,12 +87,27 @@ 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")
|
||||||
if extra := fetch("CFLAGS_EXTRA"):
|
if extra := fetch("CFLAGS_EXTRA"):
|
||||||
CFLAGS += " " + extra
|
CFLAGS += " " + extra
|
||||||
|
|
||||||
|
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, "
|
||||||
@ -238,10 +254,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),
|
||||||
@ -251,4 +285,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