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;
962 my @addincl = split(/\s*;\s*/, $configt);
963 foreach $configt (@addincl) {
964 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I".$configt;
969 if ($find_tool[0]->getValue eq "VCLinkerTool") {
970 foreach my $vc_linker_tool ($vc_configuration_tools->attributes) {
971 if ($vc_linker_tool->getName eq "AdditionalDependencies") {
972 $prj_target_libs=" ".$vc_linker_tool->getValue;
973 $prj_target_libs=~s/\\/\//g
;
974 $prj_target_libs=~s/\.lib//g;
975 $prj_target_libs=~s/\s+/ -l/g;
981 push @
{@
$project_settings[$T_LIBRARIES]},$prj_target_libs;
982 push @
{@
$project_settings[$T_CEXTRA]},$prj_target_cflags;
983 push @
{@
$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
984 push @
{@
$project_settings[$T_DEFINES]},$prj_target_defines;
986 print STDERR
"File format not supported for file: $filename\n";
990 # Add this project to the project list, except for
991 # the main project which is already in the list.
992 if ($is_sub_project == 1) {
993 push @projects,$project;
996 # Ask for project-wide options
997 if ($opt_ask_project_options == $OPT_ASK_YES) {
999 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1002 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1003 if (defined $flag_desc) {
1004 print "* (currently $flag_desc)\n";
1006 print "* or 'skip' to skip the target specific options,\n";
1007 print "* or 'never' to not be asked this question again:\n";
1009 my $options=<STDIN
>;
1011 if ($options eq "skip") {
1012 $opt_ask_target_options=$OPT_ASK_SKIP;
1014 } elsif ($options eq "never") {
1015 $opt_ask_project_options=$OPT_ASK_NO;
1017 } elsif (source_set_options
($project_settings,$options)) {
1020 print "Please re-enter the options:\n";
1024 # Create the target...
1026 target_init
($target);
1028 if ($prj_target_type==$TT_GUIEXE or $prj_target_type==$TT_CUIEXE) {
1029 $prj_name=lc($prj_name.".exe");
1030 @
$target[$T_TYPE]=$opt_target_type;
1031 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
1032 } elsif ($prj_target_type==$TT_LIB) {
1033 $prj_name=lc("lib".$prj_name.".a");
1034 @
$target[$T_TYPE]=$TT_LIB;
1035 push @
{@
$target[$T_ARFLAGS]},("rc");
1037 $prj_name=lc($prj_name.".dll");
1038 @
$target[$T_TYPE]=$TT_DLL;
1039 my $canon=canonize
($prj_name);
1040 if (@
$project_settings[$T_FLAGS] & $TF_HASDEF) {
1041 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.def)");
1043 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1047 @
$target[$T_NAME]=$prj_name;
1048 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
1050 # This is the default link list of Visual Studio
1051 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1052 my @std_libraries=qw(uuid);
1053 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1054 @
$target[$T_DLLS]=\
@std_imports;
1055 @
$target[$T_LIBRARIES]=\
@std_libraries;
1057 @
$target[$T_DLLS]=[];
1058 @
$target[$T_LIBRARIES]=[];
1060 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1061 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
1062 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1063 push @
{@
$target[$T_LDFLAGS]},"-m$opt_arch";
1066 push @
{@
$project[$P_TARGETS]},$target;
1068 # Ask for target-specific options
1069 if ($opt_ask_target_options == $OPT_ASK_YES) {
1071 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
1074 if ($flag_desc ne "") {
1077 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1078 print "* \"$prj_name\"$flag_desc or 'never' to not be asked this question again:\n";
1080 my $options=<STDIN
>;
1082 if ($options eq "never") {
1083 $opt_ask_target_options=$OPT_ASK_NO;
1085 } elsif (source_set_options
($target,$options)) {
1088 print "Please re-enter the options:\n";
1091 if (@
$target[$T_FLAGS] & $TF_MFC) {
1092 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1093 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1094 push @
{@
$target[$T_DLLS]},"mfc.dll";
1095 # FIXME: Link with the MFC in the Unix sense, until we
1096 # start exporting the functions properly.
1097 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1098 push @
{@
$target[$T_LIBRARIES]},"mfc";
1102 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
1103 @
$project_settings[$T_SOURCES_C]=[];
1105 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1106 @
$project_settings[$T_SOURCES_CXX]=[];
1108 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
1109 @
$project_settings[$T_SOURCES_RC]=[];
1111 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
1112 @
$project_settings[$T_SOURCES_MISC]=[];
1115 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
1116 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
1117 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
1118 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
1120 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1121 $opt_ask_target_options=$OPT_ASK_YES;
1124 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1125 push @
{@
$project_settings[$T_CEXTRA]},"-mno-cygwin";
1126 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1127 push @
{@
$project_settings[$T_CEXTRA]},"-m$opt_arch";
1128 push @
{@
$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1132 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
1133 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1135 # The sources that did not match, if any, go to the extra
1136 # source list of the project settings
1137 foreach my $source (@sources_c) {
1138 if ($source ne "") {
1139 push @
{@
$project_settings[$T_SOURCES_C]},$source;
1142 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
1143 foreach my $source (@sources_cxx) {
1144 if ($source ne "") {
1145 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
1148 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
1149 foreach my $source (@sources_rc) {
1150 if ($source ne "") {
1151 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
1154 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
1155 foreach my $source (@sources_misc) {
1156 if ($source ne "") {
1157 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
1160 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
1164 # Scans the specified workspace file to find the project files
1165 sub source_scan_workspace_file
($);
1166 sub source_scan_workspace_file
($)
1169 my $path=dirname
($filename);
1172 if (! -e
$filename) {
1176 if (!open(FILEIWS
,$filename)) {
1177 print STDERR
"error: unable to open $filename for reading:\n";
1178 print STDERR
" $!\n";
1185 if ($filename =~ /.dsw$/i) {
1187 # Remove any trailing CrLf
1190 # catch a project definition
1191 if (/^Project:\s\"(.*)\"=(.*)\s-/) {
1194 @components=split /[\/\\]+/, $prj_path;
1195 $prj_path=search_from
($path, \
@components);
1196 print "Name: $prj_name\nPath: $prj_path\n";
1197 source_scan_project_file
(\
@main_project,1,$prj_path);
1201 } elsif (/^Global:/) {
1202 # ignore the Global section
1204 print STDERR
"unknown section $_\n";
1205 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1206 print "\nFileversion: $3\n";
1210 } elsif ($filename =~ /.sln$/i) {
1212 # Remove any trailing CrLf
1215 # catch a project definition
1216 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1219 if ($prj_path eq "Solution Items") { next; }
1220 @components=split /[\/\\]+/, $3;
1221 $prj_path=search_from
($path, \
@components);
1222 print "Name: $prj_name\nPath: $prj_path\n";
1223 source_scan_project_file
(\
@main_project,1,$prj_path);
1225 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1226 print "\nFileversion: $3\n";
1232 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
1236 # Scans the specified directory to:
1237 # - see if we should create a Makefile in this directory. We normally do
1238 # so if we find a project file and sources
1239 # - get a list of targets for this directory
1240 # - get the list of source files
1241 sub source_scan_directory
($$$$);
1242 sub source_scan_directory
($$$$)
1244 # a reference to the parent's project
1245 my $parent_project=$_[0];
1246 # the full relative path to the current directory, including a
1247 # trailing '/', or an empty string if this is the top level directory
1249 # the name of this directory, including a trailing '/', or an empty
1250 # string if this is the top level directory
1252 # if set then no targets will be looked for and the sources will all
1253 # end up in the parent_project's 'misc' bucket
1254 my $no_target=$_[3];
1256 # reference to the project for this directory. May not be used
1258 # list of targets found in the 'current' directory
1260 # list of sources found in the current directory
1264 my @sources_misc=();
1265 # true if this directory contains a Windows project
1266 my $has_win_project=0;
1267 # true if this directory contains headers
1269 # If we don't find any executable/library then we might make up targets
1270 # from the list of .dsp/.mak files we find since they usually have the
1271 # same name as their target.
1275 if (defined $opt_single_target or $dirname eq "") {
1276 # Either there is a single target and thus a single project,
1277 # or we are in the top level directory for which a project
1279 $project=$parent_project;
1282 project_init
($project, $path, \
@global_settings);
1284 my $project_settings=@
$project[$P_SETTINGS];
1286 # First find out what this directory contains:
1287 # collect all sources, targets and subdirectories
1288 my $directory=get_directory_contents
($path);
1289 foreach my $dentry (@
$directory) {
1290 if ($dentry =~ /^\./) {
1293 my $fullentry="$path$dentry";
1294 if (-d
"$fullentry") {
1295 if ($dentry =~ /^(Release|Debug)/i) {
1296 # These directories are often used to store the object files and the
1297 # resulting executable/library. They should not contain anything else.
1298 my @candidates=grep /\.(exe|dll|lib)$/i, @
{get_directory_contents
("$fullentry")};
1299 foreach my $candidate (sort @candidates) {
1300 my $dlldup = $candidate;
1301 $dlldup =~ s/\.lib$/.dll/;
1302 if ($candidate =~ /\.lib$/ and $targets{$dlldup})
1304 # Often lib files are created together with dll files, even if the dll file is the
1308 $targets{$candidate}=1;
1310 } elsif ($dentry =~ /^include/i) {
1311 # This directory must contain headers we're going to need
1312 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1313 source_scan_directory
($project,"$fullentry/","$dentry/",1);
1315 # Recursively scan this directory. Any source file that cannot be
1316 # attributed to a project in one of the subdirectories will be
1317 # attributed to this project.
1318 source_scan_directory
($project,"$fullentry/","$dentry/",$no_target);
1320 } elsif (-f
"$fullentry") {
1321 if ($dentry =~ /\.(exe|dll|lib)$/i) {
1322 $targets{$dentry}=1;
1323 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1324 push @sources_c,"$dentry";
1325 } elsif ($dentry =~ /\.cpp$/i) {
1326 if ($dentry =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1327 push @sources_misc,"$dentry";
1328 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1330 push @sources_cxx,"$dentry";
1332 } elsif ($dentry =~ /\.cxx$/i) {
1333 @
$project_settings[$T_FLAGS]|=$TF_HASCXX;
1334 push @sources_cxx,"$dentry";
1335 } elsif ($dentry =~ /\.rc$/i) {
1336 push @sources_rc,"$dentry";
1337 } elsif ($dentry =~ /\.def$/i) {
1338 @
$project_settings[$T_FLAGS]|=$TF_HASDEF;
1339 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1341 push @sources_misc,"$dentry";
1342 if ($dentry =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1343 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1345 } elsif ($dentry =~ /\.(dsp|vcproj)$/i) {
1346 push @prj_files,"$dentry";
1348 } elsif ($dentry =~ /\.mak$/i) {
1349 push @mak_files,"$dentry";
1351 } elsif ($dentry =~ /^makefile/i) {
1358 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I.";
1360 # If we have a single target then all we have to do is assign
1361 # all the sources to it and we're done
1362 # FIXME: does this play well with the --interactive mode?
1363 if ($opt_single_target) {
1364 my $target=@
{@
$project[$P_TARGETS]}[0];
1365 push @
{@
$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1366 push @
{@
$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1367 push @
{@
$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1368 push @
{@
$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1372 my $parent_settings=@
$parent_project[$P_SETTINGS];
1373 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1374 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1375 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1376 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1377 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1381 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1382 @
{@
$project_settings[$T_SOURCES_C]}+
1383 @
{@
$project_settings[$T_SOURCES_CXX]}+
1384 @
{@
$project_settings[$T_SOURCES_RC]};
1385 if ($source_count == 0) {
1386 # A project without real sources is not a project, get out!
1387 if ($project!=$parent_project) {
1388 my $parent_settings=@
$parent_project[$P_SETTINGS];
1389 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1390 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1394 #print "targets=",%targets,"\n";
1395 #print "target_count=$target_count\n";
1396 #print "has_win_project=$has_win_project\n";
1397 #print "dirname=$dirname\n";
1400 if (($has_win_project != 0) or ($dirname eq "")) {
1401 # Deal with cases where we could not find any executable/library, and
1402 # thus have no target, although we did find some sort of windows project.
1403 $target_count=keys %targets;
1404 if ($target_count == 0) {
1405 # Try to come up with a target list based on .dsp/.mak files
1407 if (@prj_files > 0) {
1408 print "Projectfile found! You might want to try using it directly.\n";
1409 $prj_list=\
@prj_files;
1411 $prj_list=\
@mak_files;
1413 foreach my $filename (@
$prj_list) {
1414 $filename =~ s/\.(dsp|vcproj|mak)$//i;
1415 if ($opt_target_type == $TT_DLL) {
1416 $filename = "$filename.dll";
1418 $targets{$filename}=1;
1420 $target_count=keys %targets;
1421 if ($target_count == 0) {
1422 # Still nothing, try the name of the directory
1424 if ($dirname eq "") {
1425 # Bad luck, this is the top level directory!
1426 $name=(split /\//, cwd
)[-1];
1429 # Remove the trailing '/'. Also eliminate whatever is after the last
1430 # '.' as it is likely to be meaningless (.orig, .new, ...)
1431 $name =~ s
+(/|\
.[^.]*)$++;
1432 if ($name eq "src") {
1433 # 'src' is probably a subdirectory of the real project directory.
1434 # Try again with the parent (if any).
1436 if ($parent =~ s
+([^/]*)/[^/]*/$+$1+) {
1439 $name=(split /\//, cwd
)[-1];
1443 $name =~ s
+(/|\
.[^.]*)$++;
1444 if ($opt_target_type == $TT_DLL) {
1445 $name = canonize
($name).".dll";
1446 } elsif ($opt_target_type == $TT_LIB) {
1447 $name = "lib".canonize
($name).".a";
1449 $name = canonize
($name).".exe";
1455 # Ask confirmation to the user if he wishes so
1456 if ($opt_is_interactive == $OPT_ASK_YES) {
1457 my $target_list=join " ",keys %targets;
1458 print "\n*** In ",($path?
$path:"./"),"\n";
1459 print "* winemaker found the following list of (potential) targets\n";
1460 print "* $target_list\n";
1461 print "* Type enter to use it as is, your own comma-separated list of\n";
1462 print "* targets, 'none' to assign the source files to a parent directory,\n";
1463 print "* or 'ignore' to ignore everything in this directory tree.\n";
1464 print "* Target list:\n";
1465 $target_list=<STDIN
>;
1467 if ($target_list eq "") {
1468 # Keep the target list as is, i.e. do nothing
1469 } elsif ($target_list eq "none") {
1470 # Empty the target list
1472 } elsif ($target_list eq "ignore") {
1473 # Ignore this subtree altogether
1477 foreach my $target (split /,/,$target_list) {
1478 $target =~ s
+^\s
*++;
1479 $target =~ s
+\s
*$++;
1480 $targets{$target}=1;
1486 # If we have no project at this level, then transfer all
1487 # the sources to the parent project
1488 $target_count=keys %targets;
1489 if ($target_count == 0) {
1490 if ($project!=$parent_project) {
1491 my $parent_settings=@
$parent_project[$P_SETTINGS];
1492 push @
{@
$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1493 push @
{@
$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1494 push @
{@
$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1495 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1496 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1501 # Otherwise add this project to the project list, except for
1502 # the main project which is already in the list.
1503 if ($dirname ne "") {
1504 push @projects,$project;
1507 # Ask for project-wide options
1508 if ($opt_ask_project_options == $OPT_ASK_YES) {
1510 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1513 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1514 if (defined $flag_desc) {
1515 print "* (currently $flag_desc)\n";
1517 print "* or 'skip' to skip the target specific options,\n";
1518 print "* or 'never' to not be asked this question again:\n";
1520 my $options=<STDIN
>;
1522 if ($options eq "skip") {
1523 $opt_ask_target_options=$OPT_ASK_SKIP;
1525 } elsif ($options eq "never") {
1526 $opt_ask_project_options=$OPT_ASK_NO;
1528 } elsif (source_set_options
($project_settings,$options)) {
1531 print "Please re-enter the options:\n";
1535 # - Create the targets
1536 # - Check if we have both libraries and programs
1537 # - Match each target with source files (sort in reverse
1538 # alphabetical order to get the longest matches first)
1541 my @local_depends=();
1543 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1544 # Create the target...
1546 target_init
($target);
1547 @
$target[$T_NAME]=$target_name;
1548 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
1549 if ($target_name =~ /\.dll$/) {
1550 @
$target[$T_TYPE]=$TT_DLL;
1551 push @local_depends,"$target_name.so";
1552 push @local_dlls,$target_name;
1553 my $canon=canonize
($target_name);
1554 if (@
$project_settings[$T_FLAGS] & $TF_HASDEF) {
1555 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.def)");
1557 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1559 } elsif ($target_name =~ /\.lib$/) {
1560 $target_name =~ s/(.*)\.lib/lib$1.a/;
1561 @
$target[$T_NAME]=$target_name;
1562 @
$target[$T_TYPE]=$TT_LIB;
1563 push @local_depends,"$target_name";
1564 push @local_libs,$target_name;
1565 push @
{@
$target[$T_ARFLAGS]},("rc");
1566 } elsif ($target_name =~ /\.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");
1573 @
$target[$T_TYPE]=$opt_target_type;
1574 push @exe_list,$target;
1575 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
1577 my $basename=$target_name;
1578 $basename=~ s/\.(dll|exe)$//i;
1579 # This is the default link list of Visual Studio
1580 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1581 my @std_libraries=qw(uuid);
1582 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1583 @
$target[$T_DLLS]=\
@std_imports;
1584 @
$target[$T_LIBRARIES]=\
@std_libraries;
1586 @
$target[$T_DLLS]=[];
1587 @
$target[$T_LIBRARIES]=[];
1589 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1590 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
1591 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1592 push @
{@
$target[$T_LDFLAGS]},"-m$opt_arch";
1595 push @
{@
$project[$P_TARGETS]},$target;
1597 # Ask for target-specific options
1598 if ($opt_ask_target_options == $OPT_ASK_YES) {
1600 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
1603 if ($flag_desc ne "") {
1606 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1607 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1609 my $options=<STDIN
>;
1611 if ($options eq "never") {
1612 $opt_ask_target_options=$OPT_ASK_NO;
1614 } elsif (source_set_options
($target,$options)) {
1617 print "Please re-enter the options:\n";
1620 if (@
$target[$T_FLAGS] & $TF_MFC) {
1621 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1622 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1623 push @
{@
$target[$T_DLLS]},"mfc.dll";
1624 # FIXME: Link with the MFC in the Unix sense, until we
1625 # start exporting the functions properly.
1626 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1627 push @
{@
$target[$T_LIBRARIES]},"mfc";
1631 if ($target_count == 1) {
1632 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
1633 @
$project_settings[$T_SOURCES_C]=[];
1636 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1637 @
$project_settings[$T_SOURCES_CXX]=[];
1640 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
1641 @
$project_settings[$T_SOURCES_RC]=[];
1644 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
1645 # No need for sorting these sources
1646 @
$project_settings[$T_SOURCES_MISC]=[];
1649 foreach my $source (@sources_c) {
1650 if ($source =~ /^$basename/i) {
1651 push @
{@
$target[$T_SOURCES_C]},$source;
1655 foreach my $source (@sources_cxx) {
1656 if ($source =~ /^$basename/i) {
1657 push @
{@
$target[$T_SOURCES_CXX]},$source;
1661 foreach my $source (@sources_rc) {
1662 if ($source =~ /^$basename/i) {
1663 push @
{@
$target[$T_SOURCES_RC]},$source;
1667 foreach my $source (@sources_misc) {
1668 if ($source =~ /^$basename/i) {
1669 push @
{@
$target[$T_SOURCES_MISC]},$source;
1674 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
1675 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
1676 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
1677 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
1679 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1680 $opt_ask_target_options=$OPT_ASK_YES;
1683 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1684 push @
{@
$project_settings[$T_CEXTRA]},"-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 if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
1869 } elsif ($dirname !~ m
+^/+) {
1870 $dirname=cwd
. "/" . $dirname;
1872 if ($dirname !~ m
+/$+) {
1876 foreach my $component (@
$path) {
1877 $component=~s/^\"//;
1878 $component=~s/\"$//;
1879 #print " looking for $component in \"$dirname\"\n";
1880 if ($component eq ".") {
1883 } elsif ($component eq "..") {
1885 if ($dirname =~ /\.\.\/$/) {
1888 $dirname=dirname
($dirname) . "/";
1892 # The file/directory may have been renamed before. Also try to
1893 # match the renamed file.
1894 my $renamed=$component;
1895 $renamed =~ s/[ \$]/_/g;
1896 if ($renamed eq $component) {
1900 my $directory=get_directory_contents
$dirname;
1902 foreach my $dentry (@
$directory) {
1903 if ($dentry =~ /^\Q$component\E$/i or
1904 (defined $renamed and $dentry =~ /^$renamed$/i)
1906 $dirname.="$dentry/";
1907 $real_path.="$dentry/";
1912 if (!defined $found) {
1914 #print " could not find $component in $dirname\n";
1919 $real_path=~ s
+/$++;
1920 #print " -> found $real_path\n";
1925 # Performs a case-insensitive search for the specified file in the
1927 # $line is the line number that should be referenced when an error occurs
1928 # $filename is the file we are looking for
1929 # $dirname is the directory of the file containing the '#include' directive
1930 # if '"' was used, it is an empty string otherwise
1931 # $project and $target specify part of the include path
1932 sub get_real_include_name
($$$$$)
1940 if ($filename =~ /^([a-zA-Z]:)?[\/\\]/ or $filename =~ /^[a
-zA
-Z
]:[\
/\\]?/) {
1941 # This is not a relative path, we cannot make any check
1942 my $warning="path:$filename";
1943 if (!defined $warnings{$warning}) {
1944 $warnings{$warning}="1";
1945 print STDERR
"warning: cannot check the case of absolute pathnames:\n";
1946 print STDERR
"$line: $filename\n";
1949 # Here's how we proceed:
1950 # - split the filename we look for into its components
1951 # - then for each directory in the include path
1952 # - trace the directory components starting from that directory
1953 # - if we fail to find a match at any point then continue with
1954 # the next directory in the include path
1955 # - otherwise, rejoice, our quest is over.
1956 my @file_components=split /[\/\\]+/, $filename;
1957 #print " Searching for $filename from @$project[$P_PATH]\n";
1960 if ($dirname ne "") {
1961 # This is an 'include ""' -> look in dirname first.
1962 #print " in $dirname (include \"\")\n";
1963 $real_filename=search_from
($dirname,\
@file_components);
1964 if (defined $real_filename) {
1965 return $real_filename;
1968 my $project_settings=@
$project[$P_SETTINGS];
1969 foreach my $include (@
{@
$target[$T_INCLUDE_PATH]}, @
{@
$project_settings[$T_INCLUDE_PATH]}) {
1970 my $dirname=$include;
1973 if (!is_absolute
($dirname)) {
1974 $dirname="@$project[$P_PATH]$dirname";
1976 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)/++;
1977 $dirname=~ s
+^\
$\
(SRCDIR\
)/+@
$project[$P_PATH]+;
1979 #print " in $dirname\n";
1980 $real_filename=search_from
("$dirname",\
@file_components);
1981 if (defined $real_filename) {
1982 return $real_filename;
1985 my $dotdotpath=@
$project[$P_PATH];
1986 $dotdotpath =~ s/[^\/]+/../g
;
1987 foreach my $include (@
{$global_settings[$T_INCLUDE_PATH]}) {
1988 my $dirname=$include;
1990 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)\
/++;
1991 $dirname=~ s
+^\
$\
(SRCDIR\
)\
/+@
$project[$P_PATH]+;
1992 #print " in $dirname (global setting)\n";
1993 $real_filename=search_from
("$dirname",\
@file_components);
1994 if (defined $real_filename) {
1995 return $real_filename;
1999 $filename =~ s
+\\\\+/+g
; # in include ""
2000 $filename =~ s
+\\+/+g
; # in include <> !
2001 if ($opt_lower_include) {
2002 return lc "$filename";
2013 if ($size =~ /^(1|2|4|8)$/) {
2014 print FILEO
"$indent#include <pshpack$size.h>$trailer";
2016 print FILEO
"$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
2017 print FILEO
"$indent#include <pshpack4.h>$trailer";
2022 # 'Parses' a source file and fixes constructs that would not work with
2023 # Winelib. The parsing is rather simple and not all non-portable features
2024 # are corrected. The most important feature that is corrected is the case
2025 # and path separator of '#include' directives. This requires that each
2026 # source file be associated to a project & target so that the proper
2027 # include path is used.
2028 # Also note that the include path is relative to the directory in which the
2029 # compiler is run, i.e. that of the project, not to that of the file.
2035 $filename="@$project[$P_PATH]$filename";
2036 if (! -e
$filename) {
2040 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
2041 my $dirname=dirname
($filename);
2043 if (defined $target and (@
$target[$T_FLAGS] & $TF_MFC)) {
2047 print " $filename\n";
2048 if (! -e
"$filename.bak") {
2049 if (!copy
("$filename","$filename.bak")) {
2050 print STDERR
"error: unable to make a backup of $filename:\n";
2051 print STDERR
" $!\n";
2055 if (!open(FILEI
,"$filename.bak")) {
2056 print STDERR
"error: unable to open $filename.bak for reading:\n";
2057 print STDERR
" $!\n";
2060 if (!open(FILEO
,">$filename")) {
2061 print STDERR
"error: unable to open $filename for writing:\n";
2062 print STDERR
" $!\n";
2067 my $rc_block_depth=0;
2068 my $rc_textinclude_state=0;
2071 # Remove any trailing CtrlZ, which isn't strictly in the file
2079 # Make sure all files are '\n' terminated
2082 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
2083 # VC6 automatically includes 'afxres.h', an MFC specific header, in
2084 # the RC files it generates (even in non-MFC projects). So we replace
2085 # it with 'winresrc.h' its very close standard cousin so that non MFC
2086 # projects can compile in Wine without the MFC sources.
2087 my $warning="mfc:afxres.h";
2088 if (!defined $warnings{$warning}) {
2089 $warnings{$warning}="1";
2090 print STDERR
"warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
2091 print STDERR
"warning: the above warning is issued only once\n";
2093 print FILEO
"$1/* winemaker: $2\"afxres.h\" */\n";
2094 print FILEO
"$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
2095 print FILEO
"$1$2\"winresrc.h\"$'";
2098 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
2099 my $from_file=($2 eq "<"?
"":$dirname);
2100 my $real_include_name=get_real_include_name
($line,$3,$from_file,$project,$target);
2101 print FILEO
"$1$2$real_include_name$4$'";
2102 $modified|=($real_include_name ne $3);
2104 } elsif (/^(\s*)\#\s*pragma\s+comment\s*\(\s*lib\s*,\s*\"(\w+)\.lib\"\s*\)/) {
2105 my $pragma_indent=$1;
2107 push @
{@
$target[$T_LIBRARIES]},$pragma_lib;
2108 print FILEO
"$pragma_indent/* winemaker: Added -l$pragma_lib to the libraries */\n";
2109 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
2110 # Pragma pack handling
2112 # pack_stack is an array of references describing the stack of
2113 # pack directives currently in effect. Each directive if described
2114 # by a reference to an array containing:
2115 # - "push" for pack(push,...) directives, "" otherwise
2116 # - the directive's identifier at index 1
2117 # - the directive's alignment value at index 2
2119 # Don't believe a word of what the documentation says: it's all wrong.
2120 # The code below is based on the actual behavior of Visual C/C++ 6.
2125 # Pushes the default stack alignment
2126 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
2127 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2128 print_pack
($pack_indent,4,$');
2129 push @pack_stack, [ "", "", 4 ];
2131 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
2133 # pragma pack(pop,n)
2134 # Goes up the stack until it finds a pack(push,...), and pops it
2135 # Ignores any pack(n) entry
2136 # Issues a warning if the pack is of the form pack(push,label)
2137 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2138 my $pack_comment=$';
2139 $pack_comment =~ s/^\s*//;
2140 if ($pack_comment ne "") {
2141 print FILEO
"$pack_indent$pack_comment";
2144 my $alignment=pop @pack_stack;
2145 if (!defined $alignment) {
2146 print FILEO
"$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2149 if (@
$alignment[1]) {
2150 print FILEO
"$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2152 print FILEO
"$pack_indent#include <poppack.h>\n";
2153 if (@
$alignment[0]) {
2158 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2159 # pragma pack(pop,label[,n])
2160 # Goes up the stack until finding a pack(push,...) and pops it.
2161 # 'n', if specified, is ignored.
2162 # Ignores any pack(n) entry
2163 # Issues a warning if the label of the pack does not match,
2164 # or if it is in fact a pack(push,n)
2166 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
2167 my $pack_comment=$';
2168 $pack_comment =~ s/^\s*//;
2169 if ($pack_comment ne "") {
2170 print FILEO "$pack_indent$pack_comment";
2173 my $alignment=pop @pack_stack;
2174 if (!defined $alignment) {
2175 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2178 if (@$alignment[1] and @$alignment[1] ne $label) {
2179 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2181 print FILEO "$pack_indent#include <poppack.h>\n";
2182 if (@$alignment[0]) {
2187 } elsif (/^(push\s*\))/) {
2189 # Push the current alignment
2190 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2191 if (@pack_stack > 0) {
2192 my $alignment=$pack_stack[$#pack_stack];
2193 print_pack($pack_indent,@$alignment[2],$');
2194 push @pack_stack, [ "push", "", @
$alignment[2] ];
2196 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2197 print_pack
($pack_indent,4,$');
2198 push @pack_stack, [ "push", "", 4 ];
2201 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2202 # pragma pack([push,]n)
2203 # Push new alignment n
2204 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2205 print_pack($pack_indent,$3,"$'");
2206 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2208 } elsif (/^((\w+)\s*\))/) {
2209 # pragma pack(label)
2210 # label must in fact be a macro that resolves to an integer
2211 # Then behaves like 'pragma pack(n)'
2212 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2213 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2214 print_pack($pack_indent,4,$');
2215 push @pack_stack, [ "", "", 4 ];
2217 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2218 # pragma pack(push,label[,n])
2219 # Pushes a new label on the stack. It is possible to push the same
2220 # label multiple times. If 'n' is omitted then the alignment is
2221 # unchanged. Otherwise it becomes 'n'.
2222 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2226 } elsif (@pack_stack > 0) {
2227 my $alignment=$pack_stack[$#pack_stack];
2228 $size=@$alignment[2];
2230 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2233 print_pack($pack_indent,$size,$');
2234 push @pack_stack, [ "push", $2, $size ];
2237 # pragma pack(??? -> What's that?
2238 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2239 print FILEO "$pack_indent$pack_header$_";
2245 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]+)([\">]?)/) {
2246 my $from_file=($5 eq "<"?"":$dirname);
2247 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2248 print FILEO "$1$5$real_include_name$7$'";
2249 $modified|=($real_include_name ne $6);
2251 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2252 my $from_file=($2 eq "<"?"":$dirname);
2253 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2254 print FILEO "$1$2$real_include_name$4$'";
2255 $modified|=($real_include_name ne $3);
2257 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2258 $rc_textinclude_state=1;
2261 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2262 print FILEO "$1winresrc.h
$2$'";
2265 } elsif (/^\s*BEGIN(\W.*)?$/) {
2266 $rc_textinclude_state|=2;
2270 } elsif (/^\s*END(\W.*)?$/) {
2271 $rc_textinclude_state=0;
2272 if ($rc_block_depth>0) {
2288 if ($opt_backup == 0 or $modified == 0) {
2289 if (!unlink("$filename.bak")) {
2290 print STDERR "error: unable to delete $filename.bak:\n";
2291 print STDERR " $!\n";
2297 # Analyzes each source file in turn to find and correct issues
2298 # that would cause it not to compile.
2301 print "Fixing the source files...\n";
2302 foreach my $project (@projects) {
2303 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2304 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2305 fix_file($source,$project,$target);
2320 # A convenience function to generate all the lists (defines,
2321 # C sources, C++ source, etc.) in the Makefile
2322 sub generate_list($$$;$)
2331 printf FILEO "%-22s=",$name;
2333 if (defined $list) {
2334 foreach my $item (@$list) {
2336 if (defined $data) {
2337 $value=&$data($item);
2339 if (defined $item) {
2347 print FILEO " $value";
2350 print FILEO " \\\n\t\t\t$value";
2361 # Generates a project's Makefile
and all the target files
2362 sub generate_project_files
($)
2365 my $project_settings=@
$project[$P_SETTINGS];
2370 # Then sort the targets and separate the libraries from the programs
2371 foreach my $target (sort { @
$a[$T_NAME] cmp @
$b[$T_NAME] } @
{@
$project[$P_TARGETS]}) {
2372 if (@
$target[$T_TYPE] == $TT_DLL) {
2373 push @dll_list,$target;
2374 } elsif (@
$target[$T_TYPE] == $TT_LIB) {
2375 push @lib_list,$target;
2377 push @exe_list,$target;
2380 @
$project[$P_TARGETS]=[];
2381 push @
{@
$project[$P_TARGETS]}, @dll_list;
2382 push @
{@
$project[$P_TARGETS]}, @lib_list;
2383 push @
{@
$project[$P_TARGETS]}, @exe_list;
2385 if (!open(FILEO
,">@$project[$P_PATH]Makefile")) {
2386 print STDERR
"error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2387 print STDERR
" $!\n";
2390 binmode( FILEO
, ':utf8' );
2393 if (@
$project_settings[$T_FLAGS] & $TF_HASCXX) {
2394 $cpp_to_object=".cxx=.o";
2396 $cpp_to_object=".cpp=.o";
2399 print FILEO
"### Generated by Winemaker $version\n";
2400 print FILEO
"###\n";
2401 print FILEO
"### Invocation command line was\n";
2402 print FILEO
"### $0";
2406 print FILEO
"\n\n\n";
2408 generate_list
("SRCDIR",1,[ "." ]);
2409 if (@
$project[$P_PATH] eq "") {
2410 # This is the main project. It is also responsible for recursively
2411 # calling the other projects
2412 generate_list
("SUBDIRS",1,\
@projects,sub
2414 if ($_[0] != \
@main_project) {
2415 my $subdir=@
{$_[0]}[$P_PATH];
2419 # Eliminating the main project by returning undefined!
2422 if (@
{@
$project[$P_TARGETS]} > 0) {
2423 generate_list
("DLLS",1,\
@dll_list,sub
2425 return @
{$_[0]}[$T_NAME];
2427 generate_list
("LIBS",1,\
@lib_list,sub
2429 return @
{$_[0]}[$T_NAME];
2431 generate_list
("EXES",1,\
@exe_list,sub
2433 return "@{$_[0]}[$T_NAME]";
2435 print FILEO
"\n\n\n";
2437 print FILEO
"### Common settings\n\n";
2438 # Make it so that the project-wide settings override the global settings
2439 generate_list
("CEXTRA",1,@
$project_settings[$T_CEXTRA]);
2440 generate_list
("CXXEXTRA",1,@
$project_settings[$T_CXXEXTRA]);
2441 generate_list
("RCEXTRA",1,@
$project_settings[$T_RCEXTRA]);
2442 generate_list
("DEFINES",1,@
$project_settings[$T_DEFINES]);
2443 generate_list
("INCLUDE_PATH",1,@
$project_settings[$T_INCLUDE_PATH]);
2444 generate_list
("DLL_PATH",1,@
$project_settings[$T_DLL_PATH]);
2445 generate_list
("DLL_IMPORTS",1,@
$project_settings[$T_DLLS]);
2446 generate_list
("LIBRARY_PATH",1,@
$project_settings[$T_LIBRARY_PATH]);
2447 generate_list
("LIBRARIES",1,@
$project_settings[$T_LIBRARIES]);
2450 my $extra_source_count=@
{@
$project_settings[$T_SOURCES_C]}+
2451 @
{@
$project_settings[$T_SOURCES_CXX]}+
2452 @
{@
$project_settings[$T_SOURCES_RC]};
2453 my $no_extra=($extra_source_count == 0);
2455 print FILEO
"### Extra source lists\n\n";
2456 generate_list
("EXTRA_C_SRCS",1,@
$project_settings[$T_SOURCES_C]);
2457 generate_list
("EXTRA_CXX_SRCS",1,@
$project_settings[$T_SOURCES_CXX]);
2458 generate_list
("EXTRA_RC_SRCS",1,@
$project_settings[$T_SOURCES_RC]);
2460 generate_list
("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:$cpp_to_object)"]);
2461 print FILEO
"\n\n\n";
2464 # Iterate over all the targets...
2465 foreach my $target (@
{@
$project[$P_TARGETS]}) {
2466 print FILEO
"### @$target[$T_NAME] sources and settings\n\n";
2467 my $canon=canonize
("@$target[$T_NAME]");
2470 generate_list
("${canon}_MODULE",1,[@
$target[$T_NAME]]);
2471 generate_list
("${canon}_C_SRCS",1,@
$target[$T_SOURCES_C]);
2472 generate_list
("${canon}_CXX_SRCS",1,@
$target[$T_SOURCES_CXX]);
2473 generate_list
("${canon}_RC_SRCS",1,@
$target[$T_SOURCES_RC]);
2474 generate_list
("${canon}_LDFLAGS",1,@
$target[$T_LDFLAGS]);
2475 generate_list
("${canon}_ARFLAGS",1,@
$target[$T_ARFLAGS]);
2476 generate_list
("${canon}_DLL_PATH",1,@
$target[$T_DLL_PATH]);
2477 generate_list
("${canon}_DLLS",1,@
$target[$T_DLLS]);
2478 generate_list
("${canon}_LIBRARY_PATH",1,@
$target[$T_LIBRARY_PATH]);
2479 generate_list
("${canon}_LIBRARIES",1,@
$target[$T_LIBRARIES]);
2481 generate_list
("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:$cpp_to_object)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2482 print FILEO
"\n\n\n";
2484 print FILEO
"### Global source lists\n\n";
2485 generate_list
("C_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2487 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2489 return "\$(${canon}_C_SRCS)";
2492 generate_list
("",1,[ "\$(EXTRA_C_SRCS)" ]);
2494 generate_list
("CXX_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2496 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2498 return "\$(${canon}_CXX_SRCS)";
2501 generate_list
("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2503 generate_list
("RC_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2505 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2507 return "\$(${canon}_RC_SRCS)";
2510 generate_list
("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2514 print FILEO
"### Tools\n\n";
2515 print FILEO
"CC = winegcc\n";
2516 print FILEO
"CXX = wineg++\n";
2517 print FILEO
"RC = wrc\n";
2518 print FILEO
"AR = ar\n";
2521 print FILEO
"### Generic targets\n\n";
2523 if (@
$project[$P_PATH] eq "") {
2524 print FILEO
" \$(SUBDIRS)";
2526 if (@
{@
$project[$P_TARGETS]} > 0) {
2527 print FILEO
" \$(DLLS:%=%.so) \$(LIBS) \$(EXES)";
2530 print FILEO
"### Build rules\n";
2532 print FILEO
".PHONY: all clean dummy\n";
2534 print FILEO
"\$(SUBDIRS): dummy\n";
2535 print FILEO
"\t\@cd \$\@ && \$(MAKE)\n";
2537 print FILEO
"# Implicit rules\n";
2539 print FILEO
".SUFFIXES: .cpp .cxx .rc .res\n";
2540 print FILEO
"DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2542 print FILEO
".c.o:\n";
2543 print FILEO
"\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2545 print FILEO
".cpp.o:\n";
2546 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2548 print FILEO
".cxx.o:\n";
2549 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2551 print FILEO
".rc.res:\n";
2552 print FILEO
"\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2554 print FILEO
"# Rules for cleaning\n";
2556 print FILEO
"CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2557 print FILEO
" \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2559 print FILEO
"clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2560 print FILEO
"\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:$cpp_to_object)\n";
2561 print FILEO
"\t\$(RM) \$(DLLS:%=%.so) \$(LIBS) \$(EXES) \$(EXES:%=%.so)\n";
2563 print FILEO
"\$(SUBDIRS:%=%/__clean__): dummy\n";
2564 print FILEO
"\tcd `dirname \$\@` && \$(MAKE) clean\n";
2566 print FILEO
"\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2567 print FILEO
"\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2570 if (@
{@
$project[$P_TARGETS]} > 0) {
2571 print FILEO
"### Target specific build rules\n";
2572 print FILEO
"DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2573 foreach my $target (@
{@
$project[$P_TARGETS]}) {
2574 my $canon=canonize
("@$target[$T_NAME]");
2577 if (@
$target[$T_TYPE] == $TT_DLL && (@
$project_settings[$T_FLAGS] & $TF_HASDEF)) {
2578 print FILEO
"\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.def)\n";
2579 } elsif (@
$target[$T_TYPE] == $TT_DLL) {
2580 print FILEO
"\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.spec)\n";
2582 print FILEO
"\$(${canon}_MODULE): \$(${canon}_OBJS)\n";
2585 if (@
$target[$T_TYPE] == $TT_LIB) {
2586 print FILEO
"\t\$(AR) \$(${canon}_ARFLAGS) \$\@ \$(${canon}_OBJS)\n";
2588 if (@
{@
$target[$T_SOURCES_CXX]} > 0 or @
{@
$project_settings[$T_SOURCES_CXX]} > 0) {
2589 print FILEO
"\t\$(CXX)";
2591 print FILEO
"\t\$(CC)";
2593 print FILEO
" \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(${canon}_DLL_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2604 # This is where we finally generate files. In fact this method does not
2605 # do anything itself but calls the methods that do the actual work.
2608 print "Generating project files...\n";
2610 foreach my $project (@projects) {
2611 my $path=@
$project[$P_PATH];
2618 generate_project_files
($project);
2631 $opt_lower=$OPT_LOWER_UPPERCASE;
2632 $opt_lower_include=1;
2634 $opt_work_dir=undef;
2635 $opt_single_target=undef;
2636 $opt_target_type=$TT_GUIEXE;
2638 $opt_arch=$OPT_ARCH_DEFAULT;
2639 $opt_is_interactive=$OPT_ASK_NO;
2640 $opt_ask_project_options=$OPT_ASK_NO;
2641 $opt_ask_target_options=$OPT_ASK_NO;
2642 $opt_no_generated_files=0;
2643 $opt_no_source_fix=0;
2656 print "Winemaker $version\n";
2657 print "Copyright 2000-2004 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2658 print "Copyright 2004 Dimitrie O. Paun\n";
2659 print "Copyright 2009-2012 André Hentschel\n";
2665 print STDERR
"Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2666 print STDERR
" [--lower-none|--lower-all|--lower-uppercase]\n";
2667 print STDERR
" [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2668 print STDERR
" [--guiexe|--windows|--cuiexe|--console|--dll|--lib]\n";
2669 print STDERR
" [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2670 print STDERR
" [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2671 print STDERR
" [--generated-files|--nogenerated-files]\n";
2672 print STDERR
" [--wine32]\n";
2673 print STDERR
" work_directory|project_file|workspace_file\n";
2674 print STDERR
"\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2675 print STDERR
"the specified directory or project-file, so that they can be compiled with Winelib.\n";
2676 print STDERR
"During this process it will modify and rename some of the corresponding files.\n";
2677 print STDERR
"\tPlease read the manual page before use.\n";
2681 target_init
(\
@global_settings);
2686 if ($arg eq "--nobanner") {
2688 } elsif ($arg eq "--backup") {
2690 } elsif ($arg eq "--nobackup") {
2692 } elsif ($arg eq "--single-target") {
2693 $opt_single_target=shift @ARGV;
2694 } elsif ($arg eq "--lower-none") {
2695 $opt_lower=$OPT_LOWER_NONE;
2696 } elsif ($arg eq "--lower-all") {
2697 $opt_lower=$OPT_LOWER_ALL;
2698 } elsif ($arg eq "--lower-uppercase") {
2699 $opt_lower=$OPT_LOWER_UPPERCASE;
2700 } elsif ($arg eq "--lower-include") {
2701 $opt_lower_include=1;
2702 } elsif ($arg eq "--nolower-include") {
2703 $opt_lower_include=0;
2704 } elsif ($arg eq "--nosource-fix") {
2705 $opt_no_source_fix=1;
2706 } elsif ($arg eq "--generated-files") {
2707 $opt_no_generated_files=0;
2708 } elsif ($arg eq "--nogenerated-files") {
2709 $opt_no_generated_files=1;
2710 } elsif ($arg eq "--wine32") {
2711 $opt_arch=$OPT_ARCH_32;
2712 } elsif ($arg =~ /^-D/) {
2713 push @
{$global_settings[$T_DEFINES]},$arg;
2714 } elsif ($arg =~ /^-I/) {
2715 push @
{$global_settings[$T_INCLUDE_PATH]},$arg;
2716 } elsif ($arg =~ /^-P/) {
2717 push @
{$global_settings[$T_DLL_PATH]},"-L$'";
2718 } elsif ($arg =~ /^-i/) {
2719 push @
{$global_settings[$T_DLLS]},$';
2720 } elsif ($arg =~ /^-L/) {
2721 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2722 } elsif ($arg =~ /^-l/) {
2723 push @{$global_settings[$T_LIBRARIES]},$arg;
2725 # 'Source
'-based method options
2726 } elsif ($arg eq "--dll") {
2727 $opt_target_type=$TT_DLL;
2728 } elsif ($arg eq "--lib") {
2729 $opt_target_type=$TT_LIB;
2730 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2731 $opt_target_type=$TT_GUIEXE;
2732 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2733 $opt_target_type=$TT_CUIEXE;
2734 } elsif ($arg eq "--interactive") {
2735 $opt_is_interactive=$OPT_ASK_YES;
2736 $opt_ask_project_options=$OPT_ASK_YES;
2737 $opt_ask_target_options=$OPT_ASK_YES;
2738 } elsif ($arg eq "--mfc") {
2739 $opt_flags|=$TF_MFC;
2740 } elsif ($arg eq "--nomfc") {
2741 $opt_flags&=~$TF_MFC;
2742 $opt_flags|=$TF_NOMFC;
2743 } elsif ($arg eq "--nodlls") {
2744 $opt_flags|=$TF_NODLLS;
2745 } elsif ($arg eq "--nomsvcrt") {
2746 $opt_flags|=$TF_NOMSVCRT;
2750 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2751 if (!defined $opt_work_dir and !defined $opt_work_file) {
2753 $opt_work_file=$arg;
2759 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2768 if (!defined $opt_work_dir and !defined $opt_work_file) {
2769 print STDERR "error: you must specify the directory or project file containing the sources to be converted\n";
2771 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2772 print STDERR "error: could not chdir to the work directory\n";
2773 print STDERR " $!\n";
2777 if ($opt_no_banner == 0) {
2781 project_init(\@main_project, "", \@global_settings);
2783 # Fix the file and directory names
2784 fix_file_and_directory_names(".");
2786 # Scan the sources to identify the projects and targets
2789 # Fix the source files
2790 if (! $opt_no_source_fix) {
2794 # Generate the Makefile and the spec file
2795 if (! $opt_no_generated_files) {