2 $lGenDate = date("Y-m-d H:i");
13 $ACESSDIR = getenv("ACESSDIR");
14 $ARCH = getenv("ARCH");
16 $gInputFile = $argv[1];
17 $gOutputFile = $argv[2];
18 $gOutputLDOptsFile = $argv[3];
19 $gDepFile = ($argc > 4 ? $argv[4] : false);
21 $gDependencies = array();
23 $lines = file($argv[1]);
27 $lStack = array( array("",array()) );
28 foreach($lines as $line)
31 if($line[0] == "#") continue;
33 if(preg_match('/^Dir\s+"([^"]+)"\s+{$/', $line, $matches))
35 $new = array($matches[1], array());
36 array_push($lStack, $new);
44 $lStack[$lDepth][1][] = array_pop($lStack);
48 if(preg_match('/^File\s+"([^"]+)"\s+"([^"]+)"$/', $line, $matches))
50 $lStack[$lDepth][1][] = array($matches[1], $matches[2]);
53 echo "ERROR: $line\n";
59 //return "0x".str_pad( dechex(ord(fgetc($fp))), 8, "0", STR_PAD_LEFT );
60 $val = unpack("I", fread($fp, 4));
61 //print_r($val); exit -1;
62 return "0x".dechex($val[1]);
67 return "0x".str_pad( dechex(ord(fgetc($fp))), 2, "0", STR_PAD_LEFT );
72 function ProcessFolder($prefix, $items)
74 global $gOutput, $gDependencies;
75 global $ACESSDIR, $ARCH;
78 foreach($items as $i=>$item)
81 if(is_array($item[1]))
83 ProcessFolder("{$prefix}_{$i}", $item[1]);
85 $gOutput .= "tInitRD_File {$prefix}_{$i}_entries[] = {\n";
86 foreach($item[1] as $j=>$child)
88 if($j) $gOutput .= ",\n";
89 $gOutput .= "\t{\"".addslashes($child[0])."\",&{$prefix}_{$i}_{$j}}";
93 $size = count($item[1]);
95 tVFS_Node {$prefix}_{$i} = {
97 .ACLs = &gVFS_ACL_EveryoneRX,
98 .Flags = VFS_FFLAG_DIRECTORY,
101 .ImplPtr = {$prefix}_{$i}_entries,
102 .Type = &gInitRD_DirType
111 // Parse path components
112 $path = str_replace("__BIN__", "$ACESSDIR/Usermode/Output/$ARCH", $path);
113 $path = str_replace("__FS__", "$ACESSDIR/Usermode/Filesystem", $path);
114 $path = str_replace("__SRC__", "$ACESSDIR", $path);
118 $gDependencies[] = $path;
120 if(!file_exists($path)) {
121 echo "ERROR: '{$path}' does not exist\n",
124 $size = filesize($path);
126 $_sym = "_binary_".str_replace(array("/","-","."), "_", $path)."_start";
127 $gOutput .= "extern Uint8 {$_sym}[];";
128 $gSymFiles[] = $path;
130 tVFS_Node {$prefix}_{$i} = {
132 .ACLs = &gVFS_ACL_EveryoneRX,
137 .Type = &gInitRD_FileType
148 ProcessFolder("gInitRD_Files", $lStack[0][1]);
150 $gOutput .= "tInitRD_File gInitRD_Root_Files[] = {\n";
151 foreach($lStack[0][1] as $j=>$child)
153 if($j) $gOutput .= ",\n";
154 $gOutput .= "\t{\"".addslashes($child[0])."\",&gInitRD_Files_{$j}}";
156 $gOutput .= "\n};\n";
157 $nRootFiles = count($lStack[0][1]);
159 tVFS_Node gInitRD_RootNode = {
161 .ACLs = &gVFS_ACL_EveryoneRX,
162 .Flags = VFS_FFLAG_DIRECTORY,
164 .ImplPtr = gInitRD_Root_Files,
165 .Type = &gInitRD_DirType
171 tVFS_Node * const gInitRD_FileList[] = {
175 function PutNodePointers($prefix, $items)
178 foreach($items as $i=>$item)
180 $gOutput .= ",&{$prefix}_{$i}";
181 if(is_array($item[1]))
183 PutNodePointers("{$prefix}_{$i}", $item[1]);
188 PutNodePointers("gInitRD_Files", $lStack[0][1]);
192 const int giInitRD_NumFiles = sizeof(gInitRD_FileList)/sizeof(gInitRD_FileList[0]);
197 $fp = fopen($gOutputFile, "w");
198 fputs($fp, $gOutput);
201 // - Create options call
202 $fp = fopen($gOutputLDOptsFile, "w");
203 fputs($fp, "--format binary\n");
204 foreach($gSymFiles as $sym=>$file)
206 fputs($fp, "$file\n");
207 // fputs($fp, "--defsym $sym=_binary_".$sym_filename."_start\n");
211 if($gDepFile !== false)
213 $fp = fopen($gDepFile, "w");
214 $line = $gOutputFile.":\t".implode(" ", $gDependencies);