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
70 # This is the directory in which winemaker will operate.
74 # This is the file in which winemaker will operate if a project file is specified.
78 # Make a backup of the files
82 # Defines which files to rename
86 # If we don't find the file referenced by an include, lower it
87 my $opt_lower_include;
90 # If true then winemaker should not attempt to fix the source. This is
91 # useful if the source is known to be already in a suitable form and is
93 my $opt_no_source_fix;
95 # Options for the 'Source' method
98 # Specifies that we have only one target so that all sources relate
99 # to this target. By default this variable is left undefined which
100 # means winemaker should try to find out by itself what the targets
101 # are. If not undefined then this contains the name of the default
102 # target (without the extension).
103 my $opt_single_target;
106 # If '$opt_single_target' has been specified then this is the type of
107 # that target. Otherwise it specifies whether the default target type
108 # is guiexe or cuiexe.
112 # Contains the default set of flags to be used when creating a new target.
116 # If true then winemaker should ask questions to the user as it goes
118 my $opt_is_interactive;
119 my $opt_ask_project_options;
120 my $opt_ask_target_options;
123 # If false then winemaker should not generate the makefiles.
124 my $opt_no_generated_files;
127 # Specifies not to print the banner if set.
134 # Target modelization
138 # The description of a target is stored in an array. The constants
139 # below identify what is stored at each index of the array.
142 # This is the name of the target.
146 # Defines the type of target we want to build. See the TT_xxx
151 # This is a bitfield containing flags refining the way the target
152 # should be handled. See the TF_xxx constants below
156 # This is a reference to an array containing the list of the
157 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
161 my $T_SOURCES_MISC=6;
164 # This is a reference to an array containing the list of
169 # This is a reference to an array containing the list of
170 # C++ compiler options
174 # This is a reference to an array containing the list of
175 # RC compiler options
179 # This is a reference to an array containing the list of macro
184 # This is a reference to an array containing the list of directory
185 # names that constitute the include path
186 my $T_INCLUDE_PATH=11;
189 # Flags for the linker
193 # Same as T_INCLUDE_PATH but for the dll search path
197 # The list of Windows dlls to import
201 # Same as T_INCLUDE_PATH but for the library search path
202 my $T_LIBRARY_PATH=15;
205 # The list of Unix libraries to link with
209 # The list of dependencies between targets
213 # The following constants define the recognized types of target
216 # This is not a real target. This type of target is used to collect
217 # the sources that don't seem to belong to any other target. Thus no
218 # real target is generated for them, we just put the sources of the
219 # fake target in the global source list.
223 # For executables in the windows subsystem
227 # For executables in the console subsystem
231 # For dynamically linked libraries
235 # The following constants further refine how the target should be handled
238 # This target is an MFC-based target
242 # User has specified --nomfc option for this target or globally
246 # --nodlls option: Do not use standard DLL set
250 # --nomsvcrt option: Do not link with msvcrt
254 # Initialize a target:
255 # - set the target type to TT_SETTINGS, i.e. no real target will
261 @$target[$T_TYPE]=$TT_SETTINGS;
262 # leaving $T_INIT undefined
263 @$target[$T_FLAGS]=$opt_flags;
264 @$target[$T_SOURCES_C]=[];
265 @$target[$T_SOURCES_CXX]=[];
266 @$target[$T_SOURCES_RC]=[];
267 @$target[$T_SOURCES_MISC]=[];
268 @$target[$T_CEXTRA]=[];
269 @$target[$T_CXXEXTRA]=[];
270 @$target[$T_RCEXTRA]=[];
271 @$target[$T_DEFINES]=[];
272 @$target[$T_INCLUDE_PATH]=[];
273 @$target[$T_LDFLAGS]=[];
274 @$target[$T_DLL_PATH]=[];
275 @$target[$T_DLLS]=[];
276 @$target[$T_LIBRARY_PATH]=[];
277 @$target[$T_LIBRARIES]=[];
284 # Project modelization
288 # First we have the notion of project. A project is described by an
289 # array (since we don't have structs in perl). The constants below
290 # identify what is stored at each index of the array.
293 # This is the path in which this project is located. In other
294 # words, this is the path to the Makefile.
298 # This index contains a reference to an array containing the project-wide
299 # settings. The structure of that arrray is actually identical to that of
300 # a regular target since it can also contain extra sources.
304 # This index contains a reference to an array of targets for this
305 # project. Each target describes how an executable or library is to
306 # be built. For each target this description takes the same form as
307 # that of the project: an array. So this entry is an array of arrays.
311 # Initialize a project:
312 # - set the project's path
313 # - initialize the target list
314 # - create a default target (will be removed later if unnecessary)
315 sub project_init($$$)
317 my ($project, $path, $global_settings)=@_;
319 my $project_settings=[];
320 target_init($project_settings);
321 @$project_settings[$T_DEFINES]=[@{@$global_settings[$T_DEFINES]}];
322 @$project_settings[$T_INCLUDE_PATH]=[@{@$global_settings[$T_INCLUDE_PATH]}];
323 @$project_settings[$T_DLL_PATH]=[@{@$global_settings[$T_DLL_PATH]}];
324 @$project_settings[$T_DLLS]=[@{@$global_settings[$T_DLLS]}];
325 @$project_settings[$T_LIBRARY_PATH]=[@{@$global_settings[$T_LIBRARY_PATH]}];
326 @$project_settings[$T_LIBRARIES]=[@{@$global_settings[$T_LIBRARIES]}];
328 @$project[$P_PATH]=$path;
329 @$project[$P_SETTINGS]=$project_settings;
330 @$project[$P_TARGETS]=[];
346 # This maps a directory name to a reference to an array listing
347 # its contents (files and directories)
351 # Contains the list of all projects. This list tells us what are
352 # the subprojects of the main Makefile and where we have to generate
357 # This is the main project, i.e. the one in the "." directory.
358 # It may well be empty in which case the main Makefile will only
359 # call out subprojects.
363 # Contains the defaults for the include path, etc.
364 # We store the defaults as if this were a target except that we only
365 # exploit the defines, include path, library path, library list and misc
378 # Cleans up a name to make it an acceptable Makefile
384 $name =~ tr/a-zA-Z0-9_/_/c;
389 # Returns true is the specified pathname is absolute.
390 # Note: pathnames that start with a variable '$' or
391 # '~' are considered absolute.
396 return ($path =~ /^[\/~\$]/);
400 # Retrieves the contents of the specified directory.
401 # We either get it from the directories hashtable which acts as a
402 # cache, or use opendir, readdir, closedir and store the result
404 sub get_directory_contents($)
409 #print "getting the contents of $dirname\n";
411 # check for a cached version
413 if ($dirname eq "") {
416 $directory=$directories{$dirname};
417 if (defined $directory) {
418 #print "->@$directory\n";
422 # Read this directory
423 if (opendir(DIRECTORY, "$dirname")) {
424 my @files=readdir DIRECTORY;
428 # Return an empty list
429 #print "error: cannot open $dirname\n";
433 #print "->@$directory\n";
434 $directories{$dirname}=$directory;
439 # Removes a directory from the cache.
440 # This is needed if one of its files or subdirectory has been renamed.
441 sub clear_directory_cache($)
444 delete $directories{$dirname};
450 # 'Source'-based Project analysis
455 # Allows the user to specify makefile and target specific options
456 # - target: the structure in which to store the results
457 # - options: the string containing the options
458 sub source_set_options($$)
463 #FIXME: we must deal with escaping of stuff and all
464 foreach my $option (split / /,$options) {
465 if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
466 push @{@$target[$T_DEFINES]},$option;
467 } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
468 push @{@$target[$T_INCLUDE_PATH]},$option;
469 } elsif ($option =~ /^-P/) {
470 push @{@$target[$T_DLL_PATH]},"-L$'";
471 } elsif ($option =~ /^-i/) {
472 push @{@$target[$T_DLLS]},"$'";
473 } elsif ($option =~ /^-L/) {
474 push @{@$target[$T_LIBRARY_PATH]},$option;
475 } elsif ($option =~ /^-l/) {
476 push @{@$target[$T_LIBRARIES]},"$'";
477 } elsif ($option =~ /^--mfc/) {
478 @$target[$T_FLAGS]|=$TF_MFC;
479 @$target[$T_FLAGS]&=~$TF_NOMFC;
480 } elsif ($option =~ /^--nomfc/) {
481 @$target[$T_FLAGS]&=~$TF_MFC;
482 @$target[$T_FLAGS]|=$TF_NOMFC;
483 } elsif ($option =~ /^--nodlls/) {
484 @$target[$T_FLAGS]|=$TF_NODLLS;
485 } elsif ($option =~ /^--nomsvcrt/) {
486 @$target[$T_FLAGS]|=$TF_NOMSVCRT;
488 print STDERR "error: unknown option \"$option\"\n";
496 # Scans the specified project file to:
497 # - get a list of targets for this project
498 # - get some settings
499 # - get the list of source files
500 sub source_scan_project_file($$$);
501 sub source_scan_project_file($$$)
503 # a reference to the parent's project
504 my $parent_project=$_[0];
505 # 0 if it is a single project, 1 if it is part of a workspace
506 my $is_sub_project=$_[1];
507 # the name of the project file, with complete path, or without if in
511 # reference to the project for this file. May not be used
513 # list of targets found in the current file
515 # list of sources found in the current file
521 my $path=dirname($filename);
522 my $prj_target_cflags;
523 my $prj_target_ldflags;
528 my $prj_target_type=1;
529 my @prj_target_options;
531 if (!($path=~/\/$/)) {
535 if (defined $opt_single_target or $is_sub_project == 0) {
536 # Either there is a single target and thus a single project,
537 # or we are a single project-file for which a project
539 $project=$parent_project;
542 project_init($project, $path, \@global_settings);
544 my $project_settings=@$project[$P_SETTINGS];
546 if ($filename =~ /.dsp$/i) {
547 # First find out what this project file contains:
548 # collect all sources, find targets and settings
549 if (!open(FILEI,$filename)) {
550 print STDERR "error: unable to open $filename for reading:\n";
551 print STDERR " $!\n";
556 # Remove any trailing CtrlZ, which isn't strictly in the file
562 # Remove any trailing CrLf
565 # Make sure all lines are '\n' terminated
569 if (/^\# Microsoft Developer Studio Project File - Name=\"([^\"]+)/) {
571 $targets{$prj_name}=1;
574 } elsif (/^# TARGTYPE/) {
575 if (/[[:space:]]0x0101$/) {
576 # Win32 (x86) Application
578 }elsif (/[[:space:]]0x0102$/) {
579 # Win32 (x86) Dynamic-Link Library
581 }elsif (/[[:space:]]0x0103$/) {
582 # Win32 (x86) Console Application
584 }elsif (/[[:space:]]0x0104$/) {
585 # Win32 (x86) Static Library
588 } elsif (/^# ADD CPP(.*)/ && $found_cfg==1) {
589 $prj_target_cflags=$1;
590 @prj_target_options=split(" /", $prj_target_cflags);
591 $prj_target_cflags="";
592 foreach ( @prj_target_options ) {
596 # Suppress Startup Banner and Information Messages
598 # Turns off all warning messages
599 $prj_target_cflags.="-w ";
600 } elsif (/^W[123]$/) {
602 $prj_target_cflags.="-W ";
605 $prj_target_cflags.="-Wall ";
608 $prj_target_cflags.="-Werror ";
610 # Enable Minimal Rebuild
612 # Enable Exception Handling
613 $prj_target_cflags.="-fexceptions ";
614 } elsif (/^Z[d7iI]$/) {
616 $prj_target_cflags.="-g ";
618 # Disable Optimizations
619 $prj_target_cflags.="-O0 ";
622 $prj_target_cflags.="-Os ";
625 $prj_target_cflags.="-O2 ";
627 # Disables inline Expansion
628 $prj_target_cflags.="-fno-inline ";
630 #In-line Function Expansion
631 $prj_target_cflags.="-finline-functions ";
633 # auto In-line Function Expansion
634 $prj_target_cflags.="-finline-functions ";
636 # Use maximum optimization
637 $prj_target_cflags.="-O3 ";
639 # Frame-Pointer Omission
640 $prj_target_cflags.="-fomit-frame-pointer ";
642 # Frame-Pointer Omission
643 $prj_target_cflags.="-fno-omit-frame-pointer ";
645 # Catch Release-Build Errors in Debug Build
646 } elsif (/^M[DLT]d?$/) {
647 # Use Multithreaded Run-Time Library
648 } elsif (/^D\s*\"(.*)\"/) {
649 # Preprocessor Definitions
650 $prj_target_cflags.="-D".$1." ";
652 # Additional Include Directories
653 #$prj_target_cflags.="-I" fixpath(option)
654 } elsif (/^U\s*\"(.*)\"/) {
655 # Undefines a previously defined symbol
656 $prj_target_cflags.="-U".$1." ";
662 # Automatic Use of Precompiled Headers
664 # Generate File Dependencies
666 # Compile Without Linking
667 # this option is always present and is already specified in the suffix rules
670 $prj_target_cflags.="-mcpu=pentiumpro -D_M_IX86=500 ";
672 # Pentium Pro Optimization
673 $prj_target_cflags.="-march=pentiumpro -D_M_IX86=600 ";
675 # Pentium Optimization
676 $prj_target_cflags.="-mcpu=pentium -D_M_IX86=500 ";
679 $prj_target_cflags.="-mcpu=i386 -D_M_IX86=300 ";
682 $prj_target_cflags.="-mcpu=i486 -D_M_IX86=400 ";
684 # Create Precompiled Header
686 # Use Precompiled Header
688 # Disable Language Extensions
689 $prj_target_cflags.="-ansi ";
691 # Enable Microsoft Extensions
692 } elsif (/^Zm[[:digit:]]+$/) {
693 # Specify Memory Allocation Limit
695 # Packs structures on 1-byte boundaries
696 $prj_target_cflags.="-fpack-struct ";
697 } elsif (/^Zp(2|4|8|16)$/) {
698 # Struct Member Alignment
699 $prj_target_cflags.="-fpack-struct=".$1;
701 print "C compiler option $_ not implemented\n";
705 #print "\nOptions: $prj_target_cflags\n";
707 } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
708 $prj_target_ldflags=$1;
709 @prj_target_options=split(" /", $prj_target_ldflags);
710 $prj_target_ldflags="";
711 $prj_target_libs=$prj_target_options[0];
712 #print "\n$prj_target_libs bevor\n";
713 $prj_target_libs=~s/\\/\//g;
714 $prj_target_libs=~s/\.lib//g;
715 $prj_target_libs=~s/\s+/ -l/g;
716 #print "\n$prj_target_libs after\n";
717 shift (@prj_target_options);
718 foreach ( @prj_target_options ) {
721 } elsif (/^base:(.*)/) {
723 $prj_target_ldflags.="--image-base ".$1." ";
724 } elsif (/^debug$/) {
725 # Generate Debug Info
729 } elsif (/^incremental:[[:alpha:]]+$/) {
731 } elsif (/^implib:/) {
732 # Name import library
733 } elsif (/^libpath:\"(.*)\"/) {
735 push @{@$project_settings[$T_DLL_PATH]},"-L$1";
736 } elsif (/^machine:[[:alnum:]]+$/) {
737 # Specify Target Platform
741 $prj_target_ldflags.="-Map ".$1." ";
743 $prj_target_ldflags.="-Map ".$prj_name.".map ";
745 } elsif (/^nologo$/) {
746 # Suppress Startup Banner and Information Messages
749 # may use it as Target?
750 } elsif (/^pdbtype:/) {
751 # Program Database Storage
752 } elsif (/^subsystem:/) {
754 } elsif (/^version:[[:digit:].]+$/) {
755 # Version Information
757 print "Linker option $_ not implemented\n";
761 } elsif (/^LIB32=/ && $found_cfg==1) {
764 } elsif (/^SOURCE=(.*)$/) {
765 my @components=split /[\/\\]+/, $1;
766 $sfilet=search_from($path, \@components);
767 if ($sfilet =~ /\.(exe|dll)$/i) {
769 } elsif ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
770 push @sources_c,$sfilet;
771 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
772 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
773 push @sources_misc,$sfilet;
774 @$project_settings[$T_FLAGS]|=$TF_MFC;
776 push @sources_cxx,$sfilet;
778 } elsif ($sfilet =~ /\.rc$/i) {
779 push @sources_rc,$sfilet;
780 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
781 push @sources_misc,$sfilet;
782 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
783 @$project_settings[$T_FLAGS]|=$TF_MFC;
788 } elsif (/^# (Begin|End) Source File/) {
789 # Source-Files already handled
791 } elsif (/^# (Begin|End) Group/) {
794 } elsif (/^# (Begin|End) Custom Build/) {
795 # Custom Builds are ignored
797 } elsif (/^# ADD LIB32 /) {
800 } elsif (/^# Begin Target$/) {
801 # Targets are ignored
803 } elsif (/^# End Target$/) {
804 # Targets are ignored
807 if ($found_cfg == 1) {
810 if (/if (.*)\(CFG\)" == "(.*)"/i) {
811 if ($2 eq $prj_cfg) {
816 } elsif (/^CFG=(.*)/i) {
820 else { # Line recognized
826 push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
827 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
828 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
829 push @{@$project_settings[$T_LDFLAGS]},$prj_target_ldflags;
830 } elsif ($filename =~ /.vcproj$/i) {
831 # Import des Moduls XML::Simple
834 my $project_xml = XMLin($filename, forcearray=>1);
836 $targets{$project_xml->{'Name'}.".exe"}=1;
838 for my $vc_files (@{$project_xml->{'Files'}}) {
839 for my $vc_filter (@{$vc_files->{'Filter'}}) {
840 for my $vc_file (@{$vc_filter->{'File'}}) {
841 $sfilet=$vc_file->{'RelativePath'};
842 $sfilet=~s/\\\\/\\/g; #remove double backslash
843 $sfilet=~s/^\.\\//; #remove starting 'this directory'
844 $sfilet=~s/\\/\//g; #make slashes out of backslashes
845 if ($sfilet =~ /\.(exe|dll)$/i) {
847 } elsif ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
848 push @sources_c,$sfilet;
849 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
850 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
851 push @sources_misc,$sfilet;
852 @$project_settings[$T_FLAGS]|=$TF_MFC;
854 push @sources_cxx,$sfilet;
856 } elsif ($sfilet =~ /\.rc$/i) {
857 push @sources_rc,$sfilet;
858 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
859 push @sources_misc,$sfilet;
860 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
861 @$project_settings[$T_FLAGS]|=$TF_MFC;
867 $prj_target_cflags="";
868 for my $vc_configurations (@{$project_xml->{'Configurations'}}) {
869 for my $vc_configuration (@{$vc_configurations->{'Configuration'}}) {
870 for my $vc_tool (@{$vc_configuration->{'Tool'}}) {
871 if ($vc_tool->{'Name'} ne 'VCCLCompilerTool') { next; }
872 if (defined $vc_tool->{'Optimization'}) {$prj_target_cflags.="-O".$vc_tool->{'Optimization'}." ";}
873 if (defined $vc_tool->{'WarningLevel'}) {
874 if ($vc_tool->{'WarningLevel'}==0) {
875 $prj_target_cflags.="-w ";
876 } elsif ($vc_tool->{'WarningLevel'}<4) {
877 $prj_target_cflags.="-W ";
878 } elsif ($vc_tool->{'WarningLevel'}==4) {
879 $prj_target_cflags.="-Wall ";
880 } elsif ($vc_tool->{'WarningLevel'} eq "X") {
881 $prj_target_cflags.="-Werror ";
884 if (defined $vc_tool->{'PreprocessorDefinitions'}) {
885 $vc_tool->{'PreprocessorDefinitions'}=~s/;/ -D/g;
886 $prj_target_cflags.="-D".$vc_tool->{'PreprocessorDefinitions'}." ";
888 if (defined $vc_tool->{'AdditionalIncludeDirectories'}) {
889 $vc_tool->{'AdditionalIncludeDirectories'}=~s/\\/\//g;
890 $vc_tool->{'AdditionalIncludeDirectories'}=~s/;/ -I/g;
891 push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$vc_tool->{'AdditionalIncludeDirectories'};
897 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
898 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
902 $target_count=keys %targets;
905 # Add this project to the project list, except for
906 # the main project which is already in the list.
907 if ($is_sub_project == 1) {
908 push @projects,$project;
911 # Ask for project-wide options
912 if ($opt_ask_project_options == $OPT_ASK_YES) {
914 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
917 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
918 if (defined $flag_desc) {
919 print "* (currently $flag_desc)\n";
921 print "* or 'skip' to skip the target specific options,\n";
922 print "* or 'never' to not be asked this question again:\n";
926 if ($options eq "skip") {
927 $opt_ask_target_options=$OPT_ASK_SKIP;
929 } elsif ($options eq "never") {
930 $opt_ask_project_options=$OPT_ASK_NO;
932 } elsif (source_set_options($project_settings,$options)) {
935 print "Please re-enter the options:\n";
939 # - Create the targets
940 # - Check if we have both libraries and programs
941 # - Match each target with source files (sort in reverse
942 # alphabetical order to get the longest matches first)
944 my @local_depends=();
946 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
947 # Create the target...
949 target_init($target);
950 @$target[$T_NAME]=$target_name;
951 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
952 if ($target_name =~ /\.dll$/) {
953 @$target[$T_TYPE]=$TT_DLL;
954 push @local_depends,"$target_name.so";
955 push @local_dlls,$target_name;
956 my $canon=canonize($target_name);
957 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
959 @$target[$T_TYPE]=$opt_target_type;
960 push @exe_list,$target;
961 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
963 my $basename=$target_name;
964 $basename=~ s/\.(dll|exe)$//i;
965 # This is the default link list of Visual Studio
966 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
967 my @std_libraries=qw(uuid);
968 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
969 @$target[$T_DLLS]=\@std_imports;
970 @$target[$T_LIBRARIES]=\@std_libraries;
972 @$target[$T_DLLS]=[];
973 @$target[$T_LIBRARIES]=[];
975 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
976 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
977 push @{@$target[$T_LDFLAGS]},"-m32";
979 push @{@$project[$P_TARGETS]},$target;
981 # Ask for target-specific options
982 if ($opt_ask_target_options == $OPT_ASK_YES) {
984 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
987 if ($flag_desc ne "") {
990 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
991 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
995 if ($options eq "never") {
996 $opt_ask_target_options=$OPT_ASK_NO;
998 } elsif (source_set_options($target,$options)) {
1001 print "Please re-enter the options:\n";
1004 if (@$target[$T_FLAGS] & $TF_MFC) {
1005 @$project_settings[$T_FLAGS]|=$TF_MFC;
1006 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1007 push @{@$target[$T_DLLS]},"mfc.dll";
1008 # FIXME: Link with the MFC in the Unix sense, until we
1009 # start exporting the functions properly.
1010 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1011 push @{@$target[$T_LIBRARIES]},"mfc";
1015 if ($target_count == 1) {
1016 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1017 @$project_settings[$T_SOURCES_C]=[];
1020 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1021 @$project_settings[$T_SOURCES_CXX]=[];
1024 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1025 @$project_settings[$T_SOURCES_RC]=[];
1028 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1029 # No need for sorting these sources
1030 @$project_settings[$T_SOURCES_MISC]=[];
1033 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1034 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1035 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1036 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1038 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1039 $opt_ask_target_options=$OPT_ASK_YES;
1042 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1043 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1044 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1047 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1048 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1050 # The sources that did not match, if any, go to the extra
1051 # source list of the project settings
1052 foreach my $source (@sources_c) {
1053 if ($source ne "") {
1054 push @{@$project_settings[$T_SOURCES_C]},$source;
1057 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1058 foreach my $source (@sources_cxx) {
1059 if ($source ne "") {
1060 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1063 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1064 foreach my $source (@sources_rc) {
1065 if ($source ne "") {
1066 push @{@$project_settings[$T_SOURCES_RC]},$source;
1069 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1070 foreach my $source (@sources_misc) {
1071 if ($source ne "") {
1072 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1075 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1079 # Scans the specified workspace file to find the project files
1080 sub source_scan_workspace_file($);
1081 sub source_scan_workspace_file($)
1084 my $path=dirname($filename);
1087 if (! -e $filename) {
1091 if (!open(FILEIWS,$filename)) {
1092 print STDERR "error: unable to open $filename for reading:\n";
1093 print STDERR " $!\n";
1100 if ($filename =~ /.dsw$/i) {
1102 # Remove any trailing CrLf
1105 # catch a project definition
1106 if (/^Project:\s\"(.*)\"=\"?(.*)\s-/) {
1110 @components=split /[\/\\]+/, $prj_path;
1111 $prj_path=search_from($path, \@components);
1112 print "Name: $prj_name\nPath: $prj_path\n";
1113 source_scan_project_file(\@main_project,1,$prj_path);
1118 print STDERR "unknown section $_\n";
1119 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1120 print "\nFileversion: $3\n";
1124 } elsif ($filename =~ /.sln$/i) {
1126 # Remove any trailing CrLf
1129 # catch a project definition
1130 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1133 @components=split /[\/\\]+/, $3;
1134 $prj_path=search_from($path, \@components);
1135 print "Name: $prj_name\nPath: $prj_path\n";
1136 source_scan_project_file(\@main_project,1,$prj_path);
1138 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1139 print "\nFileversion: $3\n";
1145 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1149 # Scans the specified directory to:
1150 # - see if we should create a Makefile in this directory. We normally do
1151 # so if we find a project file and sources
1152 # - get a list of targets for this directory
1153 # - get the list of source files
1154 sub source_scan_directory($$$$);
1155 sub source_scan_directory($$$$)
1157 # a reference to the parent's project
1158 my $parent_project=$_[0];
1159 # the full relative path to the current directory, including a
1160 # trailing '/', or an empty string if this is the top level directory
1162 # the name of this directory, including a trailing '/', or an empty
1163 # string if this is the top level directory
1165 # if set then no targets will be looked for and the sources will all
1166 # end up in the parent_project's 'misc' bucket
1167 my $no_target=$_[3];
1169 # reference to the project for this directory. May not be used
1171 # list of targets found in the 'current' directory
1173 # list of sources found in the current directory
1177 my @sources_misc=();
1178 # true if this directory contains a Windows project
1179 my $has_win_project=0;
1180 # true if this directory contains headers
1182 # If we don't find any executable/library then we might make up targets
1183 # from the list of .dsp/.mak files we find since they usually have the
1184 # same name as their target.
1188 if (defined $opt_single_target or $dirname eq "") {
1189 # Either there is a single target and thus a single project,
1190 # or we are in the top level directory for which a project
1192 $project=$parent_project;
1195 project_init($project, $path, \@global_settings);
1197 my $project_settings=@$project[$P_SETTINGS];
1199 # First find out what this directory contains:
1200 # collect all sources, targets and subdirectories
1201 my $directory=get_directory_contents($path);
1202 foreach my $dentry (@$directory) {
1203 if ($dentry =~ /^\./) {
1206 my $fullentry="$path$dentry";
1207 if (-d "$fullentry") {
1208 if ($dentry =~ /^(Release|Debug)/i) {
1209 # These directories are often used to store the object files and the
1210 # resulting executable/library. They should not contain anything else.
1211 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
1212 foreach my $candidate (@candidates) {
1213 $targets{$candidate}=1;
1215 } elsif ($dentry =~ /^include/i) {
1216 # This directory must contain headers we're going to need
1217 push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1218 source_scan_directory($project,"$fullentry/","$dentry/",1);
1220 # Recursively scan this directory. Any source file that cannot be
1221 # attributed to a project in one of the subdirectories will be
1222 # attributed to this project.
1223 source_scan_directory($project,"$fullentry/","$dentry/",$no_target);
1225 } elsif (-f "$fullentry") {
1226 if ($dentry =~ /\.(exe|dll)$/i) {
1227 $targets{$dentry}=1;
1228 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1229 push @sources_c,"$dentry";
1230 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
1231 if ($dentry =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1232 push @sources_misc,"$dentry";
1233 @$project_settings[$T_FLAGS]|=$TF_MFC;
1235 push @sources_cxx,"$dentry";
1237 } elsif ($dentry =~ /\.rc$/i) {
1238 push @sources_rc,"$dentry";
1239 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1241 push @sources_misc,"$dentry";
1242 if ($dentry =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1243 @$project_settings[$T_FLAGS]|=$TF_MFC;
1245 } elsif ($dentry =~ /\.dsp$/i) {
1246 push @dsp_files,"$dentry";
1248 } elsif ($dentry =~ /\.mak$/i) {
1249 push @mak_files,"$dentry";
1251 } elsif ($dentry =~ /^makefile/i) {
1258 push @{@$project_settings[$T_INCLUDE_PATH]},"-I.";
1260 # If we have a single target then all we have to do is assign
1261 # all the sources to it and we're done
1262 # FIXME: does this play well with the --interactive mode?
1263 if ($opt_single_target) {
1264 my $target=@{@$project[$P_TARGETS]}[0];
1265 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1266 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1267 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1268 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1272 my $parent_settings=@$parent_project[$P_SETTINGS];
1273 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1274 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1275 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1276 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1277 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1281 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1282 @{@$project_settings[$T_SOURCES_C]}+
1283 @{@$project_settings[$T_SOURCES_CXX]}+
1284 @{@$project_settings[$T_SOURCES_RC]};
1285 if ($source_count == 0) {
1286 # A project without real sources is not a project, get out!
1287 if ($project!=$parent_project) {
1288 my $parent_settings=@$parent_project[$P_SETTINGS];
1289 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1290 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1294 #print "targets=",%targets,"\n";
1295 #print "target_count=$target_count\n";
1296 #print "has_win_project=$has_win_project\n";
1297 #print "dirname=$dirname\n";
1300 if (($has_win_project != 0) or ($dirname eq "")) {
1301 # Deal with cases where we could not find any executable/library, and
1302 # thus have no target, although we did find some sort of windows project.
1303 $target_count=keys %targets;
1304 if ($target_count == 0) {
1305 # Try to come up with a target list based on .dsp/.mak files
1307 if (@dsp_files > 0) {
1308 $prj_list=\@dsp_files;
1310 $prj_list=\@mak_files;
1312 foreach my $filename (@$prj_list) {
1313 $filename =~ s/\.(dsp|mak)$//i;
1314 if ($opt_target_type == $TT_DLL) {
1315 $filename = "$filename.dll";
1317 $targets{$filename}=1;
1319 $target_count=keys %targets;
1320 if ($target_count == 0) {
1321 # Still nothing, try the name of the directory
1323 if ($dirname eq "") {
1324 # Bad luck, this is the top level directory!
1325 $name=(split /\//, cwd)[-1];
1328 # Remove the trailing '/'. Also eliminate whatever is after the last
1329 # '.' as it is likely to be meaningless (.orig, .new, ...)
1330 $name =~ s+(/|\.[^.]*)$++;
1331 if ($name eq "src") {
1332 # 'src' is probably a subdirectory of the real project directory.
1333 # Try again with the parent (if any).
1335 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
1338 $name=(split /\//, cwd)[-1];
1342 $name =~ s+(/|\.[^.]*)$++;
1343 if ($opt_target_type == $TT_DLL) {
1344 $name = canonize($name).".dll";
1346 $name = canonize($name).".exe";
1352 # Ask confirmation to the user if he wishes so
1353 if ($opt_is_interactive == $OPT_ASK_YES) {
1354 my $target_list=join " ",keys %targets;
1355 print "\n*** In ",($path?$path:"./"),"\n";
1356 print "* winemaker found the following list of (potential) targets\n";
1357 print "* $target_list\n";
1358 print "* Type enter to use it as is, your own comma-separated list of\n";
1359 print "* targets, 'none' to assign the source files to a parent directory,\n";
1360 print "* or 'ignore' to ignore everything in this directory tree.\n";
1361 print "* Target list:\n";
1362 $target_list=<STDIN>;
1364 if ($target_list eq "") {
1365 # Keep the target list as is, i.e. do nothing
1366 } elsif ($target_list eq "none") {
1367 # Empty the target list
1369 } elsif ($target_list eq "ignore") {
1370 # Ignore this subtree altogether
1374 foreach my $target (split /,/,$target_list) {
1375 $target =~ s+^\s*++;
1376 $target =~ s+\s*$++;
1377 $targets{$target}=1;
1383 # If we have no project at this level, then transfer all
1384 # the sources to the parent project
1385 $target_count=keys %targets;
1386 if ($target_count == 0) {
1387 if ($project!=$parent_project) {
1388 my $parent_settings=@$parent_project[$P_SETTINGS];
1389 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1390 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1391 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1392 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1393 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1398 # Otherwise add this project to the project list, except for
1399 # the main project which is already in the list.
1400 if ($dirname ne "") {
1401 push @projects,$project;
1404 # Ask for project-wide options
1405 if ($opt_ask_project_options == $OPT_ASK_YES) {
1407 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1410 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1411 if (defined $flag_desc) {
1412 print "* (currently $flag_desc)\n";
1414 print "* or 'skip' to skip the target specific options,\n";
1415 print "* or 'never' to not be asked this question again:\n";
1417 my $options=<STDIN>;
1419 if ($options eq "skip") {
1420 $opt_ask_target_options=$OPT_ASK_SKIP;
1422 } elsif ($options eq "never") {
1423 $opt_ask_project_options=$OPT_ASK_NO;
1425 } elsif (source_set_options($project_settings,$options)) {
1428 print "Please re-enter the options:\n";
1432 # - Create the targets
1433 # - Check if we have both libraries and programs
1434 # - Match each target with source files (sort in reverse
1435 # alphabetical order to get the longest matches first)
1437 my @local_depends=();
1439 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1440 # Create the target...
1442 target_init($target);
1443 @$target[$T_NAME]=$target_name;
1444 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
1445 if ($target_name =~ /\.dll$/) {
1446 @$target[$T_TYPE]=$TT_DLL;
1447 push @local_depends,"$target_name.so";
1448 push @local_dlls,$target_name;
1449 my $canon=canonize($target_name);
1450 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
1452 @$target[$T_TYPE]=$opt_target_type;
1453 push @exe_list,$target;
1454 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
1456 my $basename=$target_name;
1457 $basename=~ s/\.(dll|exe)$//i;
1458 # This is the default link list of Visual Studio
1459 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1460 my @std_libraries=qw(uuid);
1461 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1462 @$target[$T_DLLS]=\@std_imports;
1463 @$target[$T_LIBRARIES]=\@std_libraries;
1465 @$target[$T_DLLS]=[];
1466 @$target[$T_LIBRARIES]=[];
1468 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1469 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
1470 push @{@$target[$T_LDFLAGS]},"-m32";
1472 push @{@$project[$P_TARGETS]},$target;
1474 # Ask for target-specific options
1475 if ($opt_ask_target_options == $OPT_ASK_YES) {
1477 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
1480 if ($flag_desc ne "") {
1483 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1484 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1486 my $options=<STDIN>;
1488 if ($options eq "never") {
1489 $opt_ask_target_options=$OPT_ASK_NO;
1491 } elsif (source_set_options($target,$options)) {
1494 print "Please re-enter the options:\n";
1497 if (@$target[$T_FLAGS] & $TF_MFC) {
1498 @$project_settings[$T_FLAGS]|=$TF_MFC;
1499 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1500 push @{@$target[$T_DLLS]},"mfc.dll";
1501 # FIXME: Link with the MFC in the Unix sense, until we
1502 # start exporting the functions properly.
1503 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1504 push @{@$target[$T_LIBRARIES]},"mfc";
1508 if ($target_count == 1) {
1509 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1510 @$project_settings[$T_SOURCES_C]=[];
1513 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1514 @$project_settings[$T_SOURCES_CXX]=[];
1517 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1518 @$project_settings[$T_SOURCES_RC]=[];
1521 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1522 # No need for sorting these sources
1523 @$project_settings[$T_SOURCES_MISC]=[];
1526 foreach my $source (@sources_c) {
1527 if ($source =~ /^$basename/i) {
1528 push @{@$target[$T_SOURCES_C]},$source;
1532 foreach my $source (@sources_cxx) {
1533 if ($source =~ /^$basename/i) {
1534 push @{@$target[$T_SOURCES_CXX]},$source;
1538 foreach my $source (@sources_rc) {
1539 if ($source =~ /^$basename/i) {
1540 push @{@$target[$T_SOURCES_RC]},$source;
1544 foreach my $source (@sources_misc) {
1545 if ($source =~ /^$basename/i) {
1546 push @{@$target[$T_SOURCES_MISC]},$source;
1551 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1552 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1553 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1554 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1556 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1557 $opt_ask_target_options=$OPT_ASK_YES;
1560 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1561 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1562 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1565 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1566 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1568 # The sources that did not match, if any, go to the extra
1569 # source list of the project settings
1570 foreach my $source (@sources_c) {
1571 if ($source ne "") {
1572 push @{@$project_settings[$T_SOURCES_C]},$source;
1575 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1576 foreach my $source (@sources_cxx) {
1577 if ($source ne "") {
1578 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1581 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1582 foreach my $source (@sources_rc) {
1583 if ($source ne "") {
1584 push @{@$project_settings[$T_SOURCES_RC]},$source;
1587 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1588 foreach my $source (@sources_misc) {
1589 if ($source ne "") {
1590 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1593 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1595 # Finally if we are building both libraries and programs in
1596 # this directory, then the programs should be linked with all
1598 if (@local_dlls > 0 and @exe_list > 0) {
1599 foreach my $target (@exe_list) {
1600 push @{@$target[$T_DLL_PATH]},"-L.";
1601 push @{@$target[$T_DLLS]},@local_dlls;
1607 # Scan the source directories in search of things to build
1610 # If there's a single target then this is going to be the default target
1611 if (defined $opt_single_target) {
1612 # Create the main target
1614 target_init($main_target);
1615 @$main_target[$T_NAME]=$opt_single_target;
1616 @$main_target[$T_TYPE]=$opt_target_type;
1618 # Add it to the list
1619 push @{$main_project[$P_TARGETS]},$main_target;
1622 # The main directory is always going to be there
1623 push @projects,\@main_project;
1625 if (defined $opt_work_dir) {
1626 # Now scan the directory tree looking for source files and, maybe, targets
1627 print "Scanning the source directories...\n";
1628 source_scan_directory(\@main_project,"","",0);
1629 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1630 } elsif (defined $opt_work_file) {
1631 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1632 source_scan_project_file(\@main_project,0,$opt_work_file);
1633 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1634 source_scan_workspace_file($opt_work_file);
1646 # Performs a directory traversal and renames the files so that:
1647 # - they have the case desired by the user
1648 # - their extension is of the appropriate case
1649 # - they don't contain annoying characters like ' ', '$', '#', ...
1650 # But only perform these changes for source files and directories.
1651 sub fix_file_and_directory_names($);
1652 sub fix_file_and_directory_names($)
1656 my $directory=get_directory_contents($dirname);
1657 foreach my $dentry (@$directory)
1659 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1662 # Set $warn to 1 if the user should be warned of the renaming
1664 my $new_name=$dentry;
1666 if (-f "$dirname/$dentry")
1668 # Don't rename Winemaker's makefiles
1669 next if ($dentry eq "Makefile" and
1670 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker/);
1672 # Leave non-source files alone
1673 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc))$/i);
1675 # Only all lowercase extensions are supported (because of
1676 # rules like '.c.o:'.
1677 $new_name =~ s/\.C$/.c/;
1678 $new_name =~ s/\.cpp$/.cpp/i;
1679 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1680 $new_name =~ s/\.rc$/.rc/i;
1681 # And this last one is to avoid confusion then running make
1682 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1685 # Adjust the case to the user's preferences
1686 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1687 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1689 $new_name=lc $new_name;
1692 # autoconf and make don't support these characters well
1693 $new_name =~ s/[ \$]/_/g;
1695 # And finally, perform the renaming
1696 if ($new_name ne $dentry)
1699 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1701 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1702 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1703 print STDERR " $!\n";
1708 clear_directory_cache($dirname);
1711 if (-d "$dirname/$new_name") {
1712 fix_file_and_directory_names("$dirname/$new_name");
1726 # Try to find a file for the specified filename. The attempt is
1727 # case-insensitive which is why it's not trivial. If a match is
1728 # found then we return the pathname with the correct case.
1735 if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
1737 } elsif ($dirname !~ m+^/+) {
1738 $dirname=cwd . "/" . $dirname;
1740 if ($dirname !~ m+/$+) {
1744 foreach my $component (@$path) {
1745 #print " looking for $component in \"$dirname\"\n";
1746 if ($component eq ".") {
1749 } elsif ($component eq "..") {
1751 $dirname=dirname($dirname) . "/";
1754 # The file/directory may have been renamed before. Also try to
1755 # match the renamed file.
1756 my $renamed=$component;
1757 $renamed =~ s/[ \$]/_/g;
1758 if ($renamed eq $component) {
1762 my $directory=get_directory_contents $dirname;
1764 foreach my $dentry (@$directory) {
1765 if ($dentry =~ /^\Q$component\E$/i or
1766 (defined $renamed and $dentry =~ /^$renamed$/i)
1768 $dirname.="$dentry/";
1769 $real_path.="$dentry/";
1774 if (!defined $found) {
1776 #print " could not find $component in $dirname\n";
1781 $real_path=~ s+/$++;
1782 #print " -> found $real_path\n";
1787 # Performs a case-insensitive search for the specified file in the
1789 # $line is the line number that should be referenced when an error occurs
1790 # $filename is the file we are looking for
1791 # $dirname is the directory of the file containing the '#include' directive
1792 # if '"' was used, it is an empty string otherwise
1793 # $project and $target specify part of the include path
1794 sub get_real_include_name($$$$$)
1802 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1803 # This is not a relative path, we cannot make any check
1804 my $warning="path:$filename";
1805 if (!defined $warnings{$warning}) {
1806 $warnings{$warning}="1";
1807 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1808 print STDERR "$line: $filename\n";
1811 # Here's how we proceed:
1812 # - split the filename we look for into its components
1813 # - then for each directory in the include path
1814 # - trace the directory components starting from that directory
1815 # - if we fail to find a match at any point then continue with
1816 # the next directory in the include path
1817 # - otherwise, rejoice, our quest is over.
1818 my @file_components=split /[\/\\]+/, $filename;
1819 #print " Searching for $filename from @$project[$P_PATH]\n";
1822 if ($dirname ne "") {
1823 # This is an 'include ""' -> look in dirname first.
1824 #print " in $dirname (include \"\")\n";
1825 $real_filename=search_from($dirname,\@file_components);
1826 if (defined $real_filename) {
1827 return $real_filename;
1830 my $project_settings=@$project[$P_SETTINGS];
1831 foreach my $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1832 my $dirname=$include;
1834 if (!is_absolute($dirname)) {
1835 $dirname="@$project[$P_PATH]$dirname";
1837 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1838 $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
1840 #print " in $dirname\n";
1841 $real_filename=search_from("$dirname",\@file_components);
1842 if (defined $real_filename) {
1843 return $real_filename;
1846 my $dotdotpath=@$project[$P_PATH];
1847 $dotdotpath =~ s/[^\/]+/../g;
1848 foreach my $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1849 my $dirname=$include;
1851 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1852 $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
1853 #print " in $dirname (global setting)\n";
1854 $real_filename=search_from("$dirname",\@file_components);
1855 if (defined $real_filename) {
1856 return $real_filename;
1860 $filename =~ s+\\\\+/+g; # in include ""
1861 $filename =~ s+\\+/+g; # in include <> !
1862 if ($opt_lower_include) {
1863 return lc "$filename";
1874 if ($size =~ /^(1|2|4|8)$/) {
1875 print FILEO "$indent#include <pshpack$size.h>$trailer";
1877 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1878 print FILEO "$indent#include <pshpack4.h>$trailer";
1883 # 'Parses' a source file and fixes constructs that would not work with
1884 # Winelib. The parsing is rather simple and not all non-portable features
1885 # are corrected. The most important feature that is corrected is the case
1886 # and path separator of '#include' directives. This requires that each
1887 # source file be associated to a project & target so that the proper
1888 # include path is used.
1889 # Also note that the include path is relative to the directory in which the
1890 # compiler is run, i.e. that of the project, not to that of the file.
1896 $filename="@$project[$P_PATH]$filename";
1897 if (! -e $filename) {
1901 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1902 my $dirname=dirname($filename);
1904 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1908 print " $filename\n";
1909 #FIXME:assuming that because there is a .bak file, this is what we want is
1910 #probably flawed. Or is it???
1911 if (! -e "$filename.bak") {
1912 if (!copy("$filename","$filename.bak")) {
1913 print STDERR "error: unable to make a backup of $filename:\n";
1914 print STDERR " $!\n";
1918 if (!open(FILEI,"$filename.bak")) {
1919 print STDERR "error: unable to open $filename.bak for reading:\n";
1920 print STDERR " $!\n";
1923 if (!open(FILEO,">$filename")) {
1924 print STDERR "error: unable to open $filename for writing:\n";
1925 print STDERR " $!\n";
1930 my $rc_block_depth=0;
1931 my $rc_textinclude_state=0;
1934 # Remove any trailing CtrlZ, which isn't strictly in the file
1942 # Make sure all files are '\n' terminated
1945 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
1946 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1947 # the RC files it generates (even in non-MFC projects). So we replace
1948 # it with 'winresrc.h' its very close standard cousin so that non MFC
1949 # projects can compile in Wine without the MFC sources.
1950 my $warning="mfc:afxres.h";
1951 if (!defined $warnings{$warning}) {
1952 $warnings{$warning}="1";
1953 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
1954 print STDERR "warning: the above warning is issued only once\n";
1956 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
1957 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
1958 print FILEO "$1$2\"winresrc.h\"$'";
1961 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1962 my $from_file=($2 eq "<"?"":$dirname);
1963 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1964 print FILEO "$1$2$real_include_name$4$'";
1965 $modified|=($real_include_name ne $3);
1967 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
1968 # Pragma pack handling
1970 # pack_stack is an array of references describing the stack of
1971 # pack directives currently in effect. Each directive if described
1972 # by a reference to an array containing:
1973 # - "push" for pack(push,...) directives, "" otherwise
1974 # - the directive's identifier at index 1
1975 # - the directive's alignment value at index 2
1977 # Don't believe a word of what the documentation says: it's all wrong.
1978 # The code below is based on the actual behavior of Visual C/C++ 6.
1983 # Pushes the default stack alignment
1984 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1985 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1986 print_pack($pack_indent,4,$');
1987 push @pack_stack, [ "", "", 4 ];
1989 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
1991 # pragma pack(pop,n)
1992 # Goes up the stack until it finds a pack(push,...), and pops it
1993 # Ignores any pack(n) entry
1994 # Issues a warning if the pack is of the form pack(push,label)
1995 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1996 my $pack_comment=$';
1997 $pack_comment =~ s/^\s*//;
1998 if ($pack_comment ne "") {
1999 print FILEO "$pack_indent$pack_comment";
2002 my $alignment=pop @pack_stack;
2003 if (!defined $alignment) {
2004 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2007 if (@$alignment[1]) {
2008 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2010 print FILEO "$pack_indent#include <poppack.h>\n";
2011 if (@$alignment[0]) {
2016 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2017 # pragma pack(pop,label[,n])
2018 # Goes up the stack until finding a pack(push,...) and pops it.
2019 # 'n', if specified, is ignored.
2020 # Ignores any pack(n) entry
2021 # Issues a warning if the label of the pack does not match,
2022 # or if it is in fact a pack(push,n)
2024 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2025 my $pack_comment=$';
2026 $pack_comment =~ s/^\s*//;
2027 if ($pack_comment ne "") {
2028 print FILEO "$pack_indent$pack_comment";
2031 my $alignment=pop @pack_stack;
2032 if (!defined $alignment) {
2033 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2036 if (@$alignment[1] and @$alignment[1] ne $label) {
2037 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2039 print FILEO "$pack_indent#include <poppack.h>\n";
2040 if (@$alignment[0]) {
2045 } elsif (/^(push\s*\))/) {
2047 # Push the current alignment
2048 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2049 if (@pack_stack > 0) {
2050 my $alignment=$pack_stack[$#pack_stack];
2051 print_pack($pack_indent,@$alignment[2],$');
2052 push @pack_stack, [ "push", "", @$alignment[2] ];
2054 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2055 print_pack($pack_indent,4,$');
2056 push @pack_stack, [ "push", "", 4 ];
2059 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2060 # pragma pack([push,]n)
2061 # Push new alignment n
2062 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2063 print_pack($pack_indent,$3,"$'");
2064 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2066 } elsif (/^((\w+)\s*\))/) {
2067 # pragma pack(label)
2068 # label must in fact be a macro that resolves to an integer
2069 # Then behaves like 'pragma pack(n)'
2070 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2071 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2072 print_pack($pack_indent,4,$');
2073 push @pack_stack, [ "", "", 4 ];
2075 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2076 # pragma pack(push,label[,n])
2077 # Pushes a new label on the stack. It is possible to push the same
2078 # label multiple times. If 'n' is omitted then the alignment is
2079 # unchanged. Otherwise it becomes 'n'.
2080 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2084 } elsif (@pack_stack > 0) {
2085 my $alignment=$pack_stack[$#pack_stack];
2086 $size=@$alignment[2];
2088 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2091 print_pack($pack_indent,$size,$');
2092 push @pack_stack, [ "push", $2, $size ];
2095 # pragma pack(??? -> What's that?
2096 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2097 print FILEO "$pack_indent$pack_header$_";
2103 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]+)([\">]?)/) {
2104 my $from_file=($5 eq "<"?"":$dirname);
2105 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2106 print FILEO "$1$5$real_include_name$7$'";
2107 $modified|=($real_include_name ne $6);
2109 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2110 my $from_file=($2 eq "<"?"":$dirname);
2111 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2112 print FILEO "$1$2$real_include_name$4$'";
2113 $modified|=($real_include_name ne $3);
2115 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2116 $rc_textinclude_state=1;
2119 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2120 print FILEO "$1winresrc.h$2$'";
2123 } elsif (/^\s*BEGIN(\W.*)?$/) {
2124 $rc_textinclude_state|=2;
2128 } elsif (/^\s*END(\W.*)?$/) {
2129 $rc_textinclude_state=0;
2130 if ($rc_block_depth>0) {
2146 if ($opt_backup == 0 or $modified == 0) {
2147 if (!unlink("$filename.bak")) {
2148 print STDERR "error: unable to delete $filename.bak:\n";
2149 print STDERR " $!\n";
2155 # Analyzes each source file in turn to find and correct issues
2156 # that would cause it not to compile.
2159 print "Fixing the source files...\n";
2160 foreach my $project (@projects) {
2161 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2162 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2163 fix_file($source,$project,$target);
2178 # A convenience function to generate all the lists (defines,
2179 # C sources, C++ source, etc.) in the Makefile
2180 sub generate_list($$$;$)
2189 printf FILEO "%-22s=",$name;
2191 if (defined $list) {
2192 foreach my $item (@$list) {
2194 if (defined $data) {
2195 $value=&$data($item);
2201 print FILEO " $value";
2204 print FILEO " \\\n\t\t\t$value";
2215 # Generates a project's Makefile and all the target files
2216 sub generate_project_files($)
2219 my $project_settings=@$project[$P_SETTINGS];
2223 # Then sort the targets and separate the libraries from the programs
2224 foreach my $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
2225 if (@$target[$T_TYPE] == $TT_DLL) {
2226 push @dll_list,$target;
2228 push @exe_list,$target;
2231 @$project[$P_TARGETS]=[];
2232 push @{@$project[$P_TARGETS]}, @dll_list;
2233 push @{@$project[$P_TARGETS]}, @exe_list;
2235 if (!open(FILEO,">@$project[$P_PATH]Makefile")) {
2236 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2237 print STDERR " $!\n";
2241 print FILEO "### Generated by Winemaker $version\n";
2244 generate_list("SRCDIR",1,[ "." ]);
2245 if (@$project[$P_PATH] eq "") {
2246 # This is the main project. It is also responsible for recursively
2247 # calling the other projects
2248 generate_list("SUBDIRS",1,\@projects,sub
2250 if ($_[0] != \@main_project) {
2251 my $subdir=@{$_[0]}[$P_PATH];
2255 # Eliminating the main project by returning undefined!
2258 if (@{@$project[$P_TARGETS]} > 0) {
2259 generate_list("DLLS",1,\@dll_list,sub
2261 return @{$_[0]}[$T_NAME];
2263 generate_list("EXES",1,\@exe_list,sub
2265 return "@{$_[0]}[$T_NAME]";
2267 print FILEO "\n\n\n";
2269 print FILEO "### Common settings\n\n";
2270 # Make it so that the project-wide settings override the global settings
2271 generate_list("CEXTRA",1,@$project_settings[$T_CEXTRA]);
2272 generate_list("CXXEXTRA",1,@$project_settings[$T_CXXEXTRA]);
2273 generate_list("RCEXTRA",1,@$project_settings[$T_RCEXTRA]);
2274 generate_list("DEFINES",1,@$project_settings[$T_DEFINES]);
2275 generate_list("INCLUDE_PATH",1,@$project_settings[$T_INCLUDE_PATH]);
2276 generate_list("DLL_PATH",1,@$project_settings[$T_DLL_PATH]);
2277 generate_list("DLL_IMPORTS",1,@$project_settings[$T_DLLS]);
2278 generate_list("LIBRARY_PATH",1,@$project_settings[$T_LIBRARY_PATH]);
2279 generate_list("LIBRARIES",1,@$project_settings[$T_LIBRARIES]);
2282 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
2283 @{@$project_settings[$T_SOURCES_CXX]}+
2284 @{@$project_settings[$T_SOURCES_RC]};
2285 my $no_extra=($extra_source_count == 0);
2287 print FILEO "### Extra source lists\n\n";
2288 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
2289 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
2290 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
2292 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
2293 print FILEO "\n\n\n";
2296 # Iterate over all the targets...
2297 foreach my $target (@{@$project[$P_TARGETS]}) {
2298 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
2299 my $canon=canonize("@$target[$T_NAME]");
2302 generate_list("${canon}_MODULE",1,[@$target[$T_NAME]]);
2303 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
2304 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
2305 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
2306 generate_list("${canon}_LDFLAGS",1,@$target[$T_LDFLAGS]);
2307 generate_list("${canon}_DLL_PATH",1,@$target[$T_DLL_PATH]);
2308 generate_list("${canon}_DLLS",1,@$target[$T_DLLS]);
2309 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]);
2310 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]);
2312 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2313 print FILEO "\n\n\n";
2315 print FILEO "### Global source lists\n\n";
2316 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
2318 my $canon=canonize(@{$_[0]}[$T_NAME]);
2320 return "\$(${canon}_C_SRCS)";
2323 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
2325 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
2327 my $canon=canonize(@{$_[0]}[$T_NAME]);
2329 return "\$(${canon}_CXX_SRCS)";
2332 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2334 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
2336 my $canon=canonize(@{$_[0]}[$T_NAME]);
2338 return "\$(${canon}_RC_SRCS)";
2341 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2345 print FILEO "### Tools\n\n";
2346 print FILEO "CC = winegcc\n";
2347 print FILEO "CXX = wineg++\n";
2348 print FILEO "RC = wrc\n";
2351 print FILEO "### Generic targets\n\n";
2353 if (@$project[$P_PATH] eq "") {
2354 print FILEO " \$(SUBDIRS)";
2356 if (@{@$project[$P_TARGETS]} > 0) {
2357 print FILEO " \$(DLLS:%=%.so) \$(EXES:%=%.so)";
2360 print FILEO "### Build rules\n";
2362 print FILEO ".PHONY: all clean dummy\n";
2364 print FILEO "\$(SUBDIRS): dummy\n";
2365 print FILEO "\t\@cd \$\@ && \$(MAKE)\n";
2367 print FILEO "# Implicit rules\n";
2369 print FILEO ".SUFFIXES: .cpp .rc .res\n";
2370 print FILEO "DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2372 print FILEO ".c.o:\n";
2373 print FILEO "\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2375 print FILEO ".cpp.o:\n";
2376 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2378 print FILEO ".cxx.o:\n";
2379 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2381 print FILEO ".rc.res:\n";
2382 print FILEO "\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2384 print FILEO "# Rules for cleaning\n";
2386 print FILEO "CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2387 print FILEO " \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2389 print FILEO "clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2390 print FILEO "\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:.cpp=.o)\n";
2391 print FILEO "\t\$(RM) \$(DLLS:%=%.so) \$(EXES:%=%.so) \$(EXES:%.exe=%)\n";
2393 print FILEO "\$(SUBDIRS:%=%/__clean__): dummy\n";
2394 print FILEO "\tcd `dirname \$\@` && \$(MAKE) clean\n";
2396 print FILEO "\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2397 print FILEO "\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2400 if (@{@$project[$P_TARGETS]} > 0) {
2401 print FILEO "### Target specific build rules\n";
2402 print FILEO "DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2403 foreach my $target (@{@$project[$P_TARGETS]}) {
2404 my $canon=canonize("@$target[$T_NAME]");
2407 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS)\n";
2408 if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
2409 print FILEO "\t\$(CXX)";
2411 print FILEO "\t\$(CC)";
2413 print FILEO " \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2423 # This is where we finally generate files. In fact this method does not
2424 # do anything itself but calls the methods that do the actual work.
2427 print "Generating project files...\n";
2429 foreach my $project (@projects) {
2430 my $path=@$project[$P_PATH];
2437 generate_project_files($project);
2450 $opt_lower=$OPT_LOWER_UPPERCASE;
2451 $opt_lower_include=1;
2453 $opt_work_dir=undef;
2454 $opt_single_target=undef;
2455 $opt_target_type=$TT_GUIEXE;
2457 $opt_is_interactive=$OPT_ASK_NO;
2458 $opt_ask_project_options=$OPT_ASK_NO;
2459 $opt_ask_target_options=$OPT_ASK_NO;
2460 $opt_no_generated_files=0;
2461 $opt_no_source_fix=0;
2474 print "Winemaker $version\n";
2475 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2476 print "Copyright 2004 Dimitrie O. Paun\n";
2477 print "Copyright 2009 André Hentschel\n";
2483 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2484 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2485 print STDERR " [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2486 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2487 print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2488 print STDERR " [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2489 print STDERR " [--generated-files|--nogenerated-files]\n";
2490 print STDERR " work_directory|project_file|workspace_file\n";
2491 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2492 print STDERR "the specified directory so that they can be compiled with Winelib. During this\n";
2493 print STDERR "process it will modify and rename some of the files in that directory.\n";
2494 print STDERR "\tPlease read the manual page before use.\n";
2498 target_init(\@global_settings);
2501 my $arg=shift @ARGV;
2503 if ($arg eq "--nobanner") {
2505 } elsif ($arg eq "--backup") {
2507 } elsif ($arg eq "--nobackup") {
2509 } elsif ($arg eq "--single-target") {
2510 $opt_single_target=shift @ARGV;
2511 } elsif ($arg eq "--lower-none") {
2512 $opt_lower=$OPT_LOWER_NONE;
2513 } elsif ($arg eq "--lower-all") {
2514 $opt_lower=$OPT_LOWER_ALL;
2515 } elsif ($arg eq "--lower-uppercase") {
2516 $opt_lower=$OPT_LOWER_UPPERCASE;
2517 } elsif ($arg eq "--lower-include") {
2518 $opt_lower_include=1;
2519 } elsif ($arg eq "--nolower-include") {
2520 $opt_lower_include=0;
2521 } elsif ($arg eq "--nosource-fix") {
2522 $opt_no_source_fix=1;
2523 } elsif ($arg eq "--generated-files") {
2524 $opt_no_generated_files=0;
2525 } elsif ($arg eq "--nogenerated-files") {
2526 $opt_no_generated_files=1;
2527 } elsif ($arg =~ /^-D/) {
2528 push @{$global_settings[$T_DEFINES]},$arg;
2529 } elsif ($arg =~ /^-I/) {
2530 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2531 } elsif ($arg =~ /^-P/) {
2532 push @{$global_settings[$T_DLL_PATH]},"-L$'";
2533 } elsif ($arg =~ /^-i/) {
2534 push @{$global_settings[$T_DLLS]},$';
2535 } elsif ($arg =~ /^-L/) {
2536 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2537 } elsif ($arg =~ /^-l/) {
2538 push @{$global_settings[$T_LIBRARIES]},$';
2540 # 'Source'-based method options
2541 } elsif ($arg eq "--dll") {
2542 $opt_target_type=$TT_DLL;
2543 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2544 $opt_target_type=$TT_GUIEXE;
2545 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2546 $opt_target_type=$TT_CUIEXE;
2547 } elsif ($arg eq "--interactive") {
2548 $opt_is_interactive=$OPT_ASK_YES;
2549 $opt_ask_project_options=$OPT_ASK_YES;
2550 $opt_ask_target_options=$OPT_ASK_YES;
2551 } elsif ($arg eq "--mfc") {
2552 $opt_flags|=$TF_MFC;
2553 } elsif ($arg eq "--nomfc") {
2554 $opt_flags&=~$TF_MFC;
2555 $opt_flags|=$TF_NOMFC;
2556 } elsif ($arg eq "--nodlls") {
2557 $opt_flags|=$TF_NODLLS;
2558 } elsif ($arg eq "--nomsvcrt") {
2559 $opt_flags|=$TF_NOMSVCRT;
2563 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2564 if (!defined $opt_work_dir and !defined $opt_work_file) {
2566 $opt_work_file=$arg;
2572 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2581 if (!defined $opt_work_dir and !defined $opt_work_file) {
2582 print STDERR "error: you must specify the directory or project file containing the sources to be converted\n";
2584 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2585 print STDERR "error: could not chdir to the work directory\n";
2586 print STDERR " $!\n";
2590 if ($opt_no_banner == 0) {
2594 project_init(\@main_project, "", \@global_settings);
2596 # Fix the file and directory names
2597 fix_file_and_directory_names(".");
2599 # Scan the sources to identify the projects and targets
2602 # Fix the source files
2603 if (! $opt_no_source_fix) {
2607 # Generate the Makefile and the spec file
2608 if (! $opt_no_generated_files) {