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 targets found in the current file
530 # list of sources found in the current file
536 my $path=dirname
($filename);
537 my $prj_target_cflags;
538 my $prj_target_defines;
539 my $prj_target_ldflags;
544 my $prj_target_type=1;
545 my @prj_target_options;
547 if (!($path=~/\/$/)) {
551 if (defined $opt_single_target or $is_sub_project == 0) {
552 # Either there is a single target and thus a single project,
553 # or we are a single project-file for which a project
555 $project=$parent_project;
558 project_init
($project, $path, \
@global_settings);
560 my $project_settings=@
$project[$P_SETTINGS];
562 if ($filename =~ /.dsp$/i) {
563 # First find out what this project file contains:
564 # collect all sources, find targets and settings
565 if (!open(FILEI
,$filename)) {
566 print STDERR
"error: unable to open $filename for reading:\n";
567 print STDERR
" $!\n";
572 # Remove any trailing CtrlZ, which isn't strictly in the file
578 # Remove any trailing CrLf
581 # Make sure all lines are '\n' terminated
585 if (/^\# Microsoft Developer Studio Project File - Name=\"([^\"]+)/) {
587 $targets{$prj_name}=1;
590 } elsif (/^# TARGTYPE/) {
591 if (/[[:space:]]0x0101$/) {
592 # Win32 (x86) Application
594 }elsif (/[[:space:]]0x0102$/) {
595 # Win32 (x86) Dynamic-Link Library
597 }elsif (/[[:space:]]0x0103$/) {
598 # Win32 (x86) Console Application
600 }elsif (/[[:space:]]0x0104$/) {
601 # Win32 (x86) Static Library
604 } elsif (/^# ADD CPP(.*)/ && $found_cfg==1) {
605 $prj_target_cflags=$1;
606 @prj_target_options=split(" /", $prj_target_cflags);
607 $prj_target_cflags="";
608 foreach ( @prj_target_options ) {
612 # Suppress Startup Banner and Information Messages
614 # Turns off all warning messages
615 $prj_target_cflags.="-w ";
616 } elsif (/^W[123]$/) {
618 $prj_target_cflags.="-W ";
621 $prj_target_cflags.="-Wall ";
624 $prj_target_cflags.="-Werror ";
626 # Enable Minimal Rebuild
628 # Enable Exception Handling
629 $prj_target_cflags.="-fexceptions ";
630 } elsif (/^Z[d7iI]$/) {
632 $prj_target_cflags.="-g ";
634 # Disable Optimizations
635 $prj_target_cflags.="-O0 ";
638 $prj_target_cflags.="-Os ";
641 $prj_target_cflags.="-O2 ";
643 # Disables inline Expansion
644 $prj_target_cflags.="-fno-inline ";
646 #In-line Function Expansion
647 $prj_target_cflags.="-finline-functions ";
649 # auto In-line Function Expansion
650 $prj_target_cflags.="-finline-functions ";
652 # Use maximum optimization
653 $prj_target_cflags.="-O3 ";
655 # Frame-Pointer Omission
656 $prj_target_cflags.="-fomit-frame-pointer ";
658 # Frame-Pointer Omission
659 $prj_target_cflags.="-fno-omit-frame-pointer ";
661 # Catch Release-Build Errors in Debug Build
662 } elsif (/^M[DLT]d?$/) {
663 # Use Multithreaded Run-Time Library
664 } elsif (/^D\s*\"(.*)\"/) {
665 # Preprocessor Definitions
666 $prj_target_defines.="-D".$1." ";
667 } elsif (/^I\s*\"(.*)\"/) {
668 # Additional Include Directories
671 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I".$sfilet." ";
672 } elsif (/^U\s*\"(.*)\"/) {
673 # Undefines a previously defined symbol
674 $prj_target_cflags.="-U".$1." ";
680 # Automatic Use of Precompiled Headers
682 # Generate File Dependencies
684 # Compile Without Linking
685 # this option is always present and is already specified in the suffix rules
688 $prj_target_cflags.="-mcpu=pentiumpro -D_M_IX86=500 ";
690 # Pentium Pro Optimization
691 $prj_target_cflags.="-march=pentiumpro -D_M_IX86=600 ";
693 # Pentium Optimization
694 $prj_target_cflags.="-mcpu=pentium -D_M_IX86=500 ";
697 $prj_target_cflags.="-mcpu=i386 -D_M_IX86=300 ";
700 $prj_target_cflags.="-mcpu=i486 -D_M_IX86=400 ";
702 # Create Precompiled Header
704 # Use Precompiled Header
706 # Disable Language Extensions
707 $prj_target_cflags.="-ansi ";
709 # Enable Microsoft Extensions
710 } elsif (/^Zm[[:digit:]]+$/) {
711 # Specify Memory Allocation Limit
713 # Packs structures on 1-byte boundaries
714 $prj_target_cflags.="-fpack-struct ";
715 } elsif (/^Zp(2|4|8|16)$/) {
716 # Struct Member Alignment
717 $prj_target_cflags.="-fpack-struct=".$1;
719 print "C compiler option $_ not implemented\n";
723 #print "\nOptions: $prj_target_cflags\n";
725 } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
726 $prj_target_ldflags=$1;
727 @prj_target_options=split(" /", $prj_target_ldflags);
728 $prj_target_ldflags="";
729 $prj_target_libs=$prj_target_options[0];
730 $prj_target_libs=~s/\\/\//g
;
731 $prj_target_libs=~s/\.lib//g;
732 $prj_target_libs=~s/\s+/ -l/g;
733 shift (@prj_target_options);
734 foreach ( @prj_target_options ) {
737 } elsif (/^base:(.*)/) {
739 $prj_target_ldflags.="--image-base ".$1." ";
740 } elsif (/^debug$/) {
741 # Generate Debug Info
745 } elsif (/^incremental:[[:alpha:]]+$/) {
747 } elsif (/^implib:/) {
748 # Name import library
749 } elsif (/^libpath:\"(.*)\"/) {
751 push @
{@
$project_settings[$T_DLL_PATH]},"-L$1";
752 } elsif (/^machine:[[:alnum:]]+$/) {
753 # Specify Target Platform
757 $prj_target_ldflags.="-Map ".$1." ";
759 $prj_target_ldflags.="-Map ".$prj_name.".map ";
761 } elsif (/^nologo$/) {
762 # Suppress Startup Banner and Information Messages
765 # may use it as Target?
766 } elsif (/^pdbtype:/) {
767 # Program Database Storage
768 } elsif (/^subsystem:/) {
770 } elsif (/^version:[[:digit:].]+$/) {
771 # Version Information
773 print "Linker option $_ not implemented\n";
777 } elsif (/^LIB32=/ && $found_cfg==1) {
780 } elsif (/^SOURCE=(.*)$/) {
781 my @components=split /[\/\\]+/, $1;
782 $sfilet=search_from
($path, \
@components);
783 if ($sfilet =~ /\.(exe|dll)$/i) {
785 } elsif ($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 $targets{$vc_project_attr->getValue.".exe"}=1;
865 for (my $flevel = 0; $flevel <= 5; $flevel++) {
866 foreach my $vc_file ($project_xml->findnodes('/VisualStudioProject/Files/'.('Filter/' x
$flevel).'File')) {
867 foreach my $vc_file_attr ($vc_file->attributes) {
868 if ($vc_file_attr->getName eq "RelativePath") {
869 $sfilet = $vc_file_attr->getValue;
870 $sfilet=~s/\\\\/\\/g; #remove double backslash
871 $sfilet=~s/^\.\\//; #remove starting 'this directory'
872 $sfilet=~s/\\/\//g
; #make slashes out of backslashes
873 if ($sfilet =~ /\.(exe|dll)$/i) {
875 } elsif ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
876 push @sources_c,$sfilet;
877 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
878 if ($sfilet =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
879 push @sources_misc,$sfilet;
880 @
$project_settings[$T_FLAGS]|=$TF_MFC;
882 push @sources_cxx,$sfilet;
884 } elsif ($sfilet =~ /\.rc$/i) {
885 push @sources_rc,$sfilet;
886 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
887 push @sources_misc,$sfilet;
888 if ($sfilet =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
889 @
$project_settings[$T_FLAGS]|=$TF_MFC;
897 my @vc_configurations = $project_xml->findnodes('/VisualStudioProject/Configurations/Configuration');
898 my $vc_configuration = $vc_configurations[0];
899 foreach my $vc_configuration_attr ($vc_configuration->attributes) {
900 if ($vc_configuration_attr->getName eq "ConfigurationType") {
901 if ($vc_configuration_attr->getValue==1) {
902 $prj_target_type=1; # Win32 (x86) Application
903 } elsif ($vc_configuration_attr->getValue==2) {
904 $prj_target_type=3; # Win32 (x86) Dynamic-Link Library
909 foreach my $vc_configuration_tools ($vc_configuration->findnodes('Tool')) {
910 my @find_tool = $vc_configuration_tools->attributes;
911 if ($find_tool[0]->getValue eq "VCCLCompilerTool") {
912 foreach my $vc_compiler_tool ($vc_configuration_tools->attributes) {
913 if ($vc_compiler_tool->getName eq "Optimization") {$prj_target_cflags.="-O".$vc_compiler_tool->getValue." ";}
914 if ($vc_compiler_tool->getName eq "WarningLevel") {
915 if ($vc_compiler_tool->getValue==0) {
916 $prj_target_cflags.="-w ";
917 } elsif ($vc_compiler_tool->getValue<4) {
918 $prj_target_cflags.="-W ";
919 } elsif ($vc_compiler_tool->getValue==4) {
920 $prj_target_cflags.="-Wall ";
921 } elsif ($vc_compiler_tool->getValue eq "X") {
922 $prj_target_cflags.="-Werror ";
925 if ($vc_compiler_tool->getName eq "PreprocessorDefinitions") {
926 $configt=$vc_compiler_tool->getValue;
928 $prj_target_defines.="-D".$configt." ";
930 if ($vc_compiler_tool->getName eq "AdditionalIncludeDirectories") {
931 $configt=$vc_compiler_tool->getValue;
934 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I".$configt;
938 if ($find_tool[0]->getValue eq "VCLinkerTool") {
939 foreach my $vc_linker_tool ($vc_configuration_tools->attributes) {
940 if ($vc_linker_tool->getName eq "AdditionalDependencies") {
941 $prj_target_libs=" ".$vc_linker_tool->getValue;
942 $prj_target_libs=~s/\\/\//g
;
943 $prj_target_libs=~s/\.lib//g;
944 $prj_target_libs=~s/\s+/ -l/g;
950 push @
{@
$project_settings[$T_LIBRARIES]},$prj_target_libs;
951 push @
{@
$project_settings[$T_CEXTRA]},$prj_target_cflags;
952 push @
{@
$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
953 push @
{@
$project_settings[$T_DEFINES]},$prj_target_defines;
957 $target_count=keys %targets;
960 # Add this project to the project list, except for
961 # the main project which is already in the list.
962 if ($is_sub_project == 1) {
963 push @projects,$project;
966 # Ask for project-wide options
967 if ($opt_ask_project_options == $OPT_ASK_YES) {
969 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
972 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
973 if (defined $flag_desc) {
974 print "* (currently $flag_desc)\n";
976 print "* or 'skip' to skip the target specific options,\n";
977 print "* or 'never' to not be asked this question again:\n";
981 if ($options eq "skip") {
982 $opt_ask_target_options=$OPT_ASK_SKIP;
984 } elsif ($options eq "never") {
985 $opt_ask_project_options=$OPT_ASK_NO;
987 } elsif (source_set_options
($project_settings,$options)) {
990 print "Please re-enter the options:\n";
994 # - Create the targets
995 # - Check if we have both libraries and programs
996 # - Match each target with source files (sort in reverse
997 # alphabetical order to get the longest matches first)
999 my @local_depends=();
1001 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1002 # Create the target...
1004 target_init
($target);
1005 @
$target[$T_NAME]=$target_name;
1006 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
1007 if ($target_name =~ /\.dll$/) {
1008 @
$target[$T_TYPE]=$TT_DLL;
1009 push @local_depends,"$target_name.so";
1010 push @local_dlls,$target_name;
1011 my $canon=canonize
($target_name);
1012 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
1014 @
$target[$T_TYPE]=$opt_target_type;
1015 push @exe_list,$target;
1016 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
1018 my $basename=$target_name;
1019 $basename=~ s/\.(dll|exe)$//i;
1020 # This is the default link list of Visual Studio
1021 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1022 my @std_libraries=qw(uuid);
1023 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1024 @
$target[$T_DLLS]=\
@std_imports;
1025 @
$target[$T_LIBRARIES]=\
@std_libraries;
1027 @
$target[$T_DLLS]=[];
1028 @
$target[$T_LIBRARIES]=[];
1030 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1031 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
1032 push @
{@
$target[$T_LDFLAGS]},"-m$opt_arch";
1034 push @
{@
$project[$P_TARGETS]},$target;
1036 # Ask for target-specific options
1037 if ($opt_ask_target_options == $OPT_ASK_YES) {
1039 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
1042 if ($flag_desc ne "") {
1045 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1046 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1048 my $options=<STDIN
>;
1050 if ($options eq "never") {
1051 $opt_ask_target_options=$OPT_ASK_NO;
1053 } elsif (source_set_options
($target,$options)) {
1056 print "Please re-enter the options:\n";
1059 if (@
$target[$T_FLAGS] & $TF_MFC) {
1060 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1061 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1062 push @
{@
$target[$T_DLLS]},"mfc.dll";
1063 # FIXME: Link with the MFC in the Unix sense, until we
1064 # start exporting the functions properly.
1065 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1066 push @
{@
$target[$T_LIBRARIES]},"mfc";
1070 if ($target_count == 1) {
1071 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
1072 @
$project_settings[$T_SOURCES_C]=[];
1075 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1076 @
$project_settings[$T_SOURCES_CXX]=[];
1079 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
1080 @
$project_settings[$T_SOURCES_RC]=[];
1083 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
1084 # No need for sorting these sources
1085 @
$project_settings[$T_SOURCES_MISC]=[];
1088 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
1089 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
1090 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
1091 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
1093 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1094 $opt_ask_target_options=$OPT_ASK_YES;
1097 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1098 push @
{@
$project_settings[$T_CEXTRA]},"-mno-cygwin";
1099 push @
{@
$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1102 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
1103 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1105 # The sources that did not match, if any, go to the extra
1106 # source list of the project settings
1107 foreach my $source (@sources_c) {
1108 if ($source ne "") {
1109 push @
{@
$project_settings[$T_SOURCES_C]},$source;
1112 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
1113 foreach my $source (@sources_cxx) {
1114 if ($source ne "") {
1115 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
1118 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
1119 foreach my $source (@sources_rc) {
1120 if ($source ne "") {
1121 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
1124 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
1125 foreach my $source (@sources_misc) {
1126 if ($source ne "") {
1127 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
1130 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
1134 # Scans the specified workspace file to find the project files
1135 sub source_scan_workspace_file
($);
1136 sub source_scan_workspace_file
($)
1139 my $path=dirname
($filename);
1142 if (! -e
$filename) {
1146 if (!open(FILEIWS
,$filename)) {
1147 print STDERR
"error: unable to open $filename for reading:\n";
1148 print STDERR
" $!\n";
1155 if ($filename =~ /.dsw$/i) {
1157 # Remove any trailing CrLf
1160 # catch a project definition
1161 if (/^Project:\s\"(.*)\"=(.*)\s-/) {
1164 @components=split /[\/\\]+/, $prj_path;
1165 $prj_path=search_from
($path, \
@components);
1166 print "Name: $prj_name\nPath: $prj_path\n";
1167 source_scan_project_file
(\
@main_project,1,$prj_path);
1172 print STDERR
"unknown section $_\n";
1173 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1174 print "\nFileversion: $3\n";
1178 } elsif ($filename =~ /.sln$/i) {
1180 # Remove any trailing CrLf
1183 # catch a project definition
1184 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1187 @components=split /[\/\\]+/, $3;
1188 $prj_path=search_from
($path, \
@components);
1189 print "Name: $prj_name\nPath: $prj_path\n";
1190 source_scan_project_file
(\
@main_project,1,$prj_path);
1192 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1193 print "\nFileversion: $3\n";
1199 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
1203 # Scans the specified directory to:
1204 # - see if we should create a Makefile in this directory. We normally do
1205 # so if we find a project file and sources
1206 # - get a list of targets for this directory
1207 # - get the list of source files
1208 sub source_scan_directory
($$$$);
1209 sub source_scan_directory
($$$$)
1211 # a reference to the parent's project
1212 my $parent_project=$_[0];
1213 # the full relative path to the current directory, including a
1214 # trailing '/', or an empty string if this is the top level directory
1216 # the name of this directory, including a trailing '/', or an empty
1217 # string if this is the top level directory
1219 # if set then no targets will be looked for and the sources will all
1220 # end up in the parent_project's 'misc' bucket
1221 my $no_target=$_[3];
1223 # reference to the project for this directory. May not be used
1225 # list of targets found in the 'current' directory
1227 # list of sources found in the current directory
1231 my @sources_misc=();
1232 # true if this directory contains a Windows project
1233 my $has_win_project=0;
1234 # true if this directory contains headers
1236 # If we don't find any executable/library then we might make up targets
1237 # from the list of .dsp/.mak files we find since they usually have the
1238 # same name as their target.
1242 if (defined $opt_single_target or $dirname eq "") {
1243 # Either there is a single target and thus a single project,
1244 # or we are in the top level directory for which a project
1246 $project=$parent_project;
1249 project_init
($project, $path, \
@global_settings);
1251 my $project_settings=@
$project[$P_SETTINGS];
1253 # First find out what this directory contains:
1254 # collect all sources, targets and subdirectories
1255 my $directory=get_directory_contents
($path);
1256 foreach my $dentry (@
$directory) {
1257 if ($dentry =~ /^\./) {
1260 my $fullentry="$path$dentry";
1261 if (-d
"$fullentry") {
1262 if ($dentry =~ /^(Release|Debug)/i) {
1263 # These directories are often used to store the object files and the
1264 # resulting executable/library. They should not contain anything else.
1265 my @candidates=grep /\.(exe|dll)$/i, @
{get_directory_contents
("$fullentry")};
1266 foreach my $candidate (@candidates) {
1267 $targets{$candidate}=1;
1269 } elsif ($dentry =~ /^include/i) {
1270 # This directory must contain headers we're going to need
1271 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1272 source_scan_directory
($project,"$fullentry/","$dentry/",1);
1274 # Recursively scan this directory. Any source file that cannot be
1275 # attributed to a project in one of the subdirectories will be
1276 # attributed to this project.
1277 source_scan_directory
($project,"$fullentry/","$dentry/",$no_target);
1279 } elsif (-f
"$fullentry") {
1280 if ($dentry =~ /\.(exe|dll)$/i) {
1281 $targets{$dentry}=1;
1282 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1283 push @sources_c,"$dentry";
1284 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
1285 if ($dentry =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1286 push @sources_misc,"$dentry";
1287 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1289 push @sources_cxx,"$dentry";
1291 } elsif ($dentry =~ /\.rc$/i) {
1292 push @sources_rc,"$dentry";
1293 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1295 push @sources_misc,"$dentry";
1296 if ($dentry =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1297 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1299 } elsif ($dentry =~ /\.dsp$/i) {
1300 push @dsp_files,"$dentry";
1302 } elsif ($dentry =~ /\.mak$/i) {
1303 push @mak_files,"$dentry";
1305 } elsif ($dentry =~ /^makefile/i) {
1312 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I.";
1314 # If we have a single target then all we have to do is assign
1315 # all the sources to it and we're done
1316 # FIXME: does this play well with the --interactive mode?
1317 if ($opt_single_target) {
1318 my $target=@
{@
$project[$P_TARGETS]}[0];
1319 push @
{@
$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1320 push @
{@
$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1321 push @
{@
$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1322 push @
{@
$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1326 my $parent_settings=@
$parent_project[$P_SETTINGS];
1327 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1328 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1329 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1330 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1331 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1335 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1336 @
{@
$project_settings[$T_SOURCES_C]}+
1337 @
{@
$project_settings[$T_SOURCES_CXX]}+
1338 @
{@
$project_settings[$T_SOURCES_RC]};
1339 if ($source_count == 0) {
1340 # A project without real sources is not a project, get out!
1341 if ($project!=$parent_project) {
1342 my $parent_settings=@
$parent_project[$P_SETTINGS];
1343 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1344 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1348 #print "targets=",%targets,"\n";
1349 #print "target_count=$target_count\n";
1350 #print "has_win_project=$has_win_project\n";
1351 #print "dirname=$dirname\n";
1354 if (($has_win_project != 0) or ($dirname eq "")) {
1355 # Deal with cases where we could not find any executable/library, and
1356 # thus have no target, although we did find some sort of windows project.
1357 $target_count=keys %targets;
1358 if ($target_count == 0) {
1359 # Try to come up with a target list based on .dsp/.mak files
1361 if (@dsp_files > 0) {
1362 $prj_list=\
@dsp_files;
1364 $prj_list=\
@mak_files;
1366 foreach my $filename (@
$prj_list) {
1367 $filename =~ s/\.(dsp|mak)$//i;
1368 if ($opt_target_type == $TT_DLL) {
1369 $filename = "$filename.dll";
1371 $targets{$filename}=1;
1373 $target_count=keys %targets;
1374 if ($target_count == 0) {
1375 # Still nothing, try the name of the directory
1377 if ($dirname eq "") {
1378 # Bad luck, this is the top level directory!
1379 $name=(split /\//, cwd
)[-1];
1382 # Remove the trailing '/'. Also eliminate whatever is after the last
1383 # '.' as it is likely to be meaningless (.orig, .new, ...)
1384 $name =~ s
+(/|\
.[^.]*)$++;
1385 if ($name eq "src") {
1386 # 'src' is probably a subdirectory of the real project directory.
1387 # Try again with the parent (if any).
1389 if ($parent =~ s
+([^/]*)/[^/]*/$+$1+) {
1392 $name=(split /\//, cwd
)[-1];
1396 $name =~ s
+(/|\
.[^.]*)$++;
1397 if ($opt_target_type == $TT_DLL) {
1398 $name = canonize
($name).".dll";
1400 $name = canonize
($name).".exe";
1406 # Ask confirmation to the user if he wishes so
1407 if ($opt_is_interactive == $OPT_ASK_YES) {
1408 my $target_list=join " ",keys %targets;
1409 print "\n*** In ",($path?
$path:"./"),"\n";
1410 print "* winemaker found the following list of (potential) targets\n";
1411 print "* $target_list\n";
1412 print "* Type enter to use it as is, your own comma-separated list of\n";
1413 print "* targets, 'none' to assign the source files to a parent directory,\n";
1414 print "* or 'ignore' to ignore everything in this directory tree.\n";
1415 print "* Target list:\n";
1416 $target_list=<STDIN
>;
1418 if ($target_list eq "") {
1419 # Keep the target list as is, i.e. do nothing
1420 } elsif ($target_list eq "none") {
1421 # Empty the target list
1423 } elsif ($target_list eq "ignore") {
1424 # Ignore this subtree altogether
1428 foreach my $target (split /,/,$target_list) {
1429 $target =~ s
+^\s
*++;
1430 $target =~ s
+\s
*$++;
1431 $targets{$target}=1;
1437 # If we have no project at this level, then transfer all
1438 # the sources to the parent project
1439 $target_count=keys %targets;
1440 if ($target_count == 0) {
1441 if ($project!=$parent_project) {
1442 my $parent_settings=@
$parent_project[$P_SETTINGS];
1443 push @
{@
$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1444 push @
{@
$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1445 push @
{@
$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1446 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1447 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1452 # Otherwise add this project to the project list, except for
1453 # the main project which is already in the list.
1454 if ($dirname ne "") {
1455 push @projects,$project;
1458 # Ask for project-wide options
1459 if ($opt_ask_project_options == $OPT_ASK_YES) {
1461 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1464 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1465 if (defined $flag_desc) {
1466 print "* (currently $flag_desc)\n";
1468 print "* or 'skip' to skip the target specific options,\n";
1469 print "* or 'never' to not be asked this question again:\n";
1471 my $options=<STDIN
>;
1473 if ($options eq "skip") {
1474 $opt_ask_target_options=$OPT_ASK_SKIP;
1476 } elsif ($options eq "never") {
1477 $opt_ask_project_options=$OPT_ASK_NO;
1479 } elsif (source_set_options
($project_settings,$options)) {
1482 print "Please re-enter the options:\n";
1486 # - Create the targets
1487 # - Check if we have both libraries and programs
1488 # - Match each target with source files (sort in reverse
1489 # alphabetical order to get the longest matches first)
1491 my @local_depends=();
1493 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1494 # Create the target...
1496 target_init
($target);
1497 @
$target[$T_NAME]=$target_name;
1498 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
1499 if ($target_name =~ /\.dll$/) {
1500 @
$target[$T_TYPE]=$TT_DLL;
1501 push @local_depends,"$target_name.so";
1502 push @local_dlls,$target_name;
1503 my $canon=canonize
($target_name);
1504 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
1506 @
$target[$T_TYPE]=$opt_target_type;
1507 push @exe_list,$target;
1508 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
1510 my $basename=$target_name;
1511 $basename=~ s/\.(dll|exe)$//i;
1512 # This is the default link list of Visual Studio
1513 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1514 my @std_libraries=qw(uuid);
1515 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1516 @
$target[$T_DLLS]=\
@std_imports;
1517 @
$target[$T_LIBRARIES]=\
@std_libraries;
1519 @
$target[$T_DLLS]=[];
1520 @
$target[$T_LIBRARIES]=[];
1522 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1523 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
1524 push @
{@
$target[$T_LDFLAGS]},"-m$opt_arch";
1526 push @
{@
$project[$P_TARGETS]},$target;
1528 # Ask for target-specific options
1529 if ($opt_ask_target_options == $OPT_ASK_YES) {
1531 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
1534 if ($flag_desc ne "") {
1537 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1538 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1540 my $options=<STDIN
>;
1542 if ($options eq "never") {
1543 $opt_ask_target_options=$OPT_ASK_NO;
1545 } elsif (source_set_options
($target,$options)) {
1548 print "Please re-enter the options:\n";
1551 if (@
$target[$T_FLAGS] & $TF_MFC) {
1552 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1553 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1554 push @
{@
$target[$T_DLLS]},"mfc.dll";
1555 # FIXME: Link with the MFC in the Unix sense, until we
1556 # start exporting the functions properly.
1557 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1558 push @
{@
$target[$T_LIBRARIES]},"mfc";
1562 if ($target_count == 1) {
1563 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
1564 @
$project_settings[$T_SOURCES_C]=[];
1567 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1568 @
$project_settings[$T_SOURCES_CXX]=[];
1571 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
1572 @
$project_settings[$T_SOURCES_RC]=[];
1575 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
1576 # No need for sorting these sources
1577 @
$project_settings[$T_SOURCES_MISC]=[];
1580 foreach my $source (@sources_c) {
1581 if ($source =~ /^$basename/i) {
1582 push @
{@
$target[$T_SOURCES_C]},$source;
1586 foreach my $source (@sources_cxx) {
1587 if ($source =~ /^$basename/i) {
1588 push @
{@
$target[$T_SOURCES_CXX]},$source;
1592 foreach my $source (@sources_rc) {
1593 if ($source =~ /^$basename/i) {
1594 push @
{@
$target[$T_SOURCES_RC]},$source;
1598 foreach my $source (@sources_misc) {
1599 if ($source =~ /^$basename/i) {
1600 push @
{@
$target[$T_SOURCES_MISC]},$source;
1605 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
1606 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
1607 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
1608 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
1610 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1611 $opt_ask_target_options=$OPT_ASK_YES;
1614 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1615 push @
{@
$project_settings[$T_CEXTRA]},"-mno-cygwin";
1616 push @
{@
$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1619 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
1620 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1622 # The sources that did not match, if any, go to the extra
1623 # source list of the project settings
1624 foreach my $source (@sources_c) {
1625 if ($source ne "") {
1626 push @
{@
$project_settings[$T_SOURCES_C]},$source;
1629 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
1630 foreach my $source (@sources_cxx) {
1631 if ($source ne "") {
1632 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
1635 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
1636 foreach my $source (@sources_rc) {
1637 if ($source ne "") {
1638 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
1641 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
1642 foreach my $source (@sources_misc) {
1643 if ($source ne "") {
1644 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
1647 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
1649 # Finally if we are building both libraries and programs in
1650 # this directory, then the programs should be linked with all
1652 if (@local_dlls > 0 and @exe_list > 0) {
1653 foreach my $target (@exe_list) {
1654 push @
{@
$target[$T_DLL_PATH]},"-L.";
1655 push @
{@
$target[$T_DLLS]},@local_dlls;
1661 # Scan the source directories in search of things to build
1664 # If there's a single target then this is going to be the default target
1665 if (defined $opt_single_target) {
1666 # Create the main target
1668 target_init
($main_target);
1669 @
$main_target[$T_NAME]=$opt_single_target;
1670 @
$main_target[$T_TYPE]=$opt_target_type;
1672 # Add it to the list
1673 push @
{$main_project[$P_TARGETS]},$main_target;
1676 # The main directory is always going to be there
1677 push @projects,\
@main_project;
1679 if (defined $opt_work_dir) {
1680 # Now scan the directory tree looking for source files and, maybe, targets
1681 print "Scanning the source directories...\n";
1682 source_scan_directory
(\
@main_project,"","",0);
1683 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
1684 } elsif (defined $opt_work_file) {
1685 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1686 source_scan_project_file
(\
@main_project,0,$opt_work_file);
1687 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1688 source_scan_workspace_file
($opt_work_file);
1700 # Performs a directory traversal and renames the files so that:
1701 # - they have the case desired by the user
1702 # - their extension is of the appropriate case
1703 # - they don't contain annoying characters like ' ', '$', '#', ...
1704 # But only perform these changes for source files and directories.
1705 sub fix_file_and_directory_names
($);
1706 sub fix_file_and_directory_names
($)
1710 my $directory=get_directory_contents
($dirname);
1711 foreach my $dentry (@
$directory)
1713 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1716 # Set $warn to 1 if the user should be warned of the renaming
1718 my $new_name=$dentry;
1720 if (-f
"$dirname/$dentry")
1722 # Don't rename Winemaker's makefiles
1723 next if ($dentry eq "Makefile" and
1724 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker
/);
1726 # Leave non-source files alone
1727 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc))$/i);
1729 # Only all lowercase extensions are supported (because of
1730 # rules like '.c.o:'.
1731 $new_name =~ s/\.C$/.c/;
1732 $new_name =~ s/\.cpp$/.cpp/i;
1733 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1734 $new_name =~ s/\.rc$/.rc/i;
1735 # And this last one is to avoid confusion then running make
1736 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1739 # Adjust the case to the user's preferences
1740 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1741 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1743 $new_name=lc $new_name;
1746 # autoconf and make don't support these characters well
1747 $new_name =~ s/[ \$]/_/g;
1749 # And finally, perform the renaming
1750 if ($new_name ne $dentry)
1753 print STDERR
"warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1755 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1756 print STDERR
"error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1757 print STDERR
" $!\n";
1762 clear_directory_cache
($dirname);
1765 if (-d
"$dirname/$new_name") {
1766 fix_file_and_directory_names
("$dirname/$new_name");
1780 # Try to find a file for the specified filename. The attempt is
1781 # case-insensitive which is why it's not trivial. If a match is
1782 # found then we return the pathname with the correct case.
1789 if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
1791 } elsif ($dirname !~ m
+^/+) {
1792 $dirname=cwd
. "/" . $dirname;
1794 if ($dirname !~ m
+/$+) {
1798 foreach my $component (@
$path) {
1799 $component=~s/^\"//;
1800 $component=~s/\"$//;
1801 #print " looking for $component in \"$dirname\"\n";
1802 if ($component eq ".") {
1805 } elsif ($component eq "..") {
1807 $dirname=dirname
($dirname) . "/";
1810 # The file/directory may have been renamed before. Also try to
1811 # match the renamed file.
1812 my $renamed=$component;
1813 $renamed =~ s/[ \$]/_/g;
1814 if ($renamed eq $component) {
1818 my $directory=get_directory_contents
$dirname;
1820 foreach my $dentry (@
$directory) {
1821 if ($dentry =~ /^\Q$component\E$/i or
1822 (defined $renamed and $dentry =~ /^$renamed$/i)
1824 $dirname.="$dentry/";
1825 $real_path.="$dentry/";
1830 if (!defined $found) {
1832 #print " could not find $component in $dirname\n";
1837 $real_path=~ s
+/$++;
1838 #print " -> found $real_path\n";
1843 # Performs a case-insensitive search for the specified file in the
1845 # $line is the line number that should be referenced when an error occurs
1846 # $filename is the file we are looking for
1847 # $dirname is the directory of the file containing the '#include' directive
1848 # if '"' was used, it is an empty string otherwise
1849 # $project and $target specify part of the include path
1850 sub get_real_include_name
($$$$$)
1858 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a
-zA
-Z
]:[\
/]?/) {
1859 # This is not a relative path, we cannot make any check
1860 my $warning="path:$filename";
1861 if (!defined $warnings{$warning}) {
1862 $warnings{$warning}="1";
1863 print STDERR
"warning: cannot check the case of absolute pathnames:\n";
1864 print STDERR
"$line: $filename\n";
1867 # Here's how we proceed:
1868 # - split the filename we look for into its components
1869 # - then for each directory in the include path
1870 # - trace the directory components starting from that directory
1871 # - if we fail to find a match at any point then continue with
1872 # the next directory in the include path
1873 # - otherwise, rejoice, our quest is over.
1874 my @file_components=split /[\/\\]+/, $filename;
1875 #print " Searching for $filename from @$project[$P_PATH]\n";
1878 if ($dirname ne "") {
1879 # This is an 'include ""' -> look in dirname first.
1880 #print " in $dirname (include \"\")\n";
1881 $real_filename=search_from
($dirname,\
@file_components);
1882 if (defined $real_filename) {
1883 return $real_filename;
1886 my $project_settings=@
$project[$P_SETTINGS];
1887 foreach my $include (@
{@
$target[$T_INCLUDE_PATH]}, @
{@
$project_settings[$T_INCLUDE_PATH]}) {
1888 my $dirname=$include;
1891 if (!is_absolute
($dirname)) {
1892 $dirname="@$project[$P_PATH]$dirname";
1894 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)/++;
1895 $dirname=~ s
+^\
$\
(SRCDIR\
)/+@
$project[$P_PATH]+;
1897 #print " in $dirname\n";
1898 $real_filename=search_from
("$dirname",\
@file_components);
1899 if (defined $real_filename) {
1900 return $real_filename;
1903 my $dotdotpath=@
$project[$P_PATH];
1904 $dotdotpath =~ s/[^\/]+/../g
;
1905 foreach my $include (@
{$global_settings[$T_INCLUDE_PATH]}) {
1906 my $dirname=$include;
1908 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)\
/++;
1909 $dirname=~ s
+^\
$\
(SRCDIR\
)\
/+@
$project[$P_PATH]+;
1910 #print " in $dirname (global setting)\n";
1911 $real_filename=search_from
("$dirname",\
@file_components);
1912 if (defined $real_filename) {
1913 return $real_filename;
1917 $filename =~ s
+\\\\+/+g
; # in include ""
1918 $filename =~ s
+\\+/+g
; # in include <> !
1919 if ($opt_lower_include) {
1920 return lc "$filename";
1931 if ($size =~ /^(1|2|4|8)$/) {
1932 print FILEO
"$indent#include <pshpack$size.h>$trailer";
1934 print FILEO
"$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1935 print FILEO
"$indent#include <pshpack4.h>$trailer";
1940 # 'Parses' a source file and fixes constructs that would not work with
1941 # Winelib. The parsing is rather simple and not all non-portable features
1942 # are corrected. The most important feature that is corrected is the case
1943 # and path separator of '#include' directives. This requires that each
1944 # source file be associated to a project & target so that the proper
1945 # include path is used.
1946 # Also note that the include path is relative to the directory in which the
1947 # compiler is run, i.e. that of the project, not to that of the file.
1953 $filename="@$project[$P_PATH]$filename";
1954 if (! -e
$filename) {
1958 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1959 my $dirname=dirname
($filename);
1961 if (defined $target and (@
$target[$T_FLAGS] & $TF_MFC)) {
1965 print " $filename\n";
1966 #FIXME:assuming that because there is a .bak file, this is what we want is
1967 #probably flawed. Or is it???
1968 if (! -e
"$filename.bak") {
1969 if (!copy
("$filename","$filename.bak")) {
1970 print STDERR
"error: unable to make a backup of $filename:\n";
1971 print STDERR
" $!\n";
1975 if (!open(FILEI
,"$filename.bak")) {
1976 print STDERR
"error: unable to open $filename.bak for reading:\n";
1977 print STDERR
" $!\n";
1980 if (!open(FILEO
,">$filename")) {
1981 print STDERR
"error: unable to open $filename for writing:\n";
1982 print STDERR
" $!\n";
1987 my $rc_block_depth=0;
1988 my $rc_textinclude_state=0;
1991 # Remove any trailing CtrlZ, which isn't strictly in the file
1999 # Make sure all files are '\n' terminated
2002 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
2003 # VC6 automatically includes 'afxres.h', an MFC specific header, in
2004 # the RC files it generates (even in non-MFC projects). So we replace
2005 # it with 'winresrc.h' its very close standard cousin so that non MFC
2006 # projects can compile in Wine without the MFC sources.
2007 my $warning="mfc:afxres.h";
2008 if (!defined $warnings{$warning}) {
2009 $warnings{$warning}="1";
2010 print STDERR
"warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
2011 print STDERR
"warning: the above warning is issued only once\n";
2013 print FILEO
"$1/* winemaker: $2\"afxres.h\" */\n";
2014 print FILEO
"$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
2015 print FILEO
"$1$2\"winresrc.h\"$'";
2018 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
2019 my $from_file=($2 eq "<"?
"":$dirname);
2020 my $real_include_name=get_real_include_name
($line,$3,$from_file,$project,$target);
2021 print FILEO
"$1$2$real_include_name$4$'";
2022 $modified|=($real_include_name ne $3);
2024 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
2025 # Pragma pack handling
2027 # pack_stack is an array of references describing the stack of
2028 # pack directives currently in effect. Each directive if described
2029 # by a reference to an array containing:
2030 # - "push" for pack(push,...) directives, "" otherwise
2031 # - the directive's identifier at index 1
2032 # - the directive's alignment value at index 2
2034 # Don't believe a word of what the documentation says: it's all wrong.
2035 # The code below is based on the actual behavior of Visual C/C++ 6.
2040 # Pushes the default stack alignment
2041 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
2042 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2043 print_pack
($pack_indent,4,$');
2044 push @pack_stack, [ "", "", 4 ];
2046 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
2048 # pragma pack(pop,n)
2049 # Goes up the stack until it finds a pack(push,...), and pops it
2050 # Ignores any pack(n) entry
2051 # Issues a warning if the pack is of the form pack(push,label)
2052 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2053 my $pack_comment=$';
2054 $pack_comment =~ s/^\s*//;
2055 if ($pack_comment ne "") {
2056 print FILEO
"$pack_indent$pack_comment";
2059 my $alignment=pop @pack_stack;
2060 if (!defined $alignment) {
2061 print FILEO
"$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2064 if (@
$alignment[1]) {
2065 print FILEO
"$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2067 print FILEO
"$pack_indent#include <poppack.h>\n";
2068 if (@
$alignment[0]) {
2073 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2074 # pragma pack(pop,label[,n])
2075 # Goes up the stack until finding a pack(push,...) and pops it.
2076 # 'n', if specified, is ignored.
2077 # Ignores any pack(n) entry
2078 # Issues a warning if the label of the pack does not match,
2079 # or if it is in fact a pack(push,n)
2081 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
2082 my $pack_comment=$';
2083 $pack_comment =~ s/^\s*//;
2084 if ($pack_comment ne "") {
2085 print FILEO "$pack_indent$pack_comment";
2088 my $alignment=pop @pack_stack;
2089 if (!defined $alignment) {
2090 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2093 if (@$alignment[1] and @$alignment[1] ne $label) {
2094 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2096 print FILEO "$pack_indent#include <poppack.h>\n";
2097 if (@$alignment[0]) {
2102 } elsif (/^(push\s*\))/) {
2104 # Push the current alignment
2105 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2106 if (@pack_stack > 0) {
2107 my $alignment=$pack_stack[$#pack_stack];
2108 print_pack($pack_indent,@$alignment[2],$');
2109 push @pack_stack, [ "push", "", @
$alignment[2] ];
2111 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2112 print_pack
($pack_indent,4,$');
2113 push @pack_stack, [ "push", "", 4 ];
2116 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2117 # pragma pack([push,]n)
2118 # Push new alignment n
2119 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2120 print_pack($pack_indent,$3,"$'");
2121 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2123 } elsif (/^((\w+)\s*\))/) {
2124 # pragma pack(label)
2125 # label must in fact be a macro that resolves to an integer
2126 # Then behaves like 'pragma pack(n)'
2127 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2128 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2129 print_pack($pack_indent,4,$');
2130 push @pack_stack, [ "", "", 4 ];
2132 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2133 # pragma pack(push,label[,n])
2134 # Pushes a new label on the stack. It is possible to push the same
2135 # label multiple times. If 'n' is omitted then the alignment is
2136 # unchanged. Otherwise it becomes 'n'.
2137 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2141 } elsif (@pack_stack > 0) {
2142 my $alignment=$pack_stack[$#pack_stack];
2143 $size=@$alignment[2];
2145 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2148 print_pack($pack_indent,$size,$');
2149 push @pack_stack, [ "push", $2, $size ];
2152 # pragma pack(??? -> What's that?
2153 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2154 print FILEO "$pack_indent$pack_header$_";
2160 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]+)([\">]?)/) {
2161 my $from_file=($5 eq "<"?"":$dirname);
2162 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2163 print FILEO "$1$5$real_include_name$7$'";
2164 $modified|=($real_include_name ne $6);
2166 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2167 my $from_file=($2 eq "<"?"":$dirname);
2168 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2169 print FILEO "$1$2$real_include_name$4$'";
2170 $modified|=($real_include_name ne $3);
2172 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2173 $rc_textinclude_state=1;
2176 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2177 print FILEO "$1winresrc.h
$2$'";
2180 } elsif (/^\s*BEGIN(\W.*)?$/) {
2181 $rc_textinclude_state|=2;
2185 } elsif (/^\s*END(\W.*)?$/) {
2186 $rc_textinclude_state=0;
2187 if ($rc_block_depth>0) {
2203 if ($opt_backup == 0 or $modified == 0) {
2204 if (!unlink("$filename.bak")) {
2205 print STDERR "error: unable to delete $filename.bak:\n";
2206 print STDERR " $!\n";
2212 # Analyzes each source file in turn to find and correct issues
2213 # that would cause it not to compile.
2216 print "Fixing the source files...\n";
2217 foreach my $project (@projects) {
2218 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2219 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2220 fix_file($source,$project,$target);
2235 # A convenience function to generate all the lists (defines,
2236 # C sources, C++ source, etc.) in the Makefile
2237 sub generate_list($$$;$)
2246 printf FILEO "%-22s=",$name;
2248 if (defined $list) {
2249 foreach my $item (@$list) {
2251 if (defined $data) {
2252 $value=&$data($item);
2258 print FILEO " $value";
2261 print FILEO " \\\n\t\t\t$value";
2272 # Generates a project's Makefile
and all the target files
2273 sub generate_project_files
($)
2276 my $project_settings=@
$project[$P_SETTINGS];
2280 # Then sort the targets and separate the libraries from the programs
2281 foreach my $target (sort { @
$a[$T_NAME] cmp @
$b[$T_NAME] } @
{@
$project[$P_TARGETS]}) {
2282 if (@
$target[$T_TYPE] == $TT_DLL) {
2283 push @dll_list,$target;
2285 push @exe_list,$target;
2288 @
$project[$P_TARGETS]=[];
2289 push @
{@
$project[$P_TARGETS]}, @dll_list;
2290 push @
{@
$project[$P_TARGETS]}, @exe_list;
2292 if (!open(FILEO
,">@$project[$P_PATH]Makefile")) {
2293 print STDERR
"error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2294 print STDERR
" $!\n";
2298 print FILEO
"### Generated by Winemaker $version\n";
2301 generate_list
("SRCDIR",1,[ "." ]);
2302 if (@
$project[$P_PATH] eq "") {
2303 # This is the main project. It is also responsible for recursively
2304 # calling the other projects
2305 generate_list
("SUBDIRS",1,\
@projects,sub
2307 if ($_[0] != \
@main_project) {
2308 my $subdir=@
{$_[0]}[$P_PATH];
2312 # Eliminating the main project by returning undefined!
2315 if (@
{@
$project[$P_TARGETS]} > 0) {
2316 generate_list
("DLLS",1,\
@dll_list,sub
2318 return @
{$_[0]}[$T_NAME];
2320 generate_list
("EXES",1,\
@exe_list,sub
2322 return "@{$_[0]}[$T_NAME]";
2324 print FILEO
"\n\n\n";
2326 print FILEO
"### Common settings\n\n";
2327 # Make it so that the project-wide settings override the global settings
2328 generate_list
("CEXTRA",1,@
$project_settings[$T_CEXTRA]);
2329 generate_list
("CXXEXTRA",1,@
$project_settings[$T_CXXEXTRA]);
2330 generate_list
("RCEXTRA",1,@
$project_settings[$T_RCEXTRA]);
2331 generate_list
("DEFINES",1,@
$project_settings[$T_DEFINES]);
2332 generate_list
("INCLUDE_PATH",1,@
$project_settings[$T_INCLUDE_PATH]);
2333 generate_list
("DLL_PATH",1,@
$project_settings[$T_DLL_PATH]);
2334 generate_list
("DLL_IMPORTS",1,@
$project_settings[$T_DLLS]);
2335 generate_list
("LIBRARY_PATH",1,@
$project_settings[$T_LIBRARY_PATH]);
2336 generate_list
("LIBRARIES",1,@
$project_settings[$T_LIBRARIES]);
2339 my $extra_source_count=@
{@
$project_settings[$T_SOURCES_C]}+
2340 @
{@
$project_settings[$T_SOURCES_CXX]}+
2341 @
{@
$project_settings[$T_SOURCES_RC]};
2342 my $no_extra=($extra_source_count == 0);
2344 print FILEO
"### Extra source lists\n\n";
2345 generate_list
("EXTRA_C_SRCS",1,@
$project_settings[$T_SOURCES_C]);
2346 generate_list
("EXTRA_CXX_SRCS",1,@
$project_settings[$T_SOURCES_CXX]);
2347 generate_list
("EXTRA_RC_SRCS",1,@
$project_settings[$T_SOURCES_RC]);
2349 generate_list
("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
2350 print FILEO
"\n\n\n";
2353 # Iterate over all the targets...
2354 foreach my $target (@
{@
$project[$P_TARGETS]}) {
2355 print FILEO
"### @$target[$T_NAME] sources and settings\n\n";
2356 my $canon=canonize
("@$target[$T_NAME]");
2359 generate_list
("${canon}_MODULE",1,[@
$target[$T_NAME]]);
2360 generate_list
("${canon}_C_SRCS",1,@
$target[$T_SOURCES_C]);
2361 generate_list
("${canon}_CXX_SRCS",1,@
$target[$T_SOURCES_CXX]);
2362 generate_list
("${canon}_RC_SRCS",1,@
$target[$T_SOURCES_RC]);
2363 generate_list
("${canon}_LDFLAGS",1,@
$target[$T_LDFLAGS]);
2364 generate_list
("${canon}_DLL_PATH",1,@
$target[$T_DLL_PATH]);
2365 generate_list
("${canon}_DLLS",1,@
$target[$T_DLLS]);
2366 generate_list
("${canon}_LIBRARY_PATH",1,@
$target[$T_LIBRARY_PATH]);
2367 generate_list
("${canon}_LIBRARIES",1,@
$target[$T_LIBRARIES]);
2369 generate_list
("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2370 print FILEO
"\n\n\n";
2372 print FILEO
"### Global source lists\n\n";
2373 generate_list
("C_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2375 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2377 return "\$(${canon}_C_SRCS)";
2380 generate_list
("",1,[ "\$(EXTRA_C_SRCS)" ]);
2382 generate_list
("CXX_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2384 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2386 return "\$(${canon}_CXX_SRCS)";
2389 generate_list
("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2391 generate_list
("RC_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2393 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2395 return "\$(${canon}_RC_SRCS)";
2398 generate_list
("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2402 print FILEO
"### Tools\n\n";
2403 print FILEO
"CC = winegcc\n";
2404 print FILEO
"CXX = wineg++\n";
2405 print FILEO
"RC = wrc\n";
2408 print FILEO
"### Generic targets\n\n";
2410 if (@
$project[$P_PATH] eq "") {
2411 print FILEO
" \$(SUBDIRS)";
2413 if (@
{@
$project[$P_TARGETS]} > 0) {
2414 print FILEO
" \$(DLLS:%=%.so) \$(EXES:%=%.so)";
2417 print FILEO
"### Build rules\n";
2419 print FILEO
".PHONY: all clean dummy\n";
2421 print FILEO
"\$(SUBDIRS): dummy\n";
2422 print FILEO
"\t\@cd \$\@ && \$(MAKE)\n";
2424 print FILEO
"# Implicit rules\n";
2426 print FILEO
".SUFFIXES: .cpp .rc .res\n";
2427 print FILEO
"DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2429 print FILEO
".c.o:\n";
2430 print FILEO
"\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2432 print FILEO
".cpp.o:\n";
2433 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2435 print FILEO
".cxx.o:\n";
2436 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2438 print FILEO
".rc.res:\n";
2439 print FILEO
"\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2441 print FILEO
"# Rules for cleaning\n";
2443 print FILEO
"CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2444 print FILEO
" \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2446 print FILEO
"clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2447 print FILEO
"\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:.cpp=.o)\n";
2448 print FILEO
"\t\$(RM) \$(DLLS:%=%.so) \$(EXES:%=%.so) \$(EXES:%.exe=%)\n";
2450 print FILEO
"\$(SUBDIRS:%=%/__clean__): dummy\n";
2451 print FILEO
"\tcd `dirname \$\@` && \$(MAKE) clean\n";
2453 print FILEO
"\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2454 print FILEO
"\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2457 if (@
{@
$project[$P_TARGETS]} > 0) {
2458 print FILEO
"### Target specific build rules\n";
2459 print FILEO
"DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2460 foreach my $target (@
{@
$project[$P_TARGETS]}) {
2461 my $canon=canonize
("@$target[$T_NAME]");
2464 print FILEO
"\$(${canon}_MODULE).so: \$(${canon}_OBJS)\n";
2465 if (@
{@
$target[$T_SOURCES_CXX]} > 0 or @
{@
$project_settings[$T_SOURCES_CXX]} > 0) {
2466 print FILEO
"\t\$(CXX)";
2468 print FILEO
"\t\$(CC)";
2470 print FILEO
" \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2480 # This is where we finally generate files. In fact this method does not
2481 # do anything itself but calls the methods that do the actual work.
2484 print "Generating project files...\n";
2486 foreach my $project (@projects) {
2487 my $path=@
$project[$P_PATH];
2494 generate_project_files
($project);
2507 $opt_lower=$OPT_LOWER_UPPERCASE;
2508 $opt_lower_include=1;
2510 $opt_work_dir=undef;
2511 $opt_single_target=undef;
2512 $opt_target_type=$TT_GUIEXE;
2514 $opt_arch=$OPT_ARCH_32;
2515 $opt_is_interactive=$OPT_ASK_NO;
2516 $opt_ask_project_options=$OPT_ASK_NO;
2517 $opt_ask_target_options=$OPT_ASK_NO;
2518 $opt_no_generated_files=0;
2519 $opt_no_source_fix=0;
2532 print "Winemaker $version\n";
2533 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2534 print "Copyright 2004 Dimitrie O. Paun\n";
2535 print "Copyright 2009 André Hentschel\n";
2541 print STDERR
"Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2542 print STDERR
" [--lower-none|--lower-all|--lower-uppercase]\n";
2543 print STDERR
" [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2544 print STDERR
" [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2545 print STDERR
" [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2546 print STDERR
" [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2547 print STDERR
" [--generated-files|--nogenerated-files]\n";
2548 print STDERR
" [--wine64]\n";
2549 print STDERR
" work_directory|project_file|workspace_file\n";
2550 print STDERR
"\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2551 print STDERR
"the specified directory so that they can be compiled with Winelib. During this\n";
2552 print STDERR
"process it will modify and rename some of the files in that directory.\n";
2553 print STDERR
"\tPlease read the manual page before use.\n";
2557 target_init
(\
@global_settings);
2560 my $arg=shift @ARGV;
2562 if ($arg eq "--nobanner") {
2564 } elsif ($arg eq "--backup") {
2566 } elsif ($arg eq "--nobackup") {
2568 } elsif ($arg eq "--single-target") {
2569 $opt_single_target=shift @ARGV;
2570 } elsif ($arg eq "--lower-none") {
2571 $opt_lower=$OPT_LOWER_NONE;
2572 } elsif ($arg eq "--lower-all") {
2573 $opt_lower=$OPT_LOWER_ALL;
2574 } elsif ($arg eq "--lower-uppercase") {
2575 $opt_lower=$OPT_LOWER_UPPERCASE;
2576 } elsif ($arg eq "--lower-include") {
2577 $opt_lower_include=1;
2578 } elsif ($arg eq "--nolower-include") {
2579 $opt_lower_include=0;
2580 } elsif ($arg eq "--nosource-fix") {
2581 $opt_no_source_fix=1;
2582 } elsif ($arg eq "--generated-files") {
2583 $opt_no_generated_files=0;
2584 } elsif ($arg eq "--nogenerated-files") {
2585 $opt_no_generated_files=1;
2586 } elsif ($arg eq "--wine64") {
2587 $opt_arch=$OPT_ARCH_64;
2588 } elsif ($arg =~ /^-D/) {
2589 push @
{$global_settings[$T_DEFINES]},$arg;
2590 } elsif ($arg =~ /^-I/) {
2591 push @
{$global_settings[$T_INCLUDE_PATH]},$arg;
2592 } elsif ($arg =~ /^-P/) {
2593 push @
{$global_settings[$T_DLL_PATH]},"-L$'";
2594 } elsif ($arg =~ /^-i/) {
2595 push @
{$global_settings[$T_DLLS]},$';
2596 } elsif ($arg =~ /^-L/) {
2597 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2598 } elsif ($arg =~ /^-l/) {
2599 push @{$global_settings[$T_LIBRARIES]},$';
2601 # 'Source'-based method options
2602 } elsif ($arg eq "--dll") {
2603 $opt_target_type=$TT_DLL;
2604 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2605 $opt_target_type=$TT_GUIEXE;
2606 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2607 $opt_target_type=$TT_CUIEXE;
2608 } elsif ($arg eq "--interactive") {
2609 $opt_is_interactive=$OPT_ASK_YES;
2610 $opt_ask_project_options=$OPT_ASK_YES;
2611 $opt_ask_target_options=$OPT_ASK_YES;
2612 } elsif ($arg eq "--mfc") {
2613 $opt_flags|=$TF_MFC;
2614 } elsif ($arg eq "--nomfc") {
2615 $opt_flags&=~$TF_MFC;
2616 $opt_flags|=$TF_NOMFC;
2617 } elsif ($arg eq "--nodlls") {
2618 $opt_flags|=$TF_NODLLS;
2619 } elsif ($arg eq "--nomsvcrt") {
2620 $opt_flags|=$TF_NOMSVCRT;
2624 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2625 if (!defined $opt_work_dir and !defined $opt_work_file) {
2627 $opt_work_file=$arg;
2633 print STDERR
"error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2642 if (!defined $opt_work_dir and !defined $opt_work_file) {
2643 print STDERR
"error: you must specify the directory or project file containing the sources to be converted\n";
2645 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2646 print STDERR
"error: could not chdir to the work directory\n";
2647 print STDERR
" $!\n";
2651 if ($opt_no_banner == 0) {
2655 project_init
(\
@main_project, "", \
@global_settings);
2657 # Fix the file and directory names
2658 fix_file_and_directory_names
(".");
2660 # Scan the sources to identify the projects and targets
2663 # Fix the source files
2664 if (! $opt_no_source_fix) {
2668 # Generate the Makefile and the spec file
2669 if (! $opt_no_generated_files) {