Only reapply the texture states necessary when a different texture
[wine/dcerpc.git] / tools / winemaker
blobba288a9d3154ec9fd3eec857c5b387e14f9c0761
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 !~ /\.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 # and uuid which we don't have in Wine.
798 my @std_imports=qw(advapi32 comdlg32 gdi32 kernel32 odbc32 ole32 oleaut32 shell32 user32 winspool);
799 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
800 @$target[$T_DLLS]=\@std_imports;
801 } else {
802 @$target[$T_DLLS]=[];
804 push @{@$project[$P_TARGETS]},$target;
806 # Ask for target-specific options
807 if ($opt_ask_target_options == $OPT_ASK_YES) {
808 my $flag_desc="";
809 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
810 $flag_desc=" (mfc";
812 if ((@$target[$T_FLAGS] & $TF_WRAP)!=0) {
813 if ($flag_desc ne "") {
814 $flag_desc.=", ";
815 } else {
816 $flag_desc=" (";
818 $flag_desc.="wrapped";
820 if ($flag_desc ne "") {
821 $flag_desc.=")";
823 print "* Specify any link option (-P/-i/-L/-l/--mfc/--wrap) specific to the target\n";
824 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
825 while (1) {
826 my $options=<STDIN>;
827 chomp $options;
828 if ($options eq "never") {
829 $opt_ask_target_options=$OPT_ASK_NO;
830 last;
831 } elsif (source_set_options($target,$options)) {
832 last;
834 print "Please re-enter the options:\n";
837 push @{@$target[$T_DLL_PATH]},"-L\$(WINE_DLL_ROOT)";
838 if (@$target[$T_FLAGS] & $TF_MFC) {
839 @$project_settings[$T_FLAGS]|=$TF_MFC;
840 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
841 push @{@$target[$T_DLLS]},"mfc.dll";
842 # FIXME: Link with the MFC in the Unix sense, until we
843 # start exporting the functions properly.
844 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
845 push @{@$target[$T_LIBRARIES]},"mfc";
848 # Match sources...
849 if ($target_count == 1) {
850 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
851 @$project_settings[$T_SOURCES_C]=[];
852 @sources_c=();
854 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
855 @$project_settings[$T_SOURCES_CXX]=[];
856 @sources_cxx=();
858 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
859 @$project_settings[$T_SOURCES_RC]=[];
860 @sources_rc=();
862 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
863 # No need for sorting these sources
864 @$project_settings[$T_SOURCES_MISC]=[];
865 @sources_misc=();
866 } else {
867 foreach my $source (@sources_c) {
868 if ($source =~ /^$basename/i) {
869 push @{@$target[$T_SOURCES_C]},$source;
870 $source="";
873 foreach my $source (@sources_cxx) {
874 if ($source =~ /^$basename/i) {
875 push @{@$target[$T_SOURCES_CXX]},$source;
876 $source="";
879 foreach my $source (@sources_rc) {
880 if ($source =~ /^$basename/i) {
881 push @{@$target[$T_SOURCES_RC]},$source;
882 $source="";
885 foreach my $source (@sources_misc) {
886 if ($source =~ /^$basename/i) {
887 push @{@$target[$T_SOURCES_MISC]},$source;
888 $source="";
892 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
893 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
894 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
895 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
897 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
898 $opt_ask_target_options=$OPT_ASK_YES;
901 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
902 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
904 # The sources that did not match, if any, go to the extra
905 # source list of the project settings
906 foreach my $source (@sources_c) {
907 if ($source ne "") {
908 push @{@$project_settings[$T_SOURCES_C]},$source;
911 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
912 foreach my $source (@sources_cxx) {
913 if ($source ne "") {
914 push @{@$project_settings[$T_SOURCES_CXX]},$source;
917 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
918 foreach my $source (@sources_rc) {
919 if ($source ne "") {
920 push @{@$project_settings[$T_SOURCES_RC]},$source;
923 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
924 foreach my $source (@sources_misc) {
925 if ($source ne "") {
926 push @{@$project_settings[$T_SOURCES_MISC]},$source;
929 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
931 # Finally if we are building both libraries and programs in
932 # this directory, then the programs should be linked with all
933 # the libraries
934 if (@local_dlls > 0 and @exe_list > 0) {
935 foreach my $target (@exe_list) {
936 push @{@$target[$T_DLL_PATH]},"-L.";
937 push @{@$target[$T_DLLS]},@local_dlls;
938 push @{@$target[$T_DEPENDS]},@local_depends;
944 # Scan the source directories in search of things to build
945 sub source_scan()
947 # If there's a single target then this is going to be the default target
948 if (defined $opt_single_target) {
949 # Create the main target
950 my $main_target=[];
951 target_init($main_target);
952 @$main_target[$T_NAME]=$opt_single_target;
953 @$main_target[$T_TYPE]=$opt_target_type;
955 # Add it to the list
956 push @{$main_project[$P_TARGETS]},$main_target;
959 # The main directory is always going to be there
960 push @projects,\@main_project;
962 # Now scan the directory tree looking for source files and, maybe, targets
963 print "Scanning the source directories...\n";
964 source_scan_directory(\@main_project,"","",0);
966 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
971 #####
973 # 'vc.dsp'-based Project analysis
975 #####
977 #sub analyze_vc_dsp
984 #####
986 # Creating the wrapper targets
988 #####
990 sub postprocess_targets()
992 foreach my $project (@projects) {
993 foreach my $target (@{@$project[$P_TARGETS]}) {
994 if ((@$target[$T_FLAGS] & $TF_WRAP) != 0) {
995 my $wrapper=[];
996 target_init($wrapper);
997 @$wrapper[$T_NAME]=@$target[$T_NAME];
998 @$wrapper[$T_TYPE]=@$target[$T_TYPE];
999 @$wrapper[$T_INIT]=get_default_init(@$target[$T_TYPE]);
1000 @$wrapper[$T_FLAGS]=$TF_WRAPPER | (@$target[$T_FLAGS] & $TF_MFC);
1001 @$wrapper[$T_DLLS]=[ "kernel32", "user32" ];
1002 push @{@$wrapper[$T_LIBRARIES]}, "dl";
1003 push @{@$wrapper[$T_SOURCES_C]},"@$wrapper[$T_NAME]_wrapper.c";
1005 my $index=bsearch(@$target[$T_SOURCES_C],"@$wrapper[$T_NAME]_wrapper.c");
1006 if (defined $index) {
1007 splice(@{@$target[$T_SOURCES_C]},$index,1);
1009 @$target[$T_NAME]=@$target[$T_NAME];
1010 @$target[$T_NAME]=~ s/.exe$/.dll/;
1011 @$target[$T_TYPE]=$TT_DLL;
1013 push @{@$project[$P_TARGETS]},$wrapper;
1015 if ((@$target[$T_FLAGS] & $TF_MFC) != 0) {
1016 @{@$project[$P_SETTINGS]}[$T_FLAGS]|=$TF_MFC;
1017 $needs_mfc=1;
1025 #####
1027 # Source search
1029 #####
1032 # Performs a directory traversal and renames the files so that:
1033 # - they have the case desired by the user
1034 # - their extension is of the appropriate case
1035 # - they don't contain annoying characters like ' ', '$', '#', ...
1036 sub fix_file_and_directory_names($);
1037 sub fix_file_and_directory_names($)
1039 my $dirname=$_[0];
1041 if (opendir(DIRECTORY, "$dirname")) {
1042 foreach my $dentry (readdir DIRECTORY) {
1043 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1044 next;
1046 # Set $warn to 1 if the user should be warned of the renaming
1047 my $warn=0;
1049 # autoconf and make don't support these characters well
1050 my $new_name=$dentry;
1051 $new_name =~ s/[ \$]/_/g;
1053 # Only all lowercase extensions are supported (because of the
1054 # transformations ':.c=.o') .
1055 if (-f "$dirname/$new_name") {
1056 if ($new_name =~ /\.C$/) {
1057 $new_name =~ s/\.C$/.c/;
1059 if ($new_name =~ /\.cpp$/i) {
1060 $new_name =~ s/\.cpp$/.cpp/i;
1062 if ($new_name =~ s/\.cxx$/.cpp/i) {
1063 $warn=1;
1065 if ($new_name =~ /\.rc$/i) {
1066 $new_name =~ s/\.rc$/.rc/i;
1068 # And this last one is to avoid confusion then running make
1069 if ($new_name =~ s/^makefile$/makefile.win/) {
1070 $warn=1;
1074 # Adjust the case to the user's preferences
1075 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1076 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1078 $new_name=lc $new_name;
1081 # And finally, perform the renaming
1082 if ($new_name ne $dentry) {
1083 if ($warn) {
1084 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1086 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1087 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1088 print STDERR " $!\n";
1089 $new_name=$dentry;
1092 if (-d "$dirname/$new_name") {
1093 fix_file_and_directory_names("$dirname/$new_name");
1096 closedir(DIRECTORY);
1102 #####
1104 # Source fixup
1106 #####
1109 # This maps a directory name to a reference to an array listing
1110 # its contents (files and directories)
1111 my %directories;
1114 # Retrieves the contents of the specified directory.
1115 # We either get it from the directories hashtable which acts as a
1116 # cache, or use opendir, readdir, closedir and store the result
1117 # in the hashtable.
1118 sub get_directory_contents($)
1120 my $dirname=$_[0];
1121 my $directory;
1123 #print "getting the contents of $dirname\n";
1125 # check for a cached version
1126 $dirname =~ s+/$++;
1127 if ($dirname eq "") {
1128 $dirname=cwd;
1130 $directory=$directories{$dirname};
1131 if (defined $directory) {
1132 #print "->@$directory\n";
1133 return $directory;
1136 # Read this directory
1137 if (opendir(DIRECTORY, "$dirname")) {
1138 my @files=readdir DIRECTORY;
1139 closedir(DIRECTORY);
1140 $directory=\@files;
1141 } else {
1142 # Return an empty list
1143 #print "error: cannot open $dirname\n";
1144 my @files;
1145 $directory=\@files;
1147 #print "->@$directory\n";
1148 $directories{$dirname}=$directory;
1149 return $directory;
1153 # Try to find a file for the specified filename. The attempt is
1154 # case-insensitive which is why it's not trivial. If a match is
1155 # found then we return the pathname with the correct case.
1156 sub search_from($$)
1158 my $dirname=$_[0];
1159 my $path=$_[1];
1160 my $real_path="";
1162 if ($dirname eq "" or $dirname eq ".") {
1163 $dirname=cwd;
1164 } elsif ($dirname =~ m+^[^/]+) {
1165 $dirname=cwd . "/" . $dirname;
1167 if ($dirname !~ m+/$+) {
1168 $dirname.="/";
1171 foreach my $component (@$path) {
1172 #print " looking for $component in \"$dirname\"\n";
1173 if ($component eq ".") {
1174 # Pass it as is
1175 $real_path.="./";
1176 } elsif ($component eq "..") {
1177 # Go up one level
1178 $dirname=dirname($dirname) . "/";
1179 $real_path.="../";
1180 } else {
1181 # The file/directory may have been renamed before. Also try to
1182 # match the renamed file.
1183 my $renamed=$component;
1184 $renamed =~ s/[ \$]/_/g;
1185 if ($renamed eq $component) {
1186 undef $renamed;
1189 my $directory=get_directory_contents $dirname;
1190 my $found;
1191 foreach my $dentry (@$directory) {
1192 if ($dentry =~ /^$component$/i or
1193 (defined $renamed and $dentry =~ /^$renamed$/i)
1195 $dirname.="$dentry/";
1196 $real_path.="$dentry/";
1197 $found=1;
1198 last;
1201 if (!defined $found) {
1202 # Give up
1203 #print " could not find $component in $dirname\n";
1204 return;
1208 $real_path=~ s+/$++;
1209 #print " -> found $real_path\n";
1210 return $real_path;
1214 # Performs a case-insensitive search for the specified file in the
1215 # include path.
1216 # $line is the line number that should be referenced when an error occurs
1217 # $filename is the file we are looking for
1218 # $dirname is the directory of the file containing the '#include' directive
1219 # if '"' was used, it is an empty string otherwise
1220 # $project and $target specify part of the include path
1221 sub get_real_include_name($$$$$)
1223 my $line=$_[0];
1224 my $filename=$_[1];
1225 my $dirname=$_[2];
1226 my $project=$_[3];
1227 my $target=$_[4];
1229 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1230 # This is not a relative path, we cannot make any check
1231 my $warning="path:$filename";
1232 if (!defined $warnings{$warning}) {
1233 $warnings{$warning}="1";
1234 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1235 print STDERR "$line: $filename\n";
1237 } else {
1238 # Here's how we proceed:
1239 # - split the filename we look for into its components
1240 # - then for each directory in the include path
1241 # - trace the directory components starting from that directory
1242 # - if we fail to find a match at any point then continue with
1243 # the next directory in the include path
1244 # - otherwise, rejoice, our quest is over.
1245 my @file_components=split /[\/\\]+/, $filename;
1246 #print " Searching for $filename from @$project[$P_PATH]\n";
1248 my $real_filename;
1249 if ($dirname ne "") {
1250 # This is an 'include ""' -> look in dirname first.
1251 #print " in $dirname (include \"\")\n";
1252 $real_filename=search_from($dirname,\@file_components);
1253 if (defined $real_filename) {
1254 return $real_filename;
1257 my $project_settings=@$project[$P_SETTINGS];
1258 foreach my $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1259 my $dirname=$include;
1260 $dirname=~ s+^-I++;
1261 if (!is_absolute($dirname)) {
1262 $dirname="@$project[$P_PATH]$dirname";
1263 } else {
1264 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1265 $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
1267 #print " in $dirname\n";
1268 $real_filename=search_from("$dirname",\@file_components);
1269 if (defined $real_filename) {
1270 return $real_filename;
1273 my $dotdotpath=@$project[$P_PATH];
1274 $dotdotpath =~ s/[^\/]+/../g;
1275 foreach my $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1276 my $dirname=$include;
1277 $dirname=~ s+^-I++;
1278 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1279 $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
1280 #print " in $dirname (global setting)\n";
1281 $real_filename=search_from("$dirname",\@file_components);
1282 if (defined $real_filename) {
1283 return $real_filename;
1287 $filename =~ s+\\\\+/+g; # in include ""
1288 $filename =~ s+\\+/+g; # in include <> !
1289 if ($opt_lower_include) {
1290 return lc "$filename";
1292 return $filename;
1295 sub print_pack($$$)
1297 my $indent=$_[0];
1298 my $size=$_[1];
1299 my $trailer=$_[2];
1301 if ($size =~ /^(1|2|4|8)$/) {
1302 print FILEO "$indent#include <pshpack$size.h>$trailer";
1303 } else {
1304 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1305 print FILEO "$indent#include <pshpack4.h>$trailer";
1310 # 'Parses' a source file and fixes constructs that would not work with
1311 # Winelib. The parsing is rather simple and not all non-portable features
1312 # are corrected. The most important feature that is corrected is the case
1313 # and path separator of '#include' directives. This requires that each
1314 # source file be associated to a project & target so that the proper
1315 # include path is used.
1316 # Also note that the include path is relative to the directory in which the
1317 # compiler is run, i.e. that of the project, not to that of the file.
1318 sub fix_file($$$)
1320 my $filename=$_[0];
1321 my $project=$_[1];
1322 my $target=$_[2];
1323 $filename="@$project[$P_PATH]$filename";
1324 if (! -e $filename) {
1325 return;
1328 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1329 my $dirname=dirname($filename);
1330 my $is_mfc=0;
1331 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1332 $is_mfc=1;
1335 print " $filename\n";
1336 #FIXME:assuming that because there is a .bak file, this is what we want is
1337 #probably flawed. Or is it???
1338 if (! -e "$filename.bak") {
1339 if (!copy("$filename","$filename.bak")) {
1340 print STDERR "error: unable to make a backup of $filename:\n";
1341 print STDERR " $!\n";
1342 return;
1345 if (!open(FILEI,"$filename.bak")) {
1346 print STDERR "error: unable to open $filename.bak for reading:\n";
1347 print STDERR " $!\n";
1348 return;
1350 if (!open(FILEO,">$filename")) {
1351 print STDERR "error: unable to open $filename for writing:\n";
1352 print STDERR " $!\n";
1353 return;
1355 my $line=0;
1356 my $modified=0;
1357 my $rc_block_depth=0;
1358 my $rc_textinclude_state=0;
1359 my @pack_stack;
1360 while (<FILEI>) {
1361 # Remove any trailing CtrlZ, which isn't strictly in the file
1362 if (/\x1A/) {
1363 s/\x1A//;
1364 last if (/^$/)
1366 $line++;
1367 s/\r\n$/\n/;
1368 if (!/\n$/) {
1369 # Make sure all files are '\n' terminated
1370 $_ .= "\n";
1372 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
1373 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1374 # the RC files it generates (even in non-MFC projects). So we replace
1375 # it with 'winres.h' its very close standard cousin so that non MFC
1376 # projects can compile in Wine without the MFC sources.
1377 my $warning="mfc:afxres.h";
1378 if (!defined $warnings{$warning}) {
1379 $warnings{$warning}="1";
1380 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winres.h'\n";
1381 print STDERR "warning: the above warning is issued only once\n";
1383 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
1384 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winres.h' */\n";
1385 print FILEO "$1$2\"winres.h\"$'";
1386 $modified=1;
1388 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1389 my $from_file=($2 eq "<"?"":$dirname);
1390 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1391 print FILEO "$1$2$real_include_name$4$'";
1392 $modified|=($real_include_name ne $3);
1394 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
1395 # Pragma pack handling
1397 # pack_stack is an array of references describing the stack of
1398 # pack directives currently in effect. Each directive if described
1399 # by a reference to an array containing:
1400 # - "push" for pack(push,...) directives, "" otherwise
1401 # - the directive's identifier at index 1
1402 # - the directive's alignement value at index 2
1404 # Don't believe a word of what the documentation says: it's all wrong.
1405 # The code below is based on the actual behavior of Visual C/C++ 6.
1406 my $pack_indent=$1;
1407 my $pack_header=$2;
1408 if (/^(\))/) {
1409 # pragma pack()
1410 # Pushes the default stack alignment
1411 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1412 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1413 print_pack($pack_indent,4,$');
1414 push @pack_stack, [ "", "", 4 ];
1416 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
1417 # pragma pack(pop)
1418 # pragma pack(pop,n)
1419 # Goes up the stack until it finds a pack(push,...), and pops it
1420 # Ignores any pack(n) entry
1421 # Issues a warning if the pack is of the form pack(push,label)
1422 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1423 my $pack_comment=$';
1424 $pack_comment =~ s/^\s*//;
1425 if ($pack_comment ne "") {
1426 print FILEO "$pack_indent$pack_comment";
1428 while (1) {
1429 my $alignment=pop @pack_stack;
1430 if (!defined $alignment) {
1431 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
1432 last;
1434 if (@$alignment[1]) {
1435 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
1437 print FILEO "$pack_indent#include <poppack.h>\n";
1438 if (@$alignment[0]) {
1439 last;
1443 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
1444 # pragma pack(pop,label[,n])
1445 # Goes up the stack until finding a pack(push,...) and pops it.
1446 # 'n', if specified, is ignored.
1447 # Ignores any pack(n) entry
1448 # Issues a warning if the label of the pack does not match,
1449 # or if it is in fact a pack(push,n)
1450 my $label=$2;
1451 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1452 my $pack_comment=$';
1453 $pack_comment =~ s/^\s*//;
1454 if ($pack_comment ne "") {
1455 print FILEO "$pack_indent$pack_comment";
1457 while (1) {
1458 my $alignment=pop @pack_stack;
1459 if (!defined $alignment) {
1460 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
1461 last;
1463 if (@$alignment[1] and @$alignment[1] ne $label) {
1464 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
1466 print FILEO "$pack_indent#include <poppack.h>\n";
1467 if (@$alignment[0]) {
1468 last;
1472 } elsif (/^(push\s*\))/) {
1473 # pragma pack(push)
1474 # Push the current alignment
1475 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1476 if (@pack_stack > 0) {
1477 my $alignment=$pack_stack[$#pack_stack];
1478 print_pack($pack_indent,@$alignment[2],$');
1479 push @pack_stack, [ "push", "", @$alignment[2] ];
1480 } else {
1481 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1482 print_pack($pack_indent,4,$');
1483 push @pack_stack, [ "push", "", 4 ];
1486 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
1487 # pragma pack([push,]n)
1488 # Push new alignment n
1489 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1490 print_pack($pack_indent,$3,"$'");
1491 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
1493 } elsif (/^((\w+)\s*\))/) {
1494 # pragma pack(label)
1495 # label must in fact be a macro that resolves to an integer
1496 # Then behaves like 'pragma pack(n)'
1497 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1498 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
1499 print_pack($pack_indent,4,$');
1500 push @pack_stack, [ "", "", 4 ];
1502 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
1503 # pragma pack(push,label[,n])
1504 # Pushes a new label on the stack. It is possible to push the same
1505 # label multiple times. If 'n' is omitted then the alignment is
1506 # unchanged. Otherwise it becomes 'n'.
1507 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1508 my $size;
1509 if (defined $4) {
1510 $size=$4;
1511 } elsif (@pack_stack > 0) {
1512 my $alignment=$pack_stack[$#pack_stack];
1513 $size=@$alignment[2];
1514 } else {
1515 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1516 $size=4;
1518 print_pack($pack_indent,$size,$');
1519 push @pack_stack, [ "push", $2, $size ];
1521 } else {
1522 # pragma pack(??? -> What's that?
1523 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
1524 print FILEO "$pack_indent$pack_header$_";
1527 $modified=1;
1529 } elsif ($is_rc) {
1530 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]+)([\">]?)/) {
1531 my $from_file=($5 eq "<"?"":$dirname);
1532 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
1533 print FILEO "$1$5$real_include_name$7$'";
1534 $modified|=($real_include_name ne $6);
1536 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1537 my $from_file=($2 eq "<"?"":$dirname);
1538 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1539 print FILEO "$1$2$real_include_name$4$'";
1540 $modified|=($real_include_name ne $3);
1542 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
1543 $rc_textinclude_state=1;
1544 print FILEO;
1546 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
1547 print FILEO "$1winres.h$2$'";
1548 $modified=1;
1550 } elsif (/^\s*BEGIN(\W.*)?$/) {
1551 $rc_textinclude_state|=2;
1552 $rc_block_depth++;
1553 print FILEO;
1555 } elsif (/^\s*END(\W.*)?$/) {
1556 $rc_textinclude_state=0;
1557 if ($rc_block_depth>0) {
1558 $rc_block_depth--;
1560 print FILEO;
1562 } else {
1563 print FILEO;
1566 } else {
1567 print FILEO;
1571 close(FILEI);
1572 close(FILEO);
1573 if ($opt_backup == 0 or $modified == 0) {
1574 if (!unlink("$filename.bak")) {
1575 print STDERR "error: unable to delete $filename.bak:\n";
1576 print STDERR " $!\n";
1582 # Analyzes each source file in turn to find and correct issues
1583 # that would cause it not to compile.
1584 sub fix_source()
1586 print "Fixing the source files...\n";
1587 foreach my $project (@projects) {
1588 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
1589 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1590 next;
1592 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
1593 fix_file($source,$project,$target);
1601 #####
1603 # File generation
1605 #####
1608 # Generates a target's .spec file
1609 sub generate_spec_file($$$)
1611 return if ($opt_no_generated_specs);
1613 my $path=$_[0];
1614 my $target=$_[1];
1615 my $project_settings=$_[2];
1617 my $basename=@$target[$T_NAME];
1618 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1619 $basename.="_wrapper";
1622 if (!open(FILEO,">$path$basename.spec")) {
1623 print STDERR "error: could not open \"$path$basename.spec\" for writing\n";
1624 print STDERR " $!\n";
1625 return;
1628 # Don't forget to export the 'Main' function for wrapped executables,
1629 # except for MFC ones!
1630 if ((@$target[$T_FLAGS]&($TF_WRAP|$TF_WRAPPER|$TF_MFC)) == $TF_WRAP) {
1631 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1632 print FILEO "\n@ stdcall @$target[$T_INIT](long long ptr long) @$target[$T_INIT]\n";
1633 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1634 print FILEO "\n@ stdcall @$target[$T_INIT](long ptr ptr) @$target[$T_INIT]\n";
1635 } else {
1636 print FILEO "\n@ stdcall @$target[$T_INIT](ptr long ptr) @$target[$T_INIT]\n";
1640 close(FILEO);
1644 # Generates a target's wrapper file
1645 sub generate_wrapper_file($$)
1647 my $path=$_[0];
1648 my $target=$_[1];
1649 my $app_name=@$target[$T_NAME];
1650 my $wrapper_name=$app_name;
1651 $app_name=~ s/\.exe$/\.dll/;
1653 return generate_from_template("$path${wrapper_name}_wrapper.c","wrapper.c",[
1654 ["APP_NAME",$app_name],
1655 ["APP_TYPE",(@$target[$T_TYPE]==$TT_GUIEXE?"GUIEXE":"CUIEXE")],
1656 ["APP_INIT",(@$target[$T_TYPE]==$TT_GUIEXE?"\"WinMain\"":"\"main\"")],
1657 ["APP_MFC",(@$target[$T_FLAGS] & $TF_MFC?"\"mfc\"":"NULL")]]);
1661 # A convenience function to generate all the lists (defines,
1662 # C sources, C++ source, etc.) in the Makefile
1663 sub generate_list($$$;$)
1665 my $name=$_[0];
1666 my $last=$_[1];
1667 my $list=$_[2];
1668 my $data=$_[3];
1669 my $first=$name;
1671 if ($name) {
1672 printf FILEO "%-22s=",$name;
1674 if (defined $list) {
1675 foreach my $item (@$list) {
1676 my $value;
1677 if (defined $data) {
1678 $value=&$data($item);
1679 } else {
1680 $value=$item;
1682 if ($value ne "") {
1683 if ($first) {
1684 print FILEO " $value";
1685 $first=0;
1686 } else {
1687 print FILEO " \\\n\t\t\t$value";
1692 if ($last) {
1693 print FILEO "\n";
1698 # Generates a project's Makefile.in and all the target files
1699 sub generate_project_files($)
1701 my $project=$_[0];
1702 my $project_settings=@$project[$P_SETTINGS];
1703 my @dll_list=();
1704 my @exe_list=();
1706 # Then sort the targets and separate the libraries from the programs
1707 foreach my $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
1708 if (@$target[$T_TYPE] == $TT_DLL) {
1709 push @dll_list,$target;
1710 } else {
1711 push @exe_list,$target;
1714 @$project[$P_TARGETS]=[];
1715 push @{@$project[$P_TARGETS]}, @dll_list;
1716 push @{@$project[$P_TARGETS]}, @exe_list;
1718 if (!open(FILEO,">@$project[$P_PATH]Makefile.in")) {
1719 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile.in\" for writing\n";
1720 print STDERR " $!\n";
1721 return;
1724 print FILEO "### Generated by Winemaker\n";
1725 print FILEO "\n\n";
1727 print FILEO "### Generic autoconf variables\n\n";
1728 generate_list("TOPSRCDIR",1,[ "\@top_srcdir\@" ]);
1729 my $dotdotpath=@$project[$P_PATH];
1730 $dotdotpath =~ s%[^/]+%..%g;
1731 $dotdotpath =~ s%/$%%;
1732 $dotdotpath = "." if ($dotdotpath eq "");
1733 generate_list("TOPOBJDIR",1,[ $dotdotpath ]);
1734 generate_list("SRCDIR",1,[ "\@srcdir\@" ]);
1735 generate_list("VPATH",1,[ "\@srcdir\@" ]);
1736 print FILEO "\n";
1737 if (@$project[$P_PATH] eq "") {
1738 # This is the main project. It is also responsible for recursively
1739 # calling the other projects
1740 generate_list("SUBDIRS",1,\@projects,sub
1742 if ($_[0] != \@main_project) {
1743 my $subdir=@{$_[0]}[$P_PATH];
1744 $subdir =~ s+/$++;
1745 return $subdir;
1747 # Eliminating the main project by returning undefined!
1750 if (@{@$project[$P_TARGETS]} > 0) {
1751 generate_list("DLLS",1,\@dll_list,sub
1753 return @{$_[0]}[$T_NAME];
1755 generate_list("EXES",1,\@exe_list,sub
1757 return "@{$_[0]}[$T_NAME]";
1759 print FILEO "\n\n\n";
1761 print FILEO "### Common settings\n\n";
1762 # Make it so that the project-wide settings override the global settings
1763 generate_list("DEFINES",1,@$project_settings[$T_DEFINES]);
1764 generate_list("INCLUDE_PATH",1,@$project_settings[$T_INCLUDE_PATH]);
1765 generate_list("DLL_PATH",1,@$project_settings[$T_DLL_PATH]);
1766 generate_list("LIBRARY_PATH",1,@$project_settings[$T_LIBRARY_PATH]);
1767 generate_list("LIBRARIES",1,@$project_settings[$T_LIBRARIES]);
1768 print FILEO "\n\n";
1770 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
1771 @{@$project_settings[$T_SOURCES_CXX]}+
1772 @{@$project_settings[$T_SOURCES_RC]};
1773 my $no_extra=($extra_source_count == 0);
1774 if (!$no_extra) {
1775 print FILEO "### Extra source lists\n\n";
1776 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
1777 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
1778 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
1779 print FILEO "\n";
1780 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
1781 print FILEO "\n\n\n";
1784 # Iterate over all the targets...
1785 foreach my $target (@{@$project[$P_TARGETS]}) {
1786 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
1787 my $appmode;
1788 my $basemodule=@$target[$T_NAME];
1789 my $canon=canonize("@$target[$T_NAME]");
1790 $canon =~ s+_so$++;
1791 if (@$target[$T_TYPE] == $TT_CUIEXE) {
1792 $appmode = "cui";
1793 $basemodule =~ s/\.exe$//;
1794 } elsif (@$target[$T_TYPE] == $TT_GUIEXE) {
1795 $appmode = "gui";
1796 $basemodule =~ s/\.exe$//;
1797 } else {
1798 $appmode = "";
1799 $basemodule =~ s/\.dll$//;
1802 generate_list("${canon}_MODULE",1,[@$target[$T_NAME]]);
1803 generate_list("${canon}_BASEMODULE",1,[$basemodule]);
1804 generate_list("${canon}_APPMODE",1,[$appmode]);
1805 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
1806 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
1807 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
1808 generate_list("${canon}_SPEC_SRCS",1,[ (@$target[$T_TYPE] == $TT_DLL?"@$target[$T_NAME].spec":"") ]);
1809 generate_list("${canon}_DLL_PATH",1,@$target[$T_DLL_PATH]);
1810 generate_list("${canon}_DLLS",1,@$target[$T_DLLS]);
1811 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]);
1812 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]);
1813 generate_list("${canon}_DEPENDS",1,@$target[$T_DEPENDS]);
1814 print FILEO "\n";
1815 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(EXTRA_OBJS)"]);
1816 print FILEO "\n\n\n";
1818 print FILEO "### Global source lists\n\n";
1819 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
1821 my $canon=canonize(@{$_[0]}[$T_NAME]);
1822 $canon =~ s+_so$++;
1823 return "\$(${canon}_C_SRCS)";
1825 if (!$no_extra) {
1826 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
1828 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
1830 my $canon=canonize(@{$_[0]}[$T_NAME]);
1831 $canon =~ s+_so$++;
1832 return "\$(${canon}_CXX_SRCS)";
1834 if (!$no_extra) {
1835 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
1837 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
1839 my $canon=canonize(@{$_[0]}[$T_NAME]);
1840 $canon =~ s+_so$++;
1841 return "\$(${canon}_RC_SRCS)";
1843 if (!$no_extra) {
1844 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
1846 generate_list("SPEC_SRCS",1,@$project[$P_TARGETS],sub
1848 my $canon=canonize(@{$_[0]}[$T_NAME]);
1849 $canon =~ s+_so$++;
1850 return "\$(${canon}_SPEC_SRCS)";
1853 print FILEO "\n\n\n";
1855 print FILEO "### Generic autoconf targets\n\n";
1856 print FILEO "all:";
1857 if (@$project[$P_PATH] eq "") {
1858 print FILEO " wineapploader";
1859 print FILEO " \$(SUBDIRS)";
1861 if (@{@$project[$P_TARGETS]} > 0) {
1862 print FILEO " \$(DLLS:%=%.so) \$(EXES:%=%.so)";
1864 print FILEO "\n\n";
1865 if (@$project[$P_PATH] eq "") {
1866 print FILEO "wineapploader: wineapploader.in\n";
1867 print FILEO "\tsed -e 's,\@bindir\\\@,\$(bindir),g' " .
1868 "-e 's,\@winelibdir\\\@,.,g' " .
1869 "\$(SRCDIR)/wineapploader.in >\$\@ || \$(RM) \$\@\n";
1870 print FILEO "\n";
1872 print FILEO "\@MAKE_RULES\@\n";
1873 print FILEO "\n";
1874 print FILEO "install::\n";
1875 if (@$project[$P_PATH] eq "") {
1876 # This is the main project. It is also responsible for recursively
1877 # calling the other projects
1878 print FILEO "\t_list=\"\$(SUBDIRS)\"; for i in \$\$_list; do (cd \$\$i; \$(MAKE) install) || exit 1; done\n";
1880 if (@{@$project[$P_TARGETS]} > 0) {
1881 print FILEO "\t_list=\"\$(EXES:%.exe=%)\"; for i in \$\$_list; do \$(INSTALL_SCRIPT) \$\$i \$(bindir); done\n";
1882 print FILEO "\t_list=\"\$(EXES:%=%.so) \$(DLLS:%=%.so)\"; for i in \$\$_list; do \$(INSTALL_PROGRAM) \$\$i \$(dlldir); done\n";
1884 print FILEO "\n";
1885 print FILEO "uninstall::\n";
1886 if (@$project[$P_PATH] eq "") {
1887 # This is the main project. It is also responsible for recursively
1888 # calling the other projects
1889 print FILEO "\t_list=\"\$(SUBDIRS)\"; for i in \$\$_list; do (cd \$\$i; \$(MAKE) uninstall) || exit 1; done\n";
1891 if (@{@$project[$P_TARGETS]} > 0) {
1892 print FILEO "\t_list=\"\$(EXES:%.exe=%)\"; for i in \$\$_list; do \$(RM) \$(bindir)/\$\$i;done\n";
1893 print FILEO "\t_list=\"\$(EXES:%=%.so) \$(DLLS:%=%.so)\"; for i in \$\$_list; do \$(RM) \$(dlldir)/\$\$i;done\n";
1895 print FILEO "\n";
1896 print FILEO "clean::\n";
1897 print FILEO "\t\$(RM)";
1898 if (@$project[$P_PATH] eq "") {
1899 print FILEO " wineapploader";
1901 if (@{@$project[$P_TARGETS]} > 0) {
1902 print FILEO " \$(EXES:%.exe=%)";
1904 print FILEO "\n\n";
1906 if (@{@$project[$P_TARGETS]} > 0) {
1907 print FILEO "### Target specific build rules\n\n";
1908 foreach my $target (@{@$project[$P_TARGETS]}) {
1909 my $canon=canonize("@$target[$T_NAME]");
1910 my $mode;
1911 my $all_dlls;
1912 my $all_libs;
1914 $canon =~ s/_so$//;
1915 if ((@$target[$T_TYPE]==$TT_GUIEXE) || (@$target[$T_TYPE]==$TT_CUIEXE)) {
1916 $mode = "--exe \$(${canon}_MODULE) -m\$(${canon}_APPMODE)";
1917 } else {
1918 $mode = "";
1921 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1922 $all_dlls="\$(${canon}_DLLS:%=-l%)";
1923 $all_libs="\$(${canon}_LIBRARIES:%=-l%) \$(WINE_LIBRARIES)";
1924 } else {
1925 $all_dlls="\$(${canon}_DLLS:%=-l%) \$(GLOBAL_DLLS:%=-l%)";
1926 $all_libs="\$(${canon}_LIBRARIES:%=-l%) \$(ALL_LIBRARIES)";
1929 print FILEO "\$(${canon}_MODULE).spec.c: \$(${canon}_SPEC_SRCS) \$(${canon}_RC_SRCS:.rc=.res) \$(${canon}_OBJS)\n";
1930 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";
1931 print FILEO "\n";
1932 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_MODULE).spec.o \$(${canon}_OBJS) \$(${canon}_DEPENDS)\n";
1933 if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
1934 print FILEO "\t\$(LDXXSHARED)";
1935 } else {
1936 print FILEO "\t\$(LDSHARED)";
1938 print FILEO " \$(LDDLLFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_MODULE).spec.o \$(${canon}_LIBRARY_PATH) \$(ALL_LIBRARY_PATH) $all_libs \$(LIBS)\n";
1939 if (@$target[$T_TYPE] != $TT_DLL) {
1940 print FILEO "\ttest -f \$(${canon}_BASEMODULE) || \$(INSTALL_SCRIPT) wineapploader \$(${canon}_BASEMODULE)\n";
1942 print FILEO "\n\n";
1945 close(FILEO);
1947 foreach my $target (@{@$project[$P_TARGETS]}) {
1948 if (@$target[$T_TYPE] == $TT_DLL) {
1949 generate_spec_file(@$project[$P_PATH],$target,$project_settings);
1951 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1952 generate_wrapper_file(@$project[$P_PATH],$target);
1958 # Perform the replacements in the template configure files
1959 # Return 1 for success, 0 for failure
1960 sub generate_from_template($$;$)
1962 my $filename=$_[0];
1963 my $template=$_[1];
1964 my $substitutions=$_[2];
1966 if (!defined $templates{$template}) {
1967 print STDERR "winemaker: internal error: No template called '$template'\n";
1968 return 0;
1971 if (!open(FILEO,">$filename")) {
1972 print STDERR "error: unable to open \"$filename\" for writing:\n";
1973 print STDERR " $!\n";
1974 return 0;
1976 my $warned;
1977 foreach my $line (@{$templates{$template}}) {
1978 if ($line =~ /(\#\#WINEMAKER_[A-Z_]+\#\#)/) {
1979 if (defined $substitutions) {
1980 foreach my $pattern (@$substitutions) {
1981 $line =~ s%\#\#WINEMAKER_@$pattern[0]\#\#%@$pattern[1]%;
1984 if (!$warned and $line =~ /(\#\#WINEMAKER_[A-Z_]+\#\#)/) {
1985 print STDERR "warning: no value was provided for template $1 in \"$filename\"\n";
1986 $warned=1;
1989 print FILEO $line;
1991 close(FILEO);
1992 return 1;
1996 # Generates the global files:
1997 # configure
1998 # configure.ac
1999 # Make.rules.in
2000 # wineapploader.in
2001 sub generate_global_files()
2003 my @include_path;
2004 foreach my $path (@{$global_settings[$T_INCLUDE_PATH]}) {
2005 if ($path !~ /^-L/ or is_absolute($')) {
2006 push @include_path, $path;
2007 } else {
2008 push @include_path, "-L\$(TOPSRCDIR)/$'";
2011 my @dll_path;
2012 foreach my $path (@{$global_settings[$T_DLL_PATH]}) {
2013 if ($path !~ /^-L/ or is_absolute($')) {
2014 push @dll_path, $path;
2015 } else {
2016 push @dll_path, "-L\$(TOPSRCDIR)/$'";
2019 my @library_path;
2020 foreach my $path (@{$global_settings[$T_LIBRARY_PATH]}) {
2021 if ($path !~ /^-L/ or is_absolute($')) {
2022 push @library_path, $path;
2023 } else {
2024 push @library_path, "-L\$(TOPSRCDIR)/$'";
2027 generate_from_template("Make.rules.in","Make.rules.in",[
2028 ["DEFINES", join(" ", @{$global_settings[$T_DEFINES]}) ],
2029 ["INCLUDE_PATH", join(" ", @include_path) ],
2030 ["DLL_PATH", join(" ", @dll_path) ],
2031 ["DLLS", join(" ", @{$global_settings[$T_DLLS]}) ],
2032 ["LIBRARY_PATH", join(" ", @library_path) ],
2033 ["LIBRARIES", join(" ", @{$global_settings[$T_LIBRARIES]}) ]]);
2034 generate_from_template("wineapploader.in","wineapploader.in");
2036 # Get the name of a source file for configure.ac
2037 my $a_source_file;
2038 search_a_file: foreach my $project (@projects) {
2039 foreach my $target (@{@$project[$P_TARGETS]}, @$project[$P_SETTINGS]) {
2040 $a_source_file=@{@$target[$T_SOURCES_C]}[0];
2041 if (!defined $a_source_file) {
2042 $a_source_file=@{@$target[$T_SOURCES_CXX]}[0];
2044 if (!defined $a_source_file) {
2045 $a_source_file=@{@$target[$T_SOURCES_RC]}[0];
2047 if (defined $a_source_file) {
2048 $a_source_file="@$project[$P_PATH]$a_source_file";
2049 last search_a_file;
2053 if (!defined $a_source_file) {
2054 $a_source_file="Makefile.in";
2056 generate_from_template("configure.ac","configure.ac",[
2057 ["PROJECTS",join("\n",map { "@$_[$P_PATH]Makefile" } @projects)],
2058 ["SOURCE","$a_source_file"],
2059 ["NEEDS_MFC","$needs_mfc"]]);
2060 system("autoconf configure.ac > configure");
2062 # Add execute permission to configure for whoever has the right to read it
2063 my @st=stat("configure");
2064 if (@st) {
2065 my $mode=$st[2];
2066 $mode|=($mode & 0444) >>2;
2067 chmod($mode,"configure");
2068 } else {
2069 print "warning: could not generate the configure script. You need to run autoconf\n";
2075 sub generate_read_templates()
2077 my $file;
2079 while (<DATA>) {
2080 if (/^--- ((\w\.?)+) ---$/) {
2081 my $filename=$1;
2082 if (defined $templates{$filename}) {
2083 print STDERR "winemaker: internal error: There is more than one template for $filename\n";
2084 undef $file;
2085 } else {
2086 $file=[];
2087 $templates{$filename}=$file;
2089 } elsif (defined $file) {
2090 push @$file, $_;
2096 # This is where we finally generate files. In fact this method does not
2097 # do anything itself but calls the methods that do the actual work.
2098 sub generate()
2100 print "Generating project files...\n";
2101 generate_read_templates();
2102 generate_global_files();
2104 foreach my $project (@projects) {
2105 my $path=@$project[$P_PATH];
2106 if ($path eq "") {
2107 $path=".";
2108 } else {
2109 $path =~ s+/$++;
2111 print " $path\n";
2112 generate_project_files($project);
2118 #####
2120 # Option defaults
2122 #####
2124 $opt_backup=1;
2125 $opt_lower=$OPT_LOWER_UPPERCASE;
2126 $opt_lower_include=1;
2128 # $opt_work_dir=<undefined>
2129 # $opt_single_target=<undefined>
2130 $opt_target_type=$TT_GUIEXE;
2131 $opt_flags=0;
2132 $opt_is_interactive=$OPT_ASK_NO;
2133 $opt_ask_project_options=$OPT_ASK_NO;
2134 $opt_ask_target_options=$OPT_ASK_NO;
2135 $opt_no_generated_files=0;
2136 $opt_no_generated_specs=0;
2137 $opt_no_source_fix=0;
2138 $opt_no_banner=0;
2142 #####
2144 # Main
2146 #####
2148 sub print_banner()
2150 print "Winemaker $version\n";
2151 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2154 sub usage()
2156 print_banner();
2157 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2158 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2159 print STDERR " [--lower-include|--nolower-include]\n";
2160 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2161 print STDERR " [--wrap|--nowrap] [--mfc|--nomfc]\n";
2162 print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2163 print STDERR " [--nodlls] [--interactive] [--single-target name]\n";
2164 print STDERR " [--generated-files|--nogenerated-files] [--nogenerated-specs]\n";
2165 print STDERR " work_directory\n";
2166 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2167 print STDERR "the specified directory so that they can be compiled with Winelib. During this\n";
2168 print STDERR "process it will modify and rename some of the files in that directory.\n";
2169 print STDERR "\tPlease read the manual page before use.\n";
2170 exit (2);
2173 target_init(\@global_settings);
2175 while (@ARGV>0) {
2176 my $arg=shift @ARGV;
2177 # General options
2178 if ($arg eq "--nobanner") {
2179 $opt_no_banner=1;
2180 } elsif ($arg eq "--backup") {
2181 $opt_backup=1;
2182 } elsif ($arg eq "--nobackup") {
2183 $opt_backup=0;
2184 } elsif ($arg eq "--single-target") {
2185 $opt_single_target=shift @ARGV;
2186 } elsif ($arg eq "--lower-none") {
2187 $opt_lower=$OPT_LOWER_NONE;
2188 } elsif ($arg eq "--lower-all") {
2189 $opt_lower=$OPT_LOWER_ALL;
2190 } elsif ($arg eq "--lower-uppercase") {
2191 $opt_lower=$OPT_LOWER_UPPERCASE;
2192 } elsif ($arg eq "--lower-include") {
2193 $opt_lower_include=1;
2194 } elsif ($arg eq "--nolower-include") {
2195 $opt_lower_include=0;
2196 } elsif ($arg eq "--nosource-fix") {
2197 $opt_no_source_fix=1;
2198 } elsif ($arg eq "--generated-files") {
2199 $opt_no_generated_files=0;
2200 } elsif ($arg eq "--nogenerated-files") {
2201 $opt_no_generated_files=1;
2202 } elsif ($arg eq "--nogenerated-specs") {
2203 $opt_no_generated_specs=1;
2205 } elsif ($arg =~ /^-D/) {
2206 push @{$global_settings[$T_DEFINES]},$arg;
2207 } elsif ($arg =~ /^-I/) {
2208 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2209 } elsif ($arg =~ /^-P/) {
2210 push @{$global_settings[$T_DLL_PATH]},"-L$'";
2211 } elsif ($arg =~ /^-i/) {
2212 my $dllname = $';
2213 if ($dllname =~ /^msvcrt$/) {
2214 push @{$global_settings[$T_INCLUDE_PATH]},"-I\$(WINE_INCLUDE_ROOT)/msvcrt";
2216 push @{$global_settings[$T_DLLS]},$dllname;
2217 } elsif ($arg =~ /^-L/) {
2218 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2219 } elsif ($arg =~ /^-l/) {
2220 push @{$global_settings[$T_LIBRARIES]},$';
2222 # 'Source'-based method options
2223 } elsif ($arg eq "--dll") {
2224 $opt_target_type=$TT_DLL;
2225 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2226 $opt_target_type=$TT_GUIEXE;
2227 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2228 $opt_target_type=$TT_CUIEXE;
2229 } elsif ($arg eq "--interactive") {
2230 $opt_is_interactive=$OPT_ASK_YES;
2231 $opt_ask_project_options=$OPT_ASK_YES;
2232 $opt_ask_target_options=$OPT_ASK_YES;
2233 } elsif ($arg eq "--wrap") {
2234 $opt_flags|=$TF_WRAP;
2235 } elsif ($arg eq "--nowrap") {
2236 $opt_flags&=~$TF_WRAP;
2237 } elsif ($arg eq "--mfc") {
2238 $opt_flags|=$TF_MFC;
2239 $needs_mfc=1;
2240 } elsif ($arg eq "--nomfc") {
2241 $opt_flags&=~$TF_MFC;
2242 $opt_flags|=$TF_NOMFC;
2243 $needs_mfc=0;
2244 } elsif ($arg eq "--nodlls") {
2245 $opt_flags|=$TF_NODLLS;
2247 # Catch errors
2248 } else {
2249 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2250 if (!defined $opt_work_dir) {
2251 $opt_work_dir=$arg;
2252 } else {
2253 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2254 usage();
2256 } else {
2257 usage();
2261 if ($opt_flags & $TF_MFC && $opt_target_type != $TT_DLL) {
2262 print STDERR "info: option --mfc requires --wrap\n";
2263 $opt_flags |= $TF_WRAP;
2267 if (!defined $opt_work_dir) {
2268 print STDERR "error: you must specify the directory containing the sources to be converted\n";
2269 usage();
2270 } elsif (!chdir $opt_work_dir) {
2271 print STDERR "error: could not chdir to the work directory\n";
2272 print STDERR " $!\n";
2273 usage();
2276 if ($opt_no_banner == 0) {
2277 print_banner();
2280 project_init(\@main_project,"");
2282 # Fix the file and directory names
2283 fix_file_and_directory_names(".");
2285 # Scan the sources to identify the projects and targets
2286 source_scan();
2288 # Create targets for wrappers, etc.
2289 postprocess_targets();
2291 # Fix the source files
2292 if (! $opt_no_source_fix) {
2293 fix_source();
2296 # Generate the Makefile and the spec file
2297 if (! $opt_no_generated_files) {
2298 generate();
2302 __DATA__
2303 --- configure.ac ---
2304 dnl Process this file with autoconf to produce a configure script.
2305 dnl Author: Michael Patra <micky@marie.physik.tu-berlin.de>
2306 dnl <patra@itp1.physik.tu-berlin.de>
2307 dnl Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2309 AC_REVISION([configure.ac 1.00])
2310 AC_INIT(##WINEMAKER_SOURCE##)
2312 NEEDS_MFC=##WINEMAKER_NEEDS_MFC##
2314 dnl **** Command-line arguments ****
2316 AC_SUBST(OPTIONS)
2318 dnl **** Check for some programs ****
2320 AC_PROG_MAKE_SET
2321 AC_PROG_CC
2322 AC_PROG_CXX
2323 AC_PROG_CPP
2324 AC_PROG_LN_S
2326 dnl **** Check for some libraries ****
2328 dnl Check for -lm for BeOS
2329 AC_CHECK_LIB(m,sqrt)
2330 dnl Check for -lw for Solaris
2331 AC_CHECK_LIB(w,iswalnum)
2332 dnl Check for -lnsl for Solaris
2333 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))
2334 dnl Check for -lsocket for Solaris
2335 AC_CHECK_FUNCS(connect,,AC_CHECK_LIB(socket,connect))
2337 dnl **** Check for gcc strength-reduce bug ****
2339 if test "x${GCC}" = "xyes"
2340 then
2341 AC_CACHE_CHECK( "for gcc strength-reduce bug", ac_cv_c_gcc_strength_bug,
2342 AC_TRY_RUN([
2343 int main(void) {
2344 static int Array[[3]];
2345 unsigned int B = 3;
2346 int i;
2347 for(i=0; i<B; i++) Array[[i]] = i - 3;
2348 exit( Array[[1]] != -2 );
2350 ac_cv_c_gcc_strength_bug="no",
2351 ac_cv_c_gcc_strength_bug="yes",
2352 ac_cv_c_gcc_strength_bug="yes") )
2353 if test "$ac_cv_c_gcc_strength_bug" = "yes"
2354 then
2355 CFLAGS="$CFLAGS -fno-strength-reduce"
2359 dnl **** Check for working dll ****
2361 LDSHARED=""
2362 LDXXSHARED=""
2363 LDDLLFLAGS=""
2364 AC_CACHE_CHECK("whether we can build a Linux dll",
2365 ac_cv_c_dll_linux,
2366 [saved_cflags=$CFLAGS
2367 CFLAGS="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0,-Bsymbolic"
2368 AC_TRY_LINK(,[return 1],ac_cv_c_dll_linux="yes",ac_cv_c_dll_linux="no")
2369 CFLAGS=$saved_cflags
2371 if test "$ac_cv_c_dll_linux" = "yes"
2372 then
2373 LDSHARED="\$(CC) -shared"
2374 LDXXSHARED="\$(CXX) -shared"
2375 LDDLLFLAGS="-Wl,-Bsymbolic"
2376 else
2377 AC_CACHE_CHECK(whether we can build a UnixWare (Solaris) dll,
2378 ac_cv_c_dll_unixware,
2379 [saved_cflags=$CFLAGS
2380 CFLAGS="$CFLAGS -fPIC -Wl,-G,-h,conftest.so.1.0,-B,symbolic"
2381 AC_TRY_LINK(,[return 1],ac_cv_c_dll_unixware="yes",ac_cv_c_dll_unixware="no")
2382 CFLAGS=$saved_cflags
2384 if test "$ac_cv_c_dll_unixware" = "yes"
2385 then
2386 LDSHARED="\$(CC) -Wl,-G"
2387 LDXXSHARED="\$(CXX) -Wl,-G"
2388 LDDLLFLAGS="-Wl,-B,symbolic"
2389 else
2390 AC_CACHE_CHECK("whether we can build a NetBSD dll",
2391 ac_cv_c_dll_netbsd,
2392 [saved_cflags=$CFLAGS
2393 CFLAGS="$CFLAGS -fPIC -Wl,-Bshareable,-Bforcearchive"
2394 AC_TRY_LINK(,[return 1],ac_cv_c_dll_netbsd="yes",ac_cv_c_dll_netbsd="no")
2395 CFLAGS=$saved_cflags
2397 if test "$ac_cv_c_dll_netbsd" = "yes"
2398 then
2399 LDSHARED="\$(CC) -Wl,-Bshareable,-Bforcearchive"
2400 LDXXSHARED="\$(CXX) -Wl,-Bshareable,-Bforcearchive"
2401 LDDLLFLAGS="" #FIXME
2405 if test "$ac_cv_c_dll_linux" = "no" -a "$ac_cv_c_dll_unixware" = "no" -a "$ac_cv_c_dll_netbsd" = "no"
2406 then
2407 AC_MSG_ERROR([Could not find how to build a dynamically linked library])
2410 CFLAGS="$CFLAGS -fPIC"
2412 AC_SUBST(LDSHARED)
2413 AC_SUBST(LDXXSHARED)
2414 AC_SUBST(LDDLLFLAGS)
2416 dnl *** check for the need to define __i386__
2418 AC_CACHE_CHECK("whether we need to define __i386__",ac_cv_cpp_def_i386,
2419 AC_EGREP_CPP(yes,[#if (defined(i386) || defined(__i386)) && !defined(__i386__)
2421 #endif],
2422 ac_cv_cpp_def_i386="yes", ac_cv_cpp_def_i386="no"))
2423 if test "$ac_cv_cpp_def_i386" = "yes"
2424 then
2425 CFLAGS="$CFLAGS -D__i386__"
2428 dnl *** check for the need to define __sparc__
2430 AC_CACHE_CHECK("whether we need to define __sparc__",ac_cv_cpp_def_sparc,
2431 AC_EGREP_CPP(yes,[#if (defined(sparc) || defined(__sparc)) && !defined(__sparc__)
2433 #endif],
2434 ac_cv_cpp_def_sparc="yes", ac_cv_cpp_def_sparc="no"))
2435 if test "$ac_cv_cpp_def_sparc" = "yes"
2436 then
2437 CFLAGS="$CFLAGS -D__sparc__"
2438 CXXFLAGS="$CXXFLAGS -D__sparc__"
2441 dnl *** check for the need to define __sun__
2443 AC_CACHE_CHECK("whether we need to define __sun__",ac_cv_cpp_def_sun,
2444 AC_EGREP_CPP(yes,[#if (defined(sun) || defined(__sun)) && !defined(__sun__)
2446 #endif],
2447 ac_cv_cpp_def_sun="yes", ac_cv_cpp_def_sun="no"))
2448 if test "$ac_cv_cpp_def_sun" = "yes"
2449 then
2450 CFLAGS="$CFLAGS -D__sun__"
2451 CXXFLAGS="$CXXFLAGS -D__sun__"
2454 dnl **** Test Winelib-related features of the C++ compiler
2455 AC_LANG_CPLUSPLUS()
2456 if test "x${GCC}" = "xyes"
2457 then
2458 OLDCXXFLAGS="$CXXFLAGS";
2459 CXXFLAGS="-fpermissive";
2460 AC_CACHE_CHECK("for g++ -fpermissive option", has_gxx_permissive,
2461 AC_TRY_COMPILE(,[
2462 for (int i=0;i<2;i++);
2463 i=0;
2465 [has_gxx_permissive="yes"],
2466 [has_gxx_permissive="no"])
2468 CXXFLAGS="-fno-for-scope";
2469 AC_CACHE_CHECK("for g++ -fno-for-scope option", has_gxx_no_for_scope,
2470 AC_TRY_COMPILE(,[
2471 for (int i=0;i<2;i++);
2472 i=0;
2474 [has_gxx_no_for_scope="yes"],
2475 [has_gxx_no_for_scope="no"])
2477 CXXFLAGS="$OLDCXXFLAGS";
2478 if test "$has_gxx_permissive" = "yes"
2479 then
2480 CXXFLAGS="$CXXFLAGS -fpermissive"
2482 if test "$has_gxx_no_for_scope" = "yes"
2483 then
2484 CXXFLAGS="$CXXFLAGS -fno-for-scope"
2487 AC_LANG_C()
2489 dnl **** Test Winelib-related features of the C compiler
2490 dnl none for now
2492 dnl **** Macros for finding a headers/libraries in a collection of places
2494 dnl AC_PATH_FILE(variable,file,action-if-not-found,default-locations)
2495 AC_DEFUN(AC_PATH_FILE,[
2496 AC_MSG_CHECKING([for $2])
2497 AC_CACHE_VAL(ac_cv_pfile_$1,
2499 ac_found=
2500 ac_dummy="ifelse([$4], , , [$4])"
2501 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2502 for ac_dir in $ac_dummy; do
2503 IFS="$ac_save_ifs"
2504 if test -z "$ac_dir"
2505 then
2506 ac_file="$2"
2507 else
2508 ac_file="$ac_dir/$2"
2510 if test -f "$ac_file"
2511 then
2512 ac_found=1
2513 ac_cv_pfile_$1="$ac_dir"
2514 break
2516 done
2517 ifelse([$3],,,[if test -z "$ac_found"
2518 then
2523 $1="$ac_cv_pfile_$1"
2524 if test -n "$ac_found" -o -n "[$]$1"
2525 then
2526 AC_MSG_RESULT([$]$1)
2527 else
2528 AC_MSG_RESULT(no)
2530 AC_SUBST($1)
2533 dnl AC_PATH_HEADER(variable,header,action-if-not-found,default-locations)
2534 dnl Note that the above may set variable to an empty value if the header is
2535 dnl already in the include path
2536 AC_DEFUN(AC_PATH_HEADER,[
2537 AC_MSG_CHECKING([for $2 header])
2538 AC_CACHE_VAL(ac_cv_pheader_$1,
2540 ac_found=
2541 ac_dummy="ifelse([$4], , :/usr/local/include, [$4])"
2542 save_CPPFLAGS="$CPPFLAGS"
2543 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2544 for ac_dir in $ac_dummy; do
2545 IFS="$ac_save_ifs"
2546 if test -z "$ac_dir"
2547 then
2548 CPPFLAGS="$save_CPPFLAGS"
2549 else
2550 CPPFLAGS="-I$ac_dir $save_CPPFLAGS"
2552 AC_TRY_COMPILE([#include <$2>],,ac_found=1;ac_cv_pheader_$1="$ac_dir";break)
2553 done
2554 CPPFLAGS="$save_CPPFLAGS"
2555 ifelse([$3],,,[if test -z "$ac_found"
2556 then
2561 $1="$ac_cv_pheader_$1"
2562 if test -n "$ac_found" -o -n "[$]$1"
2563 then
2564 AC_MSG_RESULT([$]$1)
2565 else
2566 AC_MSG_RESULT(no)
2568 AC_SUBST($1)
2571 dnl AC_PATH_LIBRARY(variable,libraries,extra libs,action-if-not-found,default-locations)
2572 AC_DEFUN(AC_PATH_LIBRARY,[
2573 AC_MSG_CHECKING([for $2])
2574 AC_CACHE_VAL(ac_cv_plibrary_$1,
2576 ac_found=
2577 ac_dummy="ifelse([$5], , :/usr/local/lib, [$5])"
2578 save_LIBS="$LIBS"
2579 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2580 for ac_dir in $ac_dummy; do
2581 IFS="$ac_save_ifs"
2582 if test -z "$ac_dir"
2583 then
2584 LIBS="$2 $3 $save_LIBS"
2585 else
2586 LIBS="-L$ac_dir $2 $3 $save_LIBS"
2588 AC_TRY_LINK(,,ac_found=1;ac_cv_plibrary_$1="$ac_dir";break)
2589 done
2590 LIBS="$save_LIBS"
2591 ifelse([$4],,,[if test -z "$ac_found"
2592 then
2597 $1="$ac_cv_plibrary_$1"
2598 if test -n "$ac_found" -o -n "[$]$1"
2599 then
2600 AC_MSG_RESULT([$]$1)
2601 else
2602 AC_MSG_RESULT(no)
2604 AC_SUBST($1)
2607 dnl **** Try to find where winelib is located ****
2609 LDPATH=""
2610 WINE_INCLUDE_ROOT=""
2611 WINE_INCLUDE_PATH=""
2612 WINE_LIBRARY_ROOT=""
2613 WINE_LIBRARY_PATH=""
2614 WINE_DLL_ROOT=""
2615 WINE_DLL_PATH=""
2616 WINE_TOOL_PATH=""
2617 WINE=""
2618 WINEBUILD=""
2619 WRC=""
2621 AC_ARG_WITH(wine,
2622 [ --with-wine=DIR the Wine package (or sources) is in DIR],
2623 [if test "$withval" != "no"; then
2624 WINE_ROOT="$withval";
2625 WINE_INCLUDES="";
2626 WINE_LIBRARIES="";
2627 WINE_TOOLS="";
2628 else
2629 WINE_ROOT="";
2630 fi])
2631 if test -n "$WINE_ROOT"
2632 then
2633 WINE_INCLUDE_ROOT="$WINE_ROOT/include:$WINE_ROOT/include/wine:$WINE_ROOT/include/wine/windows:$WINE_ROOT/include/windows"
2634 WINE_LIBRARY_ROOT="$WINE_ROOT:$WINE_ROOT/lib:$WINE_ROOT/library"
2635 WINE_UNICODE_ROOT="$WINE_ROOT:$WINE_ROOT/lib:$WINE_ROOT/unicode"
2636 WINE_UUID_ROOT="$WINE_ROOT:$WINE_ROOT/lib:$WINE_ROOT/ole"
2637 WINE_TOOL_PATH="$WINE_ROOT:$WINE_ROOT/bin:$WINE_ROOT/tools/wrc:$WINE_ROOT/tools/winebuild"
2638 WINE_DLL_ROOT="$WINE_ROOT/dlls:$WINE_ROOT/lib"
2641 AC_ARG_WITH(wine-includes,
2642 [ --with-wine-includes=DIR the Wine includes are in DIR],
2643 [if test "$withval" != "no"; then
2644 WINE_INCLUDES="$withval";
2645 else
2646 WINE_INCLUDES="";
2647 fi])
2648 if test -n "$WINE_INCLUDES"
2649 then
2650 WINE_INCLUDE_ROOT="$WINE_INCLUDES"
2653 AC_ARG_WITH(wine-libraries,
2654 [ --with-wine-libraries=DIR the Wine libraries are in DIR],
2655 [if test "$withval" != "no"; then
2656 WINE_LIBRARIES="$withval";
2657 else
2658 WINE_LIBRARIES="";
2659 fi])
2660 if test -n "$WINE_LIBRARIES"
2661 then
2662 WINE_LIBRARY_ROOT="$WINE_LIBRARIES"
2663 WINE_UNICODE_ROOT="$WINE_LIBRARIES:$WINE_LIBRARIES/unicode:$WINE_LIBRARIES/../unicode"
2664 WINE_UUID_ROOT="$WINE_LIBRARIES:$WINE_LIBRARIES/ole:$WINE_LIBRARIES/../ole"
2667 AC_ARG_WITH(wine-dlls,
2668 [ --with-wine-dlls=DIR the Wine dlls are in DIR],
2669 [if test "$withval" != "no"; then
2670 WINE_DLLS="$withval";
2671 else
2672 WINE_DLLS="";
2673 fi])
2674 if test -n "$WINE_DLLS"
2675 then
2676 WINE_DLL_ROOT="$WINE_DLLS"
2679 AC_ARG_WITH(wine-tools,
2680 [ --with-wine-tools=DIR the Wine tools are in DIR],
2681 [if test "$withval" != "no"; then
2682 WINE_TOOLS="$withval";
2683 else
2684 WINE_TOOLS="";
2685 fi])
2686 if test -n "$WINE_TOOLS"
2687 then
2688 WINE_TOOL_PATH="$WINE_TOOLS:$WINE_TOOLS/tools/wrc:$WINE_TOOLS/tools/winebuild"
2691 if test -z "$WINE_INCLUDE_ROOT"
2692 then
2693 WINE_INCLUDE_ROOT=":/usr/include/wine/windows:/usr/include/wine:/usr/local/include/wine/windows:/opt/wine/include/windows:/opt/wine/include/wine";
2694 else
2695 AC_PATH_FILE(WINE_INCLUDE_ROOT,[windef.h],[
2696 AC_MSG_ERROR([Could not find the Wine headers (windef.h)])
2697 ],$WINE_INCLUDE_ROOT)
2699 AC_PATH_HEADER(WINE_INCLUDE_ROOT,[windef.h],[
2700 AC_MSG_ERROR([Could not include the Wine headers (windef.h)])
2701 ],$WINE_INCLUDE_ROOT)
2702 if test -n "$WINE_INCLUDE_ROOT"
2703 then
2704 WINE_INCLUDE_PATH="-I$WINE_INCLUDE_ROOT"
2705 else
2706 WINE_INCLUDE_PATH=""
2709 if test -z "$WINE_LIBRARY_ROOT"
2710 then
2711 WINE_LIBRARY_ROOT=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib"
2712 else
2713 AC_PATH_FILE(WINE_LIBRARY_ROOT,[libwine.so],[
2714 AC_MSG_ERROR([Could not find the Wine libraries (libwine.so)])
2715 ],$WINE_LIBRARY_ROOT)
2717 AC_PATH_LIBRARY(WINE_LIBRARY_ROOT,[-lwine],[],[
2718 AC_MSG_ERROR([Could not link with the Wine libraries (libwine.so)])
2719 ],$WINE_LIBRARY_ROOT)
2720 if test -n "$WINE_LIBRARY_ROOT"
2721 then
2722 WINE_LIBRARY_PATH="-L$WINE_LIBRARY_ROOT"
2723 LDPATH="$WINE_LIBRARY_ROOT"
2724 else
2725 WINE_LIBRARY_PATH=""
2728 if test -z "$WINE_UNICODE_ROOT"
2729 then
2730 WINE_UNICODE_ROOT=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib"
2731 else
2732 AC_PATH_FILE(WINE_UNICODE_ROOT,[libwine_unicode.so],[
2733 AC_MSG_ERROR([Could not find the Wine libraries (libwine_unicode.so)])
2734 ],$WINE_UNICODE_ROOT)
2736 AC_PATH_LIBRARY(WINE_UNICODE_ROOT,[-lwine_unicode],[$WINE_LIBRARY_PATH -lwine],[
2737 AC_MSG_ERROR([Could not link with the Wine libraries (libwine_unicode.so)])
2738 ],[$WINE_UNICODE_ROOT])
2740 if test -n "$WINE_UNICODE_ROOT" -a "$WINE_UNICODE_ROOT" != "$WINE_LIBRARY_ROOT"
2741 then
2742 WINE_LIBRARY_PATH="$WINE_LIBRARY_PATH -L$WINE_UNICODE_ROOT"
2743 LDPATH="$LDPATH:$WINE_UNICODE_ROOT"
2746 if test -z "$WINE_UUID_ROOT"
2747 then
2748 WINE_UUID_ROOT=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib"
2749 else
2750 AC_PATH_FILE(WINE_UUID_ROOT,[libwine_uuid.a],[
2751 AC_MSG_ERROR([Could not find the Wine libraries (libwine_uuid.a)])
2752 ],$WINE_UUID_ROOT)
2754 AC_PATH_LIBRARY(WINE_UUID_ROOT,[-lwine_uuid],[$WINE_LIBRARY_PATH -lwine],[
2755 AC_MSG_ERROR([Could not link with the Wine libraries (libwine_uuid.a)])
2756 ],[$WINE_UUID_ROOT])
2758 if test -n "$WINE_UUID_ROOT" -a "$WINE_UUID_ROOT" != "$WINE_LIBRARY_ROOT"
2759 then
2760 WINE_LIBRARY_PATH="$WINE_LIBRARY_PATH -L$WINE_UUID_ROOT"
2763 if test -z "$WINE_DLL_ROOT"
2764 then
2765 if test -n "$WINE_LIBRARY_ROOT"
2766 then
2767 WINE_DLL_ROOT="$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/dlls"
2768 else
2769 WINE_DLL_ROOT="/lib:/lib/wine:/usr/lib:/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine"
2772 AC_PATH_FILE(WINE_DLL_ROOT,[libntdll.dll.so],[
2773 AC_MSG_ERROR([Could not find the Wine dlls (libntdll.dll.so)])
2774 ],[$WINE_DLL_ROOT])
2776 AC_PATH_LIBRARY(WINE_DLL_ROOT,[-lntdll.dll],[$WINE_LIBRARY_PATH -lwine -lwine_unicode],[
2777 AC_MSG_ERROR([Could not link with the Wine dlls (libntdll.dll.so)])
2778 ],[$WINE_DLL_ROOT])
2779 WINE_DLL_PATH="-L$WINE_DLL_ROOT/wine"
2781 if test -z "$WINE_TOOL_PATH"
2782 then
2783 WINE_TOOL_PATH="$PATH:/usr/local/bin:/opt/wine/bin"
2785 AC_PATH_PROG(WINE,wine,,$WINE_TOOL_PATH)
2786 if test -z "$WINE"
2787 then
2788 AC_MSG_ERROR([Could not find Wine's wine tool])
2790 AC_PATH_PROG(WINEBUILD,winebuild,,$WINE_TOOL_PATH)
2791 if test -z "$WINEBUILD"
2792 then
2793 AC_MSG_ERROR([Could not find Wine's winebuild tool])
2795 AC_PATH_PROG(WRC,wrc,,$WINE_TOOL_PATH)
2796 if test -z "$WRC"
2797 then
2798 AC_MSG_ERROR([Could not find Wine's wrc tool])
2801 LDPATH="LD_LIBRARY_PATH=\"$LDPATH:\$\$LD_LIBRARY_PATH\""
2802 AC_SUBST(LDPATH)
2803 AC_SUBST(WINE_INCLUDE_PATH)
2804 AC_SUBST(WINE_LIBRARY_PATH)
2805 AC_SUBST(WINE_DLL_PATH)
2807 dnl **** Try to find where the MFC are located ****
2808 AC_LANG_CPLUSPLUS()
2810 if test "x$NEEDS_MFC" = "x1"
2811 then
2812 ATL_INCLUDE_ROOT="";
2813 ATL_INCLUDE_PATH="";
2814 MFC_INCLUDE_ROOT="";
2815 MFC_INCLUDE_PATH="";
2816 MFC_LIBRARY_ROOT="";
2817 MFC_LIBRARY_PATH="";
2819 AC_ARG_WITH(mfc,
2820 [ --with-mfc=DIR the MFC package (or sources) is in DIR],
2821 [if test "$withval" != "no"; then
2822 MFC_ROOT="$withval";
2823 ATL_INCLUDES="";
2824 MFC_INCLUDES="";
2825 MFC_LIBRARIES="";
2826 else
2827 MFC_ROOT="";
2828 fi])
2829 if test -n "$MFC_ROOT"
2830 then
2831 ATL_INCLUDE_ROOT="$MFC_ROOT";
2832 MFC_INCLUDE_ROOT="$MFC_ROOT";
2833 MFC_LIBRARY_ROOT="$MFC_ROOT";
2836 AC_ARG_WITH(atl-includes,
2837 [ --with-atl-includes=DIR the ATL includes are in DIR],
2838 [if test "$withval" != "no"; then
2839 ATL_INCLUDES="$withval";
2840 else
2841 ATL_INCLUDES="";
2842 fi])
2843 if test -n "$ATL_INCLUDES"
2844 then
2845 ATL_INCLUDE_ROOT="$ATL_INCLUDES";
2848 AC_ARG_WITH(mfc-includes,
2849 [ --with-mfc-includes=DIR the MFC includes are in DIR],
2850 [if test "$withval" != "no"; then
2851 MFC_INCLUDES="$withval";
2852 else
2853 MFC_INCLUDES="";
2854 fi])
2855 if test -n "$MFC_INCLUDES"
2856 then
2857 MFC_INCLUDE_ROOT="$MFC_INCLUDES";
2860 AC_ARG_WITH(mfc-libraries,
2861 [ --with-mfc-libraries=DIR the MFC libraries are in DIR],
2862 [if test "$withval" != "no"; then
2863 MFC_LIBRARIES="$withval";
2864 else
2865 MFC_LIBRARIES="";
2866 fi])
2867 if test -n "$MFC_LIBRARIES"
2868 then
2869 MFC_LIBRARY_ROOT="$MFC_LIBRARIES";
2872 OLDCPPFLAGS="$CPPFLAGS"
2873 dnl FIXME: We should not have defines in any of the include paths
2874 CPPFLAGS="$WINE_INCLUDE_PATH -I$WINE_INCLUDE_ROOT/msvcrt -D_DLL -D_MT $CPPFLAGS"
2875 ATL_INCLUDE_PATH="-I\$(WINE_INCLUDE_ROOT)/msvcrt -D_DLL -D_MT"
2876 if test -z "$ATL_INCLUDE_ROOT"
2877 then
2878 ATL_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/atl:/usr/include/atl:/usr/local/include/atl:/opt/mfc/include/atl:/opt/atl/include"
2879 else
2880 ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT:$ATL_INCLUDE_ROOT/atl:$ATL_INCLUDE_ROOT/atl/include"
2882 AC_PATH_HEADER(ATL_INCLUDE_ROOT,atldef.h,[
2883 AC_MSG_ERROR([Could not find the ATL includes])
2884 ],$ATL_INCLUDE_ROOT)
2885 if test -n "$ATL_INCLUDE_ROOT"
2886 then
2887 ATL_INCLUDE_PATH="$ATL_INCLUDE_PATH -I$ATL_INCLUDE_ROOT"
2890 MFC_INCLUDE_PATH="$ATL_INCLUDE_PATH"
2891 if test -z "$MFC_INCLUDE_ROOT"
2892 then
2893 MFC_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/mfc:/usr/include/mfc:/usr/local/include/mfc:/opt/mfc/include/mfc:/opt/mfc/include"
2894 else
2895 MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT:$MFC_INCLUDE_ROOT/mfc:$MFC_INCLUDE_ROOT/mfc/include"
2897 AC_PATH_HEADER(MFC_INCLUDE_ROOT,afx.h,[
2898 AC_MSG_ERROR([Could not find the MFC includes])
2899 ],$MFC_INCLUDE_ROOT)
2900 if test -n "$MFC_INCLUDE_ROOT" -a "$ATL_INCLUDE_ROOT" != "$MFC_INCLUDE_ROOT"
2901 then
2902 MFC_INCLUDE_PATH="$MFC_INCLUDE_PATH -I$MFC_INCLUDE_ROOT"
2904 CPPFLAGS="$OLDCPPFLAGS"
2906 if test -z "$MFC_LIBRARY_ROOT"
2907 then
2908 MFC_LIBRARY_ROOT=":$WINE_LIBRARY_ROOT:/usr/lib/mfc:/usr/local/lib:/usr/local/lib/mfc:/opt/mfc/lib";
2909 else
2910 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT:$MFC_LIBRARY_ROOT/lib:$MFC_LIBRARY_ROOT/mfc/src";
2912 AC_PATH_LIBRARY(MFC_LIBRARY_ROOT,[-lmfc],[$WINE_LIBRARY_PATH -lwine -lwine_unicode],[
2913 AC_MSG_ERROR([Could not find the MFC library])
2914 ],$MFC_LIBRARY_ROOT)
2915 if test -n "$MFC_LIBRARY_ROOT" -a "$MFC_LIBRARY_ROOT" != "$WINE_LIBRARY_ROOT"
2916 then
2917 MFC_LIBRARY_PATH="-L$MFC_LIBRARY_ROOT"
2918 else
2919 MFC_LIBRARY_PATH=""
2922 AC_SUBST(ATL_INCLUDE_PATH)
2923 AC_SUBST(MFC_INCLUDE_PATH)
2924 AC_SUBST(MFC_LIBRARY_PATH)
2927 AC_LANG_C()
2929 dnl **** Generate output files ****
2931 MAKE_RULES=Make.rules
2932 AC_SUBST_FILE(MAKE_RULES)
2934 AC_OUTPUT([
2935 Make.rules
2936 ##WINEMAKER_PROJECTS##
2939 echo
2940 echo "Configure finished. Do 'make' to build the project."
2941 echo
2943 dnl Local Variables:
2944 dnl comment-start: "dnl "
2945 dnl comment-end: ""
2946 dnl comment-start-skip: "\\bdnl\\b\\s *"
2947 dnl compile-command: "autoconf"
2948 dnl End:
2949 --- Make.rules.in ---
2950 # Copyright 2000 Francois Gouget for CodeWeavers
2951 # fgouget@codeweavers.com
2953 # Global rules shared by all makefiles -*-Makefile-*-
2955 # Each individual makefile must define the following variables:
2956 # TOPOBJDIR : top-level object directory
2957 # SRCDIR : source directory for this module
2959 # Each individual makefile may define the following additional variables:
2961 # SUBDIRS : subdirectories that contain a Makefile
2962 # DLLS : WineLib libraries to be built
2963 # EXES : WineLib executables to be built
2965 # CEXTRA : extra c flags (e.g. '-Wall')
2966 # CXXEXTRA : extra c++ flags (e.g. '-Wall')
2967 # WRCEXTRA : extra wrc flags (e.g. '-p _SysRes')
2968 # DEFINES : defines (e.g. -DSTRICT)
2969 # INCLUDE_PATH : additional include path
2970 # LIBRARY_PATH : additional library path
2971 # LIBRARIES : additional Unix libraries to link with
2973 # C_SRCS : C sources for the module
2974 # CXX_SRCS : C++ sources for the module
2975 # RC_SRCS : resource source files
2976 # SPEC_SRCS : interface definition files
2979 # Where is Wine
2981 WINE_INCLUDE_ROOT = @WINE_INCLUDE_ROOT@
2982 WINE_INCLUDE_PATH = @WINE_INCLUDE_PATH@
2983 WINE_LIBRARY_ROOT = @WINE_LIBRARY_ROOT@
2984 WINE_LIBRARY_PATH = @WINE_LIBRARY_PATH@
2985 WINE_DLL_ROOT = @WINE_DLL_ROOT@
2986 WINE_DLL_PATH = @WINE_DLL_PATH@
2988 LDPATH = @LDPATH@
2990 # Where are the MFC
2992 ATL_INCLUDE_ROOT = @ATL_INCLUDE_ROOT@
2993 ATL_INCLUDE_PATH = @ATL_INCLUDE_PATH@
2994 MFC_INCLUDE_ROOT = @MFC_INCLUDE_ROOT@
2995 MFC_INCLUDE_PATH = @MFC_INCLUDE_PATH@
2996 MFC_LIBRARY_ROOT = @MFC_LIBRARY_ROOT@
2997 MFC_LIBRARY_PATH = @MFC_LIBRARY_PATH@
2999 # Global definitions and options
3001 GLOBAL_DEFINES = ##WINEMAKER_DEFINES##
3002 GLOBAL_INCLUDE_PATH = ##WINEMAKER_INCLUDE_PATH##
3003 GLOBAL_DLL_PATH = ##WINEMAKER_DLL_PATH##
3004 GLOBAL_DLLS = ##WINEMAKER_DLLS##
3005 GLOBAL_LIBRARY_PATH = ##WINEMAKER_LIBRARY_PATH##
3006 GLOBAL_LIBRARIES = ##WINEMAKER_LIBRARIES##
3008 # First some useful definitions
3010 SHELL = /bin/sh
3011 CC = @CC@
3012 CPP = @CPP@
3013 CXX = @CXX@
3014 WRC = @WRC@
3015 CFLAGS = @CFLAGS@ $(CEXTRA)
3016 CXXFLAGS = @CXXFLAGS@ $(CXXEXTRA)
3017 WRCFLAGS = $(WRCEXTRA)
3018 OPTIONS = @OPTIONS@ -D_REENTRANT
3019 LIBS = @LIBS@ $(LIBRARY_PATH)
3020 DIVINCL = $(GLOBAL_INCLUDE_PATH) -I$(SRCDIR) $(INCLUDE_PATH) $(WINE_INCLUDE_PATH)
3021 ALLCFLAGS = $(DIVINCL) $(CFLAGS) $(GLOBAL_DEFINES) $(DEFINES) $(OPTIONS)
3022 ALLCXXFLAGS=$(DIVINCL) $(CXXFLAGS) $(GLOBAL_DEFINES) $(DEFINES) $(OPTIONS)
3023 ALL_DLL_PATH = $(DLL_PATH) $(GLOBAL_DLL_PATH) $(WINE_DLL_PATH)
3024 ALL_LIBRARY_PATH = $(LIBRARY_PATH) $(GLOBAL_LIBRARY_PATH) $(WINE_LIBRARY_PATH)
3025 WINE_LIBRARIES = -lwine -lwine_unicode -lwine_uuid
3026 ALL_LIBRARIES = $(LIBRARIES:%=-l%) $(GLOBAL_LIBRARIES:%=-l%) $(WINE_LIBRARIES)
3027 LDSHARED = @LDSHARED@
3028 LDXXSHARED= @LDXXSHARED@
3029 LDDLLFLAGS= @LDDLLFLAGS@
3030 STRIP = strip
3031 STRIPFLAGS= --strip-unneeded
3032 LN_S = @LN_S@
3033 RM = rm -f
3034 MV = mv
3035 MKDIR = mkdir -p
3036 WINE = @WINE@
3037 WINEBUILD = @WINEBUILD@
3038 @SET_MAKE@
3040 # Installation infos
3042 INSTALL = install
3043 INSTALL_PROGRAM = $(INSTALL)
3044 INSTALL_SCRIPT = $(INSTALL)
3045 INSTALL_DATA = $(INSTALL) -m 644
3046 prefix = @prefix@
3047 exec_prefix = @exec_prefix@
3048 bindir = @bindir@
3049 libdir = @libdir@
3050 infodir = @infodir@
3051 mandir = @mandir@
3052 dlldir = @libdir@/wine
3054 prog_manext = 1
3055 conf_manext = 5
3057 OBJS = $(C_SRCS:.c=.o) $(CXX_SRCS:.cpp=.o) \
3058 $(SPEC_SRCS:.spec=.spec.o)
3059 CLEAN_FILES = *.spec.c y.tab.c y.tab.h lex.yy.c \
3060 core *.orig *.rej \
3061 \\\#*\\\# *~ *% .\\\#*
3062 DISTCLEAN_FILES = config.* Makefile Make.rules
3064 # Implicit rules
3066 .SUFFIXES: .cpp .rc .res .spec .spec.c .spec.o
3068 .c.o:
3069 $(CC) -c $(ALLCFLAGS) -o $@ $<
3071 .cpp.o:
3072 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
3074 .cxx.o:
3075 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
3077 .rc.res:
3078 $(LDPATH) $(WRC) $(WRCFLAGS) $(DIVINCL) -o $@ $<
3080 .PHONY: all install uninstall clean distclean depend dummy
3082 # 'all' target first in case the enclosing Makefile didn't define any target
3084 all: Makefile
3086 # Rules for makefile
3088 Makefile: Makefile.in $(TOPSRCDIR)/configure
3089 @echo $@ is older than $?, please rerun $(TOPSRCDIR)/configure
3090 @exit 1
3092 # Rules for cleaning
3094 $(SUBDIRS:%=%/__clean__): dummy
3095 cd `dirname $@` && $(MAKE) clean
3097 $(EXTRASUBDIRS:%=%/__clean__): dummy
3098 -cd `dirname $@` && $(RM) $(CLEAN_FILES)
3100 clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
3101 $(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(OBJS) $(EXES:%.exe=%) $(EXES:%=%.so) $(EXES:%=%.spec.o) $(DLLS:%=%.so) $(DLLS:%=%.spec.o)
3103 # Rule for distcleaning
3105 distclean: clean
3106 $(RM) $(DISTCLEAN_FILES)
3108 # Rules for installing
3110 $(SUBDIRS:%=%/__install__): dummy
3111 cd `dirname $@` && $(MAKE) install
3113 $(SUBDIRS:%=%/__uninstall__): dummy
3114 cd `dirname $@` && $(MAKE) uninstall
3116 # Misc. rules
3118 $(SUBDIRS): dummy
3119 @cd $@ && $(MAKE)
3121 dummy:
3123 # End of global rules
3124 --- wineapploader.in ---
3125 #!/bin/sh
3127 # Wrapper script to start a Winelib application once it is installed
3129 # Copyright (C) 2002 Alexandre Julliard
3131 # determine the app Winelib library name
3132 appname=`basename "$0" .exe`.exe
3134 #allow Wine to load Winelib application from the current directory
3135 export WINEDLLPATH=$WINEDLLPATH:@winelibdir@
3137 # first try explicit WINELOADER
3138 if [ -x "$WINELOADER" ]; then exec "$WINELOADER" "$appname" "$@"; fi
3140 # then default bin directory
3141 if [ -x "@bindir@/wine" ]; then exec "@bindir@/wine" "$appname" "$@"; fi
3143 # now try the directory containing $0
3144 appdir=""
3145 case "$0" in
3146 */*)
3147 # $0 contains a path, use it
3148 appdir=`dirname "$0"`
3151 # no directory in $0, search in PATH
3152 saved_ifs=$IFS
3153 IFS=:
3154 for d in $PATH
3156 IFS=$saved_ifs
3157 if [ -x "$d/$0" ]; then appdir="$d"; break; fi
3158 done
3160 esac
3161 if [ -x "$appdir/wine" ]; then exec "$appdir/wine" "$appname" "$@"; fi
3163 # finally look in PATH
3164 exec wine "$appname" "$@"
3165 --- wrapper.c ---
3167 * Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
3170 #ifndef STRICT
3171 #define STRICT
3172 #endif
3174 #include <dlfcn.h>
3175 #include <windows.h>
3180 * Describe the wrapped application
3184 * This is either CUIEXE for a console based application or
3185 * GUIEXE for a regular windows application.
3187 #define GUIEXE 0
3188 #define CUIEXE 1
3189 #define APP_TYPE ##WINEMAKER_APP_TYPE##
3192 * This is the name of the library containing the application,
3193 * e.g. 'hello.dll' if the application is called 'hello.exe'.
3195 static char* appName = "##WINEMAKER_APP_NAME##";
3198 * This is the name of the application's Windows module. If left NULL
3199 * then appName is used.
3201 static char* appModule = NULL;
3204 * This is the application's entry point. This is usually "WinMain" for a
3205 * GUIEXE and 'main' for a CUIEXE application.
3207 static char* appInit = ##WINEMAKER_APP_INIT##;
3210 * This is either non-NULL for MFC-based applications and is the name of the
3211 * MFC's module. This is the module in which we will take the 'WinMain'
3212 * function.
3214 static char* mfcModule = ##WINEMAKER_APP_MFC##;
3219 * Implement the main.
3222 #if APP_TYPE == GUIEXE
3223 typedef int WINAPI (*WinMainFunc)(HINSTANCE hInstance, HINSTANCE hPrevInstance,
3224 PSTR szCmdLine, int iCmdShow);
3225 #else
3226 typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp);
3227 #endif
3229 #if APP_TYPE == GUIEXE
3230 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
3231 PSTR szCmdLine, int iCmdShow)
3232 #else
3233 int WINAPI main(int argc, char** argv, char** envp)
3234 #endif
3236 /*void* appLibrary;*/
3237 HINSTANCE hApp = 0, hMFC = 0, hMain = 0;
3238 void* appMain;
3239 /*char* libName;*/
3240 int retcode;
3242 /* Load the application's library */
3243 /*libName=(char*)malloc(2+strlen(appName)+3+1);*/
3244 /* FIXME: we should get the wrapper's path and use that as the base for
3245 * the library
3247 /*sprintf(libName,"./%s.so",appName);*/
3248 /*appLibrary=dlopen(libName,RTLD_NOW);*/
3249 /*if (appLibrary==NULL) {*/
3250 /*sprintf(libName,"%s.so",appName);*/
3251 /*appLibrary=dlopen(libName,RTLD_NOW);*/
3252 /*}*/
3253 /*if (appLibrary==NULL) {*/
3254 /*char format[]="Could not load the %s library:\r\n%s";*/
3255 /*char* error;*/
3256 /*char* msg;*/
3258 /*error=dlerror();*/
3259 /*msg=(char*)malloc(strlen(format)+strlen(libName)+strlen(error));*/
3260 /*sprintf(msg,format,libName,error);*/
3261 /*MessageBox(NULL,msg,"dlopen error",MB_OK);*/
3262 /*free(msg);*/
3263 /*return 1;*/
3264 /*}*/
3266 /* Then if this application is MFC based, load the MFC module */
3267 /* FIXME: I'm not sure this is really necessary */
3268 if (mfcModule!=NULL) {
3269 hMFC=LoadLibrary(mfcModule);
3270 if (hMFC==NULL) {
3271 char format[]="Could not load the MFC module %s (%d)";
3272 char* msg;
3274 msg=(char*)malloc(strlen(format)+strlen(mfcModule)+11);
3275 sprintf(msg,format,mfcModule,GetLastError());
3276 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
3277 free(msg);
3278 return 1;
3280 /* MFC is a special case: the WinMain is in the MFC library,
3281 * instead of the application's library.
3283 hMain=hMFC;
3284 } else {
3285 hMFC=NULL;
3288 /* Load the application's module */
3289 if (appModule==NULL) {
3290 appModule=appName;
3292 hApp=LoadLibrary(appModule);
3293 if (hApp==NULL) {
3294 char format[]="Could not load the application's module %s (%d)";
3295 char* msg;
3297 msg=(char*)malloc(strlen(format)+strlen(appModule)+11);
3298 sprintf(msg,format,appModule,GetLastError());
3299 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
3300 free(msg);
3301 return 1;
3302 } else if (hMain==NULL) {
3303 hMain=hApp;
3306 /* Get the address of the application's entry point */
3307 appMain=GetProcAddress(hMain, appInit);
3308 if (appMain==NULL) {
3309 char format[]="Could not get the address of %s (%d)";
3310 char* msg;
3312 msg=(char*)malloc(strlen(format)+strlen(appInit)+11);
3313 sprintf(msg,format,appInit,GetLastError());
3314 MessageBox(NULL,msg,"GetProcAddress error",MB_OK);
3315 free(msg);
3316 return 1;
3319 /* And finally invoke the application's entry point */
3320 #if APP_TYPE == GUIEXE
3321 retcode=(*((WinMainFunc)appMain))(hApp,hPrevInstance,szCmdLine,iCmdShow);
3322 #else
3323 retcode=(*((MainFunc)appMain))(argc,argv,envp);
3324 #endif
3326 /* Cleanup and done */
3327 FreeLibrary(hApp);
3328 if (hMFC!=NULL) {
3329 FreeLibrary(hMFC);
3331 /*dlclose(appLibrary);*/
3332 /*free(libName);*/
3334 return retcode;