wined3d: Pass an IWineD3DDeviceImpl pointer to drawPrimitive().
[wine/wine-gecko.git] / tools / winemaker
blob7eb45ecd7c976fabcdd6db814244e0ecc57814c5
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 (/^Z[d7iI]$/) {
628 # Debug Info
629 $prj_target_cflags.="-g ";
630 } elsif (/^Od$/) {
631 # Disable Optimizations
632 $prj_target_cflags.="-O0 ";
633 } elsif (/^O1$/) {
634 # Minimize Size
635 $prj_target_cflags.="-Os ";
636 } elsif (/^O2$/) {
637 # Maximize Speed
638 $prj_target_cflags.="-O2 ";
639 } elsif (/^Ob0$/) {
640 # Disables inline Expansion
641 $prj_target_cflags.="-fno-inline ";
642 } elsif (/^Ob1$/) {
643 #In-line Function Expansion
644 $prj_target_cflags.="-finline-functions ";
645 } elsif (/^Ob2$/) {
646 # auto In-line Function Expansion
647 $prj_target_cflags.="-finline-functions ";
648 } elsif (/^Ox$/) {
649 # Use maximum optimization
650 $prj_target_cflags.="-O3 ";
651 } elsif (/^Oy$/) {
652 # Frame-Pointer Omission
653 $prj_target_cflags.="-fomit-frame-pointer ";
654 } elsif (/^Oy-$/) {
655 # Frame-Pointer Omission
656 $prj_target_cflags.="-fno-omit-frame-pointer ";
657 } elsif (/^GZ$/) {
658 # Catch Release-Build Errors in Debug Build
659 } elsif (/^M[DLT]d?$/) {
660 # Use Multithreaded Run-Time Library
661 } elsif (/^D\s*\"(.*)\"/) {
662 # Preprocessor Definitions
663 $prj_target_defines.="-D".$1." ";
664 } elsif (/^I\s*\"(.*)\"/) {
665 # Additional Include Directories
666 $sfilet=$1;
667 $sfilet=~s/\\/\//g;
668 if ($sfilet=~/^\w:/) {
669 print STDERR "warning: Can't fix path $sfilet\n"
670 } else {
671 push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$sfilet." ";
673 } elsif (/^U\s*\"(.*)\"/) {
674 # Undefines a previously defined symbol
675 $prj_target_cflags.="-U".$1." ";
676 } elsif (/^Fp/) {
677 # Name .PCH File
678 } elsif (/^F[Rr]/) {
679 # Create .SBR File
680 } elsif (/^YX$/) {
681 # Automatic Use of Precompiled Headers
682 } elsif (/^FD$/) {
683 # Generate File Dependencies
684 } elsif (/^c$/) {
685 # Compile Without Linking
686 # this option is always present and is already specified in the suffix rules
687 } elsif (/^GB$/) {
688 # Blend Optimization
689 $prj_target_cflags.="-D_M_IX86=500 ";
690 } elsif (/^G6$/) {
691 # Pentium Pro Optimization
692 $prj_target_cflags.="-D_M_IX86=600 ";
693 } elsif (/^G5$/) {
694 # Pentium Optimization
695 $prj_target_cflags.="-D_M_IX86=500 ";
696 } elsif (/^G3$/) {
697 # 80386 Optimization
698 $prj_target_cflags.="-D_M_IX86=300 ";
699 } elsif (/^G4$/) {
700 # 80486 Optimization
701 $prj_target_cflags.="-D_M_IX86=400 ";
702 } elsif (/^Yc/) {
703 # Create Precompiled Header
704 } elsif (/^Yu/) {
705 # Use Precompiled Header
706 } elsif (/^Za$/) {
707 # Disable Language Extensions
708 $prj_target_cflags.="-ansi ";
709 } elsif (/^Ze$/) {
710 # Enable Microsoft Extensions
711 } elsif (/^Zm[[:digit:]]+$/) {
712 # Specify Memory Allocation Limit
713 } elsif (/^Zp1?$/) {
714 # Packs structures on 1-byte boundaries
715 $prj_target_cflags.="-fpack-struct ";
716 } elsif (/^Zp(2|4|8|16)$/) {
717 # Struct Member Alignment
718 $prj_target_cflags.="-fpack-struct=".$1;
719 } else {
720 print "C compiler option $_ not implemented\n";
724 #print "\nOptions: $prj_target_cflags\n";
725 next;
726 } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
727 $prj_target_ldflags=$1;
728 @prj_target_options=split(" /", $prj_target_ldflags);
729 $prj_target_ldflags="";
730 $prj_target_libs=$prj_target_options[0];
731 $prj_target_libs=~s/\\/\//g;
732 $prj_target_libs=~s/\.lib//g;
733 $prj_target_libs=~s/\s+/ -l/g;
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=$TT_DLL;
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 (!defined $sfilet) { next; }
785 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
786 push @sources_c,$sfilet;
787 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
788 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
789 push @sources_misc,$sfilet;
790 @$project_settings[$T_FLAGS]|=$TF_MFC;
791 } else {
792 push @sources_cxx,$sfilet;
794 } elsif ($sfilet =~ /\.rc$/i) {
795 push @sources_rc,$sfilet;
796 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
797 push @sources_misc,$sfilet;
798 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
799 @$project_settings[$T_FLAGS]|=$TF_MFC;
802 next;
804 } elsif (/^# (Begin|End) Source File/) {
805 # Source-Files already handled
806 next;
807 } elsif (/^# (Begin|End) Group/) {
808 # Groups are ignored
809 next;
810 } elsif (/^# (Begin|End) Custom Build/) {
811 # Custom Builds are ignored
812 next;
813 } elsif (/^# ADD LIB32 /) {
814 #"ARFLAGS=rus"
815 next;
816 } elsif (/^# Begin Target$/) {
817 # Targets are ignored
818 next;
819 } elsif (/^# End Target$/) {
820 # Targets are ignored
821 next;
822 } elsif (/^!/) {
823 if ($found_cfg == 1) {
824 $found_cfg=0;
826 if (/if (.*)\(CFG\)" == "(.*)"/i) {
827 if ($2 eq $prj_cfg) {
828 $found_cfg=1;
831 next;
832 } elsif (/^CFG=(.*)/i) {
833 $prj_cfg=$1;
834 next;
836 else { # Line recognized
837 # print "|\n";
840 close(FILEI);
842 push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
843 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
844 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
845 push @{@$project_settings[$T_DEFINES]},$prj_target_defines;
846 push @{@$project_settings[$T_LDFLAGS]},$prj_target_ldflags;
847 } elsif ($filename =~ /.vcproj$/i) {
848 # Import XML::LibXML, you need the libxml package (deb: libxml-libxml-perl, rpm: perl-libxml-perl)
849 require XML::LibXML;
851 my $xmlparser = XML::LibXML->new();
852 my $project_xml = $xmlparser->parse_file($filename);
853 my $sfilet;
854 my $configt;
856 foreach my $vc_project ($project_xml->findnodes('/VisualStudioProject')) {
857 foreach my $vc_project_attr ($vc_project->attributes) {
858 if ($vc_project_attr->getName eq "Name") {
859 $prj_name=$vc_project_attr->getValue;
860 $prj_name=~s/\s+/_/g;
861 last;
866 for (my $flevel = 0; $flevel <= 5; $flevel++) {
867 foreach my $vc_file ($project_xml->findnodes('/VisualStudioProject/Files/'.('Filter/' x $flevel).'File')) {
868 foreach my $vc_file_attr ($vc_file->attributes) {
869 if ($vc_file_attr->getName eq "RelativePath") {
870 $sfilet = $vc_file_attr->getValue;
871 $sfilet=~s/\\\\/\\/g; #remove double backslash
872 $sfilet=~s/^\.\\//; #remove starting 'this directory'
873 $sfilet=~s/\\/\//g; #make slashes out of backslashes
874 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
875 push @sources_c,$sfilet;
876 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
877 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
878 push @sources_misc,$sfilet;
879 @$project_settings[$T_FLAGS]|=$TF_MFC;
880 } else {
881 push @sources_cxx,$sfilet;
883 } elsif ($sfilet =~ /\.rc$/i) {
884 push @sources_rc,$sfilet;
885 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
886 push @sources_misc,$sfilet;
887 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
888 @$project_settings[$T_FLAGS]|=$TF_MFC;
896 my @vc_configurations = $project_xml->findnodes('/VisualStudioProject/Configurations/Configuration');
897 my $vc_configuration = $vc_configurations[0];
898 foreach my $vc_configuration_attr ($vc_configuration->attributes) {
899 if ($vc_configuration_attr->getName eq "ConfigurationType") {
900 if ($vc_configuration_attr->getValue==1) {
901 $prj_target_type=$TT_GUIEXE; # Application
902 } elsif ($vc_configuration_attr->getValue==2) {
903 $prj_target_type=$TT_DLL; # Dynamic-Link Library
908 foreach my $vc_configuration_tools ($vc_configuration->findnodes('Tool')) {
909 my @find_tool = $vc_configuration_tools->attributes;
910 if ($find_tool[0]->getValue eq "VCCLCompilerTool") {
911 foreach my $vc_compiler_tool ($vc_configuration_tools->attributes) {
912 if ($vc_compiler_tool->getName eq "Optimization") {$prj_target_cflags.="-O".$vc_compiler_tool->getValue." ";}
913 if ($vc_compiler_tool->getName eq "WarningLevel") {
914 if ($vc_compiler_tool->getValue==0) {
915 $prj_target_cflags.="-w ";
916 } elsif ($vc_compiler_tool->getValue<4) {
917 $prj_target_cflags.="-W ";
918 } elsif ($vc_compiler_tool->getValue==4) {
919 $prj_target_cflags.="-Wall ";
920 } elsif ($vc_compiler_tool->getValue eq "X") {
921 $prj_target_cflags.="-Werror ";
924 if ($vc_compiler_tool->getName eq "PreprocessorDefinitions") {
925 $configt=$vc_compiler_tool->getValue;
926 $configt=~s/;/ -D/g;
927 $prj_target_defines.="-D".$configt." ";
929 if ($vc_compiler_tool->getName eq "AdditionalIncludeDirectories") {
930 $configt=$vc_compiler_tool->getValue;
931 $configt=~s/\\/\//g;
932 $configt=~s/;/ -I/g;
933 push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$configt;
937 if ($find_tool[0]->getValue eq "VCLinkerTool") {
938 foreach my $vc_linker_tool ($vc_configuration_tools->attributes) {
939 if ($vc_linker_tool->getName eq "AdditionalDependencies") {
940 $prj_target_libs=" ".$vc_linker_tool->getValue;
941 $prj_target_libs=~s/\\/\//g;
942 $prj_target_libs=~s/\.lib//g;
943 $prj_target_libs=~s/\s+/ -l/g;
949 push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
950 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
951 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
952 push @{@$project_settings[$T_DEFINES]},$prj_target_defines;
955 # Add this project to the project list, except for
956 # the main project which is already in the list.
957 if ($is_sub_project == 1) {
958 push @projects,$project;
961 # Ask for project-wide options
962 if ($opt_ask_project_options == $OPT_ASK_YES) {
963 my $flag_desc="";
964 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
965 $flag_desc="mfc";
967 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
968 if (defined $flag_desc) {
969 print "* (currently $flag_desc)\n";
971 print "* or 'skip' to skip the target specific options,\n";
972 print "* or 'never' to not be asked this question again:\n";
973 while (1) {
974 my $options=<STDIN>;
975 chomp $options;
976 if ($options eq "skip") {
977 $opt_ask_target_options=$OPT_ASK_SKIP;
978 last;
979 } elsif ($options eq "never") {
980 $opt_ask_project_options=$OPT_ASK_NO;
981 last;
982 } elsif (source_set_options($project_settings,$options)) {
983 last;
985 print "Please re-enter the options:\n";
989 my @local_dlls=();
990 my @local_depends=();
991 my @exe_list=();
993 # Create the target...
994 my $target=[];
995 target_init($target);
997 if ($prj_target_type!=$TT_DLL) {
998 $prj_name=lc($prj_name.".exe");
999 @$target[$T_TYPE]=$opt_target_type;
1000 push @exe_list,$target;
1001 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
1002 } else {
1003 $prj_name=lc($prj_name.".dll");
1004 @$target[$T_TYPE]=$TT_DLL;
1005 push @local_depends,"$prj_name.so";
1006 push @local_dlls,$prj_name;
1007 my $canon=canonize($prj_name);
1008 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1011 @$target[$T_NAME]=$prj_name;
1012 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
1014 # This is the default link list of Visual Studio
1015 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1016 my @std_libraries=qw(uuid);
1017 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1018 @$target[$T_DLLS]=\@std_imports;
1019 @$target[$T_LIBRARIES]=\@std_libraries;
1020 } else {
1021 @$target[$T_DLLS]=[];
1022 @$target[$T_LIBRARIES]=[];
1024 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1025 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
1026 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1027 push @{@$target[$T_LDFLAGS]},"-m$opt_arch";
1030 push @{@$project[$P_TARGETS]},$target;
1032 # Ask for target-specific options
1033 if ($opt_ask_target_options == $OPT_ASK_YES) {
1034 my $flag_desc="";
1035 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
1036 $flag_desc=" (mfc";
1038 if ($flag_desc ne "") {
1039 $flag_desc.=")";
1041 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1042 print "* \"$prj_name\"$flag_desc or 'never' to not be asked this question again:\n";
1043 while (1) {
1044 my $options=<STDIN>;
1045 chomp $options;
1046 if ($options eq "never") {
1047 $opt_ask_target_options=$OPT_ASK_NO;
1048 last;
1049 } elsif (source_set_options($target,$options)) {
1050 last;
1052 print "Please re-enter the options:\n";
1055 if (@$target[$T_FLAGS] & $TF_MFC) {
1056 @$project_settings[$T_FLAGS]|=$TF_MFC;
1057 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1058 push @{@$target[$T_DLLS]},"mfc.dll";
1059 # FIXME: Link with the MFC in the Unix sense, until we
1060 # start exporting the functions properly.
1061 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1062 push @{@$target[$T_LIBRARIES]},"mfc";
1065 # Match sources...
1066 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1067 @$project_settings[$T_SOURCES_C]=[];
1068 @sources_c=();
1069 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1070 @$project_settings[$T_SOURCES_CXX]=[];
1071 @sources_cxx=();
1072 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1073 @$project_settings[$T_SOURCES_RC]=[];
1074 @sources_rc=();
1075 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1076 @$project_settings[$T_SOURCES_MISC]=[];
1077 @sources_misc=();
1079 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1080 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1081 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1082 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1084 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1085 $opt_ask_target_options=$OPT_ASK_YES;
1088 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1089 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1090 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1091 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1092 push @{@$project_settings[$T_CEXTRA]},"-m$opt_arch";
1093 push @{@$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1097 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1098 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1100 # The sources that did not match, if any, go to the extra
1101 # source list of the project settings
1102 foreach my $source (@sources_c) {
1103 if ($source ne "") {
1104 push @{@$project_settings[$T_SOURCES_C]},$source;
1107 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1108 foreach my $source (@sources_cxx) {
1109 if ($source ne "") {
1110 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1113 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1114 foreach my $source (@sources_rc) {
1115 if ($source ne "") {
1116 push @{@$project_settings[$T_SOURCES_RC]},$source;
1119 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1120 foreach my $source (@sources_misc) {
1121 if ($source ne "") {
1122 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1125 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1129 # Scans the specified workspace file to find the project files
1130 sub source_scan_workspace_file($);
1131 sub source_scan_workspace_file($)
1133 my $filename=$_[0];
1134 my $path=dirname($filename);
1135 my @components;
1137 if (! -e $filename) {
1138 return;
1141 if (!open(FILEIWS,$filename)) {
1142 print STDERR "error: unable to open $filename for reading:\n";
1143 print STDERR " $!\n";
1144 return;
1147 my $prj_name;
1148 my $prj_path;
1150 if ($filename =~ /.dsw$/i) {
1151 while (<FILEIWS>) {
1152 # Remove any trailing CrLf
1153 s/\r\n$/\n/;
1155 # catch a project definition
1156 if (/^Project:\s\"(.*)\"=(.*)\s-/) {
1157 $prj_name=$1;
1158 $prj_path=$2;
1159 @components=split /[\/\\]+/, $prj_path;
1160 $prj_path=search_from($path, \@components);
1161 print "Name: $prj_name\nPath: $prj_path\n";
1162 source_scan_project_file(\@main_project,1,$prj_path);
1163 next;
1164 } elsif (/^#/) {
1165 # ignore Comments
1166 } elsif (/^Global:/) {
1167 # ignore the Global section
1168 } elsif (/\w:/) {
1169 print STDERR "unknown section $_\n";
1170 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1171 print "\nFileversion: $3\n";
1174 close(FILEIWS);
1175 } elsif ($filename =~ /.sln$/i) {
1176 while (<FILEIWS>) {
1177 # Remove any trailing CrLf
1178 s/\r\n$/\n/;
1180 # catch a project definition
1181 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1182 $prj_name=$2;
1183 $prj_path=$3;
1184 if ($prj_path eq "Solution Items") { next; }
1185 @components=split /[\/\\]+/, $3;
1186 $prj_path=search_from($path, \@components);
1187 print "Name: $prj_name\nPath: $prj_path\n";
1188 source_scan_project_file(\@main_project,1,$prj_path);
1189 next;
1190 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1191 print "\nFileversion: $3\n";
1194 close(FILEIWS);
1197 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1201 # Scans the specified directory to:
1202 # - see if we should create a Makefile in this directory. We normally do
1203 # so if we find a project file and sources
1204 # - get a list of targets for this directory
1205 # - get the list of source files
1206 sub source_scan_directory($$$$);
1207 sub source_scan_directory($$$$)
1209 # a reference to the parent's project
1210 my $parent_project=$_[0];
1211 # the full relative path to the current directory, including a
1212 # trailing '/', or an empty string if this is the top level directory
1213 my $path=$_[1];
1214 # the name of this directory, including a trailing '/', or an empty
1215 # string if this is the top level directory
1216 my $dirname=$_[2];
1217 # if set then no targets will be looked for and the sources will all
1218 # end up in the parent_project's 'misc' bucket
1219 my $no_target=$_[3];
1221 # reference to the project for this directory. May not be used
1222 my $project;
1223 # list of targets found in the 'current' directory
1224 my %targets;
1225 # list of sources found in the current directory
1226 my @sources_c=();
1227 my @sources_cxx=();
1228 my @sources_rc=();
1229 my @sources_misc=();
1230 # true if this directory contains a Windows project
1231 my $has_win_project=0;
1232 # true if this directory contains headers
1233 my $has_headers=0;
1234 # If we don't find any executable/library then we might make up targets
1235 # from the list of .dsp/.mak files we find since they usually have the
1236 # same name as their target.
1237 my @prj_files=();
1238 my @mak_files=();
1240 if (defined $opt_single_target or $dirname eq "") {
1241 # Either there is a single target and thus a single project,
1242 # or we are in the top level directory for which a project
1243 # already exists
1244 $project=$parent_project;
1245 } else {
1246 $project=[];
1247 project_init($project, $path, \@global_settings);
1249 my $project_settings=@$project[$P_SETTINGS];
1251 # First find out what this directory contains:
1252 # collect all sources, targets and subdirectories
1253 my $directory=get_directory_contents($path);
1254 foreach my $dentry (@$directory) {
1255 if ($dentry =~ /^\./) {
1256 next;
1258 my $fullentry="$path$dentry";
1259 if (-d "$fullentry") {
1260 if ($dentry =~ /^(Release|Debug)/i) {
1261 # These directories are often used to store the object files and the
1262 # resulting executable/library. They should not contain anything else.
1263 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
1264 foreach my $candidate (@candidates) {
1265 $targets{$candidate}=1;
1267 } elsif ($dentry =~ /^include/i) {
1268 # This directory must contain headers we're going to need
1269 push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1270 source_scan_directory($project,"$fullentry/","$dentry/",1);
1271 } else {
1272 # Recursively scan this directory. Any source file that cannot be
1273 # attributed to a project in one of the subdirectories will be
1274 # attributed to this project.
1275 source_scan_directory($project,"$fullentry/","$dentry/",$no_target);
1277 } elsif (-f "$fullentry") {
1278 if ($dentry =~ /\.(exe|dll)$/i) {
1279 $targets{$dentry}=1;
1280 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1281 push @sources_c,"$dentry";
1282 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
1283 if ($dentry =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1284 push @sources_misc,"$dentry";
1285 @$project_settings[$T_FLAGS]|=$TF_MFC;
1286 } else {
1287 push @sources_cxx,"$dentry";
1289 } elsif ($dentry =~ /\.rc$/i) {
1290 push @sources_rc,"$dentry";
1291 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1292 $has_headers=1;
1293 push @sources_misc,"$dentry";
1294 if ($dentry =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1295 @$project_settings[$T_FLAGS]|=$TF_MFC;
1297 } elsif ($dentry =~ /\.(dsp|vcproj)$/i) {
1298 push @prj_files,"$dentry";
1299 $has_win_project=1;
1300 } elsif ($dentry =~ /\.mak$/i) {
1301 push @mak_files,"$dentry";
1302 $has_win_project=1;
1303 } elsif ($dentry =~ /^makefile/i) {
1304 $has_win_project=1;
1309 if ($has_headers) {
1310 push @{@$project_settings[$T_INCLUDE_PATH]},"-I.";
1312 # If we have a single target then all we have to do is assign
1313 # all the sources to it and we're done
1314 # FIXME: does this play well with the --interactive mode?
1315 if ($opt_single_target) {
1316 my $target=@{@$project[$P_TARGETS]}[0];
1317 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1318 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1319 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1320 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1321 return;
1323 if ($no_target) {
1324 my $parent_settings=@$parent_project[$P_SETTINGS];
1325 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1326 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1327 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1328 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1329 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1330 return;
1333 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1334 @{@$project_settings[$T_SOURCES_C]}+
1335 @{@$project_settings[$T_SOURCES_CXX]}+
1336 @{@$project_settings[$T_SOURCES_RC]};
1337 if ($source_count == 0) {
1338 # A project without real sources is not a project, get out!
1339 if ($project!=$parent_project) {
1340 my $parent_settings=@$parent_project[$P_SETTINGS];
1341 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1342 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1344 return;
1346 #print "targets=",%targets,"\n";
1347 #print "target_count=$target_count\n";
1348 #print "has_win_project=$has_win_project\n";
1349 #print "dirname=$dirname\n";
1351 my $target_count;
1352 if (($has_win_project != 0) or ($dirname eq "")) {
1353 # Deal with cases where we could not find any executable/library, and
1354 # thus have no target, although we did find some sort of windows project.
1355 $target_count=keys %targets;
1356 if ($target_count == 0) {
1357 # Try to come up with a target list based on .dsp/.mak files
1358 my $prj_list;
1359 if (@prj_files > 0) {
1360 print "Projectfile found! You might want to try using it directly.\n";
1361 $prj_list=\@prj_files;
1362 } else {
1363 $prj_list=\@mak_files;
1365 foreach my $filename (@$prj_list) {
1366 $filename =~ s/\.(dsp|vcproj|mak)$//i;
1367 if ($opt_target_type == $TT_DLL) {
1368 $filename = "$filename.dll";
1370 $targets{$filename}=1;
1372 $target_count=keys %targets;
1373 if ($target_count == 0) {
1374 # Still nothing, try the name of the directory
1375 my $name;
1376 if ($dirname eq "") {
1377 # Bad luck, this is the top level directory!
1378 $name=(split /\//, cwd)[-1];
1379 } else {
1380 $name=$dirname;
1381 # Remove the trailing '/'. Also eliminate whatever is after the last
1382 # '.' as it is likely to be meaningless (.orig, .new, ...)
1383 $name =~ s+(/|\.[^.]*)$++;
1384 if ($name eq "src") {
1385 # 'src' is probably a subdirectory of the real project directory.
1386 # Try again with the parent (if any).
1387 my $parent=$path;
1388 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
1389 $name=$parent;
1390 } else {
1391 $name=(split /\//, cwd)[-1];
1395 $name =~ s+(/|\.[^.]*)$++;
1396 if ($opt_target_type == $TT_DLL) {
1397 $name = canonize($name).".dll";
1398 } else {
1399 $name = canonize($name).".exe";
1401 $targets{$name}=1;
1405 # Ask confirmation to the user if he wishes so
1406 if ($opt_is_interactive == $OPT_ASK_YES) {
1407 my $target_list=join " ",keys %targets;
1408 print "\n*** In ",($path?$path:"./"),"\n";
1409 print "* winemaker found the following list of (potential) targets\n";
1410 print "* $target_list\n";
1411 print "* Type enter to use it as is, your own comma-separated list of\n";
1412 print "* targets, 'none' to assign the source files to a parent directory,\n";
1413 print "* or 'ignore' to ignore everything in this directory tree.\n";
1414 print "* Target list:\n";
1415 $target_list=<STDIN>;
1416 chomp $target_list;
1417 if ($target_list eq "") {
1418 # Keep the target list as is, i.e. do nothing
1419 } elsif ($target_list eq "none") {
1420 # Empty the target list
1421 undef %targets;
1422 } elsif ($target_list eq "ignore") {
1423 # Ignore this subtree altogether
1424 return;
1425 } else {
1426 undef %targets;
1427 foreach my $target (split /,/,$target_list) {
1428 $target =~ s+^\s*++;
1429 $target =~ s+\s*$++;
1430 $targets{$target}=1;
1436 # If we have no project at this level, then transfer all
1437 # the sources to the parent project
1438 $target_count=keys %targets;
1439 if ($target_count == 0) {
1440 if ($project!=$parent_project) {
1441 my $parent_settings=@$parent_project[$P_SETTINGS];
1442 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1443 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1444 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1445 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1446 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1448 return;
1451 # Otherwise add this project to the project list, except for
1452 # the main project which is already in the list.
1453 if ($dirname ne "") {
1454 push @projects,$project;
1457 # Ask for project-wide options
1458 if ($opt_ask_project_options == $OPT_ASK_YES) {
1459 my $flag_desc="";
1460 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1461 $flag_desc="mfc";
1463 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1464 if (defined $flag_desc) {
1465 print "* (currently $flag_desc)\n";
1467 print "* or 'skip' to skip the target specific options,\n";
1468 print "* or 'never' to not be asked this question again:\n";
1469 while (1) {
1470 my $options=<STDIN>;
1471 chomp $options;
1472 if ($options eq "skip") {
1473 $opt_ask_target_options=$OPT_ASK_SKIP;
1474 last;
1475 } elsif ($options eq "never") {
1476 $opt_ask_project_options=$OPT_ASK_NO;
1477 last;
1478 } elsif (source_set_options($project_settings,$options)) {
1479 last;
1481 print "Please re-enter the options:\n";
1485 # - Create the targets
1486 # - Check if we have both libraries and programs
1487 # - Match each target with source files (sort in reverse
1488 # alphabetical order to get the longest matches first)
1489 my @local_dlls=();
1490 my @local_depends=();
1491 my @exe_list=();
1492 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1493 # Create the target...
1494 my $target=[];
1495 target_init($target);
1496 @$target[$T_NAME]=$target_name;
1497 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
1498 if ($target_name =~ /\.dll$/) {
1499 @$target[$T_TYPE]=$TT_DLL;
1500 push @local_depends,"$target_name.so";
1501 push @local_dlls,$target_name;
1502 my $canon=canonize($target_name);
1503 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1504 } else {
1505 @$target[$T_TYPE]=$opt_target_type;
1506 push @exe_list,$target;
1507 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
1509 my $basename=$target_name;
1510 $basename=~ s/\.(dll|exe)$//i;
1511 # This is the default link list of Visual Studio
1512 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1513 my @std_libraries=qw(uuid);
1514 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1515 @$target[$T_DLLS]=\@std_imports;
1516 @$target[$T_LIBRARIES]=\@std_libraries;
1517 } else {
1518 @$target[$T_DLLS]=[];
1519 @$target[$T_LIBRARIES]=[];
1521 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1522 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
1523 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1524 push @{@$target[$T_LDFLAGS]},"-m$opt_arch";
1527 push @{@$project[$P_TARGETS]},$target;
1529 # Ask for target-specific options
1530 if ($opt_ask_target_options == $OPT_ASK_YES) {
1531 my $flag_desc="";
1532 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
1533 $flag_desc=" (mfc";
1535 if ($flag_desc ne "") {
1536 $flag_desc.=")";
1538 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1539 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1540 while (1) {
1541 my $options=<STDIN>;
1542 chomp $options;
1543 if ($options eq "never") {
1544 $opt_ask_target_options=$OPT_ASK_NO;
1545 last;
1546 } elsif (source_set_options($target,$options)) {
1547 last;
1549 print "Please re-enter the options:\n";
1552 if (@$target[$T_FLAGS] & $TF_MFC) {
1553 @$project_settings[$T_FLAGS]|=$TF_MFC;
1554 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1555 push @{@$target[$T_DLLS]},"mfc.dll";
1556 # FIXME: Link with the MFC in the Unix sense, until we
1557 # start exporting the functions properly.
1558 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1559 push @{@$target[$T_LIBRARIES]},"mfc";
1562 # Match sources...
1563 if ($target_count == 1) {
1564 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1565 @$project_settings[$T_SOURCES_C]=[];
1566 @sources_c=();
1568 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1569 @$project_settings[$T_SOURCES_CXX]=[];
1570 @sources_cxx=();
1572 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1573 @$project_settings[$T_SOURCES_RC]=[];
1574 @sources_rc=();
1576 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1577 # No need for sorting these sources
1578 @$project_settings[$T_SOURCES_MISC]=[];
1579 @sources_misc=();
1580 } else {
1581 foreach my $source (@sources_c) {
1582 if ($source =~ /^$basename/i) {
1583 push @{@$target[$T_SOURCES_C]},$source;
1584 $source="";
1587 foreach my $source (@sources_cxx) {
1588 if ($source =~ /^$basename/i) {
1589 push @{@$target[$T_SOURCES_CXX]},$source;
1590 $source="";
1593 foreach my $source (@sources_rc) {
1594 if ($source =~ /^$basename/i) {
1595 push @{@$target[$T_SOURCES_RC]},$source;
1596 $source="";
1599 foreach my $source (@sources_misc) {
1600 if ($source =~ /^$basename/i) {
1601 push @{@$target[$T_SOURCES_MISC]},$source;
1602 $source="";
1606 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1607 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1608 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1609 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1611 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1612 $opt_ask_target_options=$OPT_ASK_YES;
1615 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1616 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1617 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1618 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1619 push @{@$project_settings[$T_CEXTRA]},"-m$opt_arch";
1620 push @{@$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1624 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1625 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1627 # The sources that did not match, if any, go to the extra
1628 # source list of the project settings
1629 foreach my $source (@sources_c) {
1630 if ($source ne "") {
1631 push @{@$project_settings[$T_SOURCES_C]},$source;
1634 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1635 foreach my $source (@sources_cxx) {
1636 if ($source ne "") {
1637 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1640 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1641 foreach my $source (@sources_rc) {
1642 if ($source ne "") {
1643 push @{@$project_settings[$T_SOURCES_RC]},$source;
1646 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1647 foreach my $source (@sources_misc) {
1648 if ($source ne "") {
1649 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1652 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1654 # Finally if we are building both libraries and programs in
1655 # this directory, then the programs should be linked with all
1656 # the libraries
1657 if (@local_dlls > 0 and @exe_list > 0) {
1658 foreach my $target (@exe_list) {
1659 push @{@$target[$T_DLL_PATH]},"-L.";
1660 push @{@$target[$T_DLLS]},@local_dlls;
1666 # Scan the source directories in search of things to build
1667 sub source_scan()
1669 # If there's a single target then this is going to be the default target
1670 if (defined $opt_single_target) {
1671 # Create the main target
1672 my $main_target=[];
1673 target_init($main_target);
1674 @$main_target[$T_NAME]=$opt_single_target;
1675 @$main_target[$T_TYPE]=$opt_target_type;
1677 # Add it to the list
1678 push @{$main_project[$P_TARGETS]},$main_target;
1681 # The main directory is always going to be there
1682 push @projects,\@main_project;
1684 if (defined $opt_work_dir) {
1685 # Now scan the directory tree looking for source files and, maybe, targets
1686 print "Scanning the source directories...\n";
1687 source_scan_directory(\@main_project,"","",0);
1688 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1689 } elsif (defined $opt_work_file) {
1690 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1691 source_scan_project_file(\@main_project,0,$opt_work_file);
1692 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1693 source_scan_workspace_file($opt_work_file);
1698 #####
1700 # Source search
1702 #####
1705 # Performs a directory traversal and renames the files so that:
1706 # - they have the case desired by the user
1707 # - their extension is of the appropriate case
1708 # - they don't contain annoying characters like ' ', '$', '#', ...
1709 # But only perform these changes for source files and directories.
1710 sub fix_file_and_directory_names($);
1711 sub fix_file_and_directory_names($)
1713 my $dirname=$_[0];
1715 my $directory=get_directory_contents($dirname);
1716 foreach my $dentry (@$directory)
1718 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1719 next;
1721 # Set $warn to 1 if the user should be warned of the renaming
1722 my $warn;
1723 my $new_name=$dentry;
1725 if (-f "$dirname/$dentry")
1727 # Don't rename Winemaker's makefiles
1728 next if ($dentry eq "Makefile" and
1729 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker/);
1731 # Leave non-source files alone
1732 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc))$/i);
1734 # Only all lowercase extensions are supported (because of
1735 # rules like '.c.o:'.
1736 $new_name =~ s/\.C$/.c/;
1737 $new_name =~ s/\.cpp$/.cpp/i;
1738 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1739 $new_name =~ s/\.rc$/.rc/i;
1740 # And this last one is to avoid confusion then running make
1741 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1744 # Adjust the case to the user's preferences
1745 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1746 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1748 $new_name=lc $new_name;
1751 # autoconf and make don't support these characters well
1752 $new_name =~ s/[ \$]/_/g;
1754 # And finally, perform the renaming
1755 if ($new_name ne $dentry)
1757 if ($warn) {
1758 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1760 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1761 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1762 print STDERR " $!\n";
1763 $new_name=$dentry;
1765 else
1767 clear_directory_cache($dirname);
1770 if (-d "$dirname/$new_name") {
1771 fix_file_and_directory_names("$dirname/$new_name");
1778 #####
1780 # Source fixup
1782 #####
1785 # Try to find a file for the specified filename. The attempt is
1786 # case-insensitive which is why it's not trivial. If a match is
1787 # found then we return the pathname with the correct case.
1788 sub search_from($$)
1790 my $dirname=$_[0];
1791 my $path=$_[1];
1792 my $real_path="";
1794 if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
1795 $dirname=cwd;
1796 } elsif ($dirname !~ m+^/+) {
1797 $dirname=cwd . "/" . $dirname;
1799 if ($dirname !~ m+/$+) {
1800 $dirname.="/";
1803 foreach my $component (@$path) {
1804 $component=~s/^\"//;
1805 $component=~s/\"$//;
1806 #print " looking for $component in \"$dirname\"\n";
1807 if ($component eq ".") {
1808 # Pass it as is
1809 $real_path.="./";
1810 } elsif ($component eq "..") {
1811 # Go up one level
1812 $dirname=dirname($dirname) . "/";
1813 $real_path.="../";
1814 } else {
1815 # The file/directory may have been renamed before. Also try to
1816 # match the renamed file.
1817 my $renamed=$component;
1818 $renamed =~ s/[ \$]/_/g;
1819 if ($renamed eq $component) {
1820 undef $renamed;
1823 my $directory=get_directory_contents $dirname;
1824 my $found;
1825 foreach my $dentry (@$directory) {
1826 if ($dentry =~ /^\Q$component\E$/i or
1827 (defined $renamed and $dentry =~ /^$renamed$/i)
1829 $dirname.="$dentry/";
1830 $real_path.="$dentry/";
1831 $found=1;
1832 last;
1835 if (!defined $found) {
1836 # Give up
1837 #print " could not find $component in $dirname\n";
1838 return;
1842 $real_path=~ s+/$++;
1843 #print " -> found $real_path\n";
1844 return $real_path;
1848 # Performs a case-insensitive search for the specified file in the
1849 # include path.
1850 # $line is the line number that should be referenced when an error occurs
1851 # $filename is the file we are looking for
1852 # $dirname is the directory of the file containing the '#include' directive
1853 # if '"' was used, it is an empty string otherwise
1854 # $project and $target specify part of the include path
1855 sub get_real_include_name($$$$$)
1857 my $line=$_[0];
1858 my $filename=$_[1];
1859 my $dirname=$_[2];
1860 my $project=$_[3];
1861 my $target=$_[4];
1863 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1864 # This is not a relative path, we cannot make any check
1865 my $warning="path:$filename";
1866 if (!defined $warnings{$warning}) {
1867 $warnings{$warning}="1";
1868 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1869 print STDERR "$line: $filename\n";
1871 } else {
1872 # Here's how we proceed:
1873 # - split the filename we look for into its components
1874 # - then for each directory in the include path
1875 # - trace the directory components starting from that directory
1876 # - if we fail to find a match at any point then continue with
1877 # the next directory in the include path
1878 # - otherwise, rejoice, our quest is over.
1879 my @file_components=split /[\/\\]+/, $filename;
1880 #print " Searching for $filename from @$project[$P_PATH]\n";
1882 my $real_filename;
1883 if ($dirname ne "") {
1884 # This is an 'include ""' -> look in dirname first.
1885 #print " in $dirname (include \"\")\n";
1886 $real_filename=search_from($dirname,\@file_components);
1887 if (defined $real_filename) {
1888 return $real_filename;
1891 my $project_settings=@$project[$P_SETTINGS];
1892 foreach my $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1893 my $dirname=$include;
1894 $dirname=~ s+^-I++;
1895 $dirname=~ s+\s$++;
1896 if (!is_absolute($dirname)) {
1897 $dirname="@$project[$P_PATH]$dirname";
1898 } else {
1899 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1900 $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
1902 #print " in $dirname\n";
1903 $real_filename=search_from("$dirname",\@file_components);
1904 if (defined $real_filename) {
1905 return $real_filename;
1908 my $dotdotpath=@$project[$P_PATH];
1909 $dotdotpath =~ s/[^\/]+/../g;
1910 foreach my $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1911 my $dirname=$include;
1912 $dirname=~ s+^-I++;
1913 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1914 $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
1915 #print " in $dirname (global setting)\n";
1916 $real_filename=search_from("$dirname",\@file_components);
1917 if (defined $real_filename) {
1918 return $real_filename;
1922 $filename =~ s+\\\\+/+g; # in include ""
1923 $filename =~ s+\\+/+g; # in include <> !
1924 if ($opt_lower_include) {
1925 return lc "$filename";
1927 return $filename;
1930 sub print_pack($$$)
1932 my $indent=$_[0];
1933 my $size=$_[1];
1934 my $trailer=$_[2];
1936 if ($size =~ /^(1|2|4|8)$/) {
1937 print FILEO "$indent#include <pshpack$size.h>$trailer";
1938 } else {
1939 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1940 print FILEO "$indent#include <pshpack4.h>$trailer";
1945 # 'Parses' a source file and fixes constructs that would not work with
1946 # Winelib. The parsing is rather simple and not all non-portable features
1947 # are corrected. The most important feature that is corrected is the case
1948 # and path separator of '#include' directives. This requires that each
1949 # source file be associated to a project & target so that the proper
1950 # include path is used.
1951 # Also note that the include path is relative to the directory in which the
1952 # compiler is run, i.e. that of the project, not to that of the file.
1953 sub fix_file($$$)
1955 my $filename=$_[0];
1956 my $project=$_[1];
1957 my $target=$_[2];
1958 $filename="@$project[$P_PATH]$filename";
1959 if (! -e $filename) {
1960 return;
1963 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1964 my $dirname=dirname($filename);
1965 my $is_mfc=0;
1966 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1967 $is_mfc=1;
1970 print " $filename\n";
1971 #FIXME:assuming that because there is a .bak file, this is what we want is
1972 #probably flawed. Or is it???
1973 if (! -e "$filename.bak") {
1974 if (!copy("$filename","$filename.bak")) {
1975 print STDERR "error: unable to make a backup of $filename:\n";
1976 print STDERR " $!\n";
1977 return;
1980 if (!open(FILEI,"$filename.bak")) {
1981 print STDERR "error: unable to open $filename.bak for reading:\n";
1982 print STDERR " $!\n";
1983 return;
1985 if (!open(FILEO,">$filename")) {
1986 print STDERR "error: unable to open $filename for writing:\n";
1987 print STDERR " $!\n";
1988 return;
1990 my $line=0;
1991 my $modified=0;
1992 my $rc_block_depth=0;
1993 my $rc_textinclude_state=0;
1994 my @pack_stack;
1995 while (<FILEI>) {
1996 # Remove any trailing CtrlZ, which isn't strictly in the file
1997 if (/\x1A/) {
1998 s/\x1A//;
1999 last if (/^$/)
2001 $line++;
2002 s/\r\n$/\n/;
2003 if (!/\n$/) {
2004 # Make sure all files are '\n' terminated
2005 $_ .= "\n";
2007 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
2008 # VC6 automatically includes 'afxres.h', an MFC specific header, in
2009 # the RC files it generates (even in non-MFC projects). So we replace
2010 # it with 'winresrc.h' its very close standard cousin so that non MFC
2011 # projects can compile in Wine without the MFC sources.
2012 my $warning="mfc:afxres.h";
2013 if (!defined $warnings{$warning}) {
2014 $warnings{$warning}="1";
2015 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
2016 print STDERR "warning: the above warning is issued only once\n";
2018 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
2019 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
2020 print FILEO "$1$2\"winresrc.h\"$'";
2021 $modified=1;
2023 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
2024 my $from_file=($2 eq "<"?"":$dirname);
2025 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2026 print FILEO "$1$2$real_include_name$4$'";
2027 $modified|=($real_include_name ne $3);
2029 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
2030 # Pragma pack handling
2032 # pack_stack is an array of references describing the stack of
2033 # pack directives currently in effect. Each directive if described
2034 # by a reference to an array containing:
2035 # - "push" for pack(push,...) directives, "" otherwise
2036 # - the directive's identifier at index 1
2037 # - the directive's alignment value at index 2
2039 # Don't believe a word of what the documentation says: it's all wrong.
2040 # The code below is based on the actual behavior of Visual C/C++ 6.
2041 my $pack_indent=$1;
2042 my $pack_header=$2;
2043 if (/^(\))/) {
2044 # pragma pack()
2045 # Pushes the default stack alignment
2046 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2047 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2048 print_pack($pack_indent,4,$');
2049 push @pack_stack, [ "", "", 4 ];
2051 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
2052 # pragma pack(pop)
2053 # pragma pack(pop,n)
2054 # Goes up the stack until it finds a pack(push,...), and pops it
2055 # Ignores any pack(n) entry
2056 # Issues a warning if the pack is of the form pack(push,label)
2057 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2058 my $pack_comment=$';
2059 $pack_comment =~ s/^\s*//;
2060 if ($pack_comment ne "") {
2061 print FILEO "$pack_indent$pack_comment";
2063 while (1) {
2064 my $alignment=pop @pack_stack;
2065 if (!defined $alignment) {
2066 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2067 last;
2069 if (@$alignment[1]) {
2070 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2072 print FILEO "$pack_indent#include <poppack.h>\n";
2073 if (@$alignment[0]) {
2074 last;
2078 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2079 # pragma pack(pop,label[,n])
2080 # Goes up the stack until finding a pack(push,...) and pops it.
2081 # 'n', if specified, is ignored.
2082 # Ignores any pack(n) entry
2083 # Issues a warning if the label of the pack does not match,
2084 # or if it is in fact a pack(push,n)
2085 my $label=$2;
2086 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2087 my $pack_comment=$';
2088 $pack_comment =~ s/^\s*//;
2089 if ($pack_comment ne "") {
2090 print FILEO "$pack_indent$pack_comment";
2092 while (1) {
2093 my $alignment=pop @pack_stack;
2094 if (!defined $alignment) {
2095 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2096 last;
2098 if (@$alignment[1] and @$alignment[1] ne $label) {
2099 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2101 print FILEO "$pack_indent#include <poppack.h>\n";
2102 if (@$alignment[0]) {
2103 last;
2107 } elsif (/^(push\s*\))/) {
2108 # pragma pack(push)
2109 # Push the current alignment
2110 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2111 if (@pack_stack > 0) {
2112 my $alignment=$pack_stack[$#pack_stack];
2113 print_pack($pack_indent,@$alignment[2],$');
2114 push @pack_stack, [ "push", "", @$alignment[2] ];
2115 } else {
2116 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2117 print_pack($pack_indent,4,$');
2118 push @pack_stack, [ "push", "", 4 ];
2121 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2122 # pragma pack([push,]n)
2123 # Push new alignment n
2124 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2125 print_pack($pack_indent,$3,"$'");
2126 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2128 } elsif (/^((\w+)\s*\))/) {
2129 # pragma pack(label)
2130 # label must in fact be a macro that resolves to an integer
2131 # Then behaves like 'pragma pack(n)'
2132 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2133 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2134 print_pack($pack_indent,4,$');
2135 push @pack_stack, [ "", "", 4 ];
2137 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2138 # pragma pack(push,label[,n])
2139 # Pushes a new label on the stack. It is possible to push the same
2140 # label multiple times. If 'n' is omitted then the alignment is
2141 # unchanged. Otherwise it becomes 'n'.
2142 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2143 my $size;
2144 if (defined $4) {
2145 $size=$4;
2146 } elsif (@pack_stack > 0) {
2147 my $alignment=$pack_stack[$#pack_stack];
2148 $size=@$alignment[2];
2149 } else {
2150 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2151 $size=4;
2153 print_pack($pack_indent,$size,$');
2154 push @pack_stack, [ "push", $2, $size ];
2156 } else {
2157 # pragma pack(??? -> What's that?
2158 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2159 print FILEO "$pack_indent$pack_header$_";
2162 $modified=1;
2164 } elsif ($is_rc) {
2165 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]+)([\">]?)/) {
2166 my $from_file=($5 eq "<"?"":$dirname);
2167 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2168 print FILEO "$1$5$real_include_name$7$'";
2169 $modified|=($real_include_name ne $6);
2171 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2172 my $from_file=($2 eq "<"?"":$dirname);
2173 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2174 print FILEO "$1$2$real_include_name$4$'";
2175 $modified|=($real_include_name ne $3);
2177 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2178 $rc_textinclude_state=1;
2179 print FILEO;
2181 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2182 print FILEO "$1winresrc.h$2$'";
2183 $modified=1;
2185 } elsif (/^\s*BEGIN(\W.*)?$/) {
2186 $rc_textinclude_state|=2;
2187 $rc_block_depth++;
2188 print FILEO;
2190 } elsif (/^\s*END(\W.*)?$/) {
2191 $rc_textinclude_state=0;
2192 if ($rc_block_depth>0) {
2193 $rc_block_depth--;
2195 print FILEO;
2197 } else {
2198 print FILEO;
2201 } else {
2202 print FILEO;
2206 close(FILEI);
2207 close(FILEO);
2208 if ($opt_backup == 0 or $modified == 0) {
2209 if (!unlink("$filename.bak")) {
2210 print STDERR "error: unable to delete $filename.bak:\n";
2211 print STDERR " $!\n";
2217 # Analyzes each source file in turn to find and correct issues
2218 # that would cause it not to compile.
2219 sub fix_source()
2221 print "Fixing the source files...\n";
2222 foreach my $project (@projects) {
2223 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2224 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2225 fix_file($source,$project,$target);
2233 #####
2235 # File generation
2237 #####
2240 # A convenience function to generate all the lists (defines,
2241 # C sources, C++ source, etc.) in the Makefile
2242 sub generate_list($$$;$)
2244 my $name=$_[0];
2245 my $last=$_[1];
2246 my $list=$_[2];
2247 my $data=$_[3];
2248 my $first=$name;
2250 if ($name) {
2251 printf FILEO "%-22s=",$name;
2253 if (defined $list) {
2254 foreach my $item (@$list) {
2255 my $value;
2256 if (defined $data) {
2257 $value=&$data($item);
2258 } else {
2259 if (defined $item) {
2260 $value=$item;
2261 } else {
2262 $value="";
2265 if ($value ne "") {
2266 if ($first) {
2267 print FILEO " $value";
2268 $first=0;
2269 } else {
2270 print FILEO " \\\n\t\t\t$value";
2275 if ($last) {
2276 print FILEO "\n";
2281 # Generates a project's Makefile and all the target files
2282 sub generate_project_files($)
2284 my $project=$_[0];
2285 my $project_settings=@$project[$P_SETTINGS];
2286 my @dll_list=();
2287 my @exe_list=();
2289 # Then sort the targets and separate the libraries from the programs
2290 foreach my $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
2291 if (@$target[$T_TYPE] == $TT_DLL) {
2292 push @dll_list,$target;
2293 } else {
2294 push @exe_list,$target;
2297 @$project[$P_TARGETS]=[];
2298 push @{@$project[$P_TARGETS]}, @dll_list;
2299 push @{@$project[$P_TARGETS]}, @exe_list;
2301 if (!open(FILEO,">@$project[$P_PATH]Makefile")) {
2302 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2303 print STDERR " $!\n";
2304 return;
2307 print FILEO "### Generated by Winemaker $version\n";
2308 print FILEO "\n\n";
2310 generate_list("SRCDIR",1,[ "." ]);
2311 if (@$project[$P_PATH] eq "") {
2312 # This is the main project. It is also responsible for recursively
2313 # calling the other projects
2314 generate_list("SUBDIRS",1,\@projects,sub
2316 if ($_[0] != \@main_project) {
2317 my $subdir=@{$_[0]}[$P_PATH];
2318 $subdir =~ s+/$++;
2319 return $subdir;
2321 # Eliminating the main project by returning undefined!
2324 if (@{@$project[$P_TARGETS]} > 0) {
2325 generate_list("DLLS",1,\@dll_list,sub
2327 return @{$_[0]}[$T_NAME];
2329 generate_list("EXES",1,\@exe_list,sub
2331 return "@{$_[0]}[$T_NAME]";
2333 print FILEO "\n\n\n";
2335 print FILEO "### Common settings\n\n";
2336 # Make it so that the project-wide settings override the global settings
2337 generate_list("CEXTRA",1,@$project_settings[$T_CEXTRA]);
2338 generate_list("CXXEXTRA",1,@$project_settings[$T_CXXEXTRA]);
2339 generate_list("RCEXTRA",1,@$project_settings[$T_RCEXTRA]);
2340 generate_list("DEFINES",1,@$project_settings[$T_DEFINES]);
2341 generate_list("INCLUDE_PATH",1,@$project_settings[$T_INCLUDE_PATH]);
2342 generate_list("DLL_PATH",1,@$project_settings[$T_DLL_PATH]);
2343 generate_list("DLL_IMPORTS",1,@$project_settings[$T_DLLS]);
2344 generate_list("LIBRARY_PATH",1,@$project_settings[$T_LIBRARY_PATH]);
2345 generate_list("LIBRARIES",1,@$project_settings[$T_LIBRARIES]);
2346 print FILEO "\n\n";
2348 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
2349 @{@$project_settings[$T_SOURCES_CXX]}+
2350 @{@$project_settings[$T_SOURCES_RC]};
2351 my $no_extra=($extra_source_count == 0);
2352 if (!$no_extra) {
2353 print FILEO "### Extra source lists\n\n";
2354 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
2355 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
2356 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
2357 print FILEO "\n";
2358 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
2359 print FILEO "\n\n\n";
2362 # Iterate over all the targets...
2363 foreach my $target (@{@$project[$P_TARGETS]}) {
2364 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
2365 my $canon=canonize("@$target[$T_NAME]");
2366 $canon =~ s+_so$++;
2368 generate_list("${canon}_MODULE",1,[@$target[$T_NAME]]);
2369 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
2370 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
2371 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
2372 generate_list("${canon}_LDFLAGS",1,@$target[$T_LDFLAGS]);
2373 generate_list("${canon}_DLL_PATH",1,@$target[$T_DLL_PATH]);
2374 generate_list("${canon}_DLLS",1,@$target[$T_DLLS]);
2375 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]);
2376 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]);
2377 print FILEO "\n";
2378 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2379 print FILEO "\n\n\n";
2381 print FILEO "### Global source lists\n\n";
2382 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
2384 my $canon=canonize(@{$_[0]}[$T_NAME]);
2385 $canon =~ s+_so$++;
2386 return "\$(${canon}_C_SRCS)";
2388 if (!$no_extra) {
2389 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
2391 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
2393 my $canon=canonize(@{$_[0]}[$T_NAME]);
2394 $canon =~ s+_so$++;
2395 return "\$(${canon}_CXX_SRCS)";
2397 if (!$no_extra) {
2398 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2400 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
2402 my $canon=canonize(@{$_[0]}[$T_NAME]);
2403 $canon =~ s+_so$++;
2404 return "\$(${canon}_RC_SRCS)";
2406 if (!$no_extra) {
2407 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2410 print FILEO "\n\n";
2411 print FILEO "### Tools\n\n";
2412 print FILEO "CC = winegcc\n";
2413 print FILEO "CXX = wineg++\n";
2414 print FILEO "RC = wrc\n";
2415 print FILEO "\n\n";
2417 print FILEO "### Generic targets\n\n";
2418 print FILEO "all:";
2419 if (@$project[$P_PATH] eq "") {
2420 print FILEO " \$(SUBDIRS)";
2422 if (@{@$project[$P_TARGETS]} > 0) {
2423 print FILEO " \$(DLLS:%=%.so) \$(EXES:%=%.so)";
2425 print FILEO "\n\n";
2426 print FILEO "### Build rules\n";
2427 print FILEO "\n";
2428 print FILEO ".PHONY: all clean dummy\n";
2429 print FILEO "\n";
2430 print FILEO "\$(SUBDIRS): dummy\n";
2431 print FILEO "\t\@cd \$\@ && \$(MAKE)\n";
2432 print FILEO "\n";
2433 print FILEO "# Implicit rules\n";
2434 print FILEO "\n";
2435 print FILEO ".SUFFIXES: .cpp .rc .res\n";
2436 print FILEO "DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2437 print FILEO "\n";
2438 print FILEO ".c.o:\n";
2439 print FILEO "\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2440 print FILEO "\n";
2441 print FILEO ".cpp.o:\n";
2442 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2443 print FILEO "\n";
2444 print FILEO ".cxx.o:\n";
2445 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2446 print FILEO "\n";
2447 print FILEO ".rc.res:\n";
2448 print FILEO "\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2449 print FILEO "\n";
2450 print FILEO "# Rules for cleaning\n";
2451 print FILEO "\n";
2452 print FILEO "CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2453 print FILEO " \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2454 print FILEO "\n";
2455 print FILEO "clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2456 print FILEO "\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:.cpp=.o)\n";
2457 print FILEO "\t\$(RM) \$(DLLS:%=%.so) \$(EXES:%=%.so) \$(EXES:%.exe=%)\n";
2458 print FILEO "\n";
2459 print FILEO "\$(SUBDIRS:%=%/__clean__): dummy\n";
2460 print FILEO "\tcd `dirname \$\@` && \$(MAKE) clean\n";
2461 print FILEO "\n";
2462 print FILEO "\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2463 print FILEO "\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2464 print FILEO "\n";
2466 if (@{@$project[$P_TARGETS]} > 0) {
2467 print FILEO "### Target specific build rules\n";
2468 print FILEO "DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2469 foreach my $target (@{@$project[$P_TARGETS]}) {
2470 my $canon=canonize("@$target[$T_NAME]");
2471 $canon =~ s/_so$//;
2473 if (@$target[$T_TYPE] == $TT_DLL) {
2474 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.spec)\n";
2475 } else {
2476 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS)\n";
2478 if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
2479 print FILEO "\t\$(CXX)";
2480 } else {
2481 print FILEO "\t\$(CC)";
2483 print FILEO " \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2484 print FILEO "\n\n";
2487 close(FILEO);
2493 # This is where we finally generate files. In fact this method does not
2494 # do anything itself but calls the methods that do the actual work.
2495 sub generate()
2497 print "Generating project files...\n";
2499 foreach my $project (@projects) {
2500 my $path=@$project[$P_PATH];
2501 if ($path eq "") {
2502 $path=".";
2503 } else {
2504 $path =~ s+/$++;
2506 print " $path\n";
2507 generate_project_files($project);
2513 #####
2515 # Option defaults
2517 #####
2519 $opt_backup=1;
2520 $opt_lower=$OPT_LOWER_UPPERCASE;
2521 $opt_lower_include=1;
2523 $opt_work_dir=undef;
2524 $opt_single_target=undef;
2525 $opt_target_type=$TT_GUIEXE;
2526 $opt_flags=0;
2527 $opt_arch=$OPT_ARCH_DEFAULT;
2528 $opt_is_interactive=$OPT_ASK_NO;
2529 $opt_ask_project_options=$OPT_ASK_NO;
2530 $opt_ask_target_options=$OPT_ASK_NO;
2531 $opt_no_generated_files=0;
2532 $opt_no_source_fix=0;
2533 $opt_no_banner=0;
2537 #####
2539 # Main
2541 #####
2543 sub print_banner()
2545 print "Winemaker $version\n";
2546 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2547 print "Copyright 2004 Dimitrie O. Paun\n";
2548 print "Copyright 2009 André Hentschel\n";
2551 sub usage()
2553 print_banner();
2554 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2555 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2556 print STDERR " [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2557 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2558 print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2559 print STDERR " [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2560 print STDERR " [--generated-files|--nogenerated-files]\n";
2561 print STDERR " [--wine32]\n";
2562 print STDERR " work_directory|project_file|workspace_file\n";
2563 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2564 print STDERR "the specified directory or project-file, so that they can be compiled with Winelib.\n";
2565 print STDERR "During this process it will modify and rename some of the corresponding files.\n";
2566 print STDERR "\tPlease read the manual page before use.\n";
2567 exit (2);
2570 target_init(\@global_settings);
2572 while (@ARGV>0) {
2573 my $arg=shift @ARGV;
2574 # General options
2575 if ($arg eq "--nobanner") {
2576 $opt_no_banner=1;
2577 } elsif ($arg eq "--backup") {
2578 $opt_backup=1;
2579 } elsif ($arg eq "--nobackup") {
2580 $opt_backup=0;
2581 } elsif ($arg eq "--single-target") {
2582 $opt_single_target=shift @ARGV;
2583 } elsif ($arg eq "--lower-none") {
2584 $opt_lower=$OPT_LOWER_NONE;
2585 } elsif ($arg eq "--lower-all") {
2586 $opt_lower=$OPT_LOWER_ALL;
2587 } elsif ($arg eq "--lower-uppercase") {
2588 $opt_lower=$OPT_LOWER_UPPERCASE;
2589 } elsif ($arg eq "--lower-include") {
2590 $opt_lower_include=1;
2591 } elsif ($arg eq "--nolower-include") {
2592 $opt_lower_include=0;
2593 } elsif ($arg eq "--nosource-fix") {
2594 $opt_no_source_fix=1;
2595 } elsif ($arg eq "--generated-files") {
2596 $opt_no_generated_files=0;
2597 } elsif ($arg eq "--nogenerated-files") {
2598 $opt_no_generated_files=1;
2599 } elsif ($arg eq "--wine32") {
2600 $opt_arch=$OPT_ARCH_32;
2601 } elsif ($arg =~ /^-D/) {
2602 push @{$global_settings[$T_DEFINES]},$arg;
2603 } elsif ($arg =~ /^-I/) {
2604 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2605 } elsif ($arg =~ /^-P/) {
2606 push @{$global_settings[$T_DLL_PATH]},"-L$'";
2607 } elsif ($arg =~ /^-i/) {
2608 push @{$global_settings[$T_DLLS]},$';
2609 } elsif ($arg =~ /^-L/) {
2610 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2611 } elsif ($arg =~ /^-l/) {
2612 push @{$global_settings[$T_LIBRARIES]},$';
2614 # 'Source'-based method options
2615 } elsif ($arg eq "--dll") {
2616 $opt_target_type=$TT_DLL;
2617 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2618 $opt_target_type=$TT_GUIEXE;
2619 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2620 $opt_target_type=$TT_CUIEXE;
2621 } elsif ($arg eq "--interactive") {
2622 $opt_is_interactive=$OPT_ASK_YES;
2623 $opt_ask_project_options=$OPT_ASK_YES;
2624 $opt_ask_target_options=$OPT_ASK_YES;
2625 } elsif ($arg eq "--mfc") {
2626 $opt_flags|=$TF_MFC;
2627 } elsif ($arg eq "--nomfc") {
2628 $opt_flags&=~$TF_MFC;
2629 $opt_flags|=$TF_NOMFC;
2630 } elsif ($arg eq "--nodlls") {
2631 $opt_flags|=$TF_NODLLS;
2632 } elsif ($arg eq "--nomsvcrt") {
2633 $opt_flags|=$TF_NOMSVCRT;
2635 # Catch errors
2636 } else {
2637 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2638 if (!defined $opt_work_dir and !defined $opt_work_file) {
2639 if (-f $arg) {
2640 $opt_work_file=$arg;
2642 else {
2643 $opt_work_dir=$arg;
2645 } else {
2646 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2647 usage();
2649 } else {
2650 usage();
2655 if (!defined $opt_work_dir and !defined $opt_work_file) {
2656 print STDERR "error: you must specify the directory or project file containing the sources to be converted\n";
2657 usage();
2658 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2659 print STDERR "error: could not chdir to the work directory\n";
2660 print STDERR " $!\n";
2661 usage();
2664 if ($opt_no_banner == 0) {
2665 print_banner();
2668 project_init(\@main_project, "", \@global_settings);
2670 # Fix the file and directory names
2671 fix_file_and_directory_names(".");
2673 # Scan the sources to identify the projects and targets
2674 source_scan();
2676 # Fix the source files
2677 if (! $opt_no_source_fix) {
2678 fix_source();
2681 # Generate the Makefile and the spec file
2682 if (! $opt_no_generated_files) {
2683 generate();