如何通过预制生成假目标?

How to generate phony target by premake?

我用premake有一段时间了。当我必须 运行 小脚本或一些似乎与构建阶段无关的东西(例如调试、打包、为外部库构建等...)时,我只是使用 Makefile 项目来实现,如下所示

    -- [[ 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"
    }

我意识到这种做法非常混乱,因为它没有将真正的构建 Makefile 与虚假目标分开,甚至为构建生成不必要的 Makefile。所以,我想弄清楚通过预制生成虚假目标。

我考虑过 newaction 语法,但我发现它只是 make target for premake script 而不是 Makefile target。

有什么最佳实践或方法可以通过 premake 生成假目标吗?

目前 Premake 不支持创建任意虚假目标(尽管您可以submit a feature request or tackle it yourself and create a pull request)。

但是你可以使用 Premake 本身来运行你的命令。这是一个创建名为 "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
}

添加到您的项目脚本后,您可以这样调用它:

$ premake5 integrate