#!/Users/runner/miniforge3/conda-bld/triqs_1775135874055/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pla/bin/python3.14
import os, sys, argparse
from cpp2cxx import Cpp2Cxx
import cpp2py.libclang_config as config

#
print("Welcome to C++2cxx")

# --- Parsing the arguments of the script and options

parser = argparse.ArgumentParser(description="""
Generate the C++/Python wrapper desc file from C++ header code
""")

parser.add_argument('filename', help = "Name of the file to parse")
parser.add_argument('--outputname', '-o',  help="Name of the xxx_desc.py file [default is same as the filename]", default = '')
parser.add_argument('--libclang_location', help='Location of the libclang', default = config.LIBCLANG_LOCATION)
parser.add_argument('--includes', '-I', action='append',  help='Includes to pass to clang')
parser.add_argument('--system_includes', '-isystem', action='append',  help='System includes to pass to clang')
parser.add_argument('--namespace', '-N', action='append',  help='namespaces to document', default= []) #specify which namespaces to document, e.g. -N triqs -N applications
parser.add_argument('--cxxflags', default = '', help='Options to pass to clang')
parser.add_argument('--target_file_only', action='store_true', help='Disable recursion into included header files')

args = parser.parse_args()

# Add the environment variables
cxx_env = os.getenv('CXXFLAGS').split() if os.getenv('CXXFLAGS') else []

# ---------------------------------------------------------
# Create the worker. It parses the file
W= Cpp2Cxx(filename = args.filename,
            namespaces= args.namespace,
            includes = args.includes or (),
            system_includes = args.system_includes or (),
            compiler_options = args.cxxflags.split(' ') + cxx_env,
            libclang_location = args.libclang_location,
            target_file_only = args.target_file_only
            )

filename_1 = os.path.split(args.filename)[1].split('.',1)[0]

# Make the desc file
W.run(output_filename = (args.outputname or filename_1) + ".cxx")
