Waf is a build automation tool written by Python and designed to assist in the automatic compilation and installation of computer software. You can learn about it at waf tutorial.
Let’s use it to build project.

Project

I wrote a CPlusPlus project and push it to GitHub, https://github.com/theArcticOcean/CLib/tree/master/myLocker.
The file structure looks like this image.

The Makefile for make has the following contents.

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

Add Wscript

The refrence tutorial: https://waf.io/book/#_common_declaration_for_c_c_fortran_and_d_applications
Put the waf script under project folder and write wscript.
The waf build system will split the whole process to multible tasks. Write task generator object in wscript.

#! /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 git:(master) ./waf configure build
Setting top to                           : /var/www/html/projects/CLib/myLocker 
Setting out to                           : /var/www/html/projects/CLib/myLocker/build 
Checking for 'gcc' (C compiler)          : /usr/bin/gcc 
'configure' finished successfully (0.076s)
Waf: Entering directory `/var/www/html/projects/CLib/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 `/var/www/html/projects/CLib/myLocker/build'
'build' finished successfully (0.136s)

Rerence

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

Categories: PythonTool

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Content Summary
: Input your strings, the tool can get a brief summary of the content for you.

X
0
Would love your thoughts, please comment.x
()
x