tags:

views:

72

answers:

2

We have an ActionScript (Flex) project that we build using GNU make. We would like to add an M4 preprocessing step to the build process (e.g., so that we can create an ASSERT() macro that includes file and line numbers).

We are having remarkable difficulty.

Our current strategy is:

  1. Create a directory "src/build" (assuming source code is in src/ and subdirectories).
  2. Within src/build, create a Makefile.
  3. Run make inside src/build.

The desired behavior is, make would then use the rules we write to send the *.as files src/ and its subdirs, creating new *.as files under build. For example:

src/bar.as -> m4 -> src/build/bar.as
src/a/foo.as -> m4 -> src/build/a/foo.as

The obvious make rule would be:

%.as : ../%.as
    echo "m4 --args < $< > $@"

This works for bar.as but not a/foo.as, apparently because make is being "smart" about splitting and re-packing directories. make -d reveals:

Trying implicit prerequisite `a/../foo.as'.
Looking for a rule with intermediate file `a/../foo.as'.

but we want the prerequisite to be "../a/foo.as". This (what we don't want) is apparently documented behavior (http://www.gnu.org/software/make/manual/make.html#Pattern-Match).

Any suggestions? Is it possible to write a pattern rule that does what we want?

We've tried VPATH also and it does not work because the generated .as files are erroneously satisfying the dependency (because . is searched before the contents of VPATH).

Any help would be greatly appreciated.

+1  A: 

One option is to use a different extension for files that haven't been preprocessed. Then you can have them in the same directory without conflict.

Anon.
Yeah, I thought of this. The key problem is that it would basically invalidate the changes in unmerged branches, of which we have many. I think that because of that, this solution is a no-go.Thanks though.
Reid
A: 

As Anon also said, your source code is no longer Flex - it is 'to be preprocessed Flex'. So, use an extension such as '.eas' (for Extended ActionScript) for the source code, and create a 'compiler' script that converts '.eas' into '.as' files, which can then be processed as before.

You may prefer to have the Extended ActionScript compiler do the whole compilation job - taking the '.eas' direct to the compiled form.

The main thing to be wary of is ensuring that '.eas' files are considered before the derived '.as' files. Otherwise, your changes in the '.eas' files will not be picked up, leading to hair-tearing and other undesirable behaviours (head banging, as in 'banging head against wall', for example) as you try to debug code that hasn't changed even though the source has.

Jonathan Leffler