winemaker: Add calling convention flags.
[wine/wine-gecko.git] / tools / winemaker
blob28fc9bdd47755ac3fdf625b95646369400a54a7a
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.5";
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 # Default Architecture will be choosen
71 my $OPT_ARCH_DEFAULT=0;
74 # 32-Bit Target
75 my $OPT_ARCH_32=32;
78 # 64-Bit Target
79 my $OPT_ARCH_64=64;
82 # General options
85 # This is the directory in which winemaker will operate.
86 my $opt_work_dir;
89 # This is the file in which winemaker will operate if a project file is specified.
90 my $opt_work_file;
93 # Make a backup of the files
94 my $opt_backup;
97 # Defines which files to rename
98 my $opt_lower;
101 # If we don't find the file referenced by an include, lower it
102 my $opt_lower_include;
105 # If true then winemaker should not attempt to fix the source. This is
106 # useful if the source is known to be already in a suitable form and is
107 # readonly
108 my $opt_no_source_fix;
110 # Options for the 'Source' method
113 # Specifies that we have only one target so that all sources relate
114 # to this target. By default this variable is left undefined which
115 # means winemaker should try to find out by itself what the targets
116 # are. If not undefined then this contains the name of the default
117 # target (without the extension).
118 my $opt_single_target;
121 # If '$opt_single_target' has been specified then this is the type of
122 # that target. Otherwise it specifies whether the default target type
123 # is guiexe or cuiexe.
124 my $opt_target_type;
127 # Contains the default set of flags to be used when creating a new target.
128 my $opt_flags;
131 # Contains 32 for 32-Bit-Targets and 64 for 64-Bit-Targets
132 my $opt_arch;
135 # If true then winemaker should ask questions to the user as it goes
136 # along.
137 my $opt_is_interactive;
138 my $opt_ask_project_options;
139 my $opt_ask_target_options;
142 # If false then winemaker should not generate the makefiles.
143 my $opt_no_generated_files;
146 # Specifies not to print the banner if set.
147 my $opt_no_banner;
151 #####
153 # Target modelization
155 #####
157 # The description of a target is stored in an array. The constants
158 # below identify what is stored at each index of the array.
161 # This is the name of the target.
162 my $T_NAME=0;
165 # Defines the type of target we want to build. See the TT_xxx
166 # constants below
167 my $T_TYPE=1;
170 # This is a bitfield containing flags refining the way the target
171 # should be handled. See the TF_xxx constants below
172 my $T_FLAGS=2;
175 # This is a reference to an array containing the list of the
176 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
177 my $T_SOURCES_C=3;
178 my $T_SOURCES_CXX=4;
179 my $T_SOURCES_RC=5;
180 my $T_SOURCES_MISC=6;
183 # This is a reference to an array containing the list of
184 # C compiler options
185 my $T_CEXTRA=7;
188 # This is a reference to an array containing the list of
189 # C++ compiler options
190 my $T_CXXEXTRA=8;
193 # This is a reference to an array containing the list of
194 # RC compiler options
195 my $T_RCEXTRA=9;
198 # This is a reference to an array containing the list of macro
199 # definitions
200 my $T_DEFINES=10;
203 # This is a reference to an array containing the list of directory
204 # names that constitute the include path
205 my $T_INCLUDE_PATH=11;
208 # Flags for the linker
209 my $T_LDFLAGS=12;
212 # Same as T_INCLUDE_PATH but for the dll search path
213 my $T_DLL_PATH=13;
216 # The list of Windows dlls to import
217 my $T_DLLS=14;
220 # Same as T_INCLUDE_PATH but for the library search path
221 my $T_LIBRARY_PATH=15;
224 # The list of Unix libraries to link with
225 my $T_LIBRARIES=16;
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 @$target[$T_FLAGS]=$opt_flags;
278 @$target[$T_SOURCES_C]=[];
279 @$target[$T_SOURCES_CXX]=[];
280 @$target[$T_SOURCES_RC]=[];
281 @$target[$T_SOURCES_MISC]=[];
282 @$target[$T_CEXTRA]=[];
283 @$target[$T_CXXEXTRA]=[];
284 @$target[$T_RCEXTRA]=[];
285 @$target[$T_DEFINES]=[];
286 @$target[$T_INCLUDE_PATH]=[];
287 @$target[$T_LDFLAGS]=[];
288 @$target[$T_DLL_PATH]=[];
289 @$target[$T_DLLS]=[];
290 @$target[$T_LIBRARY_PATH]=[];
291 @$target[$T_LIBRARIES]=[];
296 #####
298 # Project modelization
300 #####
302 # First we have the notion of project. A project is described by an
303 # array (since we don't have structs in perl). The constants below
304 # identify what is stored at each index of the array.
307 # This is the path in which this project is located. In other
308 # words, this is the path to the Makefile.
309 my $P_PATH=0;
312 # This index contains a reference to an array containing the project-wide
313 # settings. The structure of that arrray is actually identical to that of
314 # a regular target since it can also contain extra sources.
315 my $P_SETTINGS=1;
318 # This index contains a reference to an array of targets for this
319 # project. Each target describes how an executable or library is to
320 # be built. For each target this description takes the same form as
321 # that of the project: an array. So this entry is an array of arrays.
322 my $P_TARGETS=2;
325 # Initialize a project:
326 # - set the project's path
327 # - initialize the target list
328 # - create a default target (will be removed later if unnecessary)
329 sub project_init($$$)
331 my ($project, $path, $global_settings)=@_;
333 my $project_settings=[];
334 target_init($project_settings);
335 @$project_settings[$T_DEFINES]=[@{@$global_settings[$T_DEFINES]}];
336 @$project_settings[$T_INCLUDE_PATH]=[@{@$global_settings[$T_INCLUDE_PATH]}];
337 @$project_settings[$T_DLL_PATH]=[@{@$global_settings[$T_DLL_PATH]}];
338 @$project_settings[$T_DLLS]=[@{@$global_settings[$T_DLLS]}];
339 @$project_settings[$T_LIBRARY_PATH]=[@{@$global_settings[$T_LIBRARY_PATH]}];
340 @$project_settings[$T_LIBRARIES]=[@{@$global_settings[$T_LIBRARIES]}];
342 @$project[$P_PATH]=$path;
343 @$project[$P_SETTINGS]=$project_settings;
344 @$project[$P_TARGETS]=[];
349 #####
351 # Global variables
353 #####
355 my %warnings;
357 my %templates;
360 # This maps a directory name to a reference to an array listing
361 # its contents (files and directories)
362 my %directories;
365 # Contains the list of all projects. This list tells us what are
366 # the subprojects of the main Makefile and where we have to generate
367 # Makefiles.
368 my @projects=();
371 # This is the main project, i.e. the one in the "." directory.
372 # It may well be empty in which case the main Makefile will only
373 # call out subprojects.
374 my @main_project;
377 # Contains the defaults for the include path, etc.
378 # We store the defaults as if this were a target except that we only
379 # exploit the defines, include path, library path, library list and misc
380 # sources fields.
381 my @global_settings;
385 #####
387 # Utility functions
389 #####
392 # Cleans up a name to make it an acceptable Makefile
393 # variable name.
394 sub canonize($)
396 my $name=$_[0];
398 $name =~ tr/a-zA-Z0-9_/_/c;
399 return $name;
403 # Returns true is the specified pathname is absolute.
404 # Note: pathnames that start with a variable '$' or
405 # '~' are considered absolute.
406 sub is_absolute($)
408 my $path=$_[0];
410 return ($path =~ /^[\/~\$]/);
414 # Retrieves the contents of the specified directory.
415 # We either get it from the directories hashtable which acts as a
416 # cache, or use opendir, readdir, closedir and store the result
417 # in the hashtable.
418 sub get_directory_contents($)
420 my $dirname=$_[0];
421 my $directory;
423 #print "getting the contents of $dirname\n";
425 # check for a cached version
426 $dirname =~ s+/$++;
427 if ($dirname eq "") {
428 $dirname=cwd;
430 $directory=$directories{$dirname};
431 if (defined $directory) {
432 #print "->@$directory\n";
433 return $directory;
436 # Read this directory
437 if (opendir(DIRECTORY, "$dirname")) {
438 my @files=readdir DIRECTORY;
439 closedir(DIRECTORY);
440 $directory=\@files;
441 } else {
442 # Return an empty list
443 #print "error: cannot open $dirname\n";
444 my @files;
445 $directory=\@files;
447 #print "->@$directory\n";
448 $directories{$dirname}=$directory;
449 return $directory;
453 # Removes a directory from the cache.
454 # This is needed if one of its files or subdirectory has been renamed.
455 sub clear_directory_cache($)
457 my ($dirname)=@_;
458 delete $directories{$dirname};
462 #####
464 # 'Source'-based Project analysis
466 #####
469 # Allows the user to specify makefile and target specific options
470 # - target: the structure in which to store the results
471 # - options: the string containing the options
472 sub source_set_options($$)
474 my $target=$_[0];
475 my $options=$_[1];
477 #FIXME: we must deal with escaping of stuff and all
478 foreach my $option (split / /,$options) {
479 if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
480 push @{@$target[$T_DEFINES]},$option;
481 } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
482 push @{@$target[$T_INCLUDE_PATH]},$option;
483 } elsif ($option =~ /^-P/) {
484 push @{@$target[$T_DLL_PATH]},"-L$'";
485 } elsif ($option =~ /^-i/) {
486 push @{@$target[$T_DLLS]},"$'";
487 } elsif ($option =~ /^-L/) {
488 push @{@$target[$T_LIBRARY_PATH]},$option;
489 } elsif ($option =~ /^-l/) {
490 push @{@$target[$T_LIBRARIES]},"$'";
491 } elsif ($option =~ /^--mfc/) {
492 @$target[$T_FLAGS]|=$TF_MFC;
493 @$target[$T_FLAGS]&=~$TF_NOMFC;
494 } elsif ($option =~ /^--nomfc/) {
495 @$target[$T_FLAGS]&=~$TF_MFC;
496 @$target[$T_FLAGS]|=$TF_NOMFC;
497 } elsif ($option =~ /^--nodlls/) {
498 @$target[$T_FLAGS]|=$TF_NODLLS;
499 } elsif ($option =~ /^--nomsvcrt/) {
500 @$target[$T_FLAGS]|=$TF_NOMSVCRT;
501 } else {
502 print STDERR "error: unknown option \"$option\"\n";
503 return 0;
506 return 1;
510 # Scans the specified project file to:
511 # - get a list of targets for this project
512 # - get some settings
513 # - get the list of source files
514 sub source_scan_project_file($$$);
515 sub source_scan_project_file($$$)
517 # a reference to the parent's project
518 my $parent_project=$_[0];
519 # 0 if it is a single project, 1 if it is part of a workspace
520 my $is_sub_project=$_[1];
521 # the name of the project file, with complete path, or without if in
522 # the same directory
523 my $filename=$_[2];
525 # reference to the project for this file. May not be used
526 my $project;
527 # list of sources found in the current file
528 my @sources_c=();
529 my @sources_cxx=();
530 my @sources_rc=();
531 my @sources_misc=();
532 # some more settings
533 my $path=dirname($filename);
534 my $prj_target_cflags;
535 my $prj_target_defines;
536 my $prj_target_ldflags;
537 my $prj_target_libs;
538 my $prj_name;
539 my $found_cfg=0;
540 my $prj_cfg;
541 my $prj_target_type=$TT_GUIEXE;
542 my @prj_target_options;
544 if (!($path=~/\/$/)) {
545 $path.="/";
548 if (defined $opt_single_target or $is_sub_project == 0) {
549 # Either there is a single target and thus a single project,
550 # or we are a single project-file for which a project
551 # already exists
552 $project=$parent_project;
553 } else {
554 $project=[];
555 project_init($project, $path, \@global_settings);
557 my $project_settings=@$project[$P_SETTINGS];
559 if ($filename =~ /.dsp$/i) {
560 # First find out what this project file contains:
561 # collect all sources, find targets and settings
562 if (!open(FILEI,$filename)) {
563 print STDERR "error: unable to open $filename for reading:\n";
564 print STDERR " $!\n";
565 return;
567 my $sfilet;
568 while (<FILEI>) {
569 # Remove any trailing CtrlZ, which isn't strictly in the file
570 if (/\x1A/) {
571 s/\x1A//;
572 last if (/^$/)
575 # Remove any trailing CrLf
576 s/\r\n$/\n/;
577 if (!/\n$/) {
578 # Make sure all lines are '\n' terminated
579 $_ .= "\n";
582 if (/^\# Microsoft Developer Studio Project File - Name=\"([^\"]+)/) {
583 $prj_name="$1";
584 $prj_name=~s/\s+/_/g;
585 #print $prj_name;
586 next;
587 } elsif (/^# TARGTYPE/) {
588 if (/[[:space:]]0x0101$/) {
589 # Application
590 $prj_target_type=$TT_GUIEXE;
591 }elsif (/[[:space:]]0x0102$/) {
592 # Dynamic-Link Library
593 $prj_target_type=$TT_DLL;
594 }elsif (/[[:space:]]0x0103$/) {
595 # Console Application
596 $prj_target_type=$TT_CUIEXE;
597 }elsif (/[[:space:]]0x0104$/) {
598 # Static Library
600 next;
601 } elsif (/^# ADD CPP(.*)/ && $found_cfg==1) {
602 $prj_target_cflags=$1;
603 @prj_target_options=split(" /", $prj_target_cflags);
604 $prj_target_cflags="";
605 foreach ( @prj_target_options ) {
606 if ($_ eq "") {
607 # empty
608 } elsif (/nologo/) {
609 # Suppress Startup Banner and Information Messages
610 } elsif (/^W0$/) {
611 # Turns off all warning messages
612 $prj_target_cflags.="-w ";
613 } elsif (/^W[123]$/) {
614 # Warning Level
615 $prj_target_cflags.="-W ";
616 } elsif (/^W4$/) {
617 # Warning Level
618 $prj_target_cflags.="-Wall ";
619 } elsif (/^WX$/) {
620 # Warnings As Errors
621 $prj_target_cflags.="-Werror ";
622 } elsif (/^Gm$/) {
623 # Enable Minimal Rebuild
624 } elsif (/^GX$/) {
625 # Enable Exception Handling
626 $prj_target_cflags.="-fexceptions ";
627 } elsif (/^Gd$/) {
628 # use cdecl calling convention (default)
629 } elsif (/^Gr$/) {
630 # use fastcall calling convention
631 } elsif (/^Gz$/) {
632 # use stdcall calling convention
633 $prj_target_cflags.="-mrtd ";
634 } elsif (/^Z[d7iI]$/) {
635 # Debug Info
636 $prj_target_cflags.="-g ";
637 } elsif (/^Od$/) {
638 # Disable Optimizations
639 $prj_target_cflags.="-O0 ";
640 } elsif (/^O1$/) {
641 # Minimize Size
642 $prj_target_cflags.="-Os ";
643 } elsif (/^O2$/) {
644 # Maximize Speed
645 $prj_target_cflags.="-O2 ";
646 } elsif (/^Ob0$/) {
647 # Disables inline Expansion
648 $prj_target_cflags.="-fno-inline ";
649 } elsif (/^Ob1$/) {
650 #In-line Function Expansion
651 $prj_target_cflags.="-finline-functions ";
652 } elsif (/^Ob2$/) {
653 # auto In-line Function Expansion
654 $prj_target_cflags.="-finline-functions ";
655 } elsif (/^Ox$/) {
656 # Use maximum optimization
657 $prj_target_cflags.="-O3 ";
658 } elsif (/^Oy$/) {
659 # Frame-Pointer Omission
660 $prj_target_cflags.="-fomit-frame-pointer ";
661 } elsif (/^Oy-$/) {
662 # Frame-Pointer Omission
663 $prj_target_cflags.="-fno-omit-frame-pointer ";
664 } elsif (/^GZ$/) {
665 # Catch Release-Build Errors in Debug Build
666 } elsif (/^M[DLT]d?$/) {
667 # Use Multithreaded Run-Time Library
668 } elsif (/^D\s*\"(.*)\"/) {
669 # Preprocessor Definitions
670 $prj_target_defines.="-D".$1." ";
671 } elsif (/^I\s*\"(.*)\"/) {
672 # Additional Include Directories
673 $sfilet=$1;
674 $sfilet=~s/\\/\//g;
675 if ($sfilet=~/^\w:/) {
676 print STDERR "warning: Can't fix path $sfilet\n"
677 } else {
678 push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$sfilet." ";
680 } elsif (/^U\s*\"(.*)\"/) {
681 # Undefines a previously defined symbol
682 $prj_target_cflags.="-U".$1." ";
683 } elsif (/^Fp/) {
684 # Name .PCH File
685 } elsif (/^F[Rr]/) {
686 # Create .SBR File
687 } elsif (/^YX$/) {
688 # Automatic Use of Precompiled Headers
689 } elsif (/^FD$/) {
690 # Generate File Dependencies
691 } elsif (/^c$/) {
692 # Compile Without Linking
693 # this option is always present and is already specified in the suffix rules
694 } elsif (/^GB$/) {
695 # Blend Optimization
696 $prj_target_cflags.="-D_M_IX86=500 ";
697 } elsif (/^G6$/) {
698 # Pentium Pro Optimization
699 $prj_target_cflags.="-D_M_IX86=600 ";
700 } elsif (/^G5$/) {
701 # Pentium Optimization
702 $prj_target_cflags.="-D_M_IX86=500 ";
703 } elsif (/^G3$/) {
704 # 80386 Optimization
705 $prj_target_cflags.="-D_M_IX86=300 ";
706 } elsif (/^G4$/) {
707 # 80486 Optimization
708 $prj_target_cflags.="-D_M_IX86=400 ";
709 } elsif (/^Yc/) {
710 # Create Precompiled Header
711 } elsif (/^Yu/) {
712 # Use Precompiled Header
713 } elsif (/^Za$/) {
714 # Disable Language Extensions
715 $prj_target_cflags.="-ansi ";
716 } elsif (/^Ze$/) {
717 # Enable Microsoft Extensions
718 } elsif (/^Zm[[:digit:]]+$/) {
719 # Specify Memory Allocation Limit
720 } elsif (/^Zp1?$/) {
721 # Packs structures on 1-byte boundaries
722 $prj_target_cflags.="-fpack-struct ";
723 } elsif (/^Zp(2|4|8|16)$/) {
724 # Struct Member Alignment
725 $prj_target_cflags.="-fpack-struct=".$1;
726 } else {
727 print "C compiler option $_ not implemented\n";
731 #print "\nOptions: $prj_target_cflags\n";
732 next;
733 } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
734 $prj_target_ldflags=$1;
735 @prj_target_options=split(" /", $prj_target_ldflags);
736 $prj_target_ldflags="";
737 $prj_target_libs=$prj_target_options[0];
738 $prj_target_libs=~s/\\/\//g;
739 $prj_target_libs=~s/\.lib//g;
740 $prj_target_libs=~s/\s+/ -l/g;
741 shift (@prj_target_options);
742 foreach ( @prj_target_options ) {
743 if ($_ eq "") {
744 # empty
745 } elsif (/^base:(.*)/) {
746 # Base Address
747 $prj_target_ldflags.="--image-base ".$1." ";
748 } elsif (/^debug$/) {
749 # Generate Debug Info
750 } elsif (/^dll$/) {
751 # Build a DLL
752 $prj_target_type=$TT_DLL;
753 } elsif (/^incremental:[[:alpha:]]+$/) {
754 # Link Incrmentally
755 } elsif (/^implib:/) {
756 # Name import library
757 } elsif (/^libpath:\"(.*)\"/) {
758 # Additional Libpath
759 push @{@$project_settings[$T_DLL_PATH]},"-L$1";
760 } elsif (/^machine:[[:alnum:]]+$/) {
761 # Specify Target Platform
762 } elsif (/^map/) {
763 # Generate Mapfile
764 if (/^map:(.*)/) {
765 $prj_target_ldflags.="-Map ".$1." ";
766 } else {
767 $prj_target_ldflags.="-Map ".$prj_name.".map ";
769 } elsif (/^nologo$/) {
770 # Suppress Startup Banner and Information Messages
771 } elsif (/^out:/) {
772 # Output File Name
773 # may use it as Target?
774 } elsif (/^pdbtype:/) {
775 # Program Database Storage
776 } elsif (/^subsystem:/) {
777 # Specify Subsystem
778 } elsif (/^version:[[:digit:].]+$/) {
779 # Version Information
780 } else {
781 print "Linker option $_ not implemented\n";
784 next;
785 } elsif (/^LIB32=/ && $found_cfg==1) {
786 #$libflag = 1;
787 next;
788 } elsif (/^SOURCE=(.*)$/) {
789 my @components=split /[\/\\]+/, $1;
790 $sfilet=search_from($path, \@components);
791 if (!defined $sfilet) { next; }
792 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
793 push @sources_c,$sfilet;
794 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
795 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
796 push @sources_misc,$sfilet;
797 @$project_settings[$T_FLAGS]|=$TF_MFC;
798 } else {
799 push @sources_cxx,$sfilet;
801 } elsif ($sfilet =~ /\.rc$/i) {
802 push @sources_rc,$sfilet;
803 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
804 push @sources_misc,$sfilet;
805 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
806 @$project_settings[$T_FLAGS]|=$TF_MFC;
809 next;
811 } elsif (/^# (Begin|End) Source File/) {
812 # Source-Files already handled
813 next;
814 } elsif (/^# (Begin|End) Group/) {
815 # Groups are ignored
816 next;
817 } elsif (/^# (Begin|End) Custom Build/) {
818 # Custom Builds are ignored
819 next;
820 } elsif (/^# ADD LIB32 /) {
821 #"ARFLAGS=rus"
822 next;
823 } elsif (/^# Begin Target$/) {
824 # Targets are ignored
825 next;
826 } elsif (/^# End Target$/) {
827 # Targets are ignored
828 next;
829 } elsif (/^!/) {
830 if ($found_cfg == 1) {
831 $found_cfg=0;
833 if (/if (.*)\(CFG\)" == "(.*)"/i) {
834 if ($2 eq $prj_cfg) {
835 $found_cfg=1;
838 next;
839 } elsif (/^CFG=(.*)/i) {
840 $prj_cfg=$1;
841 next;
843 else { # Line recognized
844 # print "|\n";
847 close(FILEI);
849 push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
850 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
851 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
852 push @{@$project_settings[$T_DEFINES]},$prj_target_defines;
853 push @{@$project_settings[$T_LDFLAGS]},$prj_target_ldflags;
854 } elsif ($filename =~ /.vcproj$/i) {
855 # Import XML::LibXML, you need the libxml package (deb: libxml-libxml-perl, rpm: perl-libxml-perl)
856 require XML::LibXML;
858 my $xmlparser = XML::LibXML->new();
859 my $project_xml = $xmlparser->parse_file($filename);
860 my $sfilet;
861 my $configt;
863 foreach my $vc_project ($project_xml->findnodes('/VisualStudioProject')) {
864 foreach my $vc_project_attr ($vc_project->attributes) {
865 if ($vc_project_attr->getName eq "Name") {
866 $prj_name=$vc_project_attr->getValue;
867 $prj_name=~s/\s+/_/g;
868 last;
873 for (my $flevel = 0; $flevel <= 5; $flevel++) {
874 foreach my $vc_file ($project_xml->findnodes('/VisualStudioProject/Files/'.('Filter/' x $flevel).'File')) {
875 foreach my $vc_file_attr ($vc_file->attributes) {
876 if ($vc_file_attr->getName eq "RelativePath") {
877 $sfilet = $vc_file_attr->getValue;
878 $sfilet=~s/\\\\/\\/g; #remove double backslash
879 $sfilet=~s/^\.\\//; #remove starting 'this directory'
880 $sfilet=~s/\\/\//g; #make slashes out of backslashes
881 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
882 push @sources_c,$sfilet;
883 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
884 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
885 push @sources_misc,$sfilet;
886 @$project_settings[$T_FLAGS]|=$TF_MFC;
887 } else {
888 push @sources_cxx,$sfilet;
890 } elsif ($sfilet =~ /\.rc$/i) {
891 push @sources_rc,$sfilet;
892 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
893 push @sources_misc,$sfilet;
894 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
895 @$project_settings[$T_FLAGS]|=$TF_MFC;
903 my @vc_configurations = $project_xml->findnodes('/VisualStudioProject/Configurations/Configuration');
904 my $vc_configuration = $vc_configurations[0];
905 foreach my $vc_configuration_attr ($vc_configuration->attributes) {
906 if ($vc_configuration_attr->getName eq "ConfigurationType") {
907 if ($vc_configuration_attr->getValue==1) {
908 $prj_target_type=$TT_GUIEXE; # Application
909 } elsif ($vc_configuration_attr->getValue==2) {
910 $prj_target_type=$TT_DLL; # Dynamic-Link Library
915 foreach my $vc_configuration_tools ($vc_configuration->findnodes('Tool')) {
916 my @find_tool = $vc_configuration_tools->attributes;
917 if ($find_tool[0]->getValue eq "VCCLCompilerTool") {
918 foreach my $vc_compiler_tool ($vc_configuration_tools->attributes) {
919 if ($vc_compiler_tool->getName eq "Optimization") {$prj_target_cflags.="-O".$vc_compiler_tool->getValue." ";}
920 if ($vc_compiler_tool->getName eq "WarningLevel") {
921 if ($vc_compiler_tool->getValue==0) {
922 $prj_target_cflags.="-w ";
923 } elsif ($vc_compiler_tool->getValue<4) {
924 $prj_target_cflags.="-W ";
925 } elsif ($vc_compiler_tool->getValue==4) {
926 $prj_target_cflags.="-Wall ";
927 } elsif ($vc_compiler_tool->getValue eq "X") {
928 $prj_target_cflags.="-Werror ";
931 if ($vc_compiler_tool->getName eq "PreprocessorDefinitions") {
932 $configt=$vc_compiler_tool->getValue;
933 $configt=~s/;/ -D/g;
934 $prj_target_defines.="-D".$configt." ";
936 if ($vc_compiler_tool->getName eq "AdditionalIncludeDirectories") {
937 $configt=$vc_compiler_tool->getValue;
938 $configt=~s/\\/\//g;
939 $configt=~s/;/ -I/g;
940 push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$configt;
944 if ($find_tool[0]->getValue eq "VCLinkerTool") {
945 foreach my $vc_linker_tool ($vc_configuration_tools->attributes) {
946 if ($vc_linker_tool->getName eq "AdditionalDependencies") {
947 $prj_target_libs=" ".$vc_linker_tool->getValue;
948 $prj_target_libs=~s/\\/\//g;
949 $prj_target_libs=~s/\.lib//g;
950 $prj_target_libs=~s/\s+/ -l/g;
956 push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
957 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
958 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
959 push @{@$project_settings[$T_DEFINES]},$prj_target_defines;
962 # Add this project to the project list, except for
963 # the main project which is already in the list.
964 if ($is_sub_project == 1) {
965 push @projects,$project;
968 # Ask for project-wide options
969 if ($opt_ask_project_options == $OPT_ASK_YES) {
970 my $flag_desc="";
971 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
972 $flag_desc="mfc";
974 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
975 if (defined $flag_desc) {
976 print "* (currently $flag_desc)\n";
978 print "* or 'skip' to skip the target specific options,\n";
979 print "* or 'never' to not be asked this question again:\n";
980 while (1) {
981 my $options=<STDIN>;
982 chomp $options;
983 if ($options eq "skip") {
984 $opt_ask_target_options=$OPT_ASK_SKIP;
985 last;
986 } elsif ($options eq "never") {
987 $opt_ask_project_options=$OPT_ASK_NO;
988 last;
989 } elsif (source_set_options($project_settings,$options)) {
990 last;
992 print "Please re-enter the options:\n";
996 my @local_dlls=();
997 my @local_depends=();
998 my @exe_list=();
1000 # Create the target...
1001 my $target=[];
1002 target_init($target);
1004 if ($prj_target_type!=$TT_DLL) {
1005 $prj_name=lc($prj_name.".exe");
1006 @$target[$T_TYPE]=$opt_target_type;
1007 push @exe_list,$target;
1008 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
1009 } else {
1010 $prj_name=lc($prj_name.".dll");
1011 @$target[$T_TYPE]=$TT_DLL;
1012 push @local_depends,"$prj_name.so";
1013 push @local_dlls,$prj_name;
1014 my $canon=canonize($prj_name);
1015 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1018 @$target[$T_NAME]=$prj_name;
1019 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
1021 # This is the default link list of Visual Studio
1022 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1023 my @std_libraries=qw(uuid);
1024 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1025 @$target[$T_DLLS]=\@std_imports;
1026 @$target[$T_LIBRARIES]=\@std_libraries;
1027 } else {
1028 @$target[$T_DLLS]=[];
1029 @$target[$T_LIBRARIES]=[];
1031 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1032 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
1033 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1034 push @{@$target[$T_LDFLAGS]},"-m$opt_arch";
1037 push @{@$project[$P_TARGETS]},$target;
1039 # Ask for target-specific options
1040 if ($opt_ask_target_options == $OPT_ASK_YES) {
1041 my $flag_desc="";
1042 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
1043 $flag_desc=" (mfc";
1045 if ($flag_desc ne "") {
1046 $flag_desc.=")";
1048 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1049 print "* \"$prj_name\"$flag_desc or 'never' to not be asked this question again:\n";
1050 while (1) {
1051 my $options=<STDIN>;
1052 chomp $options;
1053 if ($options eq "never") {
1054 $opt_ask_target_options=$OPT_ASK_NO;
1055 last;
1056 } elsif (source_set_options($target,$options)) {
1057 last;
1059 print "Please re-enter the options:\n";
1062 if (@$target[$T_FLAGS] & $TF_MFC) {
1063 @$project_settings[$T_FLAGS]|=$TF_MFC;
1064 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1065 push @{@$target[$T_DLLS]},"mfc.dll";
1066 # FIXME: Link with the MFC in the Unix sense, until we
1067 # start exporting the functions properly.
1068 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1069 push @{@$target[$T_LIBRARIES]},"mfc";
1072 # Match sources...
1073 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1074 @$project_settings[$T_SOURCES_C]=[];
1075 @sources_c=();
1076 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1077 @$project_settings[$T_SOURCES_CXX]=[];
1078 @sources_cxx=();
1079 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1080 @$project_settings[$T_SOURCES_RC]=[];
1081 @sources_rc=();
1082 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1083 @$project_settings[$T_SOURCES_MISC]=[];
1084 @sources_misc=();
1086 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1087 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1088 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1089 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1091 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1092 $opt_ask_target_options=$OPT_ASK_YES;
1095 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1096 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1097 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1098 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1099 push @{@$project_settings[$T_CEXTRA]},"-m$opt_arch";
1100 push @{@$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1104 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1105 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1107 # The sources that did not match, if any, go to the extra
1108 # source list of the project settings
1109 foreach my $source (@sources_c) {
1110 if ($source ne "") {
1111 push @{@$project_settings[$T_SOURCES_C]},$source;
1114 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1115 foreach my $source (@sources_cxx) {
1116 if ($source ne "") {
1117 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1120 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1121 foreach my $source (@sources_rc) {
1122 if ($source ne "") {
1123 push @{@$project_settings[$T_SOURCES_RC]},$source;
1126 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1127 foreach my $source (@sources_misc) {
1128 if ($source ne "") {
1129 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1132 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1136 # Scans the specified workspace file to find the project files
1137 sub source_scan_workspace_file($);
1138 sub source_scan_workspace_file($)
1140 my $filename=$_[0];
1141 my $path=dirname($filename);
1142 my @components;
1144 if (! -e $filename) {
1145 return;
1148 if (!open(FILEIWS,$filename)) {
1149 print STDERR "error: unable to open $filename for reading:\n";
1150 print STDERR " $!\n";
1151 return;
1154 my $prj_name;
1155 my $prj_path;
1157 if ($filename =~ /.dsw$/i) {
1158 while (<FILEIWS>) {
1159 # Remove any trailing CrLf
1160 s/\r\n$/\n/;
1162 # catch a project definition
1163 if (/^Project:\s\"(.*)\"=(.*)\s-/) {
1164 $prj_name=$1;
1165 $prj_path=$2;
1166 @components=split /[\/\\]+/, $prj_path;
1167 $prj_path=search_from($path, \@components);
1168 print "Name: $prj_name\nPath: $prj_path\n";
1169 source_scan_project_file(\@main_project,1,$prj_path);
1170 next;
1171 } elsif (/^#/) {
1172 # ignore Comments
1173 } elsif (/^Global:/) {
1174 # ignore the Global section
1175 } elsif (/\w:/) {
1176 print STDERR "unknown section $_\n";
1177 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1178 print "\nFileversion: $3\n";
1181 close(FILEIWS);
1182 } elsif ($filename =~ /.sln$/i) {
1183 while (<FILEIWS>) {
1184 # Remove any trailing CrLf
1185 s/\r\n$/\n/;
1187 # catch a project definition
1188 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1189 $prj_name=$2;
1190 $prj_path=$3;
1191 if ($prj_path eq "Solution Items") { next; }
1192 @components=split /[\/\\]+/, $3;
1193 $prj_path=search_from($path, \@components);
1194 print "Name: $prj_name\nPath: $prj_path\n";
1195 source_scan_project_file(\@main_project,1,$prj_path);
1196 next;
1197 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1198 print "\nFileversion: $3\n";
1201 close(FILEIWS);
1204 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1208 # Scans the specified directory to:
1209 # - see if we should create a Makefile in this directory. We normally do
1210 # so if we find a project file and sources
1211 # - get a list of targets for this directory
1212 # - get the list of source files
1213 sub source_scan_directory($$$$);
1214 sub source_scan_directory($$$$)
1216 # a reference to the parent's project
1217 my $parent_project=$_[0];
1218 # the full relative path to the current directory, including a
1219 # trailing '/', or an empty string if this is the top level directory
1220 my $path=$_[1];
1221 # the name of this directory, including a trailing '/', or an empty
1222 # string if this is the top level directory
1223 my $dirname=$_[2];
1224 # if set then no targets will be looked for and the sources will all
1225 # end up in the parent_project's 'misc' bucket
1226 my $no_target=$_[3];
1228 # reference to the project for this directory. May not be used
1229 my $project;
1230 # list of targets found in the 'current' directory
1231 my %targets;
1232 # list of sources found in the current directory
1233 my @sources_c=();
1234 my @sources_cxx=();
1235 my @sources_rc=();
1236 my @sources_misc=();
1237 # true if this directory contains a Windows project
1238 my $has_win_project=0;
1239 # true if this directory contains headers
1240 my $has_headers=0;
1241 # If we don't find any executable/library then we might make up targets
1242 # from the list of .dsp/.mak files we find since they usually have the
1243 # same name as their target.
1244 my @prj_files=();
1245 my @mak_files=();
1247 if (defined $opt_single_target or $dirname eq "") {
1248 # Either there is a single target and thus a single project,
1249 # or we are in the top level directory for which a project
1250 # already exists
1251 $project=$parent_project;
1252 } else {
1253 $project=[];
1254 project_init($project, $path, \@global_settings);
1256 my $project_settings=@$project[$P_SETTINGS];
1258 # First find out what this directory contains:
1259 # collect all sources, targets and subdirectories
1260 my $directory=get_directory_contents($path);
1261 foreach my $dentry (@$directory) {
1262 if ($dentry =~ /^\./) {
1263 next;
1265 my $fullentry="$path$dentry";
1266 if (-d "$fullentry") {
1267 if ($dentry =~ /^(Release|Debug)/i) {
1268 # These directories are often used to store the object files and the
1269 # resulting executable/library. They should not contain anything else.
1270 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
1271 foreach my $candidate (@candidates) {
1272 $targets{$candidate}=1;
1274 } elsif ($dentry =~ /^include/i) {
1275 # This directory must contain headers we're going to need
1276 push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1277 source_scan_directory($project,"$fullentry/","$dentry/",1);
1278 } else {
1279 # Recursively scan this directory. Any source file that cannot be
1280 # attributed to a project in one of the subdirectories will be
1281 # attributed to this project.
1282 source_scan_directory($project,"$fullentry/","$dentry/",$no_target);
1284 } elsif (-f "$fullentry") {
1285 if ($dentry =~ /\.(exe|dll)$/i) {
1286 $targets{$dentry}=1;
1287 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1288 push @sources_c,"$dentry";
1289 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
1290 if ($dentry =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1291 push @sources_misc,"$dentry";
1292 @$project_settings[$T_FLAGS]|=$TF_MFC;
1293 } else {
1294 push @sources_cxx,"$dentry";
1296 } elsif ($dentry =~ /\.rc$/i) {
1297 push @sources_rc,"$dentry";
1298 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1299 $has_headers=1;
1300 push @sources_misc,"$dentry";
1301 if ($dentry =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1302 @$project_settings[$T_FLAGS]|=$TF_MFC;
1304 } elsif ($dentry =~ /\.(dsp|vcproj)$/i) {
1305 push @prj_files,"$dentry";
1306 $has_win_project=1;
1307 } elsif ($dentry =~ /\.mak$/i) {
1308 push @mak_files,"$dentry";
1309 $has_win_project=1;
1310 } elsif ($dentry =~ /^makefile/i) {
1311 $has_win_project=1;
1316 if ($has_headers) {
1317 push @{@$project_settings[$T_INCLUDE_PATH]},"-I.";
1319 # If we have a single target then all we have to do is assign
1320 # all the sources to it and we're done
1321 # FIXME: does this play well with the --interactive mode?
1322 if ($opt_single_target) {
1323 my $target=@{@$project[$P_TARGETS]}[0];
1324 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1325 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1326 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1327 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1328 return;
1330 if ($no_target) {
1331 my $parent_settings=@$parent_project[$P_SETTINGS];
1332 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1333 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1334 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1335 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1336 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1337 return;
1340 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1341 @{@$project_settings[$T_SOURCES_C]}+
1342 @{@$project_settings[$T_SOURCES_CXX]}+
1343 @{@$project_settings[$T_SOURCES_RC]};
1344 if ($source_count == 0) {
1345 # A project without real sources is not a project, get out!
1346 if ($project!=$parent_project) {
1347 my $parent_settings=@$parent_project[$P_SETTINGS];
1348 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1349 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1351 return;
1353 #print "targets=",%targets,"\n";
1354 #print "target_count=$target_count\n";
1355 #print "has_win_project=$has_win_project\n";
1356 #print "dirname=$dirname\n";
1358 my $target_count;
1359 if (($has_win_project != 0) or ($dirname eq "")) {
1360 # Deal with cases where we could not find any executable/library, and
1361 # thus have no target, although we did find some sort of windows project.
1362 $target_count=keys %targets;
1363 if ($target_count == 0) {
1364 # Try to come up with a target list based on .dsp/.mak files
1365 my $prj_list;
1366 if (@prj_files > 0) {
1367 print "Projectfile found! You might want to try using it directly.\n";
1368 $prj_list=\@prj_files;
1369 } else {
1370 $prj_list=\@mak_files;
1372 foreach my $filename (@$prj_list) {
1373 $filename =~ s/\.(dsp|vcproj|mak)$//i;
1374 if ($opt_target_type == $TT_DLL) {
1375 $filename = "$filename.dll";
1377 $targets{$filename}=1;
1379 $target_count=keys %targets;
1380 if ($target_count == 0) {
1381 # Still nothing, try the name of the directory
1382 my $name;
1383 if ($dirname eq "") {
1384 # Bad luck, this is the top level directory!
1385 $name=(split /\//, cwd)[-1];
1386 } else {
1387 $name=$dirname;
1388 # Remove the trailing '/'. Also eliminate whatever is after the last
1389 # '.' as it is likely to be meaningless (.orig, .new, ...)
1390 $name =~ s+(/|\.[^.]*)$++;
1391 if ($name eq "src") {
1392 # 'src' is probably a subdirectory of the real project directory.
1393 # Try again with the parent (if any).
1394 my $parent=$path;
1395 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
1396 $name=$parent;
1397 } else {
1398 $name=(split /\//, cwd)[-1];
1402 $name =~ s+(/|\.[^.]*)$++;
1403 if ($opt_target_type == $TT_DLL) {
1404 $name = canonize($name).".dll";
1405 } else {
1406 $name = canonize($name).".exe";
1408 $targets{$name}=1;
1412 # Ask confirmation to the user if he wishes so
1413 if ($opt_is_interactive == $OPT_ASK_YES) {
1414 my $target_list=join " ",keys %targets;
1415 print "\n*** In ",($path?$path:"./"),"\n";
1416 print "* winemaker found the following list of (potential) targets\n";
1417 print "* $target_list\n";
1418 print "* Type enter to use it as is, your own comma-separated list of\n";
1419 print "* targets, 'none' to assign the source files to a parent directory,\n";
1420 print "* or 'ignore' to ignore everything in this directory tree.\n";
1421 print "* Target list:\n";
1422 $target_list=<STDIN>;
1423 chomp $target_list;
1424 if ($target_list eq "") {
1425 # Keep the target list as is, i.e. do nothing
1426 } elsif ($target_list eq "none") {
1427 # Empty the target list
1428 undef %targets;
1429 } elsif ($target_list eq "ignore") {
1430 # Ignore this subtree altogether
1431 return;
1432 } else {
1433 undef %targets;
1434 foreach my $target (split /,/,$target_list) {
1435 $target =~ s+^\s*++;
1436 $target =~ s+\s*$++;
1437 $targets{$target}=1;
1443 # If we have no project at this level, then transfer all
1444 # the sources to the parent project
1445 $target_count=keys %targets;
1446 if ($target_count == 0) {
1447 if ($project!=$parent_project) {
1448 my $parent_settings=@$parent_project[$P_SETTINGS];
1449 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1450 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1451 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1452 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1453 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1455 return;
1458 # Otherwise add this project to the project list, except for
1459 # the main project which is already in the list.
1460 if ($dirname ne "") {
1461 push @projects,$project;
1464 # Ask for project-wide options
1465 if ($opt_ask_project_options == $OPT_ASK_YES) {
1466 my $flag_desc="";
1467 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1468 $flag_desc="mfc";
1470 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1471 if (defined $flag_desc) {
1472 print "* (currently $flag_desc)\n";
1474 print "* or 'skip' to skip the target specific options,\n";
1475 print "* or 'never' to not be asked this question again:\n";
1476 while (1) {
1477 my $options=<STDIN>;
1478 chomp $options;
1479 if ($options eq "skip") {
1480 $opt_ask_target_options=$OPT_ASK_SKIP;
1481 last;
1482 } elsif ($options eq "never") {
1483 $opt_ask_project_options=$OPT_ASK_NO;
1484 last;
1485 } elsif (source_set_options($project_settings,$options)) {
1486 last;
1488 print "Please re-enter the options:\n";
1492 # - Create the targets
1493 # - Check if we have both libraries and programs
1494 # - Match each target with source files (sort in reverse
1495 # alphabetical order to get the longest matches first)
1496 my @local_dlls=();
1497 my @local_depends=();
1498 my @exe_list=();
1499 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1500 # Create the target...
1501 my $target=[];
1502 target_init($target);
1503 @$target[$T_NAME]=$target_name;
1504 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
1505 if ($target_name =~ /\.dll$/) {
1506 @$target[$T_TYPE]=$TT_DLL;
1507 push @local_depends,"$target_name.so";
1508 push @local_dlls,$target_name;
1509 my $canon=canonize($target_name);
1510 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1511 } else {
1512 @$target[$T_TYPE]=$opt_target_type;
1513 push @exe_list,$target;
1514 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
1516 my $basename=$target_name;
1517 $basename=~ s/\.(dll|exe)$//i;
1518 # This is the default link list of Visual Studio
1519 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1520 my @std_libraries=qw(uuid);
1521 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1522 @$target[$T_DLLS]=\@std_imports;
1523 @$target[$T_LIBRARIES]=\@std_libraries;
1524 } else {
1525 @$target[$T_DLLS]=[];
1526 @$target[$T_LIBRARIES]=[];
1528 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1529 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
1530 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1531 push @{@$target[$T_LDFLAGS]},"-m$opt_arch";
1534 push @{@$project[$P_TARGETS]},$target;
1536 # Ask for target-specific options
1537 if ($opt_ask_target_options == $OPT_ASK_YES) {
1538 my $flag_desc="";
1539 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
1540 $flag_desc=" (mfc";
1542 if ($flag_desc ne "") {
1543 $flag_desc.=")";
1545 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1546 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1547 while (1) {
1548 my $options=<STDIN>;
1549 chomp $options;
1550 if ($options eq "never") {
1551 $opt_ask_target_options=$OPT_ASK_NO;
1552 last;
1553 } elsif (source_set_options($target,$options)) {
1554 last;
1556 print "Please re-enter the options:\n";
1559 if (@$target[$T_FLAGS] & $TF_MFC) {
1560 @$project_settings[$T_FLAGS]|=$TF_MFC;
1561 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1562 push @{@$target[$T_DLLS]},"mfc.dll";
1563 # FIXME: Link with the MFC in the Unix sense, until we
1564 # start exporting the functions properly.
1565 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1566 push @{@$target[$T_LIBRARIES]},"mfc";
1569 # Match sources...
1570 if ($target_count == 1) {
1571 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1572 @$project_settings[$T_SOURCES_C]=[];
1573 @sources_c=();
1575 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1576 @$project_settings[$T_SOURCES_CXX]=[];
1577 @sources_cxx=();
1579 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1580 @$project_settings[$T_SOURCES_RC]=[];
1581 @sources_rc=();
1583 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1584 # No need for sorting these sources
1585 @$project_settings[$T_SOURCES_MISC]=[];
1586 @sources_misc=();
1587 } else {
1588 foreach my $source (@sources_c) {
1589 if ($source =~ /^$basename/i) {
1590 push @{@$target[$T_SOURCES_C]},$source;
1591 $source="";
1594 foreach my $source (@sources_cxx) {
1595 if ($source =~ /^$basename/i) {
1596 push @{@$target[$T_SOURCES_CXX]},$source;
1597 $source="";
1600 foreach my $source (@sources_rc) {
1601 if ($source =~ /^$basename/i) {
1602 push @{@$target[$T_SOURCES_RC]},$source;
1603 $source="";
1606 foreach my $source (@sources_misc) {
1607 if ($source =~ /^$basename/i) {
1608 push @{@$target[$T_SOURCES_MISC]},$source;
1609 $source="";
1613 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1614 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1615 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1616 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1618 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1619 $opt_ask_target_options=$OPT_ASK_YES;
1622 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1623 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1624 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1625 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1626 push @{@$project_settings[$T_CEXTRA]},"-m$opt_arch";
1627 push @{@$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1631 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1632 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1634 # The sources that did not match, if any, go to the extra
1635 # source list of the project settings
1636 foreach my $source (@sources_c) {
1637 if ($source ne "") {
1638 push @{@$project_settings[$T_SOURCES_C]},$source;
1641 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1642 foreach my $source (@sources_cxx) {
1643 if ($source ne "") {
1644 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1647 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1648 foreach my $source (@sources_rc) {
1649 if ($source ne "") {
1650 push @{@$project_settings[$T_SOURCES_RC]},$source;
1653 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1654 foreach my $source (@sources_misc) {
1655 if ($source ne "") {
1656 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1659 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1661 # Finally if we are building both libraries and programs in
1662 # this directory, then the programs should be linked with all
1663 # the libraries
1664 if (@local_dlls > 0 and @exe_list > 0) {
1665 foreach my $target (@exe_list) {
1666 push @{@$target[$T_DLL_PATH]},"-L.";
1667 push @{@$target[$T_DLLS]},@local_dlls;
1673 # Scan the source directories in search of things to build
1674 sub source_scan()
1676 # If there's a single target then this is going to be the default target
1677 if (defined $opt_single_target) {
1678 # Create the main target
1679 my $main_target=[];
1680 target_init($main_target);
1681 @$main_target[$T_NAME]=$opt_single_target;
1682 @$main_target[$T_TYPE]=$opt_target_type;
1684 # Add it to the list
1685 push @{$main_project[$P_TARGETS]},$main_target;
1688 # The main directory is always going to be there
1689 push @projects,\@main_project;
1691 if (defined $opt_work_dir) {
1692 # Now scan the directory tree looking for source files and, maybe, targets
1693 print "Scanning the source directories...\n";
1694 source_scan_directory(\@main_project,"","",0);
1695 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1696 } elsif (defined $opt_work_file) {
1697 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1698 source_scan_project_file(\@main_project,0,$opt_work_file);
1699 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1700 source_scan_workspace_file($opt_work_file);
1705 #####
1707 # Source search
1709 #####
1712 # Performs a directory traversal and renames the files so that:
1713 # - they have the case desired by the user
1714 # - their extension is of the appropriate case
1715 # - they don't contain annoying characters like ' ', '$', '#', ...
1716 # But only perform these changes for source files and directories.
1717 sub fix_file_and_directory_names($);
1718 sub fix_file_and_directory_names($)
1720 my $dirname=$_[0];
1722 my $directory=get_directory_contents($dirname);
1723 foreach my $dentry (@$directory)
1725 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1726 next;
1728 # Set $warn to 1 if the user should be warned of the renaming
1729 my $warn;
1730 my $new_name=$dentry;
1732 if (-f "$dirname/$dentry")
1734 # Don't rename Winemaker's makefiles
1735 next if ($dentry eq "Makefile" and
1736 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker/);
1738 # Leave non-source files alone
1739 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc))$/i);
1741 # Only all lowercase extensions are supported (because of
1742 # rules like '.c.o:').
1743 $new_name =~ s/\.C$/.c/;
1744 $new_name =~ s/\.cpp$/.cpp/i;
1745 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1746 $new_name =~ s/\.rc$/.rc/i;
1747 # And this last one is to avoid confusion when running make
1748 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1751 # Adjust the case to the user's preferences
1752 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1753 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1755 $new_name=lc $new_name;
1758 # make doesn't support these characters well
1759 $new_name =~ s/[ \$]/_/g;
1761 # And finally, perform the renaming
1762 if ($new_name ne $dentry)
1764 if ($warn) {
1765 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1767 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1768 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1769 print STDERR " $!\n";
1770 $new_name=$dentry;
1772 else
1774 clear_directory_cache($dirname);
1777 if (-d "$dirname/$new_name") {
1778 fix_file_and_directory_names("$dirname/$new_name");
1785 #####
1787 # Source fixup
1789 #####
1792 # Try to find a file for the specified filename. The attempt is
1793 # case-insensitive which is why it's not trivial. If a match is
1794 # found then we return the pathname with the correct case.
1795 sub search_from($$)
1797 my $dirname=$_[0];
1798 my $path=$_[1];
1799 my $real_path="";
1801 $dirname =~ s/(\.\/)+//;
1802 if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
1803 $dirname=cwd;
1804 } elsif ($dirname !~ m+^/+) {
1805 $dirname=cwd . "/" . $dirname;
1807 if ($dirname !~ m+/$+) {
1808 $dirname.="/";
1811 foreach my $component (@$path) {
1812 $component=~s/^\"//;
1813 $component=~s/\"$//;
1814 #print " looking for $component in \"$dirname\"\n";
1815 if ($component eq ".") {
1816 # Pass it as is
1817 $real_path.="./";
1818 } elsif ($component eq "..") {
1819 # Go up one level
1820 if ($dirname =~ /\.\.\/$/) {
1821 $dirname.="../";
1822 } else {
1823 $dirname=dirname($dirname) . "/";
1825 $real_path.="../";
1826 } else {
1827 # The file/directory may have been renamed before. Also try to
1828 # match the renamed file.
1829 my $renamed=$component;
1830 $renamed =~ s/[ \$]/_/g;
1831 if ($renamed eq $component) {
1832 undef $renamed;
1835 my $directory=get_directory_contents $dirname;
1836 my $found;
1837 foreach my $dentry (@$directory) {
1838 if ($dentry =~ /^\Q$component\E$/i or
1839 (defined $renamed and $dentry =~ /^$renamed$/i)
1841 $dirname.="$dentry/";
1842 $real_path.="$dentry/";
1843 $found=1;
1844 last;
1847 if (!defined $found) {
1848 # Give up
1849 #print " could not find $component in $dirname\n";
1850 return;
1854 $real_path=~ s+/$++;
1855 #print " -> found $real_path\n";
1856 return $real_path;
1860 # Performs a case-insensitive search for the specified file in the
1861 # include path.
1862 # $line is the line number that should be referenced when an error occurs
1863 # $filename is the file we are looking for
1864 # $dirname is the directory of the file containing the '#include' directive
1865 # if '"' was used, it is an empty string otherwise
1866 # $project and $target specify part of the include path
1867 sub get_real_include_name($$$$$)
1869 my $line=$_[0];
1870 my $filename=$_[1];
1871 my $dirname=$_[2];
1872 my $project=$_[3];
1873 my $target=$_[4];
1875 if ($filename =~ /^([a-zA-Z]:)?[\/\\]/ or $filename =~ /^[a-zA-Z]:[\/\\]?/) {
1876 # This is not a relative path, we cannot make any check
1877 my $warning="path:$filename";
1878 if (!defined $warnings{$warning}) {
1879 $warnings{$warning}="1";
1880 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1881 print STDERR "$line: $filename\n";
1883 } else {
1884 # Here's how we proceed:
1885 # - split the filename we look for into its components
1886 # - then for each directory in the include path
1887 # - trace the directory components starting from that directory
1888 # - if we fail to find a match at any point then continue with
1889 # the next directory in the include path
1890 # - otherwise, rejoice, our quest is over.
1891 my @file_components=split /[\/\\]+/, $filename;
1892 #print " Searching for $filename from @$project[$P_PATH]\n";
1894 my $real_filename;
1895 if ($dirname ne "") {
1896 # This is an 'include ""' -> look in dirname first.
1897 #print " in $dirname (include \"\")\n";
1898 $real_filename=search_from($dirname,\@file_components);
1899 if (defined $real_filename) {
1900 return $real_filename;
1903 my $project_settings=@$project[$P_SETTINGS];
1904 foreach my $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1905 my $dirname=$include;
1906 $dirname=~ s+^-I++;
1907 $dirname=~ s+\s$++;
1908 if (!is_absolute($dirname)) {
1909 $dirname="@$project[$P_PATH]$dirname";
1910 } else {
1911 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1912 $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
1914 #print " in $dirname\n";
1915 $real_filename=search_from("$dirname",\@file_components);
1916 if (defined $real_filename) {
1917 return $real_filename;
1920 my $dotdotpath=@$project[$P_PATH];
1921 $dotdotpath =~ s/[^\/]+/../g;
1922 foreach my $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1923 my $dirname=$include;
1924 $dirname=~ s+^-I++;
1925 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1926 $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
1927 #print " in $dirname (global setting)\n";
1928 $real_filename=search_from("$dirname",\@file_components);
1929 if (defined $real_filename) {
1930 return $real_filename;
1934 $filename =~ s+\\\\+/+g; # in include ""
1935 $filename =~ s+\\+/+g; # in include <> !
1936 if ($opt_lower_include) {
1937 return lc "$filename";
1939 return $filename;
1942 sub print_pack($$$)
1944 my $indent=$_[0];
1945 my $size=$_[1];
1946 my $trailer=$_[2];
1948 if ($size =~ /^(1|2|4|8)$/) {
1949 print FILEO "$indent#include <pshpack$size.h>$trailer";
1950 } else {
1951 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1952 print FILEO "$indent#include <pshpack4.h>$trailer";
1957 # 'Parses' a source file and fixes constructs that would not work with
1958 # Winelib. The parsing is rather simple and not all non-portable features
1959 # are corrected. The most important feature that is corrected is the case
1960 # and path separator of '#include' directives. This requires that each
1961 # source file be associated to a project & target so that the proper
1962 # include path is used.
1963 # Also note that the include path is relative to the directory in which the
1964 # compiler is run, i.e. that of the project, not to that of the file.
1965 sub fix_file($$$)
1967 my $filename=$_[0];
1968 my $project=$_[1];
1969 my $target=$_[2];
1970 $filename="@$project[$P_PATH]$filename";
1971 if (! -e $filename) {
1972 return;
1975 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1976 my $dirname=dirname($filename);
1977 my $is_mfc=0;
1978 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1979 $is_mfc=1;
1982 print " $filename\n";
1983 #FIXME:assuming that because there is a .bak file, this is what we want is
1984 #probably flawed. Or is it???
1985 if (! -e "$filename.bak") {
1986 if (!copy("$filename","$filename.bak")) {
1987 print STDERR "error: unable to make a backup of $filename:\n";
1988 print STDERR " $!\n";
1989 return;
1992 if (!open(FILEI,"$filename.bak")) {
1993 print STDERR "error: unable to open $filename.bak for reading:\n";
1994 print STDERR " $!\n";
1995 return;
1997 if (!open(FILEO,">$filename")) {
1998 print STDERR "error: unable to open $filename for writing:\n";
1999 print STDERR " $!\n";
2000 return;
2002 my $line=0;
2003 my $modified=0;
2004 my $rc_block_depth=0;
2005 my $rc_textinclude_state=0;
2006 my @pack_stack;
2007 while (<FILEI>) {
2008 # Remove any trailing CtrlZ, which isn't strictly in the file
2009 if (/\x1A/) {
2010 s/\x1A//;
2011 last if (/^$/)
2013 $line++;
2014 s/\r\n$/\n/;
2015 if (!/\n$/) {
2016 # Make sure all files are '\n' terminated
2017 $_ .= "\n";
2019 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
2020 # VC6 automatically includes 'afxres.h', an MFC specific header, in
2021 # the RC files it generates (even in non-MFC projects). So we replace
2022 # it with 'winresrc.h' its very close standard cousin so that non MFC
2023 # projects can compile in Wine without the MFC sources.
2024 my $warning="mfc:afxres.h";
2025 if (!defined $warnings{$warning}) {
2026 $warnings{$warning}="1";
2027 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
2028 print STDERR "warning: the above warning is issued only once\n";
2030 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
2031 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
2032 print FILEO "$1$2\"winresrc.h\"$'";
2033 $modified=1;
2035 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
2036 my $from_file=($2 eq "<"?"":$dirname);
2037 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2038 print FILEO "$1$2$real_include_name$4$'";
2039 $modified|=($real_include_name ne $3);
2041 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
2042 # Pragma pack handling
2044 # pack_stack is an array of references describing the stack of
2045 # pack directives currently in effect. Each directive if described
2046 # by a reference to an array containing:
2047 # - "push" for pack(push,...) directives, "" otherwise
2048 # - the directive's identifier at index 1
2049 # - the directive's alignment value at index 2
2051 # Don't believe a word of what the documentation says: it's all wrong.
2052 # The code below is based on the actual behavior of Visual C/C++ 6.
2053 my $pack_indent=$1;
2054 my $pack_header=$2;
2055 if (/^(\))/) {
2056 # pragma pack()
2057 # Pushes the default stack alignment
2058 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2059 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2060 print_pack($pack_indent,4,$');
2061 push @pack_stack, [ "", "", 4 ];
2063 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
2064 # pragma pack(pop)
2065 # pragma pack(pop,n)
2066 # Goes up the stack until it finds a pack(push,...), and pops it
2067 # Ignores any pack(n) entry
2068 # Issues a warning if the pack is of the form pack(push,label)
2069 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2070 my $pack_comment=$';
2071 $pack_comment =~ s/^\s*//;
2072 if ($pack_comment ne "") {
2073 print FILEO "$pack_indent$pack_comment";
2075 while (1) {
2076 my $alignment=pop @pack_stack;
2077 if (!defined $alignment) {
2078 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2079 last;
2081 if (@$alignment[1]) {
2082 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2084 print FILEO "$pack_indent#include <poppack.h>\n";
2085 if (@$alignment[0]) {
2086 last;
2090 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2091 # pragma pack(pop,label[,n])
2092 # Goes up the stack until finding a pack(push,...) and pops it.
2093 # 'n', if specified, is ignored.
2094 # Ignores any pack(n) entry
2095 # Issues a warning if the label of the pack does not match,
2096 # or if it is in fact a pack(push,n)
2097 my $label=$2;
2098 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2099 my $pack_comment=$';
2100 $pack_comment =~ s/^\s*//;
2101 if ($pack_comment ne "") {
2102 print FILEO "$pack_indent$pack_comment";
2104 while (1) {
2105 my $alignment=pop @pack_stack;
2106 if (!defined $alignment) {
2107 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2108 last;
2110 if (@$alignment[1] and @$alignment[1] ne $label) {
2111 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2113 print FILEO "$pack_indent#include <poppack.h>\n";
2114 if (@$alignment[0]) {
2115 last;
2119 } elsif (/^(push\s*\))/) {
2120 # pragma pack(push)
2121 # Push the current alignment
2122 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2123 if (@pack_stack > 0) {
2124 my $alignment=$pack_stack[$#pack_stack];
2125 print_pack($pack_indent,@$alignment[2],$');
2126 push @pack_stack, [ "push", "", @$alignment[2] ];
2127 } else {
2128 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2129 print_pack($pack_indent,4,$');
2130 push @pack_stack, [ "push", "", 4 ];
2133 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2134 # pragma pack([push,]n)
2135 # Push new alignment n
2136 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2137 print_pack($pack_indent,$3,"$'");
2138 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2140 } elsif (/^((\w+)\s*\))/) {
2141 # pragma pack(label)
2142 # label must in fact be a macro that resolves to an integer
2143 # Then behaves like 'pragma pack(n)'
2144 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2145 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2146 print_pack($pack_indent,4,$');
2147 push @pack_stack, [ "", "", 4 ];
2149 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2150 # pragma pack(push,label[,n])
2151 # Pushes a new label on the stack. It is possible to push the same
2152 # label multiple times. If 'n' is omitted then the alignment is
2153 # unchanged. Otherwise it becomes 'n'.
2154 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2155 my $size;
2156 if (defined $4) {
2157 $size=$4;
2158 } elsif (@pack_stack > 0) {
2159 my $alignment=$pack_stack[$#pack_stack];
2160 $size=@$alignment[2];
2161 } else {
2162 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2163 $size=4;
2165 print_pack($pack_indent,$size,$');
2166 push @pack_stack, [ "push", $2, $size ];
2168 } else {
2169 # pragma pack(??? -> What's that?
2170 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2171 print FILEO "$pack_indent$pack_header$_";
2174 $modified=1;
2176 } elsif ($is_rc) {
2177 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]+)([\">]?)/) {
2178 my $from_file=($5 eq "<"?"":$dirname);
2179 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2180 print FILEO "$1$5$real_include_name$7$'";
2181 $modified|=($real_include_name ne $6);
2183 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2184 my $from_file=($2 eq "<"?"":$dirname);
2185 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2186 print FILEO "$1$2$real_include_name$4$'";
2187 $modified|=($real_include_name ne $3);
2189 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2190 $rc_textinclude_state=1;
2191 print FILEO;
2193 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2194 print FILEO "$1winresrc.h$2$'";
2195 $modified=1;
2197 } elsif (/^\s*BEGIN(\W.*)?$/) {
2198 $rc_textinclude_state|=2;
2199 $rc_block_depth++;
2200 print FILEO;
2202 } elsif (/^\s*END(\W.*)?$/) {
2203 $rc_textinclude_state=0;
2204 if ($rc_block_depth>0) {
2205 $rc_block_depth--;
2207 print FILEO;
2209 } else {
2210 print FILEO;
2213 } else {
2214 print FILEO;
2218 close(FILEI);
2219 close(FILEO);
2220 if ($opt_backup == 0 or $modified == 0) {
2221 if (!unlink("$filename.bak")) {
2222 print STDERR "error: unable to delete $filename.bak:\n";
2223 print STDERR " $!\n";
2229 # Analyzes each source file in turn to find and correct issues
2230 # that would cause it not to compile.
2231 sub fix_source()
2233 print "Fixing the source files...\n";
2234 foreach my $project (@projects) {
2235 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2236 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2237 fix_file($source,$project,$target);
2245 #####
2247 # File generation
2249 #####
2252 # A convenience function to generate all the lists (defines,
2253 # C sources, C++ source, etc.) in the Makefile
2254 sub generate_list($$$;$)
2256 my $name=$_[0];
2257 my $last=$_[1];
2258 my $list=$_[2];
2259 my $data=$_[3];
2260 my $first=$name;
2262 if ($name) {
2263 printf FILEO "%-22s=",$name;
2265 if (defined $list) {
2266 foreach my $item (@$list) {
2267 my $value;
2268 if (defined $data) {
2269 $value=&$data($item);
2270 } else {
2271 if (defined $item) {
2272 $value=$item;
2273 } else {
2274 $value="";
2277 if ($value ne "") {
2278 if ($first) {
2279 print FILEO " $value";
2280 $first=0;
2281 } else {
2282 print FILEO " \\\n\t\t\t$value";
2287 if ($last) {
2288 print FILEO "\n";
2293 # Generates a project's Makefile and all the target files
2294 sub generate_project_files($)
2296 my $project=$_[0];
2297 my $project_settings=@$project[$P_SETTINGS];
2298 my @dll_list=();
2299 my @exe_list=();
2301 # Then sort the targets and separate the libraries from the programs
2302 foreach my $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
2303 if (@$target[$T_TYPE] == $TT_DLL) {
2304 push @dll_list,$target;
2305 } else {
2306 push @exe_list,$target;
2309 @$project[$P_TARGETS]=[];
2310 push @{@$project[$P_TARGETS]}, @dll_list;
2311 push @{@$project[$P_TARGETS]}, @exe_list;
2313 if (!open(FILEO,">@$project[$P_PATH]Makefile")) {
2314 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2315 print STDERR " $!\n";
2316 return;
2319 print FILEO "### Generated by Winemaker $version\n";
2320 print FILEO "\n\n";
2322 generate_list("SRCDIR",1,[ "." ]);
2323 if (@$project[$P_PATH] eq "") {
2324 # This is the main project. It is also responsible for recursively
2325 # calling the other projects
2326 generate_list("SUBDIRS",1,\@projects,sub
2328 if ($_[0] != \@main_project) {
2329 my $subdir=@{$_[0]}[$P_PATH];
2330 $subdir =~ s+/$++;
2331 return $subdir;
2333 # Eliminating the main project by returning undefined!
2336 if (@{@$project[$P_TARGETS]} > 0) {
2337 generate_list("DLLS",1,\@dll_list,sub
2339 return @{$_[0]}[$T_NAME];
2341 generate_list("EXES",1,\@exe_list,sub
2343 return "@{$_[0]}[$T_NAME]";
2345 print FILEO "\n\n\n";
2347 print FILEO "### Common settings\n\n";
2348 # Make it so that the project-wide settings override the global settings
2349 generate_list("CEXTRA",1,@$project_settings[$T_CEXTRA]);
2350 generate_list("CXXEXTRA",1,@$project_settings[$T_CXXEXTRA]);
2351 generate_list("RCEXTRA",1,@$project_settings[$T_RCEXTRA]);
2352 generate_list("DEFINES",1,@$project_settings[$T_DEFINES]);
2353 generate_list("INCLUDE_PATH",1,@$project_settings[$T_INCLUDE_PATH]);
2354 generate_list("DLL_PATH",1,@$project_settings[$T_DLL_PATH]);
2355 generate_list("DLL_IMPORTS",1,@$project_settings[$T_DLLS]);
2356 generate_list("LIBRARY_PATH",1,@$project_settings[$T_LIBRARY_PATH]);
2357 generate_list("LIBRARIES",1,@$project_settings[$T_LIBRARIES]);
2358 print FILEO "\n\n";
2360 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
2361 @{@$project_settings[$T_SOURCES_CXX]}+
2362 @{@$project_settings[$T_SOURCES_RC]};
2363 my $no_extra=($extra_source_count == 0);
2364 if (!$no_extra) {
2365 print FILEO "### Extra source lists\n\n";
2366 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
2367 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
2368 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
2369 print FILEO "\n";
2370 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
2371 print FILEO "\n\n\n";
2374 # Iterate over all the targets...
2375 foreach my $target (@{@$project[$P_TARGETS]}) {
2376 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
2377 my $canon=canonize("@$target[$T_NAME]");
2378 $canon =~ s+_so$++;
2380 generate_list("${canon}_MODULE",1,[@$target[$T_NAME]]);
2381 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
2382 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
2383 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
2384 generate_list("${canon}_LDFLAGS",1,@$target[$T_LDFLAGS]);
2385 generate_list("${canon}_DLL_PATH",1,@$target[$T_DLL_PATH]);
2386 generate_list("${canon}_DLLS",1,@$target[$T_DLLS]);
2387 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]);
2388 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]);
2389 print FILEO "\n";
2390 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2391 print FILEO "\n\n\n";
2393 print FILEO "### Global source lists\n\n";
2394 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
2396 my $canon=canonize(@{$_[0]}[$T_NAME]);
2397 $canon =~ s+_so$++;
2398 return "\$(${canon}_C_SRCS)";
2400 if (!$no_extra) {
2401 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
2403 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
2405 my $canon=canonize(@{$_[0]}[$T_NAME]);
2406 $canon =~ s+_so$++;
2407 return "\$(${canon}_CXX_SRCS)";
2409 if (!$no_extra) {
2410 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2412 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
2414 my $canon=canonize(@{$_[0]}[$T_NAME]);
2415 $canon =~ s+_so$++;
2416 return "\$(${canon}_RC_SRCS)";
2418 if (!$no_extra) {
2419 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2422 print FILEO "\n\n";
2423 print FILEO "### Tools\n\n";
2424 print FILEO "CC = winegcc\n";
2425 print FILEO "CXX = wineg++\n";
2426 print FILEO "RC = wrc\n";
2427 print FILEO "\n\n";
2429 print FILEO "### Generic targets\n\n";
2430 print FILEO "all:";
2431 if (@$project[$P_PATH] eq "") {
2432 print FILEO " \$(SUBDIRS)";
2434 if (@{@$project[$P_TARGETS]} > 0) {
2435 print FILEO " \$(DLLS:%=%.so) \$(EXES:%=%.so)";
2437 print FILEO "\n\n";
2438 print FILEO "### Build rules\n";
2439 print FILEO "\n";
2440 print FILEO ".PHONY: all clean dummy\n";
2441 print FILEO "\n";
2442 print FILEO "\$(SUBDIRS): dummy\n";
2443 print FILEO "\t\@cd \$\@ && \$(MAKE)\n";
2444 print FILEO "\n";
2445 print FILEO "# Implicit rules\n";
2446 print FILEO "\n";
2447 print FILEO ".SUFFIXES: .cpp .rc .res\n";
2448 print FILEO "DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2449 print FILEO "\n";
2450 print FILEO ".c.o:\n";
2451 print FILEO "\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2452 print FILEO "\n";
2453 print FILEO ".cpp.o:\n";
2454 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2455 print FILEO "\n";
2456 print FILEO ".cxx.o:\n";
2457 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2458 print FILEO "\n";
2459 print FILEO ".rc.res:\n";
2460 print FILEO "\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2461 print FILEO "\n";
2462 print FILEO "# Rules for cleaning\n";
2463 print FILEO "\n";
2464 print FILEO "CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2465 print FILEO " \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2466 print FILEO "\n";
2467 print FILEO "clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2468 print FILEO "\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:.cpp=.o)\n";
2469 print FILEO "\t\$(RM) \$(DLLS:%=%.so) \$(EXES:%=%.so) \$(EXES:%.exe=%)\n";
2470 print FILEO "\n";
2471 print FILEO "\$(SUBDIRS:%=%/__clean__): dummy\n";
2472 print FILEO "\tcd `dirname \$\@` && \$(MAKE) clean\n";
2473 print FILEO "\n";
2474 print FILEO "\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2475 print FILEO "\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2476 print FILEO "\n";
2478 if (@{@$project[$P_TARGETS]} > 0) {
2479 print FILEO "### Target specific build rules\n";
2480 print FILEO "DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2481 foreach my $target (@{@$project[$P_TARGETS]}) {
2482 my $canon=canonize("@$target[$T_NAME]");
2483 $canon =~ s/_so$//;
2485 if (@$target[$T_TYPE] == $TT_DLL) {
2486 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.spec)\n";
2487 } else {
2488 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS)\n";
2490 if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
2491 print FILEO "\t\$(CXX)";
2492 } else {
2493 print FILEO "\t\$(CC)";
2495 print FILEO " \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2496 print FILEO "\n\n";
2499 close(FILEO);
2505 # This is where we finally generate files. In fact this method does not
2506 # do anything itself but calls the methods that do the actual work.
2507 sub generate()
2509 print "Generating project files...\n";
2511 foreach my $project (@projects) {
2512 my $path=@$project[$P_PATH];
2513 if ($path eq "") {
2514 $path=".";
2515 } else {
2516 $path =~ s+/$++;
2518 print " $path\n";
2519 generate_project_files($project);
2525 #####
2527 # Option defaults
2529 #####
2531 $opt_backup=1;
2532 $opt_lower=$OPT_LOWER_UPPERCASE;
2533 $opt_lower_include=1;
2535 $opt_work_dir=undef;
2536 $opt_single_target=undef;
2537 $opt_target_type=$TT_GUIEXE;
2538 $opt_flags=0;
2539 $opt_arch=$OPT_ARCH_DEFAULT;
2540 $opt_is_interactive=$OPT_ASK_NO;
2541 $opt_ask_project_options=$OPT_ASK_NO;
2542 $opt_ask_target_options=$OPT_ASK_NO;
2543 $opt_no_generated_files=0;
2544 $opt_no_source_fix=0;
2545 $opt_no_banner=0;
2549 #####
2551 # Main
2553 #####
2555 sub print_banner()
2557 print "Winemaker $version\n";
2558 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2559 print "Copyright 2004 Dimitrie O. Paun\n";
2560 print "Copyright 2009 André Hentschel\n";
2563 sub usage()
2565 print_banner();
2566 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2567 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2568 print STDERR " [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2569 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2570 print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2571 print STDERR " [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2572 print STDERR " [--generated-files|--nogenerated-files]\n";
2573 print STDERR " [--wine32]\n";
2574 print STDERR " work_directory|project_file|workspace_file\n";
2575 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2576 print STDERR "the specified directory or project-file, so that they can be compiled with Winelib.\n";
2577 print STDERR "During this process it will modify and rename some of the corresponding files.\n";
2578 print STDERR "\tPlease read the manual page before use.\n";
2579 exit (2);
2582 target_init(\@global_settings);
2584 while (@ARGV>0) {
2585 my $arg=shift @ARGV;
2586 # General options
2587 if ($arg eq "--nobanner") {
2588 $opt_no_banner=1;
2589 } elsif ($arg eq "--backup") {
2590 $opt_backup=1;
2591 } elsif ($arg eq "--nobackup") {
2592 $opt_backup=0;
2593 } elsif ($arg eq "--single-target") {
2594 $opt_single_target=shift @ARGV;
2595 } elsif ($arg eq "--lower-none") {
2596 $opt_lower=$OPT_LOWER_NONE;
2597 } elsif ($arg eq "--lower-all") {
2598 $opt_lower=$OPT_LOWER_ALL;
2599 } elsif ($arg eq "--lower-uppercase") {
2600 $opt_lower=$OPT_LOWER_UPPERCASE;
2601 } elsif ($arg eq "--lower-include") {
2602 $opt_lower_include=1;
2603 } elsif ($arg eq "--nolower-include") {
2604 $opt_lower_include=0;
2605 } elsif ($arg eq "--nosource-fix") {
2606 $opt_no_source_fix=1;
2607 } elsif ($arg eq "--generated-files") {
2608 $opt_no_generated_files=0;
2609 } elsif ($arg eq "--nogenerated-files") {
2610 $opt_no_generated_files=1;
2611 } elsif ($arg eq "--wine32") {
2612 $opt_arch=$OPT_ARCH_32;
2613 } elsif ($arg =~ /^-D/) {
2614 push @{$global_settings[$T_DEFINES]},$arg;
2615 } elsif ($arg =~ /^-I/) {
2616 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2617 } elsif ($arg =~ /^-P/) {
2618 push @{$global_settings[$T_DLL_PATH]},"-L$'";
2619 } elsif ($arg =~ /^-i/) {
2620 push @{$global_settings[$T_DLLS]},$';
2621 } elsif ($arg =~ /^-L/) {
2622 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2623 } elsif ($arg =~ /^-l/) {
2624 push @{$global_settings[$T_LIBRARIES]},$';
2626 # 'Source'-based method options
2627 } elsif ($arg eq "--dll") {
2628 $opt_target_type=$TT_DLL;
2629 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2630 $opt_target_type=$TT_GUIEXE;
2631 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2632 $opt_target_type=$TT_CUIEXE;
2633 } elsif ($arg eq "--interactive") {
2634 $opt_is_interactive=$OPT_ASK_YES;
2635 $opt_ask_project_options=$OPT_ASK_YES;
2636 $opt_ask_target_options=$OPT_ASK_YES;
2637 } elsif ($arg eq "--mfc") {
2638 $opt_flags|=$TF_MFC;
2639 } elsif ($arg eq "--nomfc") {
2640 $opt_flags&=~$TF_MFC;
2641 $opt_flags|=$TF_NOMFC;
2642 } elsif ($arg eq "--nodlls") {
2643 $opt_flags|=$TF_NODLLS;
2644 } elsif ($arg eq "--nomsvcrt") {
2645 $opt_flags|=$TF_NOMSVCRT;
2647 # Catch errors
2648 } else {
2649 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2650 if (!defined $opt_work_dir and !defined $opt_work_file) {
2651 if (-f $arg) {
2652 $opt_work_file=$arg;
2654 else {
2655 $opt_work_dir=$arg;
2657 } else {
2658 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2659 usage();
2661 } else {
2662 usage();
2667 if (!defined $opt_work_dir and !defined $opt_work_file) {
2668 print STDERR "error: you must specify the directory or project file containing the sources to be converted\n";
2669 usage();
2670 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2671 print STDERR "error: could not chdir to the work directory\n";
2672 print STDERR " $!\n";
2673 usage();
2676 if ($opt_no_banner == 0) {
2677 print_banner();
2680 project_init(\@main_project, "", \@global_settings);
2682 # Fix the file and directory names
2683 fix_file_and_directory_names(".");
2685 # Scan the sources to identify the projects and targets
2686 source_scan();
2688 # Fix the source files
2689 if (! $opt_no_source_fix) {
2690 fix_source();
2693 # Generate the Makefile and the spec file
2694 if (! $opt_no_generated_files) {
2695 generate();