3 # Copyright 2000 Francois Gouget for CodeWeavers
4 # fgouget@codeweavers.com
20 # The following constants define what we do with the case of filenames
23 # Never rename a file to lowercase
27 # Rename all files to lowercase
31 # Rename only files that are all uppercase to lowercase
32 my $OPT_LOWER_UPPERCASE=2;
35 # The following constants define whether to ask questions or not
38 # No (synonym of never)
46 # Skip the questions till the end of this scope
53 # This is the directory in which winemaker will operate.
57 # Make a backup of the files
61 # Defines which files to rename
65 # If we don't find the file referenced by an include, lower it
66 my $opt_lower_include;
69 # If true then winemaker should not attempt to fix the source. This is
70 # useful if the source is known to be already in a suitable form and is
72 my $opt_no_source_fix;
74 # Options for the 'Source' method
77 # Specifies that we have only one target so that all sources relate
78 # to this target. By default this variable is left undefined which
79 # means winemaker should try to find out by itself what the targets
80 # are. If not undefined then this contains the name of the default
81 # target (without the extension).
82 my $opt_single_target;
85 # If '$opt_single_target' has been specified then this is the type of
86 # that target. Otherwise it specifies whether the default target type
87 # is guiexe or cuiexe.
91 # Contains the default set of flags to be used when creating a new target.
95 # If true then winemaker should ask questions to the user as it goes
97 my $opt_is_interactive;
98 my $opt_ask_project_options;
99 my $opt_ask_target_options;
102 # If false then winemaker should not generate any file, i.e.
103 # no makefiles, but also no .spec files, no configure.in, etc.
104 my $opt_no_generated_files;
107 # If true then winemaker should not generate the spec files.
108 # This is useful if winemaker is being used to create a build environment
109 my $opt_no_generated_specs;
112 # Specifies not to print the banner if set.
119 # Target modelization
123 # The description of a target is stored in an array. The constants
124 # below identify what is stored at each index of the array.
127 # This is the name of the target.
131 # Defines the type of target we want to build. See the TT_xxx
136 # Defines the target's enty point, i.e. the function that is called
141 # This is a bitfield containing flags refining the way the target
142 # should be handled. See the TF_xxx constants below
146 # This is a reference to an array containing the list of the
147 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
151 my $T_SOURCES_MISC=7;
154 # This is a reference to an array containing the list of macro
159 # This is a reference to an array containing the list of directory
160 # names that constitute the include path
161 my $T_INCLUDE_PATH=9;
164 # Same as T_INCLUDE_PATH but for the dll search path
168 # The list of Windows dlls to import
172 # Same as T_INCLUDE_PATH but for the library search path
173 my $T_LIBRARY_PATH=12;
176 # The list of Unix libraries to link with
180 # The list of dependencies between targets
184 # The following constants define the recognized types of target
187 # This is not a real target. This type of target is used to collect
188 # the sources that don't seem to belong to any other target. Thus no
189 # real target is generated for them, we just put the sources of the
190 # fake target in the global source list.
194 # For executables in the windows subsystem
198 # For executables in the console subsystem
202 # For dynamically linked libraries
206 # The following constants further refine how the target should be handled
209 # This target needs a wrapper
213 # This target is a wrapper
217 # This target is an MFC-based target
221 # Initialize a target:
222 # - set the target type to TT_SETTINGS, i.e. no real target will
228 @$target[$T_TYPE]=$TT_SETTINGS;
229 # leaving $T_INIT undefined
230 @$target[$T_FLAGS]=$opt_flags;
231 @$target[$T_SOURCES_C]=[];
232 @$target[$T_SOURCES_CXX]=[];
233 @$target[$T_SOURCES_RC]=[];
234 @$target[$T_SOURCES_MISC]=[];
235 @$target[$T_DEFINES]=[];
236 @$target[$T_INCLUDE_PATH]=[];
237 @$target[$T_DLL_PATH]=[];
238 @$target[$T_DLLS]=[];
239 @$target[$T_LIBRARY_PATH]=[];
240 @$target[$T_LIBRARIES]=[];
241 @$target[$T_DEPENDS]=[];
247 if ($type == $TT_GUIEXE) {
249 } elsif ($type == $TT_CUIEXE) {
251 } elsif ($type == $TT_DLL) {
260 # Project modelization
264 # First we have the notion of project. A project is described by an
265 # array (since we don't have structs in perl). The constants below
266 # identify what is stored at each index of the array.
269 # This is the path in which this project is located. In other
270 # words, this is the path to the Makefile.
274 # This index contains a reference to an array containing the project-wide
275 # settings. The structure of that arrray is actually identical to that of
276 # a regular target since it can also contain extra sources.
280 # This index contains a reference to an array of targets for this
281 # project. Each target describes how an executable or library is to
282 # be built. For each target this description takes the same form as
283 # that of the project: an array. So this entry is an array of arrays.
287 # Initialize a project:
288 # - set the project's path
289 # - initialize the target list
290 # - create a default target (will be removed later if unnecessary)
296 my $project_settings=[];
297 target_init($project_settings);
299 @$project[$P_PATH]=$path;
300 @$project[$P_SETTINGS]=$project_settings;
301 @$project[$P_TARGETS]=[];
317 # Contains the list of all projects. This list tells us what are
318 # the subprojects of the main Makefile and where we have to generate
323 # This is the main project, i.e. the one in the "." directory.
324 # It may well be empty in which case the main Makefile will only
325 # call out subprojects.
329 # Contains the defaults for the include path, etc.
330 # We store the defaults as if this were a target except that we only
331 # exploit the defines, include path, library path, library list and misc
336 # If one of the projects requires the MFc then we set this global variable
337 # to true so that configure asks the user to provide a path tothe MFC
349 # Cleans up a name to make it an acceptable Makefile
355 $name =~ tr/a-zA-Z0-9_/_/c;
360 # Returns true is the specified pathname is absolute.
361 # Note: pathnames that start with a variable '$' or
362 # '~' are considered absolute.
367 return ($path =~ /^[\/~\$]/);
371 # Performs a binary search looking for the specified item
376 my $last=@{$array}-1;
379 while ($first<=$last) {
380 my $index=int(($first+$last)/2);
381 my $cmp=@$array[$index] cmp $item;
396 # 'Source'-based Project analysis
401 # Allows the user to specify makefile and target specific options
402 # - target: the structure in which to store the results
403 # - options: the string containing the options
404 sub source_set_options
409 #FIXME: we must deal with escaping of stuff and all
410 foreach $option (split / /,$options) {
411 if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
412 push @{@$target[$T_DEFINES]},$option;
413 } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
414 push @{@$target[$T_INCLUDE_PATH]},$option;
415 } elsif ($option =~ /^-P/) {
416 push @{@$target[$T_DLL_PATH]},"-L$'";
417 } elsif ($option =~ /^-i/) {
418 push @{@$target[$T_DLLS]},"$'";
419 } elsif ($option =~ /^-L/) {
420 push @{@$target[$T_LIBRARY_PATH]},$option;
421 } elsif ($option =~ /^-l/) {
422 push @{@$target[$T_LIBRARIES]},"$'";
423 } elsif (@$target[$T_TYPE] != $TT_DLL and $option =~ /^--wrap/) {
424 @$target[$T_FLAGS]|=$TF_WRAP;
425 } elsif (@$target[$T_TYPE] != $TT_DLL and $option =~ /^--nowrap/) {
426 @$target[$T_FLAGS]&=~$TF_WRAP;
427 } elsif ($option =~ /^--mfc/) {
428 @$target[$T_FLAGS]|=$TF_MFC;
429 if (@$target[$T_TYPE] != $TT_DLL) {
430 @$target[$T_FLAGS]|=$TF_WRAP;
432 } elsif ($option =~ /^--nomfc/) {
433 @$target[$T_FLAGS]&=~$TF_MFC;
434 @$target[$T_FLAGS]&=~($TF_MFC|$TF_WRAP);
436 print STDERR "error: unknown option \"$option\"\n";
444 # Scans the specified directory to:
445 # - see if we should create a Makefile in this directory. We normally do
446 # so if we find a project file and sources
447 # - get a list of targets for this directory
448 # - get the list of source files
449 sub source_scan_directory
451 # a reference to the parent's project
452 my $parent_project=$_[0];
453 # the full relative path to the current directory, including a
454 # trailing '/', or an empty string if this is the top level directory
456 # the name of this directory, including a trailing '/', or an empty
457 # string if this is the top level directory
459 # if set then no targets will be looked for and the sources will all
460 # end up in the parent_project's 'misc' bucket
463 # reference to the project for this directory. May not be used
465 # list of targets found in the 'current' directory
467 # list of sources found in the current directory
472 # true if this directory contains a Windows project
473 my $has_win_project=0;
474 # If we don't find any executable/library then we might make up targets
475 # from the list of .dsp/.mak files we find since they usually have the
476 # same name as their target.
480 if (defined $opt_single_target or $dirname eq "") {
481 # Either there is a single target and thus a single project,
482 # or we are in the top level directory for which a project
484 $project=$parent_project;
487 project_init($project,$path);
489 my $project_settings=@$project[$P_SETTINGS];
491 # First find out what this directory contains:
492 # collect all sources, targets and subdirectories
493 my $directory=get_directory_contents($path);
494 foreach $dentry (@$directory) {
495 if ($dentry =~ /^\./) {
498 my $fullentry="$path$dentry";
499 if (-d "$fullentry") {
500 if ($dentry =~ /^(Release|Debug)/i) {
501 # These directories are often used to store the object files and the
502 # resulting executable/library. They should not contain anything else.
503 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
504 foreach $candidate (@candidates) {
505 if ($candidate =~ s/\.exe$//i) {
506 $targets{$candidate}=1;
507 } elsif ($candidate =~ s/^(.*)\.dll$/lib$1.so/i) {
508 $targets{$candidate}=1;
511 } elsif ($dentry =~ /^include/i) {
512 # This directory must contain headers we're going to need
513 push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
514 source_scan_directory($project,"$fullentry/","$dentry/",1);
516 # Recursively scan this directory. Any source file that cannot be
517 # attributed to a project in one of the subdirectories will be
518 # attributed to this project.
519 source_scan_directory($project,"$fullentry/","$dentry/",$no_target);
521 } elsif (-f "$fullentry") {
522 if ($dentry =~ s/\.exe$//i) {
524 } elsif ($dentry =~ s/^(.*)\.dll$/lib$1.so/i) {
526 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.spec\.c$/) {
527 push @sources_c,"$dentry";
528 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
529 if ($dentry =~ /^stdafx.cpp$/i) {
530 push @sources_misc,"$dentry";
531 @$project_settings[$T_FLAGS]|=$TF_MFC;
533 push @sources_cxx,"$dentry";
535 } elsif ($dentry =~ /\.rc$/i) {
536 push @sources_rc,"$dentry";
537 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
538 push @sources_misc,"$dentry";
539 if ($dentry =~ /^stdafx.h$/i) {
540 @$project_settings[$T_FLAGS]|=$TF_MFC;
542 } elsif ($dentry =~ /\.dsp$/i) {
543 push @dsp_files,"$dentry";
545 } elsif ($dentry =~ /\.mak$/i) {
546 push @mak_files,"$dentry";
548 } elsif ($dentry =~ /^makefile/i) {
555 # If we have a single target then all we have to do is assign
556 # all the sources to it and we're done
557 # FIXME: does this play well with the --interactive mode?
558 if ($opt_single_target) {
559 my $target=@{@$project[$P_TARGETS]}[0];
560 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
561 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
562 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
563 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
567 my $parent_settings=@$parent_project[$P_SETTINGS];
568 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
569 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
570 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
571 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
572 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
576 my $source_count=@sources_c+@sources_cxx+@sources_rc+
577 @{@$project_settings[$T_SOURCES_C]}+
578 @{@$project_settings[$T_SOURCES_CXX]}+
579 @{@$project_settings[$T_SOURCES_RC]};
580 if ($source_count == 0) {
581 # A project without real sources is not a project, get out!
582 if ($project!=$parent_project) {
583 my $parent_settings=@$parent_project[$P_SETTINGS];
584 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
585 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
589 #print "targets=",%targets,"\n";
590 #print "target_count=$target_count\n";
591 #print "has_win_project=$has_win_project\n";
592 #print "dirname=$dirname\n";
595 if (($has_win_project != 0) or ($dirname eq "")) {
596 # Deal with cases where we could not find any executable/library, and
597 # thus have no target, although we did find some sort of windows project.
598 $target_count=keys %targets;
599 if ($target_count == 0) {
600 # Try to come up with a target list based on .dsp/.mak files
602 if (@dsp_files > 0) {
603 $prj_list=\@dsp_files;
605 $prj_list=\@mak_files;
607 foreach $filename (@$prj_list) {
608 $filename =~ s/\.(dsp|mak)$//i;
609 if ($opt_target_type == $TT_DLL) {
610 $filename = "lib$filename.so";
612 $targets{$filename}=1;
614 $target_count=keys %targets;
615 if ($target_count == 0) {
616 # Still nothing, try the name of the directory
618 if ($dirname eq "") {
619 # Bad luck, this is the top level directory!
620 $name=(split /\//, cwd)[-1];
623 # Remove the trailing '/'. Also eliminate whatever is after the last
624 # '.' as it is likely to be meaningless (.orig, .new, ...)
625 $name =~ s+(/|\.[^.]*)$++;
626 if ($name eq "src") {
627 # 'src' is probably a subdirectory of the real project directory.
628 # Try again with the parent (if any).
630 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
633 $name=(split /\//, cwd)[-1];
637 $name =~ s+(/|\.[^.]*)$++;
638 if ($opt_target_type == $TT_DLL) {
639 $name = "lib$name.so";
645 # Ask confirmation to the user if he wishes so
646 if ($opt_is_interactive == $OPT_ASK_YES) {
647 my $target_list=join " ",keys %targets;
648 print "\n*** In ",($path?$path:"./"),"\n";
649 print "* winemaker found the following list of (potential) targets\n";
650 print "* $target_list\n";
651 print "* Type enter to use it as is, your own comma-separated list of\n";
652 print "* targets, 'none' to assign the source files to a parent directory,\n";
653 print "* or 'ignore' to ignore everything in this directory tree.\n";
654 print "* Target list:\n";
655 $target_list=<STDIN>;
657 if ($target_list eq "") {
658 # Keep the target list as is, i.e. do nothing
659 } elsif ($target_list eq "none") {
660 # Empty the target list
662 } elsif ($target_list eq "ignore") {
663 # Ignore this subtree altogether
667 foreach $target (split /,/,$target_list) {
670 # Also accept .exe and .dll as a courtesy
671 $target =~ s+(.*)\.dll$+lib$1.so+;
672 $target =~ s+\.exe$++;
679 # If we have no project at this level, then transfer all
680 # the sources to the parent project
681 $target_count=keys %targets;
682 if ($target_count == 0) {
683 if ($project!=$parent_project) {
684 my $parent_settings=@$parent_project[$P_SETTINGS];
685 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
686 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
687 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
688 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
689 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
694 # Otherwise add this project to the project list, except for
695 # the main project which is already in the list.
696 if ($dirname ne "") {
697 push @projects,$project;
700 # Ask for project-wide options
701 if ($opt_ask_project_options == $OPT_ASK_YES) {
703 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
706 if ((@$project_settings[$T_FLAGS] & $TF_WRAP)!=0) {
707 if ($flag_desc ne "") {
710 $flag_desc.="wrapped";
712 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc/--wrap),\n";
713 if (defined $flag_desc) {
714 print "* (currently $flag_desc)\n";
716 print "* or 'skip' to skip the target specific options,\n";
717 print "* or 'never' to not be asked this question again:\n";
721 if ($options eq "skip") {
722 $opt_ask_target_options=$OPT_ASK_SKIP;
724 } elsif ($options eq "never") {
725 $opt_ask_project_options=$OPT_ASK_NO;
727 } elsif (source_set_options($project_settings,$options)) {
730 print "Please re-enter the options:\n";
734 # - Create the targets
735 # - Check if we have both libraries and programs
736 # - Match each target with source files (sort in reverse
737 # alphabetical order to get the longest matches first)
739 my @local_depends=();
741 foreach $target_name (sort { $b cmp $a } keys %targets) {
742 # Create the target...
745 target_init($target);
746 @$target[$T_NAME]=$target_name;
747 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
748 if ($target_name =~ /^lib(.*)\.so$/) {
749 @$target[$T_TYPE]=$TT_DLL;
750 @$target[$T_INIT]=get_default_init($TT_DLL);
751 @$target[$T_FLAGS]&=~$TF_WRAP;
753 push @local_depends,$target_name;
754 push @local_dlls,$basename;
756 @$target[$T_TYPE]=$opt_target_type;
757 @$target[$T_INIT]=get_default_init($opt_target_type);
758 $basename=$target_name;
759 push @exe_list,$target;
761 # This is the default link list of Visual Studio, except odbccp32
762 # which we don't have in Wine. Also I add ntdll which seems
763 # necessary for Winelib.
764 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);
765 @$target[$T_DLLS]=\@std_dlls;
766 push @{@$project[$P_TARGETS]},$target;
768 # Ask for target-specific options
769 if ($opt_ask_target_options == $OPT_ASK_YES) {
771 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
774 if ((@$target[$T_FLAGS] & $TF_WRAP)!=0) {
775 if ($flag_desc ne "") {
780 $flag_desc.="wrapped";
782 if ($flag_desc ne "") {
785 print "* Specify any link option (-P/-i/-L/-l/--mfc/--wrap) specific to the target\n";
786 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
790 if ($options eq "never") {
791 $opt_ask_target_options=$OPT_ASK_NO;
793 } elsif (source_set_options($target,$options)) {
796 print "Please re-enter the options:\n";
799 if (@$target[$T_FLAGS] & $TF_MFC) {
800 @$project_settings[$T_FLAGS]|=$TF_MFC;
801 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
802 push @{@$target[$T_DLLS]},"mfc.dll";
803 # FIXME: Link with the MFC in the Unix sense, until we
804 # start exporting the functions properly.
805 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
806 push @{@$target[$T_LIBRARIES]},"mfc";
810 if ($target_count == 1) {
811 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
812 @$project_settings[$T_SOURCES_C]=[];
815 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
816 @$project_settings[$T_SOURCES_CXX]=[];
819 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
820 @$project_settings[$T_SOURCES_RC]=[];
823 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
824 # No need for sorting these sources
825 @$project_settings[$T_SOURCES_MISC]=[];
828 foreach $source (@sources_c) {
829 if ($source =~ /^$basename/i) {
830 push @{@$target[$T_SOURCES_C]},$source;
834 foreach $source (@sources_cxx) {
835 if ($source =~ /^$basename/i) {
836 push @{@$target[$T_SOURCES_CXX]},$source;
840 foreach $source (@sources_rc) {
841 if ($source =~ /^$basename/i) {
842 push @{@$target[$T_SOURCES_RC]},$source;
846 foreach $source (@sources_misc) {
847 if ($source =~ /^$basename/i) {
848 push @{@$target[$T_SOURCES_MISC]},$source;
853 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
854 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
855 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
856 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
858 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
859 $opt_ask_target_options=$OPT_ASK_YES;
862 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
863 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
865 # The sources that did not match, if any, go to the extra
866 # source list of the project settings
867 foreach $source (@sources_c) {
869 push @{@$project_settings[$T_SOURCES_C]},$source;
872 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
873 foreach $source (@sources_cxx) {
875 push @{@$project_settings[$T_SOURCES_CXX]},$source;
878 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
879 foreach $source (@sources_rc) {
881 push @{@$project_settings[$T_SOURCES_RC]},$source;
884 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
885 foreach $source (@sources_misc) {
887 push @{@$project_settings[$T_SOURCES_MISC]},$source;
890 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
892 # Finally if we are building both libraries and programs in
893 # this directory, then the programs should be linked with all
895 if (@local_dlls > 0 and @exe_list > 0) {
896 foreach $target (@exe_list) {
897 push @{@$target[$T_DLL_PATH]},"-L.";
898 push @{@$target[$T_DLLS]},map { "$_.dll" } @local_dlls;
899 # Also link in the Unix sense since none of the functions
901 push @{@$target[$T_LIBRARY_PATH]},"-L.";
902 push @{@$target[$T_LIBRARIES]},@local_dlls;
903 push @{@$target[$T_DEPENDS]},@local_depends;
909 # Scan the source directories in search of things to build
912 # If there's a single target then this is going to be the default target
913 if (defined $opt_single_target) {
914 # Create the main target
916 target_init($main_target);
917 if ($opt_target_type == $TT_DLL) {
918 @$main_target[$T_NAME]="lib$opt_single_target.so";
920 @$main_target[$T_NAME]="$opt_single_target";
922 @$main_target[$T_TYPE]=$opt_target_type;
925 push @{$main_project[$P_TARGETS]},$main_target;
928 # The main directory is always going to be there
929 push @projects,\@main_project;
931 # Now scan the directory tree looking for source files and, maybe, targets
932 print "Scanning the source directories...\n";
933 source_scan_directory(\@main_project,"","",0);
935 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
942 # 'vc.dsp'-based Project analysis
955 # Creating the wrapper targets
959 sub postprocess_targets
961 foreach $project (@projects) {
962 foreach $target (@{@$project[$P_TARGETS]}) {
963 if ((@$target[$T_FLAGS] & $TF_WRAP) != 0) {
965 target_init($wrapper);
966 @$wrapper[$T_NAME]=@$target[$T_NAME];
967 @$wrapper[$T_TYPE]=@$target[$T_TYPE];
968 @$wrapper[$T_INIT]=get_default_init(@$target[$T_TYPE]);
969 @$wrapper[$T_FLAGS]=$TF_WRAPPER | (@$target[$T_FLAGS] & $TF_MFC);
970 @$wrapper[$T_DLLS]=[ "kernel32.dll", "ntdll.dll", "user32.dll" ];
971 push @{@$wrapper[$T_SOURCES_C]},"@$wrapper[$T_NAME]_wrapper.c";
973 my $index=bsearch(@$target[$T_SOURCES_C],"@$wrapper[$T_NAME]_wrapper.c");
974 if (defined $index) {
975 splice(@{@$target[$T_SOURCES_C]},$index,1);
977 @$target[$T_NAME]="lib@$target[$T_NAME].so";
978 @$target[$T_TYPE]=$TT_DLL;
980 push @{@$project[$P_TARGETS]},$wrapper;
982 if ((@$target[$T_FLAGS] & $TF_MFC) != 0) {
983 @{@$project[$P_SETTINGS]}[$T_FLAGS]|=$TF_MFC;
999 # Performs a directory traversal and renames the files so that:
1000 # - they have the case desired by the user
1001 # - their extension is of the appropriate case
1002 # - they don't contain annoying characters like ' ', '$', '#', ...
1003 sub fix_file_and_directory_names
1007 if (opendir(DIRECTORY, "$dirname")) {
1008 foreach $dentry (readdir DIRECTORY) {
1009 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1012 # Set $warn to 1 if the user should be warned of the renaming
1015 # autoconf and make don't support these characters well
1016 my $new_name=$dentry;
1017 $new_name =~ s/[ \$]/_/g;
1019 # Only all lowercase extensions are supported (because of the
1020 # transformations ':.c=.o') .
1021 if (-f "$dirname/$new_name") {
1022 if ($new_name =~ /\.C$/) {
1023 $new_name =~ s/\.C$/.c/;
1025 if ($new_name =~ /\.cpp$/i) {
1026 $new_name =~ s/\.cpp$/.cpp/i;
1028 if ($new_name =~ s/\.cxx$/.cpp/i) {
1031 if ($new_name =~ /\.rc$/i) {
1032 $new_name =~ s/\.rc$/.rc/i;
1034 # And this last one is to avoid confusion then running make
1035 if ($new_name =~ s/^makefile$/makefile.win/) {
1040 # Adjust the case to the user's preferences
1041 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1042 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1044 $new_name=lc $new_name;
1047 # And finally, perform the renaming
1048 if ($new_name ne $dentry) {
1050 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1052 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1053 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1054 print STDERR " $!\n";
1058 if (-d "$dirname/$new_name") {
1059 fix_file_and_directory_names("$dirname/$new_name");
1062 closedir(DIRECTORY);
1075 # This maps a directory name to a reference to an array listing
1076 # its contents (files and directories)
1080 # Retrieves the contents of the specified directory.
1081 # We either get it from the directories hashtable which acts as a
1082 # cache, or use opendir, readdir, closedir and store the result
1084 sub get_directory_contents
1089 #print "getting the contents of $dirname\n";
1091 # check for a cached version
1093 if ($dirname eq "") {
1096 $directory=$directories{$dirname};
1097 if (defined $directory) {
1098 #print "->@$directory\n";
1102 # Read this directory
1103 if (opendir(DIRECTORY, "$dirname")) {
1104 my @files=readdir DIRECTORY;
1105 closedir(DIRECTORY);
1108 # Return an empty list
1109 #print "error: cannot open $dirname\n";
1113 #print "->@$directory\n";
1114 $directories{$dirname}=$directory;
1119 # Try to find a file for the specified filename. The attempt is
1120 # case-insensitive which is why it's not trivial. If a match is
1121 # found then we return the pathname with the correct case.
1128 if ($dirname eq "" or $dirname eq ".") {
1130 } elsif ($dirname =~ m+^[^/]+) {
1131 $dirname=cwd . "/" . $dirname;
1133 if ($dirname !~ m+/$+) {
1137 foreach $component (@$path) {
1138 #print " looking for $component in \"$dirname\"\n";
1139 if ($component eq ".") {
1142 } elsif ($component eq "..") {
1144 $dirname=dirname($dirname) . "/";
1147 # The file/directory may have been renamed before. Also try to
1148 # match the renamed file.
1149 my $renamed=$component;
1150 $renamed =~ s/[ \$]/_/g;
1151 if ($renamed eq $component) {
1155 my $directory=get_directory_contents $dirname;
1157 foreach $dentry (@$directory) {
1158 if ($dentry =~ /^$component$/i or
1159 (defined $renamed and $dentry =~ /^$renamed$/i)
1161 $dirname.="$dentry/";
1162 $real_path.="$dentry/";
1167 if (!defined $found) {
1169 #print " could not find $component in $dirname\n";
1174 $real_path=~ s+/$++;
1175 #print " -> found $real_path\n";
1180 # Performs a case-insensitive search for the specified file in the
1182 # $line is the line number that should be referenced when an error occurs
1183 # $filename is the file we are looking for
1184 # $dirname is the directory of the file containing the '#include' directive
1185 # if '"' was used, it is an empty string otherwise
1186 # $project and $target specify part of the include path
1187 sub get_real_include_name
1195 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1196 # This is not a relative path, we cannot make any check
1197 my $warning="path:$filename";
1198 if (!defined $warnings{$warning}) {
1199 $warnings{$warning}="1";
1200 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1201 print STDERR "$line: $filename\n";
1204 # Here's how we proceed:
1205 # - split the filename we look for into its components
1206 # - then for each directory in the include path
1207 # - trace the directory components starting from that directory
1208 # - if we fail to find a match at any point then continue with
1209 # the next directory in the include path
1210 # - otherwise, rejoice, our quest is over.
1211 my @file_components=split /[\/\\]+/, $filename;
1212 #print " Searching for $filename from @$project[$P_PATH]\n";
1215 if ($dirname ne "") {
1216 # This is an 'include ""' -> look in dirname first.
1217 #print " in $dirname (include \"\")\n";
1218 $real_filename=search_from($dirname,\@file_components);
1219 if (defined $real_filename) {
1220 return $real_filename;
1223 my $project_settings=@$project[$P_SETTINGS];
1224 foreach $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1225 my $dirname=$include;
1227 if (!is_absolute($dirname)) {
1228 $dirname="@$project[$P_PATH]$dirname";
1230 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1231 $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
1233 #print " in $dirname\n";
1234 $real_filename=search_from("$dirname",\@file_components);
1235 if (defined $real_filename) {
1236 return $real_filename;
1239 my $dotdotpath=@$project[$P_PATH];
1240 $dotdotpath =~ s/[^\/]+/../g;
1241 foreach $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1242 my $dirname=$include;
1244 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1245 $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
1246 #print " in $dirname (global setting)\n";
1247 $real_filename=search_from("$dirname",\@file_components);
1248 if (defined $real_filename) {
1249 return $real_filename;
1253 $filename =~ s+\\\\+/+g; # in include ""
1254 $filename =~ s+\\+/+g; # in include <> !
1255 if ($opt_lower_include) {
1256 return lc "$filename";
1267 if ($size =~ /^(1|2|4|8)$/) {
1268 print FILEO "$indent#include <pshpack$size.h>$trailer";
1270 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1271 print FILEO "$indent#include <pshpack4.h>$trailer";
1276 # 'Parses' a source file and fixes constructs that would not work with
1277 # Winelib. The parsing is rather simple and not all non-portable features
1278 # are corrected. The most important feature that is corrected is the case
1279 # and path separator of '#include' directives. This requires that each
1280 # source file be associated to a project & target so that the proper
1281 # include path is used.
1282 # Also note that the include path is relative to the directory in which the
1283 # compiler is run, i.e. that of the project, not to that of the file.
1289 $filename="@$project[$P_PATH]$filename";
1290 if (! -e $filename) {
1294 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1295 my $dirname=dirname($filename);
1297 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1301 print " $filename\n";
1302 #FIXME:assuming that because there is a .bak file, this is what we want is
1303 #probably flawed. Or is it???
1304 if (! -e "$filename.bak") {
1305 if (!copy("$filename","$filename.bak")) {
1306 print STDERR "error: unable to make a backup of $filename:\n";
1307 print STDERR " $!\n";
1311 if (!open(FILEI,"$filename.bak")) {
1312 print STDERR "error: unable to open $filename.bak for reading:\n";
1313 print STDERR " $!\n";
1316 if (!open(FILEO,">$filename")) {
1317 print STDERR "error: unable to open $filename for writing:\n";
1318 print STDERR " $!\n";
1323 my $rc_block_depth=0;
1324 my $rc_textinclude_state=0;
1327 # Remove any trailing CtrlZ, which isn't strictly in the file
1335 # Make sure all files are '\n' terminated
1338 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
1339 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1340 # the RC files it generates (even in non-MFC projects). So we replace
1341 # it with 'winres.h' its very close standard cousin so that non MFC
1342 # projects can compile in Wine without the MFC sources.
1343 my $warning="mfc:afxres.h";
1344 if (!defined $warnings{$warning}) {
1345 $warnings{$warning}="1";
1346 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winres.h'\n";
1347 print STDERR "warning: the above warning is issued only once\n";
1349 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
1350 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winres.h' */\n";
1351 print FILEO "$1$2\"winres.h\"$'";
1354 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1355 my $from_file=($2 eq "<"?"":$dirname);
1356 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1357 print FILEO "$1$2$real_include_name$4$'";
1358 $modified|=($real_include_name ne $3);
1360 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
1361 # Pragma pack handling
1363 # pack_stack is an array of references describing the stack of
1364 # pack directives currently in effect. Each directive if described
1365 # by a reference to an array containing:
1366 # - "push" for pack(push,...) directives, "" otherwise
1367 # - the directive's identifier at index 1
1368 # - the directive's alignement value at index 2
1370 # Don't believe a word of what the documentation says: it's all wrong.
1371 # The code below is based on the actual behavior of Visual C/C++ 6.
1376 # Pushes the default stack alignment
1377 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1378 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1379 print_pack($pack_indent,4,$');
1380 push @pack_stack, [ "", "", 4 ];
1382 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
1384 # pragma pack(pop,n)
1385 # Goes up the stack until it finds a pack(push,...), and pops it
1386 # Ignores any pack(n) entry
1387 # Issues a warning if the pack is of the form pack(push,label)
1388 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1389 my $pack_comment=$';
1390 $pack_comment =~ s/^\s*//;
1391 if ($pack_comment ne "") {
1392 print FILEO "$pack_indent$pack_comment";
1395 my $alignment=pop @pack_stack;
1396 if (!defined $alignment) {
1397 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
1400 if (@$alignment[1]) {
1401 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
1403 print FILEO "$pack_indent#include <poppack.h>\n";
1404 if (@$alignment[0]) {
1409 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
1410 # pragma pack(pop,label[,n])
1411 # Goes up the stack until finding a pack(push,...) and pops it.
1412 # 'n', if specified, is ignored.
1413 # Ignores any pack(n) entry
1414 # Issues a warning if the label of the pack does not match,
1415 # or if it is in fact a pack(push,n)
1417 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1418 my $pack_comment=$';
1419 $pack_comment =~ s/^\s*//;
1420 if ($pack_comment ne "") {
1421 print FILEO "$pack_indent$pack_comment";
1424 my $alignment=pop @pack_stack;
1425 if (!defined $alignment) {
1426 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
1429 if (@$alignment[1] and @$alignment[1] ne $label) {
1430 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
1432 print FILEO "$pack_indent#include <poppack.h>\n";
1433 if (@$alignment[0]) {
1438 } elsif (/^(push\s*\))/) {
1440 # Push the current alignment
1441 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1442 if (@pack_stack > 0) {
1443 my $alignment=$pack_stack[$#pack_stack];
1444 print_pack($pack_indent,@$alignment[2],$');
1445 push @pack_stack, [ "push", "", @$alignment[2] ];
1447 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1448 print_pack($pack_indent,4,$');
1449 push @pack_stack, [ "push", "", 4 ];
1452 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
1453 # pragma pack([push,]n)
1454 # Push new alignment n
1455 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1456 print_pack($pack_indent,$3,"$'");
1457 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
1459 } elsif (/^((\w+)\s*\))/) {
1460 # pragma pack(label)
1461 # label must in fact be a macro that resolves to an integer
1462 # Then behaves like 'pragma pack(n)'
1463 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1464 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
1465 print_pack($pack_indent,4,$');
1466 push @pack_stack, [ "", "", 4 ];
1468 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
1469 # pragma pack(push,label[,n])
1470 # Pushes a new label on the stack. It is possible to push the same
1471 # label multiple times. If 'n' is omitted then the alignment is
1472 # unchanged. Otherwise it becomes 'n'.
1473 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1477 } elsif (@pack_stack > 0) {
1478 my $alignment=$pack_stack[$#pack_stack];
1479 $size=@$alignment[2];
1481 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1484 print_pack($pack_indent,$size,$');
1485 push @pack_stack, [ "push", $2, $size ];
1488 # pragma pack(??? -> What's that?
1489 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
1490 print FILEO "$pack_indent$pack_header$_";
1496 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]+)([\">]?)/) {
1497 my $from_file=($5 eq "<"?"":$dirname);
1498 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
1499 print FILEO "$1$5$real_include_name$7$'";
1500 $modified|=($real_include_name ne $6);
1502 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1503 my $from_file=($2 eq "<"?"":$dirname);
1504 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1505 print FILEO "$1$2$real_include_name$4$'";
1506 $modified|=($real_include_name ne $3);
1508 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
1509 $rc_textinclude_state=1;
1512 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
1513 print FILEO "$1winres.h$2$'";
1516 } elsif (/^\s*BEGIN(\W.*)?$/) {
1517 $rc_textinclude_state|=2;
1521 } elsif (/^\s*END(\W.*)?$/) {
1522 $rc_textinclude_state=0;
1523 if ($rc_block_depth>0) {
1539 if ($opt_backup == 0 or $modified == 0) {
1540 if (!unlink("$filename.bak")) {
1541 print STDERR "error: unable to delete $filename.bak:\n";
1542 print STDERR " $!\n";
1548 # Analyzes each source file in turn to find and correct issues
1549 # that would cause it not to compile.
1552 print "Fixing the source files...\n";
1553 foreach $project (@projects) {
1554 foreach $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
1555 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1558 foreach $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
1559 fix_file($source,$project,$target);
1574 # Generates a target's .spec file
1575 sub generate_spec_file
1577 if ($opt_no_generated_specs) {
1582 my $project_settings=$_[2];
1584 my $basename=@$target[$T_NAME];
1585 $basename =~ s+\.so$++;
1586 if (@$target[$T_FLAGS] & $TF_WRAP) {
1587 $basename =~ s+^lib++;
1588 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1589 $basename.="_wrapper";
1592 if (!open(FILEO,">$path$basename.spec")) {
1593 print STDERR "error: could not open \"$path$basename.spec\" for writing\n";
1594 print STDERR " $!\n";
1598 my $module=$basename;
1599 $module =~ s+^lib++;
1600 $module=canonize($module);
1601 print FILEO "name $module\n";
1602 print FILEO "type win32\n";
1603 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1604 print FILEO "mode guiexe\n";
1605 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1606 print FILEO "mode cuiexe\n";
1608 print FILEO "mode dll\n";
1610 if (defined @$target[$T_INIT] and ((@$target[$T_FLAGS] & $TF_WRAP) == 0)) {
1611 print FILEO "init @$target[$T_INIT]\n";
1613 if (@{@$target[$T_SOURCES_RC]} > 0) {
1614 if (@{@$target[$T_SOURCES_RC]} > 1) {
1615 print STDERR "warning: the target $basename has more than one RC file. Modify the Makefile.in to remove redundant RC files, and fix the spec file\n";
1617 my $rcname=@{@$target[$T_SOURCES_RC]}[0];
1618 $rcname =~ s+\.rc$++i;
1619 $rcname =~ s+([^/\w])+\\$1+g;
1620 print FILEO "rsrc $rcname.res\n";
1624 foreach $dll (@{$global_settings[$T_DLLS]}) {
1625 if (!defined $dlls{$dll}) {
1626 print FILEO "import $dll\n";
1630 if (defined $project_settings) {
1631 foreach $dll (@{@$project_settings[$T_DLLS]}) {
1632 if (!defined $dlls{$dll}) {
1633 print FILEO "import $dll\n";
1638 foreach $dll (@{@$target[$T_DLLS]}) {
1639 if (!defined $dlls{$dll}) {
1640 print FILEO "import $dll\n";
1645 # Don't forget to export the 'Main' function for wrapped executables,
1646 # except for MFC ones!
1647 if (@$target[$T_FLAGS] == $TF_WRAP) {
1648 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1649 print FILEO "\n@ stdcall @$target[$T_INIT](long long ptr long) @$target[$T_INIT]\n";
1650 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1651 print FILEO "\n@ stdcall @$target[$T_INIT](long ptr ptr) @$target[$T_INIT]\n";
1653 print FILEO "\n@ stdcall @$target[$T_INIT](ptr long ptr) @$target[$T_INIT]\n";
1661 # Generates a target's wrapper file
1662 sub generate_wrapper_file
1667 if (!defined $templates{"wrapper.c"}) {
1668 print STDERR "winemaker: internal error: No template called 'wrapper.c'\n";
1672 if (!open(FILEO,">$path@$target[$T_NAME]_wrapper.c")) {
1673 print STDERR "error: unable to open \"$path$basename.c\" for writing:\n";
1674 print STDERR " $!\n";
1677 my $app_name="\"@$target[$T_NAME]\"";
1678 my $app_type=(@$target[$T_TYPE]==$TT_GUIEXE?"GUIEXE":"CUIEXE");
1679 my $app_init=(@$target[$T_TYPE]==$TT_GUIEXE?"\"WinMain\"":"\"main\"");
1680 my $app_mfc=(@$target[$T_FLAGS] & $TF_MFC?"\"mfc\"":NULL);
1681 foreach $line (@{$templates{"wrapper.c"}}) {
1683 $l =~ s/\#\#WINEMAKER_APP_NAME\#\#/$app_name/;
1684 $l =~ s/\#\#WINEMAKER_APP_TYPE\#\#/$app_type/;
1685 $l =~ s/\#\#WINEMAKER_APP_INIT\#\#/$app_init/;
1686 $l =~ s/\#\#WINEMAKER_APP_MFC\#\#/$app_mfc/;
1693 # A convenience function to generate all the lists (defines,
1694 # C sources, C++ source, etc.) in the Makefile
1704 printf FILEO "%-22s=",$name;
1706 if (defined $list) {
1707 foreach $item (@$list) {
1709 if (defined $data) {
1710 $value=&$data($item);
1716 print FILEO " $value";
1719 print FILEO " \\\n\t\t\t$value";
1730 # Generates a project's Makefile.in and all the target files
1731 sub generate_project_files
1734 my $project_settings=@$project[$P_SETTINGS];
1738 # Then sort the targets and separate the libraries from the programs
1739 foreach $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
1740 if (@$target[$T_TYPE] == $TT_DLL) {
1741 push @dll_list,$target;
1743 push @exe_list,$target;
1746 @$project[$P_TARGETS]=[];
1747 push @{@$project[$P_TARGETS]}, @dll_list;
1748 push @{@$project[$P_TARGETS]}, @exe_list;
1750 if (!open(FILEO,">@$project[$P_PATH]Makefile.in")) {
1751 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile.in\" for writing\n";
1752 print STDERR " $!\n";
1756 print FILEO "### Generated by Winemaker\n";
1759 print FILEO "### Generic autoconf variables\n\n";
1760 generate_list("TOPSRCDIR",1,[ "\@top_srcdir\@" ]);
1761 generate_list("TOPOBJDIR",1,[ "." ]);
1762 generate_list("SRCDIR",1,[ "\@srcdir\@" ]);
1763 generate_list("VPATH",1,[ "\@srcdir\@" ]);
1765 if (@$project[$P_PATH] eq "") {
1766 # This is the main project. It is also responsible for recursively
1767 # calling the other projects
1768 generate_list("SUBDIRS",1,\@projects,sub
1770 if ($_[0] != \@main_project) {
1771 my $subdir=@{$_[0]}[$P_PATH];
1775 # Eliminating the main project by returning undefined!
1778 if (@{@$project[$P_TARGETS]} > 0) {
1779 generate_list("DLLS",1,\@dll_list,sub
1781 return @{$_[0]}[$T_NAME];
1783 generate_list("EXES",1,\@exe_list,sub
1785 return "@{$_[0]}[$T_NAME]";
1787 print FILEO "\n\n\n";
1789 print FILEO "### Global settings\n\n";
1790 # Make it so that the project-wide settings override the global settings
1791 generate_list("DEFINES",0,@$project_settings[$T_DEFINES]);
1792 generate_list("",1,$global_settings[$T_DEFINES]);
1793 generate_list("INCLUDE_PATH",$no_extra,@$project_settings[$T_INCLUDE_PATH]);
1794 generate_list("",1,$global_settings[$T_INCLUDE_PATH],sub
1796 if ($_[0] !~ /^-I/ or is_absolute($')) {
1799 return "-I\$(TOPSRCDIR)/$'";
1801 generate_list("DLL_PATH",$no_extra,@$project_settings[$T_DLL_PATH]);
1802 generate_list("",1,$global_settings[$T_DLL_PATH],sub
1804 if ($_[0] !~ /^-L/ or is_absolute($')) {
1807 return "-L\$(TOPSRCDIR)/$'";
1809 generate_list("LIBRARY_PATH",$no_extra,@$project_settings[$T_LIBRARY_PATH]);
1810 generate_list("",1,$global_settings[$T_LIBRARY_PATH],sub
1812 if ($_[0] !~ /^-L/ or is_absolute($')) {
1815 return "-L\$(TOPSRCDIR)/$'";
1817 generate_list("LIBRARIES",$no_extra,@$project_settings[$T_LIBRARIES]);
1818 generate_list("",1,$global_settings[$T_LIBRARIES]);
1821 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
1822 @{@$project_settings[$T_SOURCES_CXX]}+
1823 @{@$project_settings[$T_SOURCES_RC]};
1824 my $no_extra=($extra_source_count == 0);
1826 print FILEO "### Extra source lists\n\n";
1827 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
1828 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
1829 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
1831 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
1832 print FILEO "\n\n\n";
1835 # Iterate over all the targets...
1836 foreach $target (@{@$project[$P_TARGETS]}) {
1837 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
1838 my $canon=canonize("@$target[$T_NAME]");
1840 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
1841 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
1842 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
1843 my $basename=@$target[$T_NAME];
1844 $basename =~ s+\.so$++;
1845 if (@$target[$T_FLAGS] & $TF_WRAP) {
1846 $basename =~ s+^lib++;
1847 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1848 $basename.="_wrapper";
1850 generate_list("${canon}_SPEC_SRCS",1,[ "$basename.spec" ]);
1851 generate_list("${canon}_DLL_PATH",1,@$target[$T_DLL_PATH]);
1852 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]);
1853 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]);
1854 generate_list("${canon}_DEPENDS",1,@$target[$T_DEPENDS]);
1856 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(EXTRA_OBJS)"]);
1857 print FILEO "\n\n\n";
1859 print FILEO "### Global source lists\n\n";
1860 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
1862 my $canon=canonize(@{$_[0]}[$T_NAME]);
1864 return "\$(${canon}_C_SRCS)";
1867 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
1869 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
1871 my $canon=canonize(@{$_[0]}[$T_NAME]);
1873 return "\$(${canon}_CXX_SRCS)";
1876 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
1878 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
1880 my $canon=canonize(@{$_[0]}[$T_NAME]);
1882 return "\$(${canon}_RC_SRCS)";
1885 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
1887 generate_list("SPEC_SRCS",1,@$project[$P_TARGETS],sub
1889 my $canon=canonize(@{$_[0]}[$T_NAME]);
1891 return "\$(${canon}_SPEC_SRCS)";
1894 print FILEO "\n\n\n";
1896 print FILEO "### Generic autoconf targets\n\n";
1898 if (@$project[$P_PATH] eq "") {
1899 print FILEO " \$(SUBDIRS)";
1901 if (@{@$project[$P_TARGETS]} > 0) {
1902 print FILEO " \$(DLLS) \$(EXES:%=%.so)";
1905 print FILEO "\@MAKE_RULES\@\n";
1907 print FILEO "install::\n";
1908 if (@$project[$P_PATH] eq "") {
1909 # This is the main project. It is also responsible for recursively
1910 # calling the other projects
1911 print FILEO "\t_list=\"\$(SUBDIRS)\"; for i in \$\$_list; do (cd \$\$i; \$(MAKE) install) || exit 1; done\n";
1913 if (@{@$project[$P_TARGETS]} > 0) {
1914 print FILEO "\t_list=\"\$(EXES) \$(EXES:%=%.so)\"; for i in \$\$_list; do \$(INSTALL_PROGRAM) \$\$i \$(bindir); done\n";
1915 print FILEO "\t_list=\"\$(DLLS)\"; for i in \$\$_list; do \$(INSTALL_PROGRAM) \$\$i \$(libdir); done\n";
1918 print FILEO "uninstall::\n";
1919 if (@$project[$P_PATH] eq "") {
1920 # This is the main project. It is also responsible for recursively
1921 # calling the other projects
1922 print FILEO "\t_list=\"\$(SUBDIRS)\"; for i in \$\$_list; do (cd \$\$i; \$(MAKE) uninstall) || exit 1; done\n";
1924 if (@{@$project[$P_TARGETS]} > 0) {
1925 print FILEO "\t_list=\"\$(EXES) \$(EXES:%=%.so)\"; for i in \$\$_list; do \$(RM) \$(bindir)/\$\$i;done\n";
1926 print FILEO "\t_list=\"\$(DLLS)\"; for i in \$\$_list; do \$(RM) \$(libdir)/\$\$i;done\n";
1928 print FILEO "\n\n\n";
1930 if (@{@$project[$P_TARGETS]} > 0) {
1931 print FILEO "### Target specific build rules\n\n";
1932 foreach $target (@{@$project[$P_TARGETS]}) {
1933 my $canon=canonize("@$target[$T_NAME]");
1935 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.tmp.o): \$(${canon}_OBJS)\n";
1936 print FILEO "\t\$(LDCOMBINE) \$(${canon}_OBJS) -o \$\@\n";
1937 print FILEO "\t-\$(STRIP) \$(STRIPFLAGS) \$\@\n";
1939 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.spec.c): \$(${canon}_SPEC_SRCS) \$(${canon}_SPEC_SRCS:.spec=.tmp.o) \$(${canon}_RC_SRCS:.rc=.res)\n";
1940 print FILEO "\t\$(LD_PATH) \$(WINEBUILD) -fPIC \$(${canon}_DLL_PATH) \$(WINE_DLL_PATH) -sym \$(${canon}_SPEC_SRCS:.spec=.tmp.o) -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 -e @$target[$T_NAME] || \$(LN_S) \$(WINE) @$target[$T_NAME]\n";
1961 foreach $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_configure
1975 my $a_source_file=$_[1];
1977 if (!defined $templates{$filename}) {
1978 if ($filename ne "configure") {
1979 print STDERR "winemaker: internal error: No template called '$filename'\n";
1984 if (!open(FILEO,">$filename")) {
1985 print STDERR "error: unable to open \"$filename\" for writing:\n";
1986 print STDERR " $!\n";
1989 foreach $line (@{$templates{$filename}}) {
1990 if ($line =~ /^\#\#WINEMAKER_PROJECTS\#\#$/) {
1991 foreach $project (@projects) {
1992 print FILEO "@$project[$P_PATH]Makefile\n";
1995 $line =~ s+\#\#WINEMAKER_SOURCE\#\#+$a_source_file+;
1996 $line =~ s+\#\#WINEMAKER_NEEDS_MFC\#\#+$needs_mfc+;
2004 sub generate_generic
2008 if (!defined $templates{$filename}) {
2009 print STDERR "winemaker: internal error: No template called '$filename'\n";
2012 if (!open(FILEO,">$filename")) {
2013 print STDERR "error: unable to open \"$filename\" for writing:\n";
2014 print STDERR " $!\n";
2017 foreach $line (@{$templates{$filename}}) {
2024 # Generates the global files:
2028 sub generate_global_files
2030 generate_generic("Make.rules.in");
2032 # Get the name of a source file for configure.in
2034 search_a_file: foreach $project (@projects) {
2035 foreach $target (@{@$project[$P_TARGETS]}, @$project[$P_SETTINGS]) {
2036 $a_source_file=@{@$target[$T_SOURCES_C]}[0];
2037 if (!defined $a_source_file) {
2038 $a_source_file=@{@$target[$T_SOURCES_CXX]}[0];
2040 if (!defined $a_source_file) {
2041 $a_source_file=@{@$target[$T_SOURCES_RC]}[0];
2043 if (defined $a_source_file) {
2044 $a_source_file="@$project[$P_PATH]$a_source_file";
2049 if (!defined $a_source_file) {
2050 $a_source_file="Makefile.in";
2053 generate_configure("configure.in",$a_source_file);
2054 unlink("configure");
2055 if (generate_configure("configure",$a_source_file) == 0) {
2058 # Add execute permission to configure for whoever has the right to read it
2059 my @st=stat("configure");
2062 $mode|=($mode & 0444) >>2;
2063 chmod($mode,"configure");
2065 print "warning: could not generate the configure script. You need to run autoconf\n";
2071 sub generate_read_templates
2076 if (/^--- ((\w\.?)+) ---$/) {
2078 if (defined $templates{$filename}) {
2079 print STDERR "winemaker: internal error: There is more than one template for $filename\n";
2083 $templates{$filename}=$file;
2085 } elsif (defined $file) {
2092 # This is where we finally generate files. In fact this method does not
2093 # do anything itself but calls the methods that do the actual work.
2096 print "Generating project files...\n";
2097 generate_read_templates();
2098 generate_global_files();
2100 foreach $project (@projects) {
2101 my $path=@$project[$P_PATH];
2108 generate_project_files($project);
2121 $opt_lower=$OPT_LOWER_UPPERCASE;
2122 $opt_lower_include=1;
2124 # $opt_work_dir=<undefined>
2125 # $opt_single_target=<undefined>
2126 $opt_target_type=$TT_GUIEXE;
2128 $opt_is_interactive=$OPT_ASK_NO;
2129 $opt_ask_project_options=$OPT_ASK_NO;
2130 $opt_ask_target_options=$OPT_ASK_NO;
2131 $opt_no_generated_files=0;
2132 $opt_no_generated_specs=0;
2133 $opt_no_source_fix=0;
2146 print "Winemaker $version\n";
2147 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2153 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2154 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2155 print STDERR " [--lower-include|--nolower-include]\n";
2156 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2157 print STDERR " [--wrap|--nowrap] [--mfc|--nomfc]\n";
2158 print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2159 print STDERR " [--interactive] [--single-target name]\n";
2160 print STDERR " [--generated-files|--nogenerated-files] [--nogenerated-specs]\n";
2161 print STDERR " work_directory\n";
2162 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2163 print STDERR "the specified directory so that they can be compiled with Winelib. During this\n";
2164 print STDERR "process it will modify and rename some of the files in that directory.\n";
2165 print STDERR "\tPlease read the manual page before use.\n";
2170 project_init(\@main_project,"");
2173 my $arg=shift @ARGV;
2175 if ($arg eq "--nobanner") {
2177 } elsif ($arg eq "--backup") {
2179 } elsif ($arg eq "--nobackup") {
2181 } elsif ($arg eq "--single-target") {
2182 $opt_single_target=shift @ARGV;
2183 } elsif ($arg eq "--lower-none") {
2184 $opt_lower=$OPT_LOWER_NONE;
2185 } elsif ($arg eq "--lower-all") {
2186 $opt_lower=$OPT_LOWER_ALL;
2187 } elsif ($arg eq "--lower-uppercase") {
2188 $opt_lower=$OPT_LOWER_UPPERCASE;
2189 } elsif ($arg eq "--lower-include") {
2190 $opt_lower_include=1;
2191 } elsif ($arg eq "--nolower-include") {
2192 $opt_lower_include=0;
2193 } elsif ($arg eq "--nosource-fix") {
2194 $opt_no_source_fix=1;
2195 } elsif ($arg eq "--generated-files") {
2196 $opt_no_generated_files=0;
2197 } elsif ($arg eq "--nogenerated-files") {
2198 $opt_no_generated_files=1;
2199 } elsif ($arg eq "--nogenerated-specs") {
2200 $opt_no_generated_specs=1;
2202 } elsif ($arg =~ /^-D/) {
2203 push @{$global_settings[$T_DEFINES]},$arg;
2204 } elsif ($arg =~ /^-I/) {
2205 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2206 } elsif ($arg =~ /^-P/) {
2207 push @{$global_settings[$T_DLL_PATH]},"-L$'";
2208 } elsif ($arg =~ /^-i/) {
2209 push @{$global_settings[$T_DLLS]},$';
2210 } elsif ($arg =~ /^-L/) {
2211 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2212 } elsif ($arg =~ /^-l/) {
2213 push @{$global_settings[$T_LIBRARIES]},$';
2215 # 'Source'-based method options
2216 } elsif ($arg eq "--dll") {
2217 $opt_target_type=$TT_DLL;
2218 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2219 $opt_target_type=$TT_GUIEXE;
2220 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2221 $opt_target_type=$TT_CUIEXE;
2222 } elsif ($arg eq "--interactive") {
2223 $opt_is_interactive=$OPT_ASK_YES;
2224 $opt_ask_project_options=$OPT_ASK_YES;
2225 $opt_ask_target_options=$OPT_ASK_YES;
2226 } elsif ($arg eq "--wrap") {
2227 $opt_flags|=$TF_WRAP;
2228 } elsif ($arg eq "--nowrap") {
2229 $opt_flags&=~$TF_WRAP;
2230 } elsif ($arg eq "--mfc") {
2231 $opt_flags|=$TF_MFC;
2232 $opt_flags|=$TF_MFC|$TF_WRAP;
2234 } elsif ($arg eq "--nomfc") {
2235 $opt_flags&=~($TF_MFC|$TF_WRAP);
2240 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2241 if (!defined $opt_work_dir) {
2244 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2253 if (!defined $opt_work_dir) {
2254 print STDERR "error: you must specify the directory containing the sources to be converted\n";
2256 } elsif (!chdir $opt_work_dir) {
2257 print STDERR "error: could not chdir to the work directory\n";
2258 print STDERR " $!\n";
2262 if ($opt_no_banner == 0) {
2266 # Fix the file and directory names
2267 fix_file_and_directory_names(".");
2269 # Scan the sources to identify the projects and targets
2272 # Create targets for wrappers, etc.
2273 postprocess_targets();
2275 # Fix the source files
2276 if (! $opt_no_source_fix) {
2280 # Generate the Makefile and the spec file
2281 if (! $opt_no_generated_files) {
2287 --- configure.in ---
2288 dnl Process this file with autoconf to produce a configure script.
2289 dnl Author: Michael Patra <micky@marie.physik.tu-berlin.de>
2290 dnl <patra@itp1.physik.tu-berlin.de>
2291 dnl Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2293 AC_REVISION([configure.in 1.00])
2294 AC_INIT(##WINEMAKER_SOURCE##)
2296 NEEDS_MFC=##WINEMAKER_NEEDS_MFC##
2298 dnl **** Command-line arguments ****
2302 dnl **** Check for some programs ****
2310 dnl **** Check for some libraries ****
2312 dnl Check for -lm for BeOS
2313 AC_CHECK_LIB(m,sqrt)
2314 dnl Check for -lw for Solaris
2315 AC_CHECK_LIB(w,iswalnum)
2316 dnl Check for -lnsl for Solaris
2317 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))
2318 dnl Check for -lsocket for Solaris
2319 AC_CHECK_FUNCS(connect,,AC_CHECK_LIB(socket,connect))
2321 dnl **** If ln -s doesn't work, use cp instead ****
2322 if test "$ac_cv_prog_LN_S" = "ln -s"; then : ; else LN_S=cp ; fi
2324 dnl **** Check for gcc strength-reduce bug ****
2326 if test "x${GCC}" = "xyes"
2328 AC_CACHE_CHECK( "for gcc strength-reduce bug", ac_cv_c_gcc_strength_bug,
2331 static int Array[[3]];
2334 for(i=0; i<B; i++) Array[[i]] = i - 3;
2335 exit( Array[[1]] != -2 );
2337 ac_cv_c_gcc_strength_bug="no",
2338 ac_cv_c_gcc_strength_bug="yes",
2339 ac_cv_c_gcc_strength_bug="yes") )
2340 if test "$ac_cv_c_gcc_strength_bug" = "yes"
2342 CFLAGS="$CFLAGS -fno-strength-reduce"
2346 dnl **** Check for underscore on external symbols ****
2348 AC_CACHE_CHECK("whether external symbols need an underscore prefix",
2349 ac_cv_c_extern_prefix,
2351 LIBS="conftest_asm.s $LIBS"
2352 cat > conftest_asm.s <<EOF
2357 AC_TRY_LINK([extern int ac_test;],[if (ac_test) return 1],
2358 ac_cv_c_extern_prefix="yes",ac_cv_c_extern_prefix="no")
2360 if test "$ac_cv_c_extern_prefix" = "yes"
2362 AC_DEFINE(NEED_UNDERSCORE_PREFIX)
2365 dnl **** Check for working dll ****
2370 AC_CACHE_CHECK("whether we can build a Linux dll",
2372 [saved_cflags=$CFLAGS
2373 CFLAGS="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0,-Bsymbolic"
2374 AC_TRY_LINK(,[return 1],ac_cv_c_dll_linux="yes",ac_cv_c_dll_linux="no")
2375 CFLAGS=$saved_cflags
2377 if test "$ac_cv_c_dll_linux" = "yes"
2379 LDSHARED="\$(CC) -shared -Wl,-rpath,\$(libdir)"
2380 LDXXSHARED="\$(CXX) -shared -Wl,-rpath,\$(libdir)"
2381 LDDLLFLAGS="-Wl,-Bsymbolic"
2383 AC_CACHE_CHECK(whether we can build a UnixWare (Solaris) dll,
2384 ac_cv_c_dll_unixware,
2385 [saved_cflags=$CFLAGS
2386 CFLAGS="$CFLAGS -fPIC -Wl,-G,-h,conftest.so.1.0,-B,symbolic"
2387 AC_TRY_LINK(,[return 1],ac_cv_c_dll_unixware="yes",ac_cv_c_dll_unixware="no")
2388 CFLAGS=$saved_cflags
2390 if test "$ac_cv_c_dll_unixware" = "yes"
2392 LDSHARED="\$(CC) -Wl,-G"
2393 LDXXSHARED="\$(CXX) -Wl,-G"
2394 LDDLLFLAGS="-Wl,-B,symbolic"
2396 AC_CACHE_CHECK("whether we can build a NetBSD dll",
2398 [saved_cflags=$CFLAGS
2399 CFLAGS="$CFLAGS -fPIC -Wl,-Bshareable,-Bforcearchive"
2400 AC_TRY_LINK(,[return 1],ac_cv_c_dll_netbsd="yes",ac_cv_c_dll_netbsd="no")
2401 CFLAGS=$saved_cflags
2403 if test "$ac_cv_c_dll_netbsd" = "yes"
2405 LDSHARED="\$(CC) -Wl,-Bshareable,-Bforcearchive"
2406 LDXXSHARED="\$(CXX) -Wl,-Bshareable,-Bforcearchive"
2407 LDDLLFLAGS="" #FIXME
2411 if test "$ac_cv_c_dll_linux" = "no" -a "$ac_cv_c_dll_unixware" = "no" -a "$ac_cv_c_dll_netbsd" = "no"
2413 AC_MSG_ERROR([Could not find how to build a dynamically linked library])
2416 CFLAGS="$CFLAGS -fPIC"
2419 AC_SUBST(LDXXSHARED)
2420 AC_SUBST(LDDLLFLAGS)
2422 dnl *** check for the need to define __i386__
2424 AC_CACHE_CHECK("whether we need to define __i386__",ac_cv_cpp_def_i386,
2425 AC_EGREP_CPP(yes,[#if (defined(i386) || defined(__i386)) && !defined(__i386__)
2428 ac_cv_cpp_def_i386="yes", ac_cv_cpp_def_i386="no"))
2429 if test "$ac_cv_cpp_def_i386" = "yes"
2431 CFLAGS="$CFLAGS -D__i386__"
2434 dnl $GCC is set by autoconf
2436 if test "$GCC" = "yes"
2438 GCC_NO_BUILTIN="-fno-builtin"
2440 AC_SUBST(GCC_NO_BUILTIN)
2442 dnl **** Test Winelib-related features of the C++ compiler
2444 if test "x${GCC}" = "xyes"
2446 OLDCXXFLAGS="$CXXFLAGS";
2447 CXXFLAGS="-fpermissive";
2448 AC_CACHE_CHECK("for g++ -fpermissive option", has_gxx_permissive,
2450 for (int i=0;i<2;i++);
2453 [has_gxx_permissive="yes"],
2454 [has_gxx_permissive="no"])
2456 CXXFLAGS="-fno-for-scope";
2457 AC_CACHE_CHECK("for g++ -fno-for-scope option", has_gxx_no_for_scope,
2459 for (int i=0;i<2;i++);
2462 [has_gxx_no_for_scope="yes"],
2463 [has_gxx_no_for_scope="no"])
2465 CXXFLAGS="$OLDCXXFLAGS";
2466 if test "$has_gxx_permissive" = "yes"
2468 CXXFLAGS="$CXXFLAGS -fpermissive"
2470 if test "$has_gxx_no_for_scope" = "yes"
2472 CXXFLAGS="$CXXFLAGS -fno-for-scope"
2477 dnl **** Test Winelib-related features of the C compiler
2480 dnl **** Macros for finding a headers/libraries in a collection of places
2482 dnl AC_PATH_FILE(variable,file,action-if-not-found,default-locations)
2483 AC_DEFUN(AC_PATH_FILE,[
2484 AC_MSG_CHECKING([for $2])
2485 AC_CACHE_VAL(ac_cv_pfile_$1,
2488 ac_dummy="ifelse([$4], , , [$4])"
2489 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2490 for ac_dir in $ac_dummy; do
2492 if test -z "$ac_dir"
2496 ac_file="$ac_dir/$2"
2498 if test -f "$ac_file"
2501 ac_cv_pfile_$1="$ac_dir"
2505 ifelse([$3],,,[if test -z "$ac_found"
2511 $1="$ac_cv_pfile_$1"
2512 if test -n "$ac_found" -o -n "[$]$1"
2514 AC_MSG_RESULT([$]$1)
2521 dnl AC_PATH_HEADER(variable,header,action-if-not-found,default-locations)
2522 dnl Note that the above may set variable to an empty value if the header is
2523 dnl already in the include path
2524 AC_DEFUN(AC_PATH_HEADER,[
2525 AC_MSG_CHECKING([for $2 header])
2526 AC_CACHE_VAL(ac_cv_pheader_$1,
2529 ac_dummy="ifelse([$4], , :/usr/local/include, [$4])"
2530 save_CPPFLAGS="$CPPFLAGS"
2531 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2532 for ac_dir in $ac_dummy; do
2534 if test -z "$ac_dir"
2536 CPPFLAGS="$save_CPPFLAGS"
2538 CPPFLAGS="-I$ac_dir $save_CPPFLAGS"
2540 AC_TRY_COMPILE([#include <$2>],,ac_found=1;ac_cv_pheader_$1="$ac_dir";break)
2542 CPPFLAGS="$save_CPPFLAGS"
2543 ifelse([$3],,,[if test -z "$ac_found"
2549 $1="$ac_cv_pheader_$1"
2550 if test -n "$ac_found" -o -n "[$]$1"
2552 AC_MSG_RESULT([$]$1)
2559 dnl AC_PATH_LIBRARY(variable,libraries,extra libs,action-if-not-found,default-locations)
2560 AC_DEFUN(AC_PATH_LIBRARY,[
2561 AC_MSG_CHECKING([for $2])
2562 AC_CACHE_VAL(ac_cv_plibrary_$1,
2565 ac_dummy="ifelse([$5], , :/usr/local/lib, [$5])"
2567 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2568 for ac_dir in $ac_dummy; do
2570 if test -z "$ac_dir"
2572 LIBS="$2 $3 $save_LIBS"
2574 LIBS="-L$ac_dir $2 $3 $save_LIBS"
2576 AC_TRY_LINK(,,ac_found=1;ac_cv_plibrary_$1="$ac_dir";break)
2579 ifelse([$4],,,[if test -z "$ac_found"
2585 $1="$ac_cv_plibrary_$1"
2586 if test -n "$ac_found" -o -n "[$]$1"
2588 AC_MSG_RESULT([$]$1)
2595 dnl **** Try to find where winelib is located ****
2598 WINE_INCLUDE_ROOT=""
2599 WINE_INCLUDE_PATH=""
2600 WINE_LIBRARY_ROOT=""
2601 WINE_LIBRARY_PATH=""
2610 [ --with-wine=DIR the Wine package (or sources) is in DIR],
2611 [if test "$withval" != "no"; then
2612 WINE_ROOT="$withval";
2619 if test -n "$WINE_ROOT"
2621 WINE_INCLUDE_ROOT="$WINE_ROOT/include:$WINE_ROOT/include/wine"
2622 WINE_LIBRARY_ROOT="$WINE_ROOT:$WINE_ROOT/lib"
2623 WINE_TOOL_PATH="$WINE_ROOT:$WINE_ROOT/bin:$WINE_ROOT/tools/wrc:$WINE_ROOT/tools/winebuild"
2626 AC_ARG_WITH(wine-includes,
2627 [ --with-wine-includes=DIR the Wine includes are in DIR],
2628 [if test "$withval" != "no"; then
2629 WINE_INCLUDES="$withval";
2633 if test -n "$WINE_INCLUDES"
2635 WINE_INCLUDE_ROOT="$WINE_INCLUDES"
2638 AC_ARG_WITH(wine-libraries,
2639 [ --with-wine-libraries=DIR the Wine libraries are in DIR],
2640 [if test "$withval" != "no"; then
2641 WINE_LIBRARIES="$withval";
2645 if test -n "$WINE_LIBRARIES"
2647 WINE_LIBRARY_ROOT="$WINE_LIBRARIES"
2650 AC_ARG_WITH(wine-dlls,
2651 [ --with-wine-dlls=DIR the Wine dlls are in DIR],
2652 [if test "$withval" != "no"; then
2653 WINE_DLLS="$withval";
2657 if test -n "$WINE_DLLS"
2659 WINE_DLL_ROOT="$WINE_DLLS"
2662 AC_ARG_WITH(wine-tools,
2663 [ --with-wine-tools=DIR the Wine tools are in DIR],
2664 [if test "$withval" != "no"; then
2665 WINE_TOOLS="$withval";
2669 if test -n "$WINE_TOOLS"
2671 WINE_TOOL_PATH="$WINE_TOOLS:$WINE_TOOLS/tools/wrc:$WINE_TOOLS/tools/winebuild"
2674 if test -z "$WINE_INCLUDE_ROOT"
2676 WINE_INCLUDE_ROOT=":/usr/include/wine:/usr/local/include/wine:/opt/wine/include:/opt/wine/include/wine";
2678 AC_PATH_FILE(WINE_INCLUDE_ROOT,[windef.h],[
2679 AC_MSG_ERROR([Could not find the Wine headers (windef.h)])
2680 ],$WINE_INCLUDE_ROOT)
2682 AC_PATH_HEADER(WINE_INCLUDE_ROOT,[windef.h],[
2683 AC_MSG_ERROR([Could not include the Wine headers (windef.h)])
2684 ],$WINE_INCLUDE_ROOT)
2685 if test -n "$WINE_INCLUDE_ROOT"
2687 WINE_INCLUDE_PATH="-I$WINE_INCLUDE_ROOT"
2689 WINE_INCLUDE_PATH=""
2692 if test -z "$WINE_LIBRARY_ROOT"
2694 WINE_LIBRARY_ROOT=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib"
2696 AC_PATH_FILE(WINE_LIBRARY_ROOT,[libwine.so],[
2697 AC_MSG_ERROR([Could not find the Wine libraries (libwine.so)])
2698 ],$WINE_LIBRARY_ROOT)
2700 AC_PATH_LIBRARY(WINE_LIBRARY_ROOT,[-lwine],[],[
2701 AC_MSG_ERROR([Could not link with the Wine libraries (libwine.so)])
2702 ],$WINE_LIBRARY_ROOT)
2703 if test -n "$WINE_LIBRARY_ROOT"
2705 WINE_LIBRARY_PATH="-L$WINE_LIBRARY_ROOT"
2706 LD_PATH="$WINE_LIBRARY_ROOT"
2708 WINE_LIBRARY_PATH=""
2711 if test -z "$WINE_DLL_ROOT"
2713 if test -n "$WINE_LIBRARY_ROOT"
2715 WINE_DLL_ROOT="$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/dlls"
2717 WINE_DLL_ROOT="/lib:/lib/dlls:/usr/lib:/usr/lib/dlls:/usr/local/lib:/usr/local/lib/dlls"
2720 AC_PATH_FILE(WINE_DLL_ROOT,[libntdll.so],[
2721 AC_MSG_ERROR([Could not find the Wine dlls (libntdll.so)])
2724 AC_PATH_LIBRARY(WINE_DLL_ROOT,[-lntdll],[$WINE_LIBRARY_PATH -lwine -lwine_unicode],[
2725 AC_MSG_ERROR([Could not link with the Wine dlls (libntdll.so)])
2727 WINE_DLL_PATH="-L$WINE_DLL_ROOT"
2729 if test -n "$LD_PATH"
2731 LD_PATH="$LD_PATH:$WINE_DLL_ROOT"
2733 LD_PATH="$WINE_DLL_ROOT"
2735 LD_PATH="LD_LIBRARY_PATH=\"$LD_PATH:\$\$LD_LIBRARY_PATH\""
2737 if test -z "$WINE_TOOL_PATH"
2739 WINE_TOOL_PATH="$PATH:/usr/local/bin:/opt/wine/bin"
2741 AC_PATH_PROG(WINE,wine,,$WINE_TOOL_PATH)
2744 AC_MSG_ERROR([Could not find Wine's wine tool])
2746 AC_PATH_PROG(WINEBUILD,winebuild,,$WINE_TOOL_PATH)
2747 if test -z "$WINEBUILD"
2749 AC_MSG_ERROR([Could not find Wine's winebuild tool])
2751 AC_PATH_PROG(WRC,wrc,,$WINE_TOOL_PATH)
2754 AC_MSG_ERROR([Could not find Wine's wrc tool])
2758 AC_SUBST(WINE_INCLUDE_PATH)
2759 AC_SUBST(WINE_LIBRARY_PATH)
2760 AC_SUBST(WINE_DLL_PATH)
2762 dnl **** Try to find where the MFC are located ****
2765 if test "x$NEEDS_MFC" = "x1"
2767 ATL_INCLUDE_ROOT="";
2768 ATL_INCLUDE_PATH="";
2769 MFC_INCLUDE_ROOT="";
2770 MFC_INCLUDE_PATH="";
2771 MFC_LIBRARY_ROOT="";
2772 MFC_LIBRARY_PATH="";
2775 [ --with-mfc=DIR the MFC package (or sources) is in DIR],
2776 [if test "$withval" != "no"; then
2777 MFC_ROOT="$withval";
2784 if test -n "$MFC_ROOT"
2786 ATL_INCLUDE_ROOT="$MFC_ROOT";
2787 MFC_INCLUDE_ROOT="$MFC_ROOT";
2788 MFC_LIBRARY_ROOT="$MFC_ROOT";
2791 AC_ARG_WITH(atl-includes,
2792 [ --with-atl-includes=DIR the ATL includes are in DIR],
2793 [if test "$withval" != "no"; then
2794 ATL_INCLUDES="$withval";
2798 if test -n "$ATL_INCLUDES"
2800 ATL_INCLUDE_ROOT="$ATL_INCLUDES";
2803 AC_ARG_WITH(mfc-includes,
2804 [ --with-mfc-includes=DIR the MFC includes are in DIR],
2805 [if test "$withval" != "no"; then
2806 MFC_INCLUDES="$withval";
2810 if test -n "$MFC_INCLUDES"
2812 MFC_INCLUDE_ROOT="$MFC_INCLUDES";
2815 AC_ARG_WITH(mfc-libraries,
2816 [ --with-mfc-libraries=DIR the MFC libraries are in DIR],
2817 [if test "$withval" != "no"; then
2818 MFC_LIBRARIES="$withval";
2822 if test -n "$MFC_LIBRARIES"
2824 MFC_LIBRARY_ROOT="$MFC_LIBRARIES";
2827 OLDCPPFLAGS="$CPPFLAGS"
2828 dnl FIXME: We should not have defines in any of the include paths
2829 CPPFLAGS="$WINE_INCLUDE_PATH -I$WINE_INCLUDE_ROOT/mixedcrt -D_DLL -D_MT $CPPFLAGS"
2830 ATL_INCLUDE_PATH="-I\$(WINE_INCLUDE_ROOT)/mixedcrt -D_DLL -D_MT"
2831 if test -z "$ATL_INCLUDE_ROOT"
2833 ATL_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/atl:/usr/include/atl:/usr/local/include/atl:/opt/mfc/include/atl:/opt/atl/include"
2835 ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT:$ATL_INCLUDE_ROOT/atl:$ATL_INCLUDE_ROOT/atl/include"
2837 AC_PATH_HEADER(ATL_INCLUDE_ROOT,atldef.h,[
2838 AC_MSG_ERROR([Could not find the ATL includes])
2839 ],$ATL_INCLUDE_ROOT)
2840 if test -n "$ATL_INCLUDE_ROOT"
2842 ATL_INCLUDE_PATH="$ATL_INCLUDE_PATH -I$ATL_INCLUDE_ROOT"
2845 MFC_INCLUDE_PATH="$ATL_INCLUDE_PATH"
2846 if test -z "$MFC_INCLUDE_ROOT"
2848 MFC_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/mfc:/usr/include/mfc:/usr/local/include/mfc:/opt/mfc/include/mfc:/opt/mfc/include"
2850 MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT:$MFC_INCLUDE_ROOT/mfc:$MFC_INCLUDE_ROOT/mfc/include"
2852 AC_PATH_HEADER(MFC_INCLUDE_ROOT,afx.h,[
2853 AC_MSG_ERROR([Could not find the MFC includes])
2854 ],$MFC_INCLUDE_ROOT)
2855 if test -n "$MFC_INCLUDE_ROOT" -a "$ATL_INCLUDE_ROOT" != "$MFC_INCLUDE_ROOT"
2857 MFC_INCLUDE_PATH="$MFC_INCLUDE_PATH -I$MFC_INCLUDE_ROOT"
2859 CPPFLAGS="$OLDCPPFLAGS"
2861 if test -z "$MFC_LIBRARY_ROOT"
2863 MFC_LIBRARY_ROOT=":$WINE_LIBRARY_ROOT:/usr/lib/mfc:/usr/local/lib:/usr/local/lib/mfc:/opt/mfc/lib";
2865 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT:$MFC_LIBRARY_ROOT/lib:$MFC_LIBRARY_ROOT/mfc/src";
2867 AC_PATH_LIBRARY(MFC_LIBRARY_ROOT,[-lmfc],[$WINE_LIBRARY_PATH -lwine -lwine_unicode],[
2868 AC_MSG_ERROR([Could not find the MFC library])
2869 ],$MFC_LIBRARY_ROOT)
2870 if test -n "$MFC_LIBRARY_ROOT" -a "$MFC_LIBRARY_ROOT" != "$WINE_LIBRARY_ROOT"
2872 MFC_LIBRARY_PATH="-L$MFC_LIBRARY_ROOT"
2877 AC_SUBST(ATL_INCLUDE_PATH)
2878 AC_SUBST(MFC_INCLUDE_PATH)
2879 AC_SUBST(MFC_LIBRARY_PATH)
2884 dnl **** Generate output files ****
2886 MAKE_RULES=Make.rules
2887 AC_SUBST_FILE(MAKE_RULES)
2891 ##WINEMAKER_PROJECTS##
2895 echo "Configure finished. Do 'make' to build the project."
2898 dnl Local Variables:
2899 dnl comment-start: "dnl "
2901 dnl comment-start-skip: "\\bdnl\\b\\s *"
2902 dnl compile-command: "autoconf"
2904 --- Make.rules.in ---
2905 # Copyright 2000 Francois Gouget for CodeWeavers
2906 # fgouget@codeweavers.com
2908 # Global rules shared by all makefiles -*-Makefile-*-
2910 # Each individual makefile must define the following variables:
2911 # TOPOBJDIR : top-level object directory
2912 # SRCDIR : source directory for this module
2914 # Each individual makefile may define the following additional variables:
2916 # SUBDIRS : subdirectories that contain a Makefile
2917 # DLLS : WineLib libraries to be built
2918 # EXES : WineLib executables to be built
2920 # CEXTRA : extra c flags (e.g. '-Wall')
2921 # CXXEXTRA : extra c++ flags (e.g. '-Wall')
2922 # WRCEXTRA : extra wrc flags (e.g. '-p _SysRes')
2923 # DEFINES : defines (e.g. -DSTRICT)
2924 # INCLUDE_PATH : additional include path
2925 # LIBRARY_PATH : additional library path
2926 # LIBRARIES : additional Unix libraries to link with
2928 # C_SRCS : C sources for the module
2929 # CXX_SRCS : C++ sources for the module
2930 # RC_SRCS : resource source files
2931 # SPEC_SRCS : interface definition files
2936 WINE_INCLUDE_ROOT = @WINE_INCLUDE_ROOT@
2937 WINE_INCLUDE_PATH = @WINE_INCLUDE_PATH@
2938 WINE_LIBRARY_ROOT = @WINE_LIBRARY_ROOT@
2939 WINE_LIBRARY_PATH = @WINE_LIBRARY_PATH@
2940 WINE_DLL_ROOT = @WINE_DLL_ROOT@
2941 WINE_DLL_PATH = @WINE_DLL_PATH@
2947 ATL_INCLUDE_ROOT = @ATL_INCLUDE_ROOT@
2948 ATL_INCLUDE_PATH = @ATL_INCLUDE_PATH@
2949 MFC_INCLUDE_ROOT = @MFC_INCLUDE_ROOT@
2950 MFC_INCLUDE_PATH = @MFC_INCLUDE_PATH@
2951 MFC_LIBRARY_ROOT = @MFC_LIBRARY_ROOT@
2952 MFC_LIBRARY_PATH = @MFC_LIBRARY_PATH@
2954 # First some useful definitions
2962 CXXFLAGS = @CXXFLAGS@
2964 OPTIONS = @OPTIONS@ -D_REENTRANT -DWINELIB
2965 LIBS = @LIBS@ $(LIBRARY_PATH)
2967 ALLFLAGS = $(DEFINES) -I$(SRCDIR) $(INCLUDE_PATH) $(WINE_INCLUDE_PATH)
2968 ALLCFLAGS = $(CFLAGS) $(CEXTRA) $(OPTIONS) $(ALLFLAGS)
2969 ALLCXXFLAGS=$(CXXFLAGS) $(CXXEXTRA) $(OPTIONS) $(ALLFLAGS)
2970 ALLWRCFLAGS=$(WRCFLAGS) $(WRCEXTRA) $(OPTIONS) $(ALLFLAGS)
2971 DLL_LINK = $(LIBRARY_PATH) $(LIBRARIES:%=-l%) $(WINE_LIBRARY_PATH) -lwine -lwine_unicode -lwine_uuid
2973 LDSHARED = @LDSHARED@
2974 LDXXSHARED= @LDXXSHARED@
2975 LDDLLFLAGS= @LDDLLFLAGS@
2977 STRIPFLAGS= --strip-unneeded
2982 WINEBUILD = @WINEBUILD@
2985 # Installation infos
2988 INSTALL_PROGRAM = $(INSTALL)
2989 INSTALL_DATA = $(INSTALL) -m 644
2991 exec_prefix = @exec_prefix@
2999 OBJS = $(C_SRCS:.c=.o) $(CXX_SRCS:.cpp=.o) \
3000 $(SPEC_SRCS:.spec=.spec.o)
3001 CLEAN_FILES = *.spec.c y.tab.c y.tab.h lex.yy.c \
3003 \\\#*\\\# *~ *% .\\\#*
3007 .SUFFIXES: .cpp .rc .res .tmp.o .spec .spec.c .spec.o
3010 $(CC) -c $(ALLCFLAGS) -o $@ $<
3013 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
3016 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
3019 $(LD_PATH) $(WRC) $(ALLWRCFLAGS) -o $@ $<
3021 .PHONY: all install uninstall clean distclean depend dummy
3023 # 'all' target first in case the enclosing Makefile didn't define any target
3027 # Rules for makefile
3029 Makefile: Makefile.in $(TOPSRCDIR)/configure
3030 @echo Makefile is older than $?, please rerun $(TOPSRCDIR)/configure
3033 # Rules for cleaning
3035 $(SUBDIRS:%=%/__clean__): dummy
3036 cd `dirname $@` && $(MAKE) clean
3038 $(EXTRASUBDIRS:%=%/__clean__): dummy
3039 -cd `dirname $@` && $(RM) $(CLEAN_FILES)
3041 clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
3042 $(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(OBJS) $(SPEC_SRCS:.spec=.tmp.o) $(EXES) $(EXES:%=%.so) $(DLLS)
3044 # Rules for installing
3046 $(SUBDIRS:%=%/__install__): dummy
3047 cd `dirname $@` && $(MAKE) install
3049 $(SUBDIRS:%=%/__uninstall__): dummy
3050 cd `dirname $@` && $(MAKE) uninstall
3059 # End of global rules
3062 * Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
3070 #include <windows.h>
3075 * Describe the wrapped application
3079 * This is either CUIEXE for a console based application or
3080 * GUIEXE for a regular windows application.
3082 #define APP_TYPE ##WINEMAKER_APP_TYPE##
3085 * This is the application library's base name, i.e. 'hello' if the
3086 * library is called 'libhello.so'.
3088 static char* appName = ##WINEMAKER_APP_NAME##;
3091 * This is the name of the application's Windows module. If left NULL
3092 * then appName is used.
3094 static char* appModule = NULL;
3097 * This is the application's entry point. This is usually "WinMain" for a
3098 * GUIEXE and 'main' for a CUIEXE application.
3100 static char* appInit = ##WINEMAKER_APP_INIT##;
3103 * This is either non-NULL for MFC-based applications and is the name of the
3104 * MFC's module. This is the module in which we will take the 'WinMain'
3107 static char* mfcModule = ##WINEMAKER_APP_MFC##;
3112 * Implement the main.
3115 #if APP_TYPE == GUIEXE
3116 typedef int WINAPI (*WinMainFunc)(HINSTANCE hInstance, HINSTANCE hPrevInstance,
3117 PSTR szCmdLine, int iCmdShow);
3119 typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp);
3122 #if APP_TYPE == GUIEXE
3123 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
3124 PSTR szCmdLine, int iCmdShow)
3126 int WINAPI Main(int argc, char** argv, char** envp)
3130 HINSTANCE hApp,hMFC,hMain;
3135 /* Load the application's library */
3136 libName=(char*)malloc(strlen(appName)+5+3+1);
3137 /* FIXME: we should get the wrapper's path and use that as the base for
3140 sprintf(libName,"./lib%s.so",appName);
3141 appLibrary=dlopen(libName,RTLD_NOW);
3142 if (appLibrary==NULL) {
3143 sprintf(libName,"lib%s.so",appName);
3144 appLibrary=dlopen(libName,RTLD_NOW);
3146 if (appLibrary==NULL) {
3147 char format[]="Could not load the %s library:\r\n%s";
3152 msg=(char*)malloc(strlen(format)+strlen(libName)+strlen(error));
3153 sprintf(msg,format,libName,error);
3154 MessageBox(NULL,msg,"dlopen error",MB_OK);
3159 /* Then if this application is MFC based, load the MFC module */
3160 /* FIXME: I'm not sure this is really necessary */
3161 if (mfcModule!=NULL) {
3162 hMFC=LoadLibrary(mfcModule);
3164 char format[]="Could not load the MFC module %s (%d)";
3167 msg=(char*)malloc(strlen(format)+strlen(mfcModule)+11);
3168 sprintf(msg,format,mfcModule,GetLastError());
3169 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
3173 /* MFC is a special case: the WinMain is in the MFC library,
3174 * instead of the application's library.
3181 /* Load the application's module */
3182 if (appModule==NULL) {
3185 hApp=LoadLibrary(appModule);
3187 char format[]="Could not load the application's module %s (%d)";
3190 msg=(char*)malloc(strlen(format)+strlen(appModule)+11);
3191 sprintf(msg,format,appModule,GetLastError());
3192 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
3195 } else if (hMain==NULL) {
3199 /* Get the address of the application's entry point */
3200 appMain=(WinMainFunc*)GetProcAddress(hMain, appInit);
3201 if (appMain==NULL) {
3202 char format[]="Could not get the address of %s (%d)";
3205 msg=(char*)malloc(strlen(format)+strlen(appInit)+11);
3206 sprintf(msg,format,appInit,GetLastError());
3207 MessageBox(NULL,msg,"GetProcAddress error",MB_OK);
3212 /* And finally invoke the application's entry point */
3213 #if APP_TYPE == GUIEXE
3214 retcode=(*((WinMainFunc)appMain))(hApp,hPrevInstance,szCmdLine,iCmdShow);
3216 retcode=(*((MainFunc)appMain))(argc,argv,envp);
3219 /* Cleanup and done */
3224 dlclose(appLibrary);