Fixed a problem where the string in a combo box flickers if you
[wine/multimedia.git] / tools / winemaker
blobaaffe0fd7bdd9fb7419d81f7f8c898992afd1c6e
1 #!/usr/bin/perl -w
3 # Copyright 2000 Francois Gouget for CodeWeavers
4 # fgouget@codeweavers.com
6 my $version="0.5.3";
8 use Cwd;
9 use File::Basename;
10 use File::Copy;
14 #####
16 # Options
18 #####
20 # The following constants define what we do with the case of filenames
23 # Never rename a file to lowercase
24 my $OPT_LOWER_NONE=0;
27 # Rename all files to lowercase
28 my $OPT_LOWER_ALL=1;
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)
39 my $OPT_ASK_NO=0;
42 # Yes (always)
43 my $OPT_ASK_YES=1;
46 # Skip the questions till the end of this scope
47 my $OPT_ASK_SKIP=-1;
50 # General options
53 # Make a backup of the files
54 my $opt_backup;
57 # Defines which files to rename
58 my $opt_lower;
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.
79 my $opt_target_type;
82 # Contains the default set of flags to be used when creating a new target.
83 my $opt_flags;
86 # If true then winemaker should ask questions to the user as it goes
87 # along.
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.
99 my $opt_no_banner;
103 #####
105 # Target modelization
107 #####
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.
114 my $T_NAME=0;
117 # Defines the type of target we want to build. See the TT_xxx
118 # constants below
119 my $T_TYPE=1;
122 # Defines the target's enty point, i.e. the function that is called
123 # on startup.
124 my $T_INIT=2;
127 # This is a bitfield containing flags refining the way the target
128 # should be handled. See the TF_xxx constants below
129 my $T_FLAGS=3;
132 # This is a reference to an array containing the list of the
133 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
134 my $T_SOURCES_C=4;
135 my $T_SOURCES_CXX=5;
136 my $T_SOURCES_RC=6;
137 my $T_SOURCES_MISC=7;
140 # This is a reference to an array containing the list of macro
141 # definitions
142 my $T_DEFINES=8;
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
155 my $T_IMPORTS=11;
158 # The list of Unix libraries to link with
159 my $T_LIBRARIES=12;
162 # The list of dependencies between targets
163 my $T_DEPENDS=13;
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.
173 my $TT_SETTINGS=0;
176 # For executables in the windows subsystem
177 my $TT_GUIEXE=1;
180 # For executables in the console subsystem
181 my $TT_CUIEXE=2;
184 # For dynamically linked libraries
185 my $TT_DLL=3;
188 # The following constants further refine how the target should be handled
191 # This target needs a wrapper
192 my $TF_WRAP=1;
195 # This target is a wrapper
196 my $TF_WRAPPER=2;
199 # This target is an MFC-based target
200 my $TF_MFC=4;
203 # Initialize a target:
204 # - set the target type to TT_SETTINGS, i.e. no real target will
205 # be generated.
206 sub target_init
208 my $target=$_[0];
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]=[];
225 sub get_default_init
227 my $type=$_[0];
228 if ($type == $TT_GUIEXE) {
229 return "WinMain";
230 } elsif ($type == $TT_CUIEXE) {
231 return "main";
232 } elsif ($type == $TT_DLL) {
233 return "DllMain";
239 #####
241 # Project modelization
243 #####
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.
252 my $P_PATH=0;
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.
258 my $P_SETTINGS=1;
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.
265 my $P_TARGETS=2;
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)
272 sub project_init
274 my $project=$_[0];
275 my $path=$_[1];
277 my $project_settings=[];
278 target_init($project_settings);
280 @$project[$P_PATH]=$path;
281 @$project[$P_SETTINGS]=$project_settings;
282 @$project[$P_TARGETS]=[];
287 #####
289 # Global variables
291 #####
293 my $usage;
294 my %warnings;
296 my %templates;
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
301 # Makefiles.
302 my @projects=();
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.
308 my @main_project;
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
314 # sources fields.
315 my @global_settings;
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
320 my $needs_mfc=0;
324 #####
326 # Utility functions
328 #####
331 # Cleans up a name to make it an acceptable Makefile
332 # variable name.
333 sub canonize
335 my $name=$_[0];
337 $name =~ tr/a-zA-Z0-9_/_/c;
338 return $name;
342 # Returns true is the specified pathname is absolute.
343 # Note: pathnames that start with a variable '$' or
344 # '~' are considered absolute.
345 sub is_absolute
347 my $path=$_[0];
349 return ($path =~ /^[\/~\$]/);
353 # Performs a binary search looking for the specified item
354 sub bsearch
356 my $array=$_[0];
357 my $item=$_[1];
358 my $last=@{$array}-1;
359 my $first=0;
361 while ($first<=$last) {
362 my $index=int(($first+$last)/2);
363 my $cmp=@$array[$index] cmp $item;
364 if ($cmp<0) {
365 $first=$index+1;
366 } elsif ($cmp>0) {
367 $last=$index-1;
368 } else {
369 return $index;
376 #####
378 # 'Source'-based Project analysis
380 #####
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
388 my $target=$_[0];
389 my $options=$_[1];
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);
418 } else {
419 print STDERR "error: unknown option \"$option\"\n";
420 return 0;
423 return 1;
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
438 my $path=$_[1];
439 # the name of this directory, including a trailing '/', or an empty
440 # string if this is the top level directory
441 my $dirname=$_[2];
443 # reference to the project for this directory. May not be used
444 my $project;
445 # list of targets found in the 'current' directory
446 my %targets;
447 # list of sources found in the current directory
448 my @sources_c=();
449 my @sources_cxx=();
450 my @sources_rc=();
451 my @sources_misc=();
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.
457 my @dsp_files=();
458 my @mak_files=();
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
463 # already exists
464 $project=$parent_project;
465 } else {
466 $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 =~ /^\./) {
476 next;
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";
494 } else {
495 # Recursively scan this directory. Any source file that cannot be
496 # attributed to a project in one of the subdirectories will be attributed
497 # to this project.
498 source_scan_directory($project,"$fullentry/","$dentry/");
500 } elsif (-f "$fullentry") {
501 if ($dentry =~ s/\.exe$//i) {
502 $targets{$dentry}=1;
503 } elsif ($dentry =~ s/^(.*)\.dll$/lib$1.so/i) {
504 $targets{$dentry}=1;
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;
511 } else {
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";
523 $has_win_project=1;
524 } elsif ($dentry =~ /\.mak$/i) {
525 push @mak_files,"$dentry";
526 $has_win_project=1;
527 } elsif ($dentry =~ /^makefile/i) {
528 $has_win_project=1;
532 closedir(DIRECTORY);
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;
543 return;
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]};
557 return;
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";
564 my $target_count;
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
571 my $prj_list;
572 if (@dsp_files > 0) {
573 $prj_list=\@dsp_files;
574 } else {
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
587 my $name;
588 if ($dirname eq "") {
589 # Bad luck, this is the top level directory!
590 $name=(split /\//, cwd)[-1];
591 } else {
592 $name=$dirname;
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).
599 my $parent=$path;
600 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
601 $name=$parent;
602 } else {
603 $name=(split /\//, cwd)[-1];
607 $name =~ s+(/|\.[^.]*)$++;
608 if ($opt_target_type == $TT_DLL) {
609 $name = "lib$name.so";
611 $targets{$name}=1;
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>;
626 chomp $target_list;
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
631 undef %targets;
632 } elsif ($target_list eq "ignore") {
633 # Ignore this subtree altogether
634 return;
635 } else {
636 undef %targets;
637 foreach $target (split /,/,$target_list) {
638 $target =~ s+^\s*++;
639 $target =~ s+\s*$++;
640 # Also accept .exe and .dll as a courtesy
641 $target =~ s+(.*)\.dll$+lib$1.so+;
642 $target =~ s+\.exe$++;
643 $targets{$target}=1;
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]};
661 return;
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) {
672 my $flag_desc="";
673 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
674 $flag_desc="mfc";
676 if ((@$project_settings[$T_FLAGS] & $TF_WRAP)!=0) {
677 if ($flag_desc ne "") {
678 $flag_desc.=", ";
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";
688 while (1) {
689 my $options=<STDIN>;
690 chomp $options;
691 if ($options eq "skip") {
692 $opt_ask_target_options=$OPT_ASK_SKIP;
693 last;
694 } elsif ($options eq "never") {
695 $opt_ask_project_options=$OPT_ASK_NO;
696 last;
697 } elsif (source_set_options($project_settings,$options)) {
698 last;
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=();
710 my @exe_list=();
711 foreach $target_name (sort { $b cmp $a } keys %targets) {
712 # Create the target...
713 my $basename;
714 my $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;
722 $basename=$1;
723 push @local_depends,$target_name;
724 push @local_imports,$basename;
725 } else {
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) {
740 my $flag_desc="";
741 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
742 $flag_desc=" (mfc";
744 if ((@$target[$T_FLAGS] & $TF_WRAP)!=0) {
745 if ($flag_desc ne "") {
746 $flag_desc.=", ";
747 } else {
748 $flag_desc=" (";
750 $flag_desc.="wrapped";
752 if ($flag_desc ne "") {
753 $flag_desc.=")";
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";
757 while (1) {
758 my $options=<STDIN>;
759 chomp $options;
760 if ($options eq "never") {
761 $opt_ask_target_options=$OPT_ASK_NO;
762 last;
763 } elsif (source_set_options($target,$options)) {
764 last;
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";
778 # Match sources...
779 if ($target_count == 1) {
780 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
781 @$project_settings[$T_SOURCES_C]=[];
782 @sources_c=();
784 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
785 @$project_settings[$T_SOURCES_CXX]=[];
786 @sources_cxx=();
788 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
789 @$project_settings[$T_SOURCES_RC]=[];
790 @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]=[];
795 @sources_misc=();
796 } else {
797 foreach $source (@sources_c) {
798 if ($source =~ /^$basename/i) {
799 push @{@$target[$T_SOURCES_C]},$source;
800 $source="";
803 foreach $source (@sources_cxx) {
804 if ($source =~ /^$basename/i) {
805 push @{@$target[$T_SOURCES_CXX]},$source;
806 $source="";
809 foreach $source (@sources_rc) {
810 if ($source =~ /^$basename/i) {
811 push @{@$target[$T_SOURCES_RC]},$source;
812 $source="";
815 foreach $source (@sources_misc) {
816 if ($source =~ /^$basename/i) {
817 push @{@$target[$T_SOURCES_MISC]},$source;
818 $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) {
837 if ($source ne "") {
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) {
843 if ($source ne "") {
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) {
849 if ($source ne "") {
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) {
855 if ($source ne "") {
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
863 # the libraries
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
869 # will be exported.
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
878 sub source_scan
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";
886 } else {
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;
904 #####
906 # 'vc.dsp'-based Project analysis
908 #####
910 #sub analyze_vc_dsp
917 #####
919 # Creating the wrapper targets
921 #####
923 sub postprocess_targets
925 foreach $project (@projects) {
926 foreach $target (@{@$project[$P_TARGETS]}) {
927 if ((@$target[$T_FLAGS] & $TF_WRAP) != 0) {
928 my $wrapper=[];
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;
947 $needs_mfc=1;
955 #####
957 # Source search
959 #####
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
968 my $dirname=$_[0];
970 if (opendir(DIRECTORY, "$dirname")) {
971 foreach $dentry (readdir DIRECTORY) {
972 if ($dentry =~ /^\./ or $dentry eq "CVS") {
973 next;
975 # Set $warn to 1 if the user should be warned of the renaming
976 my $warn=0;
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) {
992 $warn=1;
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/) {
999 $warn=1;
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) {
1012 if ($warn) {
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";
1018 $new_name=$dentry;
1021 if (-d "$dirname/$new_name") {
1022 fix_file_and_directory_names("$dirname/$new_name");
1025 closedir(DIRECTORY);
1031 #####
1033 # Source fixup
1035 #####
1038 # This maps a directory name to a reference to an array listing
1039 # its contents (files and directories)
1040 my %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
1046 # in the hashtable.
1047 sub get_directory_contents
1049 my $dirname=$_[0];
1050 my $directory;
1052 #print "getting the contents of $dirname\n";
1054 # check for a cached version
1055 $dirname =~ s+/$++;
1056 if ($dirname eq "") {
1057 $dirname=cwd;
1059 $directory=$directories{$dirname};
1060 if (defined $directory) {
1061 #print "->@$directory\n";
1062 return $directory;
1065 # Read this directory
1066 if (opendir(DIRECTORY, "$dirname")) {
1067 my @files=readdir DIRECTORY;
1068 closedir(DIRECTORY);
1069 $directory=\@files;
1070 } else {
1071 # Return an empty list
1072 #print "error: cannot open $dirname\n";
1073 my @files;
1074 $directory=\@files;
1076 #print "->@$directory\n";
1077 $directories{$dirname}=$directory;
1078 return $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.
1085 sub search_from
1087 my $dirname=$_[0];
1088 my $path=$_[1];
1089 my $real_path="";
1091 if ($dirname eq "" or $dirname eq ".") {
1092 $dirname=cwd;
1093 } elsif ($dirname =~ m+^[^/]+) {
1094 $dirname=cwd . "/" . $dirname;
1096 if ($dirname !~ m+/$+) {
1097 $dirname.="/";
1100 foreach $component (@$path) {
1101 #print " looking for $component in \"$dirname\"\n";
1102 if ($component eq ".") {
1103 # Pass it as is
1104 $real_path.="./";
1105 } elsif ($component eq "..") {
1106 # Go up one level
1107 $dirname=dirname($dirname) . "/";
1108 $real_path.="../";
1109 } else {
1110 my $directory=get_directory_contents $dirname;
1111 my $found;
1112 foreach $dentry (@$directory) {
1113 if ($dentry =~ /^$component$/i) {
1114 $dirname.="$dentry/";
1115 $real_path.="$dentry/";
1116 $found=1;
1117 last;
1120 if (!defined $found) {
1121 # Give up
1122 #print " could not find $component in $dirname\n";
1123 return;
1127 $real_path=~ s+/$++;
1128 #print " -> found $real_path\n";
1129 return $real_path;
1133 # Performs a case-insensitive search for the specified file in the
1134 # include path.
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
1142 my $line=$_[0];
1143 my $filename=$_[1];
1144 my $dirname=$_[2];
1145 my $project=$_[3];
1146 my $target=$_[4];
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";
1156 } else {
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";
1167 my $real_filename;
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;
1179 $dirname=~ s+^-I++;
1180 if (!is_absolute($dirname)) {
1181 $dirname="@$project[$P_PATH]$dirname";
1182 } else {
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;
1195 $dirname=~ s+^-I++;
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";
1209 return $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.
1221 sub fix_file
1223 my $filename=$_[0];
1224 my $project=$_[1];
1225 my $target=$_[2];
1226 $filename="@$project[$P_PATH]$filename";
1227 if (! -e $filename) {
1228 return;
1231 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1232 my $dirname=dirname($filename);
1233 my $is_mfc=0;
1234 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1235 $is_mfc=1;
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";
1245 return;
1248 if (!open(FILEI,"$filename.bak")) {
1249 print STDERR "error: unable to open $filename.bak for reading:\n";
1250 print STDERR " $!\n";
1251 return;
1253 if (!open(FILEO,">$filename")) {
1254 print STDERR "error: unable to open $filename for writing:\n";
1255 print STDERR " $!\n";
1256 return;
1258 my $line=0;
1259 my $modified=0;
1260 my $rc_block_depth=0;
1261 my $rc_textinclude_state=0;
1262 while (<FILEI>) {
1263 $line++;
1264 $_ =~ s/\r\n$/\n/;
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
1271 # edited.
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\"$'";
1280 $modified=1;
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;
1288 my $size=$3;
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";
1293 $line++;
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>$'";
1304 } else {
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>$'";
1313 $modified=1;
1315 } elsif ($is_rc) {
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;
1328 print FILEO;
1329 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
1330 print FILEO "$1winres.h$2$'";
1331 $modified=1;
1332 } elsif (/^\s*BEGIN(\W.*)?$/) {
1333 $rc_textinclude_state|=2;
1334 $rc_block_depth++;
1335 print FILEO;
1336 } elsif (/^\s*END(\W.*)?$/) {
1337 $rc_textinclude_state=0;
1338 if ($rc_block_depth>0) {
1339 $rc_block_depth--;
1341 print FILEO;
1342 } else {
1343 print FILEO;
1345 } else {
1346 print FILEO;
1349 close(FILEI);
1350 close(FILEO);
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.
1362 sub fix_source
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) {
1368 next;
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);
1379 #####
1381 # File generation
1383 #####
1386 # Generates a target's .spec file
1387 sub generate_spec_file
1389 my $path=$_[0];
1390 my $target=$_[1];
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";
1404 return;
1407 my $canon=canonize($basename);
1408 print FILEO "name $canon\n";
1409 print FILEO "type win32\n";
1410 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1411 print FILEO "mode guiexe\n";
1412 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1413 print FILEO "mode cuiexe\n";
1414 } else {
1415 print FILEO "mode dll\n";
1417 if (defined @$target[$T_INIT] and ((@$target[$T_FLAGS] & $TF_WRAP) == 0)) {
1418 print FILEO "init @$target[$T_INIT]\n";
1420 if (@{@$target[$T_SOURCES_RC]} > 0) {
1421 if (@{@$target[$T_SOURCES_RC]} > 1) {
1422 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";
1424 my $rcname=@{@$target[$T_SOURCES_RC]}[0];
1425 $rcname =~ s+\.rc$++i;
1426 print FILEO "rsrc $rcname.res\n";
1428 print FILEO "\n";
1429 my %imports;
1430 foreach $library (@{$global_settings[$T_IMPORTS]}) {
1431 if (!defined $imports{$library}) {
1432 print FILEO "import $library\n";
1433 $imports{$library}=1;
1436 if (defined $project_settings) {
1437 foreach $library (@{@$project_settings[$T_IMPORTS]}) {
1438 if (!defined $imports{$library}) {
1439 print FILEO "import $library\n";
1440 $imports{$library}=1;
1444 foreach $library (@{@$target[$T_IMPORTS]}) {
1445 if (!defined $imports{$library}) {
1446 print FILEO "import $library\n";
1447 $imports{$library}=1;
1451 # Don't forget to export the 'Main' function for wrapped executables,
1452 # except for MFC ones!
1453 if (@$target[$T_FLAGS] == $TF_WRAP) {
1454 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1455 print FILEO "\n@ stdcall @$target[$T_INIT](long long ptr long) @$target[$T_INIT]\n";
1456 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1457 print FILEO "\n@ stdcall @$target[$T_INIT](long ptr ptr) @$target[$T_INIT]\n";
1458 } else {
1459 print FILEO "\n@ stdcall @$target[$T_INIT](ptr long ptr) @$target[$T_INIT]\n";
1463 close(FILEO);
1467 # Generates a target's wrapper file
1468 sub generate_wrapper_file
1470 my $path=$_[0];
1471 my $target=$_[1];
1473 if (!defined $templates{"wrapper.c"}) {
1474 print STDERR "winemaker: internal error: No template called 'wrapper.c'\n";
1475 return;
1478 if (!open(FILEO,">$path@$target[$T_NAME]_wrapper.c")) {
1479 print STDERR "error: unable to open \"$path$basename.c\" for writing:\n";
1480 print STDERR " $!\n";
1481 return;
1483 my $app_name="\"@$target[$T_NAME]\"";
1484 my $app_type=(@$target[$T_TYPE]==$TT_GUIEXE?"GUIEXE":"CUIEXE");
1485 my $app_init=(@$target[$T_TYPE]==$TT_GUIEXE?"\"WinMain\"":"\"main\"");
1486 my $app_mfc=(@$target[$T_FLAGS] & $TF_MFC?"\"mfc\"":NULL);
1487 foreach $line (@{$templates{"wrapper.c"}}) {
1488 $line =~ s/\#\#WINEMAKER_APP_NAME\#\#/$app_name/;
1489 $line =~ s/\#\#WINEMAKER_APP_TYPE\#\#/$app_type/;
1490 $line =~ s/\#\#WINEMAKER_APP_INIT\#\#/$app_init/;
1491 $line =~ s/\#\#WINEMAKER_APP_MFC\#\#/$app_mfc/;
1492 print FILEO $line;
1494 close(FILEO);
1498 # A convenience function to generate all the lists (defines,
1499 # C sources, C++ source, etc.) in the Makefile
1500 sub generate_list
1502 my $name=$_[0];
1503 my $last=$_[1];
1504 my $list=$_[2];
1505 my $data=$_[3];
1506 my $first=$name;
1508 if ($name) {
1509 printf FILEO "%-22s=",$name;
1511 if (defined $list) {
1512 foreach $item (@$list) {
1513 my $value;
1514 if (defined $data) {
1515 $value=&$data($item);
1516 } else {
1517 $value=$item;
1519 if ($value ne "") {
1520 if ($first) {
1521 print FILEO " $value";
1522 $first=0;
1523 } else {
1524 print FILEO " \\\n\t\t\t$value";
1529 if ($last) {
1530 print FILEO "\n";
1535 # Generates a project's Makefile.in and all the target files
1536 sub generate_project_files
1538 my $project=$_[0];
1539 my $project_settings=@$project[$P_SETTINGS];
1540 my @dll_list=();
1541 my @exe_list=();
1543 # Then sort the targets and separate the libraries from the programs
1544 foreach $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
1545 if (@$target[$T_TYPE] == $TT_DLL) {
1546 push @dll_list,$target;
1547 } else {
1548 push @exe_list,$target;
1551 @$project[$P_TARGETS]=[];
1552 push @{@$project[$P_TARGETS]}, @dll_list;
1553 push @{@$project[$P_TARGETS]}, @exe_list;
1555 if (!open(FILEO,">@$project[$P_PATH]Makefile.in")) {
1556 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile.in\" for writing\n";
1557 print STDERR " $!\n";
1558 return;
1561 print FILEO "### Generated by Winemaker\n";
1562 print FILEO "\n\n";
1564 print FILEO "### Generic autoconf variables\n\n";
1565 generate_list("TOPSRCDIR",1,[ "\@top_srcdir\@" ]);
1566 generate_list("TOPOBJDIR",1,[ "." ]);
1567 generate_list("SRCDIR",1,[ "\@srcdir\@" ]);
1568 generate_list("VPATH",1,[ "\@srcdir\@" ]);
1569 print FILEO "\n";
1570 if (@$project[$P_PATH] eq "") {
1571 # This is the main project. It is also responsible for recursively
1572 # calling the other projects
1573 generate_list("SUBDIRS",1,\@projects,sub
1575 if ($_[0] != \@main_project) {
1576 my $subdir=@{$_[0]}[$P_PATH];
1577 $subdir =~ s+/$++;
1578 return $subdir;
1580 # Eliminating the main project by returning undefined!
1583 if (@{@$project[$P_TARGETS]} > 0) {
1584 generate_list("DLLS",1,\@dll_list,sub
1586 return @{$_[0]}[$T_NAME];
1588 generate_list("EXES",1,\@exe_list,sub
1590 return "@{$_[0]}[$T_NAME]";
1592 print FILEO "\n\n\n";
1594 print FILEO "### Global settings\n\n";
1595 # Make it so that the project-wide settings override the global settings
1596 generate_list("DEFINES",0,@$project_settings[$T_DEFINES],sub
1598 return "$_[0]";
1600 generate_list("",1,$global_settings[$T_DEFINES],sub
1602 return "$_[0]";
1604 generate_list("INCLUDE_PATH",$no_extra,@$project_settings[$T_INCLUDE_PATH],sub
1606 return "$_[0]";
1608 generate_list("",1,$global_settings[$T_INCLUDE_PATH],sub
1610 if ($_[0] !~ /^-I/) {
1611 return "$_[0]";
1613 if (is_absolute($')) {
1614 return "$_[0]";
1616 return "-I\$(TOPSRCDIR)/$'";
1618 generate_list("LIBRARY_PATH",$no_extra,@$project_settings[$T_LIBRARY_PATH],sub
1620 return "$_[0]";
1622 generate_list("",1,$global_settings[$T_LIBRARY_PATH],sub
1624 if ($_[0] !~ /^-L/) {
1625 return "$_[0]";
1627 if (is_absolute($')) {
1628 return "$_[0]";
1630 return "-L\$(TOPSRCDIR)/$'";
1632 generate_list("LIBRARIES",$no_extra,@$project_settings[$T_LIBRARIES],sub
1634 return "$_[0]";
1636 generate_list("",1,$global_settings[$T_LIBRARIES],sub
1638 return "$_[0]";
1640 print FILEO "\n\n";
1642 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
1643 @{@$project_settings[$T_SOURCES_CXX]}+
1644 @{@$project_settings[$T_SOURCES_RC]};
1645 my $no_extra=($extra_source_count == 0);
1646 if (!$no_extra) {
1647 print FILEO "### Extra source lists\n\n";
1648 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
1649 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
1650 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
1651 print FILEO "\n";
1652 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
1653 print FILEO "\n\n\n";
1656 # Iterate over all the targets...
1657 foreach $target (@{@$project[$P_TARGETS]}) {
1658 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
1659 my $canon=canonize("@$target[$T_NAME]");
1660 $canon =~ s+_so$++;
1661 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
1662 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
1663 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
1664 my $basename=@$target[$T_NAME];
1665 $basename =~ s+\.so$++;
1666 if (@$target[$T_FLAGS] & $TF_WRAP) {
1667 $basename =~ s+^lib++;
1668 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1669 $basename.="_wrapper";
1671 generate_list("${canon}_SPEC_SRCS",1,[ "$basename.spec"]);
1672 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH],sub
1674 return "$_[0]";
1676 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES],sub
1678 return "$_[0]";
1680 generate_list("${canon}_DEPENDS",1,@$target[$T_DEPENDS],sub
1682 return "$_[0]";
1684 print FILEO "\n";
1685 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(EXTRA_OBJS)"]);
1686 print FILEO "\n\n\n";
1688 print FILEO "### Global source lists\n\n";
1689 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
1691 my $canon=canonize(@{$_[0]}[$T_NAME]);
1692 $canon =~ s+_so$++;
1693 return "\$(${canon}_C_SRCS)";
1695 if (!$no_extra) {
1696 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
1698 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
1700 my $canon=canonize(@{$_[0]}[$T_NAME]);
1701 $canon =~ s+_so$++;
1702 return "\$(${canon}_CXX_SRCS)";
1704 if (!$no_extra) {
1705 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
1707 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
1709 my $canon=canonize(@{$_[0]}[$T_NAME]);
1710 $canon =~ s+_so$++;
1711 return "\$(${canon}_RC_SRCS)";
1713 if (!$no_extra) {
1714 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
1716 generate_list("SPEC_SRCS",1,@$project[$P_TARGETS],sub
1718 my $canon=canonize(@{$_[0]}[$T_NAME]);
1719 $canon =~ s+_so$++;
1720 return "\$(${canon}_SPEC_SRCS)";
1723 print FILEO "\n\n\n";
1725 print FILEO "### Generic autoconf targets\n\n";
1726 print FILEO "all: ";
1727 if (@$project[$P_PATH] eq "") {
1728 print FILEO "\$(SUBDIRS)";
1730 if (@{@$project[$P_TARGETS]} > 0) {
1731 print FILEO "\$(DLLS) \$(EXES:%=%.so)";
1733 print FILEO "\n\n";
1734 print FILEO "\@MAKE_RULES\@\n";
1735 print FILEO "\n";
1736 print FILEO "install::\n";
1737 if (@$project[$P_PATH] eq "") {
1738 # This is the main project. It is also responsible for recursively
1739 # calling the other projects
1740 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) install) || exit 1; done\n";
1742 if (@{@$project[$P_TARGETS]} > 0) {
1743 print FILEO "\tfor i in \$(EXES); do \$(INSTALL_PROGRAM) \$\$i \$(bindir); done\n";
1744 print FILEO "\tfor i in \$(EXES:%=%.so) \$(DLLS); do \$(INSTALL_LIBRARY) \$\$i \$(libdir); done\n";
1746 print FILEO "\n";
1747 print FILEO "uninstall::\n";
1748 if (@$project[$P_PATH] eq "") {
1749 # This is the main project. It is also responsible for recursively
1750 # calling the other projects
1751 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) uninstall) || exit 1; done\n";
1753 if (@{@$project[$P_TARGETS]} > 0) {
1754 print FILEO "\tfor i in \$(EXES); do \$(RM) \$(bindir)/\$\$i;done\n";
1755 print FILEO "\tfor i in \$(EXES:%=%.so) \$(DLLS); do \$(RM) \$(libdir)/\$\$i;done\n";
1757 print FILEO "\n\n\n";
1759 if (@{@$project[$P_TARGETS]} > 0) {
1760 print FILEO "### Target specific build rules\n\n";
1761 foreach $target (@{@$project[$P_TARGETS]}) {
1762 my $canon=canonize("@$target[$T_NAME]");
1763 $canon =~ s/_so$//;
1764 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.tmp.o): \$(${canon}_OBJS)\n";
1765 print FILEO "\t\$(LDCOMBINE) \$(${canon}_OBJS) -o \$\@\n";
1766 print FILEO "\t-\$(STRIP) \$(STRIPFLAGS) \$\@\n";
1767 print FILEO "\n";
1768 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.spec.c): \$(${canon}_SPEC_SRCS:.spec) \$(${canon}_SPEC_SRCS:.spec=.tmp.o) \$(${canon}_RC_SRCS:.rc=.res)\n";
1769 print FILEO "\t\$(WINEBUILD) -fPIC \$(${canon}_LIBRARY_PATH) \$(WINE_LIBRARY_PATH) -sym \$(${canon}_SPEC_SRCS:.spec=.tmp.o) -o \$\@ -spec \$(${canon}_SPEC_SRCS)\n";
1770 print FILEO "\n";
1771 my $t_name=@$target[$T_NAME];
1772 if (@$target[$T_TYPE]!=$TT_DLL) {
1773 $t_name.=".so";
1775 print FILEO "$t_name: \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_OBJS) \$(${canon}_DEPENDS) \n";
1776 print FILEO "\t\$(LDSHARED) \$(LDDLLFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_LIBRARY_PATH) \$(${canon}_LIBRARIES:%=-l%) \$(DLL_LINK) \$(LIBS)\n";
1777 if (@$target[$T_TYPE] ne $TT_DLL) {
1778 print FILEO "\ttest -e @$target[$T_NAME] || \$(LN_S) \$(WINE) @$target[$T_NAME]\n";
1780 print FILEO "\n\n";
1783 close(FILEO);
1785 foreach $target (@{@$project[$P_TARGETS]}) {
1786 generate_spec_file(@$project[$P_PATH],$target,$project_settings);
1787 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1788 generate_wrapper_file(@$project[$P_PATH],$target);
1794 # Perform the replacements in the template configure files
1795 # Return 1 for success, 0 for failure
1796 sub generate_configure
1798 my $filename=$_[0];
1799 my $a_source_file=$_[1];
1801 if (!defined $templates{$filename}) {
1802 if ($filename ne "configure") {
1803 print STDERR "winemaker: internal error: No template called '$filename'\n";
1805 return 0;
1808 if (!open(FILEO,">$filename")) {
1809 print STDERR "error: unable to open \"$filename\" for writing:\n";
1810 print STDERR " $!\n";
1811 return 0;
1813 foreach $line (@{$templates{$filename}}) {
1814 if ($line =~ /^\#\#WINEMAKER_PROJECTS\#\#$/) {
1815 foreach $project (@projects) {
1816 print FILEO "@$project[$P_PATH]Makefile\n";
1818 } else {
1819 $line =~ s+\#\#WINEMAKER_SOURCE\#\#+$a_source_file+;
1820 $line =~ s+\#\#WINEMAKER_NEEDS_MFC\#\#+$needs_mfc+;
1821 print FILEO $line;
1824 close(FILEO);
1825 return 1;
1828 sub generate_generic
1830 my $filename=$_[0];
1832 if (!defined $templates{$filename}) {
1833 print STDERR "winemaker: internal error: No template called '$filename'\n";
1834 return;
1836 if (!open(FILEO,">$filename")) {
1837 print STDERR "error: unable to open \"$filename\" for writing:\n";
1838 print STDERR " $!\n";
1839 return;
1841 foreach $line (@{$templates{$filename}}) {
1842 print FILEO $line;
1844 close(FILEO);
1848 # Generates the global files:
1849 # configure
1850 # configure.in
1851 # Make.rules.in
1852 sub generate_global_files
1854 generate_generic("Make.rules.in");
1856 # Get the name of a source file for configure.in
1857 my $a_source_file;
1858 search_a_file: foreach $project (@projects) {
1859 foreach $target (@{@$project[$P_TARGETS]}, @$project[$P_SETTINGS]) {
1860 $a_source_file=@{@$target[$T_SOURCES_C]}[0];
1861 if (!defined $a_source_file) {
1862 $a_source_file=@{@$target[$T_SOURCES_CXX]}[0];
1864 if (!defined $a_source_file) {
1865 $a_source_file=@{@$target[$T_SOURCES_RC]}[0];
1867 if (defined $a_source_file) {
1868 $a_source_file="@$project[$P_PATH]$a_source_file";
1869 last search_a_file;
1874 generate_configure("configure.in",$a_source_file);
1875 unlink("configure");
1876 if (generate_configure("configure",$a_source_file) == 0) {
1877 system("autoconf");
1879 # Add execute permission to configure for whoever has the right to read it
1880 my @st=stat("configure");
1881 if (defined @st) {
1882 my $mode=$st[2];
1883 $mode|=($mode & 0444) >>2;
1884 chmod($mode,"configure");
1885 } else {
1886 print "warning: could not generate the configure script. You need to run autoconf\n";
1892 sub generate_read_templates
1894 my $file;
1896 while (<DATA>) {
1897 if (/^--- ((\w\.?)+) ---$/) {
1898 my $filename=$1;
1899 if (defined $templates{$filename}) {
1900 print STDERR "winemaker: internal error: There is more than one template for $filename\n";
1901 undef $file;
1902 } else {
1903 $file=[];
1904 $templates{$filename}=$file;
1906 } elsif (defined $file) {
1907 push @$file, $_;
1913 # This is where we finally generate files. In fact this method does not
1914 # do anything itself but calls the methods that do the actual work.
1915 sub generate
1917 print "Generating project files...\n";
1918 generate_read_templates();
1919 generate_global_files();
1921 foreach $project (@projects) {
1922 my $path=@$project[$P_PATH];
1923 if ($path eq "") {
1924 $path=".";
1925 } else {
1926 $path =~ s+/$++;
1928 print " $path\n";
1929 generate_project_files($project);
1935 #####
1937 # Option defaults
1939 #####
1941 $opt_backup=1;
1942 $opt_lower=$OPT_LOWER_UPPERCASE;
1943 $opt_lower_include=1;
1945 # $opt_single_target=<undefined>
1946 $opt_target_type=$TT_GUIEXE;
1947 $opt_flags=0;
1948 $opt_is_interactive=$OPT_ASK_NO;
1949 $opt_ask_project_options=$OPT_ASK_NO;
1950 $opt_ask_target_options=$OPT_ASK_NO;
1951 $opt_no_generated_files=0;
1952 $opt_no_banner=0;
1956 #####
1958 # Main
1960 #####
1962 project_init(\@main_project,"");
1964 while (@ARGV>0) {
1965 my $arg=shift @ARGV;
1966 # General options
1967 if ($arg eq "--nobanner") {
1968 $opt_no_banner=1;
1969 } elsif ($arg eq "--backup") {
1970 $opt_backup=1;
1971 } elsif ($arg eq "--nobackup") {
1972 $opt_backup=0;
1973 } elsif ($arg eq "--single-target") {
1974 $opt_single_target=shift @ARGV;
1975 } elsif ($arg eq "--lower-none") {
1976 $opt_lower=$OPT_LOWER_NONE;
1977 } elsif ($arg eq "--lower-all") {
1978 $opt_lower=$OPT_LOWER_ALL;
1979 } elsif ($arg eq "--lower-uppercase") {
1980 $opt_lower=$OPT_LOWER_UPPERCASE;
1981 } elsif ($arg eq "--lower-include") {
1982 $opt_lower_include=1;
1983 } elsif ($arg eq "--nolower-include") {
1984 $opt_lower_include=0;
1985 } elsif ($arg eq "--generated-files") {
1986 $opt_no_generated_files=0;
1987 } elsif ($arg eq "--nogenerated-files") {
1988 $opt_no_generated_files=1;
1990 } elsif ($arg =~ /^-D/) {
1991 push @{$global_settings[$T_DEFINES]},$arg;
1992 } elsif ($arg =~ /^-I/) {
1993 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
1994 } elsif ($arg =~ /^-L/) {
1995 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
1996 } elsif ($arg =~ /^-i/) {
1997 push @{$global_settings[$T_IMPORTS]},$';
1998 } elsif ($arg =~ /^-l/) {
1999 push @{$global_settings[$T_LIBRARIES]},$';
2001 # 'Source'-based method options
2002 } elsif ($arg eq "--dll") {
2003 $opt_target_type=$TT_DLL;
2004 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2005 $opt_target_type=$TT_GUIEXE;
2006 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2007 $opt_target_type=$TT_CUIEXE;
2008 } elsif ($arg eq "--interactive") {
2009 $opt_is_interactive=$OPT_ASK_YES;
2010 $opt_ask_project_options=$OPT_ASK_YES;
2011 $opt_ask_target_options=$OPT_ASK_YES;
2012 } elsif ($arg eq "--wrap") {
2013 print STDERR "warning: --wrap no longer supported, ignoring the option\n";
2014 #$opt_flags|=$TF_WRAP;
2015 } elsif ($arg eq "--nowrap") {
2016 $opt_flags&=~$TF_WRAP;
2017 } elsif ($arg eq "--mfc") {
2018 $opt_flags|=$TF_MFC;
2019 #$opt_flags|=$TF_MFC|$TF_WRAP;
2020 $needs_mfc=1;
2021 } elsif ($arg eq "--nomfc") {
2022 $opt_flags&=~($TF_MFC|$TF_WRAP);
2023 $needs_mfc=0;
2025 # Catch errors
2026 } else {
2027 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2028 print STDERR "Unknown option: $arg\n";
2030 $usage=1;
2031 last;
2035 if ($opt_no_banner == 0 or defined $usage) {
2036 print "Winemaker $version\n";
2037 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2040 if (defined $usage) {
2041 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup]\n";
2042 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2043 print STDERR " [--lower-include|--nolower-include]\n";
2044 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2045 print STDERR " [--wrap|--nowrap] [--mfc|--nomfc]\n";
2046 print STDERR " [-Dmacro[=defn]] [-Idir] [-Ldir] [-idll] [-llibrary]\n";
2047 print STDERR " [--interactive] [--single-target name]\n";
2048 print STDERR " [--generated-files|--nogenerated-files]\n";
2049 exit (2);
2052 # Fix the file and directory names
2053 fix_file_and_directory_names(".");
2055 # Scan the sources to identify the projects and targets
2056 source_scan();
2058 # Create targets for wrappers, etc.
2059 postprocess_targets();
2061 # Fix the source files
2062 fix_source();
2064 # Generate the Makefile and the spec file
2065 if (! $opt_no_generated_files) {
2066 generate();
2070 __DATA__
2071 --- configure.in ---
2072 dnl Process this file with autoconf to produce a configure script.
2073 dnl Author: Michael Patra <micky@marie.physik.tu-berlin.de>
2074 dnl <patra@itp1.physik.tu-berlin.de>
2075 dnl Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2077 AC_REVISION([configure.in 1.00])
2078 AC_INIT(##WINEMAKER_SOURCE##)
2080 NEEDS_MFC=##WINEMAKER_NEEDS_MFC##
2082 dnl **** Command-line arguments ****
2084 AC_SUBST(OPTIONS)
2086 dnl **** Check for some programs ****
2088 AC_PROG_MAKE_SET
2089 AC_PROG_CC
2090 AC_PROG_CXX
2091 AC_PROG_CPP
2092 AC_PATH_XTRA
2093 AC_PROG_RANLIB
2094 AC_PROG_LN_S
2095 AC_PATH_PROG(LDCONFIG, ldconfig, true, /sbin:/usr/sbin:$PATH)
2097 dnl **** Check for some libraries ****
2099 dnl Check for -lm for BeOS
2100 AC_CHECK_LIB(m,sqrt)
2101 dnl Check for -li386 for NetBSD and OpenBSD
2102 AC_CHECK_LIB(i386,i386_set_ldt)
2103 dnl Check for -lossaudio for NetBSD
2104 AC_CHECK_LIB(ossaudio,_oss_ioctl)
2105 dnl Check for -lw for Solaris
2106 AC_CHECK_LIB(w,iswalnum)
2107 dnl Check for -lnsl for Solaris
2108 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))
2109 dnl Check for -lsocket for Solaris
2110 AC_CHECK_FUNCS(connect,,AC_CHECK_LIB(socket,connect))
2111 dnl Check for -lxpg4 for FreeBSD
2112 AC_CHECK_LIB(xpg4,setrunelocale)
2113 dnl Check for -lmmap for OS/2
2114 AC_CHECK_LIB(mmap,mmap)
2115 dnl Check for openpty
2116 AC_CHECK_FUNCS(openpty,,
2117 AC_CHECK_LIB(util,openpty,
2118 AC_DEFINE(HAVE_OPENPTY)
2119 LIBS="$LIBS -lutil"
2122 AC_CHECK_HEADERS(dlfcn.h,
2123 AC_CHECK_FUNCS(dlopen,
2124 AC_DEFINE(HAVE_DL_API),
2125 AC_CHECK_LIB(dl,dlopen,
2126 AC_DEFINE(HAVE_DL_API)
2127 LIBS="$LIBS -ldl",
2132 dnl **** Check which curses lib to use ***
2133 if test "$CURSES" = "yes"
2134 then
2135 AC_CHECK_HEADERS(ncurses.h)
2136 if test "$ac_cv_header_ncurses_h" = "yes"
2137 then
2138 AC_CHECK_LIB(ncurses,waddch)
2140 if test "$ac_cv_lib_ncurses_waddch" = "yes"
2141 then
2142 AC_CHECK_LIB(ncurses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2143 AC_CHECK_LIB(ncurses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2144 else
2145 AC_CHECK_HEADERS(curses.h)
2146 if test "$ac_cv_header_curses_h" = "yes"
2147 then
2148 AC_CHECK_LIB(curses,waddch)
2149 if test "$ac_cv_lib_curses_waddch" = "yes"
2150 then
2151 AC_CHECK_LIB(curses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2152 AC_CHECK_LIB(curses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2158 dnl **** If ln -s doesn't work, use cp instead ****
2159 if test "$ac_cv_prog_LN_S" = "ln -s"; then : ; else LN_S=cp ; fi
2161 dnl **** Check for gcc strength-reduce bug ****
2163 if test "x${GCC}" = "xyes"
2164 then
2165 AC_CACHE_CHECK( "for gcc strength-reduce bug", ac_cv_c_gcc_strength_bug,
2166 AC_TRY_RUN([
2167 int main(void) {
2168 static int Array[[3]];
2169 unsigned int B = 3;
2170 int i;
2171 for(i=0; i<B; i++) Array[[i]] = i - 3;
2172 exit( Array[[1]] != -2 );
2174 ac_cv_c_gcc_strength_bug="no",
2175 ac_cv_c_gcc_strength_bug="yes",
2176 ac_cv_c_gcc_strength_bug="yes") )
2177 if test "$ac_cv_c_gcc_strength_bug" = "yes"
2178 then
2179 CFLAGS="$CFLAGS -fno-strength-reduce"
2183 dnl **** Check for underscore on external symbols ****
2185 AC_CACHE_CHECK("whether external symbols need an underscore prefix",
2186 ac_cv_c_extern_prefix,
2187 [saved_libs=$LIBS
2188 LIBS="conftest_asm.s $LIBS"
2189 cat > conftest_asm.s <<EOF
2190 .globl _ac_test
2191 _ac_test:
2192 .long 0
2194 AC_TRY_LINK([extern int ac_test;],[if (ac_test) return 1],
2195 ac_cv_c_extern_prefix="yes",ac_cv_c_extern_prefix="no")
2196 LIBS=$saved_libs])
2197 if test "$ac_cv_c_extern_prefix" = "yes"
2198 then
2199 AC_DEFINE(NEED_UNDERSCORE_PREFIX)
2202 dnl **** Check for working dll ****
2204 LDSHARED=""
2205 LDDLLFLAGS=""
2206 AC_CACHE_CHECK("whether we can build a Linux dll",
2207 ac_cv_c_dll_linux,
2208 [saved_cflags=$CFLAGS
2209 CFLAGS="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0,-Bsymbolic"
2210 AC_TRY_LINK(,[return 1],ac_cv_c_dll_linux="yes",ac_cv_c_dll_linux="no")
2211 CFLAGS=$saved_cflags
2213 if test "$ac_cv_c_dll_linux" = "yes"
2214 then
2215 LDSHARED="\$(CC) -shared -Wl,-rpath,\$(libdir)"
2216 LDDLLFLAGS="-Wl,-Bsymbolic"
2217 else
2218 AC_CACHE_CHECK(whether we can build a UnixWare (Solaris) dll,
2219 ac_cv_c_dll_unixware,
2220 [saved_cflags=$CFLAGS
2221 CFLAGS="$CFLAGS -fPIC -Wl,-G,-h,conftest.so.1.0,-B,symbolic"
2222 AC_TRY_LINK(,[return 1],ac_cv_c_dll_unixware="yes",ac_cv_c_dll_unixware="no")
2223 CFLAGS=$saved_cflags
2225 if test "$ac_cv_c_dll_unixware" = "yes"
2226 then
2227 LDSHARED="\$(CC) -Wl,-G \$(SONAME:%=-Wl,h,\$(libdir)/%)"#FIXME: why SONAME here?
2228 LDDLLFLAGS="-Wl,-B,symbolic"
2229 else
2230 AC_CACHE_CHECK("whether we can build a NetBSD dll",
2231 ac_cv_c_dll_netbsd,
2232 [saved_cflags=$CFLAGS
2233 CFLAGS="$CFLAGS -fPIC -Wl,-Bshareable,-Bforcearchive"
2234 AC_TRY_LINK(,[return 1],ac_cv_c_dll_netbsd="yes",ac_cv_c_dll_netbsd="no")
2235 CFLAGS=$saved_cflags
2237 if test "$ac_cv_c_dll_netbsd" = "yes"
2238 then
2239 LDSHARED="\$(CC) -Wl,-Bshareable,-Bforcearchive"
2240 LDDLLFLAGS="" #FIXME
2244 if test "$ac_cv_c_dll_linux" = "no" -a "$ac_cv_c_dll_unixware" = "no" -a "$ac_cv_c_dll_netbsd" = "no"
2245 then
2246 AC_MSG_ERROR([Could not find how to build a dynamically linked library])
2249 CFLAGS="$CFLAGS -fPIC"
2250 DLL_LINK="\$(WINE_LIBRARY_PATH) \$(LIBRARY_PATH) \$(LIBRARIES:%=-l%) -lwine -lwine_unicode"
2252 AC_SUBST(DLL_LINK)
2253 AC_SUBST(LDSHARED)
2254 AC_SUBST(LDDLLFLAGS)
2256 dnl *** check for the need to define __i386__
2258 AC_CACHE_CHECK("whether we need to define __i386__",ac_cv_cpp_def_i386,
2259 AC_EGREP_CPP(yes,[#if (defined(i386) || defined(__i386)) && !defined(__i386__)
2261 #endif],
2262 ac_cv_cpp_def_i386="yes", ac_cv_cpp_def_i386="no"))
2263 if test "$ac_cv_cpp_def_i386" = "yes"
2264 then
2265 CFLAGS="$CFLAGS -D__i386__"
2268 dnl $GCC is set by autoconf
2269 GCC_NO_BUILTIN=""
2270 if test "$GCC" = "yes"
2271 then
2272 GCC_NO_BUILTIN="-fno-builtin"
2274 AC_SUBST(GCC_NO_BUILTIN)
2276 dnl **** Test Winelib-related features of the C++ compiler
2277 AC_LANG_CPLUSPLUS()
2278 if test "x${GCC}" = "xyes"
2279 then
2280 OLDCXXFLAGS="$CXXFLAGS";
2281 CXXFLAGS="-fpermissive";
2282 AC_CACHE_CHECK("for g++ -fpermissive option", has_gxx_permissive,
2283 AC_TRY_COMPILE(,[
2284 for (int i=0;i<2;i++);
2285 i=0;
2287 [has_gxx_permissive="yes"],
2288 [has_gxx_permissive="no"])
2290 CXXFLAGS="-fno-for-scope";
2291 AC_CACHE_CHECK("for g++ -fno-for-scope option", has_gxx_no_for_scope,
2292 AC_TRY_COMPILE(,[
2293 for (int i=0;i<2;i++);
2294 i=0;
2296 [has_gxx_no_for_scope="yes"],
2297 [has_gxx_no_for_scope="no"])
2299 CXXFLAGS="$OLDCXXFLAGS";
2300 if test "$has_gxx_permissive" = "yes"
2301 then
2302 CXXFLAGS="$CXXFLAGS -fpermissive"
2304 if test "$has_gxx_no_for_scope" = "yes"
2305 then
2306 CXXFLAGS="$CXXFLAGS -fno-for-scope"
2309 AC_LANG_C()
2311 dnl **** Test Winelib-related features of the C compiler
2312 dnl none for now
2314 dnl **** Macros for finding a headers/libraries in a collection of places
2316 dnl AC_PATH_HEADER(variable,header,action-if-not-found,default-locations)
2317 dnl Note that the above may set variable to an empty value if the header is
2318 dnl already in the include path
2319 AC_DEFUN(AC_PATH_HEADER,[
2320 AC_MSG_CHECKING([for $2])
2321 AC_CACHE_VAL(ac_cv_path_$1,
2323 ac_found=
2324 ac_dummy="ifelse([$4], , :/usr/local/include, [$4])"
2325 save_CPPFLAGS="$CPPFLAGS"
2326 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2327 for ac_dir in $ac_dummy; do
2328 IFS="$ac_save_ifs"
2329 if test -z "$ac_dir"
2330 then
2331 CPPFLAGS="$save_CPPFLAGS"
2332 else
2333 CPPFLAGS="-I$ac_dir $save_CPPFLAGS"
2335 AC_TRY_COMPILE([#include <$2>],,ac_found=1;ac_cv_path_$1="$ac_dir";break)
2336 done
2337 CPPFLAGS="$save_CPPFLAGS"
2338 ifelse([$3],,,[if test -z "$ac_found"
2339 then
2344 $1="$ac_cv_path_$1"
2345 if test -n "$ac_found" -o -n "[$]$1"
2346 then
2347 AC_MSG_RESULT([$]$1)
2348 else
2349 AC_MSG_RESULT(no)
2351 AC_SUBST($1)
2354 dnl AC_PATH_LIBRARY(variable,libraries,extra libs,action-if-not-found,default-locations)
2355 AC_DEFUN(AC_PATH_LIBRARY,[
2356 AC_MSG_CHECKING([for $2])
2357 AC_CACHE_VAL(ac_cv_path_$1,
2359 ac_found=
2360 ac_dummy="ifelse([$5], , :/usr/local/lib, [$5])"
2361 save_LIBS="$LIBS"
2362 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2363 for ac_dir in $ac_dummy; do
2364 IFS="$ac_save_ifs"
2365 if test -z "$ac_dir"
2366 then
2367 LIBS="$2 $3 $save_LIBS"
2368 else
2369 LIBS="-L$ac_dir $2 $3 $save_LIBS"
2371 AC_TRY_LINK(,,ac_found=1;ac_cv_path_$1="$ac_dir";break)
2372 done
2373 LIBS="$save_LIBS"
2374 ifelse([$4],,,[if test -z "$ac_found"
2375 then
2380 $1="$ac_cv_path_$1"
2381 if test -n "$ac_found" -o -n "[$]$1"
2382 then
2383 AC_MSG_RESULT([$]$1)
2384 else
2385 AC_MSG_RESULT(no)
2387 AC_SUBST($1)
2390 dnl **** Try to find where winelib is located ****
2392 WINE_INCLUDE_ROOT="";
2393 WINE_INCLUDE_PATH="";
2394 WINE_LIBRARY_ROOT="";
2395 WINE_LIBRARY_PATH="";
2396 WINE_TOOL_PATH="";
2397 WINE="";
2398 WINEBUILD="";
2399 WRC="";
2401 AC_ARG_WITH(wine,
2402 [ --with-wine=DIR the Wine package (or sources) is in DIR],
2403 [if test "$withval" != "no"; then
2404 WINE_ROOT="$withval";
2405 WINE_INCLUDES="";
2406 WINE_LIBRARIES="";
2407 WINE_TOOLS="";
2408 else
2409 WINE_ROOT="";
2410 fi])
2411 if test -n "$WINE_ROOT"
2412 then
2413 WINE_INCLUDE_ROOT="$WINE_ROOT/include";
2414 WINE_LIBRARY_ROOT="$WINE_ROOT";
2415 WINE_TOOL_PATH="$WINE_ROOT:$WINE_ROOT/bin:$WINE_ROOT/tools/wrc:$WINE_ROOT/tools/winebuild:$PATH";
2418 AC_ARG_WITH(wine-includes,
2419 [ --with-wine-includes=DIR the Wine includes are in DIR],
2420 [if test "$withval" != "no"; then
2421 WINE_INCLUDES="$withval";
2422 else
2423 WINE_INCLUDES="";
2424 fi])
2425 if test -n "$WINE_INCLUDES"
2426 then
2427 WINE_INCLUDE_ROOT="$WINE_INCLUDES";
2430 AC_ARG_WITH(wine-libraries,
2431 [ --with-wine-libraries=DIR the Wine libraries are in DIR],
2432 [if test "$withval" != "no"; then
2433 WINE_LIBRARIES="$withval";
2434 else
2435 WINE_LIBRARIES="";
2436 fi])
2437 if test -n "$WINE_LIBRARIES"
2438 then
2439 WINE_LIBRARY_ROOT="$WINE_LIBRARIES";
2442 AC_ARG_WITH(wine-tools,
2443 [ --with-wine-tools=DIR the Wine tools are in DIR],
2444 [if test "$withval" != "no"; then
2445 WINE_TOOLS="$withval";
2446 else
2447 WINE_TOOLS="";
2448 fi])
2449 if test -n "$WINE_TOOLS"
2450 then
2451 WINE_TOOL_PATH="$WINE_TOOLS:$WINE_TOOLS/wrc:$WINE_TOOLS/winebuild";
2454 if test -z "$WINE_INCLUDE_ROOT"
2455 then
2456 WINE_INCLUDE_ROOT=":/usr/include/wine:/usr/local/include/wine:/opt/wine/include";
2458 AC_PATH_HEADER(WINE_INCLUDE_ROOT,windef.h,[
2459 AC_MSG_ERROR([Could not find the Wine includes])
2460 ],$WINE_INCLUDE_ROOT)
2461 if test -n "$WINE_INCLUDE_ROOT"
2462 then
2463 WINE_INCLUDE_PATH="-I$WINE_INCLUDE_ROOT"
2464 else
2465 WINE_INCLUDE_PATH=""
2468 if test -z "$WINE_LIBRARY_ROOT"
2469 then
2470 WINE_LIBRARY_ROOT=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib";
2471 else
2472 WINE_LIBRARY_ROOT="$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/lib";
2474 AC_PATH_LIBRARY(WINE_LIBRARY_ROOT,[-lwine],[-lutil],[
2475 AC_MSG_ERROR([Could not find the Wine libraries (libwine.so)])
2476 ],$WINE_LIBRARY_ROOT)
2477 if test -n "$WINE_LIBRARY_ROOT"
2478 then
2479 WINE_LIBRARY_PATH="-L$WINE_LIBRARY_ROOT"
2480 else
2481 WINE_LIBRARY_PATH=""
2483 AC_PATH_LIBRARY(LIBNTDLL_PATH,[-lntdll],[$WINE_LIBRARY_PATH -lwine -lwine_unicode -lncurses -ldl -lutil],[
2484 AC_MSG_ERROR([Could not find the Wine libraries (libntdll.so)])
2485 ],[$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/dlls])
2486 if test -n "$LIBNTDLL_PATH" -a "-L$LIBNTDLL_PATH" != "$WINE_LIBRARY_PATH"
2487 then
2488 WINE_LIBRARY_PATH="$WINE_LIBRARY_PATH -L$LIBNTDLL_PATH"
2491 if test -z "$WINE_TOOL_PATH"
2492 then
2493 WINE_TOOL_PATH="$PATH:/usr/local/bin:/opt/wine/bin";
2495 AC_PATH_PROG(WINE,wine,,$WINE_TOOL_PATH)
2496 if test -z "$WINE"
2497 then
2498 AC_MSG_ERROR([Could not find Wine's wine tool])
2500 AC_PATH_PROG(WINEBUILD,winebuild,,$WINE_TOOL_PATH)
2501 if test -z "$WINEBUILD"
2502 then
2503 AC_MSG_ERROR([Could not find Wine's winebuild tool])
2505 AC_PATH_PROG(WRC,wrc,,$WINE_TOOL_PATH)
2506 if test -z "$WRC"
2507 then
2508 AC_MSG_ERROR([Could not find Wine's wrc tool])
2511 AC_SUBST(WINE_INCLUDE_PATH)
2512 AC_SUBST(WINE_LIBRARY_PATH)
2514 dnl **** Try to find where the MFC are located ****
2515 AC_LANG_CPLUSPLUS()
2517 if test "x$NEEDS_MFC" = "x1"
2518 then
2519 ATL_INCLUDE_ROOT="";
2520 ATL_INCLUDE_PATH="";
2521 MFC_INCLUDE_ROOT="";
2522 MFC_INCLUDE_PATH="";
2523 MFC_LIBRARY_ROOT="";
2524 MFC_LIBRARY_PATH="";
2526 AC_ARG_WITH(mfc,
2527 [ --with-mfc=DIR the MFC package (or sources) is in DIR],
2528 [if test "$withval" != "no"; then
2529 MFC_ROOT="$withval";
2530 ATL_INCLUDES="";
2531 MFC_INCLUDES="";
2532 MFC_LIBRARIES="";
2533 else
2534 MFC_ROOT="";
2535 fi])
2536 if test -n "$MFC_ROOT"
2537 then
2538 ATL_INCLUDE_ROOT="$MFC_ROOT";
2539 MFC_INCLUDE_ROOT="$MFC_ROOT";
2540 MFC_LIBRARY_ROOT="$MFC_ROOT";
2543 AC_ARG_WITH(atl-includes,
2544 [ --with-atl-includes=DIR the ATL includes are in DIR],
2545 [if test "$withval" != "no"; then
2546 ATL_INCLUDES="$withval";
2547 else
2548 ATL_INCLUDES="";
2549 fi])
2550 if test -n "$ATL_INCLUDES"
2551 then
2552 ATL_INCLUDE_ROOT="$ATL_INCLUDES";
2555 AC_ARG_WITH(mfc-includes,
2556 [ --with-mfc-includes=DIR the MFC includes are in DIR],
2557 [if test "$withval" != "no"; then
2558 MFC_INCLUDES="$withval";
2559 else
2560 MFC_INCLUDES="";
2561 fi])
2562 if test -n "$MFC_INCLUDES"
2563 then
2564 MFC_INCLUDE_ROOT="$MFC_INCLUDES";
2567 AC_ARG_WITH(mfc-libraries,
2568 [ --with-mfc-libraries=DIR the MFC libraries are in DIR],
2569 [if test "$withval" != "no"; then
2570 MFC_LIBRARIES="$withval";
2571 else
2572 MFC_LIBRARIES="";
2573 fi])
2574 if test -n "$MFC_LIBRARIES"
2575 then
2576 MFC_LIBRARY_ROOT="$MFC_LIBRARIES";
2579 OLDCPPFLAGS="$CPPFLAGS"
2580 dnl FIXME: We should not have defines in any of the include paths
2581 CPPFLAGS="$WINE_INCLUDE_PATH -I$WINE_INCLUDE_ROOT/mixedcrt -D_DLL -D_MT $CPPFLAGS"
2582 ATL_INCLUDE_PATH="-I\$(WINE_INCLUDE_ROOT)/mixedcrt -D_DLL -D_MT"
2583 if test -z "$ATL_INCLUDE_ROOT"
2584 then
2585 ATL_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/atl:/usr/include/atl:/usr/local/include/atl:/opt/mfc/include/atl:/opt/atl/include"
2586 else
2587 ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT:$ATL_INCLUDE_ROOT/atl:$ATL_INCLUDE_ROOT/atl/include"
2589 AC_PATH_HEADER(ATL_INCLUDE_ROOT,atldef.h,[
2590 AC_MSG_ERROR([Could not find the ATL includes])
2591 ],$ATL_INCLUDE_ROOT)
2592 if test -n "$ATL_INCLUDE_ROOT"
2593 then
2594 ATL_INCLUDE_PATH="$ATL_INCLUDE_PATH -I$ATL_INCLUDE_ROOT"
2597 MFC_INCLUDE_PATH="$ATL_INCLUDE_PATH"
2598 if test -z "$MFC_INCLUDE_ROOT"
2599 then
2600 MFC_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/mfc:/usr/include/mfc:/usr/local/include/mfc:/opt/mfc/include/mfc:/opt/mfc/include"
2601 else
2602 MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT:$MFC_INCLUDE_ROOT/mfc:$MFC_INCLUDE_ROOT/mfc/include"
2604 AC_PATH_HEADER(MFC_INCLUDE_ROOT,afx.h,[
2605 AC_MSG_ERROR([Could not find the MFC includes])
2606 ],$MFC_INCLUDE_ROOT)
2607 if test -n "$MFC_INCLUDE_ROOT" -a "$ATL_INCLUDE_ROOT" != "$MFC_INCLUDE_ROOT"
2608 then
2609 MFC_INCLUDE_PATH="$MFC_INCLUDE_PATH -I$MFC_INCLUDE_ROOT"
2611 CPPFLAGS="$OLDCPPFLAGS"
2613 if test -z "$MFC_LIBRARY_ROOT"
2614 then
2615 MFC_LIBRARY_ROOT=":$WINE_LIBRARY_ROOT:/usr/lib/mfc:/usr/local/lib:/usr/local/lib/mfc:/opt/mfc/lib";
2616 else
2617 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT:$MFC_LIBRARY_ROOT/lib:$MFC_LIBRARY_ROOT/mfc/src";
2619 AC_PATH_LIBRARY(MFC_LIBRARY_ROOT,[-lmfc],[$WINE_LIBRARY_PATH -lwine -lwine_unicode],[
2620 AC_MSG_ERROR([Could not find the MFC library])
2621 ],$MFC_LIBRARY_ROOT)
2622 if test -n "$MFC_LIBRARY_ROOT" -a "$MFC_LIBRARY_ROOT" != "$WINE_LIBRARY_ROOT"
2623 then
2624 MFC_LIBRARY_PATH="-L$MFC_LIBRARY_ROOT"
2625 else
2626 MFC_LIBRARY_PATH=""
2629 AC_SUBST(ATL_INCLUDE_PATH)
2630 AC_SUBST(MFC_INCLUDE_PATH)
2631 AC_SUBST(MFC_LIBRARY_PATH)
2634 AC_LANG_C()
2636 dnl **** Generate output files ****
2638 MAKE_RULES=Make.rules
2639 AC_SUBST_FILE(MAKE_RULES)
2641 AC_OUTPUT([
2642 Make.rules
2643 ##WINEMAKER_PROJECTS##
2646 echo
2647 echo "Configure finished. Do 'make' to build the project."
2648 echo
2650 dnl Local Variables:
2651 dnl comment-start: "dnl "
2652 dnl comment-end: ""
2653 dnl comment-start-skip: "\\bdnl\\b\\s *"
2654 dnl compile-command: "autoconf"
2655 dnl End:
2656 --- Make.rules.in ---
2657 # Copyright 2000 Francois Gouget for CodeWeavers
2658 # fgouget@codeweavers.com
2660 # Global rules shared by all makefiles -*-Makefile-*-
2662 # Each individual makefile must define the following variables:
2663 # WINE_INCLUDE_ROOT: Wine's headers location
2664 # WINE_LIBRARY_ROOT: Wine's libraries location
2665 # TOPOBJDIR : top-level object directory
2666 # SRCDIR : source directory for this module
2668 # Each individual makefile may define the following additional variables:
2670 # SUBDIRS : subdirectories that contain a Makefile
2671 # DLLS : WineLib libraries to be built
2672 # EXES : WineLib executables to be built
2674 # CEXTRA : extra c flags (e.g. '-Wall')
2675 # CXXEXTRA : extra c++ flags (e.g. '-Wall')
2676 # WRCEXTRA : extra wrc flags (e.g. '-p _SysRes')
2677 # DEFINES : defines (e.g. -DSTRICT)
2678 # INCLUDE_PATH : additional include path
2679 # LIBRARY_PATH : additional library path
2680 # LIBRARIES : additional Unix libraries to link with
2682 # C_SRCS : C sources for the module
2683 # CXX_SRCS : C++ sources for the module
2684 # RC_SRCS : resource source files
2685 # SPEC_SRCS : interface definition files
2688 # Where is Winelib
2690 WINE_INCLUDE_ROOT = @WINE_INCLUDE_ROOT@
2691 WINE_INCLUDE_PATH = @WINE_INCLUDE_PATH@
2692 WINE_LIBRARY_ROOT = @WINE_LIBRARY_ROOT@
2693 WINE_LIBRARY_PATH = @WINE_LIBRARY_PATH@
2695 # Where are the MFC
2697 ATL_INCLUDE_ROOT = @ATL_INCLUDE_ROOT@
2698 ATL_INCLUDE_PATH = @ATL_INCLUDE_PATH@
2699 MFC_INCLUDE_ROOT = @MFC_INCLUDE_ROOT@
2700 MFC_INCLUDE_PATH = @MFC_INCLUDE_PATH@
2701 MFC_LIBRARY_ROOT = @MFC_LIBRARY_ROOT@
2702 MFC_LIBRARY_PATH = @MFC_LIBRARY_PATH@
2704 # First some useful definitions
2706 SHELL = /bin/sh
2707 CC = @CC@
2708 CPP = @CPP@
2709 WRC = @WRC@
2710 CFLAGS = @CFLAGS@
2711 CXXFLAGS = @CXXFLAGS@
2712 WRCFLAGS = -r -L
2713 OPTIONS = @OPTIONS@ -D_REENTRANT -DWINELIB
2714 X_CFLAGS = @X_CFLAGS@
2715 X_LIBS = @X_LIBS@
2716 XLIB = @X_PRE_LIBS@ @XLIB@ @X_EXTRA_LIBS@
2717 DLL_LINK = @DLL_LINK@
2718 LIBS = @LIBS@ $(LIBRARY_PATH)
2719 YACC = @YACC@
2720 LEX = @LEX@
2721 LEXLIB = @LEXLIB@
2722 LN_S = @LN_S@
2723 ALLFLAGS = $(DEFINES) -I$(SRCDIR) $(WINE_INCLUDE_PATH) $(INCLUDE_PATH)
2724 ALLCFLAGS = $(CFLAGS) $(CEXTRA) $(OPTIONS) $(X_CFLAGS) $(ALLFLAGS)
2725 ALLCXXFLAGS=$(CXXFLAGS) $(CXXEXTRA) $(OPTIONS) $(X_CFLAGS) $(ALLFLAGS)
2726 ALLWRCFLAGS=$(WRCFLAGS) $(WRCEXTRA) $(OPTIONS) $(ALLFLAGS)
2727 LDCOMBINE = ld -r
2728 LDSHARED = @LDSHARED@
2729 LDDLLFLAGS= @LDDLLFLAGS@
2730 STRIP = strip
2731 STRIPFLAGS= --strip-unneeded
2732 RM = rm -f
2733 MV = mv
2734 MKDIR = mkdir -p
2735 WINE = @WINE@
2736 WINEBUILD = @WINEBUILD@
2737 @SET_MAKE@
2739 # Installation infos
2741 INSTALL = @INSTALL@
2742 INSTALL_PROGRAM = @INSTALL_PROGRAM@
2743 INSTALL_DATA = @INSTALL_DATA@
2744 prefix = @prefix@
2745 exec_prefix = @exec_prefix@
2746 bindir = @bindir@
2747 libdir = @libdir@
2748 infodir = @infodir@
2749 mandir = @mandir@
2750 prog_manext = 1
2751 conf_manext = 5
2753 OBJS = $(C_SRCS:.c=.o) $(CXX_SRCS:.cpp=.o) \
2754 $(SPEC_SRCS:.spec=.spec.o)
2755 CLEAN_FILES = *.spec.c y.tab.c y.tab.h lex.yy.c \
2756 core *.orig *.rej \
2757 \\\#*\\\# *~ *% .\\\#*
2759 # Implicit rules
2761 .SUFFIXES: .cpp .rc .res .tmp.o .spec .spec.c .spec.o
2763 .c.o:
2764 $(CC) -c $(ALLCFLAGS) -o $@ $<
2766 .cpp.o:
2767 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2769 .cxx.o:
2770 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2772 .rc.res:
2773 $(WRC) $(ALLWRCFLAGS) -o $@ $<
2775 .PHONY: all install uninstall clean distclean depend dummy
2777 # 'all' target first in case the enclosing Makefile didn't define any target
2779 all: Makefile
2781 # Rules for makefile
2783 Makefile: Makefile.in $(TOPSRCDIR)/configure
2784 @echo Makefile is older than $?, please rerun $(TOPSRCDIR)/configure
2785 @exit 1
2787 # Rules for cleaning
2789 $(SUBDIRS:%=%/__clean__): dummy
2790 cd `dirname $@` && $(MAKE) clean
2792 $(EXTRASUBDIRS:%=%/__clean__): dummy
2793 -cd `dirname $@` && $(RM) $(CLEAN_FILES)
2795 clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
2796 $(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(OBJS) $(EXES) $(EXES:%=%.so) $(DLLS)
2798 # Rules for installing
2800 $(SUBDIRS:%=%/__install__): dummy
2801 cd `dirname $@` && $(MAKE) install
2803 $(SUBDIRS:%=%/__uninstall__): dummy
2804 cd `dirname $@` && $(MAKE) uninstall
2806 # Misc. rules
2808 $(SUBDIRS): dummy
2809 @cd $@ && $(MAKE)
2811 dummy:
2813 # End of global rules
2814 --- wrapper.c ---
2816 * Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2819 #include <dlfcn.h>
2820 #include <windows.h>
2825 * Describe the wrapped application
2829 * This is either CUIEXE for a console based application or
2830 * GUIEXE for a regular windows application.
2832 #define APP_TYPE ##WINEMAKER_APP_TYPE##
2835 * This is the application library's base name, i.e. 'hello' if the
2836 * library is called 'libhello.so'.
2838 static char* appName = ##WINEMAKER_APP_NAME##;
2841 * This is the name of the application's Windows module. If left NULL
2842 * then appName is used.
2844 static char* appModule = NULL;
2847 * This is the application's entry point. This is usually "WinMain" for a
2848 * GUIEXE and 'main' for a CUIEXE application.
2850 static char* appInit = ##WINEMAKER_APP_INIT##;
2853 * This is either non-NULL for MFC-based applications and is the name of the
2854 * MFC's module. This is the module in which we will take the 'WinMain'
2855 * function.
2857 static char* mfcModule = ##WINEMAKER_APP_MFC##;
2862 * Implement the main.
2865 #if APP_TYPE == GUIEXE
2866 typedef int WINAPI (*WinMainFunc)(HINSTANCE hInstance, HINSTANCE hPrevInstance,
2867 PSTR szCmdLine, int iCmdShow);
2868 #else
2869 typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp);
2870 #endif
2872 #if APP_TYPE == GUIEXE
2873 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
2874 PSTR szCmdLine, int iCmdShow)
2875 #else
2876 int WINAPI Main(int argc, char** argv, char** envp)
2877 #endif
2879 void* appLibrary;
2880 HINSTANCE hApp,hMFC,hMain;
2881 void* appMain;
2882 char* libName;
2883 int retcode;
2885 /* Load the application's library */
2886 libName=(char*)malloc(strlen(appName)+5+3+1);
2887 /* FIXME: we should get the wrapper's path and use that as the base for
2888 * the library
2890 sprintf(libName,"./lib%s.so",appName);
2891 appLibrary=dlopen(libName,RTLD_NOW);
2892 if (appLibrary==NULL) {
2893 sprintf(libName,"lib%s.so",appName);
2894 appLibrary=dlopen(libName,RTLD_NOW);
2896 if (appLibrary==NULL) {
2897 char format[]="Could not load the %s library:\r\n%s";
2898 char* error;
2899 char* msg;
2901 error=dlerror();
2902 msg=(char*)malloc(strlen(format)+strlen(libName)+strlen(error));
2903 sprintf(msg,format,libName,error);
2904 MessageBox(NULL,msg,"dlopen error",MB_OK);
2905 free(msg);
2906 return 1;
2909 /* Then if this application is MFC based, load the MFC module */
2910 /* FIXME: I'm not sure this is really necessary */
2911 if (mfcModule!=NULL) {
2912 hMFC=LoadLibrary(mfcModule);
2913 if (hMFC==NULL) {
2914 char format[]="Could not load the MFC module %s (%d)";
2915 char* msg;
2917 msg=(char*)malloc(strlen(format)+strlen(mfcModule)+11);
2918 sprintf(msg,format,mfcModule,GetLastError());
2919 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
2920 free(msg);
2921 return 1;
2923 /* MFC is a special case: the WinMain is in the MFC library,
2924 * instead of the application's library.
2926 hMain=hMFC;
2927 } else {
2928 hMFC=NULL;
2931 /* Load the application's module */
2932 if (appModule==NULL) {
2933 appModule=appName;
2935 hApp=LoadLibrary(appModule);
2936 if (hApp==NULL) {
2937 char format[]="Could not load the application's module %s (%d)";
2938 char* msg;
2940 msg=(char*)malloc(strlen(format)+strlen(appModule)+11);
2941 sprintf(msg,format,appModule,GetLastError());
2942 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
2943 free(msg);
2944 return 1;
2945 } else if (hMain==NULL) {
2946 hMain=hApp;
2949 /* Get the address of the application's entry point */
2950 appMain=(WinMainFunc*)GetProcAddress(hMain, appInit);
2951 if (appMain==NULL) {
2952 char format[]="Could not get the address of %s (%d)";
2953 char* msg;
2955 msg=(char*)malloc(strlen(format)+strlen(appInit)+11);
2956 sprintf(msg,format,appInit,GetLastError());
2957 MessageBox(NULL,msg,"GetProcAddress error",MB_OK);
2958 free(msg);
2959 return 1;
2962 /* And finally invoke the application's entry point */
2963 #if APP_TYPE == GUIEXE
2964 retcode=(*((WinMainFunc)appMain))(hApp,hPrevInstance,szCmdLine,iCmdShow);
2965 #else
2966 retcode=(*((MainFunc)appMain))(argc,argv,envp);
2967 #endif
2969 /* Cleanup and done */
2970 FreeLibrary(hApp);
2971 if (hMFC!=NULL) {
2972 FreeLibrary(hMFC);
2974 dlclose(appLibrary);
2975 free(libName);
2977 return retcode;