assertTrue is the professional blog of Luke Bayes and Ali Mills

Pre-Processing ActionScript files with cpp on OSX

Posted by Ali Mills Tue, 06 Jan 2009 22:08:00 GMT

Back in March 2005, Mike Chambers wrote a couple interesting posts about using cpp, a C pre-processor, to pre-process ActionScript files.

He noted that, while cpp is included on Mac OS X, for some reason it wasn’t working for him. Well, I think that I just found the reason. It appears that cpp’s docs and man pages don’t emphasize how picky the tool is about white space.

To get the examples to work on my MacBook, I had to make some minor white space modifications.

I had to get rid of all the white space before the #ifdef directive like so:

1
2
3
4
5
6
7
class HelloWorld {
    function HelloWorld() {
#ifdef DEBUG
        trace("Hello World Loaded");
#endif
    }
}

And, I had to drop the space between the ā€˜-D’ flag and the DEBUG macro name when calling cpp. The command ended up looking like this:

1
cpp -DDEBUG -P HelloWorld.p HelloWorld.as

That did it for me. With those changes and Mike’s introduction to pre-processing ActionScript files and classes, I have cpp working on OSX with ActionScript just fine.

WooHoo!

Tags  | 2 comments

Comments

  1. Tim Robles commented: Avatar That's cool that you were able to get it to work. I was wondering how you fit this in to your build process. For all dev environments are you compiling with DEBUG on, then have some sort of continuous integration which does a clean build with DEBUG off?
    Posted: 6 days later.
  2. Luke Bayes replied: Avatar Hey Tim,

    That's a great question!

    We aren't actually doing any preprocessing on our projects right now, but we did just release a new build of Sprouts (http://projectsprouts.org) that supports it.

    The big idea was that BrightRoll wants to use preprocessors to accomplish a variety of things.

    Pull debug code from production builds, include auto-incremented revisions, toggle debug state, etc..

    And they'll be using Sprouts to automate their build for development and with Cruise Control integration.

    Thanks!
    Posted: 7 days later.

Your Reply

Comment Form.

Fields denoted with an "*" are required.