2 date_default_timezone_set("UTC");
4 $lGenDate = date("Y-m-d H:i");
15 define("DEBUG_ENABLED", false);
17 $ACESSDIR = getenv("ACESSDIR");
18 $ARCH = getenv("ARCH");
20 $gInputFile = $argv[1];
21 $gOutputFile = $argv[2];
22 $gOutputLDOptsFile = $argv[3];
23 $gDepFile = ($argc > 4 ? $argv[4] : false);
25 $gDependencies = array();
27 $lines = file($argv[1]);
31 $lStack = array( array("",array()) );
32 foreach($lines as $line)
35 if($line == "" || $line[0] == "#") continue;
37 if(preg_match('/^Dir\s+"([^"]+)"\s+{$/', $line, $matches))
39 $new = array($matches[1], array());
40 array_push($lStack, $new);
47 $lStack[$lDepth][1][] = array_pop($lStack);
50 elseif(preg_match('/^((?:Opt)?)File\s+"([^"]+)"(?:\s+"([^"]+)")?$/', $line, $matches))
52 $isOptional = $matches[1];
53 $dstfile = $matches[2];
54 $path = isset($matches[3]) ? $matches[3] : "";
58 $dstfile = basename($dstfile);
61 // Parse path components
62 $path = str_replace("__EXT__", "$ACESSDIR/Externals/Output/$ARCH", $path);
63 $path = str_replace("__BIN__", "$ACESSDIR/Usermode/Output/$ARCH", $path);
64 $path = str_replace("__FS__", "$ACESSDIR/Usermode/Filesystem", $path);
65 $path = str_replace("__SRC__", "$ACESSDIR", $path);
67 $gDependencies[] = $path;
69 if( !file_exists($path) )
71 if( $isOptional == "" )
74 echo "ERROR: '{$path}' does not exist\n",
84 $lStack[$lDepth][1][] = array($dstfile, $path, $isOptional);
89 echo "ERROR: $line\n";
96 //return "0x".str_pad( dechex(ord(fgetc($fp))), 8, "0", STR_PAD_LEFT );
97 $val = unpack("I", fread($fp, 4));
98 //print_r($val); exit -1;
99 return "0x".dechex($val[1]);
104 return "0x".str_pad( dechex(ord(fgetc($fp))), 2, "0", STR_PAD_LEFT );
108 $gSymFiles = array();
109 function ProcessFolder($prefix, $items)
111 global $gOutput, $gDependencies;
112 global $ACESSDIR, $ARCH;
115 foreach($items as $i=>$item)
118 if(is_array($item[1]))
120 ProcessFolder("{$prefix}_{$i}", $item[1]);
122 $gOutput .= "tInitRD_File {$prefix}_{$i}_entries[] = {\n";
123 foreach($item[1] as $j=>$child)
125 if($j) $gOutput .= ",\n";
126 $gOutput .= "\t{\"".addslashes($child[0])."\",&{$prefix}_{$i}_{$j}}";
128 $gOutput .= "\n};\n";
130 $size = count($item[1]);
132 tVFS_Node {$prefix}_{$i} = {
134 .ACLs = &gVFS_ACL_EveryoneRX,
135 .Flags = VFS_FFLAG_DIRECTORY,
138 .ImplPtr = {$prefix}_{$i}_entries,
139 .Type = &gInitRD_DirType
150 $size = filesize($path);
152 $_sym = "_binary_".str_replace(array("/","-",".","+"), "_", $path)."_start";
153 $gOutput .= "extern Uint8 {$_sym}[];";
154 $gSymFiles[] = $path;
156 tVFS_Node {$prefix}_{$i} = {
158 .ACLs = &gVFS_ACL_EveryoneRX,
163 .Type = &gInitRD_FileType
174 ProcessFolder("gInitRD_Files", $lStack[0][1]);
176 $gOutput .= "tInitRD_File gInitRD_Root_Files[] = {\n";
177 foreach($lStack[0][1] as $j=>$child)
179 if($j) $gOutput .= ",\n";
180 $gOutput .= "\t{\"".addslashes($child[0])."\",&gInitRD_Files_{$j}}";
182 $gOutput .= "\n};\n";
183 $nRootFiles = count($lStack[0][1]);
185 tVFS_Node gInitRD_RootNode = {
187 .ACLs = &gVFS_ACL_EveryoneRX,
188 .Flags = VFS_FFLAG_DIRECTORY,
190 .ImplPtr = gInitRD_Root_Files,
191 .Type = &gInitRD_DirType
197 tVFS_Node * const gInitRD_FileList[] = {
201 function PutNodePointers($prefix, $items)
204 foreach($items as $i=>$item)
206 $gOutput .= ",&{$prefix}_{$i}";
207 if(is_array($item[1]))
209 PutNodePointers("{$prefix}_{$i}", $item[1]);
214 PutNodePointers("gInitRD_Files", $lStack[0][1]);
218 const int giInitRD_NumFiles = sizeof(gInitRD_FileList)/sizeof(gInitRD_FileList[0]);
223 $fp = fopen($gOutputFile, "w");
224 fputs($fp, $gOutput);
227 // - Create options call
228 $fp = fopen($gOutputLDOptsFile, "w");
229 fputs($fp, "--format binary\n");
230 foreach($gSymFiles as $sym=>$file)
232 fputs($fp, "$file\n");
233 // fputs($fp, "--defsym $sym=_binary_".$sym_filename."_start\n");
237 if($gDepFile !== false)
239 $fp = fopen($gDepFile, "w");
240 $line = $gOutputFile.":\t".implode(" ", $gDependencies)."\n";
242 foreach( $gDependencies as $dep )
243 fputs($fp, "$dep: \n");