Removed calls to internal (non-exported) wine functions.
[wine.git] / tools / winemaker
blobdd04af6f9610e9a938de31f528005e281c47283e
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 =~ /^--no-wrap/) {
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 =~ /^--no-mfc/) {
416 @$target[$T_FLAGS]&=~($TF_MFC|$TF_WRAP);
417 } else {
418 print STDERR "warning: unknown option \"$option\", ignoring it\n";
424 # Scans the specified directory to:
425 # - see if we should create a Makefile in this directory. We normally do
426 # so if we find a project file and sources
427 # - get a list of targets for this directory
428 # - get the list of source files
429 sub source_scan_directory
431 # a reference to the parent's project
432 my $parent_project=$_[0];
433 # the full relative path to the current directory, including a
434 # trailing '/', or an empty string if this is the top level directory
435 my $path=$_[1];
436 # the name of this directory, including a trailing '/', or an empty
437 # string if this is the top level directory
438 my $dirname=$_[2];
440 # reference to the project for this directory. May not be used
441 my $project;
442 # list of targets found in the 'current' directory
443 my %targets;
444 # list of sources found in the current directory
445 my @sources_c=();
446 my @sources_cxx=();
447 my @sources_rc=();
448 my @sources_misc=();
449 # true if this directory contains a Windows project
450 my $has_win_project=0;
451 # If we don't find any executable/library then we might make up targets
452 # from the list of .dsp/.mak files we find since they usually have the
453 # same name as their target.
454 my @dsp_files=();
455 my @mak_files=();
457 if (defined $opt_single_target or $dirname eq "") {
458 # Either there is a single target and thus a single project,
459 # or we are in the top level directory for which a project
460 # already exists
461 $project=$parent_project;
462 } else {
463 $project=[];
464 project_init($project,$path);
466 my $project_settings=@$project[$P_SETTINGS];
468 # First find out what this directory contains:
469 # collect all sources, targets and subdirectories
470 my $directory=get_directory_contents($path);
471 foreach $dentry (@$directory) {
472 if ($dentry =~ /^\./) {
473 next;
475 my $fullentry="$path$dentry";
476 if (-d "$fullentry") {
477 if ($dentry =~ /^(Release|Debug)/i) {
478 # These directories are often used to store the object files and the
479 # resulting executable/library. They should not contain anything else.
480 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
481 foreach $candidate (@candidates) {
482 if ($candidate =~ s/\.exe$//i) {
483 $targets{$candidate}=1;
484 } elsif ($candidate =~ s/^(.*)\.dll$/lib$1.so/i) {
485 $targets{$candidate}=1;
488 } else {
489 # Recursively scan this directory. Any source file that cannot be
490 # attributed to a project in one of the subdirectories will be attributed
491 # to this project.
492 source_scan_directory($project,"$fullentry/","$dentry/");
494 } elsif (-f "$fullentry") {
495 if ($dentry =~ s/\.exe$//i) {
496 $targets{$dentry}=1;
497 } elsif ($dentry =~ s/^(.*)\.dll$/lib$1.so/i) {
498 $targets{$dentry}=1;
499 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.spec\.c$/) {
500 push @sources_c,"$dentry";
501 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
502 if ($dentry =~ /^stdafx.cpp$/i) {
503 push @sources_misc,"$dentry";
504 @$project_settings[$T_FLAGS]|=$TF_MFC|$TF_WRAP;
505 } else {
506 push @sources_cxx,"$dentry";
508 } elsif ($dentry =~ /\.rc$/i) {
509 push @sources_rc,"$dentry";
510 } elsif ($dentry =~ /\.(h|hxx|inl|rc2|dlg)$/i) {
511 push @sources_misc,"$dentry";
512 if ($dentry =~ /^stdafx.h$/i) {
513 @$project_settings[$T_FLAGS]|=$TF_MFC|$TF_WRAP;
515 } elsif ($dentry =~ /\.dsp$/i) {
516 push @dsp_files,"$dentry";
517 $has_win_project=1;
518 } elsif ($dentry =~ /\.mak$/i) {
519 push @mak_files,"$dentry";
520 $has_win_project=1;
521 } elsif ($dentry =~ /^makefile/i) {
522 $has_win_project=1;
526 closedir(DIRECTORY);
528 # If we have a single target then all we have to do is assign
529 # all the sources to it and we're done
530 # FIXME: does this play well with the --interactive mode?
531 if ($opt_single_target) {
532 my $target=@{@$project[$P_TARGETS]}[0];
533 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
534 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
535 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
536 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
537 return;
540 my $source_count=@sources_c+@sources_cxx+@sources_rc+
541 @{@$project_settings[$T_SOURCES_C]}+
542 @{@$project_settings[$T_SOURCES_CXX]}+
543 @{@$project_settings[$T_SOURCES_RC]};
544 if ($source_count == 0) {
545 # A project without real sources is not a project, get out!
546 if ($project!=$parent_project) {
547 $parent_settings=@$parent_project[$P_SETTINGS];
548 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
549 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
551 return;
553 #print "targets=",%targets,"\n";
554 #print "target_count=$target_count\n";
555 #print "has_win_project=$has_win_project\n";
556 #print "dirname=$dirname\n";
558 my $target_count;
559 if (($has_win_project != 0) or ($dirname eq "")) {
560 # Deal with cases where we could not find any executable/library, and
561 # thus have no target, although we did find some sort of windows project.
562 $target_count=keys %targets;
563 if ($target_count == 0) {
564 # Try to come up with a target list based on .dsp/.mak files
565 my $prj_list;
566 if (@dsp_files > 0) {
567 $prj_list=\@dsp_files;
568 } else {
569 $prj_list=\@mak_files;
571 foreach $filename (@$prj_list) {
572 $filename =~ s/\.(dsp|mak)$//i;
573 if ($opt_target_type == $TT_DLL) {
574 $filename = "lib$filename.so";
576 $targets{$filename}=1;
578 $target_count=keys %targets;
579 if ($target_count == 0) {
580 # Still nothing, try the name of the directory
581 my $name;
582 if ($dirname eq "") {
583 # Bad luck, this is the top level directory!
584 $name=(split /\//, cwd)[-1];
585 } else {
586 $name=$dirname;
587 # Remove the trailing '/'. Also eliminate whatever is after the last
588 # '.' as it is likely to be meaningless (.orig, .new, ...)
589 $name =~ s+(/|\.[^.]*)$++;
590 if ($name eq "src") {
591 # 'src' is probably a subdirectory of the real project directory.
592 # Try again with the parent (if any).
593 my $parent=$path;
594 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
595 $name=$parent;
596 } else {
597 $name=(split /\//, cwd)[-1];
601 $name =~ s+(/|\.[^.]*)$++;
602 if ($opt_target_type == $TT_DLL) {
603 $name = "lib$name.so";
605 $targets{$name}=1;
609 # Ask confirmation to the user if he wishes so
610 if ($opt_is_interactive == $OPT_ASK_YES) {
611 my $target_list=join " ",keys %targets;
612 print "\n*** In $path\n";
613 print "* winemaker found the following list of (potential) targets\n";
614 print "* $target_list\n";
615 print "* Type enter to use it as is, your own comma-separated list of\n";
616 print "* targets, 'none' to assign the source files to a parent directory,\n";
617 print "* or 'ignore' to ignore everything in this directory tree.\n";
618 print "* Target list:\n";
619 $target_list=<STDIN>;
620 chomp $target_list;
621 if ($target_list eq "") {
622 # Keep the target list as is, i.e. do nothing
623 } elsif ($target_list eq "none") {
624 # Empty the target list
625 undef %targets;
626 } elsif ($target_list eq "ignore") {
627 # Ignore this subtree altogether
628 return;
629 } else {
630 undef %targets;
631 foreach $target (split /,/,$target_list) {
632 $target =~ s+^\s*++;
633 $target =~ s+\s*$++;
634 # Also accept .exe and .dll as a courtesy
635 $target =~ s+(.*)\.dll$+lib$1.so+;
636 $target =~ s+\.exe$++;
637 $targets{$target}=1;
643 # If we have no project at this level, then transfer all
644 # the sources to the parent project
645 $target_count=keys %targets;
646 if ($target_count == 0) {
647 if ($project!=$parent_project) {
648 my $parent_settings=@$parent_project[$P_SETTINGS];
649 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
650 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
651 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
652 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
653 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
655 return;
658 # Otherwise add this project to the project list, except for
659 # the main project which is already in the list.
660 if ($dirname ne "") {
661 push @projects,$project;
664 # Ask for project-wide options
665 if ($opt_ask_project_options == $OPT_ASK_YES) {
666 my $flag_desc="";
667 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
668 $flag_desc="mfc";
670 if ((@$project_settings[$T_FLAGS] & $TF_WRAP)!=0) {
671 if ($flag_desc ne "") {
672 $flag_desc.=", ";
674 $flag_desc.="wrapped";
676 print "* Type any project-wide options (-D/-I/-L/-l/--mfc/--wrap),\n";
677 if (defined $flag_desc) {
678 print "* (currently $flag_desc)\n";
680 print "* or 'skip' to skip the target specific options,\n";
681 print "* or 'never' to not be asked this question again:\n";
682 my $options=<STDIN>;
683 chomp $options;
684 if ($options eq "skip") {
685 $opt_ask_target_options=$OPT_ASK_SKIP;
686 } elsif ($options eq "never") {
687 $opt_ask_project_options="never";
688 } else {
689 source_set_options($project_settings,$options);
693 # - Create the targets
694 # - Check if we have both libraries and programs
695 # - Match each target with source files (sort in reverse
696 # alphabetical order to get the longest matches first)
697 my @local_imports=();
698 my @local_depends=();
699 my @exe_list=();
700 foreach $target_name (sort { $b cmp $a } keys %targets) {
701 # Create the target...
702 my $basename;
703 my $target=[];
704 target_init($target);
705 @$target[$T_NAME]=$target_name;
706 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
707 if ($target_name =~ /^lib(.*)\.so$/) {
708 @$target[$T_TYPE]=$TT_DLL;
709 @$target[$T_INIT]=get_default_init($TT_DLL);
710 @$target[$T_FLAGS]&=~$TF_WRAP;
711 $basename=$1;
712 push @local_depends,$target_name;
713 push @local_imports,$basename;
714 } else {
715 @$target[$T_TYPE]=$opt_target_type;
716 @$target[$T_INIT]=get_default_init($opt_target_type);
717 $basename=$target_name;
718 push @exe_list,$target;
720 # This is the default link list of Visual Studio, except for uuid and
721 # odbccp32 which we don't have in Wine. Also I add ntdll which seems
722 # necessary for WineLib.
723 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);
724 @$target[$T_IMPORTS]=\@std_imports;
725 push @{@$project[$P_TARGETS]},$target;
727 # Ask for target-specific options
728 if ($opt_ask_target_options == $OPT_ASK_YES) {
729 my $flag_desc="";
730 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
731 $flag_desc=" (mfc";
733 if ((@$target[$T_FLAGS] & $TF_WRAP)!=0) {
734 if ($flag_desc ne "") {
735 $flag_desc.=", ";
736 } else {
737 $flag_desc=" (";
739 $flag_desc.="wrapped";
741 if ($flag_desc ne "") {
742 $flag_desc.=")";
744 print "* Specify any link option (-L/-l/--mfc/--wrap) specific to the target\n";
745 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
746 my $options=<STDIN>;
747 chomp $options;
748 if ($options eq "never") {
749 $opt_ask_target_options=$OPT_ASK_NO;
750 } else {
751 source_set_options($target,$options);
754 if (@$target[$T_FLAGS] & $TF_MFC) {
755 @$project_settings[$T_FLAGS]|=$TF_MFC;
756 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
757 push @{@$target[$T_IMPORTS]},"mfc.dll";
758 # FIXME: Link with the MFC in the Unix sense, until we
759 # start exporting the functions properly.
760 push @{@$target[$T_LIBRARIES]},"mfc";
763 # Match sources...
764 if ($target_count == 1) {
765 push @{@$target[$T_SOURCES_C]},@sources_c;
766 push @{@$target[$T_SOURCES_CXX]},@sources_cxx;
767 push @{@$target[$T_SOURCES_RC]},@sources_rc;
768 push @{@$target[$T_SOURCES_MISC]},@sources_misc;
769 @sources_c=();
770 @sources_cxx=();
771 @sources_rc=();
772 @sources_misc=();
773 } else {
774 foreach $source (@sources_c) {
775 if ($source =~ /^$basename/i) {
776 push @{@$target[$T_SOURCES_C]},$source;
777 $source="";
780 foreach $source (@sources_cxx) {
781 if ($source =~ /^$basename/i) {
782 push @{@$target[$T_SOURCES_CXX]},$source;
783 $source="";
786 foreach $source (@sources_rc) {
787 if ($source =~ /^$basename/i) {
788 push @{@$target[$T_SOURCES_RC]},$source;
789 $source="";
792 foreach $source (@sources_misc) {
793 if ($source =~ /^$basename/i) {
794 push @{@$target[$T_SOURCES_MISC]},$source;
795 $source="";
799 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
800 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
801 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
802 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
804 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
805 $opt_ask_target_options=$OPT_ASK_YES;
808 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
809 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
811 # The sources that did not match, if any, go to the extra
812 # source list of the project settings
813 foreach $source (@sources_c) {
814 if ($source ne "") {
815 push @{@$project_settings[$T_SOURCES_C]},$source;
818 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
819 foreach $source (@sources_cxx) {
820 if ($source ne "") {
821 push @{@$project_settings[$T_SOURCES_CXX]},$source;
824 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
825 foreach $source (@sources_rc) {
826 if ($source ne "") {
827 push @{@$project_settings[$T_SOURCES_RC]},$source;
830 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
831 foreach $source (@sources_misc) {
832 if ($source ne "") {
833 push @{@$project_settings[$T_SOURCES_MISC]},$source;
836 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
838 # Finally if we are building both libraries and programs in
839 # this directory, then the programs should be linked with all
840 # the libraries
841 if (@local_imports > 0 and @exe_list > 0) {
842 foreach $target (@exe_list) {
843 push @{@$target[$T_LIBRARY_PATH]},"-L.";
844 push @{@$target[$T_IMPORTS]},map { "$_.dll" } @local_imports;
845 # Also link in the Unix sense since none of the functions
846 # will be exported.
847 push @{@$target[$T_LIBRARIES]},@local_imports;
848 push @{@$target[$T_DEPENDS]},@local_depends;
854 # Scan the source directories in search of things to build
855 sub source_scan
857 my $main_target=@{$main_project[$P_TARGETS]}[0];
859 # If there's a single target then this is going to be the default target
860 if (defined $opt_single_target) {
861 if ($opt_target_type == $TT_DLL) {
862 @$main_target[$T_NAME]="lib$opt_single_target.so";
863 } else {
864 @$main_target[$T_NAME]="$opt_single_target";
866 @$main_target[$T_TYPE]=$opt_target_type;
869 # The main directory is always going to be there
870 push @projects,\@main_project;
872 # Now scan the directory tree looking for source files and, maybe, targets
873 print "Scanning the source directories...\n";
874 source_scan_directory(\@main_project,"","");
876 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
881 #####
883 # 'vc.dsp'-based Project analysis
885 #####
887 #sub analyze_vc_dsp
894 #####
896 # Creating the wrapper targets
898 #####
900 sub postprocess_targets
902 foreach $project (@projects) {
903 foreach $target (@{@$project[$P_TARGETS]}) {
904 if ((@$target[$T_FLAGS] & $TF_WRAP) != 0) {
905 my $wrapper=[];
906 target_init($wrapper);
907 @$wrapper[$T_NAME]=@$target[$T_NAME];
908 @$wrapper[$T_TYPE]=@$target[$T_TYPE];
909 @$wrapper[$T_INIT]=get_default_init(@$target[$T_TYPE]);
910 @$wrapper[$T_FLAGS]=$TF_WRAPPER | (@$target[$T_FLAGS] & $TF_MFC);
911 push @{@$wrapper[$T_SOURCES_C]},"@$wrapper[$T_NAME]_wrapper.c";
913 my $index=bsearch(@$target[$T_SOURCES_C],"@$wrapper[$T_NAME]_wrapper.c");
914 if (defined $index) {
915 splice(@{@$target[$T_SOURCES_C]},$index,1);
917 @$target[$T_NAME]="lib@$target[$T_NAME].so";
918 @$target[$T_TYPE]=$TT_DLL;
920 push @{@$project[$P_TARGETS]},$wrapper;
922 if ((@$target[$T_FLAGS] & $TF_MFC) != 0) {
923 @{@$project[$P_SETTINGS]}[$T_FLAGS]|=$TF_MFC;
924 $needs_mfc=1;
932 #####
934 # Source search
936 #####
939 # Performs a directory traversal and renames the files so that:
940 # - they have the case desired by the user
941 # - their extension is of the appropriate case
942 # - they don't contain annoying characters like ' ', '$', '#', ...
943 sub fix_file_and_directory_names
945 my $dirname=$_[0];
947 if (opendir(DIRECTORY, "$dirname")) {
948 foreach $dentry (readdir DIRECTORY) {
949 if ($dentry =~ /^\./ or $dentry eq "CVS") {
950 next;
952 # Set $warn to 1 if the user should be warned of the renaming
953 my $warn=0;
955 # autoconf and make don't support these characters well
956 my $new_name=$dentry;
957 $new_name =~ s/[ \$]/_/g;
959 # Our Make.rules supports all-uppercase and all-lowercase extensions.
960 # The others must be fixed.
961 if (-f "$dirname/$new_name") {
962 if ($new_name =~ /\.cpp/i and $new_name !~ /\.(cpp|CPP)/) {
963 $new_name =~ s/\.cpp$/.cpp/i;
965 if ($new_name =~ s/\.cxx$/.cpp/i) {
966 $warn=1;
968 if ($new_name =~ /\.rc/i and $new_name !~ /\.(rc|RC)/) {
969 $new_name =~ s/\.rc$/.rc/i;
971 # And this last one is to avoid confusion then running make
972 if ($new_name =~ s/^makefile$/makefile.win/) {
973 $warn=1;
977 # Adjust the case to the user's preferences
978 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
979 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
981 $new_name=lc $new_name;
984 # And finally, perform the renaming
985 if ($new_name ne $dentry) {
986 if ($warn) {
987 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
989 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
990 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
991 print STDERR " $!\n";
992 $new_name=$dentry;
995 if (-d "$dirname/$new_name") {
996 fix_file_and_directory_names("$dirname/$new_name");
999 closedir(DIRECTORY);
1005 #####
1007 # Source fixup
1009 #####
1012 # This maps a directory name to a reference to an array listing
1013 # its contents (files and directories)
1014 my %directories;
1017 # Retrieves the contents of the specified directory.
1018 # We either get it from the directories hashtable which acts as a
1019 # cache, or use opendir, readdir, closedir and store the result
1020 # in the hashtable.
1021 sub get_directory_contents
1023 my $dirname=$_[0];
1024 my $directory;
1026 #print "getting the contents of $dirname\n";
1028 # check for a cached version
1029 $dirname =~ s+/$++;
1030 if ($dirname eq "") {
1031 $dirname=cwd;
1033 $directory=$directories{$dirname};
1034 if (defined $directory) {
1035 #print "->@$directory\n";
1036 return $directory;
1039 # Read this directory
1040 if (opendir(DIRECTORY, "$dirname")) {
1041 my @files=readdir DIRECTORY;
1042 closedir(DIRECTORY);
1043 $directory=\@files;
1044 } else {
1045 # Return an empty list
1046 #print "error: cannot open $dirname\n";
1047 my @files;
1048 $directory=\@files;
1050 #print "->@$directory\n";
1051 $directories{$dirname}=$directory;
1052 return $directory;
1056 # Try to find a file for the specified filename. The attempt is
1057 # case-insensitive which is why it's not trivial. If a match is
1058 # found then we return the pathname with the correct case.
1059 sub search_from
1061 my $dirname=$_[0];
1062 my $path=$_[1];
1063 my $real_path="";
1065 if ($dirname eq "" or $dirname eq ".") {
1066 $dirname=cwd;
1067 } elsif ($dirname =~ m+^[^/]+) {
1068 $dirname=cwd . "/" . $dirname;
1070 if ($dirname !~ m+/$+) {
1071 $dirname.="/";
1074 foreach $component (@$path) {
1075 #print " looking for $component in \"$dirname\"\n";
1076 if ($component eq ".") {
1077 # Pass it as is
1078 $real_path.="./";
1079 } elsif ($component eq "..") {
1080 # Go up one level
1081 $dirname=dirname($dirname) . "/";
1082 $real_path.="../";
1083 } else {
1084 my $directory=get_directory_contents $dirname;
1085 my $found;
1086 foreach $dentry (@$directory) {
1087 if ($dentry =~ /^$component$/i) {
1088 $dirname.="$dentry/";
1089 $real_path.="$dentry/";
1090 $found=1;
1091 last;
1094 if (!defined $found) {
1095 # Give up
1096 #print " could not find $component in $dirname\n";
1097 return;
1101 $real_path=~ s+/$++;
1102 #print " -> found $real_path\n";
1103 return $real_path;
1107 # Performs a case-insensitive search for the specified file in the
1108 # include path.
1109 # $line is the line number that should be referenced when an error occurs
1110 # $filename is the file we are looking for
1111 # $dirname is the directory of the file containing the '#include' directive
1112 # if '"' was used, it is an empty string otherwise
1113 # $project and $target specify part of the include path
1114 sub get_real_include_name
1116 my $line=$_[0];
1117 my $filename=$_[1];
1118 my $dirname=$_[2];
1119 my $project=$_[3];
1120 my $target=$_[4];
1122 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1123 # This is not a relative path, we cannot make any check
1124 my $warning="path:$filename";
1125 if (!defined $warnings{$warning}) {
1126 $warnings{$warning}="1";
1127 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1128 print STDERR "$line: $filename\n";
1130 } else {
1131 # Here's how we proceed:
1132 # - split the filename we look for into its components
1133 # - then for each directory in the include path
1134 # - trace the directory components starting from that directory
1135 # - if we fail to find a match at any point then continue with
1136 # the next directory in the include path
1137 # - otherwise, rejoice, our quest is over.
1138 my @file_components=split /[\/\\]+/, $filename;
1139 #print " Searching for $filename from @$project[$P_PATH]\n";
1141 my $real_filename;
1142 if ($dirname ne "") {
1143 # This is an 'include ""' -> look in dirname first.
1144 #print " in $dirname (include \"\")\n";
1145 $real_filename=search_from($dirname,\@file_components);
1146 if (defined $real_filename) {
1147 return $real_filename;
1150 my $project_settings=@$project[$P_SETTINGS];
1151 foreach $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1152 my $dirname=$include;
1153 $dirname=~ s+^-I++;
1154 if (!is_absolute($dirname)) {
1155 $dirname="@$project[$P_PATH]$dirname";
1156 } else {
1157 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1159 #print " in $dirname\n";
1160 $real_filename=search_from("$dirname",\@file_components);
1161 if (defined $real_filename) {
1162 return $real_filename;
1165 my $dotdotpath=@$project[$P_PATH];
1166 $dotdotpath =~ s/[^\/]+/../g;
1167 foreach $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1168 my $dirname=$include;
1169 $dirname=~ s+^-I++;
1170 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1171 #print " in $dirname (global setting)\n";
1172 $real_filename=search_from("$dirname",\@file_components);
1173 if (defined $real_filename) {
1174 return $real_filename;
1178 $filename =~ s+\\\\+/+g; # in include ""
1179 $filename =~ s+\\+/+g; # in include <> !
1180 if ($opt_lower_include) {
1181 return lc "$filename";
1183 return $filename;
1187 # 'Parses' a source file and fixes constructs that would not work with
1188 # Winelib. The parsing is rather simple and not all non-portable features
1189 # are corrected. The most important feature that is corrected is the case
1190 # and path separator of '#include' directives. This requires that each
1191 # source file be associated to a project & target so that the proper
1192 # include path is used.
1193 # Also note that the include path is relative to the directory in which the
1194 # compiler is run, i.e. that of the project, not to that of the file.
1195 sub fix_file
1197 my $filename=$_[0];
1198 my $project=$_[1];
1199 my $target=$_[2];
1200 $filename="@$project[$P_PATH]$filename";
1201 if (! -e $filename) {
1202 return;
1205 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1206 my $dirname=dirname($filename);
1207 my $is_mfc=0;
1208 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1209 $is_mfc=1;
1212 print " $filename\n";
1213 #FIXME:assuming that because there is a .bak file, this is what we want is
1214 #probably flawed. Or is it???
1215 if (! -e "$filename.bak") {
1216 if (!copy("$filename","$filename.bak")) {
1217 print STDERR "error: unable to make a backup of $filename:\n";
1218 print STDERR " $!\n";
1219 return;
1222 if (!open(FILEI,"$filename.bak")) {
1223 print STDERR "error: unable to open $filename.bak for reading:\n";
1224 print STDERR " $!\n";
1225 return;
1227 if (!open(FILEO,">$filename")) {
1228 print STDERR "error: unable to open $filename for writing:\n";
1229 print STDERR " $!\n";
1230 return;
1232 my $line=0;
1233 my $modified=0;
1234 my $rc_block_depth=0;
1235 my $rc_textinclude_state=0;
1236 while (<FILEI>) {
1237 $line++;
1238 $_ =~ s/\r\n$/\n/;
1239 if ($is_rc and !$is_mfc and /^(\s*\#\s*include\s*)\"afxres\.h\"/) {
1240 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1241 # the RC files it generates (even in non-MFC projects). So we replace
1242 # it with 'winres.h' its very close standard cousin so that non MFC
1243 # projects can compile in Wine without the MFC sources. This does not
1244 # harm VC but it will put 'afxres.h' back the next time the file is
1245 # edited.
1246 my $warning="mfc:afxres.h";
1247 if (!defined $warnings{$warning}) {
1248 $warnings{$warning}="1";
1249 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winres.h'\n";
1250 print STDERR "warning: the above warning is issued only once\n";
1252 print FILEO "/* winemaker: $1\"afxres.h\" */\n";
1253 print FILEO "$1\"winres.h\"$'";
1254 $modified=1;
1255 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1256 my $from_file=($2 eq "<"?"":$dirname);
1257 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1258 print FILEO "$1$2$real_include_name$4$'";
1259 $modified|=($real_include_name ne $3);
1260 } elsif (/^(\s*\#\s*pragma\s*pack\s*\((\s*push\s*,?)?\s*)(\w*)(\s*\))/) {
1261 my $pragma_header=$1;
1262 my $size=$3;
1263 my $pragma_trailer=$4;
1264 #print "$pragma_header$size$pragma_trailer$'";
1265 #print "pragma push: size=$size\n";
1266 print FILEO "/* winemaker: $pragma_header$size$pragma_trailer */\n";
1267 $line++;
1268 if ($size eq "pop") {
1269 print FILEO "#include <poppack.h>$'";
1270 } elsif ($size eq "1") {
1271 print FILEO "#include <pshpack1.h>$'";
1272 } elsif ($size eq "2") {
1273 print FILEO "#include <pshpack2.h>$'";
1274 } elsif ($size eq "8") {
1275 print FILEO "#include <pshpack8.h>$'";
1276 } elsif ($size eq "4" or $size eq "") {
1277 print FILEO "#include <pshpack4.h>$'";
1278 } else {
1279 my $warning="pack:$size";
1280 if (!defined $warnings{$warning}) {
1281 $warnings{$warning}="1";
1282 print STDERR "warning: assuming that the value of $size is 4 in\n";
1283 print STDERR "$line: $pragma_header$size$pragma_trailer\n";
1284 print STDERR "warning: the above warning is issued only once\n";
1286 print FILEO "#include <pshpack4.h>$'";
1287 $modified=1;
1289 } elsif ($is_rc) {
1290 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]+)([\">]?)/) {
1291 my $from_file=($5 eq "<"?"":$dirname);
1292 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
1293 print FILEO "$1$5$real_include_name$7$'";
1294 $modified|=($real_include_name ne $6);
1295 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1296 my $from_file=($2 eq "<"?"":$dirname);
1297 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1298 print FILEO "$1$2$real_include_name$4$'";
1299 $modified|=($real_include_name ne $3);
1300 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
1301 $rc_textinclude_state=1;
1302 print FILEO;
1303 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
1304 print FILEO "$1winres.h$2$'";
1305 $modified=1;
1306 } elsif (/^\s*BEGIN(\W.*)?$/) {
1307 $rc_textinclude_state|=2;
1308 $rc_block_depth++;
1309 print FILEO;
1310 } elsif (/^\s*END(\W.*)?$/) {
1311 $rc_textinclude_state=0;
1312 if ($rc_block_depth>0) {
1313 $rc_block_depth--;
1315 print FILEO;
1316 } else {
1317 print FILEO;
1319 } else {
1320 print FILEO;
1323 close(FILEI);
1324 close(FILEO);
1325 if ($opt_backup == 0 or $modified == 0) {
1326 if (!unlink("$filename.bak")) {
1327 print STDERR "error: unable to delete $filename.bak:\n";
1328 print STDERR " $!\n";
1334 # Analyzes each source file in turn to find and correct issues
1335 # that would cause it not to compile.
1336 sub fix_source
1338 print "Fixing the source files...\n";
1339 foreach $project (@projects) {
1340 foreach $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
1341 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1342 next;
1344 foreach $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
1345 fix_file($source,$project,$target);
1353 #####
1355 # File generation
1357 #####
1360 # Generates a target's .spec file
1361 sub generate_spec_file
1363 my $path=$_[0];
1364 my $target=$_[1];
1365 my $project_settings=$_[2];
1367 my $basename=@$target[$T_NAME];
1368 $basename =~ s+\.so$++;
1369 if (@$target[$T_FLAGS] & $TF_WRAP) {
1370 $basename =~ s+^lib++;
1371 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1372 $basename.="_wrapper";
1375 if (!open(FILEO,">$path$basename.spec")) {
1376 print STDERR "error: could not open \"$path$basename.spec\" for writing\n";
1377 print STDERR " $!\n";
1378 return;
1381 my $canon=canonize($basename);
1382 print FILEO "name $canon\n";
1383 print FILEO "type win32\n";
1384 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1385 print FILEO "mode guiexe\n";
1386 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1387 print FILEO "mode cuiexe\n";
1388 } else {
1389 print FILEO "mode dll\n";
1391 if (defined @$target[$T_INIT] and ((@$target[$T_FLAGS] & $TF_WRAP) == 0)) {
1392 print FILEO "init @$target[$T_INIT]\n";
1394 if (@{@$target[$T_SOURCES_RC]} > 0) {
1395 if (@{@$target[$T_SOURCES_RC]} > 1) {
1396 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";
1398 my $rcname=@{@$target[$T_SOURCES_RC]}[0];
1399 $rcname =~ s+\.rc$++i;
1400 print FILEO "rsrc $rcname.res\n";
1402 print FILEO "\n";
1403 my %imports;
1404 foreach $library (@{$global_settings[$T_IMPORTS]}) {
1405 if (!defined $imports{$library}) {
1406 print FILEO "import $library\n";
1407 $imports{$library}=1;
1410 if (defined $project_settings) {
1411 foreach $library (@{@$project_settings[$T_IMPORTS]}) {
1412 if (!defined $imports{$library}) {
1413 print FILEO "import $library\n";
1414 $imports{$library}=1;
1418 foreach $library (@{@$target[$T_IMPORTS]}) {
1419 if (!defined $imports{$library}) {
1420 print FILEO "import $library\n";
1421 $imports{$library}=1;
1425 # Don't forget to export the 'Main' function for wrapped executables,
1426 # except for MFC ones!
1427 if (@$target[$T_FLAGS] == $TF_WRAP) {
1428 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1429 print FILEO "\n@ stdcall @$target[$T_INIT](long long ptr long) @$target[$T_INIT]\n";
1430 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1431 print FILEO "\n@ stdcall @$target[$T_INIT](long ptr ptr) @$target[$T_INIT]\n";
1432 } else {
1433 print FILEO "\n@ stdcall @$target[$T_INIT](ptr long ptr) @$target[$T_INIT]\n";
1437 close(FILEO);
1441 # Generates a target's wrapper file
1442 sub generate_wrapper_file
1444 my $path=$_[0];
1445 my $target=$_[1];
1447 if (!defined $templates{"wrapper.c"}) {
1448 print STDERR "winemaker: internal error: No template called 'wrapper.c'\n";
1449 return;
1452 if (!open(FILEO,">$path@$target[$T_NAME]_wrapper.c")) {
1453 print STDERR "error: unable to open \"$path$basename.c\" for writing:\n";
1454 print STDERR " $!\n";
1455 return;
1457 my $app_name="\"@$target[$T_NAME]\"";
1458 my $app_type=(@$target[$T_TYPE]==$TT_GUIEXE?"GUIEXE":"CUIEXE");
1459 my $app_init=(@$target[$T_TYPE]==$TT_GUIEXE?"\"WinMain\"":"\"main\"");
1460 my $app_mfc=(@$target[$T_FLAGS] & $TF_MFC?"\"mfc\"":NULL);
1461 foreach $line (@{$templates{"wrapper.c"}}) {
1462 $line =~ s/\#\#WINEMAKER_APP_NAME\#\#/$app_name/;
1463 $line =~ s/\#\#WINEMAKER_APP_TYPE\#\#/$app_type/;
1464 $line =~ s/\#\#WINEMAKER_APP_INIT\#\#/$app_init/;
1465 $line =~ s/\#\#WINEMAKER_APP_MFC\#\#/$app_mfc/;
1466 print FILEO $line;
1468 close(FILEO);
1472 # A convenience function to generate all the lists (defines,
1473 # C sources, C++ source, etc.) in the Makefile
1474 sub generate_list
1476 my $name=$_[0];
1477 my $last=$_[1];
1478 my $list=$_[2];
1479 my $data=$_[3];
1481 if ($name) {
1482 printf FILEO "%-9s =",$name;
1484 if (defined $list and @$list > 0) {
1485 foreach $item (@$list) {
1486 my $value;
1487 if (defined $data) {
1488 $value=&$data($item);
1489 } else {
1490 $value=$item;
1492 if ($value ne "") {
1493 print FILEO " \\\n\t$value";
1497 if ($last) {
1498 print FILEO "\n\n";
1503 # Generates a project's Makefile.in and all the target files
1504 sub generate_project_files
1506 my $project=$_[0];
1507 my $project_settings=@$project[$P_SETTINGS];
1508 my @dll_list=();
1509 my @exe_list=();
1511 # Then sort the targets and separate the libraries from the programs
1512 foreach $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
1513 if (@$target[$T_TYPE] == $TT_DLL) {
1514 push @dll_list,$target;
1515 } else {
1516 push @exe_list,$target;
1519 @$project[$P_TARGETS]=[];
1520 push @{@$project[$P_TARGETS]}, @dll_list;
1521 push @{@$project[$P_TARGETS]}, @exe_list;
1523 if (!open(FILEO,">@$project[$P_PATH]Makefile.in")) {
1524 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile.in\" for writing\n";
1525 print STDERR " $!\n";
1526 return;
1529 print FILEO "### Generated by Winemaker\n";
1530 print FILEO "\n\n";
1532 print FILEO "### Generic autoconf variables\n\n";
1533 print FILEO "TOPSRCDIR = \@top_srcdir\@\n";
1534 print FILEO "TOPOBJDIR = .\n";
1535 print FILEO "SRCDIR = \@srcdir\@\n";
1536 print FILEO "VPATH = \@srcdir\@\n";
1537 print FILEO "\n";
1538 if (@$project[$P_PATH] eq "") {
1539 # This is the main project. It is also responsible for recursively
1540 # calling the other projects
1541 generate_list("SUBDIRS",1,\@projects,sub
1543 if ($_[0] != \@main_project) {
1544 my $subdir=@{$_[0]}[$P_PATH];
1545 $subdir =~ s+/$++;
1546 return $subdir;
1548 # Eliminating the main project by returning undefined!
1551 if (@{@$project[$P_TARGETS]} > 0) {
1552 generate_list("DLLS",1,\@dll_list,sub
1554 return @{$_[0]}[$T_NAME];
1556 generate_list("EXES",1,\@exe_list,sub
1558 return "@{$_[0]}[$T_NAME]";
1560 print FILEO "\n\n";
1562 print FILEO "### Global settings\n\n";
1563 # Make it so that the project-wide settings override the global settings
1564 generate_list("DEFINES",0,@$project_settings[$T_DEFINES],sub
1566 return "$_[0]";
1568 generate_list("",1,$global_settings[$T_DEFINES],sub
1570 return "$_[0]";
1572 generate_list("INCLUDE_PATH",$no_extra,@$project_settings[$T_INCLUDE_PATH],sub
1574 return "$_[0]";
1576 generate_list("",1,$global_settings[$T_INCLUDE_PATH],sub
1578 if ($_[0] !~ /^-I/) {
1579 return "$_[0]";
1581 if (is_absolute($')) {
1582 return "$_[0]";
1584 return "\$(TOPSRCDIR)/$_[0]";
1586 generate_list("LIBRARY_PATH",$no_extra,@$project_settings[$T_LIBRARY_PATH],sub
1588 return "$_[0]";
1590 generate_list("",1,$global_settings[$T_LIBRARY_PATH],sub
1592 if ($_[0] !~ /^-L/) {
1593 return "$_[0]";
1595 if (is_absolute($')) {
1596 return "$_[0]";
1598 return "\$(TOPSRCDIR)/$_[0]";
1600 generate_list("LIBRARIES",$no_extra,@$project_settings[$T_LIBRARIES],sub
1602 return "$_[0]";
1604 generate_list("",1,$global_settings[$T_LIBRARIES],sub
1606 return "$_[0]";
1608 print FILEO "\n\n";
1610 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
1611 @{@$project_settings[$T_SOURCES_CXX]}+
1612 @{@$project_settings[$T_SOURCES_RC]};
1613 my $no_extra=($extra_source_count == 0);
1614 if (!$no_extra) {
1615 print FILEO "### Extra source lists\n\n";
1616 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
1617 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
1618 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
1619 print FILEO "EXTRA_OBJS = \$(EXTRA_C_SRCS:.c=.o) \$(EXTRA_CXX_SRCS:.cpp=.o)\n";
1620 print FILEO "\n\n";
1623 # Iterate over all the targets...
1624 foreach $target (@{@$project[$P_TARGETS]}) {
1625 print FILEO "\n### @$target[$T_NAME] sources and settings\n\n";
1626 my $canon=canonize("@$target[$T_NAME]");
1627 $canon =~ s+_so$++;
1628 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
1629 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
1630 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
1631 my $basename=@$target[$T_NAME];
1632 $basename =~ s+\.so$++;
1633 if (@$target[$T_FLAGS] & $TF_WRAP) {
1634 $basename =~ s+^lib++;
1635 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1636 $basename.="_wrapper";
1638 generate_list("${canon}_SPEC_SRCS",1,[ "$basename.spec"]);
1639 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH],sub
1641 return "$_[0]";
1643 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES],sub
1645 return "$_[0]";
1647 generate_list("${canon}_DEPENDS",1,@$target[$T_DEPENDS],sub
1649 return "$_[0]";
1651 print FILEO "${canon}_OBJS = \$(${canon}_C_SRCS:.c=.o) \$(${canon}_CXX_SRCS:.cpp=.o) \$(EXTRA_OBJS)\n";
1652 print FILEO "\n\n";
1654 print FILEO "### Global source lists\n\n";
1655 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
1657 my $canon=canonize(@{$_[0]}[$T_NAME]);
1658 $canon =~ s+_so$++;
1659 return "\$(${canon}_C_SRCS)";
1661 if (!$no_extra) {
1662 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
1664 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
1666 my $canon=canonize(@{$_[0]}[$T_NAME]);
1667 $canon =~ s+_so$++;
1668 return "\$(${canon}_CXX_SRCS)";
1670 if (!$no_extra) {
1671 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
1673 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
1675 my $canon=canonize(@{$_[0]}[$T_NAME]);
1676 $canon =~ s+_so$++;
1677 return "\$(${canon}_RC_SRCS)";
1679 if (!$no_extra) {
1680 generate_list("",1,@$project_settings[$T_SOURCES_RC]);
1682 generate_list("SPEC_SRCS",1,@$project[$P_TARGETS],sub
1684 my $canon=canonize(@{$_[0]}[$T_NAME]);
1685 $canon =~ s+_so$++;
1686 return "\$(${canon}_SPEC_SRCS)";
1688 print FILEO "\n\n";
1691 print FILEO "### Generic autoconf targets\n\n";
1692 if (@$project[$P_PATH] eq "") {
1693 print FILEO "all: \$(SUBDIRS) \$(EXES:%=%.so) \$(DLLS)\n";
1694 } else {
1695 print FILEO "all: \$(EXES:%=%.so) \$(DLLS)\n";
1697 print FILEO "\n";
1698 print FILEO "\@MAKE_RULES\@\n";
1699 print FILEO "\n";
1700 print FILEO "install::\n";
1701 if (@$project[$P_PATH] eq "") {
1702 # This is the main project. It is also responsible for recursively
1703 # calling the other projects
1704 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) install) || exit 1; done\n";
1706 if (@{@$project[$P_TARGETS]} > 0) {
1707 print FILEO "\tfor i in \$(EXES); do \$(INSTALL_PROGRAM) \$\$i \$(bindir); done\n";
1708 print FILEO "\tfor i in \$(EXES:%=%.so) \$(DLLS); do \$(INSTALL_LIBRARY) \$\$i \$(libdir); done\n";
1710 print FILEO "\n";
1711 print FILEO "uninstall::\n";
1712 if (@$project[$P_PATH] eq "") {
1713 # This is the main project. It is also responsible for recursively
1714 # calling the other projects
1715 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) uninstall) || exit 1; done\n";
1717 if (@{@$project[$P_TARGETS]} > 0) {
1718 print FILEO "\tfor i in \$(EXES); do \$(RM) \$(bindir)/\$\$i;done\n";
1719 print FILEO "\tfor i in \$(EXES:%=%.so) \$(DLLS); do \$(RM) \$(libdir)/\$\$i;done\n";
1721 print FILEO "\n\n\n";
1723 if (@{@$project[$P_TARGETS]} > 0) {
1724 print FILEO "### Target specific build rules\n\n";
1725 foreach $target (@{@$project[$P_TARGETS]}) {
1726 my $canon=canonize("@$target[$T_NAME]");
1727 $canon =~ s/_so$//;
1728 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.tmp.o): \$(${canon}_OBJS)\n";
1729 print FILEO "\t\$(LDCOMBINE) \$(${canon}_OBJS) -o \$\@\n";
1730 print FILEO "\t-\$(STRIP) \$(STRIPFLAGS) \$\@\n";
1731 print FILEO "\n";
1732 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.spec.c): \$(${canon}_SPEC_SRCS:.spec) \$(${canon}_SPEC_SRCS:.spec=.tmp.o) \$(${canon}_RC_SRCS:.rc=.res)\n";
1733 print FILEO "\t\$(WINEBUILD) -fPIC \$(${canon}_LIBRARY_PATH) \$(WINE_LIBRARY_PATH) -sym \$(${canon}_SPEC_SRCS:.spec=.tmp.o) -o \$\@ -spec \$(${canon}_SPEC_SRCS)\n";
1734 print FILEO "\n";
1735 my $t_name=@$target[$T_NAME];
1736 if (@$target[$T_TYPE]!=$TT_DLL) {
1737 $t_name.=".so";
1739 print FILEO "$t_name: \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_OBJS) \$(${canon}_DEPENDS) \n";
1740 print FILEO "\t\$(LDSHARED) \$(LDDLLFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_LIBRARY_PATH) \$(${canon}_LIBRARIES:%=-l%) \$(DLL_LINK) \$(LIBS)\n";
1741 if (@$target[$T_TYPE] ne $TT_DLL) {
1742 print FILEO "\ttest -e @$target[$T_NAME] || \$(LN_S) \$(WINE) @$target[$T_NAME]\n";
1744 print FILEO "\n";
1747 close(FILEO);
1749 foreach $target (@{@$project[$P_TARGETS]}) {
1750 generate_spec_file(@$project[$P_PATH],$target,$project_settings);
1751 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1752 generate_wrapper_file(@$project[$P_PATH],$target);
1758 # Perform the replacements in the template configure files
1759 # Return 1 for success, 0 for failure
1760 sub generate_configure
1762 my $filename=$_[0];
1763 my $a_source_file=$_[1];
1765 if (!defined $templates{$filename}) {
1766 if ($filename ne "configure") {
1767 print STDERR "winemaker: internal error: No template called '$filename'\n";
1769 return 0;
1772 if (!open(FILEO,">$filename")) {
1773 print STDERR "error: unable to open \"$filename\" for writing:\n";
1774 print STDERR " $!\n";
1775 return 0;
1777 foreach $line (@{$templates{$filename}}) {
1778 if ($line =~ /^\#\#WINEMAKER_PROJECTS\#\#$/) {
1779 foreach $project (@projects) {
1780 print FILEO "@$project[$P_PATH]Makefile\n";
1782 } else {
1783 $line =~ s+\#\#WINEMAKER_SOURCE\#\#+$a_source_file+;
1784 $line =~ s+\#\#WINEMAKER_NEEDS_MFC\#\#+$needs_mfc+;
1785 print FILEO $line;
1788 close(FILEO);
1789 return 1;
1792 sub generate_generic
1794 my $filename=$_[0];
1796 if (!defined $templates{$filename}) {
1797 print STDERR "winemaker: internal error: No template called '$filename'\n";
1798 return;
1800 if (!open(FILEO,">$filename")) {
1801 print STDERR "error: unable to open \"$filename\" for writing:\n";
1802 print STDERR " $!\n";
1803 return;
1805 foreach $line (@{$templates{$filename}}) {
1806 print FILEO $line;
1808 close(FILEO);
1812 # Generates the global files:
1813 # configure
1814 # configure.in
1815 # Make.rules.in
1816 sub generate_global_files
1818 generate_generic("Make.rules.in");
1820 # Get the name of a source file for configure.in
1821 my $a_source_file;
1822 search_a_file: foreach $project (@projects) {
1823 foreach $target (@{@$project[$P_TARGETS]}, @$project[$P_SETTINGS]) {
1824 $a_source_file=@{@$target[$T_SOURCES_C]}[0];
1825 if (!defined $a_source_file) {
1826 $a_source_file=@{@$target[$T_SOURCES_CXX]}[0];
1828 if (!defined $a_source_file) {
1829 $a_source_file=@{@$target[$T_SOURCES_RC]}[0];
1831 if (defined $a_source_file) {
1832 $a_source_file="@$project[$P_PATH]$a_source_file";
1833 last search_a_file;
1838 generate_configure("configure.in",$a_source_file);
1839 unlink("configure");
1840 if (generate_configure("configure",$a_source_file) == 0) {
1841 system("autoconf");
1843 # Add execute permission to configure for whoever has the right to read it
1844 my @st=stat("configure");
1845 if (defined @st) {
1846 my $mode=$st[2];
1847 $mode|=($mode & 0444) >>2;
1848 chmod($mode,"configure");
1849 } else {
1850 print "warning: could not generate the configure script. You need to run autoconf\n";
1856 sub generate_read_templates
1858 my $file;
1860 while (<DATA>) {
1861 if (/^--- ((\w\.?)+) ---$/) {
1862 my $filename=$1;
1863 if (defined $templates{$filename}) {
1864 print STDERR "winemaker: internal error: There is more than one template for $filename\n";
1865 undef $file;
1866 } else {
1867 $file=[];
1868 $templates{$filename}=$file;
1870 } elsif (defined $file) {
1871 push @$file, $_;
1877 # This is where we finally generate files. In fact this method does not
1878 # do anything itself but calls the methods that do the actual work.
1879 sub generate
1881 print "Generating project files...\n";
1882 generate_read_templates();
1883 generate_global_files();
1885 foreach $project (@projects) {
1886 my $path=@$project[$P_PATH];
1887 if ($path eq "") {
1888 $path=".";
1889 } else {
1890 $path =~ s+/$++;
1892 print " $path\n";
1893 generate_project_files($project);
1899 #####
1901 # Option defaults
1903 #####
1905 $opt_backup=1;
1906 $opt_lower=$OPT_LOWER_UPPERCASE;
1907 $opt_lower_include=1;
1909 # $opt_single_target=<undefined>
1910 $opt_target_type=$TT_GUIEXE;
1911 $opt_flags=0;
1912 $opt_is_interactive=$OPT_ASK_NO;
1913 $opt_ask_project_options=$OPT_ASK_NO;
1914 $opt_ask_target_options=$OPT_ASK_NO;
1915 $opt_no_generated_files=0;
1916 $opt_no_banner=0;
1920 #####
1922 # Main
1924 #####
1926 project_init(\@main_project,"");
1928 while (@ARGV>0) {
1929 my $arg=shift @ARGV;
1930 # General options
1931 if ($arg eq "--nobanner") {
1932 $opt_no_banner=1;
1933 } elsif ($arg eq "--backup") {
1934 $opt_backup=1;
1935 } elsif ($arg eq "--nobackup") {
1936 $opt_backup=0;
1937 } elsif ($arg eq "--single-target") {
1938 $opt_single_target=shift @ARGV;
1939 } elsif ($arg eq "--lower-none") {
1940 $opt_lower=$OPT_LOWER_NONE;
1941 } elsif ($arg eq "--lower-all") {
1942 $opt_lower=$OPT_LOWER_ALL;
1943 } elsif ($arg eq "--lower-uppercase") {
1944 $opt_lower=$OPT_LOWER_UPPERCASE;
1945 } elsif ($arg eq "--lower-include") {
1946 $opt_lower_include=1;
1947 } elsif ($arg eq "--no-lower-include") {
1948 $opt_lower_include=0;
1949 } elsif ($arg eq "--generated-files") {
1950 $opt_no_generated_files=0;
1951 } elsif ($arg eq "--no-generated-files") {
1952 $opt_no_generated_files=1;
1954 } elsif ($arg =~ /^-D/) {
1955 push @{$global_settings[$T_DEFINES]},$arg;
1956 } elsif ($arg =~ /^-I/) {
1957 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
1958 } elsif ($arg =~ /^-L/) {
1959 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
1960 } elsif ($arg =~ /^-i/) {
1961 push @{$global_settings[$T_IMPORTS]},$';
1962 } elsif ($arg =~ /^-l/) {
1963 push @{$global_settings[$T_LIBRARIES]},$';
1965 # 'Source'-based method options
1966 } elsif ($arg eq "--dll") {
1967 $opt_target_type=$TT_DLL;
1968 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
1969 $opt_target_type=$TT_GUIEXE;
1970 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
1971 $opt_target_type=$TT_CUIEXE;
1972 } elsif ($arg eq "--interactive") {
1973 $opt_is_interactive=$OPT_ASK_YES;
1974 $opt_ask_project_options=$OPT_ASK_YES;
1975 $opt_ask_target_options=$OPT_ASK_YES;
1976 } elsif ($arg eq "--wrap") {
1977 print STDERR "warning: --wrap no longer supported, ignoring the option\n";
1978 #$opt_flags|=$TF_WRAP;
1979 } elsif ($arg eq "--nowrap") {
1980 $opt_flags&=~$TF_WRAP;
1981 } elsif ($arg eq "--mfc") {
1982 $opt_flags|=$TF_MFC;
1983 #$opt_flags|=$TF_MFC|$TF_WRAP;
1984 $needs_mfc=1;
1985 } elsif ($arg eq "--nomfc") {
1986 $opt_flags&=~($TF_MFC|$TF_WRAP);
1987 $needs_mfc=0;
1989 # Catch errors
1990 } else {
1991 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
1992 print STDERR "Unknown option: $arg\n";
1994 $usage=1;
1995 last;
1999 if ($opt_no_banner == 0 or defined $usage) {
2000 print "Winemaker $version\n";
2001 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2004 if (defined $usage) {
2005 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup]\n";
2006 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2007 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2008 print STDERR " [--wrap|--nowrap] [--mfc|--nomfc]\n";
2009 print STDERR " [-Dmacro[=defn]] [-Idir] [-Ldir] [-llibrary]\n";
2010 print STDERR " [--interactive] [--single-target name]\n";
2011 print STDERR " [--generated-files|--no-generated-files]\n";
2012 exit (2);
2015 # Fix the file and directory names
2016 fix_file_and_directory_names(".");
2018 # Scan the sources to identify the projects and targets
2019 source_scan();
2021 # Create targets for wrappers, etc.
2022 postprocess_targets();
2024 # Fix the source files
2025 fix_source();
2027 # Generate the Makefile and the spec file
2028 if (! $opt_no_generated_files) {
2029 generate();
2033 __DATA__
2034 --- configure.in ---
2035 dnl Process this file with autoconf to produce a configure script.
2036 dnl Author: Michael Patra <micky@marie.physik.tu-berlin.de>
2037 dnl <patra@itp1.physik.tu-berlin.de>
2038 dnl Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2040 AC_REVISION([configure.in 1.00])
2041 AC_INIT(##WINEMAKER_SOURCE##)
2043 NEEDS_MFC=##WINEMAKER_NEEDS_MFC##
2045 dnl **** Command-line arguments ****
2047 AC_SUBST(OPTIONS)
2049 dnl **** Check for some programs ****
2051 AC_PROG_MAKE_SET
2052 AC_PROG_CC
2053 AC_PROG_CXX
2054 AC_PROG_CPP
2055 AC_PATH_XTRA
2056 AC_PROG_RANLIB
2057 AC_PROG_LN_S
2058 AC_PATH_PROG(LDCONFIG, ldconfig, true, /sbin:/usr/sbin:$PATH)
2060 dnl **** Check for some libraries ****
2062 dnl Check for -lm for BeOS
2063 AC_CHECK_LIB(m,sqrt)
2064 dnl Check for -li386 for NetBSD and OpenBSD
2065 AC_CHECK_LIB(i386,i386_set_ldt)
2066 dnl Check for -lossaudio for NetBSD
2067 AC_CHECK_LIB(ossaudio,_oss_ioctl)
2068 dnl Check for -lw for Solaris
2069 AC_CHECK_LIB(w,iswalnum)
2070 dnl Check for -lnsl for Solaris
2071 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))
2072 dnl Check for -lsocket for Solaris
2073 AC_CHECK_FUNCS(connect,,AC_CHECK_LIB(socket,connect))
2074 dnl Check for -lxpg4 for FreeBSD
2075 AC_CHECK_LIB(xpg4,setrunelocale)
2076 dnl Check for -lmmap for OS/2
2077 AC_CHECK_LIB(mmap,mmap)
2078 dnl Check for openpty
2079 AC_CHECK_FUNCS(openpty,,
2080 AC_CHECK_LIB(util,openpty,
2081 AC_DEFINE(HAVE_OPENPTY)
2082 LIBS="$LIBS -lutil"
2085 AC_CHECK_HEADERS(dlfcn.h,
2086 AC_CHECK_FUNCS(dlopen,
2087 AC_DEFINE(HAVE_DL_API),
2088 AC_CHECK_LIB(dl,dlopen,
2089 AC_DEFINE(HAVE_DL_API)
2090 LIBS="$LIBS -ldl",
2095 dnl **** Check which curses lib to use ***
2096 if test "$CURSES" = "yes"
2097 then
2098 AC_CHECK_HEADERS(ncurses.h)
2099 if test "$ac_cv_header_ncurses_h" = "yes"
2100 then
2101 AC_CHECK_LIB(ncurses,waddch)
2103 if test "$ac_cv_lib_ncurses_waddch" = "yes"
2104 then
2105 AC_CHECK_LIB(ncurses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2106 AC_CHECK_LIB(ncurses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2107 else
2108 AC_CHECK_HEADERS(curses.h)
2109 if test "$ac_cv_header_curses_h" = "yes"
2110 then
2111 AC_CHECK_LIB(curses,waddch)
2112 if test "$ac_cv_lib_curses_waddch" = "yes"
2113 then
2114 AC_CHECK_LIB(curses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2115 AC_CHECK_LIB(curses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2121 dnl **** If ln -s doesn't work, use cp instead ****
2122 if test "$ac_cv_prog_LN_S" = "ln -s"; then : ; else LN_S=cp ; fi
2124 dnl **** Check for gcc strength-reduce bug ****
2126 if test "x${GCC}" = "xyes"
2127 then
2128 AC_CACHE_CHECK( "for gcc strength-reduce bug", ac_cv_c_gcc_strength_bug,
2129 AC_TRY_RUN([
2130 int main(void) {
2131 static int Array[[3]];
2132 unsigned int B = 3;
2133 int i;
2134 for(i=0; i<B; i++) Array[[i]] = i - 3;
2135 exit( Array[[1]] != -2 );
2137 ac_cv_c_gcc_strength_bug="no",
2138 ac_cv_c_gcc_strength_bug="yes",
2139 ac_cv_c_gcc_strength_bug="yes") )
2140 if test "$ac_cv_c_gcc_strength_bug" = "yes"
2141 then
2142 CFLAGS="$CFLAGS -fno-strength-reduce"
2146 dnl **** Check for underscore on external symbols ****
2148 AC_CACHE_CHECK("whether external symbols need an underscore prefix",
2149 ac_cv_c_extern_prefix,
2150 [saved_libs=$LIBS
2151 LIBS="conftest_asm.s $LIBS"
2152 cat > conftest_asm.s <<EOF
2153 .globl _ac_test
2154 _ac_test:
2155 .long 0
2157 AC_TRY_LINK([extern int ac_test;],[if (ac_test) return 1],
2158 ac_cv_c_extern_prefix="yes",ac_cv_c_extern_prefix="no")
2159 LIBS=$saved_libs])
2160 if test "$ac_cv_c_extern_prefix" = "yes"
2161 then
2162 AC_DEFINE(NEED_UNDERSCORE_PREFIX)
2165 dnl **** Check for working dll ****
2167 LDSHARED=""
2168 LDDLLFLAGS=""
2169 AC_CACHE_CHECK("whether we can build a Linux dll",
2170 ac_cv_c_dll_linux,
2171 [saved_cflags=$CFLAGS
2172 CFLAGS="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0,-Bsymbolic"
2173 AC_TRY_LINK(,[return 1],ac_cv_c_dll_linux="yes",ac_cv_c_dll_linux="no")
2174 CFLAGS=$saved_cflags
2176 if test "$ac_cv_c_dll_linux" = "yes"
2177 then
2178 LDSHARED="\$(CC) -shared -Wl,-rpath,\$(libdir)"
2179 LDDLLFLAGS="-Wl,-Bsymbolic"
2180 else
2181 AC_CACHE_CHECK(whether we can build a UnixWare (Solaris) dll,
2182 ac_cv_c_dll_unixware,
2183 [saved_cflags=$CFLAGS
2184 CFLAGS="$CFLAGS -fPIC -Wl,-G,-h,conftest.so.1.0,-B,symbolic"
2185 AC_TRY_LINK(,[return 1],ac_cv_c_dll_unixware="yes",ac_cv_c_dll_unixware="no")
2186 CFLAGS=$saved_cflags
2188 if test "$ac_cv_c_dll_unixware" = "yes"
2189 then
2190 LDSHARED="\$(CC) -Wl,-G \$(SONAME:%=-Wl,h,\$(libdir)/%)"#FIXME: why SONAME here?
2191 LDDLLFLAGS="-Wl,-B,symbolic"
2192 else
2193 AC_CACHE_CHECK("whether we can build a NetBSD dll",
2194 ac_cv_c_dll_netbsd,
2195 [saved_cflags=$CFLAGS
2196 CFLAGS="$CFLAGS -fPIC -Wl,-Bshareable,-Bforcearchive"
2197 AC_TRY_LINK(,[return 1],ac_cv_c_dll_netbsd="yes",ac_cv_c_dll_netbsd="no")
2198 CFLAGS=$saved_cflags
2200 if test "$ac_cv_c_dll_netbsd" = "yes"
2201 then
2202 LDSHARED="\$(CC) -Wl,-Bshareable,-Bforcearchive"
2203 LDDLLFLAGS="" #FIXME
2207 if test "$ac_cv_c_dll_linux" = "no" -a "$ac_cv_c_dll_unixware" = "no" -a "$ac_cv_c_dll_netbsd" = "no"
2208 then
2209 AC_MSG_ERROR([Could not find how to build a dynamically linked library])
2212 CFLAGS="$CFLAGS -fPIC"
2213 DLL_LINK="\$(WINE_LIBRARY_PATH) \$(LIBRARY_PATH) \$(LIBRARIES:%=-l%) -lwine -lwine_unicode"
2215 AC_SUBST(DLL_LINK)
2216 AC_SUBST(LDSHARED)
2217 AC_SUBST(LDDLLFLAGS)
2219 dnl *** check for the need to define __i386__
2221 AC_CACHE_CHECK("whether we need to define __i386__",ac_cv_cpp_def_i386,
2222 AC_EGREP_CPP(yes,[#if (defined(i386) || defined(__i386)) && !defined(__i386__)
2224 #endif],
2225 ac_cv_cpp_def_i386="yes", ac_cv_cpp_def_i386="no"))
2226 if test "$ac_cv_cpp_def_i386" = "yes"
2227 then
2228 CFLAGS="$CFLAGS -D__i386__"
2231 dnl $GCC is set by autoconf
2232 GCC_NO_BUILTIN=""
2233 if test "$GCC" = "yes"
2234 then
2235 GCC_NO_BUILTIN="-fno-builtin"
2237 AC_SUBST(GCC_NO_BUILTIN)
2239 dnl **** Test Winelib-related features of the C++ compiler
2240 AC_LANG_CPLUSPLUS()
2241 if test "x${GCC}" = "xyes"
2242 then
2243 OLDCXXFLAGS="$CXXFLAGS";
2244 CXXFLAGS="-fpermissive";
2245 AC_CACHE_CHECK("for g++ -fpermissive option", has_gxx_permissive,
2246 AC_TRY_COMPILE(,[
2247 for (int i=0;i<2;i++);
2248 i=0;
2250 [has_gxx_permissive="yes"],
2251 [has_gxx_permissive="no"])
2253 CXXFLAGS="-fno-for-scope";
2254 AC_CACHE_CHECK("for g++ -fno-for-scope option", has_gxx_no_for_scope,
2255 AC_TRY_COMPILE(,[
2256 for (int i=0;i<2;i++);
2257 i=0;
2259 [has_gxx_no_for_scope="yes"],
2260 [has_gxx_no_for_scope="no"])
2262 CXXFLAGS="$OLDCXXFLAGS";
2263 if test "$has_gxx_permissive" = "yes"
2264 then
2265 CXXFLAGS="$CXXFLAGS -fpermissive"
2267 if test "$has_gxx_no_for_scope" = "yes"
2268 then
2269 CXXFLAGS="$CXXFLAGS -fno-for-scope"
2272 AC_LANG_C()
2274 dnl **** Test Winelib-related features of the C compiler
2275 dnl none for now
2277 dnl **** Macros for finding a headers/libraries in a collection of places
2279 dnl AC_PATH_HEADER(variable,header,action-if-not-found,default-locations)
2280 dnl Note that the above may set variable to an empty value if the header is
2281 dnl already in the include path
2282 AC_DEFUN(AC_PATH_HEADER,[
2283 AC_MSG_CHECKING([for $2])
2284 AC_CACHE_VAL(ac_cv_path_$1,
2286 ac_found=
2287 ac_dummy="ifelse([$4], , :/usr/local/include, [$4])"
2288 save_CPPFLAGS="$CPPFLAGS"
2289 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2290 for ac_dir in $ac_dummy; do
2291 IFS="$ac_save_ifs"
2292 if test -z "$ac_dir"
2293 then
2294 CPPFLAGS="$save_CPPFLAGS"
2295 else
2296 CPPFLAGS="-I$ac_dir $save_CPPFLAGS"
2298 AC_TRY_COMPILE([#include <$2>],,ac_found=1;ac_cv_path_$1="$ac_dir";break)
2299 done
2300 CPPFLAGS="$save_CPPFLAGS"
2301 ifelse([$3],,,[if test -z "$ac_found"
2302 then
2307 $1="$ac_cv_path_$1"
2308 if test -n "$ac_found" -o -n "[$]$1"
2309 then
2310 AC_MSG_RESULT([$]$1)
2311 else
2312 AC_MSG_RESULT(no)
2314 AC_SUBST($1)
2317 dnl AC_PATH_LIBRARY(variable,libraries,extra libs,action-if-not-found,default-locations)
2318 AC_DEFUN(AC_PATH_LIBRARY,[
2319 AC_MSG_CHECKING([for $2])
2320 AC_CACHE_VAL(ac_cv_path_$1,
2322 ac_found=
2323 ac_dummy="ifelse([$5], , :/usr/local/lib, [$5])"
2324 save_LIBS="$LIBS"
2325 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2326 for ac_dir in $ac_dummy; do
2327 IFS="$ac_save_ifs"
2328 if test -z "$ac_dir"
2329 then
2330 LIBS="$2 $3 $save_LIBS"
2331 else
2332 LIBS="-L$ac_dir $2 $3 $save_LIBS"
2334 AC_TRY_LINK(,,ac_found=1;ac_cv_path_$1="$ac_dir";break)
2335 done
2336 LIBS="$save_LIBS"
2337 ifelse([$4],,,[if test -z "$ac_found"
2338 then
2343 $1="$ac_cv_path_$1"
2344 if test -n "$ac_found" -o -n "[$]$1"
2345 then
2346 AC_MSG_RESULT([$]$1)
2347 else
2348 AC_MSG_RESULT(no)
2350 AC_SUBST($1)
2353 dnl **** Try to find where winelib is located ****
2355 WINE_INCLUDE_ROOT="";
2356 WINE_INCLUDE_PATH="";
2357 WINE_LIBRARY_ROOT="";
2358 WINE_LIBRARY_PATH="";
2359 WINE_TOOL_PATH="";
2360 WINE="";
2361 WINEBUILD="";
2362 WRC="";
2364 AC_ARG_WITH(wine,
2365 [ --with-wine=DIR the Wine package (or sources) is in DIR],
2366 [if test "$withval" != "no"; then
2367 WINE_ROOT="$withval";
2368 WINE_INCLUDES="";
2369 WINE_LIBRARIES="";
2370 WINE_TOOLS="";
2371 else
2372 WINE_ROOT="";
2373 fi])
2374 if test -n "$WINE_ROOT"
2375 then
2376 WINE_INCLUDE_ROOT="$WINE_ROOT/include";
2377 WINE_LIBRARY_ROOT="$WINE_ROOT";
2378 WINE_TOOL_PATH="$WINE_ROOT:$WINE_ROOT/bin:$WINE_ROOT/tools/wrc:$WINE_ROOT/tools/winebuild:$PATH";
2381 AC_ARG_WITH(wine-includes,
2382 [ --with-wine-includes=DIR the Wine includes are in DIR],
2383 [if test "$withval" != "no"; then
2384 WINE_INCLUDES="$withval";
2385 else
2386 WINE_INCLUDES="";
2387 fi])
2388 if test -n "$WINE_INCLUDES"
2389 then
2390 WINE_INCLUDE_ROOT="$WINE_INCLUDES";
2393 AC_ARG_WITH(wine-libraries,
2394 [ --with-wine-libraries=DIR the Wine libraries are in DIR],
2395 [if test "$withval" != "no"; then
2396 WINE_LIBRARIES="$withval";
2397 else
2398 WINE_LIBRARIES="";
2399 fi])
2400 if test -n "$WINE_LIBRARIES"
2401 then
2402 WINE_LIBRARY_ROOT="$WINE_LIBRARIES";
2405 AC_ARG_WITH(wine-tools,
2406 [ --with-wine-tools=DIR the Wine tools are in DIR],
2407 [if test "$withval" != "no"; then
2408 WINE_TOOLS="$withval";
2409 else
2410 WINE_TOOLS="";
2411 fi])
2412 if test -n "$WINE_TOOLS"
2413 then
2414 WINE_TOOL_PATH="$WINE_TOOLS:$WINE_TOOLS/wrc:$WINE_TOOLS/winebuild";
2417 if test -z "$WINE_INCLUDE_ROOT"
2418 then
2419 WINE_INCLUDE_ROOT=":/usr/include/wine:/usr/local/include/wine:/opt/wine/include";
2421 AC_PATH_HEADER(WINE_INCLUDE_ROOT,windef.h,[
2422 AC_MSG_ERROR([Could not find the Wine includes])
2423 ],$WINE_INCLUDE_ROOT)
2424 if test -n "$WINE_INCLUDE_ROOT"
2425 then
2426 WINE_INCLUDE_PATH="-I$WINE_INCLUDE_ROOT"
2427 else
2428 WINE_INCLUDE_PATH=""
2431 if test -z "$WINE_LIBRARY_ROOT"
2432 then
2433 WINE_LIBRARY_ROOT=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib";
2434 else
2435 WINE_LIBRARY_ROOT="$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/lib";
2437 AC_PATH_LIBRARY(WINE_LIBRARY_ROOT,[-lwine],[-lutil],[
2438 AC_MSG_ERROR([Could not find the Wine libraries (libwine.so)])
2439 ],$WINE_LIBRARY_ROOT)
2440 if test -n "$WINE_LIBRARY_ROOT"
2441 then
2442 WINE_LIBRARY_PATH="-L$WINE_LIBRARY_ROOT"
2443 else
2444 WINE_LIBRARY_PATH=""
2446 AC_PATH_LIBRARY(LIBNTDLL_PATH,[-lntdll],[$WINE_LIBRARY_PATH -lwine -lwine_unicode -lncurses -ldl -lutil],[
2447 AC_MSG_ERROR([Could not find the Wine libraries (libntdll.so)])
2448 ],[$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/dlls])
2449 if test -n "$LIBNTDLL_PATH" -a "-L$LIBNTDLL_PATH" != "$WINE_LIBRARY_PATH"
2450 then
2451 WINE_LIBRARY_PATH="$WINE_LIBRARY_PATH -L$LIBNTDLL_PATH"
2454 if test -z "$WINE_TOOL_PATH"
2455 then
2456 WINE_TOOL_PATH="$PATH:/usr/local/bin:/opt/wine/bin";
2458 AC_PATH_PROG(WINE,wine,,$WINE_TOOL_PATH)
2459 if test -z "$WINE"
2460 then
2461 AC_MSG_ERROR([Could not find Wine's wine tool])
2463 AC_PATH_PROG(WINEBUILD,winebuild,,$WINE_TOOL_PATH)
2464 if test -z "$WINEBUILD"
2465 then
2466 AC_MSG_ERROR([Could not find Wine's winebuild tool])
2468 AC_PATH_PROG(WRC,wrc,,$WINE_TOOL_PATH)
2469 if test -z "$WRC"
2470 then
2471 AC_MSG_ERROR([Could not find Wine's wrc tool])
2474 AC_SUBST(WINE_INCLUDE_PATH)
2475 AC_SUBST(WINE_LIBRARY_PATH)
2477 dnl **** Try to find where the MFC are located ****
2478 AC_LANG_CPLUSPLUS()
2480 if test "x$NEEDS_MFC" = "x1"
2481 then
2482 ATL_INCLUDE_ROOT="";
2483 ATL_INCLUDE_PATH="";
2484 MFC_INCLUDE_ROOT="";
2485 MFC_INCLUDE_PATH="";
2486 MFC_LIBRARY_ROOT="";
2487 MFC_LIBRARY_PATH="";
2489 AC_ARG_WITH(mfc,
2490 [ --with-mfc=DIR the MFC package (or sources) is in DIR],
2491 [if test "$withval" != "no"; then
2492 MFC_ROOT="$withval";
2493 ATL_INCLUDES="";
2494 MFC_INCLUDES="";
2495 MFC_LIBRARIES="";
2496 else
2497 MFC_ROOT="";
2498 fi])
2499 if test -n "$MFC_ROOT"
2500 then
2501 ATL_INCLUDE_ROOT="$MFC_ROOT";
2502 MFC_INCLUDE_ROOT="$MFC_ROOT";
2503 MFC_LIBRARY_ROOT="$MFC_ROOT";
2506 AC_ARG_WITH(atl-includes,
2507 [ --with-atl-includes=DIR the ATL includes are in DIR],
2508 [if test "$withval" != "no"; then
2509 ATL_INCLUDES="$withval";
2510 else
2511 ATL_INCLUDES="";
2512 fi])
2513 if test -n "$ATL_INCLUDES"
2514 then
2515 ATL_INCLUDE_ROOT="$ATL_INCLUDES";
2518 AC_ARG_WITH(mfc-includes,
2519 [ --with-mfc-includes=DIR the MFC includes are in DIR],
2520 [if test "$withval" != "no"; then
2521 MFC_INCLUDES="$withval";
2522 else
2523 MFC_INCLUDES="";
2524 fi])
2525 if test -n "$MFC_INCLUDES"
2526 then
2527 MFC_INCLUDE_ROOT="$MFC_INCLUDES";
2530 AC_ARG_WITH(mfc-libraries,
2531 [ --with-mfc-libraries=DIR the MFC libraries are in DIR],
2532 [if test "$withval" != "no"; then
2533 MFC_LIBRARIES="$withval";
2534 else
2535 MFC_LIBRARIES="";
2536 fi])
2537 if test -n "$MFC_LIBRARIES"
2538 then
2539 MFC_LIBRARY_ROOT="$MFC_LIBRARIES";
2542 OLDCPPFLAGS="$CPPFLAGS"
2543 dnl FIXME: We should not have defines in any of the include paths
2544 CPPFLAGS="$WINE_INCLUDE_PATH -I$WINE_INCLUDE_ROOT/mixedcrt -D_DLL -D_MT $CPPFLAGS"
2545 ATL_INCLUDE_PATH="-I\$(WINE_INCLUDE_ROOT)/mixedcrt -D_DLL -D_MT"
2546 if test -z "$ATL_INCLUDE_ROOT"
2547 then
2548 ATL_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/atl:/usr/include/atl:/usr/local/include/atl:/opt/mfc/include/atl:/opt/atl/include"
2549 else
2550 ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT:$ATL_INCLUDE_ROOT/atl:$ATL_INCLUDE_ROOT/atl/include"
2552 AC_PATH_HEADER(ATL_INCLUDE_ROOT,atldef.h,[
2553 AC_MSG_ERROR([Could not find the ATL includes])
2554 ],$ATL_INCLUDE_ROOT)
2555 if test -n "$ATL_INCLUDE_ROOT"
2556 then
2557 ATL_INCLUDE_PATH="$ATL_INCLUDE_PATH -I$ATL_INCLUDE_ROOT"
2560 MFC_INCLUDE_PATH="$ATL_INCLUDE_PATH"
2561 if test -z "$MFC_INCLUDE_ROOT"
2562 then
2563 MFC_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/mfc:/usr/include/mfc:/usr/local/include/mfc:/opt/mfc/include/mfc:/opt/mfc/include"
2564 else
2565 MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT:$MFC_INCLUDE_ROOT/mfc:$MFC_INCLUDE_ROOT/mfc/include"
2567 AC_PATH_HEADER(MFC_INCLUDE_ROOT,afx.h,[
2568 AC_MSG_ERROR([Could not find the MFC includes])
2569 ],$MFC_INCLUDE_ROOT)
2570 if test -n "$MFC_INCLUDE_ROOT" -a "$ATL_INCLUDE_ROOT" != "$MFC_INCLUDE_ROOT"
2571 then
2572 MFC_INCLUDE_PATH="$MFC_INCLUDE_PATH -I$MFC_INCLUDE_ROOT"
2574 CPPFLAGS="$OLDCPPFLAGS"
2576 if test -z "$MFC_LIBRARY_ROOT"
2577 then
2578 MFC_LIBRARY_ROOT=":$WINE_LIBRARY_ROOT:/usr/lib/mfc:/usr/local/lib:/usr/local/lib/mfc:/opt/mfc/lib";
2579 else
2580 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT:$MFC_LIBRARY_ROOT/lib:$MFC_LIBRARY_ROOT/mfc/src";
2582 AC_PATH_LIBRARY(MFC_LIBRARY_ROOT,[-lmfc],[$WINE_LIBRARY_PATH -lwine -lwine_unicode -lncurses -ldl -lutil -ladvapi32 -lcomctl32 -lcomdlg32 -lcrtdll -ldplayx -lgdi32 -limagehlp -lkernel32 -lodbc32 -lntdll -lole32 -loleaut32 -loledlg -lrpcrt4 -lshell32 -lshlwapi -luser32 -lwinmm -lwinspool.drv -lwow32 -lws2_32],[
2583 AC_MSG_ERROR([Could not find the MFC library])
2584 ],$MFC_LIBRARY_ROOT)
2585 if test -n "$MFC_LIBRARY_ROOT" -a "$MFC_LIBRARY_ROOT" != "$WINE_LIBRARY_ROOT"
2586 then
2587 MFC_LIBRARY_PATH="-L$MFC_LIBRARY_ROOT"
2588 else
2589 MFC_LIBRARY_PATH=""
2592 AC_SUBST(ATL_INCLUDE_PATH)
2593 AC_SUBST(MFC_INCLUDE_PATH)
2594 AC_SUBST(MFC_LIBRARY_PATH)
2597 AC_LANG_C()
2599 dnl **** Generate output files ****
2601 MAKE_RULES=Make.rules
2602 AC_SUBST_FILE(MAKE_RULES)
2604 AC_OUTPUT([
2605 Make.rules
2606 ##WINEMAKER_PROJECTS##
2609 echo
2610 echo "Configure finished. Do 'make' to build the project."
2611 echo
2613 dnl Local Variables:
2614 dnl comment-start: "dnl "
2615 dnl comment-end: ""
2616 dnl comment-start-skip: "\\bdnl\\b\\s *"
2617 dnl compile-command: "autoconf"
2618 dnl End:
2619 --- Make.rules.in ---
2620 # Copyright 2000 Francois Gouget for CodeWeavers
2621 # fgouget@codeweavers.com
2623 # Global rules shared by all makefiles -*-Makefile-*-
2625 # Each individual makefile must define the following variables:
2626 # WINE_INCLUDE_ROOT: Wine's headers location
2627 # WINE_LIBRARY_ROOT: Wine's libraries location
2628 # TOPOBJDIR : top-level object directory
2629 # SRCDIR : source directory for this module
2631 # Each individual makefile may define the following additional variables:
2633 # SUBDIRS : subdirectories that contain a Makefile
2634 # DLLS : WineLib libraries to be built
2635 # EXES : WineLib executables to be built
2637 # CEXTRA : extra c flags (e.g. '-Wall')
2638 # CXXEXTRA : extra c++ flags (e.g. '-Wall')
2639 # WRCEXTRA : extra wrc flags (e.g. '-p _SysRes')
2640 # DEFINES : defines (e.g. -DSTRICT)
2641 # INCLUDE_PATH : additional include path
2642 # LIBRARY_PATH : additional library path
2643 # LIBRARIES : additional Unix libraries to link with
2645 # C_SRCS : C sources for the module
2646 # CXX_SRCS : C++ sources for the module
2647 # RC_SRCS : resource source files
2648 # SPEC_SRCS : interface definition files
2651 # Where is Winelib
2653 WINE_INCLUDE_ROOT = @WINE_INCLUDE_ROOT@
2654 WINE_INCLUDE_PATH = @WINE_INCLUDE_PATH@
2655 WINE_LIBRARY_ROOT = @WINE_LIBRARY_ROOT@
2656 WINE_LIBRARY_PATH = @WINE_LIBRARY_PATH@
2658 # Where are the MFC
2660 ATL_INCLUDE_ROOT = @ATL_INCLUDE_ROOT@
2661 ATL_INCLUDE_PATH = @ATL_INCLUDE_PATH@
2662 MFC_INCLUDE_ROOT = @MFC_INCLUDE_ROOT@
2663 MFC_INCLUDE_PATH = @MFC_INCLUDE_PATH@
2664 MFC_LIBRARY_ROOT = @MFC_LIBRARY_ROOT@
2665 MFC_LIBRARY_PATH = @MFC_LIBRARY_PATH@
2667 # First some useful definitions
2669 SHELL = /bin/sh
2670 CC = @CC@
2671 CPP = @CPP@
2672 CFLAGS = @CFLAGS@
2673 CXXFLAGS = @CXXFLAGS@
2674 OPTIONS = @OPTIONS@ -D_REENTRANT -DWINELIB
2675 X_CFLAGS = @X_CFLAGS@
2676 X_LIBS = @X_LIBS@
2677 XLIB = @X_PRE_LIBS@ @XLIB@ @X_EXTRA_LIBS@
2678 DLL_LINK = @DLL_LINK@
2679 LIBS = @LIBS@ $(LIBRARY_PATH)
2680 YACC = @YACC@
2681 LEX = @LEX@
2682 LEXLIB = @LEXLIB@
2683 LN_S = @LN_S@
2684 DIVINCL = -I$(SRCDIR) $(WINE_INCLUDE_PATH) $(INCLUDE_PATH)
2685 ALLCFLAGS = $(DIVINCL) $(CFLAGS) $(CEXTRA) $(OPTIONS) $(X_CFLAGS) $(DEFINES)
2686 ALLCXXFLAGS = $(DIVINCL) $(CXXFLAGS) $(CXXEXTRA) $(OPTIONS) $(X_CFLAGS) $(DEFINES)
2687 LDCOMBINE = ld -r
2688 LDSHARED = @LDSHARED@
2689 LDDLLFLAGS= @LDDLLFLAGS@
2690 STRIP = strip
2691 STRIPFLAGS= --strip-unneeded
2692 RM = rm -f
2693 MV = mv
2694 MKDIR = mkdir -p
2695 WINE = @WINE@
2696 WINEBUILD = @WINEBUILD@
2697 WRC = @WRC@
2698 WRCFLAGS = -r -L
2699 @SET_MAKE@
2701 # Installation infos
2703 INSTALL = @INSTALL@
2704 INSTALL_PROGRAM = @INSTALL_PROGRAM@
2705 INSTALL_DATA = @INSTALL_DATA@
2706 prefix = @prefix@
2707 exec_prefix = @exec_prefix@
2708 bindir = @bindir@
2709 libdir = @libdir@
2710 infodir = @infodir@
2711 mandir = @mandir@
2712 prog_manext = 1
2713 conf_manext = 5
2714 CLEAN_FILES = *.o *.a *.so \\\#*\\\# *~ *% .\\\#* *.orig *.rej \
2715 *.spec.c y.tab.c y.tab.h lex.yy.c core
2717 OBJS = $(SPEC_SRCS:.spec=.spec.o) $(C_SRCS:.c=.o) $(CXX_SRCS:.cpp=.o)
2719 # Implicit rules
2721 .SUFFIXES: .C .cpp .CPP .cxx .CXX .rc .RC .res .tmp.o .spec .spec.c .spec.o
2723 .c.o:
2724 $(CC) -c $(ALLCFLAGS) -o $@ $<
2726 .C.o:
2727 $(CC) -c $(ALLCFLAGS) -o $@ $<
2729 .cpp.o:
2730 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2732 .CPP.o:
2733 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2735 .cxx.o:
2736 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2738 .CXX.o:
2739 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2741 .rc.res:
2742 $(WRC) $(WRCFLAGS) $(WRCEXTRA) $(DIVINCL) -o $@ $<
2744 .RC.res:
2745 $(WRC) $(WRCFLAGS) $(WRCEXTRA) $(DIVINCL) -o $@ $<
2747 .PHONY: all install uninstall clean distclean depend dummy
2749 # 'all' target first in case the enclosing Makefile didn't define any target
2751 all: Makefile
2753 # Rules for makefile
2755 Makefile: Makefile.in $(TOPSRCDIR)/configure
2756 @echo Makefile is older than $?, please rerun $(TOPSRCDIR)/configure
2757 @exit 1
2759 # Rules for cleaning
2761 $(SUBDIRS:%=%/__clean__): dummy
2762 cd `dirname $@` && $(MAKE) clean
2764 $(EXTRASUBDIRS:%=%/__clean__): dummy
2765 -cd `dirname $@` && $(RM) $(CLEAN_FILES)
2767 clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
2768 $(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(EXES) $(EXES:%=%.so) $(DLLS)
2770 # Rules for installing
2772 $(SUBDIRS:%=%/__install__): dummy
2773 cd `dirname $@` && $(MAKE) install
2775 $(SUBDIRS:%=%/__uninstall__): dummy
2776 cd `dirname $@` && $(MAKE) uninstall
2778 # Misc. rules
2780 $(SUBDIRS): dummy
2781 @cd $@ && $(MAKE)
2783 dummy:
2785 # End of global rules
2786 --- wrapper.c ---
2788 * Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2791 #include <dlfcn.h>
2792 #include <windows.h>
2797 * Describe the wrapped application
2801 * This is either CUIEXE for a console based application or
2802 * GUIEXE for a regular windows application.
2804 #define APP_TYPE ##WINEMAKER_APP_TYPE##
2807 * This is the application library's base name, i.e. 'hello' if the
2808 * library is called 'libhello.so'.
2810 static char* appName = ##WINEMAKER_APP_NAME##;
2813 * This is the name of the application's Windows module. If left NULL
2814 * then appName is used.
2816 static char* appModule = NULL;
2819 * This is the application's entry point. This is usually "WinMain" for a
2820 * GUIEXE and 'main' for a CUIEXE application.
2822 static char* appInit = ##WINEMAKER_APP_INIT##;
2825 * This is either non-NULL for MFC-based applications and is the name of the
2826 * MFC's module. This is the module in which we will take the 'WinMain'
2827 * function.
2829 static char* mfcModule = ##WINEMAKER_APP_MFC##;
2834 * Implement the main.
2837 #if APP_TYPE == GUIEXE
2838 typedef int WINAPI (*WinMainFunc)(HINSTANCE hInstance, HINSTANCE hPrevInstance,
2839 PSTR szCmdLine, int iCmdShow);
2840 #else
2841 typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp);
2842 #endif
2844 #if APP_TYPE == GUIEXE
2845 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
2846 PSTR szCmdLine, int iCmdShow)
2847 #else
2848 int WINAPI Main(int argc, char** argv, char** envp)
2849 #endif
2851 void* appLibrary;
2852 HINSTANCE hApp,hMFC,hMain;
2853 void* appMain;
2854 char* libName;
2855 int retcode;
2857 /* Load the application's library */
2858 libName=(char*)malloc(strlen(appName)+5+3+1);
2859 /* FIXME: we should get the wrapper's path and use that as the base for
2860 * the library
2862 sprintf(libName,"./lib%s.so",appName);
2863 appLibrary=dlopen(libName,RTLD_NOW);
2864 if (appLibrary==NULL) {
2865 sprintf(libName,"lib%s.so",appName);
2866 appLibrary=dlopen(libName,RTLD_NOW);
2868 if (appLibrary==NULL) {
2869 char format[]="Could not load the %s library:\r\n%s";
2870 char* error;
2871 char* msg;
2873 error=dlerror();
2874 msg=(char*)malloc(strlen(format)+strlen(libName)+strlen(error));
2875 sprintf(msg,format,libName,error);
2876 MessageBox(NULL,msg,"dlopen error",MB_OK);
2877 free(msg);
2878 return 1;
2881 /* Then if this application is MFC based, load the MFC module */
2882 /* FIXME: I'm not sure this is really necessary */
2883 if (mfcModule!=NULL) {
2884 hMFC=LoadLibrary(mfcModule);
2885 if (hMFC==NULL) {
2886 char format[]="Could not load the MFC module %s (%d)";
2887 char* msg;
2889 msg=(char*)malloc(strlen(format)+strlen(mfcModule)+11);
2890 sprintf(msg,format,mfcModule,GetLastError());
2891 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
2892 free(msg);
2893 return 1;
2895 /* MFC is a special case: the WinMain is in the MFC library,
2896 * instead of the application's library.
2898 hMain=hMFC;
2899 } else {
2900 hMFC=NULL;
2903 /* Load the application's module */
2904 if (appModule==NULL) {
2905 appModule=appName;
2907 hApp=LoadLibrary(appModule);
2908 if (hApp==NULL) {
2909 char format[]="Could not load the application's module %s (%d)";
2910 char* msg;
2912 msg=(char*)malloc(strlen(format)+strlen(appModule)+11);
2913 sprintf(msg,format,appModule,GetLastError());
2914 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
2915 free(msg);
2916 return 1;
2917 } else if (hMain==NULL) {
2918 hMain=hApp;
2921 /* Get the address of the application's entry point */
2922 appMain=(WinMainFunc*)GetProcAddress(hMain, appInit);
2923 if (appMain==NULL) {
2924 char format[]="Could not get the address of %s (%d)";
2925 char* msg;
2927 msg=(char*)malloc(strlen(format)+strlen(appInit)+11);
2928 sprintf(msg,format,appInit,GetLastError());
2929 MessageBox(NULL,msg,"GetProcAddress error",MB_OK);
2930 free(msg);
2931 return 1;
2934 /* And finally invoke the application's entry point */
2935 #if APP_TYPE == GUIEXE
2936 retcode=(*((WinMainFunc)appMain))(hApp,hPrevInstance,szCmdLine,iCmdShow);
2937 #else
2938 retcode=(*((MainFunc)appMain))(argc,argv,envp);
2939 #endif
2941 /* Cleanup and done */
2942 FreeLibrary(hApp);
2943 if (hMFC!=NULL) {
2944 FreeLibrary(hMFC);
2946 dlclose(appLibrary);
2947 free(libName);
2949 return retcode;