idbrii
idbrii

Reputation: 11916

How do I write a waf file for a custom compiler?

I got sick of looking up the magic symbols in make and decided to try waf.

I'm trying to use calibre to make ebooks and I'd like to create a wscript that takes in a file, runs a program with some arguments that include that file, and produces an output. Waf should only build if the input file is newer than the output.

In make, I'd write a makefile like this:

%.epub: %.recipe
    ebook-convert $ .epub --test -vv --debug-pipeline debug

Where % is a magic symbol for the basename of the file and $ a symbol for the output filename (basename.epub).

I could call make soverflow.epub and it would run ebook-convert on soverflow.recipe. If the .recipe hadn't changed since the last build, it wouldn't do anything.

How can I do something similar in waf?

(Why waf? Because it uses a real language that I already know. If this is really easy to use in scons, that's a good answer too.)

Upvotes: 1

Views: 1458

Answers (1)

idbrii
idbrii

Reputation: 11916

I figured out how to make a basic wscript file, but I don't know how to build targets specified on the command-line.


The Waf Book has a section on Task generators. The Name and extension-based file processing section gives an example for lua that I adapted:

from waflib import TaskGen
TaskGen.declare_chain(
        rule         = 'ebook-convert ${SRC} .epub --test -vv --debug-pipeline debug', 
        ext_in       = '.recipe', 
        ext_out      = '.epub'
)

top = '.'
out = 'build'

def configure(conf):
        pass

def build(bld):
    bld(source='soverflow.recipe')

It even automatically provides a clean step that removes the epub.

Upvotes: 3

Related Questions