waf 编译入门小练习

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/theArcticOcean/article/details/80714375

原始工程

源码在:https://github.com/theArcticOcean/CLib/tree/master/myLocker

目录结构为

Make编译工具对应的Makefile:


DEPEND = pthTextCode.o main.o public.o pthTextRW.o pthLocker.o

LIB = -lpthread

CFLAGS = -gdwarf-2 -DDEBUG

CC = /usr/bin/gcc

locker: $(DEPEND)

    $(CC) $(DEPEND) $(LIB) $(CFLAGS) -o locker

pthTextCode.o: pthTextCode.c

    $(CC) -c pthTextCode.c $(CFLAGS) -o pthTextCode.o

public.o: public.c

    $(CC) -c public.c $(CFLAGS) -o public.o

pthTextRW.o: pthTextRW.c

    $(CC) -c pthTextRW.c $(CFLAGS) -o pthTextRW.o

pthLocker.o: pthLocker.c

    $(CC) -c pthLocker.c $(CFLAGS) -o pthLocker.o

main.o: main.c

    $(CC) -c main.c $(CFLAGS) -o main.o



.PHONY: clean cleanAll

clean:

    rm -f *.o

cleanAll:

    rm -f *.o locker

添加wscript

参考教程:https://waf.io/book/#_common_declaration_for_c_c_fortran_and_d_applications

首先将waf脚本放进工程文件夹,然后编写wscript。

waf编译体系将生成可执行文件的整个过程拆解成各个task。为此,我们需要在wscript中编写task generator object。

#! /usr/bin/env python
# encoding: utf-8

def options(opt):
    opt.load( 'compiler_c' )

def configure(conf):
    conf.load( 'compiler_c' )

def build(bld):
    bld.program(
        source=[
            'main.c',
            'number.c',
            'pthLocker.c',
            'pthTextCode.c',
            'pthTextRW.c'
            ],

        includes='./',
        lib='pthread',
        libpath='/usr/lib',
        target='Locker',
        cflags=[
            '-gdwarf-2',
            '-DDEBUG'
            ],
        install_path='./'
    )

build the project:


➜ myLocker ./waf configure build

Setting top to : /Users/weiyang/code/myLocker

Setting out to : /Users/weiyang/code/myLocker/build

Checking for 'clang' (C compiler) : /usr/bin/clang

'configure' finished successfully (0.118s)

Waf: Entering directory `/Users/weiyang/code/myLocker/build'

[1/6] Compiling pthLocker.c

[2/6] Compiling main.c

[3/6] Compiling number.c

[4/6] Compiling pthTextRW.c

[5/6] Compiling pthTextCode.c

[6/6] Linking build/Locker

Waf: Leaving directory `/Users/weiyang/code/myLocker/build'

'build' finished successfully (0.206s)

Rerence

waf book
https://waf.io/book/
API
https://waf.io/apidocs/
waf tool
https://pythonhosted.org/waftools/overview.html

阅读更多

没有更多推荐了,返回首页