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[0] == "#") continue;
35 if(preg_match('/^Dir\s+"([^"]+)"\s+{$/', $line, $matches))
37 $new = array($matches[1], array());
38 array_push($lStack, $new);
46 $lStack[$lDepth][1][] = array_pop($lStack);
50 if(preg_match('/^File\s+"([^"]+)"(?:\s+"([^"]+)")?$/', $line, $matches))
52 if( !isset($matches[2]) ) {
53 $matches[2] = $matches[1];
54 $matches[1] = basename($matches[2]);
56 $lStack[$lDepth][1][] = array($matches[1], $matches[2]);
59 echo "ERROR: $line\n";
65 //return "0x".str_pad( dechex(ord(fgetc($fp))), 8, "0", STR_PAD_LEFT );
66 $val = unpack("I", fread($fp, 4));
67 //print_r($val); exit -1;
68 return "0x".dechex($val[1]);
73 return "0x".str_pad( dechex(ord(fgetc($fp))), 2, "0", STR_PAD_LEFT );
78 function ProcessFolder($prefix, $items)
80 global $gOutput, $gDependencies;
81 global $ACESSDIR, $ARCH;
84 foreach($items as $i=>$item)
87 if(is_array($item[1]))
89 ProcessFolder("{$prefix}_{$i}", $item[1]);
91 $gOutput .= "tInitRD_File {$prefix}_{$i}_entries[] = {\n";
92 foreach($item[1] as $j=>$child)
94 if($j) $gOutput .= ",\n";
95 $gOutput .= "\t{\"".addslashes($child[0])."\",&{$prefix}_{$i}_{$j}}";
99 $size = count($item[1]);
101 tVFS_Node {$prefix}_{$i} = {
103 .ACLs = &gVFS_ACL_EveryoneRX,
104 .Flags = VFS_FFLAG_DIRECTORY,
107 .ImplPtr = {$prefix}_{$i}_entries,
108 .Type = &gInitRD_DirType
117 // Parse path components
118 $path = str_replace("__BIN__", "$ACESSDIR/Usermode/Output/$ARCH", $path);
119 $path = str_replace("__FS__", "$ACESSDIR/Usermode/Filesystem", $path);
120 $path = str_replace("__SRC__", "$ACESSDIR", $path);
124 $gDependencies[] = $path;
126 if(!file_exists($path)) {
127 echo "ERROR: '{$path}' does not exist\n",
130 $size = filesize($path);
132 $_sym = "_binary_".str_replace(array("/","-","."), "_", $path)."_start";
133 $gOutput .= "extern Uint8 {$_sym}[];";
134 $gSymFiles[] = $path;
136 tVFS_Node {$prefix}_{$i} = {
138 .ACLs = &gVFS_ACL_EveryoneRX,
143 .Type = &gInitRD_FileType
154 ProcessFolder("gInitRD_Files", $lStack[0][1]);
156 $gOutput .= "tInitRD_File gInitRD_Root_Files[] = {\n";
157 foreach($lStack[0][1] as $j=>$child)
159 if($j) $gOutput .= ",\n";
160 $gOutput .= "\t{\"".addslashes($child[0])."\",&gInitRD_Files_{$j}}";
162 $gOutput .= "\n};\n";
163 $nRootFiles = count($lStack[0][1]);
165 tVFS_Node gInitRD_RootNode = {
167 .ACLs = &gVFS_ACL_EveryoneRX,
168 .Flags = VFS_FFLAG_DIRECTORY,
170 .ImplPtr = gInitRD_Root_Files,
171 .Type = &gInitRD_DirType
177 tVFS_Node * const gInitRD_FileList[] = {
181 function PutNodePointers($prefix, $items)
184 foreach($items as $i=>$item)
186 $gOutput .= ",&{$prefix}_{$i}";
187 if(is_array($item[1]))
189 PutNodePointers("{$prefix}_{$i}", $item[1]);
194 PutNodePointers("gInitRD_Files", $lStack[0][1]);
198 const int giInitRD_NumFiles = sizeof(gInitRD_FileList)/sizeof(gInitRD_FileList[0]);
203 $fp = fopen($gOutputFile, "w");
204 fputs($fp, $gOutput);
207 // - Create options call
208 $fp = fopen($gOutputLDOptsFile, "w");
209 fputs($fp, "--format binary\n");
210 foreach($gSymFiles as $sym=>$file)
212 fputs($fp, "$file\n");
213 // fputs($fp, "--defsym $sym=_binary_".$sym_filename."_start\n");
217 if($gDepFile !== false)
219 $fp = fopen($gDepFile, "w");
220 $line = $gOutputFile.":\t".implode(" ", $gDependencies);