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