Search code examples
replacebjamboost-buildb2

Replace pattern in list in boost build/b2/bjam


How can I replace a pattern in a list of strings in boost build ?

In GNU make that could be done using substitution for changing file extension, or patsubst in general.


Solution

  • Here is an example using the rule "replace-list" from builtin module regex:

    SWIG_SOURCES = [ glob *.i ] ;
    
    import regex ;
    SWIG_GENERATED_CPP_FILES = [ regex.replace-list $(SWIG_SOURCES) : \\.i : _wrap.cpp ] ;
    

    Let's say the file example_file.i is located in the directory, its name will be added to the list SWIG_SOURCES by glob and will become example_file_wrap.cpp in the list SWIG_GENERATED_CPP_FILES;

    The \\ are used to mean that . is a litteral dot, without them . would match any character.

    The $ matches the end of the string.

    More information in the documentation of regex builtin