mirror of
https://github.com/misterunknown/ifm.git
synced 2025-08-18 05:41:17 +02:00
extended compiler: standalone and library build
This commit is contained in:
72
compiler.php
72
compiler.php
@@ -1,32 +1,58 @@
|
|||||||
#!/usr/bin/env php
|
#!/usr/bin/env php
|
||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* IFM compiler
|
||||||
|
*
|
||||||
|
* This script compiles all sources into one single file.
|
||||||
|
*/
|
||||||
|
|
||||||
// This compiles the source files into one file
|
chdir( realpath( dirname( __FILE__ ) ) );
|
||||||
|
|
||||||
$IFM_CONFIG = "src/config.php";
|
$IFM_SRC_MAIN = "src/main.php";
|
||||||
$IFM_MAIN = "src/main.php";
|
$IFM_SRC_PHPFILES = array( "src/ifmzip.php" );
|
||||||
$IFM_OTHER_PHPFILES = array("src/ifmzip.php");
|
$IFM_SRC_JS = "src/ifm.js";
|
||||||
|
|
||||||
$filename = "ifm.php";
|
$IFM_BUILD_STANDALONE = "ifm.php";
|
||||||
|
$IFM_BUILD_LIB_PHP = "build/ifmlib.php";
|
||||||
|
$IFM_BUILD_LIB_JS = "build/ifm.js";
|
||||||
|
|
||||||
// config
|
/**
|
||||||
file_put_contents($filename, file_get_contents($IFM_CONFIG));
|
* Prepare main script
|
||||||
|
*/
|
||||||
// other php classes
|
$main = file_get_contents( $IFM_SRC_MAIN );
|
||||||
foreach ( $IFM_OTHER_PHPFILES as $file) {
|
$includes = NULL;
|
||||||
$content_file = file($file);
|
preg_match_all( "/\@\@\@([^\@]+)\@\@\@/", $main, $includes, PREG_SET_ORDER );
|
||||||
unset($content_file[0]); // remove <?php line
|
foreach( $includes as $file ) {
|
||||||
file_put_contents($filename, $content_file, FILE_APPEND);
|
$main = str_replace( $file[0], file_get_contents( $file[1] ), $main );
|
||||||
}
|
}
|
||||||
|
|
||||||
// main
|
/**
|
||||||
$content_main = file($IFM_MAIN);
|
* Add PHP files
|
||||||
unset($content_main[0]);
|
*/
|
||||||
$content_main = implode($content_main);
|
$phpincludes = array();
|
||||||
$include_files = NULL;
|
foreach( $IFM_SRC_PHPFILES as $file ) {
|
||||||
preg_match_all( "/\@\@\@([^\@]+)\@\@\@/", $content_main, $include_files, PREG_SET_ORDER );
|
$content = file( $file );
|
||||||
foreach( $include_files as $file ) {
|
unset( $content[0] ); // remove <?php line
|
||||||
//echo $file[0]. " " .$file[1]."\n";
|
$phpincludes = array_merge( $phpincludes, $content );
|
||||||
$content_main = str_replace( $file[0], file_get_contents( $file[1] ), $content_main );
|
|
||||||
}
|
}
|
||||||
file_put_contents($filename, $content_main, FILE_APPEND);
|
|
||||||
|
/**
|
||||||
|
* Build standalone script
|
||||||
|
*/
|
||||||
|
file_put_contents( $IFM_BUILD_STANDALONE, $main );
|
||||||
|
file_put_contents( $IFM_BUILD_STANDALONE, $phpincludes, FILE_APPEND );
|
||||||
|
file_put_contents( $IFM_BUILD_STANDALONE, array(
|
||||||
|
'',
|
||||||
|
'/**',
|
||||||
|
' * start IFM',
|
||||||
|
' */',
|
||||||
|
'$ifm = new IFM();',
|
||||||
|
'$ifm->run();'
|
||||||
|
), FILE_APPEND );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build library
|
||||||
|
*/
|
||||||
|
file_put_contents( $IFM_BUILD_LIB_PHP, $main );
|
||||||
|
file_put_contents( $IFM_BUILD_LIB_PHP, $phpincludes, FILE_APPEND );
|
||||||
|
file_put_contents( $IFM_BUILD_LIB_JS, $IFM_SRC_JS );
|
||||||
|
Reference in New Issue
Block a user