I’m trying to create a Makefile for my HTML5/PHP project. I have a PHP config file like this:
<?php
...
$mode = "development"; # production / development / debug
...
?>
I would like to force that value to “production” from my Makefile.
I have a shell script which works (at least to read the value):
echo `perl -ne 'print if s/.*\\\$mode\s*=\s*"(.*)".*/$1/g' config.php`
but it doesn’t in the Makefile:
MODE = $(shell echo `perl -ne 'print if s/.*\\\$mode\s*=\s*"(.*)".*/\$1/g' config.php`)
( $(MODE) is always empty… )
I know I could use an external script, but I would prefer not to.
Probably my approach is not the most correct, I’d love to hear about different solutions to such Makefile / PHP issues…
PHP is probably the most straightforward and robust language to parse PHP config files:
That’s for reading into Make.
You could also keep the single settings file in a more standard format that both languages can easily parse, like JSON, XML, etc.
I’d recommend at the very least to have the settings in only one place.
As far as altering the settings file programmatically, I’ve seen basic templating (e.g., ###REPLACEME###) used with success. You keep a parent template file. And different build targets generate different versions of the template file, with appropriate variable values replaced. Works for managing different config files across dev and prod servers, as well as managing different config files across developers.