-
Hahn Axel (hahn) authoredHahn Axel (hahn) authored
build.php 2.88 KiB
#!/bin/env php
<?php
require("inc_vars.php");
require("inc_functions.php");
$INFILE="$selfdir/src/amcli.php";
$INCFILE="$selfdir/src/include_checks.php";
$TMPFILE="$selfdir/$dirBuild/amcli.php.tmp";
$OUTFILE="$selfdir/$dirPackages/".str_replace('.php', '', basename($INFILE)).$myosextension;
$OUTFILE2="$selfdir/$dirPackages/".str_replace('.php', '', basename($INFILE)).'_'.$myos.'_'.$myarchitecture.$myosextension;
echo "
B U I L D E R
";
_chdir($selfdir);
_mkdir($dirPackages);
// ----------------------------------------------------------------------
_h1("Check target file");
if(file_exists($OUTFILE)){
$ts_in=filemtime($INFILE);
$ts_out=filemtime($OUTFILE);
if($ts_in>$ts_out){
echo "✅ INFO: Source file \"$INFILE\" is newer than \"$OUTFILE\". Compiling changes...\n";
} else {
echo "🔹 INFO: Source is unchanged since last build... rebuilding it anyway.\n";
}
} else {
echo "✅ INFO: Target \"$OUTFILE\" does not exist yet.\n";
}
// ----------------------------------------------------------------------
_h1("Prepare source");
$sBuildDate=date("Y-m-d H:i:s");
$sBuildPhpcode="\$AMCLI_BUILD_DATE=\"$sBuildDate\";";
$datefile=str_replace('.php', '__build.php', $INFILE);
file_put_contents(
$datefile, "<?php
// This file was generated by ".__FILE__."
$sBuildPhpcode"
);
$in=file_get_contents($INFILE);
$inccode=$sBuildPhpcode . "\n". file_get_contents($INCFILE);
$inccode=str_replace("<?php", "", $inccode);
$tempcode=preg_replace("#\/\/ ---MARK---INCLUDE-CHECKS---START---.*---MARK---INCLUDE-CHECKS---END#s", "$inccode", $in);
if(file_put_contents($TMPFILE, $tempcode)){
_ok("$TMPFILE was written");
}
// ----------------------------------------------------------------------
_h1("Compile");
_chdir("$selfdir/$dirBuild");
_exec("$SPC \
micro:combine \
\"$TMPFILE\" \
-O \"$OUTFILE\"");
// if(unlink($TMPFILE)){
// echo "Cleanup: $TMPFILE was deleted\n";
// }
// ----------------------------------------------------------------------
_h1("Test generated binary");
_exec("file \"$OUTFILE\"");
_exec("\"$OUTFILE\" --ini=../tests/configs/metadata.ini");
_h1("Write architecture specific binary");
_exec("cp \"$OUTFILE\" '$OUTFILE2'");
_h1("Create readme");
$readme="{$OUTFILE2}__README.md";
$versionSPC=system("$SPC --version");
file_put_contents($readme,
"# Build infos
Date : $sBuildDate
OS : $myos
architecture: $myarchitecture
File : ".basename($OUTFILE2)."
## Versions
Used SPC : $versionSPC
PHP version : $php_version
PHP modules : $php_libs
## Conmands
Download : `$cmdSpcDownload`
Build : `$cmdSpcBuild`
see https://os-docs.iml.unibe.ch/appmonitor-cli-client/
");
echo "see $readme\n";
// ----------------------------------------------------------------------
_h1("Done: Build was successful.");
// ----------------------------------------------------------------------