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 list of dependencies between targets
232 # The following constants define the recognized types of target
235 # This is not a real target. This type of target is used to collect
236 # the sources that don't seem to belong to any other target. Thus no
237 # real target is generated for them, we just put the sources of the
238 # fake target in the global source list.
242 # For executables in the windows subsystem
246 # For executables in the console subsystem
250 # For dynamically linked libraries
254 # The following constants further refine how the target should be handled
257 # This target is an MFC-based target
261 # User has specified --nomfc option for this target or globally
265 # --nodlls option: Do not use standard DLL set
269 # --nomsvcrt option: Do not link with msvcrt
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 # leaving $T_INIT undefined
282 @
$target[$T_FLAGS]=$opt_flags;
283 @
$target[$T_SOURCES_C]=[];
284 @
$target[$T_SOURCES_CXX]=[];
285 @
$target[$T_SOURCES_RC]=[];
286 @
$target[$T_SOURCES_MISC]=[];
287 @
$target[$T_CEXTRA]=[];
288 @
$target[$T_CXXEXTRA]=[];
289 @
$target[$T_RCEXTRA]=[];
290 @
$target[$T_DEFINES]=[];
291 @
$target[$T_INCLUDE_PATH]=[];
292 @
$target[$T_LDFLAGS]=[];
293 @
$target[$T_DLL_PATH]=[];
294 @
$target[$T_DLLS]=[];
295 @
$target[$T_LIBRARY_PATH]=[];
296 @
$target[$T_LIBRARIES]=[];
303 # Project modelization
307 # First we have the notion of project. A project is described by an
308 # array (since we don't have structs in perl). The constants below
309 # identify what is stored at each index of the array.
312 # This is the path in which this project is located. In other
313 # words, this is the path to the Makefile.
317 # This index contains a reference to an array containing the project-wide
318 # settings. The structure of that arrray is actually identical to that of
319 # a regular target since it can also contain extra sources.
323 # This index contains a reference to an array of targets for this
324 # project. Each target describes how an executable or library is to
325 # be built. For each target this description takes the same form as
326 # that of the project: an array. So this entry is an array of arrays.
330 # Initialize a project:
331 # - set the project's path
332 # - initialize the target list
333 # - create a default target (will be removed later if unnecessary)
334 sub project_init
($$$)
336 my ($project, $path, $global_settings)=@_;
338 my $project_settings=[];
339 target_init
($project_settings);
340 @
$project_settings[$T_DEFINES]=[@
{@
$global_settings[$T_DEFINES]}];
341 @
$project_settings[$T_INCLUDE_PATH]=[@
{@
$global_settings[$T_INCLUDE_PATH]}];
342 @
$project_settings[$T_DLL_PATH]=[@
{@
$global_settings[$T_DLL_PATH]}];
343 @
$project_settings[$T_DLLS]=[@
{@
$global_settings[$T_DLLS]}];
344 @
$project_settings[$T_LIBRARY_PATH]=[@
{@
$global_settings[$T_LIBRARY_PATH]}];
345 @
$project_settings[$T_LIBRARIES]=[@
{@
$global_settings[$T_LIBRARIES]}];
347 @
$project[$P_PATH]=$path;
348 @
$project[$P_SETTINGS]=$project_settings;
349 @
$project[$P_TARGETS]=[];
365 # This maps a directory name to a reference to an array listing
366 # its contents (files and directories)
370 # Contains the list of all projects. This list tells us what are
371 # the subprojects of the main Makefile and where we have to generate
376 # This is the main project, i.e. the one in the "." directory.
377 # It may well be empty in which case the main Makefile will only
378 # call out subprojects.
382 # Contains the defaults for the include path, etc.
383 # We store the defaults as if this were a target except that we only
384 # exploit the defines, include path, library path, library list and misc
397 # Cleans up a name to make it an acceptable Makefile
403 $name =~ tr/a-zA-Z0-9_/_/c;
408 # Returns true is the specified pathname is absolute.
409 # Note: pathnames that start with a variable '$' or
410 # '~' are considered absolute.
415 return ($path =~ /^[\/~\
$]/);
419 # Retrieves the contents of the specified directory.
420 # We either get it from the directories hashtable which acts as a
421 # cache, or use opendir, readdir, closedir and store the result
423 sub get_directory_contents
($)
428 #print "getting the contents of $dirname\n";
430 # check for a cached version
432 if ($dirname eq "") {
435 $directory=$directories{$dirname};
436 if (defined $directory) {
437 #print "->@$directory\n";
441 # Read this directory
442 if (opendir(DIRECTORY
, "$dirname")) {
443 my @files=readdir DIRECTORY
;
447 # Return an empty list
448 #print "error: cannot open $dirname\n";
452 #print "->@$directory\n";
453 $directories{$dirname}=$directory;
458 # Removes a directory from the cache.
459 # This is needed if one of its files or subdirectory has been renamed.
460 sub clear_directory_cache
($)
463 delete $directories{$dirname};
469 # 'Source'-based Project analysis
474 # Allows the user to specify makefile and target specific options
475 # - target: the structure in which to store the results
476 # - options: the string containing the options
477 sub source_set_options
($$)
482 #FIXME: we must deal with escaping of stuff and all
483 foreach my $option (split / /,$options) {
484 if (@
$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
485 push @
{@
$target[$T_DEFINES]},$option;
486 } elsif (@
$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
487 push @
{@
$target[$T_INCLUDE_PATH]},$option;
488 } elsif ($option =~ /^-P/) {
489 push @
{@
$target[$T_DLL_PATH]},"-L$'";
490 } elsif ($option =~ /^-i/) {
491 push @
{@
$target[$T_DLLS]},"$'";
492 } elsif ($option =~ /^-L/) {
493 push @
{@
$target[$T_LIBRARY_PATH]},$option;
494 } elsif ($option =~ /^-l/) {
495 push @
{@
$target[$T_LIBRARIES]},"$'";
496 } elsif ($option =~ /^--mfc/) {
497 @
$target[$T_FLAGS]|=$TF_MFC;
498 @
$target[$T_FLAGS]&=~$TF_NOMFC;
499 } elsif ($option =~ /^--nomfc/) {
500 @
$target[$T_FLAGS]&=~$TF_MFC;
501 @
$target[$T_FLAGS]|=$TF_NOMFC;
502 } elsif ($option =~ /^--nodlls/) {
503 @
$target[$T_FLAGS]|=$TF_NODLLS;
504 } elsif ($option =~ /^--nomsvcrt/) {
505 @
$target[$T_FLAGS]|=$TF_NOMSVCRT;
507 print STDERR
"error: unknown option \"$option\"\n";
515 # Scans the specified project file to:
516 # - get a list of targets for this project
517 # - get some settings
518 # - get the list of source files
519 sub source_scan_project_file
($$$);
520 sub source_scan_project_file
($$$)
522 # a reference to the parent's project
523 my $parent_project=$_[0];
524 # 0 if it is a single project, 1 if it is part of a workspace
525 my $is_sub_project=$_[1];
526 # the name of the project file, with complete path, or without if in
530 # reference to the project for this file. May not be used
532 # list of sources found in the current file
538 my $path=dirname
($filename);
539 my $prj_target_cflags;
540 my $prj_target_defines;
541 my $prj_target_ldflags;
546 my $prj_target_type=1;
547 my @prj_target_options;
549 if (!($path=~/\/$/)) {
553 if (defined $opt_single_target or $is_sub_project == 0) {
554 # Either there is a single target and thus a single project,
555 # or we are a single project-file for which a project
557 $project=$parent_project;
560 project_init
($project, $path, \
@global_settings);
562 my $project_settings=@
$project[$P_SETTINGS];
564 if ($filename =~ /.dsp$/i) {
565 # First find out what this project file contains:
566 # collect all sources, find targets and settings
567 if (!open(FILEI
,$filename)) {
568 print STDERR
"error: unable to open $filename for reading:\n";
569 print STDERR
" $!\n";
574 # Remove any trailing CtrlZ, which isn't strictly in the file
580 # Remove any trailing CrLf
583 # Make sure all lines are '\n' terminated
587 if (/^\# Microsoft Developer Studio Project File - Name=\"([^\"]+)/) {
589 $prj_name=~s/\s+/_/g;
592 } elsif (/^# TARGTYPE/) {
593 if (/[[:space:]]0x0101$/) {
594 # Win32 (x86) Application
596 }elsif (/[[:space:]]0x0102$/) {
597 # Win32 (x86) Dynamic-Link Library
599 }elsif (/[[:space:]]0x0103$/) {
600 # Win32 (x86) Console Application
602 }elsif (/[[:space:]]0x0104$/) {
603 # Win32 (x86) Static Library
606 } elsif (/^# ADD CPP(.*)/ && $found_cfg==1) {
607 $prj_target_cflags=$1;
608 @prj_target_options=split(" /", $prj_target_cflags);
609 $prj_target_cflags="";
610 foreach ( @prj_target_options ) {
614 # Suppress Startup Banner and Information Messages
616 # Turns off all warning messages
617 $prj_target_cflags.="-w ";
618 } elsif (/^W[123]$/) {
620 $prj_target_cflags.="-W ";
623 $prj_target_cflags.="-Wall ";
626 $prj_target_cflags.="-Werror ";
628 # Enable Minimal Rebuild
630 # Enable Exception Handling
631 $prj_target_cflags.="-fexceptions ";
632 } elsif (/^Z[d7iI]$/) {
634 $prj_target_cflags.="-g ";
636 # Disable Optimizations
637 $prj_target_cflags.="-O0 ";
640 $prj_target_cflags.="-Os ";
643 $prj_target_cflags.="-O2 ";
645 # Disables inline Expansion
646 $prj_target_cflags.="-fno-inline ";
648 #In-line Function Expansion
649 $prj_target_cflags.="-finline-functions ";
651 # auto In-line Function Expansion
652 $prj_target_cflags.="-finline-functions ";
654 # Use maximum optimization
655 $prj_target_cflags.="-O3 ";
657 # Frame-Pointer Omission
658 $prj_target_cflags.="-fomit-frame-pointer ";
660 # Frame-Pointer Omission
661 $prj_target_cflags.="-fno-omit-frame-pointer ";
663 # Catch Release-Build Errors in Debug Build
664 } elsif (/^M[DLT]d?$/) {
665 # Use Multithreaded Run-Time Library
666 } elsif (/^D\s*\"(.*)\"/) {
667 # Preprocessor Definitions
668 $prj_target_defines.="-D".$1." ";
669 } elsif (/^I\s*\"(.*)\"/) {
670 # Additional Include Directories
673 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I".$sfilet." ";
674 } elsif (/^U\s*\"(.*)\"/) {
675 # Undefines a previously defined symbol
676 $prj_target_cflags.="-U".$1." ";
682 # Automatic Use of Precompiled Headers
684 # Generate File Dependencies
686 # Compile Without Linking
687 # this option is always present and is already specified in the suffix rules
690 $prj_target_cflags.="-mcpu=pentiumpro -D_M_IX86=500 ";
692 # Pentium Pro Optimization
693 $prj_target_cflags.="-march=pentiumpro -D_M_IX86=600 ";
695 # Pentium Optimization
696 $prj_target_cflags.="-mcpu=pentium -D_M_IX86=500 ";
699 $prj_target_cflags.="-mcpu=i386 -D_M_IX86=300 ";
702 $prj_target_cflags.="-mcpu=i486 -D_M_IX86=400 ";
704 # Create Precompiled Header
706 # Use Precompiled Header
708 # Disable Language Extensions
709 $prj_target_cflags.="-ansi ";
711 # Enable Microsoft Extensions
712 } elsif (/^Zm[[:digit:]]+$/) {
713 # Specify Memory Allocation Limit
715 # Packs structures on 1-byte boundaries
716 $prj_target_cflags.="-fpack-struct ";
717 } elsif (/^Zp(2|4|8|16)$/) {
718 # Struct Member Alignment
719 $prj_target_cflags.="-fpack-struct=".$1;
721 print "C compiler option $_ not implemented\n";
725 #print "\nOptions: $prj_target_cflags\n";
727 } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
728 $prj_target_ldflags=$1;
729 @prj_target_options=split(" /", $prj_target_ldflags);
730 $prj_target_ldflags="";
731 $prj_target_libs=$prj_target_options[0];
732 $prj_target_libs=~s/\\/\//g
;
733 $prj_target_libs=~s/\.lib//g;
734 $prj_target_libs=~s/\s+/ -l/g;
735 shift (@prj_target_options);
736 foreach ( @prj_target_options ) {
739 } elsif (/^base:(.*)/) {
741 $prj_target_ldflags.="--image-base ".$1." ";
742 } elsif (/^debug$/) {
743 # Generate Debug Info
747 } elsif (/^incremental:[[:alpha:]]+$/) {
749 } elsif (/^implib:/) {
750 # Name import library
751 } elsif (/^libpath:\"(.*)\"/) {
753 push @
{@
$project_settings[$T_DLL_PATH]},"-L$1";
754 } elsif (/^machine:[[:alnum:]]+$/) {
755 # Specify Target Platform
759 $prj_target_ldflags.="-Map ".$1." ";
761 $prj_target_ldflags.="-Map ".$prj_name.".map ";
763 } elsif (/^nologo$/) {
764 # Suppress Startup Banner and Information Messages
767 # may use it as Target?
768 } elsif (/^pdbtype:/) {
769 # Program Database Storage
770 } elsif (/^subsystem:/) {
772 } elsif (/^version:[[:digit:].]+$/) {
773 # Version Information
775 print "Linker option $_ not implemented\n";
779 } elsif (/^LIB32=/ && $found_cfg==1) {
782 } elsif (/^SOURCE=(.*)$/) {
783 my @components=split /[\/\\]+/, $1;
784 $sfilet=search_from
($path, \
@components);
785 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
786 push @sources_c,$sfilet;
787 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
788 if ($sfilet =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
789 push @sources_misc,$sfilet;
790 @
$project_settings[$T_FLAGS]|=$TF_MFC;
792 push @sources_cxx,$sfilet;
794 } elsif ($sfilet =~ /\.rc$/i) {
795 push @sources_rc,$sfilet;
796 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
797 push @sources_misc,$sfilet;
798 if ($sfilet =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
799 @
$project_settings[$T_FLAGS]|=$TF_MFC;
804 } elsif (/^# (Begin|End) Source File/) {
805 # Source-Files already handled
807 } elsif (/^# (Begin|End) Group/) {
810 } elsif (/^# (Begin|End) Custom Build/) {
811 # Custom Builds are ignored
813 } elsif (/^# ADD LIB32 /) {
816 } elsif (/^# Begin Target$/) {
817 # Targets are ignored
819 } elsif (/^# End Target$/) {
820 # Targets are ignored
823 if ($found_cfg == 1) {
826 if (/if (.*)\(CFG\)" == "(.*)"/i) {
827 if ($2 eq $prj_cfg) {
832 } elsif (/^CFG=(.*)/i) {
836 else { # Line recognized
842 push @
{@
$project_settings[$T_LIBRARIES]},$prj_target_libs;
843 push @
{@
$project_settings[$T_CEXTRA]},$prj_target_cflags;
844 push @
{@
$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
845 push @
{@
$project_settings[$T_DEFINES]},$prj_target_defines;
846 push @
{@
$project_settings[$T_LDFLAGS]},$prj_target_ldflags;
847 } elsif ($filename =~ /.vcproj$/i) {
848 # Import XML::LibXML, you need the libxml package (deb: libxml-libxml-perl, rpm: perl-libxml-perl)
851 my $xmlparser = XML
::LibXML
->new();
852 my $project_xml = $xmlparser->parse_file($filename);
856 foreach my $vc_project ($project_xml->findnodes('/VisualStudioProject')) {
857 foreach my $vc_project_attr ($vc_project->attributes) {
858 if ($vc_project_attr->getName eq "Name") {
859 $prj_name=$vc_project_attr->getValue;
860 $prj_name=~s/\s+/_/g;
866 for (my $flevel = 0; $flevel <= 5; $flevel++) {
867 foreach my $vc_file ($project_xml->findnodes('/VisualStudioProject/Files/'.('Filter/' x
$flevel).'File')) {
868 foreach my $vc_file_attr ($vc_file->attributes) {
869 if ($vc_file_attr->getName eq "RelativePath") {
870 $sfilet = $vc_file_attr->getValue;
871 $sfilet=~s/\\\\/\\/g; #remove double backslash
872 $sfilet=~s/^\.\\//; #remove starting 'this directory'
873 $sfilet=~s/\\/\//g
; #make slashes out of backslashes
874 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
875 push @sources_c,$sfilet;
876 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
877 if ($sfilet =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
878 push @sources_misc,$sfilet;
879 @
$project_settings[$T_FLAGS]|=$TF_MFC;
881 push @sources_cxx,$sfilet;
883 } elsif ($sfilet =~ /\.rc$/i) {
884 push @sources_rc,$sfilet;
885 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
886 push @sources_misc,$sfilet;
887 if ($sfilet =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
888 @
$project_settings[$T_FLAGS]|=$TF_MFC;
896 my @vc_configurations = $project_xml->findnodes('/VisualStudioProject/Configurations/Configuration');
897 my $vc_configuration = $vc_configurations[0];
898 foreach my $vc_configuration_attr ($vc_configuration->attributes) {
899 if ($vc_configuration_attr->getName eq "ConfigurationType") {
900 if ($vc_configuration_attr->getValue==1) {
901 $prj_target_type=1; # Win32 (x86) Application
902 } elsif ($vc_configuration_attr->getValue==2) {
903 $prj_target_type=3; # Win32 (x86) Dynamic-Link Library
908 foreach my $vc_configuration_tools ($vc_configuration->findnodes('Tool')) {
909 my @find_tool = $vc_configuration_tools->attributes;
910 if ($find_tool[0]->getValue eq "VCCLCompilerTool") {
911 foreach my $vc_compiler_tool ($vc_configuration_tools->attributes) {
912 if ($vc_compiler_tool->getName eq "Optimization") {$prj_target_cflags.="-O".$vc_compiler_tool->getValue." ";}
913 if ($vc_compiler_tool->getName eq "WarningLevel") {
914 if ($vc_compiler_tool->getValue==0) {
915 $prj_target_cflags.="-w ";
916 } elsif ($vc_compiler_tool->getValue<4) {
917 $prj_target_cflags.="-W ";
918 } elsif ($vc_compiler_tool->getValue==4) {
919 $prj_target_cflags.="-Wall ";
920 } elsif ($vc_compiler_tool->getValue eq "X") {
921 $prj_target_cflags.="-Werror ";
924 if ($vc_compiler_tool->getName eq "PreprocessorDefinitions") {
925 $configt=$vc_compiler_tool->getValue;
927 $prj_target_defines.="-D".$configt." ";
929 if ($vc_compiler_tool->getName eq "AdditionalIncludeDirectories") {
930 $configt=$vc_compiler_tool->getValue;
933 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I".$configt;
937 if ($find_tool[0]->getValue eq "VCLinkerTool") {
938 foreach my $vc_linker_tool ($vc_configuration_tools->attributes) {
939 if ($vc_linker_tool->getName eq "AdditionalDependencies") {
940 $prj_target_libs=" ".$vc_linker_tool->getValue;
941 $prj_target_libs=~s/\\/\//g
;
942 $prj_target_libs=~s/\.lib//g;
943 $prj_target_libs=~s/\s+/ -l/g;
949 push @
{@
$project_settings[$T_LIBRARIES]},$prj_target_libs;
950 push @
{@
$project_settings[$T_CEXTRA]},$prj_target_cflags;
951 push @
{@
$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
952 push @
{@
$project_settings[$T_DEFINES]},$prj_target_defines;
955 # Add this project to the project list, except for
956 # the main project which is already in the list.
957 if ($is_sub_project == 1) {
958 push @projects,$project;
961 # Ask for project-wide options
962 if ($opt_ask_project_options == $OPT_ASK_YES) {
964 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
967 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
968 if (defined $flag_desc) {
969 print "* (currently $flag_desc)\n";
971 print "* or 'skip' to skip the target specific options,\n";
972 print "* or 'never' to not be asked this question again:\n";
976 if ($options eq "skip") {
977 $opt_ask_target_options=$OPT_ASK_SKIP;
979 } elsif ($options eq "never") {
980 $opt_ask_project_options=$OPT_ASK_NO;
982 } elsif (source_set_options
($project_settings,$options)) {
985 print "Please re-enter the options:\n";
990 my @local_depends=();
993 # Create the target...
995 target_init
($target);
997 if ($prj_target_type!=3) {
998 $prj_name=lc($prj_name.".exe");
999 @
$target[$T_TYPE]=$opt_target_type;
1000 push @exe_list,$target;
1001 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
1003 $prj_name=lc($prj_name.".dll");
1004 @
$target[$T_TYPE]=$TT_DLL;
1005 push @local_depends,"$prj_name.so";
1006 push @local_dlls,$prj_name;
1007 my $canon=canonize
($prj_name);
1008 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
1011 @
$target[$T_NAME]=$prj_name;
1012 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
1014 # This is the default link list of Visual Studio
1015 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1016 my @std_libraries=qw(uuid);
1017 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1018 @
$target[$T_DLLS]=\
@std_imports;
1019 @
$target[$T_LIBRARIES]=\
@std_libraries;
1021 @
$target[$T_DLLS]=[];
1022 @
$target[$T_LIBRARIES]=[];
1024 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1025 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
1026 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1027 push @
{@
$target[$T_LDFLAGS]},"-m$opt_arch";
1030 push @
{@
$project[$P_TARGETS]},$target;
1032 # Ask for target-specific options
1033 if ($opt_ask_target_options == $OPT_ASK_YES) {
1035 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
1038 if ($flag_desc ne "") {
1041 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1042 print "* \"$prj_name\"$flag_desc or 'never' to not be asked this question again:\n";
1044 my $options=<STDIN
>;
1046 if ($options eq "never") {
1047 $opt_ask_target_options=$OPT_ASK_NO;
1049 } elsif (source_set_options
($target,$options)) {
1052 print "Please re-enter the options:\n";
1055 if (@
$target[$T_FLAGS] & $TF_MFC) {
1056 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1057 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1058 push @
{@
$target[$T_DLLS]},"mfc.dll";
1059 # FIXME: Link with the MFC in the Unix sense, until we
1060 # start exporting the functions properly.
1061 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1062 push @
{@
$target[$T_LIBRARIES]},"mfc";
1066 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
1067 @
$project_settings[$T_SOURCES_C]=[];
1069 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1070 @
$project_settings[$T_SOURCES_CXX]=[];
1072 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
1073 @
$project_settings[$T_SOURCES_RC]=[];
1075 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
1076 @
$project_settings[$T_SOURCES_MISC]=[];
1079 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
1080 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
1081 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
1082 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
1084 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1085 $opt_ask_target_options=$OPT_ASK_YES;
1088 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1089 push @
{@
$project_settings[$T_CEXTRA]},"-mno-cygwin";
1090 push @
{@
$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1091 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1092 push @
{@
$project_settings[$T_CEXTRA]},"-m$opt_arch";
1093 push @
{@
$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1097 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
1098 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1100 # The sources that did not match, if any, go to the extra
1101 # source list of the project settings
1102 foreach my $source (@sources_c) {
1103 if ($source ne "") {
1104 push @
{@
$project_settings[$T_SOURCES_C]},$source;
1107 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
1108 foreach my $source (@sources_cxx) {
1109 if ($source ne "") {
1110 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
1113 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
1114 foreach my $source (@sources_rc) {
1115 if ($source ne "") {
1116 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
1119 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
1120 foreach my $source (@sources_misc) {
1121 if ($source ne "") {
1122 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
1125 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
1129 # Scans the specified workspace file to find the project files
1130 sub source_scan_workspace_file
($);
1131 sub source_scan_workspace_file
($)
1134 my $path=dirname
($filename);
1137 if (! -e
$filename) {
1141 if (!open(FILEIWS
,$filename)) {
1142 print STDERR
"error: unable to open $filename for reading:\n";
1143 print STDERR
" $!\n";
1150 if ($filename =~ /.dsw$/i) {
1152 # Remove any trailing CrLf
1155 # catch a project definition
1156 if (/^Project:\s\"(.*)\"=(.*)\s-/) {
1159 @components=split /[\/\\]+/, $prj_path;
1160 $prj_path=search_from
($path, \
@components);
1161 print "Name: $prj_name\nPath: $prj_path\n";
1162 source_scan_project_file
(\
@main_project,1,$prj_path);
1167 print STDERR
"unknown section $_\n";
1168 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1169 print "\nFileversion: $3\n";
1173 } elsif ($filename =~ /.sln$/i) {
1175 # Remove any trailing CrLf
1178 # catch a project definition
1179 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1182 @components=split /[\/\\]+/, $3;
1183 $prj_path=search_from
($path, \
@components);
1184 print "Name: $prj_name\nPath: $prj_path\n";
1185 source_scan_project_file
(\
@main_project,1,$prj_path);
1187 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1188 print "\nFileversion: $3\n";
1194 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
1198 # Scans the specified directory to:
1199 # - see if we should create a Makefile in this directory. We normally do
1200 # so if we find a project file and sources
1201 # - get a list of targets for this directory
1202 # - get the list of source files
1203 sub source_scan_directory
($$$$);
1204 sub source_scan_directory
($$$$)
1206 # a reference to the parent's project
1207 my $parent_project=$_[0];
1208 # the full relative path to the current directory, including a
1209 # trailing '/', or an empty string if this is the top level directory
1211 # the name of this directory, including a trailing '/', or an empty
1212 # string if this is the top level directory
1214 # if set then no targets will be looked for and the sources will all
1215 # end up in the parent_project's 'misc' bucket
1216 my $no_target=$_[3];
1218 # reference to the project for this directory. May not be used
1220 # list of targets found in the 'current' directory
1222 # list of sources found in the current directory
1226 my @sources_misc=();
1227 # true if this directory contains a Windows project
1228 my $has_win_project=0;
1229 # true if this directory contains headers
1231 # If we don't find any executable/library then we might make up targets
1232 # from the list of .dsp/.mak files we find since they usually have the
1233 # same name as their target.
1237 if (defined $opt_single_target or $dirname eq "") {
1238 # Either there is a single target and thus a single project,
1239 # or we are in the top level directory for which a project
1241 $project=$parent_project;
1244 project_init
($project, $path, \
@global_settings);
1246 my $project_settings=@
$project[$P_SETTINGS];
1248 # First find out what this directory contains:
1249 # collect all sources, targets and subdirectories
1250 my $directory=get_directory_contents
($path);
1251 foreach my $dentry (@
$directory) {
1252 if ($dentry =~ /^\./) {
1255 my $fullentry="$path$dentry";
1256 if (-d
"$fullentry") {
1257 if ($dentry =~ /^(Release|Debug)/i) {
1258 # These directories are often used to store the object files and the
1259 # resulting executable/library. They should not contain anything else.
1260 my @candidates=grep /\.(exe|dll)$/i, @
{get_directory_contents
("$fullentry")};
1261 foreach my $candidate (@candidates) {
1262 $targets{$candidate}=1;
1264 } elsif ($dentry =~ /^include/i) {
1265 # This directory must contain headers we're going to need
1266 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1267 source_scan_directory
($project,"$fullentry/","$dentry/",1);
1269 # Recursively scan this directory. Any source file that cannot be
1270 # attributed to a project in one of the subdirectories will be
1271 # attributed to this project.
1272 source_scan_directory
($project,"$fullentry/","$dentry/",$no_target);
1274 } elsif (-f
"$fullentry") {
1275 if ($dentry =~ /\.(exe|dll)$/i) {
1276 $targets{$dentry}=1;
1277 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1278 push @sources_c,"$dentry";
1279 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
1280 if ($dentry =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1281 push @sources_misc,"$dentry";
1282 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1284 push @sources_cxx,"$dentry";
1286 } elsif ($dentry =~ /\.rc$/i) {
1287 push @sources_rc,"$dentry";
1288 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1290 push @sources_misc,"$dentry";
1291 if ($dentry =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1292 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1294 } elsif ($dentry =~ /\.dsp$/i) {
1295 push @dsp_files,"$dentry";
1297 } elsif ($dentry =~ /\.mak$/i) {
1298 push @mak_files,"$dentry";
1300 } elsif ($dentry =~ /^makefile/i) {
1307 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I.";
1309 # If we have a single target then all we have to do is assign
1310 # all the sources to it and we're done
1311 # FIXME: does this play well with the --interactive mode?
1312 if ($opt_single_target) {
1313 my $target=@
{@
$project[$P_TARGETS]}[0];
1314 push @
{@
$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1315 push @
{@
$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1316 push @
{@
$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1317 push @
{@
$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1321 my $parent_settings=@
$parent_project[$P_SETTINGS];
1322 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1323 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1324 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1325 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1326 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1330 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1331 @
{@
$project_settings[$T_SOURCES_C]}+
1332 @
{@
$project_settings[$T_SOURCES_CXX]}+
1333 @
{@
$project_settings[$T_SOURCES_RC]};
1334 if ($source_count == 0) {
1335 # A project without real sources is not a project, get out!
1336 if ($project!=$parent_project) {
1337 my $parent_settings=@
$parent_project[$P_SETTINGS];
1338 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1339 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1343 #print "targets=",%targets,"\n";
1344 #print "target_count=$target_count\n";
1345 #print "has_win_project=$has_win_project\n";
1346 #print "dirname=$dirname\n";
1349 if (($has_win_project != 0) or ($dirname eq "")) {
1350 # Deal with cases where we could not find any executable/library, and
1351 # thus have no target, although we did find some sort of windows project.
1352 $target_count=keys %targets;
1353 if ($target_count == 0) {
1354 # Try to come up with a target list based on .dsp/.mak files
1356 if (@dsp_files > 0) {
1357 $prj_list=\
@dsp_files;
1359 $prj_list=\
@mak_files;
1361 foreach my $filename (@
$prj_list) {
1362 $filename =~ s/\.(dsp|mak)$//i;
1363 if ($opt_target_type == $TT_DLL) {
1364 $filename = "$filename.dll";
1366 $targets{$filename}=1;
1368 $target_count=keys %targets;
1369 if ($target_count == 0) {
1370 # Still nothing, try the name of the directory
1372 if ($dirname eq "") {
1373 # Bad luck, this is the top level directory!
1374 $name=(split /\//, cwd
)[-1];
1377 # Remove the trailing '/'. Also eliminate whatever is after the last
1378 # '.' as it is likely to be meaningless (.orig, .new, ...)
1379 $name =~ s
+(/|\
.[^.]*)$++;
1380 if ($name eq "src") {
1381 # 'src' is probably a subdirectory of the real project directory.
1382 # Try again with the parent (if any).
1384 if ($parent =~ s
+([^/]*)/[^/]*/$+$1+) {
1387 $name=(split /\//, cwd
)[-1];
1391 $name =~ s
+(/|\
.[^.]*)$++;
1392 if ($opt_target_type == $TT_DLL) {
1393 $name = canonize
($name).".dll";
1395 $name = canonize
($name).".exe";
1401 # Ask confirmation to the user if he wishes so
1402 if ($opt_is_interactive == $OPT_ASK_YES) {
1403 my $target_list=join " ",keys %targets;
1404 print "\n*** In ",($path?
$path:"./"),"\n";
1405 print "* winemaker found the following list of (potential) targets\n";
1406 print "* $target_list\n";
1407 print "* Type enter to use it as is, your own comma-separated list of\n";
1408 print "* targets, 'none' to assign the source files to a parent directory,\n";
1409 print "* or 'ignore' to ignore everything in this directory tree.\n";
1410 print "* Target list:\n";
1411 $target_list=<STDIN
>;
1413 if ($target_list eq "") {
1414 # Keep the target list as is, i.e. do nothing
1415 } elsif ($target_list eq "none") {
1416 # Empty the target list
1418 } elsif ($target_list eq "ignore") {
1419 # Ignore this subtree altogether
1423 foreach my $target (split /,/,$target_list) {
1424 $target =~ s
+^\s
*++;
1425 $target =~ s
+\s
*$++;
1426 $targets{$target}=1;
1432 # If we have no project at this level, then transfer all
1433 # the sources to the parent project
1434 $target_count=keys %targets;
1435 if ($target_count == 0) {
1436 if ($project!=$parent_project) {
1437 my $parent_settings=@
$parent_project[$P_SETTINGS];
1438 push @
{@
$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1439 push @
{@
$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1440 push @
{@
$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1441 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1442 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1447 # Otherwise add this project to the project list, except for
1448 # the main project which is already in the list.
1449 if ($dirname ne "") {
1450 push @projects,$project;
1453 # Ask for project-wide options
1454 if ($opt_ask_project_options == $OPT_ASK_YES) {
1456 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1459 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1460 if (defined $flag_desc) {
1461 print "* (currently $flag_desc)\n";
1463 print "* or 'skip' to skip the target specific options,\n";
1464 print "* or 'never' to not be asked this question again:\n";
1466 my $options=<STDIN
>;
1468 if ($options eq "skip") {
1469 $opt_ask_target_options=$OPT_ASK_SKIP;
1471 } elsif ($options eq "never") {
1472 $opt_ask_project_options=$OPT_ASK_NO;
1474 } elsif (source_set_options
($project_settings,$options)) {
1477 print "Please re-enter the options:\n";
1481 # - Create the targets
1482 # - Check if we have both libraries and programs
1483 # - Match each target with source files (sort in reverse
1484 # alphabetical order to get the longest matches first)
1486 my @local_depends=();
1488 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1489 # Create the target...
1491 target_init
($target);
1492 @
$target[$T_NAME]=$target_name;
1493 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
1494 if ($target_name =~ /\.dll$/) {
1495 @
$target[$T_TYPE]=$TT_DLL;
1496 push @local_depends,"$target_name.so";
1497 push @local_dlls,$target_name;
1498 my $canon=canonize
($target_name);
1499 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
1501 @
$target[$T_TYPE]=$opt_target_type;
1502 push @exe_list,$target;
1503 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
1505 my $basename=$target_name;
1506 $basename=~ s/\.(dll|exe)$//i;
1507 # This is the default link list of Visual Studio
1508 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1509 my @std_libraries=qw(uuid);
1510 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1511 @
$target[$T_DLLS]=\
@std_imports;
1512 @
$target[$T_LIBRARIES]=\
@std_libraries;
1514 @
$target[$T_DLLS]=[];
1515 @
$target[$T_LIBRARIES]=[];
1517 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1518 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
1519 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1520 push @
{@
$target[$T_LDFLAGS]},"-m$opt_arch";
1523 push @
{@
$project[$P_TARGETS]},$target;
1525 # Ask for target-specific options
1526 if ($opt_ask_target_options == $OPT_ASK_YES) {
1528 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
1531 if ($flag_desc ne "") {
1534 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1535 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1537 my $options=<STDIN
>;
1539 if ($options eq "never") {
1540 $opt_ask_target_options=$OPT_ASK_NO;
1542 } elsif (source_set_options
($target,$options)) {
1545 print "Please re-enter the options:\n";
1548 if (@
$target[$T_FLAGS] & $TF_MFC) {
1549 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1550 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1551 push @
{@
$target[$T_DLLS]},"mfc.dll";
1552 # FIXME: Link with the MFC in the Unix sense, until we
1553 # start exporting the functions properly.
1554 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1555 push @
{@
$target[$T_LIBRARIES]},"mfc";
1559 if ($target_count == 1) {
1560 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
1561 @
$project_settings[$T_SOURCES_C]=[];
1564 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1565 @
$project_settings[$T_SOURCES_CXX]=[];
1568 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
1569 @
$project_settings[$T_SOURCES_RC]=[];
1572 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
1573 # No need for sorting these sources
1574 @
$project_settings[$T_SOURCES_MISC]=[];
1577 foreach my $source (@sources_c) {
1578 if ($source =~ /^$basename/i) {
1579 push @
{@
$target[$T_SOURCES_C]},$source;
1583 foreach my $source (@sources_cxx) {
1584 if ($source =~ /^$basename/i) {
1585 push @
{@
$target[$T_SOURCES_CXX]},$source;
1589 foreach my $source (@sources_rc) {
1590 if ($source =~ /^$basename/i) {
1591 push @
{@
$target[$T_SOURCES_RC]},$source;
1595 foreach my $source (@sources_misc) {
1596 if ($source =~ /^$basename/i) {
1597 push @
{@
$target[$T_SOURCES_MISC]},$source;
1602 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
1603 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
1604 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
1605 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
1607 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1608 $opt_ask_target_options=$OPT_ASK_YES;
1611 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1612 push @
{@
$project_settings[$T_CEXTRA]},"-mno-cygwin";
1613 push @
{@
$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1614 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1615 push @
{@
$project_settings[$T_CEXTRA]},"-m$opt_arch";
1616 push @
{@
$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1620 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
1621 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1623 # The sources that did not match, if any, go to the extra
1624 # source list of the project settings
1625 foreach my $source (@sources_c) {
1626 if ($source ne "") {
1627 push @
{@
$project_settings[$T_SOURCES_C]},$source;
1630 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
1631 foreach my $source (@sources_cxx) {
1632 if ($source ne "") {
1633 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
1636 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
1637 foreach my $source (@sources_rc) {
1638 if ($source ne "") {
1639 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
1642 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
1643 foreach my $source (@sources_misc) {
1644 if ($source ne "") {
1645 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
1648 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
1650 # Finally if we are building both libraries and programs in
1651 # this directory, then the programs should be linked with all
1653 if (@local_dlls > 0 and @exe_list > 0) {
1654 foreach my $target (@exe_list) {
1655 push @
{@
$target[$T_DLL_PATH]},"-L.";
1656 push @
{@
$target[$T_DLLS]},@local_dlls;
1662 # Scan the source directories in search of things to build
1665 # If there's a single target then this is going to be the default target
1666 if (defined $opt_single_target) {
1667 # Create the main target
1669 target_init
($main_target);
1670 @
$main_target[$T_NAME]=$opt_single_target;
1671 @
$main_target[$T_TYPE]=$opt_target_type;
1673 # Add it to the list
1674 push @
{$main_project[$P_TARGETS]},$main_target;
1677 # The main directory is always going to be there
1678 push @projects,\
@main_project;
1680 if (defined $opt_work_dir) {
1681 # Now scan the directory tree looking for source files and, maybe, targets
1682 print "Scanning the source directories...\n";
1683 source_scan_directory
(\
@main_project,"","",0);
1684 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
1685 } elsif (defined $opt_work_file) {
1686 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1687 source_scan_project_file
(\
@main_project,0,$opt_work_file);
1688 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1689 source_scan_workspace_file
($opt_work_file);
1701 # Performs a directory traversal and renames the files so that:
1702 # - they have the case desired by the user
1703 # - their extension is of the appropriate case
1704 # - they don't contain annoying characters like ' ', '$', '#', ...
1705 # But only perform these changes for source files and directories.
1706 sub fix_file_and_directory_names
($);
1707 sub fix_file_and_directory_names
($)
1711 my $directory=get_directory_contents
($dirname);
1712 foreach my $dentry (@
$directory)
1714 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1717 # Set $warn to 1 if the user should be warned of the renaming
1719 my $new_name=$dentry;
1721 if (-f
"$dirname/$dentry")
1723 # Don't rename Winemaker's makefiles
1724 next if ($dentry eq "Makefile" and
1725 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker
/);
1727 # Leave non-source files alone
1728 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc))$/i);
1730 # Only all lowercase extensions are supported (because of
1731 # rules like '.c.o:'.
1732 $new_name =~ s/\.C$/.c/;
1733 $new_name =~ s/\.cpp$/.cpp/i;
1734 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1735 $new_name =~ s/\.rc$/.rc/i;
1736 # And this last one is to avoid confusion then running make
1737 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1740 # Adjust the case to the user's preferences
1741 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1742 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1744 $new_name=lc $new_name;
1747 # autoconf and make don't support these characters well
1748 $new_name =~ s/[ \$]/_/g;
1750 # And finally, perform the renaming
1751 if ($new_name ne $dentry)
1754 print STDERR
"warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1756 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1757 print STDERR
"error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1758 print STDERR
" $!\n";
1763 clear_directory_cache
($dirname);
1766 if (-d
"$dirname/$new_name") {
1767 fix_file_and_directory_names
("$dirname/$new_name");
1781 # Try to find a file for the specified filename. The attempt is
1782 # case-insensitive which is why it's not trivial. If a match is
1783 # found then we return the pathname with the correct case.
1790 if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
1792 } elsif ($dirname !~ m
+^/+) {
1793 $dirname=cwd
. "/" . $dirname;
1795 if ($dirname !~ m
+/$+) {
1799 foreach my $component (@
$path) {
1800 $component=~s/^\"//;
1801 $component=~s/\"$//;
1802 #print " looking for $component in \"$dirname\"\n";
1803 if ($component eq ".") {
1806 } elsif ($component eq "..") {
1808 $dirname=dirname
($dirname) . "/";
1811 # The file/directory may have been renamed before. Also try to
1812 # match the renamed file.
1813 my $renamed=$component;
1814 $renamed =~ s/[ \$]/_/g;
1815 if ($renamed eq $component) {
1819 my $directory=get_directory_contents
$dirname;
1821 foreach my $dentry (@
$directory) {
1822 if ($dentry =~ /^\Q$component\E$/i or
1823 (defined $renamed and $dentry =~ /^$renamed$/i)
1825 $dirname.="$dentry/";
1826 $real_path.="$dentry/";
1831 if (!defined $found) {
1833 #print " could not find $component in $dirname\n";
1838 $real_path=~ s
+/$++;
1839 #print " -> found $real_path\n";
1844 # Performs a case-insensitive search for the specified file in the
1846 # $line is the line number that should be referenced when an error occurs
1847 # $filename is the file we are looking for
1848 # $dirname is the directory of the file containing the '#include' directive
1849 # if '"' was used, it is an empty string otherwise
1850 # $project and $target specify part of the include path
1851 sub get_real_include_name
($$$$$)
1859 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a
-zA
-Z
]:[\
/]?/) {
1860 # This is not a relative path, we cannot make any check
1861 my $warning="path:$filename";
1862 if (!defined $warnings{$warning}) {
1863 $warnings{$warning}="1";
1864 print STDERR
"warning: cannot check the case of absolute pathnames:\n";
1865 print STDERR
"$line: $filename\n";
1868 # Here's how we proceed:
1869 # - split the filename we look for into its components
1870 # - then for each directory in the include path
1871 # - trace the directory components starting from that directory
1872 # - if we fail to find a match at any point then continue with
1873 # the next directory in the include path
1874 # - otherwise, rejoice, our quest is over.
1875 my @file_components=split /[\/\\]+/, $filename;
1876 #print " Searching for $filename from @$project[$P_PATH]\n";
1879 if ($dirname ne "") {
1880 # This is an 'include ""' -> look in dirname first.
1881 #print " in $dirname (include \"\")\n";
1882 $real_filename=search_from
($dirname,\
@file_components);
1883 if (defined $real_filename) {
1884 return $real_filename;
1887 my $project_settings=@
$project[$P_SETTINGS];
1888 foreach my $include (@
{@
$target[$T_INCLUDE_PATH]}, @
{@
$project_settings[$T_INCLUDE_PATH]}) {
1889 my $dirname=$include;
1892 if (!is_absolute
($dirname)) {
1893 $dirname="@$project[$P_PATH]$dirname";
1895 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)/++;
1896 $dirname=~ s
+^\
$\
(SRCDIR\
)/+@
$project[$P_PATH]+;
1898 #print " in $dirname\n";
1899 $real_filename=search_from
("$dirname",\
@file_components);
1900 if (defined $real_filename) {
1901 return $real_filename;
1904 my $dotdotpath=@
$project[$P_PATH];
1905 $dotdotpath =~ s/[^\/]+/../g
;
1906 foreach my $include (@
{$global_settings[$T_INCLUDE_PATH]}) {
1907 my $dirname=$include;
1909 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)\
/++;
1910 $dirname=~ s
+^\
$\
(SRCDIR\
)\
/+@
$project[$P_PATH]+;
1911 #print " in $dirname (global setting)\n";
1912 $real_filename=search_from
("$dirname",\
@file_components);
1913 if (defined $real_filename) {
1914 return $real_filename;
1918 $filename =~ s
+\\\\+/+g
; # in include ""
1919 $filename =~ s
+\\+/+g
; # in include <> !
1920 if ($opt_lower_include) {
1921 return lc "$filename";
1932 if ($size =~ /^(1|2|4|8)$/) {
1933 print FILEO
"$indent#include <pshpack$size.h>$trailer";
1935 print FILEO
"$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1936 print FILEO
"$indent#include <pshpack4.h>$trailer";
1941 # 'Parses' a source file and fixes constructs that would not work with
1942 # Winelib. The parsing is rather simple and not all non-portable features
1943 # are corrected. The most important feature that is corrected is the case
1944 # and path separator of '#include' directives. This requires that each
1945 # source file be associated to a project & target so that the proper
1946 # include path is used.
1947 # Also note that the include path is relative to the directory in which the
1948 # compiler is run, i.e. that of the project, not to that of the file.
1954 $filename="@$project[$P_PATH]$filename";
1955 if (! -e
$filename) {
1959 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1960 my $dirname=dirname
($filename);
1962 if (defined $target and (@
$target[$T_FLAGS] & $TF_MFC)) {
1966 print " $filename\n";
1967 #FIXME:assuming that because there is a .bak file, this is what we want is
1968 #probably flawed. Or is it???
1969 if (! -e
"$filename.bak") {
1970 if (!copy
("$filename","$filename.bak")) {
1971 print STDERR
"error: unable to make a backup of $filename:\n";
1972 print STDERR
" $!\n";
1976 if (!open(FILEI
,"$filename.bak")) {
1977 print STDERR
"error: unable to open $filename.bak for reading:\n";
1978 print STDERR
" $!\n";
1981 if (!open(FILEO
,">$filename")) {
1982 print STDERR
"error: unable to open $filename for writing:\n";
1983 print STDERR
" $!\n";
1988 my $rc_block_depth=0;
1989 my $rc_textinclude_state=0;
1992 # Remove any trailing CtrlZ, which isn't strictly in the file
2000 # Make sure all files are '\n' terminated
2003 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
2004 # VC6 automatically includes 'afxres.h', an MFC specific header, in
2005 # the RC files it generates (even in non-MFC projects). So we replace
2006 # it with 'winresrc.h' its very close standard cousin so that non MFC
2007 # projects can compile in Wine without the MFC sources.
2008 my $warning="mfc:afxres.h";
2009 if (!defined $warnings{$warning}) {
2010 $warnings{$warning}="1";
2011 print STDERR
"warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
2012 print STDERR
"warning: the above warning is issued only once\n";
2014 print FILEO
"$1/* winemaker: $2\"afxres.h\" */\n";
2015 print FILEO
"$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
2016 print FILEO
"$1$2\"winresrc.h\"$'";
2019 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
2020 my $from_file=($2 eq "<"?
"":$dirname);
2021 my $real_include_name=get_real_include_name
($line,$3,$from_file,$project,$target);
2022 print FILEO
"$1$2$real_include_name$4$'";
2023 $modified|=($real_include_name ne $3);
2025 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
2026 # Pragma pack handling
2028 # pack_stack is an array of references describing the stack of
2029 # pack directives currently in effect. Each directive if described
2030 # by a reference to an array containing:
2031 # - "push" for pack(push,...) directives, "" otherwise
2032 # - the directive's identifier at index 1
2033 # - the directive's alignment value at index 2
2035 # Don't believe a word of what the documentation says: it's all wrong.
2036 # The code below is based on the actual behavior of Visual C/C++ 6.
2041 # Pushes the default stack alignment
2042 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
2043 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2044 print_pack
($pack_indent,4,$');
2045 push @pack_stack, [ "", "", 4 ];
2047 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
2049 # pragma pack(pop,n)
2050 # Goes up the stack until it finds a pack(push,...), and pops it
2051 # Ignores any pack(n) entry
2052 # Issues a warning if the pack is of the form pack(push,label)
2053 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2054 my $pack_comment=$';
2055 $pack_comment =~ s/^\s*//;
2056 if ($pack_comment ne "") {
2057 print FILEO
"$pack_indent$pack_comment";
2060 my $alignment=pop @pack_stack;
2061 if (!defined $alignment) {
2062 print FILEO
"$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2065 if (@
$alignment[1]) {
2066 print FILEO
"$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2068 print FILEO
"$pack_indent#include <poppack.h>\n";
2069 if (@
$alignment[0]) {
2074 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2075 # pragma pack(pop,label[,n])
2076 # Goes up the stack until finding a pack(push,...) and pops it.
2077 # 'n', if specified, is ignored.
2078 # Ignores any pack(n) entry
2079 # Issues a warning if the label of the pack does not match,
2080 # or if it is in fact a pack(push,n)
2082 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
2083 my $pack_comment=$';
2084 $pack_comment =~ s/^\s*//;
2085 if ($pack_comment ne "") {
2086 print FILEO "$pack_indent$pack_comment";
2089 my $alignment=pop @pack_stack;
2090 if (!defined $alignment) {
2091 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2094 if (@$alignment[1] and @$alignment[1] ne $label) {
2095 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2097 print FILEO "$pack_indent#include <poppack.h>\n";
2098 if (@$alignment[0]) {
2103 } elsif (/^(push\s*\))/) {
2105 # Push the current alignment
2106 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2107 if (@pack_stack > 0) {
2108 my $alignment=$pack_stack[$#pack_stack];
2109 print_pack($pack_indent,@$alignment[2],$');
2110 push @pack_stack, [ "push", "", @
$alignment[2] ];
2112 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2113 print_pack
($pack_indent,4,$');
2114 push @pack_stack, [ "push", "", 4 ];
2117 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2118 # pragma pack([push,]n)
2119 # Push new alignment n
2120 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2121 print_pack($pack_indent,$3,"$'");
2122 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2124 } elsif (/^((\w+)\s*\))/) {
2125 # pragma pack(label)
2126 # label must in fact be a macro that resolves to an integer
2127 # Then behaves like 'pragma pack(n)'
2128 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2129 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2130 print_pack($pack_indent,4,$');
2131 push @pack_stack, [ "", "", 4 ];
2133 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2134 # pragma pack(push,label[,n])
2135 # Pushes a new label on the stack. It is possible to push the same
2136 # label multiple times. If 'n' is omitted then the alignment is
2137 # unchanged. Otherwise it becomes 'n'.
2138 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2142 } elsif (@pack_stack > 0) {
2143 my $alignment=$pack_stack[$#pack_stack];
2144 $size=@$alignment[2];
2146 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2149 print_pack($pack_indent,$size,$');
2150 push @pack_stack, [ "push", $2, $size ];
2153 # pragma pack(??? -> What's that?
2154 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2155 print FILEO "$pack_indent$pack_header$_";
2161 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]+)([\">]?)/) {
2162 my $from_file=($5 eq "<"?"":$dirname);
2163 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2164 print FILEO "$1$5$real_include_name$7$'";
2165 $modified|=($real_include_name ne $6);
2167 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2168 my $from_file=($2 eq "<"?"":$dirname);
2169 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2170 print FILEO "$1$2$real_include_name$4$'";
2171 $modified|=($real_include_name ne $3);
2173 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2174 $rc_textinclude_state=1;
2177 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2178 print FILEO "$1winresrc.h
$2$'";
2181 } elsif (/^\s*BEGIN(\W.*)?$/) {
2182 $rc_textinclude_state|=2;
2186 } elsif (/^\s*END(\W.*)?$/) {
2187 $rc_textinclude_state=0;
2188 if ($rc_block_depth>0) {
2204 if ($opt_backup == 0 or $modified == 0) {
2205 if (!unlink("$filename.bak")) {
2206 print STDERR "error: unable to delete $filename.bak:\n";
2207 print STDERR " $!\n";
2213 # Analyzes each source file in turn to find and correct issues
2214 # that would cause it not to compile.
2217 print "Fixing the source files...\n";
2218 foreach my $project (@projects) {
2219 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2220 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2221 fix_file($source,$project,$target);
2236 # A convenience function to generate all the lists (defines,
2237 # C sources, C++ source, etc.) in the Makefile
2238 sub generate_list($$$;$)
2247 printf FILEO "%-22s=",$name;
2249 if (defined $list) {
2250 foreach my $item (@$list) {
2252 if (defined $data) {
2253 $value=&$data($item);
2259 print FILEO " $value";
2262 print FILEO " \\\n\t\t\t$value";
2273 # Generates a project's Makefile
and all the target files
2274 sub generate_project_files
($)
2277 my $project_settings=@
$project[$P_SETTINGS];
2281 # Then sort the targets and separate the libraries from the programs
2282 foreach my $target (sort { @
$a[$T_NAME] cmp @
$b[$T_NAME] } @
{@
$project[$P_TARGETS]}) {
2283 if (@
$target[$T_TYPE] == $TT_DLL) {
2284 push @dll_list,$target;
2286 push @exe_list,$target;
2289 @
$project[$P_TARGETS]=[];
2290 push @
{@
$project[$P_TARGETS]}, @dll_list;
2291 push @
{@
$project[$P_TARGETS]}, @exe_list;
2293 if (!open(FILEO
,">@$project[$P_PATH]Makefile")) {
2294 print STDERR
"error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2295 print STDERR
" $!\n";
2299 print FILEO
"### Generated by Winemaker $version\n";
2302 generate_list
("SRCDIR",1,[ "." ]);
2303 if (@
$project[$P_PATH] eq "") {
2304 # This is the main project. It is also responsible for recursively
2305 # calling the other projects
2306 generate_list
("SUBDIRS",1,\
@projects,sub
2308 if ($_[0] != \
@main_project) {
2309 my $subdir=@
{$_[0]}[$P_PATH];
2313 # Eliminating the main project by returning undefined!
2316 if (@
{@
$project[$P_TARGETS]} > 0) {
2317 generate_list
("DLLS",1,\
@dll_list,sub
2319 return @
{$_[0]}[$T_NAME];
2321 generate_list
("EXES",1,\
@exe_list,sub
2323 return "@{$_[0]}[$T_NAME]";
2325 print FILEO
"\n\n\n";
2327 print FILEO
"### Common settings\n\n";
2328 # Make it so that the project-wide settings override the global settings
2329 generate_list
("CEXTRA",1,@
$project_settings[$T_CEXTRA]);
2330 generate_list
("CXXEXTRA",1,@
$project_settings[$T_CXXEXTRA]);
2331 generate_list
("RCEXTRA",1,@
$project_settings[$T_RCEXTRA]);
2332 generate_list
("DEFINES",1,@
$project_settings[$T_DEFINES]);
2333 generate_list
("INCLUDE_PATH",1,@
$project_settings[$T_INCLUDE_PATH]);
2334 generate_list
("DLL_PATH",1,@
$project_settings[$T_DLL_PATH]);
2335 generate_list
("DLL_IMPORTS",1,@
$project_settings[$T_DLLS]);
2336 generate_list
("LIBRARY_PATH",1,@
$project_settings[$T_LIBRARY_PATH]);
2337 generate_list
("LIBRARIES",1,@
$project_settings[$T_LIBRARIES]);
2340 my $extra_source_count=@
{@
$project_settings[$T_SOURCES_C]}+
2341 @
{@
$project_settings[$T_SOURCES_CXX]}+
2342 @
{@
$project_settings[$T_SOURCES_RC]};
2343 my $no_extra=($extra_source_count == 0);
2345 print FILEO
"### Extra source lists\n\n";
2346 generate_list
("EXTRA_C_SRCS",1,@
$project_settings[$T_SOURCES_C]);
2347 generate_list
("EXTRA_CXX_SRCS",1,@
$project_settings[$T_SOURCES_CXX]);
2348 generate_list
("EXTRA_RC_SRCS",1,@
$project_settings[$T_SOURCES_RC]);
2350 generate_list
("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
2351 print FILEO
"\n\n\n";
2354 # Iterate over all the targets...
2355 foreach my $target (@
{@
$project[$P_TARGETS]}) {
2356 print FILEO
"### @$target[$T_NAME] sources and settings\n\n";
2357 my $canon=canonize
("@$target[$T_NAME]");
2360 generate_list
("${canon}_MODULE",1,[@
$target[$T_NAME]]);
2361 generate_list
("${canon}_C_SRCS",1,@
$target[$T_SOURCES_C]);
2362 generate_list
("${canon}_CXX_SRCS",1,@
$target[$T_SOURCES_CXX]);
2363 generate_list
("${canon}_RC_SRCS",1,@
$target[$T_SOURCES_RC]);
2364 generate_list
("${canon}_LDFLAGS",1,@
$target[$T_LDFLAGS]);
2365 generate_list
("${canon}_DLL_PATH",1,@
$target[$T_DLL_PATH]);
2366 generate_list
("${canon}_DLLS",1,@
$target[$T_DLLS]);
2367 generate_list
("${canon}_LIBRARY_PATH",1,@
$target[$T_LIBRARY_PATH]);
2368 generate_list
("${canon}_LIBRARIES",1,@
$target[$T_LIBRARIES]);
2370 generate_list
("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2371 print FILEO
"\n\n\n";
2373 print FILEO
"### Global source lists\n\n";
2374 generate_list
("C_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2376 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2378 return "\$(${canon}_C_SRCS)";
2381 generate_list
("",1,[ "\$(EXTRA_C_SRCS)" ]);
2383 generate_list
("CXX_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2385 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2387 return "\$(${canon}_CXX_SRCS)";
2390 generate_list
("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2392 generate_list
("RC_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2394 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2396 return "\$(${canon}_RC_SRCS)";
2399 generate_list
("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2403 print FILEO
"### Tools\n\n";
2404 print FILEO
"CC = winegcc\n";
2405 print FILEO
"CXX = wineg++\n";
2406 print FILEO
"RC = wrc\n";
2409 print FILEO
"### Generic targets\n\n";
2411 if (@
$project[$P_PATH] eq "") {
2412 print FILEO
" \$(SUBDIRS)";
2414 if (@
{@
$project[$P_TARGETS]} > 0) {
2415 print FILEO
" \$(DLLS:%=%.so) \$(EXES:%=%.so)";
2418 print FILEO
"### Build rules\n";
2420 print FILEO
".PHONY: all clean dummy\n";
2422 print FILEO
"\$(SUBDIRS): dummy\n";
2423 print FILEO
"\t\@cd \$\@ && \$(MAKE)\n";
2425 print FILEO
"# Implicit rules\n";
2427 print FILEO
".SUFFIXES: .cpp .rc .res\n";
2428 print FILEO
"DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2430 print FILEO
".c.o:\n";
2431 print FILEO
"\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2433 print FILEO
".cpp.o:\n";
2434 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2436 print FILEO
".cxx.o:\n";
2437 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2439 print FILEO
".rc.res:\n";
2440 print FILEO
"\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2442 print FILEO
"# Rules for cleaning\n";
2444 print FILEO
"CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2445 print FILEO
" \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2447 print FILEO
"clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2448 print FILEO
"\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:.cpp=.o)\n";
2449 print FILEO
"\t\$(RM) \$(DLLS:%=%.so) \$(EXES:%=%.so) \$(EXES:%.exe=%)\n";
2451 print FILEO
"\$(SUBDIRS:%=%/__clean__): dummy\n";
2452 print FILEO
"\tcd `dirname \$\@` && \$(MAKE) clean\n";
2454 print FILEO
"\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2455 print FILEO
"\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2458 if (@
{@
$project[$P_TARGETS]} > 0) {
2459 print FILEO
"### Target specific build rules\n";
2460 print FILEO
"DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2461 foreach my $target (@
{@
$project[$P_TARGETS]}) {
2462 my $canon=canonize
("@$target[$T_NAME]");
2465 print FILEO
"\$(${canon}_MODULE).so: \$(${canon}_OBJS)\n";
2466 if (@
{@
$target[$T_SOURCES_CXX]} > 0 or @
{@
$project_settings[$T_SOURCES_CXX]} > 0) {
2467 print FILEO
"\t\$(CXX)";
2469 print FILEO
"\t\$(CC)";
2471 print FILEO
" \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2481 # This is where we finally generate files. In fact this method does not
2482 # do anything itself but calls the methods that do the actual work.
2485 print "Generating project files...\n";
2487 foreach my $project (@projects) {
2488 my $path=@
$project[$P_PATH];
2495 generate_project_files
($project);
2508 $opt_lower=$OPT_LOWER_UPPERCASE;
2509 $opt_lower_include=1;
2511 $opt_work_dir=undef;
2512 $opt_single_target=undef;
2513 $opt_target_type=$TT_GUIEXE;
2515 $opt_arch=$OPT_ARCH_DEFAULT;
2516 $opt_is_interactive=$OPT_ASK_NO;
2517 $opt_ask_project_options=$OPT_ASK_NO;
2518 $opt_ask_target_options=$OPT_ASK_NO;
2519 $opt_no_generated_files=0;
2520 $opt_no_source_fix=0;
2533 print "Winemaker $version\n";
2534 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2535 print "Copyright 2004 Dimitrie O. Paun\n";
2536 print "Copyright 2009 André Hentschel\n";
2542 print STDERR
"Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2543 print STDERR
" [--lower-none|--lower-all|--lower-uppercase]\n";
2544 print STDERR
" [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2545 print STDERR
" [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2546 print STDERR
" [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2547 print STDERR
" [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2548 print STDERR
" [--generated-files|--nogenerated-files]\n";
2549 print STDERR
" [--wine32]\n";
2550 print STDERR
" work_directory|project_file|workspace_file\n";
2551 print STDERR
"\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2552 print STDERR
"the specified directory or project-file, so that they can be compiled with Winelib.\n";
2553 print STDERR
"During this process it will modify and rename some of the corresponding files.\n";
2554 print STDERR
"\tPlease read the manual page before use.\n";
2558 target_init
(\
@global_settings);
2561 my $arg=shift @ARGV;
2563 if ($arg eq "--nobanner") {
2565 } elsif ($arg eq "--backup") {
2567 } elsif ($arg eq "--nobackup") {
2569 } elsif ($arg eq "--single-target") {
2570 $opt_single_target=shift @ARGV;
2571 } elsif ($arg eq "--lower-none") {
2572 $opt_lower=$OPT_LOWER_NONE;
2573 } elsif ($arg eq "--lower-all") {
2574 $opt_lower=$OPT_LOWER_ALL;
2575 } elsif ($arg eq "--lower-uppercase") {
2576 $opt_lower=$OPT_LOWER_UPPERCASE;
2577 } elsif ($arg eq "--lower-include") {
2578 $opt_lower_include=1;
2579 } elsif ($arg eq "--nolower-include") {
2580 $opt_lower_include=0;
2581 } elsif ($arg eq "--nosource-fix") {
2582 $opt_no_source_fix=1;
2583 } elsif ($arg eq "--generated-files") {
2584 $opt_no_generated_files=0;
2585 } elsif ($arg eq "--nogenerated-files") {
2586 $opt_no_generated_files=1;
2587 } elsif ($arg eq "--wine32") {
2588 $opt_arch=$OPT_ARCH_32;
2589 } elsif ($arg =~ /^-D/) {
2590 push @
{$global_settings[$T_DEFINES]},$arg;
2591 } elsif ($arg =~ /^-I/) {
2592 push @
{$global_settings[$T_INCLUDE_PATH]},$arg;
2593 } elsif ($arg =~ /^-P/) {
2594 push @
{$global_settings[$T_DLL_PATH]},"-L$'";
2595 } elsif ($arg =~ /^-i/) {
2596 push @
{$global_settings[$T_DLLS]},$';
2597 } elsif ($arg =~ /^-L/) {
2598 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2599 } elsif ($arg =~ /^-l/) {
2600 push @{$global_settings[$T_LIBRARIES]},$';
2602 # 'Source'-based method options
2603 } elsif ($arg eq "--dll") {
2604 $opt_target_type=$TT_DLL;
2605 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2606 $opt_target_type=$TT_GUIEXE;
2607 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2608 $opt_target_type=$TT_CUIEXE;
2609 } elsif ($arg eq "--interactive") {
2610 $opt_is_interactive=$OPT_ASK_YES;
2611 $opt_ask_project_options=$OPT_ASK_YES;
2612 $opt_ask_target_options=$OPT_ASK_YES;
2613 } elsif ($arg eq "--mfc") {
2614 $opt_flags|=$TF_MFC;
2615 } elsif ($arg eq "--nomfc") {
2616 $opt_flags&=~$TF_MFC;
2617 $opt_flags|=$TF_NOMFC;
2618 } elsif ($arg eq "--nodlls") {
2619 $opt_flags|=$TF_NODLLS;
2620 } elsif ($arg eq "--nomsvcrt") {
2621 $opt_flags|=$TF_NOMSVCRT;
2625 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2626 if (!defined $opt_work_dir and !defined $opt_work_file) {
2628 $opt_work_file=$arg;
2634 print STDERR
"error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2643 if (!defined $opt_work_dir and !defined $opt_work_file) {
2644 print STDERR
"error: you must specify the directory or project file containing the sources to be converted\n";
2646 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2647 print STDERR
"error: could not chdir to the work directory\n";
2648 print STDERR
" $!\n";
2652 if ($opt_no_banner == 0) {
2656 project_init
(\
@main_project, "", \
@global_settings);
2658 # Fix the file and directory names
2659 fix_file_and_directory_names
(".");
2661 # Scan the sources to identify the projects and targets
2664 # Fix the source files
2665 if (! $opt_no_source_fix) {
2669 # Generate the Makefile and the spec file
2670 if (! $opt_no_generated_files) {