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_ldflags;
543 my $prj_target_type=1;
544 my @prj_target_options;
546 if (!($path=~/\/$/)) {
550 if (defined $opt_single_target or $is_sub_project == 0) {
551 # Either there is a single target and thus a single project,
552 # or we are a single project-file for which a project
554 $project=$parent_project;
557 project_init
($project, $path, \
@global_settings);
559 my $project_settings=@
$project[$P_SETTINGS];
561 if ($filename =~ /.dsp$/i) {
562 # First find out what this project file contains:
563 # collect all sources, find targets and settings
564 if (!open(FILEI
,$filename)) {
565 print STDERR
"error: unable to open $filename for reading:\n";
566 print STDERR
" $!\n";
571 # Remove any trailing CtrlZ, which isn't strictly in the file
577 # Remove any trailing CrLf
580 # Make sure all lines are '\n' terminated
584 if (/^\# Microsoft Developer Studio Project File - Name=\"([^\"]+)/) {
586 $targets{$prj_name}=1;
589 } elsif (/^# TARGTYPE/) {
590 if (/[[:space:]]0x0101$/) {
591 # Win32 (x86) Application
593 }elsif (/[[:space:]]0x0102$/) {
594 # Win32 (x86) Dynamic-Link Library
596 }elsif (/[[:space:]]0x0103$/) {
597 # Win32 (x86) Console Application
599 }elsif (/[[:space:]]0x0104$/) {
600 # Win32 (x86) Static Library
603 } elsif (/^# ADD CPP(.*)/ && $found_cfg==1) {
604 $prj_target_cflags=$1;
605 @prj_target_options=split(" /", $prj_target_cflags);
606 $prj_target_cflags="";
607 foreach ( @prj_target_options ) {
611 # Suppress Startup Banner and Information Messages
613 # Turns off all warning messages
614 $prj_target_cflags.="-w ";
615 } elsif (/^W[123]$/) {
617 $prj_target_cflags.="-W ";
620 $prj_target_cflags.="-Wall ";
623 $prj_target_cflags.="-Werror ";
625 # Enable Minimal Rebuild
627 # Enable Exception Handling
628 $prj_target_cflags.="-fexceptions ";
629 } elsif (/^Z[d7iI]$/) {
631 $prj_target_cflags.="-g ";
633 # Disable Optimizations
634 $prj_target_cflags.="-O0 ";
637 $prj_target_cflags.="-Os ";
640 $prj_target_cflags.="-O2 ";
642 # Disables inline Expansion
643 $prj_target_cflags.="-fno-inline ";
645 #In-line Function Expansion
646 $prj_target_cflags.="-finline-functions ";
648 # auto In-line Function Expansion
649 $prj_target_cflags.="-finline-functions ";
651 # Use maximum optimization
652 $prj_target_cflags.="-O3 ";
654 # Frame-Pointer Omission
655 $prj_target_cflags.="-fomit-frame-pointer ";
657 # Frame-Pointer Omission
658 $prj_target_cflags.="-fno-omit-frame-pointer ";
660 # Catch Release-Build Errors in Debug Build
661 } elsif (/^M[DLT]d?$/) {
662 # Use Multithreaded Run-Time Library
663 } elsif (/^D\s*\"(.*)\"/) {
664 # Preprocessor Definitions
665 $prj_target_cflags.="-D".$1." ";
666 } elsif (/^I\s*\"(.*)\"/) {
667 # Additional Include Directories
670 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I".$sfilet." ";
671 } elsif (/^U\s*\"(.*)\"/) {
672 # Undefines a previously defined symbol
673 $prj_target_cflags.="-U".$1." ";
679 # Automatic Use of Precompiled Headers
681 # Generate File Dependencies
683 # Compile Without Linking
684 # this option is always present and is already specified in the suffix rules
687 $prj_target_cflags.="-mcpu=pentiumpro -D_M_IX86=500 ";
689 # Pentium Pro Optimization
690 $prj_target_cflags.="-march=pentiumpro -D_M_IX86=600 ";
692 # Pentium Optimization
693 $prj_target_cflags.="-mcpu=pentium -D_M_IX86=500 ";
696 $prj_target_cflags.="-mcpu=i386 -D_M_IX86=300 ";
699 $prj_target_cflags.="-mcpu=i486 -D_M_IX86=400 ";
701 # Create Precompiled Header
703 # Use Precompiled Header
705 # Disable Language Extensions
706 $prj_target_cflags.="-ansi ";
708 # Enable Microsoft Extensions
709 } elsif (/^Zm[[:digit:]]+$/) {
710 # Specify Memory Allocation Limit
712 # Packs structures on 1-byte boundaries
713 $prj_target_cflags.="-fpack-struct ";
714 } elsif (/^Zp(2|4|8|16)$/) {
715 # Struct Member Alignment
716 $prj_target_cflags.="-fpack-struct=".$1;
718 print "C compiler option $_ not implemented\n";
722 #print "\nOptions: $prj_target_cflags\n";
724 } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
725 $prj_target_ldflags=$1;
726 @prj_target_options=split(" /", $prj_target_ldflags);
727 $prj_target_ldflags="";
728 $prj_target_libs=$prj_target_options[0];
729 #print "\n$prj_target_libs bevor\n";
730 $prj_target_libs=~s/\\/\//g
;
731 $prj_target_libs=~s/\.lib//g;
732 $prj_target_libs=~s/\s+/ -l/g;
733 #print "\n$prj_target_libs after\n";
734 shift (@prj_target_options);
735 foreach ( @prj_target_options ) {
738 } elsif (/^base:(.*)/) {
740 $prj_target_ldflags.="--image-base ".$1." ";
741 } elsif (/^debug$/) {
742 # Generate Debug Info
746 } elsif (/^incremental:[[:alpha:]]+$/) {
748 } elsif (/^implib:/) {
749 # Name import library
750 } elsif (/^libpath:\"(.*)\"/) {
752 push @
{@
$project_settings[$T_DLL_PATH]},"-L$1";
753 } elsif (/^machine:[[:alnum:]]+$/) {
754 # Specify Target Platform
758 $prj_target_ldflags.="-Map ".$1." ";
760 $prj_target_ldflags.="-Map ".$prj_name.".map ";
762 } elsif (/^nologo$/) {
763 # Suppress Startup Banner and Information Messages
766 # may use it as Target?
767 } elsif (/^pdbtype:/) {
768 # Program Database Storage
769 } elsif (/^subsystem:/) {
771 } elsif (/^version:[[:digit:].]+$/) {
772 # Version Information
774 print "Linker option $_ not implemented\n";
778 } elsif (/^LIB32=/ && $found_cfg==1) {
781 } elsif (/^SOURCE=(.*)$/) {
782 my @components=split /[\/\\]+/, $1;
783 $sfilet=search_from
($path, \
@components);
784 if ($sfilet =~ /\.(exe|dll)$/i) {
786 } elsif ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
787 push @sources_c,$sfilet;
788 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
789 if ($sfilet =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
790 push @sources_misc,$sfilet;
791 @
$project_settings[$T_FLAGS]|=$TF_MFC;
793 push @sources_cxx,$sfilet;
795 } elsif ($sfilet =~ /\.rc$/i) {
796 push @sources_rc,$sfilet;
797 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
798 push @sources_misc,$sfilet;
799 if ($sfilet =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
800 @
$project_settings[$T_FLAGS]|=$TF_MFC;
805 } elsif (/^# (Begin|End) Source File/) {
806 # Source-Files already handled
808 } elsif (/^# (Begin|End) Group/) {
811 } elsif (/^# (Begin|End) Custom Build/) {
812 # Custom Builds are ignored
814 } elsif (/^# ADD LIB32 /) {
817 } elsif (/^# Begin Target$/) {
818 # Targets are ignored
820 } elsif (/^# End Target$/) {
821 # Targets are ignored
824 if ($found_cfg == 1) {
827 if (/if (.*)\(CFG\)" == "(.*)"/i) {
828 if ($2 eq $prj_cfg) {
833 } elsif (/^CFG=(.*)/i) {
837 else { # Line recognized
843 push @
{@
$project_settings[$T_LIBRARIES]},$prj_target_libs;
844 push @
{@
$project_settings[$T_CEXTRA]},$prj_target_cflags;
845 push @
{@
$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
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 ne "VCCLCompilerTool") {next;}
912 foreach my $vc_configuration_tool ($vc_configuration_tools->attributes) {
913 if ($vc_configuration_tool->getName eq "Optimization") {$prj_target_cflags.="-O".$vc_configuration_tool->getValue." ";}
914 if ($vc_configuration_tool->getName eq "WarningLevel") {
915 if ($vc_configuration_tool->getValue==0) {
916 $prj_target_cflags.="-w ";
917 } elsif ($vc_configuration_tool->getValue<4) {
918 $prj_target_cflags.="-W ";
919 } elsif ($vc_configuration_tool->getValue==4) {
920 $prj_target_cflags.="-Wall ";
921 } elsif ($vc_configuration_tool->getValue eq "X") {
922 $prj_target_cflags.="-Werror ";
925 if ($vc_configuration_tool->getName eq "PreprocessorDefinitions") {
926 $configt=$vc_configuration_tool->getValue;
928 $prj_target_cflags.="-D".$configt." ";
930 if ($vc_configuration_tool->getName eq "AdditionalIncludeDirectories") {
931 $configt=$vc_configuration_tool->getValue;
934 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I".$configt;
939 push @
{@
$project_settings[$T_CEXTRA]},$prj_target_cflags;
940 push @
{@
$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
944 $target_count=keys %targets;
947 # Add this project to the project list, except for
948 # the main project which is already in the list.
949 if ($is_sub_project == 1) {
950 push @projects,$project;
953 # Ask for project-wide options
954 if ($opt_ask_project_options == $OPT_ASK_YES) {
956 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
959 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
960 if (defined $flag_desc) {
961 print "* (currently $flag_desc)\n";
963 print "* or 'skip' to skip the target specific options,\n";
964 print "* or 'never' to not be asked this question again:\n";
968 if ($options eq "skip") {
969 $opt_ask_target_options=$OPT_ASK_SKIP;
971 } elsif ($options eq "never") {
972 $opt_ask_project_options=$OPT_ASK_NO;
974 } elsif (source_set_options
($project_settings,$options)) {
977 print "Please re-enter the options:\n";
981 # - Create the targets
982 # - Check if we have both libraries and programs
983 # - Match each target with source files (sort in reverse
984 # alphabetical order to get the longest matches first)
986 my @local_depends=();
988 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
989 # Create the target...
991 target_init
($target);
992 @
$target[$T_NAME]=$target_name;
993 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
994 if ($target_name =~ /\.dll$/) {
995 @
$target[$T_TYPE]=$TT_DLL;
996 push @local_depends,"$target_name.so";
997 push @local_dlls,$target_name;
998 my $canon=canonize
($target_name);
999 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
1001 @
$target[$T_TYPE]=$opt_target_type;
1002 push @exe_list,$target;
1003 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
1005 my $basename=$target_name;
1006 $basename=~ s/\.(dll|exe)$//i;
1007 # This is the default link list of Visual Studio
1008 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1009 my @std_libraries=qw(uuid);
1010 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1011 @
$target[$T_DLLS]=\
@std_imports;
1012 @
$target[$T_LIBRARIES]=\
@std_libraries;
1014 @
$target[$T_DLLS]=[];
1015 @
$target[$T_LIBRARIES]=[];
1017 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1018 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
1019 push @
{@
$target[$T_LDFLAGS]},"-m$opt_arch";
1021 push @
{@
$project[$P_TARGETS]},$target;
1023 # Ask for target-specific options
1024 if ($opt_ask_target_options == $OPT_ASK_YES) {
1026 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
1029 if ($flag_desc ne "") {
1032 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1033 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1035 my $options=<STDIN
>;
1037 if ($options eq "never") {
1038 $opt_ask_target_options=$OPT_ASK_NO;
1040 } elsif (source_set_options
($target,$options)) {
1043 print "Please re-enter the options:\n";
1046 if (@
$target[$T_FLAGS] & $TF_MFC) {
1047 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1048 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1049 push @
{@
$target[$T_DLLS]},"mfc.dll";
1050 # FIXME: Link with the MFC in the Unix sense, until we
1051 # start exporting the functions properly.
1052 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1053 push @
{@
$target[$T_LIBRARIES]},"mfc";
1057 if ($target_count == 1) {
1058 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
1059 @
$project_settings[$T_SOURCES_C]=[];
1062 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1063 @
$project_settings[$T_SOURCES_CXX]=[];
1066 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
1067 @
$project_settings[$T_SOURCES_RC]=[];
1070 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
1071 # No need for sorting these sources
1072 @
$project_settings[$T_SOURCES_MISC]=[];
1075 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
1076 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
1077 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
1078 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
1080 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1081 $opt_ask_target_options=$OPT_ASK_YES;
1084 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1085 push @
{@
$project_settings[$T_CEXTRA]},"-mno-cygwin";
1086 push @
{@
$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1089 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
1090 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1092 # The sources that did not match, if any, go to the extra
1093 # source list of the project settings
1094 foreach my $source (@sources_c) {
1095 if ($source ne "") {
1096 push @
{@
$project_settings[$T_SOURCES_C]},$source;
1099 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
1100 foreach my $source (@sources_cxx) {
1101 if ($source ne "") {
1102 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
1105 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
1106 foreach my $source (@sources_rc) {
1107 if ($source ne "") {
1108 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
1111 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
1112 foreach my $source (@sources_misc) {
1113 if ($source ne "") {
1114 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
1117 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
1121 # Scans the specified workspace file to find the project files
1122 sub source_scan_workspace_file
($);
1123 sub source_scan_workspace_file
($)
1126 my $path=dirname
($filename);
1129 if (! -e
$filename) {
1133 if (!open(FILEIWS
,$filename)) {
1134 print STDERR
"error: unable to open $filename for reading:\n";
1135 print STDERR
" $!\n";
1142 if ($filename =~ /.dsw$/i) {
1144 # Remove any trailing CrLf
1147 # catch a project definition
1148 if (/^Project:\s\"(.*)\"=(.*)\s-/) {
1151 @components=split /[\/\\]+/, $prj_path;
1152 $prj_path=search_from
($path, \
@components);
1153 print "Name: $prj_name\nPath: $prj_path\n";
1154 source_scan_project_file
(\
@main_project,1,$prj_path);
1159 print STDERR
"unknown section $_\n";
1160 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1161 print "\nFileversion: $3\n";
1165 } elsif ($filename =~ /.sln$/i) {
1167 # Remove any trailing CrLf
1170 # catch a project definition
1171 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1174 @components=split /[\/\\]+/, $3;
1175 $prj_path=search_from
($path, \
@components);
1176 print "Name: $prj_name\nPath: $prj_path\n";
1177 source_scan_project_file
(\
@main_project,1,$prj_path);
1179 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1180 print "\nFileversion: $3\n";
1186 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
1190 # Scans the specified directory to:
1191 # - see if we should create a Makefile in this directory. We normally do
1192 # so if we find a project file and sources
1193 # - get a list of targets for this directory
1194 # - get the list of source files
1195 sub source_scan_directory
($$$$);
1196 sub source_scan_directory
($$$$)
1198 # a reference to the parent's project
1199 my $parent_project=$_[0];
1200 # the full relative path to the current directory, including a
1201 # trailing '/', or an empty string if this is the top level directory
1203 # the name of this directory, including a trailing '/', or an empty
1204 # string if this is the top level directory
1206 # if set then no targets will be looked for and the sources will all
1207 # end up in the parent_project's 'misc' bucket
1208 my $no_target=$_[3];
1210 # reference to the project for this directory. May not be used
1212 # list of targets found in the 'current' directory
1214 # list of sources found in the current directory
1218 my @sources_misc=();
1219 # true if this directory contains a Windows project
1220 my $has_win_project=0;
1221 # true if this directory contains headers
1223 # If we don't find any executable/library then we might make up targets
1224 # from the list of .dsp/.mak files we find since they usually have the
1225 # same name as their target.
1229 if (defined $opt_single_target or $dirname eq "") {
1230 # Either there is a single target and thus a single project,
1231 # or we are in the top level directory for which a project
1233 $project=$parent_project;
1236 project_init
($project, $path, \
@global_settings);
1238 my $project_settings=@
$project[$P_SETTINGS];
1240 # First find out what this directory contains:
1241 # collect all sources, targets and subdirectories
1242 my $directory=get_directory_contents
($path);
1243 foreach my $dentry (@
$directory) {
1244 if ($dentry =~ /^\./) {
1247 my $fullentry="$path$dentry";
1248 if (-d
"$fullentry") {
1249 if ($dentry =~ /^(Release|Debug)/i) {
1250 # These directories are often used to store the object files and the
1251 # resulting executable/library. They should not contain anything else.
1252 my @candidates=grep /\.(exe|dll)$/i, @
{get_directory_contents
("$fullentry")};
1253 foreach my $candidate (@candidates) {
1254 $targets{$candidate}=1;
1256 } elsif ($dentry =~ /^include/i) {
1257 # This directory must contain headers we're going to need
1258 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1259 source_scan_directory
($project,"$fullentry/","$dentry/",1);
1261 # Recursively scan this directory. Any source file that cannot be
1262 # attributed to a project in one of the subdirectories will be
1263 # attributed to this project.
1264 source_scan_directory
($project,"$fullentry/","$dentry/",$no_target);
1266 } elsif (-f
"$fullentry") {
1267 if ($dentry =~ /\.(exe|dll)$/i) {
1268 $targets{$dentry}=1;
1269 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1270 push @sources_c,"$dentry";
1271 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
1272 if ($dentry =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1273 push @sources_misc,"$dentry";
1274 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1276 push @sources_cxx,"$dentry";
1278 } elsif ($dentry =~ /\.rc$/i) {
1279 push @sources_rc,"$dentry";
1280 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1282 push @sources_misc,"$dentry";
1283 if ($dentry =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1284 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1286 } elsif ($dentry =~ /\.dsp$/i) {
1287 push @dsp_files,"$dentry";
1289 } elsif ($dentry =~ /\.mak$/i) {
1290 push @mak_files,"$dentry";
1292 } elsif ($dentry =~ /^makefile/i) {
1299 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I.";
1301 # If we have a single target then all we have to do is assign
1302 # all the sources to it and we're done
1303 # FIXME: does this play well with the --interactive mode?
1304 if ($opt_single_target) {
1305 my $target=@
{@
$project[$P_TARGETS]}[0];
1306 push @
{@
$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1307 push @
{@
$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1308 push @
{@
$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1309 push @
{@
$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1313 my $parent_settings=@
$parent_project[$P_SETTINGS];
1314 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1315 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1316 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1317 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1318 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1322 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1323 @
{@
$project_settings[$T_SOURCES_C]}+
1324 @
{@
$project_settings[$T_SOURCES_CXX]}+
1325 @
{@
$project_settings[$T_SOURCES_RC]};
1326 if ($source_count == 0) {
1327 # A project without real sources is not a project, get out!
1328 if ($project!=$parent_project) {
1329 my $parent_settings=@
$parent_project[$P_SETTINGS];
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 #print "targets=",%targets,"\n";
1336 #print "target_count=$target_count\n";
1337 #print "has_win_project=$has_win_project\n";
1338 #print "dirname=$dirname\n";
1341 if (($has_win_project != 0) or ($dirname eq "")) {
1342 # Deal with cases where we could not find any executable/library, and
1343 # thus have no target, although we did find some sort of windows project.
1344 $target_count=keys %targets;
1345 if ($target_count == 0) {
1346 # Try to come up with a target list based on .dsp/.mak files
1348 if (@dsp_files > 0) {
1349 $prj_list=\
@dsp_files;
1351 $prj_list=\
@mak_files;
1353 foreach my $filename (@
$prj_list) {
1354 $filename =~ s/\.(dsp|mak)$//i;
1355 if ($opt_target_type == $TT_DLL) {
1356 $filename = "$filename.dll";
1358 $targets{$filename}=1;
1360 $target_count=keys %targets;
1361 if ($target_count == 0) {
1362 # Still nothing, try the name of the directory
1364 if ($dirname eq "") {
1365 # Bad luck, this is the top level directory!
1366 $name=(split /\//, cwd
)[-1];
1369 # Remove the trailing '/'. Also eliminate whatever is after the last
1370 # '.' as it is likely to be meaningless (.orig, .new, ...)
1371 $name =~ s
+(/|\
.[^.]*)$++;
1372 if ($name eq "src") {
1373 # 'src' is probably a subdirectory of the real project directory.
1374 # Try again with the parent (if any).
1376 if ($parent =~ s
+([^/]*)/[^/]*/$+$1+) {
1379 $name=(split /\//, cwd
)[-1];
1383 $name =~ s
+(/|\
.[^.]*)$++;
1384 if ($opt_target_type == $TT_DLL) {
1385 $name = canonize
($name).".dll";
1387 $name = canonize
($name).".exe";
1393 # Ask confirmation to the user if he wishes so
1394 if ($opt_is_interactive == $OPT_ASK_YES) {
1395 my $target_list=join " ",keys %targets;
1396 print "\n*** In ",($path?
$path:"./"),"\n";
1397 print "* winemaker found the following list of (potential) targets\n";
1398 print "* $target_list\n";
1399 print "* Type enter to use it as is, your own comma-separated list of\n";
1400 print "* targets, 'none' to assign the source files to a parent directory,\n";
1401 print "* or 'ignore' to ignore everything in this directory tree.\n";
1402 print "* Target list:\n";
1403 $target_list=<STDIN
>;
1405 if ($target_list eq "") {
1406 # Keep the target list as is, i.e. do nothing
1407 } elsif ($target_list eq "none") {
1408 # Empty the target list
1410 } elsif ($target_list eq "ignore") {
1411 # Ignore this subtree altogether
1415 foreach my $target (split /,/,$target_list) {
1416 $target =~ s
+^\s
*++;
1417 $target =~ s
+\s
*$++;
1418 $targets{$target}=1;
1424 # If we have no project at this level, then transfer all
1425 # the sources to the parent project
1426 $target_count=keys %targets;
1427 if ($target_count == 0) {
1428 if ($project!=$parent_project) {
1429 my $parent_settings=@
$parent_project[$P_SETTINGS];
1430 push @
{@
$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1431 push @
{@
$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1432 push @
{@
$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1433 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1434 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1439 # Otherwise add this project to the project list, except for
1440 # the main project which is already in the list.
1441 if ($dirname ne "") {
1442 push @projects,$project;
1445 # Ask for project-wide options
1446 if ($opt_ask_project_options == $OPT_ASK_YES) {
1448 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1451 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1452 if (defined $flag_desc) {
1453 print "* (currently $flag_desc)\n";
1455 print "* or 'skip' to skip the target specific options,\n";
1456 print "* or 'never' to not be asked this question again:\n";
1458 my $options=<STDIN
>;
1460 if ($options eq "skip") {
1461 $opt_ask_target_options=$OPT_ASK_SKIP;
1463 } elsif ($options eq "never") {
1464 $opt_ask_project_options=$OPT_ASK_NO;
1466 } elsif (source_set_options
($project_settings,$options)) {
1469 print "Please re-enter the options:\n";
1473 # - Create the targets
1474 # - Check if we have both libraries and programs
1475 # - Match each target with source files (sort in reverse
1476 # alphabetical order to get the longest matches first)
1478 my @local_depends=();
1480 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1481 # Create the target...
1483 target_init
($target);
1484 @
$target[$T_NAME]=$target_name;
1485 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
1486 if ($target_name =~ /\.dll$/) {
1487 @
$target[$T_TYPE]=$TT_DLL;
1488 push @local_depends,"$target_name.so";
1489 push @local_dlls,$target_name;
1490 my $canon=canonize
($target_name);
1491 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
1493 @
$target[$T_TYPE]=$opt_target_type;
1494 push @exe_list,$target;
1495 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
1497 my $basename=$target_name;
1498 $basename=~ s/\.(dll|exe)$//i;
1499 # This is the default link list of Visual Studio
1500 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1501 my @std_libraries=qw(uuid);
1502 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1503 @
$target[$T_DLLS]=\
@std_imports;
1504 @
$target[$T_LIBRARIES]=\
@std_libraries;
1506 @
$target[$T_DLLS]=[];
1507 @
$target[$T_LIBRARIES]=[];
1509 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1510 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
1511 push @
{@
$target[$T_LDFLAGS]},"-m$opt_arch";
1513 push @
{@
$project[$P_TARGETS]},$target;
1515 # Ask for target-specific options
1516 if ($opt_ask_target_options == $OPT_ASK_YES) {
1518 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
1521 if ($flag_desc ne "") {
1524 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1525 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1527 my $options=<STDIN
>;
1529 if ($options eq "never") {
1530 $opt_ask_target_options=$OPT_ASK_NO;
1532 } elsif (source_set_options
($target,$options)) {
1535 print "Please re-enter the options:\n";
1538 if (@
$target[$T_FLAGS] & $TF_MFC) {
1539 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1540 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1541 push @
{@
$target[$T_DLLS]},"mfc.dll";
1542 # FIXME: Link with the MFC in the Unix sense, until we
1543 # start exporting the functions properly.
1544 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1545 push @
{@
$target[$T_LIBRARIES]},"mfc";
1549 if ($target_count == 1) {
1550 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
1551 @
$project_settings[$T_SOURCES_C]=[];
1554 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1555 @
$project_settings[$T_SOURCES_CXX]=[];
1558 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
1559 @
$project_settings[$T_SOURCES_RC]=[];
1562 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
1563 # No need for sorting these sources
1564 @
$project_settings[$T_SOURCES_MISC]=[];
1567 foreach my $source (@sources_c) {
1568 if ($source =~ /^$basename/i) {
1569 push @
{@
$target[$T_SOURCES_C]},$source;
1573 foreach my $source (@sources_cxx) {
1574 if ($source =~ /^$basename/i) {
1575 push @
{@
$target[$T_SOURCES_CXX]},$source;
1579 foreach my $source (@sources_rc) {
1580 if ($source =~ /^$basename/i) {
1581 push @
{@
$target[$T_SOURCES_RC]},$source;
1585 foreach my $source (@sources_misc) {
1586 if ($source =~ /^$basename/i) {
1587 push @
{@
$target[$T_SOURCES_MISC]},$source;
1592 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
1593 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
1594 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
1595 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
1597 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1598 $opt_ask_target_options=$OPT_ASK_YES;
1601 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1602 push @
{@
$project_settings[$T_CEXTRA]},"-mno-cygwin";
1603 push @
{@
$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1606 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
1607 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1609 # The sources that did not match, if any, go to the extra
1610 # source list of the project settings
1611 foreach my $source (@sources_c) {
1612 if ($source ne "") {
1613 push @
{@
$project_settings[$T_SOURCES_C]},$source;
1616 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
1617 foreach my $source (@sources_cxx) {
1618 if ($source ne "") {
1619 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
1622 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
1623 foreach my $source (@sources_rc) {
1624 if ($source ne "") {
1625 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
1628 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
1629 foreach my $source (@sources_misc) {
1630 if ($source ne "") {
1631 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
1634 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
1636 # Finally if we are building both libraries and programs in
1637 # this directory, then the programs should be linked with all
1639 if (@local_dlls > 0 and @exe_list > 0) {
1640 foreach my $target (@exe_list) {
1641 push @
{@
$target[$T_DLL_PATH]},"-L.";
1642 push @
{@
$target[$T_DLLS]},@local_dlls;
1648 # Scan the source directories in search of things to build
1651 # If there's a single target then this is going to be the default target
1652 if (defined $opt_single_target) {
1653 # Create the main target
1655 target_init
($main_target);
1656 @
$main_target[$T_NAME]=$opt_single_target;
1657 @
$main_target[$T_TYPE]=$opt_target_type;
1659 # Add it to the list
1660 push @
{$main_project[$P_TARGETS]},$main_target;
1663 # The main directory is always going to be there
1664 push @projects,\
@main_project;
1666 if (defined $opt_work_dir) {
1667 # Now scan the directory tree looking for source files and, maybe, targets
1668 print "Scanning the source directories...\n";
1669 source_scan_directory
(\
@main_project,"","",0);
1670 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
1671 } elsif (defined $opt_work_file) {
1672 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1673 source_scan_project_file
(\
@main_project,0,$opt_work_file);
1674 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1675 source_scan_workspace_file
($opt_work_file);
1687 # Performs a directory traversal and renames the files so that:
1688 # - they have the case desired by the user
1689 # - their extension is of the appropriate case
1690 # - they don't contain annoying characters like ' ', '$', '#', ...
1691 # But only perform these changes for source files and directories.
1692 sub fix_file_and_directory_names
($);
1693 sub fix_file_and_directory_names
($)
1697 my $directory=get_directory_contents
($dirname);
1698 foreach my $dentry (@
$directory)
1700 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1703 # Set $warn to 1 if the user should be warned of the renaming
1705 my $new_name=$dentry;
1707 if (-f
"$dirname/$dentry")
1709 # Don't rename Winemaker's makefiles
1710 next if ($dentry eq "Makefile" and
1711 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker
/);
1713 # Leave non-source files alone
1714 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc))$/i);
1716 # Only all lowercase extensions are supported (because of
1717 # rules like '.c.o:'.
1718 $new_name =~ s/\.C$/.c/;
1719 $new_name =~ s/\.cpp$/.cpp/i;
1720 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1721 $new_name =~ s/\.rc$/.rc/i;
1722 # And this last one is to avoid confusion then running make
1723 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1726 # Adjust the case to the user's preferences
1727 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1728 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1730 $new_name=lc $new_name;
1733 # autoconf and make don't support these characters well
1734 $new_name =~ s/[ \$]/_/g;
1736 # And finally, perform the renaming
1737 if ($new_name ne $dentry)
1740 print STDERR
"warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1742 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1743 print STDERR
"error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1744 print STDERR
" $!\n";
1749 clear_directory_cache
($dirname);
1752 if (-d
"$dirname/$new_name") {
1753 fix_file_and_directory_names
("$dirname/$new_name");
1767 # Try to find a file for the specified filename. The attempt is
1768 # case-insensitive which is why it's not trivial. If a match is
1769 # found then we return the pathname with the correct case.
1776 if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
1778 } elsif ($dirname !~ m
+^/+) {
1779 $dirname=cwd
. "/" . $dirname;
1781 if ($dirname !~ m
+/$+) {
1785 foreach my $component (@
$path) {
1786 $component=~s/^\"//;
1787 $component=~s/\"$//;
1788 #print " looking for $component in \"$dirname\"\n";
1789 if ($component eq ".") {
1792 } elsif ($component eq "..") {
1794 $dirname=dirname
($dirname) . "/";
1797 # The file/directory may have been renamed before. Also try to
1798 # match the renamed file.
1799 my $renamed=$component;
1800 $renamed =~ s/[ \$]/_/g;
1801 if ($renamed eq $component) {
1805 my $directory=get_directory_contents
$dirname;
1807 foreach my $dentry (@
$directory) {
1808 if ($dentry =~ /^\Q$component\E$/i or
1809 (defined $renamed and $dentry =~ /^$renamed$/i)
1811 $dirname.="$dentry/";
1812 $real_path.="$dentry/";
1817 if (!defined $found) {
1819 #print " could not find $component in $dirname\n";
1824 $real_path=~ s
+/$++;
1825 #print " -> found $real_path\n";
1830 # Performs a case-insensitive search for the specified file in the
1832 # $line is the line number that should be referenced when an error occurs
1833 # $filename is the file we are looking for
1834 # $dirname is the directory of the file containing the '#include' directive
1835 # if '"' was used, it is an empty string otherwise
1836 # $project and $target specify part of the include path
1837 sub get_real_include_name
($$$$$)
1845 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a
-zA
-Z
]:[\
/]?/) {
1846 # This is not a relative path, we cannot make any check
1847 my $warning="path:$filename";
1848 if (!defined $warnings{$warning}) {
1849 $warnings{$warning}="1";
1850 print STDERR
"warning: cannot check the case of absolute pathnames:\n";
1851 print STDERR
"$line: $filename\n";
1854 # Here's how we proceed:
1855 # - split the filename we look for into its components
1856 # - then for each directory in the include path
1857 # - trace the directory components starting from that directory
1858 # - if we fail to find a match at any point then continue with
1859 # the next directory in the include path
1860 # - otherwise, rejoice, our quest is over.
1861 my @file_components=split /[\/\\]+/, $filename;
1862 #print " Searching for $filename from @$project[$P_PATH]\n";
1865 if ($dirname ne "") {
1866 # This is an 'include ""' -> look in dirname first.
1867 #print " in $dirname (include \"\")\n";
1868 $real_filename=search_from
($dirname,\
@file_components);
1869 if (defined $real_filename) {
1870 return $real_filename;
1873 my $project_settings=@
$project[$P_SETTINGS];
1874 foreach my $include (@
{@
$target[$T_INCLUDE_PATH]}, @
{@
$project_settings[$T_INCLUDE_PATH]}) {
1875 my $dirname=$include;
1878 if (!is_absolute
($dirname)) {
1879 $dirname="@$project[$P_PATH]$dirname";
1881 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)/++;
1882 $dirname=~ s
+^\
$\
(SRCDIR\
)/+@
$project[$P_PATH]+;
1884 #print " in $dirname\n";
1885 $real_filename=search_from
("$dirname",\
@file_components);
1886 if (defined $real_filename) {
1887 return $real_filename;
1890 my $dotdotpath=@
$project[$P_PATH];
1891 $dotdotpath =~ s/[^\/]+/../g
;
1892 foreach my $include (@
{$global_settings[$T_INCLUDE_PATH]}) {
1893 my $dirname=$include;
1895 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)\
/++;
1896 $dirname=~ s
+^\
$\
(SRCDIR\
)\
/+@
$project[$P_PATH]+;
1897 #print " in $dirname (global setting)\n";
1898 $real_filename=search_from
("$dirname",\
@file_components);
1899 if (defined $real_filename) {
1900 return $real_filename;
1904 $filename =~ s
+\\\\+/+g
; # in include ""
1905 $filename =~ s
+\\+/+g
; # in include <> !
1906 if ($opt_lower_include) {
1907 return lc "$filename";
1918 if ($size =~ /^(1|2|4|8)$/) {
1919 print FILEO
"$indent#include <pshpack$size.h>$trailer";
1921 print FILEO
"$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1922 print FILEO
"$indent#include <pshpack4.h>$trailer";
1927 # 'Parses' a source file and fixes constructs that would not work with
1928 # Winelib. The parsing is rather simple and not all non-portable features
1929 # are corrected. The most important feature that is corrected is the case
1930 # and path separator of '#include' directives. This requires that each
1931 # source file be associated to a project & target so that the proper
1932 # include path is used.
1933 # Also note that the include path is relative to the directory in which the
1934 # compiler is run, i.e. that of the project, not to that of the file.
1940 $filename="@$project[$P_PATH]$filename";
1941 if (! -e
$filename) {
1945 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1946 my $dirname=dirname
($filename);
1948 if (defined $target and (@
$target[$T_FLAGS] & $TF_MFC)) {
1952 print " $filename\n";
1953 #FIXME:assuming that because there is a .bak file, this is what we want is
1954 #probably flawed. Or is it???
1955 if (! -e
"$filename.bak") {
1956 if (!copy
("$filename","$filename.bak")) {
1957 print STDERR
"error: unable to make a backup of $filename:\n";
1958 print STDERR
" $!\n";
1962 if (!open(FILEI
,"$filename.bak")) {
1963 print STDERR
"error: unable to open $filename.bak for reading:\n";
1964 print STDERR
" $!\n";
1967 if (!open(FILEO
,">$filename")) {
1968 print STDERR
"error: unable to open $filename for writing:\n";
1969 print STDERR
" $!\n";
1974 my $rc_block_depth=0;
1975 my $rc_textinclude_state=0;
1978 # Remove any trailing CtrlZ, which isn't strictly in the file
1986 # Make sure all files are '\n' terminated
1989 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
1990 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1991 # the RC files it generates (even in non-MFC projects). So we replace
1992 # it with 'winresrc.h' its very close standard cousin so that non MFC
1993 # projects can compile in Wine without the MFC sources.
1994 my $warning="mfc:afxres.h";
1995 if (!defined $warnings{$warning}) {
1996 $warnings{$warning}="1";
1997 print STDERR
"warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
1998 print STDERR
"warning: the above warning is issued only once\n";
2000 print FILEO
"$1/* winemaker: $2\"afxres.h\" */\n";
2001 print FILEO
"$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
2002 print FILEO
"$1$2\"winresrc.h\"$'";
2005 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
2006 my $from_file=($2 eq "<"?
"":$dirname);
2007 my $real_include_name=get_real_include_name
($line,$3,$from_file,$project,$target);
2008 print FILEO
"$1$2$real_include_name$4$'";
2009 $modified|=($real_include_name ne $3);
2011 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
2012 # Pragma pack handling
2014 # pack_stack is an array of references describing the stack of
2015 # pack directives currently in effect. Each directive if described
2016 # by a reference to an array containing:
2017 # - "push" for pack(push,...) directives, "" otherwise
2018 # - the directive's identifier at index 1
2019 # - the directive's alignment value at index 2
2021 # Don't believe a word of what the documentation says: it's all wrong.
2022 # The code below is based on the actual behavior of Visual C/C++ 6.
2027 # Pushes the default stack alignment
2028 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
2029 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2030 print_pack
($pack_indent,4,$');
2031 push @pack_stack, [ "", "", 4 ];
2033 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
2035 # pragma pack(pop,n)
2036 # Goes up the stack until it finds a pack(push,...), and pops it
2037 # Ignores any pack(n) entry
2038 # Issues a warning if the pack is of the form pack(push,label)
2039 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2040 my $pack_comment=$';
2041 $pack_comment =~ s/^\s*//;
2042 if ($pack_comment ne "") {
2043 print FILEO
"$pack_indent$pack_comment";
2046 my $alignment=pop @pack_stack;
2047 if (!defined $alignment) {
2048 print FILEO
"$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2051 if (@
$alignment[1]) {
2052 print FILEO
"$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2054 print FILEO
"$pack_indent#include <poppack.h>\n";
2055 if (@
$alignment[0]) {
2060 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2061 # pragma pack(pop,label[,n])
2062 # Goes up the stack until finding a pack(push,...) and pops it.
2063 # 'n', if specified, is ignored.
2064 # Ignores any pack(n) entry
2065 # Issues a warning if the label of the pack does not match,
2066 # or if it is in fact a pack(push,n)
2068 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
2069 my $pack_comment=$';
2070 $pack_comment =~ s/^\s*//;
2071 if ($pack_comment ne "") {
2072 print FILEO "$pack_indent$pack_comment";
2075 my $alignment=pop @pack_stack;
2076 if (!defined $alignment) {
2077 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2080 if (@$alignment[1] and @$alignment[1] ne $label) {
2081 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2083 print FILEO "$pack_indent#include <poppack.h>\n";
2084 if (@$alignment[0]) {
2089 } elsif (/^(push\s*\))/) {
2091 # Push the current alignment
2092 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2093 if (@pack_stack > 0) {
2094 my $alignment=$pack_stack[$#pack_stack];
2095 print_pack($pack_indent,@$alignment[2],$');
2096 push @pack_stack, [ "push", "", @
$alignment[2] ];
2098 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2099 print_pack
($pack_indent,4,$');
2100 push @pack_stack, [ "push", "", 4 ];
2103 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2104 # pragma pack([push,]n)
2105 # Push new alignment n
2106 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2107 print_pack($pack_indent,$3,"$'");
2108 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2110 } elsif (/^((\w+)\s*\))/) {
2111 # pragma pack(label)
2112 # label must in fact be a macro that resolves to an integer
2113 # Then behaves like 'pragma pack(n)'
2114 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2115 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2116 print_pack($pack_indent,4,$');
2117 push @pack_stack, [ "", "", 4 ];
2119 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2120 # pragma pack(push,label[,n])
2121 # Pushes a new label on the stack. It is possible to push the same
2122 # label multiple times. If 'n' is omitted then the alignment is
2123 # unchanged. Otherwise it becomes 'n'.
2124 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2128 } elsif (@pack_stack > 0) {
2129 my $alignment=$pack_stack[$#pack_stack];
2130 $size=@$alignment[2];
2132 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2135 print_pack($pack_indent,$size,$');
2136 push @pack_stack, [ "push", $2, $size ];
2139 # pragma pack(??? -> What's that?
2140 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2141 print FILEO "$pack_indent$pack_header$_";
2147 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]+)([\">]?)/) {
2148 my $from_file=($5 eq "<"?"":$dirname);
2149 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2150 print FILEO "$1$5$real_include_name$7$'";
2151 $modified|=($real_include_name ne $6);
2153 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2154 my $from_file=($2 eq "<"?"":$dirname);
2155 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2156 print FILEO "$1$2$real_include_name$4$'";
2157 $modified|=($real_include_name ne $3);
2159 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2160 $rc_textinclude_state=1;
2163 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2164 print FILEO "$1winresrc.h
$2$'";
2167 } elsif (/^\s*BEGIN(\W.*)?$/) {
2168 $rc_textinclude_state|=2;
2172 } elsif (/^\s*END(\W.*)?$/) {
2173 $rc_textinclude_state=0;
2174 if ($rc_block_depth>0) {
2190 if ($opt_backup == 0 or $modified == 0) {
2191 if (!unlink("$filename.bak")) {
2192 print STDERR "error: unable to delete $filename.bak:\n";
2193 print STDERR " $!\n";
2199 # Analyzes each source file in turn to find and correct issues
2200 # that would cause it not to compile.
2203 print "Fixing the source files...\n";
2204 foreach my $project (@projects) {
2205 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2206 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2207 fix_file($source,$project,$target);
2222 # A convenience function to generate all the lists (defines,
2223 # C sources, C++ source, etc.) in the Makefile
2224 sub generate_list($$$;$)
2233 printf FILEO "%-22s=",$name;
2235 if (defined $list) {
2236 foreach my $item (@$list) {
2238 if (defined $data) {
2239 $value=&$data($item);
2245 print FILEO " $value";
2248 print FILEO " \\\n\t\t\t$value";
2259 # Generates a project's Makefile
and all the target files
2260 sub generate_project_files
($)
2263 my $project_settings=@
$project[$P_SETTINGS];
2267 # Then sort the targets and separate the libraries from the programs
2268 foreach my $target (sort { @
$a[$T_NAME] cmp @
$b[$T_NAME] } @
{@
$project[$P_TARGETS]}) {
2269 if (@
$target[$T_TYPE] == $TT_DLL) {
2270 push @dll_list,$target;
2272 push @exe_list,$target;
2275 @
$project[$P_TARGETS]=[];
2276 push @
{@
$project[$P_TARGETS]}, @dll_list;
2277 push @
{@
$project[$P_TARGETS]}, @exe_list;
2279 if (!open(FILEO
,">@$project[$P_PATH]Makefile")) {
2280 print STDERR
"error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2281 print STDERR
" $!\n";
2285 print FILEO
"### Generated by Winemaker $version\n";
2288 generate_list
("SRCDIR",1,[ "." ]);
2289 if (@
$project[$P_PATH] eq "") {
2290 # This is the main project. It is also responsible for recursively
2291 # calling the other projects
2292 generate_list
("SUBDIRS",1,\
@projects,sub
2294 if ($_[0] != \
@main_project) {
2295 my $subdir=@
{$_[0]}[$P_PATH];
2299 # Eliminating the main project by returning undefined!
2302 if (@
{@
$project[$P_TARGETS]} > 0) {
2303 generate_list
("DLLS",1,\
@dll_list,sub
2305 return @
{$_[0]}[$T_NAME];
2307 generate_list
("EXES",1,\
@exe_list,sub
2309 return "@{$_[0]}[$T_NAME]";
2311 print FILEO
"\n\n\n";
2313 print FILEO
"### Common settings\n\n";
2314 # Make it so that the project-wide settings override the global settings
2315 generate_list
("CEXTRA",1,@
$project_settings[$T_CEXTRA]);
2316 generate_list
("CXXEXTRA",1,@
$project_settings[$T_CXXEXTRA]);
2317 generate_list
("RCEXTRA",1,@
$project_settings[$T_RCEXTRA]);
2318 generate_list
("DEFINES",1,@
$project_settings[$T_DEFINES]);
2319 generate_list
("INCLUDE_PATH",1,@
$project_settings[$T_INCLUDE_PATH]);
2320 generate_list
("DLL_PATH",1,@
$project_settings[$T_DLL_PATH]);
2321 generate_list
("DLL_IMPORTS",1,@
$project_settings[$T_DLLS]);
2322 generate_list
("LIBRARY_PATH",1,@
$project_settings[$T_LIBRARY_PATH]);
2323 generate_list
("LIBRARIES",1,@
$project_settings[$T_LIBRARIES]);
2326 my $extra_source_count=@
{@
$project_settings[$T_SOURCES_C]}+
2327 @
{@
$project_settings[$T_SOURCES_CXX]}+
2328 @
{@
$project_settings[$T_SOURCES_RC]};
2329 my $no_extra=($extra_source_count == 0);
2331 print FILEO
"### Extra source lists\n\n";
2332 generate_list
("EXTRA_C_SRCS",1,@
$project_settings[$T_SOURCES_C]);
2333 generate_list
("EXTRA_CXX_SRCS",1,@
$project_settings[$T_SOURCES_CXX]);
2334 generate_list
("EXTRA_RC_SRCS",1,@
$project_settings[$T_SOURCES_RC]);
2336 generate_list
("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
2337 print FILEO
"\n\n\n";
2340 # Iterate over all the targets...
2341 foreach my $target (@
{@
$project[$P_TARGETS]}) {
2342 print FILEO
"### @$target[$T_NAME] sources and settings\n\n";
2343 my $canon=canonize
("@$target[$T_NAME]");
2346 generate_list
("${canon}_MODULE",1,[@
$target[$T_NAME]]);
2347 generate_list
("${canon}_C_SRCS",1,@
$target[$T_SOURCES_C]);
2348 generate_list
("${canon}_CXX_SRCS",1,@
$target[$T_SOURCES_CXX]);
2349 generate_list
("${canon}_RC_SRCS",1,@
$target[$T_SOURCES_RC]);
2350 generate_list
("${canon}_LDFLAGS",1,@
$target[$T_LDFLAGS]);
2351 generate_list
("${canon}_DLL_PATH",1,@
$target[$T_DLL_PATH]);
2352 generate_list
("${canon}_DLLS",1,@
$target[$T_DLLS]);
2353 generate_list
("${canon}_LIBRARY_PATH",1,@
$target[$T_LIBRARY_PATH]);
2354 generate_list
("${canon}_LIBRARIES",1,@
$target[$T_LIBRARIES]);
2356 generate_list
("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2357 print FILEO
"\n\n\n";
2359 print FILEO
"### Global source lists\n\n";
2360 generate_list
("C_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2362 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2364 return "\$(${canon}_C_SRCS)";
2367 generate_list
("",1,[ "\$(EXTRA_C_SRCS)" ]);
2369 generate_list
("CXX_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2371 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2373 return "\$(${canon}_CXX_SRCS)";
2376 generate_list
("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2378 generate_list
("RC_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2380 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2382 return "\$(${canon}_RC_SRCS)";
2385 generate_list
("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2389 print FILEO
"### Tools\n\n";
2390 print FILEO
"CC = winegcc\n";
2391 print FILEO
"CXX = wineg++\n";
2392 print FILEO
"RC = wrc\n";
2395 print FILEO
"### Generic targets\n\n";
2397 if (@
$project[$P_PATH] eq "") {
2398 print FILEO
" \$(SUBDIRS)";
2400 if (@
{@
$project[$P_TARGETS]} > 0) {
2401 print FILEO
" \$(DLLS:%=%.so) \$(EXES:%=%.so)";
2404 print FILEO
"### Build rules\n";
2406 print FILEO
".PHONY: all clean dummy\n";
2408 print FILEO
"\$(SUBDIRS): dummy\n";
2409 print FILEO
"\t\@cd \$\@ && \$(MAKE)\n";
2411 print FILEO
"# Implicit rules\n";
2413 print FILEO
".SUFFIXES: .cpp .rc .res\n";
2414 print FILEO
"DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2416 print FILEO
".c.o:\n";
2417 print FILEO
"\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2419 print FILEO
".cpp.o:\n";
2420 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2422 print FILEO
".cxx.o:\n";
2423 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2425 print FILEO
".rc.res:\n";
2426 print FILEO
"\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2428 print FILEO
"# Rules for cleaning\n";
2430 print FILEO
"CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2431 print FILEO
" \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2433 print FILEO
"clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2434 print FILEO
"\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:.cpp=.o)\n";
2435 print FILEO
"\t\$(RM) \$(DLLS:%=%.so) \$(EXES:%=%.so) \$(EXES:%.exe=%)\n";
2437 print FILEO
"\$(SUBDIRS:%=%/__clean__): dummy\n";
2438 print FILEO
"\tcd `dirname \$\@` && \$(MAKE) clean\n";
2440 print FILEO
"\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2441 print FILEO
"\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2444 if (@
{@
$project[$P_TARGETS]} > 0) {
2445 print FILEO
"### Target specific build rules\n";
2446 print FILEO
"DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2447 foreach my $target (@
{@
$project[$P_TARGETS]}) {
2448 my $canon=canonize
("@$target[$T_NAME]");
2451 print FILEO
"\$(${canon}_MODULE).so: \$(${canon}_OBJS)\n";
2452 if (@
{@
$target[$T_SOURCES_CXX]} > 0 or @
{@
$project_settings[$T_SOURCES_CXX]} > 0) {
2453 print FILEO
"\t\$(CXX)";
2455 print FILEO
"\t\$(CC)";
2457 print FILEO
" \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2467 # This is where we finally generate files. In fact this method does not
2468 # do anything itself but calls the methods that do the actual work.
2471 print "Generating project files...\n";
2473 foreach my $project (@projects) {
2474 my $path=@
$project[$P_PATH];
2481 generate_project_files
($project);
2494 $opt_lower=$OPT_LOWER_UPPERCASE;
2495 $opt_lower_include=1;
2497 $opt_work_dir=undef;
2498 $opt_single_target=undef;
2499 $opt_target_type=$TT_GUIEXE;
2501 $opt_arch=$OPT_ARCH_32;
2502 $opt_is_interactive=$OPT_ASK_NO;
2503 $opt_ask_project_options=$OPT_ASK_NO;
2504 $opt_ask_target_options=$OPT_ASK_NO;
2505 $opt_no_generated_files=0;
2506 $opt_no_source_fix=0;
2519 print "Winemaker $version\n";
2520 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2521 print "Copyright 2004 Dimitrie O. Paun\n";
2522 print "Copyright 2009 André Hentschel\n";
2528 print STDERR
"Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2529 print STDERR
" [--lower-none|--lower-all|--lower-uppercase]\n";
2530 print STDERR
" [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2531 print STDERR
" [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2532 print STDERR
" [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2533 print STDERR
" [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2534 print STDERR
" [--generated-files|--nogenerated-files]\n";
2535 print STDERR
" [--wine64]\n";
2536 print STDERR
" work_directory|project_file|workspace_file\n";
2537 print STDERR
"\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2538 print STDERR
"the specified directory so that they can be compiled with Winelib. During this\n";
2539 print STDERR
"process it will modify and rename some of the files in that directory.\n";
2540 print STDERR
"\tPlease read the manual page before use.\n";
2544 target_init
(\
@global_settings);
2547 my $arg=shift @ARGV;
2549 if ($arg eq "--nobanner") {
2551 } elsif ($arg eq "--backup") {
2553 } elsif ($arg eq "--nobackup") {
2555 } elsif ($arg eq "--single-target") {
2556 $opt_single_target=shift @ARGV;
2557 } elsif ($arg eq "--lower-none") {
2558 $opt_lower=$OPT_LOWER_NONE;
2559 } elsif ($arg eq "--lower-all") {
2560 $opt_lower=$OPT_LOWER_ALL;
2561 } elsif ($arg eq "--lower-uppercase") {
2562 $opt_lower=$OPT_LOWER_UPPERCASE;
2563 } elsif ($arg eq "--lower-include") {
2564 $opt_lower_include=1;
2565 } elsif ($arg eq "--nolower-include") {
2566 $opt_lower_include=0;
2567 } elsif ($arg eq "--nosource-fix") {
2568 $opt_no_source_fix=1;
2569 } elsif ($arg eq "--generated-files") {
2570 $opt_no_generated_files=0;
2571 } elsif ($arg eq "--nogenerated-files") {
2572 $opt_no_generated_files=1;
2573 } elsif ($arg eq "--wine64") {
2574 $opt_arch=$OPT_ARCH_64;
2575 } elsif ($arg =~ /^-D/) {
2576 push @
{$global_settings[$T_DEFINES]},$arg;
2577 } elsif ($arg =~ /^-I/) {
2578 push @
{$global_settings[$T_INCLUDE_PATH]},$arg;
2579 } elsif ($arg =~ /^-P/) {
2580 push @
{$global_settings[$T_DLL_PATH]},"-L$'";
2581 } elsif ($arg =~ /^-i/) {
2582 push @
{$global_settings[$T_DLLS]},$';
2583 } elsif ($arg =~ /^-L/) {
2584 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2585 } elsif ($arg =~ /^-l/) {
2586 push @{$global_settings[$T_LIBRARIES]},$';
2588 # 'Source'-based method options
2589 } elsif ($arg eq "--dll") {
2590 $opt_target_type=$TT_DLL;
2591 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2592 $opt_target_type=$TT_GUIEXE;
2593 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2594 $opt_target_type=$TT_CUIEXE;
2595 } elsif ($arg eq "--interactive") {
2596 $opt_is_interactive=$OPT_ASK_YES;
2597 $opt_ask_project_options=$OPT_ASK_YES;
2598 $opt_ask_target_options=$OPT_ASK_YES;
2599 } elsif ($arg eq "--mfc") {
2600 $opt_flags|=$TF_MFC;
2601 } elsif ($arg eq "--nomfc") {
2602 $opt_flags&=~$TF_MFC;
2603 $opt_flags|=$TF_NOMFC;
2604 } elsif ($arg eq "--nodlls") {
2605 $opt_flags|=$TF_NODLLS;
2606 } elsif ($arg eq "--nomsvcrt") {
2607 $opt_flags|=$TF_NOMSVCRT;
2611 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2612 if (!defined $opt_work_dir and !defined $opt_work_file) {
2614 $opt_work_file=$arg;
2620 print STDERR
"error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2629 if (!defined $opt_work_dir and !defined $opt_work_file) {
2630 print STDERR
"error: you must specify the directory or project file containing the sources to be converted\n";
2632 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2633 print STDERR
"error: could not chdir to the work directory\n";
2634 print STDERR
" $!\n";
2638 if ($opt_no_banner == 0) {
2642 project_init
(\
@main_project, "", \
@global_settings);
2644 # Fix the file and directory names
2645 fix_file_and_directory_names
(".");
2647 # Scan the sources to identify the projects and targets
2650 # Fix the source files
2651 if (! $opt_no_source_fix) {
2655 # Generate the Makefile and the spec file
2656 if (! $opt_no_generated_files) {