1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
#!/usr/bin/perl
use File::Basename;
print <<EOF
// !\$*UTF8*\$!
{
archiveVersion = 1;
classes = {};
objectVersion = 44;
objects = {
/* Begin PBXFileReference section */
EOF
;
%files = ();
%sourceTree = ();
%headerTree = ();
findFiles("h","sourcecode.c.h");
findFiles("c","sourcecode.c.c");
findFiles("hpp","sourcecode.cpp.h");
findFiles("hh","sourcecode.cpp.h");
findFiles("cpp","sourcecode.cpp.cpp");
foreach my $k (keys %files) {
my $relpath = $k;
$relpath =~ s/\.\/(.*)/\1/;
print " ".$files{$k}[0]." /* ".$files{$k}[1]." */ = ";
print "{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = ";
print $files{$k}[2]."; path =\"".$files{$k}[1];
print "\"; sourceTree = \"<group>\"; };\n"
}
print "/* End PBXFileReference section */\n\n";
print "/* Begin PBXGroup section */\n";
my $sourcesUID = uid();
printGroup("Sources",$sourcesUID,\%sourceTree,"./");
my $headersUID = uid();
printGroup("Headers",$headersUID,\%headerTree,"./");
my $mainUID = uid();
print <<EOF
$mainUID = {
isa = PBXGroup;
children = (
$sourcesUID /* Sources */,
$headersUID /* Headers */,
);
sourceTree = "<group>";
};
EOF
;
my $rootUID = uid();
print "/* End PBXGroup section */\n";
print "/* Begin PBXProject section */\n";
print " ".$rootUID." /* Project object */ = {\n";
print " isa = PBXProject;\n";
print " compatibilityVersion = \"XCode 2.4\";\n";
print " mainGroup = ".$mainUID." /* Gecode */;\n";
print " projectDirPath = \"\";\n";
print " projectRoot = \"\";\n";
print " };\n";
print "/* End PBXProject section */\n";
print " };\n";
print " rootObject = ".$rootUID." /* Project object */;\n";
print "}\n";
sub findFiles {
my $extension = $_[0];
my $type = $_[1];
my $find = "find . -name '*.".$extension."' -type f |";
open (F, $find);
while (my $f = <F>) {
chomp($f);
my ($filename, $dummydir, $suffix) = fileparse($f);
my @dirs = split(/\//,$f);
shift(@dirs);
pop(@dirs);
my $treeP;
if ($type =~ m/sourcecode\..*\.h/) {
$treeP = \%headerTree;
} else {
$treeP = \%sourceTree;
}
foreach my $d (@dirs) {
if (not exists $treeP->{$d}) {
my %subTree = ();
my @child = (uid(), \%subTree);
$treeP->{$d} = [@child];
}
$treeP = $treeP->{$d}[1];
}
$treeP->{$filename} = "";
my @r = (uid(), $filename, $type);
$files{$f} = [@r];
}
close (F);
}
sub uid {
my $uid = `uuidgen`;
$uid =~ /[A-Z0-9]+-([A-Z0-9]+)-([A-Z0-9]+)-([A-Z0-9]+)-([A-Z0-9]+)/;
return $1.$2.$3.$4;
}
sub printGroup {
my $g = $_[0];
my $id = $_[1];
my $treeP = $_[2];
my $path = $_[3];
print " ".$id. " /* ".$g." */ = {\n";
print " isa = PBXGroup;\n";
print " children = (\n";
foreach my $k (sort keys %{$treeP}) {
if (exists $treeP->{$k}[0]) {
print " ".$treeP->{$k}[0]." /* ".$k." */,\n";
} else {
print " ".$files{$path.$k}[0]." /* ".$k." */,\n";
}
}
print " );\n";
if ($path eq "./") {
print " path = \".\";\n";
print " name = \"$g\";\n";
} else {
print " path = \"$g\";\n";
}
print " sourceTree = \"<group>\";\n };\n";
foreach my $k (keys %{$treeP}) {
if (exists $treeP->{$k}[0]) {
printGroup($k, $treeP->{$k}[0], $treeP->{$k}[1],
$path.$k."/");
}
}
}
|