set_project("m4kc")


KOS_SDK = "/projects/kos/contrib/sdk"
KOS_GCC = "/home/autobuild/tools/win32"


toolchain("kos-gcc")

    set_toolset("cc",      KOS_GCC .. "/bin/kos32-gcc")
    set_toolset("ld",      KOS_GCC .. "/bin/kos32-ld")
    set_toolset("objcopy", KOS_GCC .. "/bin/kos32-objcopy")
    
    add_cflags("-fno-ident -O3 -fomit-frame-pointer -fno-ident -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32 -D_KOLIBRI -DNO_ZIP -DPERFORMANCE -DMINIZ_NO_TIME")
    add_ldflags("-static -S -nostdlib -T " .. KOS_SDK .. "/sources/newlib/app.lds --image-base 0 --subsystem native")

toolchain_end()


target("m4kc-kolibri")
    
    set_arch("i386")
    set_plat("cross")
    set_kind("binary")
    set_toolchains("kos-gcc")

    add_defines("_KOLIBRI")

    add_includedirs(KOS_SDK .. "/sources/SDL2-2.30.6/include")
    add_includedirs(KOS_SDK .. "/sources/newlib/libc/include")
    add_includedirs(KOS_SDK .. "/sources/newlib/libc/include/sys")
    add_includedirs("src", {public = true})
    
    add_files("src/*.c")

    add_linkdirs(KOS_SDK .. "/lib")
    add_linkdirs(KOS_GCC .. "/mingw32/lib")

    add_links("SDL2", "gcc", "c.dll", "c", "sound")

    after_link(function (target)
        os.vrunv("objcopy", {target:targetfile(), "-O", "binary"})
    end)

target_end()


target("m4kc-linux")
    
    set_arch("x86_64")
    set_plat("linux")
    set_kind("binary")

    add_includedirs("src", {public = true})
    
    add_files("src/*.c")

    add_links("SDL2")

    set_optimize("fastest")

target_end()


target("m4kc-windows")
    
    set_kind("binary")
    set_toolchains("@tinycc")

    add_includedirs("../TCC/include/")
    add_includedirs("src", {public = true})

    add_files("src/*.c")

    add_linkdirs("./")
    
    add_links("SDL2")

    set_optimize("fastest")

target_end()


add_rules("mode.debug", "mode.release")
