import subprocess

output    = "il"
src_dir   = "#src"
inputs    = "*.c util/windows.c"

Import("build_dir")
Import("platform")
Import("env")

il = env.Clone()

libs = {
    "osx":   ["dl"],
    "mingw": ["mingw32", "lua51"],
    "arch":  ["dl"],
    "linux": ["dl"]
}

pkg_libs = {
    "osx":   ["luajit"],
    "arch":  ["luajit"],
    "linux": ["luajit"],
    "mingw": []
}

il.Append(CPPPATH = src_dir)
il.Append(LIBS = libs[platform])
for lib in pkg_libs[platform]:
    il.ParseConfig("pkg-config " + lib + " --cflags --libs")

sources = []
for module in Split(inputs):
    sources.extend(Glob(module))

# generate version information
handle = open("version.h", "w")
handle.write("// This file was generated by SConstruct. Do not modify. Create a tag if you wish to increment the version.\n\n")
handle.write("static const char *il_version = \"")
handle.write(subprocess.check_output(["git", "describe", "--dirty", "--always", "--tags"]).rstrip())
handle.write("\";\n")
handle.close()

ilp = il.Program(target = build_dir + "/" + output,
                 source = sources)

Return("ilp")

