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
81 # This is the directory in which winemaker will operate.
85 # This is the file in which winemaker will operate if a project file is specified.
89 # Make a backup of the files
93 # Defines which files to rename
97 # If we don't find the file referenced by an include, lower it
98 my $opt_lower_include;
101 # If true then winemaker should not attempt to fix the source. This is
102 # useful if the source is known to be already in a suitable form and is
104 my $opt_no_source_fix;
106 # Options for the 'Source' method
109 # Specifies that we have only one target so that all sources relate
110 # to this target. By default this variable is left undefined which
111 # means winemaker should try to find out by itself what the targets
112 # are. If not undefined then this contains the name of the default
113 # target (without the extension).
114 my $opt_single_target;
117 # If '$opt_single_target' has been specified then this is the type of
118 # that target. Otherwise it specifies whether the default target type
119 # is guiexe or cuiexe.
123 # Contains the default set of flags to be used when creating a new target.
127 # Contains 32 for 32-Bit-Targets and 64 for 64-Bit-Targets
131 # If true then winemaker should ask questions to the user as it goes
133 my $opt_is_interactive;
134 my $opt_ask_project_options;
135 my $opt_ask_target_options;
138 # If false then winemaker should not generate the makefiles.
139 my $opt_no_generated_files;
142 # Specifies not to print the banner if set.
149 # Target modelization
153 # The description of a target is stored in an array. The constants
154 # below identify what is stored at each index of the array.
157 # This is the name of the target.
161 # Defines the type of target we want to build. See the TT_xxx
166 # This is a bitfield containing flags refining the way the target
167 # should be handled. See the TF_xxx constants below
171 # This is a reference to an array containing the list of the
172 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
176 my $T_SOURCES_MISC=6;
179 # This is a reference to an array containing the list of
184 # This is a reference to an array containing the list of
185 # C++ compiler options
189 # This is a reference to an array containing the list of
190 # RC compiler options
194 # This is a reference to an array containing the list of macro
199 # This is a reference to an array containing the list of directory
200 # names that constitute the include path
201 my $T_INCLUDE_PATH=11;
204 # Flags for the linker
208 # Same as T_INCLUDE_PATH but for the dll search path
212 # The list of Windows dlls to import
216 # Same as T_INCLUDE_PATH but for the library search path
217 my $T_LIBRARY_PATH=15;
220 # The list of Unix libraries to link with
224 # The list of dependencies between targets
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 # leaving $T_INIT undefined
278 @
$target[$T_FLAGS]=$opt_flags;
279 @
$target[$T_SOURCES_C]=[];
280 @
$target[$T_SOURCES_CXX]=[];
281 @
$target[$T_SOURCES_RC]=[];
282 @
$target[$T_SOURCES_MISC]=[];
283 @
$target[$T_CEXTRA]=[];
284 @
$target[$T_CXXEXTRA]=[];
285 @
$target[$T_RCEXTRA]=[];
286 @
$target[$T_DEFINES]=[];
287 @
$target[$T_INCLUDE_PATH]=[];
288 @
$target[$T_LDFLAGS]=[];
289 @
$target[$T_DLL_PATH]=[];
290 @
$target[$T_DLLS]=[];
291 @
$target[$T_LIBRARY_PATH]=[];
292 @
$target[$T_LIBRARIES]=[];
299 # Project modelization
303 # First we have the notion of project. A project is described by an
304 # array (since we don't have structs in perl). The constants below
305 # identify what is stored at each index of the array.
308 # This is the path in which this project is located. In other
309 # words, this is the path to the Makefile.
313 # This index contains a reference to an array containing the project-wide
314 # settings. The structure of that arrray is actually identical to that of
315 # a regular target since it can also contain extra sources.
319 # This index contains a reference to an array of targets for this
320 # project. Each target describes how an executable or library is to
321 # be built. For each target this description takes the same form as
322 # that of the project: an array. So this entry is an array of arrays.
326 # Initialize a project:
327 # - set the project's path
328 # - initialize the target list
329 # - create a default target (will be removed later if unnecessary)
330 sub project_init
($$$)
332 my ($project, $path, $global_settings)=@_;
334 my $project_settings=[];
335 target_init
($project_settings);
336 @
$project_settings[$T_DEFINES]=[@
{@
$global_settings[$T_DEFINES]}];
337 @
$project_settings[$T_INCLUDE_PATH]=[@
{@
$global_settings[$T_INCLUDE_PATH]}];
338 @
$project_settings[$T_DLL_PATH]=[@
{@
$global_settings[$T_DLL_PATH]}];
339 @
$project_settings[$T_DLLS]=[@
{@
$global_settings[$T_DLLS]}];
340 @
$project_settings[$T_LIBRARY_PATH]=[@
{@
$global_settings[$T_LIBRARY_PATH]}];
341 @
$project_settings[$T_LIBRARIES]=[@
{@
$global_settings[$T_LIBRARIES]}];
343 @
$project[$P_PATH]=$path;
344 @
$project[$P_SETTINGS]=$project_settings;
345 @
$project[$P_TARGETS]=[];
361 # This maps a directory name to a reference to an array listing
362 # its contents (files and directories)
366 # Contains the list of all projects. This list tells us what are
367 # the subprojects of the main Makefile and where we have to generate
372 # This is the main project, i.e. the one in the "." directory.
373 # It may well be empty in which case the main Makefile will only
374 # call out subprojects.
378 # Contains the defaults for the include path, etc.
379 # We store the defaults as if this were a target except that we only
380 # exploit the defines, include path, library path, library list and misc
393 # Cleans up a name to make it an acceptable Makefile
399 $name =~ tr/a-zA-Z0-9_/_/c;
404 # Returns true is the specified pathname is absolute.
405 # Note: pathnames that start with a variable '$' or
406 # '~' are considered absolute.
411 return ($path =~ /^[\/~\
$]/);
415 # Retrieves the contents of the specified directory.
416 # We either get it from the directories hashtable which acts as a
417 # cache, or use opendir, readdir, closedir and store the result
419 sub get_directory_contents
($)
424 #print "getting the contents of $dirname\n";
426 # check for a cached version
428 if ($dirname eq "") {
431 $directory=$directories{$dirname};
432 if (defined $directory) {
433 #print "->@$directory\n";
437 # Read this directory
438 if (opendir(DIRECTORY
, "$dirname")) {
439 my @files=readdir DIRECTORY
;
443 # Return an empty list
444 #print "error: cannot open $dirname\n";
448 #print "->@$directory\n";
449 $directories{$dirname}=$directory;
454 # Removes a directory from the cache.
455 # This is needed if one of its files or subdirectory has been renamed.
456 sub clear_directory_cache
($)
459 delete $directories{$dirname};
465 # 'Source'-based Project analysis
470 # Allows the user to specify makefile and target specific options
471 # - target: the structure in which to store the results
472 # - options: the string containing the options
473 sub source_set_options
($$)
478 #FIXME: we must deal with escaping of stuff and all
479 foreach my $option (split / /,$options) {
480 if (@
$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
481 push @
{@
$target[$T_DEFINES]},$option;
482 } elsif (@
$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
483 push @
{@
$target[$T_INCLUDE_PATH]},$option;
484 } elsif ($option =~ /^-P/) {
485 push @
{@
$target[$T_DLL_PATH]},"-L$'";
486 } elsif ($option =~ /^-i/) {
487 push @
{@
$target[$T_DLLS]},"$'";
488 } elsif ($option =~ /^-L/) {
489 push @
{@
$target[$T_LIBRARY_PATH]},$option;
490 } elsif ($option =~ /^-l/) {
491 push @
{@
$target[$T_LIBRARIES]},"$'";
492 } elsif ($option =~ /^--mfc/) {
493 @
$target[$T_FLAGS]|=$TF_MFC;
494 @
$target[$T_FLAGS]&=~$TF_NOMFC;
495 } elsif ($option =~ /^--nomfc/) {
496 @
$target[$T_FLAGS]&=~$TF_MFC;
497 @
$target[$T_FLAGS]|=$TF_NOMFC;
498 } elsif ($option =~ /^--nodlls/) {
499 @
$target[$T_FLAGS]|=$TF_NODLLS;
500 } elsif ($option =~ /^--nomsvcrt/) {
501 @
$target[$T_FLAGS]|=$TF_NOMSVCRT;
503 print STDERR
"error: unknown option \"$option\"\n";
511 # Scans the specified project file to:
512 # - get a list of targets for this project
513 # - get some settings
514 # - get the list of source files
515 sub source_scan_project_file
($$$);
516 sub source_scan_project_file
($$$)
518 # a reference to the parent's project
519 my $parent_project=$_[0];
520 # 0 if it is a single project, 1 if it is part of a workspace
521 my $is_sub_project=$_[1];
522 # the name of the project file, with complete path, or without if in
526 # reference to the project for this file. May not be used
528 # list of sources found in the current file
534 my $path=dirname
($filename);
535 my $prj_target_cflags;
536 my $prj_target_defines;
537 my $prj_target_ldflags;
542 my $prj_target_type=1;
543 my @prj_target_options;
545 if (!($path=~/\/$/)) {
549 if (defined $opt_single_target or $is_sub_project == 0) {
550 # Either there is a single target and thus a single project,
551 # or we are a single project-file for which a project
553 $project=$parent_project;
556 project_init
($project, $path, \
@global_settings);
558 my $project_settings=@
$project[$P_SETTINGS];
560 if ($filename =~ /.dsp$/i) {
561 # First find out what this project file contains:
562 # collect all sources, find targets and settings
563 if (!open(FILEI
,$filename)) {
564 print STDERR
"error: unable to open $filename for reading:\n";
565 print STDERR
" $!\n";
570 # Remove any trailing CtrlZ, which isn't strictly in the file
576 # Remove any trailing CrLf
579 # Make sure all lines are '\n' terminated
583 if (/^\# Microsoft Developer Studio Project File - Name=\"([^\"]+)/) {
587 } elsif (/^# TARGTYPE/) {
588 if (/[[:space:]]0x0101$/) {
589 # Win32 (x86) Application
591 }elsif (/[[:space:]]0x0102$/) {
592 # Win32 (x86) Dynamic-Link Library
594 }elsif (/[[:space:]]0x0103$/) {
595 # Win32 (x86) Console Application
597 }elsif (/[[:space:]]0x0104$/) {
598 # Win32 (x86) Static Library
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 ";
627 } elsif (/^Z[d7iI]$/) {
629 $prj_target_cflags.="-g ";
631 # Disable Optimizations
632 $prj_target_cflags.="-O0 ";
635 $prj_target_cflags.="-Os ";
638 $prj_target_cflags.="-O2 ";
640 # Disables inline Expansion
641 $prj_target_cflags.="-fno-inline ";
643 #In-line Function Expansion
644 $prj_target_cflags.="-finline-functions ";
646 # auto In-line Function Expansion
647 $prj_target_cflags.="-finline-functions ";
649 # Use maximum optimization
650 $prj_target_cflags.="-O3 ";
652 # Frame-Pointer Omission
653 $prj_target_cflags.="-fomit-frame-pointer ";
655 # Frame-Pointer Omission
656 $prj_target_cflags.="-fno-omit-frame-pointer ";
658 # Catch Release-Build Errors in Debug Build
659 } elsif (/^M[DLT]d?$/) {
660 # Use Multithreaded Run-Time Library
661 } elsif (/^D\s*\"(.*)\"/) {
662 # Preprocessor Definitions
663 $prj_target_defines.="-D".$1." ";
664 } elsif (/^I\s*\"(.*)\"/) {
665 # Additional Include Directories
668 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I".$sfilet." ";
669 } elsif (/^U\s*\"(.*)\"/) {
670 # Undefines a previously defined symbol
671 $prj_target_cflags.="-U".$1." ";
677 # Automatic Use of Precompiled Headers
679 # Generate File Dependencies
681 # Compile Without Linking
682 # this option is always present and is already specified in the suffix rules
685 $prj_target_cflags.="-mcpu=pentiumpro -D_M_IX86=500 ";
687 # Pentium Pro Optimization
688 $prj_target_cflags.="-march=pentiumpro -D_M_IX86=600 ";
690 # Pentium Optimization
691 $prj_target_cflags.="-mcpu=pentium -D_M_IX86=500 ";
694 $prj_target_cflags.="-mcpu=i386 -D_M_IX86=300 ";
697 $prj_target_cflags.="-mcpu=i486 -D_M_IX86=400 ";
699 # Create Precompiled Header
701 # Use Precompiled Header
703 # Disable Language Extensions
704 $prj_target_cflags.="-ansi ";
706 # Enable Microsoft Extensions
707 } elsif (/^Zm[[:digit:]]+$/) {
708 # Specify Memory Allocation Limit
710 # Packs structures on 1-byte boundaries
711 $prj_target_cflags.="-fpack-struct ";
712 } elsif (/^Zp(2|4|8|16)$/) {
713 # Struct Member Alignment
714 $prj_target_cflags.="-fpack-struct=".$1;
716 print "C compiler option $_ not implemented\n";
720 #print "\nOptions: $prj_target_cflags\n";
722 } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
723 $prj_target_ldflags=$1;
724 @prj_target_options=split(" /", $prj_target_ldflags);
725 $prj_target_ldflags="";
726 $prj_target_libs=$prj_target_options[0];
727 $prj_target_libs=~s/\\/\//g
;
728 $prj_target_libs=~s/\.lib//g;
729 $prj_target_libs=~s/\s+/ -l/g;
730 shift (@prj_target_options);
731 foreach ( @prj_target_options ) {
734 } elsif (/^base:(.*)/) {
736 $prj_target_ldflags.="--image-base ".$1." ";
737 } elsif (/^debug$/) {
738 # Generate Debug Info
742 } elsif (/^incremental:[[:alpha:]]+$/) {
744 } elsif (/^implib:/) {
745 # Name import library
746 } elsif (/^libpath:\"(.*)\"/) {
748 push @
{@
$project_settings[$T_DLL_PATH]},"-L$1";
749 } elsif (/^machine:[[:alnum:]]+$/) {
750 # Specify Target Platform
754 $prj_target_ldflags.="-Map ".$1." ";
756 $prj_target_ldflags.="-Map ".$prj_name.".map ";
758 } elsif (/^nologo$/) {
759 # Suppress Startup Banner and Information Messages
762 # may use it as Target?
763 } elsif (/^pdbtype:/) {
764 # Program Database Storage
765 } elsif (/^subsystem:/) {
767 } elsif (/^version:[[:digit:].]+$/) {
768 # Version Information
770 print "Linker option $_ not implemented\n";
774 } elsif (/^LIB32=/ && $found_cfg==1) {
777 } elsif (/^SOURCE=(.*)$/) {
778 my @components=split /[\/\\]+/, $1;
779 $sfilet=search_from
($path, \
@components);
780 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
781 push @sources_c,$sfilet;
782 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
783 if ($sfilet =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
784 push @sources_misc,$sfilet;
785 @
$project_settings[$T_FLAGS]|=$TF_MFC;
787 push @sources_cxx,$sfilet;
789 } elsif ($sfilet =~ /\.rc$/i) {
790 push @sources_rc,$sfilet;
791 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
792 push @sources_misc,$sfilet;
793 if ($sfilet =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
794 @
$project_settings[$T_FLAGS]|=$TF_MFC;
799 } elsif (/^# (Begin|End) Source File/) {
800 # Source-Files already handled
802 } elsif (/^# (Begin|End) Group/) {
805 } elsif (/^# (Begin|End) Custom Build/) {
806 # Custom Builds are ignored
808 } elsif (/^# ADD LIB32 /) {
811 } elsif (/^# Begin Target$/) {
812 # Targets are ignored
814 } elsif (/^# End Target$/) {
815 # Targets are ignored
818 if ($found_cfg == 1) {
821 if (/if (.*)\(CFG\)" == "(.*)"/i) {
822 if ($2 eq $prj_cfg) {
827 } elsif (/^CFG=(.*)/i) {
831 else { # Line recognized
837 push @
{@
$project_settings[$T_LIBRARIES]},$prj_target_libs;
838 push @
{@
$project_settings[$T_CEXTRA]},$prj_target_cflags;
839 push @
{@
$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
840 push @
{@
$project_settings[$T_DEFINES]},$prj_target_defines;
841 push @
{@
$project_settings[$T_LDFLAGS]},$prj_target_ldflags;
842 } elsif ($filename =~ /.vcproj$/i) {
843 # Import XML::LibXML, you need the libxml package (deb: libxml-libxml-perl, rpm: perl-libxml-perl)
846 my $xmlparser = XML
::LibXML
->new();
847 my $project_xml = $xmlparser->parse_file($filename);
851 foreach my $vc_project ($project_xml->findnodes('/VisualStudioProject')) {
852 foreach my $vc_project_attr ($vc_project->attributes) {
853 if ($vc_project_attr->getName eq "Name") {
854 $prj_name=$vc_project_attr->getValue;
860 for (my $flevel = 0; $flevel <= 5; $flevel++) {
861 foreach my $vc_file ($project_xml->findnodes('/VisualStudioProject/Files/'.('Filter/' x
$flevel).'File')) {
862 foreach my $vc_file_attr ($vc_file->attributes) {
863 if ($vc_file_attr->getName eq "RelativePath") {
864 $sfilet = $vc_file_attr->getValue;
865 $sfilet=~s/\\\\/\\/g; #remove double backslash
866 $sfilet=~s/^\.\\//; #remove starting 'this directory'
867 $sfilet=~s/\\/\//g
; #make slashes out of backslashes
868 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
869 push @sources_c,$sfilet;
870 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
871 if ($sfilet =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
872 push @sources_misc,$sfilet;
873 @
$project_settings[$T_FLAGS]|=$TF_MFC;
875 push @sources_cxx,$sfilet;
877 } elsif ($sfilet =~ /\.rc$/i) {
878 push @sources_rc,$sfilet;
879 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
880 push @sources_misc,$sfilet;
881 if ($sfilet =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
882 @
$project_settings[$T_FLAGS]|=$TF_MFC;
890 my @vc_configurations = $project_xml->findnodes('/VisualStudioProject/Configurations/Configuration');
891 my $vc_configuration = $vc_configurations[0];
892 foreach my $vc_configuration_attr ($vc_configuration->attributes) {
893 if ($vc_configuration_attr->getName eq "ConfigurationType") {
894 if ($vc_configuration_attr->getValue==1) {
895 $prj_target_type=1; # Win32 (x86) Application
896 } elsif ($vc_configuration_attr->getValue==2) {
897 $prj_target_type=3; # Win32 (x86) Dynamic-Link Library
902 foreach my $vc_configuration_tools ($vc_configuration->findnodes('Tool')) {
903 my @find_tool = $vc_configuration_tools->attributes;
904 if ($find_tool[0]->getValue eq "VCCLCompilerTool") {
905 foreach my $vc_compiler_tool ($vc_configuration_tools->attributes) {
906 if ($vc_compiler_tool->getName eq "Optimization") {$prj_target_cflags.="-O".$vc_compiler_tool->getValue." ";}
907 if ($vc_compiler_tool->getName eq "WarningLevel") {
908 if ($vc_compiler_tool->getValue==0) {
909 $prj_target_cflags.="-w ";
910 } elsif ($vc_compiler_tool->getValue<4) {
911 $prj_target_cflags.="-W ";
912 } elsif ($vc_compiler_tool->getValue==4) {
913 $prj_target_cflags.="-Wall ";
914 } elsif ($vc_compiler_tool->getValue eq "X") {
915 $prj_target_cflags.="-Werror ";
918 if ($vc_compiler_tool->getName eq "PreprocessorDefinitions") {
919 $configt=$vc_compiler_tool->getValue;
921 $prj_target_defines.="-D".$configt." ";
923 if ($vc_compiler_tool->getName eq "AdditionalIncludeDirectories") {
924 $configt=$vc_compiler_tool->getValue;
927 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I".$configt;
931 if ($find_tool[0]->getValue eq "VCLinkerTool") {
932 foreach my $vc_linker_tool ($vc_configuration_tools->attributes) {
933 if ($vc_linker_tool->getName eq "AdditionalDependencies") {
934 $prj_target_libs=" ".$vc_linker_tool->getValue;
935 $prj_target_libs=~s/\\/\//g
;
936 $prj_target_libs=~s/\.lib//g;
937 $prj_target_libs=~s/\s+/ -l/g;
943 push @
{@
$project_settings[$T_LIBRARIES]},$prj_target_libs;
944 push @
{@
$project_settings[$T_CEXTRA]},$prj_target_cflags;
945 push @
{@
$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
946 push @
{@
$project_settings[$T_DEFINES]},$prj_target_defines;
949 # Add this project to the project list, except for
950 # the main project which is already in the list.
951 if ($is_sub_project == 1) {
952 push @projects,$project;
955 # Ask for project-wide options
956 if ($opt_ask_project_options == $OPT_ASK_YES) {
958 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
961 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
962 if (defined $flag_desc) {
963 print "* (currently $flag_desc)\n";
965 print "* or 'skip' to skip the target specific options,\n";
966 print "* or 'never' to not be asked this question again:\n";
970 if ($options eq "skip") {
971 $opt_ask_target_options=$OPT_ASK_SKIP;
973 } elsif ($options eq "never") {
974 $opt_ask_project_options=$OPT_ASK_NO;
976 } elsif (source_set_options
($project_settings,$options)) {
979 print "Please re-enter the options:\n";
984 my @local_depends=();
987 # Create the target...
989 target_init
($target);
991 if ($prj_target_type!=3) {
992 $prj_name=lc($prj_name.".exe");
993 @
$target[$T_TYPE]=$opt_target_type;
994 push @exe_list,$target;
995 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
997 $prj_name=lc($prj_name.".dll");
998 @
$target[$T_TYPE]=$TT_DLL;
999 push @local_depends,"$prj_name.so";
1000 push @local_dlls,$prj_name;
1001 my $canon=canonize
($prj_name);
1002 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
1005 @
$target[$T_NAME]=$prj_name;
1006 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
1008 # This is the default link list of Visual Studio
1009 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1010 my @std_libraries=qw(uuid);
1011 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1012 @
$target[$T_DLLS]=\
@std_imports;
1013 @
$target[$T_LIBRARIES]=\
@std_libraries;
1015 @
$target[$T_DLLS]=[];
1016 @
$target[$T_LIBRARIES]=[];
1018 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1019 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
1020 push @
{@
$target[$T_LDFLAGS]},"-m$opt_arch";
1022 push @
{@
$project[$P_TARGETS]},$target;
1024 # Ask for target-specific options
1025 if ($opt_ask_target_options == $OPT_ASK_YES) {
1027 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
1030 if ($flag_desc ne "") {
1033 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1034 print "* \"$prj_name\"$flag_desc or 'never' to not be asked this question again:\n";
1036 my $options=<STDIN
>;
1038 if ($options eq "never") {
1039 $opt_ask_target_options=$OPT_ASK_NO;
1041 } elsif (source_set_options
($target,$options)) {
1044 print "Please re-enter the options:\n";
1047 if (@
$target[$T_FLAGS] & $TF_MFC) {
1048 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1049 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1050 push @
{@
$target[$T_DLLS]},"mfc.dll";
1051 # FIXME: Link with the MFC in the Unix sense, until we
1052 # start exporting the functions properly.
1053 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1054 push @
{@
$target[$T_LIBRARIES]},"mfc";
1058 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
1059 @
$project_settings[$T_SOURCES_C]=[];
1061 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1062 @
$project_settings[$T_SOURCES_CXX]=[];
1064 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
1065 @
$project_settings[$T_SOURCES_RC]=[];
1067 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
1068 @
$project_settings[$T_SOURCES_MISC]=[];
1071 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
1072 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
1073 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
1074 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
1076 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1077 $opt_ask_target_options=$OPT_ASK_YES;
1080 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1081 push @
{@
$project_settings[$T_CEXTRA]},"-mno-cygwin";
1082 push @
{@
$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1085 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
1086 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1088 # The sources that did not match, if any, go to the extra
1089 # source list of the project settings
1090 foreach my $source (@sources_c) {
1091 if ($source ne "") {
1092 push @
{@
$project_settings[$T_SOURCES_C]},$source;
1095 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
1096 foreach my $source (@sources_cxx) {
1097 if ($source ne "") {
1098 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
1101 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
1102 foreach my $source (@sources_rc) {
1103 if ($source ne "") {
1104 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
1107 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
1108 foreach my $source (@sources_misc) {
1109 if ($source ne "") {
1110 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
1113 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
1117 # Scans the specified workspace file to find the project files
1118 sub source_scan_workspace_file
($);
1119 sub source_scan_workspace_file
($)
1122 my $path=dirname
($filename);
1125 if (! -e
$filename) {
1129 if (!open(FILEIWS
,$filename)) {
1130 print STDERR
"error: unable to open $filename for reading:\n";
1131 print STDERR
" $!\n";
1138 if ($filename =~ /.dsw$/i) {
1140 # Remove any trailing CrLf
1143 # catch a project definition
1144 if (/^Project:\s\"(.*)\"=(.*)\s-/) {
1147 @components=split /[\/\\]+/, $prj_path;
1148 $prj_path=search_from
($path, \
@components);
1149 print "Name: $prj_name\nPath: $prj_path\n";
1150 source_scan_project_file
(\
@main_project,1,$prj_path);
1155 print STDERR
"unknown section $_\n";
1156 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1157 print "\nFileversion: $3\n";
1161 } elsif ($filename =~ /.sln$/i) {
1163 # Remove any trailing CrLf
1166 # catch a project definition
1167 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1170 @components=split /[\/\\]+/, $3;
1171 $prj_path=search_from
($path, \
@components);
1172 print "Name: $prj_name\nPath: $prj_path\n";
1173 source_scan_project_file
(\
@main_project,1,$prj_path);
1175 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1176 print "\nFileversion: $3\n";
1182 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
1186 # Scans the specified directory to:
1187 # - see if we should create a Makefile in this directory. We normally do
1188 # so if we find a project file and sources
1189 # - get a list of targets for this directory
1190 # - get the list of source files
1191 sub source_scan_directory
($$$$);
1192 sub source_scan_directory
($$$$)
1194 # a reference to the parent's project
1195 my $parent_project=$_[0];
1196 # the full relative path to the current directory, including a
1197 # trailing '/', or an empty string if this is the top level directory
1199 # the name of this directory, including a trailing '/', or an empty
1200 # string if this is the top level directory
1202 # if set then no targets will be looked for and the sources will all
1203 # end up in the parent_project's 'misc' bucket
1204 my $no_target=$_[3];
1206 # reference to the project for this directory. May not be used
1208 # list of targets found in the 'current' directory
1210 # list of sources found in the current directory
1214 my @sources_misc=();
1215 # true if this directory contains a Windows project
1216 my $has_win_project=0;
1217 # true if this directory contains headers
1219 # If we don't find any executable/library then we might make up targets
1220 # from the list of .dsp/.mak files we find since they usually have the
1221 # same name as their target.
1225 if (defined $opt_single_target or $dirname eq "") {
1226 # Either there is a single target and thus a single project,
1227 # or we are in the top level directory for which a project
1229 $project=$parent_project;
1232 project_init
($project, $path, \
@global_settings);
1234 my $project_settings=@
$project[$P_SETTINGS];
1236 # First find out what this directory contains:
1237 # collect all sources, targets and subdirectories
1238 my $directory=get_directory_contents
($path);
1239 foreach my $dentry (@
$directory) {
1240 if ($dentry =~ /^\./) {
1243 my $fullentry="$path$dentry";
1244 if (-d
"$fullentry") {
1245 if ($dentry =~ /^(Release|Debug)/i) {
1246 # These directories are often used to store the object files and the
1247 # resulting executable/library. They should not contain anything else.
1248 my @candidates=grep /\.(exe|dll)$/i, @
{get_directory_contents
("$fullentry")};
1249 foreach my $candidate (@candidates) {
1250 $targets{$candidate}=1;
1252 } elsif ($dentry =~ /^include/i) {
1253 # This directory must contain headers we're going to need
1254 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1255 source_scan_directory
($project,"$fullentry/","$dentry/",1);
1257 # Recursively scan this directory. Any source file that cannot be
1258 # attributed to a project in one of the subdirectories will be
1259 # attributed to this project.
1260 source_scan_directory
($project,"$fullentry/","$dentry/",$no_target);
1262 } elsif (-f
"$fullentry") {
1263 if ($dentry =~ /\.(exe|dll)$/i) {
1264 $targets{$dentry}=1;
1265 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1266 push @sources_c,"$dentry";
1267 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
1268 if ($dentry =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1269 push @sources_misc,"$dentry";
1270 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1272 push @sources_cxx,"$dentry";
1274 } elsif ($dentry =~ /\.rc$/i) {
1275 push @sources_rc,"$dentry";
1276 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1278 push @sources_misc,"$dentry";
1279 if ($dentry =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1280 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1282 } elsif ($dentry =~ /\.dsp$/i) {
1283 push @dsp_files,"$dentry";
1285 } elsif ($dentry =~ /\.mak$/i) {
1286 push @mak_files,"$dentry";
1288 } elsif ($dentry =~ /^makefile/i) {
1295 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I.";
1297 # If we have a single target then all we have to do is assign
1298 # all the sources to it and we're done
1299 # FIXME: does this play well with the --interactive mode?
1300 if ($opt_single_target) {
1301 my $target=@
{@
$project[$P_TARGETS]}[0];
1302 push @
{@
$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1303 push @
{@
$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1304 push @
{@
$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1305 push @
{@
$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1309 my $parent_settings=@
$parent_project[$P_SETTINGS];
1310 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1311 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1312 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1313 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1314 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1318 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1319 @
{@
$project_settings[$T_SOURCES_C]}+
1320 @
{@
$project_settings[$T_SOURCES_CXX]}+
1321 @
{@
$project_settings[$T_SOURCES_RC]};
1322 if ($source_count == 0) {
1323 # A project without real sources is not a project, get out!
1324 if ($project!=$parent_project) {
1325 my $parent_settings=@
$parent_project[$P_SETTINGS];
1326 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1327 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1331 #print "targets=",%targets,"\n";
1332 #print "target_count=$target_count\n";
1333 #print "has_win_project=$has_win_project\n";
1334 #print "dirname=$dirname\n";
1337 if (($has_win_project != 0) or ($dirname eq "")) {
1338 # Deal with cases where we could not find any executable/library, and
1339 # thus have no target, although we did find some sort of windows project.
1340 $target_count=keys %targets;
1341 if ($target_count == 0) {
1342 # Try to come up with a target list based on .dsp/.mak files
1344 if (@dsp_files > 0) {
1345 $prj_list=\
@dsp_files;
1347 $prj_list=\
@mak_files;
1349 foreach my $filename (@
$prj_list) {
1350 $filename =~ s/\.(dsp|mak)$//i;
1351 if ($opt_target_type == $TT_DLL) {
1352 $filename = "$filename.dll";
1354 $targets{$filename}=1;
1356 $target_count=keys %targets;
1357 if ($target_count == 0) {
1358 # Still nothing, try the name of the directory
1360 if ($dirname eq "") {
1361 # Bad luck, this is the top level directory!
1362 $name=(split /\//, cwd
)[-1];
1365 # Remove the trailing '/'. Also eliminate whatever is after the last
1366 # '.' as it is likely to be meaningless (.orig, .new, ...)
1367 $name =~ s
+(/|\
.[^.]*)$++;
1368 if ($name eq "src") {
1369 # 'src' is probably a subdirectory of the real project directory.
1370 # Try again with the parent (if any).
1372 if ($parent =~ s
+([^/]*)/[^/]*/$+$1+) {
1375 $name=(split /\//, cwd
)[-1];
1379 $name =~ s
+(/|\
.[^.]*)$++;
1380 if ($opt_target_type == $TT_DLL) {
1381 $name = canonize
($name).".dll";
1383 $name = canonize
($name).".exe";
1389 # Ask confirmation to the user if he wishes so
1390 if ($opt_is_interactive == $OPT_ASK_YES) {
1391 my $target_list=join " ",keys %targets;
1392 print "\n*** In ",($path?
$path:"./"),"\n";
1393 print "* winemaker found the following list of (potential) targets\n";
1394 print "* $target_list\n";
1395 print "* Type enter to use it as is, your own comma-separated list of\n";
1396 print "* targets, 'none' to assign the source files to a parent directory,\n";
1397 print "* or 'ignore' to ignore everything in this directory tree.\n";
1398 print "* Target list:\n";
1399 $target_list=<STDIN
>;
1401 if ($target_list eq "") {
1402 # Keep the target list as is, i.e. do nothing
1403 } elsif ($target_list eq "none") {
1404 # Empty the target list
1406 } elsif ($target_list eq "ignore") {
1407 # Ignore this subtree altogether
1411 foreach my $target (split /,/,$target_list) {
1412 $target =~ s
+^\s
*++;
1413 $target =~ s
+\s
*$++;
1414 $targets{$target}=1;
1420 # If we have no project at this level, then transfer all
1421 # the sources to the parent project
1422 $target_count=keys %targets;
1423 if ($target_count == 0) {
1424 if ($project!=$parent_project) {
1425 my $parent_settings=@
$parent_project[$P_SETTINGS];
1426 push @
{@
$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1427 push @
{@
$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1428 push @
{@
$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1429 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1430 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1435 # Otherwise add this project to the project list, except for
1436 # the main project which is already in the list.
1437 if ($dirname ne "") {
1438 push @projects,$project;
1441 # Ask for project-wide options
1442 if ($opt_ask_project_options == $OPT_ASK_YES) {
1444 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1447 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1448 if (defined $flag_desc) {
1449 print "* (currently $flag_desc)\n";
1451 print "* or 'skip' to skip the target specific options,\n";
1452 print "* or 'never' to not be asked this question again:\n";
1454 my $options=<STDIN
>;
1456 if ($options eq "skip") {
1457 $opt_ask_target_options=$OPT_ASK_SKIP;
1459 } elsif ($options eq "never") {
1460 $opt_ask_project_options=$OPT_ASK_NO;
1462 } elsif (source_set_options
($project_settings,$options)) {
1465 print "Please re-enter the options:\n";
1469 # - Create the targets
1470 # - Check if we have both libraries and programs
1471 # - Match each target with source files (sort in reverse
1472 # alphabetical order to get the longest matches first)
1474 my @local_depends=();
1476 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1477 # Create the target...
1479 target_init
($target);
1480 @
$target[$T_NAME]=$target_name;
1481 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
1482 if ($target_name =~ /\.dll$/) {
1483 @
$target[$T_TYPE]=$TT_DLL;
1484 push @local_depends,"$target_name.so";
1485 push @local_dlls,$target_name;
1486 my $canon=canonize
($target_name);
1487 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
1489 @
$target[$T_TYPE]=$opt_target_type;
1490 push @exe_list,$target;
1491 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
1493 my $basename=$target_name;
1494 $basename=~ s/\.(dll|exe)$//i;
1495 # This is the default link list of Visual Studio
1496 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1497 my @std_libraries=qw(uuid);
1498 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1499 @
$target[$T_DLLS]=\
@std_imports;
1500 @
$target[$T_LIBRARIES]=\
@std_libraries;
1502 @
$target[$T_DLLS]=[];
1503 @
$target[$T_LIBRARIES]=[];
1505 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1506 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
1507 push @
{@
$target[$T_LDFLAGS]},"-m$opt_arch";
1509 push @
{@
$project[$P_TARGETS]},$target;
1511 # Ask for target-specific options
1512 if ($opt_ask_target_options == $OPT_ASK_YES) {
1514 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
1517 if ($flag_desc ne "") {
1520 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1521 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1523 my $options=<STDIN
>;
1525 if ($options eq "never") {
1526 $opt_ask_target_options=$OPT_ASK_NO;
1528 } elsif (source_set_options
($target,$options)) {
1531 print "Please re-enter the options:\n";
1534 if (@
$target[$T_FLAGS] & $TF_MFC) {
1535 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1536 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1537 push @
{@
$target[$T_DLLS]},"mfc.dll";
1538 # FIXME: Link with the MFC in the Unix sense, until we
1539 # start exporting the functions properly.
1540 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1541 push @
{@
$target[$T_LIBRARIES]},"mfc";
1545 if ($target_count == 1) {
1546 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
1547 @
$project_settings[$T_SOURCES_C]=[];
1550 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1551 @
$project_settings[$T_SOURCES_CXX]=[];
1554 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
1555 @
$project_settings[$T_SOURCES_RC]=[];
1558 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
1559 # No need for sorting these sources
1560 @
$project_settings[$T_SOURCES_MISC]=[];
1563 foreach my $source (@sources_c) {
1564 if ($source =~ /^$basename/i) {
1565 push @
{@
$target[$T_SOURCES_C]},$source;
1569 foreach my $source (@sources_cxx) {
1570 if ($source =~ /^$basename/i) {
1571 push @
{@
$target[$T_SOURCES_CXX]},$source;
1575 foreach my $source (@sources_rc) {
1576 if ($source =~ /^$basename/i) {
1577 push @
{@
$target[$T_SOURCES_RC]},$source;
1581 foreach my $source (@sources_misc) {
1582 if ($source =~ /^$basename/i) {
1583 push @
{@
$target[$T_SOURCES_MISC]},$source;
1588 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
1589 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
1590 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
1591 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
1593 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1594 $opt_ask_target_options=$OPT_ASK_YES;
1597 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1598 push @
{@
$project_settings[$T_CEXTRA]},"-mno-cygwin";
1599 push @
{@
$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1602 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
1603 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1605 # The sources that did not match, if any, go to the extra
1606 # source list of the project settings
1607 foreach my $source (@sources_c) {
1608 if ($source ne "") {
1609 push @
{@
$project_settings[$T_SOURCES_C]},$source;
1612 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
1613 foreach my $source (@sources_cxx) {
1614 if ($source ne "") {
1615 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
1618 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
1619 foreach my $source (@sources_rc) {
1620 if ($source ne "") {
1621 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
1624 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
1625 foreach my $source (@sources_misc) {
1626 if ($source ne "") {
1627 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
1630 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
1632 # Finally if we are building both libraries and programs in
1633 # this directory, then the programs should be linked with all
1635 if (@local_dlls > 0 and @exe_list > 0) {
1636 foreach my $target (@exe_list) {
1637 push @
{@
$target[$T_DLL_PATH]},"-L.";
1638 push @
{@
$target[$T_DLLS]},@local_dlls;
1644 # Scan the source directories in search of things to build
1647 # If there's a single target then this is going to be the default target
1648 if (defined $opt_single_target) {
1649 # Create the main target
1651 target_init
($main_target);
1652 @
$main_target[$T_NAME]=$opt_single_target;
1653 @
$main_target[$T_TYPE]=$opt_target_type;
1655 # Add it to the list
1656 push @
{$main_project[$P_TARGETS]},$main_target;
1659 # The main directory is always going to be there
1660 push @projects,\
@main_project;
1662 if (defined $opt_work_dir) {
1663 # Now scan the directory tree looking for source files and, maybe, targets
1664 print "Scanning the source directories...\n";
1665 source_scan_directory
(\
@main_project,"","",0);
1666 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
1667 } elsif (defined $opt_work_file) {
1668 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1669 source_scan_project_file
(\
@main_project,0,$opt_work_file);
1670 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1671 source_scan_workspace_file
($opt_work_file);
1683 # Performs a directory traversal and renames the files so that:
1684 # - they have the case desired by the user
1685 # - their extension is of the appropriate case
1686 # - they don't contain annoying characters like ' ', '$', '#', ...
1687 # But only perform these changes for source files and directories.
1688 sub fix_file_and_directory_names
($);
1689 sub fix_file_and_directory_names
($)
1693 my $directory=get_directory_contents
($dirname);
1694 foreach my $dentry (@
$directory)
1696 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1699 # Set $warn to 1 if the user should be warned of the renaming
1701 my $new_name=$dentry;
1703 if (-f
"$dirname/$dentry")
1705 # Don't rename Winemaker's makefiles
1706 next if ($dentry eq "Makefile" and
1707 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker
/);
1709 # Leave non-source files alone
1710 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc))$/i);
1712 # Only all lowercase extensions are supported (because of
1713 # rules like '.c.o:'.
1714 $new_name =~ s/\.C$/.c/;
1715 $new_name =~ s/\.cpp$/.cpp/i;
1716 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1717 $new_name =~ s/\.rc$/.rc/i;
1718 # And this last one is to avoid confusion then running make
1719 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1722 # Adjust the case to the user's preferences
1723 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1724 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1726 $new_name=lc $new_name;
1729 # autoconf and make don't support these characters well
1730 $new_name =~ s/[ \$]/_/g;
1732 # And finally, perform the renaming
1733 if ($new_name ne $dentry)
1736 print STDERR
"warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1738 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1739 print STDERR
"error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1740 print STDERR
" $!\n";
1745 clear_directory_cache
($dirname);
1748 if (-d
"$dirname/$new_name") {
1749 fix_file_and_directory_names
("$dirname/$new_name");
1763 # Try to find a file for the specified filename. The attempt is
1764 # case-insensitive which is why it's not trivial. If a match is
1765 # found then we return the pathname with the correct case.
1772 if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
1774 } elsif ($dirname !~ m
+^/+) {
1775 $dirname=cwd
. "/" . $dirname;
1777 if ($dirname !~ m
+/$+) {
1781 foreach my $component (@
$path) {
1782 $component=~s/^\"//;
1783 $component=~s/\"$//;
1784 #print " looking for $component in \"$dirname\"\n";
1785 if ($component eq ".") {
1788 } elsif ($component eq "..") {
1790 $dirname=dirname
($dirname) . "/";
1793 # The file/directory may have been renamed before. Also try to
1794 # match the renamed file.
1795 my $renamed=$component;
1796 $renamed =~ s/[ \$]/_/g;
1797 if ($renamed eq $component) {
1801 my $directory=get_directory_contents
$dirname;
1803 foreach my $dentry (@
$directory) {
1804 if ($dentry =~ /^\Q$component\E$/i or
1805 (defined $renamed and $dentry =~ /^$renamed$/i)
1807 $dirname.="$dentry/";
1808 $real_path.="$dentry/";
1813 if (!defined $found) {
1815 #print " could not find $component in $dirname\n";
1820 $real_path=~ s
+/$++;
1821 #print " -> found $real_path\n";
1826 # Performs a case-insensitive search for the specified file in the
1828 # $line is the line number that should be referenced when an error occurs
1829 # $filename is the file we are looking for
1830 # $dirname is the directory of the file containing the '#include' directive
1831 # if '"' was used, it is an empty string otherwise
1832 # $project and $target specify part of the include path
1833 sub get_real_include_name
($$$$$)
1841 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a
-zA
-Z
]:[\
/]?/) {
1842 # This is not a relative path, we cannot make any check
1843 my $warning="path:$filename";
1844 if (!defined $warnings{$warning}) {
1845 $warnings{$warning}="1";
1846 print STDERR
"warning: cannot check the case of absolute pathnames:\n";
1847 print STDERR
"$line: $filename\n";
1850 # Here's how we proceed:
1851 # - split the filename we look for into its components
1852 # - then for each directory in the include path
1853 # - trace the directory components starting from that directory
1854 # - if we fail to find a match at any point then continue with
1855 # the next directory in the include path
1856 # - otherwise, rejoice, our quest is over.
1857 my @file_components=split /[\/\\]+/, $filename;
1858 #print " Searching for $filename from @$project[$P_PATH]\n";
1861 if ($dirname ne "") {
1862 # This is an 'include ""' -> look in dirname first.
1863 #print " in $dirname (include \"\")\n";
1864 $real_filename=search_from
($dirname,\
@file_components);
1865 if (defined $real_filename) {
1866 return $real_filename;
1869 my $project_settings=@
$project[$P_SETTINGS];
1870 foreach my $include (@
{@
$target[$T_INCLUDE_PATH]}, @
{@
$project_settings[$T_INCLUDE_PATH]}) {
1871 my $dirname=$include;
1874 if (!is_absolute
($dirname)) {
1875 $dirname="@$project[$P_PATH]$dirname";
1877 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)/++;
1878 $dirname=~ s
+^\
$\
(SRCDIR\
)/+@
$project[$P_PATH]+;
1880 #print " in $dirname\n";
1881 $real_filename=search_from
("$dirname",\
@file_components);
1882 if (defined $real_filename) {
1883 return $real_filename;
1886 my $dotdotpath=@
$project[$P_PATH];
1887 $dotdotpath =~ s/[^\/]+/../g
;
1888 foreach my $include (@
{$global_settings[$T_INCLUDE_PATH]}) {
1889 my $dirname=$include;
1891 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)\
/++;
1892 $dirname=~ s
+^\
$\
(SRCDIR\
)\
/+@
$project[$P_PATH]+;
1893 #print " in $dirname (global setting)\n";
1894 $real_filename=search_from
("$dirname",\
@file_components);
1895 if (defined $real_filename) {
1896 return $real_filename;
1900 $filename =~ s
+\\\\+/+g
; # in include ""
1901 $filename =~ s
+\\+/+g
; # in include <> !
1902 if ($opt_lower_include) {
1903 return lc "$filename";
1914 if ($size =~ /^(1|2|4|8)$/) {
1915 print FILEO
"$indent#include <pshpack$size.h>$trailer";
1917 print FILEO
"$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1918 print FILEO
"$indent#include <pshpack4.h>$trailer";
1923 # 'Parses' a source file and fixes constructs that would not work with
1924 # Winelib. The parsing is rather simple and not all non-portable features
1925 # are corrected. The most important feature that is corrected is the case
1926 # and path separator of '#include' directives. This requires that each
1927 # source file be associated to a project & target so that the proper
1928 # include path is used.
1929 # Also note that the include path is relative to the directory in which the
1930 # compiler is run, i.e. that of the project, not to that of the file.
1936 $filename="@$project[$P_PATH]$filename";
1937 if (! -e
$filename) {
1941 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1942 my $dirname=dirname
($filename);
1944 if (defined $target and (@
$target[$T_FLAGS] & $TF_MFC)) {
1948 print " $filename\n";
1949 #FIXME:assuming that because there is a .bak file, this is what we want is
1950 #probably flawed. Or is it???
1951 if (! -e
"$filename.bak") {
1952 if (!copy
("$filename","$filename.bak")) {
1953 print STDERR
"error: unable to make a backup of $filename:\n";
1954 print STDERR
" $!\n";
1958 if (!open(FILEI
,"$filename.bak")) {
1959 print STDERR
"error: unable to open $filename.bak for reading:\n";
1960 print STDERR
" $!\n";
1963 if (!open(FILEO
,">$filename")) {
1964 print STDERR
"error: unable to open $filename for writing:\n";
1965 print STDERR
" $!\n";
1970 my $rc_block_depth=0;
1971 my $rc_textinclude_state=0;
1974 # Remove any trailing CtrlZ, which isn't strictly in the file
1982 # Make sure all files are '\n' terminated
1985 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
1986 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1987 # the RC files it generates (even in non-MFC projects). So we replace
1988 # it with 'winresrc.h' its very close standard cousin so that non MFC
1989 # projects can compile in Wine without the MFC sources.
1990 my $warning="mfc:afxres.h";
1991 if (!defined $warnings{$warning}) {
1992 $warnings{$warning}="1";
1993 print STDERR
"warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
1994 print STDERR
"warning: the above warning is issued only once\n";
1996 print FILEO
"$1/* winemaker: $2\"afxres.h\" */\n";
1997 print FILEO
"$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
1998 print FILEO
"$1$2\"winresrc.h\"$'";
2001 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
2002 my $from_file=($2 eq "<"?
"":$dirname);
2003 my $real_include_name=get_real_include_name
($line,$3,$from_file,$project,$target);
2004 print FILEO
"$1$2$real_include_name$4$'";
2005 $modified|=($real_include_name ne $3);
2007 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
2008 # Pragma pack handling
2010 # pack_stack is an array of references describing the stack of
2011 # pack directives currently in effect. Each directive if described
2012 # by a reference to an array containing:
2013 # - "push" for pack(push,...) directives, "" otherwise
2014 # - the directive's identifier at index 1
2015 # - the directive's alignment value at index 2
2017 # Don't believe a word of what the documentation says: it's all wrong.
2018 # The code below is based on the actual behavior of Visual C/C++ 6.
2023 # Pushes the default stack alignment
2024 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
2025 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2026 print_pack
($pack_indent,4,$');
2027 push @pack_stack, [ "", "", 4 ];
2029 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
2031 # pragma pack(pop,n)
2032 # Goes up the stack until it finds a pack(push,...), and pops it
2033 # Ignores any pack(n) entry
2034 # Issues a warning if the pack is of the form pack(push,label)
2035 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2036 my $pack_comment=$';
2037 $pack_comment =~ s/^\s*//;
2038 if ($pack_comment ne "") {
2039 print FILEO
"$pack_indent$pack_comment";
2042 my $alignment=pop @pack_stack;
2043 if (!defined $alignment) {
2044 print FILEO
"$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2047 if (@
$alignment[1]) {
2048 print FILEO
"$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2050 print FILEO
"$pack_indent#include <poppack.h>\n";
2051 if (@
$alignment[0]) {
2056 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2057 # pragma pack(pop,label[,n])
2058 # Goes up the stack until finding a pack(push,...) and pops it.
2059 # 'n', if specified, is ignored.
2060 # Ignores any pack(n) entry
2061 # Issues a warning if the label of the pack does not match,
2062 # or if it is in fact a pack(push,n)
2064 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
2065 my $pack_comment=$';
2066 $pack_comment =~ s/^\s*//;
2067 if ($pack_comment ne "") {
2068 print FILEO "$pack_indent$pack_comment";
2071 my $alignment=pop @pack_stack;
2072 if (!defined $alignment) {
2073 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2076 if (@$alignment[1] and @$alignment[1] ne $label) {
2077 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2079 print FILEO "$pack_indent#include <poppack.h>\n";
2080 if (@$alignment[0]) {
2085 } elsif (/^(push\s*\))/) {
2087 # Push the current alignment
2088 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2089 if (@pack_stack > 0) {
2090 my $alignment=$pack_stack[$#pack_stack];
2091 print_pack($pack_indent,@$alignment[2],$');
2092 push @pack_stack, [ "push", "", @
$alignment[2] ];
2094 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2095 print_pack
($pack_indent,4,$');
2096 push @pack_stack, [ "push", "", 4 ];
2099 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2100 # pragma pack([push,]n)
2101 # Push new alignment n
2102 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2103 print_pack($pack_indent,$3,"$'");
2104 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2106 } elsif (/^((\w+)\s*\))/) {
2107 # pragma pack(label)
2108 # label must in fact be a macro that resolves to an integer
2109 # Then behaves like 'pragma pack(n)'
2110 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2111 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2112 print_pack($pack_indent,4,$');
2113 push @pack_stack, [ "", "", 4 ];
2115 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2116 # pragma pack(push,label[,n])
2117 # Pushes a new label on the stack. It is possible to push the same
2118 # label multiple times. If 'n' is omitted then the alignment is
2119 # unchanged. Otherwise it becomes 'n'.
2120 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2124 } elsif (@pack_stack > 0) {
2125 my $alignment=$pack_stack[$#pack_stack];
2126 $size=@$alignment[2];
2128 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2131 print_pack($pack_indent,$size,$');
2132 push @pack_stack, [ "push", $2, $size ];
2135 # pragma pack(??? -> What's that?
2136 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2137 print FILEO "$pack_indent$pack_header$_";
2143 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]+)([\">]?)/) {
2144 my $from_file=($5 eq "<"?"":$dirname);
2145 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2146 print FILEO "$1$5$real_include_name$7$'";
2147 $modified|=($real_include_name ne $6);
2149 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2150 my $from_file=($2 eq "<"?"":$dirname);
2151 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2152 print FILEO "$1$2$real_include_name$4$'";
2153 $modified|=($real_include_name ne $3);
2155 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2156 $rc_textinclude_state=1;
2159 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2160 print FILEO "$1winresrc.h
$2$'";
2163 } elsif (/^\s*BEGIN(\W.*)?$/) {
2164 $rc_textinclude_state|=2;
2168 } elsif (/^\s*END(\W.*)?$/) {
2169 $rc_textinclude_state=0;
2170 if ($rc_block_depth>0) {
2186 if ($opt_backup == 0 or $modified == 0) {
2187 if (!unlink("$filename.bak")) {
2188 print STDERR "error: unable to delete $filename.bak:\n";
2189 print STDERR " $!\n";
2195 # Analyzes each source file in turn to find and correct issues
2196 # that would cause it not to compile.
2199 print "Fixing the source files...\n";
2200 foreach my $project (@projects) {
2201 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2202 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2203 fix_file($source,$project,$target);
2218 # A convenience function to generate all the lists (defines,
2219 # C sources, C++ source, etc.) in the Makefile
2220 sub generate_list($$$;$)
2229 printf FILEO "%-22s=",$name;
2231 if (defined $list) {
2232 foreach my $item (@$list) {
2234 if (defined $data) {
2235 $value=&$data($item);
2241 print FILEO " $value";
2244 print FILEO " \\\n\t\t\t$value";
2255 # Generates a project's Makefile
and all the target files
2256 sub generate_project_files
($)
2259 my $project_settings=@
$project[$P_SETTINGS];
2263 # Then sort the targets and separate the libraries from the programs
2264 foreach my $target (sort { @
$a[$T_NAME] cmp @
$b[$T_NAME] } @
{@
$project[$P_TARGETS]}) {
2265 if (@
$target[$T_TYPE] == $TT_DLL) {
2266 push @dll_list,$target;
2268 push @exe_list,$target;
2271 @
$project[$P_TARGETS]=[];
2272 push @
{@
$project[$P_TARGETS]}, @dll_list;
2273 push @
{@
$project[$P_TARGETS]}, @exe_list;
2275 if (!open(FILEO
,">@$project[$P_PATH]Makefile")) {
2276 print STDERR
"error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2277 print STDERR
" $!\n";
2281 print FILEO
"### Generated by Winemaker $version\n";
2284 generate_list
("SRCDIR",1,[ "." ]);
2285 if (@
$project[$P_PATH] eq "") {
2286 # This is the main project. It is also responsible for recursively
2287 # calling the other projects
2288 generate_list
("SUBDIRS",1,\
@projects,sub
2290 if ($_[0] != \
@main_project) {
2291 my $subdir=@
{$_[0]}[$P_PATH];
2295 # Eliminating the main project by returning undefined!
2298 if (@
{@
$project[$P_TARGETS]} > 0) {
2299 generate_list
("DLLS",1,\
@dll_list,sub
2301 return @
{$_[0]}[$T_NAME];
2303 generate_list
("EXES",1,\
@exe_list,sub
2305 return "@{$_[0]}[$T_NAME]";
2307 print FILEO
"\n\n\n";
2309 print FILEO
"### Common settings\n\n";
2310 # Make it so that the project-wide settings override the global settings
2311 generate_list
("CEXTRA",1,@
$project_settings[$T_CEXTRA]);
2312 generate_list
("CXXEXTRA",1,@
$project_settings[$T_CXXEXTRA]);
2313 generate_list
("RCEXTRA",1,@
$project_settings[$T_RCEXTRA]);
2314 generate_list
("DEFINES",1,@
$project_settings[$T_DEFINES]);
2315 generate_list
("INCLUDE_PATH",1,@
$project_settings[$T_INCLUDE_PATH]);
2316 generate_list
("DLL_PATH",1,@
$project_settings[$T_DLL_PATH]);
2317 generate_list
("DLL_IMPORTS",1,@
$project_settings[$T_DLLS]);
2318 generate_list
("LIBRARY_PATH",1,@
$project_settings[$T_LIBRARY_PATH]);
2319 generate_list
("LIBRARIES",1,@
$project_settings[$T_LIBRARIES]);
2322 my $extra_source_count=@
{@
$project_settings[$T_SOURCES_C]}+
2323 @
{@
$project_settings[$T_SOURCES_CXX]}+
2324 @
{@
$project_settings[$T_SOURCES_RC]};
2325 my $no_extra=($extra_source_count == 0);
2327 print FILEO
"### Extra source lists\n\n";
2328 generate_list
("EXTRA_C_SRCS",1,@
$project_settings[$T_SOURCES_C]);
2329 generate_list
("EXTRA_CXX_SRCS",1,@
$project_settings[$T_SOURCES_CXX]);
2330 generate_list
("EXTRA_RC_SRCS",1,@
$project_settings[$T_SOURCES_RC]);
2332 generate_list
("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
2333 print FILEO
"\n\n\n";
2336 # Iterate over all the targets...
2337 foreach my $target (@
{@
$project[$P_TARGETS]}) {
2338 print FILEO
"### @$target[$T_NAME] sources and settings\n\n";
2339 my $canon=canonize
("@$target[$T_NAME]");
2342 generate_list
("${canon}_MODULE",1,[@
$target[$T_NAME]]);
2343 generate_list
("${canon}_C_SRCS",1,@
$target[$T_SOURCES_C]);
2344 generate_list
("${canon}_CXX_SRCS",1,@
$target[$T_SOURCES_CXX]);
2345 generate_list
("${canon}_RC_SRCS",1,@
$target[$T_SOURCES_RC]);
2346 generate_list
("${canon}_LDFLAGS",1,@
$target[$T_LDFLAGS]);
2347 generate_list
("${canon}_DLL_PATH",1,@
$target[$T_DLL_PATH]);
2348 generate_list
("${canon}_DLLS",1,@
$target[$T_DLLS]);
2349 generate_list
("${canon}_LIBRARY_PATH",1,@
$target[$T_LIBRARY_PATH]);
2350 generate_list
("${canon}_LIBRARIES",1,@
$target[$T_LIBRARIES]);
2352 generate_list
("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2353 print FILEO
"\n\n\n";
2355 print FILEO
"### Global source lists\n\n";
2356 generate_list
("C_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2358 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2360 return "\$(${canon}_C_SRCS)";
2363 generate_list
("",1,[ "\$(EXTRA_C_SRCS)" ]);
2365 generate_list
("CXX_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2367 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2369 return "\$(${canon}_CXX_SRCS)";
2372 generate_list
("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2374 generate_list
("RC_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2376 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2378 return "\$(${canon}_RC_SRCS)";
2381 generate_list
("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2385 print FILEO
"### Tools\n\n";
2386 print FILEO
"CC = winegcc\n";
2387 print FILEO
"CXX = wineg++\n";
2388 print FILEO
"RC = wrc\n";
2391 print FILEO
"### Generic targets\n\n";
2393 if (@
$project[$P_PATH] eq "") {
2394 print FILEO
" \$(SUBDIRS)";
2396 if (@
{@
$project[$P_TARGETS]} > 0) {
2397 print FILEO
" \$(DLLS:%=%.so) \$(EXES:%=%.so)";
2400 print FILEO
"### Build rules\n";
2402 print FILEO
".PHONY: all clean dummy\n";
2404 print FILEO
"\$(SUBDIRS): dummy\n";
2405 print FILEO
"\t\@cd \$\@ && \$(MAKE)\n";
2407 print FILEO
"# Implicit rules\n";
2409 print FILEO
".SUFFIXES: .cpp .rc .res\n";
2410 print FILEO
"DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2412 print FILEO
".c.o:\n";
2413 print FILEO
"\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2415 print FILEO
".cpp.o:\n";
2416 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2418 print FILEO
".cxx.o:\n";
2419 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2421 print FILEO
".rc.res:\n";
2422 print FILEO
"\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2424 print FILEO
"# Rules for cleaning\n";
2426 print FILEO
"CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2427 print FILEO
" \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2429 print FILEO
"clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2430 print FILEO
"\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:.cpp=.o)\n";
2431 print FILEO
"\t\$(RM) \$(DLLS:%=%.so) \$(EXES:%=%.so) \$(EXES:%.exe=%)\n";
2433 print FILEO
"\$(SUBDIRS:%=%/__clean__): dummy\n";
2434 print FILEO
"\tcd `dirname \$\@` && \$(MAKE) clean\n";
2436 print FILEO
"\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2437 print FILEO
"\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2440 if (@
{@
$project[$P_TARGETS]} > 0) {
2441 print FILEO
"### Target specific build rules\n";
2442 print FILEO
"DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2443 foreach my $target (@
{@
$project[$P_TARGETS]}) {
2444 my $canon=canonize
("@$target[$T_NAME]");
2447 print FILEO
"\$(${canon}_MODULE).so: \$(${canon}_OBJS)\n";
2448 if (@
{@
$target[$T_SOURCES_CXX]} > 0 or @
{@
$project_settings[$T_SOURCES_CXX]} > 0) {
2449 print FILEO
"\t\$(CXX)";
2451 print FILEO
"\t\$(CC)";
2453 print FILEO
" \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2463 # This is where we finally generate files. In fact this method does not
2464 # do anything itself but calls the methods that do the actual work.
2467 print "Generating project files...\n";
2469 foreach my $project (@projects) {
2470 my $path=@
$project[$P_PATH];
2477 generate_project_files
($project);
2490 $opt_lower=$OPT_LOWER_UPPERCASE;
2491 $opt_lower_include=1;
2493 $opt_work_dir=undef;
2494 $opt_single_target=undef;
2495 $opt_target_type=$TT_GUIEXE;
2497 $opt_arch=$OPT_ARCH_32;
2498 $opt_is_interactive=$OPT_ASK_NO;
2499 $opt_ask_project_options=$OPT_ASK_NO;
2500 $opt_ask_target_options=$OPT_ASK_NO;
2501 $opt_no_generated_files=0;
2502 $opt_no_source_fix=0;
2515 print "Winemaker $version\n";
2516 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2517 print "Copyright 2004 Dimitrie O. Paun\n";
2518 print "Copyright 2009 André Hentschel\n";
2524 print STDERR
"Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2525 print STDERR
" [--lower-none|--lower-all|--lower-uppercase]\n";
2526 print STDERR
" [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2527 print STDERR
" [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2528 print STDERR
" [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2529 print STDERR
" [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2530 print STDERR
" [--generated-files|--nogenerated-files]\n";
2531 print STDERR
" [--wine64]\n";
2532 print STDERR
" work_directory|project_file|workspace_file\n";
2533 print STDERR
"\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2534 print STDERR
"the specified directory or project-file, so that they can be compiled with Winelib.\n";
2535 print STDERR
"During this process it will modify and rename some of the corresponding files.\n";
2536 print STDERR
"\tPlease read the manual page before use.\n";
2540 target_init
(\
@global_settings);
2543 my $arg=shift @ARGV;
2545 if ($arg eq "--nobanner") {
2547 } elsif ($arg eq "--backup") {
2549 } elsif ($arg eq "--nobackup") {
2551 } elsif ($arg eq "--single-target") {
2552 $opt_single_target=shift @ARGV;
2553 } elsif ($arg eq "--lower-none") {
2554 $opt_lower=$OPT_LOWER_NONE;
2555 } elsif ($arg eq "--lower-all") {
2556 $opt_lower=$OPT_LOWER_ALL;
2557 } elsif ($arg eq "--lower-uppercase") {
2558 $opt_lower=$OPT_LOWER_UPPERCASE;
2559 } elsif ($arg eq "--lower-include") {
2560 $opt_lower_include=1;
2561 } elsif ($arg eq "--nolower-include") {
2562 $opt_lower_include=0;
2563 } elsif ($arg eq "--nosource-fix") {
2564 $opt_no_source_fix=1;
2565 } elsif ($arg eq "--generated-files") {
2566 $opt_no_generated_files=0;
2567 } elsif ($arg eq "--nogenerated-files") {
2568 $opt_no_generated_files=1;
2569 } elsif ($arg eq "--wine64") {
2570 $opt_arch=$OPT_ARCH_64;
2571 } elsif ($arg =~ /^-D/) {
2572 push @
{$global_settings[$T_DEFINES]},$arg;
2573 } elsif ($arg =~ /^-I/) {
2574 push @
{$global_settings[$T_INCLUDE_PATH]},$arg;
2575 } elsif ($arg =~ /^-P/) {
2576 push @
{$global_settings[$T_DLL_PATH]},"-L$'";
2577 } elsif ($arg =~ /^-i/) {
2578 push @
{$global_settings[$T_DLLS]},$';
2579 } elsif ($arg =~ /^-L/) {
2580 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2581 } elsif ($arg =~ /^-l/) {
2582 push @{$global_settings[$T_LIBRARIES]},$';
2584 # 'Source'-based method options
2585 } elsif ($arg eq "--dll") {
2586 $opt_target_type=$TT_DLL;
2587 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2588 $opt_target_type=$TT_GUIEXE;
2589 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2590 $opt_target_type=$TT_CUIEXE;
2591 } elsif ($arg eq "--interactive") {
2592 $opt_is_interactive=$OPT_ASK_YES;
2593 $opt_ask_project_options=$OPT_ASK_YES;
2594 $opt_ask_target_options=$OPT_ASK_YES;
2595 } elsif ($arg eq "--mfc") {
2596 $opt_flags|=$TF_MFC;
2597 } elsif ($arg eq "--nomfc") {
2598 $opt_flags&=~$TF_MFC;
2599 $opt_flags|=$TF_NOMFC;
2600 } elsif ($arg eq "--nodlls") {
2601 $opt_flags|=$TF_NODLLS;
2602 } elsif ($arg eq "--nomsvcrt") {
2603 $opt_flags|=$TF_NOMSVCRT;
2607 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2608 if (!defined $opt_work_dir and !defined $opt_work_file) {
2610 $opt_work_file=$arg;
2616 print STDERR
"error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2625 if (!defined $opt_work_dir and !defined $opt_work_file) {
2626 print STDERR
"error: you must specify the directory or project file containing the sources to be converted\n";
2628 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2629 print STDERR
"error: could not chdir to the work directory\n";
2630 print STDERR
" $!\n";
2634 if ($opt_no_banner == 0) {
2638 project_init
(\
@main_project, "", \
@global_settings);
2640 # Fix the file and directory names
2641 fix_file_and_directory_names
(".");
2643 # Scan the sources to identify the projects and targets
2646 # Fix the source files
2647 if (! $opt_no_source_fix) {
2651 # Generate the Makefile and the spec file
2652 if (! $opt_no_generated_files) {