3

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?

user1785730
  • 2,326
  • 2
  • 19
  • 39

1 Answers1

1

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 ;
user686249
  • 617
  • 5
  • 15
  • 1
    Come to think of it, you probably want your source file to be updated when the script changes. So `Depends $(source) : script.py ;` should be added in the rule. You might then also pass the script as a second parameter to the actions (`GenerateSource1 $(source) : script.py ;`) and use that parameter in the actions instead of hard-coding the name there (`python $(2) $(1)`). Oh, I've been assuming that the script takes your source file name as parameter. If that's not that case, omit the `$(1)` – user686249 Oct 30 '12 at 15:00