Switch from using iconv to portable Python script

This commit is contained in:
Kieron 2023-11-10 17:19:49 +00:00
parent 5b346bad29
commit 4cd11062a4
3 changed files with 22 additions and 3 deletions

View File

@ -168,7 +168,7 @@ includes = "-I " + args.psyq_path + "/psyq_4.4/INCLUDE" + " -I $src_dir"
ninja.rule("psyq_c_preprocess_44", "$psyq_c_preprocessor_44_exe -undef -D__GNUC__=2 -D__OPTIMIZE__ " + includes + " -lang-c -Dmips -D__mips__ -D__mips -Dpsx -D__psx__ -D__psx -D_PSYQ -D__EXTENSIONS__ -D_MIPSEL -D__CHAR_UNSIGNED__ -D_LANGUAGE_C -DLANGUAGE_C $in $out", "Preprocess $in -> $out")
ninja.newline()
ninja.rule("convert_c_encoding", "iconv -f UTF8 -t EUCJP < $in > $out", "Convert $in from UTF-8 to EUC-JP")
ninja.rule("convert_c_encoding", f"{sys.executable} $src_dir/../build/convjp.py $in $out", "Convert $in from UTF-8 to EUC-JP")
ninja.newline()
# generate header deps, adds edges to the build graph for the next build -M option will write header deps

19
build/convjp.py Normal file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env python3
# A tool to convert a UTF-8 input into EUC-JP.
# This allows us to use Japanese string literals
# when saving source files as UTF-8.
import sys
def main(src, dst):
with open(src, 'r', encoding='utf8') as inf:
contents = inf.read()
with open(dst, 'w', encoding='eucjp') as outf:
outf.write(contents)
if __name__ == '__main__':
src = sys.argv[1]
dst = sys.argv[2]
main(src, dst)

View File

@ -21,7 +21,7 @@ ADDR_SUFFIX_RE = r'_([0-9A-F]{8})\.'
TMP_DIR = 'include_asm_tmp'
def main(path, output):
with open(path) as f:
with open(path, encoding='utf8') as f:
lines = f.readlines()
processed = []
@ -81,7 +81,7 @@ def main(path, output):
processed.append(func)
depends.append(include_path.replace('.s', '.obj').replace('asm/', 'obj/'))
with open(output, 'w') as f:
with open(output, 'w', encoding='utf8') as f:
f.write(''.join(processed))
with open(output + '.deps', 'w') as f: