I'm working on a system where I take a directory full of PHP files (plus some #defines, etc.), run them through the C Preprocessor (and m4 later, but that's to solve a very specific problem), and have the results go into an output directory that's web-accessible. My intent is to have one set of PHP files create several sites that are each configured their own specific way and have certain portions of the code removed. (I prefer #ifdef over an if() check in PHP because it means the code that won't be used doesn't need to be parsed either, and it's cleaner in many ways). I've had some measure of success, however I've also had quite a few problems crop up.
Rather than have 100+ lines of define() statements that need to be parsed every single page load (my include file is quite large), I've opted to replace them with CPP-level #define statements. This works (in MOST cases and I can work around the exceptions), with a few major issues: The major problem is: #define DNA 42 // Life, the Universe and Everything echo "The meaning of life is ", DNA, "."; Most of the cpp options I've tried do not strip out the //-style comments, so I end up with: echo "The meaning of life is ", 42 // Life, the Universe and Everything, "."; which creates a rather nasty parse error. I've tried -x c++ to allow the //-style comments, but then I'm not allowed to use multi-line string constants (I do this quite extensively in echo statements). As a last resort, I tried -x assembler-with-cpp, which happily changed my multi-line string constants into single-line string constants (by adding a ' at the end of the line, NOT by concatenating the lines together), which promptly causes a parse error on what's supposed to be the second line of the string -- it also causes some odd mangling in certain circumstances. I would prefer to not have to change all my // comments to /*..*/ style, and would like to keep my multi-line string constants -- my goal is to get this working without significant source code changes (exceptions being define() to #define and other small changes). Has anyone here had any luck setting up something similiar? cpp, php, and m4 are invoked as shown below (as Makefile snippets) PHP = C:/php/php.exe -C -q -d short_open_tag=off CPP = cpp -P -Wcomment -undef -Wundef -nostdinc -nostdinc++ -traditional M4 = m4 -P ... $(CPP) ../src/$@ | $(M4) > preproc.out $(PHP) ../tools/lint.php $(PHP) -l preproc.out mv preproc.out $@ [lint.php is a small PHP script that invokes PHP's -lint option, but also returns 0 or 1 so it'll stop the Make if there's a syntax error.) By the way, once I get this all working, I'll release the build system (not what it builds, however) as open-source for whoever wants it. It's going to be quite handy IMHO. -- Daniel Grace -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php