WAF is one among the various popular automation tools like Apache Ant, Bazel, CMake, and Make. Automation tools are used to facilitate the compilation and installation of an application/software/package in a system. The importance of automation can be best explained through an imaginary situation like 100 coded files required to be compiled to complete the installation of an application. It may be easy to compile these 100 files manually, but it won’t be easy to recompile these 100 files again, if any changes have been effected on any of these files. In any automation tool, there will be a new file created for managing the compilation and installation of the application, which we called as executable file or binary file. We already know about the executable files with extension like .exe in windows and .elf in Linux.
WAF is developed using the language Python. Thomas Nagy, the developer published it as open source software and also released the source code using new BSD licence. The documentation related to WAF is also published but it prohibits commercial reuse and modification. The installation of WAF is quick and simple and you can get the source file from the WAF official page. Although, it is easy to install using executable files, don’t forget to setup the environment variables accordingly.
In order to elaborate the working of WAF, let us consider a common scenario of GCC compiler. There are three files to be compiled before the installation of an application. The files include car.c, which is the main function and the two sub functions are blue.c and red.c.
Car.c :
#include <stdio.h>
// Function declarations
void red();
void blue();
// Function definition for ‘red’
void red()
{
printf(“The car is painted red.\n”);
}
// Function definition for ‘blue’
void blue()
{
printf(“Now the car is painted blue.\n”);
}
// Function definition for ‘car’
int car()
{
// Call the ‘red’ function
red();
// Call the ‘blue’ function
blue();
// Return 0 to indicate successful execution
return 0;
}
// Main function
int main()
{
// Call the ‘car’ function
car();
// Return 0 to indicate successful execution
return 0;
}
Red.c :
#include <stdio.h>
void red()
{
printf (“I Have a red benz car”);
}
Blue.c :
#include <stdio.h>
void blue()
{
Printf (“ I have a blue Royal Enfield bike”);
}
Now these three files can be compiled using GCC as follows by creating object code before generating executable file.
gcc –c car.c
gcc –c red.c
gcc –c blue.c
gcc car.o red.o blue.o –o vehicle
Here it is simple as there are only three files, but consider the case of 100. With 100 files this compilation process will be very difficult. The same above thing can be built in WAF as follows:
top = ‘.’ # Working directory (current directory)
out = ‘.’ # Output directory
def options(op):
op.load(‘compiler_c’)
def configure(co):
co.load(‘compiler_c’)
def build(bl):
# Build the ‘vehicle’ executable using ‘car.c’, ‘red.c’, and ‘blue.c’
bl.program(source=’car.c’, target=’vehicle’, use=’red blue’)
# Build object files for ‘red.c’ and ‘blue.c’
bl.objects(source=’red.c’, target=’red’)
bl.objects(source=’blue.c’, target=’blue’)
All the above compilation purpose can be integrated in a single WAF file, which should be saved with the file name wscript. Now, execute the below command to run the application
bash
./waf configure
./waf build
In simple words, WAF will recompile files that have made modifications and not the entire files. But remember, options are available to compile all these source files forcefully.