This document is confirmed by waf-1.9.3.
Please cross-check with Original Document as there may be changes.
Summary about Waf, a build tool made by python
Waf defines a file called wscript and builds it.
Since the Japanese materials are solid, I think you should basically refer to the following pages. (Because it is translated by volunteers, isn't it the latest? * Confirmation required) The Waf Book
The original English materials are as follows. The Waf Book
merit
Demerit
Download the source from Official Site or Github.
Download executable binary directly
$ wget --no-check-certificate https://waf.io/waf-1.9.3 -O waf
Build from source
$ git clone https://github.com/waf-project/waf.git
$ cd waf
$ ./waf-light configure build
$ ls
build build_system_kit ChangeLog configure demos DEVEL docs playground README.md tests TODO utils waf waflib waf-light wscript zip
If you built from source, there is a demo in the repository. There are samples in various languages, so you can refer to them.
C language sample build test
$ cd demos
$ ls
asm bisonflex c c++ csharp d dbus fortran glib2 intltool java jni lua mac_app perl precious python qt5 ruby subst tex unit_test vala variants wscript
$ cd c
$ ../../waf configure build
Setting top to : /home/user/work/waf/demos/c
Setting out to : /home/user/work/waf/demos/c/build
Checking for 'gcc' (C compiler) : /usr/bin/gcc
Checking for code snippet : yes
Checking for code snippet : yes
Checking for code snippet : yes
Checking for libraries : yes
Checking for library m : yes
Checking for large file support : yes
Checking for inline : inline
Checking for endianness : little
Checking for headers in parallel : started
... testing an arbitrary build function : ok
... stdio : yes
... unistd : yes
... optional xyztabcd.h : no
... stdlib : aye
... malloc : yes
-> processing test results : 1 test failed
Checking for header stdio.h : yes
Checking for code snippet : yes
'configure' finished successfully (1.405s)
Waf: Entering directory `/home/user/work/waf/demos/c/build'
[ 1/16] Creating build/program/b.h
[ 2/16] Creating build/abc.h
[ 3/16] Creating build/stlib/foo.h
[ 4/16] Processing wscript
[ 5/16] Trying again wscript
-Lm -Lncurses -L../wscript ayedoh -Laaa -L/home/user/work/waf/demos/c/wscript
-Lm -Lncurses -L../wscript ayedoh -Laaa -L/home/user/work/waf/demos/c/wscript
[ 6/16] Compiling stlib/main.c
[ 7/16] Compiling program/main.c
[ 8/16] Compiling shlib/test_shlib.c
[ 9/16] Compiling shlib/main.c
[10/16] Compiling stlib/test_staticlib.c
[11/16] Linking build/program/myprogram
[12/16] Linking build/shlib/libmy_shared_lib.so
[13/16] Linking build/stlib/libmy_static_lib.a
[14/16] Linking build/shlib/test_shared_link
[15/16] Linking build/stlib/test_static_link
[16/16] Symlinking build/shlib/libmy_shared_lib.so
Waf: Leaving directory `/home/user/work/waf/demos/c/build'
'build' finished successfully (1.162s)
wscript implementation procedurewaf defines the functions in wscript as * waf commands *.
As an example, the waf command hello is defined below.
sample
#! /usr/bin/env python
# encoding: utf-8
def hello(ctx):
print('hello world')
Execute waf command hello
$ ./waf hello
hello world
'hello' finished successfully (0.001s)
By specifying hello as the execution command of waf, you can see that the command is being executed.
See below in the original document The Waf Book
main.cpp
#include <iostream>
int main(int argc, char const* argv[])
{
std::cout << "hoge" << std::endl;
return 0;
}
C++Build the project
#! /usr/bin/env python
# encoding: utf-8
def options(opt):
opt.load('compiler_cxx')
def configure(conf):
conf.load('compiler_cxx')
def build(bld):
bld.program(source='main.cpp', target='app')
Build and execution results
$ ./waf configure build
Setting top to : /home/user/work/test
Setting out to : /home/user/work/test/build
Checking for 'g++' (C++ compiler) : /usr/bin/g++
'configure' finished successfully (0.051s)
Waf: Entering directory `/home/user/work/test/build'
Waf: Leaving directory `/home/user/work/test/build'
'build' finished successfully (0.003s)
$ ./build/app
hoge
For other details (include, build shared library, etc.), please refer to the original document. The Waf Book
TODO: Add if you have time
It seems that cross-build can be supported by changing the environment variable.
The Waf Book Re: [waf-users 4515] Cross-compiling QNX using qcc --Google Groups
Waf: the meta build system Introduction of waf --Mackey's Lab
The following is Japanese material, but please note that the content is out of date (2010 & 2011 article) The Waf Book waf tutorial --Pure functional miscellaneous notes
Recommended Posts