Import('env')

templates = Glob('templates/*')
sympy_helpers = "helpers/sympy_helpers.py"
ekf_sym = "helpers/ekf_sym.py"

to_build = {
    'pos_computer_4': 'helpers/lst_sq_computer.py',
    'pos_computer_5': 'helpers/lst_sq_computer.py',
    'feature_handler_5': 'helpers/feature_handler.py',
    'car': 'models/car_kf.py',
    'gnss': 'models/gnss_kf.py',
    'loc_4': 'models/loc_kf.py',
    'live': 'models/live_kf.py',
    'lane': '#xx/pipeline/lib/ekf/lane_kf.py',
}

found = {}

for target, command in to_build.items():
    if File(command).exists():
        found[target] = command

for target, command in found.items():
    target_files = File([f'generated/{target}.cpp', f'generated/{target}.h'])
    command_file = File(command)
    env.Command(target_files,
                [templates, command_file, sympy_helpers, ekf_sym],
                command_file.get_abspath()+" "+target
    )

    env.SharedLibrary('generated/' + target, target_files[0])
