winemaker: Fix wrong place for case-check.
[wine/hacks.git] / tools / winemaker
blob779523759954d2131f2ee73843de07c1a9a07581
1 #!/usr/bin/perl -w
2 use strict;
4 # Copyright 2000-2004 Francois Gouget for CodeWeavers
5 # Copyright 2004 Dimitrie O. Paun
6 # Copyright 2009 André Hentschel
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 my $version="0.7.0";
25 use Cwd;
26 use File::Basename;
27 use File::Copy;
31 #####
33 # Options
35 #####
37 # The following constants define what we do with the case of filenames
40 # Never rename a file to lowercase
41 my $OPT_LOWER_NONE=0;
44 # Rename all files to lowercase
45 my $OPT_LOWER_ALL=1;
48 # Rename only files that are all uppercase to lowercase
49 my $OPT_LOWER_UPPERCASE=2;
52 # The following constants define whether to ask questions or not
55 # No (synonym of never)
56 my $OPT_ASK_NO=0;
59 # Yes (always)
60 my $OPT_ASK_YES=1;
63 # Skip the questions till the end of this scope
64 my $OPT_ASK_SKIP=-1;
67 # General options
70 # This is the directory in which winemaker will operate.
71 my $opt_work_dir;
74 # This is the file in which winemaker will operate if a project file is specified.
75 my $opt_work_file;
78 # Make a backup of the files
79 my $opt_backup;
82 # Defines which files to rename
83 my $opt_lower;
86 # If we don't find the file referenced by an include, lower it
87 my $opt_lower_include;
90 # If true then winemaker should not attempt to fix the source. This is
91 # useful if the source is known to be already in a suitable form and is
92 # readonly
93 my $opt_no_source_fix;
95 # Options for the 'Source' method
98 # Specifies that we have only one target so that all sources relate
99 # to this target. By default this variable is left undefined which
100 # means winemaker should try to find out by itself what the targets
101 # are. If not undefined then this contains the name of the default
102 # target (without the extension).
103 my $opt_single_target;
106 # If '$opt_single_target' has been specified then this is the type of
107 # that target. Otherwise it specifies whether the default target type
108 # is guiexe or cuiexe.
109 my $opt_target_type;
112 # Contains the default set of flags to be used when creating a new target.
113 my $opt_flags;
116 # If true then winemaker should ask questions to the user as it goes
117 # along.
118 my $opt_is_interactive;
119 my $opt_ask_project_options;
120 my $opt_ask_target_options;
123 # If false then winemaker should not generate the makefiles.
124 my $opt_no_generated_files;
127 # Specifies not to print the banner if set.
128 my $opt_no_banner;
132 #####
134 # Target modelization
136 #####
138 # The description of a target is stored in an array. The constants
139 # below identify what is stored at each index of the array.
142 # This is the name of the target.
143 my $T_NAME=0;
146 # Defines the type of target we want to build. See the TT_xxx
147 # constants below
148 my $T_TYPE=1;
151 # This is a bitfield containing flags refining the way the target
152 # should be handled. See the TF_xxx constants below
153 my $T_FLAGS=2;
156 # This is a reference to an array containing the list of the
157 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
158 my $T_SOURCES_C=3;
159 my $T_SOURCES_CXX=4;
160 my $T_SOURCES_RC=5;
161 my $T_SOURCES_MISC=6;
164 # This is a reference to an array containing the list of
165 # C compiler options
166 my $T_CEXTRA=7;
169 # This is a reference to an array containing the list of
170 # C++ compiler options
171 my $T_CXXEXTRA=8;
174 # This is a reference to an array containing the list of
175 # RC compiler options
176 my $T_RCEXTRA=9;
179 # This is a reference to an array containing the list of macro
180 # definitions
181 my $T_DEFINES=10;
184 # This is a reference to an array containing the list of directory
185 # names that constitute the include path
186 my $T_INCLUDE_PATH=11;
189 # Flags for the linker
190 my $T_LDFLAGS=12;
193 # Same as T_INCLUDE_PATH but for the dll search path
194 my $T_DLL_PATH=13;
197 # The list of Windows dlls to import
198 my $T_DLLS=14;
201 # Same as T_INCLUDE_PATH but for the library search path
202 my $T_LIBRARY_PATH=15;
205 # The list of Unix libraries to link with
206 my $T_LIBRARIES=16;
209 # The list of dependencies between targets
210 my $T_DEPENDS=17;
213 # The following constants define the recognized types of target
216 # This is not a real target. This type of target is used to collect
217 # the sources that don't seem to belong to any other target. Thus no
218 # real target is generated for them, we just put the sources of the
219 # fake target in the global source list.
220 my $TT_SETTINGS=0;
223 # For executables in the windows subsystem
224 my $TT_GUIEXE=1;
227 # For executables in the console subsystem
228 my $TT_CUIEXE=2;
231 # For dynamically linked libraries
232 my $TT_DLL=3;
235 # The following constants further refine how the target should be handled
238 # This target is an MFC-based target
239 my $TF_MFC=4;
242 # User has specified --nomfc option for this target or globally
243 my $TF_NOMFC=8;
246 # --nodlls option: Do not use standard DLL set
247 my $TF_NODLLS=16;
250 # --nomsvcrt option: Do not link with msvcrt
251 my $TF_NOMSVCRT=32;
254 # Initialize a target:
255 # - set the target type to TT_SETTINGS, i.e. no real target will
256 # be generated.
257 sub target_init($)
259 my $target=$_[0];
261 @$target[$T_TYPE]=$TT_SETTINGS;
262 # leaving $T_INIT undefined
263 @$target[$T_FLAGS]=$opt_flags;
264 @$target[$T_SOURCES_C]=[];
265 @$target[$T_SOURCES_CXX]=[];
266 @$target[$T_SOURCES_RC]=[];
267 @$target[$T_SOURCES_MISC]=[];
268 @$target[$T_CEXTRA]=[];
269 @$target[$T_CXXEXTRA]=[];
270 @$target[$T_RCEXTRA]=[];
271 @$target[$T_DEFINES]=[];
272 @$target[$T_INCLUDE_PATH]=[];
273 @$target[$T_LDFLAGS]=[];
274 @$target[$T_DLL_PATH]=[];
275 @$target[$T_DLLS]=[];
276 @$target[$T_LIBRARY_PATH]=[];
277 @$target[$T_LIBRARIES]=[];
282 #####
284 # Project modelization
286 #####
288 # First we have the notion of project. A project is described by an
289 # array (since we don't have structs in perl). The constants below
290 # identify what is stored at each index of the array.
293 # This is the path in which this project is located. In other
294 # words, this is the path to the Makefile.
295 my $P_PATH=0;
298 # This index contains a reference to an array containing the project-wide
299 # settings. The structure of that arrray is actually identical to that of
300 # a regular target since it can also contain extra sources.
301 my $P_SETTINGS=1;
304 # This index contains a reference to an array of targets for this
305 # project. Each target describes how an executable or library is to
306 # be built. For each target this description takes the same form as
307 # that of the project: an array. So this entry is an array of arrays.
308 my $P_TARGETS=2;
311 # Initialize a project:
312 # - set the project's path
313 # - initialize the target list
314 # - create a default target (will be removed later if unnecessary)
315 sub project_init($$$)
317 my ($project, $path, $global_settings)=@_;
319 my $project_settings=[];
320 target_init($project_settings);
321 @$project_settings[$T_DEFINES]=[@{@$global_settings[$T_DEFINES]}];
322 @$project_settings[$T_INCLUDE_PATH]=[@{@$global_settings[$T_INCLUDE_PATH]}];
323 @$project_settings[$T_DLL_PATH]=[@{@$global_settings[$T_DLL_PATH]}];
324 @$project_settings[$T_DLLS]=[@{@$global_settings[$T_DLLS]}];
325 @$project_settings[$T_LIBRARY_PATH]=[@{@$global_settings[$T_LIBRARY_PATH]}];
326 @$project_settings[$T_LIBRARIES]=[@{@$global_settings[$T_LIBRARIES]}];
328 @$project[$P_PATH]=$path;
329 @$project[$P_SETTINGS]=$project_settings;
330 @$project[$P_TARGETS]=[];
335 #####
337 # Global variables
339 #####
341 my %warnings;
343 my %templates;
346 # This maps a directory name to a reference to an array listing
347 # its contents (files and directories)
348 my %directories;
351 # Contains the list of all projects. This list tells us what are
352 # the subprojects of the main Makefile and where we have to generate
353 # Makefiles.
354 my @projects=();
357 # This is the main project, i.e. the one in the "." directory.
358 # It may well be empty in which case the main Makefile will only
359 # call out subprojects.
360 my @main_project;
363 # Contains the defaults for the include path, etc.
364 # We store the defaults as if this were a target except that we only
365 # exploit the defines, include path, library path, library list and misc
366 # sources fields.
367 my @global_settings;
371 #####
373 # Utility functions
375 #####
378 # Cleans up a name to make it an acceptable Makefile
379 # variable name.
380 sub canonize($)
382 my $name=$_[0];
384 $name =~ tr/a-zA-Z0-9_/_/c;
385 return $name;
389 # Returns true is the specified pathname is absolute.
390 # Note: pathnames that start with a variable '$' or
391 # '~' are considered absolute.
392 sub is_absolute($)
394 my $path=$_[0];
396 return ($path =~ /^[\/~\$]/);
400 # Performs a binary search looking for the specified item
401 sub bsearch($$)
403 my $array=$_[0];
404 my $item=$_[1];
405 my $last=@{$array}-1;
406 my $first=0;
408 while ($first<=$last) {
409 my $index=int(($first+$last)/2);
410 my $cmp=@$array[$index] cmp $item;
411 if ($cmp<0) {
412 $first=$index+1;
413 } elsif ($cmp>0) {
414 $last=$index-1;
415 } else {
416 return $index;
422 # Retrieves the contents of the specified directory.
423 # We either get it from the directories hashtable which acts as a
424 # cache, or use opendir, readdir, closedir and store the result
425 # in the hashtable.
426 sub get_directory_contents($)
428 my $dirname=$_[0];
429 my $directory;
431 #print "getting the contents of $dirname\n";
433 # check for a cached version
434 $dirname =~ s+/$++;
435 if ($dirname eq "") {
436 $dirname=cwd;
438 $directory=$directories{$dirname};
439 if (defined $directory) {
440 #print "->@$directory\n";
441 return $directory;
444 # Read this directory
445 if (opendir(DIRECTORY, "$dirname")) {
446 my @files=readdir DIRECTORY;
447 closedir(DIRECTORY);
448 $directory=\@files;
449 } else {
450 # Return an empty list
451 #print "error: cannot open $dirname\n";
452 my @files;
453 $directory=\@files;
455 #print "->@$directory\n";
456 $directories{$dirname}=$directory;
457 return $directory;
461 # Removes a directory from the cache.
462 # This is needed if one of its files or subdirectory has been renamed.
463 sub clear_directory_cache($)
465 my ($dirname)=@_;
466 delete $directories{$dirname};
470 #####
472 # 'Source'-based Project analysis
474 #####
477 # Allows the user to specify makefile and target specific options
478 # - target: the structure in which to store the results
479 # - options: the string containing the options
480 sub source_set_options($$)
482 my $target=$_[0];
483 my $options=$_[1];
485 #FIXME: we must deal with escaping of stuff and all
486 foreach my $option (split / /,$options) {
487 if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
488 push @{@$target[$T_DEFINES]},$option;
489 } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
490 push @{@$target[$T_INCLUDE_PATH]},$option;
491 } elsif ($option =~ /^-P/) {
492 push @{@$target[$T_DLL_PATH]},"-L$'";
493 } elsif ($option =~ /^-i/) {
494 push @{@$target[$T_DLLS]},"$'";
495 } elsif ($option =~ /^-L/) {
496 push @{@$target[$T_LIBRARY_PATH]},$option;
497 } elsif ($option =~ /^-l/) {
498 push @{@$target[$T_LIBRARIES]},"$'";
499 } elsif ($option =~ /^--mfc/) {
500 @$target[$T_FLAGS]|=$TF_MFC;
501 @$target[$T_FLAGS]&=~$TF_NOMFC;
502 } elsif ($option =~ /^--nomfc/) {
503 @$target[$T_FLAGS]&=~$TF_MFC;
504 @$target[$T_FLAGS]|=$TF_NOMFC;
505 } elsif ($option =~ /^--nodlls/) {
506 @$target[$T_FLAGS]|=$TF_NODLLS;
507 } elsif ($option =~ /^--nomsvcrt/) {
508 @$target[$T_FLAGS]|=$TF_NOMSVCRT;
509 } else {
510 print STDERR "error: unknown option \"$option\"\n";
511 return 0;
514 return 1;
518 # Scans the specified project file to:
519 # - get a list of targets for this project
520 # - get some settings
521 # - get the list of source files
522 sub source_scan_project_file($$$);
523 sub source_scan_project_file($$$)
525 # a reference to the parent's project
526 my $parent_project=$_[0];
527 # 0 if it is a single project, 1 if it is part of a workspace
528 my $is_sub_project=$_[1];
529 # the name of the project file, with complete path, or without if in
530 # the same directory
531 my $filename=$_[2];
533 # reference to the project for this file. May not be used
534 my $project;
535 # list of targets found in the current file
536 my %targets;
537 # list of sources found in the current file
538 my @sources_c=();
539 my @sources_cxx=();
540 my @sources_rc=();
541 my @sources_misc=();
542 # some more settings
543 my $path=dirname($filename);
544 my $prj_target_cflags;
545 my $prj_target_ldflags;
546 my $prj_target_libs;
547 my $prj_name;
548 my $found_cfg=0;
549 my $prj_cfg;
550 my $prj_target_type=1;
551 my @prj_target_options;
553 if (!($path=~/\/$/)) {
554 $path.="/";
557 if (defined $opt_single_target or $is_sub_project == 0) {
558 # Either there is a single target and thus a single project,
559 # or we are a single project-file for which a project
560 # already exists
561 $project=$parent_project;
562 } else {
563 $project=[];
564 project_init($project, $path, \@global_settings);
566 my $project_settings=@$project[$P_SETTINGS];
568 if ($filename =~ /.dsp$/i) {
569 # First find out what this project file contains:
570 # collect all sources, find targets and settings
571 if (!open(FILEI,$filename)) {
572 print STDERR "error: unable to open $filename for reading:\n";
573 print STDERR " $!\n";
574 return;
576 my $sfilet;
577 while (<FILEI>) {
578 # Remove any trailing CtrlZ, which isn't strictly in the file
579 if (/\x1A/) {
580 s/\x1A//;
581 last if (/^$/)
584 # Remove any trailing CrLf
585 s/\r\n$/\n/;
586 if (!/\n$/) {
587 # Make sure all lines are '\n' terminated
588 $_ .= "\n";
591 if (/^\# Microsoft Developer Studio Project File - Name=\"([^\"]+)/) {
592 $prj_name="$1.exe";
593 $targets{$prj_name}=1;
594 #print $prj_name;
595 next;
596 } elsif (/^# TARGTYPE/) {
597 if (/[[:space:]]0x0101$/) {
598 # Win32 (x86) Application
599 $prj_target_type=1;
600 }elsif (/[[:space:]]0x0102$/) {
601 # Win32 (x86) Dynamic-Link Library
602 $prj_target_type=3;
603 }elsif (/[[:space:]]0x0103$/) {
604 # Win32 (x86) Console Application
605 $prj_target_type=2;
606 }elsif (/[[:space:]]0x0104$/) {
607 # Win32 (x86) Static Library
609 next;
610 } elsif (/^# ADD CPP(.*)/ && $found_cfg==1) {
611 $prj_target_cflags=$1;
612 @prj_target_options=split(" /", $prj_target_cflags);
613 $prj_target_cflags="";
614 foreach ( @prj_target_options ) {
615 if ($_ eq "") {
616 # empty
617 } elsif (/nologo/) {
618 # Suppress Startup Banner and Information Messages
619 } elsif (/^W0$/) {
620 # Turns off all warning messages
621 $prj_target_cflags.="-w ";
622 } elsif (/^W[123]$/) {
623 # Warning Level
624 $prj_target_cflags.="-W ";
625 } elsif (/^W4$/) {
626 # Warning Level
627 $prj_target_cflags.="-Wall ";
628 } elsif (/^WX$/) {
629 # Warnings As Errors
630 $prj_target_cflags.="-Werror ";
631 } elsif (/^Gm$/) {
632 # Enable Minimal Rebuild
633 } elsif (/^GX$/) {
634 # Enable Exception Handling
635 $prj_target_cflags.="-fexceptions ";
636 } elsif (/^Z[d7iI]$/) {
637 # Debug Info
638 $prj_target_cflags.="-g ";
639 } elsif (/^Od$/) {
640 # Disable Optimizations
641 $prj_target_cflags.="-O0 ";
642 } elsif (/^O1$/) {
643 # Minimize Size
644 $prj_target_cflags.="-Os ";
645 } elsif (/^O2$/) {
646 # Maximize Speed
647 $prj_target_cflags.="-O2 ";
648 } elsif (/^Ob0$/) {
649 # Disables inline Expansion
650 $prj_target_cflags.="-fno-inline ";
651 } elsif (/^Ob1$/) {
652 # In-line Function Expansion
653 } elsif (/^Ob2$/) {
654 # auto In-line Function Expansion
655 $prj_target_cflags.="-finline-functions ";
656 } elsif (/^Oy$/) {
657 # Frame-Pointer Omission
658 $prj_target_cflags.="-fomit-frame-pointer ";
659 } elsif (/^GZ$/) {
660 # Catch Release-Build Errors in Debug Build
661 } elsif (/^M[DLT]d?$/) {
662 # Use Multithreaded Run-Time Library
663 } elsif (/^D\s*\"(.*)\"/) {
664 # Preprocessor Definitions
665 $prj_target_cflags.="-D".$1." ";
666 } elsif (/^I/) {
667 # Additional Include Directories
668 #$prj_target_cflags.="-I" fixpath(option)
669 } elsif (/^U\s*\"(.*)\"/) {
670 # Undefines a previously defined symbol
671 $prj_target_cflags.="-U".$1." ";
672 } elsif (/^Fp/) {
673 # Name .PCH File
674 } elsif (/^F[Rr]/) {
675 # Create .SBR File
676 } elsif (/^YX$/) {
677 # Automatic Use of Precompiled Headers
678 } elsif (/^FD$/) {
679 # Generate File Dependencies
680 } elsif (/^c$/) {
681 # Compile Without Linking
682 # this option is always present and is already specified in the suffix rules
683 } elsif (/^GB$/) {
684 # Blend Optimization
685 $prj_target_cflags.="-mcpu=pentiumpro -D_M_IX86=500 ";
686 } elsif (/^G6$/) {
687 # Pentium Pro Optimization
688 $prj_target_cflags.="-march=pentiumpro -D_M_IX86=600 ";
689 } elsif (/^G5$/) {
690 # Pentium Optimization
691 $prj_target_cflags.="-mcpu=pentium -D_M_IX86=500 ";
692 } elsif (/^G3$/) {
693 # 80386 Optimization
694 $prj_target_cflags.="-mcpu=i386 -D_M_IX86=300 ";
695 } elsif (/^G4$/) {
696 # 80486 Optimization
697 $prj_target_cflags.="-mcpu=i486 -D_M_IX86=400 ";
698 } elsif (/^Yc/) {
699 # Create Precompiled Header
700 } elsif (/^Yu/) {
701 # Use Precompiled Header
702 } elsif (/^Za$/) {
703 # Disable Language Extensions
704 $prj_target_cflags.="-ansi ";
705 } elsif (/^Ze$/) {
706 # Enable Microsoft Extensions
707 } elsif (/^Zm[[:digit:]]+$/) {
708 # Specify Memory Allocation Limit
709 } elsif (/^Zp1?$/) {
710 # Packs structures on 1-byte boundaries
711 $prj_target_cflags.="-fpack-struct ";
712 } elsif (/^Zp(2|4|8|16)$/) {
713 # Struct Member Alignment
714 $prj_target_cflags.="-fpack-struct=".$1;
715 } else {
716 print "C compiler option $_ not implemented\n";
720 #print "\nOptions: $prj_target_cflags\n";
721 next;
722 } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
723 $prj_target_ldflags=$1;
724 @prj_target_options=split(" /", $prj_target_ldflags);
725 $prj_target_ldflags="";
726 $prj_target_libs=$prj_target_options[0];
727 #print "\n$prj_target_libs bevor\n";
728 $prj_target_libs=~s/\\/\//g;
729 $prj_target_libs=~s/\.lib//g;
730 $prj_target_libs=~s/\s+/ -l/g;
731 #print "\n$prj_target_libs after\n";
732 shift (@prj_target_options);
733 foreach ( @prj_target_options ) {
734 if ($_ eq "") {
735 # empty
736 } elsif (/^base:(.*)/) {
737 # Base Address
738 $prj_target_ldflags.="--image-base ".$1." ";
739 } elsif (/^debug$/) {
740 # Generate Debug Info
741 } elsif (/^dll$/) {
742 # Build a DLL
743 $prj_target_type=3;
744 } elsif (/^incremental:[[:alpha:]]+$/) {
745 # Link Incrmentally
746 } elsif (/^implib:/) {
747 # Name import library
748 } elsif (/^libpath:\"(.*)\"/) {
749 # Additional Libpath
750 push @{@$project_settings[$T_DLL_PATH]},"-L$1";
751 } elsif (/^machine:[[:alnum:]]+$/) {
752 # Specify Target Platform
753 } elsif (/^map/) {
754 # Generate Mapfile
755 if (/^map:(.*)/) {
756 $prj_target_ldflags.="-Map ".$1." ";
757 } else {
758 $prj_target_ldflags.="-Map ".$prj_name.".map ";
760 } elsif (/^nologo$/) {
761 # Suppress Startup Banner and Information Messages
762 } elsif (/^out:/) {
763 # Output File Name
764 # may use it as Target?
765 } elsif (/^pdbtype:/) {
766 # Program Database Storage
767 } elsif (/^subsystem:/) {
768 # Specify Subsystem
769 } elsif (/^version:[[:digit:].]+$/) {
770 # Version Information
771 } else {
772 print "Linker option $_ not implemented\n";
775 next;
776 } elsif (/^LIB32=/ && $found_cfg==1) {
777 #$libflag = 1;
778 next;
779 } elsif (/^SOURCE=(.*)$/) {
780 my @components=split /[\/\\]+/, $1;
781 $sfilet=search_from($path, \@components);
782 if ($sfilet =~ /\.(exe|dll)$/i) {
783 $targets{$sfilet}=1;
784 } elsif ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
785 push @sources_c,$sfilet;
786 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
787 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
788 push @sources_misc,$sfilet;
789 @$project_settings[$T_FLAGS]|=$TF_MFC;
790 } else {
791 push @sources_cxx,$sfilet;
793 } elsif ($sfilet =~ /\.rc$/i) {
794 push @sources_rc,$sfilet;
795 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
796 push @sources_misc,$sfilet;
797 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
798 @$project_settings[$T_FLAGS]|=$TF_MFC;
801 next;
803 } elsif (/^# (Begin|End) Source File/) {
804 # Source-Files already handled
805 next;
806 } elsif (/^# (Begin|End) Group/) {
807 # Groups are ignored
808 next;
809 } elsif (/^# (Begin|End) Custom Build/) {
810 # Custom Builds are ignored
811 next;
812 } elsif (/^# ADD LIB32 /) {
813 #"ARFLAGS=rus"
814 next;
815 } elsif (/^# Begin Target$/) {
816 # Targets are ignored
817 next;
818 } elsif (/^# End Target$/) {
819 # Targets are ignored
820 next;
821 } elsif (/^!/) {
822 if ($found_cfg == 1) {
823 $found_cfg=0;
825 if (/if (.*)\(CFG\)" == "(.*)"/i) {
826 if ($2 eq $prj_cfg) {
827 $found_cfg=1;
830 next;
831 } elsif (/^CFG=(.*)/i) {
832 $prj_cfg=$1;
833 next;
835 else { # Line recognized
836 # print "|\n";
839 close(FILEI);
841 push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
842 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
843 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
844 push @{@$project_settings[$T_LDFLAGS]},$prj_target_ldflags;
845 } elsif ($filename =~ /.vcproj$/i) {
846 # Import des Moduls XML::Simple
847 use XML::Simple;
849 my $project_xml = XMLin($filename, forcearray=>1);
851 $targets{$project_xml->{'Name'}.".exe"}=1;
852 my $sfilet;
853 for my $vc_files (@{$project_xml->{'Files'}}) {
854 for my $vc_filter (@{$vc_files->{'Filter'}}) {
855 for my $vc_file (@{$vc_filter->{'File'}}) {
856 $sfilet=$vc_file->{'RelativePath'};
857 $sfilet=~s/\\\\/\\/g; #remove double backslash
858 $sfilet=~s/^\.\\//; #remove starting 'this directory'
859 $sfilet=~s/\\/\//g; #make slashes out of backslashes
860 if ($sfilet =~ /\.(exe|dll)$/i) {
861 $targets{$sfilet}=1;
862 } elsif ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
863 push @sources_c,$sfilet;
864 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
865 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
866 push @sources_misc,$sfilet;
867 @$project_settings[$T_FLAGS]|=$TF_MFC;
868 } else {
869 push @sources_cxx,$sfilet;
871 } elsif ($sfilet =~ /\.rc$/i) {
872 push @sources_rc,$sfilet;
873 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
874 push @sources_misc,$sfilet;
875 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
876 @$project_settings[$T_FLAGS]|=$TF_MFC;
882 $prj_target_cflags="";
883 for my $vc_configurations (@{$project_xml->{'Configurations'}}) {
884 for my $vc_configuration (@{$vc_configurations->{'Configuration'}}) {
885 for my $vc_tool (@{$vc_configuration->{'Tool'}}) {
886 if ($vc_tool->{'Name'} ne 'VCCLCompilerTool') { next; }
887 if (defined $vc_tool->{'Optimization'}) {$prj_target_cflags.="-O".$vc_tool->{'Optimization'}." ";}
888 if (defined $vc_tool->{'WarningLevel'}) {
889 if ($vc_tool->{'WarningLevel'}==0) {
890 $prj_target_cflags.="-w ";
891 } elsif ($vc_tool->{'WarningLevel'}<4) {
892 $prj_target_cflags.="-W ";
893 } elsif ($vc_tool->{'WarningLevel'}==4) {
894 $prj_target_cflags.="-Wall ";
895 } elsif ($vc_tool->{'WarningLevel'} eq "X") {
896 $prj_target_cflags.="-Werror ";
899 if (defined $vc_tool->{'PreprocessorDefinitions'}) {
900 $vc_tool->{'PreprocessorDefinitions'}=~s/;/ -D/g;
901 $prj_target_cflags.="-D".$vc_tool->{'PreprocessorDefinitions'}." ";
904 last;
907 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
908 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
911 my $target_count;
912 $target_count=keys %targets;
915 # Add this project to the project list, except for
916 # the main project which is already in the list.
917 if ($is_sub_project == 1) {
918 push @projects,$project;
921 # Ask for project-wide options
922 if ($opt_ask_project_options == $OPT_ASK_YES) {
923 my $flag_desc="";
924 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
925 $flag_desc="mfc";
927 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
928 if (defined $flag_desc) {
929 print "* (currently $flag_desc)\n";
931 print "* or 'skip' to skip the target specific options,\n";
932 print "* or 'never' to not be asked this question again:\n";
933 while (1) {
934 my $options=<STDIN>;
935 chomp $options;
936 if ($options eq "skip") {
937 $opt_ask_target_options=$OPT_ASK_SKIP;
938 last;
939 } elsif ($options eq "never") {
940 $opt_ask_project_options=$OPT_ASK_NO;
941 last;
942 } elsif (source_set_options($project_settings,$options)) {
943 last;
945 print "Please re-enter the options:\n";
949 # - Create the targets
950 # - Check if we have both libraries and programs
951 # - Match each target with source files (sort in reverse
952 # alphabetical order to get the longest matches first)
953 my @local_dlls=();
954 my @local_depends=();
955 my @exe_list=();
956 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
957 # Create the target...
958 my $target=[];
959 target_init($target);
960 @$target[$T_NAME]=$target_name;
961 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
962 if ($target_name =~ /\.dll$/) {
963 @$target[$T_TYPE]=$TT_DLL;
964 push @local_depends,"$target_name.so";
965 push @local_dlls,$target_name;
966 my $canon=canonize($target_name);
967 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
968 } else {
969 @$target[$T_TYPE]=$opt_target_type;
970 push @exe_list,$target;
971 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
973 my $basename=$target_name;
974 $basename=~ s/\.(dll|exe)$//i;
975 # This is the default link list of Visual Studio
976 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
977 my @std_libraries=qw(uuid);
978 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
979 @$target[$T_DLLS]=\@std_imports;
980 @$target[$T_LIBRARIES]=\@std_libraries;
981 } else {
982 @$target[$T_DLLS]=[];
983 @$target[$T_LIBRARIES]=[];
985 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
986 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
987 push @{@$target[$T_LDFLAGS]},"-m32";
989 push @{@$project[$P_TARGETS]},$target;
991 # Ask for target-specific options
992 if ($opt_ask_target_options == $OPT_ASK_YES) {
993 my $flag_desc="";
994 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
995 $flag_desc=" (mfc";
997 if ($flag_desc ne "") {
998 $flag_desc.=")";
1000 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1001 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1002 while (1) {
1003 my $options=<STDIN>;
1004 chomp $options;
1005 if ($options eq "never") {
1006 $opt_ask_target_options=$OPT_ASK_NO;
1007 last;
1008 } elsif (source_set_options($target,$options)) {
1009 last;
1011 print "Please re-enter the options:\n";
1014 if (@$target[$T_FLAGS] & $TF_MFC) {
1015 @$project_settings[$T_FLAGS]|=$TF_MFC;
1016 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1017 push @{@$target[$T_DLLS]},"mfc.dll";
1018 # FIXME: Link with the MFC in the Unix sense, until we
1019 # start exporting the functions properly.
1020 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1021 push @{@$target[$T_LIBRARIES]},"mfc";
1024 # Match sources...
1025 if ($target_count == 1) {
1026 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1027 @$project_settings[$T_SOURCES_C]=[];
1028 @sources_c=();
1030 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1031 @$project_settings[$T_SOURCES_CXX]=[];
1032 @sources_cxx=();
1034 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1035 @$project_settings[$T_SOURCES_RC]=[];
1036 @sources_rc=();
1038 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1039 # No need for sorting these sources
1040 @$project_settings[$T_SOURCES_MISC]=[];
1041 @sources_misc=();
1043 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1044 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1045 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1046 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1048 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1049 $opt_ask_target_options=$OPT_ASK_YES;
1052 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1053 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1054 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1057 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1058 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1060 # The sources that did not match, if any, go to the extra
1061 # source list of the project settings
1062 foreach my $source (@sources_c) {
1063 if ($source ne "") {
1064 push @{@$project_settings[$T_SOURCES_C]},$source;
1067 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1068 foreach my $source (@sources_cxx) {
1069 if ($source ne "") {
1070 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1073 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1074 foreach my $source (@sources_rc) {
1075 if ($source ne "") {
1076 push @{@$project_settings[$T_SOURCES_RC]},$source;
1079 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1080 foreach my $source (@sources_misc) {
1081 if ($source ne "") {
1082 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1085 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1089 # Scans the specified workspace file to find the project files
1090 sub source_scan_workspace_file($);
1091 sub source_scan_workspace_file($)
1093 my $filename=$_[0];
1094 my $path=dirname($filename);
1095 my @components;
1097 if (! -e $filename) {
1098 return;
1101 if (!open(FILEIWS,$filename)) {
1102 print STDERR "error: unable to open $filename for reading:\n";
1103 print STDERR " $!\n";
1104 return;
1107 my $prj_name;
1108 my $prj_path;
1110 if ($filename =~ /.dsw$/i) {
1111 while (<FILEIWS>) {
1112 # Remove any trailing CrLf
1113 s/\r\n$/\n/;
1115 # catch a project definition
1116 if (/^Project:\s\"(.*)\"=(.*)\s-/) {
1117 $prj_name=$1;
1118 $prj_path=$2;
1119 @components=split /[\/\\]+/, $2;
1120 $prj_path=search_from($path, \@components);
1121 print "Name: $prj_name\nPath: $prj_path\n";
1122 source_scan_project_file(\@main_project,1,$prj_path);
1123 next;
1124 } elsif (/^#/) {
1125 # ignore Comments
1126 } elsif (/\w:/) {
1127 print STDERR "unknown section $_\n";
1128 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1129 print "\nFileversion: $3\n";
1132 close(FILEIWS);
1133 } elsif ($filename =~ /.sln$/i) {
1134 while (<FILEIWS>) {
1135 # Remove any trailing CrLf
1136 s/\r\n$/\n/;
1138 # catch a project definition
1139 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1140 $prj_name=$2;
1141 $prj_path=$3;
1142 @components=split /[\/\\]+/, $3;
1143 $prj_path=search_from($path, \@components);
1144 print "Name: $prj_name\nPath: $prj_path\n";
1145 source_scan_project_file(\@main_project,1,$prj_path);
1146 next;
1147 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1148 print "\nFileversion: $3\n";
1151 close(FILEIWS);
1154 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1158 # Scans the specified directory to:
1159 # - see if we should create a Makefile in this directory. We normally do
1160 # so if we find a project file and sources
1161 # - get a list of targets for this directory
1162 # - get the list of source files
1163 sub source_scan_directory($$$$);
1164 sub source_scan_directory($$$$)
1166 # a reference to the parent's project
1167 my $parent_project=$_[0];
1168 # the full relative path to the current directory, including a
1169 # trailing '/', or an empty string if this is the top level directory
1170 my $path=$_[1];
1171 # the name of this directory, including a trailing '/', or an empty
1172 # string if this is the top level directory
1173 my $dirname=$_[2];
1174 # if set then no targets will be looked for and the sources will all
1175 # end up in the parent_project's 'misc' bucket
1176 my $no_target=$_[3];
1178 # reference to the project for this directory. May not be used
1179 my $project;
1180 # list of targets found in the 'current' directory
1181 my %targets;
1182 # list of sources found in the current directory
1183 my @sources_c=();
1184 my @sources_cxx=();
1185 my @sources_rc=();
1186 my @sources_misc=();
1187 # true if this directory contains a Windows project
1188 my $has_win_project=0;
1189 # true if this directory contains headers
1190 my $has_headers=0;
1191 # If we don't find any executable/library then we might make up targets
1192 # from the list of .dsp/.mak files we find since they usually have the
1193 # same name as their target.
1194 my @dsp_files=();
1195 my @mak_files=();
1197 if (defined $opt_single_target or $dirname eq "") {
1198 # Either there is a single target and thus a single project,
1199 # or we are in the top level directory for which a project
1200 # already exists
1201 $project=$parent_project;
1202 } else {
1203 $project=[];
1204 project_init($project, $path, \@global_settings);
1206 my $project_settings=@$project[$P_SETTINGS];
1208 # First find out what this directory contains:
1209 # collect all sources, targets and subdirectories
1210 my $directory=get_directory_contents($path);
1211 foreach my $dentry (@$directory) {
1212 if ($dentry =~ /^\./) {
1213 next;
1215 my $fullentry="$path$dentry";
1216 if (-d "$fullentry") {
1217 if ($dentry =~ /^(Release|Debug)/i) {
1218 # These directories are often used to store the object files and the
1219 # resulting executable/library. They should not contain anything else.
1220 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
1221 foreach my $candidate (@candidates) {
1222 $targets{$candidate}=1;
1224 } elsif ($dentry =~ /^include/i) {
1225 # This directory must contain headers we're going to need
1226 push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1227 source_scan_directory($project,"$fullentry/","$dentry/",1);
1228 } else {
1229 # Recursively scan this directory. Any source file that cannot be
1230 # attributed to a project in one of the subdirectories will be
1231 # attributed to this project.
1232 source_scan_directory($project,"$fullentry/","$dentry/",$no_target);
1234 } elsif (-f "$fullentry") {
1235 if ($dentry =~ /\.(exe|dll)$/i) {
1236 $targets{$dentry}=1;
1237 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1238 push @sources_c,"$dentry";
1239 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
1240 if ($dentry =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1241 push @sources_misc,"$dentry";
1242 @$project_settings[$T_FLAGS]|=$TF_MFC;
1243 } else {
1244 push @sources_cxx,"$dentry";
1246 } elsif ($dentry =~ /\.rc$/i) {
1247 push @sources_rc,"$dentry";
1248 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1249 $has_headers=1;
1250 push @sources_misc,"$dentry";
1251 if ($dentry =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1252 @$project_settings[$T_FLAGS]|=$TF_MFC;
1254 } elsif ($dentry =~ /\.dsp$/i) {
1255 push @dsp_files,"$dentry";
1256 $has_win_project=1;
1257 } elsif ($dentry =~ /\.mak$/i) {
1258 push @mak_files,"$dentry";
1259 $has_win_project=1;
1260 } elsif ($dentry =~ /^makefile/i) {
1261 $has_win_project=1;
1266 if ($has_headers) {
1267 push @{@$project_settings[$T_INCLUDE_PATH]},"-I.";
1269 # If we have a single target then all we have to do is assign
1270 # all the sources to it and we're done
1271 # FIXME: does this play well with the --interactive mode?
1272 if ($opt_single_target) {
1273 my $target=@{@$project[$P_TARGETS]}[0];
1274 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1275 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1276 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1277 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1278 return;
1280 if ($no_target) {
1281 my $parent_settings=@$parent_project[$P_SETTINGS];
1282 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1283 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1284 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1285 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1286 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1287 return;
1290 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1291 @{@$project_settings[$T_SOURCES_C]}+
1292 @{@$project_settings[$T_SOURCES_CXX]}+
1293 @{@$project_settings[$T_SOURCES_RC]};
1294 if ($source_count == 0) {
1295 # A project without real sources is not a project, get out!
1296 if ($project!=$parent_project) {
1297 my $parent_settings=@$parent_project[$P_SETTINGS];
1298 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1299 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1301 return;
1303 #print "targets=",%targets,"\n";
1304 #print "target_count=$target_count\n";
1305 #print "has_win_project=$has_win_project\n";
1306 #print "dirname=$dirname\n";
1308 my $target_count;
1309 if (($has_win_project != 0) or ($dirname eq "")) {
1310 # Deal with cases where we could not find any executable/library, and
1311 # thus have no target, although we did find some sort of windows project.
1312 $target_count=keys %targets;
1313 if ($target_count == 0) {
1314 # Try to come up with a target list based on .dsp/.mak files
1315 my $prj_list;
1316 if (@dsp_files > 0) {
1317 $prj_list=\@dsp_files;
1318 } else {
1319 $prj_list=\@mak_files;
1321 foreach my $filename (@$prj_list) {
1322 $filename =~ s/\.(dsp|mak)$//i;
1323 if ($opt_target_type == $TT_DLL) {
1324 $filename = "$filename.dll";
1326 $targets{$filename}=1;
1328 $target_count=keys %targets;
1329 if ($target_count == 0) {
1330 # Still nothing, try the name of the directory
1331 my $name;
1332 if ($dirname eq "") {
1333 # Bad luck, this is the top level directory!
1334 $name=(split /\//, cwd)[-1];
1335 } else {
1336 $name=$dirname;
1337 # Remove the trailing '/'. Also eliminate whatever is after the last
1338 # '.' as it is likely to be meaningless (.orig, .new, ...)
1339 $name =~ s+(/|\.[^.]*)$++;
1340 if ($name eq "src") {
1341 # 'src' is probably a subdirectory of the real project directory.
1342 # Try again with the parent (if any).
1343 my $parent=$path;
1344 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
1345 $name=$parent;
1346 } else {
1347 $name=(split /\//, cwd)[-1];
1351 $name =~ s+(/|\.[^.]*)$++;
1352 if ($opt_target_type == $TT_DLL) {
1353 $name = "$name.dll";
1354 } else {
1355 $name = "$name.exe";
1357 $targets{$name}=1;
1361 # Ask confirmation to the user if he wishes so
1362 if ($opt_is_interactive == $OPT_ASK_YES) {
1363 my $target_list=join " ",keys %targets;
1364 print "\n*** In ",($path?$path:"./"),"\n";
1365 print "* winemaker found the following list of (potential) targets\n";
1366 print "* $target_list\n";
1367 print "* Type enter to use it as is, your own comma-separated list of\n";
1368 print "* targets, 'none' to assign the source files to a parent directory,\n";
1369 print "* or 'ignore' to ignore everything in this directory tree.\n";
1370 print "* Target list:\n";
1371 $target_list=<STDIN>;
1372 chomp $target_list;
1373 if ($target_list eq "") {
1374 # Keep the target list as is, i.e. do nothing
1375 } elsif ($target_list eq "none") {
1376 # Empty the target list
1377 undef %targets;
1378 } elsif ($target_list eq "ignore") {
1379 # Ignore this subtree altogether
1380 return;
1381 } else {
1382 undef %targets;
1383 foreach my $target (split /,/,$target_list) {
1384 $target =~ s+^\s*++;
1385 $target =~ s+\s*$++;
1386 $targets{$target}=1;
1392 # If we have no project at this level, then transfer all
1393 # the sources to the parent project
1394 $target_count=keys %targets;
1395 if ($target_count == 0) {
1396 if ($project!=$parent_project) {
1397 my $parent_settings=@$parent_project[$P_SETTINGS];
1398 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1399 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1400 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1401 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1402 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1404 return;
1407 # Otherwise add this project to the project list, except for
1408 # the main project which is already in the list.
1409 if ($dirname ne "") {
1410 push @projects,$project;
1413 # Ask for project-wide options
1414 if ($opt_ask_project_options == $OPT_ASK_YES) {
1415 my $flag_desc="";
1416 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1417 $flag_desc="mfc";
1419 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1420 if (defined $flag_desc) {
1421 print "* (currently $flag_desc)\n";
1423 print "* or 'skip' to skip the target specific options,\n";
1424 print "* or 'never' to not be asked this question again:\n";
1425 while (1) {
1426 my $options=<STDIN>;
1427 chomp $options;
1428 if ($options eq "skip") {
1429 $opt_ask_target_options=$OPT_ASK_SKIP;
1430 last;
1431 } elsif ($options eq "never") {
1432 $opt_ask_project_options=$OPT_ASK_NO;
1433 last;
1434 } elsif (source_set_options($project_settings,$options)) {
1435 last;
1437 print "Please re-enter the options:\n";
1441 # - Create the targets
1442 # - Check if we have both libraries and programs
1443 # - Match each target with source files (sort in reverse
1444 # alphabetical order to get the longest matches first)
1445 my @local_dlls=();
1446 my @local_depends=();
1447 my @exe_list=();
1448 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1449 # Create the target...
1450 my $target=[];
1451 target_init($target);
1452 @$target[$T_NAME]=$target_name;
1453 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
1454 if ($target_name =~ /\.dll$/) {
1455 @$target[$T_TYPE]=$TT_DLL;
1456 push @local_depends,"$target_name.so";
1457 push @local_dlls,$target_name;
1458 my $canon=canonize($target_name);
1459 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
1460 } else {
1461 @$target[$T_TYPE]=$opt_target_type;
1462 push @exe_list,$target;
1463 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
1465 my $basename=$target_name;
1466 $basename=~ s/\.(dll|exe)$//i;
1467 # This is the default link list of Visual Studio
1468 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1469 my @std_libraries=qw(uuid);
1470 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1471 @$target[$T_DLLS]=\@std_imports;
1472 @$target[$T_LIBRARIES]=\@std_libraries;
1473 } else {
1474 @$target[$T_DLLS]=[];
1475 @$target[$T_LIBRARIES]=[];
1477 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1478 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
1479 push @{@$target[$T_LDFLAGS]},"-m32";
1481 push @{@$project[$P_TARGETS]},$target;
1483 # Ask for target-specific options
1484 if ($opt_ask_target_options == $OPT_ASK_YES) {
1485 my $flag_desc="";
1486 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
1487 $flag_desc=" (mfc";
1489 if ($flag_desc ne "") {
1490 $flag_desc.=")";
1492 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1493 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1494 while (1) {
1495 my $options=<STDIN>;
1496 chomp $options;
1497 if ($options eq "never") {
1498 $opt_ask_target_options=$OPT_ASK_NO;
1499 last;
1500 } elsif (source_set_options($target,$options)) {
1501 last;
1503 print "Please re-enter the options:\n";
1506 if (@$target[$T_FLAGS] & $TF_MFC) {
1507 @$project_settings[$T_FLAGS]|=$TF_MFC;
1508 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1509 push @{@$target[$T_DLLS]},"mfc.dll";
1510 # FIXME: Link with the MFC in the Unix sense, until we
1511 # start exporting the functions properly.
1512 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1513 push @{@$target[$T_LIBRARIES]},"mfc";
1516 # Match sources...
1517 if ($target_count == 1) {
1518 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1519 @$project_settings[$T_SOURCES_C]=[];
1520 @sources_c=();
1522 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1523 @$project_settings[$T_SOURCES_CXX]=[];
1524 @sources_cxx=();
1526 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1527 @$project_settings[$T_SOURCES_RC]=[];
1528 @sources_rc=();
1530 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1531 # No need for sorting these sources
1532 @$project_settings[$T_SOURCES_MISC]=[];
1533 @sources_misc=();
1534 } else {
1535 foreach my $source (@sources_c) {
1536 if ($source =~ /^$basename/i) {
1537 push @{@$target[$T_SOURCES_C]},$source;
1538 $source="";
1541 foreach my $source (@sources_cxx) {
1542 if ($source =~ /^$basename/i) {
1543 push @{@$target[$T_SOURCES_CXX]},$source;
1544 $source="";
1547 foreach my $source (@sources_rc) {
1548 if ($source =~ /^$basename/i) {
1549 push @{@$target[$T_SOURCES_RC]},$source;
1550 $source="";
1553 foreach my $source (@sources_misc) {
1554 if ($source =~ /^$basename/i) {
1555 push @{@$target[$T_SOURCES_MISC]},$source;
1556 $source="";
1560 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1561 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1562 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1563 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1565 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1566 $opt_ask_target_options=$OPT_ASK_YES;
1569 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1570 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1571 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1574 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1575 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1577 # The sources that did not match, if any, go to the extra
1578 # source list of the project settings
1579 foreach my $source (@sources_c) {
1580 if ($source ne "") {
1581 push @{@$project_settings[$T_SOURCES_C]},$source;
1584 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1585 foreach my $source (@sources_cxx) {
1586 if ($source ne "") {
1587 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1590 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1591 foreach my $source (@sources_rc) {
1592 if ($source ne "") {
1593 push @{@$project_settings[$T_SOURCES_RC]},$source;
1596 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1597 foreach my $source (@sources_misc) {
1598 if ($source ne "") {
1599 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1602 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1604 # Finally if we are building both libraries and programs in
1605 # this directory, then the programs should be linked with all
1606 # the libraries
1607 if (@local_dlls > 0 and @exe_list > 0) {
1608 foreach my $target (@exe_list) {
1609 push @{@$target[$T_DLL_PATH]},"-L.";
1610 push @{@$target[$T_DLLS]},@local_dlls;
1616 # Scan the source directories in search of things to build
1617 sub source_scan()
1619 # If there's a single target then this is going to be the default target
1620 if (defined $opt_single_target) {
1621 # Create the main target
1622 my $main_target=[];
1623 target_init($main_target);
1624 @$main_target[$T_NAME]=$opt_single_target;
1625 @$main_target[$T_TYPE]=$opt_target_type;
1627 # Add it to the list
1628 push @{$main_project[$P_TARGETS]},$main_target;
1631 # The main directory is always going to be there
1632 push @projects,\@main_project;
1634 if (defined $opt_work_dir) {
1635 # Now scan the directory tree looking for source files and, maybe, targets
1636 print "Scanning the source directories...\n";
1637 source_scan_directory(\@main_project,"","",0);
1638 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1639 } elsif (defined $opt_work_file) {
1640 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1641 source_scan_project_file(\@main_project,0,$opt_work_file);
1642 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1643 source_scan_workspace_file($opt_work_file);
1648 #####
1650 # Source search
1652 #####
1655 # Performs a directory traversal and renames the files so that:
1656 # - they have the case desired by the user
1657 # - their extension is of the appropriate case
1658 # - they don't contain annoying characters like ' ', '$', '#', ...
1659 # But only perform these changes for source files and directories.
1660 sub fix_file_and_directory_names($);
1661 sub fix_file_and_directory_names($)
1663 my $dirname=$_[0];
1665 my $directory=get_directory_contents($dirname);
1666 foreach my $dentry (@$directory)
1668 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1669 next;
1671 # Set $warn to 1 if the user should be warned of the renaming
1672 my $warn;
1673 my $new_name=$dentry;
1675 if (-f "$dirname/$dentry")
1677 # Don't rename Winemaker's makefiles
1678 next if ($dentry eq "Makefile" and
1679 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker/);
1681 # Leave non-source files alone
1682 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc))$/i);
1684 # Only all lowercase extensions are supported (because of
1685 # rules like '.c.o:'.
1686 $new_name =~ s/\.C$/.c/;
1687 $new_name =~ s/\.cpp$/.cpp/i;
1688 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1689 $new_name =~ s/\.rc$/.rc/i;
1690 # And this last one is to avoid confusion then running make
1691 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1694 # Adjust the case to the user's preferences
1695 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1696 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1698 $new_name=lc $new_name;
1701 # autoconf and make don't support these characters well
1702 $new_name =~ s/[ \$]/_/g;
1704 # And finally, perform the renaming
1705 if ($new_name ne $dentry)
1707 if ($warn) {
1708 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1710 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1711 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1712 print STDERR " $!\n";
1713 $new_name=$dentry;
1715 else
1717 clear_directory_cache($dirname);
1720 if (-d "$dirname/$new_name") {
1721 fix_file_and_directory_names("$dirname/$new_name");
1728 #####
1730 # Source fixup
1732 #####
1735 # Try to find a file for the specified filename. The attempt is
1736 # case-insensitive which is why it's not trivial. If a match is
1737 # found then we return the pathname with the correct case.
1738 sub search_from($$)
1740 my $dirname=$_[0];
1741 my $path=$_[1];
1742 my $real_path="";
1744 if ($dirname eq "" or $dirname eq ".") {
1745 $dirname=cwd;
1746 } elsif ($dirname !~ m+^/+) {
1747 $dirname=cwd . "/" . $dirname;
1749 if ($dirname !~ m+/$+) {
1750 $dirname.="/";
1753 foreach my $component (@$path) {
1754 #print " looking for $component in \"$dirname\"\n";
1755 if ($component eq ".") {
1756 # Pass it as is
1757 $real_path.="./";
1758 } elsif ($component eq "..") {
1759 # Go up one level
1760 $dirname=dirname($dirname) . "/";
1761 $real_path.="../";
1762 } else {
1763 # The file/directory may have been renamed before. Also try to
1764 # match the renamed file.
1765 my $renamed=$component;
1766 $renamed =~ s/[ \$]/_/g;
1767 if ($renamed eq $component) {
1768 undef $renamed;
1771 my $directory=get_directory_contents $dirname;
1772 my $found;
1773 foreach my $dentry (@$directory) {
1774 if ($dentry =~ /^\Q$component\E$/i or
1775 (defined $renamed and $dentry =~ /^$renamed$/i)
1777 $dirname.="$dentry/";
1778 $real_path.="$dentry/";
1779 $found=1;
1780 last;
1783 if (!defined $found) {
1784 # Give up
1785 #print " could not find $component in $dirname\n";
1786 return;
1790 $real_path=~ s+/$++;
1791 #print " -> found $real_path\n";
1792 return $real_path;
1796 # Performs a case-insensitive search for the specified file in the
1797 # include path.
1798 # $line is the line number that should be referenced when an error occurs
1799 # $filename is the file we are looking for
1800 # $dirname is the directory of the file containing the '#include' directive
1801 # if '"' was used, it is an empty string otherwise
1802 # $project and $target specify part of the include path
1803 sub get_real_include_name($$$$$)
1805 my $line=$_[0];
1806 my $filename=$_[1];
1807 my $dirname=$_[2];
1808 my $project=$_[3];
1809 my $target=$_[4];
1811 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1812 # This is not a relative path, we cannot make any check
1813 my $warning="path:$filename";
1814 if (!defined $warnings{$warning}) {
1815 $warnings{$warning}="1";
1816 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1817 print STDERR "$line: $filename\n";
1819 } else {
1820 # Here's how we proceed:
1821 # - split the filename we look for into its components
1822 # - then for each directory in the include path
1823 # - trace the directory components starting from that directory
1824 # - if we fail to find a match at any point then continue with
1825 # the next directory in the include path
1826 # - otherwise, rejoice, our quest is over.
1827 my @file_components=split /[\/\\]+/, $filename;
1828 #print " Searching for $filename from @$project[$P_PATH]\n";
1830 my $real_filename;
1831 if ($dirname ne "") {
1832 # This is an 'include ""' -> look in dirname first.
1833 #print " in $dirname (include \"\")\n";
1834 $real_filename=search_from($dirname,\@file_components);
1835 if (defined $real_filename) {
1836 return $real_filename;
1839 my $project_settings=@$project[$P_SETTINGS];
1840 foreach my $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1841 my $dirname=$include;
1842 $dirname=~ s+^-I++;
1843 if (!is_absolute($dirname)) {
1844 $dirname="@$project[$P_PATH]$dirname";
1845 } else {
1846 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1847 $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
1849 #print " in $dirname\n";
1850 $real_filename=search_from("$dirname",\@file_components);
1851 if (defined $real_filename) {
1852 return $real_filename;
1855 my $dotdotpath=@$project[$P_PATH];
1856 $dotdotpath =~ s/[^\/]+/../g;
1857 foreach my $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1858 my $dirname=$include;
1859 $dirname=~ s+^-I++;
1860 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1861 $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
1862 #print " in $dirname (global setting)\n";
1863 $real_filename=search_from("$dirname",\@file_components);
1864 if (defined $real_filename) {
1865 return $real_filename;
1869 $filename =~ s+\\\\+/+g; # in include ""
1870 $filename =~ s+\\+/+g; # in include <> !
1871 if ($opt_lower_include) {
1872 return lc "$filename";
1874 return $filename;
1877 sub print_pack($$$)
1879 my $indent=$_[0];
1880 my $size=$_[1];
1881 my $trailer=$_[2];
1883 if ($size =~ /^(1|2|4|8)$/) {
1884 print FILEO "$indent#include <pshpack$size.h>$trailer";
1885 } else {
1886 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1887 print FILEO "$indent#include <pshpack4.h>$trailer";
1892 # 'Parses' a source file and fixes constructs that would not work with
1893 # Winelib. The parsing is rather simple and not all non-portable features
1894 # are corrected. The most important feature that is corrected is the case
1895 # and path separator of '#include' directives. This requires that each
1896 # source file be associated to a project & target so that the proper
1897 # include path is used.
1898 # Also note that the include path is relative to the directory in which the
1899 # compiler is run, i.e. that of the project, not to that of the file.
1900 sub fix_file($$$)
1902 my $filename=$_[0];
1903 my $project=$_[1];
1904 my $target=$_[2];
1905 $filename="@$project[$P_PATH]$filename";
1906 if (! -e $filename) {
1907 return;
1910 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1911 my $dirname=dirname($filename);
1912 my $is_mfc=0;
1913 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1914 $is_mfc=1;
1917 print " $filename\n";
1918 #FIXME:assuming that because there is a .bak file, this is what we want is
1919 #probably flawed. Or is it???
1920 if (! -e "$filename.bak") {
1921 if (!copy("$filename","$filename.bak")) {
1922 print STDERR "error: unable to make a backup of $filename:\n";
1923 print STDERR " $!\n";
1924 return;
1927 if (!open(FILEI,"$filename.bak")) {
1928 print STDERR "error: unable to open $filename.bak for reading:\n";
1929 print STDERR " $!\n";
1930 return;
1932 if (!open(FILEO,">$filename")) {
1933 print STDERR "error: unable to open $filename for writing:\n";
1934 print STDERR " $!\n";
1935 return;
1937 my $line=0;
1938 my $modified=0;
1939 my $rc_block_depth=0;
1940 my $rc_textinclude_state=0;
1941 my @pack_stack;
1942 while (<FILEI>) {
1943 # Remove any trailing CtrlZ, which isn't strictly in the file
1944 if (/\x1A/) {
1945 s/\x1A//;
1946 last if (/^$/)
1948 $line++;
1949 s/\r\n$/\n/;
1950 if (!/\n$/) {
1951 # Make sure all files are '\n' terminated
1952 $_ .= "\n";
1954 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
1955 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1956 # the RC files it generates (even in non-MFC projects). So we replace
1957 # it with 'winresrc.h' its very close standard cousin so that non MFC
1958 # projects can compile in Wine without the MFC sources.
1959 my $warning="mfc:afxres.h";
1960 if (!defined $warnings{$warning}) {
1961 $warnings{$warning}="1";
1962 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
1963 print STDERR "warning: the above warning is issued only once\n";
1965 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
1966 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
1967 print FILEO "$1$2\"winresrc.h\"$'";
1968 $modified=1;
1970 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1971 my $from_file=($2 eq "<"?"":$dirname);
1972 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1973 print FILEO "$1$2$real_include_name$4$'";
1974 $modified|=($real_include_name ne $3);
1976 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
1977 # Pragma pack handling
1979 # pack_stack is an array of references describing the stack of
1980 # pack directives currently in effect. Each directive if described
1981 # by a reference to an array containing:
1982 # - "push" for pack(push,...) directives, "" otherwise
1983 # - the directive's identifier at index 1
1984 # - the directive's alignment value at index 2
1986 # Don't believe a word of what the documentation says: it's all wrong.
1987 # The code below is based on the actual behavior of Visual C/C++ 6.
1988 my $pack_indent=$1;
1989 my $pack_header=$2;
1990 if (/^(\))/) {
1991 # pragma pack()
1992 # Pushes the default stack alignment
1993 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1994 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1995 print_pack($pack_indent,4,$');
1996 push @pack_stack, [ "", "", 4 ];
1998 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
1999 # pragma pack(pop)
2000 # pragma pack(pop,n)
2001 # Goes up the stack until it finds a pack(push,...), and pops it
2002 # Ignores any pack(n) entry
2003 # Issues a warning if the pack is of the form pack(push,label)
2004 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2005 my $pack_comment=$';
2006 $pack_comment =~ s/^\s*//;
2007 if ($pack_comment ne "") {
2008 print FILEO "$pack_indent$pack_comment";
2010 while (1) {
2011 my $alignment=pop @pack_stack;
2012 if (!defined $alignment) {
2013 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2014 last;
2016 if (@$alignment[1]) {
2017 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2019 print FILEO "$pack_indent#include <poppack.h>\n";
2020 if (@$alignment[0]) {
2021 last;
2025 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2026 # pragma pack(pop,label[,n])
2027 # Goes up the stack until finding a pack(push,...) and pops it.
2028 # 'n', if specified, is ignored.
2029 # Ignores any pack(n) entry
2030 # Issues a warning if the label of the pack does not match,
2031 # or if it is in fact a pack(push,n)
2032 my $label=$2;
2033 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2034 my $pack_comment=$';
2035 $pack_comment =~ s/^\s*//;
2036 if ($pack_comment ne "") {
2037 print FILEO "$pack_indent$pack_comment";
2039 while (1) {
2040 my $alignment=pop @pack_stack;
2041 if (!defined $alignment) {
2042 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2043 last;
2045 if (@$alignment[1] and @$alignment[1] ne $label) {
2046 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2048 print FILEO "$pack_indent#include <poppack.h>\n";
2049 if (@$alignment[0]) {
2050 last;
2054 } elsif (/^(push\s*\))/) {
2055 # pragma pack(push)
2056 # Push the current alignment
2057 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2058 if (@pack_stack > 0) {
2059 my $alignment=$pack_stack[$#pack_stack];
2060 print_pack($pack_indent,@$alignment[2],$');
2061 push @pack_stack, [ "push", "", @$alignment[2] ];
2062 } else {
2063 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2064 print_pack($pack_indent,4,$');
2065 push @pack_stack, [ "push", "", 4 ];
2068 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2069 # pragma pack([push,]n)
2070 # Push new alignment n
2071 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2072 print_pack($pack_indent,$3,"$'");
2073 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2075 } elsif (/^((\w+)\s*\))/) {
2076 # pragma pack(label)
2077 # label must in fact be a macro that resolves to an integer
2078 # Then behaves like 'pragma pack(n)'
2079 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2080 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2081 print_pack($pack_indent,4,$');
2082 push @pack_stack, [ "", "", 4 ];
2084 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2085 # pragma pack(push,label[,n])
2086 # Pushes a new label on the stack. It is possible to push the same
2087 # label multiple times. If 'n' is omitted then the alignment is
2088 # unchanged. Otherwise it becomes 'n'.
2089 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2090 my $size;
2091 if (defined $4) {
2092 $size=$4;
2093 } elsif (@pack_stack > 0) {
2094 my $alignment=$pack_stack[$#pack_stack];
2095 $size=@$alignment[2];
2096 } else {
2097 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2098 $size=4;
2100 print_pack($pack_indent,$size,$');
2101 push @pack_stack, [ "push", $2, $size ];
2103 } else {
2104 # pragma pack(??? -> What's that?
2105 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2106 print FILEO "$pack_indent$pack_header$_";
2109 $modified=1;
2111 } elsif ($is_rc) {
2112 if ($rc_block_depth == 0 and /^(\w+\s+(BITMAP|CURSOR|FONT|FONTDIR|ICON|MESSAGETABLE|TEXT|RTF)\s+((DISCARDABLE|FIXED|IMPURE|LOADONCALL|MOVEABLE|PRELOAD|PURE)\s+)*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2113 my $from_file=($5 eq "<"?"":$dirname);
2114 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2115 print FILEO "$1$5$real_include_name$7$'";
2116 $modified|=($real_include_name ne $6);
2118 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2119 my $from_file=($2 eq "<"?"":$dirname);
2120 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2121 print FILEO "$1$2$real_include_name$4$'";
2122 $modified|=($real_include_name ne $3);
2124 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2125 $rc_textinclude_state=1;
2126 print FILEO;
2128 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2129 print FILEO "$1winresrc.h$2$'";
2130 $modified=1;
2132 } elsif (/^\s*BEGIN(\W.*)?$/) {
2133 $rc_textinclude_state|=2;
2134 $rc_block_depth++;
2135 print FILEO;
2137 } elsif (/^\s*END(\W.*)?$/) {
2138 $rc_textinclude_state=0;
2139 if ($rc_block_depth>0) {
2140 $rc_block_depth--;
2142 print FILEO;
2144 } else {
2145 print FILEO;
2148 } else {
2149 print FILEO;
2153 close(FILEI);
2154 close(FILEO);
2155 if ($opt_backup == 0 or $modified == 0) {
2156 if (!unlink("$filename.bak")) {
2157 print STDERR "error: unable to delete $filename.bak:\n";
2158 print STDERR " $!\n";
2164 # Analyzes each source file in turn to find and correct issues
2165 # that would cause it not to compile.
2166 sub fix_source()
2168 print "Fixing the source files...\n";
2169 foreach my $project (@projects) {
2170 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2171 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2172 fix_file($source,$project,$target);
2180 #####
2182 # File generation
2184 #####
2187 # A convenience function to generate all the lists (defines,
2188 # C sources, C++ source, etc.) in the Makefile
2189 sub generate_list($$$;$)
2191 my $name=$_[0];
2192 my $last=$_[1];
2193 my $list=$_[2];
2194 my $data=$_[3];
2195 my $first=$name;
2197 if ($name) {
2198 printf FILEO "%-22s=",$name;
2200 if (defined $list) {
2201 foreach my $item (@$list) {
2202 my $value;
2203 if (defined $data) {
2204 $value=&$data($item);
2205 } else {
2206 $value=$item;
2208 if ($value ne "") {
2209 if ($first) {
2210 print FILEO " $value";
2211 $first=0;
2212 } else {
2213 print FILEO " \\\n\t\t\t$value";
2218 if ($last) {
2219 print FILEO "\n";
2224 # Generates a project's Makefile and all the target files
2225 sub generate_project_files($)
2227 my $project=$_[0];
2228 my $project_settings=@$project[$P_SETTINGS];
2229 my @dll_list=();
2230 my @exe_list=();
2232 # Then sort the targets and separate the libraries from the programs
2233 foreach my $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
2234 if (@$target[$T_TYPE] == $TT_DLL) {
2235 push @dll_list,$target;
2236 } else {
2237 push @exe_list,$target;
2240 @$project[$P_TARGETS]=[];
2241 push @{@$project[$P_TARGETS]}, @dll_list;
2242 push @{@$project[$P_TARGETS]}, @exe_list;
2244 if (!open(FILEO,">@$project[$P_PATH]Makefile")) {
2245 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2246 print STDERR " $!\n";
2247 return;
2250 print FILEO "### Generated by Winemaker\n";
2251 print FILEO "\n\n";
2253 generate_list("SRCDIR",1,[ "." ]);
2254 if (@$project[$P_PATH] eq "") {
2255 # This is the main project. It is also responsible for recursively
2256 # calling the other projects
2257 generate_list("SUBDIRS",1,\@projects,sub
2259 if ($_[0] != \@main_project) {
2260 my $subdir=@{$_[0]}[$P_PATH];
2261 $subdir =~ s+/$++;
2262 return $subdir;
2264 # Eliminating the main project by returning undefined!
2267 if (@{@$project[$P_TARGETS]} > 0) {
2268 generate_list("DLLS",1,\@dll_list,sub
2270 return @{$_[0]}[$T_NAME];
2272 generate_list("EXES",1,\@exe_list,sub
2274 return "@{$_[0]}[$T_NAME]";
2276 print FILEO "\n\n\n";
2278 print FILEO "### Common settings\n\n";
2279 # Make it so that the project-wide settings override the global settings
2280 generate_list("CEXTRA",1,@$project_settings[$T_CEXTRA]);
2281 generate_list("CXXEXTRA",1,@$project_settings[$T_CXXEXTRA]);
2282 generate_list("RCEXTRA",1,@$project_settings[$T_RCEXTRA]);
2283 generate_list("DEFINES",1,@$project_settings[$T_DEFINES]);
2284 generate_list("INCLUDE_PATH",1,@$project_settings[$T_INCLUDE_PATH]);
2285 generate_list("DLL_PATH",1,@$project_settings[$T_DLL_PATH]);
2286 generate_list("DLL_IMPORTS",1,@$project_settings[$T_DLLS]);
2287 generate_list("LIBRARY_PATH",1,@$project_settings[$T_LIBRARY_PATH]);
2288 generate_list("LIBRARIES",1,@$project_settings[$T_LIBRARIES]);
2289 print FILEO "\n\n";
2291 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
2292 @{@$project_settings[$T_SOURCES_CXX]}+
2293 @{@$project_settings[$T_SOURCES_RC]};
2294 my $no_extra=($extra_source_count == 0);
2295 if (!$no_extra) {
2296 print FILEO "### Extra source lists\n\n";
2297 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
2298 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
2299 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
2300 print FILEO "\n";
2301 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
2302 print FILEO "\n\n\n";
2305 # Iterate over all the targets...
2306 foreach my $target (@{@$project[$P_TARGETS]}) {
2307 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
2308 my $canon=canonize("@$target[$T_NAME]");
2309 $canon =~ s+_so$++;
2311 generate_list("${canon}_MODULE",1,[@$target[$T_NAME]]);
2312 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
2313 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
2314 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
2315 generate_list("${canon}_LDFLAGS",1,@$target[$T_LDFLAGS]);
2316 generate_list("${canon}_DLL_PATH",1,@$target[$T_DLL_PATH]);
2317 generate_list("${canon}_DLLS",1,@$target[$T_DLLS]);
2318 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]);
2319 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]);
2320 print FILEO "\n";
2321 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2322 print FILEO "\n\n\n";
2324 print FILEO "### Global source lists\n\n";
2325 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
2327 my $canon=canonize(@{$_[0]}[$T_NAME]);
2328 $canon =~ s+_so$++;
2329 return "\$(${canon}_C_SRCS)";
2331 if (!$no_extra) {
2332 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
2334 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
2336 my $canon=canonize(@{$_[0]}[$T_NAME]);
2337 $canon =~ s+_so$++;
2338 return "\$(${canon}_CXX_SRCS)";
2340 if (!$no_extra) {
2341 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2343 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
2345 my $canon=canonize(@{$_[0]}[$T_NAME]);
2346 $canon =~ s+_so$++;
2347 return "\$(${canon}_RC_SRCS)";
2349 if (!$no_extra) {
2350 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2353 print FILEO "\n\n";
2354 print FILEO "### Tools\n\n";
2355 print FILEO "CC = winegcc\n";
2356 print FILEO "CXX = wineg++\n";
2357 print FILEO "RC = wrc\n";
2358 print FILEO "\n\n";
2360 print FILEO "### Generic targets\n\n";
2361 print FILEO "all:";
2362 if (@$project[$P_PATH] eq "") {
2363 print FILEO " \$(SUBDIRS)";
2365 if (@{@$project[$P_TARGETS]} > 0) {
2366 print FILEO " \$(DLLS:%=%.so) \$(EXES:%=%.so)";
2368 print FILEO "\n\n";
2369 print FILEO "### Build rules\n";
2370 print FILEO "\n";
2371 print FILEO ".PHONY: all clean dummy\n";
2372 print FILEO "\n";
2373 print FILEO "\$(SUBDIRS): dummy\n";
2374 print FILEO "\t\@cd \$\@ && \$(MAKE)\n";
2375 print FILEO "\n";
2376 print FILEO "# Implicit rules\n";
2377 print FILEO "\n";
2378 print FILEO ".SUFFIXES: .cpp .rc .res\n";
2379 print FILEO "DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2380 print FILEO "\n";
2381 print FILEO ".c.o:\n";
2382 print FILEO "\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2383 print FILEO "\n";
2384 print FILEO ".cpp.o:\n";
2385 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2386 print FILEO "\n";
2387 print FILEO ".cxx.o:\n";
2388 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2389 print FILEO "\n";
2390 print FILEO ".rc.res:\n";
2391 print FILEO "\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2392 print FILEO "\n";
2393 print FILEO "# Rules for cleaning\n";
2394 print FILEO "\n";
2395 print FILEO "CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2396 print FILEO " \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2397 print FILEO "\n";
2398 print FILEO "clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2399 print FILEO "\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:.cpp=.o)\n";
2400 print FILEO "\t\$(RM) \$(DLLS:%=%.so) \$(EXES:%=%.so) \$(EXES:%.exe=%)\n";
2401 print FILEO "\n";
2402 print FILEO "\$(SUBDIRS:%=%/__clean__): dummy\n";
2403 print FILEO "\tcd `dirname \$\@` && \$(MAKE) clean\n";
2404 print FILEO "\n";
2405 print FILEO "\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2406 print FILEO "\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2407 print FILEO "\n";
2409 if (@{@$project[$P_TARGETS]} > 0) {
2410 print FILEO "### Target specific build rules\n";
2411 print FILEO "DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2412 foreach my $target (@{@$project[$P_TARGETS]}) {
2413 my $canon=canonize("@$target[$T_NAME]");
2414 $canon =~ s/_so$//;
2416 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS)\n";
2417 if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
2418 print FILEO "\t\$(CXX)";
2419 } else {
2420 print FILEO "\t\$(CC)";
2422 print FILEO " \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2423 print FILEO "\n\n";
2426 close(FILEO);
2432 # This is where we finally generate files. In fact this method does not
2433 # do anything itself but calls the methods that do the actual work.
2434 sub generate()
2436 print "Generating project files...\n";
2438 foreach my $project (@projects) {
2439 my $path=@$project[$P_PATH];
2440 if ($path eq "") {
2441 $path=".";
2442 } else {
2443 $path =~ s+/$++;
2445 print " $path\n";
2446 generate_project_files($project);
2452 #####
2454 # Option defaults
2456 #####
2458 $opt_backup=1;
2459 $opt_lower=$OPT_LOWER_UPPERCASE;
2460 $opt_lower_include=1;
2462 $opt_work_dir=undef;
2463 $opt_single_target=undef;
2464 $opt_target_type=$TT_GUIEXE;
2465 $opt_flags=0;
2466 $opt_is_interactive=$OPT_ASK_NO;
2467 $opt_ask_project_options=$OPT_ASK_NO;
2468 $opt_ask_target_options=$OPT_ASK_NO;
2469 $opt_no_generated_files=0;
2470 $opt_no_source_fix=0;
2471 $opt_no_banner=0;
2475 #####
2477 # Main
2479 #####
2481 sub print_banner()
2483 print "Winemaker $version\n";
2484 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2487 sub usage()
2489 print_banner();
2490 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2491 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2492 print STDERR " [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2493 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2494 print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2495 print STDERR " [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2496 print STDERR " [--generated-files|--nogenerated-files]\n";
2497 print STDERR " work_directory|project_file|workspace_file\n";
2498 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2499 print STDERR "the specified directory so that they can be compiled with Winelib. During this\n";
2500 print STDERR "process it will modify and rename some of the files in that directory.\n";
2501 print STDERR "\tPlease read the manual page before use.\n";
2502 exit (2);
2505 target_init(\@global_settings);
2507 while (@ARGV>0) {
2508 my $arg=shift @ARGV;
2509 # General options
2510 if ($arg eq "--nobanner") {
2511 $opt_no_banner=1;
2512 } elsif ($arg eq "--backup") {
2513 $opt_backup=1;
2514 } elsif ($arg eq "--nobackup") {
2515 $opt_backup=0;
2516 } elsif ($arg eq "--single-target") {
2517 $opt_single_target=shift @ARGV;
2518 } elsif ($arg eq "--lower-none") {
2519 $opt_lower=$OPT_LOWER_NONE;
2520 } elsif ($arg eq "--lower-all") {
2521 $opt_lower=$OPT_LOWER_ALL;
2522 } elsif ($arg eq "--lower-uppercase") {
2523 $opt_lower=$OPT_LOWER_UPPERCASE;
2524 } elsif ($arg eq "--lower-include") {
2525 $opt_lower_include=1;
2526 } elsif ($arg eq "--nolower-include") {
2527 $opt_lower_include=0;
2528 } elsif ($arg eq "--nosource-fix") {
2529 $opt_no_source_fix=1;
2530 } elsif ($arg eq "--generated-files") {
2531 $opt_no_generated_files=0;
2532 } elsif ($arg eq "--nogenerated-files") {
2533 $opt_no_generated_files=1;
2534 } elsif ($arg =~ /^-D/) {
2535 push @{$global_settings[$T_DEFINES]},$arg;
2536 } elsif ($arg =~ /^-I/) {
2537 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2538 } elsif ($arg =~ /^-P/) {
2539 push @{$global_settings[$T_DLL_PATH]},"-L$'";
2540 } elsif ($arg =~ /^-i/) {
2541 push @{$global_settings[$T_DLLS]},$';
2542 } elsif ($arg =~ /^-L/) {
2543 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2544 } elsif ($arg =~ /^-l/) {
2545 push @{$global_settings[$T_LIBRARIES]},$';
2547 # 'Source'-based method options
2548 } elsif ($arg eq "--dll") {
2549 $opt_target_type=$TT_DLL;
2550 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2551 $opt_target_type=$TT_GUIEXE;
2552 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2553 $opt_target_type=$TT_CUIEXE;
2554 } elsif ($arg eq "--interactive") {
2555 $opt_is_interactive=$OPT_ASK_YES;
2556 $opt_ask_project_options=$OPT_ASK_YES;
2557 $opt_ask_target_options=$OPT_ASK_YES;
2558 } elsif ($arg eq "--mfc") {
2559 $opt_flags|=$TF_MFC;
2560 } elsif ($arg eq "--nomfc") {
2561 $opt_flags&=~$TF_MFC;
2562 $opt_flags|=$TF_NOMFC;
2563 } elsif ($arg eq "--nodlls") {
2564 $opt_flags|=$TF_NODLLS;
2565 } elsif ($arg eq "--nomsvcrt") {
2566 $opt_flags|=$TF_NOMSVCRT;
2568 # Catch errors
2569 } else {
2570 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2571 if (!defined $opt_work_dir and !defined $opt_work_file) {
2572 if (-f $arg) {
2573 $opt_work_file=$arg;
2575 else {
2576 $opt_work_dir=$arg;
2578 } else {
2579 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2580 usage();
2582 } else {
2583 usage();
2588 if (!defined $opt_work_dir and !defined $opt_work_file) {
2589 print STDERR "error: you must specify the directory or project file containing the sources to be converted\n";
2590 usage();
2591 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2592 print STDERR "error: could not chdir to the work directory\n";
2593 print STDERR " $!\n";
2594 usage();
2597 if ($opt_no_banner == 0) {
2598 print_banner();
2601 project_init(\@main_project, "", \@global_settings);
2603 # Fix the file and directory names
2604 fix_file_and_directory_names(".");
2606 # Scan the sources to identify the projects and targets
2607 source_scan();
2609 # Fix the source files
2610 if (! $opt_no_source_fix) {
2611 fix_source();
2614 # Generate the Makefile and the spec file
2615 if (! $opt_no_generated_files) {
2616 generate();