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 $lStack[$lDepth][1][] = array($matches[1], $matches[2]);
55 echo "ERROR: $line\n";
61 //return "0x".str_pad( dechex(ord(fgetc($fp))), 8, "0", STR_PAD_LEFT );
62 $val = unpack("I", fread($fp, 4));
63 //print_r($val); exit -1;
64 return "0x".dechex($val[1]);
69 return "0x".str_pad( dechex(ord(fgetc($fp))), 2, "0", STR_PAD_LEFT );
74 function ProcessFolder($prefix, $items)
76 global $gOutput, $gDependencies;
77 global $ACESSDIR, $ARCH;
80 foreach($items as $i=>$item)
83 if(is_array($item[1]))
85 ProcessFolder("{$prefix}_{$i}", $item[1]);
87 $gOutput .= "tInitRD_File {$prefix}_{$i}_entries[] = {\n";
88 foreach($item[1] as $j=>$child)
90 if($j) $gOutput .= ",\n";
91 $gOutput .= "\t{\"".addslashes($child[0])."\",&{$prefix}_{$i}_{$j}}";
95 $size = count($item[1]);
97 tVFS_Node {$prefix}_{$i} = {
99 .ACLs = &gVFS_ACL_EveryoneRX,
100 .Flags = VFS_FFLAG_DIRECTORY,
103 .ImplPtr = {$prefix}_{$i}_entries,
104 .Type = &gInitRD_DirType
113 // Parse path components
114 $path = str_replace("__BIN__", "$ACESSDIR/Usermode/Output/$ARCH", $path);
115 $path = str_replace("__FS__", "$ACESSDIR/Usermode/Filesystem", $path);
116 $path = str_replace("__SRC__", "$ACESSDIR", $path);
120 $gDependencies[] = $path;
122 if(!file_exists($path)) {
123 echo "ERROR: '{$path}' does not exist\n",
126 $size = filesize($path);
128 $_sym = "_binary_".str_replace(array("/","-","."), "_", $path)."_start";
129 $gOutput .= "extern Uint8 {$_sym}[];";
130 $gSymFiles[] = $path;
132 tVFS_Node {$prefix}_{$i} = {
134 .ACLs = &gVFS_ACL_EveryoneRX,
139 .Type = &gInitRD_FileType
150 ProcessFolder("gInitRD_Files", $lStack[0][1]);
152 $gOutput .= "tInitRD_File gInitRD_Root_Files[] = {\n";
153 foreach($lStack[0][1] as $j=>$child)
155 if($j) $gOutput .= ",\n";
156 $gOutput .= "\t{\"".addslashes($child[0])."\",&gInitRD_Files_{$j}}";
158 $gOutput .= "\n};\n";
159 $nRootFiles = count($lStack[0][1]);
161 tVFS_Node gInitRD_RootNode = {
163 .ACLs = &gVFS_ACL_EveryoneRX,
164 .Flags = VFS_FFLAG_DIRECTORY,
166 .ImplPtr = gInitRD_Root_Files,
167 .Type = &gInitRD_DirType
173 tVFS_Node * const gInitRD_FileList[] = {
177 function PutNodePointers($prefix, $items)
180 foreach($items as $i=>$item)
182 $gOutput .= ",&{$prefix}_{$i}";
183 if(is_array($item[1]))
185 PutNodePointers("{$prefix}_{$i}", $item[1]);
190 PutNodePointers("gInitRD_Files", $lStack[0][1]);
194 const int giInitRD_NumFiles = sizeof(gInitRD_FileList)/sizeof(gInitRD_FileList[0]);
199 $fp = fopen($gOutputFile, "w");
200 fputs($fp, $gOutput);
203 // - Create options call
204 $fp = fopen($gOutputLDOptsFile, "w");
205 fputs($fp, "--format binary\n");
206 foreach($gSymFiles as $sym=>$file)
208 fputs($fp, "$file\n");
209 // fputs($fp, "--defsym $sym=_binary_".$sym_filename."_start\n");
213 if($gDepFile !== false)
215 $fp = fopen($gDepFile, "w");
216 $line = $gOutputFile.":\t".implode(" ", $gDependencies);