Link with msvcrt and use the msvcrt headers by default to improve the
[wine/hacks.git] / tools / winemaker
blobaac82475d0697b26a063a9ef77e08671189c8cc0
1 #!/usr/bin/perl -w
2 use strict;
4 # Copyright 2000-2002 Francois Gouget for CodeWeavers
5 # fgouget@codeweavers.com
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 my $version="0.5.9";
24 use Cwd;
25 use File::Basename;
26 use File::Copy;
30 #####
32 # Options
34 #####
36 # The following constants define what we do with the case of filenames
39 # Never rename a file to lowercase
40 my $OPT_LOWER_NONE=0;
43 # Rename all files to lowercase
44 my $OPT_LOWER_ALL=1;
47 # Rename only files that are all uppercase to lowercase
48 my $OPT_LOWER_UPPERCASE=2;
51 # The following constants define whether to ask questions or not
54 # No (synonym of never)
55 my $OPT_ASK_NO=0;
58 # Yes (always)
59 my $OPT_ASK_YES=1;
62 # Skip the questions till the end of this scope
63 my $OPT_ASK_SKIP=-1;
66 # General options
69 # This is the directory in which winemaker will operate.
70 my $opt_work_dir;
73 # Make a backup of the files
74 my $opt_backup;
77 # Defines which files to rename
78 my $opt_lower;
81 # If we don't find the file referenced by an include, lower it
82 my $opt_lower_include;
85 # If true then winemaker should not attempt to fix the source. This is
86 # useful if the source is known to be already in a suitable form and is
87 # readonly
88 my $opt_no_source_fix;
90 # Options for the 'Source' method
93 # Specifies that we have only one target so that all sources relate
94 # to this target. By default this variable is left undefined which
95 # means winemaker should try to find out by itself what the targets
96 # are. If not undefined then this contains the name of the default
97 # target (without the extension).
98 my $opt_single_target;
101 # If '$opt_single_target' has been specified then this is the type of
102 # that target. Otherwise it specifies whether the default target type
103 # is guiexe or cuiexe.
104 my $opt_target_type;
107 # Contains the default set of flags to be used when creating a new target.
108 my $opt_flags;
111 # If true then winemaker should ask questions to the user as it goes
112 # along.
113 my $opt_is_interactive;
114 my $opt_ask_project_options;
115 my $opt_ask_target_options;
118 # If false then winemaker should not generate any file, i.e.
119 # no makefiles, but also no .spec files, no configure.in, etc.
120 my $opt_no_generated_files;
123 # If true then winemaker should not generate the spec files.
124 # This is useful if winemaker is being used to create a build environment
125 my $opt_no_generated_specs;
128 # Specifies not to print the banner if set.
129 my $opt_no_banner;
133 #####
135 # Target modelization
137 #####
139 # The description of a target is stored in an array. The constants
140 # below identify what is stored at each index of the array.
143 # This is the name of the target.
144 my $T_NAME=0;
147 # Defines the type of target we want to build. See the TT_xxx
148 # constants below
149 my $T_TYPE=1;
152 # Defines the target's enty point, i.e. the function that is called
153 # on startup.
154 my $T_INIT=2;
157 # This is a bitfield containing flags refining the way the target
158 # should be handled. See the TF_xxx constants below
159 my $T_FLAGS=3;
162 # This is a reference to an array containing the list of the
163 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
164 my $T_SOURCES_C=4;
165 my $T_SOURCES_CXX=5;
166 my $T_SOURCES_RC=6;
167 my $T_SOURCES_MISC=7;
170 # This is a reference to an array containing the list of macro
171 # definitions
172 my $T_DEFINES=8;
175 # This is a reference to an array containing the list of directory
176 # names that constitute the include path
177 my $T_INCLUDE_PATH=9;
180 # Same as T_INCLUDE_PATH but for the dll search path
181 my $T_DLL_PATH=10;
184 # The list of Windows dlls to import
185 my $T_DLLS=11;
188 # Same as T_INCLUDE_PATH but for the library search path
189 my $T_LIBRARY_PATH=12;
192 # The list of Unix libraries to link with
193 my $T_LIBRARIES=13;
196 # The list of dependencies between targets
197 my $T_DEPENDS=14;
200 # The following constants define the recognized types of target
203 # This is not a real target. This type of target is used to collect
204 # the sources that don't seem to belong to any other target. Thus no
205 # real target is generated for them, we just put the sources of the
206 # fake target in the global source list.
207 my $TT_SETTINGS=0;
210 # For executables in the windows subsystem
211 my $TT_GUIEXE=1;
214 # For executables in the console subsystem
215 my $TT_CUIEXE=2;
218 # For dynamically linked libraries
219 my $TT_DLL=3;
222 # The following constants further refine how the target should be handled
225 # This target needs a wrapper
226 my $TF_WRAP=1;
229 # This target is a wrapper
230 my $TF_WRAPPER=2;
233 # This target is an MFC-based target
234 my $TF_MFC=4;
237 # User has specified --nomfc option for this target or globally
238 my $TF_NOMFC=8;
241 # --nodlls option: Do not use standard DLL set
242 my $TF_NODLLS=16;
245 # --nomsvcrt option: Do not link with msvcrt
246 my $TF_NOMSVCRT=32;
249 # Initialize a target:
250 # - set the target type to TT_SETTINGS, i.e. no real target will
251 # be generated.
252 sub target_init($)
254 my $target=$_[0];
256 @$target[$T_TYPE]=$TT_SETTINGS;
257 # leaving $T_INIT undefined
258 @$target[$T_FLAGS]=$opt_flags;
259 @$target[$T_SOURCES_C]=[];
260 @$target[$T_SOURCES_CXX]=[];
261 @$target[$T_SOURCES_RC]=[];
262 @$target[$T_SOURCES_MISC]=[];
263 @$target[$T_DEFINES]=[];
264 @$target[$T_INCLUDE_PATH]=[];
265 @$target[$T_DLL_PATH]=[];
266 @$target[$T_DLLS]=[];
267 @$target[$T_LIBRARY_PATH]=[];
268 @$target[$T_LIBRARIES]=[];
269 @$target[$T_DEPENDS]=[];
272 sub get_default_init($)
274 my $type=$_[0];
275 if ($type == $TT_GUIEXE) {
276 return "WinMain";
277 } elsif ($type == $TT_CUIEXE) {
278 return "main";
279 } elsif ($type == $TT_DLL) {
280 return "DllMain";
286 #####
288 # Project modelization
290 #####
292 # First we have the notion of project. A project is described by an
293 # array (since we don't have structs in perl). The constants below
294 # identify what is stored at each index of the array.
297 # This is the path in which this project is located. In other
298 # words, this is the path to the Makefile.
299 my $P_PATH=0;
302 # This index contains a reference to an array containing the project-wide
303 # settings. The structure of that arrray is actually identical to that of
304 # a regular target since it can also contain extra sources.
305 my $P_SETTINGS=1;
308 # This index contains a reference to an array of targets for this
309 # project. Each target describes how an executable or library is to
310 # be built. For each target this description takes the same form as
311 # that of the project: an array. So this entry is an array of arrays.
312 my $P_TARGETS=2;
315 # Initialize a project:
316 # - set the project's path
317 # - initialize the target list
318 # - create a default target (will be removed later if unnecessary)
319 sub project_init($$)
321 my $project=$_[0];
322 my $path=$_[1];
324 my $project_settings=[];
325 target_init($project_settings);
327 @$project[$P_PATH]=$path;
328 @$project[$P_SETTINGS]=$project_settings;
329 @$project[$P_TARGETS]=[];
334 #####
336 # Global variables
338 #####
340 my %warnings;
342 my %templates;
345 # Contains the list of all projects. This list tells us what are
346 # the subprojects of the main Makefile and where we have to generate
347 # Makefiles.
348 my @projects=();
351 # This is the main project, i.e. the one in the "." directory.
352 # It may well be empty in which case the main Makefile will only
353 # call out subprojects.
354 my @main_project;
357 # Contains the defaults for the include path, etc.
358 # We store the defaults as if this were a target except that we only
359 # exploit the defines, include path, library path, library list and misc
360 # sources fields.
361 my @global_settings;
364 # If one of the projects requires the MFc then we set this global variable
365 # to true so that configure asks the user to provide a path tothe MFC
366 my $needs_mfc=0;
370 #####
372 # Utility functions
374 #####
377 # Cleans up a name to make it an acceptable Makefile
378 # variable name.
379 sub canonize($)
381 my $name=$_[0];
383 $name =~ tr/a-zA-Z0-9_/_/c;
384 return $name;
388 # Returns true is the specified pathname is absolute.
389 # Note: pathnames that start with a variable '$' or
390 # '~' are considered absolute.
391 sub is_absolute($)
393 my $path=$_[0];
395 return ($path =~ /^[\/~\$]/);
399 # Performs a binary search looking for the specified item
400 sub bsearch($$)
402 my $array=$_[0];
403 my $item=$_[1];
404 my $last=@{$array}-1;
405 my $first=0;
407 while ($first<=$last) {
408 my $index=int(($first+$last)/2);
409 my $cmp=@$array[$index] cmp $item;
410 if ($cmp<0) {
411 $first=$index+1;
412 } elsif ($cmp>0) {
413 $last=$index-1;
414 } else {
415 return $index;
422 #####
424 # 'Source'-based Project analysis
426 #####
429 # Allows the user to specify makefile and target specific options
430 # - target: the structure in which to store the results
431 # - options: the string containing the options
432 sub source_set_options($$)
434 my $target=$_[0];
435 my $options=$_[1];
437 #FIXME: we must deal with escaping of stuff and all
438 foreach my $option (split / /,$options) {
439 if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
440 push @{@$target[$T_DEFINES]},$option;
441 } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
442 push @{@$target[$T_INCLUDE_PATH]},$option;
443 } elsif ($option =~ /^-P/) {
444 push @{@$target[$T_DLL_PATH]},"-L$'";
445 } elsif ($option =~ /^-i/) {
446 my $dllname = $';
447 if ($dllname =~ /^msvcrt$/) {
448 push @{@$target[$T_INCLUDE_PATH]},"-I\$(WINE_INCLUDE_ROOT)/msvcrt";
450 push @{@$target[$T_DLLS]},$dllname;
451 } elsif ($option =~ /^-L/) {
452 push @{@$target[$T_LIBRARY_PATH]},$option;
453 } elsif ($option =~ /^-l/) {
454 push @{@$target[$T_LIBRARIES]},"$'";
455 } elsif ($option =~ /^--wrap/) {
456 if (@$target[$T_TYPE] != $TT_DLL) {
457 @$target[$T_FLAGS]|=$TF_WRAP;
458 } else {
459 print STDERR "warning: option --wrap is illegal for DLLs - ignoring";
461 } elsif ($option =~ /^--nowrap/) {
462 if (@$target[$T_TYPE] != $TT_DLL) {
463 @$target[$T_FLAGS]&=~$TF_WRAP;
464 } else {
465 print STDERR "warning: option --nowrap is illegal for DLLs - ignoring";
467 } elsif ($option =~ /^--mfc/) {
468 @$target[$T_FLAGS]|=$TF_MFC;
469 @$target[$T_FLAGS]&=~$TF_NOMFC;
470 } elsif ($option =~ /^--nomfc/) {
471 @$target[$T_FLAGS]&=~$TF_MFC;
472 @$target[$T_FLAGS]|=$TF_NOMFC;
473 } elsif ($option =~ /^--nodlls/) {
474 @$target[$T_FLAGS]|=$TF_NODLLS;
475 } elsif ($option =~ /^--nomsvcrt/) {
476 @$target[$T_FLAGS]|=$TF_NOMSVCRT;
477 } else {
478 print STDERR "error: unknown option \"$option\"\n";
479 return 0;
482 if (@$target[$T_TYPE] != $TT_DLL &&
483 @$target[$T_FLAGS] & $TF_MFC &&
484 !(@$target[$T_FLAGS] & $TF_WRAP)) {
485 print STDERR "info: option --mfc requires --wrap";
486 @$target[$T_FLAGS]|=$TF_WRAP;
488 return 1;
492 # Scans the specified directory to:
493 # - see if we should create a Makefile in this directory. We normally do
494 # so if we find a project file and sources
495 # - get a list of targets for this directory
496 # - get the list of source files
497 sub source_scan_directory($$$$);
498 sub source_scan_directory($$$$)
500 # a reference to the parent's project
501 my $parent_project=$_[0];
502 # the full relative path to the current directory, including a
503 # trailing '/', or an empty string if this is the top level directory
504 my $path=$_[1];
505 # the name of this directory, including a trailing '/', or an empty
506 # string if this is the top level directory
507 my $dirname=$_[2];
508 # if set then no targets will be looked for and the sources will all
509 # end up in the parent_project's 'misc' bucket
510 my $no_target=$_[3];
512 # reference to the project for this directory. May not be used
513 my $project;
514 # list of targets found in the 'current' directory
515 my %targets;
516 # list of sources found in the current directory
517 my @sources_c=();
518 my @sources_cxx=();
519 my @sources_rc=();
520 my @sources_misc=();
521 # true if this directory contains a Windows project
522 my $has_win_project=0;
523 # If we don't find any executable/library then we might make up targets
524 # from the list of .dsp/.mak files we find since they usually have the
525 # same name as their target.
526 my @dsp_files=();
527 my @mak_files=();
529 if (defined $opt_single_target or $dirname eq "") {
530 # Either there is a single target and thus a single project,
531 # or we are in the top level directory for which a project
532 # already exists
533 $project=$parent_project;
534 } else {
535 $project=[];
536 project_init($project,$path);
538 my $project_settings=@$project[$P_SETTINGS];
540 # First find out what this directory contains:
541 # collect all sources, targets and subdirectories
542 my $directory=get_directory_contents($path);
543 foreach my $dentry (@$directory) {
544 if ($dentry =~ /^\./) {
545 next;
547 my $fullentry="$path$dentry";
548 if (-d "$fullentry") {
549 if ($dentry =~ /^(Release|Debug)/i) {
550 # These directories are often used to store the object files and the
551 # resulting executable/library. They should not contain anything else.
552 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
553 foreach my $candidate (@candidates) {
554 $targets{$candidate}=1;
556 } elsif ($dentry =~ /^include/i) {
557 # This directory must contain headers we're going to need
558 push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
559 source_scan_directory($project,"$fullentry/","$dentry/",1);
560 } else {
561 # Recursively scan this directory. Any source file that cannot be
562 # attributed to a project in one of the subdirectories will be
563 # attributed to this project.
564 source_scan_directory($project,"$fullentry/","$dentry/",$no_target);
566 } elsif (-f "$fullentry") {
567 if ($dentry =~ /\.(exe|dll)$/i) {
568 $targets{$dentry}=1;
569 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
570 push @sources_c,"$dentry";
571 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
572 if ($dentry =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
573 push @sources_misc,"$dentry";
574 @$project_settings[$T_FLAGS]|=$TF_MFC;
575 } else {
576 push @sources_cxx,"$dentry";
578 } elsif ($dentry =~ /\.rc$/i) {
579 push @sources_rc,"$dentry";
580 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
581 push @sources_misc,"$dentry";
582 if ($dentry =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
583 @$project_settings[$T_FLAGS]|=$TF_MFC;
585 } elsif ($dentry =~ /\.dsp$/i) {
586 push @dsp_files,"$dentry";
587 $has_win_project=1;
588 } elsif ($dentry =~ /\.mak$/i) {
589 push @mak_files,"$dentry";
590 $has_win_project=1;
591 } elsif ($dentry =~ /^makefile/i) {
592 $has_win_project=1;
596 closedir(DIRECTORY);
598 # If we have a single target then all we have to do is assign
599 # all the sources to it and we're done
600 # FIXME: does this play well with the --interactive mode?
601 if ($opt_single_target) {
602 my $target=@{@$project[$P_TARGETS]}[0];
603 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
604 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
605 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
606 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
607 return;
609 if ($no_target) {
610 my $parent_settings=@$parent_project[$P_SETTINGS];
611 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
612 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
613 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
614 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
615 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
616 return;
619 my $source_count=@sources_c+@sources_cxx+@sources_rc+
620 @{@$project_settings[$T_SOURCES_C]}+
621 @{@$project_settings[$T_SOURCES_CXX]}+
622 @{@$project_settings[$T_SOURCES_RC]};
623 if ($source_count == 0) {
624 # A project without real sources is not a project, get out!
625 if ($project!=$parent_project) {
626 my $parent_settings=@$parent_project[$P_SETTINGS];
627 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
628 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
630 return;
632 #print "targets=",%targets,"\n";
633 #print "target_count=$target_count\n";
634 #print "has_win_project=$has_win_project\n";
635 #print "dirname=$dirname\n";
637 my $target_count;
638 if (($has_win_project != 0) or ($dirname eq "")) {
639 # Deal with cases where we could not find any executable/library, and
640 # thus have no target, although we did find some sort of windows project.
641 $target_count=keys %targets;
642 if ($target_count == 0) {
643 # Try to come up with a target list based on .dsp/.mak files
644 my $prj_list;
645 if (@dsp_files > 0) {
646 $prj_list=\@dsp_files;
647 } else {
648 $prj_list=\@mak_files;
650 foreach my $filename (@$prj_list) {
651 $filename =~ s/\.(dsp|mak)$//i;
652 if ($opt_target_type == $TT_DLL) {
653 $filename = "$filename.dll";
655 $targets{$filename}=1;
657 $target_count=keys %targets;
658 if ($target_count == 0) {
659 # Still nothing, try the name of the directory
660 my $name;
661 if ($dirname eq "") {
662 # Bad luck, this is the top level directory!
663 $name=(split /\//, cwd)[-1];
664 } else {
665 $name=$dirname;
666 # Remove the trailing '/'. Also eliminate whatever is after the last
667 # '.' as it is likely to be meaningless (.orig, .new, ...)
668 $name =~ s+(/|\.[^.]*)$++;
669 if ($name eq "src") {
670 # 'src' is probably a subdirectory of the real project directory.
671 # Try again with the parent (if any).
672 my $parent=$path;
673 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
674 $name=$parent;
675 } else {
676 $name=(split /\//, cwd)[-1];
680 $name =~ s+(/|\.[^.]*)$++;
681 if ($opt_target_type == $TT_DLL) {
682 $name = "$name.dll";
683 } else {
684 $name = "$name.exe";
686 $targets{$name}=1;
690 # Ask confirmation to the user if he wishes so
691 if ($opt_is_interactive == $OPT_ASK_YES) {
692 my $target_list=join " ",keys %targets;
693 print "\n*** In ",($path?$path:"./"),"\n";
694 print "* winemaker found the following list of (potential) targets\n";
695 print "* $target_list\n";
696 print "* Type enter to use it as is, your own comma-separated list of\n";
697 print "* targets, 'none' to assign the source files to a parent directory,\n";
698 print "* or 'ignore' to ignore everything in this directory tree.\n";
699 print "* Target list:\n";
700 $target_list=<STDIN>;
701 chomp $target_list;
702 if ($target_list eq "") {
703 # Keep the target list as is, i.e. do nothing
704 } elsif ($target_list eq "none") {
705 # Empty the target list
706 undef %targets;
707 } elsif ($target_list eq "ignore") {
708 # Ignore this subtree altogether
709 return;
710 } else {
711 undef %targets;
712 foreach my $target (split /,/,$target_list) {
713 $target =~ s+^\s*++;
714 $target =~ s+\s*$++;
715 $targets{$target}=1;
721 # If we have no project at this level, then transfer all
722 # the sources to the parent project
723 $target_count=keys %targets;
724 if ($target_count == 0) {
725 if ($project!=$parent_project) {
726 my $parent_settings=@$parent_project[$P_SETTINGS];
727 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
728 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
729 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
730 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
731 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
733 return;
736 # Otherwise add this project to the project list, except for
737 # the main project which is already in the list.
738 if ($dirname ne "") {
739 push @projects,$project;
742 # Ask for project-wide options
743 if ($opt_ask_project_options == $OPT_ASK_YES) {
744 my $flag_desc="";
745 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
746 $flag_desc="mfc";
748 if ((@$project_settings[$T_FLAGS] & $TF_WRAP)!=0) {
749 if ($flag_desc ne "") {
750 $flag_desc.=", ";
752 $flag_desc.="wrapped";
754 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc/--wrap),\n";
755 if (defined $flag_desc) {
756 print "* (currently $flag_desc)\n";
758 print "* or 'skip' to skip the target specific options,\n";
759 print "* or 'never' to not be asked this question again:\n";
760 while (1) {
761 my $options=<STDIN>;
762 chomp $options;
763 if ($options eq "skip") {
764 $opt_ask_target_options=$OPT_ASK_SKIP;
765 last;
766 } elsif ($options eq "never") {
767 $opt_ask_project_options=$OPT_ASK_NO;
768 last;
769 } elsif (source_set_options($project_settings,$options)) {
770 last;
772 print "Please re-enter the options:\n";
776 # - Create the targets
777 # - Check if we have both libraries and programs
778 # - Match each target with source files (sort in reverse
779 # alphabetical order to get the longest matches first)
780 my @local_dlls=();
781 my @local_depends=();
782 my @exe_list=();
783 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
784 # Create the target...
785 my $target=[];
786 target_init($target);
787 @$target[$T_NAME]=$target_name;
788 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
789 if ($target_name =~ /\.dll$/) {
790 @$target[$T_TYPE]=$TT_DLL;
791 @$target[$T_INIT]=get_default_init($TT_DLL);
792 @$target[$T_FLAGS]&=~$TF_WRAP;
793 push @local_depends,"$target_name.so";
794 push @local_dlls,$target_name;
795 } else {
796 @$target[$T_TYPE]=$opt_target_type;
797 @$target[$T_INIT]=get_default_init($opt_target_type);
798 push @exe_list,$target;
800 my $basename=$target_name;
801 $basename=~ s/\.(dll|exe)$//i;
802 # This is the default link list of Visual Studio, except odbccp32
803 # which we don't have in Wine.
804 my @std_imports=qw(advapi32 comdlg32 gdi32 kernel32 odbc32 ole32 oleaut32 shell32 user32 winspool);
805 my @std_libraries=qw(uuid);
806 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
807 @$target[$T_DLLS]=\@std_imports;
808 @$target[$T_LIBRARIES]=\@std_libraries;
809 } else {
810 @$target[$T_DLLS]=[];
811 @$target[$T_LIBRARIES]=[];
813 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
814 push @{@$target[$T_DLLS]},"msvcrt";
816 push @{@$project[$P_TARGETS]},$target;
818 # Ask for target-specific options
819 if ($opt_ask_target_options == $OPT_ASK_YES) {
820 my $flag_desc="";
821 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
822 $flag_desc=" (mfc";
824 if ((@$target[$T_FLAGS] & $TF_WRAP)!=0) {
825 if ($flag_desc ne "") {
826 $flag_desc.=", ";
827 } else {
828 $flag_desc=" (";
830 $flag_desc.="wrapped";
832 if ($flag_desc ne "") {
833 $flag_desc.=")";
835 print "* Specify any link option (-P/-i/-L/-l/--mfc/--wrap) specific to the target\n";
836 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
837 while (1) {
838 my $options=<STDIN>;
839 chomp $options;
840 if ($options eq "never") {
841 $opt_ask_target_options=$OPT_ASK_NO;
842 last;
843 } elsif (source_set_options($target,$options)) {
844 last;
846 print "Please re-enter the options:\n";
849 push @{@$target[$T_DLL_PATH]},"-L\$(WINE_DLL_ROOT)";
850 if (@$target[$T_FLAGS] & $TF_MFC) {
851 @$project_settings[$T_FLAGS]|=$TF_MFC;
852 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
853 push @{@$target[$T_DLLS]},"mfc.dll";
854 # FIXME: Link with the MFC in the Unix sense, until we
855 # start exporting the functions properly.
856 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
857 push @{@$target[$T_LIBRARIES]},"mfc";
860 # Match sources...
861 if ($target_count == 1) {
862 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
863 @$project_settings[$T_SOURCES_C]=[];
864 @sources_c=();
866 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
867 @$project_settings[$T_SOURCES_CXX]=[];
868 @sources_cxx=();
870 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
871 @$project_settings[$T_SOURCES_RC]=[];
872 @sources_rc=();
874 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
875 # No need for sorting these sources
876 @$project_settings[$T_SOURCES_MISC]=[];
877 @sources_misc=();
878 } else {
879 foreach my $source (@sources_c) {
880 if ($source =~ /^$basename/i) {
881 push @{@$target[$T_SOURCES_C]},$source;
882 $source="";
885 foreach my $source (@sources_cxx) {
886 if ($source =~ /^$basename/i) {
887 push @{@$target[$T_SOURCES_CXX]},$source;
888 $source="";
891 foreach my $source (@sources_rc) {
892 if ($source =~ /^$basename/i) {
893 push @{@$target[$T_SOURCES_RC]},$source;
894 $source="";
897 foreach my $source (@sources_misc) {
898 if ($source =~ /^$basename/i) {
899 push @{@$target[$T_SOURCES_MISC]},$source;
900 $source="";
904 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
905 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
906 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
907 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
909 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
910 $opt_ask_target_options=$OPT_ASK_YES;
913 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
914 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
916 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT)==0) {
917 push @{@$project_settings[$T_INCLUDE_PATH]},"-I\$(WINE_INCLUDE_ROOT)/msvcrt";
919 # The sources that did not match, if any, go to the extra
920 # source list of the project settings
921 foreach my $source (@sources_c) {
922 if ($source ne "") {
923 push @{@$project_settings[$T_SOURCES_C]},$source;
926 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
927 foreach my $source (@sources_cxx) {
928 if ($source ne "") {
929 push @{@$project_settings[$T_SOURCES_CXX]},$source;
932 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
933 foreach my $source (@sources_rc) {
934 if ($source ne "") {
935 push @{@$project_settings[$T_SOURCES_RC]},$source;
938 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
939 foreach my $source (@sources_misc) {
940 if ($source ne "") {
941 push @{@$project_settings[$T_SOURCES_MISC]},$source;
944 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
946 # Finally if we are building both libraries and programs in
947 # this directory, then the programs should be linked with all
948 # the libraries
949 if (@local_dlls > 0 and @exe_list > 0) {
950 foreach my $target (@exe_list) {
951 push @{@$target[$T_DLL_PATH]},"-L.";
952 push @{@$target[$T_DLLS]},@local_dlls;
953 push @{@$target[$T_DEPENDS]},@local_depends;
959 # Scan the source directories in search of things to build
960 sub source_scan()
962 # If there's a single target then this is going to be the default target
963 if (defined $opt_single_target) {
964 # Create the main target
965 my $main_target=[];
966 target_init($main_target);
967 @$main_target[$T_NAME]=$opt_single_target;
968 @$main_target[$T_TYPE]=$opt_target_type;
970 # Add it to the list
971 push @{$main_project[$P_TARGETS]},$main_target;
974 # The main directory is always going to be there
975 push @projects,\@main_project;
977 # Now scan the directory tree looking for source files and, maybe, targets
978 print "Scanning the source directories...\n";
979 source_scan_directory(\@main_project,"","",0);
981 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
986 #####
988 # 'vc.dsp'-based Project analysis
990 #####
992 #sub analyze_vc_dsp
999 #####
1001 # Creating the wrapper targets
1003 #####
1005 sub postprocess_targets()
1007 foreach my $project (@projects) {
1008 foreach my $target (@{@$project[$P_TARGETS]}) {
1009 if ((@$target[$T_FLAGS] & $TF_WRAP) != 0) {
1010 my $wrapper=[];
1011 target_init($wrapper);
1012 @$wrapper[$T_NAME]=@$target[$T_NAME];
1013 @$wrapper[$T_TYPE]=@$target[$T_TYPE];
1014 @$wrapper[$T_INIT]=get_default_init(@$target[$T_TYPE]);
1015 @$wrapper[$T_FLAGS]=$TF_WRAPPER | (@$target[$T_FLAGS] & $TF_MFC);
1016 @$wrapper[$T_DLLS]=[ "kernel32", "user32" ];
1017 push @{@$wrapper[$T_LIBRARIES]}, "dl";
1018 push @{@$wrapper[$T_SOURCES_C]},"@$wrapper[$T_NAME]_wrapper.c";
1020 my $index=bsearch(@$target[$T_SOURCES_C],"@$wrapper[$T_NAME]_wrapper.c");
1021 if (defined $index) {
1022 splice(@{@$target[$T_SOURCES_C]},$index,1);
1024 @$target[$T_NAME]=@$target[$T_NAME];
1025 @$target[$T_NAME]=~ s/.exe$/.dll/;
1026 @$target[$T_TYPE]=$TT_DLL;
1028 push @{@$project[$P_TARGETS]},$wrapper;
1030 if ((@$target[$T_FLAGS] & $TF_MFC) != 0) {
1031 @{@$project[$P_SETTINGS]}[$T_FLAGS]|=$TF_MFC;
1032 $needs_mfc=1;
1040 #####
1042 # Source search
1044 #####
1047 # Performs a directory traversal and renames the files so that:
1048 # - they have the case desired by the user
1049 # - their extension is of the appropriate case
1050 # - they don't contain annoying characters like ' ', '$', '#', ...
1051 sub fix_file_and_directory_names($);
1052 sub fix_file_and_directory_names($)
1054 my $dirname=$_[0];
1056 if (opendir(DIRECTORY, "$dirname")) {
1057 foreach my $dentry (readdir DIRECTORY) {
1058 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1059 next;
1061 # Set $warn to 1 if the user should be warned of the renaming
1062 my $warn=0;
1064 # autoconf and make don't support these characters well
1065 my $new_name=$dentry;
1066 $new_name =~ s/[ \$]/_/g;
1068 # Only all lowercase extensions are supported (because of the
1069 # transformations ':.c=.o') .
1070 if (-f "$dirname/$new_name") {
1071 if ($new_name =~ /\.C$/) {
1072 $new_name =~ s/\.C$/.c/;
1074 if ($new_name =~ /\.cpp$/i) {
1075 $new_name =~ s/\.cpp$/.cpp/i;
1077 if ($new_name =~ s/\.cxx$/.cpp/i) {
1078 $warn=1;
1080 if ($new_name =~ /\.rc$/i) {
1081 $new_name =~ s/\.rc$/.rc/i;
1083 # And this last one is to avoid confusion then running make
1084 if ($new_name =~ s/^makefile$/makefile.win/) {
1085 $warn=1;
1089 # Adjust the case to the user's preferences
1090 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1091 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1093 $new_name=lc $new_name;
1096 # And finally, perform the renaming
1097 if ($new_name ne $dentry) {
1098 if ($warn) {
1099 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1101 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1102 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1103 print STDERR " $!\n";
1104 $new_name=$dentry;
1107 if (-d "$dirname/$new_name") {
1108 fix_file_and_directory_names("$dirname/$new_name");
1111 closedir(DIRECTORY);
1117 #####
1119 # Source fixup
1121 #####
1124 # This maps a directory name to a reference to an array listing
1125 # its contents (files and directories)
1126 my %directories;
1129 # Retrieves the contents of the specified directory.
1130 # We either get it from the directories hashtable which acts as a
1131 # cache, or use opendir, readdir, closedir and store the result
1132 # in the hashtable.
1133 sub get_directory_contents($)
1135 my $dirname=$_[0];
1136 my $directory;
1138 #print "getting the contents of $dirname\n";
1140 # check for a cached version
1141 $dirname =~ s+/$++;
1142 if ($dirname eq "") {
1143 $dirname=cwd;
1145 $directory=$directories{$dirname};
1146 if (defined $directory) {
1147 #print "->@$directory\n";
1148 return $directory;
1151 # Read this directory
1152 if (opendir(DIRECTORY, "$dirname")) {
1153 my @files=readdir DIRECTORY;
1154 closedir(DIRECTORY);
1155 $directory=\@files;
1156 } else {
1157 # Return an empty list
1158 #print "error: cannot open $dirname\n";
1159 my @files;
1160 $directory=\@files;
1162 #print "->@$directory\n";
1163 $directories{$dirname}=$directory;
1164 return $directory;
1168 # Try to find a file for the specified filename. The attempt is
1169 # case-insensitive which is why it's not trivial. If a match is
1170 # found then we return the pathname with the correct case.
1171 sub search_from($$)
1173 my $dirname=$_[0];
1174 my $path=$_[1];
1175 my $real_path="";
1177 if ($dirname eq "" or $dirname eq ".") {
1178 $dirname=cwd;
1179 } elsif ($dirname =~ m+^[^/]+) {
1180 $dirname=cwd . "/" . $dirname;
1182 if ($dirname !~ m+/$+) {
1183 $dirname.="/";
1186 foreach my $component (@$path) {
1187 #print " looking for $component in \"$dirname\"\n";
1188 if ($component eq ".") {
1189 # Pass it as is
1190 $real_path.="./";
1191 } elsif ($component eq "..") {
1192 # Go up one level
1193 $dirname=dirname($dirname) . "/";
1194 $real_path.="../";
1195 } else {
1196 # The file/directory may have been renamed before. Also try to
1197 # match the renamed file.
1198 my $renamed=$component;
1199 $renamed =~ s/[ \$]/_/g;
1200 if ($renamed eq $component) {
1201 undef $renamed;
1204 my $directory=get_directory_contents $dirname;
1205 my $found;
1206 foreach my $dentry (@$directory) {
1207 if ($dentry =~ /^$component$/i or
1208 (defined $renamed and $dentry =~ /^$renamed$/i)
1210 $dirname.="$dentry/";
1211 $real_path.="$dentry/";
1212 $found=1;
1213 last;
1216 if (!defined $found) {
1217 # Give up
1218 #print " could not find $component in $dirname\n";
1219 return;
1223 $real_path=~ s+/$++;
1224 #print " -> found $real_path\n";
1225 return $real_path;
1229 # Performs a case-insensitive search for the specified file in the
1230 # include path.
1231 # $line is the line number that should be referenced when an error occurs
1232 # $filename is the file we are looking for
1233 # $dirname is the directory of the file containing the '#include' directive
1234 # if '"' was used, it is an empty string otherwise
1235 # $project and $target specify part of the include path
1236 sub get_real_include_name($$$$$)
1238 my $line=$_[0];
1239 my $filename=$_[1];
1240 my $dirname=$_[2];
1241 my $project=$_[3];
1242 my $target=$_[4];
1244 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1245 # This is not a relative path, we cannot make any check
1246 my $warning="path:$filename";
1247 if (!defined $warnings{$warning}) {
1248 $warnings{$warning}="1";
1249 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1250 print STDERR "$line: $filename\n";
1252 } else {
1253 # Here's how we proceed:
1254 # - split the filename we look for into its components
1255 # - then for each directory in the include path
1256 # - trace the directory components starting from that directory
1257 # - if we fail to find a match at any point then continue with
1258 # the next directory in the include path
1259 # - otherwise, rejoice, our quest is over.
1260 my @file_components=split /[\/\\]+/, $filename;
1261 #print " Searching for $filename from @$project[$P_PATH]\n";
1263 my $real_filename;
1264 if ($dirname ne "") {
1265 # This is an 'include ""' -> look in dirname first.
1266 #print " in $dirname (include \"\")\n";
1267 $real_filename=search_from($dirname,\@file_components);
1268 if (defined $real_filename) {
1269 return $real_filename;
1272 my $project_settings=@$project[$P_SETTINGS];
1273 foreach my $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1274 my $dirname=$include;
1275 $dirname=~ s+^-I++;
1276 if (!is_absolute($dirname)) {
1277 $dirname="@$project[$P_PATH]$dirname";
1278 } else {
1279 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1280 $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
1282 #print " in $dirname\n";
1283 $real_filename=search_from("$dirname",\@file_components);
1284 if (defined $real_filename) {
1285 return $real_filename;
1288 my $dotdotpath=@$project[$P_PATH];
1289 $dotdotpath =~ s/[^\/]+/../g;
1290 foreach my $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1291 my $dirname=$include;
1292 $dirname=~ s+^-I++;
1293 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1294 $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
1295 #print " in $dirname (global setting)\n";
1296 $real_filename=search_from("$dirname",\@file_components);
1297 if (defined $real_filename) {
1298 return $real_filename;
1302 $filename =~ s+\\\\+/+g; # in include ""
1303 $filename =~ s+\\+/+g; # in include <> !
1304 if ($opt_lower_include) {
1305 return lc "$filename";
1307 return $filename;
1310 sub print_pack($$$)
1312 my $indent=$_[0];
1313 my $size=$_[1];
1314 my $trailer=$_[2];
1316 if ($size =~ /^(1|2|4|8)$/) {
1317 print FILEO "$indent#include <pshpack$size.h>$trailer";
1318 } else {
1319 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1320 print FILEO "$indent#include <pshpack4.h>$trailer";
1325 # 'Parses' a source file and fixes constructs that would not work with
1326 # Winelib. The parsing is rather simple and not all non-portable features
1327 # are corrected. The most important feature that is corrected is the case
1328 # and path separator of '#include' directives. This requires that each
1329 # source file be associated to a project & target so that the proper
1330 # include path is used.
1331 # Also note that the include path is relative to the directory in which the
1332 # compiler is run, i.e. that of the project, not to that of the file.
1333 sub fix_file($$$)
1335 my $filename=$_[0];
1336 my $project=$_[1];
1337 my $target=$_[2];
1338 $filename="@$project[$P_PATH]$filename";
1339 if (! -e $filename) {
1340 return;
1343 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1344 my $dirname=dirname($filename);
1345 my $is_mfc=0;
1346 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1347 $is_mfc=1;
1350 print " $filename\n";
1351 #FIXME:assuming that because there is a .bak file, this is what we want is
1352 #probably flawed. Or is it???
1353 if (! -e "$filename.bak") {
1354 if (!copy("$filename","$filename.bak")) {
1355 print STDERR "error: unable to make a backup of $filename:\n";
1356 print STDERR " $!\n";
1357 return;
1360 if (!open(FILEI,"$filename.bak")) {
1361 print STDERR "error: unable to open $filename.bak for reading:\n";
1362 print STDERR " $!\n";
1363 return;
1365 if (!open(FILEO,">$filename")) {
1366 print STDERR "error: unable to open $filename for writing:\n";
1367 print STDERR " $!\n";
1368 return;
1370 my $line=0;
1371 my $modified=0;
1372 my $rc_block_depth=0;
1373 my $rc_textinclude_state=0;
1374 my @pack_stack;
1375 while (<FILEI>) {
1376 # Remove any trailing CtrlZ, which isn't strictly in the file
1377 if (/\x1A/) {
1378 s/\x1A//;
1379 last if (/^$/)
1381 $line++;
1382 s/\r\n$/\n/;
1383 if (!/\n$/) {
1384 # Make sure all files are '\n' terminated
1385 $_ .= "\n";
1387 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
1388 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1389 # the RC files it generates (even in non-MFC projects). So we replace
1390 # it with 'winres.h' its very close standard cousin so that non MFC
1391 # projects can compile in Wine without the MFC sources.
1392 my $warning="mfc:afxres.h";
1393 if (!defined $warnings{$warning}) {
1394 $warnings{$warning}="1";
1395 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winres.h'\n";
1396 print STDERR "warning: the above warning is issued only once\n";
1398 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
1399 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winres.h' */\n";
1400 print FILEO "$1$2\"winres.h\"$'";
1401 $modified=1;
1403 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1404 my $from_file=($2 eq "<"?"":$dirname);
1405 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1406 print FILEO "$1$2$real_include_name$4$'";
1407 $modified|=($real_include_name ne $3);
1409 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
1410 # Pragma pack handling
1412 # pack_stack is an array of references describing the stack of
1413 # pack directives currently in effect. Each directive if described
1414 # by a reference to an array containing:
1415 # - "push" for pack(push,...) directives, "" otherwise
1416 # - the directive's identifier at index 1
1417 # - the directive's alignement value at index 2
1419 # Don't believe a word of what the documentation says: it's all wrong.
1420 # The code below is based on the actual behavior of Visual C/C++ 6.
1421 my $pack_indent=$1;
1422 my $pack_header=$2;
1423 if (/^(\))/) {
1424 # pragma pack()
1425 # Pushes the default stack alignment
1426 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1427 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1428 print_pack($pack_indent,4,$');
1429 push @pack_stack, [ "", "", 4 ];
1431 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
1432 # pragma pack(pop)
1433 # pragma pack(pop,n)
1434 # Goes up the stack until it finds a pack(push,...), and pops it
1435 # Ignores any pack(n) entry
1436 # Issues a warning if the pack is of the form pack(push,label)
1437 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1438 my $pack_comment=$';
1439 $pack_comment =~ s/^\s*//;
1440 if ($pack_comment ne "") {
1441 print FILEO "$pack_indent$pack_comment";
1443 while (1) {
1444 my $alignment=pop @pack_stack;
1445 if (!defined $alignment) {
1446 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
1447 last;
1449 if (@$alignment[1]) {
1450 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
1452 print FILEO "$pack_indent#include <poppack.h>\n";
1453 if (@$alignment[0]) {
1454 last;
1458 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
1459 # pragma pack(pop,label[,n])
1460 # Goes up the stack until finding a pack(push,...) and pops it.
1461 # 'n', if specified, is ignored.
1462 # Ignores any pack(n) entry
1463 # Issues a warning if the label of the pack does not match,
1464 # or if it is in fact a pack(push,n)
1465 my $label=$2;
1466 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1467 my $pack_comment=$';
1468 $pack_comment =~ s/^\s*//;
1469 if ($pack_comment ne "") {
1470 print FILEO "$pack_indent$pack_comment";
1472 while (1) {
1473 my $alignment=pop @pack_stack;
1474 if (!defined $alignment) {
1475 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
1476 last;
1478 if (@$alignment[1] and @$alignment[1] ne $label) {
1479 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
1481 print FILEO "$pack_indent#include <poppack.h>\n";
1482 if (@$alignment[0]) {
1483 last;
1487 } elsif (/^(push\s*\))/) {
1488 # pragma pack(push)
1489 # Push the current alignment
1490 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1491 if (@pack_stack > 0) {
1492 my $alignment=$pack_stack[$#pack_stack];
1493 print_pack($pack_indent,@$alignment[2],$');
1494 push @pack_stack, [ "push", "", @$alignment[2] ];
1495 } else {
1496 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1497 print_pack($pack_indent,4,$');
1498 push @pack_stack, [ "push", "", 4 ];
1501 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
1502 # pragma pack([push,]n)
1503 # Push new alignment n
1504 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1505 print_pack($pack_indent,$3,"$'");
1506 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
1508 } elsif (/^((\w+)\s*\))/) {
1509 # pragma pack(label)
1510 # label must in fact be a macro that resolves to an integer
1511 # Then behaves like 'pragma pack(n)'
1512 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1513 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
1514 print_pack($pack_indent,4,$');
1515 push @pack_stack, [ "", "", 4 ];
1517 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
1518 # pragma pack(push,label[,n])
1519 # Pushes a new label on the stack. It is possible to push the same
1520 # label multiple times. If 'n' is omitted then the alignment is
1521 # unchanged. Otherwise it becomes 'n'.
1522 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1523 my $size;
1524 if (defined $4) {
1525 $size=$4;
1526 } elsif (@pack_stack > 0) {
1527 my $alignment=$pack_stack[$#pack_stack];
1528 $size=@$alignment[2];
1529 } else {
1530 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1531 $size=4;
1533 print_pack($pack_indent,$size,$');
1534 push @pack_stack, [ "push", $2, $size ];
1536 } else {
1537 # pragma pack(??? -> What's that?
1538 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
1539 print FILEO "$pack_indent$pack_header$_";
1542 $modified=1;
1544 } elsif ($is_rc) {
1545 if ($rc_block_depth == 0 and /^(\w+\s+(BITMAP|CURSOR|FONT|FONTDIR|ICON|MESSAGETABLE|TEXT|RTF)\s+((DISCARDABLE|FIXED|IMPURE|LOADONCALL|MOVEABLE|PRELOAD|PURE)\s+)*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1546 my $from_file=($5 eq "<"?"":$dirname);
1547 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
1548 print FILEO "$1$5$real_include_name$7$'";
1549 $modified|=($real_include_name ne $6);
1551 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1552 my $from_file=($2 eq "<"?"":$dirname);
1553 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1554 print FILEO "$1$2$real_include_name$4$'";
1555 $modified|=($real_include_name ne $3);
1557 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
1558 $rc_textinclude_state=1;
1559 print FILEO;
1561 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
1562 print FILEO "$1winres.h$2$'";
1563 $modified=1;
1565 } elsif (/^\s*BEGIN(\W.*)?$/) {
1566 $rc_textinclude_state|=2;
1567 $rc_block_depth++;
1568 print FILEO;
1570 } elsif (/^\s*END(\W.*)?$/) {
1571 $rc_textinclude_state=0;
1572 if ($rc_block_depth>0) {
1573 $rc_block_depth--;
1575 print FILEO;
1577 } else {
1578 print FILEO;
1581 } else {
1582 print FILEO;
1586 close(FILEI);
1587 close(FILEO);
1588 if ($opt_backup == 0 or $modified == 0) {
1589 if (!unlink("$filename.bak")) {
1590 print STDERR "error: unable to delete $filename.bak:\n";
1591 print STDERR " $!\n";
1597 # Analyzes each source file in turn to find and correct issues
1598 # that would cause it not to compile.
1599 sub fix_source()
1601 print "Fixing the source files...\n";
1602 foreach my $project (@projects) {
1603 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
1604 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1605 next;
1607 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
1608 fix_file($source,$project,$target);
1616 #####
1618 # File generation
1620 #####
1623 # Generates a target's .spec file
1624 sub generate_spec_file($$$)
1626 return if ($opt_no_generated_specs);
1628 my $path=$_[0];
1629 my $target=$_[1];
1630 my $project_settings=$_[2];
1632 my $basename=@$target[$T_NAME];
1633 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1634 $basename.="_wrapper";
1637 if (!open(FILEO,">$path$basename.spec")) {
1638 print STDERR "error: could not open \"$path$basename.spec\" for writing\n";
1639 print STDERR " $!\n";
1640 return;
1643 # Don't forget to export the 'Main' function for wrapped executables,
1644 # except for MFC ones!
1645 if ((@$target[$T_FLAGS]&($TF_WRAP|$TF_WRAPPER|$TF_MFC)) == $TF_WRAP) {
1646 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1647 print FILEO "\n@ stdcall @$target[$T_INIT](long long ptr long) @$target[$T_INIT]\n";
1648 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1649 print FILEO "\n@ stdcall @$target[$T_INIT](long ptr ptr) @$target[$T_INIT]\n";
1650 } else {
1651 print FILEO "\n@ stdcall @$target[$T_INIT](ptr long ptr) @$target[$T_INIT]\n";
1655 close(FILEO);
1659 # Generates a target's wrapper file
1660 sub generate_wrapper_file($$)
1662 my $path=$_[0];
1663 my $target=$_[1];
1664 my $app_name=@$target[$T_NAME];
1665 my $wrapper_name=$app_name;
1666 $app_name=~ s/\.exe$/\.dll/;
1668 return generate_from_template("$path${wrapper_name}_wrapper.c","wrapper.c",[
1669 ["APP_NAME",$app_name],
1670 ["APP_TYPE",(@$target[$T_TYPE]==$TT_GUIEXE?"GUIEXE":"CUIEXE")],
1671 ["APP_INIT",(@$target[$T_TYPE]==$TT_GUIEXE?"\"WinMain\"":"\"main\"")],
1672 ["APP_MFC",(@$target[$T_FLAGS] & $TF_MFC?"\"mfc\"":"NULL")]]);
1676 # A convenience function to generate all the lists (defines,
1677 # C sources, C++ source, etc.) in the Makefile
1678 sub generate_list($$$;$)
1680 my $name=$_[0];
1681 my $last=$_[1];
1682 my $list=$_[2];
1683 my $data=$_[3];
1684 my $first=$name;
1686 if ($name) {
1687 printf FILEO "%-22s=",$name;
1689 if (defined $list) {
1690 foreach my $item (@$list) {
1691 my $value;
1692 if (defined $data) {
1693 $value=&$data($item);
1694 } else {
1695 $value=$item;
1697 if ($value ne "") {
1698 if ($first) {
1699 print FILEO " $value";
1700 $first=0;
1701 } else {
1702 print FILEO " \\\n\t\t\t$value";
1707 if ($last) {
1708 print FILEO "\n";
1713 # Generates a project's Makefile.in and all the target files
1714 sub generate_project_files($)
1716 my $project=$_[0];
1717 my $project_settings=@$project[$P_SETTINGS];
1718 my @dll_list=();
1719 my @exe_list=();
1721 # Then sort the targets and separate the libraries from the programs
1722 foreach my $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
1723 if (@$target[$T_TYPE] == $TT_DLL) {
1724 push @dll_list,$target;
1725 } else {
1726 push @exe_list,$target;
1729 @$project[$P_TARGETS]=[];
1730 push @{@$project[$P_TARGETS]}, @dll_list;
1731 push @{@$project[$P_TARGETS]}, @exe_list;
1733 if (!open(FILEO,">@$project[$P_PATH]Makefile.in")) {
1734 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile.in\" for writing\n";
1735 print STDERR " $!\n";
1736 return;
1739 print FILEO "### Generated by Winemaker\n";
1740 print FILEO "\n\n";
1742 print FILEO "### Generic autoconf variables\n\n";
1743 generate_list("TOPSRCDIR",1,[ "\@top_srcdir\@" ]);
1744 my $dotdotpath=@$project[$P_PATH];
1745 $dotdotpath =~ s%[^/]+%..%g;
1746 $dotdotpath =~ s%/$%%;
1747 $dotdotpath = "." if ($dotdotpath eq "");
1748 generate_list("TOPOBJDIR",1,[ $dotdotpath ]);
1749 generate_list("SRCDIR",1,[ "\@srcdir\@" ]);
1750 generate_list("VPATH",1,[ "\@srcdir\@" ]);
1751 print FILEO "\n";
1752 if (@$project[$P_PATH] eq "") {
1753 # This is the main project. It is also responsible for recursively
1754 # calling the other projects
1755 generate_list("SUBDIRS",1,\@projects,sub
1757 if ($_[0] != \@main_project) {
1758 my $subdir=@{$_[0]}[$P_PATH];
1759 $subdir =~ s+/$++;
1760 return $subdir;
1762 # Eliminating the main project by returning undefined!
1765 if (@{@$project[$P_TARGETS]} > 0) {
1766 generate_list("DLLS",1,\@dll_list,sub
1768 return @{$_[0]}[$T_NAME];
1770 generate_list("EXES",1,\@exe_list,sub
1772 return "@{$_[0]}[$T_NAME]";
1774 print FILEO "\n\n\n";
1776 print FILEO "### Common settings\n\n";
1777 # Make it so that the project-wide settings override the global settings
1778 generate_list("DEFINES",1,@$project_settings[$T_DEFINES]);
1779 generate_list("INCLUDE_PATH",1,@$project_settings[$T_INCLUDE_PATH]);
1780 generate_list("DLL_PATH",1,@$project_settings[$T_DLL_PATH]);
1781 generate_list("LIBRARY_PATH",1,@$project_settings[$T_LIBRARY_PATH]);
1782 generate_list("LIBRARIES",1,@$project_settings[$T_LIBRARIES]);
1783 print FILEO "\n\n";
1785 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
1786 @{@$project_settings[$T_SOURCES_CXX]}+
1787 @{@$project_settings[$T_SOURCES_RC]};
1788 my $no_extra=($extra_source_count == 0);
1789 if (!$no_extra) {
1790 print FILEO "### Extra source lists\n\n";
1791 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
1792 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
1793 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
1794 print FILEO "\n";
1795 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
1796 print FILEO "\n\n\n";
1799 # Iterate over all the targets...
1800 foreach my $target (@{@$project[$P_TARGETS]}) {
1801 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
1802 my $appmode;
1803 my $basemodule=@$target[$T_NAME];
1804 my $canon=canonize("@$target[$T_NAME]");
1805 $canon =~ s+_so$++;
1806 if (@$target[$T_TYPE] == $TT_CUIEXE) {
1807 $appmode = "cui";
1808 $basemodule =~ s/\.exe$//;
1809 } elsif (@$target[$T_TYPE] == $TT_GUIEXE) {
1810 $appmode = "gui";
1811 $basemodule =~ s/\.exe$//;
1812 } else {
1813 $appmode = "";
1814 $basemodule =~ s/\.dll$//;
1817 generate_list("${canon}_MODULE",1,[@$target[$T_NAME]]);
1818 generate_list("${canon}_BASEMODULE",1,[$basemodule]);
1819 generate_list("${canon}_APPMODE",1,[$appmode]);
1820 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
1821 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
1822 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
1823 generate_list("${canon}_SPEC_SRCS",1,[ (@$target[$T_TYPE] == $TT_DLL?"@$target[$T_NAME].spec":"") ]);
1824 generate_list("${canon}_DLL_PATH",1,@$target[$T_DLL_PATH]);
1825 generate_list("${canon}_DLLS",1,@$target[$T_DLLS]);
1826 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]);
1827 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]);
1828 generate_list("${canon}_DEPENDS",1,@$target[$T_DEPENDS]);
1829 print FILEO "\n";
1830 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(EXTRA_OBJS)"]);
1831 print FILEO "\n\n\n";
1833 print FILEO "### Global source lists\n\n";
1834 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
1836 my $canon=canonize(@{$_[0]}[$T_NAME]);
1837 $canon =~ s+_so$++;
1838 return "\$(${canon}_C_SRCS)";
1840 if (!$no_extra) {
1841 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
1843 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
1845 my $canon=canonize(@{$_[0]}[$T_NAME]);
1846 $canon =~ s+_so$++;
1847 return "\$(${canon}_CXX_SRCS)";
1849 if (!$no_extra) {
1850 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
1852 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
1854 my $canon=canonize(@{$_[0]}[$T_NAME]);
1855 $canon =~ s+_so$++;
1856 return "\$(${canon}_RC_SRCS)";
1858 if (!$no_extra) {
1859 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
1861 generate_list("SPEC_SRCS",1,@$project[$P_TARGETS],sub
1863 my $canon=canonize(@{$_[0]}[$T_NAME]);
1864 $canon =~ s+_so$++;
1865 return "\$(${canon}_SPEC_SRCS)";
1868 print FILEO "\n\n\n";
1870 print FILEO "### Generic autoconf targets\n\n";
1871 print FILEO "all:";
1872 if (@$project[$P_PATH] eq "") {
1873 print FILEO " wineapploader";
1874 print FILEO " \$(SUBDIRS)";
1876 if (@{@$project[$P_TARGETS]} > 0) {
1877 print FILEO " \$(DLLS:%=%.so) \$(EXES:%=%.so)";
1879 print FILEO "\n\n";
1880 if (@$project[$P_PATH] eq "") {
1881 print FILEO "wineapploader: wineapploader.in\n";
1882 print FILEO "\tsed -e 's,\@bindir\\\@,\$(bindir),g' " .
1883 "-e 's,\@winelibdir\\\@,.,g' " .
1884 "\$(SRCDIR)/wineapploader.in >\$\@ || \$(RM) \$\@\n";
1885 print FILEO "\n";
1887 print FILEO "\@MAKE_RULES\@\n";
1888 print FILEO "\n";
1889 print FILEO "install::\n";
1890 if (@$project[$P_PATH] eq "") {
1891 # This is the main project. It is also responsible for recursively
1892 # calling the other projects
1893 print FILEO "\t_list=\"\$(SUBDIRS)\"; for i in \$\$_list; do (cd \$\$i; \$(MAKE) install) || exit 1; done\n";
1895 if (@{@$project[$P_TARGETS]} > 0) {
1896 print FILEO "\t_list=\"\$(EXES:%.exe=%)\"; for i in \$\$_list; do \$(INSTALL_SCRIPT) \$\$i \$(bindir); done\n";
1897 print FILEO "\t_list=\"\$(EXES:%=%.so) \$(DLLS:%=%.so)\"; for i in \$\$_list; do \$(INSTALL_PROGRAM) \$\$i \$(dlldir); done\n";
1899 print FILEO "\n";
1900 print FILEO "uninstall::\n";
1901 if (@$project[$P_PATH] eq "") {
1902 # This is the main project. It is also responsible for recursively
1903 # calling the other projects
1904 print FILEO "\t_list=\"\$(SUBDIRS)\"; for i in \$\$_list; do (cd \$\$i; \$(MAKE) uninstall) || exit 1; done\n";
1906 if (@{@$project[$P_TARGETS]} > 0) {
1907 print FILEO "\t_list=\"\$(EXES:%.exe=%)\"; for i in \$\$_list; do \$(RM) \$(bindir)/\$\$i;done\n";
1908 print FILEO "\t_list=\"\$(EXES:%=%.so) \$(DLLS:%=%.so)\"; for i in \$\$_list; do \$(RM) \$(dlldir)/\$\$i;done\n";
1910 print FILEO "\n";
1911 if (@$project[$P_PATH] eq "") {
1912 print FILEO "clean::\n";
1913 print FILEO "\t\$(RM) wineapploader\n";
1914 print FILEO "\n";
1915 print FILEO "distclean: clean\n";
1916 print FILEO "\t\$(RM) config.* configure.lineno Make.rules\n";
1917 print FILEO "\t\$(RM) -r autom4te.cache\n";
1918 print FILEO "\tfind . -name Makefile -exec \$(RM) {} \\;\n";
1919 print FILEO "\n";
1922 if (@{@$project[$P_TARGETS]} > 0) {
1923 print FILEO "### Target specific build rules\n\n";
1924 foreach my $target (@{@$project[$P_TARGETS]}) {
1925 my $canon=canonize("@$target[$T_NAME]");
1926 my $mode;
1927 my $all_dlls;
1928 my $all_libs;
1930 $canon =~ s/_so$//;
1931 if ((@$target[$T_TYPE]==$TT_GUIEXE) || (@$target[$T_TYPE]==$TT_CUIEXE)) {
1932 $mode = "--exe \$(${canon}_MODULE) -m\$(${canon}_APPMODE)";
1933 } else {
1934 $mode = "";
1937 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1938 $all_dlls="\$(${canon}_DLLS:%=-l%)";
1939 $all_libs="\$(${canon}_LIBRARIES:%=-l%) \$(WINE_LIBRARIES)";
1940 } else {
1941 $all_dlls="\$(${canon}_DLLS:%=-l%) \$(GLOBAL_DLLS:%=-l%)";
1942 $all_libs="\$(${canon}_LIBRARIES:%=-l%) \$(ALL_LIBRARIES)";
1945 print FILEO "\$(${canon}_MODULE).dbg.c: \$(${canon}_C_SRCS) \$(${canon}_CXX_SRCS)\n";
1946 print FILEO "\t\$(LDPATH) \$(WINEBUILD) -o \$\@ --debug -C\$(SRCDIR) \$(${canon}_C_SRCS) \$(${canon}_CXX_SRCS)\n";
1947 print FILEO "\n";
1948 print FILEO "\$(${canon}_MODULE).spec.c: \$(${canon}_SPEC_SRCS) \$(${canon}_RC_SRCS:.rc=.res) \$(${canon}_OBJS)\n";
1949 print FILEO "\t\$(LDPATH) \$(WINEBUILD) -fPIC -o \$\@ $mode \$(${canon}_SPEC_SRCS:%=--spec %) \$(${canon}_RC_SRCS:%.rc=%.res) \$(${canon}_OBJS) \$(${canon}_DLL_PATH) \$(WINE_DLL_PATH) \$(GLOBAL_DLL_PATH) $all_dlls\n";
1950 print FILEO "\n";
1951 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_MODULE).dbg.o \$(${canon}_MODULE).spec.o \$(${canon}_OBJS) \$(${canon}_DEPENDS)\n";
1952 if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
1953 print FILEO "\t\$(LDXXSHARED)";
1954 } else {
1955 print FILEO "\t\$(LDSHARED)";
1957 print FILEO " \$(LDDLLFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_MODULE).dbg.o \$(${canon}_MODULE).spec.o \$(${canon}_LIBRARY_PATH) \$(ALL_LIBRARY_PATH) $all_libs \$(LIBS)\n";
1958 if (@$target[$T_TYPE] != $TT_DLL) {
1959 print FILEO "\ttest -f \$(${canon}_BASEMODULE) || \$(INSTALL_SCRIPT) \$(TOPOBJDIR)/wineapploader \$(${canon}_BASEMODULE)\n";
1961 print FILEO "\n\n";
1964 close(FILEO);
1966 foreach my $target (@{@$project[$P_TARGETS]}) {
1967 if (@$target[$T_TYPE] == $TT_DLL) {
1968 generate_spec_file(@$project[$P_PATH],$target,$project_settings);
1970 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1971 generate_wrapper_file(@$project[$P_PATH],$target);
1977 # Perform the replacements in the template configure files
1978 # Return 1 for success, 0 for failure
1979 sub generate_from_template($$;$)
1981 my $filename=$_[0];
1982 my $template=$_[1];
1983 my $substitutions=$_[2];
1985 if (!defined $templates{$template}) {
1986 print STDERR "winemaker: internal error: No template called '$template'\n";
1987 return 0;
1990 if (!open(FILEO,">$filename")) {
1991 print STDERR "error: unable to open \"$filename\" for writing:\n";
1992 print STDERR " $!\n";
1993 return 0;
1995 my $warned;
1996 foreach my $line (@{$templates{$template}}) {
1997 if ($line =~ /(\#\#WINEMAKER_[A-Z_]+\#\#)/) {
1998 if (defined $substitutions) {
1999 foreach my $pattern (@$substitutions) {
2000 $line =~ s%\#\#WINEMAKER_@$pattern[0]\#\#%@$pattern[1]%;
2003 if (!$warned and $line =~ /(\#\#WINEMAKER_[A-Z_]+\#\#)/) {
2004 print STDERR "warning: no value was provided for template $1 in \"$filename\"\n";
2005 $warned=1;
2008 print FILEO $line;
2010 close(FILEO);
2011 return 1;
2015 # Generates the global files:
2016 # configure
2017 # configure.ac
2018 # Make.rules.in
2019 # wineapploader.in
2020 sub generate_global_files()
2022 my @include_path;
2023 foreach my $path (@{$global_settings[$T_INCLUDE_PATH]}) {
2024 if ($path !~ /^-L/ or is_absolute($')) {
2025 push @include_path, $path;
2026 } else {
2027 push @include_path, "-L\$(TOPSRCDIR)/$'";
2030 my @dll_path;
2031 foreach my $path (@{$global_settings[$T_DLL_PATH]}) {
2032 if ($path !~ /^-L/ or is_absolute($')) {
2033 push @dll_path, $path;
2034 } else {
2035 push @dll_path, "-L\$(TOPSRCDIR)/$'";
2038 my @library_path;
2039 foreach my $path (@{$global_settings[$T_LIBRARY_PATH]}) {
2040 if ($path !~ /^-L/ or is_absolute($')) {
2041 push @library_path, $path;
2042 } else {
2043 push @library_path, "-L\$(TOPSRCDIR)/$'";
2046 generate_from_template("Make.rules.in","Make.rules.in",[
2047 ["DEFINES", join(" ", @{$global_settings[$T_DEFINES]}) ],
2048 ["INCLUDE_PATH", join(" ", @include_path) ],
2049 ["DLL_PATH", join(" ", @dll_path) ],
2050 ["DLLS", join(" ", @{$global_settings[$T_DLLS]}) ],
2051 ["LIBRARY_PATH", join(" ", @library_path) ],
2052 ["LIBRARIES", join(" ", @{$global_settings[$T_LIBRARIES]}) ]]);
2053 generate_from_template("wineapploader.in","wineapploader.in");
2055 # Get the name of a source file for configure.ac
2056 my $a_source_file;
2057 search_a_file: foreach my $project (@projects) {
2058 foreach my $target (@{@$project[$P_TARGETS]}, @$project[$P_SETTINGS]) {
2059 $a_source_file=@{@$target[$T_SOURCES_C]}[0];
2060 if (!defined $a_source_file) {
2061 $a_source_file=@{@$target[$T_SOURCES_CXX]}[0];
2063 if (!defined $a_source_file) {
2064 $a_source_file=@{@$target[$T_SOURCES_RC]}[0];
2066 if (defined $a_source_file) {
2067 $a_source_file="@$project[$P_PATH]$a_source_file";
2068 last search_a_file;
2072 if (!defined $a_source_file) {
2073 $a_source_file="Makefile.in";
2075 generate_from_template("configure.ac","configure.ac",[
2076 ["PROJECTS",join("\n",map { "@$_[$P_PATH]Makefile" } @projects)],
2077 ["SOURCE","$a_source_file"],
2078 ["NEEDS_MFC","$needs_mfc"]]);
2079 system("autoconf configure.ac > configure");
2081 # Add execute permission to configure for whoever has the right to read it
2082 my @st=stat("configure");
2083 if (@st) {
2084 my $mode=$st[2];
2085 $mode|=($mode & 0444) >>2;
2086 chmod($mode,"configure");
2087 } else {
2088 print "warning: could not generate the configure script. You need to run autoconf\n";
2094 sub generate_read_templates()
2096 my $file;
2098 while (<DATA>) {
2099 if (/^--- ((\w\.?)+) ---$/) {
2100 my $filename=$1;
2101 if (defined $templates{$filename}) {
2102 print STDERR "winemaker: internal error: There is more than one template for $filename\n";
2103 undef $file;
2104 } else {
2105 $file=[];
2106 $templates{$filename}=$file;
2108 } elsif (defined $file) {
2109 push @$file, $_;
2115 # This is where we finally generate files. In fact this method does not
2116 # do anything itself but calls the methods that do the actual work.
2117 sub generate()
2119 print "Generating project files...\n";
2120 generate_read_templates();
2121 generate_global_files();
2123 foreach my $project (@projects) {
2124 my $path=@$project[$P_PATH];
2125 if ($path eq "") {
2126 $path=".";
2127 } else {
2128 $path =~ s+/$++;
2130 print " $path\n";
2131 generate_project_files($project);
2137 #####
2139 # Option defaults
2141 #####
2143 $opt_backup=1;
2144 $opt_lower=$OPT_LOWER_UPPERCASE;
2145 $opt_lower_include=1;
2147 # $opt_work_dir=<undefined>
2148 # $opt_single_target=<undefined>
2149 $opt_target_type=$TT_GUIEXE;
2150 $opt_flags=0;
2151 $opt_is_interactive=$OPT_ASK_NO;
2152 $opt_ask_project_options=$OPT_ASK_NO;
2153 $opt_ask_target_options=$OPT_ASK_NO;
2154 $opt_no_generated_files=0;
2155 $opt_no_generated_specs=0;
2156 $opt_no_source_fix=0;
2157 $opt_no_banner=0;
2161 #####
2163 # Main
2165 #####
2167 sub print_banner()
2169 print "Winemaker $version\n";
2170 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2173 sub usage()
2175 print_banner();
2176 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2177 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2178 print STDERR " [--lower-include|--nolower-include]\n";
2179 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2180 print STDERR " [--wrap|--nowrap] [--mfc|--nomfc]\n";
2181 print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2182 print STDERR " [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2183 print STDERR " [--generated-files|--nogenerated-files] [--nogenerated-specs]\n";
2184 print STDERR " work_directory\n";
2185 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2186 print STDERR "the specified directory so that they can be compiled with Winelib. During this\n";
2187 print STDERR "process it will modify and rename some of the files in that directory.\n";
2188 print STDERR "\tPlease read the manual page before use.\n";
2189 exit (2);
2192 target_init(\@global_settings);
2194 while (@ARGV>0) {
2195 my $arg=shift @ARGV;
2196 # General options
2197 if ($arg eq "--nobanner") {
2198 $opt_no_banner=1;
2199 } elsif ($arg eq "--backup") {
2200 $opt_backup=1;
2201 } elsif ($arg eq "--nobackup") {
2202 $opt_backup=0;
2203 } elsif ($arg eq "--single-target") {
2204 $opt_single_target=shift @ARGV;
2205 } elsif ($arg eq "--lower-none") {
2206 $opt_lower=$OPT_LOWER_NONE;
2207 } elsif ($arg eq "--lower-all") {
2208 $opt_lower=$OPT_LOWER_ALL;
2209 } elsif ($arg eq "--lower-uppercase") {
2210 $opt_lower=$OPT_LOWER_UPPERCASE;
2211 } elsif ($arg eq "--lower-include") {
2212 $opt_lower_include=1;
2213 } elsif ($arg eq "--nolower-include") {
2214 $opt_lower_include=0;
2215 } elsif ($arg eq "--nosource-fix") {
2216 $opt_no_source_fix=1;
2217 } elsif ($arg eq "--generated-files") {
2218 $opt_no_generated_files=0;
2219 } elsif ($arg eq "--nogenerated-files") {
2220 $opt_no_generated_files=1;
2221 } elsif ($arg eq "--nogenerated-specs") {
2222 $opt_no_generated_specs=1;
2224 } elsif ($arg =~ /^-D/) {
2225 push @{$global_settings[$T_DEFINES]},$arg;
2226 } elsif ($arg =~ /^-I/) {
2227 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2228 } elsif ($arg =~ /^-P/) {
2229 push @{$global_settings[$T_DLL_PATH]},"-L$'";
2230 } elsif ($arg =~ /^-i/) {
2231 my $dllname = $';
2232 if ($dllname =~ /^msvcrt$/) {
2233 push @{$global_settings[$T_INCLUDE_PATH]},"-I\$(WINE_INCLUDE_ROOT)/msvcrt";
2235 push @{$global_settings[$T_DLLS]},$dllname;
2236 } elsif ($arg =~ /^-L/) {
2237 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2238 } elsif ($arg =~ /^-l/) {
2239 push @{$global_settings[$T_LIBRARIES]},$';
2241 # 'Source'-based method options
2242 } elsif ($arg eq "--dll") {
2243 $opt_target_type=$TT_DLL;
2244 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2245 $opt_target_type=$TT_GUIEXE;
2246 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2247 $opt_target_type=$TT_CUIEXE;
2248 } elsif ($arg eq "--interactive") {
2249 $opt_is_interactive=$OPT_ASK_YES;
2250 $opt_ask_project_options=$OPT_ASK_YES;
2251 $opt_ask_target_options=$OPT_ASK_YES;
2252 } elsif ($arg eq "--wrap") {
2253 $opt_flags|=$TF_WRAP;
2254 } elsif ($arg eq "--nowrap") {
2255 $opt_flags&=~$TF_WRAP;
2256 } elsif ($arg eq "--mfc") {
2257 $opt_flags|=$TF_MFC;
2258 $needs_mfc=1;
2259 } elsif ($arg eq "--nomfc") {
2260 $opt_flags&=~$TF_MFC;
2261 $opt_flags|=$TF_NOMFC;
2262 $needs_mfc=0;
2263 } elsif ($arg eq "--nodlls") {
2264 $opt_flags|=$TF_NODLLS;
2265 } elsif ($arg eq "--nomsvcrt") {
2266 $opt_flags|=$TF_NOMSVCRT;
2268 # Catch errors
2269 } else {
2270 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2271 if (!defined $opt_work_dir) {
2272 $opt_work_dir=$arg;
2273 } else {
2274 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2275 usage();
2277 } else {
2278 usage();
2282 if ($opt_flags & $TF_MFC && $opt_target_type != $TT_DLL) {
2283 print STDERR "info: option --mfc requires --wrap\n";
2284 $opt_flags |= $TF_WRAP;
2288 if (!defined $opt_work_dir) {
2289 print STDERR "error: you must specify the directory containing the sources to be converted\n";
2290 usage();
2291 } elsif (!chdir $opt_work_dir) {
2292 print STDERR "error: could not chdir to the work directory\n";
2293 print STDERR " $!\n";
2294 usage();
2297 if ($opt_no_banner == 0) {
2298 print_banner();
2301 project_init(\@main_project,"");
2303 # Fix the file and directory names
2304 fix_file_and_directory_names(".");
2306 # Scan the sources to identify the projects and targets
2307 source_scan();
2309 # Create targets for wrappers, etc.
2310 postprocess_targets();
2312 # Fix the source files
2313 if (! $opt_no_source_fix) {
2314 fix_source();
2317 # Generate the Makefile and the spec file
2318 if (! $opt_no_generated_files) {
2319 generate();
2323 __DATA__
2324 --- configure.ac ---
2325 dnl Process this file with autoconf to produce a configure script.
2326 dnl Author: Michael Patra <micky@marie.physik.tu-berlin.de>
2327 dnl <patra@itp1.physik.tu-berlin.de>
2328 dnl Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2330 AC_REVISION([configure.ac 1.00])
2331 AC_INIT(##WINEMAKER_SOURCE##)
2333 NEEDS_MFC=##WINEMAKER_NEEDS_MFC##
2335 dnl **** Command-line arguments ****
2337 AC_SUBST(OPTIONS)
2339 dnl **** Check for some programs ****
2341 AC_PROG_MAKE_SET
2342 AC_PROG_CC
2343 AC_PROG_CXX
2344 AC_PROG_CPP
2345 AC_PROG_LN_S
2347 dnl **** Check for some libraries ****
2349 dnl Check for -lm for BeOS
2350 AC_CHECK_LIB(m,sqrt)
2351 dnl Check for -lw for Solaris
2352 AC_CHECK_LIB(w,iswalnum)
2353 dnl Check for -lnsl for Solaris
2354 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))
2355 dnl Check for -lsocket for Solaris
2356 AC_CHECK_FUNCS(connect,,AC_CHECK_LIB(socket,connect))
2358 dnl **** Check for gcc strength-reduce bug ****
2360 if test "x${GCC}" = "xyes"
2361 then
2362 AC_CACHE_CHECK([for gcc strength-reduce bug], ac_cv_c_gcc_strength_bug,
2363 AC_TRY_RUN([
2364 int main(void) {
2365 static int Array[[3]];
2366 unsigned int B = 3;
2367 int i;
2368 for(i=0; i<B; i++) Array[[i]] = i - 3;
2369 exit( Array[[1]] != -2 );
2371 ac_cv_c_gcc_strength_bug="no",
2372 ac_cv_c_gcc_strength_bug="yes",
2373 ac_cv_c_gcc_strength_bug="yes") )
2374 if test "$ac_cv_c_gcc_strength_bug" = "yes"
2375 then
2376 CFLAGS="$CFLAGS -fno-strength-reduce"
2380 dnl **** Check for working dll ****
2382 LDSHARED=""
2383 LDXXSHARED=""
2384 LDDLLFLAGS=""
2385 AC_CACHE_CHECK([whether we can build a Linux dll],
2386 ac_cv_c_dll_linux,
2387 [saved_cflags=$CFLAGS
2388 CFLAGS="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0,-Bsymbolic"
2389 AC_TRY_LINK(,[return 1],ac_cv_c_dll_linux="yes",ac_cv_c_dll_linux="no")
2390 CFLAGS=$saved_cflags
2392 if test "$ac_cv_c_dll_linux" = "yes"
2393 then
2394 LDSHARED="\$(CC) -shared"
2395 LDXXSHARED="\$(CXX) -shared"
2396 LDDLLFLAGS="-Wl,-Bsymbolic"
2398 AC_CACHE_CHECK([whether the linker accepts -z defs], ac_cv_c_dll_zdefs,
2399 [saved_cflags=$CFLAGS
2400 CFLAGS="$CFLAGS -fPIC -shared -Wl,-Bsymbolic,-z,defs"
2401 AC_TRY_LINK([],[],ac_cv_c_dll_zdefs="yes",ac_cv_c_dll_zdefs="no")
2402 CFLAGS=$saved_cflags
2404 if test "$ac_cv_c_dll_zdefs" = "yes"
2405 then
2406 LDDLLFLAGS="$LDDLLFLAGS,-z,defs"
2409 AC_CACHE_CHECK([whether the linker accepts -init and -fini], ac_cv_c_dll_init_fini,
2410 [saved_cflags=$CFLAGS
2411 CFLAGS="$CFLAGS -fPIC -shared -Wl,-Bsymbolic,-init,__wine_spec_init,-fini,__wine_spec_fini"
2412 AC_TRY_LINK([],[],ac_cv_c_dll_init_fini="yes",ac_cv_c_dll_init_fini="no")
2413 CFLAGS=$saved_cflags
2415 if test "$ac_cv_c_dll_init_fini" = "yes"
2416 then
2417 AC_DEFINE(HAVE_LINKER_INIT_FINI,1,[Define if the linker supports renaming the init and fini functions])
2418 LDDLLFLAGS="$LDDLLFLAGS,-init,__wine_spec_init,-fini,__wine_spec_fini"
2420 else
2421 AC_CACHE_CHECK([whether we can build a UnixWare (Solaris) dll],
2422 ac_cv_c_dll_unixware,
2423 [saved_cflags=$CFLAGS
2424 CFLAGS="$CFLAGS -fPIC -Wl,-G,-h,conftest.so.1.0,-B,symbolic"
2425 AC_TRY_LINK(,[return 1],ac_cv_c_dll_unixware="yes",ac_cv_c_dll_unixware="no")
2426 CFLAGS=$saved_cflags
2428 if test "$ac_cv_c_dll_unixware" = "yes"
2429 then
2430 LDSHARED="\$(CC) -Wl,-G"
2431 LDXXSHARED="\$(CXX) -Wl,-G"
2432 LDDLLFLAGS="-Wl,-B,symbolic"
2433 else
2434 AC_CACHE_CHECK([whether we can build a NetBSD dll],
2435 ac_cv_c_dll_netbsd,
2436 [saved_cflags=$CFLAGS
2437 CFLAGS="$CFLAGS -fPIC -Wl,-Bshareable,-Bforcearchive"
2438 AC_TRY_LINK(,[return 1],ac_cv_c_dll_netbsd="yes",ac_cv_c_dll_netbsd="no")
2439 CFLAGS=$saved_cflags
2441 if test "$ac_cv_c_dll_netbsd" = "yes"
2442 then
2443 LDSHARED="\$(CC) -Wl,-Bshareable,-Bforcearchive"
2444 LDXXSHARED="\$(CXX) -Wl,-Bshareable,-Bforcearchive"
2445 LDDLLFLAGS="" #FIXME
2446 else
2447 AC_CACHE_CHECK([whether we can build a Mach-O (Mac OS X/Darwin) dll],
2448 ac_cv_c_dll_macho,
2449 [saved_cflags=$CFLAGS
2450 CFLAGS="$CFLAGS -bundle"
2451 AC_TRY_LINK(,[return 1], ac_cv_c_dll_macho="yes", ac_cv_c_dll_macho="no")
2452 CFLAGS=$saved_cflags
2454 if test "$ac_cv_c_dll_macho" = "yes"
2455 then
2456 LDSHARED="\$(CC) -bundle -flat_namespace -undefined suppress"
2457 LDXXSHARED="\$(CXX) -bundle -flat_namespace -undefined suppress"
2458 LDDLLFLAGS="-fno-common"
2459 CFLAGS="$CFLAGS -ffixed-r13 -no-cpp-precomp -Dsocklen_t=u_int32_t"
2460 CXXFLAGS="$CXXFLAGS -ffixed-r13 -no-cpp-precomp -Dsocklen_t=u_int32_t"
2465 if test "$ac_cv_c_dll_linux" = "no" -a "$ac_cv_c_dll_unixware" = "no" -a "$ac_cv_c_dll_netbsd" = "no" -a "$ac_cv_c_dll_macho" = "no"
2466 then
2467 AC_MSG_ERROR([Could not find how to build a dynamically linked library])
2470 CFLAGS="$CFLAGS -fPIC"
2472 AC_SUBST(LDSHARED)
2473 AC_SUBST(LDXXSHARED)
2474 AC_SUBST(LDDLLFLAGS)
2476 dnl *** check for the need to define __i386__
2478 AC_CACHE_CHECK([whether we need to define __i386__],ac_cv_cpp_def_i386,
2479 AC_EGREP_CPP(yes,[#if (defined(i386) || defined(__i386)) && !defined(__i386__)
2481 #endif],
2482 ac_cv_cpp_def_i386="yes", ac_cv_cpp_def_i386="no"))
2483 if test "$ac_cv_cpp_def_i386" = "yes"
2484 then
2485 CFLAGS="$CFLAGS -D__i386__"
2488 dnl *** check for the need to define __sparc__
2490 AC_CACHE_CHECK([whether we need to define __sparc__],ac_cv_cpp_def_sparc,
2491 AC_EGREP_CPP(yes,[#if (defined(sparc) || defined(__sparc)) && !defined(__sparc__)
2493 #endif],
2494 ac_cv_cpp_def_sparc="yes", ac_cv_cpp_def_sparc="no"))
2495 if test "$ac_cv_cpp_def_sparc" = "yes"
2496 then
2497 CFLAGS="$CFLAGS -D__sparc__"
2498 CXXFLAGS="$CXXFLAGS -D__sparc__"
2501 dnl *** check for the need to define __sun__
2503 AC_CACHE_CHECK([whether we need to define __sun__],ac_cv_cpp_def_sun,
2504 AC_EGREP_CPP(yes,[#if (defined(sun) || defined(__sun)) && !defined(__sun__)
2506 #endif],
2507 ac_cv_cpp_def_sun="yes", ac_cv_cpp_def_sun="no"))
2508 if test "$ac_cv_cpp_def_sun" = "yes"
2509 then
2510 CFLAGS="$CFLAGS -D__sun__"
2511 CXXFLAGS="$CXXFLAGS -D__sun__"
2514 dnl *** check for the need to define __powerpc__
2516 AC_CACHE_CHECK(whether we need to define __powerpc__,ac_cv_cpp_def_powerpc,
2517 AC_EGREP_CPP(yes,[#if (defined(__ppc__) || defined(__PPC__) || defined(__POWERPC__)) && !defined(__powerpc__)
2519 #endif],
2520 ac_cv_cpp_def_powerpc="yes", ac_cv_cpp_def_powerpc="no"))
2521 if test "$ac_cv_cpp_def_powerpc" = "yes"
2522 then
2523 CFLAGS="$CFLAGS -D__powerpc__"
2524 CXXFLAGS="$CXXFLAGS -D__powerpc__"
2528 dnl **** Test Winelib-related features of the C++ compiler
2529 AC_LANG_CPLUSPLUS()
2530 if test "x${GCC}" = "xyes"
2531 then
2532 OLDCXXFLAGS="$CXXFLAGS";
2533 CXXFLAGS="-fpermissive";
2534 AC_CACHE_CHECK([for g++ -fpermissive option], has_gxx_permissive,
2535 AC_TRY_COMPILE(,[
2536 for (int i=0;i<2;i++);
2537 i=0;
2539 [has_gxx_permissive="yes"],
2540 [has_gxx_permissive="no"])
2542 CXXFLAGS="-fms-extensions";
2543 AC_CACHE_CHECK([for g++ -fms-extensions option], has_gxx_msextensions,
2544 AC_TRY_COMPILE(,[
2547 [has_gxx_msextensions="yes"],
2548 [has_gxx_msextensions="no"])
2550 CXXFLAGS="-fno-for-scope";
2551 AC_CACHE_CHECK([for g++ -fno-for-scope option], has_gxx_no_for_scope,
2552 AC_TRY_COMPILE(,[
2553 for (int i=0;i<2;i++);
2554 i=0;
2556 [has_gxx_no_for_scope="yes"],
2557 [has_gxx_no_for_scope="no"])
2559 CXXFLAGS="$OLDCXXFLAGS";
2560 if test "$has_gxx_permissive" = "yes"
2561 then
2562 CXXFLAGS="$CXXFLAGS -fpermissive"
2564 if test "$has_gxx_msextensions" = "yes"
2565 then
2566 CXXFLAGS="$CXXFLAGS -fms-extensions"
2568 if test "$has_gxx_no_for_scope" = "yes"
2569 then
2570 CXXFLAGS="$CXXFLAGS -fno-for-scope"
2573 AC_LANG_C()
2575 dnl **** Test Winelib-related features of the C compiler
2576 dnl none for now
2578 dnl **** Macros for finding a headers/libraries in a collection of places
2580 dnl AC_PATH_FILE(variable,file,action-if-not-found,default-locations)
2581 AC_DEFUN(AC_PATH_FILE,[
2582 AC_MSG_CHECKING([for $2])
2583 AC_CACHE_VAL(ac_cv_pfile_$1,
2585 ac_found=
2586 ac_dummy="ifelse([$4], , , [$4])"
2587 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2588 for ac_dir in $ac_dummy; do
2589 IFS="$ac_save_ifs"
2590 if test -z "$ac_dir"
2591 then
2592 ac_file="$2"
2593 else
2594 ac_file="$ac_dir/$2"
2596 if test -f "$ac_file"
2597 then
2598 ac_found=1
2599 ac_cv_pfile_$1="$ac_dir"
2600 break
2602 done
2603 ifelse([$3],,,[if test -z "$ac_found"
2604 then
2609 $1="$ac_cv_pfile_$1"
2610 if test -n "$ac_found" -o -n "[$]$1"
2611 then
2612 AC_MSG_RESULT([$]$1)
2613 else
2614 AC_MSG_RESULT(no)
2616 AC_SUBST($1)
2619 dnl AC_PATH_HEADER(variable,header,action-if-not-found,default-locations)
2620 dnl Note that the above may set variable to an empty value if the header is
2621 dnl already in the include path
2622 AC_DEFUN(AC_PATH_HEADER,[
2623 AC_MSG_CHECKING([for $2 header])
2624 AC_CACHE_VAL(ac_cv_pheader_$1,
2626 ac_found=
2627 ac_dummy="ifelse([$4], , :/usr/local/include, [$4])"
2628 save_CPPFLAGS="$CPPFLAGS"
2629 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2630 for ac_dir in $ac_dummy; do
2631 IFS="$ac_save_ifs"
2632 if test -z "$ac_dir"
2633 then
2634 CPPFLAGS="$save_CPPFLAGS"
2635 else
2636 CPPFLAGS="-I$ac_dir $save_CPPFLAGS"
2638 AC_TRY_COMPILE([#include <$2>],,ac_found=1;ac_cv_pheader_$1="$ac_dir";break)
2639 done
2640 CPPFLAGS="$save_CPPFLAGS"
2641 ifelse([$3],,,[if test -z "$ac_found"
2642 then
2647 $1="$ac_cv_pheader_$1"
2648 if test -n "$ac_found" -o -n "[$]$1"
2649 then
2650 AC_MSG_RESULT([$]$1)
2651 else
2652 AC_MSG_RESULT(no)
2654 AC_SUBST($1)
2657 dnl AC_PATH_LIBRARY(variable,libraries,extra libs,action-if-not-found,default-locations)
2658 AC_DEFUN(AC_PATH_LIBRARY,[
2659 AC_MSG_CHECKING([for $2])
2660 AC_CACHE_VAL(ac_cv_plibrary_$1,
2662 ac_found=
2663 ac_dummy="ifelse([$5], , :/usr/local/lib, [$5])"
2664 save_LIBS="$LIBS"
2665 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2666 for ac_dir in $ac_dummy; do
2667 IFS="$ac_save_ifs"
2668 if test -z "$ac_dir"
2669 then
2670 LIBS="$2 $3 $save_LIBS"
2671 else
2672 LIBS="-L$ac_dir $2 $3 $save_LIBS"
2674 AC_TRY_LINK(,,ac_found=1;ac_cv_plibrary_$1="$ac_dir";break)
2675 done
2676 LIBS="$save_LIBS"
2677 ifelse([$4],,,[if test -z "$ac_found"
2678 then
2683 $1="$ac_cv_plibrary_$1"
2684 if test -n "$ac_found" -o -n "[$]$1"
2685 then
2686 AC_MSG_RESULT([$]$1)
2687 else
2688 AC_MSG_RESULT(no)
2690 AC_SUBST($1)
2693 dnl **** Try to find where winelib is located ****
2695 LDPATH=""
2696 WINE_INCLUDE_ROOT=""
2697 WINE_INCLUDE_PATH=""
2698 WINE_LIBRARY_ROOT=""
2699 WINE_LIBRARY_PATH=""
2700 WINE_DLL_ROOT=""
2701 WINE_DLL_PATH=""
2702 WINE_TOOL_PATH=""
2703 WINE=""
2704 WINEBUILD=""
2705 WRC=""
2707 AC_ARG_WITH(wine,
2708 [ --with-wine=DIR the Wine package (or sources) is in DIR],
2709 [if test "$withval" != "no"; then
2710 WINE_ROOT="$withval";
2711 WINE_INCLUDES="";
2712 WINE_LIBRARIES="";
2713 WINE_TOOLS="";
2714 else
2715 WINE_ROOT="";
2716 fi])
2717 if test -n "$WINE_ROOT"
2718 then
2719 WINE_INCLUDE_ROOT="$WINE_ROOT/include:$WINE_ROOT/include/wine:$WINE_ROOT/include/wine/windows:$WINE_ROOT/include/windows"
2720 WINE_LIBRARY_ROOT="$WINE_ROOT:$WINE_ROOT/libs:$WINE_ROOT/lib"
2721 WINE_DLL_ROOT="$WINE_ROOT/dlls:$WINE_ROOT/lib:$WINE_ROOT/lib/wine"
2722 WINE_TOOL_PATH="$WINE_ROOT:$WINE_ROOT/bin:$WINE_ROOT/tools/wrc:$WINE_ROOT/tools/winebuild"
2725 AC_ARG_WITH(wine-includes,
2726 [ --with-wine-includes=DIR the Wine includes are in DIR],
2727 [if test "$withval" != "no"; then
2728 WINE_INCLUDES="$withval";
2729 else
2730 WINE_INCLUDES="";
2731 fi])
2732 if test -n "$WINE_INCLUDES"
2733 then
2734 WINE_INCLUDE_ROOT="$WINE_INCLUDES"
2737 AC_ARG_WITH(wine-libraries,
2738 [ --with-wine-libraries=DIR the Wine libraries are in DIR],
2739 [if test "$withval" != "no"; then
2740 WINE_LIBRARIES="$withval";
2741 else
2742 WINE_LIBRARIES="";
2743 fi])
2744 if test -n "$WINE_LIBRARIES"
2745 then
2746 WINE_LIBRARY_ROOT="$WINE_LIBRARIES"
2749 AC_ARG_WITH(wine-dlls,
2750 [ --with-wine-dlls=DIR the Wine dlls are in DIR],
2751 [if test "$withval" != "no"; then
2752 WINE_DLLS="$withval";
2753 else
2754 WINE_DLLS="";
2755 fi])
2756 if test -n "$WINE_DLLS"
2757 then
2758 WINE_DLL_ROOT="$WINE_DLLS"
2761 AC_ARG_WITH(wine-tools,
2762 [ --with-wine-tools=DIR the Wine tools are in DIR],
2763 [if test "$withval" != "no"; then
2764 WINE_TOOLS="$withval";
2765 else
2766 WINE_TOOLS="";
2767 fi])
2768 if test -n "$WINE_TOOLS"
2769 then
2770 WINE_TOOL_PATH="$WINE_TOOLS:$WINE_TOOLS/tools/wrc:$WINE_TOOLS/tools/winebuild"
2773 if test -z "$WINE_INCLUDE_ROOT"
2774 then
2775 WINE_INCLUDE_ROOT=":/usr/include/wine/windows:/usr/include/wine:/usr/local/include/wine/windows:/opt/wine/include/windows:/opt/wine/include/wine";
2776 else
2777 AC_PATH_FILE(WINE_INCLUDE_ROOT,[windef.h],[
2778 AC_MSG_ERROR([Could not find the Wine headers (windef.h)])
2779 ],$WINE_INCLUDE_ROOT)
2781 AC_PATH_HEADER(WINE_INCLUDE_ROOT,[windef.h],[
2782 AC_MSG_ERROR([Could not include the Wine headers (windef.h)])
2783 ],$WINE_INCLUDE_ROOT)
2784 if test -n "$WINE_INCLUDE_ROOT"
2785 then
2786 WINE_INCLUDE_PATH="-I$WINE_INCLUDE_ROOT"
2787 else
2788 WINE_INCLUDE_PATH=""
2791 if test -z "$WINE_LIBRARY_ROOT"
2792 then
2793 WINE_LIBRARY_ROOT=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib"
2794 else
2795 AC_PATH_FILE(WINE_LIBRARY_ROOT,[libwine.so],
2797 AC_PATH_FILE(WINE_LIBRARY_ROOT,[libwine.dylib],
2798 [AC_MSG_ERROR([Could not find the Wine libraries (libwine.dylib or libwine.so)])],
2799 $WINE_LIBRARY_ROOT)
2800 ], $WINE_LIBRARY_ROOT)
2802 AC_PATH_LIBRARY(WINE_LIBRARY_ROOT,[-lwine],[],[
2803 AC_MSG_ERROR([Could not link with the Wine libraries (libwine.so)])
2804 ],$WINE_LIBRARY_ROOT)
2805 if test -n "$WINE_LIBRARY_ROOT"
2806 then
2807 WINE_LIBRARY_PATH="-L$WINE_LIBRARY_ROOT"
2808 LDPATH="$WINE_LIBRARY_ROOT"
2809 else
2810 WINE_LIBRARY_PATH=""
2813 save_LIBS="$LIBS"
2814 LIBS="$WINE_LIBRARY_PATH $LIBS"
2816 AC_CHECK_LIB(wine_unicode,wine_cp_wcstombs,[],[
2817 AC_MSG_ERROR([Could not find the Wine dlls (libwine_unicode.so)])
2820 LIBS="$save_LIBS"
2822 if test -z "$WINE_DLL_ROOT"
2823 then
2824 if test -n "$WINE_LIBRARY_ROOT"
2825 then
2826 WINE_DLL_ROOT="$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/dlls:$WINE_LIBRARY_ROOT/wine"
2827 else
2828 WINE_DLL_ROOT="/lib:/lib/wine:/usr/lib:/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine"
2832 AC_PATH_FILE(WINE_DLL_ROOT,[libntdll.def],[
2833 AC_MSG_ERROR([Could not find the Wine dlls (libntdll.def)])
2834 ],[$WINE_DLL_ROOT])
2835 WINE_DLL_PATH="-L$WINE_DLL_ROOT"
2836 WINE_LIBRARY_PATH="$WINE_LIBRARY_PATH -L$WINE_DLL_ROOT"
2838 if test -z "$WINE_TOOL_PATH"
2839 then
2840 WINE_TOOL_PATH="$PATH:/usr/local/bin:/opt/wine/bin"
2842 AC_PATH_PROG(WINE,wine,,$WINE_TOOL_PATH)
2843 if test -z "$WINE"
2844 then
2845 AC_MSG_ERROR([Could not find Wine's wine tool])
2847 AC_PATH_PROG(WINEBUILD,winebuild,,$WINE_TOOL_PATH)
2848 if test -z "$WINEBUILD"
2849 then
2850 AC_MSG_ERROR([Could not find Wine's winebuild tool])
2852 AC_PATH_PROG(WRC,wrc,,$WINE_TOOL_PATH)
2853 if test -z "$WRC"
2854 then
2855 AC_MSG_ERROR([Could not find Wine's wrc tool])
2858 case $build_os in
2859 darwin*|macosx*)
2860 LDPATH="DYLD_LIBRARY_PATH=\"$LDPATH:\$\$DYLD_LIBRARY_PATH\"";;
2862 LDPATH="LD_LIBRARY_PATH=\"$LDPATH:\$\$LD_LIBRARY_PATH\""
2863 esac
2865 AC_SUBST(LDPATH)
2866 AC_SUBST(WINE_INCLUDE_PATH)
2867 AC_SUBST(WINE_LIBRARY_PATH)
2868 AC_SUBST(WINE_DLL_PATH)
2870 dnl **** Try to find where the MFC are located ****
2871 AC_LANG_CPLUSPLUS()
2873 if test "x$NEEDS_MFC" = "x1"
2874 then
2875 ATL_INCLUDE_ROOT="";
2876 ATL_INCLUDE_PATH="";
2877 MFC_INCLUDE_ROOT="";
2878 MFC_INCLUDE_PATH="";
2879 MFC_LIBRARY_ROOT="";
2880 MFC_LIBRARY_PATH="";
2882 AC_ARG_WITH(mfc,
2883 [ --with-mfc=DIR the MFC package (or sources) is in DIR],
2884 [if test "$withval" != "no"; then
2885 MFC_ROOT="$withval";
2886 ATL_INCLUDES="";
2887 MFC_INCLUDES="";
2888 MFC_LIBRARIES="";
2889 else
2890 MFC_ROOT="";
2891 fi])
2892 if test -n "$MFC_ROOT"
2893 then
2894 ATL_INCLUDE_ROOT="$MFC_ROOT";
2895 MFC_INCLUDE_ROOT="$MFC_ROOT";
2896 MFC_LIBRARY_ROOT="$MFC_ROOT";
2899 AC_ARG_WITH(atl-includes,
2900 [ --with-atl-includes=DIR the ATL includes are in DIR],
2901 [if test "$withval" != "no"; then
2902 ATL_INCLUDES="$withval";
2903 else
2904 ATL_INCLUDES="";
2905 fi])
2906 if test -n "$ATL_INCLUDES"
2907 then
2908 ATL_INCLUDE_ROOT="$ATL_INCLUDES";
2911 AC_ARG_WITH(mfc-includes,
2912 [ --with-mfc-includes=DIR the MFC includes are in DIR],
2913 [if test "$withval" != "no"; then
2914 MFC_INCLUDES="$withval";
2915 else
2916 MFC_INCLUDES="";
2917 fi])
2918 if test -n "$MFC_INCLUDES"
2919 then
2920 MFC_INCLUDE_ROOT="$MFC_INCLUDES";
2923 AC_ARG_WITH(mfc-libraries,
2924 [ --with-mfc-libraries=DIR the MFC libraries are in DIR],
2925 [if test "$withval" != "no"; then
2926 MFC_LIBRARIES="$withval";
2927 else
2928 MFC_LIBRARIES="";
2929 fi])
2930 if test -n "$MFC_LIBRARIES"
2931 then
2932 MFC_LIBRARY_ROOT="$MFC_LIBRARIES";
2935 OLDCPPFLAGS="$CPPFLAGS"
2936 dnl FIXME: We should not have defines in any of the include paths
2937 CPPFLAGS="$WINE_INCLUDE_PATH -I$WINE_INCLUDE_ROOT/msvcrt -D_DLL -D_MT $CPPFLAGS"
2938 ATL_INCLUDE_PATH="-I\$(WINE_INCLUDE_ROOT)/msvcrt -D_DLL -D_MT"
2939 if test -z "$ATL_INCLUDE_ROOT"
2940 then
2941 ATL_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/atl:/usr/include/atl:/usr/local/include/atl:/opt/mfc/include/atl:/opt/atl/include"
2942 else
2943 ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT:$ATL_INCLUDE_ROOT/atl:$ATL_INCLUDE_ROOT/atl/include"
2945 AC_PATH_HEADER(ATL_INCLUDE_ROOT,atldef.h,[
2946 AC_MSG_ERROR([Could not find the ATL includes])
2947 ],$ATL_INCLUDE_ROOT)
2948 if test -n "$ATL_INCLUDE_ROOT"
2949 then
2950 ATL_INCLUDE_PATH="$ATL_INCLUDE_PATH -I$ATL_INCLUDE_ROOT"
2953 MFC_INCLUDE_PATH="$ATL_INCLUDE_PATH"
2954 if test -z "$MFC_INCLUDE_ROOT"
2955 then
2956 MFC_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/mfc:/usr/include/mfc:/usr/local/include/mfc:/opt/mfc/include/mfc:/opt/mfc/include"
2957 else
2958 MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT:$MFC_INCLUDE_ROOT/mfc:$MFC_INCLUDE_ROOT/mfc/include:$MFC_INCLUDE_ROOT/Include"
2960 AC_PATH_HEADER(MFC_INCLUDE_ROOT,afx.h,[
2961 AC_MSG_ERROR([Could not find the MFC includes])
2962 ],$MFC_INCLUDE_ROOT)
2963 if test -n "$MFC_INCLUDE_ROOT" -a "$ATL_INCLUDE_ROOT" != "$MFC_INCLUDE_ROOT"
2964 then
2965 MFC_INCLUDE_PATH="$MFC_INCLUDE_PATH -I$MFC_INCLUDE_ROOT"
2967 CPPFLAGS="$OLDCPPFLAGS"
2969 if test -z "$MFC_LIBRARY_ROOT"
2970 then
2971 MFC_LIBRARY_ROOT=":$WINE_LIBRARY_ROOT:/usr/lib/mfc:/usr/local/lib:/usr/local/lib/mfc:/opt/mfc/lib";
2972 else
2973 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT:$MFC_LIBRARY_ROOT/lib:$MFC_LIBRARY_ROOT/mfc/src:$MFC_LIBRARY_ROOT/src";
2975 AC_PATH_LIBRARY(MFC_LIBRARY_ROOT,[-lmfc],[$WINE_LIBRARY_PATH -lwine -lwine_unicode],[
2976 AC_MSG_ERROR([Could not find the MFC library])
2977 ],$MFC_LIBRARY_ROOT)
2978 if test -n "$MFC_LIBRARY_ROOT" -a "$MFC_LIBRARY_ROOT" != "$WINE_LIBRARY_ROOT"
2979 then
2980 MFC_LIBRARY_PATH="-L$MFC_LIBRARY_ROOT"
2981 else
2982 MFC_LIBRARY_PATH=""
2985 AC_SUBST(ATL_INCLUDE_PATH)
2986 AC_SUBST(MFC_INCLUDE_PATH)
2987 AC_SUBST(MFC_LIBRARY_PATH)
2990 AC_LANG_C()
2992 dnl **** Generate output files ****
2994 MAKE_RULES=Make.rules
2995 AC_SUBST_FILE(MAKE_RULES)
2997 AC_OUTPUT([
2998 Make.rules
2999 ##WINEMAKER_PROJECTS##
3002 echo
3003 echo "Configure finished. Do 'make' to build the project."
3004 echo
3006 dnl Local Variables:
3007 dnl comment-start: "dnl "
3008 dnl comment-end: ""
3009 dnl comment-start-skip: "\\bdnl\\b\\s *"
3010 dnl compile-command: "autoconf"
3011 dnl End:
3012 --- Make.rules.in ---
3013 # Copyright 2000 Francois Gouget for CodeWeavers
3014 # fgouget@codeweavers.com
3016 # Global rules shared by all makefiles -*-Makefile-*-
3018 # Each individual makefile must define the following variables:
3019 # TOPOBJDIR : top-level object directory
3020 # SRCDIR : source directory for this module
3022 # Each individual makefile may define the following additional variables:
3024 # SUBDIRS : subdirectories that contain a Makefile
3025 # DLLS : WineLib libraries to be built
3026 # EXES : WineLib executables to be built
3028 # CEXTRA : extra c flags (e.g. '-Wall')
3029 # CXXEXTRA : extra c++ flags (e.g. '-Wall')
3030 # WRCEXTRA : extra wrc flags (e.g. '-p _SysRes')
3031 # DEFINES : defines (e.g. -DSTRICT)
3032 # INCLUDE_PATH : additional include path
3033 # LIBRARY_PATH : additional library path
3034 # LIBRARIES : additional Unix libraries to link with
3036 # C_SRCS : C sources for the module
3037 # CXX_SRCS : C++ sources for the module
3038 # RC_SRCS : resource source files
3039 # SPEC_SRCS : interface definition files
3042 # Where is Wine
3044 WINE_INCLUDE_ROOT = @WINE_INCLUDE_ROOT@
3045 WINE_INCLUDE_PATH = @WINE_INCLUDE_PATH@
3046 WINE_LIBRARY_ROOT = @WINE_LIBRARY_ROOT@
3047 WINE_LIBRARY_PATH = @WINE_LIBRARY_PATH@
3048 WINE_DLL_ROOT = @WINE_DLL_ROOT@
3049 WINE_DLL_PATH = @WINE_DLL_PATH@
3051 LDPATH = @LDPATH@
3053 # Where are the MFC
3055 ATL_INCLUDE_ROOT = @ATL_INCLUDE_ROOT@
3056 ATL_INCLUDE_PATH = @ATL_INCLUDE_PATH@
3057 MFC_INCLUDE_ROOT = @MFC_INCLUDE_ROOT@
3058 MFC_INCLUDE_PATH = @MFC_INCLUDE_PATH@
3059 MFC_LIBRARY_ROOT = @MFC_LIBRARY_ROOT@
3060 MFC_LIBRARY_PATH = @MFC_LIBRARY_PATH@
3062 # Global definitions and options
3064 GLOBAL_DEFINES = ##WINEMAKER_DEFINES##
3065 GLOBAL_INCLUDE_PATH = ##WINEMAKER_INCLUDE_PATH##
3066 GLOBAL_DLL_PATH = ##WINEMAKER_DLL_PATH##
3067 GLOBAL_DLLS = ##WINEMAKER_DLLS##
3068 GLOBAL_LIBRARY_PATH = ##WINEMAKER_LIBRARY_PATH##
3069 GLOBAL_LIBRARIES = ##WINEMAKER_LIBRARIES##
3071 # First some useful definitions
3073 SHELL = /bin/sh
3074 CC = @CC@
3075 CPP = @CPP@
3076 CXX = @CXX@
3077 WRC = @WRC@
3078 CFLAGS = @CFLAGS@ $(CEXTRA)
3079 CXXFLAGS = @CXXFLAGS@ $(CXXEXTRA)
3080 WRCFLAGS = $(WRCEXTRA)
3081 OPTIONS = @OPTIONS@ -D_REENTRANT
3082 LIBS = @LIBS@ $(LIBRARY_PATH)
3083 DIVINCL = $(GLOBAL_INCLUDE_PATH) -I$(SRCDIR) $(INCLUDE_PATH) $(WINE_INCLUDE_PATH)
3084 ALLCFLAGS = $(DIVINCL) $(CFLAGS) $(GLOBAL_DEFINES) $(DEFINES) $(OPTIONS)
3085 ALLCXXFLAGS=$(DIVINCL) $(CXXFLAGS) $(GLOBAL_DEFINES) $(DEFINES) $(OPTIONS)
3086 ALL_DLL_PATH = $(DLL_PATH) $(GLOBAL_DLL_PATH) $(WINE_DLL_PATH)
3087 ALL_LIBRARY_PATH = $(LIBRARY_PATH) $(GLOBAL_LIBRARY_PATH) $(WINE_LIBRARY_PATH)
3088 WINE_LIBRARIES = -lwine -lwine_unicode
3089 ALL_LIBRARIES = $(LIBRARIES:%=-l%) $(GLOBAL_LIBRARIES:%=-l%) $(WINE_LIBRARIES)
3090 LDSHARED = @LDSHARED@
3091 LDXXSHARED= @LDXXSHARED@
3092 LDDLLFLAGS= @LDDLLFLAGS@
3093 LN_S = @LN_S@
3094 RM = rm -f
3095 MV = mv
3096 MKDIR = mkdir -p
3097 WINE = @WINE@
3098 WINEBUILD = @WINEBUILD@
3099 @SET_MAKE@
3101 # Installation infos
3103 INSTALL = install
3104 INSTALL_PROGRAM = $(INSTALL)
3105 INSTALL_SCRIPT = $(INSTALL)
3106 INSTALL_DATA = $(INSTALL) -m 644
3107 prefix = @prefix@
3108 exec_prefix = @exec_prefix@
3109 bindir = @bindir@
3110 libdir = @libdir@
3111 infodir = @infodir@
3112 mandir = @mandir@
3113 dlldir = @libdir@/wine
3115 prog_manext = 1
3116 conf_manext = 5
3118 OBJS = $(C_SRCS:.c=.o) $(CXX_SRCS:.cpp=.o) \
3119 $(SPEC_SRCS:.spec=.spec.o)
3120 CLEAN_FILES = *.dbg.c *.spec.c y.tab.c y.tab.h lex.yy.c \
3121 core *.orig *.rej \
3122 \\\#*\\\# *~ *% .\\\#*
3124 # Implicit rules
3126 .SUFFIXES: .cpp .rc .res .spec .spec.c .spec.o
3128 .c.o:
3129 $(CC) -c $(ALLCFLAGS) -o $@ $<
3131 .cpp.o:
3132 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
3134 .cxx.o:
3135 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
3137 .rc.res:
3138 $(LDPATH) $(WRC) $(WRCFLAGS) $(DIVINCL) -o $@ $<
3140 .PHONY: all install uninstall clean distclean depend dummy
3142 # 'all' target first in case the enclosing Makefile didn't define any target
3144 all: Makefile
3146 # Rules for makefile
3148 Makefile: Makefile.in $(TOPSRCDIR)/configure
3149 @echo $@ is older than $?, please rerun $(TOPSRCDIR)/configure
3150 @exit 1
3152 # Rules for cleaning
3154 $(SUBDIRS:%=%/__clean__): dummy
3155 cd `dirname $@` && $(MAKE) clean
3157 $(EXTRASUBDIRS:%=%/__clean__): dummy
3158 -cd `dirname $@` && $(RM) $(CLEAN_FILES)
3160 clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
3161 $(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(OBJS)
3162 $(RM) $(DLLS:%=%.dbg.o) $(DLLS:%=%.spec.o) $(DLLS:%=%.so)
3163 $(RM) $(EXES:%=%.dbg.o) $(EXES:%=%.spec.o) $(EXES:%=%.so) $(EXES:%.exe=%)
3165 # Rules for installing
3167 $(SUBDIRS:%=%/__install__): dummy
3168 cd `dirname $@` && $(MAKE) install
3170 $(SUBDIRS:%=%/__uninstall__): dummy
3171 cd `dirname $@` && $(MAKE) uninstall
3173 # Misc. rules
3175 $(SUBDIRS): dummy
3176 @cd $@ && $(MAKE)
3178 dummy:
3180 # End of global rules
3181 --- wineapploader.in ---
3182 #!/bin/sh
3184 # Wrapper script to start a Winelib application once it is installed
3186 # Copyright (C) 2002 Alexandre Julliard
3188 # determine the app Winelib library name
3189 appname=`basename "$0" .exe`.exe
3191 #allow Wine to load Winelib application from the current directory
3192 export WINEDLLPATH=$WINEDLLPATH:@winelibdir@
3194 # first try explicit WINELOADER
3195 if [ -x "$WINELOADER" ]; then exec "$WINELOADER" "$appname" "$@"; fi
3197 # then default bin directory
3198 if [ -x "@bindir@/wine" ]; then exec "@bindir@/wine" "$appname" "$@"; fi
3200 # now try the directory containing $0
3201 appdir=""
3202 case "$0" in
3203 */*)
3204 # $0 contains a path, use it
3205 appdir=`dirname "$0"`
3208 # no directory in $0, search in PATH
3209 saved_ifs=$IFS
3210 IFS=:
3211 for d in $PATH
3213 IFS=$saved_ifs
3214 if [ -x "$d/$0" ]; then appdir="$d"; break; fi
3215 done
3217 esac
3218 if [ -x "$appdir/wine" ]; then exec "$appdir/wine" "$appname" "$@"; fi
3220 # finally look in PATH
3221 exec wine "$appname" "$@"
3222 --- wrapper.c ---
3224 * Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
3227 #ifndef STRICT
3228 #define STRICT
3229 #endif
3231 #include <dlfcn.h>
3232 #include <windows.h>
3237 * Describe the wrapped application
3241 * This is either CUIEXE for a console based application or
3242 * GUIEXE for a regular windows application.
3244 #define GUIEXE 0
3245 #define CUIEXE 1
3246 #define APP_TYPE ##WINEMAKER_APP_TYPE##
3249 * This is the name of the library containing the application,
3250 * e.g. 'hello.dll' if the application is called 'hello.exe'.
3252 static char* appName = "##WINEMAKER_APP_NAME##";
3255 * This is the name of the application's Windows module. If left NULL
3256 * then appName is used.
3258 static char* appModule = NULL;
3261 * This is the application's entry point. This is usually "WinMain" for a
3262 * GUIEXE and 'main' for a CUIEXE application.
3264 static char* appInit = ##WINEMAKER_APP_INIT##;
3267 * This is either non-NULL for MFC-based applications and is the name of the
3268 * MFC's module. This is the module in which we will take the 'WinMain'
3269 * function.
3271 static char* mfcModule = ##WINEMAKER_APP_MFC##;
3276 * Implement the main.
3279 #if APP_TYPE == GUIEXE
3280 typedef int WINAPI (*WinMainFunc)(HINSTANCE hInstance, HINSTANCE hPrevInstance,
3281 PSTR szCmdLine, int iCmdShow);
3282 #else
3283 typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp);
3284 #endif
3286 #if APP_TYPE == GUIEXE
3287 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
3288 PSTR szCmdLine, int iCmdShow)
3289 #else
3290 int WINAPI main(int argc, char** argv, char** envp)
3291 #endif
3293 HINSTANCE hApp = 0, hMFC = 0, hMain = 0;
3294 void* appMain;
3295 int retcode;
3297 /* Then if this application is MFC based, load the MFC module */
3298 /* FIXME: I'm not sure this is really necessary */
3299 if (mfcModule!=NULL) {
3300 hMFC=LoadLibrary(mfcModule);
3301 if (hMFC==NULL) {
3302 char format[]="Could not load the MFC module %s (%d)";
3303 char* msg;
3305 msg=(char*)malloc(strlen(format)+strlen(mfcModule)+11);
3306 sprintf(msg,format,mfcModule,GetLastError());
3307 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
3308 free(msg);
3309 return 1;
3311 /* MFC is a special case: the WinMain is in the MFC library,
3312 * instead of the application's library.
3314 hMain=hMFC;
3315 } else {
3316 hMFC=NULL;
3319 /* Load the application's module */
3320 if (appModule==NULL) {
3321 appModule=appName;
3323 hApp=LoadLibrary(appModule);
3324 if (hApp==NULL) {
3325 char format[]="Could not load the application's module %s (%d)";
3326 char* msg;
3328 msg=(char*)malloc(strlen(format)+strlen(appModule)+11);
3329 sprintf(msg,format,appModule,GetLastError());
3330 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
3331 free(msg);
3332 return 1;
3333 } else if (hMain==NULL) {
3334 hMain=hApp;
3337 /* Get the address of the application's entry point */
3338 appMain=GetProcAddress(hMain, appInit);
3339 if (appMain==NULL) {
3340 char format[]="Could not get the address of %s (%d)";
3341 char* msg;
3343 msg=(char*)malloc(strlen(format)+strlen(appInit)+11);
3344 sprintf(msg,format,appInit,GetLastError());
3345 MessageBox(NULL,msg,"GetProcAddress error",MB_OK);
3346 free(msg);
3347 return 1;
3350 /* And finally invoke the application's entry point */
3351 #if APP_TYPE == GUIEXE
3352 retcode=(*((WinMainFunc)appMain))(hApp,hPrevInstance,szCmdLine,iCmdShow);
3353 #else
3354 retcode=(*((MainFunc)appMain))(argc,argv,envp);
3355 #endif
3357 /* Cleanup and done */
3358 FreeLibrary(hApp);
3359 if (hMFC!=NULL) {
3360 FreeLibrary(hMFC);
3363 return retcode;