InitRD - Libc++, libm, bochs, dbserver
[tpg/acess2.git] / KernelLand / Modules / Filesystems / InitRD / GenerateInitRD.php
index e7cd4f7..5034b4b 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+date_default_timezone_set("UTC");
+
 $lGenDate = date("Y-m-d H:i");
 $gOutput = <<<EOF
 /*
@@ -28,29 +30,63 @@ $lStack = array( array("",array()) );
 foreach($lines as $line)
 {
        $line = trim($line);
+       if($line == "" || $line[0] == "#")      continue;
        // Directory
        if(preg_match('/^Dir\s+"([^"]+)"\s+{$/', $line, $matches))
        {
                $new = array($matches[1], array());
                array_push($lStack, $new);
                $lDepth ++;
-               continue;
        }
        // End of a block
-       if($line == "}")
+       elseif($line == "}")
        {
                $lDepth --;
                $lStack[$lDepth][1][] = array_pop($lStack);
-               continue;
        }
        // File
-       if(preg_match('/^File\s+"([^"]+)"\s+"([^"]+)"$/', $line, $matches))
+       elseif(preg_match('/^((?:Opt)?)File\s+"([^"]+)"(?:\s+"([^"]+)")?$/', $line, $matches))
        {
-               $lStack[$lDepth][1][] = array($matches[1], $matches[2]);
-               continue;
+               $isOptional = $matches[1];
+               $dstfile = $matches[2];
+               $path = isset($matches[3]) ? $matches[3] : "";
+               
+               if( $path == "" ) {
+                       $path = $dstfile;
+                       $dstfile = basename($dstfile);
+               }
+               
+               // Parse path components
+               $path = str_replace("__EXT__", "$ACESSDIR/Externals/Output/$ARCH", $path);
+               $path = str_replace("__BIN__", "$ACESSDIR/Usermode/Output/$ARCH", $path);
+               $path = str_replace("__FS__", "$ACESSDIR/Usermode/Filesystem", $path);
+               $path = str_replace("__SRC__", "$ACESSDIR", $path);
+
+               $gDependencies[] = $path;
+               
+               if( !file_exists($path) )
+               {
+                       if( $isOptional == "" )
+                       {
+                               // Oops
+                               echo "ERROR: '{$path}' does not exist\n", 
+                               exit(1);
+                       }
+                       else
+                       {
+                               // optional file
+                       }
+               }
+               else
+               {
+                       $lStack[$lDepth][1][] = array($dstfile, $path, $isOptional);
+               }
+       }
+       else
+       {
+               echo "ERROR: $line\n";
+               exit(0);
        }
-       echo "ERROR: $line\n";
-       exit(0);
 }
 
 function hd($fp)
@@ -107,51 +143,12 @@ EOF;
                {
                        $path = $item[1];
                        
-                       // Parse path components
-                       $path = str_replace("__BIN__", "$ACESSDIR/Usermode/Output/$ARCH", $path);
-                       $path = str_replace("__FS__", "$ACESSDIR/Usermode/Filesystem", $path);
-                       $path = str_replace("__SRC__", "$ACESSDIR", $path);
                        echo $path,"\n";
-                       // ---
-                       
-                       $gDependencies[] = $path;
-
-                       if(!file_exists($path)) {
-                               echo "ERROR: '{$path}' does not exist\n", 
-                               exit(1);
-                       }
                        $size = filesize($path);
        
-/*             
-                       $_sym = $prefix."_".$i."_data";
-                       $fp = fopen($path, "rb");
-                       
-                       $gOutput .= "Uint8 $_sym[] = {\n";
-                       for( $j = 0; $j + 16 < $size; $j += 16 ) {
-                               $gOutput .= "\t";
-                               $gOutput .= hd8($fp).",".hd8($fp).",";
-                               $gOutput .= hd8($fp).",".hd8($fp).",";
-                               $gOutput .= hd8($fp).",".hd8($fp).",";
-                               $gOutput .= hd8($fp).",".hd8($fp).",";
-                               $gOutput .= hd8($fp).",".hd8($fp).",";
-                               $gOutput .= hd8($fp).",".hd8($fp).",";
-                               $gOutput .= hd8($fp).",".hd8($fp).",";
-                               $gOutput .= hd8($fp).",".hd8($fp).",\n";
-                       }
-                       $gOutput .= "\t";
-                       for( ; $j < $size; $j ++ ) {
-                               if( $j & 15 )   $gOutput .= ",";
-                               $gOutput .= hd8($fp);
-                       }
-                       fclose($fp);
-                       $gOutput .= "\n};\n";
-*/
-                       
-//*
-                       $_sym = "_binary_".str_replace(array("/","-","."), "_", $path)."_start";
+                       $_sym = "_binary_".str_replace(array("/","-",".","+"), "_", $path)."_start";
                        $gOutput .= "extern Uint8 {$_sym}[];";
                        $gSymFiles[] = $path;
-//*/
                        $gOutput .= <<<EOF
 tVFS_Node {$prefix}_{$i} = {
        .NumACLs = 1,
@@ -237,8 +234,10 @@ fclose($fp);
 if($gDepFile !== false)
 {
        $fp = fopen($gDepFile, "w");
-       $line = $gOutputFile.":\t".implode(" ", $gDependencies);
+       $line = $gOutputFile.":\t".implode(" ", $gDependencies)."\n";
        fputs($fp, $line);
+       foreach( $gDependencies as $dep )
+               fputs($fp, "$dep: \n");
        fclose($fp);
 }
 

UCC git Repository :: git.ucc.asn.au