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

build.php

Blame
  • build.php 1.97 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/src/amcli.php.tmp";
    $OUTFILE="$selfdir/$dirPackages/".str_replace('.php', '', basename($INFILE));
    
    
    echo "
    
        B U I L D E R
    
    
    
    ";
    
    _chdir($selfdir);
    _mkdir($dirPackages);
    
    // ----------------------------------------------------------------------
    
    _h1("Check target file");
    if(file_exists($OUTFILE)){
        echo "INFO: output file '$OUTFILE' already exists.\n";
        $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..\n";
        }
    }
    
    // ----------------------------------------------------------------------
    
    _h1("Prepare source");
    $in=file_get_contents($INFILE);
    $inccode=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=../src/simple.ini");
    
    _h1("Test binary in other location");
    $testfile="/tmp/".basename($OUTFILE);
    _exec("cp '$OUTFILE' '$testfile'");
    _exec("'$testfile' --ini=$selfdir/src/simple.ini");
    _exec("rm '$testfile'");
    
    // ----------------------------------------------------------------------
    
    _h1("Done");
    
    // ----------------------------------------------------------------------