function silverchain_generation()
    darwin.silverchain.generate({
        src = "src",
        tags = { "dep_declare", "macros", "types","consts", "fdeclare","globals", "dep_define","fdefine" },
        project_short_cut = "LuaCEmbed",
        implement_main = false
    })
end

function amalgamation_build()
    local MAX_CONNTENT = darwin.camalgamator.ONE_MB * 20
    local MAX_RECURSION = 100

    local lincense = "/* " .. darwin.dtw.load_file("LICENSE") .. " */ \n"

    local onefile = darwin.camalgamator.generate_amalgamation("src/one.c", MAX_CONNTENT, MAX_RECURSION)
    onefile = lincense .. onefile

    darwin.dtw.write_file("release/LuaCEmbedOne.c", onefile)

    local only_declare = darwin.camalgamator.generate_amalgamation("src/imports/imports.fdeclare.h", MAX_CONNTENT,
    MAX_RECURSION)
    only_declare = lincense .. only_declare
    darwin.dtw.write_file("release/LuaCEmbed.h", only_declare)


    local only_definition = darwin.camalgamator.generate_amalgamation_with_callback("src/imports/imports.fdefine.h",
        function(import, path)  
   
            
            if darwin.dtw.ends_with(import,"cJSON.h") then
                return "dont-include"
            end
            
            if darwin.dtw.ends_with(import,"CTextEngine.h") then
                return "dont-include"
            end

            if darwin.dtw.ends_with(import,"UniversalGarbage.h") then
                return "dont-include"
            end

            if darwin.dtw.ends_with(import,"UniversalSocket.h") then
                return "dont-include"
            end
            
            if darwin.dtw.ends_with(path,"imports.fdeclare.h") then
                    return "dont-include"
            end



            return "include-once"
        end,
        
        MAX_CONNTENT,
        MAX_RECURSION
    )

    only_definition = '#include "LuaCEmbed.h"\n' .. only_definition

    only_definition = lincense .. only_definition

    darwin.dtw.write_file("release/LuaCEmbed.c", only_definition)

    os.execute("zip -r release/LuaCEmbed.zip dependencies src build")

end

-- Recipe definitions
darwin.add_recipe({
    name = "silverchain",
    description = "Generate silverchain imports",
    outs = {"src/imports/"},
    inputs = {"src"},
    callback = silverchain_generation
})

darwin.add_recipe({
    name = "amalgamation",
    requires = {"silverchain"},
    description = "Make a single file amalgamation of the project",
    outs = {"release/LuaCEmbedOne.c", "release/LuaCEmbed.h", "release/LuaCEmbed.c", "release/LuaCEmbed.zip"},
    inputs = {"src", "dependencies", "LICENSE"},
    callback = amalgamation_build
})
