1
0

bytebeat_compiler.py: search for compiler, fix section names

and reformat
This commit is contained in:
Intel A80486DX2-66 2024-06-02 19:34:49 +03:00
parent f48d603cc4
commit bae2bb6e18
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -4,9 +4,10 @@ if __name__ == "__main__":
print(":: C bytebeat generator: compiler unit")
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 shlex import split as command_line_split
from shutil import which
from sys import stdin, stdout, exit
from typing import Dict, Union
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'\"') + '"'
CC = fetch("CC")
CC_SEARCH_LIST = [
"gcc",
"clang",
"tcc"
]
if os_name == "nt":
CC_SEARCH_LIST = [
"msc",
*CC_SEARCH_LIST
]
CFLAGS = fetch("CFLAGS")
INPUT_FILE = fetch("INPUT_FILE")
OUTPUT_FILE = fetch("OUTPUT_FILE")
if extra := fetch("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__":
parser = ArgumentParser(description=\
"Substitutes supplied C (non-JavaScript!) bytebeat into the template, "
@ -238,10 +254,28 @@ if __name__ == "__main__":
"ansi_escape_codes_supported": ansi_escape_codes_supported
}, 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")
# Let the system execute aliases by calling os.system
command = [
CC,
*command_line_split(CFLAGS),
@ -251,4 +285,5 @@ if __name__ == "__main__":
"-I" + PATHS["include_directory"]
]
print(" ".join(command), flush=True)
exit(subprocess.run(command).returncode)