Skip to content
Snippets Groups Projects
Select Git revision
  • f832b925ae7eb6cd802111293ca2806eb3eec32e
  • main default protected
  • v0.1
3 results

build.php

Blame
  • build.php 2.94 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)){