NCBI C Toolkit Cross Reference

C/make/make_xml_proj.txt


  1 #!c:/perl/bin/perl.exe
  2 # This script will create the CodeWarrior projects for the C Toolkit Windows build.
  3 
  4 require Cwd;
  5 
  6 use Win32::OLE;
  7 
  8 $build_all = 0;
  9 #get args
 10 while ($arg = shift) {
 11   if ($arg =~ /\-b/) {
 12     $build_all = 1;
 13   } else {
 14     $project_list = $arg;
 15   }
 16 }
 17 
 18 
 19 #Setup
 20 #Current working directory should be distrib\make
 21 $cwd = Cwd::getcwd();
 22 $cwd =~ s/\//\\/g;
 23 
 24 $distrib_root = $cwd;
 25 $distrib_root =~ s/\\[^\\]*$//;
 26 
 27 if (! -d "$distrib_root\\build") {
 28   mkdir ("$distrib_root\\build") || die "Unable to make build directory\n";
 29 }
 30 if (! -d "$distrib_root\\lib") {
 31   mkdir ("$distrib_root\\lib") || die "Unable to make lib directory\n";
 32 }
 33 
 34 #start CodeWarrior
 35 $CW = Win32::OLE->new("CodeWarrior.CodeWarriorApp");
 36 die "Unable to get app reference\n" unless $CW;
 37 
 38 #Create Projects
 39 open (PROJECTLIST, "$project_list") || die "Can't open $project_list\n";
 40 $project_name = "";
 41 $project = 0;
 42 while ($thisline = <PROJECTLIST>) {
 43   chop $thisline;
 44   if ($thisline =~ /(\S+)\s*:\s*/) {
 45     $new_project_name = $1;
 46     $new_dirs = $';
 47     if ($project_name) {
 48       # build previous project
 49       &build_project_xml ($CW, $project_name, $distrib_root, $build_all,
 50                           scalar (@files), @files,
 51                           scalar (@includes), @includes, 
 52                           scalar (@defines), @defines,
 53                           scalar (@libs), @libs,
 54                           scalar (@syslibs), @syslibs);
 55       @files = ();
 56       @includes = ();
 57       @defines = ();
 58       @libs = ();
 59       @syslibs = ();
 60     }
 61     $project_name = $new_project_name;
 62     $dirs = $new_dirs;
 63     # create project
 64     print "create project $project_name\n";
 65   } else {
 66     $dirs = $thisline;
 67   }
 68   @dirlist = split (/;/, $dirs);
 69   foreach $dir (@dirlist) {
 70     if ($dir =~ /^\s*\-I\s+/) {
 71       $paths = $';
 72       push (@includes, split (/\s+/, $paths));
 73     } elsif ($dir =~ /^\s*\-D\s*/) {
 74       $paths = $';
 75       push (@defines, split (/\s+/, $paths));
 76     } elsif ($dir =~ /^\s*\-L\s*/) {
 77       $paths = $';
 78       push (@libs, split (/\s+/, $paths));
 79     } elsif ($dir =~ /^\s*\-S\s*/) {
 80       $paths = $';
 81       push (@syslibs, split (/\s+/, $paths));
 82     } elsif ($dir =~ /(\S+),\s*/) {
 83       $dir_name = $1;
 84       $ex_files = $';
 85       @ex_files = split (/\s+/, $ex_files);
 86       # add this directory to the includes
 87       push (@includes, $dir_name);
 88       # add all files in directory to project except those listed 
 89       $dir_name = "$distrib_root\\$dir_name";
 90       push (@files, &dir_to_project ($dir_name, @ex_files));
 91     } else {
 92       $dir_name = "$distrib_root\\$dir";
 93       if (-d $dir_name) {
 94         # add this directory to the includes
 95         push (@includes, $dir);
 96         # add all files in directory to project
 97         push (@files, &dir_to_project ($dir_name));
 98       } else {
 99         # add file to project
100         $file_name = $dir;
101         push (@files, $file_name);
102       }
103     }
104   }      
105 }
106 close (PROJECTLIST);
107 
108 if ($project_name) {
109   &build_project_xml ($CW, $project_name, $distrib_root, $build_all,
110                       scalar (@files), @files,
111                       scalar (@includes), @includes, 
112                       scalar (@defines), @defines,
113                       scalar (@libs), @libs,
114                       scalar (@syslibs), @syslibs);
115 }
116 
117 sub project_file_from_project_name
118 {
119   my ($distrib_root) = shift (@_);
120   my ($project_name) = shift (@_);
121   my ($project_file) = "";
122   my ($project_dir);
123 
124   if ($project_name =~ /\.lib/) {
125     $project_dir = "$distrib_root\\lib";
126   } else {
127     $project_dir = "$distrib_root\\build";
128   }
129   $project_file = $project_name;
130   #truncate extension
131   $project_file =~ s/\..*$//;
132   $project_file = "$project_dir\\$project_file.mcp";
133   return $project_file;
134 }
135 
136 sub build_project_xml
137 {
138   my ($CW) = shift (@_);
139   my ($project_name) = shift (@_);
140   my ($distrib_root) = shift (@_);
141   my ($build_all) = shift (@_);
142   my ($num_files) = shift (@_);
143   my (@files) = splice (@_, 0, $num_files);
144   my ($num_includes) = shift (@_);
145   my (@includes) = splice (@_, 0, $num_includes);
146   my ($num_defines) = shift (@_);
147   my (@defines) = splice (@_, 0, $num_defines);
148   my ($num_libs) = shift (@_);
149   my (@libs) = splice (@_, 0, $num_libs);
150   my ($num_syslibs) = shift (@_);
151   my (@syslibs) = splice (@_, 0, $num_syslibs);
152   my ($project_file) = &project_file_from_project_name ($distrib_root, $project_name);
153   my ($proj_xml) = $project_file . ".xml";
154   my ($stationery_file);
155   my ($thisline);
156   my ($project);
157   my ($messages);
158 
159   print "$project_name: $num_files files, $num_includes includes, $num_defines defines, $num_libs libs $num_syslibs syslibs\n";
160 
161   if (-f $project_file) {
162     print "Project already exists\n";
163     if ($build_all) {
164       $project = $CW->OpenProject ($project_file, true, 0, 0);
165       if (! $project) {
166         die "Unable to open $project_file\n";
167       }
168     }
169   } else {
170     if ($project_name =~ /\.lib/) {
171       $stationery_file = "$distrib_root\\link\\winmet\\LibraryStationery\\LibraryStationery.mcp.xml";
172     } else {
173       $stationery_file = "$distrib_root\\link\\winmet\\ApplicationStationery\\GUIAppDefaults.mcp.xml";
174     }
175 
176     open (XML_IN, $stationery_file) || die "Can't open $stationery_file\n";
177     open (XML_OUT, ">$proj_xml") || die "Can't open $proj_xml\n";
178     $thisline = &copy_to_replace_point();
179     while ($thisline) {
180       if (&line_has_setting_name($thisline, "UserSearchPaths")) {
181         &write_xml_user_paths (@includes);
182       } elsif (&line_has_setting_name ($thisline, "C_CPP_Preprocessor_PrefixText")) {
183         &write_prefix_text (@defines);
184       } elsif ($thisline =~ /\<FILELIST\>/) {
185         &write_file_text ("Debug", scalar(@files), @files,
186                         scalar (@libs), @libs, scalar (@syslibs), @syslibs);
187       } elsif ($thisline =~ /\<GROUPLIST\>/) {
188         if ($project_name =~ /\.lib/) {
189           @targets = ("Win32 x86 DLL Debug");
190         } else {
191           @targets = ("Debug Win32 x86");
192         }
193         &write_group_list (scalar (@targets), @targets,
194                            scalar (@files), @files,
195                            scalar (@libs), @libs,
196                            scalar (@syslibs), @syslibs);
197       }
198 
199       $thisline = &skip_to_continue ($thisline);
200       print XML_OUT $thisline;
201       $thisline = &copy_to_replace_point($project_name);
202     }
203     close (XML_OUT);
204     close (XML_IN);
205 
206     $project = $CW->ImportProject ($proj_xml, $project_file, true);
207     if (! $project) {
208       die "Unable to create $project_file\n";
209     }
210   }
211   if ($project) {
212     $messages = &build_debug ($project);
213     &print_build_messages ($messages);
214     $project->Close();
215   }
216 }
217 
218 sub build_debug
219 {
220   my ($project) = shift (@_);
221   my ($targets);
222   my ($num_targets);
223   my ($debug_target);
224   my ($messages);
225 
226   $targets = $project->Targets();
227   if (! $targets) {
228     die "Project has no targets\n";
229   }
230   $num_targets = $targets->Count();
231   if ($num_targets == 0) {
232     die "Project has no targets\n";
233   }
234   $debug_target = $targets->Item(0);
235   $messages = $debug_target->BuildAndWaitToComplete();
236   return $messages;    
237 }
238 
239 sub print_build_messages
240 {
241   my ($messages) = shift (@_);
242   my ($errors);
243   my ($numerrors);
244   my ($warnings);
245   my ($num_warnings);
246   my ($informations);
247   my ($numinformations);
248   my ($definitions);
249   my ($numdefinitions);
250 
251   $errors = $messages->Errors();
252   $numerrors = $messages->ErrorCount();
253   $warnings = $messages->Warnings();
254   $numwarnings = $messages->WarningCount();
255   $informations = $messages->Informations();
256   $numinformations = $messages->InformationCount();
257   $definitions = $messages->Definitions();
258   $numdefinitions = $messages->DefinitionCount();
259 
260   print "$numerrors errors, $numwarnings warnings\n";
261   if ($numerrors > 0) {
262     die "Encountered errors\n";
263   }
264 }
265 
266 sub copy_to_replace_point
267 {
268   my ($project_name) = shift (@_);
269   my ($thisline);
270 
271   while ($thisline = <XML_IN>) {
272     if (&line_has_setting_name ($thisline, "UserSearchPaths")
273         || &line_has_setting_name ($thisline, "C_CPP_Preprocessor_PrefixText")
274         || $thisline =~ /\<FILELIST\>/
275         || $thisline =~ /\<GROUPLIST\>/) {
276       return $thisline;
277     } elsif (&line_has_setting_name ($thisline, "AlwaysSearchUserPaths")) {
278       $thisline =~ s/false/true/;
279       print XML_OUT $thisline;
280     } elsif (&line_has_setting_name ($thisline, "SourceRelativeIncludes")) {
281       $thisline =~ s/false/true/;
282       print XML_OUT $thisline;
283     } elsif (&line_has_setting_name ($thisline, "MWProject_X86_outfile")) {
284       $thisline =~ s/\<VALUE\>.*\<\/VALUE\>/\<VALUE\>$project_name\<\/VALUE\>/;
285       print XML_OUT $thisline;
286     } else {
287       print XML_OUT $thisline;
288     }
289   }
290   return 0;
291 }
292 
293 sub skip_to_continue
294 {
295   my ($skip_type) = shift (@_);
296   my ($thisline);
297 
298   if (&line_has_setting_name ($skip_type, "UserSearchPaths")) {
299     while ($thisline = <XML_IN>) {
300       if (&line_has_setting_name ($thisline, "SystemSearchPaths")) {
301         return $thisline;
302       }
303     }
304   } elsif ($skip_type =~ /\<FILELIST\>/) {
305     while ($thisline = <XML_IN>) {
306       if ($thisline =~ /\<\/LINKORDER\>/) {
307         $thisline = <XML_IN>;
308         return $thisline;
309       }
310     }
311   } elsif ($skip_type =~ /\<GROUPLIST\>/) {
312     while ($thisline = <XML_IN>) {
313       if ($thisline =~ /\<\/GROUPLIST\>/) {
314         $thisline = <XML_IN>;
315         return $thisline;
316       }
317     }    
318   } else {
319     $thisline = <XML_IN>;
320     return $thisline;
321   }
322 }
323 
324 sub line_has_setting_name
325 {
326   my ($thisline) = shift (@_);
327   my ($setting_name) = shift (@_);
328   my ($this_name);
329 
330   if ($thisline =~ /\<SETTING\>\<NAME\>([^\<]*)\<\/NAME\>/) {
331     $this_name = $1;
332     if ($this_name eq $setting_name) {
333       return 1;
334     } else {
335       return 0;
336     }
337   } else {
338     return 0;
339   }
340 }
341 
342 sub write_xml_user_paths
343 {
344   my (@includes) = @_;
345   my ($path);
346   print XML_OUT "                <SETTING><NAME>UserSearchPaths</NAME>\n";
347   &write_one_xml_user_path ("");
348   &write_one_xml_user_path ("..");
349   foreach $path (@includes) {
350     &write_one_xml_user_path ("..\\$path");
351   }
352   print XML_OUT "                </SETTING>\n";
353 }
354 
355 sub write_one_xml_user_path
356 {
357   my ($path) = shift (@_);
358 
359   print XML_OUT "                    <SETTING>\n";
360   print XML_OUT "                        <SETTING><NAME>SearchPath</NAME>\n";
361   print XML_OUT "                            <SETTING><NAME>Path</NAME><VALUE>$path</VALUE></SETTING>\n";
362   print XML_OUT "                            <SETTING><NAME>PathFormat</NAME><VALUE>Windows</VALUE></SETTING>\n";
363   print XML_OUT "                            <SETTING><NAME>PathRoot</NAME><VALUE>Project</VALUE></SETTING>\n";
364   print XML_OUT "                        </SETTING>\n";
365   print XML_OUT "                        <SETTING><NAME>Recursive</NAME><VALUE>true</VALUE></SETTING>\n";
366   print XML_OUT "                        <SETTING><NAME>FrameworkPath</NAME><VALUE>false</VALUE></SETTING>\n";
367   print XML_OUT "                        <SETTING><NAME>HostFlags</NAME><VALUE>All</VALUE></SETTING>\n";
368   print XML_OUT "                    </SETTING>\n";
369 }
370 
371 sub write_prefix_text
372 {
373   my (@defines) = @_;
374   my ($define);
375   print XML_OUT "                <SETTING><NAME>C_CPP_Preprocessor_PrefixText</NAME><VALUE>";
376   foreach $define (@defines) {
377     print XML_OUT "#define $define\n";
378   }
379   print XML_OUT "</VALUE></SETTING>\n";
380 
381 }
382 
383 sub write_file_text
384 {
385   my ($file_flags) = shift (@_);
386   my ($num_files) = shift (@_);
387   my (@files) = splice (@_, 0, $num_files);
388   my ($num_libs) = shift (@_);
389   my (@libs) = splice (@_, 0, $num_libs);
390   my ($num_syslibs) = shift (@_);
391   my (@syslibs) = splice (@_, 0, $num_syslibs);
392   my ($file, $lib, $syslib, $libproj);
393   print XML_OUT "            <FILELIST>\n";
394   foreach $file (@files) {
395     &write_one_file_text ($file, $file_flags);
396   }
397   foreach $lib (@libs) {
398     $libproj = $lib;
399     $libproj =~ s/\.lib/\.mcp/;
400     &write_one_file_text ($libproj, $file_flags);
401     if ($file_flags) {
402       &write_one_file_text ($lib, "$file_flags, TargetOutputFile");
403     } else {
404       &write_one_file_text ($lib, "TargetOutputFile");
405     }
406   }
407   foreach $syslib (@syslibs) {
408     &write_one_file_text ($syslib, $file_flags);
409   }    
410   print XML_OUT "            </FILELIST>\n";
411 
412   print XML_OUT "            <LINKORDER>\n";
413   foreach $file (@files) {
414     &write_one_file_link ($file);
415   }
416   foreach $lib (@libs) {
417     &write_one_file_link ($lib);
418   }
419   foreach $syslib (@syslibs) {
420     &write_one_file_link ($syslib);
421   }
422   print XML_OUT "            </LINKORDER>\n";
423   if ($num_libs) {
424     &write_subprojects ("WIN32 x86 DLL Debug", @libs);
425   }
426 }
427 
428 sub write_one_file_text
429 {
430   my ($file) = shift (@_);
431   my ($file_flags) = shift (@_);
432   my ($filekind);
433 
434   if ($file =~ /\.lib/) {
435     $filekind = "Library";
436   } elsif ($file =~ /\.mcp/) {
437     $filekind = "Project";
438   } else {
439     $filekind = "Text";
440   }
441   print XML_OUT "                <FILE>\n";
442   print XML_OUT "                    <PATHTYPE>Name</PATHTYPE>\n";
443   print XML_OUT "                    <PATH>$file</PATH>\n";
444   print XML_OUT "                    <PATHFORMAT>Windows</PATHFORMAT>\n";
445   print XML_OUT "                    <FILEKIND>$filekind</FILEKIND>\n";
446   print XML_OUT "                    <FILEFLAGS>$file_flags</FILEFLAGS>\n";
447   print XML_OUT "                </FILE>\n";
448 }
449 
450 sub write_one_file_link
451 {
452   my ($file) = shift (@_);
453   my ($target_name) = shift (@_);
454   print XML_OUT "                <FILEREF>\n";
455   if ($target_name) {
456     print XML_OUT "            <TARGETNAME>$target_name</TARGETNAME>\n";
457   }
458   print XML_OUT "                    <PATHTYPE>Name</PATHTYPE>\n";
459   print XML_OUT "                    <PATH>$file</PATH>\n";
460   print XML_OUT "                    <PATHFORMAT>Windows</PATHFORMAT>\n";
461   print XML_OUT "                </FILEREF>\n";
462 }
463 
464 sub write_subprojects
465 {
466   my ($target) = shift (@_);
467   my (@libs) = @_;
468   my ($lib);
469   
470   print XML_OUT "            <SUBPROJECTLIST>\n";
471   foreach $lib (@libs) {
472     &write_one_subproject($lib, $target);
473   }
474   print XML_OUT "            </SUBPROJECTLIST>\n";
475 }
476 
477 sub write_one_subproject
478 {
479   my ($lib) = shift (@_);
480   my ($target) = shift (@_);
481   my ($libproj) = $lib;
482 
483   $libproj =~ s/\.lib/\.mcp/;
484 
485   print XML_OUT "                <SUBPROJECT>\n";
486   print XML_OUT "                    <FILEREF>\n";
487   print XML_OUT "                        <PATHTYPE>Name</PATHTYPE>\n";
488   print XML_OUT "                        <PATH>$libproj</PATH>\n";
489   print XML_OUT "                        <PATHFORMAT>Windows</PATHFORMAT>\n";
490   print XML_OUT "                    </FILEREF>\n";
491   print XML_OUT "                    <SUBPROJECTTARGETLIST>\n";
492   print XML_OUT "                        <SUBPROJECTTARGET>\n";
493   print XML_OUT "                            <TARGETNAME>$target</TARGETNAME>\n";
494   print XML_OUT "                            <ATTRIBUTES>LinkAgainst</ATTRIBUTES>\n";
495   print XML_OUT "                            <FILEREF>\n";
496   print XML_OUT "                                <PATHTYPE>Name</PATHTYPE>\n";
497   print XML_OUT "                                <PATH>$lib</PATH>\n";
498   print XML_OUT "                                <PATHFORMAT>Windows</PATHFORMAT>\n";
499   print XML_OUT "                            </FILEREF>\n";
500   print XML_OUT "                        </SUBPROJECTTARGET>\n";
501   print XML_OUT "                    </SUBPROJECTTARGETLIST>\n";
502   print XML_OUT "                </SUBPROJECT>\n";
503 }
504 
505 sub write_group_list
506 {
507   my ($num_targets) = shift (@_);
508   my (@targets) = splice (@_, 0, $num_targets);
509   my ($num_files) = shift (@_);
510   my (@files) = splice (@_, 0, $num_files);
511   my ($num_libs) = shift (@_);
512   my (@libs) = splice (@_, 0, $num_libs);
513   my ($num_syslibs) = shift (@_);
514   my (@syslibs) = splice (@_, 0, $num_syslibs);
515   my ($target, $file, $lib, $libproj, $syslib);
516 
517   print XML_OUT "    <GROUPLIST>\n";
518   print XML_OUT "        <GROUP><NAME>Source</NAME>\n";
519   print XML_OUT "        </GROUP>\n";
520 
521   foreach $target (@targets) {
522     foreach $file (@files) {
523       &write_one_file_link ($file, $target);
524     }
525     foreach $lib (@libs) {
526       $libproj = $lib;
527       $libproj =~ s/\.lib/\.mcp/;
528       &write_one_file_link ($libproj, $target);
529       &write_one_file_link ($lib, $target);
530     }
531     foreach $syslib (@syslibs) {
532       &write_one_file_link ($syslib, $target);
533     }   
534   }
535   print XML_OUT "    </GROUPLIST>\n";
536 }  
537 
538 sub is_dir_to_skip
539 {
540   my ($entry) = shift (@_);
541   my (@skip_files) = @_;
542   my ($badfile);
543 
544   foreach $badfile (@skip_files) {
545     if ($badfile eq $entry) {
546       return 1;
547     }
548   }    
549   return 0;
550 }
551 
552 sub dir_to_project
553 {
554   my ($entry) = shift (@_);
555   my (@skip_files) = @_;
556   my (@files) = ();
557   my (@subdirs) = ();
558   my ($thisentry);
559 
560   if (! -d $entry) {
561     print "$entry is not a directory\n";
562     return;
563   }
564   if (-s $entry) {
565     print "$entry exists\n";
566   }
567   opendir (MYDIR, $entry) || die "Can't open $entry ($!)\n";
568   while ($thisentry = readdir(MYDIR)) {
569     if (&is_dir_to_skip ($thisentry, @skip_files)) {
570       # do nothing
571     } elsif (-d $thisentry) {
572       # do nothing
573     } elsif ($thisentry =~ /\.c$/) {
574       push(@files, $thisentry);
575     }
576   }
577   closedir (MYDIR);
578   return @files;
579 }

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.