2 eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
3 & eval 'exec perl -w -S $0 $argv:q'
6 # ******************************************************************
9 # Description: Generate a base project based on a library project
10 # ******************************************************************
12 # ******************************************************************
14 # ******************************************************************
22 my $basePath = $FindBin::Bin
;
24 $basePath = File
::Spec
->rel2abs(dirname
($0)) if ($basePath eq '');
25 $basePath = VMS
::Filespec
::unixify
($basePath);
27 unshift(@INC, $basePath . '/modules');
31 # ******************************************************************
33 # ******************************************************************
37 # ******************************************************************
39 # ******************************************************************
43 my $fh = new FileHandle
();
45 if (open($fh, $name)) {
49 ## Get the line a remove leading and trailing white space
54 ## Look for the project declaration and pull out the name and any
56 if ($line =~ /^project\s*(\(([^\)]+)\))?\s*(:.+)?\s*{$/) {
58 my $parents = $3 || '';
60 ## Create the default project name by removing the extension and
61 ## converting back-slashes, spaces and dashes to underscores.
62 ## This needs to be done regardless of whether the project name
63 ## was provided or not since it's used below in the
64 ## fill_type_name call.
65 my $def = basename
($name);
66 $def =~ s/\.[^\.]+$//;
70 if (!defined $pname || $pname eq '') {
71 ## Take the default project name since one wasn't provided.
75 ## Convert back-slashes, spaces and dashes to underscores.
77 $pname =~ s/[\s\-]/_/g;
80 ## If the project has a '*' we need to have MPC fix that up for
82 $pname = Creator
::fill_type_name
(undef, $pname, $def);
83 push(@lines, "project$parents {");
85 elsif ($line =~ /^(shared|static)name\s*=\s*(.+)$/) {
86 ## Add in the libs and after settings.
88 if (defined $pname && $lib ne '') {
89 push(@lines, " libs += $2",
98 ## Only return the lines if there is more than one line. It is
99 ## possible (and likely) that we've read in the project declaration,
100 ## but the project did not contain a sharedname or staticname
102 return @lines if ($#lines > 0);
110 my @lines = gather_info
($in);
114 print STDERR
"ERROR: $out already exists\n";
117 my $fh = new FileHandle
();
118 if (open($fh, ">$out")) {
119 foreach my $line (@lines) {
124 ## Everything was ok, return zero.
128 print STDERR
"ERROR: Unable to write to $out\n";
134 print STDERR
"ERROR: $in is not a valid MPC file\n";
137 print STDERR
"ERROR: Unable to read from $in\n";
141 ## Non-zero indicates an error (as in the shell $? value).
147 print STDERR
"$str\n" if (defined $str);
148 print STDERR
"Create Base Project v$version\n",
149 "Usage: ", basename
($0), " <mpc files> <output file or ",
150 "directory>\n\nThis script will create a base project ",
151 "based on the contents of the\nsupplied MPC file. ",
152 "This is only useful if the project ",
153 "explicitly sets\nsharedname or staticname.\n";
157 # ******************************************************************
159 # ******************************************************************
162 ## Get the last argument and make sure it's a directory.
163 my $dir = pop(@ARGV);
165 usageAndExit
("Creating multiple base projects, but the " .
166 "last argument, $dir, is not a directory");
169 ## Process each input file and create the base project with an implicit
170 ## base project file name.
172 foreach my $input (@ARGV) {
173 my $output = $dir . '/' . lc(basename
($input));
174 $output =~ s/mpc$/mpb/;
175 $status += write_base
($input, $output);
183 ## Print the usage and exit if there is no input, output or the input
184 ## file looks like an option.
185 usageAndExit
() if (!defined $output ||
186 !defined $input || index($input, '-') == 0);
188 ## If the output file is a directory, we will create the output file
189 ## name based on the input file.
191 $output .= '/' . lc(basename
($input));
192 $output =~ s/mpc$/mpb/;
195 ## Create the base project and return the status to the caller of the
197 exit(write_base
($input, $output));