pythonjam

Calling a python script from a Jamfile


I would like to call a python script from a Jamfile to generate a necessary source file.

In a Makefile, it would look somewhat like this:

sourcefile.c:
    python script.py

What is the most elegant way to archive something like this in a Jamfile?


Solution

  • The jam equivalent is this:

    actions CallScript
    {
        python script.py
    }
    
    CallScript sourcefile.c ;
    

    Depending on the context of your application, you might need to do a bit more. E.g. if the script generates the source file and you want to compile that generated source file, the solution would probably look like:

    rule GenerateSource
    {
        local source = [ FGristFiles $(1) ] ;
        MakeLocate $(source) : $(LOCATE_SOURCE) ;
        Clean clean : $(source) ;
        GenerateSource1 $(source) ;
    }
    
    actions GenerateSource1
    {
        python script.py $(1)
    }
    
    GenerateSource sourcefile.c ;
    
    Main foo : sourcefile.c ;