How to generate phony target by premake?

I have been used premake for a while. When I have to run small script or something which seems to be unrelated to build phase(eg debug, packaging, build for external libraries etc...), I just used Makefile project for that like below

    -- [[ X. External Makefile libraries ]]
project "external"
    kind "Makefile"
    location "build"

    buildcommands {
        "cd ..; make -f Makefile" 
    }

    cleancommands {
        "cd ..; make -f Makefile clean" 
    }

-- [[ X+1. Integration ]]
project "integration"
    kind "Makefile"
    location "build"

    buildcommands {
        -- PacketNgin Application Library
        "ar x ../libc.a",
        "ar x ../libm.a",
        "ar x ../libtlsf.a",
        "ar x ../libcore.a",
        "ar x ../libexpat.a",
        "ar rcs ../libpacketngin.a *.o",

    "cp -rL ../core/include/* ../../include",
    "cp -rL ../expat/include/* ../../include",
    "cp -rL ../openssl/include/* ../../include",
    "cp -rL ../zlib/*.h ../../include",

        "rm ./*.o -rf",

        -- Linux Application library
        "ar x ../libtlsf.a ",       -- Blank is added at the end on purpose
        "ar x ../libcore_linux.a",
        "ar rcs ../libumpn.a *.o",
        "rm ./*.o -rf ",            -- Blank is added at the end on purpose
    }

    cleancommands {
        "rm *.o -rf",
        "rm ../*.a -rf"
    }

I realize this practice is very confused since it does not separates real build Makefile from just phony targets, even make unecessary Makefiles for build. So, I want to figure out generate phony target by premake.

I considered newaction syntax but I found it just make target for premake script rather than Makefile target.

Is there any best practice or way to generate phony target by premake?


Creating arbitrary phony targets is not supported by Premake at this time (though you can submit a feature request or tackle it yourself and create a pull request).

But you could use Premake itself to run the commands for you. Here's a simple example that creates a new action called "integrate":

function executeAll(commands)
    for _, command in ipairs(commands) do
        os.execute(command)
    end
end

newaction
{
    trigger = "integrate",
    description = "Run integration steps",
    execute = function ()
        executeAll {
            "ar x ../libc.a",
            "ar x ../libm.a",
            "ar x ../libtlsf.a",
            "ar x ../libcore.a",
            "ar x ../libexpat.a",
            "ar rcs ../libpacketngin.a *.o",
            -- and so on...
        }
    end
}

Once added to your project script, you can call it like:

$ premake5 integrate
链接地址: http://www.djcxy.com/p/64128.html

上一篇: GNU Linux Makefile PHONY目标依赖不能正常工作

下一篇: 如何通过预制产生假目标?