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)) {
51 ## Get the line a remove leading and trailing white space
56 ## Look for the project declaration and pull out the name and any
58 if ($line =~ /^project\s*(\(([^\)]+)\))?\s*(:.+)?\s*{$/) {
60 my $parents = $3 || '';
62 ## Create the default project name by removing the extension and
63 ## converting back-slashes, spaces and dashes to underscores.
64 ## This needs to be done regardless of whether the project name
65 ## was provided or not since it's used below in the
66 ## fill_type_name call.
67 my $def = basename
($name);
68 $def =~ s/\.[^\.]+$//;
72 if (!defined $pname || $pname eq '') {
73 ## Take the default project name since one wasn't provided.
77 ## Convert back-slashes, spaces and dashes to underscores.
79 $pname =~ s/[\s\-]/_/g;
82 ## If the project has a '*' we need to have MPC fix that up for
84 $pname = Creator
::fill_type_name
(undef, $pname, $def);
85 push(@lines, "project$parents {");
88 elsif ($line =~ /^(shared|static)name\s*=\s*(.+)$/) {
89 ## Add in the libs and after settings.
91 if (defined $pname && $lib ne '') {
92 push(@lines, " libs += $2",
101 ## If we have the unmodified project name, but the user did not provide
102 ## a sharedname or staticname, we will use that as the library name.
103 if (defined $pline && $#lines == 0) {
104 push(@lines, " libs += $pline",
109 ## Only return the lines if there is more than one line.
110 return @lines if ($#lines > 0);
118 my @lines = gather_info
($in);
122 print STDERR
"ERROR: $out already exists\n";
125 my $fh = new FileHandle
();
126 if (open($fh, ">$out")) {
127 foreach my $line (@lines) {
132 ## Everything was ok, return zero.
136 print STDERR
"ERROR: Unable to write to $out\n";
142 print STDERR
"ERROR: $in is not a valid MPC file\n";
145 print STDERR
"ERROR: Unable to read from $in\n";
149 ## Non-zero indicates an error (as in the shell $? value).
155 print STDERR
"$str\n" if (defined $str);
156 print STDERR
"Create Base Project v$version\n",
157 "Usage: ", basename
($0), " <mpc files> <output file or ",
158 "directory>\n\nThis script will create a base project ",
159 "based on the contents of the\nsupplied MPC file.\n";
163 # ******************************************************************
165 # ******************************************************************
168 ## Get the last argument and make sure it's a directory.
169 my $dir = pop(@ARGV);
171 usageAndExit
("Creating multiple base projects, but the " .
172 "last argument, $dir, is not a directory");
175 ## Process each input file and create the base project with an implicit
176 ## base project file name.
178 foreach my $input (@ARGV) {
179 my $output = $dir . '/' . lc(basename
($input));
180 $output =~ s/mpc$/mpb/;
181 $status += write_base
($input, $output);
189 ## Print the usage and exit if there is no input, output or the input
190 ## file looks like an option.
191 usageAndExit
() if (!defined $output ||
192 !defined $input || index($input, '-') == 0);
194 ## If the output file is a directory, we will create the output file
195 ## name based on the input file.
197 $output .= '/' . lc(basename
($input));
198 $output =~ s/mpc$/mpb/;
201 ## Create the base project and return the status to the caller of the
203 exit(write_base
($input, $output));