4 # Copyright 2000-2004 Francois Gouget for CodeWeavers
5 # Copyright 2004 Dimitrie O. Paun
6 # Copyright 2009-2011 André Hentschel
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
37 # The following constants define what we do with the case of filenames
40 # Never rename a file to lowercase
44 # Rename all files to lowercase
48 # Rename only files that are all uppercase to lowercase
49 my $OPT_LOWER_UPPERCASE=2;
52 # The following constants define whether to ask questions or not
55 # No (synonym of never)
63 # Skip the questions till the end of this scope
67 # The following constants define the architecture
70 # Default Architecture will be chosen
71 my $OPT_ARCH_DEFAULT=0;
85 # This is the directory in which winemaker will operate.
89 # This is the file in which winemaker will operate if a project file is specified.
93 # Make a backup of the files
97 # Defines which files to rename
101 # If we don't find the file referenced by an include, lower it
102 my $opt_lower_include;
105 # If true then winemaker should not attempt to fix the source. This is
106 # useful if the source is known to be already in a suitable form and is
108 my $opt_no_source_fix;
110 # Options for the 'Source' method
113 # Specifies that we have only one target so that all sources relate
114 # to this target. By default this variable is left undefined which
115 # means winemaker should try to find out by itself what the targets
116 # are. If not undefined then this contains the name of the default
117 # target (without the extension).
118 my $opt_single_target;
121 # If '$opt_single_target' has been specified then this is the type of
122 # that target. Otherwise it specifies whether the default target type
123 # is guiexe or cuiexe.
127 # Contains the default set of flags to be used when creating a new target.
131 # Contains 32 for 32-Bit-Targets and 64 for 64-Bit-Targets
135 # If true then winemaker should ask questions to the user as it goes
137 my $opt_is_interactive;
138 my $opt_ask_project_options;
139 my $opt_ask_target_options;
142 # If false then winemaker should not generate the makefiles.
143 my $opt_no_generated_files;
146 # Specifies not to print the banner if set.
153 # Target modelization
157 # The description of a target is stored in an array. The constants
158 # below identify what is stored at each index of the array.
161 # This is the name of the target.
165 # Defines the type of target we want to build. See the TT_xxx
170 # This is a bitfield containing flags refining the way the target
171 # should be handled. See the TF_xxx constants below
175 # This is a reference to an array containing the list of the
176 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
180 my $T_SOURCES_MISC=6;
183 # This is a reference to an array containing the list of
188 # This is a reference to an array containing the list of
189 # C++ compiler options
193 # This is a reference to an array containing the list of
194 # RC compiler options
198 # This is a reference to an array containing the list of macro
203 # This is a reference to an array containing the list of directory
204 # names that constitute the include path
205 my $T_INCLUDE_PATH=11;
208 # Flags for the linker
212 # Same as T_INCLUDE_PATH but for the dll search path
216 # The list of Windows dlls to import
220 # Same as T_INCLUDE_PATH but for the library search path
221 my $T_LIBRARY_PATH=15;
224 # The list of Unix libraries to link with
228 # The following constants define the recognized types of target
231 # This is not a real target. This type of target is used to collect
232 # the sources that don't seem to belong to any other target. Thus no
233 # real target is generated for them, we just put the sources of the
234 # fake target in the global source list.
238 # For executables in the windows subsystem
242 # For executables in the console subsystem
246 # For dynamically linked libraries
250 # The following constants further refine how the target should be handled
253 # This target is an MFC-based target
257 # User has specified --nomfc option for this target or globally
261 # --nodlls option: Do not use standard DLL set
265 # --nomsvcrt option: Do not link with msvcrt
269 # This target has a def file (only use it with TT_DLL)
273 # Initialize a target:
274 # - set the target type to TT_SETTINGS, i.e. no real target will
280 @$target[$T_TYPE]=$TT_SETTINGS;
281 @$target[$T_FLAGS]=$opt_flags;
282 @$target[$T_SOURCES_C]=[];
283 @$target[$T_SOURCES_CXX]=[];
284 @$target[$T_SOURCES_RC]=[];
285 @$target[$T_SOURCES_MISC]=[];
286 @$target[$T_CEXTRA]=[];
287 @$target[$T_CXXEXTRA]=[];
288 @$target[$T_RCEXTRA]=[];
289 @$target[$T_DEFINES]=[];
290 @$target[$T_INCLUDE_PATH]=[];
291 @$target[$T_LDFLAGS]=[];
292 @$target[$T_DLL_PATH]=[];
293 @$target[$T_DLLS]=[];
294 @$target[$T_LIBRARY_PATH]=[];
295 @$target[$T_LIBRARIES]=[];
302 # Project modelization
306 # First we have the notion of project. A project is described by an
307 # array (since we don't have structs in perl). The constants below
308 # identify what is stored at each index of the array.
311 # This is the path in which this project is located. In other
312 # words, this is the path to the Makefile.
316 # This index contains a reference to an array containing the project-wide
317 # settings. The structure of that arrray is actually identical to that of
318 # a regular target since it can also contain extra sources.
322 # This index contains a reference to an array of targets for this
323 # project. Each target describes how an executable or library is to
324 # be built. For each target this description takes the same form as
325 # that of the project: an array. So this entry is an array of arrays.
329 # Initialize a project:
330 # - set the project's path
331 # - initialize the target list
332 # - create a default target (will be removed later if unnecessary)
333 sub project_init($$$)
335 my ($project, $path, $global_settings)=@_;
337 my $project_settings=[];
338 target_init($project_settings);
339 @$project_settings[$T_DEFINES]=[@{@$global_settings[$T_DEFINES]}];
340 @$project_settings[$T_INCLUDE_PATH]=[@{@$global_settings[$T_INCLUDE_PATH]}];
341 @$project_settings[$T_DLL_PATH]=[@{@$global_settings[$T_DLL_PATH]}];
342 @$project_settings[$T_DLLS]=[@{@$global_settings[$T_DLLS]}];
343 @$project_settings[$T_LIBRARY_PATH]=[@{@$global_settings[$T_LIBRARY_PATH]}];
344 @$project_settings[$T_LIBRARIES]=[@{@$global_settings[$T_LIBRARIES]}];
346 @$project[$P_PATH]=$path;
347 @$project[$P_SETTINGS]=$project_settings;
348 @$project[$P_TARGETS]=[];
364 # This maps a directory name to a reference to an array listing
365 # its contents (files and directories)
369 # Contains the list of all projects. This list tells us what are
370 # the subprojects of the main Makefile and where we have to generate
375 # This is the main project, i.e. the one in the "." directory.
376 # It may well be empty in which case the main Makefile will only
377 # call out subprojects.
381 # Contains the defaults for the include path, etc.
382 # We store the defaults as if this were a target except that we only
383 # exploit the defines, include path, library path, library list and misc
396 # Cleans up a name to make it an acceptable Makefile
402 $name =~ tr/a-zA-Z0-9_/_/c;
407 # Returns true is the specified pathname is absolute.
408 # Note: pathnames that start with a variable '$' or
409 # '~' are considered absolute.
414 return ($path =~ /^[\/~\$]/);
418 # Retrieves the contents of the specified directory.
419 # We either get it from the directories hashtable which acts as a
420 # cache, or use opendir, readdir, closedir and store the result
422 sub get_directory_contents($)
427 #print "getting the contents of $dirname\n";
429 # check for a cached version
431 if ($dirname eq "") {
434 $directory=$directories{$dirname};
435 if (defined $directory) {
436 #print "->@$directory\n";
440 # Read this directory
441 if (opendir(DIRECTORY, "$dirname")) {
442 my @files=readdir DIRECTORY;
446 # Return an empty list
447 #print "error: cannot open $dirname\n";
451 #print "->@$directory\n";
452 $directories{$dirname}=$directory;
457 # Removes a directory from the cache.
458 # This is needed if one of its files or subdirectory has been renamed.
459 sub clear_directory_cache($)
462 delete $directories{$dirname};
468 # 'Source'-based Project analysis
473 # Allows the user to specify makefile and target specific options
474 # - target: the structure in which to store the results
475 # - options: the string containing the options
476 sub source_set_options($$)
481 #FIXME: we must deal with escaping of stuff and all
482 foreach my $option (split / /,$options) {
483 if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
484 push @{@$target[$T_DEFINES]},$option;
485 } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
486 push @{@$target[$T_INCLUDE_PATH]},$option;
487 } elsif ($option =~ /^-P/) {
488 push @{@$target[$T_DLL_PATH]},"-L$'";
489 } elsif ($option =~ /^-i/) {
490 push @{@$target[$T_DLLS]},"$'";
491 } elsif ($option =~ /^-L/) {
492 push @{@$target[$T_LIBRARY_PATH]},$option;
493 } elsif ($option =~ /^-l/) {
494 push @{@$target[$T_LIBRARIES]},"$'";
495 } elsif ($option =~ /^--mfc/) {
496 @$target[$T_FLAGS]|=$TF_MFC;
497 @$target[$T_FLAGS]&=~$TF_NOMFC;
498 } elsif ($option =~ /^--nomfc/) {
499 @$target[$T_FLAGS]&=~$TF_MFC;
500 @$target[$T_FLAGS]|=$TF_NOMFC;
501 } elsif ($option =~ /^--nodlls/) {
502 @$target[$T_FLAGS]|=$TF_NODLLS;
503 } elsif ($option =~ /^--nomsvcrt/) {
504 @$target[$T_FLAGS]|=$TF_NOMSVCRT;
506 print STDERR "error: unknown option \"$option\"\n";
514 # Scans the specified project file to:
515 # - get a list of targets for this project
516 # - get some settings
517 # - get the list of source files
518 sub source_scan_project_file($$$);
519 sub source_scan_project_file($$$)
521 # a reference to the parent's project
522 my $parent_project=$_[0];
523 # 0 if it is a single project, 1 if it is part of a workspace
524 my $is_sub_project=$_[1];
525 # the name of the project file, with complete path, or without if in
529 # reference to the project for this file. May not be used
531 # list of sources found in the current file
537 my $path=dirname($filename);
538 my $prj_target_cflags;
539 my $prj_target_defines;
540 my $prj_target_ldflags;
545 my $prj_target_type=$TT_GUIEXE;
546 my @prj_target_options;
548 if (!($path=~/\/$/)) {
552 if (defined $opt_single_target or $is_sub_project == 0) {
553 # Either there is a single target and thus a single project,
554 # or we are a single project-file for which a project
556 $project=$parent_project;
559 project_init($project, $path, \@global_settings);
561 my $project_settings=@$project[$P_SETTINGS];
563 if ($filename =~ /.dsp$/i) {
564 # First find out what this project file contains:
565 # collect all sources, find targets and settings
566 if (!open(FILEI,$filename)) {
567 print STDERR "error: unable to open $filename for reading:\n";
568 print STDERR " $!\n";
573 # Remove any trailing CtrlZ, which isn't strictly in the file
579 # Remove any trailing CrLf
582 # Make sure all lines are '\n' terminated
586 if (/^\# Microsoft Developer Studio Project File - Name=\"([^\"]+)/) {
588 $prj_name=~s/\s+/_/g;
591 } elsif (/^# TARGTYPE/) {
592 if (/[[:space:]]0+x0*101$/) {
594 $prj_target_type=$TT_GUIEXE;
595 }elsif (/[[:space:]]0+x0*102$/) {
596 # Dynamic-Link Library
597 $prj_target_type=$TT_DLL;
598 }elsif (/[[:space:]]0+x0*103$/) {
599 # Console Application
600 $prj_target_type=$TT_CUIEXE;
601 }elsif (/[[:space:]]0+x0*104$/) {
605 } elsif (/^# ADD CPP(.*)/ && $found_cfg==1) {
606 $prj_target_cflags=$1;
607 @prj_target_options=split(/\s+\//, $prj_target_cflags);
608 $prj_target_cflags="";
609 foreach ( @prj_target_options ) {
613 # Suppress Startup Banner and Information Messages
615 # Turns off all warning messages
616 $prj_target_cflags.="-w ";
617 } elsif (/^W[123]$/) {
619 $prj_target_cflags.="-W ";
622 $prj_target_cflags.="-Wall ";
625 $prj_target_cflags.="-Werror ";
627 # Enable Minimal Rebuild
629 # Enable Exception Handling
630 $prj_target_cflags.="-fexceptions ";
632 # use cdecl calling convention (default)
634 # use fastcall calling convention
636 # use stdcall calling convention
637 $prj_target_cflags.="-mrtd ";
638 } elsif (/^Z[d7iI]$/) {
640 $prj_target_cflags.="-g ";
642 # Disable Optimizations
643 $prj_target_cflags.="-O0 ";
646 $prj_target_cflags.="-Os ";
649 $prj_target_cflags.="-O2 ";
651 # Disables inline Expansion
652 $prj_target_cflags.="-fno-inline ";
654 #In-line Function Expansion
655 $prj_target_cflags.="-finline-functions ";
657 # auto In-line Function Expansion
658 $prj_target_cflags.="-finline-functions ";
660 # Use maximum optimization
661 $prj_target_cflags.="-O3 ";
663 # Frame-Pointer Omission
664 $prj_target_cflags.="-fomit-frame-pointer ";
666 # Frame-Pointer Omission
667 $prj_target_cflags.="-fno-omit-frame-pointer ";
669 # Catch Release-Build Errors in Debug Build
670 } elsif (/^M[DLT]d?$/) {
671 # Use Multithreaded Run-Time Library
672 } elsif (/^D\s*\"(.*)\"/) {
673 # Preprocessor Definitions
674 $prj_target_defines.="-D".$1." ";
675 } elsif (/^I\s*\"(.*)\"/) {
676 # Additional Include Directories
679 if ($sfilet=~/^\w:/) {
680 print STDERR "warning: Can't fix path $sfilet\n"
682 push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$sfilet." ";
684 } elsif (/^U\s*\"(.*)\"/) {
685 # Undefines a previously defined symbol
686 $prj_target_cflags.="-U".$1." ";
692 # Automatic Use of Precompiled Headers
694 # Generate File Dependencies
696 # Compile Without Linking
697 # this option is always present and is already specified in the suffix rules
700 $prj_target_cflags.="-D_M_IX86=500 ";
702 # Pentium Pro Optimization
703 $prj_target_cflags.="-D_M_IX86=600 ";
705 # Pentium Optimization
706 $prj_target_cflags.="-D_M_IX86=500 ";
709 $prj_target_cflags.="-D_M_IX86=300 ";
712 $prj_target_cflags.="-D_M_IX86=400 ";
714 # Create Precompiled Header
716 # Use Precompiled Header
718 # Disable Language Extensions
719 $prj_target_cflags.="-ansi ";
721 # Enable Microsoft Extensions
722 } elsif (/^Zm[[:digit:]]+$/) {
723 # Specify Memory Allocation Limit
725 # Packs structures on 1-byte boundaries
726 $prj_target_cflags.="-fpack-struct ";
727 } elsif (/^Zp(2|4|8|16)$/) {
728 # Struct Member Alignment
729 $prj_target_cflags.="-fpack-struct=".$1;
731 print "C compiler option $_ not implemented\n";
735 #print "\nOptions: $prj_target_cflags\n";
737 } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
738 $prj_target_ldflags=$1;
739 @prj_target_options=split(/\s+\//, $prj_target_ldflags);
740 $prj_target_ldflags="";
741 $prj_target_libs=$prj_target_options[0];
742 $prj_target_libs=~s/\\/\//g;
743 $prj_target_libs=~s/\.lib//g;
744 $prj_target_libs=~s/\s+/ -l/g;
745 shift (@prj_target_options);
746 foreach ( @prj_target_options ) {
749 } elsif (/^base:(.*)/) {
751 $prj_target_ldflags.="--image-base ".$1." ";
752 } elsif (/^debug$/) {
753 # Generate Debug Info
756 $prj_target_type=$TT_DLL;
757 } elsif (/^incremental:[[:alpha:]]+$/) {
759 } elsif (/^implib:/) {
760 # Name import library
761 } elsif (/^libpath:\"(.*)\"/) {
763 push @{@$project_settings[$T_DLL_PATH]},"-L$1";
764 } elsif (/^machine:[[:alnum:]]+$/) {
765 # Specify Target Platform
769 $prj_target_ldflags.="-Map ".$1." ";
771 $prj_target_ldflags.="-Map ".$prj_name.".map ";
773 } elsif (/^nologo$/) {
774 # Suppress Startup Banner and Information Messages
777 # may use it as Target?
778 } elsif (/^pdbtype:/) {
779 # Program Database Storage
780 } elsif (/^subsystem:/) {
782 } elsif (/^version:[[:digit:].]+$/) {
783 # Version Information
785 print "Linker option $_ not implemented\n";
789 } elsif (/^LIB32=/ && $found_cfg==1) {
792 } elsif (/^SOURCE=(.*)$/) {
793 my @components=split /[\/\\]+/, $1;
794 $sfilet=search_from($path, \@components);
795 if (!defined $sfilet) { next; }
796 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
797 push @sources_c,$sfilet;
798 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
799 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
800 push @sources_misc,$sfilet;
801 @$project_settings[$T_FLAGS]|=$TF_MFC;
803 push @sources_cxx,$sfilet;
805 } elsif ($sfilet =~ /\.rc$/i) {
806 push @sources_rc,$sfilet;
807 } elsif ($sfilet =~ /\.def$/i) {
808 @$project_settings[$T_FLAGS]|=$TF_HASDEF;
809 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
810 push @sources_misc,$sfilet;
811 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
812 @$project_settings[$T_FLAGS]|=$TF_MFC;
817 } elsif (/^# (Begin|End) Source File/) {
818 # Source-Files already handled
820 } elsif (/^# (Begin|End) Group/) {
823 } elsif (/^# (Begin|End) Custom Build/) {
824 # Custom Builds are ignored
826 } elsif (/^# ADD LIB32 /) {
829 } elsif (/^# Begin Target$/) {
830 # Targets are ignored
832 } elsif (/^# End Target$/) {
833 # Targets are ignored
836 if ($found_cfg == 1) {
839 if (/if (.*)\(CFG\)" == "(.*)"/i) {
840 if ($2 eq $prj_cfg) {
845 } elsif (/^CFG=(.*)/i) {
849 else { # Line recognized
855 push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
856 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
857 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
858 push @{@$project_settings[$T_DEFINES]},$prj_target_defines;
859 push @{@$project_settings[$T_LDFLAGS]},$prj_target_ldflags;
860 } elsif ($filename =~ /.vcproj$/i) {
861 # Import XML::LibXML, you need the libxml package (deb: libxml-libxml-perl, rpm: perl-libxml-perl)
864 my $xmlparser = XML::LibXML->new();
865 my $project_xml = $xmlparser->parse_file($filename);
869 foreach my $vc_project ($project_xml->findnodes('/VisualStudioProject')) {
870 foreach my $vc_project_attr ($vc_project->attributes) {
871 if ($vc_project_attr->getName eq "Name") {
872 $prj_name=$vc_project_attr->getValue;
873 $prj_name=~s/\s+/_/g;
879 for (my $flevel = 0; $flevel <= 5; $flevel++) {
880 foreach my $vc_file ($project_xml->findnodes('/VisualStudioProject/Files/'.('Filter/' x $flevel).'File')) {
881 foreach my $vc_file_attr ($vc_file->attributes) {
882 if ($vc_file_attr->getName eq "RelativePath") {
883 $sfilet = $vc_file_attr->getValue;
884 $sfilet=~s/\\\\/\\/g; #remove double backslash
885 $sfilet=~s/^\.\\//; #remove starting 'this directory'
886 $sfilet=~s/\\/\//g; #make slashes out of backslashes
887 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
888 push @sources_c,$sfilet;
889 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
890 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
891 push @sources_misc,$sfilet;
892 @$project_settings[$T_FLAGS]|=$TF_MFC;
894 push @sources_cxx,$sfilet;
896 } elsif ($sfilet =~ /\.rc$/i) {
897 push @sources_rc,$sfilet;
898 } elsif ($sfilet =~ /\.def$/i) {
899 @$project_settings[$T_FLAGS]|=$TF_HASDEF;
900 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
901 push @sources_misc,$sfilet;
902 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
903 @$project_settings[$T_FLAGS]|=$TF_MFC;
911 my @vc_configurations = $project_xml->findnodes('/VisualStudioProject/Configurations/Configuration');
912 my $vc_configuration = $vc_configurations[0];
913 foreach my $vc_configuration_attr ($vc_configuration->attributes) {
914 if ($vc_configuration_attr->getName eq "ConfigurationType") {
915 if ($vc_configuration_attr->getValue==1) {
916 $prj_target_type=$TT_GUIEXE; # Application
917 } elsif ($vc_configuration_attr->getValue==2) {
918 $prj_target_type=$TT_DLL; # Dynamic-Link Library
923 foreach my $vc_configuration_tools ($vc_configuration->findnodes('Tool')) {
924 my @find_tool = $vc_configuration_tools->attributes;
925 if ($find_tool[0]->getValue eq "VCCLCompilerTool") {
926 foreach my $vc_compiler_tool ($vc_configuration_tools->attributes) {
927 if ($vc_compiler_tool->getName eq "Optimization") {$prj_target_cflags.="-O".$vc_compiler_tool->getValue." ";}
928 if ($vc_compiler_tool->getName eq "WarningLevel") {
929 if ($vc_compiler_tool->getValue==0) {
930 $prj_target_cflags.="-w ";
931 } elsif ($vc_compiler_tool->getValue<4) {
932 $prj_target_cflags.="-W ";
933 } elsif ($vc_compiler_tool->getValue==4) {
934 $prj_target_cflags.="-Wall ";
935 } elsif ($vc_compiler_tool->getValue eq "X") {
936 $prj_target_cflags.="-Werror ";
939 if ($vc_compiler_tool->getName eq "PreprocessorDefinitions") {
940 $configt=$vc_compiler_tool->getValue;
941 $configt=~s/;\s*/ -D/g;
942 $prj_target_defines.="-D".$configt." ";
944 if ($vc_compiler_tool->getName eq "AdditionalIncludeDirectories") {
945 $configt=$vc_compiler_tool->getValue;
948 push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$configt;
952 if ($find_tool[0]->getValue eq "VCLinkerTool") {
953 foreach my $vc_linker_tool ($vc_configuration_tools->attributes) {
954 if ($vc_linker_tool->getName eq "AdditionalDependencies") {
955 $prj_target_libs=" ".$vc_linker_tool->getValue;
956 $prj_target_libs=~s/\\/\//g;
957 $prj_target_libs=~s/\.lib//g;
958 $prj_target_libs=~s/\s+/ -l/g;
964 push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
965 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
966 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
967 push @{@$project_settings[$T_DEFINES]},$prj_target_defines;
970 # Add this project to the project list, except for
971 # the main project which is already in the list.
972 if ($is_sub_project == 1) {
973 push @projects,$project;
976 # Ask for project-wide options
977 if ($opt_ask_project_options == $OPT_ASK_YES) {
979 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
982 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
983 if (defined $flag_desc) {
984 print "* (currently $flag_desc)\n";
986 print "* or 'skip' to skip the target specific options,\n";
987 print "* or 'never' to not be asked this question again:\n";
991 if ($options eq "skip") {
992 $opt_ask_target_options=$OPT_ASK_SKIP;
994 } elsif ($options eq "never") {
995 $opt_ask_project_options=$OPT_ASK_NO;
997 } elsif (source_set_options($project_settings,$options)) {
1000 print "Please re-enter the options:\n";
1004 # Create the target...
1006 target_init($target);
1008 if ($prj_target_type!=$TT_DLL) {
1009 $prj_name=lc($prj_name.".exe");
1010 @$target[$T_TYPE]=$opt_target_type;
1011 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
1013 $prj_name=lc($prj_name.".dll");
1014 @$target[$T_TYPE]=$TT_DLL;
1015 my $canon=canonize($prj_name);
1016 if (@$project_settings[$T_FLAGS] & $TF_HASDEF) {
1017 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.def)");
1019 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1023 @$target[$T_NAME]=$prj_name;
1024 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
1026 # This is the default link list of Visual Studio
1027 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1028 my @std_libraries=qw(uuid);
1029 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1030 @$target[$T_DLLS]=\@std_imports;
1031 @$target[$T_LIBRARIES]=\@std_libraries;
1033 @$target[$T_DLLS]=[];
1034 @$target[$T_LIBRARIES]=[];
1036 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1037 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
1038 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1039 push @{@$target[$T_LDFLAGS]},"-m$opt_arch";
1042 push @{@$project[$P_TARGETS]},$target;
1044 # Ask for target-specific options
1045 if ($opt_ask_target_options == $OPT_ASK_YES) {
1047 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
1050 if ($flag_desc ne "") {
1053 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1054 print "* \"$prj_name\"$flag_desc or 'never' to not be asked this question again:\n";
1056 my $options=<STDIN>;
1058 if ($options eq "never") {
1059 $opt_ask_target_options=$OPT_ASK_NO;
1061 } elsif (source_set_options($target,$options)) {
1064 print "Please re-enter the options:\n";
1067 if (@$target[$T_FLAGS] & $TF_MFC) {
1068 @$project_settings[$T_FLAGS]|=$TF_MFC;
1069 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1070 push @{@$target[$T_DLLS]},"mfc.dll";
1071 # FIXME: Link with the MFC in the Unix sense, until we
1072 # start exporting the functions properly.
1073 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1074 push @{@$target[$T_LIBRARIES]},"mfc";
1078 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1079 @$project_settings[$T_SOURCES_C]=[];
1081 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1082 @$project_settings[$T_SOURCES_CXX]=[];
1084 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1085 @$project_settings[$T_SOURCES_RC]=[];
1087 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1088 @$project_settings[$T_SOURCES_MISC]=[];
1091 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1092 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1093 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1094 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1096 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1097 $opt_ask_target_options=$OPT_ASK_YES;
1100 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1101 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1102 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1103 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1104 push @{@$project_settings[$T_CEXTRA]},"-m$opt_arch";
1105 push @{@$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1109 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1110 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1112 # The sources that did not match, if any, go to the extra
1113 # source list of the project settings
1114 foreach my $source (@sources_c) {
1115 if ($source ne "") {
1116 push @{@$project_settings[$T_SOURCES_C]},$source;
1119 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1120 foreach my $source (@sources_cxx) {
1121 if ($source ne "") {
1122 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1125 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1126 foreach my $source (@sources_rc) {
1127 if ($source ne "") {
1128 push @{@$project_settings[$T_SOURCES_RC]},$source;
1131 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1132 foreach my $source (@sources_misc) {
1133 if ($source ne "") {
1134 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1137 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1141 # Scans the specified workspace file to find the project files
1142 sub source_scan_workspace_file($);
1143 sub source_scan_workspace_file($)
1146 my $path=dirname($filename);
1149 if (! -e $filename) {
1153 if (!open(FILEIWS,$filename)) {
1154 print STDERR "error: unable to open $filename for reading:\n";
1155 print STDERR " $!\n";
1162 if ($filename =~ /.dsw$/i) {
1164 # Remove any trailing CrLf
1167 # catch a project definition
1168 if (/^Project:\s\"(.*)\"=(.*)\s-/) {
1171 @components=split /[\/\\]+/, $prj_path;
1172 $prj_path=search_from($path, \@components);
1173 print "Name: $prj_name\nPath: $prj_path\n";
1174 source_scan_project_file(\@main_project,1,$prj_path);
1178 } elsif (/^Global:/) {
1179 # ignore the Global section
1181 print STDERR "unknown section $_\n";
1182 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1183 print "\nFileversion: $3\n";
1187 } elsif ($filename =~ /.sln$/i) {
1189 # Remove any trailing CrLf
1192 # catch a project definition
1193 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1196 if ($prj_path eq "Solution Items") { next; }
1197 @components=split /[\/\\]+/, $3;
1198 $prj_path=search_from($path, \@components);
1199 print "Name: $prj_name\nPath: $prj_path\n";
1200 source_scan_project_file(\@main_project,1,$prj_path);
1202 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1203 print "\nFileversion: $3\n";
1209 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1213 # Scans the specified directory to:
1214 # - see if we should create a Makefile in this directory. We normally do
1215 # so if we find a project file and sources
1216 # - get a list of targets for this directory
1217 # - get the list of source files
1218 sub source_scan_directory($$$$);
1219 sub source_scan_directory($$$$)
1221 # a reference to the parent's project
1222 my $parent_project=$_[0];
1223 # the full relative path to the current directory, including a
1224 # trailing '/', or an empty string if this is the top level directory
1226 # the name of this directory, including a trailing '/', or an empty
1227 # string if this is the top level directory
1229 # if set then no targets will be looked for and the sources will all
1230 # end up in the parent_project's 'misc' bucket
1231 my $no_target=$_[3];
1233 # reference to the project for this directory. May not be used
1235 # list of targets found in the 'current' directory
1237 # list of sources found in the current directory
1241 my @sources_misc=();
1242 # true if this directory contains a Windows project
1243 my $has_win_project=0;
1244 # true if this directory contains headers
1246 # If we don't find any executable/library then we might make up targets
1247 # from the list of .dsp/.mak files we find since they usually have the
1248 # same name as their target.
1252 if (defined $opt_single_target or $dirname eq "") {
1253 # Either there is a single target and thus a single project,
1254 # or we are in the top level directory for which a project
1256 $project=$parent_project;
1259 project_init($project, $path, \@global_settings);
1261 my $project_settings=@$project[$P_SETTINGS];
1263 # First find out what this directory contains:
1264 # collect all sources, targets and subdirectories
1265 my $directory=get_directory_contents($path);
1266 foreach my $dentry (@$directory) {
1267 if ($dentry =~ /^\./) {
1270 my $fullentry="$path$dentry";
1271 if (-d "$fullentry") {
1272 if ($dentry =~ /^(Release|Debug)/i) {
1273 # These directories are often used to store the object files and the
1274 # resulting executable/library. They should not contain anything else.
1275 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
1276 foreach my $candidate (@candidates) {
1277 $targets{$candidate}=1;
1279 } elsif ($dentry =~ /^include/i) {
1280 # This directory must contain headers we're going to need
1281 push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1282 source_scan_directory($project,"$fullentry/","$dentry/",1);
1284 # Recursively scan this directory. Any source file that cannot be
1285 # attributed to a project in one of the subdirectories will be
1286 # attributed to this project.
1287 source_scan_directory($project,"$fullentry/","$dentry/",$no_target);
1289 } elsif (-f "$fullentry") {
1290 if ($dentry =~ /\.(exe|dll)$/i) {
1291 $targets{$dentry}=1;
1292 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1293 push @sources_c,"$dentry";
1294 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
1295 if ($dentry =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1296 push @sources_misc,"$dentry";
1297 @$project_settings[$T_FLAGS]|=$TF_MFC;
1299 push @sources_cxx,"$dentry";
1301 } elsif ($dentry =~ /\.rc$/i) {
1302 push @sources_rc,"$dentry";
1303 } elsif ($dentry =~ /\.def$/i) {
1304 @$project_settings[$T_FLAGS]|=$TF_HASDEF;
1305 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1307 push @sources_misc,"$dentry";
1308 if ($dentry =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1309 @$project_settings[$T_FLAGS]|=$TF_MFC;
1311 } elsif ($dentry =~ /\.(dsp|vcproj)$/i) {
1312 push @prj_files,"$dentry";
1314 } elsif ($dentry =~ /\.mak$/i) {
1315 push @mak_files,"$dentry";
1317 } elsif ($dentry =~ /^makefile/i) {
1324 push @{@$project_settings[$T_INCLUDE_PATH]},"-I.";
1326 # If we have a single target then all we have to do is assign
1327 # all the sources to it and we're done
1328 # FIXME: does this play well with the --interactive mode?
1329 if ($opt_single_target) {
1330 my $target=@{@$project[$P_TARGETS]}[0];
1331 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1332 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1333 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1334 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1338 my $parent_settings=@$parent_project[$P_SETTINGS];
1339 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1340 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1341 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1342 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1343 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1347 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1348 @{@$project_settings[$T_SOURCES_C]}+
1349 @{@$project_settings[$T_SOURCES_CXX]}+
1350 @{@$project_settings[$T_SOURCES_RC]};
1351 if ($source_count == 0) {
1352 # A project without real sources is not a project, get out!
1353 if ($project!=$parent_project) {
1354 my $parent_settings=@$parent_project[$P_SETTINGS];
1355 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1356 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1360 #print "targets=",%targets,"\n";
1361 #print "target_count=$target_count\n";
1362 #print "has_win_project=$has_win_project\n";
1363 #print "dirname=$dirname\n";
1366 if (($has_win_project != 0) or ($dirname eq "")) {
1367 # Deal with cases where we could not find any executable/library, and
1368 # thus have no target, although we did find some sort of windows project.
1369 $target_count=keys %targets;
1370 if ($target_count == 0) {
1371 # Try to come up with a target list based on .dsp/.mak files
1373 if (@prj_files > 0) {
1374 print "Projectfile found! You might want to try using it directly.\n";
1375 $prj_list=\@prj_files;
1377 $prj_list=\@mak_files;
1379 foreach my $filename (@$prj_list) {
1380 $filename =~ s/\.(dsp|vcproj|mak)$//i;
1381 if ($opt_target_type == $TT_DLL) {
1382 $filename = "$filename.dll";
1384 $targets{$filename}=1;
1386 $target_count=keys %targets;
1387 if ($target_count == 0) {
1388 # Still nothing, try the name of the directory
1390 if ($dirname eq "") {
1391 # Bad luck, this is the top level directory!
1392 $name=(split /\//, cwd)[-1];
1395 # Remove the trailing '/'. Also eliminate whatever is after the last
1396 # '.' as it is likely to be meaningless (.orig, .new, ...)
1397 $name =~ s+(/|\.[^.]*)$++;
1398 if ($name eq "src") {
1399 # 'src' is probably a subdirectory of the real project directory.
1400 # Try again with the parent (if any).
1402 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
1405 $name=(split /\//, cwd)[-1];
1409 $name =~ s+(/|\.[^.]*)$++;
1410 if ($opt_target_type == $TT_DLL) {
1411 $name = canonize($name).".dll";
1413 $name = canonize($name).".exe";
1419 # Ask confirmation to the user if he wishes so
1420 if ($opt_is_interactive == $OPT_ASK_YES) {
1421 my $target_list=join " ",keys %targets;
1422 print "\n*** In ",($path?$path:"./"),"\n";
1423 print "* winemaker found the following list of (potential) targets\n";
1424 print "* $target_list\n";
1425 print "* Type enter to use it as is, your own comma-separated list of\n";
1426 print "* targets, 'none' to assign the source files to a parent directory,\n";
1427 print "* or 'ignore' to ignore everything in this directory tree.\n";
1428 print "* Target list:\n";
1429 $target_list=<STDIN>;
1431 if ($target_list eq "") {
1432 # Keep the target list as is, i.e. do nothing
1433 } elsif ($target_list eq "none") {
1434 # Empty the target list
1436 } elsif ($target_list eq "ignore") {
1437 # Ignore this subtree altogether
1441 foreach my $target (split /,/,$target_list) {
1442 $target =~ s+^\s*++;
1443 $target =~ s+\s*$++;
1444 $targets{$target}=1;
1450 # If we have no project at this level, then transfer all
1451 # the sources to the parent project
1452 $target_count=keys %targets;
1453 if ($target_count == 0) {
1454 if ($project!=$parent_project) {
1455 my $parent_settings=@$parent_project[$P_SETTINGS];
1456 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1457 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1458 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1459 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1460 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1465 # Otherwise add this project to the project list, except for
1466 # the main project which is already in the list.
1467 if ($dirname ne "") {
1468 push @projects,$project;
1471 # Ask for project-wide options
1472 if ($opt_ask_project_options == $OPT_ASK_YES) {
1474 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1477 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1478 if (defined $flag_desc) {
1479 print "* (currently $flag_desc)\n";
1481 print "* or 'skip' to skip the target specific options,\n";
1482 print "* or 'never' to not be asked this question again:\n";
1484 my $options=<STDIN>;
1486 if ($options eq "skip") {
1487 $opt_ask_target_options=$OPT_ASK_SKIP;
1489 } elsif ($options eq "never") {
1490 $opt_ask_project_options=$OPT_ASK_NO;
1492 } elsif (source_set_options($project_settings,$options)) {
1495 print "Please re-enter the options:\n";
1499 # - Create the targets
1500 # - Check if we have both libraries and programs
1501 # - Match each target with source files (sort in reverse
1502 # alphabetical order to get the longest matches first)
1504 my @local_depends=();
1506 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1507 # Create the target...
1509 target_init($target);
1510 @$target[$T_NAME]=$target_name;
1511 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
1512 if ($target_name =~ /\.dll$/) {
1513 @$target[$T_TYPE]=$TT_DLL;
1514 push @local_depends,"$target_name.so";
1515 push @local_dlls,$target_name;
1516 my $canon=canonize($target_name);
1517 if (@$project_settings[$T_FLAGS] & $TF_HASDEF) {
1518 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.def)");
1520 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1523 @$target[$T_TYPE]=$opt_target_type;
1524 push @exe_list,$target;
1525 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
1527 my $basename=$target_name;
1528 $basename=~ s/\.(dll|exe)$//i;
1529 # This is the default link list of Visual Studio
1530 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1531 my @std_libraries=qw(uuid);
1532 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1533 @$target[$T_DLLS]=\@std_imports;
1534 @$target[$T_LIBRARIES]=\@std_libraries;
1536 @$target[$T_DLLS]=[];
1537 @$target[$T_LIBRARIES]=[];
1539 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1540 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
1541 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1542 push @{@$target[$T_LDFLAGS]},"-m$opt_arch";
1545 push @{@$project[$P_TARGETS]},$target;
1547 # Ask for target-specific options
1548 if ($opt_ask_target_options == $OPT_ASK_YES) {
1550 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
1553 if ($flag_desc ne "") {
1556 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1557 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1559 my $options=<STDIN>;
1561 if ($options eq "never") {
1562 $opt_ask_target_options=$OPT_ASK_NO;
1564 } elsif (source_set_options($target,$options)) {
1567 print "Please re-enter the options:\n";
1570 if (@$target[$T_FLAGS] & $TF_MFC) {
1571 @$project_settings[$T_FLAGS]|=$TF_MFC;
1572 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1573 push @{@$target[$T_DLLS]},"mfc.dll";
1574 # FIXME: Link with the MFC in the Unix sense, until we
1575 # start exporting the functions properly.
1576 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1577 push @{@$target[$T_LIBRARIES]},"mfc";
1581 if ($target_count == 1) {
1582 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1583 @$project_settings[$T_SOURCES_C]=[];
1586 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1587 @$project_settings[$T_SOURCES_CXX]=[];
1590 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1591 @$project_settings[$T_SOURCES_RC]=[];
1594 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1595 # No need for sorting these sources
1596 @$project_settings[$T_SOURCES_MISC]=[];
1599 foreach my $source (@sources_c) {
1600 if ($source =~ /^$basename/i) {
1601 push @{@$target[$T_SOURCES_C]},$source;
1605 foreach my $source (@sources_cxx) {
1606 if ($source =~ /^$basename/i) {
1607 push @{@$target[$T_SOURCES_CXX]},$source;
1611 foreach my $source (@sources_rc) {
1612 if ($source =~ /^$basename/i) {
1613 push @{@$target[$T_SOURCES_RC]},$source;
1617 foreach my $source (@sources_misc) {
1618 if ($source =~ /^$basename/i) {
1619 push @{@$target[$T_SOURCES_MISC]},$source;
1624 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1625 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1626 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1627 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1629 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1630 $opt_ask_target_options=$OPT_ASK_YES;
1633 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1634 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1635 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1636 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1637 push @{@$project_settings[$T_CEXTRA]},"-m$opt_arch";
1638 push @{@$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1642 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1643 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1645 # The sources that did not match, if any, go to the extra
1646 # source list of the project settings
1647 foreach my $source (@sources_c) {
1648 if ($source ne "") {
1649 push @{@$project_settings[$T_SOURCES_C]},$source;
1652 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1653 foreach my $source (@sources_cxx) {
1654 if ($source ne "") {
1655 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1658 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1659 foreach my $source (@sources_rc) {
1660 if ($source ne "") {
1661 push @{@$project_settings[$T_SOURCES_RC]},$source;
1664 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1665 foreach my $source (@sources_misc) {
1666 if ($source ne "") {
1667 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1670 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1672 # Finally if we are building both libraries and programs in
1673 # this directory, then the programs should be linked with all
1675 if (@local_dlls > 0 and @exe_list > 0) {
1676 foreach my $target (@exe_list) {
1677 push @{@$target[$T_DLL_PATH]},"-L.";
1678 push @{@$target[$T_DLLS]},@local_dlls;
1684 # Scan the source directories in search of things to build
1687 # If there's a single target then this is going to be the default target
1688 if (defined $opt_single_target) {
1689 # Create the main target
1691 target_init($main_target);
1692 @$main_target[$T_NAME]=$opt_single_target;
1693 @$main_target[$T_TYPE]=$opt_target_type;
1695 # Add it to the list
1696 push @{$main_project[$P_TARGETS]},$main_target;
1699 # The main directory is always going to be there
1700 push @projects,\@main_project;
1702 if (defined $opt_work_dir) {
1703 # Now scan the directory tree looking for source files and, maybe, targets
1704 print "Scanning the source directories...\n";
1705 source_scan_directory(\@main_project,"","",0);
1706 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1707 } elsif (defined $opt_work_file) {
1708 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1709 source_scan_project_file(\@main_project,0,$opt_work_file);
1710 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1711 source_scan_workspace_file($opt_work_file);
1723 # Performs a directory traversal and renames the files so that:
1724 # - they have the case desired by the user
1725 # - their extension is of the appropriate case
1726 # - they don't contain annoying characters like ' ', '$', '#', ...
1727 # But only perform these changes for source files and directories.
1728 sub fix_file_and_directory_names($);
1729 sub fix_file_and_directory_names($)
1733 my $directory=get_directory_contents($dirname);
1734 foreach my $dentry (@$directory)
1736 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1739 # Set $warn to 1 if the user should be warned of the renaming
1741 my $new_name=$dentry;
1743 if (-f "$dirname/$dentry")
1745 # Don't rename Winemaker's makefiles
1746 next if ($dentry eq "Makefile" and
1747 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker/);
1749 # Leave non-source files alone
1750 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc|spec|def))$/i);
1752 # Only all lowercase extensions are supported (because of
1753 # rules like '.c.o:').
1754 $new_name =~ s/\.C$/.c/;
1755 $new_name =~ s/\.cpp$/.cpp/i;
1756 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1757 $new_name =~ s/\.rc$/.rc/i;
1758 # And this last one is to avoid confusion when running make
1759 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1762 # Adjust the case to the user's preferences
1763 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1764 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1766 $new_name=lc $new_name;
1769 # make doesn't support these characters well
1770 $new_name =~ s/[ \$]/_/g;
1772 # And finally, perform the renaming
1773 if ($new_name ne $dentry)
1776 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1778 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1779 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1780 print STDERR " $!\n";
1785 clear_directory_cache($dirname);
1788 if (-d "$dirname/$new_name") {
1789 fix_file_and_directory_names("$dirname/$new_name");
1803 # Try to find a file for the specified filename. The attempt is
1804 # case-insensitive which is why it's not trivial. If a match is
1805 # found then we return the pathname with the correct case.
1812 $dirname =~ s/(\.\/)+//;
1813 if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
1815 } elsif ($dirname !~ m+^/+) {
1816 $dirname=cwd . "/" . $dirname;
1818 if ($dirname !~ m+/$+) {
1822 foreach my $component (@$path) {
1823 $component=~s/^\"//;
1824 $component=~s/\"$//;
1825 #print " looking for $component in \"$dirname\"\n";
1826 if ($component eq ".") {
1829 } elsif ($component eq "..") {
1831 if ($dirname =~ /\.\.\/$/) {
1834 $dirname=dirname($dirname) . "/";
1838 # The file/directory may have been renamed before. Also try to
1839 # match the renamed file.
1840 my $renamed=$component;
1841 $renamed =~ s/[ \$]/_/g;
1842 if ($renamed eq $component) {
1846 my $directory=get_directory_contents $dirname;
1848 foreach my $dentry (@$directory) {
1849 if ($dentry =~ /^\Q$component\E$/i or
1850 (defined $renamed and $dentry =~ /^$renamed$/i)
1852 $dirname.="$dentry/";
1853 $real_path.="$dentry/";
1858 if (!defined $found) {
1860 #print " could not find $component in $dirname\n";
1865 $real_path=~ s+/$++;
1866 #print " -> found $real_path\n";
1871 # Performs a case-insensitive search for the specified file in the
1873 # $line is the line number that should be referenced when an error occurs
1874 # $filename is the file we are looking for
1875 # $dirname is the directory of the file containing the '#include' directive
1876 # if '"' was used, it is an empty string otherwise
1877 # $project and $target specify part of the include path
1878 sub get_real_include_name($$$$$)
1886 if ($filename =~ /^([a-zA-Z]:)?[\/\\]/ or $filename =~ /^[a-zA-Z]:[\/\\]?/) {
1887 # This is not a relative path, we cannot make any check
1888 my $warning="path:$filename";
1889 if (!defined $warnings{$warning}) {
1890 $warnings{$warning}="1";
1891 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1892 print STDERR "$line: $filename\n";
1895 # Here's how we proceed:
1896 # - split the filename we look for into its components
1897 # - then for each directory in the include path
1898 # - trace the directory components starting from that directory
1899 # - if we fail to find a match at any point then continue with
1900 # the next directory in the include path
1901 # - otherwise, rejoice, our quest is over.
1902 my @file_components=split /[\/\\]+/, $filename;
1903 #print " Searching for $filename from @$project[$P_PATH]\n";
1906 if ($dirname ne "") {
1907 # This is an 'include ""' -> look in dirname first.
1908 #print " in $dirname (include \"\")\n";
1909 $real_filename=search_from($dirname,\@file_components);
1910 if (defined $real_filename) {
1911 return $real_filename;
1914 my $project_settings=@$project[$P_SETTINGS];
1915 foreach my $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1916 my $dirname=$include;
1919 if (!is_absolute($dirname)) {
1920 $dirname="@$project[$P_PATH]$dirname";
1922 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1923 $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
1925 #print " in $dirname\n";
1926 $real_filename=search_from("$dirname",\@file_components);
1927 if (defined $real_filename) {
1928 return $real_filename;
1931 my $dotdotpath=@$project[$P_PATH];
1932 $dotdotpath =~ s/[^\/]+/../g;
1933 foreach my $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1934 my $dirname=$include;
1936 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1937 $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
1938 #print " in $dirname (global setting)\n";
1939 $real_filename=search_from("$dirname",\@file_components);
1940 if (defined $real_filename) {
1941 return $real_filename;
1945 $filename =~ s+\\\\+/+g; # in include ""
1946 $filename =~ s+\\+/+g; # in include <> !
1947 if ($opt_lower_include) {
1948 return lc "$filename";
1959 if ($size =~ /^(1|2|4|8)$/) {
1960 print FILEO "$indent#include <pshpack$size.h>$trailer";
1962 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1963 print FILEO "$indent#include <pshpack4.h>$trailer";
1968 # 'Parses' a source file and fixes constructs that would not work with
1969 # Winelib. The parsing is rather simple and not all non-portable features
1970 # are corrected. The most important feature that is corrected is the case
1971 # and path separator of '#include' directives. This requires that each
1972 # source file be associated to a project & target so that the proper
1973 # include path is used.
1974 # Also note that the include path is relative to the directory in which the
1975 # compiler is run, i.e. that of the project, not to that of the file.
1981 $filename="@$project[$P_PATH]$filename";
1982 if (! -e $filename) {
1986 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1987 my $dirname=dirname($filename);
1989 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1993 print " $filename\n";
1994 if (! -e "$filename.bak") {
1995 if (!copy("$filename","$filename.bak")) {
1996 print STDERR "error: unable to make a backup of $filename:\n";
1997 print STDERR " $!\n";
2001 if (!open(FILEI,"$filename.bak")) {
2002 print STDERR "error: unable to open $filename.bak for reading:\n";
2003 print STDERR " $!\n";
2006 if (!open(FILEO,">$filename")) {
2007 print STDERR "error: unable to open $filename for writing:\n";
2008 print STDERR " $!\n";
2013 my $rc_block_depth=0;
2014 my $rc_textinclude_state=0;
2017 # Remove any trailing CtrlZ, which isn't strictly in the file
2025 # Make sure all files are '\n' terminated
2028 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
2029 # VC6 automatically includes 'afxres.h', an MFC specific header, in
2030 # the RC files it generates (even in non-MFC projects). So we replace
2031 # it with 'winresrc.h' its very close standard cousin so that non MFC
2032 # projects can compile in Wine without the MFC sources.
2033 my $warning="mfc:afxres.h";
2034 if (!defined $warnings{$warning}) {
2035 $warnings{$warning}="1";
2036 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
2037 print STDERR "warning: the above warning is issued only once\n";
2039 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
2040 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
2041 print FILEO "$1$2\"winresrc.h\"$'";
2044 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
2045 my $from_file=($2 eq "<"?"":$dirname);
2046 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2047 print FILEO "$1$2$real_include_name$4$'";
2048 $modified|=($real_include_name ne $3);
2050 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
2051 # Pragma pack handling
2053 # pack_stack is an array of references describing the stack of
2054 # pack directives currently in effect. Each directive if described
2055 # by a reference to an array containing:
2056 # - "push" for pack(push,...) directives, "" otherwise
2057 # - the directive's identifier at index 1
2058 # - the directive's alignment value at index 2
2060 # Don't believe a word of what the documentation says: it's all wrong.
2061 # The code below is based on the actual behavior of Visual C/C++ 6.
2066 # Pushes the default stack alignment
2067 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2068 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2069 print_pack($pack_indent,4,$');
2070 push @pack_stack, [ "", "", 4 ];
2072 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
2074 # pragma pack(pop,n)
2075 # Goes up the stack until it finds a pack(push,...), and pops it
2076 # Ignores any pack(n) entry
2077 # Issues a warning if the pack is of the form pack(push,label)
2078 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2079 my $pack_comment=$';
2080 $pack_comment =~ s/^\s*//;
2081 if ($pack_comment ne "") {
2082 print FILEO "$pack_indent$pack_comment";
2085 my $alignment=pop @pack_stack;
2086 if (!defined $alignment) {
2087 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2090 if (@$alignment[1]) {
2091 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2093 print FILEO "$pack_indent#include <poppack.h>\n";
2094 if (@$alignment[0]) {
2099 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2100 # pragma pack(pop,label[,n])
2101 # Goes up the stack until finding a pack(push,...) and pops it.
2102 # 'n', if specified, is ignored.
2103 # Ignores any pack(n) entry
2104 # Issues a warning if the label of the pack does not match,
2105 # or if it is in fact a pack(push,n)
2107 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2108 my $pack_comment=$';
2109 $pack_comment =~ s/^\s*//;
2110 if ($pack_comment ne "") {
2111 print FILEO "$pack_indent$pack_comment";
2114 my $alignment=pop @pack_stack;
2115 if (!defined $alignment) {
2116 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2119 if (@$alignment[1] and @$alignment[1] ne $label) {
2120 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2122 print FILEO "$pack_indent#include <poppack.h>\n";
2123 if (@$alignment[0]) {
2128 } elsif (/^(push\s*\))/) {
2130 # Push the current alignment
2131 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2132 if (@pack_stack > 0) {
2133 my $alignment=$pack_stack[$#pack_stack];
2134 print_pack($pack_indent,@$alignment[2],$');
2135 push @pack_stack, [ "push", "", @$alignment[2] ];
2137 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2138 print_pack($pack_indent,4,$');
2139 push @pack_stack, [ "push", "", 4 ];
2142 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2143 # pragma pack([push,]n)
2144 # Push new alignment n
2145 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2146 print_pack($pack_indent,$3,"$'");
2147 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2149 } elsif (/^((\w+)\s*\))/) {
2150 # pragma pack(label)
2151 # label must in fact be a macro that resolves to an integer
2152 # Then behaves like 'pragma pack(n)'
2153 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2154 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2155 print_pack($pack_indent,4,$');
2156 push @pack_stack, [ "", "", 4 ];
2158 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2159 # pragma pack(push,label[,n])
2160 # Pushes a new label on the stack. It is possible to push the same
2161 # label multiple times. If 'n' is omitted then the alignment is
2162 # unchanged. Otherwise it becomes 'n'.
2163 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2167 } elsif (@pack_stack > 0) {
2168 my $alignment=$pack_stack[$#pack_stack];
2169 $size=@$alignment[2];
2171 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2174 print_pack($pack_indent,$size,$');
2175 push @pack_stack, [ "push", $2, $size ];
2178 # pragma pack(??? -> What's that?
2179 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2180 print FILEO "$pack_indent$pack_header$_";
2186 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]+)([\">]?)/) {
2187 my $from_file=($5 eq "<"?"":$dirname);
2188 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2189 print FILEO "$1$5$real_include_name$7$'";
2190 $modified|=($real_include_name ne $6);
2192 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2193 my $from_file=($2 eq "<"?"":$dirname);
2194 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2195 print FILEO "$1$2$real_include_name$4$'";
2196 $modified|=($real_include_name ne $3);
2198 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2199 $rc_textinclude_state=1;
2202 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2203 print FILEO "$1winresrc.h$2$'";
2206 } elsif (/^\s*BEGIN(\W.*)?$/) {
2207 $rc_textinclude_state|=2;
2211 } elsif (/^\s*END(\W.*)?$/) {
2212 $rc_textinclude_state=0;
2213 if ($rc_block_depth>0) {
2229 if ($opt_backup == 0 or $modified == 0) {
2230 if (!unlink("$filename.bak")) {
2231 print STDERR "error: unable to delete $filename.bak:\n";
2232 print STDERR " $!\n";
2238 # Analyzes each source file in turn to find and correct issues
2239 # that would cause it not to compile.
2242 print "Fixing the source files...\n";
2243 foreach my $project (@projects) {
2244 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2245 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2246 fix_file($source,$project,$target);
2261 # A convenience function to generate all the lists (defines,
2262 # C sources, C++ source, etc.) in the Makefile
2263 sub generate_list($$$;$)
2272 printf FILEO "%-22s=",$name;
2274 if (defined $list) {
2275 foreach my $item (@$list) {
2277 if (defined $data) {
2278 $value=&$data($item);
2280 if (defined $item) {
2288 print FILEO " $value";
2291 print FILEO " \\\n\t\t\t$value";
2302 # Generates a project's Makefile and all the target files
2303 sub generate_project_files($)
2306 my $project_settings=@$project[$P_SETTINGS];
2310 # Then sort the targets and separate the libraries from the programs
2311 foreach my $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
2312 if (@$target[$T_TYPE] == $TT_DLL) {
2313 push @dll_list,$target;
2315 push @exe_list,$target;
2318 @$project[$P_TARGETS]=[];
2319 push @{@$project[$P_TARGETS]}, @dll_list;
2320 push @{@$project[$P_TARGETS]}, @exe_list;
2322 if (!open(FILEO,">@$project[$P_PATH]Makefile")) {
2323 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2324 print STDERR " $!\n";
2328 print FILEO "### Generated by Winemaker $version\n";
2331 generate_list("SRCDIR",1,[ "." ]);
2332 if (@$project[$P_PATH] eq "") {
2333 # This is the main project. It is also responsible for recursively
2334 # calling the other projects
2335 generate_list("SUBDIRS",1,\@projects,sub
2337 if ($_[0] != \@main_project) {
2338 my $subdir=@{$_[0]}[$P_PATH];
2342 # Eliminating the main project by returning undefined!
2345 if (@{@$project[$P_TARGETS]} > 0) {
2346 generate_list("DLLS",1,\@dll_list,sub
2348 return @{$_[0]}[$T_NAME];
2350 generate_list("EXES",1,\@exe_list,sub
2352 return "@{$_[0]}[$T_NAME]";
2354 print FILEO "\n\n\n";
2356 print FILEO "### Common settings\n\n";
2357 # Make it so that the project-wide settings override the global settings
2358 generate_list("CEXTRA",1,@$project_settings[$T_CEXTRA]);
2359 generate_list("CXXEXTRA",1,@$project_settings[$T_CXXEXTRA]);
2360 generate_list("RCEXTRA",1,@$project_settings[$T_RCEXTRA]);
2361 generate_list("DEFINES",1,@$project_settings[$T_DEFINES]);
2362 generate_list("INCLUDE_PATH",1,@$project_settings[$T_INCLUDE_PATH]);
2363 generate_list("DLL_PATH",1,@$project_settings[$T_DLL_PATH]);
2364 generate_list("DLL_IMPORTS",1,@$project_settings[$T_DLLS]);
2365 generate_list("LIBRARY_PATH",1,@$project_settings[$T_LIBRARY_PATH]);
2366 generate_list("LIBRARIES",1,@$project_settings[$T_LIBRARIES]);
2369 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
2370 @{@$project_settings[$T_SOURCES_CXX]}+
2371 @{@$project_settings[$T_SOURCES_RC]};
2372 my $no_extra=($extra_source_count == 0);
2374 print FILEO "### Extra source lists\n\n";
2375 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
2376 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
2377 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
2379 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
2380 print FILEO "\n\n\n";
2383 # Iterate over all the targets...
2384 foreach my $target (@{@$project[$P_TARGETS]}) {
2385 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
2386 my $canon=canonize("@$target[$T_NAME]");
2389 generate_list("${canon}_MODULE",1,[@$target[$T_NAME]]);
2390 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
2391 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
2392 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
2393 generate_list("${canon}_LDFLAGS",1,@$target[$T_LDFLAGS]);
2394 generate_list("${canon}_DLL_PATH",1,@$target[$T_DLL_PATH]);
2395 generate_list("${canon}_DLLS",1,@$target[$T_DLLS]);
2396 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]);
2397 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]);
2399 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2400 print FILEO "\n\n\n";
2402 print FILEO "### Global source lists\n\n";
2403 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
2405 my $canon=canonize(@{$_[0]}[$T_NAME]);
2407 return "\$(${canon}_C_SRCS)";
2410 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
2412 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
2414 my $canon=canonize(@{$_[0]}[$T_NAME]);
2416 return "\$(${canon}_CXX_SRCS)";
2419 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2421 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
2423 my $canon=canonize(@{$_[0]}[$T_NAME]);
2425 return "\$(${canon}_RC_SRCS)";
2428 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2432 print FILEO "### Tools\n\n";
2433 print FILEO "CC = winegcc\n";
2434 print FILEO "CXX = wineg++\n";
2435 print FILEO "RC = wrc\n";
2438 print FILEO "### Generic targets\n\n";
2440 if (@$project[$P_PATH] eq "") {
2441 print FILEO " \$(SUBDIRS)";
2443 if (@{@$project[$P_TARGETS]} > 0) {
2444 print FILEO " \$(DLLS:%=%.so) \$(EXES)";
2447 print FILEO "### Build rules\n";
2449 print FILEO ".PHONY: all clean dummy\n";
2451 print FILEO "\$(SUBDIRS): dummy\n";
2452 print FILEO "\t\@cd \$\@ && \$(MAKE)\n";
2454 print FILEO "# Implicit rules\n";
2456 print FILEO ".SUFFIXES: .cpp .rc .res\n";
2457 print FILEO "DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2459 print FILEO ".c.o:\n";
2460 print FILEO "\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2462 print FILEO ".cpp.o:\n";
2463 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2465 print FILEO ".cxx.o:\n";
2466 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2468 print FILEO ".rc.res:\n";
2469 print FILEO "\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2471 print FILEO "# Rules for cleaning\n";
2473 print FILEO "CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2474 print FILEO " \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2476 print FILEO "clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2477 print FILEO "\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:.cpp=.o)\n";
2478 print FILEO "\t\$(RM) \$(DLLS:%=%.so) \$(EXES) \$(EXES:%=%.so)\n";
2480 print FILEO "\$(SUBDIRS:%=%/__clean__): dummy\n";
2481 print FILEO "\tcd `dirname \$\@` && \$(MAKE) clean\n";
2483 print FILEO "\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2484 print FILEO "\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2487 if (@{@$project[$P_TARGETS]} > 0) {
2488 print FILEO "### Target specific build rules\n";
2489 print FILEO "DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2490 foreach my $target (@{@$project[$P_TARGETS]}) {
2491 my $canon=canonize("@$target[$T_NAME]");
2494 if (@$target[$T_TYPE] == $TT_DLL && (@$project_settings[$T_FLAGS] & $TF_HASDEF)) {
2495 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.def)\n";
2496 } elsif (@$target[$T_TYPE] == $TT_DLL) {
2497 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.spec)\n";
2499 print FILEO "\$(${canon}_MODULE): \$(${canon}_OBJS)\n";
2501 if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
2502 print FILEO "\t\$(CXX)";
2504 print FILEO "\t\$(CC)";
2506 print FILEO " \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2516 # This is where we finally generate files. In fact this method does not
2517 # do anything itself but calls the methods that do the actual work.
2520 print "Generating project files...\n";
2522 foreach my $project (@projects) {
2523 my $path=@$project[$P_PATH];
2530 generate_project_files($project);
2543 $opt_lower=$OPT_LOWER_UPPERCASE;
2544 $opt_lower_include=1;
2546 $opt_work_dir=undef;
2547 $opt_single_target=undef;
2548 $opt_target_type=$TT_GUIEXE;
2550 $opt_arch=$OPT_ARCH_DEFAULT;
2551 $opt_is_interactive=$OPT_ASK_NO;
2552 $opt_ask_project_options=$OPT_ASK_NO;
2553 $opt_ask_target_options=$OPT_ASK_NO;
2554 $opt_no_generated_files=0;
2555 $opt_no_source_fix=0;
2568 print "Winemaker $version\n";
2569 print "Copyright 2000-2004 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2570 print "Copyright 2004 Dimitrie O. Paun\n";
2571 print "Copyright 2009-2011 André Hentschel\n";
2577 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2578 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2579 print STDERR " [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2580 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2581 print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2582 print STDERR " [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2583 print STDERR " [--generated-files|--nogenerated-files]\n";
2584 print STDERR " [--wine32]\n";
2585 print STDERR " work_directory|project_file|workspace_file\n";
2586 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2587 print STDERR "the specified directory or project-file, so that they can be compiled with Winelib.\n";
2588 print STDERR "During this process it will modify and rename some of the corresponding files.\n";
2589 print STDERR "\tPlease read the manual page before use.\n";
2593 target_init(\@global_settings);
2596 my $arg=shift @ARGV;
2598 if ($arg eq "--nobanner") {
2600 } elsif ($arg eq "--backup") {
2602 } elsif ($arg eq "--nobackup") {
2604 } elsif ($arg eq "--single-target") {
2605 $opt_single_target=shift @ARGV;
2606 } elsif ($arg eq "--lower-none") {
2607 $opt_lower=$OPT_LOWER_NONE;
2608 } elsif ($arg eq "--lower-all") {
2609 $opt_lower=$OPT_LOWER_ALL;
2610 } elsif ($arg eq "--lower-uppercase") {
2611 $opt_lower=$OPT_LOWER_UPPERCASE;
2612 } elsif ($arg eq "--lower-include") {
2613 $opt_lower_include=1;
2614 } elsif ($arg eq "--nolower-include") {
2615 $opt_lower_include=0;
2616 } elsif ($arg eq "--nosource-fix") {
2617 $opt_no_source_fix=1;
2618 } elsif ($arg eq "--generated-files") {
2619 $opt_no_generated_files=0;
2620 } elsif ($arg eq "--nogenerated-files") {
2621 $opt_no_generated_files=1;
2622 } elsif ($arg eq "--wine32") {
2623 $opt_arch=$OPT_ARCH_32;
2624 } elsif ($arg =~ /^-D/) {
2625 push @{$global_settings[$T_DEFINES]},$arg;
2626 } elsif ($arg =~ /^-I/) {
2627 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2628 } elsif ($arg =~ /^-P/) {
2629 push @{$global_settings[$T_DLL_PATH]},"-L$'";
2630 } elsif ($arg =~ /^-i/) {
2631 push @{$global_settings[$T_DLLS]},$';
2632 } elsif ($arg =~ /^-L/) {
2633 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2634 } elsif ($arg =~ /^-l/) {
2635 push @{$global_settings[$T_LIBRARIES]},$arg;
2637 # 'Source'-based method options
2638 } elsif ($arg eq "--dll") {
2639 $opt_target_type=$TT_DLL;
2640 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2641 $opt_target_type=$TT_GUIEXE;
2642 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2643 $opt_target_type=$TT_CUIEXE;
2644 } elsif ($arg eq "--interactive") {
2645 $opt_is_interactive=$OPT_ASK_YES;
2646 $opt_ask_project_options=$OPT_ASK_YES;
2647 $opt_ask_target_options=$OPT_ASK_YES;
2648 } elsif ($arg eq "--mfc") {
2649 $opt_flags|=$TF_MFC;
2650 } elsif ($arg eq "--nomfc") {
2651 $opt_flags&=~$TF_MFC;
2652 $opt_flags|=$TF_NOMFC;
2653 } elsif ($arg eq "--nodlls") {
2654 $opt_flags|=$TF_NODLLS;
2655 } elsif ($arg eq "--nomsvcrt") {
2656 $opt_flags|=$TF_NOMSVCRT;
2660 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2661 if (!defined $opt_work_dir and !defined $opt_work_file) {
2663 $opt_work_file=$arg;
2669 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2678 if (!defined $opt_work_dir and !defined $opt_work_file) {
2679 print STDERR "error: you must specify the directory or project file containing the sources to be converted\n";
2681 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2682 print STDERR "error: could not chdir to the work directory\n";
2683 print STDERR " $!\n";
2687 if ($opt_no_banner == 0) {
2691 project_init(\@main_project, "", \@global_settings);
2693 # Fix the file and directory names
2694 fix_file_and_directory_names(".");
2696 # Scan the sources to identify the projects and targets
2699 # Fix the source files
2700 if (! $opt_no_source_fix) {
2704 # Generate the Makefile and the spec file
2705 if (! $opt_no_generated_files) {