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 # Make a backup of the files
57 # Defines which files to rename
61 # If we don't find the file referenced by an include, lower it
62 my $opt_lower_include;
65 # Options for the 'Source' method
68 # Specifies that we have only one target so that all sources relate
69 # to this target. By default this variable is left undefined which
70 # means winemaker should try to find out by itself what the targets
71 # are. If not undefined then this contains the name of the default
72 # target (without the extension).
73 my $opt_single_target;
76 # If '$opt_single_target' has been specified then this is the type of
77 # that target. Otherwise it specifies whether the default target type
78 # is guiexe or cuiexe.
82 # Contains the default set of flags to be used when creating a new target.
86 # If true then winemaker should ask questions to the user as it goes
88 my $opt_is_interactive;
89 my $opt_ask_project_options;
90 my $opt_ask_target_options;
93 # If false then winemaker should not generate any file, i.e.
94 # no makefiles, but also no .spec files, no configure.in, etc.
95 my $opt_no_generated_files;
98 # Specifies not to print the banner if set.
105 # Target modelization
109 # The description of a target is stored in an array. The constants
110 # below identify what is stored at each index of the array.
113 # This is the name of the target.
117 # Defines the type of target we want to build. See the TT_xxx
122 # Defines the target's enty point, i.e. the function that is called
127 # This is a bitfield containing flags refining the way the target
128 # should be handled. See the TF_xxx constants below
132 # This is a reference to an array containing the list of the
133 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
137 my $T_SOURCES_MISC=7;
140 # This is a reference to an array containing the list of macro
145 # This is a reference to an array containing the list of directory
146 # names that constitute the include path
147 my $T_INCLUDE_PATH=9;
150 # Same as T_INCLUDE_PATH but for the library search path
151 my $T_LIBRARY_PATH=10;
154 # The list of Windows libraries to import
158 # The list of Unix libraries to link with
162 # The list of dependencies between targets
166 # The following constants define the recognized types of target
169 # This is not a real target. This type of target is used to collect
170 # the sources that don't seem to belong to any other target. Thus no
171 # real target is generated for them, we just put the sources of the
172 # fake target in the global source list.
176 # For executables in the windows subsystem
180 # For executables in the console subsystem
184 # For dynamically linked libraries
188 # The following constants further refine how the target should be handled
191 # This target needs a wrapper
195 # This target is a wrapper
199 # This target is an MFC-based target
203 # Initialize a target:
204 # - set the target type to TT_SETTINGS, i.e. no real target will
210 @
$target[$T_TYPE]=$TT_SETTINGS;
211 # leaving $T_INIT undefined
212 @
$target[$T_FLAGS]=$opt_flags;
213 @
$target[$T_SOURCES_C]=[];
214 @
$target[$T_SOURCES_CXX]=[];
215 @
$target[$T_SOURCES_RC]=[];
216 @
$target[$T_SOURCES_MISC]=[];
217 @
$target[$T_DEFINES]=[];
218 @
$target[$T_INCLUDE_PATH]=[];
219 @
$target[$T_LIBRARY_PATH]=[];
220 @
$target[$T_IMPORTS]=[];
221 @
$target[$T_LIBRARIES]=[];
222 @
$target[$T_DEPENDS]=[];
228 if ($type == $TT_GUIEXE) {
230 } elsif ($type == $TT_CUIEXE) {
232 } elsif ($type == $TT_DLL) {
241 # Project modelization
245 # First we have the notion of project. A project is described by an
246 # array (since we don't have structs in perl). The constants below
247 # identify what is stored at each index of the array.
250 # This is the path in which this project is located. In other
251 # words, this is the path to the Makefile.
255 # This index contains a reference to an array containing the project-wide
256 # settings. The structure of that arrray is actually identical to that of
257 # a regular target since it can also contain extra sources.
261 # This index contains a reference to an array of targets for this
262 # project. Each target describes how an executable or library is to
263 # be built. For each target this description takes the same form as
264 # that of the project: an array. So this entry is an array of arrays.
268 # Initialize a project:
269 # - set the project's path
270 # - initialize the target list
271 # - create a default target (will be removed later if unnecessary)
277 my $project_settings=[];
278 target_init
($project_settings);
280 @
$project[$P_PATH]=$path;
281 @
$project[$P_SETTINGS]=$project_settings;
282 @
$project[$P_TARGETS]=[];
299 # Contains the list of all projects. This list tells us what are
300 # the subprojects of the main Makefile and where we have to generate
305 # This is the main project, i.e. the one in the "." directory.
306 # It may well be empty in which case the main Makefile will only
307 # call out subprojects.
311 # Contains the defaults for the include path, etc.
312 # We store the defaults as if this were a target except that we only
313 # exploit the defines, include path, library path, library list and misc
318 # If one of the projects requires the MFc then we set this global variable
319 # to true so that configure asks the user to provide a path tothe MFC
331 # Cleans up a name to make it an acceptable Makefile
337 $name =~ tr/a-zA-Z0-9_/_/c;
342 # Returns true is the specified pathname is absolute.
343 # Note: pathnames that start with a variable '$' or
344 # '~' are considered absolute.
349 return ($path =~ /^[\/~\
$]/);
353 # Performs a binary search looking for the specified item
358 my $last=@
{$array}-1;
361 while ($first<=$last) {
362 my $index=int(($first+$last)/2);
363 my $cmp=@
$array[$index] cmp $item;
378 # 'Source'-based Project analysis
383 # Allows the user to specify makefile and target specific options
384 # - target: the structure in which to store the results
385 # - options: the string containing the options
386 sub source_set_options
391 #FIXME: we must deal with escaping of stuff and all
392 foreach $option (split / /,$options) {
393 if (@
$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
394 push @
{@
$target[$T_DEFINES]},$option;
395 } elsif (@
$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
396 push @
{@
$target[$T_INCLUDE_PATH]},$option;
397 } elsif ($option =~ /^-L/) {
398 push @
{@
$target[$T_LIBRARY_PATH]},$option;
399 } elsif ($option =~ /^-i/) {
400 push @
{@
$target[$T_IMPORTS]},$';
401 } elsif ($option =~ /^-l/) {
402 push @{@$target[$T_LIBRARIES]},$';
403 } elsif (@
$target[$T_TYPE] != $TT_DLL and
404 $option =~ /^--wrap/) {
405 print STDERR
"warning: --wrap no longer supported, ignoring\n";
406 #@$target[$T_FLAGS]|=$TF_WRAP;
407 } elsif (@
$target[$T_TYPE] != $TT_DLL and
408 $option =~ /^--nowrap/) {
409 @
$target[$T_FLAGS]&=~$TF_WRAP;
410 } elsif ($option =~ /^--mfc/) {
411 @
$target[$T_FLAGS]|=$TF_MFC;
412 #if (@$target[$T_TYPE] != $TT_DLL) {
413 # @$target[$T_FLAGS]|=$TF_WRAP;
415 } elsif ($option =~ /^--nomfc/) {
416 @
$target[$T_FLAGS]&=~$TF_MFC;
417 #@$target[$T_FLAGS]&=~($TF_MFC|$TF_WRAP);
419 print STDERR
"error: unknown option \"$option\"\n";
427 # Scans the specified directory to:
428 # - see if we should create a Makefile in this directory. We normally do
429 # so if we find a project file and sources
430 # - get a list of targets for this directory
431 # - get the list of source files
432 sub source_scan_directory
434 # a reference to the parent's project
435 my $parent_project=$_[0];
436 # the full relative path to the current directory, including a
437 # trailing '/', or an empty string if this is the top level directory
439 # the name of this directory, including a trailing '/', or an empty
440 # string if this is the top level directory
443 # reference to the project for this directory. May not be used
445 # list of targets found in the 'current' directory
447 # list of sources found in the current directory
452 # true if this directory contains a Windows project
453 my $has_win_project=0;
454 # If we don't find any executable/library then we might make up targets
455 # from the list of .dsp/.mak files we find since they usually have the
456 # same name as their target.
460 if (defined $opt_single_target or $dirname eq "") {
461 # Either there is a single target and thus a single project,
462 # or we are in the top level directory for which a project
464 $project=$parent_project;
467 project_init
($project,$path);
469 my $project_settings=@
$project[$P_SETTINGS];
471 # First find out what this directory contains:
472 # collect all sources, targets and subdirectories
473 my $directory=get_directory_contents
($path);
474 foreach $dentry (@
$directory) {
475 if ($dentry =~ /^\./) {
478 my $fullentry="$path$dentry";
479 if (-d
"$fullentry") {
480 if ($dentry =~ /^(Release|Debug)/i) {
481 # These directories are often used to store the object files and the
482 # resulting executable/library. They should not contain anything else.
483 my @candidates=grep /\.(exe|dll)$/i, @
{get_directory_contents
("$fullentry")};
484 foreach $candidate (@candidates) {
485 if ($candidate =~ s/\.exe$//i) {
486 $targets{$candidate}=1;
487 } elsif ($candidate =~ s/^(.*)\.dll$/lib$1.so/i) {
488 $targets{$candidate}=1;
491 } elsif ($dentry =~ /^include/i) {
492 # This directory must contain headers we're going to need
493 push @
{@
$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
495 # Recursively scan this directory. Any source file that cannot be
496 # attributed to a project in one of the subdirectories will be attributed
498 source_scan_directory
($project,"$fullentry/","$dentry/");
500 } elsif (-f
"$fullentry") {
501 if ($dentry =~ s/\.exe$//i) {
503 } elsif ($dentry =~ s/^(.*)\.dll$/lib$1.so/i) {
505 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.spec\.c$/) {
506 push @sources_c,"$dentry";
507 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
508 if ($dentry =~ /^stdafx.cpp$/i) {
509 push @sources_misc,"$dentry";
510 @
$project_settings[$T_FLAGS]|=$TF_MFC;
512 push @sources_cxx,"$dentry";
514 } elsif ($dentry =~ /\.rc$/i) {
515 push @sources_rc,"$dentry";
516 } elsif ($dentry =~ /\.(h|hxx|inl|rc2|dlg)$/i) {
517 push @sources_misc,"$dentry";
518 if ($dentry =~ /^stdafx.h$/i) {
519 @
$project_settings[$T_FLAGS]|=$TF_MFC;
521 } elsif ($dentry =~ /\.dsp$/i) {
522 push @dsp_files,"$dentry";
524 } elsif ($dentry =~ /\.mak$/i) {
525 push @mak_files,"$dentry";
527 } elsif ($dentry =~ /^makefile/i) {
534 # If we have a single target then all we have to do is assign
535 # all the sources to it and we're done
536 # FIXME: does this play well with the --interactive mode?
537 if ($opt_single_target) {
538 my $target=@
{@
$project[$P_TARGETS]}[0];
539 push @
{@
$target[$T_SOURCES_C]},map "$path$_",@sources_c;
540 push @
{@
$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
541 push @
{@
$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
542 push @
{@
$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
546 my $source_count=@sources_c+@sources_cxx+@sources_rc+
547 @
{@
$project_settings[$T_SOURCES_C]}+
548 @
{@
$project_settings[$T_SOURCES_CXX]}+
549 @
{@
$project_settings[$T_SOURCES_RC]};
550 if ($source_count == 0) {
551 # A project without real sources is not a project, get out!
552 if ($project!=$parent_project) {
553 $parent_settings=@
$parent_project[$P_SETTINGS];
554 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
555 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
559 #print "targets=",%targets,"\n";
560 #print "target_count=$target_count\n";
561 #print "has_win_project=$has_win_project\n";
562 #print "dirname=$dirname\n";
565 if (($has_win_project != 0) or ($dirname eq "")) {
566 # Deal with cases where we could not find any executable/library, and
567 # thus have no target, although we did find some sort of windows project.
568 $target_count=keys %targets;
569 if ($target_count == 0) {
570 # Try to come up with a target list based on .dsp/.mak files
572 if (@dsp_files > 0) {
573 $prj_list=\
@dsp_files;
575 $prj_list=\
@mak_files;
577 foreach $filename (@
$prj_list) {
578 $filename =~ s/\.(dsp|mak)$//i;
579 if ($opt_target_type == $TT_DLL) {
580 $filename = "lib$filename.so";
582 $targets{$filename}=1;
584 $target_count=keys %targets;
585 if ($target_count == 0) {
586 # Still nothing, try the name of the directory
588 if ($dirname eq "") {
589 # Bad luck, this is the top level directory!
590 $name=(split /\//, cwd
)[-1];
593 # Remove the trailing '/'. Also eliminate whatever is after the last
594 # '.' as it is likely to be meaningless (.orig, .new, ...)
595 $name =~ s
+(/|\
.[^.]*)$++;
596 if ($name eq "src") {
597 # 'src' is probably a subdirectory of the real project directory.
598 # Try again with the parent (if any).
600 if ($parent =~ s
+([^/]*)/[^/]*/$+$1+) {
603 $name=(split /\//, cwd
)[-1];
607 $name =~ s
+(/|\
.[^.]*)$++;
608 if ($opt_target_type == $TT_DLL) {
609 $name = "lib$name.so";
615 # Ask confirmation to the user if he wishes so
616 if ($opt_is_interactive == $OPT_ASK_YES) {
617 my $target_list=join " ",keys %targets;
618 print "\n*** In ",($path?
$path:"./"),"\n";
619 print "* winemaker found the following list of (potential) targets\n";
620 print "* $target_list\n";
621 print "* Type enter to use it as is, your own comma-separated list of\n";
622 print "* targets, 'none' to assign the source files to a parent directory,\n";
623 print "* or 'ignore' to ignore everything in this directory tree.\n";
624 print "* Target list:\n";
625 $target_list=<STDIN
>;
627 if ($target_list eq "") {
628 # Keep the target list as is, i.e. do nothing
629 } elsif ($target_list eq "none") {
630 # Empty the target list
632 } elsif ($target_list eq "ignore") {
633 # Ignore this subtree altogether
637 foreach $target (split /,/,$target_list) {
640 # Also accept .exe and .dll as a courtesy
641 $target =~ s
+(.*)\
.dll
$+lib
$1.so
+;
642 $target =~ s
+\
.exe
$++;
649 # If we have no project at this level, then transfer all
650 # the sources to the parent project
651 $target_count=keys %targets;
652 if ($target_count == 0) {
653 if ($project!=$parent_project) {
654 my $parent_settings=@
$parent_project[$P_SETTINGS];
655 push @
{@
$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
656 push @
{@
$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
657 push @
{@
$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
658 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
659 push @
{@
$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@
{@
$project_settings[$T_SOURCES_MISC]};
664 # Otherwise add this project to the project list, except for
665 # the main project which is already in the list.
666 if ($dirname ne "") {
667 push @projects,$project;
670 # Ask for project-wide options
671 if ($opt_ask_project_options == $OPT_ASK_YES) {
673 if ((@
$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
676 if ((@
$project_settings[$T_FLAGS] & $TF_WRAP)!=0) {
677 if ($flag_desc ne "") {
680 $flag_desc.="wrapped";
682 print "* Type any project-wide options (-D/-I/-L/-i/-l/--mfc/--wrap),\n";
683 if (defined $flag_desc) {
684 print "* (currently $flag_desc)\n";
686 print "* or 'skip' to skip the target specific options,\n";
687 print "* or 'never' to not be asked this question again:\n";
691 if ($options eq "skip") {
692 $opt_ask_target_options=$OPT_ASK_SKIP;
694 } elsif ($options eq "never") {
695 $opt_ask_project_options=$OPT_ASK_NO;
697 } elsif (source_set_options
($project_settings,$options)) {
700 print "Please re-enter the options:\n";
704 # - Create the targets
705 # - Check if we have both libraries and programs
706 # - Match each target with source files (sort in reverse
707 # alphabetical order to get the longest matches first)
708 my @local_imports=();
709 my @local_depends=();
711 foreach $target_name (sort { $b cmp $a } keys %targets) {
712 # Create the target...
715 target_init
($target);
716 @
$target[$T_NAME]=$target_name;
717 @
$target[$T_FLAGS]|=@
$project_settings[$T_FLAGS];
718 if ($target_name =~ /^lib(.*)\.so$/) {
719 @
$target[$T_TYPE]=$TT_DLL;
720 @
$target[$T_INIT]=get_default_init
($TT_DLL);
721 @
$target[$T_FLAGS]&=~$TF_WRAP;
723 push @local_depends,$target_name;
724 push @local_imports,$basename;
726 @
$target[$T_TYPE]=$opt_target_type;
727 @
$target[$T_INIT]=get_default_init
($opt_target_type);
728 $basename=$target_name;
729 push @exe_list,$target;
731 # This is the default link list of Visual Studio, except for uuid and
732 # odbccp32 which we don't have in Wine. Also I add ntdll which seems
733 # necessary for Winelib.
734 my @std_imports=qw(advapi32.dll comdlg32.dll gdi32.dll kernel32.dll ntdll.dll odbc32.dll ole32 oleaut32.dll shell32.dll user32.dll winspool.drv);
735 @
$target[$T_IMPORTS]=\
@std_imports;
736 push @
{@
$project[$P_TARGETS]},$target;
738 # Ask for target-specific options
739 if ($opt_ask_target_options == $OPT_ASK_YES) {
741 if ((@
$target[$T_FLAGS] & $TF_MFC)!=0) {
744 if ((@
$target[$T_FLAGS] & $TF_WRAP)!=0) {
745 if ($flag_desc ne "") {
750 $flag_desc.="wrapped";
752 if ($flag_desc ne "") {
755 print "* Specify any link option (-L/-i/-l/--mfc/--wrap) specific to the target\n";
756 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
760 if ($options eq "never") {
761 $opt_ask_target_options=$OPT_ASK_NO;
763 } elsif (source_set_options
($target,$options)) {
766 print "Please re-enter the options:\n";
769 if (@
$target[$T_FLAGS] & $TF_MFC) {
770 @
$project_settings[$T_FLAGS]|=$TF_MFC;
771 push @
{@
$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
772 push @
{@
$target[$T_IMPORTS]},"mfc.dll";
773 # FIXME: Link with the MFC in the Unix sense, until we
774 # start exporting the functions properly.
775 push @
{@
$target[$T_LIBRARIES]},"mfc";
779 if ($target_count == 1) {
780 push @
{@
$target[$T_SOURCES_C]},@
{@
$project_settings[$T_SOURCES_C]},@sources_c;
781 @
$project_settings[$T_SOURCES_C]=[];
784 push @
{@
$target[$T_SOURCES_CXX]},@
{@
$project_settings[$T_SOURCES_CXX]},@sources_cxx;
785 @
$project_settings[$T_SOURCES_CXX]=[];
788 push @
{@
$target[$T_SOURCES_RC]},@
{@
$project_settings[$T_SOURCES_RC]},@sources_rc;
789 @
$project_settings[$T_SOURCES_RC]=[];
792 push @
{@
$target[$T_SOURCES_MISC]},@
{@
$project_settings[$T_SOURCES_MISC]},@sources_misc;
793 # No need for sorting these sources
794 @
$project_settings[$T_SOURCES_MISC]=[];
797 foreach $source (@sources_c) {
798 if ($source =~ /^$basename/i) {
799 push @
{@
$target[$T_SOURCES_C]},$source;
803 foreach $source (@sources_cxx) {
804 if ($source =~ /^$basename/i) {
805 push @
{@
$target[$T_SOURCES_CXX]},$source;
809 foreach $source (@sources_rc) {
810 if ($source =~ /^$basename/i) {
811 push @
{@
$target[$T_SOURCES_RC]},$source;
815 foreach $source (@sources_misc) {
816 if ($source =~ /^$basename/i) {
817 push @
{@
$target[$T_SOURCES_MISC]},$source;
822 @
$target[$T_SOURCES_C]=[sort @
{@
$target[$T_SOURCES_C]}];
823 @
$target[$T_SOURCES_CXX]=[sort @
{@
$target[$T_SOURCES_CXX]}];
824 @
$target[$T_SOURCES_RC]=[sort @
{@
$target[$T_SOURCES_RC]}];
825 @
$target[$T_SOURCES_MISC]=[sort @
{@
$target[$T_SOURCES_MISC]}];
827 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
828 $opt_ask_target_options=$OPT_ASK_YES;
831 if (@
$project_settings[$T_FLAGS] & $TF_MFC) {
832 push @
{@
$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
834 # The sources that did not match, if any, go to the extra
835 # source list of the project settings
836 foreach $source (@sources_c) {
838 push @
{@
$project_settings[$T_SOURCES_C]},$source;
841 @
$project_settings[$T_SOURCES_C]=[sort @
{@
$project_settings[$T_SOURCES_C]}];
842 foreach $source (@sources_cxx) {
844 push @
{@
$project_settings[$T_SOURCES_CXX]},$source;
847 @
$project_settings[$T_SOURCES_CXX]=[sort @
{@
$project_settings[$T_SOURCES_CXX]}];
848 foreach $source (@sources_rc) {
850 push @
{@
$project_settings[$T_SOURCES_RC]},$source;
853 @
$project_settings[$T_SOURCES_RC]=[sort @
{@
$project_settings[$T_SOURCES_RC]}];
854 foreach $source (@sources_misc) {
856 push @
{@
$project_settings[$T_SOURCES_MISC]},$source;
859 @
$project_settings[$T_SOURCES_MISC]=[sort @
{@
$project_settings[$T_SOURCES_MISC]}];
861 # Finally if we are building both libraries and programs in
862 # this directory, then the programs should be linked with all
864 if (@local_imports > 0 and @exe_list > 0) {
865 foreach $target (@exe_list) {
866 push @
{@
$target[$T_LIBRARY_PATH]},"-L.";
867 push @
{@
$target[$T_IMPORTS]},map { "$_.dll" } @local_imports;
868 # Also link in the Unix sense since none of the functions
870 push @
{@
$target[$T_LIBRARIES]},@local_imports;
871 push @
{@
$target[$T_DEPENDS]},@local_depends;
877 # Scan the source directories in search of things to build
880 my $main_target=@
{$main_project[$P_TARGETS]}[0];
882 # If there's a single target then this is going to be the default target
883 if (defined $opt_single_target) {
884 if ($opt_target_type == $TT_DLL) {
885 @
$main_target[$T_NAME]="lib$opt_single_target.so";
887 @
$main_target[$T_NAME]="$opt_single_target";
889 @
$main_target[$T_TYPE]=$opt_target_type;
892 # The main directory is always going to be there
893 push @projects,\
@main_project;
895 # Now scan the directory tree looking for source files and, maybe, targets
896 print "Scanning the source directories...\n";
897 source_scan_directory
(\
@main_project,"","");
899 @projects=sort { @
$a[$P_PATH] cmp @
$b[$P_PATH] } @projects;
906 # 'vc.dsp'-based Project analysis
919 # Creating the wrapper targets
923 sub postprocess_targets
925 foreach $project (@projects) {
926 foreach $target (@
{@
$project[$P_TARGETS]}) {
927 if ((@
$target[$T_FLAGS] & $TF_WRAP) != 0) {
929 target_init
($wrapper);
930 @
$wrapper[$T_NAME]=@
$target[$T_NAME];
931 @
$wrapper[$T_TYPE]=@
$target[$T_TYPE];
932 @
$wrapper[$T_INIT]=get_default_init
(@
$target[$T_TYPE]);
933 @
$wrapper[$T_FLAGS]=$TF_WRAPPER | (@
$target[$T_FLAGS] & $TF_MFC);
934 push @
{@
$wrapper[$T_SOURCES_C]},"@$wrapper[$T_NAME]_wrapper.c";
936 my $index=bsearch
(@
$target[$T_SOURCES_C],"@$wrapper[$T_NAME]_wrapper.c");
937 if (defined $index) {
938 splice(@
{@
$target[$T_SOURCES_C]},$index,1);
940 @
$target[$T_NAME]="lib@$target[$T_NAME].so";
941 @
$target[$T_TYPE]=$TT_DLL;
943 push @
{@
$project[$P_TARGETS]},$wrapper;
945 if ((@
$target[$T_FLAGS] & $TF_MFC) != 0) {
946 @
{@
$project[$P_SETTINGS]}[$T_FLAGS]|=$TF_MFC;
962 # Performs a directory traversal and renames the files so that:
963 # - they have the case desired by the user
964 # - their extension is of the appropriate case
965 # - they don't contain annoying characters like ' ', '$', '#', ...
966 sub fix_file_and_directory_names
970 if (opendir(DIRECTORY
, "$dirname")) {
971 foreach $dentry (readdir DIRECTORY
) {
972 if ($dentry =~ /^\./ or $dentry eq "CVS") {
975 # Set $warn to 1 if the user should be warned of the renaming
978 # autoconf and make don't support these characters well
979 my $new_name=$dentry;
980 $new_name =~ s/[ \$]/_/g;
982 # Only all lowercase extensions are supported (because of the
983 # transformations ':.c=.o') .
984 if (-f
"$dirname/$new_name") {
985 if ($new_name =~ /\.C$/) {
986 $new_name =~ s/\.C$/.c/;
988 if ($new_name =~ /\.cpp$/i) {
989 $new_name =~ s/\.cpp$/.cpp/i;
991 if ($new_name =~ s/\.cxx$/.cpp/i) {
994 if ($new_name =~ /\.rc$/i) {
995 $new_name =~ s/\.rc$/.rc/i;
997 # And this last one is to avoid confusion then running make
998 if ($new_name =~ s/^makefile$/makefile.win/) {
1003 # Adjust the case to the user's preferences
1004 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1005 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1007 $new_name=lc $new_name;
1010 # And finally, perform the renaming
1011 if ($new_name ne $dentry) {
1013 print STDERR
"warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1015 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1016 print STDERR
"error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1017 print STDERR
" $!\n";
1021 if (-d
"$dirname/$new_name") {
1022 fix_file_and_directory_names
("$dirname/$new_name");
1025 closedir(DIRECTORY
);
1038 # This maps a directory name to a reference to an array listing
1039 # its contents (files and directories)
1043 # Retrieves the contents of the specified directory.
1044 # We either get it from the directories hashtable which acts as a
1045 # cache, or use opendir, readdir, closedir and store the result
1047 sub get_directory_contents
1052 #print "getting the contents of $dirname\n";
1054 # check for a cached version
1056 if ($dirname eq "") {
1059 $directory=$directories{$dirname};
1060 if (defined $directory) {
1061 #print "->@$directory\n";
1065 # Read this directory
1066 if (opendir(DIRECTORY
, "$dirname")) {
1067 my @files=readdir DIRECTORY
;
1068 closedir(DIRECTORY
);
1071 # Return an empty list
1072 #print "error: cannot open $dirname\n";
1076 #print "->@$directory\n";
1077 $directories{$dirname}=$directory;
1082 # Try to find a file for the specified filename. The attempt is
1083 # case-insensitive which is why it's not trivial. If a match is
1084 # found then we return the pathname with the correct case.
1091 if ($dirname eq "" or $dirname eq ".") {
1093 } elsif ($dirname =~ m
+^[^/]+) {
1094 $dirname=cwd
. "/" . $dirname;
1096 if ($dirname !~ m
+/$+) {
1100 foreach $component (@
$path) {
1101 #print " looking for $component in \"$dirname\"\n";
1102 if ($component eq ".") {
1105 } elsif ($component eq "..") {
1107 $dirname=dirname
($dirname) . "/";
1110 my $directory=get_directory_contents
$dirname;
1112 foreach $dentry (@
$directory) {
1113 if ($dentry =~ /^$component$/i) {
1114 $dirname.="$dentry/";
1115 $real_path.="$dentry/";
1120 if (!defined $found) {
1122 #print " could not find $component in $dirname\n";
1127 $real_path=~ s
+/$++;
1128 #print " -> found $real_path\n";
1133 # Performs a case-insensitive search for the specified file in the
1135 # $line is the line number that should be referenced when an error occurs
1136 # $filename is the file we are looking for
1137 # $dirname is the directory of the file containing the '#include' directive
1138 # if '"' was used, it is an empty string otherwise
1139 # $project and $target specify part of the include path
1140 sub get_real_include_name
1148 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a
-zA
-Z
]:[\
/]?/) {
1149 # This is not a relative path, we cannot make any check
1150 my $warning="path:$filename";
1151 if (!defined $warnings{$warning}) {
1152 $warnings{$warning}="1";
1153 print STDERR
"warning: cannot check the case of absolute pathnames:\n";
1154 print STDERR
"$line: $filename\n";
1157 # Here's how we proceed:
1158 # - split the filename we look for into its components
1159 # - then for each directory in the include path
1160 # - trace the directory components starting from that directory
1161 # - if we fail to find a match at any point then continue with
1162 # the next directory in the include path
1163 # - otherwise, rejoice, our quest is over.
1164 my @file_components=split /[\/\\]+/, $filename;
1165 #print " Searching for $filename from @$project[$P_PATH]\n";
1168 if ($dirname ne "") {
1169 # This is an 'include ""' -> look in dirname first.
1170 #print " in $dirname (include \"\")\n";
1171 $real_filename=search_from
($dirname,\
@file_components);
1172 if (defined $real_filename) {
1173 return $real_filename;
1176 my $project_settings=@
$project[$P_SETTINGS];
1177 foreach $include (@
{@
$target[$T_INCLUDE_PATH]}, @
{@
$project_settings[$T_INCLUDE_PATH]}) {
1178 my $dirname=$include;
1180 if (!is_absolute
($dirname)) {
1181 $dirname="@$project[$P_PATH]$dirname";
1183 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)/++;
1185 #print " in $dirname\n";
1186 $real_filename=search_from
("$dirname",\
@file_components);
1187 if (defined $real_filename) {
1188 return $real_filename;
1191 my $dotdotpath=@
$project[$P_PATH];
1192 $dotdotpath =~ s/[^\/]+/../g
;
1193 foreach $include (@
{$global_settings[$T_INCLUDE_PATH]}) {
1194 my $dirname=$include;
1196 $dirname=~ s
+^\
$\
(TOPSRCDIR\
)\
/++;
1197 #print " in $dirname (global setting)\n";
1198 $real_filename=search_from
("$dirname",\
@file_components);
1199 if (defined $real_filename) {
1200 return $real_filename;
1204 $filename =~ s
+\\\\+/+g
; # in include ""
1205 $filename =~ s
+\\+/+g
; # in include <> !
1206 if ($opt_lower_include) {
1207 return lc "$filename";
1213 # 'Parses' a source file and fixes constructs that would not work with
1214 # Winelib. The parsing is rather simple and not all non-portable features
1215 # are corrected. The most important feature that is corrected is the case
1216 # and path separator of '#include' directives. This requires that each
1217 # source file be associated to a project & target so that the proper
1218 # include path is used.
1219 # Also note that the include path is relative to the directory in which the
1220 # compiler is run, i.e. that of the project, not to that of the file.
1226 $filename="@$project[$P_PATH]$filename";
1227 if (! -e
$filename) {
1231 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1232 my $dirname=dirname
($filename);
1234 if (defined $target and (@
$target[$T_FLAGS] & $TF_MFC)) {
1238 print " $filename\n";
1239 #FIXME:assuming that because there is a .bak file, this is what we want is
1240 #probably flawed. Or is it???
1241 if (! -e
"$filename.bak") {
1242 if (!copy
("$filename","$filename.bak")) {
1243 print STDERR
"error: unable to make a backup of $filename:\n";
1244 print STDERR
" $!\n";
1248 if (!open(FILEI
,"$filename.bak")) {
1249 print STDERR
"error: unable to open $filename.bak for reading:\n";
1250 print STDERR
" $!\n";
1253 if (!open(FILEO
,">$filename")) {
1254 print STDERR
"error: unable to open $filename for writing:\n";
1255 print STDERR
" $!\n";
1260 my $rc_block_depth=0;
1261 my $rc_textinclude_state=0;
1265 if ($is_rc and !$is_mfc and /^(\s*\#\s*include\s*)\"afxres\.h\"/) {
1266 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1267 # the RC files it generates (even in non-MFC projects). So we replace
1268 # it with 'winres.h' its very close standard cousin so that non MFC
1269 # projects can compile in Wine without the MFC sources. This does not
1270 # harm VC but it will put 'afxres.h' back the next time the file is
1272 my $warning="mfc:afxres.h";
1273 if (!defined $warnings{$warning}) {
1274 $warnings{$warning}="1";
1275 print STDERR
"warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winres.h'\n";
1276 print STDERR
"warning: the above warning is issued only once\n";
1278 print FILEO
"/* winemaker: $1\"afxres.h\" */\n";
1279 print FILEO
"$1\"winres.h\"$'";
1281 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1282 my $from_file=($2 eq "<"?
"":$dirname);
1283 my $real_include_name=get_real_include_name
($line,$3,$from_file,$project,$target);
1284 print FILEO
"$1$2$real_include_name$4$'";
1285 $modified|=($real_include_name ne $3);
1286 } elsif (/^(\s*\#\s*pragma\s*pack\s*\((\s*push\s*,?)?\s*)(\w*)(\s*\))/) {
1287 my $pragma_header=$1;
1289 my $pragma_trailer=$4;
1290 #print "$pragma_header$size$pragma_trailer$'";
1291 #print "pragma push: size=$size\n";
1292 print FILEO
"/* winemaker: $pragma_header$size$pragma_trailer */\n";
1294 if ($size eq "pop") {
1295 print FILEO
"#include <poppack.h>$'";
1296 } elsif ($size eq "1") {
1297 print FILEO
"#include <pshpack1.h>$'";
1298 } elsif ($size eq "2") {
1299 print FILEO
"#include <pshpack2.h>$'";
1300 } elsif ($size eq "8") {
1301 print FILEO
"#include <pshpack8.h>$'";
1302 } elsif ($size eq "4" or $size eq "") {
1303 print FILEO
"#include <pshpack4.h>$'";
1305 my $warning="pack:$size";
1306 if (!defined $warnings{$warning}) {
1307 $warnings{$warning}="1";
1308 print STDERR
"warning: assuming that the value of $size is 4 in\n";
1309 print STDERR
"$line: $pragma_header$size$pragma_trailer\n";
1310 print STDERR
"warning: the above warning is issued only once\n";
1312 print FILEO
"#include <pshpack4.h>$'";
1316 if ($rc_block_depth == 0 and /^(\w+\s+(BITMAP|CURSOR|FONT|FONTDIR|ICON|MESSAGETABLE|TEXT)\s+((DISCARDABLE|FIXED|IMPURE|LOADONCALL|MOVEABLE|PRELOAD|PURE)\s+)*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1317 my $from_file=($5 eq "<"?
"":$dirname);
1318 my $real_include_name=get_real_include_name
($line,$6,$from_file,$project,$target);
1319 print FILEO
"$1$5$real_include_name$7$'";
1320 $modified|=($real_include_name ne $6);
1321 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1322 my $from_file=($2 eq "<"?
"":$dirname);
1323 my $real_include_name=get_real_include_name
($line,$3,$from_file,$project,$target);
1324 print FILEO
"$1$2$real_include_name$4$'";
1325 $modified|=($real_include_name ne $3);
1326 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
1327 $rc_textinclude_state=1;
1329 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
1330 print FILEO
"$1winres.h$2$'";
1332 } elsif (/^\s*BEGIN(\W.*)?$/) {
1333 $rc_textinclude_state|=2;
1336 } elsif (/^\s*END(\W.*)?$/) {
1337 $rc_textinclude_state=0;
1338 if ($rc_block_depth>0) {
1351 if ($opt_backup == 0 or $modified == 0) {
1352 if (!unlink("$filename.bak")) {
1353 print STDERR
"error: unable to delete $filename.bak:\n";
1354 print STDERR
" $!\n";
1360 # Analyzes each source file in turn to find and correct issues
1361 # that would cause it not to compile.
1364 print "Fixing the source files...\n";
1365 foreach $project (@projects) {
1366 foreach $target (@
$project[$P_SETTINGS],@
{@
$project[$P_TARGETS]}) {
1367 if (@
$target[$T_FLAGS] & $TF_WRAPPER) {
1370 foreach $source (@
{@
$target[$T_SOURCES_C]}, @
{@
$target[$T_SOURCES_CXX]}, @
{@
$target[$T_SOURCES_RC]}, @
{@
$target[$T_SOURCES_MISC]}) {
1371 fix_file
($source,$project,$target);
1386 # Generates a target's .spec file
1387 sub generate_spec_file
1391 my $project_settings=$_[2];
1393 my $basename=@
$target[$T_NAME];
1394 $basename =~ s
+\
.so
$++;
1395 if (@
$target[$T_FLAGS] & $TF_WRAP) {
1396 $basename =~ s
+^lib
++;
1397 } elsif (@
$target[$T_FLAGS] & $TF_WRAPPER) {
1398 $basename.="_wrapper";
1401 if (!open(FILEO
,">$path$basename.spec")) {
1402 print STDERR
"error: could not open \"$path$basename.spec\" for writing\n";
1403 print STDERR
" $!\n";
1407 my $module=$basename;
1408 $module =~ s
+^lib
++;
1409 $module=canonize
($module);
1410 print FILEO
"name $module\n";
1411 print FILEO
"type win32\n";
1412 if (@
$target[$T_TYPE] == $TT_GUIEXE) {
1413 print FILEO
"mode guiexe\n";
1414 } elsif (@
$target[$T_TYPE] == $TT_CUIEXE) {
1415 print FILEO
"mode cuiexe\n";
1417 print FILEO
"mode dll\n";
1419 if (defined @
$target[$T_INIT] and ((@
$target[$T_FLAGS] & $TF_WRAP) == 0)) {
1420 print FILEO
"init @$target[$T_INIT]\n";
1422 if (@
{@
$target[$T_SOURCES_RC]} > 0) {
1423 if (@
{@
$target[$T_SOURCES_RC]} > 1) {
1424 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";
1426 my $rcname=@
{@
$target[$T_SOURCES_RC]}[0];
1427 $rcname =~ s
+\
.rc
$++i
;
1428 print FILEO
"rsrc $rcname.res\n";
1432 foreach $library (@
{$global_settings[$T_IMPORTS]}) {
1433 if (!defined $imports{$library}) {
1434 print FILEO
"import $library\n";
1435 $imports{$library}=1;
1438 if (defined $project_settings) {
1439 foreach $library (@
{@
$project_settings[$T_IMPORTS]}) {
1440 if (!defined $imports{$library}) {
1441 print FILEO
"import $library\n";
1442 $imports{$library}=1;
1446 foreach $library (@
{@
$target[$T_IMPORTS]}) {
1447 if (!defined $imports{$library}) {
1448 print FILEO
"import $library\n";
1449 $imports{$library}=1;
1453 # Don't forget to export the 'Main' function for wrapped executables,
1454 # except for MFC ones!
1455 if (@
$target[$T_FLAGS] == $TF_WRAP) {
1456 if (@
$target[$T_TYPE] == $TT_GUIEXE) {
1457 print FILEO
"\n@ stdcall @$target[$T_INIT](long long ptr long) @$target[$T_INIT]\n";
1458 } elsif (@
$target[$T_TYPE] == $TT_CUIEXE) {
1459 print FILEO
"\n@ stdcall @$target[$T_INIT](long ptr ptr) @$target[$T_INIT]\n";
1461 print FILEO
"\n@ stdcall @$target[$T_INIT](ptr long ptr) @$target[$T_INIT]\n";
1469 # Generates a target's wrapper file
1470 sub generate_wrapper_file
1475 if (!defined $templates{"wrapper.c"}) {
1476 print STDERR
"winemaker: internal error: No template called 'wrapper.c'\n";
1480 if (!open(FILEO
,">$path@$target[$T_NAME]_wrapper.c")) {
1481 print STDERR
"error: unable to open \"$path$basename.c\" for writing:\n";
1482 print STDERR
" $!\n";
1485 my $app_name="\"@$target[$T_NAME]\"";
1486 my $app_type=(@
$target[$T_TYPE]==$TT_GUIEXE?
"GUIEXE":"CUIEXE");
1487 my $app_init=(@
$target[$T_TYPE]==$TT_GUIEXE?
"\"WinMain\"":"\"main\"");
1488 my $app_mfc=(@
$target[$T_FLAGS] & $TF_MFC?
"\"mfc\"":NULL
);
1489 foreach $line (@
{$templates{"wrapper.c"}}) {
1490 $line =~ s/\#\#WINEMAKER_APP_NAME\#\#/$app_name/;
1491 $line =~ s/\#\#WINEMAKER_APP_TYPE\#\#/$app_type/;
1492 $line =~ s/\#\#WINEMAKER_APP_INIT\#\#/$app_init/;
1493 $line =~ s/\#\#WINEMAKER_APP_MFC\#\#/$app_mfc/;
1500 # A convenience function to generate all the lists (defines,
1501 # C sources, C++ source, etc.) in the Makefile
1511 printf FILEO
"%-22s=",$name;
1513 if (defined $list) {
1514 foreach $item (@
$list) {
1516 if (defined $data) {
1517 $value=&$data($item);
1523 print FILEO
" $value";
1526 print FILEO
" \\\n\t\t\t$value";
1537 # Generates a project's Makefile.in and all the target files
1538 sub generate_project_files
1541 my $project_settings=@
$project[$P_SETTINGS];
1545 # Then sort the targets and separate the libraries from the programs
1546 foreach $target (sort { @
$a[$T_NAME] cmp @
$b[$T_NAME] } @
{@
$project[$P_TARGETS]}) {
1547 if (@
$target[$T_TYPE] == $TT_DLL) {
1548 push @dll_list,$target;
1550 push @exe_list,$target;
1553 @
$project[$P_TARGETS]=[];
1554 push @
{@
$project[$P_TARGETS]}, @dll_list;
1555 push @
{@
$project[$P_TARGETS]}, @exe_list;
1557 if (!open(FILEO
,">@$project[$P_PATH]Makefile.in")) {
1558 print STDERR
"error: could not open \"@$project[$P_PATH]/Makefile.in\" for writing\n";
1559 print STDERR
" $!\n";
1563 print FILEO
"### Generated by Winemaker\n";
1566 print FILEO
"### Generic autoconf variables\n\n";
1567 generate_list
("TOPSRCDIR",1,[ "\@top_srcdir\@" ]);
1568 generate_list
("TOPOBJDIR",1,[ "." ]);
1569 generate_list
("SRCDIR",1,[ "\@srcdir\@" ]);
1570 generate_list
("VPATH",1,[ "\@srcdir\@" ]);
1572 if (@
$project[$P_PATH] eq "") {
1573 # This is the main project. It is also responsible for recursively
1574 # calling the other projects
1575 generate_list
("SUBDIRS",1,\
@projects,sub
1577 if ($_[0] != \
@main_project) {
1578 my $subdir=@
{$_[0]}[$P_PATH];
1582 # Eliminating the main project by returning undefined!
1585 if (@
{@
$project[$P_TARGETS]} > 0) {
1586 generate_list
("DLLS",1,\
@dll_list,sub
1588 return @
{$_[0]}[$T_NAME];
1590 generate_list
("EXES",1,\
@exe_list,sub
1592 return "@{$_[0]}[$T_NAME]";
1594 print FILEO
"\n\n\n";
1596 print FILEO
"### Global settings\n\n";
1597 # Make it so that the project-wide settings override the global settings
1598 generate_list
("DEFINES",0,@
$project_settings[$T_DEFINES],sub
1602 generate_list
("",1,$global_settings[$T_DEFINES],sub
1606 generate_list
("INCLUDE_PATH",$no_extra,@
$project_settings[$T_INCLUDE_PATH],sub
1610 generate_list
("",1,$global_settings[$T_INCLUDE_PATH],sub
1612 if ($_[0] !~ /^-I/) {
1615 if (is_absolute
($')) {
1618 return "-I\$(TOPSRCDIR)/$'";
1620 generate_list("LIBRARY_PATH
",$no_extra,@$project_settings[$T_LIBRARY_PATH],sub
1624 generate_list("",1,$global_settings[$T_LIBRARY_PATH],sub
1626 if ($_[0] !~ /^-L/) {
1629 if (is_absolute($')) {
1632 return "-L\
$(TOPSRCDIR
)/$'";
1634 generate_list("LIBRARIES",$no_extra,@$project_settings[$T_LIBRARIES],sub
1638 generate_list("",1,$global_settings[$T_LIBRARIES],sub
1644 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
1645 @{@$project_settings[$T_SOURCES_CXX]}+
1646 @{@$project_settings[$T_SOURCES_RC]};
1647 my $no_extra=($extra_source_count == 0);
1649 print FILEO "### Extra source lists\n\n";
1650 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
1651 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
1652 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
1654 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
1655 print FILEO "\n\n\n";
1658 # Iterate over all the targets...
1659 foreach $target (@{@$project[$P_TARGETS]}) {
1660 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
1661 my $canon=canonize("@$target[$T_NAME]");
1663 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
1664 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
1665 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
1666 my $basename=@$target[$T_NAME];
1667 $basename =~ s+\.so$++;
1668 if (@$target[$T_FLAGS] & $TF_WRAP) {
1669 $basename =~ s+^lib++;
1670 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1671 $basename.="_wrapper";
1673 generate_list("${canon}_SPEC_SRCS",1,[ "$basename.spec"]);
1674 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH],sub
1678 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES],sub
1682 generate_list("${canon}_DEPENDS",1,@$target[$T_DEPENDS],sub
1687 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(EXTRA_OBJS)"]);
1688 print FILEO "\n\n\n";
1690 print FILEO "### Global source lists\n\n";
1691 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
1693 my $canon=canonize(@{$_[0]}[$T_NAME]);
1695 return "\$(${canon}_C_SRCS)";
1698 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
1700 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
1702 my $canon=canonize(@{$_[0]}[$T_NAME]);
1704 return "\$(${canon}_CXX_SRCS)";
1707 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
1709 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
1711 my $canon=canonize(@{$_[0]}[$T_NAME]);
1713 return "\$(${canon}_RC_SRCS)";
1716 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
1718 generate_list("SPEC_SRCS",1,@$project[$P_TARGETS],sub
1720 my $canon=canonize(@{$_[0]}[$T_NAME]);
1722 return "\$(${canon}_SPEC_SRCS)";
1725 print FILEO "\n\n\n";
1727 print FILEO "### Generic autoconf targets\n\n";
1728 print FILEO "all: ";
1729 if (@$project[$P_PATH] eq "") {
1730 print FILEO "\$(SUBDIRS)";
1732 if (@{@$project[$P_TARGETS]} > 0) {
1733 print FILEO "\$(DLLS) \$(EXES:%=%.so)";
1736 print FILEO "\@MAKE_RULES\@\n";
1738 print FILEO "install::\n";
1739 if (@$project[$P_PATH] eq "") {
1740 # This is the main project. It is also responsible for recursively
1741 # calling the other projects
1742 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) install) || exit 1; done\n";
1744 if (@{@$project[$P_TARGETS]} > 0) {
1745 print FILEO "\tfor i in \$(EXES); do \$(INSTALL_PROGRAM) \$\$i \$(bindir); done\n";
1746 print FILEO "\tfor i in \$(EXES:%=%.so) \$(DLLS); do \$(INSTALL_LIBRARY) \$\$i \$(libdir); done\n";
1749 print FILEO "uninstall::\n";
1750 if (@$project[$P_PATH] eq "") {
1751 # This is the main project. It is also responsible for recursively
1752 # calling the other projects
1753 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) uninstall) || exit 1; done\n";
1755 if (@{@$project[$P_TARGETS]} > 0) {
1756 print FILEO "\tfor i in \$(EXES); do \$(RM) \$(bindir)/\$\$i;done\n";
1757 print FILEO "\tfor i in \$(EXES:%=%.so) \$(DLLS); do \$(RM) \$(libdir)/\$\$i;done\n";
1759 print FILEO "\n\n\n";
1761 if (@{@$project[$P_TARGETS]} > 0) {
1762 print FILEO "### Target specific build rules\n\n";
1763 foreach $target (@{@$project[$P_TARGETS]}) {
1764 my $canon=canonize("@$target[$T_NAME]");
1766 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.tmp.o): \$(${canon}_OBJS)\n";
1767 print FILEO "\t\$(LDCOMBINE) \$(${canon}_OBJS) -o \$\@\n";
1768 print FILEO "\t-\$(STRIP) \$(STRIPFLAGS) \$\@\n";
1770 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.spec.c): \$(${canon}_SPEC_SRCS:.spec) \$(${canon}_SPEC_SRCS:.spec=.tmp.o) \$(${canon}_RC_SRCS:.rc=.res)\n";
1771 print FILEO "\t\$(WINEBUILD) -fPIC \$(${canon}_LIBRARY_PATH) \$(WINE_LIBRARY_PATH) -sym \$(${canon}_SPEC_SRCS:.spec=.tmp.o) -o \$\@ -spec \$(${canon}_SPEC_SRCS)\n";
1773 my $t_name=@$target[$T_NAME];
1774 if (@$target[$T_TYPE]!=$TT_DLL) {
1777 print FILEO "$t_name: \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_OBJS) \$(${canon}_DEPENDS) \n";
1778 print FILEO "\t\$(LDSHARED) \$(LDDLLFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_LIBRARY_PATH) \$(${canon}_LIBRARIES:%=-l%) \$(DLL_LINK) \$(LIBS)\n";
1779 if (@$target[$T_TYPE] ne $TT_DLL) {
1780 print FILEO "\ttest -e @$target[$T_NAME] || \$(LN_S) \$(WINE) @$target[$T_NAME]\n";
1787 foreach $target (@{@$project[$P_TARGETS]}) {
1788 generate_spec_file(@$project[$P_PATH],$target,$project_settings);
1789 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1790 generate_wrapper_file(@$project[$P_PATH],$target);
1796 # Perform the replacements in the template configure files
1797 # Return 1 for success, 0 for failure
1798 sub generate_configure
1801 my $a_source_file=$_[1];
1803 if (!defined $templates{$filename}) {
1804 if ($filename ne "configure") {
1805 print STDERR "winemaker: internal error: No template called '$filename'\n";
1810 if (!open(FILEO,">$filename")) {
1811 print STDERR "error: unable to open \"$filename\" for writing:\n";
1812 print STDERR " $!\n";
1815 foreach $line (@{$templates{$filename}}) {
1816 if ($line =~ /^\#\#WINEMAKER_PROJECTS\#\#$/) {
1817 foreach $project (@projects) {
1818 print FILEO "@$project[$P_PATH]Makefile\n";
1821 $line =~ s+\#\#WINEMAKER_SOURCE\#\#+$a_source_file+;
1822 $line =~ s+\#\#WINEMAKER_NEEDS_MFC\#\#+$needs_mfc+;
1830 sub generate_generic
1834 if (!defined $templates{$filename}) {
1835 print STDERR "winemaker: internal error: No template called '$filename'\n";
1838 if (!open(FILEO,">$filename")) {
1839 print STDERR "error: unable to open \"$filename\" for writing:\n";
1840 print STDERR " $!\n";
1843 foreach $line (@{$templates{$filename}}) {
1850 # Generates the global files:
1854 sub generate_global_files
1856 generate_generic("Make.rules.in");
1858 # Get the name of a source file for configure.in
1860 search_a_file: foreach $project (@projects) {
1861 foreach $target (@{@$project[$P_TARGETS]}, @$project[$P_SETTINGS]) {
1862 $a_source_file=@{@$target[$T_SOURCES_C]}[0];
1863 if (!defined $a_source_file) {
1864 $a_source_file=@{@$target[$T_SOURCES_CXX]}[0];
1866 if (!defined $a_source_file) {
1867 $a_source_file=@{@$target[$T_SOURCES_RC]}[0];
1869 if (defined $a_source_file) {
1870 $a_source_file="@$project[$P_PATH]$a_source_file";
1876 generate_configure("configure.in",$a_source_file);
1877 unlink("configure");
1878 if (generate_configure("configure",$a_source_file) == 0) {
1881 # Add execute permission to configure for whoever has the right to read it
1882 my @st=stat("configure");
1885 $mode|=($mode & 0444) >>2;
1886 chmod($mode,"configure");
1888 print "warning: could not generate the configure script. You need to run autoconf\n";
1894 sub generate_read_templates
1899 if (/^--- ((\w\.?)+) ---$/) {
1901 if (defined $templates{$filename}) {
1902 print STDERR "winemaker: internal error: There is more than one template for $filename\n";
1906 $templates{$filename}=$file;
1908 } elsif (defined $file) {
1915 # This is where we finally generate files. In fact this method does not
1916 # do anything itself but calls the methods that do the actual work.
1919 print "Generating project files...\n";
1920 generate_read_templates();
1921 generate_global_files();
1923 foreach $project (@projects) {
1924 my $path=@$project[$P_PATH];
1931 generate_project_files($project);
1944 $opt_lower=$OPT_LOWER_UPPERCASE;
1945 $opt_lower_include=1;
1947 # $opt_single_target=<undefined>
1948 $opt_target_type=$TT_GUIEXE;
1950 $opt_is_interactive=$OPT_ASK_NO;
1951 $opt_ask_project_options=$OPT_ASK_NO;
1952 $opt_ask_target_options=$OPT_ASK_NO;
1953 $opt_no_generated_files=0;
1964 project_init(\@main_project,"");
1967 my $arg=shift @ARGV;
1969 if ($arg eq "--nobanner") {
1971 } elsif ($arg eq "--backup") {
1973 } elsif ($arg eq "--nobackup") {
1975 } elsif ($arg eq "--single-target") {
1976 $opt_single_target=shift @ARGV;
1977 } elsif ($arg eq "--lower-none") {
1978 $opt_lower=$OPT_LOWER_NONE;
1979 } elsif ($arg eq "--lower-all") {
1980 $opt_lower=$OPT_LOWER_ALL;
1981 } elsif ($arg eq "--lower-uppercase") {
1982 $opt_lower=$OPT_LOWER_UPPERCASE;
1983 } elsif ($arg eq "--lower-include") {
1984 $opt_lower_include=1;
1985 } elsif ($arg eq "--nolower-include") {
1986 $opt_lower_include=0;
1987 } elsif ($arg eq "--generated-files") {
1988 $opt_no_generated_files=0;
1989 } elsif ($arg eq "--nogenerated-files") {
1990 $opt_no_generated_files=1;
1992 } elsif ($arg =~ /^-D/) {
1993 push @{$global_settings[$T_DEFINES]},$arg;
1994 } elsif ($arg =~ /^-I/) {
1995 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
1996 } elsif ($arg =~ /^-L/) {
1997 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
1998 } elsif ($arg =~ /^-i/) {
1999 push @{$global_settings[$T_IMPORTS]},$';
2000 } elsif ($arg =~ /^-l/) {
2001 push @
{$global_settings[$T_LIBRARIES]},$';
2003 # 'Source
'-based method options
2004 } elsif ($arg eq "--dll") {
2005 $opt_target_type=$TT_DLL;
2006 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2007 $opt_target_type=$TT_GUIEXE;
2008 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2009 $opt_target_type=$TT_CUIEXE;
2010 } elsif ($arg eq "--interactive") {
2011 $opt_is_interactive=$OPT_ASK_YES;
2012 $opt_ask_project_options=$OPT_ASK_YES;
2013 $opt_ask_target_options=$OPT_ASK_YES;
2014 } elsif ($arg eq "--wrap") {
2015 print STDERR "warning: --wrap no longer supported, ignoring the option\n";
2016 #$opt_flags|=$TF_WRAP;
2017 } elsif ($arg eq "--nowrap") {
2018 $opt_flags&=~$TF_WRAP;
2019 } elsif ($arg eq "--mfc") {
2020 $opt_flags|=$TF_MFC;
2021 #$opt_flags|=$TF_MFC|$TF_WRAP;
2023 } elsif ($arg eq "--nomfc") {
2024 $opt_flags&=~($TF_MFC|$TF_WRAP);
2029 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2030 print STDERR "Unknown option: $arg\n";
2037 if ($opt_no_banner == 0 or defined $usage) {
2038 print "Winemaker $version\n";
2039 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2042 if (defined $usage) {
2043 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup]\n";
2044 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2045 print STDERR " [--lower-include|--nolower-include]\n";
2046 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2047 print STDERR " [--wrap|--nowrap] [--mfc|--nomfc]\n";
2048 print STDERR " [-Dmacro[=defn]] [-Idir] [-Ldir] [-idll] [-llibrary]\n";
2049 print STDERR " [--interactive] [--single-target name]\n";
2050 print STDERR " [--generated-files|--nogenerated-files]\n";
2054 # Fix the file and directory names
2055 fix_file_and_directory_names(".");
2057 # Scan the sources to identify the projects and targets
2060 # Create targets for wrappers, etc.
2061 postprocess_targets();
2063 # Fix the source files
2066 # Generate the Makefile and the spec file
2067 if (! $opt_no_generated_files) {
2073 --- configure.in ---
2074 dnl Process this file with autoconf to produce a configure script.
2075 dnl Author: Michael Patra <micky@marie.physik.tu-berlin.de>
2076 dnl <patra@itp1.physik.tu-berlin.de>
2077 dnl Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2079 AC_REVISION([configure.in 1.00])
2080 AC_INIT(##WINEMAKER_SOURCE##)
2082 NEEDS_MFC=##WINEMAKER_NEEDS_MFC##
2084 dnl **** Command-line arguments ****
2088 dnl **** Check for some programs ****
2097 AC_PATH_PROG(LDCONFIG, ldconfig, true, /sbin:/usr/sbin:$PATH)
2099 dnl **** Check for some libraries ****
2101 dnl Check for -lm for BeOS
2102 AC_CHECK_LIB(m,sqrt)
2103 dnl Check for -li386 for NetBSD and OpenBSD
2104 AC_CHECK_LIB(i386,i386_set_ldt)
2105 dnl Check for -lossaudio for NetBSD
2106 AC_CHECK_LIB(ossaudio,_oss_ioctl)
2107 dnl Check for -lw for Solaris
2108 AC_CHECK_LIB(w,iswalnum)
2109 dnl Check for -lnsl for Solaris
2110 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))
2111 dnl Check for -lsocket for Solaris
2112 AC_CHECK_FUNCS(connect,,AC_CHECK_LIB(socket,connect))
2113 dnl Check for -lxpg4 for FreeBSD
2114 AC_CHECK_LIB(xpg4,setrunelocale)
2115 dnl Check for -lmmap for OS/2
2116 AC_CHECK_LIB(mmap,mmap)
2117 dnl Check for openpty
2118 AC_CHECK_FUNCS(openpty,,
2119 AC_CHECK_LIB(util,openpty,
2120 AC_DEFINE(HAVE_OPENPTY)
2124 AC_CHECK_HEADERS(dlfcn.h,
2125 AC_CHECK_FUNCS(dlopen,
2126 AC_DEFINE(HAVE_DL_API),
2127 AC_CHECK_LIB(dl,dlopen,
2128 AC_DEFINE(HAVE_DL_API)
2134 dnl **** Check which curses lib to use ***
2135 if test "$CURSES" = "yes"
2137 AC_CHECK_HEADERS(ncurses.h)
2138 if test "$ac_cv_header_ncurses_h" = "yes"
2140 AC_CHECK_LIB(ncurses,waddch)
2142 if test "$ac_cv_lib_ncurses_waddch" = "yes"
2144 AC_CHECK_LIB(ncurses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2145 AC_CHECK_LIB(ncurses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2147 AC_CHECK_HEADERS(curses.h)
2148 if test "$ac_cv_header_curses_h" = "yes"
2150 AC_CHECK_LIB(curses,waddch)
2151 if test "$ac_cv_lib_curses_waddch" = "yes"
2153 AC_CHECK_LIB(curses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2154 AC_CHECK_LIB(curses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2160 dnl **** If ln -s doesn't work
, use cp instead
****
2161 if test
"$ac_cv_prog_LN_S" = "ln -s"; then
: ; else LN_S
=cp
; fi
2163 dnl
**** Check
for gcc strength
-reduce bug
****
2165 if test
"x${GCC}" = "xyes"
2167 AC_CACHE_CHECK
( "for gcc strength-reduce bug", ac_cv_c_gcc_strength_bug
,
2170 static
int Array
[[3]];
2173 for(i
=0; i
<B
; i
++) Array
[[i
]] = i
- 3;
2174 exit( Array
[[1]] != -2 );
2176 ac_cv_c_gcc_strength_bug
="no",
2177 ac_cv_c_gcc_strength_bug
="yes",
2178 ac_cv_c_gcc_strength_bug
="yes") )
2179 if test
"$ac_cv_c_gcc_strength_bug" = "yes"
2181 CFLAGS
="$CFLAGS -fno-strength-reduce"
2185 dnl
**** Check
for underscore on external symbols
****
2187 AC_CACHE_CHECK
("whether external symbols need an underscore prefix",
2188 ac_cv_c_extern_prefix
,
2190 LIBS
="conftest_asm.s $LIBS"
2191 cat
> conftest_asm
.s
<<EOF
2196 AC_TRY_LINK
([extern
int ac_test
;],[if (ac_test
) return 1],
2197 ac_cv_c_extern_prefix
="yes",ac_cv_c_extern_prefix
="no")
2199 if test
"$ac_cv_c_extern_prefix" = "yes"
2201 AC_DEFINE
(NEED_UNDERSCORE_PREFIX
)
2204 dnl
**** Check
for working dll
****
2208 AC_CACHE_CHECK
("whether we can build a Linux dll",
2210 [saved_cflags
=$CFLAGS
2211 CFLAGS
="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0,-Bsymbolic"
2212 AC_TRY_LINK
(,[return 1],ac_cv_c_dll_linux
="yes",ac_cv_c_dll_linux
="no")
2213 CFLAGS
=$saved_cflags
2215 if test
"$ac_cv_c_dll_linux" = "yes"
2217 LDSHARED
="\$(CC) -shared -Wl,-rpath,\$(libdir)"
2218 LDDLLFLAGS
="-Wl,-Bsymbolic"
2220 AC_CACHE_CHECK
(whether we can build a UnixWare
(Solaris
) dll
,
2221 ac_cv_c_dll_unixware
,
2222 [saved_cflags
=$CFLAGS
2223 CFLAGS
="$CFLAGS -fPIC -Wl,-G,-h,conftest.so.1.0,-B,symbolic"
2224 AC_TRY_LINK
(,[return 1],ac_cv_c_dll_unixware
="yes",ac_cv_c_dll_unixware
="no")
2225 CFLAGS
=$saved_cflags
2227 if test
"$ac_cv_c_dll_unixware" = "yes"
2229 LDSHARED
="\$(CC) -Wl,-G \$(SONAME:%=-Wl,h,\$(libdir)/%)"#FIXME: why SONAME here?
2230 LDDLLFLAGS
="-Wl,-B,symbolic"
2232 AC_CACHE_CHECK
("whether we can build a NetBSD dll",
2234 [saved_cflags
=$CFLAGS
2235 CFLAGS
="$CFLAGS -fPIC -Wl,-Bshareable,-Bforcearchive"
2236 AC_TRY_LINK
(,[return 1],ac_cv_c_dll_netbsd
="yes",ac_cv_c_dll_netbsd
="no")
2237 CFLAGS
=$saved_cflags
2239 if test
"$ac_cv_c_dll_netbsd" = "yes"
2241 LDSHARED
="\$(CC) -Wl,-Bshareable,-Bforcearchive"
2242 LDDLLFLAGS
="" #FIXME
2246 if test
"$ac_cv_c_dll_linux" = "no" -a
"$ac_cv_c_dll_unixware" = "no" -a
"$ac_cv_c_dll_netbsd" = "no"
2248 AC_MSG_ERROR
([Could
not find how to build a dynamically linked library
])
2251 CFLAGS
="$CFLAGS -fPIC"
2252 DLL_LINK
="\$(WINE_LIBRARY_PATH) \$(LIBRARY_PATH) \$(LIBRARIES:%=-l%) -lwine -lwine_unicode"
2256 AC_SUBST
(LDDLLFLAGS
)
2258 dnl
*** check
for the need to define __i386__
2260 AC_CACHE_CHECK
("whether we need to define __i386__",ac_cv_cpp_def_i386
,
2261 AC_EGREP_CPP
(yes
,[#if (defined(i386) || defined(__i386)) && !defined(__i386__)
2264 ac_cv_cpp_def_i386
="yes", ac_cv_cpp_def_i386
="no"))
2265 if test
"$ac_cv_cpp_def_i386" = "yes"
2267 CFLAGS
="$CFLAGS -D__i386__"
2270 dnl
$GCC is set by autoconf
2272 if test
"$GCC" = "yes"
2274 GCC_NO_BUILTIN
="-fno-builtin"
2276 AC_SUBST
(GCC_NO_BUILTIN
)
2278 dnl
**** Test Winelib
-related features of the C
++ compiler
2280 if test
"x${GCC}" = "xyes"
2282 OLDCXXFLAGS
="$CXXFLAGS";
2283 CXXFLAGS
="-fpermissive";
2284 AC_CACHE_CHECK
("for g++ -fpermissive option", has_gxx_permissive
,
2286 for (int i
=0;i
<2;i
++);
2289 [has_gxx_permissive
="yes"],
2290 [has_gxx_permissive
="no"])
2292 CXXFLAGS
="-fno-for-scope";
2293 AC_CACHE_CHECK
("for g++ -fno-for-scope option", has_gxx_no_for_scope
,
2295 for (int i
=0;i
<2;i
++);
2298 [has_gxx_no_for_scope
="yes"],
2299 [has_gxx_no_for_scope
="no"])
2301 CXXFLAGS
="$OLDCXXFLAGS";
2302 if test
"$has_gxx_permissive" = "yes"
2304 CXXFLAGS
="$CXXFLAGS -fpermissive"
2306 if test
"$has_gxx_no_for_scope" = "yes"
2308 CXXFLAGS
="$CXXFLAGS -fno-for-scope"
2313 dnl
**** Test Winelib
-related features of the C compiler
2316 dnl
**** Macros
for finding a headers
/libraries
in a collection of places
2318 dnl AC_PATH_HEADER
(variable
,header
,action
-if-not-found
,default-locations
)
2319 dnl Note that the above may set variable to an empty value
if the header is
2320 dnl already
in the include path
2321 AC_DEFUN
(AC_PATH_HEADER
,[
2322 AC_MSG_CHECKING
([for $2])
2323 AC_CACHE_VAL
(ac_cv_path_
$1,
2326 ac_dummy
="ifelse([$4], , :/usr/local/include, [$4])"
2327 save_CPPFLAGS
="$CPPFLAGS"
2328 IFS
="${IFS= }"; ac_save_ifs
="$IFS"; IFS
=":"
2329 for ac_dir
in $ac_dummy; do
2331 if test
-z
"$ac_dir"
2333 CPPFLAGS
="$save_CPPFLAGS"
2335 CPPFLAGS
="-I$ac_dir $save_CPPFLAGS"
2337 AC_TRY_COMPILE
([#include <$2>],,ac_found=1;ac_cv_path_$1="$ac_dir";break)
2339 CPPFLAGS
="$save_CPPFLAGS"
2340 ifelse
([$3],,,[if test
-z
"$ac_found"
2347 if test
-n
"$ac_found" -o
-n
"[$]$1"
2349 AC_MSG_RESULT
([$]$1)
2356 dnl AC_PATH_LIBRARY
(variable
,libraries
,extra libs
,action
-if-not-found
,default-locations
)
2357 AC_DEFUN
(AC_PATH_LIBRARY
,[
2358 AC_MSG_CHECKING
([for $2])
2359 AC_CACHE_VAL
(ac_cv_path_
$1,
2362 ac_dummy
="ifelse([$5], , :/usr/local/lib, [$5])"
2364 IFS
="${IFS= }"; ac_save_ifs
="$IFS"; IFS
=":"
2365 for ac_dir
in $ac_dummy; do
2367 if test
-z
"$ac_dir"
2369 LIBS
="$2 $3 $save_LIBS"
2371 LIBS
="-L$ac_dir $2 $3 $save_LIBS"
2373 AC_TRY_LINK
(,,ac_found
=1;ac_cv_path_
$1="$ac_dir";break)
2376 ifelse
([$4],,,[if test
-z
"$ac_found"
2383 if test
-n
"$ac_found" -o
-n
"[$]$1"
2385 AC_MSG_RESULT
([$]$1)
2392 dnl
**** Try to find where winelib is located
****
2394 WINE_INCLUDE_ROOT
="";
2395 WINE_INCLUDE_PATH
="";
2396 WINE_LIBRARY_ROOT
="";
2397 WINE_LIBRARY_PATH
="";
2404 [ --with
-wine
=DIR the Wine
package (or sources
) is
in DIR
],
2405 [if test
"$withval" != "no"; then
2406 WINE_ROOT
="$withval";
2413 if test
-n
"$WINE_ROOT"
2415 WINE_INCLUDE_ROOT
="$WINE_ROOT/include";
2416 WINE_LIBRARY_ROOT
="$WINE_ROOT";
2417 WINE_TOOL_PATH
="$WINE_ROOT:$WINE_ROOT/bin:$WINE_ROOT/tools/wrc:$WINE_ROOT/tools/winebuild:$PATH";
2420 AC_ARG_WITH
(wine
-includes
,
2421 [ --with
-wine
-includes
=DIR the Wine includes are
in DIR
],
2422 [if test
"$withval" != "no"; then
2423 WINE_INCLUDES
="$withval";
2427 if test
-n
"$WINE_INCLUDES"
2429 WINE_INCLUDE_ROOT
="$WINE_INCLUDES";
2432 AC_ARG_WITH
(wine
-libraries
,
2433 [ --with
-wine
-libraries
=DIR the Wine libraries are
in DIR
],
2434 [if test
"$withval" != "no"; then
2435 WINE_LIBRARIES
="$withval";
2439 if test
-n
"$WINE_LIBRARIES"
2441 WINE_LIBRARY_ROOT
="$WINE_LIBRARIES";
2444 AC_ARG_WITH
(wine
-tools
,
2445 [ --with
-wine
-tools
=DIR the Wine tools are
in DIR
],
2446 [if test
"$withval" != "no"; then
2447 WINE_TOOLS
="$withval";
2451 if test
-n
"$WINE_TOOLS"
2453 WINE_TOOL_PATH
="$WINE_TOOLS:$WINE_TOOLS/wrc:$WINE_TOOLS/winebuild";
2456 if test
-z
"$WINE_INCLUDE_ROOT"
2458 WINE_INCLUDE_ROOT
=":/usr/include/wine:/usr/local/include/wine:/opt/wine/include";
2460 AC_PATH_HEADER
(WINE_INCLUDE_ROOT
,windef
.h
,[
2461 AC_MSG_ERROR
([Could
not find the Wine includes
])
2462 ],$WINE_INCLUDE_ROOT)
2463 if test
-n
"$WINE_INCLUDE_ROOT"
2465 WINE_INCLUDE_PATH
="-I$WINE_INCLUDE_ROOT"
2467 WINE_INCLUDE_PATH
=""
2470 if test
-z
"$WINE_LIBRARY_ROOT"
2472 WINE_LIBRARY_ROOT
=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib";
2474 WINE_LIBRARY_ROOT
="$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/lib";
2476 AC_PATH_LIBRARY
(WINE_LIBRARY_ROOT
,[-lwine
],[-lutil
],[
2477 AC_MSG_ERROR
([Could
not find the Wine libraries
(libwine
.so
)])
2478 ],$WINE_LIBRARY_ROOT)
2479 if test
-n
"$WINE_LIBRARY_ROOT"
2481 WINE_LIBRARY_PATH
="-L$WINE_LIBRARY_ROOT"
2483 WINE_LIBRARY_PATH
=""
2485 AC_PATH_LIBRARY
(LIBNTDLL_PATH
,[-lntdll
],[$WINE_LIBRARY_PATH -lwine
-lwine_unicode
-lncurses
-ldl
-lutil
],[
2486 AC_MSG_ERROR
([Could
not find the Wine libraries
(libntdll
.so
)])
2487 ],[$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/dlls
])
2488 if test
-n
"$LIBNTDLL_PATH" -a
"-L$LIBNTDLL_PATH" != "$WINE_LIBRARY_PATH"
2490 WINE_LIBRARY_PATH
="$WINE_LIBRARY_PATH -L$LIBNTDLL_PATH"
2493 if test
-z
"$WINE_TOOL_PATH"
2495 WINE_TOOL_PATH
="$PATH:/usr/local/bin:/opt/wine/bin";
2497 AC_PATH_PROG
(WINE
,wine
,,$WINE_TOOL_PATH)
2500 AC_MSG_ERROR
([Could
not find Wine
's wine tool])
2502 AC_PATH_PROG(WINEBUILD,winebuild,,$WINE_TOOL_PATH)
2503 if test -z "$WINEBUILD"
2505 AC_MSG_ERROR([Could not find Wine's winebuild tool
])
2507 AC_PATH_PROG
(WRC
,wrc
,,$WINE_TOOL_PATH)
2510 AC_MSG_ERROR
([Could
not find Wine
's wrc tool])
2513 AC_SUBST(WINE_INCLUDE_PATH)
2514 AC_SUBST(WINE_LIBRARY_PATH)
2516 dnl **** Try to find where the MFC are located ****
2519 if test "x$NEEDS_MFC" = "x1"
2521 ATL_INCLUDE_ROOT="";
2522 ATL_INCLUDE_PATH="";
2523 MFC_INCLUDE_ROOT="";
2524 MFC_INCLUDE_PATH="";
2525 MFC_LIBRARY_ROOT="";
2526 MFC_LIBRARY_PATH="";
2529 [ --with-mfc=DIR the MFC package (or sources) is in DIR],
2530 [if test "$withval" != "no"; then
2531 MFC_ROOT="$withval";
2538 if test -n "$MFC_ROOT"
2540 ATL_INCLUDE_ROOT="$MFC_ROOT";
2541 MFC_INCLUDE_ROOT="$MFC_ROOT";
2542 MFC_LIBRARY_ROOT="$MFC_ROOT";
2545 AC_ARG_WITH(atl-includes,
2546 [ --with-atl-includes=DIR the ATL includes are in DIR],
2547 [if test "$withval" != "no"; then
2548 ATL_INCLUDES="$withval";
2552 if test -n "$ATL_INCLUDES"
2554 ATL_INCLUDE_ROOT="$ATL_INCLUDES";
2557 AC_ARG_WITH(mfc-includes,
2558 [ --with-mfc-includes=DIR the MFC includes are in DIR],
2559 [if test "$withval" != "no"; then
2560 MFC_INCLUDES="$withval";
2564 if test -n "$MFC_INCLUDES"
2566 MFC_INCLUDE_ROOT="$MFC_INCLUDES";
2569 AC_ARG_WITH(mfc-libraries,
2570 [ --with-mfc-libraries=DIR the MFC libraries are in DIR],
2571 [if test "$withval" != "no"; then
2572 MFC_LIBRARIES="$withval";
2576 if test -n "$MFC_LIBRARIES"
2578 MFC_LIBRARY_ROOT="$MFC_LIBRARIES";
2581 OLDCPPFLAGS="$CPPFLAGS"
2582 dnl FIXME: We should not have defines in any of the include paths
2583 CPPFLAGS="$WINE_INCLUDE_PATH -I$WINE_INCLUDE_ROOT/mixedcrt -D_DLL -D_MT $CPPFLAGS"
2584 ATL_INCLUDE_PATH="-I\$(WINE_INCLUDE_ROOT)/mixedcrt -D_DLL -D_MT"
2585 if test -z "$ATL_INCLUDE_ROOT"
2587 ATL_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/atl:/usr/include/atl:/usr/local/include/atl:/opt/mfc/include/atl:/opt/atl/include"
2589 ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT:$ATL_INCLUDE_ROOT/atl:$ATL_INCLUDE_ROOT/atl/include"
2591 AC_PATH_HEADER(ATL_INCLUDE_ROOT,atldef.h,[
2592 AC_MSG_ERROR([Could not find the ATL includes])
2593 ],$ATL_INCLUDE_ROOT)
2594 if test -n "$ATL_INCLUDE_ROOT"
2596 ATL_INCLUDE_PATH="$ATL_INCLUDE_PATH -I$ATL_INCLUDE_ROOT"
2599 MFC_INCLUDE_PATH="$ATL_INCLUDE_PATH"
2600 if test -z "$MFC_INCLUDE_ROOT"
2602 MFC_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/mfc:/usr/include/mfc:/usr/local/include/mfc:/opt/mfc/include/mfc:/opt/mfc/include"
2604 MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT:$MFC_INCLUDE_ROOT/mfc:$MFC_INCLUDE_ROOT/mfc/include"
2606 AC_PATH_HEADER(MFC_INCLUDE_ROOT,afx.h,[
2607 AC_MSG_ERROR([Could not find the MFC includes])
2608 ],$MFC_INCLUDE_ROOT)
2609 if test -n "$MFC_INCLUDE_ROOT" -a "$ATL_INCLUDE_ROOT" != "$MFC_INCLUDE_ROOT"
2611 MFC_INCLUDE_PATH="$MFC_INCLUDE_PATH -I$MFC_INCLUDE_ROOT"
2613 CPPFLAGS="$OLDCPPFLAGS"
2615 if test -z "$MFC_LIBRARY_ROOT"
2617 MFC_LIBRARY_ROOT=":$WINE_LIBRARY_ROOT:/usr/lib/mfc:/usr/local/lib:/usr/local/lib/mfc:/opt/mfc/lib";
2619 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT:$MFC_LIBRARY_ROOT/lib:$MFC_LIBRARY_ROOT/mfc/src";
2621 AC_PATH_LIBRARY(MFC_LIBRARY_ROOT,[-lmfc],[$WINE_LIBRARY_PATH -lwine -lwine_unicode],[
2622 AC_MSG_ERROR([Could not find the MFC library])
2623 ],$MFC_LIBRARY_ROOT)
2624 if test -n "$MFC_LIBRARY_ROOT" -a "$MFC_LIBRARY_ROOT" != "$WINE_LIBRARY_ROOT"
2626 MFC_LIBRARY_PATH="-L$MFC_LIBRARY_ROOT"
2631 AC_SUBST(ATL_INCLUDE_PATH)
2632 AC_SUBST(MFC_INCLUDE_PATH)
2633 AC_SUBST(MFC_LIBRARY_PATH)
2638 dnl **** Generate output files ****
2640 MAKE_RULES=Make.rules
2641 AC_SUBST_FILE(MAKE_RULES)
2645 ##WINEMAKER_PROJECTS##
2649 echo "Configure finished. Do 'make
' to build the project."
2652 dnl Local Variables:
2653 dnl comment-start: "dnl "
2655 dnl comment-start-skip: "\\bdnl\\b\\s *"
2656 dnl compile-command: "autoconf"
2658 --- Make.rules.in ---
2659 # Copyright 2000 Francois Gouget for CodeWeavers
2660 # fgouget@codeweavers.com
2662 # Global rules shared by all makefiles -*-Makefile-*-
2664 # Each individual makefile must define the following variables:
2665 # WINE_INCLUDE_ROOT: Wine's headers location
2666 # WINE_LIBRARY_ROOT: Wine's libraries location
2667 # TOPOBJDIR : top-level object directory
2668 # SRCDIR : source directory for this module
2670 # Each individual makefile may define the following additional variables:
2672 # SUBDIRS : subdirectories that contain a Makefile
2673 # DLLS : WineLib libraries to be built
2674 # EXES : WineLib executables to be built
2676 # CEXTRA : extra c flags (e.g. '-Wall')
2677 # CXXEXTRA : extra c++ flags (e.g. '-Wall')
2678 # WRCEXTRA : extra wrc flags (e.g. '-p _SysRes')
2679 # DEFINES : defines (e.g. -DSTRICT)
2680 # INCLUDE_PATH : additional include path
2681 # LIBRARY_PATH : additional library path
2682 # LIBRARIES : additional Unix libraries to link with
2684 # C_SRCS : C sources for the module
2685 # CXX_SRCS : C++ sources for the module
2686 # RC_SRCS : resource source files
2687 # SPEC_SRCS : interface definition files
2692 WINE_INCLUDE_ROOT
= @WINE_INCLUDE_ROOT@
2693 WINE_INCLUDE_PATH
= @WINE_INCLUDE_PATH@
2694 WINE_LIBRARY_ROOT
= @WINE_LIBRARY_ROOT@
2695 WINE_LIBRARY_PATH
= @WINE_LIBRARY_PATH@
2699 ATL_INCLUDE_ROOT
= @ATL_INCLUDE_ROOT@
2700 ATL_INCLUDE_PATH
= @ATL_INCLUDE_PATH@
2701 MFC_INCLUDE_ROOT
= @MFC_INCLUDE_ROOT@
2702 MFC_INCLUDE_PATH
= @MFC_INCLUDE_PATH@
2703 MFC_LIBRARY_ROOT
= @MFC_LIBRARY_ROOT@
2704 MFC_LIBRARY_PATH
= @MFC_LIBRARY_PATH@
2706 # First some useful definitions
2713 CXXFLAGS
= @CXXFLAGS@
2715 OPTIONS
= @OPTIONS@
-D_REENTRANT
-DWINELIB
2716 X_CFLAGS
= @X_CFLAGS@
2718 XLIB
= @X_PRE_LIBS@
@XLIB@
@X_EXTRA_LIBS@
2719 DLL_LINK
= @DLL_LINK@
2720 LIBS
= @LIBS@
$(LIBRARY_PATH
)
2725 ALLFLAGS
= $(DEFINES
) -I
$(SRCDIR
) $(WINE_INCLUDE_PATH
) $(INCLUDE_PATH
)
2726 ALLCFLAGS
= $(CFLAGS
) $(CEXTRA
) $(OPTIONS
) $(X_CFLAGS
) $(ALLFLAGS
)
2727 ALLCXXFLAGS
=$(CXXFLAGS
) $(CXXEXTRA
) $(OPTIONS
) $(X_CFLAGS
) $(ALLFLAGS
)
2728 ALLWRCFLAGS
=$(WRCFLAGS
) $(WRCEXTRA
) $(OPTIONS
) $(ALLFLAGS
)
2730 LDSHARED
= @LDSHARED@
2731 LDDLLFLAGS
= @LDDLLFLAGS@
2733 STRIPFLAGS
= --strip
-unneeded
2738 WINEBUILD
= @WINEBUILD@
2741 # Installation infos
2744 INSTALL_PROGRAM
= @INSTALL_PROGRAM@
2745 INSTALL_DATA
= @INSTALL_DATA@
2747 exec_prefix
= @exec_prefix@
2755 OBJS
= $(C_SRCS
:.c
=.o
) $(CXX_SRCS
:.cpp
=.o
) \
2756 $(SPEC_SRCS
:.spec
=.spec
.o
)
2757 CLEAN_FILES
= *.spec
.c y
.tab
.c y
.tab
.h lex
.yy
.c \
2759 \\\#
*\\\#
*~ *% .\\\#
*
2763 .SUFFIXES
: .cpp
.rc
.res
.tmp
.o
.spec
.spec
.c
.spec
.o
2766 $(CC
) -c
$(ALLCFLAGS
) -o
$@
$<
2769 $(CXX
) -c
$(ALLCXXFLAGS
) -o
$@
$<
2772 $(CXX
) -c
$(ALLCXXFLAGS
) -o
$@
$<
2775 $(WRC
) $(ALLWRCFLAGS
) -o
$@
$<
2777 .PHONY
: all install uninstall clean distclean depend dummy
2779 # 'all' target first in case the enclosing Makefile didn't define any target
2783 # Rules for makefile
2785 Makefile
: Makefile
.in $(TOPSRCDIR
)/configure
2786 @echo Makefile is older than
$?
, please rerun
$(TOPSRCDIR
)/configure
2789 # Rules for cleaning
2791 $(SUBDIRS
:%=%/__clean__
): dummy
2792 cd
`dirname $@` && $(MAKE
) clean
2794 $(EXTRASUBDIRS
:%=%/__clean__
): dummy
2795 -cd
`dirname $@` && $(RM
) $(CLEAN_FILES
)
2797 clean
:: $(SUBDIRS
:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__
)
2798 $(RM
) $(CLEAN_FILES
) $(RC_SRCS
:.rc
=.res
) $(OBJS
) $(SPEC_SRCS
:.spec
=.tmp
.o
) $(EXES
) $(EXES
:%=%.so
) $(DLLS
)
2800 # Rules for installing
2802 $(SUBDIRS
:%=%/__install__
): dummy
2803 cd
`dirname $@` && $(MAKE
) install
2805 $(SUBDIRS
:%=%/__uninstall__
): dummy
2806 cd
`dirname $@` && $(MAKE
) uninstall
2815 # End of global rules
2818 * Copyright
2000 Francois Gouget
<fgouget
@codeweavers.com
> for CodeWeavers
2822 #include <windows.h>
2827 * Describe the wrapped application
2831 * This is either CUIEXE
for a console based application
or
2832 * GUIEXE
for a regular windows application
.
2834 #define APP_TYPE ##WINEMAKER_APP_TYPE##
2837 * This is the application library
's base name, i.e. 'hello
' if the
2838 * library is called 'libhello
.so
'.
2840 static char* appName = ##WINEMAKER_APP_NAME##;
2843 * This is the name of the application's Windows module
. If left NULL
2844 * then appName is used
.
2846 static char
* appModule
= NULL
;
2849 * This is the application
's entry point. This is usually "WinMain" for a
2850 * GUIEXE and 'main
' for a CUIEXE application.
2852 static char* appInit = ##WINEMAKER_APP_INIT##;
2855 * This is either non-NULL for MFC-based applications and is the name of the
2856 * MFC's module
. This is the module
in which we will take the
'WinMain'
2859 static char
* mfcModule
= ##WINEMAKER_APP_MFC##;
2864 * Implement the main
.
2867 #if APP_TYPE == GUIEXE
2868 typedef
int WINAPI
(*WinMainFunc
)(HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
2869 PSTR szCmdLine
, int iCmdShow
);
2871 typedef
int WINAPI
(*MainFunc
)(int argc
, char
** argv
, char
** envp
);
2874 #if APP_TYPE == GUIEXE
2875 int WINAPI WinMain
(HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
2876 PSTR szCmdLine
, int iCmdShow
)
2878 int WINAPI Main
(int argc
, char
** argv
, char
** envp
)
2882 HINSTANCE hApp
,hMFC
,hMain
;
2887 /* Load the application's library */
2888 libName
=(char
*)malloc
(strlen
(appName
)+5+3+1);
2889 /* FIXME
: we should get the wrapper
's path and use that as the base for
2892 sprintf(libName,"./lib%s.so",appName);
2893 appLibrary=dlopen(libName,RTLD_NOW);
2894 if (appLibrary==NULL) {
2895 sprintf(libName,"lib%s.so",appName);
2896 appLibrary=dlopen(libName,RTLD_NOW);
2898 if (appLibrary==NULL) {
2899 char format[]="Could not load the %s library:\r\n%s";
2904 msg=(char*)malloc(strlen(format)+strlen(libName)+strlen(error));
2905 sprintf(msg,format,libName,error);
2906 MessageBox(NULL,msg,"dlopen error",MB_OK);
2911 /* Then if this application is MFC based, load the MFC module */
2912 /* FIXME: I'm
not sure this is really necessary
*/
2913 if (mfcModule
!=NULL
) {
2914 hMFC
=LoadLibrary
(mfcModule
);
2916 char format
[]="Could not load the MFC module %s (%d)";
2919 msg
=(char
*)malloc
(strlen
(format
)+strlen
(mfcModule
)+11);
2920 sprintf(msg
,format
,mfcModule
,GetLastError
());
2921 MessageBox
(NULL
,msg
,"LoadLibrary error",MB_OK
);
2925 /* MFC is a special case
: the WinMain is
in the MFC library
,
2926 * instead of the application
's library.
2933 /* Load the application's module
*/
2934 if (appModule
==NULL
) {
2937 hApp
=LoadLibrary
(appModule
);
2939 char format
[]="Could not load the application's module %s (%d)";
2942 msg
=(char
*)malloc
(strlen
(format
)+strlen
(appModule
)+11);
2943 sprintf(msg
,format
,appModule
,GetLastError
());
2944 MessageBox
(NULL
,msg
,"LoadLibrary error",MB_OK
);
2947 } else if (hMain
==NULL
) {
2951 /* Get the address of the application's entry point */
2952 appMain
=(WinMainFunc
*)GetProcAddress
(hMain
, appInit
);
2953 if (appMain
==NULL
) {
2954 char format
[]="Could not get the address of %s (%d)";
2957 msg
=(char
*)malloc
(strlen
(format
)+strlen
(appInit
)+11);
2958 sprintf(msg
,format
,appInit
,GetLastError
());
2959 MessageBox
(NULL
,msg
,"GetProcAddress error",MB_OK
);
2964 /* And finally invoke the application's entry point */
2965 #if APP_TYPE == GUIEXE
2966 retcode
=(*((WinMainFunc
)appMain
))(hApp
,hPrevInstance
,szCmdLine
,iCmdShow
);
2968 retcode
=(*((MainFunc
)appMain
))(argc
,argv
,envp
);
2971 /* Cleanup and done */
2976 dlclose
(appLibrary
);