代码之家  ›  专栏  ›  技术社区  ›  Michael Kuhn

如何生成复杂的Makefile,例如从模板生成

  •  1
  • Michael Kuhn  · 技术社区  · 16 年前

    Makefile真的很有用。但是,语法有点复杂和有限。对于一个项目,我需要创建目标1到n,我真的很想写这样的东西:

    all : target1 ... target100
    
    target%d : target%d.pre
        ./script.py %d
    

    我想要 make %d )然后在整个规则中使用它。我可以想象,通过复杂地使用模式(%.xyz)和 patsubst

    Cheetah

    2 回复  |  直到 16 年前
        1
  •  0
  •   anon anon    16 年前

    你一定要看看 CMake ,它可以为您生成所有makefile。

        2
  •  0
  •   Michael Kuhn    16 年前

    正如beta在评论中指出的那样,第二部分实际上是通过以下方式解决的

    target% : target%d.pre
        ./script.py %d
    

    鉴于上述情况,第一部分可以通过以下方式解决:

    files := $(shell for i in `seq 1 100`; do echo target$$i; done)
    
    all : $(files)