Define environment variable TMP as an alias for TEMP.
[wine.git] / tools / winemaker
blob975a38aa96f6862e27e1cfaa87965d47c60eeeb9
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 odbccp32
732 # 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 $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";
1416 } else {
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";
1430 print FILEO "\n";
1431 my %imports;
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";
1460 } else {
1461 print FILEO "\n@ stdcall @$target[$T_INIT](ptr long ptr) @$target[$T_INIT]\n";
1465 close(FILEO);
1469 # Generates a target's wrapper file
1470 sub generate_wrapper_file
1472 my $path=$_[0];
1473 my $target=$_[1];
1475 if (!defined $templates{"wrapper.c"}) {
1476 print STDERR "winemaker: internal error: No template called 'wrapper.c'\n";
1477 return;
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";
1483 return;
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/;
1494 print FILEO $line;
1496 close(FILEO);
1500 # A convenience function to generate all the lists (defines,
1501 # C sources, C++ source, etc.) in the Makefile
1502 sub generate_list
1504 my $name=$_[0];
1505 my $last=$_[1];
1506 my $list=$_[2];
1507 my $data=$_[3];
1508 my $first=$name;
1510 if ($name) {
1511 printf FILEO "%-22s=",$name;
1513 if (defined $list) {
1514 foreach $item (@$list) {
1515 my $value;
1516 if (defined $data) {
1517 $value=&$data($item);
1518 } else {
1519 $value=$item;
1521 if ($value ne "") {
1522 if ($first) {
1523 print FILEO " $value";
1524 $first=0;
1525 } else {
1526 print FILEO " \\\n\t\t\t$value";
1531 if ($last) {
1532 print FILEO "\n";
1537 # Generates a project's Makefile.in and all the target files
1538 sub generate_project_files
1540 my $project=$_[0];
1541 my $project_settings=@$project[$P_SETTINGS];
1542 my @dll_list=();
1543 my @exe_list=();
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;
1549 } else {
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";
1560 return;
1563 print FILEO "### Generated by Winemaker\n";
1564 print FILEO "\n\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\@" ]);
1571 print FILEO "\n";
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];
1579 $subdir =~ s+/$++;
1580 return $subdir;
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
1600 return "$_[0]";
1602 generate_list("",1,$global_settings[$T_DEFINES],sub
1604 return "$_[0]";
1606 generate_list("INCLUDE_PATH",$no_extra,@$project_settings[$T_INCLUDE_PATH],sub
1608 return "$_[0]";
1610 generate_list("",1,$global_settings[$T_INCLUDE_PATH],sub
1612 if ($_[0] !~ /^-I/) {
1613 return "$_[0]";
1615 if (is_absolute($')) {
1616 return "$_[0]";
1618 return "-I\$(TOPSRCDIR)/$'";
1620 generate_list("LIBRARY_PATH",$no_extra,@$project_settings[$T_LIBRARY_PATH],sub
1622 return "$_[0]";
1624 generate_list("",1,$global_settings[$T_LIBRARY_PATH],sub
1626 if ($_[0] !~ /^-L/) {
1627 return "$_[0]";
1629 if (is_absolute($')) {
1630 return "$_[0]";
1632 return "-L\$(TOPSRCDIR)/$'";
1634 generate_list("LIBRARIES",$no_extra,@$project_settings[$T_LIBRARIES],sub
1636 return "$_[0]";
1638 generate_list("",1,$global_settings[$T_LIBRARIES],sub
1640 return "$_[0]";
1642 print FILEO "\n\n";
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);
1648 if (!$no_extra) {
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]);
1653 print FILEO "\n";
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]");
1662 $canon =~ s+_so$++;
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
1676 return "$_[0]";
1678 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES],sub
1680 return "$_[0]";
1682 generate_list("${canon}_DEPENDS",1,@$target[$T_DEPENDS],sub
1684 return "$_[0]";
1686 print FILEO "\n";
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]);
1694 $canon =~ s+_so$++;
1695 return "\$(${canon}_C_SRCS)";
1697 if (!$no_extra) {
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]);
1703 $canon =~ s+_so$++;
1704 return "\$(${canon}_CXX_SRCS)";
1706 if (!$no_extra) {
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]);
1712 $canon =~ s+_so$++;
1713 return "\$(${canon}_RC_SRCS)";
1715 if (!$no_extra) {
1716 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
1718 generate_list("SPEC_SRCS",1,@$project[$P_TARGETS],sub
1720 my $canon=canonize(@{$_[0]}[$T_NAME]);
1721 $canon =~ s+_so$++;
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)";
1735 print FILEO "\n\n";
1736 print FILEO "\@MAKE_RULES\@\n";
1737 print FILEO "\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";
1748 print FILEO "\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]");
1765 $canon =~ s/_so$//;
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";
1769 print FILEO "\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";
1772 print FILEO "\n";
1773 my $t_name=@$target[$T_NAME];
1774 if (@$target[$T_TYPE]!=$TT_DLL) {
1775 $t_name.=".so";
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";
1782 print FILEO "\n\n";
1785 close(FILEO);
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
1800 my $filename=$_[0];
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";
1807 return 0;
1810 if (!open(FILEO,">$filename")) {
1811 print STDERR "error: unable to open \"$filename\" for writing:\n";
1812 print STDERR " $!\n";
1813 return 0;
1815 foreach $line (@{$templates{$filename}}) {
1816 if ($line =~ /^\#\#WINEMAKER_PROJECTS\#\#$/) {
1817 foreach $project (@projects) {
1818 print FILEO "@$project[$P_PATH]Makefile\n";
1820 } else {
1821 $line =~ s+\#\#WINEMAKER_SOURCE\#\#+$a_source_file+;
1822 $line =~ s+\#\#WINEMAKER_NEEDS_MFC\#\#+$needs_mfc+;
1823 print FILEO $line;
1826 close(FILEO);
1827 return 1;
1830 sub generate_generic
1832 my $filename=$_[0];
1834 if (!defined $templates{$filename}) {
1835 print STDERR "winemaker: internal error: No template called '$filename'\n";
1836 return;
1838 if (!open(FILEO,">$filename")) {
1839 print STDERR "error: unable to open \"$filename\" for writing:\n";
1840 print STDERR " $!\n";
1841 return;
1843 foreach $line (@{$templates{$filename}}) {
1844 print FILEO $line;
1846 close(FILEO);
1850 # Generates the global files:
1851 # configure
1852 # configure.in
1853 # Make.rules.in
1854 sub generate_global_files
1856 generate_generic("Make.rules.in");
1858 # Get the name of a source file for configure.in
1859 my $a_source_file;
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";
1871 last search_a_file;
1876 generate_configure("configure.in",$a_source_file);
1877 unlink("configure");
1878 if (generate_configure("configure",$a_source_file) == 0) {
1879 system("autoconf");
1881 # Add execute permission to configure for whoever has the right to read it
1882 my @st=stat("configure");
1883 if (defined @st) {
1884 my $mode=$st[2];
1885 $mode|=($mode & 0444) >>2;
1886 chmod($mode,"configure");
1887 } else {
1888 print "warning: could not generate the configure script. You need to run autoconf\n";
1894 sub generate_read_templates
1896 my $file;
1898 while (<DATA>) {
1899 if (/^--- ((\w\.?)+) ---$/) {
1900 my $filename=$1;
1901 if (defined $templates{$filename}) {
1902 print STDERR "winemaker: internal error: There is more than one template for $filename\n";
1903 undef $file;
1904 } else {
1905 $file=[];
1906 $templates{$filename}=$file;
1908 } elsif (defined $file) {
1909 push @$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.
1917 sub generate
1919 print "Generating project files...\n";
1920 generate_read_templates();
1921 generate_global_files();
1923 foreach $project (@projects) {
1924 my $path=@$project[$P_PATH];
1925 if ($path eq "") {
1926 $path=".";
1927 } else {
1928 $path =~ s+/$++;
1930 print " $path\n";
1931 generate_project_files($project);
1937 #####
1939 # Option defaults
1941 #####
1943 $opt_backup=1;
1944 $opt_lower=$OPT_LOWER_UPPERCASE;
1945 $opt_lower_include=1;
1947 # $opt_single_target=<undefined>
1948 $opt_target_type=$TT_GUIEXE;
1949 $opt_flags=0;
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;
1954 $opt_no_banner=0;
1958 #####
1960 # Main
1962 #####
1964 project_init(\@main_project,"");
1966 while (@ARGV>0) {
1967 my $arg=shift @ARGV;
1968 # General options
1969 if ($arg eq "--nobanner") {
1970 $opt_no_banner=1;
1971 } elsif ($arg eq "--backup") {
1972 $opt_backup=1;
1973 } elsif ($arg eq "--nobackup") {
1974 $opt_backup=0;
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;
2022 $needs_mfc=1;
2023 } elsif ($arg eq "--nomfc") {
2024 $opt_flags&=~($TF_MFC|$TF_WRAP);
2025 $needs_mfc=0;
2027 # Catch errors
2028 } else {
2029 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2030 print STDERR "Unknown option: $arg\n";
2032 $usage=1;
2033 last;
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";
2051 exit (2);
2054 # Fix the file and directory names
2055 fix_file_and_directory_names(".");
2057 # Scan the sources to identify the projects and targets
2058 source_scan();
2060 # Create targets for wrappers, etc.
2061 postprocess_targets();
2063 # Fix the source files
2064 fix_source();
2066 # Generate the Makefile and the spec file
2067 if (! $opt_no_generated_files) {
2068 generate();
2072 __DATA__
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 ****
2086 AC_SUBST(OPTIONS)
2088 dnl **** Check for some programs ****
2090 AC_PROG_MAKE_SET
2091 AC_PROG_CC
2092 AC_PROG_CXX
2093 AC_PROG_CPP
2094 AC_PATH_XTRA
2095 AC_PROG_RANLIB
2096 AC_PROG_LN_S
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)
2121 LIBS="$LIBS -lutil"
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)
2129 LIBS="$LIBS -ldl",
2134 dnl **** Check which curses lib to use ***
2135 if test "$CURSES" = "yes"
2136 then
2137 AC_CHECK_HEADERS(ncurses.h)
2138 if test "$ac_cv_header_ncurses_h" = "yes"
2139 then
2140 AC_CHECK_LIB(ncurses,waddch)
2142 if test "$ac_cv_lib_ncurses_waddch" = "yes"
2143 then
2144 AC_CHECK_LIB(ncurses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2145 AC_CHECK_LIB(ncurses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2146 else
2147 AC_CHECK_HEADERS(curses.h)
2148 if test "$ac_cv_header_curses_h" = "yes"
2149 then
2150 AC_CHECK_LIB(curses,waddch)
2151 if test "$ac_cv_lib_curses_waddch" = "yes"
2152 then
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"
2166 then
2167 AC_CACHE_CHECK( "for gcc strength-reduce bug", ac_cv_c_gcc_strength_bug,
2168 AC_TRY_RUN([
2169 int main(void) {
2170 static int Array[[3]];
2171 unsigned int B = 3;
2172 int i;
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"
2180 then
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,
2189 [saved_libs=$LIBS
2190 LIBS="conftest_asm.s $LIBS"
2191 cat > conftest_asm.s <<EOF
2192 .globl _ac_test
2193 _ac_test:
2194 .long 0
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")
2198 LIBS=$saved_libs])
2199 if test "$ac_cv_c_extern_prefix" = "yes"
2200 then
2201 AC_DEFINE(NEED_UNDERSCORE_PREFIX)
2204 dnl **** Check for working dll ****
2206 LDSHARED=""
2207 LDDLLFLAGS=""
2208 AC_CACHE_CHECK("whether we can build a Linux dll",
2209 ac_cv_c_dll_linux,
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"
2216 then
2217 LDSHARED="\$(CC) -shared -Wl,-rpath,\$(libdir)"
2218 LDDLLFLAGS="-Wl,-Bsymbolic"
2219 else
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"
2228 then
2229 LDSHARED="\$(CC) -Wl,-G \$(SONAME:%=-Wl,h,\$(libdir)/%)"#FIXME: why SONAME here?
2230 LDDLLFLAGS="-Wl,-B,symbolic"
2231 else
2232 AC_CACHE_CHECK("whether we can build a NetBSD dll",
2233 ac_cv_c_dll_netbsd,
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"
2240 then
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"
2247 then
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 -luuid"
2254 AC_SUBST(DLL_LINK)
2255 AC_SUBST(LDSHARED)
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__)
2263 #endif],
2264 ac_cv_cpp_def_i386="yes", ac_cv_cpp_def_i386="no"))
2265 if test "$ac_cv_cpp_def_i386" = "yes"
2266 then
2267 CFLAGS="$CFLAGS -D__i386__"
2270 dnl $GCC is set by autoconf
2271 GCC_NO_BUILTIN=""
2272 if test "$GCC" = "yes"
2273 then
2274 GCC_NO_BUILTIN="-fno-builtin"
2276 AC_SUBST(GCC_NO_BUILTIN)
2278 dnl **** Test Winelib-related features of the C++ compiler
2279 AC_LANG_CPLUSPLUS()
2280 if test "x${GCC}" = "xyes"
2281 then
2282 OLDCXXFLAGS="$CXXFLAGS";
2283 CXXFLAGS="-fpermissive";
2284 AC_CACHE_CHECK("for g++ -fpermissive option", has_gxx_permissive,
2285 AC_TRY_COMPILE(,[
2286 for (int i=0;i<2;i++);
2287 i=0;
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,
2294 AC_TRY_COMPILE(,[
2295 for (int i=0;i<2;i++);
2296 i=0;
2298 [has_gxx_no_for_scope="yes"],
2299 [has_gxx_no_for_scope="no"])
2301 CXXFLAGS="$OLDCXXFLAGS";
2302 if test "$has_gxx_permissive" = "yes"
2303 then
2304 CXXFLAGS="$CXXFLAGS -fpermissive"
2306 if test "$has_gxx_no_for_scope" = "yes"
2307 then
2308 CXXFLAGS="$CXXFLAGS -fno-for-scope"
2311 AC_LANG_C()
2313 dnl **** Test Winelib-related features of the C compiler
2314 dnl none for now
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,
2325 ac_found=
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
2330 IFS="$ac_save_ifs"
2331 if test -z "$ac_dir"
2332 then
2333 CPPFLAGS="$save_CPPFLAGS"
2334 else
2335 CPPFLAGS="-I$ac_dir $save_CPPFLAGS"
2337 AC_TRY_COMPILE([#include <$2>],,ac_found=1;ac_cv_path_$1="$ac_dir";break)
2338 done
2339 CPPFLAGS="$save_CPPFLAGS"
2340 ifelse([$3],,,[if test -z "$ac_found"
2341 then
2346 $1="$ac_cv_path_$1"
2347 if test -n "$ac_found" -o -n "[$]$1"
2348 then
2349 AC_MSG_RESULT([$]$1)
2350 else
2351 AC_MSG_RESULT(no)
2353 AC_SUBST($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,
2361 ac_found=
2362 ac_dummy="ifelse([$5], , :/usr/local/lib, [$5])"
2363 save_LIBS="$LIBS"
2364 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2365 for ac_dir in $ac_dummy; do
2366 IFS="$ac_save_ifs"
2367 if test -z "$ac_dir"
2368 then
2369 LIBS="$2 $3 $save_LIBS"
2370 else
2371 LIBS="-L$ac_dir $2 $3 $save_LIBS"
2373 AC_TRY_LINK(,,ac_found=1;ac_cv_path_$1="$ac_dir";break)
2374 done
2375 LIBS="$save_LIBS"
2376 ifelse([$4],,,[if test -z "$ac_found"
2377 then
2382 $1="$ac_cv_path_$1"
2383 if test -n "$ac_found" -o -n "[$]$1"
2384 then
2385 AC_MSG_RESULT([$]$1)
2386 else
2387 AC_MSG_RESULT(no)
2389 AC_SUBST($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="";
2398 WINE_TOOL_PATH="";
2399 WINE="";
2400 WINEBUILD="";
2401 WRC="";
2403 AC_ARG_WITH(wine,
2404 [ --with-wine=DIR the Wine package (or sources) is in DIR],
2405 [if test "$withval" != "no"; then
2406 WINE_ROOT="$withval";
2407 WINE_INCLUDES="";
2408 WINE_LIBRARIES="";
2409 WINE_TOOLS="";
2410 else
2411 WINE_ROOT="";
2412 fi])
2413 if test -n "$WINE_ROOT"
2414 then
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";
2424 else
2425 WINE_INCLUDES="";
2426 fi])
2427 if test -n "$WINE_INCLUDES"
2428 then
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";
2436 else
2437 WINE_LIBRARIES="";
2438 fi])
2439 if test -n "$WINE_LIBRARIES"
2440 then
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";
2448 else
2449 WINE_TOOLS="";
2450 fi])
2451 if test -n "$WINE_TOOLS"
2452 then
2453 WINE_TOOL_PATH="$WINE_TOOLS:$WINE_TOOLS/wrc:$WINE_TOOLS/winebuild";
2456 if test -z "$WINE_INCLUDE_ROOT"
2457 then
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"
2464 then
2465 WINE_INCLUDE_PATH="-I$WINE_INCLUDE_ROOT"
2466 else
2467 WINE_INCLUDE_PATH=""
2470 if test -z "$WINE_LIBRARY_ROOT"
2471 then
2472 WINE_LIBRARY_ROOT=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib";
2473 else
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"
2480 then
2481 WINE_LIBRARY_PATH="-L$WINE_LIBRARY_ROOT"
2482 else
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"
2489 then
2490 WINE_LIBRARY_PATH="$WINE_LIBRARY_PATH -L$LIBNTDLL_PATH"
2493 if test -z "$WINE_TOOL_PATH"
2494 then
2495 WINE_TOOL_PATH="$PATH:/usr/local/bin:/opt/wine/bin";
2497 AC_PATH_PROG(WINE,wine,,$WINE_TOOL_PATH)
2498 if test -z "$WINE"
2499 then
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"
2504 then
2505 AC_MSG_ERROR([Could not find Wine's winebuild tool])
2507 AC_PATH_PROG(WRC,wrc,,$WINE_TOOL_PATH)
2508 if test -z "$WRC"
2509 then
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 ****
2517 AC_LANG_CPLUSPLUS()
2519 if test "x$NEEDS_MFC" = "x1"
2520 then
2521 ATL_INCLUDE_ROOT="";
2522 ATL_INCLUDE_PATH="";
2523 MFC_INCLUDE_ROOT="";
2524 MFC_INCLUDE_PATH="";
2525 MFC_LIBRARY_ROOT="";
2526 MFC_LIBRARY_PATH="";
2528 AC_ARG_WITH(mfc,
2529 [ --with-mfc=DIR the MFC package (or sources) is in DIR],
2530 [if test "$withval" != "no"; then
2531 MFC_ROOT="$withval";
2532 ATL_INCLUDES="";
2533 MFC_INCLUDES="";
2534 MFC_LIBRARIES="";
2535 else
2536 MFC_ROOT="";
2537 fi])
2538 if test -n "$MFC_ROOT"
2539 then
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";
2549 else
2550 ATL_INCLUDES="";
2551 fi])
2552 if test -n "$ATL_INCLUDES"
2553 then
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";
2561 else
2562 MFC_INCLUDES="";
2563 fi])
2564 if test -n "$MFC_INCLUDES"
2565 then
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";
2573 else
2574 MFC_LIBRARIES="";
2575 fi])
2576 if test -n "$MFC_LIBRARIES"
2577 then
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"
2586 then
2587 ATL_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/atl:/usr/include/atl:/usr/local/include/atl:/opt/mfc/include/atl:/opt/atl/include"
2588 else
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"
2595 then
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"
2601 then
2602 MFC_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/mfc:/usr/include/mfc:/usr/local/include/mfc:/opt/mfc/include/mfc:/opt/mfc/include"
2603 else
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"
2610 then
2611 MFC_INCLUDE_PATH="$MFC_INCLUDE_PATH -I$MFC_INCLUDE_ROOT"
2613 CPPFLAGS="$OLDCPPFLAGS"
2615 if test -z "$MFC_LIBRARY_ROOT"
2616 then
2617 MFC_LIBRARY_ROOT=":$WINE_LIBRARY_ROOT:/usr/lib/mfc:/usr/local/lib:/usr/local/lib/mfc:/opt/mfc/lib";
2618 else
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"
2625 then
2626 MFC_LIBRARY_PATH="-L$MFC_LIBRARY_ROOT"
2627 else
2628 MFC_LIBRARY_PATH=""
2631 AC_SUBST(ATL_INCLUDE_PATH)
2632 AC_SUBST(MFC_INCLUDE_PATH)
2633 AC_SUBST(MFC_LIBRARY_PATH)
2636 AC_LANG_C()
2638 dnl **** Generate output files ****
2640 MAKE_RULES=Make.rules
2641 AC_SUBST_FILE(MAKE_RULES)
2643 AC_OUTPUT([
2644 Make.rules
2645 ##WINEMAKER_PROJECTS##
2648 echo
2649 echo "Configure finished. Do 'make' to build the project."
2650 echo
2652 dnl Local Variables:
2653 dnl comment-start: "dnl "
2654 dnl comment-end: ""
2655 dnl comment-start-skip: "\\bdnl\\b\\s *"
2656 dnl compile-command: "autoconf"
2657 dnl End:
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
2690 # Where is Winelib
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@
2697 # Where are the MFC
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
2708 SHELL = /bin/sh
2709 CC = @CC@
2710 CPP = @CPP@
2711 WRC = @WRC@
2712 CFLAGS = @CFLAGS@
2713 CXXFLAGS = @CXXFLAGS@
2714 WRCFLAGS = -r -L
2715 OPTIONS = @OPTIONS@ -D_REENTRANT -DWINELIB
2716 X_CFLAGS = @X_CFLAGS@
2717 X_LIBS = @X_LIBS@
2718 XLIB = @X_PRE_LIBS@ @XLIB@ @X_EXTRA_LIBS@
2719 DLL_LINK = @DLL_LINK@
2720 LIBS = @LIBS@ $(LIBRARY_PATH)
2721 YACC = @YACC@
2722 LEX = @LEX@
2723 LEXLIB = @LEXLIB@
2724 LN_S = @LN_S@
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)
2729 LDCOMBINE = ld -r
2730 LDSHARED = @LDSHARED@
2731 LDDLLFLAGS= @LDDLLFLAGS@
2732 STRIP = strip
2733 STRIPFLAGS= --strip-unneeded
2734 RM = rm -f
2735 MV = mv
2736 MKDIR = mkdir -p
2737 WINE = @WINE@
2738 WINEBUILD = @WINEBUILD@
2739 @SET_MAKE@
2741 # Installation infos
2743 INSTALL = @INSTALL@
2744 INSTALL_PROGRAM = @INSTALL_PROGRAM@
2745 INSTALL_DATA = @INSTALL_DATA@
2746 prefix = @prefix@
2747 exec_prefix = @exec_prefix@
2748 bindir = @bindir@
2749 libdir = @libdir@
2750 infodir = @infodir@
2751 mandir = @mandir@
2752 prog_manext = 1
2753 conf_manext = 5
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 \
2758 core *.orig *.rej \
2759 \\\#*\\\# *~ *% .\\\#*
2761 # Implicit rules
2763 .SUFFIXES: .cpp .rc .res .tmp.o .spec .spec.c .spec.o
2765 .c.o:
2766 $(CC) -c $(ALLCFLAGS) -o $@ $<
2768 .cpp.o:
2769 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2771 .cxx.o:
2772 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2774 .rc.res:
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
2781 all: Makefile
2783 # Rules for makefile
2785 Makefile: Makefile.in $(TOPSRCDIR)/configure
2786 @echo Makefile is older than $?, please rerun $(TOPSRCDIR)/configure
2787 @exit 1
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
2808 # Misc. rules
2810 $(SUBDIRS): dummy
2811 @cd $@ && $(MAKE)
2813 dummy:
2815 # End of global rules
2816 --- wrapper.c ---
2818 * Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2821 #include <dlfcn.h>
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'
2857 * function.
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);
2870 #else
2871 typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp);
2872 #endif
2874 #if APP_TYPE == GUIEXE
2875 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
2876 PSTR szCmdLine, int iCmdShow)
2877 #else
2878 int WINAPI Main(int argc, char** argv, char** envp)
2879 #endif
2881 void* appLibrary;
2882 HINSTANCE hApp,hMFC,hMain;
2883 void* appMain;
2884 char* libName;
2885 int retcode;
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
2890 * the library
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";
2900 char* error;
2901 char* msg;
2903 error=dlerror();
2904 msg=(char*)malloc(strlen(format)+strlen(libName)+strlen(error));
2905 sprintf(msg,format,libName,error);
2906 MessageBox(NULL,msg,"dlopen error",MB_OK);
2907 free(msg);
2908 return 1;
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);
2915 if (hMFC==NULL) {
2916 char format[]="Could not load the MFC module %s (%d)";
2917 char* msg;
2919 msg=(char*)malloc(strlen(format)+strlen(mfcModule)+11);
2920 sprintf(msg,format,mfcModule,GetLastError());
2921 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
2922 free(msg);
2923 return 1;
2925 /* MFC is a special case: the WinMain is in the MFC library,
2926 * instead of the application's library.
2928 hMain=hMFC;
2929 } else {
2930 hMFC=NULL;
2933 /* Load the application's module */
2934 if (appModule==NULL) {
2935 appModule=appName;
2937 hApp=LoadLibrary(appModule);
2938 if (hApp==NULL) {
2939 char format[]="Could not load the application's module %s (%d)";
2940 char* msg;
2942 msg=(char*)malloc(strlen(format)+strlen(appModule)+11);
2943 sprintf(msg,format,appModule,GetLastError());
2944 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
2945 free(msg);
2946 return 1;
2947 } else if (hMain==NULL) {
2948 hMain=hApp;
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)";
2955 char* msg;
2957 msg=(char*)malloc(strlen(format)+strlen(appInit)+11);
2958 sprintf(msg,format,appInit,GetLastError());
2959 MessageBox(NULL,msg,"GetProcAddress error",MB_OK);
2960 free(msg);
2961 return 1;
2964 /* And finally invoke the application's entry point */
2965 #if APP_TYPE == GUIEXE
2966 retcode=(*((WinMainFunc)appMain))(hApp,hPrevInstance,szCmdLine,iCmdShow);
2967 #else
2968 retcode=(*((MainFunc)appMain))(argc,argv,envp);
2969 #endif
2971 /* Cleanup and done */
2972 FreeLibrary(hApp);
2973 if (hMFC!=NULL) {
2974 FreeLibrary(hMFC);
2976 dlclose(appLibrary);
2977 free(libName);
2979 return retcode;