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

Make replacement #972

Closed
tim-lebedkov opened this issue Sep 24, 2020 · 5 comments
Closed

Make replacement #972

tim-lebedkov opened this issue Sep 24, 2020 · 5 comments
Milestone

Comments

@tim-lebedkov
Copy link

Is your feature request related to a problem? Please describe.

xmake is a good replacement for CMake, but it is not a good replacement for make. As far as I understand it lacks the simple file dependencies like

a.msi: a.exe
   create-msi.exe a.exe

Describe the solution you'd like

Top level rule for a file with dependencies on other files, tasks, targets, e.g.:

add_file_target("a.msi", ["a.exe"], function() {
execute_program("create-msi.exe", ["a.exe"]);
})

Describe alternatives you've considered

Using make

Additional context

@waruqi
Copy link
Member

waruqi commented Sep 25, 2020

You need only call os.exec to do it in after_build().

target("a")
    set_kind("binary")
    add_files("src/*.c")
    after_build(function (target)
        os.execv("create-msi.exe", {target:targetfile()})
        -- or
        --  os.exec("create-msi.exe %s", target:targetfile())
    end)

As far as I understand it lacks the simple file dependencies like

You can also define a dependent phony target to do it.

target("a")
    set_kind("binary")
    add_files("src/*.c")

target("msi")
    set_kind("phony")
    add_deps("a") -- add dependences
    on_build(function (target)
        os.execv("create-msi.exe", {target:dep("a"):targetfile()})
    end)

Or you can also define a custom rule to do it.

-- define a custom msi rule
rule("msi")
    after_build(function (target)
        os.execv("create-msi.exe", {target:targetfile()})
    end)

target("a")
    set_kind("binary")
    add_files("src/*.c")
    add_rules("msi") --- apply msi rule to this target

And we can also add dependencies for multiple rules through add_deps()

rule("x")
    -- ...

rule("y")
    add_deps("x")
    -- ..

target("a")
    add_rules("y") -- it will apply rules: x and y

Using make

xmake does not rely on make, but it can also generate makefiles.

xmake project -k makefile

@tim-lebedkov
Copy link
Author

What is obviously missing is the check that a.msi is up-to-date and also if this get more complicated. Basically a Makefile is a DAG where edges should be ordered according to the dependencies.

@waruqi
Copy link
Member

waruqi commented Sep 25, 2020

What is obviously missing is the check that a.msi is up-to-date and also if this get more complicated. Basically a Makefile is a DAG where edges should be ordered according to the dependencies.

You can add a check through os.mtime/io.load/io.save ...

if not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile), values = depvalues}) then

@tim-lebedkov
Copy link
Author

Yes, I could do this. Lua is a programming language and allows everything. But this is a feature request for something that is easily done in make, but not in xmake.

@waruqi
Copy link
Member

waruqi commented Oct 5, 2020

I added depend.on_changed() to simplify adding dependent files on dev branch. xmake update dev

    after_build(function (target)
        import("core.project.depend")
        depend.on_changed(function ()
            os.execv("create-msi.exe", {target:targetfile()})
        end, {files = target:targetfile()})
    end)

@waruqi waruqi added this to the v2.3.8 milestone Oct 6, 2020
@waruqi waruqi closed this as completed Oct 12, 2020
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

2 participants