1

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.)

idbrii
  • 10,975
  • 5
  • 66
  • 107
  • I gave up on waf and found that it's pretty easy to do in [scons](http://www.scons.org/). The documentation has a section on [Writing Your Own Builders](http://www.scons.org/doc/production/HTML/scons-user.html#chap-builders-writing). See [more details here](https://hastebin.com/ohezulesoz.md). – idbrii Sep 08 '20 at 21:23

1 Answers1

3

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.

idbrii
  • 10,975
  • 5
  • 66
  • 107