Files

40 lines
2.2 KiB
Python

"""Build the headless DSView decoder worker against the prepared ARM runtime sysroot."""
import argparse
from pathlib import Path
import subprocess
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--cc', type=Path, required=True)
parser.add_argument('--sysroot', type=Path, required=True)
parser.add_argument('--dsview-source', type=Path, required=True)
parser.add_argument('--fallback-include', type=Path)
parser.add_argument('--output', type=Path, required=True)
args = parser.parse_args()
cc, sysroot, source, out = [p.resolve() for p in (args.cc, args.sysroot, args.dsview_source, args.output)]
out.mkdir(parents=True, exist_ok=True)
includes = [source/'common', source/'libsigrokdecode4DSL', sysroot/'usr/include/python3.11', sysroot/'usr/include/glib-2.0', sysroot/'usr/lib/arm-linux-gnueabihf/glib-2.0/include']
flags = [str(cc), '--sysroot='+str(sysroot), '-mcpu=cortex-a9', '-O2', '-std=c11', '-D_DEFAULT_SOURCE', '-pthread', '-isystem', str(sysroot/'usr/include/arm-linux-gnueabihf')]
if args.fallback_include:
flags += ['-idirafter', str(args.fallback_include.resolve())]
for path in includes:
flags += ['-I', str(path)]
objects = []
files = sorted((source/'libsigrokdecode4DSL').glob('*.c')) + [source/'common/log/xlog.c', Path(__file__).with_name('scope_decode.c')]
if len(files) < 10:
raise RuntimeError('Prepare the DSView fork sources and ARM sysroot first')
for path in files:
target = out/('decoder-'+path.stem+'.o')
subprocess.run(flags + ['-c', str(path), '-o', str(target)], check=True)
objects.append(str(target))
link = flags + objects
for path in (sysroot/'usr/lib/arm-linux-gnueabihf', sysroot/'lib/arm-linux-gnueabihf', sysroot/'usr/lib/gcc/arm-linux-gnueabihf/12'):
link += ['-B'+str(path)+'/', '-L'+str(path), '-Wl,-rpath-link,'+str(path)]
subprocess.run(link + ['-lglib-2.0', '-lpython3.11', '-lm', '-lpthread', '-o', str(out/'scope-decode-arm.elf')], check=True)
(out/'scope-decode').write_bytes(Path(__file__).with_name('scope-decode').read_bytes().replace(b'\r\n', b'\n'))
if __name__ == '__main__':
main()