#!/usr/bin/env python3

import argparse
import sys
import os

our_version = 17


def do_version():
    return '{}.0.6'.format(our_version)


def do_components():
    return 'aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils aggressiveinstcombine all all-targets amdgpu amdgpuasmparser amdgpucodegen amdgpudesc amdgpudisassembler amdgpuinfo amdgputargetmca amdgpuutils analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter avr avrasmparser avrcodegen avrdesc avrdisassembler avrinfo binaryformat bitreader bitstreamreader bitwriter bpf bpfasmparser bpfcodegen bpfdesc bpfdisassembler bpfinfo cfguard codegen codegentypes core coroutines coverage debuginfobtf debuginfocodeview debuginfodwarf debuginfogsym debuginfologicalview debuginfomsf debuginfopdb demangle dlltooldriver dwarflinker dwarflinkerparallel dwp engine executionengine extensions filecheck frontendhlsl frontendopenacc frontendopenmp fuzzercli fuzzmutate globalisel hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interfacestub interpreter ipo irprinter irreader jitlink lanai lanaiasmparser lanaicodegen lanaidesc lanaidisassembler lanaiinfo libdriver lineeditor linker loongarch loongarchasmparser loongarchcodegen loongarchdesc loongarchdisassembler loongarchinfo lto mc mca mcdisassembler mcjit mcparser mips mipsasmparser mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmparser msp430codegen msp430desc msp430disassembler msp430info native nativecodegen nvptx nvptxcodegen nvptxdesc nvptxinfo objcarcopts objcopy object objectyaml option orcjit orcshared orctargetprocess passes powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo riscvtargetmca runtimedyld scalaropts selectiondag sparc sparcasmparser sparccodegen sparcdesc sparcdisassembler sparcinfo support symbolize systemz systemzasmparser systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target targetparser textapi transformutils ve veasmparser vecodegen vectorize vedesc vedisassembler veinfo webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo webassemblyutils windowsdriver windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info x86targetmca xcore xcorecodegen xcoredesc xcoredisassembler xcoreinfo xray'


def do_targets_built():
    return 'AArch64 AMDGPU ARM AVR BPF Hexagon Lanai LoongArch Mips MSP430 NVPTX PowerPC RISCV Sparc SystemZ VE WebAssembly X86 XCore'


def get_includedir():
    return '/sysroot/usr/include'


def get_libdir():
    return '/sysroot/usr/lib'


def do_has_rtti():
    return 'YES'


def do_shared_mode():
    return 'shared'


def do_libs():
    return f'-lLLVM-{our_version}'


def do_system_libs():
    return f'-lLLVM-{our_version}'


def do_cppflags():
    return ''


def do_cxxflags():
    return ''


def do_ldflags():
    return '-L' + get_libdir()


parser = argparse.ArgumentParser()
parser.add_argument('--version', action='append_const',
                    dest='command', const=do_version)
parser.add_argument('--targets-built', action='append_const',
                    dest='command', const=do_targets_built)
parser.add_argument('--components', action='append_const',
                    dest='command', const=do_components)
parser.add_argument('--includedir', action='append_const',
                    dest='command', const=get_includedir)
parser.add_argument('--libdir', action='append_const',
                    dest='command', const=get_libdir)
parser.add_argument('--has-rtti', action='append_const',
                    dest='command', const=do_has_rtti)
parser.add_argument('--shared-mode', action='append_const',
                    dest='command', const=do_shared_mode)
parser.add_argument('--link-shared', action='store_const',
                    dest='link', const='shared')
parser.add_argument('--cppflags', action='append_const',
                    dest='command', const=do_cppflags)
parser.add_argument('--cxxflags', action='append_const',
                    dest='command', const=do_cxxflags)
parser.add_argument('--ldflags', action='append_const',
                    dest='command', const=do_ldflags)
parser.add_argument('--libs', action='append_const',
                    dest='command', const=do_libs)
parser.add_argument('--system-libs', action='append_const',
                    dest='command', const=do_system_libs)
parser.add_argument('components', type=str, nargs='*')

print("cross-llvm-config:", sys.argv, file=sys.stderr)

args = parser.parse_args()
for command in args.command:
    result = command()
    print("cross-llvm-config yields:", result, file=sys.stderr)
    print(result)
