2 date_default_timezone_set("UTC");
4 $lGenDate = date("Y-m-d H:i");
15 $ACESSDIR = getenv("ACESSDIR");
16 $ARCH = getenv("ARCH");
18 $gInputFile = $argv[1];
19 $gOutputFile = $argv[2];
20 $gOutputLDOptsFile = $argv[3];
21 $gDepFile = ($argc > 4 ? $argv[4] : false);
23 $gDependencies = array();
25 $lines = file($argv[1]);
29 $lStack = array( array("",array()) );
30 foreach($lines as $line)
33 if($line == "" || $line[0] == "#") continue;
35 if(preg_match('/^Dir\s+"([^"]+)"\s+{$/', $line, $matches))
37 $new = array($matches[1], array());
38 array_push($lStack, $new);
45 $lStack[$lDepth][1][] = array_pop($lStack);
48 elseif(preg_match('/^((?:Opt)?)File\s+"([^"]+)"(?:\s+"([^"]+)")?$/', $line, $matches))
50 $isOptional = $matches[1];
51 $dstfile = $matches[2];
52 $path = isset($matches[3]) ? $matches[3] : "";
56 $dstfile = basename($dstfile);
59 // Parse path components
60 $path = str_replace("__EXT__", "$ACESSDIR/Externals/Output/$ARCH", $path);
61 $path = str_replace("__BIN__", "$ACESSDIR/Usermode/Output/$ARCH", $path);
62 $path = str_replace("__FS__", "$ACESSDIR/Usermode/Filesystem", $path);
63 $path = str_replace("__SRC__", "$ACESSDIR", $path);
65 $gDependencies[] = $path;
67 if( !file_exists($path) )
69 if( $isOptional == "" )
72 echo "ERROR: '{$path}' does not exist\n",
82 $lStack[$lDepth][1][] = array($dstfile, $path, $isOptional);
87 echo "ERROR: $line\n";
94 //return "0x".str_pad( dechex(ord(fgetc($fp))), 8, "0", STR_PAD_LEFT );
95 $val = unpack("I", fread($fp, 4));
96 //print_r($val); exit -1;
97 return "0x".dechex($val[1]);
102 return "0x".str_pad( dechex(ord(fgetc($fp))), 2, "0", STR_PAD_LEFT );
106 $gSymFiles = array();
107 function ProcessFolder($prefix, $items)
109 global $gOutput, $gDependencies;
110 global $ACESSDIR, $ARCH;
113 foreach($items as $i=>$item)
116 if(is_array($item[1]))
118 ProcessFolder("{$prefix}_{$i}", $item[1]);
120 $gOutput .= "tInitRD_File {$prefix}_{$i}_entries[] = {\n";
121 foreach($item[1] as $j=>$child)
123 if($j) $gOutput .= ",\n";
124 $gOutput .= "\t{\"".addslashes($child[0])."\",&{$prefix}_{$i}_{$j}}";
126 $gOutput .= "\n};\n";
128 $size = count($item[1]);
130 tVFS_Node {$prefix}_{$i} = {
132 .ACLs = &gVFS_ACL_EveryoneRX,
133 .Flags = VFS_FFLAG_DIRECTORY,
136 .ImplPtr = {$prefix}_{$i}_entries,
137 .Type = &gInitRD_DirType
147 $size = filesize($path);
149 $_sym = "_binary_".str_replace(array("/","-",".","+"), "_", $path)."_start";
150 $gOutput .= "extern Uint8 {$_sym}[];";
151 $gSymFiles[] = $path;
153 tVFS_Node {$prefix}_{$i} = {
155 .ACLs = &gVFS_ACL_EveryoneRX,
160 .Type = &gInitRD_FileType
171 ProcessFolder("gInitRD_Files", $lStack[0][1]);
173 $gOutput .= "tInitRD_File gInitRD_Root_Files[] = {\n";
174 foreach($lStack[0][1] as $j=>$child)
176 if($j) $gOutput .= ",\n";
177 $gOutput .= "\t{\"".addslashes($child[0])."\",&gInitRD_Files_{$j}}";
179 $gOutput .= "\n};\n";
180 $nRootFiles = count($lStack[0][1]);
182 tVFS_Node gInitRD_RootNode = {
184 .ACLs = &gVFS_ACL_EveryoneRX,
185 .Flags = VFS_FFLAG_DIRECTORY,
187 .ImplPtr = gInitRD_Root_Files,
188 .Type = &gInitRD_DirType
194 tVFS_Node * const gInitRD_FileList[] = {
198 function PutNodePointers($prefix, $items)
201 foreach($items as $i=>$item)
203 $gOutput .= ",&{$prefix}_{$i}";
204 if(is_array($item[1]))
206 PutNodePointers("{$prefix}_{$i}", $item[1]);
211 PutNodePointers("gInitRD_Files", $lStack[0][1]);
215 const int giInitRD_NumFiles = sizeof(gInitRD_FileList)/sizeof(gInitRD_FileList[0]);
220 $fp = fopen($gOutputFile, "w");
221 fputs($fp, $gOutput);
224 // - Create options call
225 $fp = fopen($gOutputLDOptsFile, "w");
226 fputs($fp, "--format binary\n");
227 foreach($gSymFiles as $sym=>$file)
229 fputs($fp, "$file\n");
230 // fputs($fp, "--defsym $sym=_binary_".$sym_filename."_start\n");
234 if($gDepFile !== false)
236 $fp = fopen($gDepFile, "w");
237 $line = $gOutputFile.":\t".implode(" ", $gDependencies)."\n";
239 foreach( $gDependencies as $dep )
240 fputs($fp, "$dep: \n");