push e9c4c6cdd0babd7b2cb4288f191bb331b756eaf2
[wine/hacks.git] / tools / winemaker
blob3d452475e1157ebd61ff9df9d4c3dd70a509d477
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.1";
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 # The following constants define the architecture
70 # 32-Bit Target
71 my $OPT_ARCH_32=32;
74 # 64-Bit Target
75 my $OPT_ARCH_64=64;
78 # General options
81 # This is the directory in which winemaker will operate.
82 my $opt_work_dir;
85 # This is the file in which winemaker will operate if a project file is specified.
86 my $opt_work_file;
89 # Make a backup of the files
90 my $opt_backup;
93 # Defines which files to rename
94 my $opt_lower;
97 # If we don't find the file referenced by an include, lower it
98 my $opt_lower_include;
101 # If true then winemaker should not attempt to fix the source. This is
102 # useful if the source is known to be already in a suitable form and is
103 # readonly
104 my $opt_no_source_fix;
106 # Options for the 'Source' method
109 # Specifies that we have only one target so that all sources relate
110 # to this target. By default this variable is left undefined which
111 # means winemaker should try to find out by itself what the targets
112 # are. If not undefined then this contains the name of the default
113 # target (without the extension).
114 my $opt_single_target;
117 # If '$opt_single_target' has been specified then this is the type of
118 # that target. Otherwise it specifies whether the default target type
119 # is guiexe or cuiexe.
120 my $opt_target_type;
123 # Contains the default set of flags to be used when creating a new target.
124 my $opt_flags;
127 # Contains 32 for 32-Bit-Targets and 64 for 64-Bit-Targets
128 my $opt_arch;
131 # If true then winemaker should ask questions to the user as it goes
132 # along.
133 my $opt_is_interactive;
134 my $opt_ask_project_options;
135 my $opt_ask_target_options;
138 # If false then winemaker should not generate the makefiles.
139 my $opt_no_generated_files;
142 # Specifies not to print the banner if set.
143 my $opt_no_banner;
147 #####
149 # Target modelization
151 #####
153 # The description of a target is stored in an array. The constants
154 # below identify what is stored at each index of the array.
157 # This is the name of the target.
158 my $T_NAME=0;
161 # Defines the type of target we want to build. See the TT_xxx
162 # constants below
163 my $T_TYPE=1;
166 # This is a bitfield containing flags refining the way the target
167 # should be handled. See the TF_xxx constants below
168 my $T_FLAGS=2;
171 # This is a reference to an array containing the list of the
172 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
173 my $T_SOURCES_C=3;
174 my $T_SOURCES_CXX=4;
175 my $T_SOURCES_RC=5;
176 my $T_SOURCES_MISC=6;
179 # This is a reference to an array containing the list of
180 # C compiler options
181 my $T_CEXTRA=7;
184 # This is a reference to an array containing the list of
185 # C++ compiler options
186 my $T_CXXEXTRA=8;
189 # This is a reference to an array containing the list of
190 # RC compiler options
191 my $T_RCEXTRA=9;
194 # This is a reference to an array containing the list of macro
195 # definitions
196 my $T_DEFINES=10;
199 # This is a reference to an array containing the list of directory
200 # names that constitute the include path
201 my $T_INCLUDE_PATH=11;
204 # Flags for the linker
205 my $T_LDFLAGS=12;
208 # Same as T_INCLUDE_PATH but for the dll search path
209 my $T_DLL_PATH=13;
212 # The list of Windows dlls to import
213 my $T_DLLS=14;
216 # Same as T_INCLUDE_PATH but for the library search path
217 my $T_LIBRARY_PATH=15;
220 # The list of Unix libraries to link with
221 my $T_LIBRARIES=16;
224 # The list of dependencies between targets
225 my $T_DEPENDS=17;
228 # The following constants define the recognized types of target
231 # This is not a real target. This type of target is used to collect
232 # the sources that don't seem to belong to any other target. Thus no
233 # real target is generated for them, we just put the sources of the
234 # fake target in the global source list.
235 my $TT_SETTINGS=0;
238 # For executables in the windows subsystem
239 my $TT_GUIEXE=1;
242 # For executables in the console subsystem
243 my $TT_CUIEXE=2;
246 # For dynamically linked libraries
247 my $TT_DLL=3;
250 # The following constants further refine how the target should be handled
253 # This target is an MFC-based target
254 my $TF_MFC=4;
257 # User has specified --nomfc option for this target or globally
258 my $TF_NOMFC=8;
261 # --nodlls option: Do not use standard DLL set
262 my $TF_NODLLS=16;
265 # --nomsvcrt option: Do not link with msvcrt
266 my $TF_NOMSVCRT=32;
269 # Initialize a target:
270 # - set the target type to TT_SETTINGS, i.e. no real target will
271 # be generated.
272 sub target_init($)
274 my $target=$_[0];
276 @$target[$T_TYPE]=$TT_SETTINGS;
277 # leaving $T_INIT undefined
278 @$target[$T_FLAGS]=$opt_flags;
279 @$target[$T_SOURCES_C]=[];
280 @$target[$T_SOURCES_CXX]=[];
281 @$target[$T_SOURCES_RC]=[];
282 @$target[$T_SOURCES_MISC]=[];
283 @$target[$T_CEXTRA]=[];
284 @$target[$T_CXXEXTRA]=[];
285 @$target[$T_RCEXTRA]=[];
286 @$target[$T_DEFINES]=[];
287 @$target[$T_INCLUDE_PATH]=[];
288 @$target[$T_LDFLAGS]=[];
289 @$target[$T_DLL_PATH]=[];
290 @$target[$T_DLLS]=[];
291 @$target[$T_LIBRARY_PATH]=[];
292 @$target[$T_LIBRARIES]=[];
297 #####
299 # Project modelization
301 #####
303 # First we have the notion of project. A project is described by an
304 # array (since we don't have structs in perl). The constants below
305 # identify what is stored at each index of the array.
308 # This is the path in which this project is located. In other
309 # words, this is the path to the Makefile.
310 my $P_PATH=0;
313 # This index contains a reference to an array containing the project-wide
314 # settings. The structure of that arrray is actually identical to that of
315 # a regular target since it can also contain extra sources.
316 my $P_SETTINGS=1;
319 # This index contains a reference to an array of targets for this
320 # project. Each target describes how an executable or library is to
321 # be built. For each target this description takes the same form as
322 # that of the project: an array. So this entry is an array of arrays.
323 my $P_TARGETS=2;
326 # Initialize a project:
327 # - set the project's path
328 # - initialize the target list
329 # - create a default target (will be removed later if unnecessary)
330 sub project_init($$$)
332 my ($project, $path, $global_settings)=@_;
334 my $project_settings=[];
335 target_init($project_settings);
336 @$project_settings[$T_DEFINES]=[@{@$global_settings[$T_DEFINES]}];
337 @$project_settings[$T_INCLUDE_PATH]=[@{@$global_settings[$T_INCLUDE_PATH]}];
338 @$project_settings[$T_DLL_PATH]=[@{@$global_settings[$T_DLL_PATH]}];
339 @$project_settings[$T_DLLS]=[@{@$global_settings[$T_DLLS]}];
340 @$project_settings[$T_LIBRARY_PATH]=[@{@$global_settings[$T_LIBRARY_PATH]}];
341 @$project_settings[$T_LIBRARIES]=[@{@$global_settings[$T_LIBRARIES]}];
343 @$project[$P_PATH]=$path;
344 @$project[$P_SETTINGS]=$project_settings;
345 @$project[$P_TARGETS]=[];
350 #####
352 # Global variables
354 #####
356 my %warnings;
358 my %templates;
361 # This maps a directory name to a reference to an array listing
362 # its contents (files and directories)
363 my %directories;
366 # Contains the list of all projects. This list tells us what are
367 # the subprojects of the main Makefile and where we have to generate
368 # Makefiles.
369 my @projects=();
372 # This is the main project, i.e. the one in the "." directory.
373 # It may well be empty in which case the main Makefile will only
374 # call out subprojects.
375 my @main_project;
378 # Contains the defaults for the include path, etc.
379 # We store the defaults as if this were a target except that we only
380 # exploit the defines, include path, library path, library list and misc
381 # sources fields.
382 my @global_settings;
386 #####
388 # Utility functions
390 #####
393 # Cleans up a name to make it an acceptable Makefile
394 # variable name.
395 sub canonize($)
397 my $name=$_[0];
399 $name =~ tr/a-zA-Z0-9_/_/c;
400 return $name;
404 # Returns true is the specified pathname is absolute.
405 # Note: pathnames that start with a variable '$' or
406 # '~' are considered absolute.
407 sub is_absolute($)
409 my $path=$_[0];
411 return ($path =~ /^[\/~\$]/);
415 # Retrieves the contents of the specified directory.
416 # We either get it from the directories hashtable which acts as a
417 # cache, or use opendir, readdir, closedir and store the result
418 # in the hashtable.
419 sub get_directory_contents($)
421 my $dirname=$_[0];
422 my $directory;
424 #print "getting the contents of $dirname\n";
426 # check for a cached version
427 $dirname =~ s+/$++;
428 if ($dirname eq "") {
429 $dirname=cwd;
431 $directory=$directories{$dirname};
432 if (defined $directory) {
433 #print "->@$directory\n";
434 return $directory;
437 # Read this directory
438 if (opendir(DIRECTORY, "$dirname")) {
439 my @files=readdir DIRECTORY;
440 closedir(DIRECTORY);
441 $directory=\@files;
442 } else {
443 # Return an empty list
444 #print "error: cannot open $dirname\n";
445 my @files;
446 $directory=\@files;
448 #print "->@$directory\n";
449 $directories{$dirname}=$directory;
450 return $directory;
454 # Removes a directory from the cache.
455 # This is needed if one of its files or subdirectory has been renamed.
456 sub clear_directory_cache($)
458 my ($dirname)=@_;
459 delete $directories{$dirname};
463 #####
465 # 'Source'-based Project analysis
467 #####
470 # Allows the user to specify makefile and target specific options
471 # - target: the structure in which to store the results
472 # - options: the string containing the options
473 sub source_set_options($$)
475 my $target=$_[0];
476 my $options=$_[1];
478 #FIXME: we must deal with escaping of stuff and all
479 foreach my $option (split / /,$options) {
480 if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
481 push @{@$target[$T_DEFINES]},$option;
482 } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
483 push @{@$target[$T_INCLUDE_PATH]},$option;
484 } elsif ($option =~ /^-P/) {
485 push @{@$target[$T_DLL_PATH]},"-L$'";
486 } elsif ($option =~ /^-i/) {
487 push @{@$target[$T_DLLS]},"$'";
488 } elsif ($option =~ /^-L/) {
489 push @{@$target[$T_LIBRARY_PATH]},$option;
490 } elsif ($option =~ /^-l/) {
491 push @{@$target[$T_LIBRARIES]},"$'";
492 } elsif ($option =~ /^--mfc/) {
493 @$target[$T_FLAGS]|=$TF_MFC;
494 @$target[$T_FLAGS]&=~$TF_NOMFC;
495 } elsif ($option =~ /^--nomfc/) {
496 @$target[$T_FLAGS]&=~$TF_MFC;
497 @$target[$T_FLAGS]|=$TF_NOMFC;
498 } elsif ($option =~ /^--nodlls/) {
499 @$target[$T_FLAGS]|=$TF_NODLLS;
500 } elsif ($option =~ /^--nomsvcrt/) {
501 @$target[$T_FLAGS]|=$TF_NOMSVCRT;
502 } else {
503 print STDERR "error: unknown option \"$option\"\n";
504 return 0;
507 return 1;
511 # Scans the specified project file to:
512 # - get a list of targets for this project
513 # - get some settings
514 # - get the list of source files
515 sub source_scan_project_file($$$);
516 sub source_scan_project_file($$$)
518 # a reference to the parent's project
519 my $parent_project=$_[0];
520 # 0 if it is a single project, 1 if it is part of a workspace
521 my $is_sub_project=$_[1];
522 # the name of the project file, with complete path, or without if in
523 # the same directory
524 my $filename=$_[2];
526 # reference to the project for this file. May not be used
527 my $project;
528 # list of targets found in the current file
529 my %targets;
530 # list of sources found in the current file
531 my @sources_c=();
532 my @sources_cxx=();
533 my @sources_rc=();
534 my @sources_misc=();
535 # some more settings
536 my $path=dirname($filename);
537 my $prj_target_cflags;
538 my $prj_target_ldflags;
539 my $prj_target_libs;
540 my $prj_name;
541 my $found_cfg=0;
542 my $prj_cfg;
543 my $prj_target_type=1;
544 my @prj_target_options;
546 if (!($path=~/\/$/)) {
547 $path.="/";
550 if (defined $opt_single_target or $is_sub_project == 0) {
551 # Either there is a single target and thus a single project,
552 # or we are a single project-file for which a project
553 # already exists
554 $project=$parent_project;
555 } else {
556 $project=[];
557 project_init($project, $path, \@global_settings);
559 my $project_settings=@$project[$P_SETTINGS];
561 if ($filename =~ /.dsp$/i) {
562 # First find out what this project file contains:
563 # collect all sources, find targets and settings
564 if (!open(FILEI,$filename)) {
565 print STDERR "error: unable to open $filename for reading:\n";
566 print STDERR " $!\n";
567 return;
569 my $sfilet;
570 while (<FILEI>) {
571 # Remove any trailing CtrlZ, which isn't strictly in the file
572 if (/\x1A/) {
573 s/\x1A//;
574 last if (/^$/)
577 # Remove any trailing CrLf
578 s/\r\n$/\n/;
579 if (!/\n$/) {
580 # Make sure all lines are '\n' terminated
581 $_ .= "\n";
584 if (/^\# Microsoft Developer Studio Project File - Name=\"([^\"]+)/) {
585 $prj_name="$1.exe";
586 $targets{$prj_name}=1;
587 #print $prj_name;
588 next;
589 } elsif (/^# TARGTYPE/) {
590 if (/[[:space:]]0x0101$/) {
591 # Win32 (x86) Application
592 $prj_target_type=1;
593 }elsif (/[[:space:]]0x0102$/) {
594 # Win32 (x86) Dynamic-Link Library
595 $prj_target_type=3;
596 }elsif (/[[:space:]]0x0103$/) {
597 # Win32 (x86) Console Application
598 $prj_target_type=2;
599 }elsif (/[[:space:]]0x0104$/) {
600 # Win32 (x86) Static Library
602 next;
603 } elsif (/^# ADD CPP(.*)/ && $found_cfg==1) {
604 $prj_target_cflags=$1;
605 @prj_target_options=split(" /", $prj_target_cflags);
606 $prj_target_cflags="";
607 foreach ( @prj_target_options ) {
608 if ($_ eq "") {
609 # empty
610 } elsif (/nologo/) {
611 # Suppress Startup Banner and Information Messages
612 } elsif (/^W0$/) {
613 # Turns off all warning messages
614 $prj_target_cflags.="-w ";
615 } elsif (/^W[123]$/) {
616 # Warning Level
617 $prj_target_cflags.="-W ";
618 } elsif (/^W4$/) {
619 # Warning Level
620 $prj_target_cflags.="-Wall ";
621 } elsif (/^WX$/) {
622 # Warnings As Errors
623 $prj_target_cflags.="-Werror ";
624 } elsif (/^Gm$/) {
625 # Enable Minimal Rebuild
626 } elsif (/^GX$/) {
627 # Enable Exception Handling
628 $prj_target_cflags.="-fexceptions ";
629 } elsif (/^Z[d7iI]$/) {
630 # Debug Info
631 $prj_target_cflags.="-g ";
632 } elsif (/^Od$/) {
633 # Disable Optimizations
634 $prj_target_cflags.="-O0 ";
635 } elsif (/^O1$/) {
636 # Minimize Size
637 $prj_target_cflags.="-Os ";
638 } elsif (/^O2$/) {
639 # Maximize Speed
640 $prj_target_cflags.="-O2 ";
641 } elsif (/^Ob0$/) {
642 # Disables inline Expansion
643 $prj_target_cflags.="-fno-inline ";
644 } elsif (/^Ob1$/) {
645 #In-line Function Expansion
646 $prj_target_cflags.="-finline-functions ";
647 } elsif (/^Ob2$/) {
648 # auto In-line Function Expansion
649 $prj_target_cflags.="-finline-functions ";
650 } elsif (/^Ox$/) {
651 # Use maximum optimization
652 $prj_target_cflags.="-O3 ";
653 } elsif (/^Oy$/) {
654 # Frame-Pointer Omission
655 $prj_target_cflags.="-fomit-frame-pointer ";
656 } elsif (/^Oy-$/) {
657 # Frame-Pointer Omission
658 $prj_target_cflags.="-fno-omit-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\s*\"(.*)\"/) {
667 # Additional Include Directories
668 $sfilet=$1;
669 $sfilet=~s/\\/\//g;
670 push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$sfilet." ";
671 } elsif (/^U\s*\"(.*)\"/) {
672 # Undefines a previously defined symbol
673 $prj_target_cflags.="-U".$1." ";
674 } elsif (/^Fp/) {
675 # Name .PCH File
676 } elsif (/^F[Rr]/) {
677 # Create .SBR File
678 } elsif (/^YX$/) {
679 # Automatic Use of Precompiled Headers
680 } elsif (/^FD$/) {
681 # Generate File Dependencies
682 } elsif (/^c$/) {
683 # Compile Without Linking
684 # this option is always present and is already specified in the suffix rules
685 } elsif (/^GB$/) {
686 # Blend Optimization
687 $prj_target_cflags.="-mcpu=pentiumpro -D_M_IX86=500 ";
688 } elsif (/^G6$/) {
689 # Pentium Pro Optimization
690 $prj_target_cflags.="-march=pentiumpro -D_M_IX86=600 ";
691 } elsif (/^G5$/) {
692 # Pentium Optimization
693 $prj_target_cflags.="-mcpu=pentium -D_M_IX86=500 ";
694 } elsif (/^G3$/) {
695 # 80386 Optimization
696 $prj_target_cflags.="-mcpu=i386 -D_M_IX86=300 ";
697 } elsif (/^G4$/) {
698 # 80486 Optimization
699 $prj_target_cflags.="-mcpu=i486 -D_M_IX86=400 ";
700 } elsif (/^Yc/) {
701 # Create Precompiled Header
702 } elsif (/^Yu/) {
703 # Use Precompiled Header
704 } elsif (/^Za$/) {
705 # Disable Language Extensions
706 $prj_target_cflags.="-ansi ";
707 } elsif (/^Ze$/) {
708 # Enable Microsoft Extensions
709 } elsif (/^Zm[[:digit:]]+$/) {
710 # Specify Memory Allocation Limit
711 } elsif (/^Zp1?$/) {
712 # Packs structures on 1-byte boundaries
713 $prj_target_cflags.="-fpack-struct ";
714 } elsif (/^Zp(2|4|8|16)$/) {
715 # Struct Member Alignment
716 $prj_target_cflags.="-fpack-struct=".$1;
717 } else {
718 print "C compiler option $_ not implemented\n";
722 #print "\nOptions: $prj_target_cflags\n";
723 next;
724 } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
725 $prj_target_ldflags=$1;
726 @prj_target_options=split(" /", $prj_target_ldflags);
727 $prj_target_ldflags="";
728 $prj_target_libs=$prj_target_options[0];
729 #print "\n$prj_target_libs bevor\n";
730 $prj_target_libs=~s/\\/\//g;
731 $prj_target_libs=~s/\.lib//g;
732 $prj_target_libs=~s/\s+/ -l/g;
733 #print "\n$prj_target_libs after\n";
734 shift (@prj_target_options);
735 foreach ( @prj_target_options ) {
736 if ($_ eq "") {
737 # empty
738 } elsif (/^base:(.*)/) {
739 # Base Address
740 $prj_target_ldflags.="--image-base ".$1." ";
741 } elsif (/^debug$/) {
742 # Generate Debug Info
743 } elsif (/^dll$/) {
744 # Build a DLL
745 $prj_target_type=3;
746 } elsif (/^incremental:[[:alpha:]]+$/) {
747 # Link Incrmentally
748 } elsif (/^implib:/) {
749 # Name import library
750 } elsif (/^libpath:\"(.*)\"/) {
751 # Additional Libpath
752 push @{@$project_settings[$T_DLL_PATH]},"-L$1";
753 } elsif (/^machine:[[:alnum:]]+$/) {
754 # Specify Target Platform
755 } elsif (/^map/) {
756 # Generate Mapfile
757 if (/^map:(.*)/) {
758 $prj_target_ldflags.="-Map ".$1." ";
759 } else {
760 $prj_target_ldflags.="-Map ".$prj_name.".map ";
762 } elsif (/^nologo$/) {
763 # Suppress Startup Banner and Information Messages
764 } elsif (/^out:/) {
765 # Output File Name
766 # may use it as Target?
767 } elsif (/^pdbtype:/) {
768 # Program Database Storage
769 } elsif (/^subsystem:/) {
770 # Specify Subsystem
771 } elsif (/^version:[[:digit:].]+$/) {
772 # Version Information
773 } else {
774 print "Linker option $_ not implemented\n";
777 next;
778 } elsif (/^LIB32=/ && $found_cfg==1) {
779 #$libflag = 1;
780 next;
781 } elsif (/^SOURCE=(.*)$/) {
782 my @components=split /[\/\\]+/, $1;
783 $sfilet=search_from($path, \@components);
784 if ($sfilet =~ /\.(exe|dll)$/i) {
785 $targets{$sfilet}=1;
786 } elsif ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
787 push @sources_c,$sfilet;
788 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
789 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
790 push @sources_misc,$sfilet;
791 @$project_settings[$T_FLAGS]|=$TF_MFC;
792 } else {
793 push @sources_cxx,$sfilet;
795 } elsif ($sfilet =~ /\.rc$/i) {
796 push @sources_rc,$sfilet;
797 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
798 push @sources_misc,$sfilet;
799 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
800 @$project_settings[$T_FLAGS]|=$TF_MFC;
803 next;
805 } elsif (/^# (Begin|End) Source File/) {
806 # Source-Files already handled
807 next;
808 } elsif (/^# (Begin|End) Group/) {
809 # Groups are ignored
810 next;
811 } elsif (/^# (Begin|End) Custom Build/) {
812 # Custom Builds are ignored
813 next;
814 } elsif (/^# ADD LIB32 /) {
815 #"ARFLAGS=rus"
816 next;
817 } elsif (/^# Begin Target$/) {
818 # Targets are ignored
819 next;
820 } elsif (/^# End Target$/) {
821 # Targets are ignored
822 next;
823 } elsif (/^!/) {
824 if ($found_cfg == 1) {
825 $found_cfg=0;
827 if (/if (.*)\(CFG\)" == "(.*)"/i) {
828 if ($2 eq $prj_cfg) {
829 $found_cfg=1;
832 next;
833 } elsif (/^CFG=(.*)/i) {
834 $prj_cfg=$1;
835 next;
837 else { # Line recognized
838 # print "|\n";
841 close(FILEI);
843 push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
844 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
845 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
846 push @{@$project_settings[$T_LDFLAGS]},$prj_target_ldflags;
847 } elsif ($filename =~ /.vcproj$/i) {
848 # Import des Moduls XML::Simple
849 use XML::Simple;
851 my $project_xml = XMLin($filename, forcearray=>1);
853 $targets{$project_xml->{'Name'}.".exe"}=1;
854 my $sfilet;
855 for my $vc_files (@{$project_xml->{'Files'}}) {
856 for my $vc_filter (@{$vc_files->{'Filter'}}) {
857 for my $vc_file (@{$vc_filter->{'File'}}) {
858 $sfilet=$vc_file->{'RelativePath'};
859 $sfilet=~s/\\\\/\\/g; #remove double backslash
860 $sfilet=~s/^\.\\//; #remove starting 'this directory'
861 $sfilet=~s/\\/\//g; #make slashes out of backslashes
862 if ($sfilet =~ /\.(exe|dll)$/i) {
863 $targets{$sfilet}=1;
864 } elsif ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
865 push @sources_c,$sfilet;
866 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
867 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
868 push @sources_misc,$sfilet;
869 @$project_settings[$T_FLAGS]|=$TF_MFC;
870 } else {
871 push @sources_cxx,$sfilet;
873 } elsif ($sfilet =~ /\.rc$/i) {
874 push @sources_rc,$sfilet;
875 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
876 push @sources_misc,$sfilet;
877 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
878 @$project_settings[$T_FLAGS]|=$TF_MFC;
884 $prj_target_cflags="";
885 for my $vc_configurations (@{$project_xml->{'Configurations'}}) {
886 for my $vc_configuration (@{$vc_configurations->{'Configuration'}}) {
887 for my $vc_tool (@{$vc_configuration->{'Tool'}}) {
888 if ($vc_tool->{'Name'} ne 'VCCLCompilerTool') { next; }
889 if (defined $vc_tool->{'Optimization'}) {$prj_target_cflags.="-O".$vc_tool->{'Optimization'}." ";}
890 if (defined $vc_tool->{'WarningLevel'}) {
891 if ($vc_tool->{'WarningLevel'}==0) {
892 $prj_target_cflags.="-w ";
893 } elsif ($vc_tool->{'WarningLevel'}<4) {
894 $prj_target_cflags.="-W ";
895 } elsif ($vc_tool->{'WarningLevel'}==4) {
896 $prj_target_cflags.="-Wall ";
897 } elsif ($vc_tool->{'WarningLevel'} eq "X") {
898 $prj_target_cflags.="-Werror ";
901 if (defined $vc_tool->{'PreprocessorDefinitions'}) {
902 $vc_tool->{'PreprocessorDefinitions'}=~s/;/ -D/g;
903 $prj_target_cflags.="-D".$vc_tool->{'PreprocessorDefinitions'}." ";
905 if (defined $vc_tool->{'AdditionalIncludeDirectories'}) {
906 $vc_tool->{'AdditionalIncludeDirectories'}=~s/\\/\//g;
907 $vc_tool->{'AdditionalIncludeDirectories'}=~s/;/ -I/g;
908 push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$vc_tool->{'AdditionalIncludeDirectories'};
911 last;
914 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
915 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
918 my $target_count;
919 $target_count=keys %targets;
922 # Add this project to the project list, except for
923 # the main project which is already in the list.
924 if ($is_sub_project == 1) {
925 push @projects,$project;
928 # Ask for project-wide options
929 if ($opt_ask_project_options == $OPT_ASK_YES) {
930 my $flag_desc="";
931 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
932 $flag_desc="mfc";
934 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
935 if (defined $flag_desc) {
936 print "* (currently $flag_desc)\n";
938 print "* or 'skip' to skip the target specific options,\n";
939 print "* or 'never' to not be asked this question again:\n";
940 while (1) {
941 my $options=<STDIN>;
942 chomp $options;
943 if ($options eq "skip") {
944 $opt_ask_target_options=$OPT_ASK_SKIP;
945 last;
946 } elsif ($options eq "never") {
947 $opt_ask_project_options=$OPT_ASK_NO;
948 last;
949 } elsif (source_set_options($project_settings,$options)) {
950 last;
952 print "Please re-enter the options:\n";
956 # - Create the targets
957 # - Check if we have both libraries and programs
958 # - Match each target with source files (sort in reverse
959 # alphabetical order to get the longest matches first)
960 my @local_dlls=();
961 my @local_depends=();
962 my @exe_list=();
963 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
964 # Create the target...
965 my $target=[];
966 target_init($target);
967 @$target[$T_NAME]=$target_name;
968 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
969 if ($target_name =~ /\.dll$/) {
970 @$target[$T_TYPE]=$TT_DLL;
971 push @local_depends,"$target_name.so";
972 push @local_dlls,$target_name;
973 my $canon=canonize($target_name);
974 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
975 } else {
976 @$target[$T_TYPE]=$opt_target_type;
977 push @exe_list,$target;
978 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
980 my $basename=$target_name;
981 $basename=~ s/\.(dll|exe)$//i;
982 # This is the default link list of Visual Studio
983 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
984 my @std_libraries=qw(uuid);
985 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
986 @$target[$T_DLLS]=\@std_imports;
987 @$target[$T_LIBRARIES]=\@std_libraries;
988 } else {
989 @$target[$T_DLLS]=[];
990 @$target[$T_LIBRARIES]=[];
992 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
993 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
994 push @{@$target[$T_LDFLAGS]},"-m$opt_arch";
996 push @{@$project[$P_TARGETS]},$target;
998 # Ask for target-specific options
999 if ($opt_ask_target_options == $OPT_ASK_YES) {
1000 my $flag_desc="";
1001 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
1002 $flag_desc=" (mfc";
1004 if ($flag_desc ne "") {
1005 $flag_desc.=")";
1007 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1008 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1009 while (1) {
1010 my $options=<STDIN>;
1011 chomp $options;
1012 if ($options eq "never") {
1013 $opt_ask_target_options=$OPT_ASK_NO;
1014 last;
1015 } elsif (source_set_options($target,$options)) {
1016 last;
1018 print "Please re-enter the options:\n";
1021 if (@$target[$T_FLAGS] & $TF_MFC) {
1022 @$project_settings[$T_FLAGS]|=$TF_MFC;
1023 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1024 push @{@$target[$T_DLLS]},"mfc.dll";
1025 # FIXME: Link with the MFC in the Unix sense, until we
1026 # start exporting the functions properly.
1027 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1028 push @{@$target[$T_LIBRARIES]},"mfc";
1031 # Match sources...
1032 if ($target_count == 1) {
1033 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1034 @$project_settings[$T_SOURCES_C]=[];
1035 @sources_c=();
1037 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1038 @$project_settings[$T_SOURCES_CXX]=[];
1039 @sources_cxx=();
1041 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1042 @$project_settings[$T_SOURCES_RC]=[];
1043 @sources_rc=();
1045 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1046 # No need for sorting these sources
1047 @$project_settings[$T_SOURCES_MISC]=[];
1048 @sources_misc=();
1050 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1051 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1052 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1053 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1055 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1056 $opt_ask_target_options=$OPT_ASK_YES;
1059 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1060 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1061 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1064 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1065 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1067 # The sources that did not match, if any, go to the extra
1068 # source list of the project settings
1069 foreach my $source (@sources_c) {
1070 if ($source ne "") {
1071 push @{@$project_settings[$T_SOURCES_C]},$source;
1074 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1075 foreach my $source (@sources_cxx) {
1076 if ($source ne "") {
1077 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1080 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1081 foreach my $source (@sources_rc) {
1082 if ($source ne "") {
1083 push @{@$project_settings[$T_SOURCES_RC]},$source;
1086 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1087 foreach my $source (@sources_misc) {
1088 if ($source ne "") {
1089 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1092 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1096 # Scans the specified workspace file to find the project files
1097 sub source_scan_workspace_file($);
1098 sub source_scan_workspace_file($)
1100 my $filename=$_[0];
1101 my $path=dirname($filename);
1102 my @components;
1104 if (! -e $filename) {
1105 return;
1108 if (!open(FILEIWS,$filename)) {
1109 print STDERR "error: unable to open $filename for reading:\n";
1110 print STDERR " $!\n";
1111 return;
1114 my $prj_name;
1115 my $prj_path;
1117 if ($filename =~ /.dsw$/i) {
1118 while (<FILEIWS>) {
1119 # Remove any trailing CrLf
1120 s/\r\n$/\n/;
1122 # catch a project definition
1123 if (/^Project:\s\"(.*)\"=(.*)\s-/) {
1124 $prj_name=$1;
1125 $prj_path=$2;
1126 @components=split /[\/\\]+/, $prj_path;
1127 $prj_path=search_from($path, \@components);
1128 print "Name: $prj_name\nPath: $prj_path\n";
1129 source_scan_project_file(\@main_project,1,$prj_path);
1130 next;
1131 } elsif (/^#/) {
1132 # ignore Comments
1133 } elsif (/\w:/) {
1134 print STDERR "unknown section $_\n";
1135 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1136 print "\nFileversion: $3\n";
1139 close(FILEIWS);
1140 } elsif ($filename =~ /.sln$/i) {
1141 while (<FILEIWS>) {
1142 # Remove any trailing CrLf
1143 s/\r\n$/\n/;
1145 # catch a project definition
1146 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1147 $prj_name=$2;
1148 $prj_path=$3;
1149 @components=split /[\/\\]+/, $3;
1150 $prj_path=search_from($path, \@components);
1151 print "Name: $prj_name\nPath: $prj_path\n";
1152 source_scan_project_file(\@main_project,1,$prj_path);
1153 next;
1154 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1155 print "\nFileversion: $3\n";
1158 close(FILEIWS);
1161 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1165 # Scans the specified directory to:
1166 # - see if we should create a Makefile in this directory. We normally do
1167 # so if we find a project file and sources
1168 # - get a list of targets for this directory
1169 # - get the list of source files
1170 sub source_scan_directory($$$$);
1171 sub source_scan_directory($$$$)
1173 # a reference to the parent's project
1174 my $parent_project=$_[0];
1175 # the full relative path to the current directory, including a
1176 # trailing '/', or an empty string if this is the top level directory
1177 my $path=$_[1];
1178 # the name of this directory, including a trailing '/', or an empty
1179 # string if this is the top level directory
1180 my $dirname=$_[2];
1181 # if set then no targets will be looked for and the sources will all
1182 # end up in the parent_project's 'misc' bucket
1183 my $no_target=$_[3];
1185 # reference to the project for this directory. May not be used
1186 my $project;
1187 # list of targets found in the 'current' directory
1188 my %targets;
1189 # list of sources found in the current directory
1190 my @sources_c=();
1191 my @sources_cxx=();
1192 my @sources_rc=();
1193 my @sources_misc=();
1194 # true if this directory contains a Windows project
1195 my $has_win_project=0;
1196 # true if this directory contains headers
1197 my $has_headers=0;
1198 # If we don't find any executable/library then we might make up targets
1199 # from the list of .dsp/.mak files we find since they usually have the
1200 # same name as their target.
1201 my @dsp_files=();
1202 my @mak_files=();
1204 if (defined $opt_single_target or $dirname eq "") {
1205 # Either there is a single target and thus a single project,
1206 # or we are in the top level directory for which a project
1207 # already exists
1208 $project=$parent_project;
1209 } else {
1210 $project=[];
1211 project_init($project, $path, \@global_settings);
1213 my $project_settings=@$project[$P_SETTINGS];
1215 # First find out what this directory contains:
1216 # collect all sources, targets and subdirectories
1217 my $directory=get_directory_contents($path);
1218 foreach my $dentry (@$directory) {
1219 if ($dentry =~ /^\./) {
1220 next;
1222 my $fullentry="$path$dentry";
1223 if (-d "$fullentry") {
1224 if ($dentry =~ /^(Release|Debug)/i) {
1225 # These directories are often used to store the object files and the
1226 # resulting executable/library. They should not contain anything else.
1227 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
1228 foreach my $candidate (@candidates) {
1229 $targets{$candidate}=1;
1231 } elsif ($dentry =~ /^include/i) {
1232 # This directory must contain headers we're going to need
1233 push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1234 source_scan_directory($project,"$fullentry/","$dentry/",1);
1235 } else {
1236 # Recursively scan this directory. Any source file that cannot be
1237 # attributed to a project in one of the subdirectories will be
1238 # attributed to this project.
1239 source_scan_directory($project,"$fullentry/","$dentry/",$no_target);
1241 } elsif (-f "$fullentry") {
1242 if ($dentry =~ /\.(exe|dll)$/i) {
1243 $targets{$dentry}=1;
1244 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1245 push @sources_c,"$dentry";
1246 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
1247 if ($dentry =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1248 push @sources_misc,"$dentry";
1249 @$project_settings[$T_FLAGS]|=$TF_MFC;
1250 } else {
1251 push @sources_cxx,"$dentry";
1253 } elsif ($dentry =~ /\.rc$/i) {
1254 push @sources_rc,"$dentry";
1255 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1256 $has_headers=1;
1257 push @sources_misc,"$dentry";
1258 if ($dentry =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1259 @$project_settings[$T_FLAGS]|=$TF_MFC;
1261 } elsif ($dentry =~ /\.dsp$/i) {
1262 push @dsp_files,"$dentry";
1263 $has_win_project=1;
1264 } elsif ($dentry =~ /\.mak$/i) {
1265 push @mak_files,"$dentry";
1266 $has_win_project=1;
1267 } elsif ($dentry =~ /^makefile/i) {
1268 $has_win_project=1;
1273 if ($has_headers) {
1274 push @{@$project_settings[$T_INCLUDE_PATH]},"-I.";
1276 # If we have a single target then all we have to do is assign
1277 # all the sources to it and we're done
1278 # FIXME: does this play well with the --interactive mode?
1279 if ($opt_single_target) {
1280 my $target=@{@$project[$P_TARGETS]}[0];
1281 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1282 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1283 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1284 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1285 return;
1287 if ($no_target) {
1288 my $parent_settings=@$parent_project[$P_SETTINGS];
1289 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1290 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1291 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1292 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1293 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1294 return;
1297 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1298 @{@$project_settings[$T_SOURCES_C]}+
1299 @{@$project_settings[$T_SOURCES_CXX]}+
1300 @{@$project_settings[$T_SOURCES_RC]};
1301 if ($source_count == 0) {
1302 # A project without real sources is not a project, get out!
1303 if ($project!=$parent_project) {
1304 my $parent_settings=@$parent_project[$P_SETTINGS];
1305 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1306 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1308 return;
1310 #print "targets=",%targets,"\n";
1311 #print "target_count=$target_count\n";
1312 #print "has_win_project=$has_win_project\n";
1313 #print "dirname=$dirname\n";
1315 my $target_count;
1316 if (($has_win_project != 0) or ($dirname eq "")) {
1317 # Deal with cases where we could not find any executable/library, and
1318 # thus have no target, although we did find some sort of windows project.
1319 $target_count=keys %targets;
1320 if ($target_count == 0) {
1321 # Try to come up with a target list based on .dsp/.mak files
1322 my $prj_list;
1323 if (@dsp_files > 0) {
1324 $prj_list=\@dsp_files;
1325 } else {
1326 $prj_list=\@mak_files;
1328 foreach my $filename (@$prj_list) {
1329 $filename =~ s/\.(dsp|mak)$//i;
1330 if ($opt_target_type == $TT_DLL) {
1331 $filename = "$filename.dll";
1333 $targets{$filename}=1;
1335 $target_count=keys %targets;
1336 if ($target_count == 0) {
1337 # Still nothing, try the name of the directory
1338 my $name;
1339 if ($dirname eq "") {
1340 # Bad luck, this is the top level directory!
1341 $name=(split /\//, cwd)[-1];
1342 } else {
1343 $name=$dirname;
1344 # Remove the trailing '/'. Also eliminate whatever is after the last
1345 # '.' as it is likely to be meaningless (.orig, .new, ...)
1346 $name =~ s+(/|\.[^.]*)$++;
1347 if ($name eq "src") {
1348 # 'src' is probably a subdirectory of the real project directory.
1349 # Try again with the parent (if any).
1350 my $parent=$path;
1351 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
1352 $name=$parent;
1353 } else {
1354 $name=(split /\//, cwd)[-1];
1358 $name =~ s+(/|\.[^.]*)$++;
1359 if ($opt_target_type == $TT_DLL) {
1360 $name = canonize($name).".dll";
1361 } else {
1362 $name = canonize($name).".exe";
1364 $targets{$name}=1;
1368 # Ask confirmation to the user if he wishes so
1369 if ($opt_is_interactive == $OPT_ASK_YES) {
1370 my $target_list=join " ",keys %targets;
1371 print "\n*** In ",($path?$path:"./"),"\n";
1372 print "* winemaker found the following list of (potential) targets\n";
1373 print "* $target_list\n";
1374 print "* Type enter to use it as is, your own comma-separated list of\n";
1375 print "* targets, 'none' to assign the source files to a parent directory,\n";
1376 print "* or 'ignore' to ignore everything in this directory tree.\n";
1377 print "* Target list:\n";
1378 $target_list=<STDIN>;
1379 chomp $target_list;
1380 if ($target_list eq "") {
1381 # Keep the target list as is, i.e. do nothing
1382 } elsif ($target_list eq "none") {
1383 # Empty the target list
1384 undef %targets;
1385 } elsif ($target_list eq "ignore") {
1386 # Ignore this subtree altogether
1387 return;
1388 } else {
1389 undef %targets;
1390 foreach my $target (split /,/,$target_list) {
1391 $target =~ s+^\s*++;
1392 $target =~ s+\s*$++;
1393 $targets{$target}=1;
1399 # If we have no project at this level, then transfer all
1400 # the sources to the parent project
1401 $target_count=keys %targets;
1402 if ($target_count == 0) {
1403 if ($project!=$parent_project) {
1404 my $parent_settings=@$parent_project[$P_SETTINGS];
1405 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1406 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1407 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1408 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1409 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1411 return;
1414 # Otherwise add this project to the project list, except for
1415 # the main project which is already in the list.
1416 if ($dirname ne "") {
1417 push @projects,$project;
1420 # Ask for project-wide options
1421 if ($opt_ask_project_options == $OPT_ASK_YES) {
1422 my $flag_desc="";
1423 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1424 $flag_desc="mfc";
1426 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1427 if (defined $flag_desc) {
1428 print "* (currently $flag_desc)\n";
1430 print "* or 'skip' to skip the target specific options,\n";
1431 print "* or 'never' to not be asked this question again:\n";
1432 while (1) {
1433 my $options=<STDIN>;
1434 chomp $options;
1435 if ($options eq "skip") {
1436 $opt_ask_target_options=$OPT_ASK_SKIP;
1437 last;
1438 } elsif ($options eq "never") {
1439 $opt_ask_project_options=$OPT_ASK_NO;
1440 last;
1441 } elsif (source_set_options($project_settings,$options)) {
1442 last;
1444 print "Please re-enter the options:\n";
1448 # - Create the targets
1449 # - Check if we have both libraries and programs
1450 # - Match each target with source files (sort in reverse
1451 # alphabetical order to get the longest matches first)
1452 my @local_dlls=();
1453 my @local_depends=();
1454 my @exe_list=();
1455 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1456 # Create the target...
1457 my $target=[];
1458 target_init($target);
1459 @$target[$T_NAME]=$target_name;
1460 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
1461 if ($target_name =~ /\.dll$/) {
1462 @$target[$T_TYPE]=$TT_DLL;
1463 push @local_depends,"$target_name.so";
1464 push @local_dlls,$target_name;
1465 my $canon=canonize($target_name);
1466 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
1467 } else {
1468 @$target[$T_TYPE]=$opt_target_type;
1469 push @exe_list,$target;
1470 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
1472 my $basename=$target_name;
1473 $basename=~ s/\.(dll|exe)$//i;
1474 # This is the default link list of Visual Studio
1475 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1476 my @std_libraries=qw(uuid);
1477 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1478 @$target[$T_DLLS]=\@std_imports;
1479 @$target[$T_LIBRARIES]=\@std_libraries;
1480 } else {
1481 @$target[$T_DLLS]=[];
1482 @$target[$T_LIBRARIES]=[];
1484 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1485 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
1486 push @{@$target[$T_LDFLAGS]},"-m$opt_arch";
1488 push @{@$project[$P_TARGETS]},$target;
1490 # Ask for target-specific options
1491 if ($opt_ask_target_options == $OPT_ASK_YES) {
1492 my $flag_desc="";
1493 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
1494 $flag_desc=" (mfc";
1496 if ($flag_desc ne "") {
1497 $flag_desc.=")";
1499 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1500 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1501 while (1) {
1502 my $options=<STDIN>;
1503 chomp $options;
1504 if ($options eq "never") {
1505 $opt_ask_target_options=$OPT_ASK_NO;
1506 last;
1507 } elsif (source_set_options($target,$options)) {
1508 last;
1510 print "Please re-enter the options:\n";
1513 if (@$target[$T_FLAGS] & $TF_MFC) {
1514 @$project_settings[$T_FLAGS]|=$TF_MFC;
1515 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1516 push @{@$target[$T_DLLS]},"mfc.dll";
1517 # FIXME: Link with the MFC in the Unix sense, until we
1518 # start exporting the functions properly.
1519 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1520 push @{@$target[$T_LIBRARIES]},"mfc";
1523 # Match sources...
1524 if ($target_count == 1) {
1525 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1526 @$project_settings[$T_SOURCES_C]=[];
1527 @sources_c=();
1529 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1530 @$project_settings[$T_SOURCES_CXX]=[];
1531 @sources_cxx=();
1533 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1534 @$project_settings[$T_SOURCES_RC]=[];
1535 @sources_rc=();
1537 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1538 # No need for sorting these sources
1539 @$project_settings[$T_SOURCES_MISC]=[];
1540 @sources_misc=();
1541 } else {
1542 foreach my $source (@sources_c) {
1543 if ($source =~ /^$basename/i) {
1544 push @{@$target[$T_SOURCES_C]},$source;
1545 $source="";
1548 foreach my $source (@sources_cxx) {
1549 if ($source =~ /^$basename/i) {
1550 push @{@$target[$T_SOURCES_CXX]},$source;
1551 $source="";
1554 foreach my $source (@sources_rc) {
1555 if ($source =~ /^$basename/i) {
1556 push @{@$target[$T_SOURCES_RC]},$source;
1557 $source="";
1560 foreach my $source (@sources_misc) {
1561 if ($source =~ /^$basename/i) {
1562 push @{@$target[$T_SOURCES_MISC]},$source;
1563 $source="";
1567 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1568 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1569 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1570 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1572 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1573 $opt_ask_target_options=$OPT_ASK_YES;
1576 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1577 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1578 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1581 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1582 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1584 # The sources that did not match, if any, go to the extra
1585 # source list of the project settings
1586 foreach my $source (@sources_c) {
1587 if ($source ne "") {
1588 push @{@$project_settings[$T_SOURCES_C]},$source;
1591 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1592 foreach my $source (@sources_cxx) {
1593 if ($source ne "") {
1594 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1597 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1598 foreach my $source (@sources_rc) {
1599 if ($source ne "") {
1600 push @{@$project_settings[$T_SOURCES_RC]},$source;
1603 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1604 foreach my $source (@sources_misc) {
1605 if ($source ne "") {
1606 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1609 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1611 # Finally if we are building both libraries and programs in
1612 # this directory, then the programs should be linked with all
1613 # the libraries
1614 if (@local_dlls > 0 and @exe_list > 0) {
1615 foreach my $target (@exe_list) {
1616 push @{@$target[$T_DLL_PATH]},"-L.";
1617 push @{@$target[$T_DLLS]},@local_dlls;
1623 # Scan the source directories in search of things to build
1624 sub source_scan()
1626 # If there's a single target then this is going to be the default target
1627 if (defined $opt_single_target) {
1628 # Create the main target
1629 my $main_target=[];
1630 target_init($main_target);
1631 @$main_target[$T_NAME]=$opt_single_target;
1632 @$main_target[$T_TYPE]=$opt_target_type;
1634 # Add it to the list
1635 push @{$main_project[$P_TARGETS]},$main_target;
1638 # The main directory is always going to be there
1639 push @projects,\@main_project;
1641 if (defined $opt_work_dir) {
1642 # Now scan the directory tree looking for source files and, maybe, targets
1643 print "Scanning the source directories...\n";
1644 source_scan_directory(\@main_project,"","",0);
1645 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1646 } elsif (defined $opt_work_file) {
1647 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1648 source_scan_project_file(\@main_project,0,$opt_work_file);
1649 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1650 source_scan_workspace_file($opt_work_file);
1655 #####
1657 # Source search
1659 #####
1662 # Performs a directory traversal and renames the files so that:
1663 # - they have the case desired by the user
1664 # - their extension is of the appropriate case
1665 # - they don't contain annoying characters like ' ', '$', '#', ...
1666 # But only perform these changes for source files and directories.
1667 sub fix_file_and_directory_names($);
1668 sub fix_file_and_directory_names($)
1670 my $dirname=$_[0];
1672 my $directory=get_directory_contents($dirname);
1673 foreach my $dentry (@$directory)
1675 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1676 next;
1678 # Set $warn to 1 if the user should be warned of the renaming
1679 my $warn;
1680 my $new_name=$dentry;
1682 if (-f "$dirname/$dentry")
1684 # Don't rename Winemaker's makefiles
1685 next if ($dentry eq "Makefile" and
1686 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker/);
1688 # Leave non-source files alone
1689 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc))$/i);
1691 # Only all lowercase extensions are supported (because of
1692 # rules like '.c.o:'.
1693 $new_name =~ s/\.C$/.c/;
1694 $new_name =~ s/\.cpp$/.cpp/i;
1695 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1696 $new_name =~ s/\.rc$/.rc/i;
1697 # And this last one is to avoid confusion then running make
1698 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1701 # Adjust the case to the user's preferences
1702 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1703 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1705 $new_name=lc $new_name;
1708 # autoconf and make don't support these characters well
1709 $new_name =~ s/[ \$]/_/g;
1711 # And finally, perform the renaming
1712 if ($new_name ne $dentry)
1714 if ($warn) {
1715 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1717 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1718 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1719 print STDERR " $!\n";
1720 $new_name=$dentry;
1722 else
1724 clear_directory_cache($dirname);
1727 if (-d "$dirname/$new_name") {
1728 fix_file_and_directory_names("$dirname/$new_name");
1735 #####
1737 # Source fixup
1739 #####
1742 # Try to find a file for the specified filename. The attempt is
1743 # case-insensitive which is why it's not trivial. If a match is
1744 # found then we return the pathname with the correct case.
1745 sub search_from($$)
1747 my $dirname=$_[0];
1748 my $path=$_[1];
1749 my $real_path="";
1751 if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
1752 $dirname=cwd;
1753 } elsif ($dirname !~ m+^/+) {
1754 $dirname=cwd . "/" . $dirname;
1756 if ($dirname !~ m+/$+) {
1757 $dirname.="/";
1760 foreach my $component (@$path) {
1761 $component=~s/^\"//;
1762 $component=~s/\"$//;
1763 #print " looking for $component in \"$dirname\"\n";
1764 if ($component eq ".") {
1765 # Pass it as is
1766 $real_path.="./";
1767 } elsif ($component eq "..") {
1768 # Go up one level
1769 $dirname=dirname($dirname) . "/";
1770 $real_path.="../";
1771 } else {
1772 # The file/directory may have been renamed before. Also try to
1773 # match the renamed file.
1774 my $renamed=$component;
1775 $renamed =~ s/[ \$]/_/g;
1776 if ($renamed eq $component) {
1777 undef $renamed;
1780 my $directory=get_directory_contents $dirname;
1781 my $found;
1782 foreach my $dentry (@$directory) {
1783 if ($dentry =~ /^\Q$component\E$/i or
1784 (defined $renamed and $dentry =~ /^$renamed$/i)
1786 $dirname.="$dentry/";
1787 $real_path.="$dentry/";
1788 $found=1;
1789 last;
1792 if (!defined $found) {
1793 # Give up
1794 #print " could not find $component in $dirname\n";
1795 return;
1799 $real_path=~ s+/$++;
1800 #print " -> found $real_path\n";
1801 return $real_path;
1805 # Performs a case-insensitive search for the specified file in the
1806 # include path.
1807 # $line is the line number that should be referenced when an error occurs
1808 # $filename is the file we are looking for
1809 # $dirname is the directory of the file containing the '#include' directive
1810 # if '"' was used, it is an empty string otherwise
1811 # $project and $target specify part of the include path
1812 sub get_real_include_name($$$$$)
1814 my $line=$_[0];
1815 my $filename=$_[1];
1816 my $dirname=$_[2];
1817 my $project=$_[3];
1818 my $target=$_[4];
1820 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1821 # This is not a relative path, we cannot make any check
1822 my $warning="path:$filename";
1823 if (!defined $warnings{$warning}) {
1824 $warnings{$warning}="1";
1825 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1826 print STDERR "$line: $filename\n";
1828 } else {
1829 # Here's how we proceed:
1830 # - split the filename we look for into its components
1831 # - then for each directory in the include path
1832 # - trace the directory components starting from that directory
1833 # - if we fail to find a match at any point then continue with
1834 # the next directory in the include path
1835 # - otherwise, rejoice, our quest is over.
1836 my @file_components=split /[\/\\]+/, $filename;
1837 #print " Searching for $filename from @$project[$P_PATH]\n";
1839 my $real_filename;
1840 if ($dirname ne "") {
1841 # This is an 'include ""' -> look in dirname first.
1842 #print " in $dirname (include \"\")\n";
1843 $real_filename=search_from($dirname,\@file_components);
1844 if (defined $real_filename) {
1845 return $real_filename;
1848 my $project_settings=@$project[$P_SETTINGS];
1849 foreach my $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1850 my $dirname=$include;
1851 $dirname=~ s+^-I++;
1852 $dirname=~ s+\s$++;
1853 if (!is_absolute($dirname)) {
1854 $dirname="@$project[$P_PATH]$dirname";
1855 } else {
1856 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1857 $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
1859 #print " in $dirname\n";
1860 $real_filename=search_from("$dirname",\@file_components);
1861 if (defined $real_filename) {
1862 return $real_filename;
1865 my $dotdotpath=@$project[$P_PATH];
1866 $dotdotpath =~ s/[^\/]+/../g;
1867 foreach my $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1868 my $dirname=$include;
1869 $dirname=~ s+^-I++;
1870 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1871 $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
1872 #print " in $dirname (global setting)\n";
1873 $real_filename=search_from("$dirname",\@file_components);
1874 if (defined $real_filename) {
1875 return $real_filename;
1879 $filename =~ s+\\\\+/+g; # in include ""
1880 $filename =~ s+\\+/+g; # in include <> !
1881 if ($opt_lower_include) {
1882 return lc "$filename";
1884 return $filename;
1887 sub print_pack($$$)
1889 my $indent=$_[0];
1890 my $size=$_[1];
1891 my $trailer=$_[2];
1893 if ($size =~ /^(1|2|4|8)$/) {
1894 print FILEO "$indent#include <pshpack$size.h>$trailer";
1895 } else {
1896 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1897 print FILEO "$indent#include <pshpack4.h>$trailer";
1902 # 'Parses' a source file and fixes constructs that would not work with
1903 # Winelib. The parsing is rather simple and not all non-portable features
1904 # are corrected. The most important feature that is corrected is the case
1905 # and path separator of '#include' directives. This requires that each
1906 # source file be associated to a project & target so that the proper
1907 # include path is used.
1908 # Also note that the include path is relative to the directory in which the
1909 # compiler is run, i.e. that of the project, not to that of the file.
1910 sub fix_file($$$)
1912 my $filename=$_[0];
1913 my $project=$_[1];
1914 my $target=$_[2];
1915 $filename="@$project[$P_PATH]$filename";
1916 if (! -e $filename) {
1917 return;
1920 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1921 my $dirname=dirname($filename);
1922 my $is_mfc=0;
1923 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1924 $is_mfc=1;
1927 print " $filename\n";
1928 #FIXME:assuming that because there is a .bak file, this is what we want is
1929 #probably flawed. Or is it???
1930 if (! -e "$filename.bak") {
1931 if (!copy("$filename","$filename.bak")) {
1932 print STDERR "error: unable to make a backup of $filename:\n";
1933 print STDERR " $!\n";
1934 return;
1937 if (!open(FILEI,"$filename.bak")) {
1938 print STDERR "error: unable to open $filename.bak for reading:\n";
1939 print STDERR " $!\n";
1940 return;
1942 if (!open(FILEO,">$filename")) {
1943 print STDERR "error: unable to open $filename for writing:\n";
1944 print STDERR " $!\n";
1945 return;
1947 my $line=0;
1948 my $modified=0;
1949 my $rc_block_depth=0;
1950 my $rc_textinclude_state=0;
1951 my @pack_stack;
1952 while (<FILEI>) {
1953 # Remove any trailing CtrlZ, which isn't strictly in the file
1954 if (/\x1A/) {
1955 s/\x1A//;
1956 last if (/^$/)
1958 $line++;
1959 s/\r\n$/\n/;
1960 if (!/\n$/) {
1961 # Make sure all files are '\n' terminated
1962 $_ .= "\n";
1964 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
1965 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1966 # the RC files it generates (even in non-MFC projects). So we replace
1967 # it with 'winresrc.h' its very close standard cousin so that non MFC
1968 # projects can compile in Wine without the MFC sources.
1969 my $warning="mfc:afxres.h";
1970 if (!defined $warnings{$warning}) {
1971 $warnings{$warning}="1";
1972 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
1973 print STDERR "warning: the above warning is issued only once\n";
1975 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
1976 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
1977 print FILEO "$1$2\"winresrc.h\"$'";
1978 $modified=1;
1980 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1981 my $from_file=($2 eq "<"?"":$dirname);
1982 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1983 print FILEO "$1$2$real_include_name$4$'";
1984 $modified|=($real_include_name ne $3);
1986 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
1987 # Pragma pack handling
1989 # pack_stack is an array of references describing the stack of
1990 # pack directives currently in effect. Each directive if described
1991 # by a reference to an array containing:
1992 # - "push" for pack(push,...) directives, "" otherwise
1993 # - the directive's identifier at index 1
1994 # - the directive's alignment value at index 2
1996 # Don't believe a word of what the documentation says: it's all wrong.
1997 # The code below is based on the actual behavior of Visual C/C++ 6.
1998 my $pack_indent=$1;
1999 my $pack_header=$2;
2000 if (/^(\))/) {
2001 # pragma pack()
2002 # Pushes the default stack alignment
2003 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2004 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2005 print_pack($pack_indent,4,$');
2006 push @pack_stack, [ "", "", 4 ];
2008 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
2009 # pragma pack(pop)
2010 # pragma pack(pop,n)
2011 # Goes up the stack until it finds a pack(push,...), and pops it
2012 # Ignores any pack(n) entry
2013 # Issues a warning if the pack is of the form pack(push,label)
2014 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2015 my $pack_comment=$';
2016 $pack_comment =~ s/^\s*//;
2017 if ($pack_comment ne "") {
2018 print FILEO "$pack_indent$pack_comment";
2020 while (1) {
2021 my $alignment=pop @pack_stack;
2022 if (!defined $alignment) {
2023 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2024 last;
2026 if (@$alignment[1]) {
2027 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2029 print FILEO "$pack_indent#include <poppack.h>\n";
2030 if (@$alignment[0]) {
2031 last;
2035 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2036 # pragma pack(pop,label[,n])
2037 # Goes up the stack until finding a pack(push,...) and pops it.
2038 # 'n', if specified, is ignored.
2039 # Ignores any pack(n) entry
2040 # Issues a warning if the label of the pack does not match,
2041 # or if it is in fact a pack(push,n)
2042 my $label=$2;
2043 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2044 my $pack_comment=$';
2045 $pack_comment =~ s/^\s*//;
2046 if ($pack_comment ne "") {
2047 print FILEO "$pack_indent$pack_comment";
2049 while (1) {
2050 my $alignment=pop @pack_stack;
2051 if (!defined $alignment) {
2052 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2053 last;
2055 if (@$alignment[1] and @$alignment[1] ne $label) {
2056 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2058 print FILEO "$pack_indent#include <poppack.h>\n";
2059 if (@$alignment[0]) {
2060 last;
2064 } elsif (/^(push\s*\))/) {
2065 # pragma pack(push)
2066 # Push the current alignment
2067 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2068 if (@pack_stack > 0) {
2069 my $alignment=$pack_stack[$#pack_stack];
2070 print_pack($pack_indent,@$alignment[2],$');
2071 push @pack_stack, [ "push", "", @$alignment[2] ];
2072 } else {
2073 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2074 print_pack($pack_indent,4,$');
2075 push @pack_stack, [ "push", "", 4 ];
2078 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2079 # pragma pack([push,]n)
2080 # Push new alignment n
2081 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2082 print_pack($pack_indent,$3,"$'");
2083 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2085 } elsif (/^((\w+)\s*\))/) {
2086 # pragma pack(label)
2087 # label must in fact be a macro that resolves to an integer
2088 # Then behaves like 'pragma pack(n)'
2089 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2090 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2091 print_pack($pack_indent,4,$');
2092 push @pack_stack, [ "", "", 4 ];
2094 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2095 # pragma pack(push,label[,n])
2096 # Pushes a new label on the stack. It is possible to push the same
2097 # label multiple times. If 'n' is omitted then the alignment is
2098 # unchanged. Otherwise it becomes 'n'.
2099 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2100 my $size;
2101 if (defined $4) {
2102 $size=$4;
2103 } elsif (@pack_stack > 0) {
2104 my $alignment=$pack_stack[$#pack_stack];
2105 $size=@$alignment[2];
2106 } else {
2107 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2108 $size=4;
2110 print_pack($pack_indent,$size,$');
2111 push @pack_stack, [ "push", $2, $size ];
2113 } else {
2114 # pragma pack(??? -> What's that?
2115 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2116 print FILEO "$pack_indent$pack_header$_";
2119 $modified=1;
2121 } elsif ($is_rc) {
2122 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]+)([\">]?)/) {
2123 my $from_file=($5 eq "<"?"":$dirname);
2124 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2125 print FILEO "$1$5$real_include_name$7$'";
2126 $modified|=($real_include_name ne $6);
2128 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2129 my $from_file=($2 eq "<"?"":$dirname);
2130 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2131 print FILEO "$1$2$real_include_name$4$'";
2132 $modified|=($real_include_name ne $3);
2134 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2135 $rc_textinclude_state=1;
2136 print FILEO;
2138 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2139 print FILEO "$1winresrc.h$2$'";
2140 $modified=1;
2142 } elsif (/^\s*BEGIN(\W.*)?$/) {
2143 $rc_textinclude_state|=2;
2144 $rc_block_depth++;
2145 print FILEO;
2147 } elsif (/^\s*END(\W.*)?$/) {
2148 $rc_textinclude_state=0;
2149 if ($rc_block_depth>0) {
2150 $rc_block_depth--;
2152 print FILEO;
2154 } else {
2155 print FILEO;
2158 } else {
2159 print FILEO;
2163 close(FILEI);
2164 close(FILEO);
2165 if ($opt_backup == 0 or $modified == 0) {
2166 if (!unlink("$filename.bak")) {
2167 print STDERR "error: unable to delete $filename.bak:\n";
2168 print STDERR " $!\n";
2174 # Analyzes each source file in turn to find and correct issues
2175 # that would cause it not to compile.
2176 sub fix_source()
2178 print "Fixing the source files...\n";
2179 foreach my $project (@projects) {
2180 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2181 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2182 fix_file($source,$project,$target);
2190 #####
2192 # File generation
2194 #####
2197 # A convenience function to generate all the lists (defines,
2198 # C sources, C++ source, etc.) in the Makefile
2199 sub generate_list($$$;$)
2201 my $name=$_[0];
2202 my $last=$_[1];
2203 my $list=$_[2];
2204 my $data=$_[3];
2205 my $first=$name;
2207 if ($name) {
2208 printf FILEO "%-22s=",$name;
2210 if (defined $list) {
2211 foreach my $item (@$list) {
2212 my $value;
2213 if (defined $data) {
2214 $value=&$data($item);
2215 } else {
2216 $value=$item;
2218 if ($value ne "") {
2219 if ($first) {
2220 print FILEO " $value";
2221 $first=0;
2222 } else {
2223 print FILEO " \\\n\t\t\t$value";
2228 if ($last) {
2229 print FILEO "\n";
2234 # Generates a project's Makefile and all the target files
2235 sub generate_project_files($)
2237 my $project=$_[0];
2238 my $project_settings=@$project[$P_SETTINGS];
2239 my @dll_list=();
2240 my @exe_list=();
2242 # Then sort the targets and separate the libraries from the programs
2243 foreach my $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
2244 if (@$target[$T_TYPE] == $TT_DLL) {
2245 push @dll_list,$target;
2246 } else {
2247 push @exe_list,$target;
2250 @$project[$P_TARGETS]=[];
2251 push @{@$project[$P_TARGETS]}, @dll_list;
2252 push @{@$project[$P_TARGETS]}, @exe_list;
2254 if (!open(FILEO,">@$project[$P_PATH]Makefile")) {
2255 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2256 print STDERR " $!\n";
2257 return;
2260 print FILEO "### Generated by Winemaker $version\n";
2261 print FILEO "\n\n";
2263 generate_list("SRCDIR",1,[ "." ]);
2264 if (@$project[$P_PATH] eq "") {
2265 # This is the main project. It is also responsible for recursively
2266 # calling the other projects
2267 generate_list("SUBDIRS",1,\@projects,sub
2269 if ($_[0] != \@main_project) {
2270 my $subdir=@{$_[0]}[$P_PATH];
2271 $subdir =~ s+/$++;
2272 return $subdir;
2274 # Eliminating the main project by returning undefined!
2277 if (@{@$project[$P_TARGETS]} > 0) {
2278 generate_list("DLLS",1,\@dll_list,sub
2280 return @{$_[0]}[$T_NAME];
2282 generate_list("EXES",1,\@exe_list,sub
2284 return "@{$_[0]}[$T_NAME]";
2286 print FILEO "\n\n\n";
2288 print FILEO "### Common settings\n\n";
2289 # Make it so that the project-wide settings override the global settings
2290 generate_list("CEXTRA",1,@$project_settings[$T_CEXTRA]);
2291 generate_list("CXXEXTRA",1,@$project_settings[$T_CXXEXTRA]);
2292 generate_list("RCEXTRA",1,@$project_settings[$T_RCEXTRA]);
2293 generate_list("DEFINES",1,@$project_settings[$T_DEFINES]);
2294 generate_list("INCLUDE_PATH",1,@$project_settings[$T_INCLUDE_PATH]);
2295 generate_list("DLL_PATH",1,@$project_settings[$T_DLL_PATH]);
2296 generate_list("DLL_IMPORTS",1,@$project_settings[$T_DLLS]);
2297 generate_list("LIBRARY_PATH",1,@$project_settings[$T_LIBRARY_PATH]);
2298 generate_list("LIBRARIES",1,@$project_settings[$T_LIBRARIES]);
2299 print FILEO "\n\n";
2301 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
2302 @{@$project_settings[$T_SOURCES_CXX]}+
2303 @{@$project_settings[$T_SOURCES_RC]};
2304 my $no_extra=($extra_source_count == 0);
2305 if (!$no_extra) {
2306 print FILEO "### Extra source lists\n\n";
2307 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
2308 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
2309 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
2310 print FILEO "\n";
2311 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
2312 print FILEO "\n\n\n";
2315 # Iterate over all the targets...
2316 foreach my $target (@{@$project[$P_TARGETS]}) {
2317 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
2318 my $canon=canonize("@$target[$T_NAME]");
2319 $canon =~ s+_so$++;
2321 generate_list("${canon}_MODULE",1,[@$target[$T_NAME]]);
2322 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
2323 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
2324 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
2325 generate_list("${canon}_LDFLAGS",1,@$target[$T_LDFLAGS]);
2326 generate_list("${canon}_DLL_PATH",1,@$target[$T_DLL_PATH]);
2327 generate_list("${canon}_DLLS",1,@$target[$T_DLLS]);
2328 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]);
2329 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]);
2330 print FILEO "\n";
2331 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2332 print FILEO "\n\n\n";
2334 print FILEO "### Global source lists\n\n";
2335 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
2337 my $canon=canonize(@{$_[0]}[$T_NAME]);
2338 $canon =~ s+_so$++;
2339 return "\$(${canon}_C_SRCS)";
2341 if (!$no_extra) {
2342 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
2344 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
2346 my $canon=canonize(@{$_[0]}[$T_NAME]);
2347 $canon =~ s+_so$++;
2348 return "\$(${canon}_CXX_SRCS)";
2350 if (!$no_extra) {
2351 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2353 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
2355 my $canon=canonize(@{$_[0]}[$T_NAME]);
2356 $canon =~ s+_so$++;
2357 return "\$(${canon}_RC_SRCS)";
2359 if (!$no_extra) {
2360 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2363 print FILEO "\n\n";
2364 print FILEO "### Tools\n\n";
2365 print FILEO "CC = winegcc\n";
2366 print FILEO "CXX = wineg++\n";
2367 print FILEO "RC = wrc\n";
2368 print FILEO "\n\n";
2370 print FILEO "### Generic targets\n\n";
2371 print FILEO "all:";
2372 if (@$project[$P_PATH] eq "") {
2373 print FILEO " \$(SUBDIRS)";
2375 if (@{@$project[$P_TARGETS]} > 0) {
2376 print FILEO " \$(DLLS:%=%.so) \$(EXES:%=%.so)";
2378 print FILEO "\n\n";
2379 print FILEO "### Build rules\n";
2380 print FILEO "\n";
2381 print FILEO ".PHONY: all clean dummy\n";
2382 print FILEO "\n";
2383 print FILEO "\$(SUBDIRS): dummy\n";
2384 print FILEO "\t\@cd \$\@ && \$(MAKE)\n";
2385 print FILEO "\n";
2386 print FILEO "# Implicit rules\n";
2387 print FILEO "\n";
2388 print FILEO ".SUFFIXES: .cpp .rc .res\n";
2389 print FILEO "DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2390 print FILEO "\n";
2391 print FILEO ".c.o:\n";
2392 print FILEO "\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2393 print FILEO "\n";
2394 print FILEO ".cpp.o:\n";
2395 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2396 print FILEO "\n";
2397 print FILEO ".cxx.o:\n";
2398 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2399 print FILEO "\n";
2400 print FILEO ".rc.res:\n";
2401 print FILEO "\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2402 print FILEO "\n";
2403 print FILEO "# Rules for cleaning\n";
2404 print FILEO "\n";
2405 print FILEO "CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2406 print FILEO " \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2407 print FILEO "\n";
2408 print FILEO "clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2409 print FILEO "\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:.cpp=.o)\n";
2410 print FILEO "\t\$(RM) \$(DLLS:%=%.so) \$(EXES:%=%.so) \$(EXES:%.exe=%)\n";
2411 print FILEO "\n";
2412 print FILEO "\$(SUBDIRS:%=%/__clean__): dummy\n";
2413 print FILEO "\tcd `dirname \$\@` && \$(MAKE) clean\n";
2414 print FILEO "\n";
2415 print FILEO "\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2416 print FILEO "\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2417 print FILEO "\n";
2419 if (@{@$project[$P_TARGETS]} > 0) {
2420 print FILEO "### Target specific build rules\n";
2421 print FILEO "DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2422 foreach my $target (@{@$project[$P_TARGETS]}) {
2423 my $canon=canonize("@$target[$T_NAME]");
2424 $canon =~ s/_so$//;
2426 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS)\n";
2427 if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
2428 print FILEO "\t\$(CXX)";
2429 } else {
2430 print FILEO "\t\$(CC)";
2432 print FILEO " \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2433 print FILEO "\n\n";
2436 close(FILEO);
2442 # This is where we finally generate files. In fact this method does not
2443 # do anything itself but calls the methods that do the actual work.
2444 sub generate()
2446 print "Generating project files...\n";
2448 foreach my $project (@projects) {
2449 my $path=@$project[$P_PATH];
2450 if ($path eq "") {
2451 $path=".";
2452 } else {
2453 $path =~ s+/$++;
2455 print " $path\n";
2456 generate_project_files($project);
2462 #####
2464 # Option defaults
2466 #####
2468 $opt_backup=1;
2469 $opt_lower=$OPT_LOWER_UPPERCASE;
2470 $opt_lower_include=1;
2472 $opt_work_dir=undef;
2473 $opt_single_target=undef;
2474 $opt_target_type=$TT_GUIEXE;
2475 $opt_flags=0;
2476 $opt_arch=$OPT_ARCH_32;
2477 $opt_is_interactive=$OPT_ASK_NO;
2478 $opt_ask_project_options=$OPT_ASK_NO;
2479 $opt_ask_target_options=$OPT_ASK_NO;
2480 $opt_no_generated_files=0;
2481 $opt_no_source_fix=0;
2482 $opt_no_banner=0;
2486 #####
2488 # Main
2490 #####
2492 sub print_banner()
2494 print "Winemaker $version\n";
2495 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2496 print "Copyright 2004 Dimitrie O. Paun\n";
2497 print "Copyright 2009 André Hentschel\n";
2500 sub usage()
2502 print_banner();
2503 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2504 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2505 print STDERR " [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2506 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2507 print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2508 print STDERR " [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2509 print STDERR " [--generated-files|--nogenerated-files]\n";
2510 print STDERR " [--wine64]\n";
2511 print STDERR " work_directory|project_file|workspace_file\n";
2512 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2513 print STDERR "the specified directory so that they can be compiled with Winelib. During this\n";
2514 print STDERR "process it will modify and rename some of the files in that directory.\n";
2515 print STDERR "\tPlease read the manual page before use.\n";
2516 exit (2);
2519 target_init(\@global_settings);
2521 while (@ARGV>0) {
2522 my $arg=shift @ARGV;
2523 # General options
2524 if ($arg eq "--nobanner") {
2525 $opt_no_banner=1;
2526 } elsif ($arg eq "--backup") {
2527 $opt_backup=1;
2528 } elsif ($arg eq "--nobackup") {
2529 $opt_backup=0;
2530 } elsif ($arg eq "--single-target") {
2531 $opt_single_target=shift @ARGV;
2532 } elsif ($arg eq "--lower-none") {
2533 $opt_lower=$OPT_LOWER_NONE;
2534 } elsif ($arg eq "--lower-all") {
2535 $opt_lower=$OPT_LOWER_ALL;
2536 } elsif ($arg eq "--lower-uppercase") {
2537 $opt_lower=$OPT_LOWER_UPPERCASE;
2538 } elsif ($arg eq "--lower-include") {
2539 $opt_lower_include=1;
2540 } elsif ($arg eq "--nolower-include") {
2541 $opt_lower_include=0;
2542 } elsif ($arg eq "--nosource-fix") {
2543 $opt_no_source_fix=1;
2544 } elsif ($arg eq "--generated-files") {
2545 $opt_no_generated_files=0;
2546 } elsif ($arg eq "--nogenerated-files") {
2547 $opt_no_generated_files=1;
2548 } elsif ($arg eq "--wine64") {
2549 $opt_arch=$OPT_ARCH_64;
2550 } elsif ($arg =~ /^-D/) {
2551 push @{$global_settings[$T_DEFINES]},$arg;
2552 } elsif ($arg =~ /^-I/) {
2553 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2554 } elsif ($arg =~ /^-P/) {
2555 push @{$global_settings[$T_DLL_PATH]},"-L$'";
2556 } elsif ($arg =~ /^-i/) {
2557 push @{$global_settings[$T_DLLS]},$';
2558 } elsif ($arg =~ /^-L/) {
2559 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2560 } elsif ($arg =~ /^-l/) {
2561 push @{$global_settings[$T_LIBRARIES]},$';
2563 # 'Source'-based method options
2564 } elsif ($arg eq "--dll") {
2565 $opt_target_type=$TT_DLL;
2566 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2567 $opt_target_type=$TT_GUIEXE;
2568 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2569 $opt_target_type=$TT_CUIEXE;
2570 } elsif ($arg eq "--interactive") {
2571 $opt_is_interactive=$OPT_ASK_YES;
2572 $opt_ask_project_options=$OPT_ASK_YES;
2573 $opt_ask_target_options=$OPT_ASK_YES;
2574 } elsif ($arg eq "--mfc") {
2575 $opt_flags|=$TF_MFC;
2576 } elsif ($arg eq "--nomfc") {
2577 $opt_flags&=~$TF_MFC;
2578 $opt_flags|=$TF_NOMFC;
2579 } elsif ($arg eq "--nodlls") {
2580 $opt_flags|=$TF_NODLLS;
2581 } elsif ($arg eq "--nomsvcrt") {
2582 $opt_flags|=$TF_NOMSVCRT;
2584 # Catch errors
2585 } else {
2586 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2587 if (!defined $opt_work_dir and !defined $opt_work_file) {
2588 if (-f $arg) {
2589 $opt_work_file=$arg;
2591 else {
2592 $opt_work_dir=$arg;
2594 } else {
2595 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2596 usage();
2598 } else {
2599 usage();
2604 if (!defined $opt_work_dir and !defined $opt_work_file) {
2605 print STDERR "error: you must specify the directory or project file containing the sources to be converted\n";
2606 usage();
2607 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2608 print STDERR "error: could not chdir to the work directory\n";
2609 print STDERR " $!\n";
2610 usage();
2613 if ($opt_no_banner == 0) {
2614 print_banner();
2617 project_init(\@main_project, "", \@global_settings);
2619 # Fix the file and directory names
2620 fix_file_and_directory_names(".");
2622 # Scan the sources to identify the projects and targets
2623 source_scan();
2625 # Fix the source files
2626 if (! $opt_no_source_fix) {
2627 fix_source();
2630 # Generate the Makefile and the spec file
2631 if (! $opt_no_generated_files) {
2632 generate();