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 des Moduls XML::Simple
851 my $project_xml = XMLin
($filename, forcearray
=>1);
853 $targets{$project_xml->{'Name'}.".exe"}=1;
855 for my $vc_files (@
{$project_xml->{'Files'}}) {
856 for my $vc_filter (@
{$vc_files->{'Filter'}}) {
857 for my $vc_file (@
{$vc_filter->{'File'}}) {
858 $sfilet=$vc_file->{'RelativePath'};
859 $sfilet=~s/\\\\/\\/g; #remove double backslash
860 $sfilet=~s/^\.\\//; #remove starting 'this directory'
861 $sfilet=~s/\\/\//g
; #make slashes out of backslashes
862 if ($sfilet =~ /\.(exe|dll)$/i) {
864 } elsif ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
865 push @sources_c,$sfilet;
866 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
867 if ($sfilet =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
868 push @sources_misc,$sfilet;
869 @
$project_settings[$T_FLAGS]|=$TF_MFC;
871 push @sources_cxx,$sfilet;
873 } elsif ($sfilet =~ /\.rc$/i) {
874 push @sources_rc,$sfilet;
875 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
876 push @sources_misc,$sfilet;
877 if ($sfilet =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
878 @
$project_settings[$T_FLAGS]|=$TF_MFC;
884 $prj_target_cflags="";
885 for my $vc_configurations (@
{$project_xml->{'Configurations'}}) {
886 for my $vc_configuration (@
{$vc_configurations->{'Configuration'}}) {
887 for my $vc_tool (@
{$vc_configuration->{'Tool'}}) {
888 if ($vc_tool->{'Name'} ne 'VCCLCompilerTool') { next; }
889 if (defined $vc_tool->{'Optimization'}) {$prj_target_cflags.="-O".$vc_tool->{'Optimization'}." ";}
890 if (defined $vc_tool->{'WarningLevel'}) {
891 if ($vc_tool->{'WarningLevel'}==0) {
892 $prj_target_cflags.="-w ";
893 } elsif ($vc_tool->{'WarningLevel'}<4) {
894 $prj_target_cflags.="-W ";
895 } elsif ($vc_tool->{'WarningLevel'}==4) {
896 $prj_target_cflags.="-Wall ";
897 } elsif ($vc_tool->{'WarningLevel'} eq "X") {
898 $prj_target_cflags.="-Werror ";
901 if (defined $vc_tool->{'PreprocessorDefinitions'}) {
902 $vc_tool->{'PreprocessorDefinitions'}=~s/;/ -D/g;
903 $prj_target_cflags.="-D".$vc_tool->{'PreprocessorDefinitions'}." ";
905 if (defined $vc_tool->{'AdditionalIncludeDirectories'}) {
906 $vc_tool->{'AdditionalIncludeDirectories'}=~s/\\/\//g
;
907 $vc_tool->{'AdditionalIncludeDirectories'}=~s/;/ -I/g;
908 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I".$vc_tool->{'AdditionalIncludeDirectories'};
914 push @
{@
$project_settings[$T_CEXTRA]},$prj_target_cflags;
915 push @
{@
$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
919 $target_count=keys %targets;
922 # Add this project to the project list, except for
923 # the main project which is already in the list.
924 if ($is_sub_project == 1) {
925 push @projects,$project;
928 # Ask for project-wide options
929 if ($opt_ask_project_options == $OPT_ASK_YES) {
931 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
934 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
935 if (defined $flag_desc) {
936 print "* (currently $flag_desc)\n";
938 print "* or 'skip' to skip the target specific options,\n";
939 print "* or 'never' to not be asked this question again:\n";
943 if ($options eq "skip") {
944 $opt_ask_target_options=$OPT_ASK_SKIP;
946 } elsif ($options eq "never") {
947 $opt_ask_project_options=$OPT_ASK_NO;
949 } elsif (source_set_options
($project_settings,$options)) {
952 print "Please re-enter the options:\n";
956 # - Create the targets
957 # - Check if we have both libraries and programs
958 # - Match each target with source files (sort in reverse
959 # alphabetical order to get the longest matches first)
961 my @local_depends=();
963 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
964 # Create the target...
966 target_init
($target);
967 @
$target[$T_NAME]=$target_name;
968 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
969 if ($target_name =~ /\.dll$/) {
970 @
$target[$T_TYPE]=$TT_DLL;
971 push @local_depends,"$target_name.so";
972 push @local_dlls,$target_name;
973 my $canon=canonize
($target_name);
974 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
976 @
$target[$T_TYPE]=$opt_target_type;
977 push @exe_list,$target;
978 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
980 my $basename=$target_name;
981 $basename=~ s/\.(dll|exe)$//i;
982 # This is the default link list of Visual Studio
983 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
984 my @std_libraries=qw(uuid);
985 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
986 @
$target[$T_DLLS]=\
@std_imports;
987 @
$target[$T_LIBRARIES]=\
@std_libraries;
989 @
$target[$T_DLLS]=[];
990 @
$target[$T_LIBRARIES]=[];
992 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
993 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
994 push @
{@
$target[$T_LDFLAGS]},"-m$opt_arch";
996 push @
{@
$project[$P_TARGETS]},$target;
998 # Ask for target-specific options
999 if ($opt_ask_target_options == $OPT_ASK_YES) {
1001 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
1004 if ($flag_desc ne "") {
1007 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1008 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1010 my $options=<STDIN
>;
1012 if ($options eq "never") {
1013 $opt_ask_target_options=$OPT_ASK_NO;
1015 } elsif (source_set_options
($target,$options)) {
1018 print "Please re-enter the options:\n";
1021 if (@
$target[$T_FLAGS] & $TF_MFC) {
1022 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1023 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1024 push @
{@
$target[$T_DLLS]},"mfc.dll";
1025 # FIXME: Link with the MFC in the Unix sense, until we
1026 # start exporting the functions properly.
1027 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1028 push @
{@
$target[$T_LIBRARIES]},"mfc";
1032 if ($target_count == 1) {
1033 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
1034 @
$project_settings[$T_SOURCES_C]=[];
1037 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1038 @
$project_settings[$T_SOURCES_CXX]=[];
1041 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
1042 @
$project_settings[$T_SOURCES_RC]=[];
1045 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
1046 # No need for sorting these sources
1047 @
$project_settings[$T_SOURCES_MISC]=[];
1050 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
1051 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
1052 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
1053 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
1055 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1056 $opt_ask_target_options=$OPT_ASK_YES;
1059 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1060 push @
{@
$project_settings[$T_CEXTRA]},"-mno-cygwin";
1061 push @
{@
$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1064 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
1065 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1067 # The sources that did not match, if any, go to the extra
1068 # source list of the project settings
1069 foreach my $source (@sources_c) {
1070 if ($source ne "") {
1071 push @
{@
$project_settings[$T_SOURCES_C]},$source;
1074 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
1075 foreach my $source (@sources_cxx) {
1076 if ($source ne "") {
1077 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
1080 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
1081 foreach my $source (@sources_rc) {
1082 if ($source ne "") {
1083 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
1086 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
1087 foreach my $source (@sources_misc) {
1088 if ($source ne "") {
1089 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
1092 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
1096 # Scans the specified workspace file to find the project files
1097 sub source_scan_workspace_file
($);
1098 sub source_scan_workspace_file
($)
1101 my $path=dirname
($filename);
1104 if (! -e
$filename) {
1108 if (!open(FILEIWS
,$filename)) {
1109 print STDERR
"error: unable to open $filename for reading:\n";
1110 print STDERR
" $!\n";
1117 if ($filename =~ /.dsw$/i) {
1119 # Remove any trailing CrLf
1122 # catch a project definition
1123 if (/^Project:\s\"(.*)\"=(.*)\s-/) {
1126 @components=split /[\/\\]+/, $prj_path;
1127 $prj_path=search_from
($path, \
@components);
1128 print "Name: $prj_name\nPath: $prj_path\n";
1129 source_scan_project_file
(\
@main_project,1,$prj_path);
1134 print STDERR
"unknown section $_\n";
1135 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1136 print "\nFileversion: $3\n";
1140 } elsif ($filename =~ /.sln$/i) {
1142 # Remove any trailing CrLf
1145 # catch a project definition
1146 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1149 @components=split /[\/\\]+/, $3;
1150 $prj_path=search_from
($path, \
@components);
1151 print "Name: $prj_name\nPath: $prj_path\n";
1152 source_scan_project_file
(\
@main_project,1,$prj_path);
1154 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1155 print "\nFileversion: $3\n";
1161 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
1165 # Scans the specified directory to:
1166 # - see if we should create a Makefile in this directory. We normally do
1167 # so if we find a project file and sources
1168 # - get a list of targets for this directory
1169 # - get the list of source files
1170 sub source_scan_directory
($$$$);
1171 sub source_scan_directory
($$$$)
1173 # a reference to the parent's project
1174 my $parent_project=$_[0];
1175 # the full relative path to the current directory, including a
1176 # trailing '/', or an empty string if this is the top level directory
1178 # the name of this directory, including a trailing '/', or an empty
1179 # string if this is the top level directory
1181 # if set then no targets will be looked for and the sources will all
1182 # end up in the parent_project's 'misc' bucket
1183 my $no_target=$_[3];
1185 # reference to the project for this directory. May not be used
1187 # list of targets found in the 'current' directory
1189 # list of sources found in the current directory
1193 my @sources_misc=();
1194 # true if this directory contains a Windows project
1195 my $has_win_project=0;
1196 # true if this directory contains headers
1198 # If we don't find any executable/library then we might make up targets
1199 # from the list of .dsp/.mak files we find since they usually have the
1200 # same name as their target.
1204 if (defined $opt_single_target or $dirname eq "") {
1205 # Either there is a single target and thus a single project,
1206 # or we are in the top level directory for which a project
1208 $project=$parent_project;
1211 project_init
($project, $path, \
@global_settings);
1213 my $project_settings=@
$project[$P_SETTINGS];
1215 # First find out what this directory contains:
1216 # collect all sources, targets and subdirectories
1217 my $directory=get_directory_contents
($path);
1218 foreach my $dentry (@
$directory) {
1219 if ($dentry =~ /^\./) {
1222 my $fullentry="$path$dentry";
1223 if (-d
"$fullentry") {
1224 if ($dentry =~ /^(Release|Debug)/i) {
1225 # These directories are often used to store the object files and the
1226 # resulting executable/library. They should not contain anything else.
1227 my @candidates=grep /\.(exe|dll)$/i, @
{get_directory_contents
("$fullentry")};
1228 foreach my $candidate (@candidates) {
1229 $targets{$candidate}=1;
1231 } elsif ($dentry =~ /^include/i) {
1232 # This directory must contain headers we're going to need
1233 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1234 source_scan_directory
($project,"$fullentry/","$dentry/",1);
1236 # Recursively scan this directory. Any source file that cannot be
1237 # attributed to a project in one of the subdirectories will be
1238 # attributed to this project.
1239 source_scan_directory
($project,"$fullentry/","$dentry/",$no_target);
1241 } elsif (-f
"$fullentry") {
1242 if ($dentry =~ /\.(exe|dll)$/i) {
1243 $targets{$dentry}=1;
1244 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1245 push @sources_c,"$dentry";
1246 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
1247 if ($dentry =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1248 push @sources_misc,"$dentry";
1249 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1251 push @sources_cxx,"$dentry";
1253 } elsif ($dentry =~ /\.rc$/i) {
1254 push @sources_rc,"$dentry";
1255 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1257 push @sources_misc,"$dentry";
1258 if ($dentry =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1259 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1261 } elsif ($dentry =~ /\.dsp$/i) {
1262 push @dsp_files,"$dentry";
1264 } elsif ($dentry =~ /\.mak$/i) {
1265 push @mak_files,"$dentry";
1267 } elsif ($dentry =~ /^makefile/i) {
1274 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I.";
1276 # If we have a single target then all we have to do is assign
1277 # all the sources to it and we're done
1278 # FIXME: does this play well with the --interactive mode?
1279 if ($opt_single_target) {
1280 my $target=@
{@
$project[$P_TARGETS]}[0];
1281 push @
{@
$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1282 push @
{@
$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1283 push @
{@
$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1284 push @
{@
$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1288 my $parent_settings=@
$parent_project[$P_SETTINGS];
1289 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1290 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1291 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1292 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1293 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1297 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1298 @
{@
$project_settings[$T_SOURCES_C]}+
1299 @
{@
$project_settings[$T_SOURCES_CXX]}+
1300 @
{@
$project_settings[$T_SOURCES_RC]};
1301 if ($source_count == 0) {
1302 # A project without real sources is not a project, get out!
1303 if ($project!=$parent_project) {
1304 my $parent_settings=@
$parent_project[$P_SETTINGS];
1305 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1306 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1310 #print "targets=",%targets,"\n";
1311 #print "target_count=$target_count\n";
1312 #print "has_win_project=$has_win_project\n";
1313 #print "dirname=$dirname\n";
1316 if (($has_win_project != 0) or ($dirname eq "")) {
1317 # Deal with cases where we could not find any executable/library, and
1318 # thus have no target, although we did find some sort of windows project.
1319 $target_count=keys %targets;
1320 if ($target_count == 0) {
1321 # Try to come up with a target list based on .dsp/.mak files
1323 if (@dsp_files > 0) {
1324 $prj_list=\
@dsp_files;
1326 $prj_list=\
@mak_files;
1328 foreach my $filename (@
$prj_list) {
1329 $filename =~ s/\.(dsp|mak)$//i;
1330 if ($opt_target_type == $TT_DLL) {
1331 $filename = "$filename.dll";
1333 $targets{$filename}=1;
1335 $target_count=keys %targets;
1336 if ($target_count == 0) {
1337 # Still nothing, try the name of the directory
1339 if ($dirname eq "") {
1340 # Bad luck, this is the top level directory!
1341 $name=(split /\//, cwd
)[-1];
1344 # Remove the trailing '/'. Also eliminate whatever is after the last
1345 # '.' as it is likely to be meaningless (.orig, .new, ...)
1346 $name =~ s
+(/|\
.[^.]*)$++;
1347 if ($name eq "src") {
1348 # 'src' is probably a subdirectory of the real project directory.
1349 # Try again with the parent (if any).
1351 if ($parent =~ s
+([^/]*)/[^/]*/$+$1+) {
1354 $name=(split /\//, cwd
)[-1];
1358 $name =~ s
+(/|\
.[^.]*)$++;
1359 if ($opt_target_type == $TT_DLL) {
1360 $name = canonize
($name).".dll";
1362 $name = canonize
($name).".exe";
1368 # Ask confirmation to the user if he wishes so
1369 if ($opt_is_interactive == $OPT_ASK_YES) {
1370 my $target_list=join " ",keys %targets;
1371 print "\n*** In ",($path?
$path:"./"),"\n";
1372 print "* winemaker found the following list of (potential) targets\n";
1373 print "* $target_list\n";
1374 print "* Type enter to use it as is, your own comma-separated list of\n";
1375 print "* targets, 'none' to assign the source files to a parent directory,\n";
1376 print "* or 'ignore' to ignore everything in this directory tree.\n";
1377 print "* Target list:\n";
1378 $target_list=<STDIN
>;
1380 if ($target_list eq "") {
1381 # Keep the target list as is, i.e. do nothing
1382 } elsif ($target_list eq "none") {
1383 # Empty the target list
1385 } elsif ($target_list eq "ignore") {
1386 # Ignore this subtree altogether
1390 foreach my $target (split /,/,$target_list) {
1391 $target =~ s
+^\s
*++;
1392 $target =~ s
+\s
*$++;
1393 $targets{$target}=1;
1399 # If we have no project at this level, then transfer all
1400 # the sources to the parent project
1401 $target_count=keys %targets;
1402 if ($target_count == 0) {
1403 if ($project!=$parent_project) {
1404 my $parent_settings=@
$parent_project[$P_SETTINGS];
1405 push @
{@
$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1406 push @
{@
$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1407 push @
{@
$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1408 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1409 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
1414 # Otherwise add this project to the project list, except for
1415 # the main project which is already in the list.
1416 if ($dirname ne "") {
1417 push @projects,$project;
1420 # Ask for project-wide options
1421 if ($opt_ask_project_options == $OPT_ASK_YES) {
1423 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1426 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1427 if (defined $flag_desc) {
1428 print "* (currently $flag_desc)\n";
1430 print "* or 'skip' to skip the target specific options,\n";
1431 print "* or 'never' to not be asked this question again:\n";
1433 my $options=<STDIN
>;
1435 if ($options eq "skip") {
1436 $opt_ask_target_options=$OPT_ASK_SKIP;
1438 } elsif ($options eq "never") {
1439 $opt_ask_project_options=$OPT_ASK_NO;
1441 } elsif (source_set_options
($project_settings,$options)) {
1444 print "Please re-enter the options:\n";
1448 # - Create the targets
1449 # - Check if we have both libraries and programs
1450 # - Match each target with source files (sort in reverse
1451 # alphabetical order to get the longest matches first)
1453 my @local_depends=();
1455 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1456 # Create the target...
1458 target_init
($target);
1459 @
$target[$T_NAME]=$target_name;
1460 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
1461 if ($target_name =~ /\.dll$/) {
1462 @
$target[$T_TYPE]=$TT_DLL;
1463 push @local_depends,"$target_name.so";
1464 push @local_dlls,$target_name;
1465 my $canon=canonize
($target_name);
1466 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
1468 @
$target[$T_TYPE]=$opt_target_type;
1469 push @exe_list,$target;
1470 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
1472 my $basename=$target_name;
1473 $basename=~ s/\.(dll|exe)$//i;
1474 # This is the default link list of Visual Studio
1475 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1476 my @std_libraries=qw(uuid);
1477 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1478 @
$target[$T_DLLS]=\
@std_imports;
1479 @
$target[$T_LIBRARIES]=\
@std_libraries;
1481 @
$target[$T_DLLS]=[];
1482 @
$target[$T_LIBRARIES]=[];
1484 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1485 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
1486 push @
{@
$target[$T_LDFLAGS]},"-m$opt_arch";
1488 push @
{@
$project[$P_TARGETS]},$target;
1490 # Ask for target-specific options
1491 if ($opt_ask_target_options == $OPT_ASK_YES) {
1493 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
1496 if ($flag_desc ne "") {
1499 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1500 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1502 my $options=<STDIN
>;
1504 if ($options eq "never") {
1505 $opt_ask_target_options=$OPT_ASK_NO;
1507 } elsif (source_set_options
($target,$options)) {
1510 print "Please re-enter the options:\n";
1513 if (@
$target[$T_FLAGS] & $TF_MFC) {
1514 @
$project_settings[$T_FLAGS]|=$TF_MFC;
1515 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1516 push @
{@
$target[$T_DLLS]},"mfc.dll";
1517 # FIXME: Link with the MFC in the Unix sense, until we
1518 # start exporting the functions properly.
1519 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1520 push @
{@
$target[$T_LIBRARIES]},"mfc";
1524 if ($target_count == 1) {
1525 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
1526 @
$project_settings[$T_SOURCES_C]=[];
1529 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1530 @
$project_settings[$T_SOURCES_CXX]=[];
1533 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
1534 @
$project_settings[$T_SOURCES_RC]=[];
1537 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
1538 # No need for sorting these sources
1539 @
$project_settings[$T_SOURCES_MISC]=[];
1542 foreach my $source (@sources_c) {
1543 if ($source =~ /^$basename/i) {
1544 push @
{@
$target[$T_SOURCES_C]},$source;
1548 foreach my $source (@sources_cxx) {
1549 if ($source =~ /^$basename/i) {
1550 push @
{@
$target[$T_SOURCES_CXX]},$source;
1554 foreach my $source (@sources_rc) {
1555 if ($source =~ /^$basename/i) {
1556 push @
{@
$target[$T_SOURCES_RC]},$source;
1560 foreach my $source (@sources_misc) {
1561 if ($source =~ /^$basename/i) {
1562 push @
{@
$target[$T_SOURCES_MISC]},$source;
1567 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
1568 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
1569 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
1570 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
1572 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1573 $opt_ask_target_options=$OPT_ASK_YES;
1576 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1577 push @
{@
$project_settings[$T_CEXTRA]},"-mno-cygwin";
1578 push @
{@
$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1581 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
1582 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1584 # The sources that did not match, if any, go to the extra
1585 # source list of the project settings
1586 foreach my $source (@sources_c) {
1587 if ($source ne "") {
1588 push @
{@
$project_settings[$T_SOURCES_C]},$source;
1591 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
1592 foreach my $source (@sources_cxx) {
1593 if ($source ne "") {
1594 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
1597 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
1598 foreach my $source (@sources_rc) {
1599 if ($source ne "") {
1600 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
1603 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
1604 foreach my $source (@sources_misc) {
1605 if ($source ne "") {
1606 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
1609 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
1611 # Finally if we are building both libraries and programs in
1612 # this directory, then the programs should be linked with all
1614 if (@local_dlls > 0 and @exe_list > 0) {
1615 foreach my $target (@exe_list) {
1616 push @
{@
$target[$T_DLL_PATH]},"-L.";
1617 push @
{@
$target[$T_DLLS]},@local_dlls;
1623 # Scan the source directories in search of things to build
1626 # If there's a single target then this is going to be the default target
1627 if (defined $opt_single_target) {
1628 # Create the main target
1630 target_init
($main_target);
1631 @
$main_target[$T_NAME]=$opt_single_target;
1632 @
$main_target[$T_TYPE]=$opt_target_type;
1634 # Add it to the list
1635 push @
{$main_project[$P_TARGETS]},$main_target;
1638 # The main directory is always going to be there
1639 push @projects,\
@main_project;
1641 if (defined $opt_work_dir) {
1642 # Now scan the directory tree looking for source files and, maybe, targets
1643 print "Scanning the source directories...\n";
1644 source_scan_directory
(\
@main_project,"","",0);
1645 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
1646 } elsif (defined $opt_work_file) {
1647 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1648 source_scan_project_file
(\
@main_project,0,$opt_work_file);
1649 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1650 source_scan_workspace_file
($opt_work_file);
1662 # Performs a directory traversal and renames the files so that:
1663 # - they have the case desired by the user
1664 # - their extension is of the appropriate case
1665 # - they don't contain annoying characters like ' ', '$', '#', ...
1666 # But only perform these changes for source files and directories.
1667 sub fix_file_and_directory_names
($);
1668 sub fix_file_and_directory_names
($)
1672 my $directory=get_directory_contents
($dirname);
1673 foreach my $dentry (@
$directory)
1675 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1678 # Set $warn to 1 if the user should be warned of the renaming
1680 my $new_name=$dentry;
1682 if (-f
"$dirname/$dentry")
1684 # Don't rename Winemaker's makefiles
1685 next if ($dentry eq "Makefile" and
1686 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker
/);
1688 # Leave non-source files alone
1689 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc))$/i);
1691 # Only all lowercase extensions are supported (because of
1692 # rules like '.c.o:'.
1693 $new_name =~ s/\.C$/.c/;
1694 $new_name =~ s/\.cpp$/.cpp/i;
1695 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1696 $new_name =~ s/\.rc$/.rc/i;
1697 # And this last one is to avoid confusion then running make
1698 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1701 # Adjust the case to the user's preferences
1702 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1703 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1705 $new_name=lc $new_name;
1708 # autoconf and make don't support these characters well
1709 $new_name =~ s/[ \$]/_/g;
1711 # And finally, perform the renaming
1712 if ($new_name ne $dentry)
1715 print STDERR
"warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1717 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1718 print STDERR
"error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1719 print STDERR
" $!\n";
1724 clear_directory_cache
($dirname);
1727 if (-d
"$dirname/$new_name") {
1728 fix_file_and_directory_names
("$dirname/$new_name");
1742 # Try to find a file for the specified filename. The attempt is
1743 # case-insensitive which is why it's not trivial. If a match is
1744 # found then we return the pathname with the correct case.
1751 if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
1753 } elsif ($dirname !~ m
+^/+) {
1754 $dirname=cwd
. "/" . $dirname;
1756 if ($dirname !~ m
+/$+) {
1760 foreach my $component (@
$path) {
1761 $component=~s/^\"//;
1762 $component=~s/\"$//;
1763 #print " looking for $component in \"$dirname\"\n";
1764 if ($component eq ".") {
1767 } elsif ($component eq "..") {
1769 $dirname=dirname
($dirname) . "/";
1772 # The file/directory may have been renamed before. Also try to
1773 # match the renamed file.
1774 my $renamed=$component;
1775 $renamed =~ s/[ \$]/_/g;
1776 if ($renamed eq $component) {
1780 my $directory=get_directory_contents
$dirname;
1782 foreach my $dentry (@
$directory) {
1783 if ($dentry =~ /^\Q$component\E$/i or
1784 (defined $renamed and $dentry =~ /^$renamed$/i)
1786 $dirname.="$dentry/";
1787 $real_path.="$dentry/";
1792 if (!defined $found) {
1794 #print " could not find $component in $dirname\n";
1799 $real_path=~ s
+/$++;
1800 #print " -> found $real_path\n";
1805 # Performs a case-insensitive search for the specified file in the
1807 # $line is the line number that should be referenced when an error occurs
1808 # $filename is the file we are looking for
1809 # $dirname is the directory of the file containing the '#include' directive
1810 # if '"' was used, it is an empty string otherwise
1811 # $project and $target specify part of the include path
1812 sub get_real_include_name
($$$$$)
1820 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a
-zA
-Z
]:[\
/]?/) {
1821 # This is not a relative path, we cannot make any check
1822 my $warning="path:$filename";
1823 if (!defined $warnings{$warning}) {
1824 $warnings{$warning}="1";
1825 print STDERR
"warning: cannot check the case of absolute pathnames:\n";
1826 print STDERR
"$line: $filename\n";
1829 # Here's how we proceed:
1830 # - split the filename we look for into its components
1831 # - then for each directory in the include path
1832 # - trace the directory components starting from that directory
1833 # - if we fail to find a match at any point then continue with
1834 # the next directory in the include path
1835 # - otherwise, rejoice, our quest is over.
1836 my @file_components=split /[\/\\]+/, $filename;
1837 #print " Searching for $filename from @$project[$P_PATH]\n";
1840 if ($dirname ne "") {
1841 # This is an 'include ""' -> look in dirname first.
1842 #print " in $dirname (include \"\")\n";
1843 $real_filename=search_from
($dirname,\
@file_components);
1844 if (defined $real_filename) {
1845 return $real_filename;
1848 my $project_settings=@
$project[$P_SETTINGS];
1849 foreach my $include (@
{@
$target[$T_INCLUDE_PATH]}, @
{@
$project_settings[$T_INCLUDE_PATH]}) {
1850 my $dirname=$include;
1853 if (!is_absolute
($dirname)) {
1854 $dirname="@$project[$P_PATH]$dirname";
1856 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)/++;
1857 $dirname=~ s
+^\
$\
(SRCDIR\
)/+@
$project[$P_PATH]+;
1859 #print " in $dirname\n";
1860 $real_filename=search_from
("$dirname",\
@file_components);
1861 if (defined $real_filename) {
1862 return $real_filename;
1865 my $dotdotpath=@
$project[$P_PATH];
1866 $dotdotpath =~ s/[^\/]+/../g
;
1867 foreach my $include (@
{$global_settings[$T_INCLUDE_PATH]}) {
1868 my $dirname=$include;
1870 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)\
/++;
1871 $dirname=~ s
+^\
$\
(SRCDIR\
)\
/+@
$project[$P_PATH]+;
1872 #print " in $dirname (global setting)\n";
1873 $real_filename=search_from
("$dirname",\
@file_components);
1874 if (defined $real_filename) {
1875 return $real_filename;
1879 $filename =~ s
+\\\\+/+g
; # in include ""
1880 $filename =~ s
+\\+/+g
; # in include <> !
1881 if ($opt_lower_include) {
1882 return lc "$filename";
1893 if ($size =~ /^(1|2|4|8)$/) {
1894 print FILEO
"$indent#include <pshpack$size.h>$trailer";
1896 print FILEO
"$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1897 print FILEO
"$indent#include <pshpack4.h>$trailer";
1902 # 'Parses' a source file and fixes constructs that would not work with
1903 # Winelib. The parsing is rather simple and not all non-portable features
1904 # are corrected. The most important feature that is corrected is the case
1905 # and path separator of '#include' directives. This requires that each
1906 # source file be associated to a project & target so that the proper
1907 # include path is used.
1908 # Also note that the include path is relative to the directory in which the
1909 # compiler is run, i.e. that of the project, not to that of the file.
1915 $filename="@$project[$P_PATH]$filename";
1916 if (! -e
$filename) {
1920 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1921 my $dirname=dirname
($filename);
1923 if (defined $target and (@
$target[$T_FLAGS] & $TF_MFC)) {
1927 print " $filename\n";
1928 #FIXME:assuming that because there is a .bak file, this is what we want is
1929 #probably flawed. Or is it???
1930 if (! -e
"$filename.bak") {
1931 if (!copy
("$filename","$filename.bak")) {
1932 print STDERR
"error: unable to make a backup of $filename:\n";
1933 print STDERR
" $!\n";
1937 if (!open(FILEI
,"$filename.bak")) {
1938 print STDERR
"error: unable to open $filename.bak for reading:\n";
1939 print STDERR
" $!\n";
1942 if (!open(FILEO
,">$filename")) {
1943 print STDERR
"error: unable to open $filename for writing:\n";
1944 print STDERR
" $!\n";
1949 my $rc_block_depth=0;
1950 my $rc_textinclude_state=0;
1953 # Remove any trailing CtrlZ, which isn't strictly in the file
1961 # Make sure all files are '\n' terminated
1964 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
1965 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1966 # the RC files it generates (even in non-MFC projects). So we replace
1967 # it with 'winresrc.h' its very close standard cousin so that non MFC
1968 # projects can compile in Wine without the MFC sources.
1969 my $warning="mfc:afxres.h";
1970 if (!defined $warnings{$warning}) {
1971 $warnings{$warning}="1";
1972 print STDERR
"warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
1973 print STDERR
"warning: the above warning is issued only once\n";
1975 print FILEO
"$1/* winemaker: $2\"afxres.h\" */\n";
1976 print FILEO
"$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
1977 print FILEO
"$1$2\"winresrc.h\"$'";
1980 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1981 my $from_file=($2 eq "<"?
"":$dirname);
1982 my $real_include_name=get_real_include_name
($line,$3,$from_file,$project,$target);
1983 print FILEO
"$1$2$real_include_name$4$'";
1984 $modified|=($real_include_name ne $3);
1986 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
1987 # Pragma pack handling
1989 # pack_stack is an array of references describing the stack of
1990 # pack directives currently in effect. Each directive if described
1991 # by a reference to an array containing:
1992 # - "push" for pack(push,...) directives, "" otherwise
1993 # - the directive's identifier at index 1
1994 # - the directive's alignment value at index 2
1996 # Don't believe a word of what the documentation says: it's all wrong.
1997 # The code below is based on the actual behavior of Visual C/C++ 6.
2002 # Pushes the default stack alignment
2003 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
2004 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2005 print_pack
($pack_indent,4,$');
2006 push @pack_stack, [ "", "", 4 ];
2008 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
2010 # pragma pack(pop,n)
2011 # Goes up the stack until it finds a pack(push,...), and pops it
2012 # Ignores any pack(n) entry
2013 # Issues a warning if the pack is of the form pack(push,label)
2014 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2015 my $pack_comment=$';
2016 $pack_comment =~ s/^\s*//;
2017 if ($pack_comment ne "") {
2018 print FILEO
"$pack_indent$pack_comment";
2021 my $alignment=pop @pack_stack;
2022 if (!defined $alignment) {
2023 print FILEO
"$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2026 if (@
$alignment[1]) {
2027 print FILEO
"$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2029 print FILEO
"$pack_indent#include <poppack.h>\n";
2030 if (@
$alignment[0]) {
2035 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2036 # pragma pack(pop,label[,n])
2037 # Goes up the stack until finding a pack(push,...) and pops it.
2038 # 'n', if specified, is ignored.
2039 # Ignores any pack(n) entry
2040 # Issues a warning if the label of the pack does not match,
2041 # or if it is in fact a pack(push,n)
2043 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
2044 my $pack_comment=$';
2045 $pack_comment =~ s/^\s*//;
2046 if ($pack_comment ne "") {
2047 print FILEO "$pack_indent$pack_comment";
2050 my $alignment=pop @pack_stack;
2051 if (!defined $alignment) {
2052 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2055 if (@$alignment[1] and @$alignment[1] ne $label) {
2056 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2058 print FILEO "$pack_indent#include <poppack.h>\n";
2059 if (@$alignment[0]) {
2064 } elsif (/^(push\s*\))/) {
2066 # Push the current alignment
2067 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2068 if (@pack_stack > 0) {
2069 my $alignment=$pack_stack[$#pack_stack];
2070 print_pack($pack_indent,@$alignment[2],$');
2071 push @pack_stack, [ "push", "", @
$alignment[2] ];
2073 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2074 print_pack
($pack_indent,4,$');
2075 push @pack_stack, [ "push", "", 4 ];
2078 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2079 # pragma pack([push,]n)
2080 # Push new alignment n
2081 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2082 print_pack($pack_indent,$3,"$'");
2083 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2085 } elsif (/^((\w+)\s*\))/) {
2086 # pragma pack(label)
2087 # label must in fact be a macro that resolves to an integer
2088 # Then behaves like 'pragma pack(n)'
2089 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2090 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2091 print_pack($pack_indent,4,$');
2092 push @pack_stack, [ "", "", 4 ];
2094 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2095 # pragma pack(push,label[,n])
2096 # Pushes a new label on the stack. It is possible to push the same
2097 # label multiple times. If 'n' is omitted then the alignment is
2098 # unchanged. Otherwise it becomes 'n'.
2099 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2103 } elsif (@pack_stack > 0) {
2104 my $alignment=$pack_stack[$#pack_stack];
2105 $size=@$alignment[2];
2107 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2110 print_pack($pack_indent,$size,$');
2111 push @pack_stack, [ "push", $2, $size ];
2114 # pragma pack(??? -> What's that?
2115 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2116 print FILEO "$pack_indent$pack_header$_";
2122 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]+)([\">]?)/) {
2123 my $from_file=($5 eq "<"?"":$dirname);
2124 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2125 print FILEO "$1$5$real_include_name$7$'";
2126 $modified|=($real_include_name ne $6);
2128 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2129 my $from_file=($2 eq "<"?"":$dirname);
2130 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2131 print FILEO "$1$2$real_include_name$4$'";
2132 $modified|=($real_include_name ne $3);
2134 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2135 $rc_textinclude_state=1;
2138 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2139 print FILEO "$1winresrc.h
$2$'";
2142 } elsif (/^\s*BEGIN(\W.*)?$/) {
2143 $rc_textinclude_state|=2;
2147 } elsif (/^\s*END(\W.*)?$/) {
2148 $rc_textinclude_state=0;
2149 if ($rc_block_depth>0) {
2165 if ($opt_backup == 0 or $modified == 0) {
2166 if (!unlink("$filename.bak")) {
2167 print STDERR "error: unable to delete $filename.bak:\n";
2168 print STDERR " $!\n";
2174 # Analyzes each source file in turn to find and correct issues
2175 # that would cause it not to compile.
2178 print "Fixing the source files...\n";
2179 foreach my $project (@projects) {
2180 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2181 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2182 fix_file($source,$project,$target);
2197 # A convenience function to generate all the lists (defines,
2198 # C sources, C++ source, etc.) in the Makefile
2199 sub generate_list($$$;$)
2208 printf FILEO "%-22s=",$name;
2210 if (defined $list) {
2211 foreach my $item (@$list) {
2213 if (defined $data) {
2214 $value=&$data($item);
2220 print FILEO " $value";
2223 print FILEO " \\\n\t\t\t$value";
2234 # Generates a project's Makefile
and all the target files
2235 sub generate_project_files
($)
2238 my $project_settings=@
$project[$P_SETTINGS];
2242 # Then sort the targets and separate the libraries from the programs
2243 foreach my $target (sort { @
$a[$T_NAME] cmp @
$b[$T_NAME] } @
{@
$project[$P_TARGETS]}) {
2244 if (@
$target[$T_TYPE] == $TT_DLL) {
2245 push @dll_list,$target;
2247 push @exe_list,$target;
2250 @
$project[$P_TARGETS]=[];
2251 push @
{@
$project[$P_TARGETS]}, @dll_list;
2252 push @
{@
$project[$P_TARGETS]}, @exe_list;
2254 if (!open(FILEO
,">@$project[$P_PATH]Makefile")) {
2255 print STDERR
"error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2256 print STDERR
" $!\n";
2260 print FILEO
"### Generated by Winemaker $version\n";
2263 generate_list
("SRCDIR",1,[ "." ]);
2264 if (@
$project[$P_PATH] eq "") {
2265 # This is the main project. It is also responsible for recursively
2266 # calling the other projects
2267 generate_list
("SUBDIRS",1,\
@projects,sub
2269 if ($_[0] != \
@main_project) {
2270 my $subdir=@
{$_[0]}[$P_PATH];
2274 # Eliminating the main project by returning undefined!
2277 if (@
{@
$project[$P_TARGETS]} > 0) {
2278 generate_list
("DLLS",1,\
@dll_list,sub
2280 return @
{$_[0]}[$T_NAME];
2282 generate_list
("EXES",1,\
@exe_list,sub
2284 return "@{$_[0]}[$T_NAME]";
2286 print FILEO
"\n\n\n";
2288 print FILEO
"### Common settings\n\n";
2289 # Make it so that the project-wide settings override the global settings
2290 generate_list
("CEXTRA",1,@
$project_settings[$T_CEXTRA]);
2291 generate_list
("CXXEXTRA",1,@
$project_settings[$T_CXXEXTRA]);
2292 generate_list
("RCEXTRA",1,@
$project_settings[$T_RCEXTRA]);
2293 generate_list
("DEFINES",1,@
$project_settings[$T_DEFINES]);
2294 generate_list
("INCLUDE_PATH",1,@
$project_settings[$T_INCLUDE_PATH]);
2295 generate_list
("DLL_PATH",1,@
$project_settings[$T_DLL_PATH]);
2296 generate_list
("DLL_IMPORTS",1,@
$project_settings[$T_DLLS]);
2297 generate_list
("LIBRARY_PATH",1,@
$project_settings[$T_LIBRARY_PATH]);
2298 generate_list
("LIBRARIES",1,@
$project_settings[$T_LIBRARIES]);
2301 my $extra_source_count=@
{@
$project_settings[$T_SOURCES_C]}+
2302 @
{@
$project_settings[$T_SOURCES_CXX]}+
2303 @
{@
$project_settings[$T_SOURCES_RC]};
2304 my $no_extra=($extra_source_count == 0);
2306 print FILEO
"### Extra source lists\n\n";
2307 generate_list
("EXTRA_C_SRCS",1,@
$project_settings[$T_SOURCES_C]);
2308 generate_list
("EXTRA_CXX_SRCS",1,@
$project_settings[$T_SOURCES_CXX]);
2309 generate_list
("EXTRA_RC_SRCS",1,@
$project_settings[$T_SOURCES_RC]);
2311 generate_list
("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
2312 print FILEO
"\n\n\n";
2315 # Iterate over all the targets...
2316 foreach my $target (@
{@
$project[$P_TARGETS]}) {
2317 print FILEO
"### @$target[$T_NAME] sources and settings\n\n";
2318 my $canon=canonize
("@$target[$T_NAME]");
2321 generate_list
("${canon}_MODULE",1,[@
$target[$T_NAME]]);
2322 generate_list
("${canon}_C_SRCS",1,@
$target[$T_SOURCES_C]);
2323 generate_list
("${canon}_CXX_SRCS",1,@
$target[$T_SOURCES_CXX]);
2324 generate_list
("${canon}_RC_SRCS",1,@
$target[$T_SOURCES_RC]);
2325 generate_list
("${canon}_LDFLAGS",1,@
$target[$T_LDFLAGS]);
2326 generate_list
("${canon}_DLL_PATH",1,@
$target[$T_DLL_PATH]);
2327 generate_list
("${canon}_DLLS",1,@
$target[$T_DLLS]);
2328 generate_list
("${canon}_LIBRARY_PATH",1,@
$target[$T_LIBRARY_PATH]);
2329 generate_list
("${canon}_LIBRARIES",1,@
$target[$T_LIBRARIES]);
2331 generate_list
("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2332 print FILEO
"\n\n\n";
2334 print FILEO
"### Global source lists\n\n";
2335 generate_list
("C_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2337 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2339 return "\$(${canon}_C_SRCS)";
2342 generate_list
("",1,[ "\$(EXTRA_C_SRCS)" ]);
2344 generate_list
("CXX_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2346 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2348 return "\$(${canon}_CXX_SRCS)";
2351 generate_list
("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2353 generate_list
("RC_SRCS",$no_extra,@
$project[$P_TARGETS],sub
2355 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
2357 return "\$(${canon}_RC_SRCS)";
2360 generate_list
("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2364 print FILEO
"### Tools\n\n";
2365 print FILEO
"CC = winegcc\n";
2366 print FILEO
"CXX = wineg++\n";
2367 print FILEO
"RC = wrc\n";
2370 print FILEO
"### Generic targets\n\n";
2372 if (@
$project[$P_PATH] eq "") {
2373 print FILEO
" \$(SUBDIRS)";
2375 if (@
{@
$project[$P_TARGETS]} > 0) {
2376 print FILEO
" \$(DLLS:%=%.so) \$(EXES:%=%.so)";
2379 print FILEO
"### Build rules\n";
2381 print FILEO
".PHONY: all clean dummy\n";
2383 print FILEO
"\$(SUBDIRS): dummy\n";
2384 print FILEO
"\t\@cd \$\@ && \$(MAKE)\n";
2386 print FILEO
"# Implicit rules\n";
2388 print FILEO
".SUFFIXES: .cpp .rc .res\n";
2389 print FILEO
"DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2391 print FILEO
".c.o:\n";
2392 print FILEO
"\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2394 print FILEO
".cpp.o:\n";
2395 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2397 print FILEO
".cxx.o:\n";
2398 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2400 print FILEO
".rc.res:\n";
2401 print FILEO
"\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2403 print FILEO
"# Rules for cleaning\n";
2405 print FILEO
"CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2406 print FILEO
" \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2408 print FILEO
"clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2409 print FILEO
"\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:.cpp=.o)\n";
2410 print FILEO
"\t\$(RM) \$(DLLS:%=%.so) \$(EXES:%=%.so) \$(EXES:%.exe=%)\n";
2412 print FILEO
"\$(SUBDIRS:%=%/__clean__): dummy\n";
2413 print FILEO
"\tcd `dirname \$\@` && \$(MAKE) clean\n";
2415 print FILEO
"\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2416 print FILEO
"\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2419 if (@
{@
$project[$P_TARGETS]} > 0) {
2420 print FILEO
"### Target specific build rules\n";
2421 print FILEO
"DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2422 foreach my $target (@
{@
$project[$P_TARGETS]}) {
2423 my $canon=canonize
("@$target[$T_NAME]");
2426 print FILEO
"\$(${canon}_MODULE).so: \$(${canon}_OBJS)\n";
2427 if (@
{@
$target[$T_SOURCES_CXX]} > 0 or @
{@
$project_settings[$T_SOURCES_CXX]} > 0) {
2428 print FILEO
"\t\$(CXX)";
2430 print FILEO
"\t\$(CC)";
2432 print FILEO
" \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2442 # This is where we finally generate files. In fact this method does not
2443 # do anything itself but calls the methods that do the actual work.
2446 print "Generating project files...\n";
2448 foreach my $project (@projects) {
2449 my $path=@
$project[$P_PATH];
2456 generate_project_files
($project);
2469 $opt_lower=$OPT_LOWER_UPPERCASE;
2470 $opt_lower_include=1;
2472 $opt_work_dir=undef;
2473 $opt_single_target=undef;
2474 $opt_target_type=$TT_GUIEXE;
2476 $opt_arch=$OPT_ARCH_32;
2477 $opt_is_interactive=$OPT_ASK_NO;
2478 $opt_ask_project_options=$OPT_ASK_NO;
2479 $opt_ask_target_options=$OPT_ASK_NO;
2480 $opt_no_generated_files=0;
2481 $opt_no_source_fix=0;
2494 print "Winemaker $version\n";
2495 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2496 print "Copyright 2004 Dimitrie O. Paun\n";
2497 print "Copyright 2009 André Hentschel\n";
2503 print STDERR
"Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2504 print STDERR
" [--lower-none|--lower-all|--lower-uppercase]\n";
2505 print STDERR
" [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2506 print STDERR
" [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2507 print STDERR
" [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2508 print STDERR
" [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2509 print STDERR
" [--generated-files|--nogenerated-files]\n";
2510 print STDERR
" [--wine64]\n";
2511 print STDERR
" work_directory|project_file|workspace_file\n";
2512 print STDERR
"\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2513 print STDERR
"the specified directory so that they can be compiled with Winelib. During this\n";
2514 print STDERR
"process it will modify and rename some of the files in that directory.\n";
2515 print STDERR
"\tPlease read the manual page before use.\n";
2519 target_init
(\
@global_settings);
2522 my $arg=shift @ARGV;
2524 if ($arg eq "--nobanner") {
2526 } elsif ($arg eq "--backup") {
2528 } elsif ($arg eq "--nobackup") {
2530 } elsif ($arg eq "--single-target") {
2531 $opt_single_target=shift @ARGV;
2532 } elsif ($arg eq "--lower-none") {
2533 $opt_lower=$OPT_LOWER_NONE;
2534 } elsif ($arg eq "--lower-all") {
2535 $opt_lower=$OPT_LOWER_ALL;
2536 } elsif ($arg eq "--lower-uppercase") {
2537 $opt_lower=$OPT_LOWER_UPPERCASE;
2538 } elsif ($arg eq "--lower-include") {
2539 $opt_lower_include=1;
2540 } elsif ($arg eq "--nolower-include") {
2541 $opt_lower_include=0;
2542 } elsif ($arg eq "--nosource-fix") {
2543 $opt_no_source_fix=1;
2544 } elsif ($arg eq "--generated-files") {
2545 $opt_no_generated_files=0;
2546 } elsif ($arg eq "--nogenerated-files") {
2547 $opt_no_generated_files=1;
2548 } elsif ($arg eq "--wine64") {
2549 $opt_arch=$OPT_ARCH_64;
2550 } elsif ($arg =~ /^-D/) {
2551 push @
{$global_settings[$T_DEFINES]},$arg;
2552 } elsif ($arg =~ /^-I/) {
2553 push @
{$global_settings[$T_INCLUDE_PATH]},$arg;
2554 } elsif ($arg =~ /^-P/) {
2555 push @
{$global_settings[$T_DLL_PATH]},"-L$'";
2556 } elsif ($arg =~ /^-i/) {
2557 push @
{$global_settings[$T_DLLS]},$';
2558 } elsif ($arg =~ /^-L/) {
2559 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2560 } elsif ($arg =~ /^-l/) {
2561 push @{$global_settings[$T_LIBRARIES]},$';
2563 # 'Source'-based method options
2564 } elsif ($arg eq "--dll") {
2565 $opt_target_type=$TT_DLL;
2566 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2567 $opt_target_type=$TT_GUIEXE;
2568 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2569 $opt_target_type=$TT_CUIEXE;
2570 } elsif ($arg eq "--interactive") {
2571 $opt_is_interactive=$OPT_ASK_YES;
2572 $opt_ask_project_options=$OPT_ASK_YES;
2573 $opt_ask_target_options=$OPT_ASK_YES;
2574 } elsif ($arg eq "--mfc") {
2575 $opt_flags|=$TF_MFC;
2576 } elsif ($arg eq "--nomfc") {
2577 $opt_flags&=~$TF_MFC;
2578 $opt_flags|=$TF_NOMFC;
2579 } elsif ($arg eq "--nodlls") {
2580 $opt_flags|=$TF_NODLLS;
2581 } elsif ($arg eq "--nomsvcrt") {
2582 $opt_flags|=$TF_NOMSVCRT;
2586 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2587 if (!defined $opt_work_dir and !defined $opt_work_file) {
2589 $opt_work_file=$arg;
2595 print STDERR
"error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2604 if (!defined $opt_work_dir and !defined $opt_work_file) {
2605 print STDERR
"error: you must specify the directory or project file containing the sources to be converted\n";
2607 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2608 print STDERR
"error: could not chdir to the work directory\n";
2609 print STDERR
" $!\n";
2613 if ($opt_no_banner == 0) {
2617 project_init
(\
@main_project, "", \
@global_settings);
2619 # Fix the file and directory names
2620 fix_file_and_directory_names
(".");
2622 # Scan the sources to identify the projects and targets
2625 # Fix the source files
2626 if (! $opt_no_source_fix) {
2630 # Generate the Makefile and the spec file
2631 if (! $opt_no_generated_files) {