0
点赞
收藏
分享

微信扫一扫

waf 编译入门小练习


原始工程

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

目录结构为

Make编译工具对应的Makefile:

.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

添加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:

'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'

Rerence

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


举报

相关推荐

0 条评论