4 # Copyright 2000-2004 Francois Gouget for CodeWeavers
5 # Copyright 2004 Dimitrie O. Paun
6 # Copyright 2009 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 choosen
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 # Initialize a target:
270 # - set the target type to TT_SETTINGS, i.e. no real target will
276 @
$target[$T_TYPE]=$TT_SETTINGS;
277 @
$target[$T_FLAGS]=$opt_flags;
278 @
$target[$T_SOURCES_C]=[];
279 @
$target[$T_SOURCES_CXX]=[];
280 @
$target[$T_SOURCES_RC]=[];
281 @
$target[$T_SOURCES_MISC]=[];
282 @
$target[$T_CEXTRA]=[];
283 @
$target[$T_CXXEXTRA]=[];
284 @
$target[$T_RCEXTRA]=[];
285 @
$target[$T_DEFINES]=[];
286 @
$target[$T_INCLUDE_PATH]=[];
287 @
$target[$T_LDFLAGS]=[];
288 @
$target[$T_DLL_PATH]=[];
289 @
$target[$T_DLLS]=[];
290 @
$target[$T_LIBRARY_PATH]=[];
291 @
$target[$T_LIBRARIES]=[];
298 # Project modelization
302 # First we have the notion of project. A project is described by an
303 # array (since we don't have structs in perl). The constants below
304 # identify what is stored at each index of the array.
307 # This is the path in which this project is located. In other
308 # words, this is the path to the Makefile.
312 # This index contains a reference to an array containing the project-wide
313 # settings. The structure of that arrray is actually identical to that of
314 # a regular target since it can also contain extra sources.
318 # This index contains a reference to an array of targets for this
319 # project. Each target describes how an executable or library is to
320 # be built. For each target this description takes the same form as
321 # that of the project: an array. So this entry is an array of arrays.
325 # Initialize a project:
326 # - set the project's path
327 # - initialize the target list
328 # - create a default target (will be removed later if unnecessary)
329 sub project_init
($$$)
331 my ($project, $path, $global_settings)=@_;
333 my $project_settings=[];
334 target_init
($project_settings);
335 @
$project_settings[$T_DEFINES]=[@
{@
$global_settings[$T_DEFINES]}];
336 @
$project_settings[$T_INCLUDE_PATH]=[@
{@
$global_settings[$T_INCLUDE_PATH]}];
337 @
$project_settings[$T_DLL_PATH]=[@
{@
$global_settings[$T_DLL_PATH]}];
338 @
$project_settings[$T_DLLS]=[@
{@
$global_settings[$T_DLLS]}];
339 @
$project_settings[$T_LIBRARY_PATH]=[@
{@
$global_settings[$T_LIBRARY_PATH]}];
340 @
$project_settings[$T_LIBRARIES]=[@
{@
$global_settings[$T_LIBRARIES]}];
342 @
$project[$P_PATH]=$path;
343 @
$project[$P_SETTINGS]=$project_settings;
344 @
$project[$P_TARGETS]=[];
360 # This maps a directory name to a reference to an array listing
361 # its contents (files and directories)
365 # Contains the list of all projects. This list tells us what are
366 # the subprojects of the main Makefile and where we have to generate
371 # This is the main project, i.e. the one in the "." directory.
372 # It may well be empty in which case the main Makefile will only
373 # call out subprojects.
377 # Contains the defaults for the include path, etc.
378 # We store the defaults as if this were a target except that we only
379 # exploit the defines, include path, library path, library list and misc
392 # Cleans up a name to make it an acceptable Makefile
398 $name =~ tr/a-zA-Z0-9_/_/c;
403 # Returns true is the specified pathname is absolute.
404 # Note: pathnames that start with a variable '$' or
405 # '~' are considered absolute.
410 return ($path =~ /^[\/~\
$]/);
414 # Retrieves the contents of the specified directory.
415 # We either get it from the directories hashtable which acts as a
416 # cache, or use opendir, readdir, closedir and store the result
418 sub get_directory_contents
($)
423 #print "getting the contents of $dirname\n";
425 # check for a cached version
427 if ($dirname eq "") {
430 $directory=$directories{$dirname};
431 if (defined $directory) {
432 #print "->@$directory\n";
436 # Read this directory
437 if (opendir(DIRECTORY
, "$dirname")) {
438 my @files=readdir DIRECTORY
;
442 # Return an empty list
443 #print "error: cannot open $dirname\n";
447 #print "->@$directory\n";
448 $directories{$dirname}=$directory;
453 # Removes a directory from the cache.
454 # This is needed if one of its files or subdirectory has been renamed.
455 sub clear_directory_cache
($)
458 delete $directories{$dirname};
464 # 'Source'-based Project analysis
469 # Allows the user to specify makefile and target specific options
470 # - target: the structure in which to store the results
471 # - options: the string containing the options
472 sub source_set_options
($$)
477 #FIXME: we must deal with escaping of stuff and all
478 foreach my $option (split / /,$options) {
479 if (@
$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
480 push @
{@
$target[$T_DEFINES]},$option;
481 } elsif (@
$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
482 push @
{@
$target[$T_INCLUDE_PATH]},$option;
483 } elsif ($option =~ /^-P/) {
484 push @
{@
$target[$T_DLL_PATH]},"-L$'";
485 } elsif ($option =~ /^-i/) {
486 push @
{@
$target[$T_DLLS]},"$'";
487 } elsif ($option =~ /^-L/) {
488 push @
{@
$target[$T_LIBRARY_PATH]},$option;
489 } elsif ($option =~ /^-l/) {
490 push @
{@
$target[$T_LIBRARIES]},"$'";
491 } elsif ($option =~ /^--mfc/) {
492 @
$target[$T_FLAGS]|=$TF_MFC;
493 @
$target[$T_FLAGS]&=~$TF_NOMFC;
494 } elsif ($option =~ /^--nomfc/) {
495 @
$target[$T_FLAGS]&=~$TF_MFC;
496 @
$target[$T_FLAGS]|=$TF_NOMFC;
497 } elsif ($option =~ /^--nodlls/) {
498 @
$target[$T_FLAGS]|=$TF_NODLLS;
499 } elsif ($option =~ /^--nomsvcrt/) {
500 @
$target[$T_FLAGS]|=$TF_NOMSVCRT;
502 print STDERR
"error: unknown option \"$option\"\n";
510 # Scans the specified project file to:
511 # - get a list of targets for this project
512 # - get some settings
513 # - get the list of source files
514 sub source_scan_project_file
($$$);
515 sub source_scan_project_file
($$$)
517 # a reference to the parent's project
518 my $parent_project=$_[0];
519 # 0 if it is a single project, 1 if it is part of a workspace
520 my $is_sub_project=$_[1];
521 # the name of the project file, with complete path, or without if in
525 # reference to the project for this file. May not be used
527 # list of sources found in the current file
533 my $path=dirname
($filename);
534 my $prj_target_cflags;
535 my $prj_target_defines;
536 my $prj_target_ldflags;
541 my $prj_target_type=$TT_GUIEXE;
542 my @prj_target_options;
544 if (!($path=~/\/$/)) {
548 if (defined $opt_single_target or $is_sub_project == 0) {
549 # Either there is a single target and thus a single project,
550 # or we are a single project-file for which a project
552 $project=$parent_project;
555 project_init
($project, $path, \
@global_settings);
557 my $project_settings=@
$project[$P_SETTINGS];
559 if ($filename =~ /.dsp$/i) {
560 # First find out what this project file contains:
561 # collect all sources, find targets and settings
562 if (!open(FILEI
,$filename)) {
563 print STDERR
"error: unable to open $filename for reading:\n";
564 print STDERR
" $!\n";
569 # Remove any trailing CtrlZ, which isn't strictly in the file
575 # Remove any trailing CrLf
578 # Make sure all lines are '\n' terminated
582 if (/^\# Microsoft Developer Studio Project File - Name=\"([^\"]+)/) {
584 $prj_name=~s/\s+/_/g;
587 } elsif (/^# TARGTYPE/) {
588 if (/[[:space:]]0x0101$/) {
590 $prj_target_type=$TT_GUIEXE;
591 }elsif (/[[:space:]]0x0102$/) {
592 # Dynamic-Link Library
593 $prj_target_type=$TT_DLL;
594 }elsif (/[[:space:]]0x0103$/) {
595 # Console Application
596 $prj_target_type=$TT_CUIEXE;
597 }elsif (/[[:space:]]0x0104$/) {
601 } elsif (/^# ADD CPP(.*)/ && $found_cfg==1) {
602 $prj_target_cflags=$1;
603 @prj_target_options=split(" /", $prj_target_cflags);
604 $prj_target_cflags="";
605 foreach ( @prj_target_options ) {
609 # Suppress Startup Banner and Information Messages
611 # Turns off all warning messages
612 $prj_target_cflags.="-w ";
613 } elsif (/^W[123]$/) {
615 $prj_target_cflags.="-W ";
618 $prj_target_cflags.="-Wall ";
621 $prj_target_cflags.="-Werror ";
623 # Enable Minimal Rebuild
625 # Enable Exception Handling
626 $prj_target_cflags.="-fexceptions ";
628 # use cdecl calling convention (default)
630 # use fastcall calling convention
632 # use stdcall calling convention
633 $prj_target_cflags.="-mrtd ";
634 } elsif (/^Z[d7iI]$/) {
636 $prj_target_cflags.="-g ";
638 # Disable Optimizations
639 $prj_target_cflags.="-O0 ";
642 $prj_target_cflags.="-Os ";
645 $prj_target_cflags.="-O2 ";
647 # Disables inline Expansion
648 $prj_target_cflags.="-fno-inline ";
650 #In-line Function Expansion
651 $prj_target_cflags.="-finline-functions ";
653 # auto In-line Function Expansion
654 $prj_target_cflags.="-finline-functions ";
656 # Use maximum optimization
657 $prj_target_cflags.="-O3 ";
659 # Frame-Pointer Omission
660 $prj_target_cflags.="-fomit-frame-pointer ";
662 # Frame-Pointer Omission
663 $prj_target_cflags.="-fno-omit-frame-pointer ";
665 # Catch Release-Build Errors in Debug Build
666 } elsif (/^M[DLT]d?$/) {
667 # Use Multithreaded Run-Time Library
668 } elsif (/^D\s*\"(.*)\"/) {
669 # Preprocessor Definitions
670 $prj_target_defines.="-D".$1." ";
671 } elsif (/^I\s*\"(.*)\"/) {
672 # Additional Include Directories
675 if ($sfilet=~/^\w:/) {
676 print STDERR
"warning: Can't fix path $sfilet\n"
678 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I".$sfilet." ";
680 } elsif (/^U\s*\"(.*)\"/) {
681 # Undefines a previously defined symbol
682 $prj_target_cflags.="-U".$1." ";
688 # Automatic Use of Precompiled Headers
690 # Generate File Dependencies
692 # Compile Without Linking
693 # this option is always present and is already specified in the suffix rules
696 $prj_target_cflags.="-D_M_IX86=500 ";
698 # Pentium Pro Optimization
699 $prj_target_cflags.="-D_M_IX86=600 ";
701 # Pentium Optimization
702 $prj_target_cflags.="-D_M_IX86=500 ";
705 $prj_target_cflags.="-D_M_IX86=300 ";
708 $prj_target_cflags.="-D_M_IX86=400 ";
710 # Create Precompiled Header
712 # Use Precompiled Header
714 # Disable Language Extensions
715 $prj_target_cflags.="-ansi ";
717 # Enable Microsoft Extensions
718 } elsif (/^Zm[[:digit:]]+$/) {
719 # Specify Memory Allocation Limit
721 # Packs structures on 1-byte boundaries
722 $prj_target_cflags.="-fpack-struct ";
723 } elsif (/^Zp(2|4|8|16)$/) {
724 # Struct Member Alignment
725 $prj_target_cflags.="-fpack-struct=".$1;
727 print "C compiler option $_ not implemented\n";
731 #print "\nOptions: $prj_target_cflags\n";
733 } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
734 $prj_target_ldflags=$1;
735 @prj_target_options=split(" /", $prj_target_ldflags);
736 $prj_target_ldflags="";
737 $prj_target_libs=$prj_target_options[0];
738 $prj_target_libs=~s/\\/\//g
;
739 $prj_target_libs=~s/\.lib//g;
740 $prj_target_libs=~s/\s+/ -l/g;
741 shift (@prj_target_options);
742 foreach ( @prj_target_options ) {
745 } elsif (/^base:(.*)/) {
747 $prj_target_ldflags.="--image-base ".$1." ";
748 } elsif (/^debug$/) {
749 # Generate Debug Info
752 $prj_target_type=$TT_DLL;
753 } elsif (/^incremental:[[:alpha:]]+$/) {
755 } elsif (/^implib:/) {
756 # Name import library
757 } elsif (/^libpath:\"(.*)\"/) {
759 push @
{@
$project_settings[$T_DLL_PATH]},"-L$1";
760 } elsif (/^machine:[[:alnum:]]+$/) {
761 # Specify Target Platform
765 $prj_target_ldflags.="-Map ".$1." ";
767 $prj_target_ldflags.="-Map ".$prj_name.".map ";
769 } elsif (/^nologo$/) {
770 # Suppress Startup Banner and Information Messages
773 # may use it as Target?
774 } elsif (/^pdbtype:/) {
775 # Program Database Storage
776 } elsif (/^subsystem:/) {
778 } elsif (/^version:[[:digit:].]+$/) {
779 # Version Information
781 print "Linker option $_ not implemented\n";
785 } elsif (/^LIB32=/ && $found_cfg==1) {
788 } elsif (/^SOURCE=(.*)$/) {
789 my @components=split /[\/\\]+/, $1;
790 $sfilet=search_from
($path, \
@components);
791 if (!defined $sfilet) { next; }
792 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
793 push @sources_c,$sfilet;
794 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
795 if ($sfilet =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
796 push @sources_misc,$sfilet;
797 @
$project_settings[$T_FLAGS]|=$TF_MFC;
799 push @sources_cxx,$sfilet;
801 } elsif ($sfilet =~ /\.rc$/i) {
802 push @sources_rc,$sfilet;
803 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
804 push @sources_misc,$sfilet;
805 if ($sfilet =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
806 @
$project_settings[$T_FLAGS]|=$TF_MFC;
811 } elsif (/^# (Begin|End) Source File/) {
812 # Source-Files already handled
814 } elsif (/^# (Begin|End) Group/) {
817 } elsif (/^# (Begin|End) Custom Build/) {
818 # Custom Builds are ignored
820 } elsif (/^# ADD LIB32 /) {
823 } elsif (/^# Begin Target$/) {
824 # Targets are ignored
826 } elsif (/^# End Target$/) {
827 # Targets are ignored
830 if ($found_cfg == 1) {
833 if (/if (.*)\(CFG\)" == "(.*)"/i) {
834 if ($2 eq $prj_cfg) {
839 } elsif (/^CFG=(.*)/i) {
843 else { # Line recognized
849 push @
{@
$project_settings[$T_LIBRARIES]},$prj_target_libs;
850 push @
{@
$project_settings[$T_CEXTRA]},$prj_target_cflags;
851 push @
{@
$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
852 push @
{@
$project_settings[$T_DEFINES]},$prj_target_defines;
853 push @
{@
$project_settings[$T_LDFLAGS]},$prj_target_ldflags;
854 } elsif ($filename =~ /.vcproj$/i) {
855 # Import XML::LibXML, you need the libxml package (deb: libxml-libxml-perl, rpm: perl-libxml-perl)
858 my $xmlparser = XML
::LibXML
->new();
859 my $project_xml = $xmlparser->parse_file($filename);
863 foreach my $vc_project ($project_xml->findnodes('/VisualStudioProject')) {
864 foreach my $vc_project_attr ($vc_project->attributes) {
865 if ($vc_project_attr->getName eq "Name") {
866 $prj_name=$vc_project_attr->getValue;
867 $prj_name=~s/\s+/_/g;
873 for (my $flevel = 0; $flevel <= 5; $flevel++) {
874 foreach my $vc_file ($project_xml->findnodes('/VisualStudioProject/Files/'.('Filter/' x
$flevel).'File')) {
875 foreach my $vc_file_attr ($vc_file->attributes) {
876 if ($vc_file_attr->getName eq "RelativePath") {
877 $sfilet = $vc_file_attr->getValue;
878 $sfilet=~s/\\\\/\\/g; #remove double backslash
879 $sfilet=~s/^\.\\//; #remove starting 'this directory'
880 $sfilet=~s/\\/\//g
; #make slashes out of backslashes
881 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
882 push @sources_c,$sfilet;
883 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
884 if ($sfilet =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
885 push @sources_misc,$sfilet;
886 @
$project_settings[$T_FLAGS]|=$TF_MFC;
888 push @sources_cxx,$sfilet;
890 } elsif ($sfilet =~ /\.rc$/i) {
891 push @sources_rc,$sfilet;
892 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
893 push @sources_misc,$sfilet;
894 if ($sfilet =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
895 @
$project_settings[$T_FLAGS]|=$TF_MFC;
903 my @vc_configurations = $project_xml->findnodes('/VisualStudioProject/Configurations/Configuration');
904 my $vc_configuration = $vc_configurations[0];
905 foreach my $vc_configuration_attr ($vc_configuration->attributes) {
906 if ($vc_configuration_attr->getName eq "ConfigurationType") {
907 if ($vc_configuration_attr->getValue==1) {
908 $prj_target_type=$TT_GUIEXE; # Application
909 } elsif ($vc_configuration_attr->getValue==2) {
910 $prj_target_type=$TT_DLL; # Dynamic-Link Library
915 foreach my $vc_configuration_tools ($vc_configuration->findnodes('Tool')) {
916 my @find_tool = $vc_configuration_tools->attributes;
917 if ($find_tool[0]->getValue eq "VCCLCompilerTool") {
918 foreach my $vc_compiler_tool ($vc_configuration_tools->attributes) {
919 if ($vc_compiler_tool->getName eq "Optimization") {$prj_target_cflags.="-O".$vc_compiler_tool->getValue." ";}
920 if ($vc_compiler_tool->getName eq "WarningLevel") {
921 if ($vc_compiler_tool->getValue==0) {
922 $prj_target_cflags.="-w ";
923 } elsif ($vc_compiler_tool->getValue<4) {
924 $prj_target_cflags.="-W ";
925 } elsif ($vc_compiler_tool->getValue==4) {
926 $prj_target_cflags.="-Wall ";
927 } elsif ($vc_compiler_tool->getValue eq "X") {
928 $prj_target_cflags.="-Werror ";
931 if ($vc_compiler_tool->getName eq "PreprocessorDefinitions") {
932 $configt=$vc_compiler_tool->getValue;
934 $prj_target_defines.="-D".$configt." ";
936 if ($vc_compiler_tool->getName eq "AdditionalIncludeDirectories") {
937 $configt=$vc_compiler_tool->getValue;
940 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I".$configt;
944 if ($find_tool[0]->getValue eq "VCLinkerTool") {
945 foreach my $vc_linker_tool ($vc_configuration_tools->attributes) {
946 if ($vc_linker_tool->getName eq "AdditionalDependencies") {
947 $prj_target_libs=" ".$vc_linker_tool->getValue;
948 $prj_target_libs=~s/\\/\//g
;
949 $prj_target_libs=~s/\.lib//g;
950 $prj_target_libs=~s/\s+/ -l/g;
956 push @
{@
$project_settings[$T_LIBRARIES]},$prj_target_libs;
957 push @
{@
$project_settings[$T_CEXTRA]},$prj_target_cflags;
958 push @
{@
$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
959 push @
{@
$project_settings[$T_DEFINES]},$prj_target_defines;
962 # Add this project to the project list, except for
963 # the main project which is already in the list.
964 if ($is_sub_project == 1) {
965 push @projects,$project;
968 # Ask for project-wide options
969 if ($opt_ask_project_options == $OPT_ASK_YES) {
971 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
974 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
975 if (defined $flag_desc) {
976 print "* (currently $flag_desc)\n";
978 print "* or 'skip' to skip the target specific options,\n";
979 print "* or 'never' to not be asked this question again:\n";
983 if ($options eq "skip") {
984 $opt_ask_target_options=$OPT_ASK_SKIP;
986 } elsif ($options eq "never") {
987 $opt_ask_project_options=$OPT_ASK_NO;
989 } elsif (source_set_options
($project_settings,$options)) {
992 print "Please re-enter the options:\n";
997 my @local_depends=();
1000 # Create the target...
1002 target_init
($target);
1004 if ($prj_target_type!=$TT_DLL) {
1005 $prj_name=lc($prj_name.".exe");
1006 @
$target[$T_TYPE]=$opt_target_type;
1007 push @exe_list,$target;
1008 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
1010 $prj_name=lc($prj_name.".dll");
1011 @
$target[$T_TYPE]=$TT_DLL;
1012 push @local_depends,"$prj_name.so";
1013 push @local_dlls,$prj_name;
1014 my $canon=canonize
($prj_name);
1015 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1018 @
$target[$T_NAME]=$prj_name;
1019 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
1021 # This is the default link list of Visual Studio
1022 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1023 my @std_libraries=qw(uuid);
1024 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1025 @
$target[$T_DLLS]=\
@std_imports;
1026 @
$target[$T_LIBRARIES]=\
@std_libraries;
1028 @
$target[$T_DLLS]=[];
1029 @
$target[$T_LIBRARIES]=[];
1031 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1032 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
1033 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1034 push @
{@
$target[$T_LDFLAGS]},"-m$opt_arch";
1037 push @
{@
$project[$P_TARGETS]},$target;
1039 # Ask for target-specific options
1040 if ($opt_ask_target_options == $OPT_ASK_YES) {
1042 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
1045 if ($flag_desc ne "") {
1048 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1049 print "* \"$prj_name\"$flag_desc or 'never' to not be asked this question again:\n";
1051 my $options=<STDIN
>;
1053 if ($options eq "never") {
1054 $opt_ask_target_options=$OPT_ASK_NO;
1056 } elsif (source_set_options
($target,$options)) {
1059 print "Please re-enter the options:\n";
1062 if (@
$target[$T_FLAGS] & $TF_MFC) {
1063 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1064 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1065 push @
{@
$target[$T_DLLS]},"mfc.dll";
1066 # FIXME: Link with the MFC in the Unix sense, until we
1067 # start exporting the functions properly.
1068 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1069 push @
{@
$target[$T_LIBRARIES]},"mfc";
1073 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
1074 @
$project_settings[$T_SOURCES_C]=[];
1076 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1077 @
$project_settings[$T_SOURCES_CXX]=[];
1079 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
1080 @
$project_settings[$T_SOURCES_RC]=[];
1082 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
1083 @
$project_settings[$T_SOURCES_MISC]=[];
1086 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
1087 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
1088 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
1089 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
1091 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1092 $opt_ask_target_options=$OPT_ASK_YES;
1095 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1096 push @
{@
$project_settings[$T_CEXTRA]},"-mno-cygwin";
1097 push @
{@
$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1098 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1099 push @
{@
$project_settings[$T_CEXTRA]},"-m$opt_arch";
1100 push @
{@
$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1104 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
1105 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1107 # The sources that did not match, if any, go to the extra
1108 # source list of the project settings
1109 foreach my $source (@sources_c) {
1110 if ($source ne "") {
1111 push @
{@
$project_settings[$T_SOURCES_C]},$source;
1114 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
1115 foreach my $source (@sources_cxx) {
1116 if ($source ne "") {
1117 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
1120 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
1121 foreach my $source (@sources_rc) {
1122 if ($source ne "") {
1123 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
1126 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
1127 foreach my $source (@sources_misc) {
1128 if ($source ne "") {
1129 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
1132 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
1136 # Scans the specified workspace file to find the project files
1137 sub source_scan_workspace_file
($);
1138 sub source_scan_workspace_file
($)
1141 my $path=dirname
($filename);
1144 if (! -e
$filename) {
1148 if (!open(FILEIWS
,$filename)) {
1149 print STDERR
"error: unable to open $filename for reading:\n";
1150 print STDERR
" $!\n";
1157 if ($filename =~ /.dsw$/i) {
1159 # Remove any trailing CrLf
1162 # catch a project definition
1163 if (/^Project:\s\"(.*)\"=(.*)\s-/) {
1166 @components=split /[\/\\]+/, $prj_path;
1167 $prj_path=search_from
($path, \
@components);
1168 print "Name: $prj_name\nPath: $prj_path\n";
1169 source_scan_project_file
(\
@main_project,1,$prj_path);
1173 } elsif (/^Global:/) {
1174 # ignore the Global section
1176 print STDERR
"unknown section $_\n";
1177 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1178 print "\nFileversion: $3\n";
1182 } elsif ($filename =~ /.sln$/i) {
1184 # Remove any trailing CrLf
1187 # catch a project definition
1188 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1191 if ($prj_path eq "Solution Items") { next; }
1192 @components=split /[\/\\]+/, $3;
1193 $prj_path=search_from
($path, \
@components);
1194 print "Name: $prj_name\nPath: $prj_path\n";
1195 source_scan_project_file
(\
@main_project,1,$prj_path);
1197 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1198 print "\nFileversion: $3\n";
1204 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
1208 # Scans the specified directory to:
1209 # - see if we should create a Makefile in this directory. We normally do
1210 # so if we find a project file and sources
1211 # - get a list of targets for this directory
1212 # - get the list of source files
1213 sub source_scan_directory
($$$$);
1214 sub source_scan_directory
($$$$)
1216 # a reference to the parent's project
1217 my $parent_project=$_[0];
1218 # the full relative path to the current directory, including a
1219 # trailing '/', or an empty string if this is the top level directory
1221 # the name of this directory, including a trailing '/', or an empty
1222 # string if this is the top level directory
1224 # if set then no targets will be looked for and the sources will all
1225 # end up in the parent_project's 'misc' bucket
1226 my $no_target=$_[3];
1228 # reference to the project for this directory. May not be used
1230 # list of targets found in the 'current' directory
1232 # list of sources found in the current directory
1236 my @sources_misc=();
1237 # true if this directory contains a Windows project
1238 my $has_win_project=0;
1239 # true if this directory contains headers
1241 # If we don't find any executable/library then we might make up targets
1242 # from the list of .dsp/.mak files we find since they usually have the
1243 # same name as their target.
1247 if (defined $opt_single_target or $dirname eq "") {
1248 # Either there is a single target and thus a single project,
1249 # or we are in the top level directory for which a project
1251 $project=$parent_project;
1254 project_init
($project, $path, \
@global_settings);
1256 my $project_settings=@
$project[$P_SETTINGS];
1258 # First find out what this directory contains:
1259 # collect all sources, targets and subdirectories
1260 my $directory=get_directory_contents
($path);
1261 foreach my $dentry (@
$directory) {
1262 if ($dentry =~ /^\./) {
1265 my $fullentry="$path$dentry";
1266 if (-d
"$fullentry") {
1267 if ($dentry =~ /^(Release|Debug)/i) {
1268 # These directories are often used to store the object files and the
1269 # resulting executable/library. They should not contain anything else.
1270 my @candidates=grep /\.(exe|dll)$/i, @
{get_directory_contents
("$fullentry")};
1271 foreach my $candidate (@candidates) {
1272 $targets{$candidate}=1;
1274 } elsif ($dentry =~ /^include/i) {
1275 # This directory must contain headers we're going to need
1276 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1277 source_scan_directory
($project,"$fullentry/","$dentry/",1);
1279 # Recursively scan this directory. Any source file that cannot be
1280 # attributed to a project in one of the subdirectories will be
1281 # attributed to this project.
1282 source_scan_directory
($project,"$fullentry/","$dentry/",$no_target);
1284 } elsif (-f
"$fullentry") {
1285 if ($dentry =~ /\.(exe|dll)$/i) {
1286 $targets{$dentry}=1;
1287 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1288 push @sources_c,"$dentry";
1289 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
1290 if ($dentry =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1291 push @sources_misc,"$dentry";
1292 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1294 push @sources_cxx,"$dentry";
1296 } elsif ($dentry =~ /\.rc$/i) {
1297 push @sources_rc,"$dentry";
1298 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1300 push @sources_misc,"$dentry";
1301 if ($dentry =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1302 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1304 } elsif ($dentry =~ /\.(dsp|vcproj)$/i) {
1305 push @prj_files,"$dentry";
1307 } elsif ($dentry =~ /\.mak$/i) {
1308 push @mak_files,"$dentry";
1310 } elsif ($dentry =~ /^makefile/i) {
1317 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I.";
1319 # If we have a single target then all we have to do is assign
1320 # all the sources to it and we're done
1321 # FIXME: does this play well with the --interactive mode?
1322 if ($opt_single_target) {
1323 my $target=@
{@
$project[$P_TARGETS]}[0];
1324 push @
{@
$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1325 push @
{@
$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1326 push @
{@
$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1327 push @
{@
$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1331 my $parent_settings=@
$parent_project[$P_SETTINGS];
1332 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1333 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1334 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1335 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1336 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1340 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1341 @
{@
$project_settings[$T_SOURCES_C]}+
1342 @
{@
$project_settings[$T_SOURCES_CXX]}+
1343 @
{@
$project_settings[$T_SOURCES_RC]};
1344 if ($source_count == 0) {
1345 # A project without real sources is not a project, get out!
1346 if ($project!=$parent_project) {
1347 my $parent_settings=@
$parent_project[$P_SETTINGS];
1348 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1349 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1353 #print "targets=",%targets,"\n";
1354 #print "target_count=$target_count\n";
1355 #print "has_win_project=$has_win_project\n";
1356 #print "dirname=$dirname\n";
1359 if (($has_win_project != 0) or ($dirname eq "")) {
1360 # Deal with cases where we could not find any executable/library, and
1361 # thus have no target, although we did find some sort of windows project.
1362 $target_count=keys %targets;
1363 if ($target_count == 0) {
1364 # Try to come up with a target list based on .dsp/.mak files
1366 if (@prj_files > 0) {
1367 print "Projectfile found! You might want to try using it directly.\n";
1368 $prj_list=\
@prj_files;
1370 $prj_list=\
@mak_files;
1372 foreach my $filename (@
$prj_list) {
1373 $filename =~ s/\.(dsp|vcproj|mak)$//i;
1374 if ($opt_target_type == $TT_DLL) {
1375 $filename = "$filename.dll";
1377 $targets{$filename}=1;
1379 $target_count=keys %targets;
1380 if ($target_count == 0) {
1381 # Still nothing, try the name of the directory
1383 if ($dirname eq "") {
1384 # Bad luck, this is the top level directory!
1385 $name=(split /\//, cwd
)[-1];
1388 # Remove the trailing '/'. Also eliminate whatever is after the last
1389 # '.' as it is likely to be meaningless (.orig, .new, ...)
1390 $name =~ s
+(/|\
.[^.]*)$++;
1391 if ($name eq "src") {
1392 # 'src' is probably a subdirectory of the real project directory.
1393 # Try again with the parent (if any).
1395 if ($parent =~ s
+([^/]*)/[^/]*/$+$1+) {
1398 $name=(split /\//, cwd
)[-1];
1402 $name =~ s
+(/|\
.[^.]*)$++;
1403 if ($opt_target_type == $TT_DLL) {
1404 $name = canonize
($name).".dll";
1406 $name = canonize
($name).".exe";
1412 # Ask confirmation to the user if he wishes so
1413 if ($opt_is_interactive == $OPT_ASK_YES) {
1414 my $target_list=join " ",keys %targets;
1415 print "\n*** In ",($path?
$path:"./"),"\n";
1416 print "* winemaker found the following list of (potential) targets\n";
1417 print "* $target_list\n";
1418 print "* Type enter to use it as is, your own comma-separated list of\n";
1419 print "* targets, 'none' to assign the source files to a parent directory,\n";
1420 print "* or 'ignore' to ignore everything in this directory tree.\n";
1421 print "* Target list:\n";
1422 $target_list=<STDIN
>;
1424 if ($target_list eq "") {
1425 # Keep the target list as is, i.e. do nothing
1426 } elsif ($target_list eq "none") {
1427 # Empty the target list
1429 } elsif ($target_list eq "ignore") {
1430 # Ignore this subtree altogether
1434 foreach my $target (split /,/,$target_list) {
1435 $target =~ s
+^\s
*++;
1436 $target =~ s
+\s
*$++;
1437 $targets{$target}=1;
1443 # If we have no project at this level, then transfer all
1444 # the sources to the parent project
1445 $target_count=keys %targets;
1446 if ($target_count == 0) {
1447 if ($project!=$parent_project) {
1448 my $parent_settings=@
$parent_project[$P_SETTINGS];
1449 push @
{@
$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1450 push @
{@
$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1451 push @
{@
$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1452 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1453 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1458 # Otherwise add this project to the project list, except for
1459 # the main project which is already in the list.
1460 if ($dirname ne "") {
1461 push @projects,$project;
1464 # Ask for project-wide options
1465 if ($opt_ask_project_options == $OPT_ASK_YES) {
1467 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1470 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1471 if (defined $flag_desc) {
1472 print "* (currently $flag_desc)\n";
1474 print "* or 'skip' to skip the target specific options,\n";
1475 print "* or 'never' to not be asked this question again:\n";
1477 my $options=<STDIN
>;
1479 if ($options eq "skip") {
1480 $opt_ask_target_options=$OPT_ASK_SKIP;
1482 } elsif ($options eq "never") {
1483 $opt_ask_project_options=$OPT_ASK_NO;
1485 } elsif (source_set_options
($project_settings,$options)) {
1488 print "Please re-enter the options:\n";
1492 # - Create the targets
1493 # - Check if we have both libraries and programs
1494 # - Match each target with source files (sort in reverse
1495 # alphabetical order to get the longest matches first)
1497 my @local_depends=();
1499 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1500 # Create the target...
1502 target_init
($target);
1503 @
$target[$T_NAME]=$target_name;
1504 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
1505 if ($target_name =~ /\.dll$/) {
1506 @
$target[$T_TYPE]=$TT_DLL;
1507 push @local_depends,"$target_name.so";
1508 push @local_dlls,$target_name;
1509 my $canon=canonize
($target_name);
1510 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1512 @
$target[$T_TYPE]=$opt_target_type;
1513 push @exe_list,$target;
1514 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
1516 my $basename=$target_name;
1517 $basename=~ s/\.(dll|exe)$//i;
1518 # This is the default link list of Visual Studio
1519 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1520 my @std_libraries=qw(uuid);
1521 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1522 @
$target[$T_DLLS]=\
@std_imports;
1523 @
$target[$T_LIBRARIES]=\
@std_libraries;
1525 @
$target[$T_DLLS]=[];
1526 @
$target[$T_LIBRARIES]=[];
1528 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1529 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
1530 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1531 push @
{@
$target[$T_LDFLAGS]},"-m$opt_arch";
1534 push @
{@
$project[$P_TARGETS]},$target;
1536 # Ask for target-specific options
1537 if ($opt_ask_target_options == $OPT_ASK_YES) {
1539 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
1542 if ($flag_desc ne "") {
1545 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1546 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1548 my $options=<STDIN
>;
1550 if ($options eq "never") {
1551 $opt_ask_target_options=$OPT_ASK_NO;
1553 } elsif (source_set_options
($target,$options)) {
1556 print "Please re-enter the options:\n";
1559 if (@
$target[$T_FLAGS] & $TF_MFC) {
1560 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1561 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1562 push @
{@
$target[$T_DLLS]},"mfc.dll";
1563 # FIXME: Link with the MFC in the Unix sense, until we
1564 # start exporting the functions properly.
1565 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1566 push @
{@
$target[$T_LIBRARIES]},"mfc";
1570 if ($target_count == 1) {
1571 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
1572 @
$project_settings[$T_SOURCES_C]=[];
1575 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1576 @
$project_settings[$T_SOURCES_CXX]=[];
1579 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
1580 @
$project_settings[$T_SOURCES_RC]=[];
1583 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
1584 # No need for sorting these sources
1585 @
$project_settings[$T_SOURCES_MISC]=[];
1588 foreach my $source (@sources_c) {
1589 if ($source =~ /^$basename/i) {
1590 push @
{@
$target[$T_SOURCES_C]},$source;
1594 foreach my $source (@sources_cxx) {
1595 if ($source =~ /^$basename/i) {
1596 push @
{@
$target[$T_SOURCES_CXX]},$source;
1600 foreach my $source (@sources_rc) {
1601 if ($source =~ /^$basename/i) {
1602 push @
{@
$target[$T_SOURCES_RC]},$source;
1606 foreach my $source (@sources_misc) {
1607 if ($source =~ /^$basename/i) {
1608 push @
{@
$target[$T_SOURCES_MISC]},$source;
1613 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
1614 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
1615 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
1616 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
1618 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1619 $opt_ask_target_options=$OPT_ASK_YES;
1622 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1623 push @
{@
$project_settings[$T_CEXTRA]},"-mno-cygwin";
1624 push @
{@
$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1625 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1626 push @
{@
$project_settings[$T_CEXTRA]},"-m$opt_arch";
1627 push @
{@
$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1631 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
1632 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1634 # The sources that did not match, if any, go to the extra
1635 # source list of the project settings
1636 foreach my $source (@sources_c) {
1637 if ($source ne "") {
1638 push @
{@
$project_settings[$T_SOURCES_C]},$source;
1641 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
1642 foreach my $source (@sources_cxx) {
1643 if ($source ne "") {
1644 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
1647 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
1648 foreach my $source (@sources_rc) {
1649 if ($source ne "") {
1650 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
1653 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
1654 foreach my $source (@sources_misc) {
1655 if ($source ne "") {
1656 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
1659 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
1661 # Finally if we are building both libraries and programs in
1662 # this directory, then the programs should be linked with all
1664 if (@local_dlls > 0 and @exe_list > 0) {
1665 foreach my $target (@exe_list) {
1666 push @
{@
$target[$T_DLL_PATH]},"-L.";
1667 push @
{@
$target[$T_DLLS]},@local_dlls;
1673 # Scan the source directories in search of things to build
1676 # If there's a single target then this is going to be the default target
1677 if (defined $opt_single_target) {
1678 # Create the main target
1680 target_init
($main_target);
1681 @
$main_target[$T_NAME]=$opt_single_target;
1682 @
$main_target[$T_TYPE]=$opt_target_type;
1684 # Add it to the list
1685 push @
{$main_project[$P_TARGETS]},$main_target;
1688 # The main directory is always going to be there
1689 push @projects,\
@main_project;
1691 if (defined $opt_work_dir) {
1692 # Now scan the directory tree looking for source files and, maybe, targets
1693 print "Scanning the source directories...\n";
1694 source_scan_directory
(\
@main_project,"","",0);
1695 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
1696 } elsif (defined $opt_work_file) {
1697 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1698 source_scan_project_file
(\
@main_project,0,$opt_work_file);
1699 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1700 source_scan_workspace_file
($opt_work_file);
1712 # Performs a directory traversal and renames the files so that:
1713 # - they have the case desired by the user
1714 # - their extension is of the appropriate case
1715 # - they don't contain annoying characters like ' ', '$', '#', ...
1716 # But only perform these changes for source files and directories.
1717 sub fix_file_and_directory_names
($);
1718 sub fix_file_and_directory_names
($)
1722 my $directory=get_directory_contents
($dirname);
1723 foreach my $dentry (@
$directory)
1725 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1728 # Set $warn to 1 if the user should be warned of the renaming
1730 my $new_name=$dentry;
1732 if (-f
"$dirname/$dentry")
1734 # Don't rename Winemaker's makefiles
1735 next if ($dentry eq "Makefile" and
1736 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker
/);
1738 # Leave non-source files alone
1739 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc))$/i);
1741 # Only all lowercase extensions are supported (because of
1742 # rules like '.c.o:').
1743 $new_name =~ s/\.C$/.c/;
1744 $new_name =~ s/\.cpp$/.cpp/i;
1745 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1746 $new_name =~ s/\.rc$/.rc/i;
1747 # And this last one is to avoid confusion when running make
1748 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1751 # Adjust the case to the user's preferences
1752 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1753 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1755 $new_name=lc $new_name;
1758 # make doesn't support these characters well
1759 $new_name =~ s/[ \$]/_/g;
1761 # And finally, perform the renaming
1762 if ($new_name ne $dentry)
1765 print STDERR
"warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1767 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1768 print STDERR
"error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1769 print STDERR
" $!\n";
1774 clear_directory_cache
($dirname);
1777 if (-d
"$dirname/$new_name") {
1778 fix_file_and_directory_names
("$dirname/$new_name");
1792 # Try to find a file for the specified filename. The attempt is
1793 # case-insensitive which is why it's not trivial. If a match is
1794 # found then we return the pathname with the correct case.
1801 $dirname =~ s/(\.\/)+//;
1802 if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
1804 } elsif ($dirname !~ m
+^/+) {
1805 $dirname=cwd
. "/" . $dirname;
1807 if ($dirname !~ m
+/$+) {
1811 foreach my $component (@
$path) {
1812 $component=~s/^\"//;
1813 $component=~s/\"$//;
1814 #print " looking for $component in \"$dirname\"\n";
1815 if ($component eq ".") {
1818 } elsif ($component eq "..") {
1820 if ($dirname =~ /\.\.\/$/) {
1823 $dirname=dirname
($dirname) . "/";
1827 # The file/directory may have been renamed before. Also try to
1828 # match the renamed file.
1829 my $renamed=$component;
1830 $renamed =~ s/[ \$]/_/g;
1831 if ($renamed eq $component) {
1835 my $directory=get_directory_contents
$dirname;
1837 foreach my $dentry (@
$directory) {
1838 if ($dentry =~ /^\Q$component\E$/i or
1839 (defined $renamed and $dentry =~ /^$renamed$/i)
1841 $dirname.="$dentry/";
1842 $real_path.="$dentry/";
1847 if (!defined $found) {
1849 #print " could not find $component in $dirname\n";
1854 $real_path=~ s
+/$++;
1855 #print " -> found $real_path\n";
1860 # Performs a case-insensitive search for the specified file in the
1862 # $line is the line number that should be referenced when an error occurs
1863 # $filename is the file we are looking for
1864 # $dirname is the directory of the file containing the '#include' directive
1865 # if '"' was used, it is an empty string otherwise
1866 # $project and $target specify part of the include path
1867 sub get_real_include_name
($$$$$)
1875 if ($filename =~ /^([a-zA-Z]:)?[\/\\]/ or $filename =~ /^[a
-zA
-Z
]:[\
/\\]?/) {
1876 # This is not a relative path, we cannot make any check
1877 my $warning="path:$filename";
1878 if (!defined $warnings{$warning}) {
1879 $warnings{$warning}="1";
1880 print STDERR
"warning: cannot check the case of absolute pathnames:\n";
1881 print STDERR
"$line: $filename\n";
1884 # Here's how we proceed:
1885 # - split the filename we look for into its components
1886 # - then for each directory in the include path
1887 # - trace the directory components starting from that directory
1888 # - if we fail to find a match at any point then continue with
1889 # the next directory in the include path
1890 # - otherwise, rejoice, our quest is over.
1891 my @file_components=split /[\/\\]+/, $filename;
1892 #print " Searching for $filename from @$project[$P_PATH]\n";
1895 if ($dirname ne "") {
1896 # This is an 'include ""' -> look in dirname first.
1897 #print " in $dirname (include \"\")\n";
1898 $real_filename=search_from
($dirname,\
@file_components);
1899 if (defined $real_filename) {
1900 return $real_filename;
1903 my $project_settings=@
$project[$P_SETTINGS];
1904 foreach my $include (@
{@
$target[$T_INCLUDE_PATH]}, @
{@
$project_settings[$T_INCLUDE_PATH]}) {
1905 my $dirname=$include;
1908 if (!is_absolute
($dirname)) {
1909 $dirname="@$project[$P_PATH]$dirname";
1911 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)/++;
1912 $dirname=~ s
+^\
$\
(SRCDIR\
)/+@
$project[$P_PATH]+;
1914 #print " in $dirname\n";
1915 $real_filename=search_from
("$dirname",\
@file_components);
1916 if (defined $real_filename) {
1917 return $real_filename;
1920 my $dotdotpath=@
$project[$P_PATH];
1921 $dotdotpath =~ s/[^\/]+/../g
;
1922 foreach my $include (@
{$global_settings[$T_INCLUDE_PATH]}) {
1923 my $dirname=$include;
1925 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)\
/++;
1926 $dirname=~ s
+^\
$\
(SRCDIR\
)\
/+@
$project[$P_PATH]+;
1927 #print " in $dirname (global setting)\n";
1928 $real_filename=search_from
("$dirname",\
@file_components);
1929 if (defined $real_filename) {
1930 return $real_filename;
1934 $filename =~ s
+\\\\+/+g
; # in include ""
1935 $filename =~ s
+\\+/+g
; # in include <> !
1936 if ($opt_lower_include) {
1937 return lc "$filename";
1948 if ($size =~ /^(1|2|4|8)$/) {
1949 print FILEO
"$indent#include <pshpack$size.h>$trailer";
1951 print FILEO
"$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1952 print FILEO
"$indent#include <pshpack4.h>$trailer";
1957 # 'Parses' a source file and fixes constructs that would not work with
1958 # Winelib. The parsing is rather simple and not all non-portable features
1959 # are corrected. The most important feature that is corrected is the case
1960 # and path separator of '#include' directives. This requires that each
1961 # source file be associated to a project & target so that the proper
1962 # include path is used.
1963 # Also note that the include path is relative to the directory in which the
1964 # compiler is run, i.e. that of the project, not to that of the file.
1970 $filename="@$project[$P_PATH]$filename";
1971 if (! -e
$filename) {
1975 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1976 my $dirname=dirname
($filename);
1978 if (defined $target and (@
$target[$T_FLAGS] & $TF_MFC)) {
1982 print " $filename\n";
1983 if (! -e
"$filename.bak") {
1984 if (!copy
("$filename","$filename.bak")) {
1985 print STDERR
"error: unable to make a backup of $filename:\n";
1986 print STDERR
" $!\n";
1990 if (!open(FILEI
,"$filename.bak")) {
1991 print STDERR
"error: unable to open $filename.bak for reading:\n";
1992 print STDERR
" $!\n";
1995 if (!open(FILEO
,">$filename")) {
1996 print STDERR
"error: unable to open $filename for writing:\n";
1997 print STDERR
" $!\n";
2002 my $rc_block_depth=0;
2003 my $rc_textinclude_state=0;
2006 # Remove any trailing CtrlZ, which isn't strictly in the file
2014 # Make sure all files are '\n' terminated
2017 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
2018 # VC6 automatically includes 'afxres.h', an MFC specific header, in
2019 # the RC files it generates (even in non-MFC projects). So we replace
2020 # it with 'winresrc.h' its very close standard cousin so that non MFC
2021 # projects can compile in Wine without the MFC sources.
2022 my $warning="mfc:afxres.h";
2023 if (!defined $warnings{$warning}) {
2024 $warnings{$warning}="1";
2025 print STDERR
"warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
2026 print STDERR
"warning: the above warning is issued only once\n";
2028 print FILEO
"$1/* winemaker: $2\"afxres.h\" */\n";
2029 print FILEO
"$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
2030 print FILEO
"$1$2\"winresrc.h\"$'";
2033 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
2034 my $from_file=($2 eq "<"?
"":$dirname);
2035 my $real_include_name=get_real_include_name
($line,$3,$from_file,$project,$target);
2036 print FILEO
"$1$2$real_include_name$4$'";
2037 $modified|=($real_include_name ne $3);
2039 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
2040 # Pragma pack handling
2042 # pack_stack is an array of references describing the stack of
2043 # pack directives currently in effect. Each directive if described
2044 # by a reference to an array containing:
2045 # - "push" for pack(push,...) directives, "" otherwise
2046 # - the directive's identifier at index 1
2047 # - the directive's alignment value at index 2
2049 # Don't believe a word of what the documentation says: it's all wrong.
2050 # The code below is based on the actual behavior of Visual C/C++ 6.
2055 # Pushes the default stack alignment
2056 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
2057 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2058 print_pack
($pack_indent,4,$');
2059 push @pack_stack, [ "", "", 4 ];
2061 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
2063 # pragma pack(pop,n)
2064 # Goes up the stack until it finds a pack(push,...), and pops it
2065 # Ignores any pack(n) entry
2066 # Issues a warning if the pack is of the form pack(push,label)
2067 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2068 my $pack_comment=$';
2069 $pack_comment =~ s/^\s*//;
2070 if ($pack_comment ne "") {
2071 print FILEO
"$pack_indent$pack_comment";
2074 my $alignment=pop @pack_stack;
2075 if (!defined $alignment) {
2076 print FILEO
"$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2079 if (@
$alignment[1]) {
2080 print FILEO
"$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2082 print FILEO
"$pack_indent#include <poppack.h>\n";
2083 if (@
$alignment[0]) {
2088 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2089 # pragma pack(pop,label[,n])
2090 # Goes up the stack until finding a pack(push,...) and pops it.
2091 # 'n', if specified, is ignored.
2092 # Ignores any pack(n) entry
2093 # Issues a warning if the label of the pack does not match,
2094 # or if it is in fact a pack(push,n)
2096 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
2097 my $pack_comment=$';
2098 $pack_comment =~ s/^\s*//;
2099 if ($pack_comment ne "") {
2100 print FILEO "$pack_indent$pack_comment";
2103 my $alignment=pop @pack_stack;
2104 if (!defined $alignment) {
2105 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2108 if (@$alignment[1] and @$alignment[1] ne $label) {
2109 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2111 print FILEO "$pack_indent#include <poppack.h>\n";
2112 if (@$alignment[0]) {
2117 } elsif (/^(push\s*\))/) {
2119 # Push the current alignment
2120 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2121 if (@pack_stack > 0) {
2122 my $alignment=$pack_stack[$#pack_stack];
2123 print_pack($pack_indent,@$alignment[2],$');
2124 push @pack_stack, [ "push", "", @
$alignment[2] ];
2126 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2127 print_pack
($pack_indent,4,$');
2128 push @pack_stack, [ "push", "", 4 ];
2131 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2132 # pragma pack([push,]n)
2133 # Push new alignment n
2134 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2135 print_pack($pack_indent,$3,"$'");
2136 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2138 } elsif (/^((\w+)\s*\))/) {
2139 # pragma pack(label)
2140 # label must in fact be a macro that resolves to an integer
2141 # Then behaves like 'pragma pack(n)'
2142 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2143 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2144 print_pack($pack_indent,4,$');
2145 push @pack_stack, [ "", "", 4 ];
2147 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2148 # pragma pack(push,label[,n])
2149 # Pushes a new label on the stack. It is possible to push the same
2150 # label multiple times. If 'n' is omitted then the alignment is
2151 # unchanged. Otherwise it becomes 'n'.
2152 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2156 } elsif (@pack_stack > 0) {
2157 my $alignment=$pack_stack[$#pack_stack];
2158 $size=@$alignment[2];
2160 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2163 print_pack($pack_indent,$size,$');
2164 push @pack_stack, [ "push", $2, $size ];
2167 # pragma pack(??? -> What's that?
2168 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2169 print FILEO "$pack_indent$pack_header$_";
2175 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]+)([\">]?)/) {
2176 my $from_file=($5 eq "<"?"":$dirname);
2177 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2178 print FILEO "$1$5$real_include_name$7$'";
2179 $modified|=($real_include_name ne $6);
2181 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2182 my $from_file=($2 eq "<"?"":$dirname);
2183 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2184 print FILEO "$1$2$real_include_name$4$'";
2185 $modified|=($real_include_name ne $3);
2187 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2188 $rc_textinclude_state=1;
2191 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2192 print FILEO "$1winresrc.h
$2$'";
2195 } elsif (/^\s*BEGIN(\W.*)?$/) {
2196 $rc_textinclude_state|=2;
2200 } elsif (/^\s*END(\W.*)?$/) {
2201 $rc_textinclude_state=0;
2202 if ($rc_block_depth>0) {
2218 if ($opt_backup == 0 or $modified == 0) {
2219 if (!unlink("$filename.bak")) {
2220 print STDERR "error: unable to delete $filename.bak:\n";
2221 print STDERR " $!\n";
2227 # Analyzes each source file in turn to find and correct issues
2228 # that would cause it not to compile.
2231 print "Fixing the source files...\n";
2232 foreach my $project (@projects) {
2233 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2234 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2235 fix_file($source,$project,$target);
2250 # A convenience function to generate all the lists (defines,
2251 # C sources, C++ source, etc.) in the Makefile
2252 sub generate_list($$$;$)
2261 printf FILEO "%-22s=",$name;
2263 if (defined $list) {
2264 foreach my $item (@$list) {
2266 if (defined $data) {
2267 $value=&$data($item);
2269 if (defined $item) {
2277 print FILEO " $value";
2280 print FILEO " \\\n\t\t\t$value";
2291 # Generates a project's Makefile
and all the target files
2292 sub generate_project_files
($)
2295 my $project_settings=@
$project[$P_SETTINGS];
2299 # Then sort the targets and separate the libraries from the programs
2300 foreach my $target (sort { @
$a[$T_NAME] cmp @
$b[$T_NAME] } @
{@
$project[$P_TARGETS]}) {
2301 if (@
$target[$T_TYPE] == $TT_DLL) {
2302 push @dll_list,$target;
2304 push @exe_list,$target;
2307 @
$project[$P_TARGETS]=[];
2308 push @
{@
$project[$P_TARGETS]}, @dll_list;
2309 push @
{@
$project[$P_TARGETS]}, @exe_list;
2311 if (!open(FILEO
,">@$project[$P_PATH]Makefile")) {
2312 print STDERR
"error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2313 print STDERR
" $!\n";
2317 print FILEO
"### Generated by Winemaker $version\n";
2320 generate_list
("SRCDIR",1,[ "." ]);
2321 if (@
$project[$P_PATH] eq "") {
2322 # This is the main project. It is also responsible for recursively
2323 # calling the other projects
2324 generate_list
("SUBDIRS",1,\
@projects,sub
2326 if ($_[0] != \
@main_project) {
2327 my $subdir=@
{$_[0]}[$P_PATH];
2331 # Eliminating the main project by returning undefined!
2334 if (@
{@
$project[$P_TARGETS]} > 0) {
2335 generate_list
("DLLS",1,\
@dll_list,sub
2337 return @
{$_[0]}[$T_NAME];
2339 generate_list
("EXES",1,\
@exe_list,sub
2341 return "@{$_[0]}[$T_NAME]";
2343 print FILEO
"\n\n\n";
2345 print FILEO
"### Common settings\n\n";
2346 # Make it so that the project-wide settings override the global settings
2347 generate_list
("CEXTRA",1,@
$project_settings[$T_CEXTRA]);
2348 generate_list
("CXXEXTRA",1,@
$project_settings[$T_CXXEXTRA]);
2349 generate_list
("RCEXTRA",1,@
$project_settings[$T_RCEXTRA]);
2350 generate_list
("DEFINES",1,@
$project_settings[$T_DEFINES]);
2351 generate_list
("INCLUDE_PATH",1,@
$project_settings[$T_INCLUDE_PATH]);
2352 generate_list
("DLL_PATH",1,@
$project_settings[$T_DLL_PATH]);
2353 generate_list
("DLL_IMPORTS",1,@
$project_settings[$T_DLLS]);
2354 generate_list
("LIBRARY_PATH",1,@
$project_settings[$T_LIBRARY_PATH]);
2355 generate_list
("LIBRARIES",1,@
$project_settings[$T_LIBRARIES]);
2358 my $extra_source_count=@
{@
$project_settings[$T_SOURCES_C]}+
2359 @
{@
$project_settings[$T_SOURCES_CXX]}+
2360 @
{@
$project_settings[$T_SOURCES_RC]};
2361 my $no_extra=($extra_source_count == 0);
2363 print FILEO
"### Extra source lists\n\n";
2364 generate_list
("EXTRA_C_SRCS",1,@
$project_settings[$T_SOURCES_C]);
2365 generate_list
("EXTRA_CXX_SRCS",1,@
$project_settings[$T_SOURCES_CXX]);
2366 generate_list
("EXTRA_RC_SRCS",1,@
$project_settings[$T_SOURCES_RC]);
2368 generate_list
("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
2369 print FILEO
"\n\n\n";
2372 # Iterate over all the targets...
2373 foreach my $target (@
{@
$project[$P_TARGETS]}) {
2374 print FILEO
"### @$target[$T_NAME] sources and settings\n\n";
2375 my $canon=canonize
("@$target[$T_NAME]");
2378 generate_list
("${canon}_MODULE",1,[@
$target[$T_NAME]]);
2379 generate_list
("${canon}_C_SRCS",1,@
$target[$T_SOURCES_C]);
2380 generate_list
("${canon}_CXX_SRCS",1,@
$target[$T_SOURCES_CXX]);
2381 generate_list
("${canon}_RC_SRCS",1,@
$target[$T_SOURCES_RC]);
2382 generate_list
("${canon}_LDFLAGS",1,@
$target[$T_LDFLAGS]);
2383 generate_list
("${canon}_DLL_PATH",1,@
$target[$T_DLL_PATH]);
2384 generate_list
("${canon}_DLLS",1,@
$target[$T_DLLS]);
2385 generate_list
("${canon}_LIBRARY_PATH",1,@
$target[$T_LIBRARY_PATH]);
2386 generate_list
("${canon}_LIBRARIES",1,@
$target[$T_LIBRARIES]);
2388 generate_list
("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2389 print FILEO
"\n\n\n";
2391 print FILEO
"### Global source lists\n\n";
2392 generate_list
("C_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2394 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2396 return "\$(${canon}_C_SRCS)";
2399 generate_list
("",1,[ "\$(EXTRA_C_SRCS)" ]);
2401 generate_list
("CXX_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2403 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2405 return "\$(${canon}_CXX_SRCS)";
2408 generate_list
("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2410 generate_list
("RC_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2412 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2414 return "\$(${canon}_RC_SRCS)";
2417 generate_list
("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2421 print FILEO
"### Tools\n\n";
2422 print FILEO
"CC = winegcc\n";
2423 print FILEO
"CXX = wineg++\n";
2424 print FILEO
"RC = wrc\n";
2427 print FILEO
"### Generic targets\n\n";
2429 if (@
$project[$P_PATH] eq "") {
2430 print FILEO
" \$(SUBDIRS)";
2432 if (@
{@
$project[$P_TARGETS]} > 0) {
2433 print FILEO
" \$(DLLS:%=%.so) \$(EXES:%=%.so)";
2436 print FILEO
"### Build rules\n";
2438 print FILEO
".PHONY: all clean dummy\n";
2440 print FILEO
"\$(SUBDIRS): dummy\n";
2441 print FILEO
"\t\@cd \$\@ && \$(MAKE)\n";
2443 print FILEO
"# Implicit rules\n";
2445 print FILEO
".SUFFIXES: .cpp .rc .res\n";
2446 print FILEO
"DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2448 print FILEO
".c.o:\n";
2449 print FILEO
"\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2451 print FILEO
".cpp.o:\n";
2452 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2454 print FILEO
".cxx.o:\n";
2455 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2457 print FILEO
".rc.res:\n";
2458 print FILEO
"\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2460 print FILEO
"# Rules for cleaning\n";
2462 print FILEO
"CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2463 print FILEO
" \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2465 print FILEO
"clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2466 print FILEO
"\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:.cpp=.o)\n";
2467 print FILEO
"\t\$(RM) \$(DLLS:%=%.so) \$(EXES:%=%.so) \$(EXES:%.exe=%)\n";
2469 print FILEO
"\$(SUBDIRS:%=%/__clean__): dummy\n";
2470 print FILEO
"\tcd `dirname \$\@` && \$(MAKE) clean\n";
2472 print FILEO
"\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2473 print FILEO
"\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2476 if (@
{@
$project[$P_TARGETS]} > 0) {
2477 print FILEO
"### Target specific build rules\n";
2478 print FILEO
"DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2479 foreach my $target (@
{@
$project[$P_TARGETS]}) {
2480 my $canon=canonize
("@$target[$T_NAME]");
2483 if (@
$target[$T_TYPE] == $TT_DLL) {
2484 print FILEO
"\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.spec)\n";
2486 print FILEO
"\$(${canon}_MODULE).so: \$(${canon}_OBJS)\n";
2488 if (@
{@
$target[$T_SOURCES_CXX]} > 0 or @
{@
$project_settings[$T_SOURCES_CXX]} > 0) {
2489 print FILEO
"\t\$(CXX)";
2491 print FILEO
"\t\$(CC)";
2493 print FILEO
" \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2503 # This is where we finally generate files. In fact this method does not
2504 # do anything itself but calls the methods that do the actual work.
2507 print "Generating project files...\n";
2509 foreach my $project (@projects) {
2510 my $path=@
$project[$P_PATH];
2517 generate_project_files
($project);
2530 $opt_lower=$OPT_LOWER_UPPERCASE;
2531 $opt_lower_include=1;
2533 $opt_work_dir=undef;
2534 $opt_single_target=undef;
2535 $opt_target_type=$TT_GUIEXE;
2537 $opt_arch=$OPT_ARCH_DEFAULT;
2538 $opt_is_interactive=$OPT_ASK_NO;
2539 $opt_ask_project_options=$OPT_ASK_NO;
2540 $opt_ask_target_options=$OPT_ASK_NO;
2541 $opt_no_generated_files=0;
2542 $opt_no_source_fix=0;
2555 print "Winemaker $version\n";
2556 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2557 print "Copyright 2004 Dimitrie O. Paun\n";
2558 print "Copyright 2009 André Hentschel\n";
2564 print STDERR
"Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2565 print STDERR
" [--lower-none|--lower-all|--lower-uppercase]\n";
2566 print STDERR
" [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2567 print STDERR
" [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2568 print STDERR
" [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2569 print STDERR
" [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2570 print STDERR
" [--generated-files|--nogenerated-files]\n";
2571 print STDERR
" [--wine32]\n";
2572 print STDERR
" work_directory|project_file|workspace_file\n";
2573 print STDERR
"\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2574 print STDERR
"the specified directory or project-file, so that they can be compiled with Winelib.\n";
2575 print STDERR
"During this process it will modify and rename some of the corresponding files.\n";
2576 print STDERR
"\tPlease read the manual page before use.\n";
2580 target_init
(\
@global_settings);
2583 my $arg=shift @ARGV;
2585 if ($arg eq "--nobanner") {
2587 } elsif ($arg eq "--backup") {
2589 } elsif ($arg eq "--nobackup") {
2591 } elsif ($arg eq "--single-target") {
2592 $opt_single_target=shift @ARGV;
2593 } elsif ($arg eq "--lower-none") {
2594 $opt_lower=$OPT_LOWER_NONE;
2595 } elsif ($arg eq "--lower-all") {
2596 $opt_lower=$OPT_LOWER_ALL;
2597 } elsif ($arg eq "--lower-uppercase") {
2598 $opt_lower=$OPT_LOWER_UPPERCASE;
2599 } elsif ($arg eq "--lower-include") {
2600 $opt_lower_include=1;
2601 } elsif ($arg eq "--nolower-include") {
2602 $opt_lower_include=0;
2603 } elsif ($arg eq "--nosource-fix") {
2604 $opt_no_source_fix=1;
2605 } elsif ($arg eq "--generated-files") {
2606 $opt_no_generated_files=0;
2607 } elsif ($arg eq "--nogenerated-files") {
2608 $opt_no_generated_files=1;
2609 } elsif ($arg eq "--wine32") {
2610 $opt_arch=$OPT_ARCH_32;
2611 } elsif ($arg =~ /^-D/) {
2612 push @
{$global_settings[$T_DEFINES]},$arg;
2613 } elsif ($arg =~ /^-I/) {
2614 push @
{$global_settings[$T_INCLUDE_PATH]},$arg;
2615 } elsif ($arg =~ /^-P/) {
2616 push @
{$global_settings[$T_DLL_PATH]},"-L$'";
2617 } elsif ($arg =~ /^-i/) {
2618 push @
{$global_settings[$T_DLLS]},$';
2619 } elsif ($arg =~ /^-L/) {
2620 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2621 } elsif ($arg =~ /^-l/) {
2622 push @{$global_settings[$T_LIBRARIES]},$';
2624 # 'Source'-based method options
2625 } elsif ($arg eq "--dll") {
2626 $opt_target_type=$TT_DLL;
2627 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2628 $opt_target_type=$TT_GUIEXE;
2629 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2630 $opt_target_type=$TT_CUIEXE;
2631 } elsif ($arg eq "--interactive") {
2632 $opt_is_interactive=$OPT_ASK_YES;
2633 $opt_ask_project_options=$OPT_ASK_YES;
2634 $opt_ask_target_options=$OPT_ASK_YES;
2635 } elsif ($arg eq "--mfc") {
2636 $opt_flags|=$TF_MFC;
2637 } elsif ($arg eq "--nomfc") {
2638 $opt_flags&=~$TF_MFC;
2639 $opt_flags|=$TF_NOMFC;
2640 } elsif ($arg eq "--nodlls") {
2641 $opt_flags|=$TF_NODLLS;
2642 } elsif ($arg eq "--nomsvcrt") {
2643 $opt_flags|=$TF_NOMSVCRT;
2647 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2648 if (!defined $opt_work_dir and !defined $opt_work_file) {
2650 $opt_work_file=$arg;
2656 print STDERR
"error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2665 if (!defined $opt_work_dir and !defined $opt_work_file) {
2666 print STDERR
"error: you must specify the directory or project file containing the sources to be converted\n";
2668 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2669 print STDERR
"error: could not chdir to the work directory\n";
2670 print STDERR
" $!\n";
2674 if ($opt_no_banner == 0) {
2678 project_init
(\
@main_project, "", \
@global_settings);
2680 # Fix the file and directory names
2681 fix_file_and_directory_names
(".");
2683 # Scan the sources to identify the projects and targets
2686 # Fix the source files
2687 if (! $opt_no_source_fix) {
2691 # Generate the Makefile and the spec file
2692 if (! $opt_no_generated_files) {