是否有工具可以帮助从make迁移到waf?

fre*_*ley 5 migration makefile waf

我正在寻找将大型项目从使用迁移make到使用waf.是否有任何工具可以在某种程度上帮助自动化过程?

cJ *_*oub 4

不,没有,但迁移并没有那么复杂。

如果您以前从未使用过 waf,请查看文件夹中的示例demos/c这是典型的示例),并消化waf 书籍

然后,从make到waf:

  • 在配置步骤中,由configure()函数具体化,实例化所需的高级工具,并在可能的情况下使用高级工具(例如check_cfg()handles pkg-config(1))定义与外部库的关系,或者回退到定义中{DEFINES,INCLUDE,LIB,...}_$LIBNAME,例如:
def configure(cfg):
    # I want to do C with any available compiler
    cfg.load("compiler_c") # will detect MSVC, GCC, or other common compilers

    # always include cwd
    cfg.env.INCLUDES += ['.']

    # I want to link all my programs with pthread
    cfg.env.LIB += ['pthread']

    # I want to link with static zlib
    cfg.env.STLIB_Z += ['z']

    # I want to use pkg-config to tell me how to link with pjsip
    # and avoid typing the risky -DPJ_AUTOCONF=1 -pipe -O2 -march=k8-sse3 -mcx16 -msahf -mno-movbe -mno-aes -mno-pclmul -mno-popcnt -mno-abm -mno-lwp -mno-fma -mno-fma4 -mno-xop -mno-bmi -mno-tbm -mno-avx -mno-sse4.2 -mno-sse4.1 --param l1-cache-size=64 l1-cache-line-size=64 l2-cache-size=512 -mtune=k8 -DPJ_IS_BIG_ENDIAN=0 -DPJ_IS_LITTLE_ENDIAN=1 -I/home/portage/tmp/net-libs-pjsip-1.12/image//usr/include  -L/home/portage/tmp/net-libs-pjsip-1.12/image//usr/lib -lpjsua -lpjsip-ua -lpjsip-simple -lpjsip -lpjmedia-codec -lpjmedia -lpjmedia-audiodev -lpjnath -lpjlib-util -lresample -lmilenage -lsrtp -lg7221codec -lpj -lm -luuid -lnsl -lrt -lpthread -lasound -lcrypto -lssl -lopencore-amrnb
    # the *_PJSIP variables will be created
    cfg.check_cfg(package='libpjproject',
                  uselib_store='PJSIP',
                  args='--libs --cflags',)
Run Code Online (Sandbox Code Playgroud)

*FLAGS尽可能避免使用,因为它们是特定于编译器的。

  • 用高级规则替换标准 makefile 规则(使用 中实例化的工具configure()),例如。
bld(target='mylib',
    features='c', # see note
    source=['a.c', 'b.c'],
    use=['Z', 'PJSIP'],
    )

bld(target='name',
    features='c cprogram',
    source=['main.c'],
    use=['mylib'],
    )
Run Code Online (Sandbox Code Playgroud)
  • 如果需要,可以创建非标准规则和高级工具,请参阅 waf 书籍

总体而言,构建脚本比 makefile 更短且更易于阅读。它们更加线性,并且内容更加语义化。

请注意,如果您不打算导出静态库,则无需创建它们waf工具不使用shell来调用程序,因此命令行长度限制(创建内部静态库的主要原因)不是问题。