5 # Copyright 2000-2004 Francois Gouget for CodeWeavers
6 # Copyright 2004 Dimitrie O. Paun
7 # Copyright 2009-2012 André Hentschel
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
38 # The following constants define what we do with the case of filenames
41 # Never rename a file to lowercase
45 # Rename all files to lowercase
49 # Rename only files that are all uppercase to lowercase
50 my $OPT_LOWER_UPPERCASE=2;
53 # The following constants define whether to ask questions or not
56 # No (synonym of never)
64 # Skip the questions till the end of this scope
68 # The following constants define the architecture
71 # Default Architecture will be chosen
72 my $OPT_ARCH_DEFAULT=0;
86 # This is the directory in which winemaker will operate.
90 # This is the file in which winemaker will operate if a project file is specified.
94 # Make a backup of the files
98 # Defines which files to rename
102 # If we don't find the file referenced by an include, lower it
103 my $opt_lower_include;
106 # If true then winemaker should not attempt to fix the source. This is
107 # useful if the source is known to be already in a suitable form and is
109 my $opt_no_source_fix;
111 # Options for the 'Source' method
114 # Specifies that we have only one target so that all sources relate
115 # to this target. By default this variable is left undefined which
116 # means winemaker should try to find out by itself what the targets
117 # are. If not undefined then this contains the name of the default
118 # target (without the extension).
119 my $opt_single_target;
122 # If '$opt_single_target' has been specified then this is the type of
123 # that target. Otherwise it specifies whether the default target type
124 # is guiexe or cuiexe.
128 # Contains the default set of flags to be used when creating a new target.
132 # Contains 32 for 32-Bit-Targets and 64 for 64-Bit-Targets
136 # If true then winemaker should ask questions to the user as it goes
138 my $opt_is_interactive;
139 my $opt_ask_project_options;
140 my $opt_ask_target_options;
143 # If false then winemaker should not generate the makefiles.
144 my $opt_no_generated_files;
147 # Specifies not to print the banner if set.
154 # Target modelization
158 # The description of a target is stored in an array. The constants
159 # below identify what is stored at each index of the array.
162 # This is the name of the target.
166 # Defines the type of target we want to build. See the TT_xxx
171 # This is a bitfield containing flags refining the way the target
172 # should be handled. See the TF_xxx constants below
176 # This is a reference to an array containing the list of the
177 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
181 my $T_SOURCES_MISC=6;
184 # This is a reference to an array containing the list of
189 # This is a reference to an array containing the list of
190 # C++ compiler options
194 # This is a reference to an array containing the list of
195 # RC compiler options
199 # This is a reference to an array containing the list of macro
204 # This is a reference to an array containing the list of directory
205 # names that constitute the include path
206 my $T_INCLUDE_PATH=11;
209 # Flags for the linker
213 # Flags for the archiver
217 # Same as T_INCLUDE_PATH but for the dll search path
221 # The list of Windows dlls to import
225 # Same as T_INCLUDE_PATH but for the library search path
226 my $T_LIBRARY_PATH=16;
229 # The list of Unix libraries to link with
233 # The following constants define the recognized types of target
236 # This is not a real target. This type of target is used to collect
237 # the sources that don't seem to belong to any other target. Thus no
238 # real target is generated for them, we just put the sources of the
239 # fake target in the global source list.
243 # For executables in the windows subsystem
247 # For executables in the console subsystem
251 # For dynamically linked libraries
255 # For static libraries
259 # The following constants further refine how the target should be handled
262 # This target is an MFC-based target
266 # User has specified --nomfc option for this target or globally
270 # --nodlls option: Do not use standard DLL set
274 # --nomsvcrt option: Do not link with msvcrt
278 # This target has a def file (only use it with TT_DLL)
282 # This target has C++ files named *.cxx (instead of *.cpp)
286 # Initialize a target:
287 # - set the target type to TT_SETTINGS, i.e. no real target will
293 @
$target[$T_TYPE]=$TT_SETTINGS;
294 @
$target[$T_FLAGS]=$opt_flags;
295 @
$target[$T_SOURCES_C]=[];
296 @
$target[$T_SOURCES_CXX]=[];
297 @
$target[$T_SOURCES_RC]=[];
298 @
$target[$T_SOURCES_MISC]=[];
299 @
$target[$T_CEXTRA]=[];
300 @
$target[$T_CXXEXTRA]=[];
301 @
$target[$T_RCEXTRA]=[];
302 @
$target[$T_DEFINES]=[];
303 @
$target[$T_INCLUDE_PATH]=[];
304 @
$target[$T_LDFLAGS]=[];
305 @
$target[$T_ARFLAGS]=[];
306 @
$target[$T_DLL_PATH]=[];
307 @
$target[$T_DLLS]=[];
308 @
$target[$T_LIBRARY_PATH]=[];
309 @
$target[$T_LIBRARIES]=[];
316 # Project modelization
320 # First we have the notion of project. A project is described by an
321 # array (since we don't have structs in perl). The constants below
322 # identify what is stored at each index of the array.
325 # This is the path in which this project is located. In other
326 # words, this is the path to the Makefile.
330 # This index contains a reference to an array containing the project-wide
331 # settings. The structure of that arrray is actually identical to that of
332 # a regular target since it can also contain extra sources.
336 # This index contains a reference to an array of targets for this
337 # project. Each target describes how an executable or library is to
338 # be built. For each target this description takes the same form as
339 # that of the project: an array. So this entry is an array of arrays.
343 # Initialize a project:
344 # - set the project's path
345 # - initialize the target list
346 # - create a default target (will be removed later if unnecessary)
347 sub project_init
($$$)
349 my ($project, $path, $global_settings)=@_;
351 my $project_settings=[];
352 target_init
($project_settings);
353 @
$project_settings[$T_DEFINES]=[@
{@
$global_settings[$T_DEFINES]}];
354 @
$project_settings[$T_INCLUDE_PATH]=[@
{@
$global_settings[$T_INCLUDE_PATH]}];
355 @
$project_settings[$T_DLL_PATH]=[@
{@
$global_settings[$T_DLL_PATH]}];
356 @
$project_settings[$T_DLLS]=[@
{@
$global_settings[$T_DLLS]}];
357 @
$project_settings[$T_LIBRARY_PATH]=[@
{@
$global_settings[$T_LIBRARY_PATH]}];
358 @
$project_settings[$T_LIBRARIES]=[@
{@
$global_settings[$T_LIBRARIES]}];
360 @
$project[$P_PATH]=$path;
361 @
$project[$P_SETTINGS]=$project_settings;
362 @
$project[$P_TARGETS]=[];
378 # This maps a directory name to a reference to an array listing
379 # its contents (files and directories)
383 # Contains the list of all projects. This list tells us what are
384 # the subprojects of the main Makefile and where we have to generate
389 # This is the main project, i.e. the one in the "." directory.
390 # It may well be empty in which case the main Makefile will only
391 # call out subprojects.
395 # Contains the defaults for the include path, etc.
396 # We store the defaults as if this were a target except that we only
397 # exploit the defines, include path, library path, library list and misc
410 # Cleans up a name to make it an acceptable Makefile
416 $name =~ tr/a-zA-Z0-9_/_/c;
421 # Returns true is the specified pathname is absolute.
422 # Note: pathnames that start with a variable '$' or
423 # '~' are considered absolute.
428 return ($path =~ /^[\/~\
$]/);
432 # Retrieves the contents of the specified directory.
433 # We either get it from the directories hashtable which acts as a
434 # cache, or use opendir, readdir, closedir and store the result
436 sub get_directory_contents
($)
441 #print "getting the contents of $dirname\n";
443 # check for a cached version
445 if ($dirname eq "") {
448 $directory=$directories{$dirname};
449 if (defined $directory) {
450 #print "->@$directory\n";
454 # Read this directory
455 if (opendir(DIRECTORY
, "$dirname")) {
456 my @files=readdir DIRECTORY
;
460 # Return an empty list
461 #print "error: cannot open $dirname\n";
465 #print "->@$directory\n";
466 $directories{$dirname}=$directory;
471 # Removes a directory from the cache.
472 # This is needed if one of its files or subdirectory has been renamed.
473 sub clear_directory_cache
($)
476 delete $directories{$dirname};
482 # 'Source'-based Project analysis
487 # Allows the user to specify makefile and target specific options
488 # - target: the structure in which to store the results
489 # - options: the string containing the options
490 sub source_set_options
($$)
495 #FIXME: we must deal with escaping of stuff and all
496 foreach my $option (split / /,$options) {
497 if (@
$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
498 push @
{@
$target[$T_DEFINES]},$option;
499 } elsif (@
$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
500 push @
{@
$target[$T_INCLUDE_PATH]},$option;
501 } elsif ($option =~ /^-P/) {
502 push @
{@
$target[$T_DLL_PATH]},"-L$'";
503 } elsif ($option =~ /^-i/) {
504 push @
{@
$target[$T_DLLS]},"$'";
505 } elsif ($option =~ /^-L/) {
506 push @
{@
$target[$T_LIBRARY_PATH]},$option;
507 } elsif ($option =~ /^-l/) {
508 push @
{@
$target[$T_LIBRARIES]},"$'";
509 } elsif ($option =~ /^--mfc/) {
510 @
$target[$T_FLAGS]|=$TF_MFC;
511 @
$target[$T_FLAGS]&=~$TF_NOMFC;
512 } elsif ($option =~ /^--nomfc/) {
513 @
$target[$T_FLAGS]&=~$TF_MFC;
514 @
$target[$T_FLAGS]|=$TF_NOMFC;
515 } elsif ($option =~ /^--nodlls/) {
516 @
$target[$T_FLAGS]|=$TF_NODLLS;
517 } elsif ($option =~ /^--nomsvcrt/) {
518 @
$target[$T_FLAGS]|=$TF_NOMSVCRT;
520 print STDERR
"error: unknown option \"$option\"\n";
528 # Scans the specified project file to:
529 # - get a list of targets for this project
530 # - get some settings
531 # - get the list of source files
532 sub source_scan_project_file
($$$);
533 sub source_scan_project_file
($$$)
535 # a reference to the parent's project
536 my $parent_project=$_[0];
537 # 0 if it is a single project, 1 if it is part of a workspace
538 my $is_sub_project=$_[1];
539 # the name of the project file, with complete path, or without if in
543 # reference to the project for this file. May not be used
545 # list of sources found in the current file
551 my $path=dirname
($filename);
552 my $prj_target_cflags;
553 my $prj_target_defines;
554 my $prj_target_ldflags;
559 my $prj_target_type=$TT_GUIEXE;
560 my @prj_target_options;
562 if (!($path=~/\/$/)) {
566 $project=$parent_project;
567 my $project_settings=@
$project[$P_SETTINGS];
569 if ($filename =~ /.dsp$/i) {
570 # First find out what this project file contains:
571 # collect all sources, find targets and settings
572 if (!open(FILEI
,$filename)) {
573 print STDERR
"error: unable to open $filename for reading:\n";
574 print STDERR
" $!\n";
579 # Remove any trailing CtrlZ, which isn't strictly in the file
585 # Remove any trailing CrLf
588 # Make sure all lines are '\n' terminated
592 if (/^\# Microsoft Developer Studio Project File - Name=\"([^\"]+)/) {
594 $prj_name=~s/\s+/_/g;
597 } elsif (/^# TARGTYPE/) {
598 if (/[[:space:]]0+x0*101$/) {
600 $prj_target_type=$TT_GUIEXE;
601 }elsif (/[[:space:]]0+x0*102$/) {
602 # Dynamic-Link Library
603 $prj_target_type=$TT_DLL;
604 }elsif (/[[:space:]]0+x0*103$/) {
605 # Console Application
606 $prj_target_type=$TT_CUIEXE;
607 }elsif (/[[:space:]]0+x0*104$/) {
609 $prj_target_type=$TT_LIB;
612 } elsif (/^# ADD CPP(.*)/ && $found_cfg==1) {
613 $prj_target_cflags=$1;
614 @prj_target_options=split(/\s+\//, $prj_target_cflags);
615 $prj_target_cflags="";
616 foreach ( @prj_target_options ) {
620 # Suppress Startup Banner and Information Messages
622 # Turns off all warning messages
623 $prj_target_cflags.="-w ";
624 } elsif (/^W[123]$/) {
626 $prj_target_cflags.="-W ";
629 $prj_target_cflags.="-Wall ";
632 $prj_target_cflags.="-Werror ";
634 # Enable Minimal Rebuild
636 # Enable Exception Handling
637 $prj_target_cflags.="-fexceptions ";
639 # use cdecl calling convention (default)
641 # use fastcall calling convention
643 # use stdcall calling convention
644 $prj_target_cflags.="-mrtd ";
645 } elsif (/^Z[d7iI]$/) {
647 $prj_target_cflags.="-g ";
649 # Disable Optimizations
650 $prj_target_cflags.="-O0 ";
653 $prj_target_cflags.="-Os ";
656 $prj_target_cflags.="-O2 ";
658 # Disables inline Expansion
659 $prj_target_cflags.="-fno-inline ";
661 #In-line Function Expansion
662 $prj_target_cflags.="-finline-functions ";
664 # auto In-line Function Expansion
665 $prj_target_cflags.="-finline-functions ";
667 # Use maximum optimization
668 $prj_target_cflags.="-O3 ";
670 # Frame-Pointer Omission
671 $prj_target_cflags.="-fomit-frame-pointer ";
673 # Frame-Pointer Omission
674 $prj_target_cflags.="-fno-omit-frame-pointer ";
676 # Catch Release-Build Errors in Debug Build
677 } elsif (/^M[DLT]d?$/) {
678 # Use Multithreaded Run-Time Library
679 } elsif (/^D\s*\"(.*)\"/) {
680 # Preprocessor Definitions
681 $prj_target_defines.="-D".$1." ";
682 } elsif (/^I\s*\"(.*)\"/) {
683 # Additional Include Directories
686 if ($sfilet=~/^\w:/) {
687 print STDERR
"warning: Can't fix path $sfilet\n"
689 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I".$sfilet." ";
691 } elsif (/^U\s*\"(.*)\"/) {
692 # Undefines a previously defined symbol
693 $prj_target_cflags.="-U".$1." ";
699 # Automatic Use of Precompiled Headers
701 # Generate File Dependencies
703 # Compile Without Linking
704 # this option is always present and is already specified in the suffix rules
707 $prj_target_cflags.="-D_M_IX86=500 ";
709 # Pentium Pro Optimization
710 $prj_target_cflags.="-D_M_IX86=600 ";
712 # Pentium Optimization
713 $prj_target_cflags.="-D_M_IX86=500 ";
716 $prj_target_cflags.="-D_M_IX86=300 ";
719 $prj_target_cflags.="-D_M_IX86=400 ";
721 # Create Precompiled Header
723 # Use Precompiled Header
725 # Disable Language Extensions
726 $prj_target_cflags.="-ansi ";
728 # Enable Microsoft Extensions
729 } elsif (/^Zm[[:digit:]]+$/) {
730 # Specify Memory Allocation Limit
732 # Packs structures on 1-byte boundaries
733 $prj_target_cflags.="-fpack-struct ";
734 } elsif (/^Zp(2|4|8|16)$/) {
735 # Struct Member Alignment
736 $prj_target_cflags.="-fpack-struct=".$1;
738 print "C compiler option $_ not implemented\n";
742 #print "\nOptions: $prj_target_cflags\n";
744 } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
745 $prj_target_ldflags=$1;
746 @prj_target_options=split(/\s+\//, $prj_target_ldflags);
747 $prj_target_ldflags="";
748 $prj_target_libs=$prj_target_options[0];
749 $prj_target_libs=~s/\\/\//g
;
750 $prj_target_libs=~s/\.lib//g;
751 $prj_target_libs=~s/\s+/ -l/g;
752 shift (@prj_target_options);
753 foreach ( @prj_target_options ) {
756 } elsif (/^base:(.*)/) {
758 $prj_target_ldflags.="--image-base ".$1." ";
759 } elsif (/^debug$/) {
760 # Generate Debug Info
763 $prj_target_type=$TT_DLL;
764 } elsif (/^incremental:[[:alpha:]]+$/) {
766 } elsif (/^implib:/) {
767 # Name import library
768 } elsif (/^libpath:\"(.*)\"/) {
770 push @
{@
$project_settings[$T_DLL_PATH]},"-L$1";
771 } elsif (/^machine:[[:alnum:]]+$/) {
772 # Specify Target Platform
776 $prj_target_ldflags.="-Map ".$1." ";
778 $prj_target_ldflags.="-Map ".$prj_name.".map ";
780 } elsif (/^nologo$/) {
781 # Suppress Startup Banner and Information Messages
784 # may use it as Target?
785 } elsif (/^pdbtype:/) {
786 # Program Database Storage
787 } elsif (/^subsystem:/) {
789 } elsif (/^version:[[:digit:].]+$/) {
790 # Version Information
792 print "Linker option $_ not implemented\n";
796 } elsif (/^LIB32=/ && $found_cfg==1) {
799 } elsif (/^SOURCE=(.*)$/) {
800 my @components=split /[\/\\]+/, $1;
801 $sfilet=search_from
($path, \
@components);
802 if (!defined $sfilet) { next; }
803 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
804 push @sources_c,$sfilet;
805 } elsif ($sfilet =~ /\.cpp$/i) {
806 if ($sfilet =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
807 push @sources_misc,$sfilet;
808 @
$project_settings[$T_FLAGS]|=$TF_MFC;
810 push @sources_cxx,$sfilet;
812 } elsif ($sfilet =~ /\.cxx$/i) {
813 @
$project_settings[$T_FLAGS]|=$TF_HASCXX;
814 push @sources_cxx,$sfilet;
815 } elsif ($sfilet =~ /\.rc$/i) {
816 push @sources_rc,$sfilet;
817 } elsif ($sfilet =~ /\.def$/i) {
818 @
$project_settings[$T_FLAGS]|=$TF_HASDEF;
819 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
820 push @sources_misc,$sfilet;
821 if ($sfilet =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
822 @
$project_settings[$T_FLAGS]|=$TF_MFC;
827 } elsif (/^# (Begin|End) Source File/) {
828 # Source-Files already handled
830 } elsif (/^# (Begin|End) Group/) {
833 } elsif (/^# (Begin|End) Custom Build/) {
834 # Custom Builds are ignored
836 } elsif (/^# ADD LIB32 /) {
839 } elsif (/^# Begin Target$/) {
840 # Targets are ignored
842 } elsif (/^# End Target$/) {
843 # Targets are ignored
846 if ($found_cfg == 1) {
849 if (/if (.*)\(CFG\)" == "(.*)"/i) {
850 if ($2 eq $prj_cfg) {
855 } elsif (/^CFG=(.*)/i) {
859 else { # Line recognized
865 push @
{@
$project_settings[$T_LIBRARIES]},$prj_target_libs;
866 push @
{@
$project_settings[$T_CEXTRA]},$prj_target_cflags;
867 push @
{@
$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
868 push @
{@
$project_settings[$T_DEFINES]},$prj_target_defines;
869 push @
{@
$project_settings[$T_LDFLAGS]},$prj_target_ldflags;
870 } elsif ($filename =~ /.vcproj$/i) {
871 # Import XML::LibXML, you need the libxml package (deb: libxml-libxml-perl, rpm: perl-libxml-perl)
874 my $xmlparser = XML
::LibXML
->new();
875 my $project_xml = $xmlparser->parse_file($filename);
879 foreach my $vc_project ($project_xml->findnodes('/VisualStudioProject')) {
880 foreach my $vc_project_attr ($vc_project->attributes) {
881 if ($vc_project_attr->getName eq "Name") {
882 $prj_name=$vc_project_attr->getValue;
883 $prj_name=~s/\s+/_/g;
889 for (my $flevel = 0; $flevel <= 5; $flevel++) {
890 foreach my $vc_file ($project_xml->findnodes('/VisualStudioProject/Files/'.('Filter/' x
$flevel).'File')) {
891 foreach my $vc_file_attr ($vc_file->attributes) {
892 if ($vc_file_attr->getName eq "RelativePath") {
893 $sfilet = $vc_file_attr->getValue;
894 $sfilet=~s/\\\\/\\/g; #remove double backslash
895 $sfilet=~s/^\.\\//; #remove starting 'this directory'
896 $sfilet=~s/\\/\//g
; #make slashes out of backslashes
897 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
898 push @sources_c,$sfilet;
899 } elsif ($sfilet =~ /\.cpp$/i) {
900 if ($sfilet =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
901 push @sources_misc,$sfilet;
902 @
$project_settings[$T_FLAGS]|=$TF_MFC;
904 push @sources_cxx,$sfilet;
906 } elsif ($sfilet =~ /\.cxx$/i) {
907 @
$project_settings[$T_FLAGS]|=$TF_HASCXX;
908 push @sources_cxx,$sfilet;
909 } elsif ($sfilet =~ /\.rc$/i) {
910 push @sources_rc,$sfilet;
911 } elsif ($sfilet =~ /\.def$/i) {
912 @
$project_settings[$T_FLAGS]|=$TF_HASDEF;
913 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
914 push @sources_misc,$sfilet;
915 if ($sfilet =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
916 @
$project_settings[$T_FLAGS]|=$TF_MFC;
924 my @vc_configurations = $project_xml->findnodes('/VisualStudioProject/Configurations/Configuration');
925 my $vc_configuration = $vc_configurations[0];
926 foreach my $vc_configuration_attr ($vc_configuration->attributes) {
927 if ($vc_configuration_attr->getName eq "ConfigurationType") {
928 if ($vc_configuration_attr->getValue==1) {
929 $prj_target_type=$TT_GUIEXE; # Application
930 } elsif ($vc_configuration_attr->getValue==2) {
931 $prj_target_type=$TT_DLL; # Dynamic-Link Library
932 } elsif ($vc_configuration_attr->getValue==4) {
933 $prj_target_type=$TT_LIB; # Static Library
938 foreach my $vc_configuration_tools ($vc_configuration->findnodes('Tool')) {
939 my @find_tool = $vc_configuration_tools->attributes;
940 if ($find_tool[0]->getValue eq "VCCLCompilerTool") {
941 foreach my $vc_compiler_tool ($vc_configuration_tools->attributes) {
942 if ($vc_compiler_tool->getName eq "Optimization") {$prj_target_cflags.="-O".$vc_compiler_tool->getValue." ";}
943 if ($vc_compiler_tool->getName eq "WarningLevel") {
944 if ($vc_compiler_tool->getValue==0) {
945 $prj_target_cflags.="-w ";
946 } elsif ($vc_compiler_tool->getValue<4) {
947 $prj_target_cflags.="-W ";
948 } elsif ($vc_compiler_tool->getValue==4) {
949 $prj_target_cflags.="-Wall ";
950 } elsif ($vc_compiler_tool->getValue eq "X") {
951 $prj_target_cflags.="-Werror ";
954 if ($vc_compiler_tool->getName eq "PreprocessorDefinitions") {
955 $configt=$vc_compiler_tool->getValue;
956 $configt=~s/;\s*/ -D/g;
957 $prj_target_defines.="-D".$configt." ";
959 if ($vc_compiler_tool->getName eq "AdditionalIncludeDirectories") {
960 $configt=$vc_compiler_tool->getValue;
963 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I".$configt;
967 if ($find_tool[0]->getValue eq "VCLinkerTool") {
968 foreach my $vc_linker_tool ($vc_configuration_tools->attributes) {
969 if ($vc_linker_tool->getName eq "AdditionalDependencies") {
970 $prj_target_libs=" ".$vc_linker_tool->getValue;
971 $prj_target_libs=~s/\\/\//g
;
972 $prj_target_libs=~s/\.lib//g;
973 $prj_target_libs=~s/\s+/ -l/g;
979 push @
{@
$project_settings[$T_LIBRARIES]},$prj_target_libs;
980 push @
{@
$project_settings[$T_CEXTRA]},$prj_target_cflags;
981 push @
{@
$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
982 push @
{@
$project_settings[$T_DEFINES]},$prj_target_defines;
984 print STDERR
"File format not supported for file: $filename\n";
988 # Add this project to the project list, except for
989 # the main project which is already in the list.
990 if ($is_sub_project == 1) {
991 push @projects,$project;
994 # Ask for project-wide options
995 if ($opt_ask_project_options == $OPT_ASK_YES) {
997 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1000 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1001 if (defined $flag_desc) {
1002 print "* (currently $flag_desc)\n";
1004 print "* or 'skip' to skip the target specific options,\n";
1005 print "* or 'never' to not be asked this question again:\n";
1007 my $options=<STDIN
>;
1009 if ($options eq "skip") {
1010 $opt_ask_target_options=$OPT_ASK_SKIP;
1012 } elsif ($options eq "never") {
1013 $opt_ask_project_options=$OPT_ASK_NO;
1015 } elsif (source_set_options
($project_settings,$options)) {
1018 print "Please re-enter the options:\n";
1022 # Create the target...
1024 target_init
($target);
1026 if ($prj_target_type==$TT_GUIEXE or $prj_target_type==$TT_CUIEXE) {
1027 $prj_name=lc($prj_name.".exe");
1028 @
$target[$T_TYPE]=$opt_target_type;
1029 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
1030 } elsif ($prj_target_type==$TT_LIB) {
1031 $prj_name=lc("lib".$prj_name.".a");
1032 @
$target[$T_TYPE]=$TT_LIB;
1033 push @
{@
$target[$T_ARFLAGS]},("rc");
1035 $prj_name=lc($prj_name.".dll");
1036 @
$target[$T_TYPE]=$TT_DLL;
1037 my $canon=canonize
($prj_name);
1038 if (@
$project_settings[$T_FLAGS] & $TF_HASDEF) {
1039 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.def)");
1041 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1045 @
$target[$T_NAME]=$prj_name;
1046 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
1048 # This is the default link list of Visual Studio
1049 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1050 my @std_libraries=qw(uuid);
1051 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1052 @
$target[$T_DLLS]=\
@std_imports;
1053 @
$target[$T_LIBRARIES]=\
@std_libraries;
1055 @
$target[$T_DLLS]=[];
1056 @
$target[$T_LIBRARIES]=[];
1058 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1059 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
1060 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1061 push @
{@
$target[$T_LDFLAGS]},"-m$opt_arch";
1064 push @
{@
$project[$P_TARGETS]},$target;
1066 # Ask for target-specific options
1067 if ($opt_ask_target_options == $OPT_ASK_YES) {
1069 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
1072 if ($flag_desc ne "") {
1075 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1076 print "* \"$prj_name\"$flag_desc or 'never' to not be asked this question again:\n";
1078 my $options=<STDIN
>;
1080 if ($options eq "never") {
1081 $opt_ask_target_options=$OPT_ASK_NO;
1083 } elsif (source_set_options
($target,$options)) {
1086 print "Please re-enter the options:\n";
1089 if (@
$target[$T_FLAGS] & $TF_MFC) {
1090 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1091 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1092 push @
{@
$target[$T_DLLS]},"mfc.dll";
1093 # FIXME: Link with the MFC in the Unix sense, until we
1094 # start exporting the functions properly.
1095 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1096 push @
{@
$target[$T_LIBRARIES]},"mfc";
1100 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
1101 @
$project_settings[$T_SOURCES_C]=[];
1103 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1104 @
$project_settings[$T_SOURCES_CXX]=[];
1106 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
1107 @
$project_settings[$T_SOURCES_RC]=[];
1109 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
1110 @
$project_settings[$T_SOURCES_MISC]=[];
1113 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
1114 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
1115 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
1116 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
1118 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1119 $opt_ask_target_options=$OPT_ASK_YES;
1122 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1123 push @
{@
$project_settings[$T_CEXTRA]},"-mno-cygwin";
1124 push @
{@
$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1125 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1126 push @
{@
$project_settings[$T_CEXTRA]},"-m$opt_arch";
1127 push @
{@
$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1131 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
1132 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1134 # The sources that did not match, if any, go to the extra
1135 # source list of the project settings
1136 foreach my $source (@sources_c) {
1137 if ($source ne "") {
1138 push @
{@
$project_settings[$T_SOURCES_C]},$source;
1141 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
1142 foreach my $source (@sources_cxx) {
1143 if ($source ne "") {
1144 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
1147 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
1148 foreach my $source (@sources_rc) {
1149 if ($source ne "") {
1150 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
1153 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
1154 foreach my $source (@sources_misc) {
1155 if ($source ne "") {
1156 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
1159 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
1163 # Scans the specified workspace file to find the project files
1164 sub source_scan_workspace_file
($);
1165 sub source_scan_workspace_file
($)
1168 my $path=dirname
($filename);
1171 if (! -e
$filename) {
1175 if (!open(FILEIWS
,$filename)) {
1176 print STDERR
"error: unable to open $filename for reading:\n";
1177 print STDERR
" $!\n";
1184 if ($filename =~ /.dsw$/i) {
1186 # Remove any trailing CrLf
1189 # catch a project definition
1190 if (/^Project:\s\"(.*)\"=(.*)\s-/) {
1193 @components=split /[\/\\]+/, $prj_path;
1194 $prj_path=search_from
($path, \
@components);
1195 print "Name: $prj_name\nPath: $prj_path\n";
1196 source_scan_project_file
(\
@main_project,1,$prj_path);
1200 } elsif (/^Global:/) {
1201 # ignore the Global section
1203 print STDERR
"unknown section $_\n";
1204 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1205 print "\nFileversion: $3\n";
1209 } elsif ($filename =~ /.sln$/i) {
1211 # Remove any trailing CrLf
1214 # catch a project definition
1215 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1218 if ($prj_path eq "Solution Items") { next; }
1219 @components=split /[\/\\]+/, $3;
1220 $prj_path=search_from
($path, \
@components);
1221 print "Name: $prj_name\nPath: $prj_path\n";
1222 source_scan_project_file
(\
@main_project,1,$prj_path);
1224 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1225 print "\nFileversion: $3\n";
1231 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
1235 # Scans the specified directory to:
1236 # - see if we should create a Makefile in this directory. We normally do
1237 # so if we find a project file and sources
1238 # - get a list of targets for this directory
1239 # - get the list of source files
1240 sub source_scan_directory
($$$$);
1241 sub source_scan_directory
($$$$)
1243 # a reference to the parent's project
1244 my $parent_project=$_[0];
1245 # the full relative path to the current directory, including a
1246 # trailing '/', or an empty string if this is the top level directory
1248 # the name of this directory, including a trailing '/', or an empty
1249 # string if this is the top level directory
1251 # if set then no targets will be looked for and the sources will all
1252 # end up in the parent_project's 'misc' bucket
1253 my $no_target=$_[3];
1255 # reference to the project for this directory. May not be used
1257 # list of targets found in the 'current' directory
1259 # list of sources found in the current directory
1263 my @sources_misc=();
1264 # true if this directory contains a Windows project
1265 my $has_win_project=0;
1266 # true if this directory contains headers
1268 # If we don't find any executable/library then we might make up targets
1269 # from the list of .dsp/.mak files we find since they usually have the
1270 # same name as their target.
1274 if (defined $opt_single_target or $dirname eq "") {
1275 # Either there is a single target and thus a single project,
1276 # or we are in the top level directory for which a project
1278 $project=$parent_project;
1281 project_init
($project, $path, \
@global_settings);
1283 my $project_settings=@
$project[$P_SETTINGS];
1285 # First find out what this directory contains:
1286 # collect all sources, targets and subdirectories
1287 my $directory=get_directory_contents
($path);
1288 foreach my $dentry (@
$directory) {
1289 if ($dentry =~ /^\./) {
1292 my $fullentry="$path$dentry";
1293 if (-d
"$fullentry") {
1294 if ($dentry =~ /^(Release|Debug)/i) {
1295 # These directories are often used to store the object files and the
1296 # resulting executable/library. They should not contain anything else.
1297 my @candidates=grep /\.(exe|dll|lib)$/i, @
{get_directory_contents
("$fullentry")};
1298 foreach my $candidate (sort @candidates) {
1299 my $dlldup = $candidate;
1300 $dlldup =~ s/\.lib$/.dll/;
1301 if ($candidate =~ /\.lib$/ and $targets{$dlldup})
1303 # Often lib files are created together with dll files, even if the dll file is the
1307 $targets{$candidate}=1;
1309 } elsif ($dentry =~ /^include/i) {
1310 # This directory must contain headers we're going to need
1311 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1312 source_scan_directory
($project,"$fullentry/","$dentry/",1);
1314 # Recursively scan this directory. Any source file that cannot be
1315 # attributed to a project in one of the subdirectories will be
1316 # attributed to this project.
1317 source_scan_directory
($project,"$fullentry/","$dentry/",$no_target);
1319 } elsif (-f
"$fullentry") {
1320 if ($dentry =~ /\.(exe|dll|lib)$/i) {
1321 $targets{$dentry}=1;
1322 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1323 push @sources_c,"$dentry";
1324 } elsif ($dentry =~ /\.cpp$/i) {
1325 if ($dentry =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1326 push @sources_misc,"$dentry";
1327 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1329 push @sources_cxx,"$dentry";
1331 } elsif ($dentry =~ /\.cxx$/i) {
1332 @
$project_settings[$T_FLAGS]|=$TF_HASCXX;
1333 push @sources_cxx,"$dentry";
1334 } elsif ($dentry =~ /\.rc$/i) {
1335 push @sources_rc,"$dentry";
1336 } elsif ($dentry =~ /\.def$/i) {
1337 @
$project_settings[$T_FLAGS]|=$TF_HASDEF;
1338 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1340 push @sources_misc,"$dentry";
1341 if ($dentry =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1342 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1344 } elsif ($dentry =~ /\.(dsp|vcproj)$/i) {
1345 push @prj_files,"$dentry";
1347 } elsif ($dentry =~ /\.mak$/i) {
1348 push @mak_files,"$dentry";
1350 } elsif ($dentry =~ /^makefile/i) {
1357 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I.";
1359 # If we have a single target then all we have to do is assign
1360 # all the sources to it and we're done
1361 # FIXME: does this play well with the --interactive mode?
1362 if ($opt_single_target) {
1363 my $target=@
{@
$project[$P_TARGETS]}[0];
1364 push @
{@
$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1365 push @
{@
$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1366 push @
{@
$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1367 push @
{@
$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1371 my $parent_settings=@
$parent_project[$P_SETTINGS];
1372 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1373 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1374 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1375 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1376 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1380 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1381 @
{@
$project_settings[$T_SOURCES_C]}+
1382 @
{@
$project_settings[$T_SOURCES_CXX]}+
1383 @
{@
$project_settings[$T_SOURCES_RC]};
1384 if ($source_count == 0) {
1385 # A project without real sources is not a project, get out!
1386 if ($project!=$parent_project) {
1387 my $parent_settings=@
$parent_project[$P_SETTINGS];
1388 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1389 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1393 #print "targets=",%targets,"\n";
1394 #print "target_count=$target_count\n";
1395 #print "has_win_project=$has_win_project\n";
1396 #print "dirname=$dirname\n";
1399 if (($has_win_project != 0) or ($dirname eq "")) {
1400 # Deal with cases where we could not find any executable/library, and
1401 # thus have no target, although we did find some sort of windows project.
1402 $target_count=keys %targets;
1403 if ($target_count == 0) {
1404 # Try to come up with a target list based on .dsp/.mak files
1406 if (@prj_files > 0) {
1407 print "Projectfile found! You might want to try using it directly.\n";
1408 $prj_list=\
@prj_files;
1410 $prj_list=\
@mak_files;
1412 foreach my $filename (@
$prj_list) {
1413 $filename =~ s/\.(dsp|vcproj|mak)$//i;
1414 if ($opt_target_type == $TT_DLL) {
1415 $filename = "$filename.dll";
1417 $targets{$filename}=1;
1419 $target_count=keys %targets;
1420 if ($target_count == 0) {
1421 # Still nothing, try the name of the directory
1423 if ($dirname eq "") {
1424 # Bad luck, this is the top level directory!
1425 $name=(split /\//, cwd
)[-1];
1428 # Remove the trailing '/'. Also eliminate whatever is after the last
1429 # '.' as it is likely to be meaningless (.orig, .new, ...)
1430 $name =~ s
+(/|\
.[^.]*)$++;
1431 if ($name eq "src") {
1432 # 'src' is probably a subdirectory of the real project directory.
1433 # Try again with the parent (if any).
1435 if ($parent =~ s
+([^/]*)/[^/]*/$+$1+) {
1438 $name=(split /\//, cwd
)[-1];
1442 $name =~ s
+(/|\
.[^.]*)$++;
1443 if ($opt_target_type == $TT_DLL) {
1444 $name = canonize
($name).".dll";
1445 } elsif ($opt_target_type == $TT_LIB) {
1446 $name = "lib".canonize
($name).".a";
1448 $name = canonize
($name).".exe";
1454 # Ask confirmation to the user if he wishes so
1455 if ($opt_is_interactive == $OPT_ASK_YES) {
1456 my $target_list=join " ",keys %targets;
1457 print "\n*** In ",($path?
$path:"./"),"\n";
1458 print "* winemaker found the following list of (potential) targets\n";
1459 print "* $target_list\n";
1460 print "* Type enter to use it as is, your own comma-separated list of\n";
1461 print "* targets, 'none' to assign the source files to a parent directory,\n";
1462 print "* or 'ignore' to ignore everything in this directory tree.\n";
1463 print "* Target list:\n";
1464 $target_list=<STDIN
>;
1466 if ($target_list eq "") {
1467 # Keep the target list as is, i.e. do nothing
1468 } elsif ($target_list eq "none") {
1469 # Empty the target list
1471 } elsif ($target_list eq "ignore") {
1472 # Ignore this subtree altogether
1476 foreach my $target (split /,/,$target_list) {
1477 $target =~ s
+^\s
*++;
1478 $target =~ s
+\s
*$++;
1479 $targets{$target}=1;
1485 # If we have no project at this level, then transfer all
1486 # the sources to the parent project
1487 $target_count=keys %targets;
1488 if ($target_count == 0) {
1489 if ($project!=$parent_project) {
1490 my $parent_settings=@
$parent_project[$P_SETTINGS];
1491 push @
{@
$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1492 push @
{@
$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1493 push @
{@
$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1494 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1495 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1500 # Otherwise add this project to the project list, except for
1501 # the main project which is already in the list.
1502 if ($dirname ne "") {
1503 push @projects,$project;
1506 # Ask for project-wide options
1507 if ($opt_ask_project_options == $OPT_ASK_YES) {
1509 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1512 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1513 if (defined $flag_desc) {
1514 print "* (currently $flag_desc)\n";
1516 print "* or 'skip' to skip the target specific options,\n";
1517 print "* or 'never' to not be asked this question again:\n";
1519 my $options=<STDIN
>;
1521 if ($options eq "skip") {
1522 $opt_ask_target_options=$OPT_ASK_SKIP;
1524 } elsif ($options eq "never") {
1525 $opt_ask_project_options=$OPT_ASK_NO;
1527 } elsif (source_set_options
($project_settings,$options)) {
1530 print "Please re-enter the options:\n";
1534 # - Create the targets
1535 # - Check if we have both libraries and programs
1536 # - Match each target with source files (sort in reverse
1537 # alphabetical order to get the longest matches first)
1540 my @local_depends=();
1542 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1543 # Create the target...
1545 target_init
($target);
1546 @
$target[$T_NAME]=$target_name;
1547 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
1548 if ($target_name =~ /\.dll$/) {
1549 @
$target[$T_TYPE]=$TT_DLL;
1550 push @local_depends,"$target_name.so";
1551 push @local_dlls,$target_name;
1552 my $canon=canonize
($target_name);
1553 if (@
$project_settings[$T_FLAGS] & $TF_HASDEF) {
1554 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.def)");
1556 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1558 } elsif ($target_name =~ /\.lib$/) {
1559 $target_name =~ s/(.*)\.lib/lib$1.a/;
1560 @
$target[$T_NAME]=$target_name;
1561 @
$target[$T_TYPE]=$TT_LIB;
1562 push @local_depends,"$target_name";
1563 push @local_libs,$target_name;
1564 push @
{@
$target[$T_ARFLAGS]},("rc");
1565 } elsif ($target_name =~ /\.a$/) {
1566 @
$target[$T_NAME]=$target_name;
1567 @
$target[$T_TYPE]=$TT_LIB;
1568 push @local_depends,"$target_name";
1569 push @local_libs,$target_name;
1570 push @
{@
$target[$T_ARFLAGS]},("rc");
1572 @
$target[$T_TYPE]=$opt_target_type;
1573 push @exe_list,$target;
1574 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
1576 my $basename=$target_name;
1577 $basename=~ s/\.(dll|exe)$//i;
1578 # This is the default link list of Visual Studio
1579 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1580 my @std_libraries=qw(uuid);
1581 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1582 @
$target[$T_DLLS]=\
@std_imports;
1583 @
$target[$T_LIBRARIES]=\
@std_libraries;
1585 @
$target[$T_DLLS]=[];
1586 @
$target[$T_LIBRARIES]=[];
1588 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1589 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
1590 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1591 push @
{@
$target[$T_LDFLAGS]},"-m$opt_arch";
1594 push @
{@
$project[$P_TARGETS]},$target;
1596 # Ask for target-specific options
1597 if ($opt_ask_target_options == $OPT_ASK_YES) {
1599 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
1602 if ($flag_desc ne "") {
1605 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1606 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1608 my $options=<STDIN
>;
1610 if ($options eq "never") {
1611 $opt_ask_target_options=$OPT_ASK_NO;
1613 } elsif (source_set_options
($target,$options)) {
1616 print "Please re-enter the options:\n";
1619 if (@
$target[$T_FLAGS] & $TF_MFC) {
1620 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1621 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1622 push @
{@
$target[$T_DLLS]},"mfc.dll";
1623 # FIXME: Link with the MFC in the Unix sense, until we
1624 # start exporting the functions properly.
1625 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1626 push @
{@
$target[$T_LIBRARIES]},"mfc";
1630 if ($target_count == 1) {
1631 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
1632 @
$project_settings[$T_SOURCES_C]=[];
1635 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1636 @
$project_settings[$T_SOURCES_CXX]=[];
1639 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
1640 @
$project_settings[$T_SOURCES_RC]=[];
1643 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
1644 # No need for sorting these sources
1645 @
$project_settings[$T_SOURCES_MISC]=[];
1648 foreach my $source (@sources_c) {
1649 if ($source =~ /^$basename/i) {
1650 push @
{@
$target[$T_SOURCES_C]},$source;
1654 foreach my $source (@sources_cxx) {
1655 if ($source =~ /^$basename/i) {
1656 push @
{@
$target[$T_SOURCES_CXX]},$source;
1660 foreach my $source (@sources_rc) {
1661 if ($source =~ /^$basename/i) {
1662 push @
{@
$target[$T_SOURCES_RC]},$source;
1666 foreach my $source (@sources_misc) {
1667 if ($source =~ /^$basename/i) {
1668 push @
{@
$target[$T_SOURCES_MISC]},$source;
1673 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
1674 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
1675 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
1676 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
1678 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1679 $opt_ask_target_options=$OPT_ASK_YES;
1682 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1683 push @
{@
$project_settings[$T_CEXTRA]},"-mno-cygwin";
1684 push @
{@
$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1685 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1686 push @
{@
$project_settings[$T_CEXTRA]},"-m$opt_arch";
1687 push @
{@
$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1691 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
1692 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1694 # The sources that did not match, if any, go to the extra
1695 # source list of the project settings
1696 foreach my $source (@sources_c) {
1697 if ($source ne "") {
1698 push @
{@
$project_settings[$T_SOURCES_C]},$source;
1701 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
1702 foreach my $source (@sources_cxx) {
1703 if ($source ne "") {
1704 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
1707 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
1708 foreach my $source (@sources_rc) {
1709 if ($source ne "") {
1710 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
1713 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
1714 foreach my $source (@sources_misc) {
1715 if ($source ne "") {
1716 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
1719 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
1721 # Finally if we are building both libraries and programs in
1722 # this directory, then the programs should be linked with all
1724 if (@local_dlls > 0 and @exe_list > 0) {
1725 foreach my $target (@exe_list) {
1726 push @
{@
$target[$T_DLL_PATH]},"-L.";
1727 push @
{@
$target[$T_DLLS]},@local_dlls;
1730 if (@local_libs > 0 and @exe_list > 0) {
1731 foreach my $target (@exe_list) {
1732 push @
{@
$target[$T_LIBRARY_PATH]},"-L.";
1733 push @
{@
$target[$T_LIBRARIES]},@local_libs;
1739 # Scan the source directories in search of things to build
1742 # If there's a single target then this is going to be the default target
1743 if (defined $opt_single_target) {
1744 # Create the main target
1746 target_init
($main_target);
1747 @
$main_target[$T_NAME]=$opt_single_target;
1748 @
$main_target[$T_TYPE]=$opt_target_type;
1750 # Add it to the list
1751 push @
{$main_project[$P_TARGETS]},$main_target;
1754 # The main directory is always going to be there
1755 push @projects,\
@main_project;
1757 if (defined $opt_work_dir) {
1758 # Now scan the directory tree looking for source files and, maybe, targets
1759 print "Scanning the source directories...\n";
1760 source_scan_directory
(\
@main_project,"","",0);
1761 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
1762 } elsif (defined $opt_work_file) {
1763 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1764 source_scan_project_file
(\
@main_project,0,$opt_work_file);
1765 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1766 source_scan_workspace_file
($opt_work_file);
1778 # Performs a directory traversal and renames the files so that:
1779 # - they have the case desired by the user
1780 # - their extension is of the appropriate case
1781 # - they don't contain annoying characters like ' ', '$', '#', ...
1782 # But only perform these changes for source files and directories.
1783 sub fix_file_and_directory_names
($);
1784 sub fix_file_and_directory_names
($)
1788 my $directory=get_directory_contents
($dirname);
1789 foreach my $dentry (@
$directory)
1791 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1794 # Set $warn to 1 if the user should be warned of the renaming
1796 my $new_name=$dentry;
1798 if (-f
"$dirname/$dentry")
1800 # Don't rename Winemaker's makefiles
1801 next if ($dentry eq "Makefile" and
1802 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker
/);
1804 # Leave non-source files alone
1805 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc|spec|def))$/i);
1807 # Only all lowercase extensions are supported (because of
1808 # rules like '.c.o:').
1809 $new_name =~ s/\.C$/.c/;
1810 $new_name =~ s/\.cpp$/.cpp/i;
1811 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1812 $new_name =~ s/\.rc$/.rc/i;
1813 # And this last one is to avoid confusion when running make
1814 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1817 # Adjust the case to the user's preferences
1818 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1819 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1821 $new_name=lc $new_name;
1824 # make doesn't support these characters well
1825 $new_name =~ s/[ \$]/_/g;
1827 # And finally, perform the renaming
1828 if ($new_name ne $dentry)
1831 print STDERR
"warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1833 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1834 print STDERR
"error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1835 print STDERR
" $!\n";
1840 clear_directory_cache
($dirname);
1843 if (-d
"$dirname/$new_name") {
1844 fix_file_and_directory_names
("$dirname/$new_name");
1858 # Try to find a file for the specified filename. The attempt is
1859 # case-insensitive which is why it's not trivial. If a match is
1860 # found then we return the pathname with the correct case.
1867 $dirname =~ s/(\.\/)+//;
1868 if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
1870 } elsif ($dirname !~ m
+^/+) {
1871 $dirname=cwd
. "/" . $dirname;
1873 if ($dirname !~ m
+/$+) {
1877 foreach my $component (@
$path) {
1878 $component=~s/^\"//;
1879 $component=~s/\"$//;
1880 #print " looking for $component in \"$dirname\"\n";
1881 if ($component eq ".") {
1884 } elsif ($component eq "..") {
1886 if ($dirname =~ /\.\.\/$/) {
1889 $dirname=dirname
($dirname) . "/";
1893 # The file/directory may have been renamed before. Also try to
1894 # match the renamed file.
1895 my $renamed=$component;
1896 $renamed =~ s/[ \$]/_/g;
1897 if ($renamed eq $component) {
1901 my $directory=get_directory_contents
$dirname;
1903 foreach my $dentry (@
$directory) {
1904 if ($dentry =~ /^\Q$component\E$/i or
1905 (defined $renamed and $dentry =~ /^$renamed$/i)
1907 $dirname.="$dentry/";
1908 $real_path.="$dentry/";
1913 if (!defined $found) {
1915 #print " could not find $component in $dirname\n";
1920 $real_path=~ s
+/$++;
1921 #print " -> found $real_path\n";
1926 # Performs a case-insensitive search for the specified file in the
1928 # $line is the line number that should be referenced when an error occurs
1929 # $filename is the file we are looking for
1930 # $dirname is the directory of the file containing the '#include' directive
1931 # if '"' was used, it is an empty string otherwise
1932 # $project and $target specify part of the include path
1933 sub get_real_include_name
($$$$$)
1941 if ($filename =~ /^([a-zA-Z]:)?[\/\\]/ or $filename =~ /^[a
-zA
-Z
]:[\
/\\]?/) {
1942 # This is not a relative path, we cannot make any check
1943 my $warning="path:$filename";
1944 if (!defined $warnings{$warning}) {
1945 $warnings{$warning}="1";
1946 print STDERR
"warning: cannot check the case of absolute pathnames:\n";
1947 print STDERR
"$line: $filename\n";
1950 # Here's how we proceed:
1951 # - split the filename we look for into its components
1952 # - then for each directory in the include path
1953 # - trace the directory components starting from that directory
1954 # - if we fail to find a match at any point then continue with
1955 # the next directory in the include path
1956 # - otherwise, rejoice, our quest is over.
1957 my @file_components=split /[\/\\]+/, $filename;
1958 #print " Searching for $filename from @$project[$P_PATH]\n";
1961 if ($dirname ne "") {
1962 # This is an 'include ""' -> look in dirname first.
1963 #print " in $dirname (include \"\")\n";
1964 $real_filename=search_from
($dirname,\
@file_components);
1965 if (defined $real_filename) {
1966 return $real_filename;
1969 my $project_settings=@
$project[$P_SETTINGS];
1970 foreach my $include (@
{@
$target[$T_INCLUDE_PATH]}, @
{@
$project_settings[$T_INCLUDE_PATH]}) {
1971 my $dirname=$include;
1974 if (!is_absolute
($dirname)) {
1975 $dirname="@$project[$P_PATH]$dirname";
1977 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)/++;
1978 $dirname=~ s
+^\
$\
(SRCDIR\
)/+@
$project[$P_PATH]+;
1980 #print " in $dirname\n";
1981 $real_filename=search_from
("$dirname",\
@file_components);
1982 if (defined $real_filename) {
1983 return $real_filename;
1986 my $dotdotpath=@
$project[$P_PATH];
1987 $dotdotpath =~ s/[^\/]+/../g
;
1988 foreach my $include (@
{$global_settings[$T_INCLUDE_PATH]}) {
1989 my $dirname=$include;
1991 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)\
/++;
1992 $dirname=~ s
+^\
$\
(SRCDIR\
)\
/+@
$project[$P_PATH]+;
1993 #print " in $dirname (global setting)\n";
1994 $real_filename=search_from
("$dirname",\
@file_components);
1995 if (defined $real_filename) {
1996 return $real_filename;
2000 $filename =~ s
+\\\\+/+g
; # in include ""
2001 $filename =~ s
+\\+/+g
; # in include <> !
2002 if ($opt_lower_include) {
2003 return lc "$filename";
2014 if ($size =~ /^(1|2|4|8)$/) {
2015 print FILEO
"$indent#include <pshpack$size.h>$trailer";
2017 print FILEO
"$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
2018 print FILEO
"$indent#include <pshpack4.h>$trailer";
2023 # 'Parses' a source file and fixes constructs that would not work with
2024 # Winelib. The parsing is rather simple and not all non-portable features
2025 # are corrected. The most important feature that is corrected is the case
2026 # and path separator of '#include' directives. This requires that each
2027 # source file be associated to a project & target so that the proper
2028 # include path is used.
2029 # Also note that the include path is relative to the directory in which the
2030 # compiler is run, i.e. that of the project, not to that of the file.
2036 $filename="@$project[$P_PATH]$filename";
2037 if (! -e
$filename) {
2041 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
2042 my $dirname=dirname
($filename);
2044 if (defined $target and (@
$target[$T_FLAGS] & $TF_MFC)) {
2048 print " $filename\n";
2049 if (! -e
"$filename.bak") {
2050 if (!copy
("$filename","$filename.bak")) {
2051 print STDERR
"error: unable to make a backup of $filename:\n";
2052 print STDERR
" $!\n";
2056 if (!open(FILEI
,"$filename.bak")) {
2057 print STDERR
"error: unable to open $filename.bak for reading:\n";
2058 print STDERR
" $!\n";
2061 if (!open(FILEO
,">$filename")) {
2062 print STDERR
"error: unable to open $filename for writing:\n";
2063 print STDERR
" $!\n";
2068 my $rc_block_depth=0;
2069 my $rc_textinclude_state=0;
2072 # Remove any trailing CtrlZ, which isn't strictly in the file
2080 # Make sure all files are '\n' terminated
2083 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
2084 # VC6 automatically includes 'afxres.h', an MFC specific header, in
2085 # the RC files it generates (even in non-MFC projects). So we replace
2086 # it with 'winresrc.h' its very close standard cousin so that non MFC
2087 # projects can compile in Wine without the MFC sources.
2088 my $warning="mfc:afxres.h";
2089 if (!defined $warnings{$warning}) {
2090 $warnings{$warning}="1";
2091 print STDERR
"warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
2092 print STDERR
"warning: the above warning is issued only once\n";
2094 print FILEO
"$1/* winemaker: $2\"afxres.h\" */\n";
2095 print FILEO
"$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
2096 print FILEO
"$1$2\"winresrc.h\"$'";
2099 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
2100 my $from_file=($2 eq "<"?
"":$dirname);
2101 my $real_include_name=get_real_include_name
($line,$3,$from_file,$project,$target);
2102 print FILEO
"$1$2$real_include_name$4$'";
2103 $modified|=($real_include_name ne $3);
2105 } elsif (/^(\s*)\#\s*pragma\s+comment\s*\(\s*lib\s*,\s*\"(\w+)\.lib\"\s*\)/) {
2106 my $pragma_indent=$1;
2108 push @
{@
$target[$T_LIBRARIES]},$pragma_lib;
2109 print FILEO
"$pragma_indent/* winemaker: Added -l$pragma_lib to the libraries */\n";
2110 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
2111 # Pragma pack handling
2113 # pack_stack is an array of references describing the stack of
2114 # pack directives currently in effect. Each directive if described
2115 # by a reference to an array containing:
2116 # - "push" for pack(push,...) directives, "" otherwise
2117 # - the directive's identifier at index 1
2118 # - the directive's alignment value at index 2
2120 # Don't believe a word of what the documentation says: it's all wrong.
2121 # The code below is based on the actual behavior of Visual C/C++ 6.
2126 # Pushes the default stack alignment
2127 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
2128 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2129 print_pack
($pack_indent,4,$');
2130 push @pack_stack, [ "", "", 4 ];
2132 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
2134 # pragma pack(pop,n)
2135 # Goes up the stack until it finds a pack(push,...), and pops it
2136 # Ignores any pack(n) entry
2137 # Issues a warning if the pack is of the form pack(push,label)
2138 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2139 my $pack_comment=$';
2140 $pack_comment =~ s/^\s*//;
2141 if ($pack_comment ne "") {
2142 print FILEO
"$pack_indent$pack_comment";
2145 my $alignment=pop @pack_stack;
2146 if (!defined $alignment) {
2147 print FILEO
"$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2150 if (@
$alignment[1]) {
2151 print FILEO
"$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2153 print FILEO
"$pack_indent#include <poppack.h>\n";
2154 if (@
$alignment[0]) {
2159 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2160 # pragma pack(pop,label[,n])
2161 # Goes up the stack until finding a pack(push,...) and pops it.
2162 # 'n', if specified, is ignored.
2163 # Ignores any pack(n) entry
2164 # Issues a warning if the label of the pack does not match,
2165 # or if it is in fact a pack(push,n)
2167 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
2168 my $pack_comment=$';
2169 $pack_comment =~ s/^\s*//;
2170 if ($pack_comment ne "") {
2171 print FILEO "$pack_indent$pack_comment";
2174 my $alignment=pop @pack_stack;
2175 if (!defined $alignment) {
2176 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2179 if (@$alignment[1] and @$alignment[1] ne $label) {
2180 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2182 print FILEO "$pack_indent#include <poppack.h>\n";
2183 if (@$alignment[0]) {
2188 } elsif (/^(push\s*\))/) {
2190 # Push the current alignment
2191 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2192 if (@pack_stack > 0) {
2193 my $alignment=$pack_stack[$#pack_stack];
2194 print_pack($pack_indent,@$alignment[2],$');
2195 push @pack_stack, [ "push", "", @
$alignment[2] ];
2197 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2198 print_pack
($pack_indent,4,$');
2199 push @pack_stack, [ "push", "", 4 ];
2202 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2203 # pragma pack([push,]n)
2204 # Push new alignment n
2205 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2206 print_pack($pack_indent,$3,"$'");
2207 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2209 } elsif (/^((\w+)\s*\))/) {
2210 # pragma pack(label)
2211 # label must in fact be a macro that resolves to an integer
2212 # Then behaves like 'pragma pack(n)'
2213 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2214 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2215 print_pack($pack_indent,4,$');
2216 push @pack_stack, [ "", "", 4 ];
2218 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2219 # pragma pack(push,label[,n])
2220 # Pushes a new label on the stack. It is possible to push the same
2221 # label multiple times. If 'n' is omitted then the alignment is
2222 # unchanged. Otherwise it becomes 'n'.
2223 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2227 } elsif (@pack_stack > 0) {
2228 my $alignment=$pack_stack[$#pack_stack];
2229 $size=@$alignment[2];
2231 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2234 print_pack($pack_indent,$size,$');
2235 push @pack_stack, [ "push", $2, $size ];
2238 # pragma pack(??? -> What's that?
2239 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2240 print FILEO "$pack_indent$pack_header$_";
2246 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]+)([\">]?)/) {
2247 my $from_file=($5 eq "<"?"":$dirname);
2248 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2249 print FILEO "$1$5$real_include_name$7$'";
2250 $modified|=($real_include_name ne $6);
2252 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2253 my $from_file=($2 eq "<"?"":$dirname);
2254 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2255 print FILEO "$1$2$real_include_name$4$'";
2256 $modified|=($real_include_name ne $3);
2258 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2259 $rc_textinclude_state=1;
2262 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2263 print FILEO "$1winresrc.h
$2$'";
2266 } elsif (/^\s*BEGIN(\W.*)?$/) {
2267 $rc_textinclude_state|=2;
2271 } elsif (/^\s*END(\W.*)?$/) {
2272 $rc_textinclude_state=0;
2273 if ($rc_block_depth>0) {
2289 if ($opt_backup == 0 or $modified == 0) {
2290 if (!unlink("$filename.bak")) {
2291 print STDERR "error: unable to delete $filename.bak:\n";
2292 print STDERR " $!\n";
2298 # Analyzes each source file in turn to find and correct issues
2299 # that would cause it not to compile.
2302 print "Fixing the source files...\n";
2303 foreach my $project (@projects) {
2304 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2305 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2306 fix_file($source,$project,$target);
2321 # A convenience function to generate all the lists (defines,
2322 # C sources, C++ source, etc.) in the Makefile
2323 sub generate_list($$$;$)
2332 printf FILEO "%-22s=",$name;
2334 if (defined $list) {
2335 foreach my $item (@$list) {
2337 if (defined $data) {
2338 $value=&$data($item);
2340 if (defined $item) {
2348 print FILEO " $value";
2351 print FILEO " \\\n\t\t\t$value";
2362 # Generates a project's Makefile
and all the target files
2363 sub generate_project_files
($)
2366 my $project_settings=@
$project[$P_SETTINGS];
2371 # Then sort the targets and separate the libraries from the programs
2372 foreach my $target (sort { @
$a[$T_NAME] cmp @
$b[$T_NAME] } @
{@
$project[$P_TARGETS]}) {
2373 if (@
$target[$T_TYPE] == $TT_DLL) {
2374 push @dll_list,$target;
2375 } elsif (@
$target[$T_TYPE] == $TT_LIB) {
2376 push @lib_list,$target;
2378 push @exe_list,$target;
2381 @
$project[$P_TARGETS]=[];
2382 push @
{@
$project[$P_TARGETS]}, @dll_list;
2383 push @
{@
$project[$P_TARGETS]}, @lib_list;
2384 push @
{@
$project[$P_TARGETS]}, @exe_list;
2386 if (!open(FILEO
,">@$project[$P_PATH]Makefile")) {
2387 print STDERR
"error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2388 print STDERR
" $!\n";
2391 binmode( FILEO
, ':utf8' );
2394 if (@
$project_settings[$T_FLAGS] & $TF_HASCXX) {
2395 $cpp_to_object=".cxx=.o";
2397 $cpp_to_object=".cpp=.o";
2400 print FILEO
"### Generated by Winemaker $version\n";
2401 print FILEO
"###\n";
2402 print FILEO
"### Invocation command line was\n";
2403 print FILEO
"### $0";
2407 print FILEO
"\n\n\n";
2409 generate_list
("SRCDIR",1,[ "." ]);
2410 if (@
$project[$P_PATH] eq "") {
2411 # This is the main project. It is also responsible for recursively
2412 # calling the other projects
2413 generate_list
("SUBDIRS",1,\
@projects,sub
2415 if ($_[0] != \
@main_project) {
2416 my $subdir=@
{$_[0]}[$P_PATH];
2420 # Eliminating the main project by returning undefined!
2423 if (@
{@
$project[$P_TARGETS]} > 0) {
2424 generate_list
("DLLS",1,\
@dll_list,sub
2426 return @
{$_[0]}[$T_NAME];
2428 generate_list
("LIBS",1,\
@lib_list,sub
2430 return @
{$_[0]}[$T_NAME];
2432 generate_list
("EXES",1,\
@exe_list,sub
2434 return "@{$_[0]}[$T_NAME]";
2436 print FILEO
"\n\n\n";
2438 print FILEO
"### Common settings\n\n";
2439 # Make it so that the project-wide settings override the global settings
2440 generate_list
("CEXTRA",1,@
$project_settings[$T_CEXTRA]);
2441 generate_list
("CXXEXTRA",1,@
$project_settings[$T_CXXEXTRA]);
2442 generate_list
("RCEXTRA",1,@
$project_settings[$T_RCEXTRA]);
2443 generate_list
("DEFINES",1,@
$project_settings[$T_DEFINES]);
2444 generate_list
("INCLUDE_PATH",1,@
$project_settings[$T_INCLUDE_PATH]);
2445 generate_list
("DLL_PATH",1,@
$project_settings[$T_DLL_PATH]);
2446 generate_list
("DLL_IMPORTS",1,@
$project_settings[$T_DLLS]);
2447 generate_list
("LIBRARY_PATH",1,@
$project_settings[$T_LIBRARY_PATH]);
2448 generate_list
("LIBRARIES",1,@
$project_settings[$T_LIBRARIES]);
2451 my $extra_source_count=@
{@
$project_settings[$T_SOURCES_C]}+
2452 @
{@
$project_settings[$T_SOURCES_CXX]}+
2453 @
{@
$project_settings[$T_SOURCES_RC]};
2454 my $no_extra=($extra_source_count == 0);
2456 print FILEO
"### Extra source lists\n\n";
2457 generate_list
("EXTRA_C_SRCS",1,@
$project_settings[$T_SOURCES_C]);
2458 generate_list
("EXTRA_CXX_SRCS",1,@
$project_settings[$T_SOURCES_CXX]);
2459 generate_list
("EXTRA_RC_SRCS",1,@
$project_settings[$T_SOURCES_RC]);
2461 generate_list
("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:$cpp_to_object)"]);
2462 print FILEO
"\n\n\n";
2465 # Iterate over all the targets...
2466 foreach my $target (@
{@
$project[$P_TARGETS]}) {
2467 print FILEO
"### @$target[$T_NAME] sources and settings\n\n";
2468 my $canon=canonize
("@$target[$T_NAME]");
2471 generate_list
("${canon}_MODULE",1,[@
$target[$T_NAME]]);
2472 generate_list
("${canon}_C_SRCS",1,@
$target[$T_SOURCES_C]);
2473 generate_list
("${canon}_CXX_SRCS",1,@
$target[$T_SOURCES_CXX]);
2474 generate_list
("${canon}_RC_SRCS",1,@
$target[$T_SOURCES_RC]);
2475 generate_list
("${canon}_LDFLAGS",1,@
$target[$T_LDFLAGS]);
2476 generate_list
("${canon}_ARFLAGS",1,@
$target[$T_ARFLAGS]);
2477 generate_list
("${canon}_DLL_PATH",1,@
$target[$T_DLL_PATH]);
2478 generate_list
("${canon}_DLLS",1,@
$target[$T_DLLS]);
2479 generate_list
("${canon}_LIBRARY_PATH",1,@
$target[$T_LIBRARY_PATH]);
2480 generate_list
("${canon}_LIBRARIES",1,@
$target[$T_LIBRARIES]);
2482 generate_list
("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:$cpp_to_object)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2483 print FILEO
"\n\n\n";
2485 print FILEO
"### Global source lists\n\n";
2486 generate_list
("C_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2488 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2490 return "\$(${canon}_C_SRCS)";
2493 generate_list
("",1,[ "\$(EXTRA_C_SRCS)" ]);
2495 generate_list
("CXX_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2497 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2499 return "\$(${canon}_CXX_SRCS)";
2502 generate_list
("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2504 generate_list
("RC_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2506 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2508 return "\$(${canon}_RC_SRCS)";
2511 generate_list
("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2515 print FILEO
"### Tools\n\n";
2516 print FILEO
"CC = winegcc\n";
2517 print FILEO
"CXX = wineg++\n";
2518 print FILEO
"RC = wrc\n";
2519 print FILEO
"AR = ar\n";
2522 print FILEO
"### Generic targets\n\n";
2524 if (@
$project[$P_PATH] eq "") {
2525 print FILEO
" \$(SUBDIRS)";
2527 if (@
{@
$project[$P_TARGETS]} > 0) {
2528 print FILEO
" \$(DLLS:%=%.so) \$(LIBS) \$(EXES)";
2531 print FILEO
"### Build rules\n";
2533 print FILEO
".PHONY: all clean dummy\n";
2535 print FILEO
"\$(SUBDIRS): dummy\n";
2536 print FILEO
"\t\@cd \$\@ && \$(MAKE)\n";
2538 print FILEO
"# Implicit rules\n";
2540 print FILEO
".SUFFIXES: .cpp .cxx .rc .res\n";
2541 print FILEO
"DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2543 print FILEO
".c.o:\n";
2544 print FILEO
"\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2546 print FILEO
".cpp.o:\n";
2547 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2549 print FILEO
".cxx.o:\n";
2550 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2552 print FILEO
".rc.res:\n";
2553 print FILEO
"\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2555 print FILEO
"# Rules for cleaning\n";
2557 print FILEO
"CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2558 print FILEO
" \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2560 print FILEO
"clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2561 print FILEO
"\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:$cpp_to_object)\n";
2562 print FILEO
"\t\$(RM) \$(DLLS:%=%.so) \$(LIBS) \$(EXES) \$(EXES:%=%.so)\n";
2564 print FILEO
"\$(SUBDIRS:%=%/__clean__): dummy\n";
2565 print FILEO
"\tcd `dirname \$\@` && \$(MAKE) clean\n";
2567 print FILEO
"\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2568 print FILEO
"\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2571 if (@
{@
$project[$P_TARGETS]} > 0) {
2572 print FILEO
"### Target specific build rules\n";
2573 print FILEO
"DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2574 foreach my $target (@
{@
$project[$P_TARGETS]}) {
2575 my $canon=canonize
("@$target[$T_NAME]");
2578 if (@
$target[$T_TYPE] == $TT_DLL && (@
$project_settings[$T_FLAGS] & $TF_HASDEF)) {
2579 print FILEO
"\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.def)\n";
2580 } elsif (@
$target[$T_TYPE] == $TT_DLL) {
2581 print FILEO
"\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.spec)\n";
2583 print FILEO
"\$(${canon}_MODULE): \$(${canon}_OBJS)\n";
2586 if (@
$target[$T_TYPE] == $TT_LIB) {
2587 print FILEO
"\t\$(AR) \$(${canon}_ARFLAGS) \$\@ \$(${canon}_OBJS)\n";
2589 if (@
{@
$target[$T_SOURCES_CXX]} > 0 or @
{@
$project_settings[$T_SOURCES_CXX]} > 0) {
2590 print FILEO
"\t\$(CXX)";
2592 print FILEO
"\t\$(CC)";
2594 print FILEO
" \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(${canon}_DLL_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2605 # This is where we finally generate files. In fact this method does not
2606 # do anything itself but calls the methods that do the actual work.
2609 print "Generating project files...\n";
2611 foreach my $project (@projects) {
2612 my $path=@
$project[$P_PATH];
2619 generate_project_files
($project);
2632 $opt_lower=$OPT_LOWER_UPPERCASE;
2633 $opt_lower_include=1;
2635 $opt_work_dir=undef;
2636 $opt_single_target=undef;
2637 $opt_target_type=$TT_GUIEXE;
2639 $opt_arch=$OPT_ARCH_DEFAULT;
2640 $opt_is_interactive=$OPT_ASK_NO;
2641 $opt_ask_project_options=$OPT_ASK_NO;
2642 $opt_ask_target_options=$OPT_ASK_NO;
2643 $opt_no_generated_files=0;
2644 $opt_no_source_fix=0;
2657 print "Winemaker $version\n";
2658 print "Copyright 2000-2004 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2659 print "Copyright 2004 Dimitrie O. Paun\n";
2660 print "Copyright 2009-2012 André Hentschel\n";
2666 print STDERR
"Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2667 print STDERR
" [--lower-none|--lower-all|--lower-uppercase]\n";
2668 print STDERR
" [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2669 print STDERR
" [--guiexe|--windows|--cuiexe|--console|--dll|--lib]\n";
2670 print STDERR
" [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2671 print STDERR
" [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2672 print STDERR
" [--generated-files|--nogenerated-files]\n";
2673 print STDERR
" [--wine32]\n";
2674 print STDERR
" work_directory|project_file|workspace_file\n";
2675 print STDERR
"\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2676 print STDERR
"the specified directory or project-file, so that they can be compiled with Winelib.\n";
2677 print STDERR
"During this process it will modify and rename some of the corresponding files.\n";
2678 print STDERR
"\tPlease read the manual page before use.\n";
2682 target_init
(\
@global_settings);
2687 if ($arg eq "--nobanner") {
2689 } elsif ($arg eq "--backup") {
2691 } elsif ($arg eq "--nobackup") {
2693 } elsif ($arg eq "--single-target") {
2694 $opt_single_target=shift @ARGV;
2695 } elsif ($arg eq "--lower-none") {
2696 $opt_lower=$OPT_LOWER_NONE;
2697 } elsif ($arg eq "--lower-all") {
2698 $opt_lower=$OPT_LOWER_ALL;
2699 } elsif ($arg eq "--lower-uppercase") {
2700 $opt_lower=$OPT_LOWER_UPPERCASE;
2701 } elsif ($arg eq "--lower-include") {
2702 $opt_lower_include=1;
2703 } elsif ($arg eq "--nolower-include") {
2704 $opt_lower_include=0;
2705 } elsif ($arg eq "--nosource-fix") {
2706 $opt_no_source_fix=1;
2707 } elsif ($arg eq "--generated-files") {
2708 $opt_no_generated_files=0;
2709 } elsif ($arg eq "--nogenerated-files") {
2710 $opt_no_generated_files=1;
2711 } elsif ($arg eq "--wine32") {
2712 $opt_arch=$OPT_ARCH_32;
2713 } elsif ($arg =~ /^-D/) {
2714 push @
{$global_settings[$T_DEFINES]},$arg;
2715 } elsif ($arg =~ /^-I/) {
2716 push @
{$global_settings[$T_INCLUDE_PATH]},$arg;
2717 } elsif ($arg =~ /^-P/) {
2718 push @
{$global_settings[$T_DLL_PATH]},"-L$'";
2719 } elsif ($arg =~ /^-i/) {
2720 push @
{$global_settings[$T_DLLS]},$';
2721 } elsif ($arg =~ /^-L/) {
2722 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2723 } elsif ($arg =~ /^-l/) {
2724 push @{$global_settings[$T_LIBRARIES]},$arg;
2726 # 'Source
'-based method options
2727 } elsif ($arg eq "--dll") {
2728 $opt_target_type=$TT_DLL;
2729 } elsif ($arg eq "--lib") {
2730 $opt_target_type=$TT_LIB;
2731 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2732 $opt_target_type=$TT_GUIEXE;
2733 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2734 $opt_target_type=$TT_CUIEXE;
2735 } elsif ($arg eq "--interactive") {
2736 $opt_is_interactive=$OPT_ASK_YES;
2737 $opt_ask_project_options=$OPT_ASK_YES;
2738 $opt_ask_target_options=$OPT_ASK_YES;
2739 } elsif ($arg eq "--mfc") {
2740 $opt_flags|=$TF_MFC;
2741 } elsif ($arg eq "--nomfc") {
2742 $opt_flags&=~$TF_MFC;
2743 $opt_flags|=$TF_NOMFC;
2744 } elsif ($arg eq "--nodlls") {
2745 $opt_flags|=$TF_NODLLS;
2746 } elsif ($arg eq "--nomsvcrt") {
2747 $opt_flags|=$TF_NOMSVCRT;
2751 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2752 if (!defined $opt_work_dir and !defined $opt_work_file) {
2754 $opt_work_file=$arg;
2760 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2769 if (!defined $opt_work_dir and !defined $opt_work_file) {
2770 print STDERR "error: you must specify the directory or project file containing the sources to be converted\n";
2772 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2773 print STDERR "error: could not chdir to the work directory\n";
2774 print STDERR " $!\n";
2778 if ($opt_no_banner == 0) {
2782 project_init(\@main_project, "", \@global_settings);
2784 # Fix the file and directory names
2785 fix_file_and_directory_names(".");
2787 # Scan the sources to identify the projects and targets
2790 # Fix the source files
2791 if (! $opt_no_source_fix) {
2795 # Generate the Makefile and the spec file
2796 if (! $opt_no_generated_files) {