Add stubs for the Activation Context API (XP+).
[wine/dcerpc.git] / tools / winemaker
blob2beff156be7e6549323c843062e3c18278d51a67
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 # Initialize a target:
246 # - set the target type to TT_SETTINGS, i.e. no real target will
247 # be generated.
248 sub target_init($)
250 my $target=$_[0];
252 @$target[$T_TYPE]=$TT_SETTINGS;
253 # leaving $T_INIT undefined
254 @$target[$T_FLAGS]=$opt_flags;
255 @$target[$T_SOURCES_C]=[];
256 @$target[$T_SOURCES_CXX]=[];
257 @$target[$T_SOURCES_RC]=[];
258 @$target[$T_SOURCES_MISC]=[];
259 @$target[$T_DEFINES]=[];
260 @$target[$T_INCLUDE_PATH]=[];
261 @$target[$T_DLL_PATH]=[];
262 @$target[$T_DLLS]=[];
263 @$target[$T_LIBRARY_PATH]=[];
264 @$target[$T_LIBRARIES]=[];
265 @$target[$T_DEPENDS]=[];
268 sub get_default_init($)
270 my $type=$_[0];
271 if ($type == $TT_GUIEXE) {
272 return "WinMain";
273 } elsif ($type == $TT_CUIEXE) {
274 return "main";
275 } elsif ($type == $TT_DLL) {
276 return "DllMain";
282 #####
284 # Project modelization
286 #####
288 # First we have the notion of project. A project is described by an
289 # array (since we don't have structs in perl). The constants below
290 # identify what is stored at each index of the array.
293 # This is the path in which this project is located. In other
294 # words, this is the path to the Makefile.
295 my $P_PATH=0;
298 # This index contains a reference to an array containing the project-wide
299 # settings. The structure of that arrray is actually identical to that of
300 # a regular target since it can also contain extra sources.
301 my $P_SETTINGS=1;
304 # This index contains a reference to an array of targets for this
305 # project. Each target describes how an executable or library is to
306 # be built. For each target this description takes the same form as
307 # that of the project: an array. So this entry is an array of arrays.
308 my $P_TARGETS=2;
311 # Initialize a project:
312 # - set the project's path
313 # - initialize the target list
314 # - create a default target (will be removed later if unnecessary)
315 sub project_init($$)
317 my $project=$_[0];
318 my $path=$_[1];
320 my $project_settings=[];
321 target_init($project_settings);
323 @$project[$P_PATH]=$path;
324 @$project[$P_SETTINGS]=$project_settings;
325 @$project[$P_TARGETS]=[];
330 #####
332 # Global variables
334 #####
336 my %warnings;
338 my %templates;
341 # Contains the list of all projects. This list tells us what are
342 # the subprojects of the main Makefile and where we have to generate
343 # Makefiles.
344 my @projects=();
347 # This is the main project, i.e. the one in the "." directory.
348 # It may well be empty in which case the main Makefile will only
349 # call out subprojects.
350 my @main_project;
353 # Contains the defaults for the include path, etc.
354 # We store the defaults as if this were a target except that we only
355 # exploit the defines, include path, library path, library list and misc
356 # sources fields.
357 my @global_settings;
360 # If one of the projects requires the MFc then we set this global variable
361 # to true so that configure asks the user to provide a path tothe MFC
362 my $needs_mfc=0;
366 #####
368 # Utility functions
370 #####
373 # Cleans up a name to make it an acceptable Makefile
374 # variable name.
375 sub canonize($)
377 my $name=$_[0];
379 $name =~ tr/a-zA-Z0-9_/_/c;
380 return $name;
384 # Returns true is the specified pathname is absolute.
385 # Note: pathnames that start with a variable '$' or
386 # '~' are considered absolute.
387 sub is_absolute($)
389 my $path=$_[0];
391 return ($path =~ /^[\/~\$]/);
395 # Performs a binary search looking for the specified item
396 sub bsearch($$)
398 my $array=$_[0];
399 my $item=$_[1];
400 my $last=@{$array}-1;
401 my $first=0;
403 while ($first<=$last) {
404 my $index=int(($first+$last)/2);
405 my $cmp=@$array[$index] cmp $item;
406 if ($cmp<0) {
407 $first=$index+1;
408 } elsif ($cmp>0) {
409 $last=$index-1;
410 } else {
411 return $index;
418 #####
420 # 'Source'-based Project analysis
422 #####
425 # Allows the user to specify makefile and target specific options
426 # - target: the structure in which to store the results
427 # - options: the string containing the options
428 sub source_set_options($$)
430 my $target=$_[0];
431 my $options=$_[1];
433 #FIXME: we must deal with escaping of stuff and all
434 foreach my $option (split / /,$options) {
435 if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
436 push @{@$target[$T_DEFINES]},$option;
437 } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
438 push @{@$target[$T_INCLUDE_PATH]},$option;
439 } elsif ($option =~ /^-P/) {
440 push @{@$target[$T_DLL_PATH]},"-L$'";
441 } elsif ($option =~ /^-i/) {
442 my $dllname = $';
443 if ($dllname =~ /^msvcrt$/) {
444 push @{@$target[$T_INCLUDE_PATH]},"-I\$(WINE_INCLUDE_ROOT)/msvcrt";
446 push @{@$target[$T_DLLS]},$dllname;
447 } elsif ($option =~ /^-L/) {
448 push @{@$target[$T_LIBRARY_PATH]},$option;
449 } elsif ($option =~ /^-l/) {
450 push @{@$target[$T_LIBRARIES]},"$'";
451 } elsif ($option =~ /^--wrap/) {
452 if (@$target[$T_TYPE] != $TT_DLL) {
453 @$target[$T_FLAGS]|=$TF_WRAP;
454 } else {
455 print STDERR "warning: option --wrap is illegal for DLLs - ignoring";
457 } elsif ($option =~ /^--nowrap/) {
458 if (@$target[$T_TYPE] != $TT_DLL) {
459 @$target[$T_FLAGS]&=~$TF_WRAP;
460 } else {
461 print STDERR "warning: option --nowrap is illegal for DLLs - ignoring";
463 } elsif ($option =~ /^--mfc/) {
464 @$target[$T_FLAGS]|=$TF_MFC;
465 @$target[$T_FLAGS]&=~$TF_NOMFC;
466 } elsif ($option =~ /^--nomfc/) {
467 @$target[$T_FLAGS]&=~$TF_MFC;
468 @$target[$T_FLAGS]|=$TF_NOMFC;
469 } elsif ($option =~ /^--nodlls/) {
470 @$target[$T_FLAGS]|=$TF_NODLLS;
471 } else {
472 print STDERR "error: unknown option \"$option\"\n";
473 return 0;
476 if (@$target[$T_TYPE] != $TT_DLL &&
477 @$target[$T_FLAGS] & $TF_MFC &&
478 !(@$target[$T_FLAGS] & $TF_WRAP)) {
479 print STDERR "info: option --mfc requires --wrap";
480 @$target[$T_FLAGS]|=$TF_WRAP;
482 return 1;
486 # Scans the specified directory to:
487 # - see if we should create a Makefile in this directory. We normally do
488 # so if we find a project file and sources
489 # - get a list of targets for this directory
490 # - get the list of source files
491 sub source_scan_directory($$$$);
492 sub source_scan_directory($$$$)
494 # a reference to the parent's project
495 my $parent_project=$_[0];
496 # the full relative path to the current directory, including a
497 # trailing '/', or an empty string if this is the top level directory
498 my $path=$_[1];
499 # the name of this directory, including a trailing '/', or an empty
500 # string if this is the top level directory
501 my $dirname=$_[2];
502 # if set then no targets will be looked for and the sources will all
503 # end up in the parent_project's 'misc' bucket
504 my $no_target=$_[3];
506 # reference to the project for this directory. May not be used
507 my $project;
508 # list of targets found in the 'current' directory
509 my %targets;
510 # list of sources found in the current directory
511 my @sources_c=();
512 my @sources_cxx=();
513 my @sources_rc=();
514 my @sources_misc=();
515 # true if this directory contains a Windows project
516 my $has_win_project=0;
517 # If we don't find any executable/library then we might make up targets
518 # from the list of .dsp/.mak files we find since they usually have the
519 # same name as their target.
520 my @dsp_files=();
521 my @mak_files=();
523 if (defined $opt_single_target or $dirname eq "") {
524 # Either there is a single target and thus a single project,
525 # or we are in the top level directory for which a project
526 # already exists
527 $project=$parent_project;
528 } else {
529 $project=[];
530 project_init($project,$path);
532 my $project_settings=@$project[$P_SETTINGS];
534 # First find out what this directory contains:
535 # collect all sources, targets and subdirectories
536 my $directory=get_directory_contents($path);
537 foreach my $dentry (@$directory) {
538 if ($dentry =~ /^\./) {
539 next;
541 my $fullentry="$path$dentry";
542 if (-d "$fullentry") {
543 if ($dentry =~ /^(Release|Debug)/i) {
544 # These directories are often used to store the object files and the
545 # resulting executable/library. They should not contain anything else.
546 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
547 foreach my $candidate (@candidates) {
548 $targets{$candidate}=1;
550 } elsif ($dentry =~ /^include/i) {
551 # This directory must contain headers we're going to need
552 push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
553 source_scan_directory($project,"$fullentry/","$dentry/",1);
554 } else {
555 # Recursively scan this directory. Any source file that cannot be
556 # attributed to a project in one of the subdirectories will be
557 # attributed to this project.
558 source_scan_directory($project,"$fullentry/","$dentry/",$no_target);
560 } elsif (-f "$fullentry") {
561 if ($dentry =~ /\.(exe|dll)$/i) {
562 $targets{$dentry}=1;
563 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
564 push @sources_c,"$dentry";
565 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
566 if ($dentry =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
567 push @sources_misc,"$dentry";
568 @$project_settings[$T_FLAGS]|=$TF_MFC;
569 } else {
570 push @sources_cxx,"$dentry";
572 } elsif ($dentry =~ /\.rc$/i) {
573 push @sources_rc,"$dentry";
574 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
575 push @sources_misc,"$dentry";
576 if ($dentry =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
577 @$project_settings[$T_FLAGS]|=$TF_MFC;
579 } elsif ($dentry =~ /\.dsp$/i) {
580 push @dsp_files,"$dentry";
581 $has_win_project=1;
582 } elsif ($dentry =~ /\.mak$/i) {
583 push @mak_files,"$dentry";
584 $has_win_project=1;
585 } elsif ($dentry =~ /^makefile/i) {
586 $has_win_project=1;
590 closedir(DIRECTORY);
592 # If we have a single target then all we have to do is assign
593 # all the sources to it and we're done
594 # FIXME: does this play well with the --interactive mode?
595 if ($opt_single_target) {
596 my $target=@{@$project[$P_TARGETS]}[0];
597 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
598 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
599 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
600 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
601 return;
603 if ($no_target) {
604 my $parent_settings=@$parent_project[$P_SETTINGS];
605 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
606 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
607 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
608 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
609 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
610 return;
613 my $source_count=@sources_c+@sources_cxx+@sources_rc+
614 @{@$project_settings[$T_SOURCES_C]}+
615 @{@$project_settings[$T_SOURCES_CXX]}+
616 @{@$project_settings[$T_SOURCES_RC]};
617 if ($source_count == 0) {
618 # A project without real sources is not a project, get out!
619 if ($project!=$parent_project) {
620 my $parent_settings=@$parent_project[$P_SETTINGS];
621 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
622 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
624 return;
626 #print "targets=",%targets,"\n";
627 #print "target_count=$target_count\n";
628 #print "has_win_project=$has_win_project\n";
629 #print "dirname=$dirname\n";
631 my $target_count;
632 if (($has_win_project != 0) or ($dirname eq "")) {
633 # Deal with cases where we could not find any executable/library, and
634 # thus have no target, although we did find some sort of windows project.
635 $target_count=keys %targets;
636 if ($target_count == 0) {
637 # Try to come up with a target list based on .dsp/.mak files
638 my $prj_list;
639 if (@dsp_files > 0) {
640 $prj_list=\@dsp_files;
641 } else {
642 $prj_list=\@mak_files;
644 foreach my $filename (@$prj_list) {
645 $filename =~ s/\.(dsp|mak)$//i;
646 if ($opt_target_type == $TT_DLL) {
647 $filename = "$filename.dll";
649 $targets{$filename}=1;
651 $target_count=keys %targets;
652 if ($target_count == 0) {
653 # Still nothing, try the name of the directory
654 my $name;
655 if ($dirname eq "") {
656 # Bad luck, this is the top level directory!
657 $name=(split /\//, cwd)[-1];
658 } else {
659 $name=$dirname;
660 # Remove the trailing '/'. Also eliminate whatever is after the last
661 # '.' as it is likely to be meaningless (.orig, .new, ...)
662 $name =~ s+(/|\.[^.]*)$++;
663 if ($name eq "src") {
664 # 'src' is probably a subdirectory of the real project directory.
665 # Try again with the parent (if any).
666 my $parent=$path;
667 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
668 $name=$parent;
669 } else {
670 $name=(split /\//, cwd)[-1];
674 $name =~ s+(/|\.[^.]*)$++;
675 if ($opt_target_type == $TT_DLL) {
676 $name = "$name.dll";
677 } else {
678 $name = "$name.exe";
680 $targets{$name}=1;
684 # Ask confirmation to the user if he wishes so
685 if ($opt_is_interactive == $OPT_ASK_YES) {
686 my $target_list=join " ",keys %targets;
687 print "\n*** In ",($path?$path:"./"),"\n";
688 print "* winemaker found the following list of (potential) targets\n";
689 print "* $target_list\n";
690 print "* Type enter to use it as is, your own comma-separated list of\n";
691 print "* targets, 'none' to assign the source files to a parent directory,\n";
692 print "* or 'ignore' to ignore everything in this directory tree.\n";
693 print "* Target list:\n";
694 $target_list=<STDIN>;
695 chomp $target_list;
696 if ($target_list eq "") {
697 # Keep the target list as is, i.e. do nothing
698 } elsif ($target_list eq "none") {
699 # Empty the target list
700 undef %targets;
701 } elsif ($target_list eq "ignore") {
702 # Ignore this subtree altogether
703 return;
704 } else {
705 undef %targets;
706 foreach my $target (split /,/,$target_list) {
707 $target =~ s+^\s*++;
708 $target =~ s+\s*$++;
709 $targets{$target}=1;
715 # If we have no project at this level, then transfer all
716 # the sources to the parent project
717 $target_count=keys %targets;
718 if ($target_count == 0) {
719 if ($project!=$parent_project) {
720 my $parent_settings=@$parent_project[$P_SETTINGS];
721 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
722 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
723 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
724 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
725 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
727 return;
730 # Otherwise add this project to the project list, except for
731 # the main project which is already in the list.
732 if ($dirname ne "") {
733 push @projects,$project;
736 # Ask for project-wide options
737 if ($opt_ask_project_options == $OPT_ASK_YES) {
738 my $flag_desc="";
739 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
740 $flag_desc="mfc";
742 if ((@$project_settings[$T_FLAGS] & $TF_WRAP)!=0) {
743 if ($flag_desc ne "") {
744 $flag_desc.=", ";
746 $flag_desc.="wrapped";
748 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc/--wrap),\n";
749 if (defined $flag_desc) {
750 print "* (currently $flag_desc)\n";
752 print "* or 'skip' to skip the target specific options,\n";
753 print "* or 'never' to not be asked this question again:\n";
754 while (1) {
755 my $options=<STDIN>;
756 chomp $options;
757 if ($options eq "skip") {
758 $opt_ask_target_options=$OPT_ASK_SKIP;
759 last;
760 } elsif ($options eq "never") {
761 $opt_ask_project_options=$OPT_ASK_NO;
762 last;
763 } elsif (source_set_options($project_settings,$options)) {
764 last;
766 print "Please re-enter the options:\n";
770 # - Create the targets
771 # - Check if we have both libraries and programs
772 # - Match each target with source files (sort in reverse
773 # alphabetical order to get the longest matches first)
774 my @local_dlls=();
775 my @local_depends=();
776 my @exe_list=();
777 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
778 # Create the target...
779 my $target=[];
780 target_init($target);
781 @$target[$T_NAME]=$target_name;
782 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
783 if ($target_name =~ /\.dll$/) {
784 @$target[$T_TYPE]=$TT_DLL;
785 @$target[$T_INIT]=get_default_init($TT_DLL);
786 @$target[$T_FLAGS]&=~$TF_WRAP;
787 push @local_depends,"$target_name.so";
788 push @local_dlls,$target_name;
789 } else {
790 @$target[$T_TYPE]=$opt_target_type;
791 @$target[$T_INIT]=get_default_init($opt_target_type);
792 push @exe_list,$target;
794 my $basename=$target_name;
795 $basename=~ s/\.(dll|exe)$//i;
796 # This is the default link list of Visual Studio, except odbccp32
797 # which we don't have in Wine.
798 my @std_imports=qw(advapi32 comdlg32 gdi32 kernel32 odbc32 ole32 oleaut32 shell32 user32 winspool);
799 my @std_libraries=qw(uuid);
800 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
801 @$target[$T_DLLS]=\@std_imports;
802 @$target[$T_LIBRARIES]=\@std_libraries;
803 } else {
804 @$target[$T_DLLS]=[];
805 @$target[$T_LIBRARIES]=[];
807 push @{@$project[$P_TARGETS]},$target;
809 # Ask for target-specific options
810 if ($opt_ask_target_options == $OPT_ASK_YES) {
811 my $flag_desc="";
812 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
813 $flag_desc=" (mfc";
815 if ((@$target[$T_FLAGS] & $TF_WRAP)!=0) {
816 if ($flag_desc ne "") {
817 $flag_desc.=", ";
818 } else {
819 $flag_desc=" (";
821 $flag_desc.="wrapped";
823 if ($flag_desc ne "") {
824 $flag_desc.=")";
826 print "* Specify any link option (-P/-i/-L/-l/--mfc/--wrap) specific to the target\n";
827 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
828 while (1) {
829 my $options=<STDIN>;
830 chomp $options;
831 if ($options eq "never") {
832 $opt_ask_target_options=$OPT_ASK_NO;
833 last;
834 } elsif (source_set_options($target,$options)) {
835 last;
837 print "Please re-enter the options:\n";
840 push @{@$target[$T_DLL_PATH]},"-L\$(WINE_DLL_ROOT)";
841 if (@$target[$T_FLAGS] & $TF_MFC) {
842 @$project_settings[$T_FLAGS]|=$TF_MFC;
843 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
844 push @{@$target[$T_DLLS]},"mfc.dll";
845 # FIXME: Link with the MFC in the Unix sense, until we
846 # start exporting the functions properly.
847 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
848 push @{@$target[$T_LIBRARIES]},"mfc";
851 # Match sources...
852 if ($target_count == 1) {
853 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
854 @$project_settings[$T_SOURCES_C]=[];
855 @sources_c=();
857 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
858 @$project_settings[$T_SOURCES_CXX]=[];
859 @sources_cxx=();
861 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
862 @$project_settings[$T_SOURCES_RC]=[];
863 @sources_rc=();
865 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
866 # No need for sorting these sources
867 @$project_settings[$T_SOURCES_MISC]=[];
868 @sources_misc=();
869 } else {
870 foreach my $source (@sources_c) {
871 if ($source =~ /^$basename/i) {
872 push @{@$target[$T_SOURCES_C]},$source;
873 $source="";
876 foreach my $source (@sources_cxx) {
877 if ($source =~ /^$basename/i) {
878 push @{@$target[$T_SOURCES_CXX]},$source;
879 $source="";
882 foreach my $source (@sources_rc) {
883 if ($source =~ /^$basename/i) {
884 push @{@$target[$T_SOURCES_RC]},$source;
885 $source="";
888 foreach my $source (@sources_misc) {
889 if ($source =~ /^$basename/i) {
890 push @{@$target[$T_SOURCES_MISC]},$source;
891 $source="";
895 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
896 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
897 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
898 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
900 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
901 $opt_ask_target_options=$OPT_ASK_YES;
904 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
905 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
907 # The sources that did not match, if any, go to the extra
908 # source list of the project settings
909 foreach my $source (@sources_c) {
910 if ($source ne "") {
911 push @{@$project_settings[$T_SOURCES_C]},$source;
914 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
915 foreach my $source (@sources_cxx) {
916 if ($source ne "") {
917 push @{@$project_settings[$T_SOURCES_CXX]},$source;
920 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
921 foreach my $source (@sources_rc) {
922 if ($source ne "") {
923 push @{@$project_settings[$T_SOURCES_RC]},$source;
926 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
927 foreach my $source (@sources_misc) {
928 if ($source ne "") {
929 push @{@$project_settings[$T_SOURCES_MISC]},$source;
932 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
934 # Finally if we are building both libraries and programs in
935 # this directory, then the programs should be linked with all
936 # the libraries
937 if (@local_dlls > 0 and @exe_list > 0) {
938 foreach my $target (@exe_list) {
939 push @{@$target[$T_DLL_PATH]},"-L.";
940 push @{@$target[$T_DLLS]},@local_dlls;
941 push @{@$target[$T_DEPENDS]},@local_depends;
947 # Scan the source directories in search of things to build
948 sub source_scan()
950 # If there's a single target then this is going to be the default target
951 if (defined $opt_single_target) {
952 # Create the main target
953 my $main_target=[];
954 target_init($main_target);
955 @$main_target[$T_NAME]=$opt_single_target;
956 @$main_target[$T_TYPE]=$opt_target_type;
958 # Add it to the list
959 push @{$main_project[$P_TARGETS]},$main_target;
962 # The main directory is always going to be there
963 push @projects,\@main_project;
965 # Now scan the directory tree looking for source files and, maybe, targets
966 print "Scanning the source directories...\n";
967 source_scan_directory(\@main_project,"","",0);
969 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
974 #####
976 # 'vc.dsp'-based Project analysis
978 #####
980 #sub analyze_vc_dsp
987 #####
989 # Creating the wrapper targets
991 #####
993 sub postprocess_targets()
995 foreach my $project (@projects) {
996 foreach my $target (@{@$project[$P_TARGETS]}) {
997 if ((@$target[$T_FLAGS] & $TF_WRAP) != 0) {
998 my $wrapper=[];
999 target_init($wrapper);
1000 @$wrapper[$T_NAME]=@$target[$T_NAME];
1001 @$wrapper[$T_TYPE]=@$target[$T_TYPE];
1002 @$wrapper[$T_INIT]=get_default_init(@$target[$T_TYPE]);
1003 @$wrapper[$T_FLAGS]=$TF_WRAPPER | (@$target[$T_FLAGS] & $TF_MFC);
1004 @$wrapper[$T_DLLS]=[ "kernel32", "user32" ];
1005 push @{@$wrapper[$T_LIBRARIES]}, "dl";
1006 push @{@$wrapper[$T_SOURCES_C]},"@$wrapper[$T_NAME]_wrapper.c";
1008 my $index=bsearch(@$target[$T_SOURCES_C],"@$wrapper[$T_NAME]_wrapper.c");
1009 if (defined $index) {
1010 splice(@{@$target[$T_SOURCES_C]},$index,1);
1012 @$target[$T_NAME]=@$target[$T_NAME];
1013 @$target[$T_NAME]=~ s/.exe$/.dll/;
1014 @$target[$T_TYPE]=$TT_DLL;
1016 push @{@$project[$P_TARGETS]},$wrapper;
1018 if ((@$target[$T_FLAGS] & $TF_MFC) != 0) {
1019 @{@$project[$P_SETTINGS]}[$T_FLAGS]|=$TF_MFC;
1020 $needs_mfc=1;
1028 #####
1030 # Source search
1032 #####
1035 # Performs a directory traversal and renames the files so that:
1036 # - they have the case desired by the user
1037 # - their extension is of the appropriate case
1038 # - they don't contain annoying characters like ' ', '$', '#', ...
1039 sub fix_file_and_directory_names($);
1040 sub fix_file_and_directory_names($)
1042 my $dirname=$_[0];
1044 if (opendir(DIRECTORY, "$dirname")) {
1045 foreach my $dentry (readdir DIRECTORY) {
1046 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1047 next;
1049 # Set $warn to 1 if the user should be warned of the renaming
1050 my $warn=0;
1052 # autoconf and make don't support these characters well
1053 my $new_name=$dentry;
1054 $new_name =~ s/[ \$]/_/g;
1056 # Only all lowercase extensions are supported (because of the
1057 # transformations ':.c=.o') .
1058 if (-f "$dirname/$new_name") {
1059 if ($new_name =~ /\.C$/) {
1060 $new_name =~ s/\.C$/.c/;
1062 if ($new_name =~ /\.cpp$/i) {
1063 $new_name =~ s/\.cpp$/.cpp/i;
1065 if ($new_name =~ s/\.cxx$/.cpp/i) {
1066 $warn=1;
1068 if ($new_name =~ /\.rc$/i) {
1069 $new_name =~ s/\.rc$/.rc/i;
1071 # And this last one is to avoid confusion then running make
1072 if ($new_name =~ s/^makefile$/makefile.win/) {
1073 $warn=1;
1077 # Adjust the case to the user's preferences
1078 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1079 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1081 $new_name=lc $new_name;
1084 # And finally, perform the renaming
1085 if ($new_name ne $dentry) {
1086 if ($warn) {
1087 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1089 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1090 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1091 print STDERR " $!\n";
1092 $new_name=$dentry;
1095 if (-d "$dirname/$new_name") {
1096 fix_file_and_directory_names("$dirname/$new_name");
1099 closedir(DIRECTORY);
1105 #####
1107 # Source fixup
1109 #####
1112 # This maps a directory name to a reference to an array listing
1113 # its contents (files and directories)
1114 my %directories;
1117 # Retrieves the contents of the specified directory.
1118 # We either get it from the directories hashtable which acts as a
1119 # cache, or use opendir, readdir, closedir and store the result
1120 # in the hashtable.
1121 sub get_directory_contents($)
1123 my $dirname=$_[0];
1124 my $directory;
1126 #print "getting the contents of $dirname\n";
1128 # check for a cached version
1129 $dirname =~ s+/$++;
1130 if ($dirname eq "") {
1131 $dirname=cwd;
1133 $directory=$directories{$dirname};
1134 if (defined $directory) {
1135 #print "->@$directory\n";
1136 return $directory;
1139 # Read this directory
1140 if (opendir(DIRECTORY, "$dirname")) {
1141 my @files=readdir DIRECTORY;
1142 closedir(DIRECTORY);
1143 $directory=\@files;
1144 } else {
1145 # Return an empty list
1146 #print "error: cannot open $dirname\n";
1147 my @files;
1148 $directory=\@files;
1150 #print "->@$directory\n";
1151 $directories{$dirname}=$directory;
1152 return $directory;
1156 # Try to find a file for the specified filename. The attempt is
1157 # case-insensitive which is why it's not trivial. If a match is
1158 # found then we return the pathname with the correct case.
1159 sub search_from($$)
1161 my $dirname=$_[0];
1162 my $path=$_[1];
1163 my $real_path="";
1165 if ($dirname eq "" or $dirname eq ".") {
1166 $dirname=cwd;
1167 } elsif ($dirname =~ m+^[^/]+) {
1168 $dirname=cwd . "/" . $dirname;
1170 if ($dirname !~ m+/$+) {
1171 $dirname.="/";
1174 foreach my $component (@$path) {
1175 #print " looking for $component in \"$dirname\"\n";
1176 if ($component eq ".") {
1177 # Pass it as is
1178 $real_path.="./";
1179 } elsif ($component eq "..") {
1180 # Go up one level
1181 $dirname=dirname($dirname) . "/";
1182 $real_path.="../";
1183 } else {
1184 # The file/directory may have been renamed before. Also try to
1185 # match the renamed file.
1186 my $renamed=$component;
1187 $renamed =~ s/[ \$]/_/g;
1188 if ($renamed eq $component) {
1189 undef $renamed;
1192 my $directory=get_directory_contents $dirname;
1193 my $found;
1194 foreach my $dentry (@$directory) {
1195 if ($dentry =~ /^$component$/i or
1196 (defined $renamed and $dentry =~ /^$renamed$/i)
1198 $dirname.="$dentry/";
1199 $real_path.="$dentry/";
1200 $found=1;
1201 last;
1204 if (!defined $found) {
1205 # Give up
1206 #print " could not find $component in $dirname\n";
1207 return;
1211 $real_path=~ s+/$++;
1212 #print " -> found $real_path\n";
1213 return $real_path;
1217 # Performs a case-insensitive search for the specified file in the
1218 # include path.
1219 # $line is the line number that should be referenced when an error occurs
1220 # $filename is the file we are looking for
1221 # $dirname is the directory of the file containing the '#include' directive
1222 # if '"' was used, it is an empty string otherwise
1223 # $project and $target specify part of the include path
1224 sub get_real_include_name($$$$$)
1226 my $line=$_[0];
1227 my $filename=$_[1];
1228 my $dirname=$_[2];
1229 my $project=$_[3];
1230 my $target=$_[4];
1232 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1233 # This is not a relative path, we cannot make any check
1234 my $warning="path:$filename";
1235 if (!defined $warnings{$warning}) {
1236 $warnings{$warning}="1";
1237 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1238 print STDERR "$line: $filename\n";
1240 } else {
1241 # Here's how we proceed:
1242 # - split the filename we look for into its components
1243 # - then for each directory in the include path
1244 # - trace the directory components starting from that directory
1245 # - if we fail to find a match at any point then continue with
1246 # the next directory in the include path
1247 # - otherwise, rejoice, our quest is over.
1248 my @file_components=split /[\/\\]+/, $filename;
1249 #print " Searching for $filename from @$project[$P_PATH]\n";
1251 my $real_filename;
1252 if ($dirname ne "") {
1253 # This is an 'include ""' -> look in dirname first.
1254 #print " in $dirname (include \"\")\n";
1255 $real_filename=search_from($dirname,\@file_components);
1256 if (defined $real_filename) {
1257 return $real_filename;
1260 my $project_settings=@$project[$P_SETTINGS];
1261 foreach my $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1262 my $dirname=$include;
1263 $dirname=~ s+^-I++;
1264 if (!is_absolute($dirname)) {
1265 $dirname="@$project[$P_PATH]$dirname";
1266 } else {
1267 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1268 $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
1270 #print " in $dirname\n";
1271 $real_filename=search_from("$dirname",\@file_components);
1272 if (defined $real_filename) {
1273 return $real_filename;
1276 my $dotdotpath=@$project[$P_PATH];
1277 $dotdotpath =~ s/[^\/]+/../g;
1278 foreach my $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1279 my $dirname=$include;
1280 $dirname=~ s+^-I++;
1281 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1282 $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
1283 #print " in $dirname (global setting)\n";
1284 $real_filename=search_from("$dirname",\@file_components);
1285 if (defined $real_filename) {
1286 return $real_filename;
1290 $filename =~ s+\\\\+/+g; # in include ""
1291 $filename =~ s+\\+/+g; # in include <> !
1292 if ($opt_lower_include) {
1293 return lc "$filename";
1295 return $filename;
1298 sub print_pack($$$)
1300 my $indent=$_[0];
1301 my $size=$_[1];
1302 my $trailer=$_[2];
1304 if ($size =~ /^(1|2|4|8)$/) {
1305 print FILEO "$indent#include <pshpack$size.h>$trailer";
1306 } else {
1307 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1308 print FILEO "$indent#include <pshpack4.h>$trailer";
1313 # 'Parses' a source file and fixes constructs that would not work with
1314 # Winelib. The parsing is rather simple and not all non-portable features
1315 # are corrected. The most important feature that is corrected is the case
1316 # and path separator of '#include' directives. This requires that each
1317 # source file be associated to a project & target so that the proper
1318 # include path is used.
1319 # Also note that the include path is relative to the directory in which the
1320 # compiler is run, i.e. that of the project, not to that of the file.
1321 sub fix_file($$$)
1323 my $filename=$_[0];
1324 my $project=$_[1];
1325 my $target=$_[2];
1326 $filename="@$project[$P_PATH]$filename";
1327 if (! -e $filename) {
1328 return;
1331 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1332 my $dirname=dirname($filename);
1333 my $is_mfc=0;
1334 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1335 $is_mfc=1;
1338 print " $filename\n";
1339 #FIXME:assuming that because there is a .bak file, this is what we want is
1340 #probably flawed. Or is it???
1341 if (! -e "$filename.bak") {
1342 if (!copy("$filename","$filename.bak")) {
1343 print STDERR "error: unable to make a backup of $filename:\n";
1344 print STDERR " $!\n";
1345 return;
1348 if (!open(FILEI,"$filename.bak")) {
1349 print STDERR "error: unable to open $filename.bak for reading:\n";
1350 print STDERR " $!\n";
1351 return;
1353 if (!open(FILEO,">$filename")) {
1354 print STDERR "error: unable to open $filename for writing:\n";
1355 print STDERR " $!\n";
1356 return;
1358 my $line=0;
1359 my $modified=0;
1360 my $rc_block_depth=0;
1361 my $rc_textinclude_state=0;
1362 my @pack_stack;
1363 while (<FILEI>) {
1364 # Remove any trailing CtrlZ, which isn't strictly in the file
1365 if (/\x1A/) {
1366 s/\x1A//;
1367 last if (/^$/)
1369 $line++;
1370 s/\r\n$/\n/;
1371 if (!/\n$/) {
1372 # Make sure all files are '\n' terminated
1373 $_ .= "\n";
1375 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
1376 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1377 # the RC files it generates (even in non-MFC projects). So we replace
1378 # it with 'winres.h' its very close standard cousin so that non MFC
1379 # projects can compile in Wine without the MFC sources.
1380 my $warning="mfc:afxres.h";
1381 if (!defined $warnings{$warning}) {
1382 $warnings{$warning}="1";
1383 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winres.h'\n";
1384 print STDERR "warning: the above warning is issued only once\n";
1386 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
1387 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winres.h' */\n";
1388 print FILEO "$1$2\"winres.h\"$'";
1389 $modified=1;
1391 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1392 my $from_file=($2 eq "<"?"":$dirname);
1393 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1394 print FILEO "$1$2$real_include_name$4$'";
1395 $modified|=($real_include_name ne $3);
1397 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
1398 # Pragma pack handling
1400 # pack_stack is an array of references describing the stack of
1401 # pack directives currently in effect. Each directive if described
1402 # by a reference to an array containing:
1403 # - "push" for pack(push,...) directives, "" otherwise
1404 # - the directive's identifier at index 1
1405 # - the directive's alignement value at index 2
1407 # Don't believe a word of what the documentation says: it's all wrong.
1408 # The code below is based on the actual behavior of Visual C/C++ 6.
1409 my $pack_indent=$1;
1410 my $pack_header=$2;
1411 if (/^(\))/) {
1412 # pragma pack()
1413 # Pushes the default stack alignment
1414 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1415 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1416 print_pack($pack_indent,4,$');
1417 push @pack_stack, [ "", "", 4 ];
1419 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
1420 # pragma pack(pop)
1421 # pragma pack(pop,n)
1422 # Goes up the stack until it finds a pack(push,...), and pops it
1423 # Ignores any pack(n) entry
1424 # Issues a warning if the pack is of the form pack(push,label)
1425 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1426 my $pack_comment=$';
1427 $pack_comment =~ s/^\s*//;
1428 if ($pack_comment ne "") {
1429 print FILEO "$pack_indent$pack_comment";
1431 while (1) {
1432 my $alignment=pop @pack_stack;
1433 if (!defined $alignment) {
1434 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
1435 last;
1437 if (@$alignment[1]) {
1438 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
1440 print FILEO "$pack_indent#include <poppack.h>\n";
1441 if (@$alignment[0]) {
1442 last;
1446 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
1447 # pragma pack(pop,label[,n])
1448 # Goes up the stack until finding a pack(push,...) and pops it.
1449 # 'n', if specified, is ignored.
1450 # Ignores any pack(n) entry
1451 # Issues a warning if the label of the pack does not match,
1452 # or if it is in fact a pack(push,n)
1453 my $label=$2;
1454 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1455 my $pack_comment=$';
1456 $pack_comment =~ s/^\s*//;
1457 if ($pack_comment ne "") {
1458 print FILEO "$pack_indent$pack_comment";
1460 while (1) {
1461 my $alignment=pop @pack_stack;
1462 if (!defined $alignment) {
1463 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
1464 last;
1466 if (@$alignment[1] and @$alignment[1] ne $label) {
1467 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
1469 print FILEO "$pack_indent#include <poppack.h>\n";
1470 if (@$alignment[0]) {
1471 last;
1475 } elsif (/^(push\s*\))/) {
1476 # pragma pack(push)
1477 # Push the current alignment
1478 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1479 if (@pack_stack > 0) {
1480 my $alignment=$pack_stack[$#pack_stack];
1481 print_pack($pack_indent,@$alignment[2],$');
1482 push @pack_stack, [ "push", "", @$alignment[2] ];
1483 } else {
1484 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1485 print_pack($pack_indent,4,$');
1486 push @pack_stack, [ "push", "", 4 ];
1489 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
1490 # pragma pack([push,]n)
1491 # Push new alignment n
1492 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1493 print_pack($pack_indent,$3,"$'");
1494 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
1496 } elsif (/^((\w+)\s*\))/) {
1497 # pragma pack(label)
1498 # label must in fact be a macro that resolves to an integer
1499 # Then behaves like 'pragma pack(n)'
1500 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1501 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
1502 print_pack($pack_indent,4,$');
1503 push @pack_stack, [ "", "", 4 ];
1505 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
1506 # pragma pack(push,label[,n])
1507 # Pushes a new label on the stack. It is possible to push the same
1508 # label multiple times. If 'n' is omitted then the alignment is
1509 # unchanged. Otherwise it becomes 'n'.
1510 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1511 my $size;
1512 if (defined $4) {
1513 $size=$4;
1514 } elsif (@pack_stack > 0) {
1515 my $alignment=$pack_stack[$#pack_stack];
1516 $size=@$alignment[2];
1517 } else {
1518 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1519 $size=4;
1521 print_pack($pack_indent,$size,$');
1522 push @pack_stack, [ "push", $2, $size ];
1524 } else {
1525 # pragma pack(??? -> What's that?
1526 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
1527 print FILEO "$pack_indent$pack_header$_";
1530 $modified=1;
1532 } elsif ($is_rc) {
1533 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]+)([\">]?)/) {
1534 my $from_file=($5 eq "<"?"":$dirname);
1535 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
1536 print FILEO "$1$5$real_include_name$7$'";
1537 $modified|=($real_include_name ne $6);
1539 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1540 my $from_file=($2 eq "<"?"":$dirname);
1541 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1542 print FILEO "$1$2$real_include_name$4$'";
1543 $modified|=($real_include_name ne $3);
1545 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
1546 $rc_textinclude_state=1;
1547 print FILEO;
1549 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
1550 print FILEO "$1winres.h$2$'";
1551 $modified=1;
1553 } elsif (/^\s*BEGIN(\W.*)?$/) {
1554 $rc_textinclude_state|=2;
1555 $rc_block_depth++;
1556 print FILEO;
1558 } elsif (/^\s*END(\W.*)?$/) {
1559 $rc_textinclude_state=0;
1560 if ($rc_block_depth>0) {
1561 $rc_block_depth--;
1563 print FILEO;
1565 } else {
1566 print FILEO;
1569 } else {
1570 print FILEO;
1574 close(FILEI);
1575 close(FILEO);
1576 if ($opt_backup == 0 or $modified == 0) {
1577 if (!unlink("$filename.bak")) {
1578 print STDERR "error: unable to delete $filename.bak:\n";
1579 print STDERR " $!\n";
1585 # Analyzes each source file in turn to find and correct issues
1586 # that would cause it not to compile.
1587 sub fix_source()
1589 print "Fixing the source files...\n";
1590 foreach my $project (@projects) {
1591 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
1592 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1593 next;
1595 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
1596 fix_file($source,$project,$target);
1604 #####
1606 # File generation
1608 #####
1611 # Generates a target's .spec file
1612 sub generate_spec_file($$$)
1614 return if ($opt_no_generated_specs);
1616 my $path=$_[0];
1617 my $target=$_[1];
1618 my $project_settings=$_[2];
1620 my $basename=@$target[$T_NAME];
1621 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1622 $basename.="_wrapper";
1625 if (!open(FILEO,">$path$basename.spec")) {
1626 print STDERR "error: could not open \"$path$basename.spec\" for writing\n";
1627 print STDERR " $!\n";
1628 return;
1631 # Don't forget to export the 'Main' function for wrapped executables,
1632 # except for MFC ones!
1633 if ((@$target[$T_FLAGS]&($TF_WRAP|$TF_WRAPPER|$TF_MFC)) == $TF_WRAP) {
1634 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1635 print FILEO "\n@ stdcall @$target[$T_INIT](long long ptr long) @$target[$T_INIT]\n";
1636 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1637 print FILEO "\n@ stdcall @$target[$T_INIT](long ptr ptr) @$target[$T_INIT]\n";
1638 } else {
1639 print FILEO "\n@ stdcall @$target[$T_INIT](ptr long ptr) @$target[$T_INIT]\n";
1643 close(FILEO);
1647 # Generates a target's wrapper file
1648 sub generate_wrapper_file($$)
1650 my $path=$_[0];
1651 my $target=$_[1];
1652 my $app_name=@$target[$T_NAME];
1653 my $wrapper_name=$app_name;
1654 $app_name=~ s/\.exe$/\.dll/;
1656 return generate_from_template("$path${wrapper_name}_wrapper.c","wrapper.c",[
1657 ["APP_NAME",$app_name],
1658 ["APP_TYPE",(@$target[$T_TYPE]==$TT_GUIEXE?"GUIEXE":"CUIEXE")],
1659 ["APP_INIT",(@$target[$T_TYPE]==$TT_GUIEXE?"\"WinMain\"":"\"main\"")],
1660 ["APP_MFC",(@$target[$T_FLAGS] & $TF_MFC?"\"mfc\"":"NULL")]]);
1664 # A convenience function to generate all the lists (defines,
1665 # C sources, C++ source, etc.) in the Makefile
1666 sub generate_list($$$;$)
1668 my $name=$_[0];
1669 my $last=$_[1];
1670 my $list=$_[2];
1671 my $data=$_[3];
1672 my $first=$name;
1674 if ($name) {
1675 printf FILEO "%-22s=",$name;
1677 if (defined $list) {
1678 foreach my $item (@$list) {
1679 my $value;
1680 if (defined $data) {
1681 $value=&$data($item);
1682 } else {
1683 $value=$item;
1685 if ($value ne "") {
1686 if ($first) {
1687 print FILEO " $value";
1688 $first=0;
1689 } else {
1690 print FILEO " \\\n\t\t\t$value";
1695 if ($last) {
1696 print FILEO "\n";
1701 # Generates a project's Makefile.in and all the target files
1702 sub generate_project_files($)
1704 my $project=$_[0];
1705 my $project_settings=@$project[$P_SETTINGS];
1706 my @dll_list=();
1707 my @exe_list=();
1709 # Then sort the targets and separate the libraries from the programs
1710 foreach my $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
1711 if (@$target[$T_TYPE] == $TT_DLL) {
1712 push @dll_list,$target;
1713 } else {
1714 push @exe_list,$target;
1717 @$project[$P_TARGETS]=[];
1718 push @{@$project[$P_TARGETS]}, @dll_list;
1719 push @{@$project[$P_TARGETS]}, @exe_list;
1721 if (!open(FILEO,">@$project[$P_PATH]Makefile.in")) {
1722 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile.in\" for writing\n";
1723 print STDERR " $!\n";
1724 return;
1727 print FILEO "### Generated by Winemaker\n";
1728 print FILEO "\n\n";
1730 print FILEO "### Generic autoconf variables\n\n";
1731 generate_list("TOPSRCDIR",1,[ "\@top_srcdir\@" ]);
1732 my $dotdotpath=@$project[$P_PATH];
1733 $dotdotpath =~ s%[^/]+%..%g;
1734 $dotdotpath =~ s%/$%%;
1735 $dotdotpath = "." if ($dotdotpath eq "");
1736 generate_list("TOPOBJDIR",1,[ $dotdotpath ]);
1737 generate_list("SRCDIR",1,[ "\@srcdir\@" ]);
1738 generate_list("VPATH",1,[ "\@srcdir\@" ]);
1739 print FILEO "\n";
1740 if (@$project[$P_PATH] eq "") {
1741 # This is the main project. It is also responsible for recursively
1742 # calling the other projects
1743 generate_list("SUBDIRS",1,\@projects,sub
1745 if ($_[0] != \@main_project) {
1746 my $subdir=@{$_[0]}[$P_PATH];
1747 $subdir =~ s+/$++;
1748 return $subdir;
1750 # Eliminating the main project by returning undefined!
1753 if (@{@$project[$P_TARGETS]} > 0) {
1754 generate_list("DLLS",1,\@dll_list,sub
1756 return @{$_[0]}[$T_NAME];
1758 generate_list("EXES",1,\@exe_list,sub
1760 return "@{$_[0]}[$T_NAME]";
1762 print FILEO "\n\n\n";
1764 print FILEO "### Common settings\n\n";
1765 # Make it so that the project-wide settings override the global settings
1766 generate_list("DEFINES",1,@$project_settings[$T_DEFINES]);
1767 generate_list("INCLUDE_PATH",1,@$project_settings[$T_INCLUDE_PATH]);
1768 generate_list("DLL_PATH",1,@$project_settings[$T_DLL_PATH]);
1769 generate_list("LIBRARY_PATH",1,@$project_settings[$T_LIBRARY_PATH]);
1770 generate_list("LIBRARIES",1,@$project_settings[$T_LIBRARIES]);
1771 print FILEO "\n\n";
1773 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
1774 @{@$project_settings[$T_SOURCES_CXX]}+
1775 @{@$project_settings[$T_SOURCES_RC]};
1776 my $no_extra=($extra_source_count == 0);
1777 if (!$no_extra) {
1778 print FILEO "### Extra source lists\n\n";
1779 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
1780 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
1781 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
1782 print FILEO "\n";
1783 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
1784 print FILEO "\n\n\n";
1787 # Iterate over all the targets...
1788 foreach my $target (@{@$project[$P_TARGETS]}) {
1789 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
1790 my $appmode;
1791 my $basemodule=@$target[$T_NAME];
1792 my $canon=canonize("@$target[$T_NAME]");
1793 $canon =~ s+_so$++;
1794 if (@$target[$T_TYPE] == $TT_CUIEXE) {
1795 $appmode = "cui";
1796 $basemodule =~ s/\.exe$//;
1797 } elsif (@$target[$T_TYPE] == $TT_GUIEXE) {
1798 $appmode = "gui";
1799 $basemodule =~ s/\.exe$//;
1800 } else {
1801 $appmode = "";
1802 $basemodule =~ s/\.dll$//;
1805 generate_list("${canon}_MODULE",1,[@$target[$T_NAME]]);
1806 generate_list("${canon}_BASEMODULE",1,[$basemodule]);
1807 generate_list("${canon}_APPMODE",1,[$appmode]);
1808 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
1809 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
1810 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
1811 generate_list("${canon}_SPEC_SRCS",1,[ (@$target[$T_TYPE] == $TT_DLL?"@$target[$T_NAME].spec":"") ]);
1812 generate_list("${canon}_DLL_PATH",1,@$target[$T_DLL_PATH]);
1813 generate_list("${canon}_DLLS",1,@$target[$T_DLLS]);
1814 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]);
1815 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]);
1816 generate_list("${canon}_DEPENDS",1,@$target[$T_DEPENDS]);
1817 print FILEO "\n";
1818 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(EXTRA_OBJS)"]);
1819 print FILEO "\n\n\n";
1821 print FILEO "### Global source lists\n\n";
1822 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
1824 my $canon=canonize(@{$_[0]}[$T_NAME]);
1825 $canon =~ s+_so$++;
1826 return "\$(${canon}_C_SRCS)";
1828 if (!$no_extra) {
1829 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
1831 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
1833 my $canon=canonize(@{$_[0]}[$T_NAME]);
1834 $canon =~ s+_so$++;
1835 return "\$(${canon}_CXX_SRCS)";
1837 if (!$no_extra) {
1838 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
1840 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
1842 my $canon=canonize(@{$_[0]}[$T_NAME]);
1843 $canon =~ s+_so$++;
1844 return "\$(${canon}_RC_SRCS)";
1846 if (!$no_extra) {
1847 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
1849 generate_list("SPEC_SRCS",1,@$project[$P_TARGETS],sub
1851 my $canon=canonize(@{$_[0]}[$T_NAME]);
1852 $canon =~ s+_so$++;
1853 return "\$(${canon}_SPEC_SRCS)";
1856 print FILEO "\n\n\n";
1858 print FILEO "### Generic autoconf targets\n\n";
1859 print FILEO "all:";
1860 if (@$project[$P_PATH] eq "") {
1861 print FILEO " wineapploader";
1862 print FILEO " \$(SUBDIRS)";
1864 if (@{@$project[$P_TARGETS]} > 0) {
1865 print FILEO " \$(DLLS:%=%.so) \$(EXES:%=%.so)";
1867 print FILEO "\n\n";
1868 if (@$project[$P_PATH] eq "") {
1869 print FILEO "wineapploader: wineapploader.in\n";
1870 print FILEO "\tsed -e 's,\@bindir\\\@,\$(bindir),g' " .
1871 "-e 's,\@winelibdir\\\@,.,g' " .
1872 "\$(SRCDIR)/wineapploader.in >\$\@ || \$(RM) \$\@\n";
1873 print FILEO "\n";
1875 print FILEO "\@MAKE_RULES\@\n";
1876 print FILEO "\n";
1877 print FILEO "install::\n";
1878 if (@$project[$P_PATH] eq "") {
1879 # This is the main project. It is also responsible for recursively
1880 # calling the other projects
1881 print FILEO "\t_list=\"\$(SUBDIRS)\"; for i in \$\$_list; do (cd \$\$i; \$(MAKE) install) || exit 1; done\n";
1883 if (@{@$project[$P_TARGETS]} > 0) {
1884 print FILEO "\t_list=\"\$(EXES:%.exe=%)\"; for i in \$\$_list; do \$(INSTALL_SCRIPT) \$\$i \$(bindir); done\n";
1885 print FILEO "\t_list=\"\$(EXES:%=%.so) \$(DLLS:%=%.so)\"; for i in \$\$_list; do \$(INSTALL_PROGRAM) \$\$i \$(dlldir); done\n";
1887 print FILEO "\n";
1888 print FILEO "uninstall::\n";
1889 if (@$project[$P_PATH] eq "") {
1890 # This is the main project. It is also responsible for recursively
1891 # calling the other projects
1892 print FILEO "\t_list=\"\$(SUBDIRS)\"; for i in \$\$_list; do (cd \$\$i; \$(MAKE) uninstall) || exit 1; done\n";
1894 if (@{@$project[$P_TARGETS]} > 0) {
1895 print FILEO "\t_list=\"\$(EXES:%.exe=%)\"; for i in \$\$_list; do \$(RM) \$(bindir)/\$\$i;done\n";
1896 print FILEO "\t_list=\"\$(EXES:%=%.so) \$(DLLS:%=%.so)\"; for i in \$\$_list; do \$(RM) \$(dlldir)/\$\$i;done\n";
1898 print FILEO "\n";
1899 if (@$project[$P_PATH] eq "") {
1900 print FILEO "clean::\n";
1901 print FILEO "\t\$(RM) wineapploader\n";
1902 print FILEO "\n";
1903 print FILEO "distclean: clean\n";
1904 print FILEO "\t\$(RM) config.* configure.lineno Make.rules\n";
1905 print FILEO "\t\$(RM) -r autom4te.cache\n";
1906 print FILEO "\tfind . -name Makefile -exec \$(RM) {} \\;\n";
1907 print FILEO "\n";
1910 if (@{@$project[$P_TARGETS]} > 0) {
1911 print FILEO "### Target specific build rules\n\n";
1912 foreach my $target (@{@$project[$P_TARGETS]}) {
1913 my $canon=canonize("@$target[$T_NAME]");
1914 my $mode;
1915 my $all_dlls;
1916 my $all_libs;
1918 $canon =~ s/_so$//;
1919 if ((@$target[$T_TYPE]==$TT_GUIEXE) || (@$target[$T_TYPE]==$TT_CUIEXE)) {
1920 $mode = "--exe \$(${canon}_MODULE) -m\$(${canon}_APPMODE)";
1921 } else {
1922 $mode = "";
1925 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1926 $all_dlls="\$(${canon}_DLLS:%=-l%)";
1927 $all_libs="\$(${canon}_LIBRARIES:%=-l%) \$(WINE_LIBRARIES)";
1928 } else {
1929 $all_dlls="\$(${canon}_DLLS:%=-l%) \$(GLOBAL_DLLS:%=-l%)";
1930 $all_libs="\$(${canon}_LIBRARIES:%=-l%) \$(ALL_LIBRARIES)";
1933 print FILEO "\$(${canon}_MODULE).dbg.c: \$(${canon}_C_SRCS) \$(${canon}_CXX_SRCS)\n";
1934 print FILEO "\t\$(LDPATH) \$(WINEBUILD) -o \$\@ --debug -C\$(SRCDIR) \$(${canon}_C_SRCS) \$(${canon}_CXX_SRCS)\n";
1935 print FILEO "\n";
1936 print FILEO "\$(${canon}_MODULE).spec.c: \$(${canon}_SPEC_SRCS) \$(${canon}_RC_SRCS:.rc=.res) \$(${canon}_OBJS)\n";
1937 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";
1938 print FILEO "\n";
1939 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_MODULE).dbg.o \$(${canon}_MODULE).spec.o \$(${canon}_OBJS) \$(${canon}_DEPENDS)\n";
1940 if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
1941 print FILEO "\t\$(LDXXSHARED)";
1942 } else {
1943 print FILEO "\t\$(LDSHARED)";
1945 print FILEO " \$(LDDLLFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_MODULE).dbg.o \$(${canon}_MODULE).spec.o \$(${canon}_LIBRARY_PATH) \$(ALL_LIBRARY_PATH) $all_libs \$(LIBS)\n";
1946 if (@$target[$T_TYPE] != $TT_DLL) {
1947 print FILEO "\ttest -f \$(${canon}_BASEMODULE) || \$(INSTALL_SCRIPT) \$(TOPOBJDIR)/wineapploader \$(${canon}_BASEMODULE)\n";
1949 print FILEO "\n\n";
1952 close(FILEO);
1954 foreach my $target (@{@$project[$P_TARGETS]}) {
1955 if (@$target[$T_TYPE] == $TT_DLL) {
1956 generate_spec_file(@$project[$P_PATH],$target,$project_settings);
1958 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1959 generate_wrapper_file(@$project[$P_PATH],$target);
1965 # Perform the replacements in the template configure files
1966 # Return 1 for success, 0 for failure
1967 sub generate_from_template($$;$)
1969 my $filename=$_[0];
1970 my $template=$_[1];
1971 my $substitutions=$_[2];
1973 if (!defined $templates{$template}) {
1974 print STDERR "winemaker: internal error: No template called '$template'\n";
1975 return 0;
1978 if (!open(FILEO,">$filename")) {
1979 print STDERR "error: unable to open \"$filename\" for writing:\n";
1980 print STDERR " $!\n";
1981 return 0;
1983 my $warned;
1984 foreach my $line (@{$templates{$template}}) {
1985 if ($line =~ /(\#\#WINEMAKER_[A-Z_]+\#\#)/) {
1986 if (defined $substitutions) {
1987 foreach my $pattern (@$substitutions) {
1988 $line =~ s%\#\#WINEMAKER_@$pattern[0]\#\#%@$pattern[1]%;
1991 if (!$warned and $line =~ /(\#\#WINEMAKER_[A-Z_]+\#\#)/) {
1992 print STDERR "warning: no value was provided for template $1 in \"$filename\"\n";
1993 $warned=1;
1996 print FILEO $line;
1998 close(FILEO);
1999 return 1;
2003 # Generates the global files:
2004 # configure
2005 # configure.ac
2006 # Make.rules.in
2007 # wineapploader.in
2008 sub generate_global_files()
2010 my @include_path;
2011 foreach my $path (@{$global_settings[$T_INCLUDE_PATH]}) {
2012 if ($path !~ /^-L/ or is_absolute($')) {
2013 push @include_path, $path;
2014 } else {
2015 push @include_path, "-L\$(TOPSRCDIR)/$'";
2018 my @dll_path;
2019 foreach my $path (@{$global_settings[$T_DLL_PATH]}) {
2020 if ($path !~ /^-L/ or is_absolute($')) {
2021 push @dll_path, $path;
2022 } else {
2023 push @dll_path, "-L\$(TOPSRCDIR)/$'";
2026 my @library_path;
2027 foreach my $path (@{$global_settings[$T_LIBRARY_PATH]}) {
2028 if ($path !~ /^-L/ or is_absolute($')) {
2029 push @library_path, $path;
2030 } else {
2031 push @library_path, "-L\$(TOPSRCDIR)/$'";
2034 generate_from_template("Make.rules.in","Make.rules.in",[
2035 ["DEFINES", join(" ", @{$global_settings[$T_DEFINES]}) ],
2036 ["INCLUDE_PATH", join(" ", @include_path) ],
2037 ["DLL_PATH", join(" ", @dll_path) ],
2038 ["DLLS", join(" ", @{$global_settings[$T_DLLS]}) ],
2039 ["LIBRARY_PATH", join(" ", @library_path) ],
2040 ["LIBRARIES", join(" ", @{$global_settings[$T_LIBRARIES]}) ]]);
2041 generate_from_template("wineapploader.in","wineapploader.in");
2043 # Get the name of a source file for configure.ac
2044 my $a_source_file;
2045 search_a_file: foreach my $project (@projects) {
2046 foreach my $target (@{@$project[$P_TARGETS]}, @$project[$P_SETTINGS]) {
2047 $a_source_file=@{@$target[$T_SOURCES_C]}[0];
2048 if (!defined $a_source_file) {
2049 $a_source_file=@{@$target[$T_SOURCES_CXX]}[0];
2051 if (!defined $a_source_file) {
2052 $a_source_file=@{@$target[$T_SOURCES_RC]}[0];
2054 if (defined $a_source_file) {
2055 $a_source_file="@$project[$P_PATH]$a_source_file";
2056 last search_a_file;
2060 if (!defined $a_source_file) {
2061 $a_source_file="Makefile.in";
2063 generate_from_template("configure.ac","configure.ac",[
2064 ["PROJECTS",join("\n",map { "@$_[$P_PATH]Makefile" } @projects)],
2065 ["SOURCE","$a_source_file"],
2066 ["NEEDS_MFC","$needs_mfc"]]);
2067 system("autoconf configure.ac > configure");
2069 # Add execute permission to configure for whoever has the right to read it
2070 my @st=stat("configure");
2071 if (@st) {
2072 my $mode=$st[2];
2073 $mode|=($mode & 0444) >>2;
2074 chmod($mode,"configure");
2075 } else {
2076 print "warning: could not generate the configure script. You need to run autoconf\n";
2082 sub generate_read_templates()
2084 my $file;
2086 while (<DATA>) {
2087 if (/^--- ((\w\.?)+) ---$/) {
2088 my $filename=$1;
2089 if (defined $templates{$filename}) {
2090 print STDERR "winemaker: internal error: There is more than one template for $filename\n";
2091 undef $file;
2092 } else {
2093 $file=[];
2094 $templates{$filename}=$file;
2096 } elsif (defined $file) {
2097 push @$file, $_;
2103 # This is where we finally generate files. In fact this method does not
2104 # do anything itself but calls the methods that do the actual work.
2105 sub generate()
2107 print "Generating project files...\n";
2108 generate_read_templates();
2109 generate_global_files();
2111 foreach my $project (@projects) {
2112 my $path=@$project[$P_PATH];
2113 if ($path eq "") {
2114 $path=".";
2115 } else {
2116 $path =~ s+/$++;
2118 print " $path\n";
2119 generate_project_files($project);
2125 #####
2127 # Option defaults
2129 #####
2131 $opt_backup=1;
2132 $opt_lower=$OPT_LOWER_UPPERCASE;
2133 $opt_lower_include=1;
2135 # $opt_work_dir=<undefined>
2136 # $opt_single_target=<undefined>
2137 $opt_target_type=$TT_GUIEXE;
2138 $opt_flags=0;
2139 $opt_is_interactive=$OPT_ASK_NO;
2140 $opt_ask_project_options=$OPT_ASK_NO;
2141 $opt_ask_target_options=$OPT_ASK_NO;
2142 $opt_no_generated_files=0;
2143 $opt_no_generated_specs=0;
2144 $opt_no_source_fix=0;
2145 $opt_no_banner=0;
2149 #####
2151 # Main
2153 #####
2155 sub print_banner()
2157 print "Winemaker $version\n";
2158 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2161 sub usage()
2163 print_banner();
2164 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2165 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2166 print STDERR " [--lower-include|--nolower-include]\n";
2167 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2168 print STDERR " [--wrap|--nowrap] [--mfc|--nomfc]\n";
2169 print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2170 print STDERR " [--nodlls] [--interactive] [--single-target name]\n";
2171 print STDERR " [--generated-files|--nogenerated-files] [--nogenerated-specs]\n";
2172 print STDERR " work_directory\n";
2173 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2174 print STDERR "the specified directory so that they can be compiled with Winelib. During this\n";
2175 print STDERR "process it will modify and rename some of the files in that directory.\n";
2176 print STDERR "\tPlease read the manual page before use.\n";
2177 exit (2);
2180 target_init(\@global_settings);
2182 while (@ARGV>0) {
2183 my $arg=shift @ARGV;
2184 # General options
2185 if ($arg eq "--nobanner") {
2186 $opt_no_banner=1;
2187 } elsif ($arg eq "--backup") {
2188 $opt_backup=1;
2189 } elsif ($arg eq "--nobackup") {
2190 $opt_backup=0;
2191 } elsif ($arg eq "--single-target") {
2192 $opt_single_target=shift @ARGV;
2193 } elsif ($arg eq "--lower-none") {
2194 $opt_lower=$OPT_LOWER_NONE;
2195 } elsif ($arg eq "--lower-all") {
2196 $opt_lower=$OPT_LOWER_ALL;
2197 } elsif ($arg eq "--lower-uppercase") {
2198 $opt_lower=$OPT_LOWER_UPPERCASE;
2199 } elsif ($arg eq "--lower-include") {
2200 $opt_lower_include=1;
2201 } elsif ($arg eq "--nolower-include") {
2202 $opt_lower_include=0;
2203 } elsif ($arg eq "--nosource-fix") {
2204 $opt_no_source_fix=1;
2205 } elsif ($arg eq "--generated-files") {
2206 $opt_no_generated_files=0;
2207 } elsif ($arg eq "--nogenerated-files") {
2208 $opt_no_generated_files=1;
2209 } elsif ($arg eq "--nogenerated-specs") {
2210 $opt_no_generated_specs=1;
2212 } elsif ($arg =~ /^-D/) {
2213 push @{$global_settings[$T_DEFINES]},$arg;
2214 } elsif ($arg =~ /^-I/) {
2215 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2216 } elsif ($arg =~ /^-P/) {
2217 push @{$global_settings[$T_DLL_PATH]},"-L$'";
2218 } elsif ($arg =~ /^-i/) {
2219 my $dllname = $';
2220 if ($dllname =~ /^msvcrt$/) {
2221 push @{$global_settings[$T_INCLUDE_PATH]},"-I\$(WINE_INCLUDE_ROOT)/msvcrt";
2223 push @{$global_settings[$T_DLLS]},$dllname;
2224 } elsif ($arg =~ /^-L/) {
2225 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2226 } elsif ($arg =~ /^-l/) {
2227 push @{$global_settings[$T_LIBRARIES]},$';
2229 # 'Source'-based method options
2230 } elsif ($arg eq "--dll") {
2231 $opt_target_type=$TT_DLL;
2232 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2233 $opt_target_type=$TT_GUIEXE;
2234 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2235 $opt_target_type=$TT_CUIEXE;
2236 } elsif ($arg eq "--interactive") {
2237 $opt_is_interactive=$OPT_ASK_YES;
2238 $opt_ask_project_options=$OPT_ASK_YES;
2239 $opt_ask_target_options=$OPT_ASK_YES;
2240 } elsif ($arg eq "--wrap") {
2241 $opt_flags|=$TF_WRAP;
2242 } elsif ($arg eq "--nowrap") {
2243 $opt_flags&=~$TF_WRAP;
2244 } elsif ($arg eq "--mfc") {
2245 $opt_flags|=$TF_MFC;
2246 $needs_mfc=1;
2247 } elsif ($arg eq "--nomfc") {
2248 $opt_flags&=~$TF_MFC;
2249 $opt_flags|=$TF_NOMFC;
2250 $needs_mfc=0;
2251 } elsif ($arg eq "--nodlls") {
2252 $opt_flags|=$TF_NODLLS;
2254 # Catch errors
2255 } else {
2256 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2257 if (!defined $opt_work_dir) {
2258 $opt_work_dir=$arg;
2259 } else {
2260 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2261 usage();
2263 } else {
2264 usage();
2268 if ($opt_flags & $TF_MFC && $opt_target_type != $TT_DLL) {
2269 print STDERR "info: option --mfc requires --wrap\n";
2270 $opt_flags |= $TF_WRAP;
2274 if (!defined $opt_work_dir) {
2275 print STDERR "error: you must specify the directory containing the sources to be converted\n";
2276 usage();
2277 } elsif (!chdir $opt_work_dir) {
2278 print STDERR "error: could not chdir to the work directory\n";
2279 print STDERR " $!\n";
2280 usage();
2283 if ($opt_no_banner == 0) {
2284 print_banner();
2287 project_init(\@main_project,"");
2289 # Fix the file and directory names
2290 fix_file_and_directory_names(".");
2292 # Scan the sources to identify the projects and targets
2293 source_scan();
2295 # Create targets for wrappers, etc.
2296 postprocess_targets();
2298 # Fix the source files
2299 if (! $opt_no_source_fix) {
2300 fix_source();
2303 # Generate the Makefile and the spec file
2304 if (! $opt_no_generated_files) {
2305 generate();
2309 __DATA__
2310 --- configure.ac ---
2311 dnl Process this file with autoconf to produce a configure script.
2312 dnl Author: Michael Patra <micky@marie.physik.tu-berlin.de>
2313 dnl <patra@itp1.physik.tu-berlin.de>
2314 dnl Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2316 AC_REVISION([configure.ac 1.00])
2317 AC_INIT(##WINEMAKER_SOURCE##)
2319 NEEDS_MFC=##WINEMAKER_NEEDS_MFC##
2321 dnl **** Command-line arguments ****
2323 AC_SUBST(OPTIONS)
2325 dnl **** Check for some programs ****
2327 AC_PROG_MAKE_SET
2328 AC_PROG_CC
2329 AC_PROG_CXX
2330 AC_PROG_CPP
2331 AC_PROG_LN_S
2333 dnl **** Check for some libraries ****
2335 dnl Check for -lm for BeOS
2336 AC_CHECK_LIB(m,sqrt)
2337 dnl Check for -lw for Solaris
2338 AC_CHECK_LIB(w,iswalnum)
2339 dnl Check for -lnsl for Solaris
2340 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))
2341 dnl Check for -lsocket for Solaris
2342 AC_CHECK_FUNCS(connect,,AC_CHECK_LIB(socket,connect))
2344 dnl **** Check for gcc strength-reduce bug ****
2346 if test "x${GCC}" = "xyes"
2347 then
2348 AC_CACHE_CHECK([for gcc strength-reduce bug], ac_cv_c_gcc_strength_bug,
2349 AC_TRY_RUN([
2350 int main(void) {
2351 static int Array[[3]];
2352 unsigned int B = 3;
2353 int i;
2354 for(i=0; i<B; i++) Array[[i]] = i - 3;
2355 exit( Array[[1]] != -2 );
2357 ac_cv_c_gcc_strength_bug="no",
2358 ac_cv_c_gcc_strength_bug="yes",
2359 ac_cv_c_gcc_strength_bug="yes") )
2360 if test "$ac_cv_c_gcc_strength_bug" = "yes"
2361 then
2362 CFLAGS="$CFLAGS -fno-strength-reduce"
2366 dnl **** Check for working dll ****
2368 LDSHARED=""
2369 LDXXSHARED=""
2370 LDDLLFLAGS=""
2371 AC_CACHE_CHECK([whether we can build a Linux dll],
2372 ac_cv_c_dll_linux,
2373 [saved_cflags=$CFLAGS
2374 CFLAGS="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0,-Bsymbolic"
2375 AC_TRY_LINK(,[return 1],ac_cv_c_dll_linux="yes",ac_cv_c_dll_linux="no")
2376 CFLAGS=$saved_cflags
2378 if test "$ac_cv_c_dll_linux" = "yes"
2379 then
2380 LDSHARED="\$(CC) -shared"
2381 LDXXSHARED="\$(CXX) -shared"
2382 LDDLLFLAGS="-Wl,-Bsymbolic"
2384 AC_CACHE_CHECK([whether the linker accepts -z defs], ac_cv_c_dll_zdefs,
2385 [saved_cflags=$CFLAGS
2386 CFLAGS="$CFLAGS -fPIC -shared -Wl,-Bsymbolic,-z,defs"
2387 AC_TRY_LINK([],[],ac_cv_c_dll_zdefs="yes",ac_cv_c_dll_zdefs="no")
2388 CFLAGS=$saved_cflags
2390 if test "$ac_cv_c_dll_zdefs" = "yes"
2391 then
2392 LDDLLFLAGS="$LDDLLFLAGS,-z,defs"
2395 AC_CACHE_CHECK([whether the linker accepts -init and -fini], ac_cv_c_dll_init_fini,
2396 [saved_cflags=$CFLAGS
2397 CFLAGS="$CFLAGS -fPIC -shared -Wl,-Bsymbolic,-init,__wine_spec_init,-fini,__wine_spec_fini"
2398 AC_TRY_LINK([],[],ac_cv_c_dll_init_fini="yes",ac_cv_c_dll_init_fini="no")
2399 CFLAGS=$saved_cflags
2401 if test "$ac_cv_c_dll_init_fini" = "yes"
2402 then
2403 AC_DEFINE(HAVE_LINKER_INIT_FINI,1,[Define if the linker supports renaming the init and fini functions])
2404 LDDLLFLAGS="$LDDLLFLAGS,-init,__wine_spec_init,-fini,__wine_spec_fini"
2406 else
2407 AC_CACHE_CHECK([whether we can build a UnixWare (Solaris) dll],
2408 ac_cv_c_dll_unixware,
2409 [saved_cflags=$CFLAGS
2410 CFLAGS="$CFLAGS -fPIC -Wl,-G,-h,conftest.so.1.0,-B,symbolic"
2411 AC_TRY_LINK(,[return 1],ac_cv_c_dll_unixware="yes",ac_cv_c_dll_unixware="no")
2412 CFLAGS=$saved_cflags
2414 if test "$ac_cv_c_dll_unixware" = "yes"
2415 then
2416 LDSHARED="\$(CC) -Wl,-G"
2417 LDXXSHARED="\$(CXX) -Wl,-G"
2418 LDDLLFLAGS="-Wl,-B,symbolic"
2419 else
2420 AC_CACHE_CHECK([whether we can build a NetBSD dll],
2421 ac_cv_c_dll_netbsd,
2422 [saved_cflags=$CFLAGS
2423 CFLAGS="$CFLAGS -fPIC -Wl,-Bshareable,-Bforcearchive"
2424 AC_TRY_LINK(,[return 1],ac_cv_c_dll_netbsd="yes",ac_cv_c_dll_netbsd="no")
2425 CFLAGS=$saved_cflags
2427 if test "$ac_cv_c_dll_netbsd" = "yes"
2428 then
2429 LDSHARED="\$(CC) -Wl,-Bshareable,-Bforcearchive"
2430 LDXXSHARED="\$(CXX) -Wl,-Bshareable,-Bforcearchive"
2431 LDDLLFLAGS="" #FIXME
2432 else
2433 AC_CACHE_CHECK([whether we can build a Mach-O (Mac OS X/Darwin) dll],
2434 ac_cv_c_dll_macho,
2435 [saved_cflags=$CFLAGS
2436 CFLAGS="$CFLAGS -bundle"
2437 AC_TRY_LINK(,[return 1], ac_cv_c_dll_macho="yes", ac_cv_c_dll_macho="no")
2438 CFLAGS=$saved_cflags
2440 if test "$ac_cv_c_dll_macho" = "yes"
2441 then
2442 LDSHARED="\$(CC) -bundle -flat_namespace -undefined suppress"
2443 LDXXSHARED="\$(CXX) -bundle -flat_namespace -undefined suppress"
2444 LDDLLFLAGS="-fno-common"
2445 CFLAGS="$CFLAGS -ffixed-r13 -no-cpp-precomp -Dsocklen_t=u_int32_t"
2446 CXXFLAGS="$CXXFLAGS -ffixed-r13 -no-cpp-precomp -Dsocklen_t=u_int32_t"
2451 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"
2452 then
2453 AC_MSG_ERROR([Could not find how to build a dynamically linked library])
2456 CFLAGS="$CFLAGS -fPIC"
2458 AC_SUBST(LDSHARED)
2459 AC_SUBST(LDXXSHARED)
2460 AC_SUBST(LDDLLFLAGS)
2462 dnl *** check for the need to define __i386__
2464 AC_CACHE_CHECK([whether we need to define __i386__],ac_cv_cpp_def_i386,
2465 AC_EGREP_CPP(yes,[#if (defined(i386) || defined(__i386)) && !defined(__i386__)
2467 #endif],
2468 ac_cv_cpp_def_i386="yes", ac_cv_cpp_def_i386="no"))
2469 if test "$ac_cv_cpp_def_i386" = "yes"
2470 then
2471 CFLAGS="$CFLAGS -D__i386__"
2474 dnl *** check for the need to define __sparc__
2476 AC_CACHE_CHECK([whether we need to define __sparc__],ac_cv_cpp_def_sparc,
2477 AC_EGREP_CPP(yes,[#if (defined(sparc) || defined(__sparc)) && !defined(__sparc__)
2479 #endif],
2480 ac_cv_cpp_def_sparc="yes", ac_cv_cpp_def_sparc="no"))
2481 if test "$ac_cv_cpp_def_sparc" = "yes"
2482 then
2483 CFLAGS="$CFLAGS -D__sparc__"
2484 CXXFLAGS="$CXXFLAGS -D__sparc__"
2487 dnl *** check for the need to define __sun__
2489 AC_CACHE_CHECK([whether we need to define __sun__],ac_cv_cpp_def_sun,
2490 AC_EGREP_CPP(yes,[#if (defined(sun) || defined(__sun)) && !defined(__sun__)
2492 #endif],
2493 ac_cv_cpp_def_sun="yes", ac_cv_cpp_def_sun="no"))
2494 if test "$ac_cv_cpp_def_sun" = "yes"
2495 then
2496 CFLAGS="$CFLAGS -D__sun__"
2497 CXXFLAGS="$CXXFLAGS -D__sun__"
2500 dnl *** check for the need to define __powerpc__
2502 AC_CACHE_CHECK(whether we need to define __powerpc__,ac_cv_cpp_def_powerpc,
2503 AC_EGREP_CPP(yes,[#if (defined(__ppc__) || defined(__PPC__) || defined(__POWERPC__)) && !defined(__powerpc__)
2505 #endif],
2506 ac_cv_cpp_def_powerpc="yes", ac_cv_cpp_def_powerpc="no"))
2507 if test "$ac_cv_cpp_def_powerpc" = "yes"
2508 then
2509 CFLAGS="$CFLAGS -D__powerpc__"
2510 CXXFLAGS="$CXXFLAGS -D__powerpc__"
2514 dnl **** Test Winelib-related features of the C++ compiler
2515 AC_LANG_CPLUSPLUS()
2516 if test "x${GCC}" = "xyes"
2517 then
2518 OLDCXXFLAGS="$CXXFLAGS";
2519 CXXFLAGS="-fpermissive";
2520 AC_CACHE_CHECK([for g++ -fpermissive option], has_gxx_permissive,
2521 AC_TRY_COMPILE(,[
2522 for (int i=0;i<2;i++);
2523 i=0;
2525 [has_gxx_permissive="yes"],
2526 [has_gxx_permissive="no"])
2528 CXXFLAGS="-fms-extensions";
2529 AC_CACHE_CHECK([for g++ -fms-extensions option], has_gxx_msextensions,
2530 AC_TRY_COMPILE(,[
2533 [has_gxx_msextensions="yes"],
2534 [has_gxx_msextensions="no"])
2536 CXXFLAGS="-fno-for-scope";
2537 AC_CACHE_CHECK([for g++ -fno-for-scope option], has_gxx_no_for_scope,
2538 AC_TRY_COMPILE(,[
2539 for (int i=0;i<2;i++);
2540 i=0;
2542 [has_gxx_no_for_scope="yes"],
2543 [has_gxx_no_for_scope="no"])
2545 CXXFLAGS="$OLDCXXFLAGS";
2546 if test "$has_gxx_permissive" = "yes"
2547 then
2548 CXXFLAGS="$CXXFLAGS -fpermissive"
2550 if test "$has_gxx_msextensions" = "yes"
2551 then
2552 CXXFLAGS="$CXXFLAGS -fms-extensions"
2554 if test "$has_gxx_no_for_scope" = "yes"
2555 then
2556 CXXFLAGS="$CXXFLAGS -fno-for-scope"
2559 AC_LANG_C()
2561 dnl **** Test Winelib-related features of the C compiler
2562 dnl none for now
2564 dnl **** Macros for finding a headers/libraries in a collection of places
2566 dnl AC_PATH_FILE(variable,file,action-if-not-found,default-locations)
2567 AC_DEFUN(AC_PATH_FILE,[
2568 AC_MSG_CHECKING([for $2])
2569 AC_CACHE_VAL(ac_cv_pfile_$1,
2571 ac_found=
2572 ac_dummy="ifelse([$4], , , [$4])"
2573 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2574 for ac_dir in $ac_dummy; do
2575 IFS="$ac_save_ifs"
2576 if test -z "$ac_dir"
2577 then
2578 ac_file="$2"
2579 else
2580 ac_file="$ac_dir/$2"
2582 if test -f "$ac_file"
2583 then
2584 ac_found=1
2585 ac_cv_pfile_$1="$ac_dir"
2586 break
2588 done
2589 ifelse([$3],,,[if test -z "$ac_found"
2590 then
2595 $1="$ac_cv_pfile_$1"
2596 if test -n "$ac_found" -o -n "[$]$1"
2597 then
2598 AC_MSG_RESULT([$]$1)
2599 else
2600 AC_MSG_RESULT(no)
2602 AC_SUBST($1)
2605 dnl AC_PATH_HEADER(variable,header,action-if-not-found,default-locations)
2606 dnl Note that the above may set variable to an empty value if the header is
2607 dnl already in the include path
2608 AC_DEFUN(AC_PATH_HEADER,[
2609 AC_MSG_CHECKING([for $2 header])
2610 AC_CACHE_VAL(ac_cv_pheader_$1,
2612 ac_found=
2613 ac_dummy="ifelse([$4], , :/usr/local/include, [$4])"
2614 save_CPPFLAGS="$CPPFLAGS"
2615 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2616 for ac_dir in $ac_dummy; do
2617 IFS="$ac_save_ifs"
2618 if test -z "$ac_dir"
2619 then
2620 CPPFLAGS="$save_CPPFLAGS"
2621 else
2622 CPPFLAGS="-I$ac_dir $save_CPPFLAGS"
2624 AC_TRY_COMPILE([#include <$2>],,ac_found=1;ac_cv_pheader_$1="$ac_dir";break)
2625 done
2626 CPPFLAGS="$save_CPPFLAGS"
2627 ifelse([$3],,,[if test -z "$ac_found"
2628 then
2633 $1="$ac_cv_pheader_$1"
2634 if test -n "$ac_found" -o -n "[$]$1"
2635 then
2636 AC_MSG_RESULT([$]$1)
2637 else
2638 AC_MSG_RESULT(no)
2640 AC_SUBST($1)
2643 dnl AC_PATH_LIBRARY(variable,libraries,extra libs,action-if-not-found,default-locations)
2644 AC_DEFUN(AC_PATH_LIBRARY,[
2645 AC_MSG_CHECKING([for $2])
2646 AC_CACHE_VAL(ac_cv_plibrary_$1,
2648 ac_found=
2649 ac_dummy="ifelse([$5], , :/usr/local/lib, [$5])"
2650 save_LIBS="$LIBS"
2651 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2652 for ac_dir in $ac_dummy; do
2653 IFS="$ac_save_ifs"
2654 if test -z "$ac_dir"
2655 then
2656 LIBS="$2 $3 $save_LIBS"
2657 else
2658 LIBS="-L$ac_dir $2 $3 $save_LIBS"
2660 AC_TRY_LINK(,,ac_found=1;ac_cv_plibrary_$1="$ac_dir";break)
2661 done
2662 LIBS="$save_LIBS"
2663 ifelse([$4],,,[if test -z "$ac_found"
2664 then
2669 $1="$ac_cv_plibrary_$1"
2670 if test -n "$ac_found" -o -n "[$]$1"
2671 then
2672 AC_MSG_RESULT([$]$1)
2673 else
2674 AC_MSG_RESULT(no)
2676 AC_SUBST($1)
2679 dnl **** Try to find where winelib is located ****
2681 LDPATH=""
2682 WINE_INCLUDE_ROOT=""
2683 WINE_INCLUDE_PATH=""
2684 WINE_LIBRARY_ROOT=""
2685 WINE_LIBRARY_PATH=""
2686 WINE_DLL_ROOT=""
2687 WINE_DLL_PATH=""
2688 WINE_TOOL_PATH=""
2689 WINE=""
2690 WINEBUILD=""
2691 WRC=""
2693 AC_ARG_WITH(wine,
2694 [ --with-wine=DIR the Wine package (or sources) is in DIR],
2695 [if test "$withval" != "no"; then
2696 WINE_ROOT="$withval";
2697 WINE_INCLUDES="";
2698 WINE_LIBRARIES="";
2699 WINE_TOOLS="";
2700 else
2701 WINE_ROOT="";
2702 fi])
2703 if test -n "$WINE_ROOT"
2704 then
2705 WINE_INCLUDE_ROOT="$WINE_ROOT/include:$WINE_ROOT/include/wine:$WINE_ROOT/include/wine/windows:$WINE_ROOT/include/windows"
2706 WINE_LIBRARY_ROOT="$WINE_ROOT:$WINE_ROOT/libs:$WINE_ROOT/lib"
2707 WINE_DLL_ROOT="$WINE_ROOT/dlls:$WINE_ROOT/lib:$WINE_ROOT/lib/wine"
2708 WINE_TOOL_PATH="$WINE_ROOT:$WINE_ROOT/bin:$WINE_ROOT/tools/wrc:$WINE_ROOT/tools/winebuild"
2711 AC_ARG_WITH(wine-includes,
2712 [ --with-wine-includes=DIR the Wine includes are in DIR],
2713 [if test "$withval" != "no"; then
2714 WINE_INCLUDES="$withval";
2715 else
2716 WINE_INCLUDES="";
2717 fi])
2718 if test -n "$WINE_INCLUDES"
2719 then
2720 WINE_INCLUDE_ROOT="$WINE_INCLUDES"
2723 AC_ARG_WITH(wine-libraries,
2724 [ --with-wine-libraries=DIR the Wine libraries are in DIR],
2725 [if test "$withval" != "no"; then
2726 WINE_LIBRARIES="$withval";
2727 else
2728 WINE_LIBRARIES="";
2729 fi])
2730 if test -n "$WINE_LIBRARIES"
2731 then
2732 WINE_LIBRARY_ROOT="$WINE_LIBRARIES"
2735 AC_ARG_WITH(wine-dlls,
2736 [ --with-wine-dlls=DIR the Wine dlls are in DIR],
2737 [if test "$withval" != "no"; then
2738 WINE_DLLS="$withval";
2739 else
2740 WINE_DLLS="";
2741 fi])
2742 if test -n "$WINE_DLLS"
2743 then
2744 WINE_DLL_ROOT="$WINE_DLLS"
2747 AC_ARG_WITH(wine-tools,
2748 [ --with-wine-tools=DIR the Wine tools are in DIR],
2749 [if test "$withval" != "no"; then
2750 WINE_TOOLS="$withval";
2751 else
2752 WINE_TOOLS="";
2753 fi])
2754 if test -n "$WINE_TOOLS"
2755 then
2756 WINE_TOOL_PATH="$WINE_TOOLS:$WINE_TOOLS/tools/wrc:$WINE_TOOLS/tools/winebuild"
2759 if test -z "$WINE_INCLUDE_ROOT"
2760 then
2761 WINE_INCLUDE_ROOT=":/usr/include/wine/windows:/usr/include/wine:/usr/local/include/wine/windows:/opt/wine/include/windows:/opt/wine/include/wine";
2762 else
2763 AC_PATH_FILE(WINE_INCLUDE_ROOT,[windef.h],[
2764 AC_MSG_ERROR([Could not find the Wine headers (windef.h)])
2765 ],$WINE_INCLUDE_ROOT)
2767 AC_PATH_HEADER(WINE_INCLUDE_ROOT,[windef.h],[
2768 AC_MSG_ERROR([Could not include the Wine headers (windef.h)])
2769 ],$WINE_INCLUDE_ROOT)
2770 if test -n "$WINE_INCLUDE_ROOT"
2771 then
2772 WINE_INCLUDE_PATH="-I$WINE_INCLUDE_ROOT"
2773 else
2774 WINE_INCLUDE_PATH=""
2777 if test -z "$WINE_LIBRARY_ROOT"
2778 then
2779 WINE_LIBRARY_ROOT=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib"
2780 else
2781 AC_PATH_FILE(WINE_LIBRARY_ROOT,[libwine.so],
2783 AC_PATH_FILE(WINE_LIBRARY_ROOT,[libwine.dylib],
2784 [AC_MSG_ERROR([Could not find the Wine libraries (libwine.dylib or libwine.so)])],
2785 $WINE_LIBRARY_ROOT)
2786 ], $WINE_LIBRARY_ROOT)
2788 AC_PATH_LIBRARY(WINE_LIBRARY_ROOT,[-lwine],[],[
2789 AC_MSG_ERROR([Could not link with the Wine libraries (libwine.so)])
2790 ],$WINE_LIBRARY_ROOT)
2791 if test -n "$WINE_LIBRARY_ROOT"
2792 then
2793 WINE_LIBRARY_PATH="-L$WINE_LIBRARY_ROOT"
2794 LDPATH="$WINE_LIBRARY_ROOT"
2795 else
2796 WINE_LIBRARY_PATH=""
2799 save_LIBS="$LIBS"
2800 LIBS="$WINE_LIBRARY_PATH $LIBS"
2802 AC_CHECK_LIB(wine_unicode,wine_cp_wcstombs,[],[
2803 AC_MSG_ERROR([Could not find the Wine dlls (libwine_unicode.so)])
2806 LIBS="$save_LIBS"
2808 if test -z "$WINE_DLL_ROOT"
2809 then
2810 if test -n "$WINE_LIBRARY_ROOT"
2811 then
2812 WINE_DLL_ROOT="$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/dlls:$WINE_LIBRARY_ROOT/wine"
2813 else
2814 WINE_DLL_ROOT="/lib:/lib/wine:/usr/lib:/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine"
2818 AC_PATH_FILE(WINE_DLL_ROOT,[libntdll.def],[
2819 AC_MSG_ERROR([Could not find the Wine dlls (libntdll.def)])
2820 ],[$WINE_DLL_ROOT])
2821 WINE_DLL_PATH="-L$WINE_DLL_ROOT"
2822 WINE_LIBRARY_PATH="$WINE_LIBRARY_PATH -L$WINE_DLL_ROOT"
2824 if test -z "$WINE_TOOL_PATH"
2825 then
2826 WINE_TOOL_PATH="$PATH:/usr/local/bin:/opt/wine/bin"
2828 AC_PATH_PROG(WINE,wine,,$WINE_TOOL_PATH)
2829 if test -z "$WINE"
2830 then
2831 AC_MSG_ERROR([Could not find Wine's wine tool])
2833 AC_PATH_PROG(WINEBUILD,winebuild,,$WINE_TOOL_PATH)
2834 if test -z "$WINEBUILD"
2835 then
2836 AC_MSG_ERROR([Could not find Wine's winebuild tool])
2838 AC_PATH_PROG(WRC,wrc,,$WINE_TOOL_PATH)
2839 if test -z "$WRC"
2840 then
2841 AC_MSG_ERROR([Could not find Wine's wrc tool])
2844 case $build_os in
2845 darwin*|macosx*)
2846 LDPATH="DYLD_LIBRARY_PATH=\"$LDPATH:\$\$DYLD_LIBRARY_PATH\"";;
2848 LDPATH="LD_LIBRARY_PATH=\"$LDPATH:\$\$LD_LIBRARY_PATH\""
2849 esac
2851 AC_SUBST(LDPATH)
2852 AC_SUBST(WINE_INCLUDE_PATH)
2853 AC_SUBST(WINE_LIBRARY_PATH)
2854 AC_SUBST(WINE_DLL_PATH)
2856 dnl **** Try to find where the MFC are located ****
2857 AC_LANG_CPLUSPLUS()
2859 if test "x$NEEDS_MFC" = "x1"
2860 then
2861 ATL_INCLUDE_ROOT="";
2862 ATL_INCLUDE_PATH="";
2863 MFC_INCLUDE_ROOT="";
2864 MFC_INCLUDE_PATH="";
2865 MFC_LIBRARY_ROOT="";
2866 MFC_LIBRARY_PATH="";
2868 AC_ARG_WITH(mfc,
2869 [ --with-mfc=DIR the MFC package (or sources) is in DIR],
2870 [if test "$withval" != "no"; then
2871 MFC_ROOT="$withval";
2872 ATL_INCLUDES="";
2873 MFC_INCLUDES="";
2874 MFC_LIBRARIES="";
2875 else
2876 MFC_ROOT="";
2877 fi])
2878 if test -n "$MFC_ROOT"
2879 then
2880 ATL_INCLUDE_ROOT="$MFC_ROOT";
2881 MFC_INCLUDE_ROOT="$MFC_ROOT";
2882 MFC_LIBRARY_ROOT="$MFC_ROOT";
2885 AC_ARG_WITH(atl-includes,
2886 [ --with-atl-includes=DIR the ATL includes are in DIR],
2887 [if test "$withval" != "no"; then
2888 ATL_INCLUDES="$withval";
2889 else
2890 ATL_INCLUDES="";
2891 fi])
2892 if test -n "$ATL_INCLUDES"
2893 then
2894 ATL_INCLUDE_ROOT="$ATL_INCLUDES";
2897 AC_ARG_WITH(mfc-includes,
2898 [ --with-mfc-includes=DIR the MFC includes are in DIR],
2899 [if test "$withval" != "no"; then
2900 MFC_INCLUDES="$withval";
2901 else
2902 MFC_INCLUDES="";
2903 fi])
2904 if test -n "$MFC_INCLUDES"
2905 then
2906 MFC_INCLUDE_ROOT="$MFC_INCLUDES";
2909 AC_ARG_WITH(mfc-libraries,
2910 [ --with-mfc-libraries=DIR the MFC libraries are in DIR],
2911 [if test "$withval" != "no"; then
2912 MFC_LIBRARIES="$withval";
2913 else
2914 MFC_LIBRARIES="";
2915 fi])
2916 if test -n "$MFC_LIBRARIES"
2917 then
2918 MFC_LIBRARY_ROOT="$MFC_LIBRARIES";
2921 OLDCPPFLAGS="$CPPFLAGS"
2922 dnl FIXME: We should not have defines in any of the include paths
2923 CPPFLAGS="$WINE_INCLUDE_PATH -I$WINE_INCLUDE_ROOT/msvcrt -D_DLL -D_MT $CPPFLAGS"
2924 ATL_INCLUDE_PATH="-I\$(WINE_INCLUDE_ROOT)/msvcrt -D_DLL -D_MT"
2925 if test -z "$ATL_INCLUDE_ROOT"
2926 then
2927 ATL_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/atl:/usr/include/atl:/usr/local/include/atl:/opt/mfc/include/atl:/opt/atl/include"
2928 else
2929 ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT:$ATL_INCLUDE_ROOT/atl:$ATL_INCLUDE_ROOT/atl/include"
2931 AC_PATH_HEADER(ATL_INCLUDE_ROOT,atldef.h,[
2932 AC_MSG_ERROR([Could not find the ATL includes])
2933 ],$ATL_INCLUDE_ROOT)
2934 if test -n "$ATL_INCLUDE_ROOT"
2935 then
2936 ATL_INCLUDE_PATH="$ATL_INCLUDE_PATH -I$ATL_INCLUDE_ROOT"
2939 MFC_INCLUDE_PATH="$ATL_INCLUDE_PATH"
2940 if test -z "$MFC_INCLUDE_ROOT"
2941 then
2942 MFC_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/mfc:/usr/include/mfc:/usr/local/include/mfc:/opt/mfc/include/mfc:/opt/mfc/include"
2943 else
2944 MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT:$MFC_INCLUDE_ROOT/mfc:$MFC_INCLUDE_ROOT/mfc/include:$MFC_INCLUDE_ROOT/Include"
2946 AC_PATH_HEADER(MFC_INCLUDE_ROOT,afx.h,[
2947 AC_MSG_ERROR([Could not find the MFC includes])
2948 ],$MFC_INCLUDE_ROOT)
2949 if test -n "$MFC_INCLUDE_ROOT" -a "$ATL_INCLUDE_ROOT" != "$MFC_INCLUDE_ROOT"
2950 then
2951 MFC_INCLUDE_PATH="$MFC_INCLUDE_PATH -I$MFC_INCLUDE_ROOT"
2953 CPPFLAGS="$OLDCPPFLAGS"
2955 if test -z "$MFC_LIBRARY_ROOT"
2956 then
2957 MFC_LIBRARY_ROOT=":$WINE_LIBRARY_ROOT:/usr/lib/mfc:/usr/local/lib:/usr/local/lib/mfc:/opt/mfc/lib";
2958 else
2959 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT:$MFC_LIBRARY_ROOT/lib:$MFC_LIBRARY_ROOT/mfc/src:$MFC_LIBRARY_ROOT/src";
2961 AC_PATH_LIBRARY(MFC_LIBRARY_ROOT,[-lmfc],[$WINE_LIBRARY_PATH -lwine -lwine_unicode],[
2962 AC_MSG_ERROR([Could not find the MFC library])
2963 ],$MFC_LIBRARY_ROOT)
2964 if test -n "$MFC_LIBRARY_ROOT" -a "$MFC_LIBRARY_ROOT" != "$WINE_LIBRARY_ROOT"
2965 then
2966 MFC_LIBRARY_PATH="-L$MFC_LIBRARY_ROOT"
2967 else
2968 MFC_LIBRARY_PATH=""
2971 AC_SUBST(ATL_INCLUDE_PATH)
2972 AC_SUBST(MFC_INCLUDE_PATH)
2973 AC_SUBST(MFC_LIBRARY_PATH)
2976 AC_LANG_C()
2978 dnl **** Generate output files ****
2980 MAKE_RULES=Make.rules
2981 AC_SUBST_FILE(MAKE_RULES)
2983 AC_OUTPUT([
2984 Make.rules
2985 ##WINEMAKER_PROJECTS##
2988 echo
2989 echo "Configure finished. Do 'make' to build the project."
2990 echo
2992 dnl Local Variables:
2993 dnl comment-start: "dnl "
2994 dnl comment-end: ""
2995 dnl comment-start-skip: "\\bdnl\\b\\s *"
2996 dnl compile-command: "autoconf"
2997 dnl End:
2998 --- Make.rules.in ---
2999 # Copyright 2000 Francois Gouget for CodeWeavers
3000 # fgouget@codeweavers.com
3002 # Global rules shared by all makefiles -*-Makefile-*-
3004 # Each individual makefile must define the following variables:
3005 # TOPOBJDIR : top-level object directory
3006 # SRCDIR : source directory for this module
3008 # Each individual makefile may define the following additional variables:
3010 # SUBDIRS : subdirectories that contain a Makefile
3011 # DLLS : WineLib libraries to be built
3012 # EXES : WineLib executables to be built
3014 # CEXTRA : extra c flags (e.g. '-Wall')
3015 # CXXEXTRA : extra c++ flags (e.g. '-Wall')
3016 # WRCEXTRA : extra wrc flags (e.g. '-p _SysRes')
3017 # DEFINES : defines (e.g. -DSTRICT)
3018 # INCLUDE_PATH : additional include path
3019 # LIBRARY_PATH : additional library path
3020 # LIBRARIES : additional Unix libraries to link with
3022 # C_SRCS : C sources for the module
3023 # CXX_SRCS : C++ sources for the module
3024 # RC_SRCS : resource source files
3025 # SPEC_SRCS : interface definition files
3028 # Where is Wine
3030 WINE_INCLUDE_ROOT = @WINE_INCLUDE_ROOT@
3031 WINE_INCLUDE_PATH = @WINE_INCLUDE_PATH@
3032 WINE_LIBRARY_ROOT = @WINE_LIBRARY_ROOT@
3033 WINE_LIBRARY_PATH = @WINE_LIBRARY_PATH@
3034 WINE_DLL_ROOT = @WINE_DLL_ROOT@
3035 WINE_DLL_PATH = @WINE_DLL_PATH@
3037 LDPATH = @LDPATH@
3039 # Where are the MFC
3041 ATL_INCLUDE_ROOT = @ATL_INCLUDE_ROOT@
3042 ATL_INCLUDE_PATH = @ATL_INCLUDE_PATH@
3043 MFC_INCLUDE_ROOT = @MFC_INCLUDE_ROOT@
3044 MFC_INCLUDE_PATH = @MFC_INCLUDE_PATH@
3045 MFC_LIBRARY_ROOT = @MFC_LIBRARY_ROOT@
3046 MFC_LIBRARY_PATH = @MFC_LIBRARY_PATH@
3048 # Global definitions and options
3050 GLOBAL_DEFINES = ##WINEMAKER_DEFINES##
3051 GLOBAL_INCLUDE_PATH = ##WINEMAKER_INCLUDE_PATH##
3052 GLOBAL_DLL_PATH = ##WINEMAKER_DLL_PATH##
3053 GLOBAL_DLLS = ##WINEMAKER_DLLS##
3054 GLOBAL_LIBRARY_PATH = ##WINEMAKER_LIBRARY_PATH##
3055 GLOBAL_LIBRARIES = ##WINEMAKER_LIBRARIES##
3057 # First some useful definitions
3059 SHELL = /bin/sh
3060 CC = @CC@
3061 CPP = @CPP@
3062 CXX = @CXX@
3063 WRC = @WRC@
3064 CFLAGS = @CFLAGS@ $(CEXTRA)
3065 CXXFLAGS = @CXXFLAGS@ $(CXXEXTRA)
3066 WRCFLAGS = $(WRCEXTRA)
3067 OPTIONS = @OPTIONS@ -D_REENTRANT
3068 LIBS = @LIBS@ $(LIBRARY_PATH)
3069 DIVINCL = $(GLOBAL_INCLUDE_PATH) -I$(SRCDIR) $(INCLUDE_PATH) $(WINE_INCLUDE_PATH)
3070 ALLCFLAGS = $(DIVINCL) $(CFLAGS) $(GLOBAL_DEFINES) $(DEFINES) $(OPTIONS)
3071 ALLCXXFLAGS=$(DIVINCL) $(CXXFLAGS) $(GLOBAL_DEFINES) $(DEFINES) $(OPTIONS)
3072 ALL_DLL_PATH = $(DLL_PATH) $(GLOBAL_DLL_PATH) $(WINE_DLL_PATH)
3073 ALL_LIBRARY_PATH = $(LIBRARY_PATH) $(GLOBAL_LIBRARY_PATH) $(WINE_LIBRARY_PATH)
3074 WINE_LIBRARIES = -lwine -lwine_unicode
3075 ALL_LIBRARIES = $(LIBRARIES:%=-l%) $(GLOBAL_LIBRARIES:%=-l%) $(WINE_LIBRARIES)
3076 LDSHARED = @LDSHARED@
3077 LDXXSHARED= @LDXXSHARED@
3078 LDDLLFLAGS= @LDDLLFLAGS@
3079 LN_S = @LN_S@
3080 RM = rm -f
3081 MV = mv
3082 MKDIR = mkdir -p
3083 WINE = @WINE@
3084 WINEBUILD = @WINEBUILD@
3085 @SET_MAKE@
3087 # Installation infos
3089 INSTALL = install
3090 INSTALL_PROGRAM = $(INSTALL)
3091 INSTALL_SCRIPT = $(INSTALL)
3092 INSTALL_DATA = $(INSTALL) -m 644
3093 prefix = @prefix@
3094 exec_prefix = @exec_prefix@
3095 bindir = @bindir@
3096 libdir = @libdir@
3097 infodir = @infodir@
3098 mandir = @mandir@
3099 dlldir = @libdir@/wine
3101 prog_manext = 1
3102 conf_manext = 5
3104 OBJS = $(C_SRCS:.c=.o) $(CXX_SRCS:.cpp=.o) \
3105 $(SPEC_SRCS:.spec=.spec.o)
3106 CLEAN_FILES = *.dbg.c *.spec.c y.tab.c y.tab.h lex.yy.c \
3107 core *.orig *.rej \
3108 \\\#*\\\# *~ *% .\\\#*
3110 # Implicit rules
3112 .SUFFIXES: .cpp .rc .res .spec .spec.c .spec.o
3114 .c.o:
3115 $(CC) -c $(ALLCFLAGS) -o $@ $<
3117 .cpp.o:
3118 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
3120 .cxx.o:
3121 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
3123 .rc.res:
3124 $(LDPATH) $(WRC) $(WRCFLAGS) $(DIVINCL) -o $@ $<
3126 .PHONY: all install uninstall clean distclean depend dummy
3128 # 'all' target first in case the enclosing Makefile didn't define any target
3130 all: Makefile
3132 # Rules for makefile
3134 Makefile: Makefile.in $(TOPSRCDIR)/configure
3135 @echo $@ is older than $?, please rerun $(TOPSRCDIR)/configure
3136 @exit 1
3138 # Rules for cleaning
3140 $(SUBDIRS:%=%/__clean__): dummy
3141 cd `dirname $@` && $(MAKE) clean
3143 $(EXTRASUBDIRS:%=%/__clean__): dummy
3144 -cd `dirname $@` && $(RM) $(CLEAN_FILES)
3146 clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
3147 $(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(OBJS)
3148 $(RM) $(DLLS:%=%.dbg.o) $(DLLS:%=%.spec.o) $(DLLS:%=%.so)
3149 $(RM) $(EXES:%=%.dbg.o) $(EXES:%=%.spec.o) $(EXES:%=%.so) $(EXES:%.exe=%)
3151 # Rules for installing
3153 $(SUBDIRS:%=%/__install__): dummy
3154 cd `dirname $@` && $(MAKE) install
3156 $(SUBDIRS:%=%/__uninstall__): dummy
3157 cd `dirname $@` && $(MAKE) uninstall
3159 # Misc. rules
3161 $(SUBDIRS): dummy
3162 @cd $@ && $(MAKE)
3164 dummy:
3166 # End of global rules
3167 --- wineapploader.in ---
3168 #!/bin/sh
3170 # Wrapper script to start a Winelib application once it is installed
3172 # Copyright (C) 2002 Alexandre Julliard
3174 # determine the app Winelib library name
3175 appname=`basename "$0" .exe`.exe
3177 #allow Wine to load Winelib application from the current directory
3178 export WINEDLLPATH=$WINEDLLPATH:@winelibdir@
3180 # first try explicit WINELOADER
3181 if [ -x "$WINELOADER" ]; then exec "$WINELOADER" "$appname" "$@"; fi
3183 # then default bin directory
3184 if [ -x "@bindir@/wine" ]; then exec "@bindir@/wine" "$appname" "$@"; fi
3186 # now try the directory containing $0
3187 appdir=""
3188 case "$0" in
3189 */*)
3190 # $0 contains a path, use it
3191 appdir=`dirname "$0"`
3194 # no directory in $0, search in PATH
3195 saved_ifs=$IFS
3196 IFS=:
3197 for d in $PATH
3199 IFS=$saved_ifs
3200 if [ -x "$d/$0" ]; then appdir="$d"; break; fi
3201 done
3203 esac
3204 if [ -x "$appdir/wine" ]; then exec "$appdir/wine" "$appname" "$@"; fi
3206 # finally look in PATH
3207 exec wine "$appname" "$@"
3208 --- wrapper.c ---
3210 * Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
3213 #ifndef STRICT
3214 #define STRICT
3215 #endif
3217 #include <dlfcn.h>
3218 #include <windows.h>
3223 * Describe the wrapped application
3227 * This is either CUIEXE for a console based application or
3228 * GUIEXE for a regular windows application.
3230 #define GUIEXE 0
3231 #define CUIEXE 1
3232 #define APP_TYPE ##WINEMAKER_APP_TYPE##
3235 * This is the name of the library containing the application,
3236 * e.g. 'hello.dll' if the application is called 'hello.exe'.
3238 static char* appName = "##WINEMAKER_APP_NAME##";
3241 * This is the name of the application's Windows module. If left NULL
3242 * then appName is used.
3244 static char* appModule = NULL;
3247 * This is the application's entry point. This is usually "WinMain" for a
3248 * GUIEXE and 'main' for a CUIEXE application.
3250 static char* appInit = ##WINEMAKER_APP_INIT##;
3253 * This is either non-NULL for MFC-based applications and is the name of the
3254 * MFC's module. This is the module in which we will take the 'WinMain'
3255 * function.
3257 static char* mfcModule = ##WINEMAKER_APP_MFC##;
3262 * Implement the main.
3265 #if APP_TYPE == GUIEXE
3266 typedef int WINAPI (*WinMainFunc)(HINSTANCE hInstance, HINSTANCE hPrevInstance,
3267 PSTR szCmdLine, int iCmdShow);
3268 #else
3269 typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp);
3270 #endif
3272 #if APP_TYPE == GUIEXE
3273 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
3274 PSTR szCmdLine, int iCmdShow)
3275 #else
3276 int WINAPI main(int argc, char** argv, char** envp)
3277 #endif
3279 HINSTANCE hApp = 0, hMFC = 0, hMain = 0;
3280 void* appMain;
3281 int retcode;
3283 /* Then if this application is MFC based, load the MFC module */
3284 /* FIXME: I'm not sure this is really necessary */
3285 if (mfcModule!=NULL) {
3286 hMFC=LoadLibrary(mfcModule);
3287 if (hMFC==NULL) {
3288 char format[]="Could not load the MFC module %s (%d)";
3289 char* msg;
3291 msg=(char*)malloc(strlen(format)+strlen(mfcModule)+11);
3292 sprintf(msg,format,mfcModule,GetLastError());
3293 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
3294 free(msg);
3295 return 1;
3297 /* MFC is a special case: the WinMain is in the MFC library,
3298 * instead of the application's library.
3300 hMain=hMFC;
3301 } else {
3302 hMFC=NULL;
3305 /* Load the application's module */
3306 if (appModule==NULL) {
3307 appModule=appName;
3309 hApp=LoadLibrary(appModule);
3310 if (hApp==NULL) {
3311 char format[]="Could not load the application's module %s (%d)";
3312 char* msg;
3314 msg=(char*)malloc(strlen(format)+strlen(appModule)+11);
3315 sprintf(msg,format,appModule,GetLastError());
3316 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
3317 free(msg);
3318 return 1;
3319 } else if (hMain==NULL) {
3320 hMain=hApp;
3323 /* Get the address of the application's entry point */
3324 appMain=GetProcAddress(hMain, appInit);
3325 if (appMain==NULL) {
3326 char format[]="Could not get the address of %s (%d)";
3327 char* msg;
3329 msg=(char*)malloc(strlen(format)+strlen(appInit)+11);
3330 sprintf(msg,format,appInit,GetLastError());
3331 MessageBox(NULL,msg,"GetProcAddress error",MB_OK);
3332 free(msg);
3333 return 1;
3336 /* And finally invoke the application's entry point */
3337 #if APP_TYPE == GUIEXE
3338 retcode=(*((WinMainFunc)appMain))(hApp,hPrevInstance,szCmdLine,iCmdShow);
3339 #else
3340 retcode=(*((MainFunc)appMain))(argc,argv,envp);
3341 #endif
3343 /* Cleanup and done */
3344 FreeLibrary(hApp);
3345 if (hMFC!=NULL) {
3346 FreeLibrary(hMFC);
3349 return retcode;