4 # Copyright 2000-2004 Francois Gouget for CodeWeavers
5 # Copyright 2004 Dimitrie O. Paun
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
36 # The following constants define what we do with the case of filenames
39 # Never rename a file to lowercase
43 # Rename all files to lowercase
47 # Rename only files that are all uppercase to lowercase
48 my $OPT_LOWER_UPPERCASE=2;
51 # The following constants define whether to ask questions or not
54 # No (synonym of never)
62 # Skip the questions till the end of this scope
69 # This is the directory in which winemaker will operate.
73 # Make a backup of the files
77 # Defines which files to rename
81 # If we don't find the file referenced by an include, lower it
82 my $opt_lower_include;
85 # If true then winemaker should not attempt to fix the source. This is
86 # useful if the source is known to be already in a suitable form and is
88 my $opt_no_source_fix;
90 # Options for the 'Source' method
93 # Specifies that we have only one target so that all sources relate
94 # to this target. By default this variable is left undefined which
95 # means winemaker should try to find out by itself what the targets
96 # are. If not undefined then this contains the name of the default
97 # target (without the extension).
98 my $opt_single_target;
101 # If '$opt_single_target' has been specified then this is the type of
102 # that target. Otherwise it specifies whether the default target type
103 # is guiexe or cuiexe.
107 # Contains the default set of flags to be used when creating a new target.
111 # If true then winemaker should ask questions to the user as it goes
113 my $opt_is_interactive;
114 my $opt_ask_project_options;
115 my $opt_ask_target_options;
118 # If false then winemaker should not generate the makefiles.
119 my $opt_no_generated_files;
122 # Specifies not to print the banner if set.
129 # Target modelization
133 # The description of a target is stored in an array. The constants
134 # below identify what is stored at each index of the array.
137 # This is the name of the target.
141 # Defines the type of target we want to build. See the TT_xxx
146 # This is a bitfield containing flags refining the way the target
147 # should be handled. See the TF_xxx constants below
151 # This is a reference to an array containing the list of the
152 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
156 my $T_SOURCES_MISC=6;
159 # This is a reference to an array containing the list of
164 # This is a reference to an array containing the list of
165 # C++ compiler options
169 # This is a reference to an array containing the list of
170 # RC compiler options
174 # This is a reference to an array containing the list of macro
179 # This is a reference to an array containing the list of directory
180 # names that constitute the include path
181 my $T_INCLUDE_PATH=11;
184 # Flags for the linker
188 # Same as T_INCLUDE_PATH but for the dll search path
192 # The list of Windows dlls to import
196 # Same as T_INCLUDE_PATH but for the library search path
197 my $T_LIBRARY_PATH=15;
200 # The list of Unix libraries to link with
204 # The list of dependencies between targets
208 # The following constants define the recognized types of target
211 # This is not a real target. This type of target is used to collect
212 # the sources that don't seem to belong to any other target. Thus no
213 # real target is generated for them, we just put the sources of the
214 # fake target in the global source list.
218 # For executables in the windows subsystem
222 # For executables in the console subsystem
226 # For dynamically linked libraries
230 # The following constants further refine how the target should be handled
233 # This target is an MFC-based target
237 # User has specified --nomfc option for this target or globally
241 # --nodlls option: Do not use standard DLL set
245 # --nomsvcrt option: Do not link with msvcrt
249 # Initialize a target:
250 # - set the target type to TT_SETTINGS, i.e. no real target will
256 @
$target[$T_TYPE]=$TT_SETTINGS;
257 # leaving $T_INIT undefined
258 @
$target[$T_FLAGS]=$opt_flags;
259 @
$target[$T_SOURCES_C]=[];
260 @
$target[$T_SOURCES_CXX]=[];
261 @
$target[$T_SOURCES_RC]=[];
262 @
$target[$T_SOURCES_MISC]=[];
263 @
$target[$T_CEXTRA]=[];
264 @
$target[$T_CXXEXTRA]=[];
265 @
$target[$T_RCEXTRA]=[];
266 @
$target[$T_DEFINES]=[];
267 @
$target[$T_INCLUDE_PATH]=[];
268 @
$target[$T_LDFLAGS]=[];
269 @
$target[$T_DLL_PATH]=[];
270 @
$target[$T_DLLS]=[];
271 @
$target[$T_LIBRARY_PATH]=[];
272 @
$target[$T_LIBRARIES]=[];
279 # Project modelization
283 # First we have the notion of project. A project is described by an
284 # array (since we don't have structs in perl). The constants below
285 # identify what is stored at each index of the array.
288 # This is the path in which this project is located. In other
289 # words, this is the path to the Makefile.
293 # This index contains a reference to an array containing the project-wide
294 # settings. The structure of that arrray is actually identical to that of
295 # a regular target since it can also contain extra sources.
299 # This index contains a reference to an array of targets for this
300 # project. Each target describes how an executable or library is to
301 # be built. For each target this description takes the same form as
302 # that of the project: an array. So this entry is an array of arrays.
306 # Initialize a project:
307 # - set the project's path
308 # - initialize the target list
309 # - create a default target (will be removed later if unnecessary)
310 sub project_init
($$$)
312 my ($project, $path, $global_settings)=@_;
314 my $project_settings=[];
315 target_init
($project_settings);
316 @
$project_settings[$T_DEFINES]=[@
{@
$global_settings[$T_DEFINES]}];
317 @
$project_settings[$T_INCLUDE_PATH]=[@
{@
$global_settings[$T_INCLUDE_PATH]}];
318 @
$project_settings[$T_DLL_PATH]=[@
{@
$global_settings[$T_DLL_PATH]}];
319 @
$project_settings[$T_DLLS]=[@
{@
$global_settings[$T_DLLS]}];
320 @
$project_settings[$T_LIBRARY_PATH]=[@
{@
$global_settings[$T_LIBRARY_PATH]}];
321 @
$project_settings[$T_LIBRARIES]=[@
{@
$global_settings[$T_LIBRARIES]}];
323 @
$project[$P_PATH]=$path;
324 @
$project[$P_SETTINGS]=$project_settings;
325 @
$project[$P_TARGETS]=[];
341 # This maps a directory name to a reference to an array listing
342 # its contents (files and directories)
346 # Contains the list of all projects. This list tells us what are
347 # the subprojects of the main Makefile and where we have to generate
352 # This is the main project, i.e. the one in the "." directory.
353 # It may well be empty in which case the main Makefile will only
354 # call out subprojects.
358 # Contains the defaults for the include path, etc.
359 # We store the defaults as if this were a target except that we only
360 # exploit the defines, include path, library path, library list and misc
373 # Cleans up a name to make it an acceptable Makefile
379 $name =~ tr/a-zA-Z0-9_/_/c;
384 # Returns true is the specified pathname is absolute.
385 # Note: pathnames that start with a variable '$' or
386 # '~' are considered absolute.
391 return ($path =~ /^[\/~\
$]/);
395 # Performs a binary search looking for the specified item
400 my $last=@
{$array}-1;
403 while ($first<=$last) {
404 my $index=int(($first+$last)/2);
405 my $cmp=@
$array[$index] cmp $item;
417 # Retrieves the contents of the specified directory.
418 # We either get it from the directories hashtable which acts as a
419 # cache, or use opendir, readdir, closedir and store the result
421 sub get_directory_contents
($)
426 #print "getting the contents of $dirname\n";
428 # check for a cached version
430 if ($dirname eq "") {
433 $directory=$directories{$dirname};
434 if (defined $directory) {
435 #print "->@$directory\n";
439 # Read this directory
440 if (opendir(DIRECTORY
, "$dirname")) {
441 my @files=readdir DIRECTORY
;
445 # Return an empty list
446 #print "error: cannot open $dirname\n";
450 #print "->@$directory\n";
451 $directories{$dirname}=$directory;
456 # Removes a directory from the cache.
457 # This is needed if one of its files or subdirectory has been renamed.
458 sub clear_directory_cache
($)
461 delete $directories{$dirname};
467 # 'Source'-based Project analysis
472 # Allows the user to specify makefile and target specific options
473 # - target: the structure in which to store the results
474 # - options: the string containing the options
475 sub source_set_options
($$)
480 #FIXME: we must deal with escaping of stuff and all
481 foreach my $option (split / /,$options) {
482 if (@
$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
483 push @
{@
$target[$T_DEFINES]},$option;
484 } elsif (@
$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
485 push @
{@
$target[$T_INCLUDE_PATH]},$option;
486 } elsif ($option =~ /^-P/) {
487 push @
{@
$target[$T_DLL_PATH]},"-L$'";
488 } elsif ($option =~ /^-i/) {
489 push @
{@
$target[$T_DLLS]},"$'";
490 } elsif ($option =~ /^-L/) {
491 push @
{@
$target[$T_LIBRARY_PATH]},$option;
492 } elsif ($option =~ /^-l/) {
493 push @
{@
$target[$T_LIBRARIES]},"$'";
494 } elsif ($option =~ /^--mfc/) {
495 @
$target[$T_FLAGS]|=$TF_MFC;
496 @
$target[$T_FLAGS]&=~$TF_NOMFC;
497 } elsif ($option =~ /^--nomfc/) {
498 @
$target[$T_FLAGS]&=~$TF_MFC;
499 @
$target[$T_FLAGS]|=$TF_NOMFC;
500 } elsif ($option =~ /^--nodlls/) {
501 @
$target[$T_FLAGS]|=$TF_NODLLS;
502 } elsif ($option =~ /^--nomsvcrt/) {
503 @
$target[$T_FLAGS]|=$TF_NOMSVCRT;
505 print STDERR
"error: unknown option \"$option\"\n";
513 # Scans the specified directory to:
514 # - see if we should create a Makefile in this directory. We normally do
515 # so if we find a project file and sources
516 # - get a list of targets for this directory
517 # - get the list of source files
518 sub source_scan_directory
($$$$);
519 sub source_scan_directory
($$$$)
521 # a reference to the parent's project
522 my $parent_project=$_[0];
523 # the full relative path to the current directory, including a
524 # trailing '/', or an empty string if this is the top level directory
526 # the name of this directory, including a trailing '/', or an empty
527 # string if this is the top level directory
529 # if set then no targets will be looked for and the sources will all
530 # end up in the parent_project's 'misc' bucket
533 # reference to the project for this directory. May not be used
535 # list of targets found in the 'current' directory
537 # list of sources found in the current directory
542 # true if this directory contains a Windows project
543 my $has_win_project=0;
544 # true if this directory contains headers
546 # If we don't find any executable/library then we might make up targets
547 # from the list of .dsp/.mak files we find since they usually have the
548 # same name as their target.
552 if (defined $opt_single_target or $dirname eq "") {
553 # Either there is a single target and thus a single project,
554 # or we are in the top level directory for which a project
556 $project=$parent_project;
559 project_init
($project, $path, \
@global_settings);
561 my $project_settings=@
$project[$P_SETTINGS];
563 # First find out what this directory contains:
564 # collect all sources, targets and subdirectories
565 my $directory=get_directory_contents
($path);
566 foreach my $dentry (@
$directory) {
567 if ($dentry =~ /^\./) {
570 my $fullentry="$path$dentry";
571 if (-d
"$fullentry") {
572 if ($dentry =~ /^(Release|Debug)/i) {
573 # These directories are often used to store the object files and the
574 # resulting executable/library. They should not contain anything else.
575 my @candidates=grep /\.(exe|dll)$/i, @
{get_directory_contents
("$fullentry")};
576 foreach my $candidate (@candidates) {
577 $targets{$candidate}=1;
579 } elsif ($dentry =~ /^include/i) {
580 # This directory must contain headers we're going to need
581 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
582 source_scan_directory
($project,"$fullentry/","$dentry/",1);
584 # Recursively scan this directory. Any source file that cannot be
585 # attributed to a project in one of the subdirectories will be
586 # attributed to this project.
587 source_scan_directory
($project,"$fullentry/","$dentry/",$no_target);
589 } elsif (-f
"$fullentry") {
590 if ($dentry =~ /\.(exe|dll)$/i) {
592 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
593 push @sources_c,"$dentry";
594 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
595 if ($dentry =~ /^stdafx.cpp$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
596 push @sources_misc,"$dentry";
597 @
$project_settings[$T_FLAGS]|=$TF_MFC;
599 push @sources_cxx,"$dentry";
601 } elsif ($dentry =~ /\.rc$/i) {
602 push @sources_rc,"$dentry";
603 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
605 push @sources_misc,"$dentry";
606 if ($dentry =~ /^stdafx.h$/i && !(@
$project_settings[$T_FLAGS] & $TF_NOMFC)) {
607 @
$project_settings[$T_FLAGS]|=$TF_MFC;
609 } elsif ($dentry =~ /\.dsp$/i) {
610 push @dsp_files,"$dentry";
612 } elsif ($dentry =~ /\.mak$/i) {
613 push @mak_files,"$dentry";
615 } elsif ($dentry =~ /^makefile/i) {
622 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I.";
624 # If we have a single target then all we have to do is assign
625 # all the sources to it and we're done
626 # FIXME: does this play well with the --interactive mode?
627 if ($opt_single_target) {
628 my $target=@
{@
$project[$P_TARGETS]}[0];
629 push @
{@
$target[$T_SOURCES_C]},map "$path$_",@sources_c;
630 push @
{@
$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
631 push @
{@
$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
632 push @
{@
$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
636 my $parent_settings=@
$parent_project[$P_SETTINGS];
637 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
638 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
639 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
640 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
641 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
645 my $source_count=@sources_c+@sources_cxx+@sources_rc+
646 @
{@
$project_settings[$T_SOURCES_C]}+
647 @
{@
$project_settings[$T_SOURCES_CXX]}+
648 @
{@
$project_settings[$T_SOURCES_RC]};
649 if ($source_count == 0) {
650 # A project without real sources is not a project, get out!
651 if ($project!=$parent_project) {
652 my $parent_settings=@
$parent_project[$P_SETTINGS];
653 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
654 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
658 #print "targets=",%targets,"\n";
659 #print "target_count=$target_count\n";
660 #print "has_win_project=$has_win_project\n";
661 #print "dirname=$dirname\n";
664 if (($has_win_project != 0) or ($dirname eq "")) {
665 # Deal with cases where we could not find any executable/library, and
666 # thus have no target, although we did find some sort of windows project.
667 $target_count=keys %targets;
668 if ($target_count == 0) {
669 # Try to come up with a target list based on .dsp/.mak files
671 if (@dsp_files > 0) {
672 $prj_list=\
@dsp_files;
674 $prj_list=\
@mak_files;
676 foreach my $filename (@
$prj_list) {
677 $filename =~ s/\.(dsp|mak)$//i;
678 if ($opt_target_type == $TT_DLL) {
679 $filename = "$filename.dll";
681 $targets{$filename}=1;
683 $target_count=keys %targets;
684 if ($target_count == 0) {
685 # Still nothing, try the name of the directory
687 if ($dirname eq "") {
688 # Bad luck, this is the top level directory!
689 $name=(split /\//, cwd
)[-1];
692 # Remove the trailing '/'. Also eliminate whatever is after the last
693 # '.' as it is likely to be meaningless (.orig, .new, ...)
694 $name =~ s
+(/|\
.[^.]*)$++;
695 if ($name eq "src") {
696 # 'src' is probably a subdirectory of the real project directory.
697 # Try again with the parent (if any).
699 if ($parent =~ s
+([^/]*)/[^/]*/$+$1+) {
702 $name=(split /\//, cwd
)[-1];
706 $name =~ s
+(/|\
.[^.]*)$++;
707 if ($opt_target_type == $TT_DLL) {
716 # Ask confirmation to the user if he wishes so
717 if ($opt_is_interactive == $OPT_ASK_YES) {
718 my $target_list=join " ",keys %targets;
719 print "\n*** In ",($path?
$path:"./"),"\n";
720 print "* winemaker found the following list of (potential) targets\n";
721 print "* $target_list\n";
722 print "* Type enter to use it as is, your own comma-separated list of\n";
723 print "* targets, 'none' to assign the source files to a parent directory,\n";
724 print "* or 'ignore' to ignore everything in this directory tree.\n";
725 print "* Target list:\n";
726 $target_list=<STDIN
>;
728 if ($target_list eq "") {
729 # Keep the target list as is, i.e. do nothing
730 } elsif ($target_list eq "none") {
731 # Empty the target list
733 } elsif ($target_list eq "ignore") {
734 # Ignore this subtree altogether
738 foreach my $target (split /,/,$target_list) {
747 # If we have no project at this level, then transfer all
748 # the sources to the parent project
749 $target_count=keys %targets;
750 if ($target_count == 0) {
751 if ($project!=$parent_project) {
752 my $parent_settings=@
$parent_project[$P_SETTINGS];
753 push @
{@
$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
754 push @
{@
$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
755 push @
{@
$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
756 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
757 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
762 # Otherwise add this project to the project list, except for
763 # the main project which is already in the list.
764 if ($dirname ne "") {
765 push @projects,$project;
768 # Ask for project-wide options
769 if ($opt_ask_project_options == $OPT_ASK_YES) {
771 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
774 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
775 if (defined $flag_desc) {
776 print "* (currently $flag_desc)\n";
778 print "* or 'skip' to skip the target specific options,\n";
779 print "* or 'never' to not be asked this question again:\n";
783 if ($options eq "skip") {
784 $opt_ask_target_options=$OPT_ASK_SKIP;
786 } elsif ($options eq "never") {
787 $opt_ask_project_options=$OPT_ASK_NO;
789 } elsif (source_set_options
($project_settings,$options)) {
792 print "Please re-enter the options:\n";
796 # - Create the targets
797 # - Check if we have both libraries and programs
798 # - Match each target with source files (sort in reverse
799 # alphabetical order to get the longest matches first)
801 my @local_depends=();
803 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
804 # Create the target...
806 target_init
($target);
807 @
$target[$T_NAME]=$target_name;
808 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
809 if ($target_name =~ /\.dll$/) {
810 @
$target[$T_TYPE]=$TT_DLL;
811 push @local_depends,"$target_name.so";
812 push @local_dlls,$target_name;
813 my $canon=canonize
($target_name);
814 push @
{@
$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
816 @
$target[$T_TYPE]=$opt_target_type;
817 push @exe_list,$target;
818 push @
{@
$target[$T_LDFLAGS]},(@
$target[$T_TYPE] == $TT_CUIEXE ?
"-mconsole" : "-mwindows");
820 my $basename=$target_name;
821 $basename=~ s/\.(dll|exe)$//i;
822 # This is the default link list of Visual Studio
823 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
824 my @std_libraries=qw(uuid);
825 if ((@
$target[$T_FLAGS] & $TF_NODLLS) == 0) {
826 @
$target[$T_DLLS]=\
@std_imports;
827 @
$target[$T_LIBRARIES]=\
@std_libraries;
829 @
$target[$T_DLLS]=[];
830 @
$target[$T_LIBRARIES]=[];
832 if ((@
$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
833 push @
{@
$target[$T_LDFLAGS]},"-mno-cygwin";
835 push @
{@
$project[$P_TARGETS]},$target;
837 # Ask for target-specific options
838 if ($opt_ask_target_options == $OPT_ASK_YES) {
840 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
843 if ($flag_desc ne "") {
846 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
847 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
851 if ($options eq "never") {
852 $opt_ask_target_options=$OPT_ASK_NO;
854 } elsif (source_set_options
($target,$options)) {
857 print "Please re-enter the options:\n";
860 if (@
$target[$T_FLAGS] & $TF_MFC) {
861 @
$project_settings[$T_FLAGS]|=$TF_MFC;
862 push @
{@
$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
863 push @
{@
$target[$T_DLLS]},"mfc.dll";
864 # FIXME: Link with the MFC in the Unix sense, until we
865 # start exporting the functions properly.
866 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
867 push @
{@
$target[$T_LIBRARIES]},"mfc";
871 if ($target_count == 1) {
872 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
873 @
$project_settings[$T_SOURCES_C]=[];
876 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
877 @
$project_settings[$T_SOURCES_CXX]=[];
880 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
881 @
$project_settings[$T_SOURCES_RC]=[];
884 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
885 # No need for sorting these sources
886 @
$project_settings[$T_SOURCES_MISC]=[];
889 foreach my $source (@sources_c) {
890 if ($source =~ /^$basename/i) {
891 push @
{@
$target[$T_SOURCES_C]},$source;
895 foreach my $source (@sources_cxx) {
896 if ($source =~ /^$basename/i) {
897 push @
{@
$target[$T_SOURCES_CXX]},$source;
901 foreach my $source (@sources_rc) {
902 if ($source =~ /^$basename/i) {
903 push @
{@
$target[$T_SOURCES_RC]},$source;
907 foreach my $source (@sources_misc) {
908 if ($source =~ /^$basename/i) {
909 push @
{@
$target[$T_SOURCES_MISC]},$source;
914 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
915 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
916 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
917 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
919 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
920 $opt_ask_target_options=$OPT_ASK_YES;
923 if ((@
$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
924 push @
{@
$project_settings[$T_CEXTRA]},"-mno-cygwin";
925 push @
{@
$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
928 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
929 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
931 # The sources that did not match, if any, go to the extra
932 # source list of the project settings
933 foreach my $source (@sources_c) {
935 push @
{@
$project_settings[$T_SOURCES_C]},$source;
938 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
939 foreach my $source (@sources_cxx) {
941 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
944 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
945 foreach my $source (@sources_rc) {
947 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
950 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
951 foreach my $source (@sources_misc) {
953 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
956 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
958 # Finally if we are building both libraries and programs in
959 # this directory, then the programs should be linked with all
961 if (@local_dlls > 0 and @exe_list > 0) {
962 foreach my $target (@exe_list) {
963 push @
{@
$target[$T_DLL_PATH]},"-L.";
964 push @
{@
$target[$T_DLLS]},@local_dlls;
970 # Scan the source directories in search of things to build
973 # If there's a single target then this is going to be the default target
974 if (defined $opt_single_target) {
975 # Create the main target
977 target_init
($main_target);
978 @
$main_target[$T_NAME]=$opt_single_target;
979 @
$main_target[$T_TYPE]=$opt_target_type;
982 push @
{$main_project[$P_TARGETS]},$main_target;
985 # The main directory is always going to be there
986 push @projects,\
@main_project;
988 # Now scan the directory tree looking for source files and, maybe, targets
989 print "Scanning the source directories...\n";
990 source_scan_directory
(\
@main_project,"","",0);
992 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
1002 # Performs a directory traversal and renames the files so that:
1003 # - they have the case desired by the user
1004 # - their extension is of the appropriate case
1005 # - they don't contain annoying characters like ' ', '$', '#', ...
1006 # But only perform these changes for source files and directories.
1007 sub fix_file_and_directory_names
($);
1008 sub fix_file_and_directory_names
($)
1012 my $directory=get_directory_contents
($dirname);
1013 foreach my $dentry (@
$directory)
1015 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1018 # Set $warn to 1 if the user should be warned of the renaming
1020 my $new_name=$dentry;
1022 if (-f
"$dirname/$dentry")
1024 # Don't rename Winemaker's makefiles
1025 next if ($dentry eq "Makefile" and
1026 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker
/);
1028 # Leave non-source files alone
1029 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc))$/i);
1031 # Only all lowercase extensions are supported (because of
1032 # rules like '.c.o:'.
1033 $new_name =~ s/\.C$/.c/;
1034 $new_name =~ s/\.cpp$/.cpp/i;
1035 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1036 $new_name =~ s/\.rc$/.rc/i;
1037 # And this last one is to avoid confusion then running make
1038 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1041 # Adjust the case to the user's preferences
1042 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1043 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1045 $new_name=lc $new_name;
1048 # autoconf and make don't support these characters well
1049 $new_name =~ s/[ \$]/_/g;
1051 # And finally, perform the renaming
1052 if ($new_name ne $dentry)
1055 print STDERR
"warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1057 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1058 print STDERR
"error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1059 print STDERR
" $!\n";
1064 clear_directory_cache
($dirname);
1067 if (-d
"$dirname/$new_name") {
1068 fix_file_and_directory_names
("$dirname/$new_name");
1082 # Try to find a file for the specified filename. The attempt is
1083 # case-insensitive which is why it's not trivial. If a match is
1084 # found then we return the pathname with the correct case.
1091 if ($dirname eq "" or $dirname eq ".") {
1093 } elsif ($dirname !~ m
+^/+) {
1094 $dirname=cwd
. "/" . $dirname;
1096 if ($dirname !~ m
+/$+) {
1100 foreach my $component (@
$path) {
1101 #print " looking for $component in \"$dirname\"\n";
1102 if ($component eq ".") {
1105 } elsif ($component eq "..") {
1107 $dirname=dirname
($dirname) . "/";
1110 # The file/directory may have been renamed before. Also try to
1111 # match the renamed file.
1112 my $renamed=$component;
1113 $renamed =~ s/[ \$]/_/g;
1114 if ($renamed eq $component) {
1118 my $directory=get_directory_contents
$dirname;
1120 foreach my $dentry (@
$directory) {
1121 if ($dentry =~ /^\Q$component\E$/i or
1122 (defined $renamed and $dentry =~ /^$renamed$/i)
1124 $dirname.="$dentry/";
1125 $real_path.="$dentry/";
1130 if (!defined $found) {
1132 #print " could not find $component in $dirname\n";
1137 $real_path=~ s
+/$++;
1138 #print " -> found $real_path\n";
1143 # Performs a case-insensitive search for the specified file in the
1145 # $line is the line number that should be referenced when an error occurs
1146 # $filename is the file we are looking for
1147 # $dirname is the directory of the file containing the '#include' directive
1148 # if '"' was used, it is an empty string otherwise
1149 # $project and $target specify part of the include path
1150 sub get_real_include_name
($$$$$)
1158 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a
-zA
-Z
]:[\
/]?/) {
1159 # This is not a relative path, we cannot make any check
1160 my $warning="path:$filename";
1161 if (!defined $warnings{$warning}) {
1162 $warnings{$warning}="1";
1163 print STDERR
"warning: cannot check the case of absolute pathnames:\n";
1164 print STDERR
"$line: $filename\n";
1167 # Here's how we proceed:
1168 # - split the filename we look for into its components
1169 # - then for each directory in the include path
1170 # - trace the directory components starting from that directory
1171 # - if we fail to find a match at any point then continue with
1172 # the next directory in the include path
1173 # - otherwise, rejoice, our quest is over.
1174 my @file_components=split /[\/\\]+/, $filename;
1175 #print " Searching for $filename from @$project[$P_PATH]\n";
1178 if ($dirname ne "") {
1179 # This is an 'include ""' -> look in dirname first.
1180 #print " in $dirname (include \"\")\n";
1181 $real_filename=search_from
($dirname,\
@file_components);
1182 if (defined $real_filename) {
1183 return $real_filename;
1186 my $project_settings=@
$project[$P_SETTINGS];
1187 foreach my $include (@
{@
$target[$T_INCLUDE_PATH]}, @
{@
$project_settings[$T_INCLUDE_PATH]}) {
1188 my $dirname=$include;
1190 if (!is_absolute
($dirname)) {
1191 $dirname="@$project[$P_PATH]$dirname";
1193 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)/++;
1194 $dirname=~ s
+^\
$\
(SRCDIR\
)/+@
$project[$P_PATH]+;
1196 #print " in $dirname\n";
1197 $real_filename=search_from
("$dirname",\
@file_components);
1198 if (defined $real_filename) {
1199 return $real_filename;
1202 my $dotdotpath=@
$project[$P_PATH];
1203 $dotdotpath =~ s/[^\/]+/../g
;
1204 foreach my $include (@
{$global_settings[$T_INCLUDE_PATH]}) {
1205 my $dirname=$include;
1207 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)\
/++;
1208 $dirname=~ s
+^\
$\
(SRCDIR\
)\
/+@
$project[$P_PATH]+;
1209 #print " in $dirname (global setting)\n";
1210 $real_filename=search_from
("$dirname",\
@file_components);
1211 if (defined $real_filename) {
1212 return $real_filename;
1216 $filename =~ s
+\\\\+/+g
; # in include ""
1217 $filename =~ s
+\\+/+g
; # in include <> !
1218 if ($opt_lower_include) {
1219 return lc "$filename";
1230 if ($size =~ /^(1|2|4|8)$/) {
1231 print FILEO
"$indent#include <pshpack$size.h>$trailer";
1233 print FILEO
"$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1234 print FILEO
"$indent#include <pshpack4.h>$trailer";
1239 # 'Parses' a source file and fixes constructs that would not work with
1240 # Winelib. The parsing is rather simple and not all non-portable features
1241 # are corrected. The most important feature that is corrected is the case
1242 # and path separator of '#include' directives. This requires that each
1243 # source file be associated to a project & target so that the proper
1244 # include path is used.
1245 # Also note that the include path is relative to the directory in which the
1246 # compiler is run, i.e. that of the project, not to that of the file.
1252 $filename="@$project[$P_PATH]$filename";
1253 if (! -e
$filename) {
1257 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1258 my $dirname=dirname
($filename);
1260 if (defined $target and (@
$target[$T_FLAGS] & $TF_MFC)) {
1264 print " $filename\n";
1265 #FIXME:assuming that because there is a .bak file, this is what we want is
1266 #probably flawed. Or is it???
1267 if (! -e
"$filename.bak") {
1268 if (!copy
("$filename","$filename.bak")) {
1269 print STDERR
"error: unable to make a backup of $filename:\n";
1270 print STDERR
" $!\n";
1274 if (!open(FILEI
,"$filename.bak")) {
1275 print STDERR
"error: unable to open $filename.bak for reading:\n";
1276 print STDERR
" $!\n";
1279 if (!open(FILEO
,">$filename")) {
1280 print STDERR
"error: unable to open $filename for writing:\n";
1281 print STDERR
" $!\n";
1286 my $rc_block_depth=0;
1287 my $rc_textinclude_state=0;
1290 # Remove any trailing CtrlZ, which isn't strictly in the file
1298 # Make sure all files are '\n' terminated
1301 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
1302 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1303 # the RC files it generates (even in non-MFC projects). So we replace
1304 # it with 'winres.h' its very close standard cousin so that non MFC
1305 # projects can compile in Wine without the MFC sources.
1306 my $warning="mfc:afxres.h";
1307 if (!defined $warnings{$warning}) {
1308 $warnings{$warning}="1";
1309 print STDERR
"warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winres.h'\n";
1310 print STDERR
"warning: the above warning is issued only once\n";
1312 print FILEO
"$1/* winemaker: $2\"afxres.h\" */\n";
1313 print FILEO
"$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winres.h' */\n";
1314 print FILEO
"$1$2\"winres.h\"$'";
1317 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1318 my $from_file=($2 eq "<"?
"":$dirname);
1319 my $real_include_name=get_real_include_name
($line,$3,$from_file,$project,$target);
1320 print FILEO
"$1$2$real_include_name$4$'";
1321 $modified|=($real_include_name ne $3);
1323 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
1324 # Pragma pack handling
1326 # pack_stack is an array of references describing the stack of
1327 # pack directives currently in effect. Each directive if described
1328 # by a reference to an array containing:
1329 # - "push" for pack(push,...) directives, "" otherwise
1330 # - the directive's identifier at index 1
1331 # - the directive's alignment value at index 2
1333 # Don't believe a word of what the documentation says: it's all wrong.
1334 # The code below is based on the actual behavior of Visual C/C++ 6.
1339 # Pushes the default stack alignment
1340 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
1341 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1342 print_pack
($pack_indent,4,$');
1343 push @pack_stack, [ "", "", 4 ];
1345 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
1347 # pragma pack(pop,n)
1348 # Goes up the stack until it finds a pack(push,...), and pops it
1349 # Ignores any pack(n) entry
1350 # Issues a warning if the pack is of the form pack(push,label)
1351 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1352 my $pack_comment=$';
1353 $pack_comment =~ s/^\s*//;
1354 if ($pack_comment ne "") {
1355 print FILEO
"$pack_indent$pack_comment";
1358 my $alignment=pop @pack_stack;
1359 if (!defined $alignment) {
1360 print FILEO
"$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
1363 if (@
$alignment[1]) {
1364 print FILEO
"$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
1366 print FILEO
"$pack_indent#include <poppack.h>\n";
1367 if (@
$alignment[0]) {
1372 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
1373 # pragma pack(pop,label[,n])
1374 # Goes up the stack until finding a pack(push,...) and pops it.
1375 # 'n', if specified, is ignored.
1376 # Ignores any pack(n) entry
1377 # Issues a warning if the label of the pack does not match,
1378 # or if it is in fact a pack(push,n)
1380 print FILEO
"$pack_indent/* winemaker: $pack_header$1 */\n";
1381 my $pack_comment=$';
1382 $pack_comment =~ s/^\s*//;
1383 if ($pack_comment ne "") {
1384 print FILEO "$pack_indent$pack_comment";
1387 my $alignment=pop @pack_stack;
1388 if (!defined $alignment) {
1389 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
1392 if (@$alignment[1] and @$alignment[1] ne $label) {
1393 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
1395 print FILEO "$pack_indent#include <poppack.h>\n";
1396 if (@$alignment[0]) {
1401 } elsif (/^(push\s*\))/) {
1403 # Push the current alignment
1404 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1405 if (@pack_stack > 0) {
1406 my $alignment=$pack_stack[$#pack_stack];
1407 print_pack($pack_indent,@$alignment[2],$');
1408 push @pack_stack, [ "push", "", @
$alignment[2] ];
1410 print FILEO
"$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1411 print_pack
($pack_indent,4,$');
1412 push @pack_stack, [ "push", "", 4 ];
1415 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
1416 # pragma pack([push,]n)
1417 # Push new alignment n
1418 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1419 print_pack($pack_indent,$3,"$'");
1420 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
1422 } elsif (/^((\w+)\s*\))/) {
1423 # pragma pack(label)
1424 # label must in fact be a macro that resolves to an integer
1425 # Then behaves like 'pragma pack(n)'
1426 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1427 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
1428 print_pack($pack_indent,4,$');
1429 push @pack_stack, [ "", "", 4 ];
1431 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
1432 # pragma pack(push,label[,n])
1433 # Pushes a new label on the stack. It is possible to push the same
1434 # label multiple times. If 'n' is omitted then the alignment is
1435 # unchanged. Otherwise it becomes 'n'.
1436 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1440 } elsif (@pack_stack > 0) {
1441 my $alignment=$pack_stack[$#pack_stack];
1442 $size=@$alignment[2];
1444 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1447 print_pack($pack_indent,$size,$');
1448 push @pack_stack, [ "push", $2, $size ];
1451 # pragma pack(??? -> What's that?
1452 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
1453 print FILEO "$pack_indent$pack_header$_";
1459 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]+)([\">]?)/) {
1460 my $from_file=($5 eq "<"?"":$dirname);
1461 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
1462 print FILEO "$1$5$real_include_name$7$'";
1463 $modified|=($real_include_name ne $6);
1465 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1466 my $from_file=($2 eq "<"?"":$dirname);
1467 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1468 print FILEO "$1$2$real_include_name$4$'";
1469 $modified|=($real_include_name ne $3);
1471 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
1472 $rc_textinclude_state=1;
1475 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
1476 print FILEO "$1winres.h
$2$'";
1479 } elsif (/^\s*BEGIN(\W.*)?$/) {
1480 $rc_textinclude_state|=2;
1484 } elsif (/^\s*END(\W.*)?$/) {
1485 $rc_textinclude_state=0;
1486 if ($rc_block_depth>0) {
1502 if ($opt_backup == 0 or $modified == 0) {
1503 if (!unlink("$filename.bak")) {
1504 print STDERR "error: unable to delete $filename.bak:\n";
1505 print STDERR " $!\n";
1511 # Analyzes each source file in turn to find and correct issues
1512 # that would cause it not to compile.
1515 print "Fixing the source files...\n";
1516 foreach my $project (@projects) {
1517 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
1518 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
1519 fix_file($source,$project,$target);
1534 # A convenience function to generate all the lists (defines,
1535 # C sources, C++ source, etc.) in the Makefile
1536 sub generate_list($$$;$)
1545 printf FILEO "%-22s=",$name;
1547 if (defined $list) {
1548 foreach my $item (@$list) {
1550 if (defined $data) {
1551 $value=&$data($item);
1557 print FILEO " $value";
1560 print FILEO " \\\n\t\t\t$value";
1571 # Generates a project's Makefile
and all the target files
1572 sub generate_project_files
($)
1575 my $project_settings=@
$project[$P_SETTINGS];
1579 # Then sort the targets and separate the libraries from the programs
1580 foreach my $target (sort { @
$a[$T_NAME] cmp @
$b[$T_NAME] } @
{@
$project[$P_TARGETS]}) {
1581 if (@
$target[$T_TYPE] == $TT_DLL) {
1582 push @dll_list,$target;
1584 push @exe_list,$target;
1587 @
$project[$P_TARGETS]=[];
1588 push @
{@
$project[$P_TARGETS]}, @dll_list;
1589 push @
{@
$project[$P_TARGETS]}, @exe_list;
1591 if (!open(FILEO
,">@$project[$P_PATH]Makefile")) {
1592 print STDERR
"error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
1593 print STDERR
" $!\n";
1597 print FILEO
"### Generated by Winemaker\n";
1600 generate_list
("SRCDIR",1,[ "." ]);
1601 if (@
$project[$P_PATH] eq "") {
1602 # This is the main project. It is also responsible for recursively
1603 # calling the other projects
1604 generate_list
("SUBDIRS",1,\
@projects,sub
1606 if ($_[0] != \
@main_project) {
1607 my $subdir=@
{$_[0]}[$P_PATH];
1611 # Eliminating the main project by returning undefined!
1614 if (@
{@
$project[$P_TARGETS]} > 0) {
1615 generate_list
("DLLS",1,\
@dll_list,sub
1617 return @
{$_[0]}[$T_NAME];
1619 generate_list
("EXES",1,\
@exe_list,sub
1621 return "@{$_[0]}[$T_NAME]";
1623 print FILEO
"\n\n\n";
1625 print FILEO
"### Common settings\n\n";
1626 # Make it so that the project-wide settings override the global settings
1627 generate_list
("CEXTRA",1,@
$project_settings[$T_CEXTRA]);
1628 generate_list
("CXXEXTRA",1,@
$project_settings[$T_CXXEXTRA]);
1629 generate_list
("RCEXTRA",1,@
$project_settings[$T_RCEXTRA]);
1630 generate_list
("DEFINES",1,@
$project_settings[$T_DEFINES]);
1631 generate_list
("INCLUDE_PATH",1,@
$project_settings[$T_INCLUDE_PATH]);
1632 generate_list
("DLL_PATH",1,@
$project_settings[$T_DLL_PATH]);
1633 generate_list
("DLL_IMPORTS",1,@
$project_settings[$T_DLLS]);
1634 generate_list
("LIBRARY_PATH",1,@
$project_settings[$T_LIBRARY_PATH]);
1635 generate_list
("LIBRARIES",1,@
$project_settings[$T_LIBRARIES]);
1638 my $extra_source_count=@
{@
$project_settings[$T_SOURCES_C]}+
1639 @
{@
$project_settings[$T_SOURCES_CXX]}+
1640 @
{@
$project_settings[$T_SOURCES_RC]};
1641 my $no_extra=($extra_source_count == 0);
1643 print FILEO
"### Extra source lists\n\n";
1644 generate_list
("EXTRA_C_SRCS",1,@
$project_settings[$T_SOURCES_C]);
1645 generate_list
("EXTRA_CXX_SRCS",1,@
$project_settings[$T_SOURCES_CXX]);
1646 generate_list
("EXTRA_RC_SRCS",1,@
$project_settings[$T_SOURCES_RC]);
1648 generate_list
("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
1649 print FILEO
"\n\n\n";
1652 # Iterate over all the targets...
1653 foreach my $target (@
{@
$project[$P_TARGETS]}) {
1654 print FILEO
"### @$target[$T_NAME] sources and settings\n\n";
1655 my $canon=canonize
("@$target[$T_NAME]");
1658 generate_list
("${canon}_MODULE",1,[@
$target[$T_NAME]]);
1659 generate_list
("${canon}_C_SRCS",1,@
$target[$T_SOURCES_C]);
1660 generate_list
("${canon}_CXX_SRCS",1,@
$target[$T_SOURCES_CXX]);
1661 generate_list
("${canon}_RC_SRCS",1,@
$target[$T_SOURCES_RC]);
1662 generate_list
("${canon}_LDFLAGS",1,@
$target[$T_LDFLAGS]);
1663 generate_list
("${canon}_DLL_PATH",1,@
$target[$T_DLL_PATH]);
1664 generate_list
("${canon}_DLLS",1,@
$target[$T_DLLS]);
1665 generate_list
("${canon}_LIBRARY_PATH",1,@
$target[$T_LIBRARY_PATH]);
1666 generate_list
("${canon}_LIBRARIES",1,@
$target[$T_LIBRARIES]);
1668 generate_list
("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(${canon}_RC_SRCS:.rc=.res)"]);
1669 print FILEO
"\n\n\n";
1671 print FILEO
"### Global source lists\n\n";
1672 generate_list
("C_SRCS",$no_extra,@
$project[$P_TARGETS],sub
1674 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
1676 return "\$(${canon}_C_SRCS)";
1679 generate_list
("",1,[ "\$(EXTRA_C_SRCS)" ]);
1681 generate_list
("CXX_SRCS",$no_extra,@
$project[$P_TARGETS],sub
1683 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
1685 return "\$(${canon}_CXX_SRCS)";
1688 generate_list
("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
1690 generate_list
("RC_SRCS",$no_extra,@
$project[$P_TARGETS],sub
1692 my $canon=canonize
(@
{$_[0]}[$T_NAME]);
1694 return "\$(${canon}_RC_SRCS)";
1697 generate_list
("",1,[ "\$(EXTRA_RC_SRCS)" ]);
1701 print FILEO
"### Tools\n\n";
1702 print FILEO
"CC = winegcc\n";
1703 print FILEO
"CXX = wineg++\n";
1704 print FILEO
"RC = wrc\n";
1707 print FILEO
"### Generic targets\n\n";
1709 if (@
$project[$P_PATH] eq "") {
1710 print FILEO
" \$(SUBDIRS)";
1712 if (@
{@
$project[$P_TARGETS]} > 0) {
1713 print FILEO
" \$(DLLS:%=%.so) \$(EXES:%=%.so)";
1716 print FILEO
"### Build rules\n";
1718 print FILEO
".PHONY: all clean dummy\n";
1720 print FILEO
"\$(SUBDIRS): dummy\n";
1721 print FILEO
"\t\@cd \$\@ && \$(MAKE)\n";
1723 print FILEO
"# Implicit rules\n";
1725 print FILEO
".SUFFIXES: .cpp .rc .res\n";
1726 print FILEO
"DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
1728 print FILEO
".c.o:\n";
1729 print FILEO
"\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
1731 print FILEO
".cpp.o:\n";
1732 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
1734 print FILEO
".cxx.o:\n";
1735 print FILEO
"\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
1737 print FILEO
".rc.res:\n";
1738 print FILEO
"\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
1740 print FILEO
"# Rules for cleaning\n";
1742 print FILEO
"CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
1743 print FILEO
" \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
1745 print FILEO
"clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
1746 print FILEO
"\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:.cpp=.o)\n";
1747 print FILEO
"\t\$(RM) \$(DLLS:%=%.so) \$(EXES:%=%.so) \$(EXES:%.exe=%)\n";
1749 print FILEO
"\$(SUBDIRS:%=%/__clean__): dummy\n";
1750 print FILEO
"\tcd `dirname \$\@` && \$(MAKE) clean\n";
1752 print FILEO
"\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
1753 print FILEO
"\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
1756 if (@
{@
$project[$P_TARGETS]} > 0) {
1757 print FILEO
"### Target specific build rules\n";
1758 print FILEO
"DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
1759 foreach my $target (@
{@
$project[$P_TARGETS]}) {
1760 my $canon=canonize
("@$target[$T_NAME]");
1763 print FILEO
"\$(${canon}_MODULE).so: \$(${canon}_OBJS)\n";
1764 if (@
{@
$target[$T_SOURCES_CXX]} > 0 or @
{@
$project_settings[$T_SOURCES_CXX]} > 0) {
1765 print FILEO
"\t\$(CXX)";
1767 print FILEO
"\t\$(CC)";
1769 print FILEO
" \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
1779 # This is where we finally generate files. In fact this method does not
1780 # do anything itself but calls the methods that do the actual work.
1783 print "Generating project files...\n";
1785 foreach my $project (@projects) {
1786 my $path=@
$project[$P_PATH];
1793 generate_project_files
($project);
1806 $opt_lower=$OPT_LOWER_UPPERCASE;
1807 $opt_lower_include=1;
1809 $opt_work_dir=undef;
1810 $opt_single_target=undef;
1811 $opt_target_type=$TT_GUIEXE;
1813 $opt_is_interactive=$OPT_ASK_NO;
1814 $opt_ask_project_options=$OPT_ASK_NO;
1815 $opt_ask_target_options=$OPT_ASK_NO;
1816 $opt_no_generated_files=0;
1817 $opt_no_source_fix=0;
1830 print "Winemaker $version\n";
1831 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
1837 print STDERR
"Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
1838 print STDERR
" [--lower-none|--lower-all|--lower-uppercase]\n";
1839 print STDERR
" [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
1840 print STDERR
" [--guiexe|--windows|--cuiexe|--console|--dll]\n";
1841 print STDERR
" [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
1842 print STDERR
" [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
1843 print STDERR
" [--generated-files|--nogenerated-files]\n";
1844 print STDERR
" work_directory\n";
1845 print STDERR
"\nWinemaker is designed to recursively convert all the Windows sources found in\n";
1846 print STDERR
"the specified directory so that they can be compiled with Winelib. During this\n";
1847 print STDERR
"process it will modify and rename some of the files in that directory.\n";
1848 print STDERR
"\tPlease read the manual page before use.\n";
1852 target_init
(\
@global_settings);
1855 my $arg=shift @ARGV;
1857 if ($arg eq "--nobanner") {
1859 } elsif ($arg eq "--backup") {
1861 } elsif ($arg eq "--nobackup") {
1863 } elsif ($arg eq "--single-target") {
1864 $opt_single_target=shift @ARGV;
1865 } elsif ($arg eq "--lower-none") {
1866 $opt_lower=$OPT_LOWER_NONE;
1867 } elsif ($arg eq "--lower-all") {
1868 $opt_lower=$OPT_LOWER_ALL;
1869 } elsif ($arg eq "--lower-uppercase") {
1870 $opt_lower=$OPT_LOWER_UPPERCASE;
1871 } elsif ($arg eq "--lower-include") {
1872 $opt_lower_include=1;
1873 } elsif ($arg eq "--nolower-include") {
1874 $opt_lower_include=0;
1875 } elsif ($arg eq "--nosource-fix") {
1876 $opt_no_source_fix=1;
1877 } elsif ($arg eq "--generated-files") {
1878 $opt_no_generated_files=0;
1879 } elsif ($arg eq "--nogenerated-files") {
1880 $opt_no_generated_files=1;
1881 } elsif ($arg =~ /^-D/) {
1882 push @
{$global_settings[$T_DEFINES]},$arg;
1883 } elsif ($arg =~ /^-I/) {
1884 push @
{$global_settings[$T_INCLUDE_PATH]},$arg;
1885 } elsif ($arg =~ /^-P/) {
1886 push @
{$global_settings[$T_DLL_PATH]},"-L$'";
1887 } elsif ($arg =~ /^-i/) {
1888 push @
{$global_settings[$T_DLLS]},$';
1889 } elsif ($arg =~ /^-L/) {
1890 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
1891 } elsif ($arg =~ /^-l/) {
1892 push @{$global_settings[$T_LIBRARIES]},$';
1894 # 'Source'-based method options
1895 } elsif ($arg eq "--dll") {
1896 $opt_target_type=$TT_DLL;
1897 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
1898 $opt_target_type=$TT_GUIEXE;
1899 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
1900 $opt_target_type=$TT_CUIEXE;
1901 } elsif ($arg eq "--interactive") {
1902 $opt_is_interactive=$OPT_ASK_YES;
1903 $opt_ask_project_options=$OPT_ASK_YES;
1904 $opt_ask_target_options=$OPT_ASK_YES;
1905 } elsif ($arg eq "--mfc") {
1906 $opt_flags|=$TF_MFC;
1907 } elsif ($arg eq "--nomfc") {
1908 $opt_flags&=~$TF_MFC;
1909 $opt_flags|=$TF_NOMFC;
1910 } elsif ($arg eq "--nodlls") {
1911 $opt_flags|=$TF_NODLLS;
1912 } elsif ($arg eq "--nomsvcrt") {
1913 $opt_flags|=$TF_NOMSVCRT;
1917 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
1918 if (!defined $opt_work_dir) {
1921 print STDERR
"error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
1930 if (!defined $opt_work_dir) {
1931 print STDERR
"error: you must specify the directory containing the sources to be converted\n";
1933 } elsif (!chdir $opt_work_dir) {
1934 print STDERR
"error: could not chdir to the work directory\n";
1935 print STDERR
" $!\n";
1939 if ($opt_no_banner == 0) {
1943 project_init
(\
@main_project, "", \
@global_settings);
1945 # Fix the file and directory names
1946 fix_file_and_directory_names
(".");
1948 # Scan the sources to identify the projects and targets
1951 # Fix the source files
1952 if (! $opt_no_source_fix) {
1956 # Generate the Makefile and the spec file
1957 if (! $opt_no_generated_files) {