【问题标题】:How to generate phony target by premake?如何通过预制生成虚假目标?
【发布时间】:2017-03-15 00:43:30
【问题描述】:

我已经使用 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 语法,但我发现它只是为 premake 脚本制作目标而不是 Makefile 目标。

是否有任何最佳实践或方法可以通过 premake 生成虚假目标?

【问题讨论】:

    标签: makefile build premake


    【解决方案1】:

    Premake 目前不支持创建任意虚假目标(尽管您可以submit a feature request 或自己解决它和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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-24
      • 2013-03-11
      • 2015-09-29
      • 1970-01-01
      • 2017-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多