Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom build rules in xmake.lua #149

Closed
waruqi opened this issue Nov 10, 2017 · 1 comment
Closed

Add custom build rules in xmake.lua #149

waruqi opened this issue Nov 10, 2017 · 1 comment
Milestone

Comments

@waruqi
Copy link
Member

waruqi commented Nov 10, 2017

-- define rule: markdown
rule("markdown")
    set_extensions(".md", ".markdown")
    on_build(function (target, sourcefile)
        os.cp(sourcefile, path.join(target:targetdir(), path.basename(sourcefile) .. ".html"))
    end)

-- define rule: man
rule("man")
    add_imports("core.project.rule")
    on_build(function (target, sourcefile)
        rule.build("markdown", target, sourcefile)
    end)

-- define rule: c code
rule("c code")
    add_imports("core.tool.compiler")
    on_build(function (target, sourcefile)
        local objectfile = os.tmpfile() .. ".o"
        compiler.compile(sourcefile, objectfile, {sourcekind = "cc"})
        table.insert(target:objectfiles(), objectfile)
    end)

-- define rule: stub
rule("stub")
    on_build(function (target, sourcefile)
        print("on_build: %s", sourcefile)
    end)
    on_clean(function (target, sourcefile)
        print("on_clean: %s", sourcefile)
    end)
    on_install(function (target, sourcefile)
        print("on_install: %s", sourcefile)
    end)
    on_uninstall(function (target, sourcefile)
        print("on_uninstall: %s", sourcefile)
    end)
    on_package(function (target, sourcefile)
        print("on_package: %s", sourcefile)
    end)

-- define target
target("test")

    -- set kind
    set_kind("binary")

    -- add rules
    add_rules("markdown")

    -- add files
    add_files("src/*.c") 
    add_files("src/man/*.in",   {rule = "man"})
    add_files("src/index.md")
    add_files("src/test.c.in",  {rule = "c code"})
    add_files("src/empty.stub", {rule = "stub"})
@waruqi
Copy link
Member Author

waruqi commented Apr 14, 2018

#167

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant