5 # Copyright 2000-2004 François 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 array 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 my @compinc=split /\/+/, $sfilet;
687 my $realinc=search_from
($path, \
@compinc);
688 if (defined $realinc) {
691 if ($sfilet=~/^\w:/) {
692 print STDERR
"warning: Can't fix path $sfilet\n"
694 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I".$sfilet." ";
696 } elsif (/^U\s*\"(.*)\"/) {
697 # Undefines a previously defined symbol
698 $prj_target_cflags.="-U".$1." ";
704 # Automatic Use of Precompiled Headers
706 # Generate File Dependencies
708 # Compile Without Linking
709 # this option is always present and is already specified in the suffix rules
712 $prj_target_cflags.="-D_M_IX86=500 ";
714 # Pentium Pro Optimization
715 $prj_target_cflags.="-D_M_IX86=600 ";
717 # Pentium Optimization
718 $prj_target_cflags.="-D_M_IX86=500 ";
721 $prj_target_cflags.="-D_M_IX86=300 ";
724 $prj_target_cflags.="-D_M_IX86=400 ";
726 # Create Precompiled Header
728 # Use Precompiled Header
730 # Disable Language Extensions
731 $prj_target_cflags.="-ansi ";
733 # Enable Microsoft Extensions
734 } elsif (/^Zm[[:digit:]]+$/) {
735 # Specify Memory Allocation Limit
737 # Packs structures on 1-byte boundaries
738 $prj_target_cflags.="-fpack-struct ";
739 } elsif (/^Zp(2|4|8|16)$/) {
740 # Struct Member Alignment
741 $prj_target_cflags.="-fpack-struct=".$1;
743 print "C compiler option $_ not implemented\n";
747 #print "\nOptions: $prj_target_cflags\n";
749 } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
750 $prj_target_ldflags=$1;
751 @prj_target_options=split(/\s+\//, $prj_target_ldflags);
752 $prj_target_ldflags="";
753 $prj_target_libs=$prj_target_options[0];
754 $prj_target_libs=~s/\\/\//g
;
755 $prj_target_libs=~s/\.lib//g;
756 $prj_target_libs=~s/\s+/ -l/g;
757 shift (@prj_target_options);
758 foreach ( @prj_target_options ) {
761 } elsif (/^base:(.*)/) {
763 $prj_target_ldflags.="--image-base ".$1." ";
764 } elsif (/^debug$/) {
765 # Generate Debug Info
768 $prj_target_type=$TT_DLL;
769 } elsif (/^incremental:[[:alpha:]]+$/) {
771 } elsif (/^implib:/) {
772 # Name import library
773 } elsif (/^libpath:\"(.*)\"/) {
775 push @
{@
$project_settings[$T_DLL_PATH]},"-L$1";
776 } elsif (/^machine:[[:alnum:]]+$/) {
777 # Specify Target Platform
781 $prj_target_ldflags.="-Map ".$1." ";
783 $prj_target_ldflags.="-Map ".$prj_name.".map ";
785 } elsif (/^nologo$/) {
786 # Suppress Startup Banner and Information Messages
789 # may use it as Target?
790 } elsif (/^pdbtype:/) {
791 # Program Database Storage
792 } elsif (/^subsystem:/) {
794 } elsif (/^version:[[:digit:].]+$/) {
795 # Version Information
797 print "Linker option $_ not implemented\n";
801 } elsif (/^LIB32=/ && $found_cfg==1) {
804 } elsif (/^SOURCE=(.*)$/) {
805 my @components=split /[\/\\]+/, $1;
806 $sfilet=search_from
($path, \
@components);
807 if (!defined $sfilet) { next; }
808 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
809 push @sources_c,$sfilet;
810 } elsif ($sfilet =~ /\.cpp$/i) {
811 if ($sfilet =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
812 push @sources_misc,$sfilet;
813 @
$project_settings[$T_FLAGS]|=$TF_MFC;
815 push @sources_cxx,$sfilet;
817 } elsif ($sfilet =~ /\.cxx$/i) {
818 @
$project_settings[$T_FLAGS]|=$TF_HASCXX;
819 push @sources_cxx,$sfilet;
820 } elsif ($sfilet =~ /\.rc$/i) {
821 push @sources_rc,$sfilet;
822 } elsif ($sfilet =~ /\.def$/i) {
823 @
$project_settings[$T_FLAGS]|=$TF_HASDEF;
824 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
825 push @sources_misc,$sfilet;
826 if ($sfilet =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
827 @
$project_settings[$T_FLAGS]|=$TF_MFC;
832 } elsif (/^# (Begin|End) Source File/) {
833 # Source-Files already handled
835 } elsif (/^# (Begin|End) Group/) {
838 } elsif (/^# (Begin|End) Custom Build/) {
839 # Custom Builds are ignored
841 } elsif (/^# ADD LIB32 /) {
844 } elsif (/^# Begin Target$/) {
845 # Targets are ignored
847 } elsif (/^# End Target$/) {
848 # Targets are ignored
851 if ($found_cfg == 1) {
854 if (/if (.*)\(CFG\)" == "(.*)"/i) {
855 if ($2 eq $prj_cfg) {
860 } elsif (/^CFG=(.*)/i) {
864 else { # Line recognized
870 push @
{@
$project_settings[$T_LIBRARIES]},$prj_target_libs;
871 push @
{@
$project_settings[$T_CEXTRA]},$prj_target_cflags;
872 push @
{@
$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
873 push @
{@
$project_settings[$T_DEFINES]},$prj_target_defines;
874 push @
{@
$project_settings[$T_LDFLAGS]},$prj_target_ldflags;
875 } elsif ($filename =~ /.vcproj$/i) {
880 die "Error: You need the libxml package (deb: libxml-libxml-perl, rpm: perl-libxml-perl)";
883 my $xmlparser = XML
::LibXML
->new();
884 my $project_xml = $xmlparser->parse_file($filename);
888 foreach my $vc_project ($project_xml->findnodes('/VisualStudioProject')) {
889 foreach my $vc_project_attr ($vc_project->attributes) {
890 if ($vc_project_attr->getName eq "Name") {
891 $prj_name=$vc_project_attr->getValue;
892 $prj_name=~s/\s+/_/g;
898 for (my $flevel = 0; $flevel <= 5; $flevel++) {
899 foreach my $vc_file ($project_xml->findnodes('/VisualStudioProject/Files/'.('Filter/' x
$flevel).'File')) {
900 foreach my $vc_file_attr ($vc_file->attributes) {
901 if ($vc_file_attr->getName eq "RelativePath") {
902 $sfilet = $vc_file_attr->getValue;
903 $sfilet=~s/\\\\/\\/g; #remove double backslash
904 $sfilet=~s/^\.\\//; #remove starting 'this directory'
905 $sfilet=~s/\\/\//g
; #make slashes out of backslashes
906 my @compsrc=split(/\/+/, $sfilet);
907 my $realsrc=search_from
($path, \
@compsrc);
908 if (defined $realsrc) {
911 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
912 push @sources_c,$sfilet;
913 } elsif ($sfilet =~ /\.cpp$/i) {
914 if ($sfilet =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
915 push @sources_misc,$sfilet;
916 @
$project_settings[$T_FLAGS]|=$TF_MFC;
918 push @sources_cxx,$sfilet;
920 } elsif ($sfilet =~ /\.cxx$/i) {
921 @
$project_settings[$T_FLAGS]|=$TF_HASCXX;
922 push @sources_cxx,$sfilet;
923 } elsif ($sfilet =~ /\.rc$/i) {
924 push @sources_rc,$sfilet;
925 } elsif ($sfilet =~ /\.def$/i) {
926 @
$project_settings[$T_FLAGS]|=$TF_HASDEF;
927 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
928 push @sources_misc,$sfilet;
929 if ($sfilet =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
930 @
$project_settings[$T_FLAGS]|=$TF_MFC;
938 my @vc_configurations = $project_xml->findnodes('/VisualStudioProject/Configurations/Configuration');
939 my $vc_configuration = $vc_configurations[0];
940 foreach my $vc_configuration_attr ($vc_configuration->attributes) {
941 if ($vc_configuration_attr->getName eq "ConfigurationType") {
942 if ($vc_configuration_attr->getValue==1) {
943 $prj_target_type=$TT_GUIEXE; # Application
944 } elsif ($vc_configuration_attr->getValue==2) {
945 $prj_target_type=$TT_DLL; # Dynamic-Link Library
946 } elsif ($vc_configuration_attr->getValue==4) {
947 $prj_target_type=$TT_LIB; # Static Library
952 foreach my $vc_configuration_tools ($vc_configuration->findnodes('Tool')) {
953 my @find_tool = $vc_configuration_tools->attributes;
954 if ($find_tool[0]->getValue eq "VCCLCompilerTool") {
955 foreach my $vc_compiler_tool ($vc_configuration_tools->attributes) {
956 if ($vc_compiler_tool->getName eq "Optimization") {$prj_target_cflags.="-O".$vc_compiler_tool->getValue." ";}
957 if ($vc_compiler_tool->getName eq "WarningLevel") {
958 if ($vc_compiler_tool->getValue==0) {
959 $prj_target_cflags.="-w ";
960 } elsif ($vc_compiler_tool->getValue<4) {
961 $prj_target_cflags.="-W ";
962 } elsif ($vc_compiler_tool->getValue==4) {
963 $prj_target_cflags.="-Wall ";
964 } elsif ($vc_compiler_tool->getValue eq "X") {
965 $prj_target_cflags.="-Werror ";
968 if ($vc_compiler_tool->getName eq "PreprocessorDefinitions") {
969 $configt=$vc_compiler_tool->getValue;
971 $configt=~s/;\s*/ -D/g;
972 $prj_target_defines.="-D".$configt." ";
974 if ($vc_compiler_tool->getName eq "AdditionalIncludeDirectories") {
975 $configt=$vc_compiler_tool->getValue;
977 my @addincl = split(/\s*;\s*/, $configt);
978 foreach $configt (@addincl) {
979 my @compinc=split(/\/+/, $configt);
980 my $realinc=search_from
($path, \
@compinc);
981 if (defined $realinc) {
984 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I".$configt;
989 if ($find_tool[0]->getValue eq "VCLinkerTool") {
990 foreach my $vc_linker_tool ($vc_configuration_tools->attributes) {
991 if ($vc_linker_tool->getName eq "AdditionalDependencies") {
992 $prj_target_libs=" ".$vc_linker_tool->getValue;
993 $prj_target_libs=~s/\\/\//g
;
994 $prj_target_libs=~s/\.lib//g;
995 $prj_target_libs=~s/\s+/ -l/g;
1001 push @
{@
$project_settings[$T_LIBRARIES]},$prj_target_libs;
1002 push @
{@
$project_settings[$T_CEXTRA]},$prj_target_cflags;
1003 push @
{@
$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
1004 push @
{@
$project_settings[$T_DEFINES]},$prj_target_defines;
1006 print STDERR
"File format not supported for file: $filename\n";
1010 # Add this project to the project list, except for
1011 # the main project which is already in the list.
1012 if ($is_sub_project == 1) {
1013 push @projects,$project;
1016 # Ask for project-wide options
1017 if ($opt_ask_project_options == $OPT_ASK_YES) {
1019 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1022 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1023 if (defined $flag_desc) {
1024 print "* (currently $flag_desc)\n";
1026 print "* or 'skip' to skip the target specific options,\n";
1027 print "* or 'never' to not be asked this question again:\n";
1029 my $options=<STDIN
>;
1031 if ($options eq "skip") {
1032 $opt_ask_target_options=$OPT_ASK_SKIP;
1034 } elsif ($options eq "never") {
1035 $opt_ask_project_options=$OPT_ASK_NO;
1037 } elsif (source_set_options
($project_settings,$options)) {
1040 print "Please re-enter the options:\n";
1044 # Create the target...
1046 target_init
($target);
1048 if ($prj_target_type==$TT_GUIEXE or $prj_target_type==$TT_CUIEXE) {
1049 $prj_name=lc($prj_name.".exe");
1050 @
$target[$T_TYPE]=$opt_target_type;
1051 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
1052 } elsif ($prj_target_type==$TT_LIB) {
1053 $prj_name=lc("lib".$prj_name.".a");
1054 @
$target[$T_TYPE]=$TT_LIB;
1055 push @
{@
$target[$T_ARFLAGS]},("rc");
1057 $prj_name=lc($prj_name.".dll");
1058 @
$target[$T_TYPE]=$TT_DLL;
1059 my $canon=canonize
($prj_name);
1060 if (@
$project_settings[$T_FLAGS] & $TF_HASDEF) {
1061 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.def)");
1063 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1067 @
$target[$T_NAME]=$prj_name;
1068 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
1070 # This is the default link list of Visual Studio
1071 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1072 my @std_libraries=qw(uuid);
1073 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1074 @
$target[$T_DLLS]=\
@std_imports;
1075 @
$target[$T_LIBRARIES]=\
@std_libraries;
1077 @
$target[$T_DLLS]=[];
1078 @
$target[$T_LIBRARIES]=[];
1080 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1081 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
1082 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1083 push @
{@
$target[$T_LDFLAGS]},"-m$opt_arch";
1086 push @
{@
$project[$P_TARGETS]},$target;
1088 # Ask for target-specific options
1089 if ($opt_ask_target_options == $OPT_ASK_YES) {
1091 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
1094 if ($flag_desc ne "") {
1097 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1098 print "* \"$prj_name\"$flag_desc or 'never' to not be asked this question again:\n";
1100 my $options=<STDIN
>;
1102 if ($options eq "never") {
1103 $opt_ask_target_options=$OPT_ASK_NO;
1105 } elsif (source_set_options
($target,$options)) {
1108 print "Please re-enter the options:\n";
1111 if (@
$target[$T_FLAGS] & $TF_MFC) {
1112 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1113 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1114 push @
{@
$target[$T_DLLS]},"mfc.dll";
1115 # FIXME: Link with the MFC in the Unix sense, until we
1116 # start exporting the functions properly.
1117 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1118 push @
{@
$target[$T_LIBRARIES]},"mfc";
1122 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
1123 @
$project_settings[$T_SOURCES_C]=[];
1125 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1126 @
$project_settings[$T_SOURCES_CXX]=[];
1128 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
1129 @
$project_settings[$T_SOURCES_RC]=[];
1131 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
1132 @
$project_settings[$T_SOURCES_MISC]=[];
1135 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
1136 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
1137 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
1138 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
1140 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1141 $opt_ask_target_options=$OPT_ASK_YES;
1144 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1145 push @
{@
$project_settings[$T_CEXTRA]},"-mno-cygwin";
1146 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1147 push @
{@
$project_settings[$T_CEXTRA]},"-m$opt_arch";
1148 push @
{@
$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1152 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
1153 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1155 # The sources that did not match, if any, go to the extra
1156 # source list of the project settings
1157 foreach my $source (@sources_c) {
1158 if ($source ne "") {
1159 push @
{@
$project_settings[$T_SOURCES_C]},$source;
1162 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
1163 foreach my $source (@sources_cxx) {
1164 if ($source ne "") {
1165 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
1168 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
1169 foreach my $source (@sources_rc) {
1170 if ($source ne "") {
1171 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
1174 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
1175 foreach my $source (@sources_misc) {
1176 if ($source ne "") {
1177 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
1180 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
1184 # Scans the specified workspace file to find the project files
1185 sub source_scan_workspace_file
($);
1186 sub source_scan_workspace_file
($)
1189 my $path=dirname
($filename);
1192 if (! -e
$filename) {
1196 if (!open(FILEIWS
,$filename)) {
1197 print STDERR
"error: unable to open $filename for reading:\n";
1198 print STDERR
" $!\n";
1205 if ($filename =~ /.dsw$/i) {
1207 # Remove any trailing CrLf
1210 # catch a project definition
1211 if (/^Project:\s\"(.*)\"=(.*)\s-/) {
1214 @components=split /[\/\\]+/, $prj_path;
1215 $prj_path=search_from
($path, \
@components);
1216 print "Name: $prj_name\nPath: $prj_path\n";
1217 source_scan_project_file
(\
@main_project,1,$prj_path);
1221 } elsif (/^Global:/) {
1222 # ignore the Global section
1224 print STDERR
"unknown section $_\n";
1225 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1226 print "\nFileversion: $3\n";
1230 } elsif ($filename =~ /.sln$/i) {
1232 # Remove any trailing CrLf
1235 # catch a project definition
1236 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1239 if ($prj_path eq "Solution Items") { next; }
1240 @components=split /[\/\\]+/, $3;
1241 $prj_path=search_from
($path, \
@components);
1242 print "Name: $prj_name\nPath: $prj_path\n";
1243 source_scan_project_file
(\
@main_project,1,$prj_path);
1245 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1246 print "\nFileversion: $3\n";
1252 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
1256 # Scans the specified directory to:
1257 # - see if we should create a Makefile in this directory. We normally do
1258 # so if we find a project file and sources
1259 # - get a list of targets for this directory
1260 # - get the list of source files
1261 sub source_scan_directory
($$$$);
1262 sub source_scan_directory
($$$$)
1264 # a reference to the parent's project
1265 my $parent_project=$_[0];
1266 # the full relative path to the current directory, including a
1267 # trailing '/', or an empty string if this is the top level directory
1269 # the name of this directory, including a trailing '/', or an empty
1270 # string if this is the top level directory
1272 # if set then no targets will be looked for and the sources will all
1273 # end up in the parent_project's 'misc' bucket
1274 my $no_target=$_[3];
1276 # reference to the project for this directory. May not be used
1278 # list of targets found in the 'current' directory
1280 # list of sources found in the current directory
1284 my @sources_misc=();
1285 # true if this directory contains a Windows project
1286 my $has_win_project=0;
1287 # true if this directory contains headers
1289 # If we don't find any executable/library then we might make up targets
1290 # from the list of .dsp/.mak files we find since they usually have the
1291 # same name as their target.
1295 if (defined $opt_single_target or $dirname eq "") {
1296 # Either there is a single target and thus a single project,
1297 # or we are in the top level directory for which a project
1299 $project=$parent_project;
1302 project_init
($project, $path, \
@global_settings);
1304 my $project_settings=@
$project[$P_SETTINGS];
1306 # First find out what this directory contains:
1307 # collect all sources, targets and subdirectories
1308 my $directory=get_directory_contents
($path);
1309 foreach my $dentry (@
$directory) {
1310 if ($dentry =~ /^\./) {
1313 my $fullentry="$path$dentry";
1314 if (-d
"$fullentry") {
1315 if ($dentry =~ /^(Release|Debug)/i) {
1316 # These directories are often used to store the object files and the
1317 # resulting executable/library. They should not contain anything else.
1318 my @candidates=grep /\.(exe|dll|lib)$/i, @
{get_directory_contents
("$fullentry")};
1319 foreach my $candidate (sort @candidates) {
1320 my $dlldup = $candidate;
1321 $dlldup =~ s/\.lib$/.dll/;
1322 if ($candidate =~ /\.lib$/ and $targets{$dlldup})
1324 # Often lib files are created together with dll files, even if the dll file is the
1328 $targets{$candidate}=1;
1330 } elsif ($dentry =~ /^include/i) {
1331 # This directory must contain headers we're going to need
1332 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1333 source_scan_directory
($project,"$fullentry/","$dentry/",1);
1335 # Recursively scan this directory. Any source file that cannot be
1336 # attributed to a project in one of the subdirectories will be
1337 # attributed to this project.
1338 source_scan_directory
($project,"$fullentry/","$dentry/",$no_target);
1340 } elsif (-f
"$fullentry") {
1341 if ($dentry =~ /\.(exe|dll|lib)$/i) {
1342 $targets{$dentry}=1;
1343 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1344 push @sources_c,"$dentry";
1345 } elsif ($dentry =~ /\.cpp$/i) {
1346 if ($dentry =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1347 push @sources_misc,"$dentry";
1348 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1350 push @sources_cxx,"$dentry";
1352 } elsif ($dentry =~ /\.cxx$/i) {
1353 @
$project_settings[$T_FLAGS]|=$TF_HASCXX;
1354 push @sources_cxx,"$dentry";
1355 } elsif ($dentry =~ /\.rc$/i) {
1356 push @sources_rc,"$dentry";
1357 } elsif ($dentry =~ /\.def$/i) {
1358 @
$project_settings[$T_FLAGS]|=$TF_HASDEF;
1359 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1361 push @sources_misc,"$dentry";
1362 if ($dentry =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1363 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1365 } elsif ($dentry =~ /\.(dsp|vcproj)$/i) {
1366 push @prj_files,"$dentry";
1368 } elsif ($dentry =~ /\.mak$/i) {
1369 push @mak_files,"$dentry";
1371 } elsif ($dentry =~ /^makefile/i) {
1378 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I.";
1380 # If we have a single target then all we have to do is assign
1381 # all the sources to it and we're done
1382 # FIXME: does this play well with the --interactive mode?
1383 if ($opt_single_target) {
1384 my $target=@
{@
$project[$P_TARGETS]}[0];
1385 push @
{@
$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1386 push @
{@
$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1387 push @
{@
$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1388 push @
{@
$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1392 my $parent_settings=@
$parent_project[$P_SETTINGS];
1393 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1394 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1395 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1396 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1397 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1401 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1402 @
{@
$project_settings[$T_SOURCES_C]}+
1403 @
{@
$project_settings[$T_SOURCES_CXX]}+
1404 @
{@
$project_settings[$T_SOURCES_RC]};
1405 if ($source_count == 0) {
1406 # A project without real sources is not a project, get out!
1407 if ($project!=$parent_project) {
1408 my $parent_settings=@
$parent_project[$P_SETTINGS];
1409 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1410 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1414 #print "targets=",%targets,"\n";
1415 #print "target_count=$target_count\n";
1416 #print "has_win_project=$has_win_project\n";
1417 #print "dirname=$dirname\n";
1420 if (($has_win_project != 0) or ($dirname eq "")) {
1421 # Deal with cases where we could not find any executable/library, and
1422 # thus have no target, although we did find some sort of windows project.
1423 $target_count=keys %targets;
1424 if ($target_count == 0) {
1425 # Try to come up with a target list based on .dsp/.mak files
1427 if (@prj_files > 0) {
1428 print "Projectfile found! You might want to try using it directly.\n";
1429 $prj_list=\
@prj_files;
1431 $prj_list=\
@mak_files;
1433 foreach my $filename (@
$prj_list) {
1434 $filename =~ s/\.(dsp|vcproj|mak)$//i;
1435 if ($opt_target_type == $TT_DLL) {
1436 $filename = "$filename.dll";
1438 $targets{$filename}=1;
1440 $target_count=keys %targets;
1441 if ($target_count == 0) {
1442 # Still nothing, try the name of the directory
1444 if ($dirname eq "") {
1445 # Bad luck, this is the top level directory!
1446 $name=(split /\//, cwd
)[-1];
1449 # Remove the trailing '/'. Also eliminate whatever is after the last
1450 # '.' as it is likely to be meaningless (.orig, .new, ...)
1451 $name =~ s
+(/|\
.[^.]*)$++;
1452 if ($name eq "src") {
1453 # 'src' is probably a subdirectory of the real project directory.
1454 # Try again with the parent (if any).
1456 if ($parent =~ s
+([^/]*)/[^/]*/$+$1+) {
1459 $name=(split /\//, cwd
)[-1];
1463 $name =~ s
+(/|\
.[^.]*)$++;
1464 if ($opt_target_type == $TT_DLL) {
1465 $name = canonize
($name).".dll";
1466 } elsif ($opt_target_type == $TT_LIB) {
1467 $name = "lib".canonize
($name).".a";
1469 $name = canonize
($name).".exe";
1475 # Ask confirmation to the user if he wishes so
1476 if ($opt_is_interactive == $OPT_ASK_YES) {
1477 my $target_list=join " ",keys %targets;
1478 print "\n*** In ",($path?
$path:"./"),"\n";
1479 print "* winemaker found the following list of (potential) targets\n";
1480 print "* $target_list\n";
1481 print "* Type enter to use it as is, your own comma-separated list of\n";
1482 print "* targets, 'none' to assign the source files to a parent directory,\n";
1483 print "* or 'ignore' to ignore everything in this directory tree.\n";
1484 print "* Target list:\n";
1485 $target_list=<STDIN
>;
1487 if ($target_list eq "") {
1488 # Keep the target list as is, i.e. do nothing
1489 } elsif ($target_list eq "none") {
1490 # Empty the target list
1492 } elsif ($target_list eq "ignore") {
1493 # Ignore this subtree altogether
1497 foreach my $target (split /,/,$target_list) {
1498 $target =~ s
+^\s
*++;
1499 $target =~ s
+\s
*$++;
1500 $targets{$target}=1;
1506 # If we have no project at this level, then transfer all
1507 # the sources to the parent project
1508 $target_count=keys %targets;
1509 if ($target_count == 0) {
1510 if ($project!=$parent_project) {
1511 my $parent_settings=@
$parent_project[$P_SETTINGS];
1512 push @
{@
$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1513 push @
{@
$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1514 push @
{@
$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1515 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1516 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1521 # Otherwise add this project to the project list, except for
1522 # the main project which is already in the list.
1523 if ($dirname ne "") {
1524 push @projects,$project;
1527 # Ask for project-wide options
1528 if ($opt_ask_project_options == $OPT_ASK_YES) {
1530 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1533 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1534 if (defined $flag_desc) {
1535 print "* (currently $flag_desc)\n";
1537 print "* or 'skip' to skip the target specific options,\n";
1538 print "* or 'never' to not be asked this question again:\n";
1540 my $options=<STDIN
>;
1542 if ($options eq "skip") {
1543 $opt_ask_target_options=$OPT_ASK_SKIP;
1545 } elsif ($options eq "never") {
1546 $opt_ask_project_options=$OPT_ASK_NO;
1548 } elsif (source_set_options
($project_settings,$options)) {
1551 print "Please re-enter the options:\n";
1555 # - Create the targets
1556 # - Check if we have both libraries and programs
1557 # - Match each target with source files (sort in reverse
1558 # alphabetical order to get the longest matches first)
1561 my @local_depends=();
1563 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1564 # Create the target...
1566 target_init
($target);
1567 @
$target[$T_NAME]=$target_name;
1568 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
1569 if ($target_name =~ /\.dll$/) {
1570 @
$target[$T_TYPE]=$TT_DLL;
1571 push @local_depends,"$target_name.so";
1572 push @local_dlls,$target_name;
1573 my $canon=canonize
($target_name);
1574 if (@
$project_settings[$T_FLAGS] & $TF_HASDEF) {
1575 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.def)");
1577 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1579 } elsif ($target_name =~ /\.lib$/) {
1580 $target_name =~ s/(.*)\.lib/lib$1.a/;
1581 @
$target[$T_NAME]=$target_name;
1582 @
$target[$T_TYPE]=$TT_LIB;
1583 push @local_depends,"$target_name";
1584 push @local_libs,$target_name;
1585 push @
{@
$target[$T_ARFLAGS]},("rc");
1586 } elsif ($target_name =~ /\.a$/) {
1587 @
$target[$T_NAME]=$target_name;
1588 @
$target[$T_TYPE]=$TT_LIB;
1589 push @local_depends,"$target_name";
1590 push @local_libs,$target_name;
1591 push @
{@
$target[$T_ARFLAGS]},("rc");
1593 @
$target[$T_TYPE]=$opt_target_type;
1594 push @exe_list,$target;
1595 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
1597 my $basename=$target_name;
1598 $basename=~ s/\.(dll|exe)$//i;
1599 # This is the default link list of Visual Studio
1600 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1601 my @std_libraries=qw(uuid);
1602 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1603 @
$target[$T_DLLS]=\
@std_imports;
1604 @
$target[$T_LIBRARIES]=\
@std_libraries;
1606 @
$target[$T_DLLS]=[];
1607 @
$target[$T_LIBRARIES]=[];
1609 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1610 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
1611 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1612 push @
{@
$target[$T_LDFLAGS]},"-m$opt_arch";
1615 push @
{@
$project[$P_TARGETS]},$target;
1617 # Ask for target-specific options
1618 if ($opt_ask_target_options == $OPT_ASK_YES) {
1620 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
1623 if ($flag_desc ne "") {
1626 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1627 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1629 my $options=<STDIN
>;
1631 if ($options eq "never") {
1632 $opt_ask_target_options=$OPT_ASK_NO;
1634 } elsif (source_set_options
($target,$options)) {
1637 print "Please re-enter the options:\n";
1640 if (@
$target[$T_FLAGS] & $TF_MFC) {
1641 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1642 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1643 push @
{@
$target[$T_DLLS]},"mfc.dll";
1644 # FIXME: Link with the MFC in the Unix sense, until we
1645 # start exporting the functions properly.
1646 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1647 push @
{@
$target[$T_LIBRARIES]},"mfc";
1651 if ($target_count == 1) {
1652 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
1653 @
$project_settings[$T_SOURCES_C]=[];
1656 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1657 @
$project_settings[$T_SOURCES_CXX]=[];
1660 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
1661 @
$project_settings[$T_SOURCES_RC]=[];
1664 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
1665 # No need for sorting these sources
1666 @
$project_settings[$T_SOURCES_MISC]=[];
1669 foreach my $source (@sources_c) {
1670 if ($source =~ /^$basename/i) {
1671 push @
{@
$target[$T_SOURCES_C]},$source;
1675 foreach my $source (@sources_cxx) {
1676 if ($source =~ /^$basename/i) {
1677 push @
{@
$target[$T_SOURCES_CXX]},$source;
1681 foreach my $source (@sources_rc) {
1682 if ($source =~ /^$basename/i) {
1683 push @
{@
$target[$T_SOURCES_RC]},$source;
1687 foreach my $source (@sources_misc) {
1688 if ($source =~ /^$basename/i) {
1689 push @
{@
$target[$T_SOURCES_MISC]},$source;
1694 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
1695 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
1696 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
1697 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
1699 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1700 $opt_ask_target_options=$OPT_ASK_YES;
1703 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1704 push @
{@
$project_settings[$T_CEXTRA]},"-mno-cygwin";
1705 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1706 push @
{@
$project_settings[$T_CEXTRA]},"-m$opt_arch";
1707 push @
{@
$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1711 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
1712 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1714 # The sources that did not match, if any, go to the extra
1715 # source list of the project settings
1716 foreach my $source (@sources_c) {
1717 if ($source ne "") {
1718 push @
{@
$project_settings[$T_SOURCES_C]},$source;
1721 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
1722 foreach my $source (@sources_cxx) {
1723 if ($source ne "") {
1724 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
1727 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
1728 foreach my $source (@sources_rc) {
1729 if ($source ne "") {
1730 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
1733 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
1734 foreach my $source (@sources_misc) {
1735 if ($source ne "") {
1736 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
1739 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
1741 # Finally if we are building both libraries and programs in
1742 # this directory, then the programs should be linked with all
1744 if (@local_dlls > 0 and @exe_list > 0) {
1745 foreach my $target (@exe_list) {
1746 push @
{@
$target[$T_DLL_PATH]},"-L.";
1747 push @
{@
$target[$T_DLLS]},@local_dlls;
1750 if (@local_libs > 0 and @exe_list > 0) {
1751 foreach my $target (@exe_list) {
1752 push @
{@
$target[$T_LIBRARY_PATH]},"-L.";
1753 push @
{@
$target[$T_LIBRARIES]},@local_libs;
1759 # Scan the source directories in search of things to build
1762 # If there's a single target then this is going to be the default target
1763 if (defined $opt_single_target) {
1764 # Create the main target
1766 target_init
($main_target);
1767 @
$main_target[$T_NAME]=$opt_single_target;
1768 @
$main_target[$T_TYPE]=$opt_target_type;
1770 # Add it to the list
1771 push @
{$main_project[$P_TARGETS]},$main_target;
1774 # The main directory is always going to be there
1775 push @projects,\
@main_project;
1777 if (defined $opt_work_dir) {
1778 # Now scan the directory tree looking for source files and, maybe, targets
1779 print "Scanning the source directories...\n";
1780 source_scan_directory
(\
@main_project,"","",0);
1781 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
1782 } elsif (defined $opt_work_file) {
1783 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1784 source_scan_project_file
(\
@main_project,0,$opt_work_file);
1785 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1786 source_scan_workspace_file
($opt_work_file);
1798 # Performs a directory traversal and renames the files so that:
1799 # - they have the case desired by the user
1800 # - their extension is of the appropriate case
1801 # - they don't contain annoying characters like ' ', '$', '#', ...
1802 # But only perform these changes for source files and directories.
1803 sub fix_file_and_directory_names
($);
1804 sub fix_file_and_directory_names
($)
1808 my $directory=get_directory_contents
($dirname);
1809 foreach my $dentry (@
$directory)
1811 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1814 # Set $warn to 1 if the user should be warned of the renaming
1816 my $new_name=$dentry;
1818 if (-f
"$dirname/$dentry")
1820 # Don't rename Winemaker's makefiles
1821 next if ($dentry eq "Makefile" and
1822 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker
/);
1824 # Leave non-source files alone
1825 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc|spec|def))$/i);
1827 # Only all lowercase extensions are supported (because of
1828 # rules like '.c.o:').
1829 $new_name =~ s/\.C$/.c/;
1830 $new_name =~ s/\.cpp$/.cpp/i;
1831 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1832 $new_name =~ s/\.rc$/.rc/i;
1833 # And this last one is to avoid confusion when running make
1834 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1837 # Adjust the case to the user's preferences
1838 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1839 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1841 $new_name=lc $new_name;
1844 # make doesn't support these characters well
1845 $new_name =~ s/[ \$]/_/g;
1847 # And finally, perform the renaming
1848 if ($new_name ne $dentry)
1851 print STDERR
"warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1853 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1854 print STDERR
"error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1855 print STDERR
" $!\n";
1860 clear_directory_cache
($dirname);
1863 if (-d
"$dirname/$new_name") {
1864 fix_file_and_directory_names
("$dirname/$new_name");
1878 # Try to find a file for the specified filename. The attempt is
1879 # case-insensitive which is why it's not trivial. If a match is
1880 # found then we return the pathname with the correct case.
1887 if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
1889 } elsif ($dirname !~ m
+^/+) {
1890 $dirname=cwd
. "/" . $dirname;
1892 if ($dirname !~ m
+/$+) {
1896 foreach my $component (@
$path) {
1897 $component=~s/^\"//;
1898 $component=~s/\"$//;
1899 #print " looking for $component in \"$dirname\"\n";
1900 if ($component eq ".") {
1903 } elsif ($component eq "..") {
1905 if ($dirname =~ /\.\.\/$/) {
1908 $dirname=dirname
($dirname) . "/";
1912 # The file/directory may have been renamed before. Also try to
1913 # match the renamed file.
1914 my $renamed=$component;
1915 $renamed =~ s/[ \$]/_/g;
1916 if ($renamed eq $component) {
1920 my $directory=get_directory_contents
$dirname;
1922 foreach my $dentry (@
$directory) {
1923 if ($dentry =~ /^\Q$component\E$/i or
1924 (defined $renamed and $dentry =~ /^$renamed$/i)
1926 $dirname.="$dentry/";
1927 $real_path.="$dentry/";
1932 if (!defined $found) {
1934 #print " could not find $component in $dirname\n";
1939 $real_path=~ s
+/$++;
1940 #print " -> found $real_path\n";
1945 # Performs a case-insensitive search for the specified file in the
1947 # $line is the line number that should be referenced when an error occurs
1948 # $filename is the file we are looking for
1949 # $dirname is the directory of the file containing the '#include' directive
1950 # if '"' was used, it is an empty string otherwise
1951 # $project and $target specify part of the include path
1952 sub get_real_include_name
($$$$$)
1960 if ($filename =~ /^([a-zA-Z]:)?[\/\\]/ or $filename =~ /^[a
-zA
-Z
]:[\
/\\]?/) {
1961 # This is not a relative path, we cannot make any check
1962 my $warning="path:$filename";
1963 if (!defined $warnings{$warning}) {
1964 $warnings{$warning}="1";
1965 print STDERR
"warning: cannot check the case of absolute pathnames:\n";
1966 print STDERR
"$line: $filename\n";
1969 # Here's how we proceed:
1970 # - split the filename we look for into its components
1971 # - then for each directory in the include path
1972 # - trace the directory components starting from that directory
1973 # - if we fail to find a match at any point then continue with
1974 # the next directory in the include path
1975 # - otherwise, rejoice, our quest is over.
1976 my @file_components=split /[\/\\]+/, $filename;
1977 #print " Searching for $filename from @$project[$P_PATH]\n";
1980 if ($dirname ne "") {
1981 # This is an 'include ""' -> look in dirname first.
1982 #print " in $dirname (include \"\")\n";
1983 $real_filename=search_from
($dirname,\
@file_components);
1984 if (defined $real_filename) {
1985 return $real_filename;
1988 my $project_settings=@
$project[$P_SETTINGS];
1989 foreach my $include (@
{@
$target[$T_INCLUDE_PATH]}, @
{@
$project_settings[$T_INCLUDE_PATH]}) {
1990 my $dirname=$include;
1993 if (!is_absolute
($dirname)) {
1994 $dirname="@$project[$P_PATH]$dirname";
1996 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)/++;
1997 $dirname=~ s
+^\
$\
(SRCDIR\
)/+@
$project[$P_PATH]+;
1999 #print " in $dirname\n";
2000 $real_filename=search_from
("$dirname",\
@file_components);
2001 if (defined $real_filename) {
2002 return $real_filename;
2005 my $dotdotpath=@
$project[$P_PATH];
2006 $dotdotpath =~ s/[^\/]+/../g
;
2007 foreach my $include (@
{$global_settings[$T_INCLUDE_PATH]}) {
2008 my $dirname=$include;
2010 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)\
/++;
2011 $dirname=~ s
+^\
$\
(SRCDIR\
)\
/+@
$project[$P_PATH]+;
2012 #print " in $dirname (global setting)\n";
2013 $real_filename=search_from
("$dirname",\
@file_components);
2014 if (defined $real_filename) {
2015 return $real_filename;
2019 $filename =~ s
+\\\\+/+g
; # in include ""
2020 $filename =~ s
+\\+/+g
; # in include <> !
2021 if ($opt_lower_include) {
2022 return lc "$filename";
2033 if ($size =~ /^(1|2|4|8)$/) {
2034 print FILEO
"$indent#include <pshpack$size.h>$trailer";
2036 print FILEO
"$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
2037 print FILEO
"$indent#include <pshpack4.h>$trailer";
2042 # 'Parses' a source file and fixes constructs that would not work with
2043 # Winelib. The parsing is rather simple and not all non-portable features
2044 # are corrected. The most important feature that is corrected is the case
2045 # and path separator of '#include' directives. This requires that each
2046 # source file be associated to a project & target so that the proper
2047 # include path is used.
2048 # Also note that the include path is relative to the directory in which the
2049 # compiler is run, i.e. that of the project, not to that of the file.
2055 $filename="@$project[$P_PATH]$filename";
2056 if (! -e
$filename) {
2060 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
2061 my $dirname=dirname
($filename);
2063 if (defined $target and (@
$target[$T_FLAGS] & $TF_MFC)) {
2067 print " $filename\n";
2068 if (! -e
"$filename.bak") {
2069 if (!copy
("$filename","$filename.bak")) {
2070 print STDERR
"error: unable to make a backup of $filename:\n";
2071 print STDERR
" $!\n";
2075 if (!open(FILEI
,"$filename.bak")) {
2076 print STDERR
"error: unable to open $filename.bak for reading:\n";
2077 print STDERR
" $!\n";
2080 if (!open(FILEO
,">$filename")) {
2081 print STDERR
"error: unable to open $filename for writing:\n";
2082 print STDERR
" $!\n";
2087 my $rc_block_depth=0;
2088 my $rc_textinclude_state=0;
2091 # Remove any trailing CtrlZ, which isn't strictly in the file
2099 # Make sure all files are '\n' terminated
2102 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
2103 # VC6 automatically includes 'afxres.h', an MFC specific header, in
2104 # the RC files it generates (even in non-MFC projects). So we replace
2105 # it with 'winresrc.h' its very close standard cousin so that non MFC
2106 # projects can compile in Wine without the MFC sources.
2107 my $warning="mfc:afxres.h";
2108 if (!defined $warnings{$warning}) {
2109 $warnings{$warning}="1";
2110 print STDERR
"warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
2111 print STDERR
"warning: the above warning is issued only once\n";
2113 print FILEO
"$1/* winemaker: $2\"afxres.h\" */\n";
2114 print FILEO
"$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
2115 print FILEO
"$1$2\"winresrc.h\"$'";
2118 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
2119 my $from_file=($2 eq "<"?
"":$dirname);
2120 my $real_include_name=get_real_include_name
($line,$3,$from_file,$project,$target);
2121 print FILEO
"$1$2$real_include_name$4$'";
2122 $modified|=($real_include_name ne $3);
2124 } elsif (/^(\s*)\#\s*pragma\s+comment\s*\(\s*lib\s*,\s*\"(\w+)\.lib\"\s*\)/) {
2125 my $pragma_indent=$1;
2127 push @
{@
$target[$T_LIBRARIES]},$pragma_lib;
2128 print FILEO
"$pragma_indent/* winemaker: Added -l$pragma_lib to the libraries */\n";
2129 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
2130 # Pragma pack handling
2132 # pack_stack is an array of references describing the stack of
2133 # pack directives currently in effect. Each directive if described
2134 # by a reference to an array containing:
2135 # - "push" for pack(push,...) directives, "" otherwise
2136 # - the directive's identifier at index 1
2137 # - the directive's alignment value at index 2
2139 # Don't believe a word of what the documentation says: it's all wrong.
2140 # The code below is based on the actual behavior of Visual C/C++ 6.
2145 # Pushes the default stack alignment
2146 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
2147 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2148 print_pack
($pack_indent,4,$');
2149 push @pack_stack, [ "", "", 4 ];
2151 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
2153 # pragma pack(pop,n)
2154 # Goes up the stack until it finds a pack(push,...), and pops it
2155 # Ignores any pack(n) entry
2156 # Issues a warning if the pack is of the form pack(push,label)
2157 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2158 my $pack_comment=$';
2159 $pack_comment =~ s/^\s*//;
2160 if ($pack_comment ne "") {
2161 print FILEO
"$pack_indent$pack_comment";
2164 my $alignment=pop @pack_stack;
2165 if (!defined $alignment) {
2166 print FILEO
"$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2169 if (@
$alignment[1]) {
2170 print FILEO
"$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2172 print FILEO
"$pack_indent#include <poppack.h>\n";
2173 if (@
$alignment[0]) {
2178 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2179 # pragma pack(pop,label[,n])
2180 # Goes up the stack until finding a pack(push,...) and pops it.
2181 # 'n', if specified, is ignored.
2182 # Ignores any pack(n) entry
2183 # Issues a warning if the label of the pack does not match,
2184 # or if it is in fact a pack(push,n)
2186 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
2187 my $pack_comment=$';
2188 $pack_comment =~ s/^\s*//;
2189 if ($pack_comment ne "") {
2190 print FILEO "$pack_indent$pack_comment";
2193 my $alignment=pop @pack_stack;
2194 if (!defined $alignment) {
2195 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2198 if (@$alignment[1] and @$alignment[1] ne $label) {
2199 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2201 print FILEO "$pack_indent#include <poppack.h>\n";
2202 if (@$alignment[0]) {
2207 } elsif (/^(push\s*\))/) {
2209 # Push the current alignment
2210 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2211 if (@pack_stack > 0) {
2212 my $alignment=$pack_stack[$#pack_stack];
2213 print_pack($pack_indent,@$alignment[2],$');
2214 push @pack_stack, [ "push", "", @
$alignment[2] ];
2216 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2217 print_pack
($pack_indent,4,$');
2218 push @pack_stack, [ "push", "", 4 ];
2221 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2222 # pragma pack([push,]n)
2223 # Push new alignment n
2224 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2225 print_pack($pack_indent,$3,"$'");
2226 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2228 } elsif (/^((\w+)\s*\))/) {
2229 # pragma pack(label)
2230 # label must in fact be a macro that resolves to an integer
2231 # Then behaves like 'pragma pack(n)'
2232 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2233 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2234 print_pack($pack_indent,4,$');
2235 push @pack_stack, [ "", "", 4 ];
2237 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2238 # pragma pack(push,label[,n])
2239 # Pushes a new label on the stack. It is possible to push the same
2240 # label multiple times. If 'n' is omitted then the alignment is
2241 # unchanged. Otherwise it becomes 'n'.
2242 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2246 } elsif (@pack_stack > 0) {
2247 my $alignment=$pack_stack[$#pack_stack];
2248 $size=@$alignment[2];
2250 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2253 print_pack($pack_indent,$size,$');
2254 push @pack_stack, [ "push", $2, $size ];
2257 # pragma pack(??? -> What's that?
2258 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2259 print FILEO "$pack_indent$pack_header$_";
2265 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]+)([\">]?)/) {
2266 my $from_file=($5 eq "<"?"":$dirname);
2267 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2268 print FILEO "$1$5$real_include_name$7$'";
2269 $modified|=($real_include_name ne $6);
2271 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2272 my $from_file=($2 eq "<"?"":$dirname);
2273 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2274 print FILEO "$1$2$real_include_name$4$'";
2275 $modified|=($real_include_name ne $3);
2277 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2278 $rc_textinclude_state=1;
2281 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2282 print FILEO "$1winresrc.h
$2$'";
2285 } elsif (/^\s*BEGIN(\W.*)?$/) {
2286 $rc_textinclude_state|=2;
2290 } elsif (/^\s*END(\W.*)?$/) {
2291 $rc_textinclude_state=0;
2292 if ($rc_block_depth>0) {
2308 if ($opt_backup == 0 or $modified == 0) {
2309 if (!unlink("$filename.bak")) {
2310 print STDERR "error: unable to delete $filename.bak:\n";
2311 print STDERR " $!\n";
2317 # Analyzes each source file in turn to find and correct issues
2318 # that would cause it not to compile.
2321 print "Fixing the source files...\n";
2322 foreach my $project (@projects) {
2323 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2324 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2325 fix_file($source,$project,$target);
2340 # A convenience function to generate all the lists (defines,
2341 # C sources, C++ source, etc.) in the Makefile
2342 sub generate_list($$$;$)
2351 printf FILEO "%-22s=",$name;
2353 if (defined $list) {
2354 foreach my $item (@$list) {
2356 if (defined $data) {
2357 $value=&$data($item);
2359 if (defined $item) {
2367 print FILEO " $value";
2370 print FILEO " \\\n\t\t\t$value";
2381 # Generates a project's Makefile
and all the target files
2382 sub generate_project_files
($)
2385 my $project_settings=@
$project[$P_SETTINGS];
2390 # Then sort the targets and separate the libraries from the programs
2391 foreach my $target (sort { @
$a[$T_NAME] cmp @
$b[$T_NAME] } @
{@
$project[$P_TARGETS]}) {
2392 if (@
$target[$T_TYPE] == $TT_DLL) {
2393 push @dll_list,$target;
2394 } elsif (@
$target[$T_TYPE] == $TT_LIB) {
2395 push @lib_list,$target;
2397 push @exe_list,$target;
2400 @
$project[$P_TARGETS]=[];
2401 push @
{@
$project[$P_TARGETS]}, @dll_list;
2402 push @
{@
$project[$P_TARGETS]}, @lib_list;
2403 push @
{@
$project[$P_TARGETS]}, @exe_list;
2405 if (!open(FILEO
,">@$project[$P_PATH]Makefile")) {
2406 print STDERR
"error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2407 print STDERR
" $!\n";
2410 binmode( FILEO
, ':utf8' );
2413 if (@
$project_settings[$T_FLAGS] & $TF_HASCXX) {
2414 $cpp_to_object=".cxx=.o";
2416 $cpp_to_object=".cpp=.o";
2419 print FILEO
"### Generated by Winemaker $version\n";
2420 print FILEO
"###\n";
2421 print FILEO
"### Invocation command line was\n";
2422 print FILEO
"### $0";
2426 print FILEO
"\n\n\n";
2428 generate_list
("SRCDIR",1,[ "." ]);
2429 if (@
$project[$P_PATH] eq "") {
2430 # This is the main project. It is also responsible for recursively
2431 # calling the other projects
2432 generate_list
("SUBDIRS",1,\
@projects,sub
2434 if ($_[0] != \
@main_project) {
2435 my $subdir=@
{$_[0]}[$P_PATH];
2439 # Eliminating the main project by returning undefined!
2442 if (@
{@
$project[$P_TARGETS]} > 0) {
2443 generate_list
("DLLS",1,\
@dll_list,sub
2445 return @
{$_[0]}[$T_NAME];
2447 generate_list
("LIBS",1,\
@lib_list,sub
2449 return @
{$_[0]}[$T_NAME];
2451 generate_list
("EXES",1,\
@exe_list,sub
2453 return "@{$_[0]}[$T_NAME]";
2455 print FILEO
"\n\n\n";
2457 print FILEO
"### Common settings\n\n";
2458 # Make it so that the project-wide settings override the global settings
2459 generate_list
("CEXTRA",1,@
$project_settings[$T_CEXTRA]);
2460 generate_list
("CXXEXTRA",1,@
$project_settings[$T_CXXEXTRA]);
2461 generate_list
("RCEXTRA",1,@
$project_settings[$T_RCEXTRA]);
2462 generate_list
("DEFINES",1,@
$project_settings[$T_DEFINES]);
2463 generate_list
("INCLUDE_PATH",1,@
$project_settings[$T_INCLUDE_PATH]);
2464 generate_list
("DLL_PATH",1,@
$project_settings[$T_DLL_PATH]);
2465 generate_list
("DLL_IMPORTS",1,@
$project_settings[$T_DLLS]);
2466 generate_list
("LIBRARY_PATH",1,@
$project_settings[$T_LIBRARY_PATH]);
2467 generate_list
("LIBRARIES",1,@
$project_settings[$T_LIBRARIES]);
2470 my $extra_source_count=@
{@
$project_settings[$T_SOURCES_C]}+
2471 @
{@
$project_settings[$T_SOURCES_CXX]}+
2472 @
{@
$project_settings[$T_SOURCES_RC]};
2473 my $no_extra=($extra_source_count == 0);
2475 print FILEO
"### Extra source lists\n\n";
2476 generate_list
("EXTRA_C_SRCS",1,@
$project_settings[$T_SOURCES_C]);
2477 generate_list
("EXTRA_CXX_SRCS",1,@
$project_settings[$T_SOURCES_CXX]);
2478 generate_list
("EXTRA_RC_SRCS",1,@
$project_settings[$T_SOURCES_RC]);
2480 generate_list
("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:$cpp_to_object)"]);
2481 print FILEO
"\n\n\n";
2484 # Iterate over all the targets...
2485 foreach my $target (@
{@
$project[$P_TARGETS]}) {
2486 print FILEO
"### @$target[$T_NAME] sources and settings\n\n";
2487 my $canon=canonize
("@$target[$T_NAME]");
2490 generate_list
("${canon}_MODULE",1,[@
$target[$T_NAME]]);
2491 generate_list
("${canon}_C_SRCS",1,@
$target[$T_SOURCES_C]);
2492 generate_list
("${canon}_CXX_SRCS",1,@
$target[$T_SOURCES_CXX]);
2493 generate_list
("${canon}_RC_SRCS",1,@
$target[$T_SOURCES_RC]);
2494 generate_list
("${canon}_LDFLAGS",1,@
$target[$T_LDFLAGS]);
2495 generate_list
("${canon}_ARFLAGS",1,@
$target[$T_ARFLAGS]);
2496 generate_list
("${canon}_DLL_PATH",1,@
$target[$T_DLL_PATH]);
2497 generate_list
("${canon}_DLLS",1,@
$target[$T_DLLS]);
2498 generate_list
("${canon}_LIBRARY_PATH",1,@
$target[$T_LIBRARY_PATH]);
2499 generate_list
("${canon}_LIBRARIES",1,@
$target[$T_LIBRARIES]);
2501 generate_list
("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:$cpp_to_object)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2502 print FILEO
"\n\n\n";
2504 print FILEO
"### Global source lists\n\n";
2505 generate_list
("C_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2507 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2509 return "\$(${canon}_C_SRCS)";
2512 generate_list
("",1,[ "\$(EXTRA_C_SRCS)" ]);
2514 generate_list
("CXX_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2516 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2518 return "\$(${canon}_CXX_SRCS)";
2521 generate_list
("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2523 generate_list
("RC_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2525 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2527 return "\$(${canon}_RC_SRCS)";
2530 generate_list
("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2534 print FILEO
"### Tools\n\n";
2535 print FILEO
"CC = winegcc\n";
2536 print FILEO
"CXX = wineg++\n";
2537 print FILEO
"RC = wrc\n";
2538 print FILEO
"AR = ar\n";
2541 print FILEO
"### Generic targets\n\n";
2543 if (@
$project[$P_PATH] eq "") {
2544 print FILEO
" \$(SUBDIRS)";
2546 if (@
{@
$project[$P_TARGETS]} > 0) {
2547 print FILEO
" \$(DLLS:%=%.so) \$(LIBS) \$(EXES)";
2550 print FILEO
"### Build rules\n";
2552 print FILEO
".PHONY: all clean dummy\n";
2554 print FILEO
"\$(SUBDIRS): dummy\n";
2555 print FILEO
"\t\@cd \$\@ && \$(MAKE)\n";
2557 print FILEO
"# Implicit rules\n";
2559 print FILEO
".SUFFIXES: .cpp .cxx .rc .res\n";
2560 print FILEO
"DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2562 print FILEO
".c.o:\n";
2563 print FILEO
"\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2565 print FILEO
".cpp.o:\n";
2566 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2568 print FILEO
".cxx.o:\n";
2569 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2571 print FILEO
".rc.res:\n";
2572 print FILEO
"\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2574 print FILEO
"# Rules for cleaning\n";
2576 print FILEO
"CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2577 print FILEO
" \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2579 print FILEO
"clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2580 print FILEO
"\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:$cpp_to_object)\n";
2581 print FILEO
"\t\$(RM) \$(DLLS:%=%.so) \$(LIBS) \$(EXES) \$(EXES:%=%.so)\n";
2583 print FILEO
"\$(SUBDIRS:%=%/__clean__): dummy\n";
2584 print FILEO
"\tcd `dirname \$\@` && \$(MAKE) clean\n";
2586 print FILEO
"\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2587 print FILEO
"\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2590 if (@
{@
$project[$P_TARGETS]} > 0) {
2591 print FILEO
"### Target specific build rules\n";
2592 print FILEO
"DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2593 foreach my $target (@
{@
$project[$P_TARGETS]}) {
2594 my $canon=canonize
("@$target[$T_NAME]");
2597 if (@
$target[$T_TYPE] == $TT_DLL && (@
$project_settings[$T_FLAGS] & $TF_HASDEF)) {
2598 print FILEO
"\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.def)\n";
2599 } elsif (@
$target[$T_TYPE] == $TT_DLL) {
2600 print FILEO
"\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.spec)\n";
2602 print FILEO
"\$(${canon}_MODULE): \$(${canon}_OBJS)\n";
2605 if (@
$target[$T_TYPE] == $TT_LIB) {
2606 print FILEO
"\t\$(AR) \$(${canon}_ARFLAGS) \$\@ \$(${canon}_OBJS)\n";
2608 if (@
{@
$target[$T_SOURCES_CXX]} > 0 or @
{@
$project_settings[$T_SOURCES_CXX]} > 0) {
2609 print FILEO
"\t\$(CXX)";
2611 print FILEO
"\t\$(CC)";
2613 print FILEO
" \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(${canon}_DLL_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2624 # This is where we finally generate files. In fact this method does not
2625 # do anything itself but calls the methods that do the actual work.
2628 print "Generating project files...\n";
2630 foreach my $project (@projects) {
2631 my $path=@
$project[$P_PATH];
2638 generate_project_files
($project);
2651 $opt_lower=$OPT_LOWER_UPPERCASE;
2652 $opt_lower_include=1;
2654 $opt_work_dir=undef;
2655 $opt_single_target=undef;
2656 $opt_target_type=$TT_GUIEXE;
2658 $opt_arch=$OPT_ARCH_DEFAULT;
2659 $opt_is_interactive=$OPT_ASK_NO;
2660 $opt_ask_project_options=$OPT_ASK_NO;
2661 $opt_ask_target_options=$OPT_ASK_NO;
2662 $opt_no_generated_files=0;
2663 $opt_no_source_fix=0;
2676 print "Winemaker $version\n";
2677 print "Copyright 2000-2004 François Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2678 print "Copyright 2004 Dimitrie O. Paun\n";
2679 print "Copyright 2009-2012 André Hentschel\n";
2685 print STDERR
"Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2686 print STDERR
" [--lower-none|--lower-all|--lower-uppercase]\n";
2687 print STDERR
" [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2688 print STDERR
" [--guiexe|--windows|--cuiexe|--console|--dll|--lib]\n";
2689 print STDERR
" [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2690 print STDERR
" [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2691 print STDERR
" [--generated-files|--nogenerated-files]\n";
2692 print STDERR
" [--wine32]\n";
2693 print STDERR
" work_directory|project_file|workspace_file\n";
2694 print STDERR
"\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2695 print STDERR
"the specified directory or project-file, so that they can be compiled with Winelib.\n";
2696 print STDERR
"During this process it will modify and rename some of the corresponding files.\n";
2697 print STDERR
"\tPlease read the manual page before use.\n";
2701 binmode(STDOUT
, ":utf8");
2703 target_init
(\
@global_settings);
2708 if ($arg eq "--nobanner") {
2710 } elsif ($arg eq "--backup") {
2712 } elsif ($arg eq "--nobackup") {
2714 } elsif ($arg eq "--single-target") {
2715 $opt_single_target=shift @ARGV;
2716 } elsif ($arg eq "--lower-none") {
2717 $opt_lower=$OPT_LOWER_NONE;
2718 } elsif ($arg eq "--lower-all") {
2719 $opt_lower=$OPT_LOWER_ALL;
2720 } elsif ($arg eq "--lower-uppercase") {
2721 $opt_lower=$OPT_LOWER_UPPERCASE;
2722 } elsif ($arg eq "--lower-include") {
2723 $opt_lower_include=1;
2724 } elsif ($arg eq "--nolower-include") {
2725 $opt_lower_include=0;
2726 } elsif ($arg eq "--nosource-fix") {
2727 $opt_no_source_fix=1;
2728 } elsif ($arg eq "--generated-files") {
2729 $opt_no_generated_files=0;
2730 } elsif ($arg eq "--nogenerated-files") {
2731 $opt_no_generated_files=1;
2732 } elsif ($arg eq "--wine32") {
2733 $opt_arch=$OPT_ARCH_32;
2734 } elsif ($arg =~ /^-D/) {
2735 push @
{$global_settings[$T_DEFINES]},$arg;
2736 } elsif ($arg =~ /^-I/) {
2737 push @
{$global_settings[$T_INCLUDE_PATH]},$arg;
2738 } elsif ($arg =~ /^-P/) {
2739 push @
{$global_settings[$T_DLL_PATH]},"-L$'";
2740 } elsif ($arg =~ /^-i/) {
2741 push @
{$global_settings[$T_DLLS]},$';
2742 } elsif ($arg =~ /^-L/) {
2743 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2744 } elsif ($arg =~ /^-l/) {
2745 push @{$global_settings[$T_LIBRARIES]},$arg;
2747 # 'Source
'-based method options
2748 } elsif ($arg eq "--dll") {
2749 $opt_target_type=$TT_DLL;
2750 } elsif ($arg eq "--lib") {
2751 $opt_target_type=$TT_LIB;
2752 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2753 $opt_target_type=$TT_GUIEXE;
2754 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2755 $opt_target_type=$TT_CUIEXE;
2756 } elsif ($arg eq "--interactive") {
2757 $opt_is_interactive=$OPT_ASK_YES;
2758 $opt_ask_project_options=$OPT_ASK_YES;
2759 $opt_ask_target_options=$OPT_ASK_YES;
2760 } elsif ($arg eq "--mfc") {
2761 $opt_flags|=$TF_MFC;
2762 } elsif ($arg eq "--nomfc") {
2763 $opt_flags&=~$TF_MFC;
2764 $opt_flags|=$TF_NOMFC;
2765 } elsif ($arg eq "--nodlls") {
2766 $opt_flags|=$TF_NODLLS;
2767 } elsif ($arg eq "--nomsvcrt") {
2768 $opt_flags|=$TF_NOMSVCRT;
2772 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2773 if (!defined $opt_work_dir and !defined $opt_work_file) {
2775 $opt_work_file=$arg;
2781 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2790 if (!defined $opt_work_dir and !defined $opt_work_file) {
2791 print STDERR "error: you must specify the directory or project file containing the sources to be converted\n";
2793 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2794 print STDERR "error: could not chdir to the work directory\n";
2795 print STDERR " $!\n";
2799 if ($opt_no_banner == 0) {
2803 project_init(\@main_project, "", \@global_settings);
2805 # Fix the file and directory names
2806 fix_file_and_directory_names(".");
2808 # Scan the sources to identify the projects and targets
2811 # Fix the source files
2812 if (! $opt_no_source_fix) {
2816 # Generate the Makefile and the spec file
2817 if (! $opt_no_generated_files) {