4 # Copyright 2000-2002 Francois Gouget for CodeWeavers
5 # fgouget@codeweavers.com
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 any file, i.e.
119 # no makefiles, but also no .spec files, no configure.in, etc.
120 my $opt_no_generated_files;
123 # If true then winemaker should not generate the spec files.
124 # This is useful if winemaker is being used to create a build environment
125 my $opt_no_generated_specs;
128 # Specifies not to print the banner if set.
135 # Target modelization
139 # The description of a target is stored in an array. The constants
140 # below identify what is stored at each index of the array.
143 # This is the name of the target.
147 # Defines the type of target we want to build. See the TT_xxx
152 # Defines the target's enty point, i.e. the function that is called
157 # This is a bitfield containing flags refining the way the target
158 # should be handled. See the TF_xxx constants below
162 # This is a reference to an array containing the list of the
163 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
167 my $T_SOURCES_MISC=7;
170 # This is a reference to an array containing the list of macro
175 # This is a reference to an array containing the list of directory
176 # names that constitute the include path
177 my $T_INCLUDE_PATH=9;
180 # Same as T_INCLUDE_PATH but for the dll search path
184 # The list of Windows dlls to import
188 # Same as T_INCLUDE_PATH but for the library search path
189 my $T_LIBRARY_PATH=12;
192 # The list of Unix libraries to link with
196 # The list of dependencies between targets
200 # The following constants define the recognized types of target
203 # This is not a real target. This type of target is used to collect
204 # the sources that don't seem to belong to any other target. Thus no
205 # real target is generated for them, we just put the sources of the
206 # fake target in the global source list.
210 # For executables in the windows subsystem
214 # For executables in the console subsystem
218 # For dynamically linked libraries
222 # The following constants further refine how the target should be handled
225 # This target needs a wrapper
229 # This target is a wrapper
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 # Initialize a target:
246 # - set the target type to TT_SETTINGS, i.e. no real target will
252 @$target[$T_TYPE]=$TT_SETTINGS;
253 # leaving $T_INIT undefined
254 @$target[$T_FLAGS]=$opt_flags;
255 @$target[$T_SOURCES_C]=[];
256 @$target[$T_SOURCES_CXX]=[];
257 @$target[$T_SOURCES_RC]=[];
258 @$target[$T_SOURCES_MISC]=[];
259 @$target[$T_DEFINES]=[];
260 @$target[$T_INCLUDE_PATH]=[];
261 @$target[$T_DLL_PATH]=[];
262 @$target[$T_DLLS]=[];
263 @$target[$T_LIBRARY_PATH]=[];
264 @$target[$T_LIBRARIES]=[];
265 @$target[$T_DEPENDS]=[];
268 sub get_default_init($)
271 if ($type == $TT_GUIEXE) {
273 } elsif ($type == $TT_CUIEXE) {
275 } elsif ($type == $TT_DLL) {
284 # Project modelization
288 # First we have the notion of project. A project is described by an
289 # array (since we don't have structs in perl). The constants below
290 # identify what is stored at each index of the array.
293 # This is the path in which this project is located. In other
294 # words, this is the path to the Makefile.
298 # This index contains a reference to an array containing the project-wide
299 # settings. The structure of that arrray is actually identical to that of
300 # a regular target since it can also contain extra sources.
304 # This index contains a reference to an array of targets for this
305 # project. Each target describes how an executable or library is to
306 # be built. For each target this description takes the same form as
307 # that of the project: an array. So this entry is an array of arrays.
311 # Initialize a project:
312 # - set the project's path
313 # - initialize the target list
314 # - create a default target (will be removed later if unnecessary)
320 my $project_settings=[];
321 target_init($project_settings);
323 @$project[$P_PATH]=$path;
324 @$project[$P_SETTINGS]=$project_settings;
325 @$project[$P_TARGETS]=[];
341 # Contains the list of all projects. This list tells us what are
342 # the subprojects of the main Makefile and where we have to generate
347 # This is the main project, i.e. the one in the "." directory.
348 # It may well be empty in which case the main Makefile will only
349 # call out subprojects.
353 # Contains the defaults for the include path, etc.
354 # We store the defaults as if this were a target except that we only
355 # exploit the defines, include path, library path, library list and misc
360 # If one of the projects requires the MFc then we set this global variable
361 # to true so that configure asks the user to provide a path tothe MFC
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;
420 # 'Source'-based Project analysis
425 # Allows the user to specify makefile and target specific options
426 # - target: the structure in which to store the results
427 # - options: the string containing the options
428 sub source_set_options($$)
433 #FIXME: we must deal with escaping of stuff and all
434 foreach my $option (split / /,$options) {
435 if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
436 push @{@$target[$T_DEFINES]},$option;
437 } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
438 push @{@$target[$T_INCLUDE_PATH]},$option;
439 } elsif ($option =~ /^-P/) {
440 push @{@$target[$T_DLL_PATH]},"-L$'";
441 } elsif ($option =~ /^-i/) {
442 push @{@$target[$T_DLLS]},"$'";
443 } elsif ($option =~ /^-L/) {
444 push @{@$target[$T_LIBRARY_PATH]},$option;
445 } elsif ($option =~ /^-l/) {
446 push @{@$target[$T_LIBRARIES]},"$'";
447 } elsif ($option =~ /^--wrap/) {
448 if (@$target[$T_TYPE] != $TT_DLL) {
449 @$target[$T_FLAGS]|=$TF_WRAP;
451 print STDERR "warning: option --wrap is illegal for DLLs - ignoring";
453 } elsif ($option =~ /^--nowrap/) {
454 if (@$target[$T_TYPE] != $TT_DLL) {
455 @$target[$T_FLAGS]&=~$TF_WRAP;
457 print STDERR "warning: option --nowrap is illegal for DLLs - ignoring";
459 } elsif ($option =~ /^--mfc/) {
460 @$target[$T_FLAGS]|=$TF_MFC;
461 @$target[$T_FLAGS]&=~$TF_NOMFC;
462 } elsif ($option =~ /^--nomfc/) {
463 @$target[$T_FLAGS]&=~$TF_MFC;
464 @$target[$T_FLAGS]|=$TF_NOMFC;
465 } elsif ($option =~ /^--nodlls/) {
466 @$target[$T_FLAGS]|=$TF_NODLLS;
468 print STDERR "error: unknown option \"$option\"\n";
472 if (@$target[$T_TYPE] != $TT_DLL &&
473 @$target[$T_FLAGS] & $TF_MFC &&
474 !(@$target[$T_FLAGS] & $TF_WRAP)) {
475 print STDERR "info: option --mfc requires --wrap";
476 @$target[$T_FLAGS]|=$TF_WRAP;
482 # Scans the specified directory to:
483 # - see if we should create a Makefile in this directory. We normally do
484 # so if we find a project file and sources
485 # - get a list of targets for this directory
486 # - get the list of source files
487 sub source_scan_directory($$$$);
488 sub source_scan_directory($$$$)
490 # a reference to the parent's project
491 my $parent_project=$_[0];
492 # the full relative path to the current directory, including a
493 # trailing '/', or an empty string if this is the top level directory
495 # the name of this directory, including a trailing '/', or an empty
496 # string if this is the top level directory
498 # if set then no targets will be looked for and the sources will all
499 # end up in the parent_project's 'misc' bucket
502 # reference to the project for this directory. May not be used
504 # list of targets found in the 'current' directory
506 # list of sources found in the current directory
511 # true if this directory contains a Windows project
512 my $has_win_project=0;
513 # If we don't find any executable/library then we might make up targets
514 # from the list of .dsp/.mak files we find since they usually have the
515 # same name as their target.
519 if (defined $opt_single_target or $dirname eq "") {
520 # Either there is a single target and thus a single project,
521 # or we are in the top level directory for which a project
523 $project=$parent_project;
526 project_init($project,$path);
528 my $project_settings=@$project[$P_SETTINGS];
530 # First find out what this directory contains:
531 # collect all sources, targets and subdirectories
532 my $directory=get_directory_contents($path);
533 foreach my $dentry (@$directory) {
534 if ($dentry =~ /^\./) {
537 my $fullentry="$path$dentry";
538 if (-d "$fullentry") {
539 if ($dentry =~ /^(Release|Debug)/i) {
540 # These directories are often used to store the object files and the
541 # resulting executable/library. They should not contain anything else.
542 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
543 foreach my $candidate (@candidates) {
544 if ($candidate =~ s/\.exe$//i) {
545 $targets{$candidate}=1;
546 } elsif ($candidate =~ s/^(.*)\.dll$/lib$1.so/i) {
547 $targets{$candidate}=1;
550 } elsif ($dentry =~ /^include/i) {
551 # This directory must contain headers we're going to need
552 push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
553 source_scan_directory($project,"$fullentry/","$dentry/",1);
555 # Recursively scan this directory. Any source file that cannot be
556 # attributed to a project in one of the subdirectories will be
557 # attributed to this project.
558 source_scan_directory($project,"$fullentry/","$dentry/",$no_target);
560 } elsif (-f "$fullentry") {
561 if ($dentry =~ s/\.exe$//i) {
563 } elsif ($dentry =~ s/^(.*)\.dll$/lib$1.so/i) {
565 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.spec\.c$/) {
566 push @sources_c,"$dentry";
567 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
568 if ($dentry =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
569 push @sources_misc,"$dentry";
570 @$project_settings[$T_FLAGS]|=$TF_MFC;
572 push @sources_cxx,"$dentry";
574 } elsif ($dentry =~ /\.rc$/i) {
575 push @sources_rc,"$dentry";
576 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
577 push @sources_misc,"$dentry";
578 if ($dentry =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
579 @$project_settings[$T_FLAGS]|=$TF_MFC;
581 } elsif ($dentry =~ /\.dsp$/i) {
582 push @dsp_files,"$dentry";
584 } elsif ($dentry =~ /\.mak$/i) {
585 push @mak_files,"$dentry";
587 } elsif ($dentry =~ /^makefile/i) {
594 # If we have a single target then all we have to do is assign
595 # all the sources to it and we're done
596 # FIXME: does this play well with the --interactive mode?
597 if ($opt_single_target) {
598 my $target=@{@$project[$P_TARGETS]}[0];
599 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
600 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
601 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
602 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
606 my $parent_settings=@$parent_project[$P_SETTINGS];
607 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
608 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
609 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
610 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
611 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
615 my $source_count=@sources_c+@sources_cxx+@sources_rc+
616 @{@$project_settings[$T_SOURCES_C]}+
617 @{@$project_settings[$T_SOURCES_CXX]}+
618 @{@$project_settings[$T_SOURCES_RC]};
619 if ($source_count == 0) {
620 # A project without real sources is not a project, get out!
621 if ($project!=$parent_project) {
622 my $parent_settings=@$parent_project[$P_SETTINGS];
623 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
624 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
628 #print "targets=",%targets,"\n";
629 #print "target_count=$target_count\n";
630 #print "has_win_project=$has_win_project\n";
631 #print "dirname=$dirname\n";
634 if (($has_win_project != 0) or ($dirname eq "")) {
635 # Deal with cases where we could not find any executable/library, and
636 # thus have no target, although we did find some sort of windows project.
637 $target_count=keys %targets;
638 if ($target_count == 0) {
639 # Try to come up with a target list based on .dsp/.mak files
641 if (@dsp_files > 0) {
642 $prj_list=\@dsp_files;
644 $prj_list=\@mak_files;
646 foreach my $filename (@$prj_list) {
647 $filename =~ s/\.(dsp|mak)$//i;
648 if ($opt_target_type == $TT_DLL) {
649 $filename = "lib$filename.so";
651 $targets{$filename}=1;
653 $target_count=keys %targets;
654 if ($target_count == 0) {
655 # Still nothing, try the name of the directory
657 if ($dirname eq "") {
658 # Bad luck, this is the top level directory!
659 $name=(split /\//, cwd)[-1];
662 # Remove the trailing '/'. Also eliminate whatever is after the last
663 # '.' as it is likely to be meaningless (.orig, .new, ...)
664 $name =~ s+(/|\.[^.]*)$++;
665 if ($name eq "src") {
666 # 'src' is probably a subdirectory of the real project directory.
667 # Try again with the parent (if any).
669 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
672 $name=(split /\//, cwd)[-1];
676 $name =~ s+(/|\.[^.]*)$++;
677 if ($opt_target_type == $TT_DLL) {
678 $name = "lib$name.so";
684 # Ask confirmation to the user if he wishes so
685 if ($opt_is_interactive == $OPT_ASK_YES) {
686 my $target_list=join " ",keys %targets;
687 print "\n*** In ",($path?$path:"./"),"\n";
688 print "* winemaker found the following list of (potential) targets\n";
689 print "* $target_list\n";
690 print "* Type enter to use it as is, your own comma-separated list of\n";
691 print "* targets, 'none' to assign the source files to a parent directory,\n";
692 print "* or 'ignore' to ignore everything in this directory tree.\n";
693 print "* Target list:\n";
694 $target_list=<STDIN>;
696 if ($target_list eq "") {
697 # Keep the target list as is, i.e. do nothing
698 } elsif ($target_list eq "none") {
699 # Empty the target list
701 } elsif ($target_list eq "ignore") {
702 # Ignore this subtree altogether
706 foreach my $target (split /,/,$target_list) {
709 # Also accept .exe and .dll as a courtesy
710 $target =~ s+(.*)\.dll$+lib$1.so+;
711 $target =~ s+\.exe$++;
718 # If we have no project at this level, then transfer all
719 # the sources to the parent project
720 $target_count=keys %targets;
721 if ($target_count == 0) {
722 if ($project!=$parent_project) {
723 my $parent_settings=@$parent_project[$P_SETTINGS];
724 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
725 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
726 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
727 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
728 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
733 # Otherwise add this project to the project list, except for
734 # the main project which is already in the list.
735 if ($dirname ne "") {
736 push @projects,$project;
739 # Ask for project-wide options
740 if ($opt_ask_project_options == $OPT_ASK_YES) {
742 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
745 if ((@$project_settings[$T_FLAGS] & $TF_WRAP)!=0) {
746 if ($flag_desc ne "") {
749 $flag_desc.="wrapped";
751 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc/--wrap),\n";
752 if (defined $flag_desc) {
753 print "* (currently $flag_desc)\n";
755 print "* or 'skip' to skip the target specific options,\n";
756 print "* or 'never' to not be asked this question again:\n";
760 if ($options eq "skip") {
761 $opt_ask_target_options=$OPT_ASK_SKIP;
763 } elsif ($options eq "never") {
764 $opt_ask_project_options=$OPT_ASK_NO;
766 } elsif (source_set_options($project_settings,$options)) {
769 print "Please re-enter the options:\n";
773 # - Create the targets
774 # - Check if we have both libraries and programs
775 # - Match each target with source files (sort in reverse
776 # alphabetical order to get the longest matches first)
778 my @local_depends=();
780 foreach my $target_name (sort { $b cmp $a } keys %targets) {
781 # Create the target...
784 target_init($target);
785 @$target[$T_NAME]=$target_name;
786 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
787 if ($target_name =~ /^lib(.*)\.so$/) {
788 @$target[$T_TYPE]=$TT_DLL;
789 @$target[$T_INIT]=get_default_init($TT_DLL);
790 @$target[$T_FLAGS]&=~$TF_WRAP;
792 push @local_depends,$target_name;
793 push @local_dlls,$basename;
795 @$target[$T_TYPE]=$opt_target_type;
796 @$target[$T_INIT]=get_default_init($opt_target_type);
797 $basename=$target_name;
798 push @exe_list,$target;
800 # This is the default link list of Visual Studio, except odbccp32
801 # which we don't have in Wine. Also I add ntdll which seems
802 # necessary for Winelib.
803 my @std_dlls=qw(advapi32.dll comdlg32.dll gdi32.dll kernel32.dll ntdll.dll odbc32.dll ole32.dll oleaut32.dll shell32.dll user32.dll winspool.drv);
804 if (@$target[$T_FLAGS] & $TF_NODLLS == 0) {
805 @$target[$T_DLLS]=\@std_dlls;
807 @$target[$T_DLLS]=[];
809 push @{@$project[$P_TARGETS]},$target;
811 # Ask for target-specific options
812 if ($opt_ask_target_options == $OPT_ASK_YES) {
814 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
817 if ((@$target[$T_FLAGS] & $TF_WRAP)!=0) {
818 if ($flag_desc ne "") {
823 $flag_desc.="wrapped";
825 if ($flag_desc ne "") {
828 print "* Specify any link option (-P/-i/-L/-l/--mfc/--wrap) specific to the target\n";
829 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
833 if ($options eq "never") {
834 $opt_ask_target_options=$OPT_ASK_NO;
836 } elsif (source_set_options($target,$options)) {
839 print "Please re-enter the options:\n";
842 push @{@$target[$T_DLL_PATH]},"-L\$(WINE_DLL_ROOT)";
843 if (@$target[$T_FLAGS] & $TF_MFC) {
844 @$project_settings[$T_FLAGS]|=$TF_MFC;
845 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
846 push @{@$target[$T_DLLS]},"mfc.dll";
847 # FIXME: Link with the MFC in the Unix sense, until we
848 # start exporting the functions properly.
849 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
850 push @{@$target[$T_LIBRARIES]},"mfc";
854 if ($target_count == 1) {
855 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
856 @$project_settings[$T_SOURCES_C]=[];
859 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
860 @$project_settings[$T_SOURCES_CXX]=[];
863 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
864 @$project_settings[$T_SOURCES_RC]=[];
867 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
868 # No need for sorting these sources
869 @$project_settings[$T_SOURCES_MISC]=[];
872 foreach my $source (@sources_c) {
873 if ($source =~ /^$basename/i) {
874 push @{@$target[$T_SOURCES_C]},$source;
878 foreach my $source (@sources_cxx) {
879 if ($source =~ /^$basename/i) {
880 push @{@$target[$T_SOURCES_CXX]},$source;
884 foreach my $source (@sources_rc) {
885 if ($source =~ /^$basename/i) {
886 push @{@$target[$T_SOURCES_RC]},$source;
890 foreach my $source (@sources_misc) {
891 if ($source =~ /^$basename/i) {
892 push @{@$target[$T_SOURCES_MISC]},$source;
897 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
898 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
899 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
900 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
902 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
903 $opt_ask_target_options=$OPT_ASK_YES;
906 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
907 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
909 # The sources that did not match, if any, go to the extra
910 # source list of the project settings
911 foreach my $source (@sources_c) {
913 push @{@$project_settings[$T_SOURCES_C]},$source;
916 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
917 foreach my $source (@sources_cxx) {
919 push @{@$project_settings[$T_SOURCES_CXX]},$source;
922 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
923 foreach my $source (@sources_rc) {
925 push @{@$project_settings[$T_SOURCES_RC]},$source;
928 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
929 foreach my $source (@sources_misc) {
931 push @{@$project_settings[$T_SOURCES_MISC]},$source;
934 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
936 # Finally if we are building both libraries and programs in
937 # this directory, then the programs should be linked with all
939 if (@local_dlls > 0 and @exe_list > 0) {
940 foreach my $target (@exe_list) {
941 push @{@$target[$T_DLL_PATH]},"-L.";
942 push @{@$target[$T_DLLS]},map { "$_.dll" } @local_dlls;
943 # Also link in the Unix sense since none of the functions
945 push @{@$target[$T_LIBRARY_PATH]},"-L.";
946 push @{@$target[$T_LIBRARIES]},@local_dlls;
947 push @{@$target[$T_DEPENDS]},@local_depends;
953 # Scan the source directories in search of things to build
956 # If there's a single target then this is going to be the default target
957 if (defined $opt_single_target) {
958 # Create the main target
960 target_init($main_target);
961 if ($opt_target_type == $TT_DLL) {
962 @$main_target[$T_NAME]="lib$opt_single_target.so";
964 @$main_target[$T_NAME]="$opt_single_target";
966 @$main_target[$T_TYPE]=$opt_target_type;
969 push @{$main_project[$P_TARGETS]},$main_target;
972 # The main directory is always going to be there
973 push @projects,\@main_project;
975 # Now scan the directory tree looking for source files and, maybe, targets
976 print "Scanning the source directories...\n";
977 source_scan_directory(\@main_project,"","",0);
979 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
986 # 'vc.dsp'-based Project analysis
999 # Creating the wrapper targets
1003 sub postprocess_targets()
1005 foreach my $project (@projects) {
1006 foreach my $target (@{@$project[$P_TARGETS]}) {
1007 if ((@$target[$T_FLAGS] & $TF_WRAP) != 0) {
1009 target_init($wrapper);
1010 @$wrapper[$T_NAME]=@$target[$T_NAME];
1011 @$wrapper[$T_TYPE]=@$target[$T_TYPE];
1012 @$wrapper[$T_INIT]=get_default_init(@$target[$T_TYPE]);
1013 @$wrapper[$T_FLAGS]=$TF_WRAPPER | (@$target[$T_FLAGS] & $TF_MFC);
1014 @$wrapper[$T_DLLS]=[ "kernel32.dll", "ntdll.dll", "user32.dll" ];
1015 push @{@$wrapper[$T_LIBRARIES]}, "dl";
1016 push @{@$wrapper[$T_SOURCES_C]},"@$wrapper[$T_NAME]_wrapper.c";
1018 my $index=bsearch(@$target[$T_SOURCES_C],"@$wrapper[$T_NAME]_wrapper.c");
1019 if (defined $index) {
1020 splice(@{@$target[$T_SOURCES_C]},$index,1);
1022 @$target[$T_NAME]="lib@$target[$T_NAME].so";
1023 @$target[$T_TYPE]=$TT_DLL;
1025 push @{@$project[$P_TARGETS]},$wrapper;
1027 if ((@$target[$T_FLAGS] & $TF_MFC) != 0) {
1028 @{@$project[$P_SETTINGS]}[$T_FLAGS]|=$TF_MFC;
1044 # Performs a directory traversal and renames the files so that:
1045 # - they have the case desired by the user
1046 # - their extension is of the appropriate case
1047 # - they don't contain annoying characters like ' ', '$', '#', ...
1048 sub fix_file_and_directory_names($);
1049 sub fix_file_and_directory_names($)
1053 if (opendir(DIRECTORY, "$dirname")) {
1054 foreach my $dentry (readdir DIRECTORY) {
1055 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1058 # Set $warn to 1 if the user should be warned of the renaming
1061 # autoconf and make don't support these characters well
1062 my $new_name=$dentry;
1063 $new_name =~ s/[ \$]/_/g;
1065 # Only all lowercase extensions are supported (because of the
1066 # transformations ':.c=.o') .
1067 if (-f "$dirname/$new_name") {
1068 if ($new_name =~ /\.C$/) {
1069 $new_name =~ s/\.C$/.c/;
1071 if ($new_name =~ /\.cpp$/i) {
1072 $new_name =~ s/\.cpp$/.cpp/i;
1074 if ($new_name =~ s/\.cxx$/.cpp/i) {
1077 if ($new_name =~ /\.rc$/i) {
1078 $new_name =~ s/\.rc$/.rc/i;
1080 # And this last one is to avoid confusion then running make
1081 if ($new_name =~ s/^makefile$/makefile.win/) {
1086 # Adjust the case to the user's preferences
1087 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1088 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1090 $new_name=lc $new_name;
1093 # And finally, perform the renaming
1094 if ($new_name ne $dentry) {
1096 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1098 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1099 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1100 print STDERR " $!\n";
1104 if (-d "$dirname/$new_name") {
1105 fix_file_and_directory_names("$dirname/$new_name");
1108 closedir(DIRECTORY);
1121 # This maps a directory name to a reference to an array listing
1122 # its contents (files and directories)
1126 # Retrieves the contents of the specified directory.
1127 # We either get it from the directories hashtable which acts as a
1128 # cache, or use opendir, readdir, closedir and store the result
1130 sub get_directory_contents($)
1135 #print "getting the contents of $dirname\n";
1137 # check for a cached version
1139 if ($dirname eq "") {
1142 $directory=$directories{$dirname};
1143 if (defined $directory) {
1144 #print "->@$directory\n";
1148 # Read this directory
1149 if (opendir(DIRECTORY, "$dirname")) {
1150 my @files=readdir DIRECTORY;
1151 closedir(DIRECTORY);
1154 # Return an empty list
1155 #print "error: cannot open $dirname\n";
1159 #print "->@$directory\n";
1160 $directories{$dirname}=$directory;
1165 # Try to find a file for the specified filename. The attempt is
1166 # case-insensitive which is why it's not trivial. If a match is
1167 # found then we return the pathname with the correct case.
1174 if ($dirname eq "" or $dirname eq ".") {
1176 } elsif ($dirname =~ m+^[^/]+) {
1177 $dirname=cwd . "/" . $dirname;
1179 if ($dirname !~ m+/$+) {
1183 foreach my $component (@$path) {
1184 #print " looking for $component in \"$dirname\"\n";
1185 if ($component eq ".") {
1188 } elsif ($component eq "..") {
1190 $dirname=dirname($dirname) . "/";
1193 # The file/directory may have been renamed before. Also try to
1194 # match the renamed file.
1195 my $renamed=$component;
1196 $renamed =~ s/[ \$]/_/g;
1197 if ($renamed eq $component) {
1201 my $directory=get_directory_contents $dirname;
1203 foreach my $dentry (@$directory) {
1204 if ($dentry =~ /^$component$/i or
1205 (defined $renamed and $dentry =~ /^$renamed$/i)
1207 $dirname.="$dentry/";
1208 $real_path.="$dentry/";
1213 if (!defined $found) {
1215 #print " could not find $component in $dirname\n";
1220 $real_path=~ s+/$++;
1221 #print " -> found $real_path\n";
1226 # Performs a case-insensitive search for the specified file in the
1228 # $line is the line number that should be referenced when an error occurs
1229 # $filename is the file we are looking for
1230 # $dirname is the directory of the file containing the '#include' directive
1231 # if '"' was used, it is an empty string otherwise
1232 # $project and $target specify part of the include path
1233 sub get_real_include_name($$$$$)
1241 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1242 # This is not a relative path, we cannot make any check
1243 my $warning="path:$filename";
1244 if (!defined $warnings{$warning}) {
1245 $warnings{$warning}="1";
1246 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1247 print STDERR "$line: $filename\n";
1250 # Here's how we proceed:
1251 # - split the filename we look for into its components
1252 # - then for each directory in the include path
1253 # - trace the directory components starting from that directory
1254 # - if we fail to find a match at any point then continue with
1255 # the next directory in the include path
1256 # - otherwise, rejoice, our quest is over.
1257 my @file_components=split /[\/\\]+/, $filename;
1258 #print " Searching for $filename from @$project[$P_PATH]\n";
1261 if ($dirname ne "") {
1262 # This is an 'include ""' -> look in dirname first.
1263 #print " in $dirname (include \"\")\n";
1264 $real_filename=search_from($dirname,\@file_components);
1265 if (defined $real_filename) {
1266 return $real_filename;
1269 my $project_settings=@$project[$P_SETTINGS];
1270 foreach my $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1271 my $dirname=$include;
1273 if (!is_absolute($dirname)) {
1274 $dirname="@$project[$P_PATH]$dirname";
1276 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1277 $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
1279 #print " in $dirname\n";
1280 $real_filename=search_from("$dirname",\@file_components);
1281 if (defined $real_filename) {
1282 return $real_filename;
1285 my $dotdotpath=@$project[$P_PATH];
1286 $dotdotpath =~ s/[^\/]+/../g;
1287 foreach my $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1288 my $dirname=$include;
1290 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1291 $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
1292 #print " in $dirname (global setting)\n";
1293 $real_filename=search_from("$dirname",\@file_components);
1294 if (defined $real_filename) {
1295 return $real_filename;
1299 $filename =~ s+\\\\+/+g; # in include ""
1300 $filename =~ s+\\+/+g; # in include <> !
1301 if ($opt_lower_include) {
1302 return lc "$filename";
1313 if ($size =~ /^(1|2|4|8)$/) {
1314 print FILEO "$indent#include <pshpack$size.h>$trailer";
1316 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1317 print FILEO "$indent#include <pshpack4.h>$trailer";
1322 # 'Parses' a source file and fixes constructs that would not work with
1323 # Winelib. The parsing is rather simple and not all non-portable features
1324 # are corrected. The most important feature that is corrected is the case
1325 # and path separator of '#include' directives. This requires that each
1326 # source file be associated to a project & target so that the proper
1327 # include path is used.
1328 # Also note that the include path is relative to the directory in which the
1329 # compiler is run, i.e. that of the project, not to that of the file.
1335 $filename="@$project[$P_PATH]$filename";
1336 if (! -e $filename) {
1340 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1341 my $dirname=dirname($filename);
1343 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1347 print " $filename\n";
1348 #FIXME:assuming that because there is a .bak file, this is what we want is
1349 #probably flawed. Or is it???
1350 if (! -e "$filename.bak") {
1351 if (!copy("$filename","$filename.bak")) {
1352 print STDERR "error: unable to make a backup of $filename:\n";
1353 print STDERR " $!\n";
1357 if (!open(FILEI,"$filename.bak")) {
1358 print STDERR "error: unable to open $filename.bak for reading:\n";
1359 print STDERR " $!\n";
1362 if (!open(FILEO,">$filename")) {
1363 print STDERR "error: unable to open $filename for writing:\n";
1364 print STDERR " $!\n";
1369 my $rc_block_depth=0;
1370 my $rc_textinclude_state=0;
1373 # Remove any trailing CtrlZ, which isn't strictly in the file
1381 # Make sure all files are '\n' terminated
1384 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
1385 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1386 # the RC files it generates (even in non-MFC projects). So we replace
1387 # it with 'winres.h' its very close standard cousin so that non MFC
1388 # projects can compile in Wine without the MFC sources.
1389 my $warning="mfc:afxres.h";
1390 if (!defined $warnings{$warning}) {
1391 $warnings{$warning}="1";
1392 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winres.h'\n";
1393 print STDERR "warning: the above warning is issued only once\n";
1395 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
1396 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winres.h' */\n";
1397 print FILEO "$1$2\"winres.h\"$'";
1400 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1401 my $from_file=($2 eq "<"?"":$dirname);
1402 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1403 print FILEO "$1$2$real_include_name$4$'";
1404 $modified|=($real_include_name ne $3);
1406 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
1407 # Pragma pack handling
1409 # pack_stack is an array of references describing the stack of
1410 # pack directives currently in effect. Each directive if described
1411 # by a reference to an array containing:
1412 # - "push" for pack(push,...) directives, "" otherwise
1413 # - the directive's identifier at index 1
1414 # - the directive's alignement value at index 2
1416 # Don't believe a word of what the documentation says: it's all wrong.
1417 # The code below is based on the actual behavior of Visual C/C++ 6.
1422 # Pushes the default stack alignment
1423 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1424 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1425 print_pack($pack_indent,4,$');
1426 push @pack_stack, [ "", "", 4 ];
1428 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
1430 # pragma pack(pop,n)
1431 # Goes up the stack until it finds a pack(push,...), and pops it
1432 # Ignores any pack(n) entry
1433 # Issues a warning if the pack is of the form pack(push,label)
1434 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1435 my $pack_comment=$';
1436 $pack_comment =~ s/^\s*//;
1437 if ($pack_comment ne "") {
1438 print FILEO "$pack_indent$pack_comment";
1441 my $alignment=pop @pack_stack;
1442 if (!defined $alignment) {
1443 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
1446 if (@$alignment[1]) {
1447 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
1449 print FILEO "$pack_indent#include <poppack.h>\n";
1450 if (@$alignment[0]) {
1455 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
1456 # pragma pack(pop,label[,n])
1457 # Goes up the stack until finding a pack(push,...) and pops it.
1458 # 'n', if specified, is ignored.
1459 # Ignores any pack(n) entry
1460 # Issues a warning if the label of the pack does not match,
1461 # or if it is in fact a pack(push,n)
1463 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1464 my $pack_comment=$';
1465 $pack_comment =~ s/^\s*//;
1466 if ($pack_comment ne "") {
1467 print FILEO "$pack_indent$pack_comment";
1470 my $alignment=pop @pack_stack;
1471 if (!defined $alignment) {
1472 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
1475 if (@$alignment[1] and @$alignment[1] ne $label) {
1476 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
1478 print FILEO "$pack_indent#include <poppack.h>\n";
1479 if (@$alignment[0]) {
1484 } elsif (/^(push\s*\))/) {
1486 # Push the current alignment
1487 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1488 if (@pack_stack > 0) {
1489 my $alignment=$pack_stack[$#pack_stack];
1490 print_pack($pack_indent,@$alignment[2],$');
1491 push @pack_stack, [ "push", "", @$alignment[2] ];
1493 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1494 print_pack($pack_indent,4,$');
1495 push @pack_stack, [ "push", "", 4 ];
1498 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
1499 # pragma pack([push,]n)
1500 # Push new alignment n
1501 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1502 print_pack($pack_indent,$3,"$'");
1503 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
1505 } elsif (/^((\w+)\s*\))/) {
1506 # pragma pack(label)
1507 # label must in fact be a macro that resolves to an integer
1508 # Then behaves like 'pragma pack(n)'
1509 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1510 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
1511 print_pack($pack_indent,4,$');
1512 push @pack_stack, [ "", "", 4 ];
1514 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
1515 # pragma pack(push,label[,n])
1516 # Pushes a new label on the stack. It is possible to push the same
1517 # label multiple times. If 'n' is omitted then the alignment is
1518 # unchanged. Otherwise it becomes 'n'.
1519 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1523 } elsif (@pack_stack > 0) {
1524 my $alignment=$pack_stack[$#pack_stack];
1525 $size=@$alignment[2];
1527 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1530 print_pack($pack_indent,$size,$');
1531 push @pack_stack, [ "push", $2, $size ];
1534 # pragma pack(??? -> What's that?
1535 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
1536 print FILEO "$pack_indent$pack_header$_";
1542 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]+)([\">]?)/) {
1543 my $from_file=($5 eq "<"?"":$dirname);
1544 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
1545 print FILEO "$1$5$real_include_name$7$'";
1546 $modified|=($real_include_name ne $6);
1548 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1549 my $from_file=($2 eq "<"?"":$dirname);
1550 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1551 print FILEO "$1$2$real_include_name$4$'";
1552 $modified|=($real_include_name ne $3);
1554 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
1555 $rc_textinclude_state=1;
1558 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
1559 print FILEO "$1winres.h$2$'";
1562 } elsif (/^\s*BEGIN(\W.*)?$/) {
1563 $rc_textinclude_state|=2;
1567 } elsif (/^\s*END(\W.*)?$/) {
1568 $rc_textinclude_state=0;
1569 if ($rc_block_depth>0) {
1585 if ($opt_backup == 0 or $modified == 0) {
1586 if (!unlink("$filename.bak")) {
1587 print STDERR "error: unable to delete $filename.bak:\n";
1588 print STDERR " $!\n";
1594 # Analyzes each source file in turn to find and correct issues
1595 # that would cause it not to compile.
1598 print "Fixing the source files...\n";
1599 foreach my $project (@projects) {
1600 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
1601 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1604 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
1605 fix_file($source,$project,$target);
1620 # Generates a target's .spec file
1621 sub generate_spec_file($$$)
1623 if ($opt_no_generated_specs) {
1628 my $project_settings=$_[2];
1630 my $basename=@$target[$T_NAME];
1631 $basename =~ s+\.so$++;
1632 if (@$target[$T_FLAGS] & $TF_WRAP) {
1633 $basename =~ s+^lib++;
1634 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1635 $basename.="_wrapper";
1637 if (@$target[$T_TYPE] != $TT_DLL) {
1638 $basename .= '.exe';
1641 if (!open(FILEO,">$path$basename.spec")) {
1642 print STDERR "error: could not open \"$path$basename.spec\" for writing\n";
1643 print STDERR " $!\n";
1647 if (defined @$target[$T_INIT] and ((@$target[$T_FLAGS] & $TF_WRAP) == 0)) {
1648 print FILEO "init @$target[$T_INIT]\n";
1652 # Don't forget to export the 'Main' function for wrapped executables,
1653 # except for MFC ones!
1654 if ((@$target[$T_FLAGS]&($TF_WRAP|$TF_WRAPPER|$TF_MFC)) == $TF_WRAP) {
1655 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1656 print FILEO "\n@ stdcall @$target[$T_INIT](long long ptr long) @$target[$T_INIT]\n";
1657 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1658 print FILEO "\n@ stdcall @$target[$T_INIT](long ptr ptr) @$target[$T_INIT]\n";
1660 print FILEO "\n@ stdcall @$target[$T_INIT](ptr long ptr) @$target[$T_INIT]\n";
1668 # Generates a target's wrapper file
1669 sub generate_wrapper_file($$)
1674 return generate_from_template("wrapper.c","$path${app_name}_wrapper.c",[
1675 ["APP_NAME",@$target[$T_NAME]],
1676 ["APP_TYPE",(@$target[$T_TYPE]==$TT_GUIEXE?"GUIEXE":"CUIEXE")],
1677 ["APP_INIT",(@$target[$T_TYPE]==$TT_GUIEXE?"\"WinMain\"":"\"main\"")],
1678 ["APP_MFC",(@$target[$T_FLAGS] & $TF_MFC?"\"mfc\"":"NULL")]]);
1682 # A convenience function to generate all the lists (defines,
1683 # C sources, C++ source, etc.) in the Makefile
1684 sub generate_list($$$;$)
1693 printf FILEO "%-22s=",$name;
1695 if (defined $list) {
1696 foreach my $item (@$list) {
1698 if (defined $data) {
1699 $value=&$data($item);
1705 print FILEO " $value";
1708 print FILEO " \\\n\t\t\t$value";
1719 # Generates a project's Makefile.in and all the target files
1720 sub generate_project_files($)
1723 my $project_settings=@$project[$P_SETTINGS];
1727 # Then sort the targets and separate the libraries from the programs
1728 foreach my $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
1729 if (@$target[$T_TYPE] == $TT_DLL) {
1730 push @dll_list,$target;
1732 push @exe_list,$target;
1735 @$project[$P_TARGETS]=[];
1736 push @{@$project[$P_TARGETS]}, @dll_list;
1737 push @{@$project[$P_TARGETS]}, @exe_list;
1739 if (!open(FILEO,">@$project[$P_PATH]Makefile.in")) {
1740 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile.in\" for writing\n";
1741 print STDERR " $!\n";
1745 print FILEO "### Generated by Winemaker\n";
1748 print FILEO "### Generic autoconf variables\n\n";
1749 generate_list("TOPSRCDIR",1,[ "\@top_srcdir\@" ]);
1750 my $dotdotpath=@$project[$P_PATH];
1751 $dotdotpath =~ s%[^/]+%..%g;
1752 $dotdotpath =~ s%/$%%;
1753 $dotdotpath = "." if ($dotdotpath eq "");
1754 generate_list("TOPOBJDIR",1,[ $dotdotpath ]);
1755 generate_list("SRCDIR",1,[ "\@srcdir\@" ]);
1756 generate_list("VPATH",1,[ "\@srcdir\@" ]);
1758 if (@$project[$P_PATH] eq "") {
1759 # This is the main project. It is also responsible for recursively
1760 # calling the other projects
1761 generate_list("SUBDIRS",1,\@projects,sub
1763 if ($_[0] != \@main_project) {
1764 my $subdir=@{$_[0]}[$P_PATH];
1768 # Eliminating the main project by returning undefined!
1771 if (@{@$project[$P_TARGETS]} > 0) {
1772 generate_list("DLLS",1,\@dll_list,sub
1774 return @{$_[0]}[$T_NAME];
1776 generate_list("EXES",1,\@exe_list,sub
1778 return "@{$_[0]}[$T_NAME].exe";
1780 print FILEO "\n\n\n";
1782 print FILEO "### Common settings\n\n";
1783 # Make it so that the project-wide settings override the global settings
1784 generate_list("DEFINES",1,@$project_settings[$T_DEFINES]);
1785 generate_list("INCLUDE_PATH",1,@$project_settings[$T_INCLUDE_PATH]);
1786 generate_list("DLL_PATH",1,@$project_settings[$T_DLL_PATH]);
1787 generate_list("LIBRARY_PATH",1,@$project_settings[$T_LIBRARY_PATH]);
1788 generate_list("LIBRARIES",1,@$project_settings[$T_LIBRARIES]);
1791 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
1792 @{@$project_settings[$T_SOURCES_CXX]}+
1793 @{@$project_settings[$T_SOURCES_RC]};
1794 my $no_extra=($extra_source_count == 0);
1796 print FILEO "### Extra source lists\n\n";
1797 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
1798 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
1799 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
1801 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
1802 print FILEO "\n\n\n";
1805 # Iterate over all the targets...
1806 foreach my $target (@{@$project[$P_TARGETS]}) {
1807 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
1808 my $canon=canonize("@$target[$T_NAME]");
1810 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
1811 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
1812 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
1813 my $basename=@$target[$T_NAME];
1814 $basename =~ s+\.so$++;
1815 if (@$target[$T_FLAGS] & $TF_WRAP) {
1816 $basename =~ s+^lib++;
1817 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1818 $basename.="_wrapper";
1820 if (@$target[$T_TYPE] != $TT_DLL) {
1821 generate_list("${canon}_SPEC_SRCS",1,[ "$basename.exe.spec" ]);
1823 generate_list("${canon}_SPEC_SRCS",1,[ "$basename.spec" ]);
1825 generate_list("${canon}_DLL_PATH",1,@$target[$T_DLL_PATH]);
1826 generate_list("${canon}_DLLS",1,@$target[$T_DLLS]);
1827 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]);
1828 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]);
1829 generate_list("${canon}_DEPENDS",1,@$target[$T_DEPENDS]);
1831 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(EXTRA_OBJS)"]);
1832 print FILEO "\n\n\n";
1834 print FILEO "### Global source lists\n\n";
1835 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
1837 my $canon=canonize(@{$_[0]}[$T_NAME]);
1839 return "\$(${canon}_C_SRCS)";
1842 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
1844 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
1846 my $canon=canonize(@{$_[0]}[$T_NAME]);
1848 return "\$(${canon}_CXX_SRCS)";
1851 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
1853 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
1855 my $canon=canonize(@{$_[0]}[$T_NAME]);
1857 return "\$(${canon}_RC_SRCS)";
1860 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
1862 generate_list("SPEC_SRCS",1,@$project[$P_TARGETS],sub
1864 my $canon=canonize(@{$_[0]}[$T_NAME]);
1866 return "\$(${canon}_SPEC_SRCS)";
1869 print FILEO "\n\n\n";
1871 print FILEO "### Generic autoconf targets\n\n";
1873 if (@$project[$P_PATH] eq "") {
1874 print FILEO " wineapploader";
1875 print FILEO " \$(SUBDIRS)";
1877 if (@{@$project[$P_TARGETS]} > 0) {
1878 print FILEO " \$(DLLS) \$(EXES:%=%.so)";
1881 if (@$project[$P_PATH] eq "") {
1882 print FILEO "wineapploader: wineapploader.in\n";
1883 print FILEO "\tsed -e 's,\@bindir\\\@,\$(bindir),g' " .
1884 "-e 's,\@winelibdir\\\@,.,g' " .
1885 "\$(SRCDIR)/wineapploader.in >\$\@ || \$(RM) \$\@\n";
1888 print FILEO "\@MAKE_RULES\@\n";
1890 print FILEO "install::\n";
1891 if (@$project[$P_PATH] eq "") {
1892 # This is the main project. It is also responsible for recursively
1893 # calling the other projects
1894 print FILEO "\t_list=\"\$(SUBDIRS)\"; for i in \$\$_list; do (cd \$\$i; \$(MAKE) install) || exit 1; done\n";
1896 if (@{@$project[$P_TARGETS]} > 0) {
1897 print FILEO "\t_list=\"\$(EXES:%=%.so)\"; for i in \$\$_list; do \$(INSTALL_PROGRAM) \$\$i \$(libdir); done\n";
1898 print FILEO "\t_list=\"\$(EXES)\"; for i in \$\$_list; do \$(INSTALL_SCRIPT) \$\$i \$(bindir); done\n";
1899 print FILEO "\t_list=\"\$(DLLS)\"; for i in \$\$_list; do \$(INSTALL_PROGRAM) \$\$i \$(libdir); done\n";
1902 print FILEO "uninstall::\n";
1903 if (@$project[$P_PATH] eq "") {
1904 # This is the main project. It is also responsible for recursively
1905 # calling the other projects
1906 print FILEO "\t_list=\"\$(SUBDIRS)\"; for i in \$\$_list; do (cd \$\$i; \$(MAKE) uninstall) || exit 1; done\n";
1908 if (@{@$project[$P_TARGETS]} > 0) {
1909 print FILEO "\t_list=\"\$(EXES) \$(EXES:%=%.so)\"; for i in \$\$_list; do \$(RM) \$(libdir)/\$\$i;done\n";
1910 print FILEO "\t_list=\"\$(EXES)\"; for i in \$\$_list; do \$(RM) \$(bindir)/\$\$i;done\n";
1911 print FILEO "\t_list=\"\$(DLLS)\"; for i in \$\$_list; do \$(RM) \$(libdir)/\$\$i;done\n";
1914 print FILEO "clean::\n";
1915 print FILEO "\t\$(RM)";
1916 if (@$project[$P_PATH] eq "") {
1917 print FILEO " wineapploader";
1919 if (@{@$project[$P_TARGETS]} > 0) {
1920 print FILEO " \$(EXES)";
1924 if (@{@$project[$P_TARGETS]} > 0) {
1925 print FILEO "### Target specific build rules\n\n";
1926 foreach my $target (@{@$project[$P_TARGETS]}) {
1927 my $canon=canonize("@$target[$T_NAME]");
1931 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1933 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1939 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.spec.c): \$(${canon}_SPEC_SRCS) \$(${canon}_OBJS) \$(${canon}_RC_SRCS:.rc=.res)\n";
1940 print FILEO "\t\$(LD_PATH) \$(WINEBUILD) -fPIC \$(${canon}_DLL_PATH) \$(WINE_DLL_PATH) \$(${canon}_DLLS:%=-l%) \$(${canon}_RC_SRCS:%.rc=-res %.res) $mode \$(${canon}_OBJS) -o \$\@ -spec \$(SRCDIR)/\$(${canon}_SPEC_SRCS)\n";
1942 my $t_name=@$target[$T_NAME];
1943 if (@$target[$T_TYPE]!=$TT_DLL) {
1946 print FILEO "$t_name: \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_OBJS) \$(${canon}_DEPENDS) \n";
1947 if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
1948 print FILEO "\t\$(LDXXSHARED)";
1950 print FILEO "\t\$(LDSHARED)";
1952 print FILEO " \$(LDDLLFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_LIBRARY_PATH) \$(${canon}_LIBRARIES:%=-l%) \$(DLL_LINK) \$(LIBS)\n";
1953 if (@$target[$T_TYPE] ne $TT_DLL) {
1954 print FILEO "\ttest -f @$target[$T_NAME] || \$(INSTALL_SCRIPT) wineapploader @$target[$T_NAME]\n";
1961 foreach my $target (@{@$project[$P_TARGETS]}) {
1962 generate_spec_file(@$project[$P_PATH],$target,$project_settings);
1963 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1964 generate_wrapper_file(@$project[$P_PATH],$target);
1970 # Perform the replacements in the template configure files
1971 # Return 1 for success, 0 for failure
1972 sub generate_from_template($$;$)
1976 my $substitutions=$_[2];
1978 if (!defined $templates{$template}) {
1979 print STDERR "winemaker: internal error: No template called '$template'\n";
1983 if (!open(FILEO,">$filename")) {
1984 print STDERR "error: unable to open \"$filename\" for writing:\n";
1985 print STDERR " $!\n";
1989 foreach my $line (@{$templates{$template}}) {
1990 if ($line =~ /(\#\#WINEMAKER_[A-Z_]+\#\#)/) {
1991 if (defined $substitutions) {
1992 foreach my $pattern (@$substitutions) {
1993 $line =~ s%\#\#WINEMAKER_@$pattern[0]\#\#%@$pattern[1]%;
1996 if (!$warned and $line =~ /(\#\#WINEMAKER_[A-Z_]+\#\#)/) {
1997 print STDERR "warning: no value was provided for template $1 in \"$filename\"\n";
2008 # Generates the global files:
2013 sub generate_global_files()
2016 foreach my $path (@{$global_settings[$T_INCLUDE_PATH]}) {
2017 if ($path !~ /^-L/ or is_absolute($')) {
2018 push @include_path, $path;
2020 push @include_path, "-L\$(TOPSRCDIR)/$'";
2024 foreach my $path (@{$global_settings[$T_DLL_PATH]}) {
2025 if ($path !~ /^-L/ or is_absolute($')) {
2026 push @dll_path, $path;
2028 push @dll_path, "-L\$(TOPSRCDIR)/$'";
2032 foreach my $path (@{$global_settings[$T_LIBRARY_PATH]}) {
2033 if ($path !~ /^-L/ or is_absolute($')) {
2034 push @library_path, $path;
2036 push @library_path, "-L\$(TOPSRCDIR)/$'";
2039 generate_from_template("Make.rules.in","Make.rules.in",[
2040 ["DEFINES", join(" ", @{$global_settings[$T_DEFINES]}) ],
2041 ["INCLUDE_PATH", join(" ", @include_path) ],
2042 ["DLL_PATH", join(" ", @dll_path) ],
2043 ["DLLS", join(" ", @{$global_settings[$T_DLLS]}) ],
2044 ["LIBRARY_PATH", join(" ", @library_path) ],
2045 ["LIBRARIES", join(" ", @{$global_settings[$T_LIBRARIES]}) ]]);
2046 generate_from_template("wineapploader.in","wineapploader.in");
2048 # Get the name of a source file for configure.ac
2050 search_a_file: foreach my $project (@projects) {
2051 foreach my $target (@{@$project[$P_TARGETS]}, @$project[$P_SETTINGS]) {
2052 $a_source_file=@{@$target[$T_SOURCES_C]}[0];
2053 if (!defined $a_source_file) {
2054 $a_source_file=@{@$target[$T_SOURCES_CXX]}[0];
2056 if (!defined $a_source_file) {
2057 $a_source_file=@{@$target[$T_SOURCES_RC]}[0];
2059 if (defined $a_source_file) {
2060 $a_source_file="@$project[$P_PATH]$a_source_file";
2065 if (!defined $a_source_file) {
2066 $a_source_file="Makefile.in";
2068 generate_from_template("configure.ac","configure.ac",[
2069 ["PROJECTS",join("\n",map { "@$_[$P_PATH]Makefile" } @projects)],
2070 ["SOURCE","$a_source_file"],
2071 ["NEEDS_MFC","$needs_mfc"]]);
2074 # Add execute permission to configure for whoever has the right to read it
2075 my @st=stat("configure");
2078 $mode|=($mode & 0444) >>2;
2079 chmod($mode,"configure");
2081 print "warning: could not generate the configure script. You need to run autoconf\n";
2087 sub generate_read_templates()
2092 if (/^--- ((\w\.?)+) ---$/) {
2094 if (defined $templates{$filename}) {
2095 print STDERR "winemaker: internal error: There is more than one template for $filename\n";
2099 $templates{$filename}=$file;
2101 } elsif (defined $file) {
2108 # This is where we finally generate files. In fact this method does not
2109 # do anything itself but calls the methods that do the actual work.
2112 print "Generating project files...\n";
2113 generate_read_templates();
2114 generate_global_files();
2116 foreach my $project (@projects) {
2117 my $path=@$project[$P_PATH];
2124 generate_project_files($project);
2137 $opt_lower=$OPT_LOWER_UPPERCASE;
2138 $opt_lower_include=1;
2140 # $opt_work_dir=<undefined>
2141 # $opt_single_target=<undefined>
2142 $opt_target_type=$TT_GUIEXE;
2144 $opt_is_interactive=$OPT_ASK_NO;
2145 $opt_ask_project_options=$OPT_ASK_NO;
2146 $opt_ask_target_options=$OPT_ASK_NO;
2147 $opt_no_generated_files=0;
2148 $opt_no_generated_specs=0;
2149 $opt_no_source_fix=0;
2162 print "Winemaker $version\n";
2163 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2169 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2170 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2171 print STDERR " [--lower-include|--nolower-include]\n";
2172 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll|--nodlls]\n";
2173 print STDERR " [--wrap|--nowrap] [--mfc|--nomfc]\n";
2174 print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2175 print STDERR " [--interactive] [--single-target name]\n";
2176 print STDERR " [--generated-files|--nogenerated-files] [--nogenerated-specs]\n";
2177 print STDERR " work_directory\n";
2178 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2179 print STDERR "the specified directory so that they can be compiled with Winelib. During this\n";
2180 print STDERR "process it will modify and rename some of the files in that directory.\n";
2181 print STDERR "\tPlease read the manual page before use.\n";
2186 my $arg=shift @ARGV;
2188 if ($arg eq "--nobanner") {
2190 } elsif ($arg eq "--backup") {
2192 } elsif ($arg eq "--nobackup") {
2194 } elsif ($arg eq "--single-target") {
2195 $opt_single_target=shift @ARGV;
2196 } elsif ($arg eq "--lower-none") {
2197 $opt_lower=$OPT_LOWER_NONE;
2198 } elsif ($arg eq "--lower-all") {
2199 $opt_lower=$OPT_LOWER_ALL;
2200 } elsif ($arg eq "--lower-uppercase") {
2201 $opt_lower=$OPT_LOWER_UPPERCASE;
2202 } elsif ($arg eq "--lower-include") {
2203 $opt_lower_include=1;
2204 } elsif ($arg eq "--nolower-include") {
2205 $opt_lower_include=0;
2206 } elsif ($arg eq "--nosource-fix") {
2207 $opt_no_source_fix=1;
2208 } elsif ($arg eq "--generated-files") {
2209 $opt_no_generated_files=0;
2210 } elsif ($arg eq "--nogenerated-files") {
2211 $opt_no_generated_files=1;
2212 } elsif ($arg eq "--nogenerated-specs") {
2213 $opt_no_generated_specs=1;
2215 } elsif ($arg =~ /^-D/) {
2216 push @{$global_settings[$T_DEFINES]},$arg;
2217 } elsif ($arg =~ /^-I/) {
2218 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2219 } elsif ($arg =~ /^-P/) {
2220 push @{$global_settings[$T_DLL_PATH]},"-L$'";
2221 } elsif ($arg =~ /^-i/) {
2222 push @{$global_settings[$T_DLLS]},$';
2223 } elsif ($arg =~ /^-L/) {
2224 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2225 } elsif ($arg =~ /^-l/) {
2226 push @{$global_settings[$T_LIBRARIES]},$';
2228 # 'Source'-based method options
2229 } elsif ($arg eq "--dll") {
2230 $opt_target_type=$TT_DLL;
2231 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2232 $opt_target_type=$TT_GUIEXE;
2233 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2234 $opt_target_type=$TT_CUIEXE;
2235 } elsif ($arg eq "--interactive") {
2236 $opt_is_interactive=$OPT_ASK_YES;
2237 $opt_ask_project_options=$OPT_ASK_YES;
2238 $opt_ask_target_options=$OPT_ASK_YES;
2239 } elsif ($arg eq "--wrap") {
2240 $opt_flags|=$TF_WRAP;
2241 } elsif ($arg eq "--nowrap") {
2242 $opt_flags&=~$TF_WRAP;
2243 } elsif ($arg eq "--mfc") {
2244 $opt_flags|=$TF_MFC;
2246 } elsif ($arg eq "--nomfc") {
2247 $opt_flags&=~$TF_MFC;
2248 $opt_flags|=$TF_NOMFC;
2250 } elsif ($arg eq "--nodlls") {
2251 $opt_flags|=$TF_NODLLS;
2255 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2256 if (!defined $opt_work_dir) {
2259 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2267 if ($opt_flags & $TF_MFC && $opt_target_type != $TT_DLL) {
2268 print STDERR "info: option --mfc requires --wrap\n";
2269 $opt_flags |= $TF_WRAP;
2273 if (!defined $opt_work_dir) {
2274 print STDERR "error: you must specify the directory containing the sources to be converted\n";
2276 } elsif (!chdir $opt_work_dir) {
2277 print STDERR "error: could not chdir to the work directory\n";
2278 print STDERR " $!\n";
2282 if ($opt_no_banner == 0) {
2286 project_init(\@main_project,"");
2287 target_init(\@global_settings);
2289 # Fix the file and directory names
2290 fix_file_and_directory_names(".");
2292 # Scan the sources to identify the projects and targets
2295 # Create targets for wrappers, etc.
2296 postprocess_targets();
2298 # Fix the source files
2299 if (! $opt_no_source_fix) {
2303 # Generate the Makefile and the spec file
2304 if (! $opt_no_generated_files) {
2310 --- configure.ac ---
2311 dnl Process this file with autoconf to produce a configure script.
2312 dnl Author: Michael Patra <micky@marie.physik.tu-berlin.de>
2313 dnl <patra@itp1.physik.tu-berlin.de>
2314 dnl Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2316 AC_REVISION([configure.ac 1.00])
2317 AC_INIT(##WINEMAKER_SOURCE##)
2319 NEEDS_MFC=##WINEMAKER_NEEDS_MFC##
2321 dnl **** Command-line arguments ****
2325 dnl **** Check for some programs ****
2333 dnl **** Check for some libraries ****
2335 dnl Check for -lm for BeOS
2336 AC_CHECK_LIB(m,sqrt)
2337 dnl Check for -lw for Solaris
2338 AC_CHECK_LIB(w,iswalnum)
2339 dnl Check for -lnsl for Solaris
2340 AC_CHECK_FUNCS(gethostbyname,, AC_CHECK_LIB(nsl, gethostbyname, X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl", AC_CHECK_LIB(socket, gethostbyname, X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl", , -lnsl), -lsocket))
2341 dnl Check for -lsocket for Solaris
2342 AC_CHECK_FUNCS(connect,,AC_CHECK_LIB(socket,connect))
2344 dnl **** Check for gcc strength-reduce bug ****
2346 if test "x${GCC}" = "xyes"
2348 AC_CACHE_CHECK( "for gcc strength-reduce bug", ac_cv_c_gcc_strength_bug,
2351 static int Array[[3]];
2354 for(i=0; i<B; i++) Array[[i]] = i - 3;
2355 exit( Array[[1]] != -2 );
2357 ac_cv_c_gcc_strength_bug="no",
2358 ac_cv_c_gcc_strength_bug="yes",
2359 ac_cv_c_gcc_strength_bug="yes") )
2360 if test "$ac_cv_c_gcc_strength_bug" = "yes"
2362 CFLAGS="$CFLAGS -fno-strength-reduce"
2366 dnl **** Check for underscore on external symbols ****
2368 AC_CACHE_CHECK("whether external symbols need an underscore prefix",
2369 ac_cv_c_extern_prefix,
2371 LIBS="conftest_asm.s $LIBS"
2372 cat > conftest_asm.s <<EOF
2377 AC_TRY_LINK([extern int ac_test;],[if (ac_test) return 1],
2378 ac_cv_c_extern_prefix="yes",ac_cv_c_extern_prefix="no")
2380 if test "$ac_cv_c_extern_prefix" = "yes"
2382 AC_DEFINE(NEED_UNDERSCORE_PREFIX)
2385 dnl **** Check for working dll ****
2390 AC_CACHE_CHECK("whether we can build a Linux dll",
2392 [saved_cflags=$CFLAGS
2393 CFLAGS="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0,-Bsymbolic"
2394 AC_TRY_LINK(,[return 1],ac_cv_c_dll_linux="yes",ac_cv_c_dll_linux="no")
2395 CFLAGS=$saved_cflags
2397 if test "$ac_cv_c_dll_linux" = "yes"
2399 LDSHARED="\$(CC) -shared"
2400 LDXXSHARED="\$(CXX) -shared"
2401 LDDLLFLAGS="-Wl,-Bsymbolic"
2403 AC_CACHE_CHECK(whether we can build a UnixWare (Solaris) dll,
2404 ac_cv_c_dll_unixware,
2405 [saved_cflags=$CFLAGS
2406 CFLAGS="$CFLAGS -fPIC -Wl,-G,-h,conftest.so.1.0,-B,symbolic"
2407 AC_TRY_LINK(,[return 1],ac_cv_c_dll_unixware="yes",ac_cv_c_dll_unixware="no")
2408 CFLAGS=$saved_cflags
2410 if test "$ac_cv_c_dll_unixware" = "yes"
2412 LDSHARED="\$(CC) -Wl,-G"
2413 LDXXSHARED="\$(CXX) -Wl,-G"
2414 LDDLLFLAGS="-Wl,-B,symbolic"
2416 AC_CACHE_CHECK("whether we can build a NetBSD dll",
2418 [saved_cflags=$CFLAGS
2419 CFLAGS="$CFLAGS -fPIC -Wl,-Bshareable,-Bforcearchive"
2420 AC_TRY_LINK(,[return 1],ac_cv_c_dll_netbsd="yes",ac_cv_c_dll_netbsd="no")
2421 CFLAGS=$saved_cflags
2423 if test "$ac_cv_c_dll_netbsd" = "yes"
2425 LDSHARED="\$(CC) -Wl,-Bshareable,-Bforcearchive"
2426 LDXXSHARED="\$(CXX) -Wl,-Bshareable,-Bforcearchive"
2427 LDDLLFLAGS="" #FIXME
2431 if test "$ac_cv_c_dll_linux" = "no" -a "$ac_cv_c_dll_unixware" = "no" -a "$ac_cv_c_dll_netbsd" = "no"
2433 AC_MSG_ERROR([Could not find how to build a dynamically linked library])
2436 CFLAGS="$CFLAGS -fPIC"
2439 AC_SUBST(LDXXSHARED)
2440 AC_SUBST(LDDLLFLAGS)
2442 dnl *** check for the need to define __i386__
2444 AC_CACHE_CHECK("whether we need to define __i386__",ac_cv_cpp_def_i386,
2445 AC_EGREP_CPP(yes,[#if (defined(i386) || defined(__i386)) && !defined(__i386__)
2448 ac_cv_cpp_def_i386="yes", ac_cv_cpp_def_i386="no"))
2449 if test "$ac_cv_cpp_def_i386" = "yes"
2451 CFLAGS="$CFLAGS -D__i386__"
2454 dnl *** check for the need to define __sparc__
2456 AC_CACHE_CHECK("whether we need to define __sparc__",ac_cv_cpp_def_sparc,
2457 AC_EGREP_CPP(yes,[#if (defined(sparc) || defined(__sparc)) && !defined(__sparc__)
2460 ac_cv_cpp_def_sparc="yes", ac_cv_cpp_def_sparc="no"))
2461 if test "$ac_cv_cpp_def_sparc" = "yes"
2463 CFLAGS="$CFLAGS -D__sparc__"
2464 CXXFLAGS="$CXXFLAGS -D__sparc__"
2467 dnl *** check for the need to define __sun__
2469 AC_CACHE_CHECK("whether we need to define __sun__",ac_cv_cpp_def_sun,
2470 AC_EGREP_CPP(yes,[#if (defined(sun) || defined(__sun)) && !defined(__sun__)
2473 ac_cv_cpp_def_sun="yes", ac_cv_cpp_def_sun="no"))
2474 if test "$ac_cv_cpp_def_sun" = "yes"
2476 CFLAGS="$CFLAGS -D__sun__"
2477 CXXFLAGS="$CXXFLAGS -D__sun__"
2480 dnl $GCC is set by autoconf
2482 if test "$GCC" = "yes"
2484 GCC_NO_BUILTIN="-fno-builtin"
2486 AC_SUBST(GCC_NO_BUILTIN)
2488 dnl **** Test Winelib-related features of the C++ compiler
2490 if test "x${GCC}" = "xyes"
2492 OLDCXXFLAGS="$CXXFLAGS";
2493 CXXFLAGS="-fpermissive";
2494 AC_CACHE_CHECK("for g++ -fpermissive option", has_gxx_permissive,
2496 for (int i=0;i<2;i++);
2499 [has_gxx_permissive="yes"],
2500 [has_gxx_permissive="no"])
2502 CXXFLAGS="-fno-for-scope";
2503 AC_CACHE_CHECK("for g++ -fno-for-scope option", has_gxx_no_for_scope,
2505 for (int i=0;i<2;i++);
2508 [has_gxx_no_for_scope="yes"],
2509 [has_gxx_no_for_scope="no"])
2511 CXXFLAGS="$OLDCXXFLAGS";
2512 if test "$has_gxx_permissive" = "yes"
2514 CXXFLAGS="$CXXFLAGS -fpermissive"
2516 if test "$has_gxx_no_for_scope" = "yes"
2518 CXXFLAGS="$CXXFLAGS -fno-for-scope"
2523 dnl **** Test Winelib-related features of the C compiler
2526 dnl **** Macros for finding a headers/libraries in a collection of places
2528 dnl AC_PATH_FILE(variable,file,action-if-not-found,default-locations)
2529 AC_DEFUN(AC_PATH_FILE,[
2530 AC_MSG_CHECKING([for $2])
2531 AC_CACHE_VAL(ac_cv_pfile_$1,
2534 ac_dummy="ifelse([$4], , , [$4])"
2535 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2536 for ac_dir in $ac_dummy; do
2538 if test -z "$ac_dir"
2542 ac_file="$ac_dir/$2"
2544 if test -f "$ac_file"
2547 ac_cv_pfile_$1="$ac_dir"
2551 ifelse([$3],,,[if test -z "$ac_found"
2557 $1="$ac_cv_pfile_$1"
2558 if test -n "$ac_found" -o -n "[$]$1"
2560 AC_MSG_RESULT([$]$1)
2567 dnl AC_PATH_HEADER(variable,header,action-if-not-found,default-locations)
2568 dnl Note that the above may set variable to an empty value if the header is
2569 dnl already in the include path
2570 AC_DEFUN(AC_PATH_HEADER,[
2571 AC_MSG_CHECKING([for $2 header])
2572 AC_CACHE_VAL(ac_cv_pheader_$1,
2575 ac_dummy="ifelse([$4], , :/usr/local/include, [$4])"
2576 save_CPPFLAGS="$CPPFLAGS"
2577 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2578 for ac_dir in $ac_dummy; do
2580 if test -z "$ac_dir"
2582 CPPFLAGS="$save_CPPFLAGS"
2584 CPPFLAGS="-I$ac_dir $save_CPPFLAGS"
2586 AC_TRY_COMPILE([#include <$2>],,ac_found=1;ac_cv_pheader_$1="$ac_dir";break)
2588 CPPFLAGS="$save_CPPFLAGS"
2589 ifelse([$3],,,[if test -z "$ac_found"
2595 $1="$ac_cv_pheader_$1"
2596 if test -n "$ac_found" -o -n "[$]$1"
2598 AC_MSG_RESULT([$]$1)
2605 dnl AC_PATH_LIBRARY(variable,libraries,extra libs,action-if-not-found,default-locations)
2606 AC_DEFUN(AC_PATH_LIBRARY,[
2607 AC_MSG_CHECKING([for $2])
2608 AC_CACHE_VAL(ac_cv_plibrary_$1,
2611 ac_dummy="ifelse([$5], , :/usr/local/lib, [$5])"
2613 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2614 for ac_dir in $ac_dummy; do
2616 if test -z "$ac_dir"
2618 LIBS="$2 $3 $save_LIBS"
2620 LIBS="-L$ac_dir $2 $3 $save_LIBS"
2622 AC_TRY_LINK(,,ac_found=1;ac_cv_plibrary_$1="$ac_dir";break)
2625 ifelse([$4],,,[if test -z "$ac_found"
2631 $1="$ac_cv_plibrary_$1"
2632 if test -n "$ac_found" -o -n "[$]$1"
2634 AC_MSG_RESULT([$]$1)
2641 dnl **** Try to find where winelib is located ****
2644 WINE_INCLUDE_ROOT=""
2645 WINE_INCLUDE_PATH=""
2646 WINE_LIBRARY_ROOT=""
2647 WINE_LIBRARY_PATH=""
2656 [ --with-wine=DIR the Wine package (or sources) is in DIR],
2657 [if test "$withval" != "no"; then
2658 WINE_ROOT="$withval";
2665 if test -n "$WINE_ROOT"
2667 WINE_INCLUDE_ROOT="$WINE_ROOT/include:$WINE_ROOT/include/wine"
2668 WINE_LIBRARY_ROOT="$WINE_ROOT:$WINE_ROOT/lib:$WINE_ROOT/library"
2669 WINE_UNICODE_ROOT="$WINE_ROOT:$WINE_ROOT/lib:$WINE_ROOT/unicode"
2670 WINE_UUID_ROOT="$WINE_ROOT:$WINE_ROOT/lib:$WINE_ROOT/ole"
2671 WINE_TOOL_PATH="$WINE_ROOT:$WINE_ROOT/bin:$WINE_ROOT/tools/wrc:$WINE_ROOT/tools/winebuild"
2672 WINE_DLL_ROOT="$WINE_ROOT/dlls:$WINE_ROOT/lib"
2675 AC_ARG_WITH(wine-includes,
2676 [ --with-wine-includes=DIR the Wine includes are in DIR],
2677 [if test "$withval" != "no"; then
2678 WINE_INCLUDES="$withval";
2682 if test -n "$WINE_INCLUDES"
2684 WINE_INCLUDE_ROOT="$WINE_INCLUDES"
2687 AC_ARG_WITH(wine-libraries,
2688 [ --with-wine-libraries=DIR the Wine libraries are in DIR],
2689 [if test "$withval" != "no"; then
2690 WINE_LIBRARIES="$withval";
2694 if test -n "$WINE_LIBRARIES"
2696 WINE_LIBRARY_ROOT="$WINE_LIBRARIES"
2697 WINE_UNICODE_ROOT="$WINE_LIBRARIES:$WINE_LIBRARIES/unicode:$WINE_LIBRARIES/../unicode"
2698 WINE_UUID_ROOT="$WINE_LIBRARIES:$WINE_LIBRARIES/ole:$WINE_LIBRARIES/../ole"
2701 AC_ARG_WITH(wine-dlls,
2702 [ --with-wine-dlls=DIR the Wine dlls are in DIR],
2703 [if test "$withval" != "no"; then
2704 WINE_DLLS="$withval";
2708 if test -n "$WINE_DLLS"
2710 WINE_DLL_ROOT="$WINE_DLLS"
2713 AC_ARG_WITH(wine-tools,
2714 [ --with-wine-tools=DIR the Wine tools are in DIR],
2715 [if test "$withval" != "no"; then
2716 WINE_TOOLS="$withval";
2720 if test -n "$WINE_TOOLS"
2722 WINE_TOOL_PATH="$WINE_TOOLS:$WINE_TOOLS/tools/wrc:$WINE_TOOLS/tools/winebuild"
2725 if test -z "$WINE_INCLUDE_ROOT"
2727 WINE_INCLUDE_ROOT=":/usr/include/wine:/usr/local/include/wine:/opt/wine/include:/opt/wine/include/wine";
2729 AC_PATH_FILE(WINE_INCLUDE_ROOT,[windef.h],[
2730 AC_MSG_ERROR([Could not find the Wine headers (windef.h)])
2731 ],$WINE_INCLUDE_ROOT)
2733 AC_PATH_HEADER(WINE_INCLUDE_ROOT,[windef.h],[
2734 AC_MSG_ERROR([Could not include the Wine headers (windef.h)])
2735 ],$WINE_INCLUDE_ROOT)
2736 if test -n "$WINE_INCLUDE_ROOT"
2738 WINE_INCLUDE_PATH="-I$WINE_INCLUDE_ROOT"
2740 WINE_INCLUDE_PATH=""
2743 if test -z "$WINE_LIBRARY_ROOT"
2745 WINE_LIBRARY_ROOT=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib"
2747 AC_PATH_FILE(WINE_LIBRARY_ROOT,[libwine.so],[
2748 AC_MSG_ERROR([Could not find the Wine libraries (libwine.so)])
2749 ],$WINE_LIBRARY_ROOT)
2751 AC_PATH_LIBRARY(WINE_LIBRARY_ROOT,[-lwine],[],[
2752 AC_MSG_ERROR([Could not link with the Wine libraries (libwine.so)])
2753 ],$WINE_LIBRARY_ROOT)
2754 if test -n "$WINE_LIBRARY_ROOT"
2756 WINE_LIBRARY_PATH="-L$WINE_LIBRARY_ROOT"
2757 LD_PATH="$WINE_LIBRARY_ROOT"
2759 WINE_LIBRARY_PATH=""
2762 if test -z "$WINE_UNICODE_ROOT"
2764 WINE_UNICODE_ROOT=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib"
2766 AC_PATH_FILE(WINE_UNICODE_ROOT,[libwine_unicode.so],[
2767 AC_MSG_ERROR([Could not find the Wine libraries (libwine_unicode.so)])
2768 ],$WINE_UNICODE_ROOT)
2770 AC_PATH_LIBRARY(WINE_UNICODE_ROOT,[-lwine_unicode],[$WINE_LIBRARY_PATH -lwine],[
2771 AC_MSG_ERROR([Could not link with the Wine libraries (libwine_unicode.so)])
2772 ],[$WINE_UNICODE_ROOT])
2774 if test -n "$WINE_UNICODE_ROOT" -a "$WINE_UNICODE_ROOT" != "$WINE_LIBRARY_ROOT"
2776 WINE_LIBRARY_PATH="$WINE_LIBRARY_PATH -L$WINE_UNICODE_ROOT"
2777 LD_PATH="$LD_PATH:$WINE_UNICODE_ROOT"
2780 if test -z "$WINE_UUID_ROOT"
2782 WINE_UUID_ROOT=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib"
2784 AC_PATH_FILE(WINE_UUID_ROOT,[libwine_uuid.a],[
2785 AC_MSG_ERROR([Could not find the Wine libraries (libwine_uuid.a)])
2788 AC_PATH_LIBRARY(WINE_UUID_ROOT,[-lwine_uuid],[$WINE_LIBRARY_PATH -lwine],[
2789 AC_MSG_ERROR([Could not link with the Wine libraries (libwine_uuid.a)])
2790 ],[$WINE_UUID_ROOT])
2792 if test -n "$WINE_UUID_ROOT" -a "$WINE_UUID_ROOT" != "$WINE_LIBRARY_ROOT"
2794 WINE_LIBRARY_PATH="$WINE_LIBRARY_PATH -L$WINE_UUID_ROOT"
2795 LD_PATH="$LD_PATH:$WINE_UUID_ROOT"
2798 if test -z "$WINE_DLL_ROOT"
2800 if test -n "$WINE_LIBRARY_ROOT"
2802 WINE_DLL_ROOT="$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/dlls"
2804 WINE_DLL_ROOT="/lib:/lib/wine:/usr/lib:/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine"
2807 AC_PATH_FILE(WINE_DLL_ROOT,[libntdll.dll.so],[
2808 AC_MSG_ERROR([Could not find the Wine dlls (libntdll.dll.so)])
2811 AC_PATH_LIBRARY(WINE_DLL_ROOT,[-lntdll.dll],[$WINE_LIBRARY_PATH -lwine -lwine_unicode],[
2812 AC_MSG_ERROR([Could not link with the Wine dlls (libntdll.dll.so)])
2814 WINE_DLL_PATH="-L$WINE_DLL_ROOT/wine"
2816 if test -n "$LD_PATH"
2818 LD_PATH="$LD_PATH:$WINE_DLL_ROOT"
2820 LD_PATH="$WINE_DLL_ROOT"
2822 LD_PATH="LD_LIBRARY_PATH=\"$LD_PATH:\$\$LD_LIBRARY_PATH\""
2824 if test -z "$WINE_TOOL_PATH"
2826 WINE_TOOL_PATH="$PATH:/usr/local/bin:/opt/wine/bin"
2828 AC_PATH_PROG(WINE,wine,,$WINE_TOOL_PATH)
2831 AC_MSG_ERROR([Could not find Wine's wine tool])
2833 AC_PATH_PROG(WINEBUILD,winebuild,,$WINE_TOOL_PATH)
2834 if test -z "$WINEBUILD"
2836 AC_MSG_ERROR([Could not find Wine's winebuild tool])
2838 AC_PATH_PROG(WRC,wrc,,$WINE_TOOL_PATH)
2841 AC_MSG_ERROR([Could not find Wine's wrc tool])
2845 AC_SUBST(WINE_INCLUDE_PATH)
2846 AC_SUBST(WINE_LIBRARY_PATH)
2847 AC_SUBST(WINE_DLL_PATH)
2849 dnl **** Try to find where the MFC are located ****
2852 if test "x$NEEDS_MFC" = "x1"
2854 ATL_INCLUDE_ROOT="";
2855 ATL_INCLUDE_PATH="";
2856 MFC_INCLUDE_ROOT="";
2857 MFC_INCLUDE_PATH="";
2858 MFC_LIBRARY_ROOT="";
2859 MFC_LIBRARY_PATH="";
2862 [ --with-mfc=DIR the MFC package (or sources) is in DIR],
2863 [if test "$withval" != "no"; then
2864 MFC_ROOT="$withval";
2871 if test -n "$MFC_ROOT"
2873 ATL_INCLUDE_ROOT="$MFC_ROOT";
2874 MFC_INCLUDE_ROOT="$MFC_ROOT";
2875 MFC_LIBRARY_ROOT="$MFC_ROOT";
2878 AC_ARG_WITH(atl-includes,
2879 [ --with-atl-includes=DIR the ATL includes are in DIR],
2880 [if test "$withval" != "no"; then
2881 ATL_INCLUDES="$withval";
2885 if test -n "$ATL_INCLUDES"
2887 ATL_INCLUDE_ROOT="$ATL_INCLUDES";
2890 AC_ARG_WITH(mfc-includes,
2891 [ --with-mfc-includes=DIR the MFC includes are in DIR],
2892 [if test "$withval" != "no"; then
2893 MFC_INCLUDES="$withval";
2897 if test -n "$MFC_INCLUDES"
2899 MFC_INCLUDE_ROOT="$MFC_INCLUDES";
2902 AC_ARG_WITH(mfc-libraries,
2903 [ --with-mfc-libraries=DIR the MFC libraries are in DIR],
2904 [if test "$withval" != "no"; then
2905 MFC_LIBRARIES="$withval";
2909 if test -n "$MFC_LIBRARIES"
2911 MFC_LIBRARY_ROOT="$MFC_LIBRARIES";
2914 OLDCPPFLAGS="$CPPFLAGS"
2915 dnl FIXME: We should not have defines in any of the include paths
2916 CPPFLAGS="$WINE_INCLUDE_PATH -I$WINE_INCLUDE_ROOT/msvcrt -D_DLL -D_MT $CPPFLAGS"
2917 ATL_INCLUDE_PATH="-I\$(WINE_INCLUDE_ROOT)/msvcrt -D_DLL -D_MT"
2918 if test -z "$ATL_INCLUDE_ROOT"
2920 ATL_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/atl:/usr/include/atl:/usr/local/include/atl:/opt/mfc/include/atl:/opt/atl/include"
2922 ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT:$ATL_INCLUDE_ROOT/atl:$ATL_INCLUDE_ROOT/atl/include"
2924 AC_PATH_HEADER(ATL_INCLUDE_ROOT,atldef.h,[
2925 AC_MSG_ERROR([Could not find the ATL includes])
2926 ],$ATL_INCLUDE_ROOT)
2927 if test -n "$ATL_INCLUDE_ROOT"
2929 ATL_INCLUDE_PATH="$ATL_INCLUDE_PATH -I$ATL_INCLUDE_ROOT"
2932 MFC_INCLUDE_PATH="$ATL_INCLUDE_PATH"
2933 if test -z "$MFC_INCLUDE_ROOT"
2935 MFC_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/mfc:/usr/include/mfc:/usr/local/include/mfc:/opt/mfc/include/mfc:/opt/mfc/include"
2937 MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT:$MFC_INCLUDE_ROOT/mfc:$MFC_INCLUDE_ROOT/mfc/include"
2939 AC_PATH_HEADER(MFC_INCLUDE_ROOT,afx.h,[
2940 AC_MSG_ERROR([Could not find the MFC includes])
2941 ],$MFC_INCLUDE_ROOT)
2942 if test -n "$MFC_INCLUDE_ROOT" -a "$ATL_INCLUDE_ROOT" != "$MFC_INCLUDE_ROOT"
2944 MFC_INCLUDE_PATH="$MFC_INCLUDE_PATH -I$MFC_INCLUDE_ROOT"
2946 CPPFLAGS="$OLDCPPFLAGS"
2948 if test -z "$MFC_LIBRARY_ROOT"
2950 MFC_LIBRARY_ROOT=":$WINE_LIBRARY_ROOT:/usr/lib/mfc:/usr/local/lib:/usr/local/lib/mfc:/opt/mfc/lib";
2952 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT:$MFC_LIBRARY_ROOT/lib:$MFC_LIBRARY_ROOT/mfc/src";
2954 AC_PATH_LIBRARY(MFC_LIBRARY_ROOT,[-lmfc],[$WINE_LIBRARY_PATH -lwine -lwine_unicode],[
2955 AC_MSG_ERROR([Could not find the MFC library])
2956 ],$MFC_LIBRARY_ROOT)
2957 if test -n "$MFC_LIBRARY_ROOT" -a "$MFC_LIBRARY_ROOT" != "$WINE_LIBRARY_ROOT"
2959 MFC_LIBRARY_PATH="-L$MFC_LIBRARY_ROOT"
2964 AC_SUBST(ATL_INCLUDE_PATH)
2965 AC_SUBST(MFC_INCLUDE_PATH)
2966 AC_SUBST(MFC_LIBRARY_PATH)
2971 dnl **** Generate output files ****
2973 MAKE_RULES=Make.rules
2974 AC_SUBST_FILE(MAKE_RULES)
2978 ##WINEMAKER_PROJECTS##
2982 echo "Configure finished. Do 'make' to build the project."
2985 dnl Local Variables:
2986 dnl comment-start: "dnl "
2988 dnl comment-start-skip: "\\bdnl\\b\\s *"
2989 dnl compile-command: "autoconf"
2991 --- Make.rules.in ---
2992 # Copyright 2000 Francois Gouget for CodeWeavers
2993 # fgouget@codeweavers.com
2995 # Global rules shared by all makefiles -*-Makefile-*-
2997 # Each individual makefile must define the following variables:
2998 # TOPOBJDIR : top-level object directory
2999 # SRCDIR : source directory for this module
3001 # Each individual makefile may define the following additional variables:
3003 # SUBDIRS : subdirectories that contain a Makefile
3004 # DLLS : WineLib libraries to be built
3005 # EXES : WineLib executables to be built
3007 # CEXTRA : extra c flags (e.g. '-Wall')
3008 # CXXEXTRA : extra c++ flags (e.g. '-Wall')
3009 # WRCEXTRA : extra wrc flags (e.g. '-p _SysRes')
3010 # DEFINES : defines (e.g. -DSTRICT)
3011 # INCLUDE_PATH : additional include path
3012 # LIBRARY_PATH : additional library path
3013 # LIBRARIES : additional Unix libraries to link with
3015 # C_SRCS : C sources for the module
3016 # CXX_SRCS : C++ sources for the module
3017 # RC_SRCS : resource source files
3018 # SPEC_SRCS : interface definition files
3023 WINE_INCLUDE_ROOT = @WINE_INCLUDE_ROOT@
3024 WINE_INCLUDE_PATH = @WINE_INCLUDE_PATH@
3025 WINE_LIBRARY_ROOT = @WINE_LIBRARY_ROOT@
3026 WINE_LIBRARY_PATH = @WINE_LIBRARY_PATH@
3027 WINE_DLL_ROOT = @WINE_DLL_ROOT@
3028 WINE_DLL_PATH = @WINE_DLL_PATH@
3034 ATL_INCLUDE_ROOT = @ATL_INCLUDE_ROOT@
3035 ATL_INCLUDE_PATH = @ATL_INCLUDE_PATH@
3036 MFC_INCLUDE_ROOT = @MFC_INCLUDE_ROOT@
3037 MFC_INCLUDE_PATH = @MFC_INCLUDE_PATH@
3038 MFC_LIBRARY_ROOT = @MFC_LIBRARY_ROOT@
3039 MFC_LIBRARY_PATH = @MFC_LIBRARY_PATH@
3041 # Global definitions and options
3043 GLOBAL_DEFINES = ##WINEMAKER_DEFINES##
3044 GLOBAL_INCLUDE_PATH = ##WINEMAKER_INCLUDE_PATH##
3045 GLOBAL_DLL_PATH = ##WINEMAKER_DLL_PATH##
3046 GLOBAL_DLLS = ##WINEMAKER_DLLS##
3047 GLOBAL_LIBRARY_PATH = ##WINEMAKER_LIBRARY_PATH##
3048 GLOBAL_LIBRARIES = ##WINEMAKER_LIBRARIES##
3050 # First some useful definitions
3058 CXXFLAGS = @CXXFLAGS@
3060 OPTIONS = @OPTIONS@ -D_REENTRANT -DWINELIB $(GLOBAL_DEFINES)
3061 LIBS = @LIBS@ $(LIBRARY_PATH)
3062 ALLFLAGS = $(DEFINES) -I$(SRCDIR) $(INCLUDE_PATH) $(WINE_INCLUDE_PATH)
3063 ALLCFLAGS = $(CFLAGS) $(CEXTRA) $(OPTIONS) $(ALLFLAGS)
3064 ALLCXXFLAGS=$(CXXFLAGS) $(CXXEXTRA) $(OPTIONS) $(ALLFLAGS)
3065 ALLWRCFLAGS=$(WRCFLAGS) $(WRCEXTRA) $(OPTIONS) $(ALLFLAGS)
3066 DLL_LINK = $(LIBRARY_PATH) $(LIBRARIES:%=-l%) $(WINE_LIBRARY_PATH) $(GLOBAL_LIBRARY_PATH) -lwine -lwine_unicode -lwine_uuid $(GLOBAL_LIBRARIES:%=-l%)
3068 LDSHARED = @LDSHARED@
3069 LDXXSHARED= @LDXXSHARED@
3070 LDDLLFLAGS= @LDDLLFLAGS@
3072 STRIPFLAGS= --strip-unneeded
3078 WINEBUILD = @WINEBUILD@
3081 # Installation infos
3084 INSTALL_PROGRAM = $(INSTALL)
3085 INSTALL_SCRIPT = $(INSTALL)
3086 INSTALL_DATA = $(INSTALL) -m 644
3088 exec_prefix = @exec_prefix@
3096 OBJS = $(C_SRCS:.c=.o) $(CXX_SRCS:.cpp=.o) \
3097 $(SPEC_SRCS:.spec=.spec.o)
3098 CLEAN_FILES = *.spec.c y.tab.c y.tab.h lex.yy.c \
3100 \\\#*\\\# *~ *% .\\\#*
3104 .SUFFIXES: .cpp .rc .res .spec .spec.c .spec.o
3107 $(CC) -c $(ALLCFLAGS) -o $@ $<
3110 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
3113 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
3116 $(LD_PATH) $(WRC) $(ALLWRCFLAGS) -o $@ $<
3118 .PHONY: all install uninstall clean distclean depend dummy
3120 # 'all' target first in case the enclosing Makefile didn't define any target
3124 # Rules for makefile
3126 Makefile: Makefile.in $(TOPSRCDIR)/configure
3127 @echo $@ is older than $?, please rerun $(TOPSRCDIR)/configure
3130 # Rules for cleaning
3132 $(SUBDIRS:%=%/__clean__): dummy
3133 cd `dirname $@` && $(MAKE) clean
3135 $(EXTRASUBDIRS:%=%/__clean__): dummy
3136 -cd `dirname $@` && $(RM) $(CLEAN_FILES)
3138 clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
3139 $(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(OBJS) $(EXES) $(EXES:%=%.so) $(DLLS)
3141 # Rules for installing
3143 $(SUBDIRS:%=%/__install__): dummy
3144 cd `dirname $@` && $(MAKE) install
3146 $(SUBDIRS:%=%/__uninstall__): dummy
3147 cd `dirname $@` && $(MAKE) uninstall
3156 # End of global rules
3157 --- wineapploader.in ---
3160 # Wrapper script to start a Winelib application once it is installed
3162 # Copyright (C) 2002 Alexandre Julliard
3164 # determine the app Winelib library name
3165 appname=`basename "$0" .exe`.exe
3167 #allow Wine to load Winelib application from the current directory
3168 export WINEDLLPATH=$WINEDLLPATH:@winelibdir@
3170 # first try explicit WINELOADER
3171 if [ -x "$WINELOADER" ]; then exec "$WINELOADER" "$appname" "$@"; fi
3173 # then default bin directory
3174 if [ -x "@bindir@/wine" ]; then exec "@bindir@/wine" "$appname" "$@"; fi
3176 # now try the directory containing $0
3180 # $0 contains a path, use it
3181 appdir=`dirname "$0"`
3184 # no directory in $0, search in PATH
3190 if [ -x "$d/$0" ]; then appdir="$d"; break; fi
3194 if [ -x "$appdir/wine" ]; then exec "$appdir/wine" "$appname" "$@"; fi
3196 # finally look in PATH
3197 exec wine "$appname" "$@"
3200 * Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
3208 #include <windows.h>
3213 * Describe the wrapped application
3217 * This is either CUIEXE for a console based application or
3218 * GUIEXE for a regular windows application.
3222 #define APP_TYPE ##WINEMAKER_APP_TYPE##
3225 * This is the application library's base name, i.e. 'hello' if the
3226 * library is called 'libhello.so'.
3228 static char* appName = ##WINEMAKER_APP_NAME##;
3231 * This is the name of the application's Windows module. If left NULL
3232 * then appName is used.
3234 static char* appModule = NULL;
3237 * This is the application's entry point. This is usually "WinMain" for a
3238 * GUIEXE and 'main' for a CUIEXE application.
3240 static char* appInit = ##WINEMAKER_APP_INIT##;
3243 * This is either non-NULL for MFC-based applications and is the name of the
3244 * MFC's module. This is the module in which we will take the 'WinMain'
3247 static char* mfcModule = ##WINEMAKER_APP_MFC##;
3252 * Implement the main.
3255 #if APP_TYPE == GUIEXE
3256 typedef int WINAPI (*WinMainFunc)(HINSTANCE hInstance, HINSTANCE hPrevInstance,
3257 PSTR szCmdLine, int iCmdShow);
3259 typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp);
3262 #if APP_TYPE == GUIEXE
3263 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
3264 PSTR szCmdLine, int iCmdShow)
3266 int WINAPI main(int argc, char** argv, char** envp)
3270 HINSTANCE hApp = 0, hMFC = 0, hMain = 0;
3275 /* Load the application's library */
3276 libName=(char*)malloc(strlen(appName)+5+3+1);
3277 /* FIXME: we should get the wrapper's path and use that as the base for
3280 sprintf(libName,"./lib%s.so",appName);
3281 appLibrary=dlopen(libName,RTLD_NOW);
3282 if (appLibrary==NULL) {
3283 sprintf(libName,"lib%s.so",appName);
3284 appLibrary=dlopen(libName,RTLD_NOW);
3286 if (appLibrary==NULL) {
3287 char format[]="Could not load the %s library:\r\n%s";
3292 msg=(char*)malloc(strlen(format)+strlen(libName)+strlen(error));
3293 sprintf(msg,format,libName,error);
3294 MessageBox(NULL,msg,"dlopen error",MB_OK);
3299 /* Then if this application is MFC based, load the MFC module */
3300 /* FIXME: I'm not sure this is really necessary */
3301 if (mfcModule!=NULL) {
3302 hMFC=LoadLibrary(mfcModule);
3304 char format[]="Could not load the MFC module %s (%d)";
3307 msg=(char*)malloc(strlen(format)+strlen(mfcModule)+11);
3308 sprintf(msg,format,mfcModule,GetLastError());
3309 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
3313 /* MFC is a special case: the WinMain is in the MFC library,
3314 * instead of the application's library.
3321 /* Load the application's module */
3322 if (appModule==NULL) {
3325 hApp=LoadLibrary(appModule);
3327 char format[]="Could not load the application's module %s (%d)";
3330 msg=(char*)malloc(strlen(format)+strlen(appModule)+11);
3331 sprintf(msg,format,appModule,GetLastError());
3332 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
3335 } else if (hMain==NULL) {
3339 /* Get the address of the application's entry point */
3340 appMain=GetProcAddress(hMain, appInit);
3341 if (appMain==NULL) {
3342 char format[]="Could not get the address of %s (%d)";
3345 msg=(char*)malloc(strlen(format)+strlen(appInit)+11);
3346 sprintf(msg,format,appInit,GetLastError());
3347 MessageBox(NULL,msg,"GetProcAddress error",MB_OK);
3352 /* And finally invoke the application's entry point */
3353 #if APP_TYPE == GUIEXE
3354 retcode=(*((WinMainFunc)appMain))(hApp,hPrevInstance,szCmdLine,iCmdShow);
3356 retcode=(*((MainFunc)appMain))(argc,argv,envp);
3359 /* Cleanup and done */
3364 dlclose(appLibrary);