Handling include defines

Added by Steven Craft over 1 year ago

Hi there,

We support multiple platforms off a single code base, and as a result have got a lot of code that is included via a macro as follows:

#include NUPATH

This expands to:

#include "nu3d/wii/nurenderstate.h"

Where 'wii' could also be 'ps3', 'pc', '360' and so on, depending on the target platform.

Currently with JamPlus, all files included in this manner do not get correctly detected in the header scan, so dependencies aren't correctly tracked. Is there a nice solution to this problem? Or would I be better off attempting to put some custom support in purely for our usage above?

Many thanks,

Steve


Replies (3)

RE: Handling include defines - Added by Steven Craft over 1 year ago

The first include which didn't appear correctly above should read:

#include NUPATH(nu3d/NUPLATFORM/nurenderstate.h)

Steve

RE: Handling include defines - Added by Steven Craft over 1 year ago

My first stab at hacking something to work for my needs is:

1. Editing headers.c, and basically replacing all instances of:

startp[0]/endp[0]

with

startp[1]/endp[1]

This means the header scan rule will use the second match group for the filename. The reason I had to do this is because non matching groups do not appear to be supported (groups beginning with ?:) - and I need to have a group before the filename, that specifies that NUPATH maybe in the include statement.

2. Editing c.jam so the HDRPATTERN is:

C.HDRPATTERN =
        "^[     ]*#[     ]*include[     ](NUPATH)*[<\"\(]([^\)\">]*)[\)\">].*$" ;

As you can see, it allows between 0 and 1 instances of NUPATH to appear before the filename, and also allows the filename to appear in parenthesis.

3. Adding to C.HdrRule like this:

rule C.HdrRule SOURCE : HEADERS
{
    # HdrRule source : headers ;

    # Fix up NUPLATFORM defines (lowercase by time they reach us here).
    HEADERS = [ Subst $(HEADERS) : "nuplatform[\\/]" : "$(PF:L)/" ] ;

You can note $(PF) will resolve for the short-platform in my case, where short platform is what is used in my directory layout for platform specific files.

With that in place, dependencies do start working for me (through the NUPATH macro). So that's good news, but the next question is how could this be integrated sensibly? Firstly it'd be nice if jam.exe always treated the LAST matching group as being the filename when dealing with HDRPATTERN, which I am guessing would be easier to implement than attempting to add non matching group support. The remaining problems would be in jam.c - would there be a way to allow my Jamrules file to specify a custom header matching pattern, and a custom header fix up pattern? I'm hopeful this can be done reasonably neatly... Maybe I can just created my own C.HDRPATTERN to mask the one in c.jam, and have a call to C._HdrRule right at the top of C.HdrRule, which would by default call a rule that does nothing, but if the user (me) implements a C._HdrRule in my Jamrules file, it would call that instead.

Does any of this make any sense?! Or is there a better solution?

Steve

RE: Handling include defines - Added by Steven Craft over 1 year ago

Slight update on the header pattern:

C.HDRPATTERN =
        "^[     ]*#[     ]*include[     ]*(NUPATH|)[<\"\(]([^\)\">]*)[\)\">].*$" ;

Previously I was only getting headers included with the NUPATH macro, this updated version gets normal headers too I believe..

Steve

(1-3/3)