如何通过premake生成假目标?

时间:2017-03-15 00:43:31

标签: makefile build 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。所以,我想弄清楚通过premake生成假目标。

我考虑了newaction语法,但我发现它只是为premake脚本而不是Makefile目标制作目标。

是否有通过预制生成虚假目标的最佳实践或方法?

1 个答案:

答案 0 :(得分:0)

Premake目前不支持创建任意虚假目标(尽管您可以submit a feature request或自己处理并create a pull request)。

可以使用Premake本身为您运行命令。这是一个简单的例子,它创建了一个名为" integration":

的新动作
i = 2

For Each c In Range("D2", Range("D" & Rows.Count).End(xlUp))
    CB_Account.AddItem Cells(i, 3).Value
    CB_Account.AddItem Cells(i, 4).Value
    i = i + 1

Next

添加到项目脚本后,您可以将其命名为:

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
}