4 # Copyright 2000-2004 Francois Gouget for CodeWeavers
5 # Copyright 2004 Dimitrie O. Paun
6 # Copyright 2009-2011 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
37 # The following constants define what we do with the case of filenames
40 # Never rename a file to lowercase
44 # Rename all files to lowercase
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)
63 # Skip the questions till the end of this scope
67 # The following constants define the architecture
70 # Default Architecture will be chosen
71 my $OPT_ARCH_DEFAULT=0;
85 # This is the directory in which winemaker will operate.
89 # This is the file in which winemaker will operate if a project file is specified.
93 # Make a backup of the files
97 # Defines which files to rename
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
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.
127 # Contains the default set of flags to be used when creating a new target.
131 # Contains 32 for 32-Bit-Targets and 64 for 64-Bit-Targets
135 # If true then winemaker should ask questions to the user as it goes
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.
153 # Target modelization
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.
165 # Defines the type of target we want to build. See the TT_xxx
170 # This is a bitfield containing flags refining the way the target
171 # should be handled. See the TF_xxx constants below
175 # This is a reference to an array containing the list of the
176 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
180 my $T_SOURCES_MISC=6;
183 # This is a reference to an array containing the list of
188 # This is a reference to an array containing the list of
189 # C++ compiler options
193 # This is a reference to an array containing the list of
194 # RC compiler options
198 # This is a reference to an array containing the list of macro
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
212 # Flags for the archiver
216 # Same as T_INCLUDE_PATH but for the dll search path
220 # The list of Windows dlls to import
224 # Same as T_INCLUDE_PATH but for the library search path
225 my $T_LIBRARY_PATH=16;
228 # The list of Unix libraries to link with
232 # The following constants define the recognized types of target
235 # This is not a real target. This type of target is used to collect
236 # the sources that don't seem to belong to any other target. Thus no
237 # real target is generated for them, we just put the sources of the
238 # fake target in the global source list.
242 # For executables in the windows subsystem
246 # For executables in the console subsystem
250 # For dynamically linked libraries
254 # For static libraries
258 # The following constants further refine how the target should be handled
261 # This target is an MFC-based target
265 # User has specified --nomfc option for this target or globally
269 # --nodlls option: Do not use standard DLL set
273 # --nomsvcrt option: Do not link with msvcrt
277 # This target has a def file (only use it with TT_DLL)
281 # This target has C++ files named *.cxx (instead of *.cpp)
285 # Initialize a target:
286 # - set the target type to TT_SETTINGS, i.e. no real target will
292 @$target[$T_TYPE]=$TT_SETTINGS;
293 @$target[$T_FLAGS]=$opt_flags;
294 @$target[$T_SOURCES_C]=[];
295 @$target[$T_SOURCES_CXX]=[];
296 @$target[$T_SOURCES_RC]=[];
297 @$target[$T_SOURCES_MISC]=[];
298 @$target[$T_CEXTRA]=[];
299 @$target[$T_CXXEXTRA]=[];
300 @$target[$T_RCEXTRA]=[];
301 @$target[$T_DEFINES]=[];
302 @$target[$T_INCLUDE_PATH]=[];
303 @$target[$T_LDFLAGS]=[];
304 @$target[$T_ARFLAGS]=[];
305 @$target[$T_DLL_PATH]=[];
306 @$target[$T_DLLS]=[];
307 @$target[$T_LIBRARY_PATH]=[];
308 @$target[$T_LIBRARIES]=[];
315 # Project modelization
319 # First we have the notion of project. A project is described by an
320 # array (since we don't have structs in perl). The constants below
321 # identify what is stored at each index of the array.
324 # This is the path in which this project is located. In other
325 # words, this is the path to the Makefile.
329 # This index contains a reference to an array containing the project-wide
330 # settings. The structure of that arrray is actually identical to that of
331 # a regular target since it can also contain extra sources.
335 # This index contains a reference to an array of targets for this
336 # project. Each target describes how an executable or library is to
337 # be built. For each target this description takes the same form as
338 # that of the project: an array. So this entry is an array of arrays.
342 # Initialize a project:
343 # - set the project's path
344 # - initialize the target list
345 # - create a default target (will be removed later if unnecessary)
346 sub project_init($$$)
348 my ($project, $path, $global_settings)=@_;
350 my $project_settings=[];
351 target_init($project_settings);
352 @$project_settings[$T_DEFINES]=[@{@$global_settings[$T_DEFINES]}];
353 @$project_settings[$T_INCLUDE_PATH]=[@{@$global_settings[$T_INCLUDE_PATH]}];
354 @$project_settings[$T_DLL_PATH]=[@{@$global_settings[$T_DLL_PATH]}];
355 @$project_settings[$T_DLLS]=[@{@$global_settings[$T_DLLS]}];
356 @$project_settings[$T_LIBRARY_PATH]=[@{@$global_settings[$T_LIBRARY_PATH]}];
357 @$project_settings[$T_LIBRARIES]=[@{@$global_settings[$T_LIBRARIES]}];
359 @$project[$P_PATH]=$path;
360 @$project[$P_SETTINGS]=$project_settings;
361 @$project[$P_TARGETS]=[];
377 # This maps a directory name to a reference to an array listing
378 # its contents (files and directories)
382 # Contains the list of all projects. This list tells us what are
383 # the subprojects of the main Makefile and where we have to generate
388 # This is the main project, i.e. the one in the "." directory.
389 # It may well be empty in which case the main Makefile will only
390 # call out subprojects.
394 # Contains the defaults for the include path, etc.
395 # We store the defaults as if this were a target except that we only
396 # exploit the defines, include path, library path, library list and misc
409 # Cleans up a name to make it an acceptable Makefile
415 $name =~ tr/a-zA-Z0-9_/_/c;
420 # Returns true is the specified pathname is absolute.
421 # Note: pathnames that start with a variable '$' or
422 # '~' are considered absolute.
427 return ($path =~ /^[\/~\$]/);
431 # Retrieves the contents of the specified directory.
432 # We either get it from the directories hashtable which acts as a
433 # cache, or use opendir, readdir, closedir and store the result
435 sub get_directory_contents($)
440 #print "getting the contents of $dirname\n";
442 # check for a cached version
444 if ($dirname eq "") {
447 $directory=$directories{$dirname};
448 if (defined $directory) {
449 #print "->@$directory\n";
453 # Read this directory
454 if (opendir(DIRECTORY, "$dirname")) {
455 my @files=readdir DIRECTORY;
459 # Return an empty list
460 #print "error: cannot open $dirname\n";
464 #print "->@$directory\n";
465 $directories{$dirname}=$directory;
470 # Removes a directory from the cache.
471 # This is needed if one of its files or subdirectory has been renamed.
472 sub clear_directory_cache($)
475 delete $directories{$dirname};
481 # 'Source'-based Project analysis
486 # Allows the user to specify makefile and target specific options
487 # - target: the structure in which to store the results
488 # - options: the string containing the options
489 sub source_set_options($$)
494 #FIXME: we must deal with escaping of stuff and all
495 foreach my $option (split / /,$options) {
496 if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
497 push @{@$target[$T_DEFINES]},$option;
498 } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
499 push @{@$target[$T_INCLUDE_PATH]},$option;
500 } elsif ($option =~ /^-P/) {
501 push @{@$target[$T_DLL_PATH]},"-L$'";
502 } elsif ($option =~ /^-i/) {
503 push @{@$target[$T_DLLS]},"$'";
504 } elsif ($option =~ /^-L/) {
505 push @{@$target[$T_LIBRARY_PATH]},$option;
506 } elsif ($option =~ /^-l/) {
507 push @{@$target[$T_LIBRARIES]},"$'";
508 } elsif ($option =~ /^--mfc/) {
509 @$target[$T_FLAGS]|=$TF_MFC;
510 @$target[$T_FLAGS]&=~$TF_NOMFC;
511 } elsif ($option =~ /^--nomfc/) {
512 @$target[$T_FLAGS]&=~$TF_MFC;
513 @$target[$T_FLAGS]|=$TF_NOMFC;
514 } elsif ($option =~ /^--nodlls/) {
515 @$target[$T_FLAGS]|=$TF_NODLLS;
516 } elsif ($option =~ /^--nomsvcrt/) {
517 @$target[$T_FLAGS]|=$TF_NOMSVCRT;
519 print STDERR "error: unknown option \"$option\"\n";
527 # Scans the specified project file to:
528 # - get a list of targets for this project
529 # - get some settings
530 # - get the list of source files
531 sub source_scan_project_file($$$);
532 sub source_scan_project_file($$$)
534 # a reference to the parent's project
535 my $parent_project=$_[0];
536 # 0 if it is a single project, 1 if it is part of a workspace
537 my $is_sub_project=$_[1];
538 # the name of the project file, with complete path, or without if in
542 # reference to the project for this file. May not be used
544 # list of sources found in the current file
550 my $path=dirname($filename);
551 my $prj_target_cflags;
552 my $prj_target_defines;
553 my $prj_target_ldflags;
558 my $prj_target_type=$TT_GUIEXE;
559 my @prj_target_options;
561 if (!($path=~/\/$/)) {
565 if (defined $opt_single_target or $is_sub_project == 0) {
566 # Either there is a single target and thus a single project,
567 # or we are a single project-file for which a project
569 $project=$parent_project;
572 project_init($project, $path, \@global_settings);
574 my $project_settings=@$project[$P_SETTINGS];
576 if ($filename =~ /.dsp$/i) {
577 # First find out what this project file contains:
578 # collect all sources, find targets and settings
579 if (!open(FILEI,$filename)) {
580 print STDERR "error: unable to open $filename for reading:\n";
581 print STDERR " $!\n";
586 # Remove any trailing CtrlZ, which isn't strictly in the file
592 # Remove any trailing CrLf
595 # Make sure all lines are '\n' terminated
599 if (/^\# Microsoft Developer Studio Project File - Name=\"([^\"]+)/) {
601 $prj_name=~s/\s+/_/g;
604 } elsif (/^# TARGTYPE/) {
605 if (/[[:space:]]0+x0*101$/) {
607 $prj_target_type=$TT_GUIEXE;
608 }elsif (/[[:space:]]0+x0*102$/) {
609 # Dynamic-Link Library
610 $prj_target_type=$TT_DLL;
611 }elsif (/[[:space:]]0+x0*103$/) {
612 # Console Application
613 $prj_target_type=$TT_CUIEXE;
614 }elsif (/[[:space:]]0+x0*104$/) {
616 $prj_target_type=$TT_LIB;
619 } elsif (/^# ADD CPP(.*)/ && $found_cfg==1) {
620 $prj_target_cflags=$1;
621 @prj_target_options=split(/\s+\//, $prj_target_cflags);
622 $prj_target_cflags="";
623 foreach ( @prj_target_options ) {
627 # Suppress Startup Banner and Information Messages
629 # Turns off all warning messages
630 $prj_target_cflags.="-w ";
631 } elsif (/^W[123]$/) {
633 $prj_target_cflags.="-W ";
636 $prj_target_cflags.="-Wall ";
639 $prj_target_cflags.="-Werror ";
641 # Enable Minimal Rebuild
643 # Enable Exception Handling
644 $prj_target_cflags.="-fexceptions ";
646 # use cdecl calling convention (default)
648 # use fastcall calling convention
650 # use stdcall calling convention
651 $prj_target_cflags.="-mrtd ";
652 } elsif (/^Z[d7iI]$/) {
654 $prj_target_cflags.="-g ";
656 # Disable Optimizations
657 $prj_target_cflags.="-O0 ";
660 $prj_target_cflags.="-Os ";
663 $prj_target_cflags.="-O2 ";
665 # Disables inline Expansion
666 $prj_target_cflags.="-fno-inline ";
668 #In-line Function Expansion
669 $prj_target_cflags.="-finline-functions ";
671 # auto In-line Function Expansion
672 $prj_target_cflags.="-finline-functions ";
674 # Use maximum optimization
675 $prj_target_cflags.="-O3 ";
677 # Frame-Pointer Omission
678 $prj_target_cflags.="-fomit-frame-pointer ";
680 # Frame-Pointer Omission
681 $prj_target_cflags.="-fno-omit-frame-pointer ";
683 # Catch Release-Build Errors in Debug Build
684 } elsif (/^M[DLT]d?$/) {
685 # Use Multithreaded Run-Time Library
686 } elsif (/^D\s*\"(.*)\"/) {
687 # Preprocessor Definitions
688 $prj_target_defines.="-D".$1." ";
689 } elsif (/^I\s*\"(.*)\"/) {
690 # Additional Include Directories
693 if ($sfilet=~/^\w:/) {
694 print STDERR "warning: Can't fix path $sfilet\n"
696 push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$sfilet." ";
698 } elsif (/^U\s*\"(.*)\"/) {
699 # Undefines a previously defined symbol
700 $prj_target_cflags.="-U".$1." ";
706 # Automatic Use of Precompiled Headers
708 # Generate File Dependencies
710 # Compile Without Linking
711 # this option is always present and is already specified in the suffix rules
714 $prj_target_cflags.="-D_M_IX86=500 ";
716 # Pentium Pro Optimization
717 $prj_target_cflags.="-D_M_IX86=600 ";
719 # Pentium Optimization
720 $prj_target_cflags.="-D_M_IX86=500 ";
723 $prj_target_cflags.="-D_M_IX86=300 ";
726 $prj_target_cflags.="-D_M_IX86=400 ";
728 # Create Precompiled Header
730 # Use Precompiled Header
732 # Disable Language Extensions
733 $prj_target_cflags.="-ansi ";
735 # Enable Microsoft Extensions
736 } elsif (/^Zm[[:digit:]]+$/) {
737 # Specify Memory Allocation Limit
739 # Packs structures on 1-byte boundaries
740 $prj_target_cflags.="-fpack-struct ";
741 } elsif (/^Zp(2|4|8|16)$/) {
742 # Struct Member Alignment
743 $prj_target_cflags.="-fpack-struct=".$1;
745 print "C compiler option $_ not implemented\n";
749 #print "\nOptions: $prj_target_cflags\n";
751 } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
752 $prj_target_ldflags=$1;
753 @prj_target_options=split(/\s+\//, $prj_target_ldflags);
754 $prj_target_ldflags="";
755 $prj_target_libs=$prj_target_options[0];
756 $prj_target_libs=~s/\\/\//g;
757 $prj_target_libs=~s/\.lib//g;
758 $prj_target_libs=~s/\s+/ -l/g;
759 shift (@prj_target_options);
760 foreach ( @prj_target_options ) {
763 } elsif (/^base:(.*)/) {
765 $prj_target_ldflags.="--image-base ".$1." ";
766 } elsif (/^debug$/) {
767 # Generate Debug Info
770 $prj_target_type=$TT_DLL;
771 } elsif (/^incremental:[[:alpha:]]+$/) {
773 } elsif (/^implib:/) {
774 # Name import library
775 } elsif (/^libpath:\"(.*)\"/) {
777 push @{@$project_settings[$T_DLL_PATH]},"-L$1";
778 } elsif (/^machine:[[:alnum:]]+$/) {
779 # Specify Target Platform
783 $prj_target_ldflags.="-Map ".$1." ";
785 $prj_target_ldflags.="-Map ".$prj_name.".map ";
787 } elsif (/^nologo$/) {
788 # Suppress Startup Banner and Information Messages
791 # may use it as Target?
792 } elsif (/^pdbtype:/) {
793 # Program Database Storage
794 } elsif (/^subsystem:/) {
796 } elsif (/^version:[[:digit:].]+$/) {
797 # Version Information
799 print "Linker option $_ not implemented\n";
803 } elsif (/^LIB32=/ && $found_cfg==1) {
806 } elsif (/^SOURCE=(.*)$/) {
807 my @components=split /[\/\\]+/, $1;
808 $sfilet=search_from($path, \@components);
809 if (!defined $sfilet) { next; }
810 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
811 push @sources_c,$sfilet;
812 } elsif ($sfilet =~ /\.cpp$/i) {
813 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
814 push @sources_misc,$sfilet;
815 @$project_settings[$T_FLAGS]|=$TF_MFC;
817 push @sources_cxx,$sfilet;
819 } elsif ($sfilet =~ /\.cxx$/i) {
820 @$project_settings[$T_FLAGS]|=$TF_HASCXX;
821 push @sources_cxx,$sfilet;
822 } elsif ($sfilet =~ /\.rc$/i) {
823 push @sources_rc,$sfilet;
824 } elsif ($sfilet =~ /\.def$/i) {
825 @$project_settings[$T_FLAGS]|=$TF_HASDEF;
826 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
827 push @sources_misc,$sfilet;
828 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
829 @$project_settings[$T_FLAGS]|=$TF_MFC;
834 } elsif (/^# (Begin|End) Source File/) {
835 # Source-Files already handled
837 } elsif (/^# (Begin|End) Group/) {
840 } elsif (/^# (Begin|End) Custom Build/) {
841 # Custom Builds are ignored
843 } elsif (/^# ADD LIB32 /) {
846 } elsif (/^# Begin Target$/) {
847 # Targets are ignored
849 } elsif (/^# End Target$/) {
850 # Targets are ignored
853 if ($found_cfg == 1) {
856 if (/if (.*)\(CFG\)" == "(.*)"/i) {
857 if ($2 eq $prj_cfg) {
862 } elsif (/^CFG=(.*)/i) {
866 else { # Line recognized
872 push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
873 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
874 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
875 push @{@$project_settings[$T_DEFINES]},$prj_target_defines;
876 push @{@$project_settings[$T_LDFLAGS]},$prj_target_ldflags;
877 } elsif ($filename =~ /.vcproj$/i) {
878 # Import XML::LibXML, you need the libxml package (deb: libxml-libxml-perl, rpm: perl-libxml-perl)
881 my $xmlparser = XML::LibXML->new();
882 my $project_xml = $xmlparser->parse_file($filename);
886 foreach my $vc_project ($project_xml->findnodes('/VisualStudioProject')) {
887 foreach my $vc_project_attr ($vc_project->attributes) {
888 if ($vc_project_attr->getName eq "Name") {
889 $prj_name=$vc_project_attr->getValue;
890 $prj_name=~s/\s+/_/g;
896 for (my $flevel = 0; $flevel <= 5; $flevel++) {
897 foreach my $vc_file ($project_xml->findnodes('/VisualStudioProject/Files/'.('Filter/' x $flevel).'File')) {
898 foreach my $vc_file_attr ($vc_file->attributes) {
899 if ($vc_file_attr->getName eq "RelativePath") {
900 $sfilet = $vc_file_attr->getValue;
901 $sfilet=~s/\\\\/\\/g; #remove double backslash
902 $sfilet=~s/^\.\\//; #remove starting 'this directory'
903 $sfilet=~s/\\/\//g; #make slashes out of backslashes
904 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
905 push @sources_c,$sfilet;
906 } elsif ($sfilet =~ /\.cpp$/i) {
907 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
908 push @sources_misc,$sfilet;
909 @$project_settings[$T_FLAGS]|=$TF_MFC;
911 push @sources_cxx,$sfilet;
913 } elsif ($sfilet =~ /\.cxx$/i) {
914 @$project_settings[$T_FLAGS]|=$TF_HASCXX;
915 push @sources_cxx,$sfilet;
916 } elsif ($sfilet =~ /\.rc$/i) {
917 push @sources_rc,$sfilet;
918 } elsif ($sfilet =~ /\.def$/i) {
919 @$project_settings[$T_FLAGS]|=$TF_HASDEF;
920 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
921 push @sources_misc,$sfilet;
922 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
923 @$project_settings[$T_FLAGS]|=$TF_MFC;
931 my @vc_configurations = $project_xml->findnodes('/VisualStudioProject/Configurations/Configuration');
932 my $vc_configuration = $vc_configurations[0];
933 foreach my $vc_configuration_attr ($vc_configuration->attributes) {
934 if ($vc_configuration_attr->getName eq "ConfigurationType") {
935 if ($vc_configuration_attr->getValue==1) {
936 $prj_target_type=$TT_GUIEXE; # Application
937 } elsif ($vc_configuration_attr->getValue==2) {
938 $prj_target_type=$TT_DLL; # Dynamic-Link Library
939 } elsif ($vc_configuration_attr->getValue==4) {
940 $prj_target_type=$TT_LIB; # Static Library
945 foreach my $vc_configuration_tools ($vc_configuration->findnodes('Tool')) {
946 my @find_tool = $vc_configuration_tools->attributes;
947 if ($find_tool[0]->getValue eq "VCCLCompilerTool") {
948 foreach my $vc_compiler_tool ($vc_configuration_tools->attributes) {
949 if ($vc_compiler_tool->getName eq "Optimization") {$prj_target_cflags.="-O".$vc_compiler_tool->getValue." ";}
950 if ($vc_compiler_tool->getName eq "WarningLevel") {
951 if ($vc_compiler_tool->getValue==0) {
952 $prj_target_cflags.="-w ";
953 } elsif ($vc_compiler_tool->getValue<4) {
954 $prj_target_cflags.="-W ";
955 } elsif ($vc_compiler_tool->getValue==4) {
956 $prj_target_cflags.="-Wall ";
957 } elsif ($vc_compiler_tool->getValue eq "X") {
958 $prj_target_cflags.="-Werror ";
961 if ($vc_compiler_tool->getName eq "PreprocessorDefinitions") {
962 $configt=$vc_compiler_tool->getValue;
963 $configt=~s/;\s*/ -D/g;
964 $prj_target_defines.="-D".$configt." ";
966 if ($vc_compiler_tool->getName eq "AdditionalIncludeDirectories") {
967 $configt=$vc_compiler_tool->getValue;
970 push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$configt;
974 if ($find_tool[0]->getValue eq "VCLinkerTool") {
975 foreach my $vc_linker_tool ($vc_configuration_tools->attributes) {
976 if ($vc_linker_tool->getName eq "AdditionalDependencies") {
977 $prj_target_libs=" ".$vc_linker_tool->getValue;
978 $prj_target_libs=~s/\\/\//g;
979 $prj_target_libs=~s/\.lib//g;
980 $prj_target_libs=~s/\s+/ -l/g;
986 push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
987 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
988 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
989 push @{@$project_settings[$T_DEFINES]},$prj_target_defines;
991 print STDERR "File format not supported for file: $filename\n";
995 # Add this project to the project list, except for
996 # the main project which is already in the list.
997 if ($is_sub_project == 1) {
998 push @projects,$project;
1001 # Ask for project-wide options
1002 if ($opt_ask_project_options == $OPT_ASK_YES) {
1004 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1007 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1008 if (defined $flag_desc) {
1009 print "* (currently $flag_desc)\n";
1011 print "* or 'skip' to skip the target specific options,\n";
1012 print "* or 'never' to not be asked this question again:\n";
1014 my $options=<STDIN>;
1016 if ($options eq "skip") {
1017 $opt_ask_target_options=$OPT_ASK_SKIP;
1019 } elsif ($options eq "never") {
1020 $opt_ask_project_options=$OPT_ASK_NO;
1022 } elsif (source_set_options($project_settings,$options)) {
1025 print "Please re-enter the options:\n";
1029 # Create the target...
1031 target_init($target);
1033 if ($prj_target_type==$TT_GUIEXE or $prj_target_type==$TT_CUIEXE) {
1034 $prj_name=lc($prj_name.".exe");
1035 @$target[$T_TYPE]=$opt_target_type;
1036 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
1037 } elsif ($prj_target_type==$TT_LIB) {
1038 $prj_name=lc("lib".$prj_name.".a");
1039 @$target[$T_TYPE]=$TT_LIB;
1040 push @{@$target[$T_ARFLAGS]},("rc");
1042 $prj_name=lc($prj_name.".dll");
1043 @$target[$T_TYPE]=$TT_DLL;
1044 my $canon=canonize($prj_name);
1045 if (@$project_settings[$T_FLAGS] & $TF_HASDEF) {
1046 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.def)");
1048 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1052 @$target[$T_NAME]=$prj_name;
1053 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
1055 # This is the default link list of Visual Studio
1056 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1057 my @std_libraries=qw(uuid);
1058 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1059 @$target[$T_DLLS]=\@std_imports;
1060 @$target[$T_LIBRARIES]=\@std_libraries;
1062 @$target[$T_DLLS]=[];
1063 @$target[$T_LIBRARIES]=[];
1065 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1066 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
1067 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1068 push @{@$target[$T_LDFLAGS]},"-m$opt_arch";
1071 push @{@$project[$P_TARGETS]},$target;
1073 # Ask for target-specific options
1074 if ($opt_ask_target_options == $OPT_ASK_YES) {
1076 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
1079 if ($flag_desc ne "") {
1082 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1083 print "* \"$prj_name\"$flag_desc or 'never' to not be asked this question again:\n";
1085 my $options=<STDIN>;
1087 if ($options eq "never") {
1088 $opt_ask_target_options=$OPT_ASK_NO;
1090 } elsif (source_set_options($target,$options)) {
1093 print "Please re-enter the options:\n";
1096 if (@$target[$T_FLAGS] & $TF_MFC) {
1097 @$project_settings[$T_FLAGS]|=$TF_MFC;
1098 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1099 push @{@$target[$T_DLLS]},"mfc.dll";
1100 # FIXME: Link with the MFC in the Unix sense, until we
1101 # start exporting the functions properly.
1102 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1103 push @{@$target[$T_LIBRARIES]},"mfc";
1107 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1108 @$project_settings[$T_SOURCES_C]=[];
1110 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1111 @$project_settings[$T_SOURCES_CXX]=[];
1113 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1114 @$project_settings[$T_SOURCES_RC]=[];
1116 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1117 @$project_settings[$T_SOURCES_MISC]=[];
1120 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1121 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1122 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1123 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1125 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1126 $opt_ask_target_options=$OPT_ASK_YES;
1129 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1130 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1131 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1132 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1133 push @{@$project_settings[$T_CEXTRA]},"-m$opt_arch";
1134 push @{@$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1138 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1139 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1141 # The sources that did not match, if any, go to the extra
1142 # source list of the project settings
1143 foreach my $source (@sources_c) {
1144 if ($source ne "") {
1145 push @{@$project_settings[$T_SOURCES_C]},$source;
1148 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1149 foreach my $source (@sources_cxx) {
1150 if ($source ne "") {
1151 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1154 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1155 foreach my $source (@sources_rc) {
1156 if ($source ne "") {
1157 push @{@$project_settings[$T_SOURCES_RC]},$source;
1160 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1161 foreach my $source (@sources_misc) {
1162 if ($source ne "") {
1163 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1166 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1170 # Scans the specified workspace file to find the project files
1171 sub source_scan_workspace_file($);
1172 sub source_scan_workspace_file($)
1175 my $path=dirname($filename);
1178 if (! -e $filename) {
1182 if (!open(FILEIWS,$filename)) {
1183 print STDERR "error: unable to open $filename for reading:\n";
1184 print STDERR " $!\n";
1191 if ($filename =~ /.dsw$/i) {
1193 # Remove any trailing CrLf
1196 # catch a project definition
1197 if (/^Project:\s\"(.*)\"=(.*)\s-/) {
1200 @components=split /[\/\\]+/, $prj_path;
1201 $prj_path=search_from($path, \@components);
1202 print "Name: $prj_name\nPath: $prj_path\n";
1203 source_scan_project_file(\@main_project,1,$prj_path);
1207 } elsif (/^Global:/) {
1208 # ignore the Global section
1210 print STDERR "unknown section $_\n";
1211 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1212 print "\nFileversion: $3\n";
1216 } elsif ($filename =~ /.sln$/i) {
1218 # Remove any trailing CrLf
1221 # catch a project definition
1222 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1225 if ($prj_path eq "Solution Items") { next; }
1226 @components=split /[\/\\]+/, $3;
1227 $prj_path=search_from($path, \@components);
1228 print "Name: $prj_name\nPath: $prj_path\n";
1229 source_scan_project_file(\@main_project,1,$prj_path);
1231 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1232 print "\nFileversion: $3\n";
1238 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1242 # Scans the specified directory to:
1243 # - see if we should create a Makefile in this directory. We normally do
1244 # so if we find a project file and sources
1245 # - get a list of targets for this directory
1246 # - get the list of source files
1247 sub source_scan_directory($$$$);
1248 sub source_scan_directory($$$$)
1250 # a reference to the parent's project
1251 my $parent_project=$_[0];
1252 # the full relative path to the current directory, including a
1253 # trailing '/', or an empty string if this is the top level directory
1255 # the name of this directory, including a trailing '/', or an empty
1256 # string if this is the top level directory
1258 # if set then no targets will be looked for and the sources will all
1259 # end up in the parent_project's 'misc' bucket
1260 my $no_target=$_[3];
1262 # reference to the project for this directory. May not be used
1264 # list of targets found in the 'current' directory
1266 # list of sources found in the current directory
1270 my @sources_misc=();
1271 # true if this directory contains a Windows project
1272 my $has_win_project=0;
1273 # true if this directory contains headers
1275 # If we don't find any executable/library then we might make up targets
1276 # from the list of .dsp/.mak files we find since they usually have the
1277 # same name as their target.
1281 if (defined $opt_single_target or $dirname eq "") {
1282 # Either there is a single target and thus a single project,
1283 # or we are in the top level directory for which a project
1285 $project=$parent_project;
1288 project_init($project, $path, \@global_settings);
1290 my $project_settings=@$project[$P_SETTINGS];
1292 # First find out what this directory contains:
1293 # collect all sources, targets and subdirectories
1294 my $directory=get_directory_contents($path);
1295 foreach my $dentry (@$directory) {
1296 if ($dentry =~ /^\./) {
1299 my $fullentry="$path$dentry";
1300 if (-d "$fullentry") {
1301 if ($dentry =~ /^(Release|Debug)/i) {
1302 # These directories are often used to store the object files and the
1303 # resulting executable/library. They should not contain anything else.
1304 my @candidates=grep /\.(exe|dll|lib)$/i, @{get_directory_contents("$fullentry")};
1305 foreach my $candidate (sort @candidates) {
1306 my $dlldup = $candidate;
1307 $dlldup =~ s/\.lib$/.dll/;
1308 if ($candidate =~ /\.lib$/ and $targets{$dlldup})
1310 # Often lib files are created together with dll files, even if the dll file is the
1314 $targets{$candidate}=1;
1316 } elsif ($dentry =~ /^include/i) {
1317 # This directory must contain headers we're going to need
1318 push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1319 source_scan_directory($project,"$fullentry/","$dentry/",1);
1321 # Recursively scan this directory. Any source file that cannot be
1322 # attributed to a project in one of the subdirectories will be
1323 # attributed to this project.
1324 source_scan_directory($project,"$fullentry/","$dentry/",$no_target);
1326 } elsif (-f "$fullentry") {
1327 if ($dentry =~ /\.(exe|dll|lib)$/i) {
1328 $targets{$dentry}=1;
1329 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1330 push @sources_c,"$dentry";
1331 } elsif ($dentry =~ /\.cpp$/i) {
1332 if ($dentry =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1333 push @sources_misc,"$dentry";
1334 @$project_settings[$T_FLAGS]|=$TF_MFC;
1336 push @sources_cxx,"$dentry";
1338 } elsif ($dentry =~ /\.cxx$/i) {
1339 @$project_settings[$T_FLAGS]|=$TF_HASCXX;
1340 push @sources_cxx,"$dentry";
1341 } elsif ($dentry =~ /\.rc$/i) {
1342 push @sources_rc,"$dentry";
1343 } elsif ($dentry =~ /\.def$/i) {
1344 @$project_settings[$T_FLAGS]|=$TF_HASDEF;
1345 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1347 push @sources_misc,"$dentry";
1348 if ($dentry =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1349 @$project_settings[$T_FLAGS]|=$TF_MFC;
1351 } elsif ($dentry =~ /\.(dsp|vcproj)$/i) {
1352 push @prj_files,"$dentry";
1354 } elsif ($dentry =~ /\.mak$/i) {
1355 push @mak_files,"$dentry";
1357 } elsif ($dentry =~ /^makefile/i) {
1364 push @{@$project_settings[$T_INCLUDE_PATH]},"-I.";
1366 # If we have a single target then all we have to do is assign
1367 # all the sources to it and we're done
1368 # FIXME: does this play well with the --interactive mode?
1369 if ($opt_single_target) {
1370 my $target=@{@$project[$P_TARGETS]}[0];
1371 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1372 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1373 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1374 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1378 my $parent_settings=@$parent_project[$P_SETTINGS];
1379 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1380 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1381 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1382 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1383 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1387 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1388 @{@$project_settings[$T_SOURCES_C]}+
1389 @{@$project_settings[$T_SOURCES_CXX]}+
1390 @{@$project_settings[$T_SOURCES_RC]};
1391 if ($source_count == 0) {
1392 # A project without real sources is not a project, get out!
1393 if ($project!=$parent_project) {
1394 my $parent_settings=@$parent_project[$P_SETTINGS];
1395 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1396 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1400 #print "targets=",%targets,"\n";
1401 #print "target_count=$target_count\n";
1402 #print "has_win_project=$has_win_project\n";
1403 #print "dirname=$dirname\n";
1406 if (($has_win_project != 0) or ($dirname eq "")) {
1407 # Deal with cases where we could not find any executable/library, and
1408 # thus have no target, although we did find some sort of windows project.
1409 $target_count=keys %targets;
1410 if ($target_count == 0) {
1411 # Try to come up with a target list based on .dsp/.mak files
1413 if (@prj_files > 0) {
1414 print "Projectfile found! You might want to try using it directly.\n";
1415 $prj_list=\@prj_files;
1417 $prj_list=\@mak_files;
1419 foreach my $filename (@$prj_list) {
1420 $filename =~ s/\.(dsp|vcproj|mak)$//i;
1421 if ($opt_target_type == $TT_DLL) {
1422 $filename = "$filename.dll";
1424 $targets{$filename}=1;
1426 $target_count=keys %targets;
1427 if ($target_count == 0) {
1428 # Still nothing, try the name of the directory
1430 if ($dirname eq "") {
1431 # Bad luck, this is the top level directory!
1432 $name=(split /\//, cwd)[-1];
1435 # Remove the trailing '/'. Also eliminate whatever is after the last
1436 # '.' as it is likely to be meaningless (.orig, .new, ...)
1437 $name =~ s+(/|\.[^.]*)$++;
1438 if ($name eq "src") {
1439 # 'src' is probably a subdirectory of the real project directory.
1440 # Try again with the parent (if any).
1442 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
1445 $name=(split /\//, cwd)[-1];
1449 $name =~ s+(/|\.[^.]*)$++;
1450 if ($opt_target_type == $TT_DLL) {
1451 $name = canonize($name).".dll";
1452 } elsif ($opt_target_type == $TT_LIB) {
1453 $name = "lib".canonize($name).".a";
1455 $name = canonize($name).".exe";
1461 # Ask confirmation to the user if he wishes so
1462 if ($opt_is_interactive == $OPT_ASK_YES) {
1463 my $target_list=join " ",keys %targets;
1464 print "\n*** In ",($path?$path:"./"),"\n";
1465 print "* winemaker found the following list of (potential) targets\n";
1466 print "* $target_list\n";
1467 print "* Type enter to use it as is, your own comma-separated list of\n";
1468 print "* targets, 'none' to assign the source files to a parent directory,\n";
1469 print "* or 'ignore' to ignore everything in this directory tree.\n";
1470 print "* Target list:\n";
1471 $target_list=<STDIN>;
1473 if ($target_list eq "") {
1474 # Keep the target list as is, i.e. do nothing
1475 } elsif ($target_list eq "none") {
1476 # Empty the target list
1478 } elsif ($target_list eq "ignore") {
1479 # Ignore this subtree altogether
1483 foreach my $target (split /,/,$target_list) {
1484 $target =~ s+^\s*++;
1485 $target =~ s+\s*$++;
1486 $targets{$target}=1;
1492 # If we have no project at this level, then transfer all
1493 # the sources to the parent project
1494 $target_count=keys %targets;
1495 if ($target_count == 0) {
1496 if ($project!=$parent_project) {
1497 my $parent_settings=@$parent_project[$P_SETTINGS];
1498 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1499 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1500 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1501 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1502 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1507 # Otherwise add this project to the project list, except for
1508 # the main project which is already in the list.
1509 if ($dirname ne "") {
1510 push @projects,$project;
1513 # Ask for project-wide options
1514 if ($opt_ask_project_options == $OPT_ASK_YES) {
1516 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1519 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1520 if (defined $flag_desc) {
1521 print "* (currently $flag_desc)\n";
1523 print "* or 'skip' to skip the target specific options,\n";
1524 print "* or 'never' to not be asked this question again:\n";
1526 my $options=<STDIN>;
1528 if ($options eq "skip") {
1529 $opt_ask_target_options=$OPT_ASK_SKIP;
1531 } elsif ($options eq "never") {
1532 $opt_ask_project_options=$OPT_ASK_NO;
1534 } elsif (source_set_options($project_settings,$options)) {
1537 print "Please re-enter the options:\n";
1541 # - Create the targets
1542 # - Check if we have both libraries and programs
1543 # - Match each target with source files (sort in reverse
1544 # alphabetical order to get the longest matches first)
1547 my @local_depends=();
1549 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1550 # Create the target...
1552 target_init($target);
1553 @$target[$T_NAME]=$target_name;
1554 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
1555 if ($target_name =~ /\.dll$/) {
1556 @$target[$T_TYPE]=$TT_DLL;
1557 push @local_depends,"$target_name.so";
1558 push @local_dlls,$target_name;
1559 my $canon=canonize($target_name);
1560 if (@$project_settings[$T_FLAGS] & $TF_HASDEF) {
1561 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.def)");
1563 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1565 } elsif ($target_name =~ /\.lib$/) {
1566 $target_name =~ s/(.*)\.lib/lib$1.a/;
1567 @$target[$T_NAME]=$target_name;
1568 @$target[$T_TYPE]=$TT_LIB;
1569 push @local_depends,"$target_name";
1570 push @local_libs,$target_name;
1571 push @{@$target[$T_ARFLAGS]},("rc");
1572 } elsif ($target_name =~ /\.a$/) {
1573 @$target[$T_NAME]=$target_name;
1574 @$target[$T_TYPE]=$TT_LIB;
1575 push @local_depends,"$target_name";
1576 push @local_libs,$target_name;
1577 push @{@$target[$T_ARFLAGS]},("rc");
1579 @$target[$T_TYPE]=$opt_target_type;
1580 push @exe_list,$target;
1581 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
1583 my $basename=$target_name;
1584 $basename=~ s/\.(dll|exe)$//i;
1585 # This is the default link list of Visual Studio
1586 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1587 my @std_libraries=qw(uuid);
1588 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1589 @$target[$T_DLLS]=\@std_imports;
1590 @$target[$T_LIBRARIES]=\@std_libraries;
1592 @$target[$T_DLLS]=[];
1593 @$target[$T_LIBRARIES]=[];
1595 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1596 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
1597 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1598 push @{@$target[$T_LDFLAGS]},"-m$opt_arch";
1601 push @{@$project[$P_TARGETS]},$target;
1603 # Ask for target-specific options
1604 if ($opt_ask_target_options == $OPT_ASK_YES) {
1606 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
1609 if ($flag_desc ne "") {
1612 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1613 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1615 my $options=<STDIN>;
1617 if ($options eq "never") {
1618 $opt_ask_target_options=$OPT_ASK_NO;
1620 } elsif (source_set_options($target,$options)) {
1623 print "Please re-enter the options:\n";
1626 if (@$target[$T_FLAGS] & $TF_MFC) {
1627 @$project_settings[$T_FLAGS]|=$TF_MFC;
1628 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1629 push @{@$target[$T_DLLS]},"mfc.dll";
1630 # FIXME: Link with the MFC in the Unix sense, until we
1631 # start exporting the functions properly.
1632 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1633 push @{@$target[$T_LIBRARIES]},"mfc";
1637 if ($target_count == 1) {
1638 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1639 @$project_settings[$T_SOURCES_C]=[];
1642 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1643 @$project_settings[$T_SOURCES_CXX]=[];
1646 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1647 @$project_settings[$T_SOURCES_RC]=[];
1650 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1651 # No need for sorting these sources
1652 @$project_settings[$T_SOURCES_MISC]=[];
1655 foreach my $source (@sources_c) {
1656 if ($source =~ /^$basename/i) {
1657 push @{@$target[$T_SOURCES_C]},$source;
1661 foreach my $source (@sources_cxx) {
1662 if ($source =~ /^$basename/i) {
1663 push @{@$target[$T_SOURCES_CXX]},$source;
1667 foreach my $source (@sources_rc) {
1668 if ($source =~ /^$basename/i) {
1669 push @{@$target[$T_SOURCES_RC]},$source;
1673 foreach my $source (@sources_misc) {
1674 if ($source =~ /^$basename/i) {
1675 push @{@$target[$T_SOURCES_MISC]},$source;
1680 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1681 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1682 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1683 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1685 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1686 $opt_ask_target_options=$OPT_ASK_YES;
1689 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1690 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1691 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1692 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1693 push @{@$project_settings[$T_CEXTRA]},"-m$opt_arch";
1694 push @{@$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1698 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1699 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1701 # The sources that did not match, if any, go to the extra
1702 # source list of the project settings
1703 foreach my $source (@sources_c) {
1704 if ($source ne "") {
1705 push @{@$project_settings[$T_SOURCES_C]},$source;
1708 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1709 foreach my $source (@sources_cxx) {
1710 if ($source ne "") {
1711 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1714 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1715 foreach my $source (@sources_rc) {
1716 if ($source ne "") {
1717 push @{@$project_settings[$T_SOURCES_RC]},$source;
1720 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1721 foreach my $source (@sources_misc) {
1722 if ($source ne "") {
1723 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1726 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1728 # Finally if we are building both libraries and programs in
1729 # this directory, then the programs should be linked with all
1731 if (@local_dlls > 0 and @exe_list > 0) {
1732 foreach my $target (@exe_list) {
1733 push @{@$target[$T_DLL_PATH]},"-L.";
1734 push @{@$target[$T_DLLS]},@local_dlls;
1737 if (@local_libs > 0 and @exe_list > 0) {
1738 foreach my $target (@exe_list) {
1739 push @{@$target[$T_LIBRARY_PATH]},"-L.";
1740 push @{@$target[$T_LIBRARIES]},@local_libs;
1746 # Scan the source directories in search of things to build
1749 # If there's a single target then this is going to be the default target
1750 if (defined $opt_single_target) {
1751 # Create the main target
1753 target_init($main_target);
1754 @$main_target[$T_NAME]=$opt_single_target;
1755 @$main_target[$T_TYPE]=$opt_target_type;
1757 # Add it to the list
1758 push @{$main_project[$P_TARGETS]},$main_target;
1761 # The main directory is always going to be there
1762 push @projects,\@main_project;
1764 if (defined $opt_work_dir) {
1765 # Now scan the directory tree looking for source files and, maybe, targets
1766 print "Scanning the source directories...\n";
1767 source_scan_directory(\@main_project,"","",0);
1768 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1769 } elsif (defined $opt_work_file) {
1770 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1771 source_scan_project_file(\@main_project,0,$opt_work_file);
1772 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1773 source_scan_workspace_file($opt_work_file);
1785 # Performs a directory traversal and renames the files so that:
1786 # - they have the case desired by the user
1787 # - their extension is of the appropriate case
1788 # - they don't contain annoying characters like ' ', '$', '#', ...
1789 # But only perform these changes for source files and directories.
1790 sub fix_file_and_directory_names($);
1791 sub fix_file_and_directory_names($)
1795 my $directory=get_directory_contents($dirname);
1796 foreach my $dentry (@$directory)
1798 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1801 # Set $warn to 1 if the user should be warned of the renaming
1803 my $new_name=$dentry;
1805 if (-f "$dirname/$dentry")
1807 # Don't rename Winemaker's makefiles
1808 next if ($dentry eq "Makefile" and
1809 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker/);
1811 # Leave non-source files alone
1812 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc|spec|def))$/i);
1814 # Only all lowercase extensions are supported (because of
1815 # rules like '.c.o:').
1816 $new_name =~ s/\.C$/.c/;
1817 $new_name =~ s/\.cpp$/.cpp/i;
1818 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1819 $new_name =~ s/\.rc$/.rc/i;
1820 # And this last one is to avoid confusion when running make
1821 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1824 # Adjust the case to the user's preferences
1825 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1826 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1828 $new_name=lc $new_name;
1831 # make doesn't support these characters well
1832 $new_name =~ s/[ \$]/_/g;
1834 # And finally, perform the renaming
1835 if ($new_name ne $dentry)
1838 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1840 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1841 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1842 print STDERR " $!\n";
1847 clear_directory_cache($dirname);
1850 if (-d "$dirname/$new_name") {
1851 fix_file_and_directory_names("$dirname/$new_name");
1865 # Try to find a file for the specified filename. The attempt is
1866 # case-insensitive which is why it's not trivial. If a match is
1867 # found then we return the pathname with the correct case.
1874 $dirname =~ s/(\.\/)+//;
1875 if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
1877 } elsif ($dirname !~ m+^/+) {
1878 $dirname=cwd . "/" . $dirname;
1880 if ($dirname !~ m+/$+) {
1884 foreach my $component (@$path) {
1885 $component=~s/^\"//;
1886 $component=~s/\"$//;
1887 #print " looking for $component in \"$dirname\"\n";
1888 if ($component eq ".") {
1891 } elsif ($component eq "..") {
1893 if ($dirname =~ /\.\.\/$/) {
1896 $dirname=dirname($dirname) . "/";
1900 # The file/directory may have been renamed before. Also try to
1901 # match the renamed file.
1902 my $renamed=$component;
1903 $renamed =~ s/[ \$]/_/g;
1904 if ($renamed eq $component) {
1908 my $directory=get_directory_contents $dirname;
1910 foreach my $dentry (@$directory) {
1911 if ($dentry =~ /^\Q$component\E$/i or
1912 (defined $renamed and $dentry =~ /^$renamed$/i)
1914 $dirname.="$dentry/";
1915 $real_path.="$dentry/";
1920 if (!defined $found) {
1922 #print " could not find $component in $dirname\n";
1927 $real_path=~ s+/$++;
1928 #print " -> found $real_path\n";
1933 # Performs a case-insensitive search for the specified file in the
1935 # $line is the line number that should be referenced when an error occurs
1936 # $filename is the file we are looking for
1937 # $dirname is the directory of the file containing the '#include' directive
1938 # if '"' was used, it is an empty string otherwise
1939 # $project and $target specify part of the include path
1940 sub get_real_include_name($$$$$)
1948 if ($filename =~ /^([a-zA-Z]:)?[\/\\]/ or $filename =~ /^[a-zA-Z]:[\/\\]?/) {
1949 # This is not a relative path, we cannot make any check
1950 my $warning="path:$filename";
1951 if (!defined $warnings{$warning}) {
1952 $warnings{$warning}="1";
1953 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1954 print STDERR "$line: $filename\n";
1957 # Here's how we proceed:
1958 # - split the filename we look for into its components
1959 # - then for each directory in the include path
1960 # - trace the directory components starting from that directory
1961 # - if we fail to find a match at any point then continue with
1962 # the next directory in the include path
1963 # - otherwise, rejoice, our quest is over.
1964 my @file_components=split /[\/\\]+/, $filename;
1965 #print " Searching for $filename from @$project[$P_PATH]\n";
1968 if ($dirname ne "") {
1969 # This is an 'include ""' -> look in dirname first.
1970 #print " in $dirname (include \"\")\n";
1971 $real_filename=search_from($dirname,\@file_components);
1972 if (defined $real_filename) {
1973 return $real_filename;
1976 my $project_settings=@$project[$P_SETTINGS];
1977 foreach my $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1978 my $dirname=$include;
1981 if (!is_absolute($dirname)) {
1982 $dirname="@$project[$P_PATH]$dirname";
1984 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1985 $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
1987 #print " in $dirname\n";
1988 $real_filename=search_from("$dirname",\@file_components);
1989 if (defined $real_filename) {
1990 return $real_filename;
1993 my $dotdotpath=@$project[$P_PATH];
1994 $dotdotpath =~ s/[^\/]+/../g;
1995 foreach my $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1996 my $dirname=$include;
1998 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1999 $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
2000 #print " in $dirname (global setting)\n";
2001 $real_filename=search_from("$dirname",\@file_components);
2002 if (defined $real_filename) {
2003 return $real_filename;
2007 $filename =~ s+\\\\+/+g; # in include ""
2008 $filename =~ s+\\+/+g; # in include <> !
2009 if ($opt_lower_include) {
2010 return lc "$filename";
2021 if ($size =~ /^(1|2|4|8)$/) {
2022 print FILEO "$indent#include <pshpack$size.h>$trailer";
2024 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
2025 print FILEO "$indent#include <pshpack4.h>$trailer";
2030 # 'Parses' a source file and fixes constructs that would not work with
2031 # Winelib. The parsing is rather simple and not all non-portable features
2032 # are corrected. The most important feature that is corrected is the case
2033 # and path separator of '#include' directives. This requires that each
2034 # source file be associated to a project & target so that the proper
2035 # include path is used.
2036 # Also note that the include path is relative to the directory in which the
2037 # compiler is run, i.e. that of the project, not to that of the file.
2043 $filename="@$project[$P_PATH]$filename";
2044 if (! -e $filename) {
2048 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
2049 my $dirname=dirname($filename);
2051 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
2055 print " $filename\n";
2056 if (! -e "$filename.bak") {
2057 if (!copy("$filename","$filename.bak")) {
2058 print STDERR "error: unable to make a backup of $filename:\n";
2059 print STDERR " $!\n";
2063 if (!open(FILEI,"$filename.bak")) {
2064 print STDERR "error: unable to open $filename.bak for reading:\n";
2065 print STDERR " $!\n";
2068 if (!open(FILEO,">$filename")) {
2069 print STDERR "error: unable to open $filename for writing:\n";
2070 print STDERR " $!\n";
2075 my $rc_block_depth=0;
2076 my $rc_textinclude_state=0;
2079 # Remove any trailing CtrlZ, which isn't strictly in the file
2087 # Make sure all files are '\n' terminated
2090 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
2091 # VC6 automatically includes 'afxres.h', an MFC specific header, in
2092 # the RC files it generates (even in non-MFC projects). So we replace
2093 # it with 'winresrc.h' its very close standard cousin so that non MFC
2094 # projects can compile in Wine without the MFC sources.
2095 my $warning="mfc:afxres.h";
2096 if (!defined $warnings{$warning}) {
2097 $warnings{$warning}="1";
2098 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
2099 print STDERR "warning: the above warning is issued only once\n";
2101 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
2102 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
2103 print FILEO "$1$2\"winresrc.h\"$'";
2106 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
2107 my $from_file=($2 eq "<"?"":$dirname);
2108 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2109 print FILEO "$1$2$real_include_name$4$'";
2110 $modified|=($real_include_name ne $3);
2112 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
2113 # Pragma pack handling
2115 # pack_stack is an array of references describing the stack of
2116 # pack directives currently in effect. Each directive if described
2117 # by a reference to an array containing:
2118 # - "push" for pack(push,...) directives, "" otherwise
2119 # - the directive's identifier at index 1
2120 # - the directive's alignment value at index 2
2122 # Don't believe a word of what the documentation says: it's all wrong.
2123 # The code below is based on the actual behavior of Visual C/C++ 6.
2128 # Pushes the default stack alignment
2129 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2130 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2131 print_pack($pack_indent,4,$');
2132 push @pack_stack, [ "", "", 4 ];
2134 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
2136 # pragma pack(pop,n)
2137 # Goes up the stack until it finds a pack(push,...), and pops it
2138 # Ignores any pack(n) entry
2139 # Issues a warning if the pack is of the form pack(push,label)
2140 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2141 my $pack_comment=$';
2142 $pack_comment =~ s/^\s*//;
2143 if ($pack_comment ne "") {
2144 print FILEO "$pack_indent$pack_comment";
2147 my $alignment=pop @pack_stack;
2148 if (!defined $alignment) {
2149 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2152 if (@$alignment[1]) {
2153 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2155 print FILEO "$pack_indent#include <poppack.h>\n";
2156 if (@$alignment[0]) {
2161 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2162 # pragma pack(pop,label[,n])
2163 # Goes up the stack until finding a pack(push,...) and pops it.
2164 # 'n', if specified, is ignored.
2165 # Ignores any pack(n) entry
2166 # Issues a warning if the label of the pack does not match,
2167 # or if it is in fact a pack(push,n)
2169 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2170 my $pack_comment=$';
2171 $pack_comment =~ s/^\s*//;
2172 if ($pack_comment ne "") {
2173 print FILEO "$pack_indent$pack_comment";
2176 my $alignment=pop @pack_stack;
2177 if (!defined $alignment) {
2178 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2181 if (@$alignment[1] and @$alignment[1] ne $label) {
2182 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2184 print FILEO "$pack_indent#include <poppack.h>\n";
2185 if (@$alignment[0]) {
2190 } elsif (/^(push\s*\))/) {
2192 # Push the current alignment
2193 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2194 if (@pack_stack > 0) {
2195 my $alignment=$pack_stack[$#pack_stack];
2196 print_pack($pack_indent,@$alignment[2],$');
2197 push @pack_stack, [ "push", "", @$alignment[2] ];
2199 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2200 print_pack($pack_indent,4,$');
2201 push @pack_stack, [ "push", "", 4 ];
2204 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2205 # pragma pack([push,]n)
2206 # Push new alignment n
2207 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2208 print_pack($pack_indent,$3,"$'");
2209 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2211 } elsif (/^((\w+)\s*\))/) {
2212 # pragma pack(label)
2213 # label must in fact be a macro that resolves to an integer
2214 # Then behaves like 'pragma pack(n)'
2215 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2216 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2217 print_pack($pack_indent,4,$');
2218 push @pack_stack, [ "", "", 4 ];
2220 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2221 # pragma pack(push,label[,n])
2222 # Pushes a new label on the stack. It is possible to push the same
2223 # label multiple times. If 'n' is omitted then the alignment is
2224 # unchanged. Otherwise it becomes 'n'.
2225 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2229 } elsif (@pack_stack > 0) {
2230 my $alignment=$pack_stack[$#pack_stack];
2231 $size=@$alignment[2];
2233 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2236 print_pack($pack_indent,$size,$');
2237 push @pack_stack, [ "push", $2, $size ];
2240 # pragma pack(??? -> What's that?
2241 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2242 print FILEO "$pack_indent$pack_header$_";
2248 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]+)([\">]?)/) {
2249 my $from_file=($5 eq "<"?"":$dirname);
2250 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2251 print FILEO "$1$5$real_include_name$7$'";
2252 $modified|=($real_include_name ne $6);
2254 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2255 my $from_file=($2 eq "<"?"":$dirname);
2256 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2257 print FILEO "$1$2$real_include_name$4$'";
2258 $modified|=($real_include_name ne $3);
2260 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2261 $rc_textinclude_state=1;
2264 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2265 print FILEO "$1winresrc.h$2$'";
2268 } elsif (/^\s*BEGIN(\W.*)?$/) {
2269 $rc_textinclude_state|=2;
2273 } elsif (/^\s*END(\W.*)?$/) {
2274 $rc_textinclude_state=0;
2275 if ($rc_block_depth>0) {
2291 if ($opt_backup == 0 or $modified == 0) {
2292 if (!unlink("$filename.bak")) {
2293 print STDERR "error: unable to delete $filename.bak:\n";
2294 print STDERR " $!\n";
2300 # Analyzes each source file in turn to find and correct issues
2301 # that would cause it not to compile.
2304 print "Fixing the source files...\n";
2305 foreach my $project (@projects) {
2306 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2307 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2308 fix_file($source,$project,$target);
2323 # A convenience function to generate all the lists (defines,
2324 # C sources, C++ source, etc.) in the Makefile
2325 sub generate_list($$$;$)
2334 printf FILEO "%-22s=",$name;
2336 if (defined $list) {
2337 foreach my $item (@$list) {
2339 if (defined $data) {
2340 $value=&$data($item);
2342 if (defined $item) {
2350 print FILEO " $value";
2353 print FILEO " \\\n\t\t\t$value";
2364 # Generates a project's Makefile and all the target files
2365 sub generate_project_files($)
2368 my $project_settings=@$project[$P_SETTINGS];
2373 # Then sort the targets and separate the libraries from the programs
2374 foreach my $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
2375 if (@$target[$T_TYPE] == $TT_DLL) {
2376 push @dll_list,$target;
2377 } elsif (@$target[$T_TYPE] == $TT_LIB) {
2378 push @lib_list,$target;
2380 push @exe_list,$target;
2383 @$project[$P_TARGETS]=[];
2384 push @{@$project[$P_TARGETS]}, @dll_list;
2385 push @{@$project[$P_TARGETS]}, @lib_list;
2386 push @{@$project[$P_TARGETS]}, @exe_list;
2388 if (!open(FILEO,">@$project[$P_PATH]Makefile")) {
2389 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2390 print STDERR " $!\n";
2395 if (@$project_settings[$T_FLAGS] & $TF_HASCXX) {
2396 $cpp_to_object=".cxx=.o";
2398 $cpp_to_object=".cpp=.o";
2401 print FILEO "### Generated by Winemaker $version\n";
2402 print FILEO "###\n";
2403 print FILEO "### Invocation command line was\n";
2404 print FILEO "### $0";
2408 print FILEO "\n\n\n";
2410 generate_list("SRCDIR",1,[ "." ]);
2411 if (@$project[$P_PATH] eq "") {
2412 # This is the main project. It is also responsible for recursively
2413 # calling the other projects
2414 generate_list("SUBDIRS",1,\@projects,sub
2416 if ($_[0] != \@main_project) {
2417 my $subdir=@{$_[0]}[$P_PATH];
2421 # Eliminating the main project by returning undefined!
2424 if (@{@$project[$P_TARGETS]} > 0) {
2425 generate_list("DLLS",1,\@dll_list,sub
2427 return @{$_[0]}[$T_NAME];
2429 generate_list("LIBS",1,\@lib_list,sub
2431 return @{$_[0]}[$T_NAME];
2433 generate_list("EXES",1,\@exe_list,sub
2435 return "@{$_[0]}[$T_NAME]";
2437 print FILEO "\n\n\n";
2439 print FILEO "### Common settings\n\n";
2440 # Make it so that the project-wide settings override the global settings
2441 generate_list("CEXTRA",1,@$project_settings[$T_CEXTRA]);
2442 generate_list("CXXEXTRA",1,@$project_settings[$T_CXXEXTRA]);
2443 generate_list("RCEXTRA",1,@$project_settings[$T_RCEXTRA]);
2444 generate_list("DEFINES",1,@$project_settings[$T_DEFINES]);
2445 generate_list("INCLUDE_PATH",1,@$project_settings[$T_INCLUDE_PATH]);
2446 generate_list("DLL_PATH",1,@$project_settings[$T_DLL_PATH]);
2447 generate_list("DLL_IMPORTS",1,@$project_settings[$T_DLLS]);
2448 generate_list("LIBRARY_PATH",1,@$project_settings[$T_LIBRARY_PATH]);
2449 generate_list("LIBRARIES",1,@$project_settings[$T_LIBRARIES]);
2452 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
2453 @{@$project_settings[$T_SOURCES_CXX]}+
2454 @{@$project_settings[$T_SOURCES_RC]};
2455 my $no_extra=($extra_source_count == 0);
2457 print FILEO "### Extra source lists\n\n";
2458 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
2459 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
2460 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
2462 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:$cpp_to_object)"]);
2463 print FILEO "\n\n\n";
2466 # Iterate over all the targets...
2467 foreach my $target (@{@$project[$P_TARGETS]}) {
2468 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
2469 my $canon=canonize("@$target[$T_NAME]");
2472 generate_list("${canon}_MODULE",1,[@$target[$T_NAME]]);
2473 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
2474 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
2475 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
2476 generate_list("${canon}_LDFLAGS",1,@$target[$T_LDFLAGS]);
2477 generate_list("${canon}_ARFLAGS",1,@$target[$T_ARFLAGS]);
2478 generate_list("${canon}_DLL_PATH",1,@$target[$T_DLL_PATH]);
2479 generate_list("${canon}_DLLS",1,@$target[$T_DLLS]);
2480 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]);
2481 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]);
2483 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:$cpp_to_object)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2484 print FILEO "\n\n\n";
2486 print FILEO "### Global source lists\n\n";
2487 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
2489 my $canon=canonize(@{$_[0]}[$T_NAME]);
2491 return "\$(${canon}_C_SRCS)";
2494 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
2496 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
2498 my $canon=canonize(@{$_[0]}[$T_NAME]);
2500 return "\$(${canon}_CXX_SRCS)";
2503 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2505 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
2507 my $canon=canonize(@{$_[0]}[$T_NAME]);
2509 return "\$(${canon}_RC_SRCS)";
2512 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2516 print FILEO "### Tools\n\n";
2517 print FILEO "CC = winegcc\n";
2518 print FILEO "CXX = wineg++\n";
2519 print FILEO "RC = wrc\n";
2520 print FILEO "AR = ar\n";
2523 print FILEO "### Generic targets\n\n";
2525 if (@$project[$P_PATH] eq "") {
2526 print FILEO " \$(SUBDIRS)";
2528 if (@{@$project[$P_TARGETS]} > 0) {
2529 print FILEO " \$(DLLS:%=%.so) \$(LIBS) \$(EXES)";
2532 print FILEO "### Build rules\n";
2534 print FILEO ".PHONY: all clean dummy\n";
2536 print FILEO "\$(SUBDIRS): dummy\n";
2537 print FILEO "\t\@cd \$\@ && \$(MAKE)\n";
2539 print FILEO "# Implicit rules\n";
2541 print FILEO ".SUFFIXES: .cpp .cxx .rc .res\n";
2542 print FILEO "DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2544 print FILEO ".c.o:\n";
2545 print FILEO "\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2547 print FILEO ".cpp.o:\n";
2548 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2550 print FILEO ".cxx.o:\n";
2551 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2553 print FILEO ".rc.res:\n";
2554 print FILEO "\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2556 print FILEO "# Rules for cleaning\n";
2558 print FILEO "CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2559 print FILEO " \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2561 print FILEO "clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2562 print FILEO "\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:$cpp_to_object)\n";
2563 print FILEO "\t\$(RM) \$(DLLS:%=%.so) \$(LIBS) \$(EXES) \$(EXES:%=%.so)\n";
2565 print FILEO "\$(SUBDIRS:%=%/__clean__): dummy\n";
2566 print FILEO "\tcd `dirname \$\@` && \$(MAKE) clean\n";
2568 print FILEO "\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2569 print FILEO "\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2572 if (@{@$project[$P_TARGETS]} > 0) {
2573 print FILEO "### Target specific build rules\n";
2574 print FILEO "DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2575 foreach my $target (@{@$project[$P_TARGETS]}) {
2576 my $canon=canonize("@$target[$T_NAME]");
2579 if (@$target[$T_TYPE] == $TT_DLL && (@$project_settings[$T_FLAGS] & $TF_HASDEF)) {
2580 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.def)\n";
2581 } elsif (@$target[$T_TYPE] == $TT_DLL) {
2582 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.spec)\n";
2584 print FILEO "\$(${canon}_MODULE): \$(${canon}_OBJS)\n";
2587 if (@$target[$T_TYPE] == $TT_LIB) {
2588 print FILEO "\t\$(AR) \$(${canon}_ARFLAGS) \$\@ \$(${canon}_OBJS)\n";
2590 if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
2591 print FILEO "\t\$(CXX)";
2593 print FILEO "\t\$(CC)";
2595 print FILEO " \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2606 # This is where we finally generate files. In fact this method does not
2607 # do anything itself but calls the methods that do the actual work.
2610 print "Generating project files...\n";
2612 foreach my $project (@projects) {
2613 my $path=@$project[$P_PATH];
2620 generate_project_files($project);
2633 $opt_lower=$OPT_LOWER_UPPERCASE;
2634 $opt_lower_include=1;
2636 $opt_work_dir=undef;
2637 $opt_single_target=undef;
2638 $opt_target_type=$TT_GUIEXE;
2640 $opt_arch=$OPT_ARCH_DEFAULT;
2641 $opt_is_interactive=$OPT_ASK_NO;
2642 $opt_ask_project_options=$OPT_ASK_NO;
2643 $opt_ask_target_options=$OPT_ASK_NO;
2644 $opt_no_generated_files=0;
2645 $opt_no_source_fix=0;
2658 print "Winemaker $version\n";
2659 print "Copyright 2000-2004 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2660 print "Copyright 2004 Dimitrie O. Paun\n";
2661 print "Copyright 2009-2011 André Hentschel\n";
2667 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2668 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2669 print STDERR " [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2670 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll|--lib]\n";
2671 print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2672 print STDERR " [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2673 print STDERR " [--generated-files|--nogenerated-files]\n";
2674 print STDERR " [--wine32]\n";
2675 print STDERR " work_directory|project_file|workspace_file\n";
2676 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2677 print STDERR "the specified directory or project-file, so that they can be compiled with Winelib.\n";
2678 print STDERR "During this process it will modify and rename some of the corresponding files.\n";
2679 print STDERR "\tPlease read the manual page before use.\n";
2683 target_init(\@global_settings);
2688 if ($arg eq "--nobanner") {
2690 } elsif ($arg eq "--backup") {
2692 } elsif ($arg eq "--nobackup") {
2694 } elsif ($arg eq "--single-target") {
2695 $opt_single_target=shift @ARGV;
2696 } elsif ($arg eq "--lower-none") {
2697 $opt_lower=$OPT_LOWER_NONE;
2698 } elsif ($arg eq "--lower-all") {
2699 $opt_lower=$OPT_LOWER_ALL;
2700 } elsif ($arg eq "--lower-uppercase") {
2701 $opt_lower=$OPT_LOWER_UPPERCASE;
2702 } elsif ($arg eq "--lower-include") {
2703 $opt_lower_include=1;
2704 } elsif ($arg eq "--nolower-include") {
2705 $opt_lower_include=0;
2706 } elsif ($arg eq "--nosource-fix") {
2707 $opt_no_source_fix=1;
2708 } elsif ($arg eq "--generated-files") {
2709 $opt_no_generated_files=0;
2710 } elsif ($arg eq "--nogenerated-files") {
2711 $opt_no_generated_files=1;
2712 } elsif ($arg eq "--wine32") {
2713 $opt_arch=$OPT_ARCH_32;
2714 } elsif ($arg =~ /^-D/) {
2715 push @{$global_settings[$T_DEFINES]},$arg;
2716 } elsif ($arg =~ /^-I/) {
2717 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2718 } elsif ($arg =~ /^-P/) {
2719 push @{$global_settings[$T_DLL_PATH]},"-L$'";
2720 } elsif ($arg =~ /^-i/) {
2721 push @{$global_settings[$T_DLLS]},$';
2722 } elsif ($arg =~ /^-L/) {
2723 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2724 } elsif ($arg =~ /^-l/) {
2725 push @{$global_settings[$T_LIBRARIES]},$arg;
2727 # 'Source'-based method options
2728 } elsif ($arg eq "--dll") {
2729 $opt_target_type=$TT_DLL;
2730 } elsif ($arg eq "--lib") {
2731 $opt_target_type=$TT_LIB;
2732 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2733 $opt_target_type=$TT_GUIEXE;
2734 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2735 $opt_target_type=$TT_CUIEXE;
2736 } elsif ($arg eq "--interactive") {
2737 $opt_is_interactive=$OPT_ASK_YES;
2738 $opt_ask_project_options=$OPT_ASK_YES;
2739 $opt_ask_target_options=$OPT_ASK_YES;
2740 } elsif ($arg eq "--mfc") {
2741 $opt_flags|=$TF_MFC;
2742 } elsif ($arg eq "--nomfc") {
2743 $opt_flags&=~$TF_MFC;
2744 $opt_flags|=$TF_NOMFC;
2745 } elsif ($arg eq "--nodlls") {
2746 $opt_flags|=$TF_NODLLS;
2747 } elsif ($arg eq "--nomsvcrt") {
2748 $opt_flags|=$TF_NOMSVCRT;
2752 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2753 if (!defined $opt_work_dir and !defined $opt_work_file) {
2755 $opt_work_file=$arg;
2761 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2770 if (!defined $opt_work_dir and !defined $opt_work_file) {
2771 print STDERR "error: you must specify the directory or project file containing the sources to be converted\n";
2773 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2774 print STDERR "error: could not chdir to the work directory\n";
2775 print STDERR " $!\n";
2779 if ($opt_no_banner == 0) {
2783 project_init(\@main_project, "", \@global_settings);
2785 # Fix the file and directory names
2786 fix_file_and_directory_names(".");
2788 # Scan the sources to identify the projects and targets
2791 # Fix the source files
2792 if (! $opt_no_source_fix) {
2796 # Generate the Makefile and the spec file
2797 if (! $opt_no_generated_files) {