I have recenlty posted on this topic but got no response, probably because I didn't phrase it well.
I would like to implement this proposed feature if I can get some feedback to know if it would be accepted for inclusion.

Here is the proposal:

* Add a '-M' option to sapi/cli/php that would behave essentially the same as gcc -M and enable the use of php command-line scripts to work properly in a makefile build environment (See below for explanation of gcc -M).

* 'php -M -f myFile.php' should differ from 'gcc -M myFile.c', in two ways:
a) Command output should only list prerequisite files rather than a complete dependency makefile rule since there is no standard suffix for php output as for C [ myFile.o : myFile.c ... ]
b) Detect dependencies other than included and required files, as reported by get_included_files(). There are many other ways that a PHP script could become dependent on other files which cannot easily be determined automatically unless a function is available for a script to explicitly declare that it depends on an external file. [Example: <? if (file_exists($myFile)) echo "hello";?>].

* Add two built-in PHP functions to allow '-M' option to accurately identify file dependencies in PHP source files (the names could change):
void register_prerequisite_file( string $myFile )
Array get_prerequisite_files( )

* With the above two functions, this is how the system should work:
In the following example, /usr/local/bin/php-cli is the command-line version of PHP: sapi/cli/php
--------- file: test.php
#!/usr/local/bin/php-cli
<?
php include( "myIncludedFile.php" );
register_prerequisite_file( "myRequiredFile")
if (file_exists( "myRequiredFile" )) echo "got file";
?>
-------- eof

Internally php-cli -M would call get_included_files() and get_prerequisite_files() and join them together in a space separated list, with the first item being the source file. Here is what php-cli would do from the command line:

$/usr/local/bin/php-cli -M -f test.php
test.php myIncludedFile.php myRequiredFile

---------------
# A makefile rule could now use these features:

$(PHP):=/usr/local/bin/php-cli

define phpDependencies
$(shell $(PHP) -M -f $(1))
endef

myFile.html : $(call phpDependencies,myFile.php)
$(PHP) -f $< > $@ || { echo "failed"; cat $@; exit 1; }
# end of makefile

-------------- APPENDIX - For those unfamiliar with gcc -M, following if from info gcc

`-M'
Tell the preprocessor to output a rule suitable for `make'
describing the dependencies of each object file. For each source
file, the preprocessor outputs one `make'-rule whose target is the
object file name for that source file and whose dependencies are
all the `#include' header files it uses. This rule may be a
single line or may be continued with `\'-newline if it is long.
The list of rules is printed on standard output instead of the
preprocessed C program.

`-M' implies `-E'.

Another way to specify output of a `make' rule is by setting the
environment variable `DEPENDENCIES_OUTPUT' (*note Environment
Variables::.).

`-E'
Run only the C preprocessor. Preprocess all the C source files
specified and output the results to standard output or to the
specified output file.




- Greg Keraunen
http://www.xmake.org
http://www.xmlmake.com


--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to