Moved DCX_* constants to winuser.h.
[wine/multimedia.git] / tools / winemaker
blobd1a478029c324698779c402b0758554866f79d1f
1 #!/usr/bin/perl -w
3 # Copyright 2000 Francois Gouget for CodeWeavers
4 # fgouget@codeweavers.com
6 my $version="0.5.7";
8 use Cwd;
9 use File::Basename;
10 use File::Copy;
14 #####
16 # Options
18 #####
20 # The following constants define what we do with the case of filenames
23 # Never rename a file to lowercase
24 my $OPT_LOWER_NONE=0;
27 # Rename all files to lowercase
28 my $OPT_LOWER_ALL=1;
31 # Rename only files that are all uppercase to lowercase
32 my $OPT_LOWER_UPPERCASE=2;
35 # The following constants define whether to ask questions or not
38 # No (synonym of never)
39 my $OPT_ASK_NO=0;
42 # Yes (always)
43 my $OPT_ASK_YES=1;
46 # Skip the questions till the end of this scope
47 my $OPT_ASK_SKIP=-1;
50 # General options
53 # This is the directory in which winemaker will operate.
54 my $opt_work_dir;
57 # Make a backup of the files
58 my $opt_backup;
61 # Defines which files to rename
62 my $opt_lower;
65 # If we don't find the file referenced by an include, lower it
66 my $opt_lower_include;
69 # Options for the 'Source' method
72 # Specifies that we have only one target so that all sources relate
73 # to this target. By default this variable is left undefined which
74 # means winemaker should try to find out by itself what the targets
75 # are. If not undefined then this contains the name of the default
76 # target (without the extension).
77 my $opt_single_target;
80 # If '$opt_single_target' has been specified then this is the type of
81 # that target. Otherwise it specifies whether the default target type
82 # is guiexe or cuiexe.
83 my $opt_target_type;
86 # Contains the default set of flags to be used when creating a new target.
87 my $opt_flags;
90 # If true then winemaker should ask questions to the user as it goes
91 # along.
92 my $opt_is_interactive;
93 my $opt_ask_project_options;
94 my $opt_ask_target_options;
97 # If false then winemaker should not generate any file, i.e.
98 # no makefiles, but also no .spec files, no configure.in, etc.
99 my $opt_no_generated_files;
102 # Specifies not to print the banner if set.
103 my $opt_no_banner;
107 #####
109 # Target modelization
111 #####
113 # The description of a target is stored in an array. The constants
114 # below identify what is stored at each index of the array.
117 # This is the name of the target.
118 my $T_NAME=0;
121 # Defines the type of target we want to build. See the TT_xxx
122 # constants below
123 my $T_TYPE=1;
126 # Defines the target's enty point, i.e. the function that is called
127 # on startup.
128 my $T_INIT=2;
131 # This is a bitfield containing flags refining the way the target
132 # should be handled. See the TF_xxx constants below
133 my $T_FLAGS=3;
136 # This is a reference to an array containing the list of the
137 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
138 my $T_SOURCES_C=4;
139 my $T_SOURCES_CXX=5;
140 my $T_SOURCES_RC=6;
141 my $T_SOURCES_MISC=7;
144 # This is a reference to an array containing the list of macro
145 # definitions
146 my $T_DEFINES=8;
149 # This is a reference to an array containing the list of directory
150 # names that constitute the include path
151 my $T_INCLUDE_PATH=9;
154 # Same as T_INCLUDE_PATH but for the library search path
155 my $T_LIBRARY_PATH=10;
158 # The list of Windows libraries to import
159 my $T_IMPORTS=11;
162 # The list of Unix libraries to link with
163 my $T_LIBRARIES=12;
166 # The list of dependencies between targets
167 my $T_DEPENDS=13;
170 # The following constants define the recognized types of target
173 # This is not a real target. This type of target is used to collect
174 # the sources that don't seem to belong to any other target. Thus no
175 # real target is generated for them, we just put the sources of the
176 # fake target in the global source list.
177 my $TT_SETTINGS=0;
180 # For executables in the windows subsystem
181 my $TT_GUIEXE=1;
184 # For executables in the console subsystem
185 my $TT_CUIEXE=2;
188 # For dynamically linked libraries
189 my $TT_DLL=3;
192 # The following constants further refine how the target should be handled
195 # This target needs a wrapper
196 my $TF_WRAP=1;
199 # This target is a wrapper
200 my $TF_WRAPPER=2;
203 # This target is an MFC-based target
204 my $TF_MFC=4;
207 # Initialize a target:
208 # - set the target type to TT_SETTINGS, i.e. no real target will
209 # be generated.
210 sub target_init
212 my $target=$_[0];
214 @$target[$T_TYPE]=$TT_SETTINGS;
215 # leaving $T_INIT undefined
216 @$target[$T_FLAGS]=$opt_flags;
217 @$target[$T_SOURCES_C]=[];
218 @$target[$T_SOURCES_CXX]=[];
219 @$target[$T_SOURCES_RC]=[];
220 @$target[$T_SOURCES_MISC]=[];
221 @$target[$T_DEFINES]=[];
222 @$target[$T_INCLUDE_PATH]=[];
223 @$target[$T_LIBRARY_PATH]=[];
224 @$target[$T_IMPORTS]=[];
225 @$target[$T_LIBRARIES]=[];
226 @$target[$T_DEPENDS]=[];
229 sub get_default_init
231 my $type=$_[0];
232 if ($type == $TT_GUIEXE) {
233 return "WinMain";
234 } elsif ($type == $TT_CUIEXE) {
235 return "main";
236 } elsif ($type == $TT_DLL) {
237 return "DllMain";
243 #####
245 # Project modelization
247 #####
249 # First we have the notion of project. A project is described by an
250 # array (since we don't have structs in perl). The constants below
251 # identify what is stored at each index of the array.
254 # This is the path in which this project is located. In other
255 # words, this is the path to the Makefile.
256 my $P_PATH=0;
259 # This index contains a reference to an array containing the project-wide
260 # settings. The structure of that arrray is actually identical to that of
261 # a regular target since it can also contain extra sources.
262 my $P_SETTINGS=1;
265 # This index contains a reference to an array of targets for this
266 # project. Each target describes how an executable or library is to
267 # be built. For each target this description takes the same form as
268 # that of the project: an array. So this entry is an array of arrays.
269 my $P_TARGETS=2;
272 # Initialize a project:
273 # - set the project's path
274 # - initialize the target list
275 # - create a default target (will be removed later if unnecessary)
276 sub project_init
278 my $project=$_[0];
279 my $path=$_[1];
281 my $project_settings=[];
282 target_init($project_settings);
284 @$project[$P_PATH]=$path;
285 @$project[$P_SETTINGS]=$project_settings;
286 @$project[$P_TARGETS]=[];
291 #####
293 # Global variables
295 #####
297 my %warnings;
299 my %templates;
302 # Contains the list of all projects. This list tells us what are
303 # the subprojects of the main Makefile and where we have to generate
304 # Makefiles.
305 my @projects=();
308 # This is the main project, i.e. the one in the "." directory.
309 # It may well be empty in which case the main Makefile will only
310 # call out subprojects.
311 my @main_project;
314 # Contains the defaults for the include path, etc.
315 # We store the defaults as if this were a target except that we only
316 # exploit the defines, include path, library path, library list and misc
317 # sources fields.
318 my @global_settings;
321 # If one of the projects requires the MFc then we set this global variable
322 # to true so that configure asks the user to provide a path tothe MFC
323 my $needs_mfc=0;
327 #####
329 # Utility functions
331 #####
334 # Cleans up a name to make it an acceptable Makefile
335 # variable name.
336 sub canonize
338 my $name=$_[0];
340 $name =~ tr/a-zA-Z0-9_/_/c;
341 return $name;
345 # Returns true is the specified pathname is absolute.
346 # Note: pathnames that start with a variable '$' or
347 # '~' are considered absolute.
348 sub is_absolute
350 my $path=$_[0];
352 return ($path =~ /^[\/~\$]/);
356 # Performs a binary search looking for the specified item
357 sub bsearch
359 my $array=$_[0];
360 my $item=$_[1];
361 my $last=@{$array}-1;
362 my $first=0;
364 while ($first<=$last) {
365 my $index=int(($first+$last)/2);
366 my $cmp=@$array[$index] cmp $item;
367 if ($cmp<0) {
368 $first=$index+1;
369 } elsif ($cmp>0) {
370 $last=$index-1;
371 } else {
372 return $index;
379 #####
381 # 'Source'-based Project analysis
383 #####
386 # Allows the user to specify makefile and target specific options
387 # - target: the structure in which to store the results
388 # - options: the string containing the options
389 sub source_set_options
391 my $target=$_[0];
392 my $options=$_[1];
394 #FIXME: we must deal with escaping of stuff and all
395 foreach $option (split / /,$options) {
396 if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
397 push @{@$target[$T_DEFINES]},$option;
398 } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
399 push @{@$target[$T_INCLUDE_PATH]},$option;
400 } elsif ($option =~ /^-L/) {
401 push @{@$target[$T_LIBRARY_PATH]},$option;
402 } elsif ($option =~ /^-i/) {
403 push @{@$target[$T_IMPORTS]},$';
404 } elsif ($option =~ /^-l/) {
405 push @{@$target[$T_LIBRARIES]},$';
406 } elsif (@$target[$T_TYPE] != $TT_DLL and
407 $option =~ /^--wrap/) {
408 @$target[$T_FLAGS]|=$TF_WRAP;
409 } elsif (@$target[$T_TYPE] != $TT_DLL and
410 $option =~ /^--nowrap/) {
411 @$target[$T_FLAGS]&=~$TF_WRAP;
412 } elsif ($option =~ /^--mfc/) {
413 @$target[$T_FLAGS]|=$TF_MFC;
414 if (@$target[$T_TYPE] != $TT_DLL) {
415 @$target[$T_FLAGS]|=$TF_WRAP;
417 } elsif ($option =~ /^--nomfc/) {
418 @$target[$T_FLAGS]&=~$TF_MFC;
419 @$target[$T_FLAGS]&=~($TF_MFC|$TF_WRAP);
420 } else {
421 print STDERR "error: unknown option \"$option\"\n";
422 return 0;
425 return 1;
429 # Scans the specified directory to:
430 # - see if we should create a Makefile in this directory. We normally do
431 # so if we find a project file and sources
432 # - get a list of targets for this directory
433 # - get the list of source files
434 sub source_scan_directory
436 # a reference to the parent's project
437 my $parent_project=$_[0];
438 # the full relative path to the current directory, including a
439 # trailing '/', or an empty string if this is the top level directory
440 my $path=$_[1];
441 # the name of this directory, including a trailing '/', or an empty
442 # string if this is the top level directory
443 my $dirname=$_[2];
444 # if set then no targets will be looked for and the sources will all
445 # end up in the parent_project's 'misc' bucket
446 my $no_target=$_[3];
448 # reference to the project for this directory. May not be used
449 my $project;
450 # list of targets found in the 'current' directory
451 my %targets;
452 # list of sources found in the current directory
453 my @sources_c=();
454 my @sources_cxx=();
455 my @sources_rc=();
456 my @sources_misc=();
457 # true if this directory contains a Windows project
458 my $has_win_project=0;
459 # If we don't find any executable/library then we might make up targets
460 # from the list of .dsp/.mak files we find since they usually have the
461 # same name as their target.
462 my @dsp_files=();
463 my @mak_files=();
465 if (defined $opt_single_target or $dirname eq "") {
466 # Either there is a single target and thus a single project,
467 # or we are in the top level directory for which a project
468 # already exists
469 $project=$parent_project;
470 } else {
471 $project=[];
472 project_init($project,$path);
474 my $project_settings=@$project[$P_SETTINGS];
476 # First find out what this directory contains:
477 # collect all sources, targets and subdirectories
478 my $directory=get_directory_contents($path);
479 foreach $dentry (@$directory) {
480 if ($dentry =~ /^\./) {
481 next;
483 my $fullentry="$path$dentry";
484 if (-d "$fullentry") {
485 if ($dentry =~ /^(Release|Debug)/i) {
486 # These directories are often used to store the object files and the
487 # resulting executable/library. They should not contain anything else.
488 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
489 foreach $candidate (@candidates) {
490 if ($candidate =~ s/\.exe$//i) {
491 $targets{$candidate}=1;
492 } elsif ($candidate =~ s/^(.*)\.dll$/lib$1.so/i) {
493 $targets{$candidate}=1;
496 } elsif ($dentry =~ /^include/i) {
497 # This directory must contain headers we're going to need
498 push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
499 source_scan_directory($project,"$fullentry/","$dentry/",1);
500 } else {
501 # Recursively scan this directory. Any source file that cannot be
502 # attributed to a project in one of the subdirectories will be
503 # attributed to this project.
504 source_scan_directory($project,"$fullentry/","$dentry/",$no_target);
506 } elsif (-f "$fullentry") {
507 if ($dentry =~ s/\.exe$//i) {
508 $targets{$dentry}=1;
509 } elsif ($dentry =~ s/^(.*)\.dll$/lib$1.so/i) {
510 $targets{$dentry}=1;
511 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.spec\.c$/) {
512 push @sources_c,"$dentry";
513 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
514 if ($dentry =~ /^stdafx.cpp$/i) {
515 push @sources_misc,"$dentry";
516 @$project_settings[$T_FLAGS]|=$TF_MFC;
517 } else {
518 push @sources_cxx,"$dentry";
520 } elsif ($dentry =~ /\.rc$/i) {
521 push @sources_rc,"$dentry";
522 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
523 push @sources_misc,"$dentry";
524 if ($dentry =~ /^stdafx.h$/i) {
525 @$project_settings[$T_FLAGS]|=$TF_MFC;
527 } elsif ($dentry =~ /\.dsp$/i) {
528 push @dsp_files,"$dentry";
529 $has_win_project=1;
530 } elsif ($dentry =~ /\.mak$/i) {
531 push @mak_files,"$dentry";
532 $has_win_project=1;
533 } elsif ($dentry =~ /^makefile/i) {
534 $has_win_project=1;
538 closedir(DIRECTORY);
540 # If we have a single target then all we have to do is assign
541 # all the sources to it and we're done
542 # FIXME: does this play well with the --interactive mode?
543 if ($opt_single_target) {
544 my $target=@{@$project[$P_TARGETS]}[0];
545 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
546 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
547 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
548 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
549 return;
551 if ($no_target) {
552 my $parent_settings=@$parent_project[$P_SETTINGS];
553 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
554 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
555 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
556 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
557 return;
560 my $source_count=@sources_c+@sources_cxx+@sources_rc+
561 @{@$project_settings[$T_SOURCES_C]}+
562 @{@$project_settings[$T_SOURCES_CXX]}+
563 @{@$project_settings[$T_SOURCES_RC]};
564 if ($source_count == 0) {
565 # A project without real sources is not a project, get out!
566 if ($project!=$parent_project) {
567 my $parent_settings=@$parent_project[$P_SETTINGS];
568 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
569 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
571 return;
573 #print "targets=",%targets,"\n";
574 #print "target_count=$target_count\n";
575 #print "has_win_project=$has_win_project\n";
576 #print "dirname=$dirname\n";
578 my $target_count;
579 if (($has_win_project != 0) or ($dirname eq "")) {
580 # Deal with cases where we could not find any executable/library, and
581 # thus have no target, although we did find some sort of windows project.
582 $target_count=keys %targets;
583 if ($target_count == 0) {
584 # Try to come up with a target list based on .dsp/.mak files
585 my $prj_list;
586 if (@dsp_files > 0) {
587 $prj_list=\@dsp_files;
588 } else {
589 $prj_list=\@mak_files;
591 foreach $filename (@$prj_list) {
592 $filename =~ s/\.(dsp|mak)$//i;
593 if ($opt_target_type == $TT_DLL) {
594 $filename = "lib$filename.so";
596 $targets{$filename}=1;
598 $target_count=keys %targets;
599 if ($target_count == 0) {
600 # Still nothing, try the name of the directory
601 my $name;
602 if ($dirname eq "") {
603 # Bad luck, this is the top level directory!
604 $name=(split /\//, cwd)[-1];
605 } else {
606 $name=$dirname;
607 # Remove the trailing '/'. Also eliminate whatever is after the last
608 # '.' as it is likely to be meaningless (.orig, .new, ...)
609 $name =~ s+(/|\.[^.]*)$++;
610 if ($name eq "src") {
611 # 'src' is probably a subdirectory of the real project directory.
612 # Try again with the parent (if any).
613 my $parent=$path;
614 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
615 $name=$parent;
616 } else {
617 $name=(split /\//, cwd)[-1];
621 $name =~ s+(/|\.[^.]*)$++;
622 if ($opt_target_type == $TT_DLL) {
623 $name = "lib$name.so";
625 $targets{$name}=1;
629 # Ask confirmation to the user if he wishes so
630 if ($opt_is_interactive == $OPT_ASK_YES) {
631 my $target_list=join " ",keys %targets;
632 print "\n*** In ",($path?$path:"./"),"\n";
633 print "* winemaker found the following list of (potential) targets\n";
634 print "* $target_list\n";
635 print "* Type enter to use it as is, your own comma-separated list of\n";
636 print "* targets, 'none' to assign the source files to a parent directory,\n";
637 print "* or 'ignore' to ignore everything in this directory tree.\n";
638 print "* Target list:\n";
639 $target_list=<STDIN>;
640 chomp $target_list;
641 if ($target_list eq "") {
642 # Keep the target list as is, i.e. do nothing
643 } elsif ($target_list eq "none") {
644 # Empty the target list
645 undef %targets;
646 } elsif ($target_list eq "ignore") {
647 # Ignore this subtree altogether
648 return;
649 } else {
650 undef %targets;
651 foreach $target (split /,/,$target_list) {
652 $target =~ s+^\s*++;
653 $target =~ s+\s*$++;
654 # Also accept .exe and .dll as a courtesy
655 $target =~ s+(.*)\.dll$+lib$1.so+;
656 $target =~ s+\.exe$++;
657 $targets{$target}=1;
663 # If we have no project at this level, then transfer all
664 # the sources to the parent project
665 $target_count=keys %targets;
666 if ($target_count == 0) {
667 if ($project!=$parent_project) {
668 my $parent_settings=@$parent_project[$P_SETTINGS];
669 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
670 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
671 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
672 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
673 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
675 return;
678 # Otherwise add this project to the project list, except for
679 # the main project which is already in the list.
680 if ($dirname ne "") {
681 push @projects,$project;
684 # Ask for project-wide options
685 if ($opt_ask_project_options == $OPT_ASK_YES) {
686 my $flag_desc="";
687 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
688 $flag_desc="mfc";
690 if ((@$project_settings[$T_FLAGS] & $TF_WRAP)!=0) {
691 if ($flag_desc ne "") {
692 $flag_desc.=", ";
694 $flag_desc.="wrapped";
696 print "* Type any project-wide options (-D/-I/-L/-i/-l/--mfc/--wrap),\n";
697 if (defined $flag_desc) {
698 print "* (currently $flag_desc)\n";
700 print "* or 'skip' to skip the target specific options,\n";
701 print "* or 'never' to not be asked this question again:\n";
702 while (1) {
703 my $options=<STDIN>;
704 chomp $options;
705 if ($options eq "skip") {
706 $opt_ask_target_options=$OPT_ASK_SKIP;
707 last;
708 } elsif ($options eq "never") {
709 $opt_ask_project_options=$OPT_ASK_NO;
710 last;
711 } elsif (source_set_options($project_settings,$options)) {
712 last;
714 print "Please re-enter the options:\n";
718 # - Create the targets
719 # - Check if we have both libraries and programs
720 # - Match each target with source files (sort in reverse
721 # alphabetical order to get the longest matches first)
722 my @local_imports=();
723 my @local_depends=();
724 my @exe_list=();
725 foreach $target_name (sort { $b cmp $a } keys %targets) {
726 # Create the target...
727 my $basename;
728 my $target=[];
729 target_init($target);
730 @$target[$T_NAME]=$target_name;
731 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
732 if ($target_name =~ /^lib(.*)\.so$/) {
733 @$target[$T_TYPE]=$TT_DLL;
734 @$target[$T_INIT]=get_default_init($TT_DLL);
735 @$target[$T_FLAGS]&=~$TF_WRAP;
736 $basename=$1;
737 push @local_depends,$target_name;
738 push @local_imports,$basename;
739 } else {
740 @$target[$T_TYPE]=$opt_target_type;
741 @$target[$T_INIT]=get_default_init($opt_target_type);
742 $basename=$target_name;
743 push @exe_list,$target;
745 # This is the default link list of Visual Studio, except odbccp32
746 # which we don't have in Wine. Also I add ntdll which seems
747 # necessary for Winelib.
748 my @std_imports=qw(advapi32.dll comdlg32.dll gdi32.dll kernel32.dll ntdll.dll odbc32.dll ole32.dll oleaut32.dll shell32.dll user32.dll winspool.drv);
749 @$target[$T_IMPORTS]=\@std_imports;
750 push @{@$project[$P_TARGETS]},$target;
752 # Ask for target-specific options
753 if ($opt_ask_target_options == $OPT_ASK_YES) {
754 my $flag_desc="";
755 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
756 $flag_desc=" (mfc";
758 if ((@$target[$T_FLAGS] & $TF_WRAP)!=0) {
759 if ($flag_desc ne "") {
760 $flag_desc.=", ";
761 } else {
762 $flag_desc=" (";
764 $flag_desc.="wrapped";
766 if ($flag_desc ne "") {
767 $flag_desc.=")";
769 print "* Specify any link option (-L/-i/-l/--mfc/--wrap) specific to the target\n";
770 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
771 while (1) {
772 my $options=<STDIN>;
773 chomp $options;
774 if ($options eq "never") {
775 $opt_ask_target_options=$OPT_ASK_NO;
776 last;
777 } elsif (source_set_options($target,$options)) {
778 last;
780 print "Please re-enter the options:\n";
783 if (@$target[$T_FLAGS] & $TF_MFC) {
784 @$project_settings[$T_FLAGS]|=$TF_MFC;
785 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
786 push @{@$target[$T_IMPORTS]},"mfc.dll";
787 # FIXME: Link with the MFC in the Unix sense, until we
788 # start exporting the functions properly.
789 push @{@$target[$T_LIBRARIES]},"mfc";
792 # Match sources...
793 if ($target_count == 1) {
794 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
795 @$project_settings[$T_SOURCES_C]=[];
796 @sources_c=();
798 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
799 @$project_settings[$T_SOURCES_CXX]=[];
800 @sources_cxx=();
802 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
803 @$project_settings[$T_SOURCES_RC]=[];
804 @sources_rc=();
806 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
807 # No need for sorting these sources
808 @$project_settings[$T_SOURCES_MISC]=[];
809 @sources_misc=();
810 } else {
811 foreach $source (@sources_c) {
812 if ($source =~ /^$basename/i) {
813 push @{@$target[$T_SOURCES_C]},$source;
814 $source="";
817 foreach $source (@sources_cxx) {
818 if ($source =~ /^$basename/i) {
819 push @{@$target[$T_SOURCES_CXX]},$source;
820 $source="";
823 foreach $source (@sources_rc) {
824 if ($source =~ /^$basename/i) {
825 push @{@$target[$T_SOURCES_RC]},$source;
826 $source="";
829 foreach $source (@sources_misc) {
830 if ($source =~ /^$basename/i) {
831 push @{@$target[$T_SOURCES_MISC]},$source;
832 $source="";
836 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
837 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
838 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
839 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
841 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
842 $opt_ask_target_options=$OPT_ASK_YES;
845 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
846 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
848 # The sources that did not match, if any, go to the extra
849 # source list of the project settings
850 foreach $source (@sources_c) {
851 if ($source ne "") {
852 push @{@$project_settings[$T_SOURCES_C]},$source;
855 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
856 foreach $source (@sources_cxx) {
857 if ($source ne "") {
858 push @{@$project_settings[$T_SOURCES_CXX]},$source;
861 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
862 foreach $source (@sources_rc) {
863 if ($source ne "") {
864 push @{@$project_settings[$T_SOURCES_RC]},$source;
867 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
868 foreach $source (@sources_misc) {
869 if ($source ne "") {
870 push @{@$project_settings[$T_SOURCES_MISC]},$source;
873 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
875 # Finally if we are building both libraries and programs in
876 # this directory, then the programs should be linked with all
877 # the libraries
878 if (@local_imports > 0 and @exe_list > 0) {
879 foreach $target (@exe_list) {
880 push @{@$target[$T_LIBRARY_PATH]},"-L.";
881 push @{@$target[$T_IMPORTS]},map { "$_.dll" } @local_imports;
882 # Also link in the Unix sense since none of the functions
883 # will be exported.
884 push @{@$target[$T_LIBRARIES]},@local_imports;
885 push @{@$target[$T_DEPENDS]},@local_depends;
891 # Scan the source directories in search of things to build
892 sub source_scan
894 # If there's a single target then this is going to be the default target
895 if (defined $opt_single_target) {
896 # Create the main target
897 my $main_target=[];
898 target_init($main_target);
899 if ($opt_target_type == $TT_DLL) {
900 @$main_target[$T_NAME]="lib$opt_single_target.so";
901 } else {
902 @$main_target[$T_NAME]="$opt_single_target";
904 @$main_target[$T_TYPE]=$opt_target_type;
906 # Add it to the list
907 push @{$main_project[$P_TARGETS]},$main_target;
910 # The main directory is always going to be there
911 push @projects,\@main_project;
913 # Now scan the directory tree looking for source files and, maybe, targets
914 print "Scanning the source directories...\n";
915 source_scan_directory(\@main_project,"","",0);
917 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
922 #####
924 # 'vc.dsp'-based Project analysis
926 #####
928 #sub analyze_vc_dsp
935 #####
937 # Creating the wrapper targets
939 #####
941 sub postprocess_targets
943 foreach $project (@projects) {
944 foreach $target (@{@$project[$P_TARGETS]}) {
945 if ((@$target[$T_FLAGS] & $TF_WRAP) != 0) {
946 my $wrapper=[];
947 target_init($wrapper);
948 @$wrapper[$T_NAME]=@$target[$T_NAME];
949 @$wrapper[$T_TYPE]=@$target[$T_TYPE];
950 @$wrapper[$T_INIT]=get_default_init(@$target[$T_TYPE]);
951 @$wrapper[$T_FLAGS]=$TF_WRAPPER | (@$target[$T_FLAGS] & $TF_MFC);
952 @$wrapper[$T_IMPORTS]=[ "kernel32.dll", "ntdll.dll", "user32.dll" ];
953 push @{@$wrapper[$T_SOURCES_C]},"@$wrapper[$T_NAME]_wrapper.c";
955 my $index=bsearch(@$target[$T_SOURCES_C],"@$wrapper[$T_NAME]_wrapper.c");
956 if (defined $index) {
957 splice(@{@$target[$T_SOURCES_C]},$index,1);
959 @$target[$T_NAME]="lib@$target[$T_NAME].so";
960 @$target[$T_TYPE]=$TT_DLL;
962 push @{@$project[$P_TARGETS]},$wrapper;
964 if ((@$target[$T_FLAGS] & $TF_MFC) != 0) {
965 @{@$project[$P_SETTINGS]}[$T_FLAGS]|=$TF_MFC;
966 $needs_mfc=1;
974 #####
976 # Source search
978 #####
981 # Performs a directory traversal and renames the files so that:
982 # - they have the case desired by the user
983 # - their extension is of the appropriate case
984 # - they don't contain annoying characters like ' ', '$', '#', ...
985 sub fix_file_and_directory_names
987 my $dirname=$_[0];
989 if (opendir(DIRECTORY, "$dirname")) {
990 foreach $dentry (readdir DIRECTORY) {
991 if ($dentry =~ /^\./ or $dentry eq "CVS") {
992 next;
994 # Set $warn to 1 if the user should be warned of the renaming
995 my $warn=0;
997 # autoconf and make don't support these characters well
998 my $new_name=$dentry;
999 $new_name =~ s/[ \$]/_/g;
1001 # Only all lowercase extensions are supported (because of the
1002 # transformations ':.c=.o') .
1003 if (-f "$dirname/$new_name") {
1004 if ($new_name =~ /\.C$/) {
1005 $new_name =~ s/\.C$/.c/;
1007 if ($new_name =~ /\.cpp$/i) {
1008 $new_name =~ s/\.cpp$/.cpp/i;
1010 if ($new_name =~ s/\.cxx$/.cpp/i) {
1011 $warn=1;
1013 if ($new_name =~ /\.rc$/i) {
1014 $new_name =~ s/\.rc$/.rc/i;
1016 # And this last one is to avoid confusion then running make
1017 if ($new_name =~ s/^makefile$/makefile.win/) {
1018 $warn=1;
1022 # Adjust the case to the user's preferences
1023 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1024 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1026 $new_name=lc $new_name;
1029 # And finally, perform the renaming
1030 if ($new_name ne $dentry) {
1031 if ($warn) {
1032 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1034 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1035 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1036 print STDERR " $!\n";
1037 $new_name=$dentry;
1040 if (-d "$dirname/$new_name") {
1041 fix_file_and_directory_names("$dirname/$new_name");
1044 closedir(DIRECTORY);
1050 #####
1052 # Source fixup
1054 #####
1057 # This maps a directory name to a reference to an array listing
1058 # its contents (files and directories)
1059 my %directories;
1062 # Retrieves the contents of the specified directory.
1063 # We either get it from the directories hashtable which acts as a
1064 # cache, or use opendir, readdir, closedir and store the result
1065 # in the hashtable.
1066 sub get_directory_contents
1068 my $dirname=$_[0];
1069 my $directory;
1071 #print "getting the contents of $dirname\n";
1073 # check for a cached version
1074 $dirname =~ s+/$++;
1075 if ($dirname eq "") {
1076 $dirname=cwd;
1078 $directory=$directories{$dirname};
1079 if (defined $directory) {
1080 #print "->@$directory\n";
1081 return $directory;
1084 # Read this directory
1085 if (opendir(DIRECTORY, "$dirname")) {
1086 my @files=readdir DIRECTORY;
1087 closedir(DIRECTORY);
1088 $directory=\@files;
1089 } else {
1090 # Return an empty list
1091 #print "error: cannot open $dirname\n";
1092 my @files;
1093 $directory=\@files;
1095 #print "->@$directory\n";
1096 $directories{$dirname}=$directory;
1097 return $directory;
1101 # Try to find a file for the specified filename. The attempt is
1102 # case-insensitive which is why it's not trivial. If a match is
1103 # found then we return the pathname with the correct case.
1104 sub search_from
1106 my $dirname=$_[0];
1107 my $path=$_[1];
1108 my $real_path="";
1110 if ($dirname eq "" or $dirname eq ".") {
1111 $dirname=cwd;
1112 } elsif ($dirname =~ m+^[^/]+) {
1113 $dirname=cwd . "/" . $dirname;
1115 if ($dirname !~ m+/$+) {
1116 $dirname.="/";
1119 foreach $component (@$path) {
1120 #print " looking for $component in \"$dirname\"\n";
1121 if ($component eq ".") {
1122 # Pass it as is
1123 $real_path.="./";
1124 } elsif ($component eq "..") {
1125 # Go up one level
1126 $dirname=dirname($dirname) . "/";
1127 $real_path.="../";
1128 } else {
1129 my $directory=get_directory_contents $dirname;
1130 my $found;
1131 foreach $dentry (@$directory) {
1132 if ($dentry =~ /^$component$/i) {
1133 $dirname.="$dentry/";
1134 $real_path.="$dentry/";
1135 $found=1;
1136 last;
1139 if (!defined $found) {
1140 # Give up
1141 #print " could not find $component in $dirname\n";
1142 return;
1146 $real_path=~ s+/$++;
1147 #print " -> found $real_path\n";
1148 return $real_path;
1152 # Performs a case-insensitive search for the specified file in the
1153 # include path.
1154 # $line is the line number that should be referenced when an error occurs
1155 # $filename is the file we are looking for
1156 # $dirname is the directory of the file containing the '#include' directive
1157 # if '"' was used, it is an empty string otherwise
1158 # $project and $target specify part of the include path
1159 sub get_real_include_name
1161 my $line=$_[0];
1162 my $filename=$_[1];
1163 my $dirname=$_[2];
1164 my $project=$_[3];
1165 my $target=$_[4];
1167 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1168 # This is not a relative path, we cannot make any check
1169 my $warning="path:$filename";
1170 if (!defined $warnings{$warning}) {
1171 $warnings{$warning}="1";
1172 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1173 print STDERR "$line: $filename\n";
1175 } else {
1176 # Here's how we proceed:
1177 # - split the filename we look for into its components
1178 # - then for each directory in the include path
1179 # - trace the directory components starting from that directory
1180 # - if we fail to find a match at any point then continue with
1181 # the next directory in the include path
1182 # - otherwise, rejoice, our quest is over.
1183 my @file_components=split /[\/\\]+/, $filename;
1184 #print " Searching for $filename from @$project[$P_PATH]\n";
1186 my $real_filename;
1187 if ($dirname ne "") {
1188 # This is an 'include ""' -> look in dirname first.
1189 #print " in $dirname (include \"\")\n";
1190 $real_filename=search_from($dirname,\@file_components);
1191 if (defined $real_filename) {
1192 return $real_filename;
1195 my $project_settings=@$project[$P_SETTINGS];
1196 foreach $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1197 my $dirname=$include;
1198 $dirname=~ s+^-I++;
1199 if (!is_absolute($dirname)) {
1200 $dirname="@$project[$P_PATH]$dirname";
1201 } else {
1202 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1204 #print " in $dirname\n";
1205 $real_filename=search_from("$dirname",\@file_components);
1206 if (defined $real_filename) {
1207 return $real_filename;
1210 my $dotdotpath=@$project[$P_PATH];
1211 $dotdotpath =~ s/[^\/]+/../g;
1212 foreach $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1213 my $dirname=$include;
1214 $dirname=~ s+^-I++;
1215 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1216 #print " in $dirname (global setting)\n";
1217 $real_filename=search_from("$dirname",\@file_components);
1218 if (defined $real_filename) {
1219 return $real_filename;
1223 $filename =~ s+\\\\+/+g; # in include ""
1224 $filename =~ s+\\+/+g; # in include <> !
1225 if ($opt_lower_include) {
1226 return lc "$filename";
1228 return $filename;
1231 sub print_pack
1233 my $indent=$_[0];
1234 my $size=$_[1];
1235 my $trailer=$_[2];
1237 if ($size =~ /^(1|2|4|8)$/) {
1238 print FILEO "$indent#include <pshpack$size.h>$trailer";
1239 } else {
1240 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1241 print FILEO "$indent#include <pshpack4.h>$trailer";
1246 # 'Parses' a source file and fixes constructs that would not work with
1247 # Winelib. The parsing is rather simple and not all non-portable features
1248 # are corrected. The most important feature that is corrected is the case
1249 # and path separator of '#include' directives. This requires that each
1250 # source file be associated to a project & target so that the proper
1251 # include path is used.
1252 # Also note that the include path is relative to the directory in which the
1253 # compiler is run, i.e. that of the project, not to that of the file.
1254 sub fix_file
1256 my $filename=$_[0];
1257 my $project=$_[1];
1258 my $target=$_[2];
1259 $filename="@$project[$P_PATH]$filename";
1260 if (! -e $filename) {
1261 return;
1264 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1265 my $dirname=dirname($filename);
1266 my $is_mfc=0;
1267 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1268 $is_mfc=1;
1271 print " $filename\n";
1272 #FIXME:assuming that because there is a .bak file, this is what we want is
1273 #probably flawed. Or is it???
1274 if (! -e "$filename.bak") {
1275 if (!copy("$filename","$filename.bak")) {
1276 print STDERR "error: unable to make a backup of $filename:\n";
1277 print STDERR " $!\n";
1278 return;
1281 if (!open(FILEI,"$filename.bak")) {
1282 print STDERR "error: unable to open $filename.bak for reading:\n";
1283 print STDERR " $!\n";
1284 return;
1286 if (!open(FILEO,">$filename")) {
1287 print STDERR "error: unable to open $filename for writing:\n";
1288 print STDERR " $!\n";
1289 return;
1291 my $line=0;
1292 my $modified=0;
1293 my $rc_block_depth=0;
1294 my $rc_textinclude_state=0;
1295 my @pack_stack;
1296 while (<FILEI>) {
1297 $line++;
1298 s/\r\n$/\n/;
1299 if (!/\n$/) {
1300 # Make sure all files are '\n' terminated
1301 $_ .= "\n";
1303 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
1304 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1305 # the RC files it generates (even in non-MFC projects). So we replace
1306 # it with 'winres.h' its very close standard cousin so that non MFC
1307 # projects can compile in Wine without the MFC sources.
1308 my $warning="mfc:afxres.h";
1309 if (!defined $warnings{$warning}) {
1310 $warnings{$warning}="1";
1311 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winres.h'\n";
1312 print STDERR "warning: the above warning is issued only once\n";
1314 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
1315 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winres.h' */\n";
1316 print FILEO "$1$2\"winres.h\"$'";
1317 $modified=1;
1319 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1320 my $from_file=($2 eq "<"?"":$dirname);
1321 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1322 print FILEO "$1$2$real_include_name$4$'";
1323 $modified|=($real_include_name ne $3);
1325 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
1326 # Pragma pack handling
1328 # pack_stack is an array of references describing the stack of
1329 # pack directives currently in effect. Each directive if described
1330 # by a reference to an array containing:
1331 # - "push" for pack(push,...) directives, "" otherwise
1332 # - the directive's identifier at index 1
1333 # - the directive's alignement value at index 2
1335 # Don't believe a word of what the documentation says: it's all wrong.
1336 # The code below is based on the actual behavior of Visual C/C++ 6.
1337 my $pack_indent=$1;
1338 my $pack_header=$2;
1339 if (/^(\))/) {
1340 # pragma pack()
1341 # Pushes the default stack alignment
1342 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1343 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1344 print_pack($pack_indent,4,$');
1345 push @pack_stack, [ "", "", 4 ];
1347 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
1348 # pragma pack(pop)
1349 # pragma pack(pop,n)
1350 # Goes up the stack until it finds a pack(push,...), and pops it
1351 # Ignores any pack(n) entry
1352 # Issues a warning if the pack is of the form pack(push,label)
1353 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1354 my $pack_comment=$';
1355 $pack_comment =~ s/^\s*//;
1356 if ($pack_comment ne "") {
1357 print FILEO "$pack_indent$pack_comment";
1359 while (1) {
1360 my $alignment=pop @pack_stack;
1361 if (!defined $alignment) {
1362 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
1363 last;
1365 if (@$alignment[1]) {
1366 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
1368 print FILEO "$pack_indent#include <poppack.h>\n";
1369 if (@$alignment[0]) {
1370 last;
1374 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
1375 # pragma pack(pop,label[,n])
1376 # Goes up the stack until finding a pack(push,...) and pops it.
1377 # 'n', if specified, is ignored.
1378 # Ignores any pack(n) entry
1379 # Issues a warning if the label of the pack does not match,
1380 # or if it is in fact a pack(push,n)
1381 my $label=$2;
1382 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1383 my $pack_comment=$';
1384 $pack_comment =~ s/^\s*//;
1385 if ($pack_comment ne "") {
1386 print FILEO "$pack_indent$pack_comment";
1388 while (1) {
1389 my $alignment=pop @pack_stack;
1390 if (!defined $alignment) {
1391 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
1392 last;
1394 if (@$alignment[1] and @$alignment[1] ne $label) {
1395 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
1397 print FILEO "$pack_indent#include <poppack.h>\n";
1398 if (@$alignment[0]) {
1399 last;
1403 } elsif (/^(push\s*\))/) {
1404 # pragma pack(push)
1405 # Push the current alignment
1406 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1407 if (@pack_stack > 0) {
1408 my $alignment=$pack_stack[$#pack_stack];
1409 print_pack($pack_indent,@$alignment[2],$');
1410 push @pack_stack, [ "push", "", @$alignment[2] ];
1411 } else {
1412 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1413 print_pack($pack_indent,4,$');
1414 push @pack_stack, [ "push", "", 4 ];
1417 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
1418 # pragma pack([push,]n)
1419 # Push new alignment n
1420 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1421 print_pack($pack_indent,$3,"$'");
1422 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
1424 } elsif (/^((\w+)\s*\))/) {
1425 # pragma pack(label)
1426 # label must in fact be a macro that resolves to an integer
1427 # Then behaves like 'pragma pack(n)'
1428 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1429 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
1430 print_pack($pack_indent,4,$');
1431 push @pack_stack, [ "", "", 4 ];
1433 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
1434 # pragma pack(push,label[,n])
1435 # Pushes a new label on the stack. It is possible to push the same
1436 # label multiple times. If 'n' is omitted then the alignment is
1437 # unchanged. Otherwise it becomes 'n'.
1438 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1439 my $size;
1440 if (defined $4) {
1441 $size=$4;
1442 } elsif (@pack_stack > 0) {
1443 my $alignment=$pack_stack[$#pack_stack];
1444 $size=@$alignment[2];
1445 } else {
1446 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1447 $size=4;
1449 print_pack($pack_indent,$size,$');
1450 push @pack_stack, [ "push", $2, $size ];
1452 } else {
1453 # pragma pack(??? -> What's that?
1454 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
1455 print FILEO "$pack_indent$pack_header$_";
1458 $modified=1;
1460 } elsif ($is_rc) {
1461 if ($rc_block_depth == 0 and /^(\w+\s+(BITMAP|CURSOR|FONT|FONTDIR|ICON|MESSAGETABLE|TEXT)\s+((DISCARDABLE|FIXED|IMPURE|LOADONCALL|MOVEABLE|PRELOAD|PURE|RTF)\s+)*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1462 my $from_file=($5 eq "<"?"":$dirname);
1463 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
1464 print FILEO "$1$5$real_include_name$7$'";
1465 $modified|=($real_include_name ne $6);
1467 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1468 my $from_file=($2 eq "<"?"":$dirname);
1469 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1470 print FILEO "$1$2$real_include_name$4$'";
1471 $modified|=($real_include_name ne $3);
1473 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
1474 $rc_textinclude_state=1;
1475 print FILEO;
1477 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
1478 print FILEO "$1winres.h$2$'";
1479 $modified=1;
1481 } elsif (/^\s*BEGIN(\W.*)?$/) {
1482 $rc_textinclude_state|=2;
1483 $rc_block_depth++;
1484 print FILEO;
1486 } elsif (/^\s*END(\W.*)?$/) {
1487 $rc_textinclude_state=0;
1488 if ($rc_block_depth>0) {
1489 $rc_block_depth--;
1491 print FILEO;
1493 } else {
1494 print FILEO;
1497 } else {
1498 print FILEO;
1502 close(FILEI);
1503 close(FILEO);
1504 if ($opt_backup == 0 or $modified == 0) {
1505 if (!unlink("$filename.bak")) {
1506 print STDERR "error: unable to delete $filename.bak:\n";
1507 print STDERR " $!\n";
1513 # Analyzes each source file in turn to find and correct issues
1514 # that would cause it not to compile.
1515 sub fix_source
1517 print "Fixing the source files...\n";
1518 foreach $project (@projects) {
1519 foreach $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
1520 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1521 next;
1523 foreach $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
1524 fix_file($source,$project,$target);
1532 #####
1534 # File generation
1536 #####
1539 # Generates a target's .spec file
1540 sub generate_spec_file
1542 my $path=$_[0];
1543 my $target=$_[1];
1544 my $project_settings=$_[2];
1546 my $basename=@$target[$T_NAME];
1547 $basename =~ s+\.so$++;
1548 if (@$target[$T_FLAGS] & $TF_WRAP) {
1549 $basename =~ s+^lib++;
1550 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1551 $basename.="_wrapper";
1554 if (!open(FILEO,">$path$basename.spec")) {
1555 print STDERR "error: could not open \"$path$basename.spec\" for writing\n";
1556 print STDERR " $!\n";
1557 return;
1560 my $module=$basename;
1561 $module =~ s+^lib++;
1562 $module=canonize($module);
1563 print FILEO "name $module\n";
1564 print FILEO "type win32\n";
1565 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1566 print FILEO "mode guiexe\n";
1567 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1568 print FILEO "mode cuiexe\n";
1569 } else {
1570 print FILEO "mode dll\n";
1572 if (defined @$target[$T_INIT] and ((@$target[$T_FLAGS] & $TF_WRAP) == 0)) {
1573 print FILEO "init @$target[$T_INIT]\n";
1575 if (@{@$target[$T_SOURCES_RC]} > 0) {
1576 if (@{@$target[$T_SOURCES_RC]} > 1) {
1577 print STDERR "warning: the target $basename has more than one RC file. Modify the Makefile.in to remove redundant RC files, and fix the spec file\n";
1579 my $rcname=@{@$target[$T_SOURCES_RC]}[0];
1580 $rcname =~ s+\.rc$++i;
1581 print FILEO "rsrc $rcname.res\n";
1583 print FILEO "\n";
1584 my %imports;
1585 foreach $library (@{$global_settings[$T_IMPORTS]}) {
1586 if (!defined $imports{$library}) {
1587 print FILEO "import $library\n";
1588 $imports{$library}=1;
1591 if (defined $project_settings) {
1592 foreach $library (@{@$project_settings[$T_IMPORTS]}) {
1593 if (!defined $imports{$library}) {
1594 print FILEO "import $library\n";
1595 $imports{$library}=1;
1599 foreach $library (@{@$target[$T_IMPORTS]}) {
1600 if (!defined $imports{$library}) {
1601 print FILEO "import $library\n";
1602 $imports{$library}=1;
1606 # Don't forget to export the 'Main' function for wrapped executables,
1607 # except for MFC ones!
1608 if (@$target[$T_FLAGS] == $TF_WRAP) {
1609 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1610 print FILEO "\n@ stdcall @$target[$T_INIT](long long ptr long) @$target[$T_INIT]\n";
1611 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1612 print FILEO "\n@ stdcall @$target[$T_INIT](long ptr ptr) @$target[$T_INIT]\n";
1613 } else {
1614 print FILEO "\n@ stdcall @$target[$T_INIT](ptr long ptr) @$target[$T_INIT]\n";
1618 close(FILEO);
1622 # Generates a target's wrapper file
1623 sub generate_wrapper_file
1625 my $path=$_[0];
1626 my $target=$_[1];
1628 if (!defined $templates{"wrapper.c"}) {
1629 print STDERR "winemaker: internal error: No template called 'wrapper.c'\n";
1630 return;
1633 if (!open(FILEO,">$path@$target[$T_NAME]_wrapper.c")) {
1634 print STDERR "error: unable to open \"$path$basename.c\" for writing:\n";
1635 print STDERR " $!\n";
1636 return;
1638 my $app_name="\"@$target[$T_NAME]\"";
1639 my $app_type=(@$target[$T_TYPE]==$TT_GUIEXE?"GUIEXE":"CUIEXE");
1640 my $app_init=(@$target[$T_TYPE]==$TT_GUIEXE?"\"WinMain\"":"\"main\"");
1641 my $app_mfc=(@$target[$T_FLAGS] & $TF_MFC?"\"mfc\"":NULL);
1642 foreach $line (@{$templates{"wrapper.c"}}) {
1643 my $l=$line;
1644 $l =~ s/\#\#WINEMAKER_APP_NAME\#\#/$app_name/;
1645 $l =~ s/\#\#WINEMAKER_APP_TYPE\#\#/$app_type/;
1646 $l =~ s/\#\#WINEMAKER_APP_INIT\#\#/$app_init/;
1647 $l =~ s/\#\#WINEMAKER_APP_MFC\#\#/$app_mfc/;
1648 print FILEO $l;
1650 close(FILEO);
1654 # A convenience function to generate all the lists (defines,
1655 # C sources, C++ source, etc.) in the Makefile
1656 sub generate_list
1658 my $name=$_[0];
1659 my $last=$_[1];
1660 my $list=$_[2];
1661 my $data=$_[3];
1662 my $first=$name;
1664 if ($name) {
1665 printf FILEO "%-22s=",$name;
1667 if (defined $list) {
1668 foreach $item (@$list) {
1669 my $value;
1670 if (defined $data) {
1671 $value=&$data($item);
1672 } else {
1673 $value=$item;
1675 if ($value ne "") {
1676 if ($first) {
1677 print FILEO " $value";
1678 $first=0;
1679 } else {
1680 print FILEO " \\\n\t\t\t$value";
1685 if ($last) {
1686 print FILEO "\n";
1691 # Generates a project's Makefile.in and all the target files
1692 sub generate_project_files
1694 my $project=$_[0];
1695 my $project_settings=@$project[$P_SETTINGS];
1696 my @dll_list=();
1697 my @exe_list=();
1699 # Then sort the targets and separate the libraries from the programs
1700 foreach $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
1701 if (@$target[$T_TYPE] == $TT_DLL) {
1702 push @dll_list,$target;
1703 } else {
1704 push @exe_list,$target;
1707 @$project[$P_TARGETS]=[];
1708 push @{@$project[$P_TARGETS]}, @dll_list;
1709 push @{@$project[$P_TARGETS]}, @exe_list;
1711 if (!open(FILEO,">@$project[$P_PATH]Makefile.in")) {
1712 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile.in\" for writing\n";
1713 print STDERR " $!\n";
1714 return;
1717 print FILEO "### Generated by Winemaker\n";
1718 print FILEO "\n\n";
1720 print FILEO "### Generic autoconf variables\n\n";
1721 generate_list("TOPSRCDIR",1,[ "\@top_srcdir\@" ]);
1722 generate_list("TOPOBJDIR",1,[ "." ]);
1723 generate_list("SRCDIR",1,[ "\@srcdir\@" ]);
1724 generate_list("VPATH",1,[ "\@srcdir\@" ]);
1725 print FILEO "\n";
1726 if (@$project[$P_PATH] eq "") {
1727 # This is the main project. It is also responsible for recursively
1728 # calling the other projects
1729 generate_list("SUBDIRS",1,\@projects,sub
1731 if ($_[0] != \@main_project) {
1732 my $subdir=@{$_[0]}[$P_PATH];
1733 $subdir =~ s+/$++;
1734 return $subdir;
1736 # Eliminating the main project by returning undefined!
1739 if (@{@$project[$P_TARGETS]} > 0) {
1740 generate_list("DLLS",1,\@dll_list,sub
1742 return @{$_[0]}[$T_NAME];
1744 generate_list("EXES",1,\@exe_list,sub
1746 return "@{$_[0]}[$T_NAME]";
1748 print FILEO "\n\n\n";
1750 print FILEO "### Global settings\n\n";
1751 # Make it so that the project-wide settings override the global settings
1752 generate_list("DEFINES",0,@$project_settings[$T_DEFINES],sub
1754 return "$_[0]";
1756 generate_list("",1,$global_settings[$T_DEFINES],sub
1758 return "$_[0]";
1760 generate_list("INCLUDE_PATH",$no_extra,@$project_settings[$T_INCLUDE_PATH],sub
1762 return "$_[0]";
1764 generate_list("",1,$global_settings[$T_INCLUDE_PATH],sub
1766 if ($_[0] !~ /^-I/) {
1767 return "$_[0]";
1769 if (is_absolute($')) {
1770 return "$_[0]";
1772 return "-I\$(TOPSRCDIR)/$'";
1774 generate_list("LIBRARY_PATH",$no_extra,@$project_settings[$T_LIBRARY_PATH],sub
1776 return "$_[0]";
1778 generate_list("",1,$global_settings[$T_LIBRARY_PATH],sub
1780 if ($_[0] !~ /^-L/) {
1781 return "$_[0]";
1783 if (is_absolute($')) {
1784 return "$_[0]";
1786 return "-L\$(TOPSRCDIR)/$'";
1788 generate_list("LIBRARIES",$no_extra,@$project_settings[$T_LIBRARIES],sub
1790 return "$_[0]";
1792 generate_list("",1,$global_settings[$T_LIBRARIES],sub
1794 return "$_[0]";
1796 print FILEO "\n\n";
1798 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
1799 @{@$project_settings[$T_SOURCES_CXX]}+
1800 @{@$project_settings[$T_SOURCES_RC]};
1801 my $no_extra=($extra_source_count == 0);
1802 if (!$no_extra) {
1803 print FILEO "### Extra source lists\n\n";
1804 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
1805 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
1806 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
1807 print FILEO "\n";
1808 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
1809 print FILEO "\n\n\n";
1812 # Iterate over all the targets...
1813 foreach $target (@{@$project[$P_TARGETS]}) {
1814 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
1815 my $canon=canonize("@$target[$T_NAME]");
1816 $canon =~ s+_so$++;
1817 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
1818 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
1819 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
1820 my $basename=@$target[$T_NAME];
1821 $basename =~ s+\.so$++;
1822 if (@$target[$T_FLAGS] & $TF_WRAP) {
1823 $basename =~ s+^lib++;
1824 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1825 $basename.="_wrapper";
1827 generate_list("${canon}_SPEC_SRCS",1,[ "$basename.spec"]);
1828 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH],sub
1830 return "$_[0]";
1832 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES],sub
1834 return "$_[0]";
1836 generate_list("${canon}_DEPENDS",1,@$target[$T_DEPENDS],sub
1838 return "$_[0]";
1840 print FILEO "\n";
1841 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(EXTRA_OBJS)"]);
1842 print FILEO "\n\n\n";
1844 print FILEO "### Global source lists\n\n";
1845 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
1847 my $canon=canonize(@{$_[0]}[$T_NAME]);
1848 $canon =~ s+_so$++;
1849 return "\$(${canon}_C_SRCS)";
1851 if (!$no_extra) {
1852 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
1854 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
1856 my $canon=canonize(@{$_[0]}[$T_NAME]);
1857 $canon =~ s+_so$++;
1858 return "\$(${canon}_CXX_SRCS)";
1860 if (!$no_extra) {
1861 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
1863 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
1865 my $canon=canonize(@{$_[0]}[$T_NAME]);
1866 $canon =~ s+_so$++;
1867 return "\$(${canon}_RC_SRCS)";
1869 if (!$no_extra) {
1870 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
1872 generate_list("SPEC_SRCS",1,@$project[$P_TARGETS],sub
1874 my $canon=canonize(@{$_[0]}[$T_NAME]);
1875 $canon =~ s+_so$++;
1876 return "\$(${canon}_SPEC_SRCS)";
1879 print FILEO "\n\n\n";
1881 print FILEO "### Generic autoconf targets\n\n";
1882 print FILEO "all: ";
1883 if (@$project[$P_PATH] eq "") {
1884 print FILEO "\$(SUBDIRS)";
1886 if (@{@$project[$P_TARGETS]} > 0) {
1887 print FILEO "\$(DLLS) \$(EXES:%=%.so)";
1889 print FILEO "\n\n";
1890 print FILEO "\@MAKE_RULES\@\n";
1891 print FILEO "\n";
1892 print FILEO "install::\n";
1893 if (@$project[$P_PATH] eq "") {
1894 # This is the main project. It is also responsible for recursively
1895 # calling the other projects
1896 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) install) || exit 1; done\n";
1898 if (@{@$project[$P_TARGETS]} > 0) {
1899 print FILEO "\tfor i in \$(EXES); do \$(INSTALL_PROGRAM) \$\$i \$(bindir); done\n";
1900 print FILEO "\tfor i in \$(EXES:%=%.so) \$(DLLS); do \$(INSTALL_LIBRARY) \$\$i \$(libdir); done\n";
1902 print FILEO "\n";
1903 print FILEO "uninstall::\n";
1904 if (@$project[$P_PATH] eq "") {
1905 # This is the main project. It is also responsible for recursively
1906 # calling the other projects
1907 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) uninstall) || exit 1; done\n";
1909 if (@{@$project[$P_TARGETS]} > 0) {
1910 print FILEO "\tfor i in \$(EXES); do \$(RM) \$(bindir)/\$\$i;done\n";
1911 print FILEO "\tfor i in \$(EXES:%=%.so) \$(DLLS); do \$(RM) \$(libdir)/\$\$i;done\n";
1913 print FILEO "\n\n\n";
1915 if (@{@$project[$P_TARGETS]} > 0) {
1916 print FILEO "### Target specific build rules\n\n";
1917 foreach $target (@{@$project[$P_TARGETS]}) {
1918 my $canon=canonize("@$target[$T_NAME]");
1919 $canon =~ s/_so$//;
1920 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.tmp.o): \$(${canon}_OBJS)\n";
1921 print FILEO "\t\$(LDCOMBINE) \$(${canon}_OBJS) -o \$\@\n";
1922 print FILEO "\t-\$(STRIP) \$(STRIPFLAGS) \$\@\n";
1923 print FILEO "\n";
1924 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.spec.c): \$(${canon}_SPEC_SRCS:.spec) \$(${canon}_SPEC_SRCS:.spec=.tmp.o) \$(${canon}_RC_SRCS:.rc=.res)\n";
1925 print FILEO "\t\$(LD_PATH) \$(WINEBUILD) -fPIC \$(${canon}_LIBRARY_PATH) \$(WINE_LIBRARY_PATH) -sym \$(${canon}_SPEC_SRCS:.spec=.tmp.o) -o \$\@ -spec \$(${canon}_SPEC_SRCS)\n";
1926 print FILEO "\n";
1927 my $t_name=@$target[$T_NAME];
1928 if (@$target[$T_TYPE]!=$TT_DLL) {
1929 $t_name.=".so";
1931 print FILEO "$t_name: \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_OBJS) \$(${canon}_DEPENDS) \n";
1932 if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
1933 print FILEO "\t\$(LDXXSHARED)";
1934 } else {
1935 print FILEO "\t\$(LDSHARED)";
1937 print FILEO " \$(LDDLLFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_LIBRARY_PATH) \$(${canon}_LIBRARIES:%=-l%) \$(DLL_LINK) \$(LIBS)\n";
1938 if (@$target[$T_TYPE] ne $TT_DLL) {
1939 print FILEO "\ttest -e @$target[$T_NAME] || \$(LN_S) \$(WINE) @$target[$T_NAME]\n";
1941 print FILEO "\n\n";
1944 close(FILEO);
1946 foreach $target (@{@$project[$P_TARGETS]}) {
1947 generate_spec_file(@$project[$P_PATH],$target,$project_settings);
1948 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1949 generate_wrapper_file(@$project[$P_PATH],$target);
1955 # Perform the replacements in the template configure files
1956 # Return 1 for success, 0 for failure
1957 sub generate_configure
1959 my $filename=$_[0];
1960 my $a_source_file=$_[1];
1962 if (!defined $templates{$filename}) {
1963 if ($filename ne "configure") {
1964 print STDERR "winemaker: internal error: No template called '$filename'\n";
1966 return 0;
1969 if (!open(FILEO,">$filename")) {
1970 print STDERR "error: unable to open \"$filename\" for writing:\n";
1971 print STDERR " $!\n";
1972 return 0;
1974 foreach $line (@{$templates{$filename}}) {
1975 if ($line =~ /^\#\#WINEMAKER_PROJECTS\#\#$/) {
1976 foreach $project (@projects) {
1977 print FILEO "@$project[$P_PATH]Makefile\n";
1979 } else {
1980 $line =~ s+\#\#WINEMAKER_SOURCE\#\#+$a_source_file+;
1981 $line =~ s+\#\#WINEMAKER_NEEDS_MFC\#\#+$needs_mfc+;
1982 print FILEO $line;
1985 close(FILEO);
1986 return 1;
1989 sub generate_generic
1991 my $filename=$_[0];
1993 if (!defined $templates{$filename}) {
1994 print STDERR "winemaker: internal error: No template called '$filename'\n";
1995 return;
1997 if (!open(FILEO,">$filename")) {
1998 print STDERR "error: unable to open \"$filename\" for writing:\n";
1999 print STDERR " $!\n";
2000 return;
2002 foreach $line (@{$templates{$filename}}) {
2003 print FILEO $line;
2005 close(FILEO);
2009 # Generates the global files:
2010 # configure
2011 # configure.in
2012 # Make.rules.in
2013 sub generate_global_files
2015 generate_generic("Make.rules.in");
2017 # Get the name of a source file for configure.in
2018 my $a_source_file;
2019 search_a_file: foreach $project (@projects) {
2020 foreach $target (@{@$project[$P_TARGETS]}, @$project[$P_SETTINGS]) {
2021 $a_source_file=@{@$target[$T_SOURCES_C]}[0];
2022 if (!defined $a_source_file) {
2023 $a_source_file=@{@$target[$T_SOURCES_CXX]}[0];
2025 if (!defined $a_source_file) {
2026 $a_source_file=@{@$target[$T_SOURCES_RC]}[0];
2028 if (defined $a_source_file) {
2029 $a_source_file="@$project[$P_PATH]$a_source_file";
2030 last search_a_file;
2034 if (!defined $a_source_file) {
2035 $a_source_file="Makefile.in";
2038 generate_configure("configure.in",$a_source_file);
2039 unlink("configure");
2040 if (generate_configure("configure",$a_source_file) == 0) {
2041 system("autoconf");
2043 # Add execute permission to configure for whoever has the right to read it
2044 my @st=stat("configure");
2045 if (@st) {
2046 my $mode=$st[2];
2047 $mode|=($mode & 0444) >>2;
2048 chmod($mode,"configure");
2049 } else {
2050 print "warning: could not generate the configure script. You need to run autoconf\n";
2056 sub generate_read_templates
2058 my $file;
2060 while (<DATA>) {
2061 if (/^--- ((\w\.?)+) ---$/) {
2062 my $filename=$1;
2063 if (defined $templates{$filename}) {
2064 print STDERR "winemaker: internal error: There is more than one template for $filename\n";
2065 undef $file;
2066 } else {
2067 $file=[];
2068 $templates{$filename}=$file;
2070 } elsif (defined $file) {
2071 push @$file, $_;
2077 # This is where we finally generate files. In fact this method does not
2078 # do anything itself but calls the methods that do the actual work.
2079 sub generate
2081 print "Generating project files...\n";
2082 generate_read_templates();
2083 generate_global_files();
2085 foreach $project (@projects) {
2086 my $path=@$project[$P_PATH];
2087 if ($path eq "") {
2088 $path=".";
2089 } else {
2090 $path =~ s+/$++;
2092 print " $path\n";
2093 generate_project_files($project);
2099 #####
2101 # Option defaults
2103 #####
2105 $opt_backup=1;
2106 $opt_lower=$OPT_LOWER_UPPERCASE;
2107 $opt_lower_include=1;
2109 # $opt_work_dir=<undefined>
2110 # $opt_single_target=<undefined>
2111 $opt_target_type=$TT_GUIEXE;
2112 $opt_flags=0;
2113 $opt_is_interactive=$OPT_ASK_NO;
2114 $opt_ask_project_options=$OPT_ASK_NO;
2115 $opt_ask_target_options=$OPT_ASK_NO;
2116 $opt_no_generated_files=0;
2117 $opt_no_banner=0;
2121 #####
2123 # Main
2125 #####
2127 sub print_banner
2129 print "Winemaker $version\n";
2130 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2133 sub usage
2135 print_banner();
2136 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup]\n";
2137 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2138 print STDERR " [--lower-include|--nolower-include]\n";
2139 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2140 print STDERR " [--wrap|--nowrap] [--mfc|--nomfc]\n";
2141 print STDERR " [-Dmacro[=defn]] [-Idir] [-Ldir] [-idll] [-llibrary]\n";
2142 print STDERR " [--interactive] [--single-target name]\n";
2143 print STDERR " [--generated-files|--nogenerated-files]\n";
2144 print STDERR " work_directory\n";
2145 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2146 print STDERR "the specified directory so that they can be compiled with Winelib. During this\n";
2147 print STDERR "process it will modify and rename some of the files in that directory.\n";
2148 print STDERR "\tPlease read the manual page before use.\n";
2149 exit (2);
2153 project_init(\@main_project,"");
2155 while (@ARGV>0) {
2156 my $arg=shift @ARGV;
2157 # General options
2158 if ($arg eq "--nobanner") {
2159 $opt_no_banner=1;
2160 } elsif ($arg eq "--backup") {
2161 $opt_backup=1;
2162 } elsif ($arg eq "--nobackup") {
2163 $opt_backup=0;
2164 } elsif ($arg eq "--single-target") {
2165 $opt_single_target=shift @ARGV;
2166 } elsif ($arg eq "--lower-none") {
2167 $opt_lower=$OPT_LOWER_NONE;
2168 } elsif ($arg eq "--lower-all") {
2169 $opt_lower=$OPT_LOWER_ALL;
2170 } elsif ($arg eq "--lower-uppercase") {
2171 $opt_lower=$OPT_LOWER_UPPERCASE;
2172 } elsif ($arg eq "--lower-include") {
2173 $opt_lower_include=1;
2174 } elsif ($arg eq "--nolower-include") {
2175 $opt_lower_include=0;
2176 } elsif ($arg eq "--generated-files") {
2177 $opt_no_generated_files=0;
2178 } elsif ($arg eq "--nogenerated-files") {
2179 $opt_no_generated_files=1;
2181 } elsif ($arg =~ /^-D/) {
2182 push @{$global_settings[$T_DEFINES]},$arg;
2183 } elsif ($arg =~ /^-I/) {
2184 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2185 } elsif ($arg =~ /^-L/) {
2186 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2187 } elsif ($arg =~ /^-i/) {
2188 push @{$global_settings[$T_IMPORTS]},$';
2189 } elsif ($arg =~ /^-l/) {
2190 push @{$global_settings[$T_LIBRARIES]},$';
2192 # 'Source'-based method options
2193 } elsif ($arg eq "--dll") {
2194 $opt_target_type=$TT_DLL;
2195 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2196 $opt_target_type=$TT_GUIEXE;
2197 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2198 $opt_target_type=$TT_CUIEXE;
2199 } elsif ($arg eq "--interactive") {
2200 $opt_is_interactive=$OPT_ASK_YES;
2201 $opt_ask_project_options=$OPT_ASK_YES;
2202 $opt_ask_target_options=$OPT_ASK_YES;
2203 } elsif ($arg eq "--wrap") {
2204 $opt_flags|=$TF_WRAP;
2205 } elsif ($arg eq "--nowrap") {
2206 $opt_flags&=~$TF_WRAP;
2207 } elsif ($arg eq "--mfc") {
2208 $opt_flags|=$TF_MFC;
2209 $opt_flags|=$TF_MFC|$TF_WRAP;
2210 $needs_mfc=1;
2211 } elsif ($arg eq "--nomfc") {
2212 $opt_flags&=~($TF_MFC|$TF_WRAP);
2213 $needs_mfc=0;
2215 # Catch errors
2216 } else {
2217 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2218 if (!defined $opt_work_dir) {
2219 $opt_work_dir=$arg;
2220 } else {
2221 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2222 usage();
2224 } else {
2225 usage();
2230 if (!defined $opt_work_dir) {
2231 print STDERR "error: you must specify the directory containing the sources to be converted\n";
2232 usage();
2233 } elsif (!chdir $opt_work_dir) {
2234 print STDERR "error: could not chdir to the work directory\n";
2235 print STDERR " $!\n";
2236 usage();
2239 if ($opt_no_banner == 0) {
2240 print_banner();
2243 # Fix the file and directory names
2244 fix_file_and_directory_names(".");
2246 # Scan the sources to identify the projects and targets
2247 source_scan();
2249 # Create targets for wrappers, etc.
2250 postprocess_targets();
2252 # Fix the source files
2253 fix_source();
2255 # Generate the Makefile and the spec file
2256 if (! $opt_no_generated_files) {
2257 generate();
2261 __DATA__
2262 --- configure.in ---
2263 dnl Process this file with autoconf to produce a configure script.
2264 dnl Author: Michael Patra <micky@marie.physik.tu-berlin.de>
2265 dnl <patra@itp1.physik.tu-berlin.de>
2266 dnl Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2268 AC_REVISION([configure.in 1.00])
2269 AC_INIT(##WINEMAKER_SOURCE##)
2271 NEEDS_MFC=##WINEMAKER_NEEDS_MFC##
2273 dnl **** Command-line arguments ****
2275 AC_SUBST(OPTIONS)
2277 dnl **** Check for some programs ****
2279 AC_PROG_MAKE_SET
2280 AC_PROG_CC
2281 AC_PROG_CXX
2282 AC_PROG_CPP
2283 AC_PATH_XTRA
2284 AC_PROG_RANLIB
2285 AC_PROG_LN_S
2286 AC_PATH_PROG(LDCONFIG, ldconfig, true, /sbin:/usr/sbin:$PATH)
2288 dnl **** Check for some libraries ****
2290 dnl Check for -lm for BeOS
2291 AC_CHECK_LIB(m,sqrt)
2292 dnl Check for -li386 for NetBSD and OpenBSD
2293 AC_CHECK_LIB(i386,i386_set_ldt)
2294 dnl Check for -lossaudio for NetBSD
2295 AC_CHECK_LIB(ossaudio,_oss_ioctl)
2296 dnl Check for -lw for Solaris
2297 AC_CHECK_LIB(w,iswalnum)
2298 dnl Check for -lnsl for Solaris
2299 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))
2300 dnl Check for -lsocket for Solaris
2301 AC_CHECK_FUNCS(connect,,AC_CHECK_LIB(socket,connect))
2302 dnl Check for -lxpg4 for FreeBSD
2303 AC_CHECK_LIB(xpg4,setrunelocale)
2304 dnl Check for -lmmap for OS/2
2305 AC_CHECK_LIB(mmap,mmap)
2306 dnl Check for openpty
2307 AC_CHECK_FUNCS(openpty,,
2308 AC_CHECK_LIB(util,openpty,
2309 AC_DEFINE(HAVE_OPENPTY)
2310 LIBS="$LIBS -lutil"
2313 AC_CHECK_HEADERS(dlfcn.h,
2314 AC_CHECK_FUNCS(dlopen,
2315 AC_DEFINE(HAVE_DL_API),
2316 AC_CHECK_LIB(dl,dlopen,
2317 AC_DEFINE(HAVE_DL_API)
2318 LIBS="$LIBS -ldl",
2323 dnl **** Check which curses lib to use ***
2324 if test "$CURSES" = "yes"
2325 then
2326 AC_CHECK_HEADERS(ncurses.h)
2327 if test "$ac_cv_header_ncurses_h" = "yes"
2328 then
2329 AC_CHECK_LIB(ncurses,waddch)
2331 if test "$ac_cv_lib_ncurses_waddch" = "yes"
2332 then
2333 AC_CHECK_LIB(ncurses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2334 AC_CHECK_LIB(ncurses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2335 else
2336 AC_CHECK_HEADERS(curses.h)
2337 if test "$ac_cv_header_curses_h" = "yes"
2338 then
2339 AC_CHECK_LIB(curses,waddch)
2340 if test "$ac_cv_lib_curses_waddch" = "yes"
2341 then
2342 AC_CHECK_LIB(curses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2343 AC_CHECK_LIB(curses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2349 dnl **** If ln -s doesn't work, use cp instead ****
2350 if test "$ac_cv_prog_LN_S" = "ln -s"; then : ; else LN_S=cp ; fi
2352 dnl **** Check for gcc strength-reduce bug ****
2354 if test "x${GCC}" = "xyes"
2355 then
2356 AC_CACHE_CHECK( "for gcc strength-reduce bug", ac_cv_c_gcc_strength_bug,
2357 AC_TRY_RUN([
2358 int main(void) {
2359 static int Array[[3]];
2360 unsigned int B = 3;
2361 int i;
2362 for(i=0; i<B; i++) Array[[i]] = i - 3;
2363 exit( Array[[1]] != -2 );
2365 ac_cv_c_gcc_strength_bug="no",
2366 ac_cv_c_gcc_strength_bug="yes",
2367 ac_cv_c_gcc_strength_bug="yes") )
2368 if test "$ac_cv_c_gcc_strength_bug" = "yes"
2369 then
2370 CFLAGS="$CFLAGS -fno-strength-reduce"
2374 dnl **** Check for underscore on external symbols ****
2376 AC_CACHE_CHECK("whether external symbols need an underscore prefix",
2377 ac_cv_c_extern_prefix,
2378 [saved_libs=$LIBS
2379 LIBS="conftest_asm.s $LIBS"
2380 cat > conftest_asm.s <<EOF
2381 .globl _ac_test
2382 _ac_test:
2383 .long 0
2385 AC_TRY_LINK([extern int ac_test;],[if (ac_test) return 1],
2386 ac_cv_c_extern_prefix="yes",ac_cv_c_extern_prefix="no")
2387 LIBS=$saved_libs])
2388 if test "$ac_cv_c_extern_prefix" = "yes"
2389 then
2390 AC_DEFINE(NEED_UNDERSCORE_PREFIX)
2393 dnl **** Check for working dll ****
2395 LDSHARED=""
2396 LDXXSHARED=""
2397 LDDLLFLAGS=""
2398 AC_CACHE_CHECK("whether we can build a Linux dll",
2399 ac_cv_c_dll_linux,
2400 [saved_cflags=$CFLAGS
2401 CFLAGS="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0,-Bsymbolic"
2402 AC_TRY_LINK(,[return 1],ac_cv_c_dll_linux="yes",ac_cv_c_dll_linux="no")
2403 CFLAGS=$saved_cflags
2405 if test "$ac_cv_c_dll_linux" = "yes"
2406 then
2407 LDSHARED="\$(CC) -shared -Wl,-rpath,\$(libdir)"
2408 LDXXSHARED="\$(CXX) -shared -Wl,-rpath,\$(libdir)"
2409 LDDLLFLAGS="-Wl,-Bsymbolic"
2410 else
2411 AC_CACHE_CHECK(whether we can build a UnixWare (Solaris) dll,
2412 ac_cv_c_dll_unixware,
2413 [saved_cflags=$CFLAGS
2414 CFLAGS="$CFLAGS -fPIC -Wl,-G,-h,conftest.so.1.0,-B,symbolic"
2415 AC_TRY_LINK(,[return 1],ac_cv_c_dll_unixware="yes",ac_cv_c_dll_unixware="no")
2416 CFLAGS=$saved_cflags
2418 if test "$ac_cv_c_dll_unixware" = "yes"
2419 then
2420 LDSHARED="\$(CC) -Wl,-G"
2421 LDXXSHARED="\$(CXX) -Wl,-G"
2422 LDDLLFLAGS="-Wl,-B,symbolic"
2423 else
2424 AC_CACHE_CHECK("whether we can build a NetBSD dll",
2425 ac_cv_c_dll_netbsd,
2426 [saved_cflags=$CFLAGS
2427 CFLAGS="$CFLAGS -fPIC -Wl,-Bshareable,-Bforcearchive"
2428 AC_TRY_LINK(,[return 1],ac_cv_c_dll_netbsd="yes",ac_cv_c_dll_netbsd="no")
2429 CFLAGS=$saved_cflags
2431 if test "$ac_cv_c_dll_netbsd" = "yes"
2432 then
2433 LDSHARED="\$(CC) -Wl,-Bshareable,-Bforcearchive"
2434 LDXXSHARED="\$(CXX) -Wl,-Bshareable,-Bforcearchive"
2435 LDDLLFLAGS="" #FIXME
2439 if test "$ac_cv_c_dll_linux" = "no" -a "$ac_cv_c_dll_unixware" = "no" -a "$ac_cv_c_dll_netbsd" = "no"
2440 then
2441 AC_MSG_ERROR([Could not find how to build a dynamically linked library])
2444 CFLAGS="$CFLAGS -fPIC"
2445 DLL_LINK="\$(WINE_LIBRARY_PATH) \$(LIBRARY_PATH) \$(LIBRARIES:%=-l%) -lwine -lwine_unicode -lwine_uuid"
2447 AC_SUBST(DLL_LINK)
2448 AC_SUBST(LDSHARED)
2449 AC_SUBST(LDXXSHARED)
2450 AC_SUBST(LDDLLFLAGS)
2452 dnl *** check for the need to define __i386__
2454 AC_CACHE_CHECK("whether we need to define __i386__",ac_cv_cpp_def_i386,
2455 AC_EGREP_CPP(yes,[#if (defined(i386) || defined(__i386)) && !defined(__i386__)
2457 #endif],
2458 ac_cv_cpp_def_i386="yes", ac_cv_cpp_def_i386="no"))
2459 if test "$ac_cv_cpp_def_i386" = "yes"
2460 then
2461 CFLAGS="$CFLAGS -D__i386__"
2464 dnl $GCC is set by autoconf
2465 GCC_NO_BUILTIN=""
2466 if test "$GCC" = "yes"
2467 then
2468 GCC_NO_BUILTIN="-fno-builtin"
2470 AC_SUBST(GCC_NO_BUILTIN)
2472 dnl **** Test Winelib-related features of the C++ compiler
2473 AC_LANG_CPLUSPLUS()
2474 if test "x${GCC}" = "xyes"
2475 then
2476 OLDCXXFLAGS="$CXXFLAGS";
2477 CXXFLAGS="-fpermissive";
2478 AC_CACHE_CHECK("for g++ -fpermissive option", has_gxx_permissive,
2479 AC_TRY_COMPILE(,[
2480 for (int i=0;i<2;i++);
2481 i=0;
2483 [has_gxx_permissive="yes"],
2484 [has_gxx_permissive="no"])
2486 CXXFLAGS="-fno-for-scope";
2487 AC_CACHE_CHECK("for g++ -fno-for-scope option", has_gxx_no_for_scope,
2488 AC_TRY_COMPILE(,[
2489 for (int i=0;i<2;i++);
2490 i=0;
2492 [has_gxx_no_for_scope="yes"],
2493 [has_gxx_no_for_scope="no"])
2495 CXXFLAGS="$OLDCXXFLAGS";
2496 if test "$has_gxx_permissive" = "yes"
2497 then
2498 CXXFLAGS="$CXXFLAGS -fpermissive"
2500 if test "$has_gxx_no_for_scope" = "yes"
2501 then
2502 CXXFLAGS="$CXXFLAGS -fno-for-scope"
2505 AC_LANG_C()
2507 dnl **** Test Winelib-related features of the C compiler
2508 dnl none for now
2510 dnl **** Macros for finding a headers/libraries in a collection of places
2512 dnl AC_PATH_HEADER(variable,header,action-if-not-found,default-locations)
2513 dnl Note that the above may set variable to an empty value if the header is
2514 dnl already in the include path
2515 AC_DEFUN(AC_PATH_HEADER,[
2516 AC_MSG_CHECKING([for $2])
2517 AC_CACHE_VAL(ac_cv_path_$1,
2519 ac_found=
2520 ac_dummy="ifelse([$4], , :/usr/local/include, [$4])"
2521 save_CPPFLAGS="$CPPFLAGS"
2522 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2523 for ac_dir in $ac_dummy; do
2524 IFS="$ac_save_ifs"
2525 if test -z "$ac_dir"
2526 then
2527 CPPFLAGS="$save_CPPFLAGS"
2528 else
2529 CPPFLAGS="-I$ac_dir $save_CPPFLAGS"
2531 AC_TRY_COMPILE([#include <$2>],,ac_found=1;ac_cv_path_$1="$ac_dir";break)
2532 done
2533 CPPFLAGS="$save_CPPFLAGS"
2534 ifelse([$3],,,[if test -z "$ac_found"
2535 then
2540 $1="$ac_cv_path_$1"
2541 if test -n "$ac_found" -o -n "[$]$1"
2542 then
2543 AC_MSG_RESULT([$]$1)
2544 else
2545 AC_MSG_RESULT(no)
2547 AC_SUBST($1)
2550 dnl AC_PATH_LIBRARY(variable,libraries,extra libs,action-if-not-found,default-locations)
2551 AC_DEFUN(AC_PATH_LIBRARY,[
2552 AC_MSG_CHECKING([for $2])
2553 AC_CACHE_VAL(ac_cv_path_$1,
2555 ac_found=
2556 ac_dummy="ifelse([$5], , :/usr/local/lib, [$5])"
2557 save_LIBS="$LIBS"
2558 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2559 for ac_dir in $ac_dummy; do
2560 IFS="$ac_save_ifs"
2561 if test -z "$ac_dir"
2562 then
2563 LIBS="$2 $3 $save_LIBS"
2564 else
2565 LIBS="-L$ac_dir $2 $3 $save_LIBS"
2567 AC_TRY_LINK(,,ac_found=1;ac_cv_path_$1="$ac_dir";break)
2568 done
2569 LIBS="$save_LIBS"
2570 ifelse([$4],,,[if test -z "$ac_found"
2571 then
2576 $1="$ac_cv_path_$1"
2577 if test -n "$ac_found" -o -n "[$]$1"
2578 then
2579 AC_MSG_RESULT([$]$1)
2580 else
2581 AC_MSG_RESULT(no)
2583 AC_SUBST($1)
2586 dnl **** Try to find where winelib is located ****
2588 LD_PATH="";
2589 WINE_INCLUDE_ROOT="";
2590 WINE_INCLUDE_PATH="";
2591 WINE_LIBRARY_ROOT="";
2592 WINE_LIBRARY_PATH="";
2593 WINE_TOOL_PATH="";
2594 WINE="";
2595 WINEBUILD="";
2596 WRC="";
2598 AC_ARG_WITH(wine,
2599 [ --with-wine=DIR the Wine package (or sources) is in DIR],
2600 [if test "$withval" != "no"; then
2601 WINE_ROOT="$withval";
2602 WINE_INCLUDES="";
2603 WINE_LIBRARIES="";
2604 WINE_TOOLS="";
2605 else
2606 WINE_ROOT="";
2607 fi])
2608 if test -n "$WINE_ROOT"
2609 then
2610 WINE_INCLUDE_ROOT="$WINE_ROOT/include:$WINE_ROOT/include/wine";
2611 WINE_LIBRARY_ROOT="$WINE_ROOT";
2612 WINE_TOOL_PATH="$WINE_ROOT:$WINE_ROOT/bin:$WINE_ROOT/tools/wrc:$WINE_ROOT/tools/winebuild:$PATH";
2615 AC_ARG_WITH(wine-includes,
2616 [ --with-wine-includes=DIR the Wine includes are in DIR],
2617 [if test "$withval" != "no"; then
2618 WINE_INCLUDES="$withval";
2619 else
2620 WINE_INCLUDES="";
2621 fi])
2622 if test -n "$WINE_INCLUDES"
2623 then
2624 WINE_INCLUDE_ROOT="$WINE_INCLUDES";
2627 AC_ARG_WITH(wine-libraries,
2628 [ --with-wine-libraries=DIR the Wine libraries are in DIR],
2629 [if test "$withval" != "no"; then
2630 WINE_LIBRARIES="$withval";
2631 else
2632 WINE_LIBRARIES="";
2633 fi])
2634 if test -n "$WINE_LIBRARIES"
2635 then
2636 WINE_LIBRARY_ROOT="$WINE_LIBRARIES";
2639 AC_ARG_WITH(wine-tools,
2640 [ --with-wine-tools=DIR the Wine tools are in DIR],
2641 [if test "$withval" != "no"; then
2642 WINE_TOOLS="$withval";
2643 else
2644 WINE_TOOLS="";
2645 fi])
2646 if test -n "$WINE_TOOLS"
2647 then
2648 WINE_TOOL_PATH="$WINE_TOOLS:$WINE_TOOLS/wrc:$WINE_TOOLS/winebuild";
2651 if test -z "$WINE_INCLUDE_ROOT"
2652 then
2653 WINE_INCLUDE_ROOT=":/usr/include/wine:/usr/local/include/wine:/opt/wine/include:/opt/wine/include/wine";
2655 AC_PATH_HEADER(WINE_INCLUDE_ROOT,windef.h,[
2656 AC_MSG_ERROR([Could not find the Wine includes])
2657 ],$WINE_INCLUDE_ROOT)
2658 if test -n "$WINE_INCLUDE_ROOT"
2659 then
2660 WINE_INCLUDE_PATH="-I$WINE_INCLUDE_ROOT"
2661 else
2662 WINE_INCLUDE_PATH=""
2665 if test -z "$WINE_LIBRARY_ROOT"
2666 then
2667 WINE_LIBRARY_ROOT=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib";
2668 else
2669 WINE_LIBRARY_ROOT="$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/lib";
2671 AC_PATH_LIBRARY(WINE_LIBRARY_ROOT,[-lwine],[-lutil],[
2672 AC_MSG_ERROR([Could not find the Wine libraries (libwine.so)])
2673 ],$WINE_LIBRARY_ROOT)
2674 if test -n "$WINE_LIBRARY_ROOT"
2675 then
2676 WINE_LIBRARY_PATH="-L$WINE_LIBRARY_ROOT"
2677 else
2678 WINE_LIBRARY_PATH=""
2680 AC_PATH_LIBRARY(LIBNTDLL_PATH,[-lntdll],[$WINE_LIBRARY_PATH -lwine -lwine_unicode -lncurses -ldl -lutil],[
2681 AC_MSG_ERROR([Could not find the Wine libraries (libntdll.so)])
2682 ],[$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/dlls])
2683 if test -n "$LIBNTDLL_PATH" -a "-L$LIBNTDLL_PATH" != "$WINE_LIBRARY_PATH"
2684 then
2685 WINE_LIBRARY_PATH="$WINE_LIBRARY_PATH -L$LIBNTDLL_PATH"
2687 if test -n "$WINE_LIBRARY_PATH"
2688 then
2689 LD_PATH="LD_LIBRARY_PATH=\"`echo $WINE_LIBRARY_PATH | sed -e 's/ *-L/:/g' -e 's/^://' -e 's/ *$//'`:\$\$LD_LIBRARY_PATH\""
2692 if test -z "$WINE_TOOL_PATH"
2693 then
2694 WINE_TOOL_PATH="$PATH:/usr/local/bin:/opt/wine/bin";
2696 AC_PATH_PROG(WINE,wine,,$WINE_TOOL_PATH)
2697 if test -z "$WINE"
2698 then
2699 AC_MSG_ERROR([Could not find Wine's wine tool])
2701 AC_PATH_PROG(WINEBUILD,winebuild,,$WINE_TOOL_PATH)
2702 if test -z "$WINEBUILD"
2703 then
2704 AC_MSG_ERROR([Could not find Wine's winebuild tool])
2706 AC_PATH_PROG(WRC,wrc,,$WINE_TOOL_PATH)
2707 if test -z "$WRC"
2708 then
2709 AC_MSG_ERROR([Could not find Wine's wrc tool])
2712 AC_SUBST(LD_PATH)
2713 AC_SUBST(WINE_INCLUDE_PATH)
2714 AC_SUBST(WINE_LIBRARY_PATH)
2716 dnl **** Try to find where the MFC are located ****
2717 AC_LANG_CPLUSPLUS()
2719 if test "x$NEEDS_MFC" = "x1"
2720 then
2721 ATL_INCLUDE_ROOT="";
2722 ATL_INCLUDE_PATH="";
2723 MFC_INCLUDE_ROOT="";
2724 MFC_INCLUDE_PATH="";
2725 MFC_LIBRARY_ROOT="";
2726 MFC_LIBRARY_PATH="";
2728 AC_ARG_WITH(mfc,
2729 [ --with-mfc=DIR the MFC package (or sources) is in DIR],
2730 [if test "$withval" != "no"; then
2731 MFC_ROOT="$withval";
2732 ATL_INCLUDES="";
2733 MFC_INCLUDES="";
2734 MFC_LIBRARIES="";
2735 else
2736 MFC_ROOT="";
2737 fi])
2738 if test -n "$MFC_ROOT"
2739 then
2740 ATL_INCLUDE_ROOT="$MFC_ROOT";
2741 MFC_INCLUDE_ROOT="$MFC_ROOT";
2742 MFC_LIBRARY_ROOT="$MFC_ROOT";
2745 AC_ARG_WITH(atl-includes,
2746 [ --with-atl-includes=DIR the ATL includes are in DIR],
2747 [if test "$withval" != "no"; then
2748 ATL_INCLUDES="$withval";
2749 else
2750 ATL_INCLUDES="";
2751 fi])
2752 if test -n "$ATL_INCLUDES"
2753 then
2754 ATL_INCLUDE_ROOT="$ATL_INCLUDES";
2757 AC_ARG_WITH(mfc-includes,
2758 [ --with-mfc-includes=DIR the MFC includes are in DIR],
2759 [if test "$withval" != "no"; then
2760 MFC_INCLUDES="$withval";
2761 else
2762 MFC_INCLUDES="";
2763 fi])
2764 if test -n "$MFC_INCLUDES"
2765 then
2766 MFC_INCLUDE_ROOT="$MFC_INCLUDES";
2769 AC_ARG_WITH(mfc-libraries,
2770 [ --with-mfc-libraries=DIR the MFC libraries are in DIR],
2771 [if test "$withval" != "no"; then
2772 MFC_LIBRARIES="$withval";
2773 else
2774 MFC_LIBRARIES="";
2775 fi])
2776 if test -n "$MFC_LIBRARIES"
2777 then
2778 MFC_LIBRARY_ROOT="$MFC_LIBRARIES";
2781 OLDCPPFLAGS="$CPPFLAGS"
2782 dnl FIXME: We should not have defines in any of the include paths
2783 CPPFLAGS="$WINE_INCLUDE_PATH -I$WINE_INCLUDE_ROOT/mixedcrt -D_DLL -D_MT $CPPFLAGS"
2784 ATL_INCLUDE_PATH="-I\$(WINE_INCLUDE_ROOT)/mixedcrt -D_DLL -D_MT"
2785 if test -z "$ATL_INCLUDE_ROOT"
2786 then
2787 ATL_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/atl:/usr/include/atl:/usr/local/include/atl:/opt/mfc/include/atl:/opt/atl/include"
2788 else
2789 ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT:$ATL_INCLUDE_ROOT/atl:$ATL_INCLUDE_ROOT/atl/include"
2791 AC_PATH_HEADER(ATL_INCLUDE_ROOT,atldef.h,[
2792 AC_MSG_ERROR([Could not find the ATL includes])
2793 ],$ATL_INCLUDE_ROOT)
2794 if test -n "$ATL_INCLUDE_ROOT"
2795 then
2796 ATL_INCLUDE_PATH="$ATL_INCLUDE_PATH -I$ATL_INCLUDE_ROOT"
2799 MFC_INCLUDE_PATH="$ATL_INCLUDE_PATH"
2800 if test -z "$MFC_INCLUDE_ROOT"
2801 then
2802 MFC_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/mfc:/usr/include/mfc:/usr/local/include/mfc:/opt/mfc/include/mfc:/opt/mfc/include"
2803 else
2804 MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT:$MFC_INCLUDE_ROOT/mfc:$MFC_INCLUDE_ROOT/mfc/include"
2806 AC_PATH_HEADER(MFC_INCLUDE_ROOT,afx.h,[
2807 AC_MSG_ERROR([Could not find the MFC includes])
2808 ],$MFC_INCLUDE_ROOT)
2809 if test -n "$MFC_INCLUDE_ROOT" -a "$ATL_INCLUDE_ROOT" != "$MFC_INCLUDE_ROOT"
2810 then
2811 MFC_INCLUDE_PATH="$MFC_INCLUDE_PATH -I$MFC_INCLUDE_ROOT"
2813 CPPFLAGS="$OLDCPPFLAGS"
2815 if test -z "$MFC_LIBRARY_ROOT"
2816 then
2817 MFC_LIBRARY_ROOT=":$WINE_LIBRARY_ROOT:/usr/lib/mfc:/usr/local/lib:/usr/local/lib/mfc:/opt/mfc/lib";
2818 else
2819 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT:$MFC_LIBRARY_ROOT/lib:$MFC_LIBRARY_ROOT/mfc/src";
2821 AC_PATH_LIBRARY(MFC_LIBRARY_ROOT,[-lmfc],[$WINE_LIBRARY_PATH -lwine -lwine_unicode],[
2822 AC_MSG_ERROR([Could not find the MFC library])
2823 ],$MFC_LIBRARY_ROOT)
2824 if test -n "$MFC_LIBRARY_ROOT" -a "$MFC_LIBRARY_ROOT" != "$WINE_LIBRARY_ROOT"
2825 then
2826 MFC_LIBRARY_PATH="-L$MFC_LIBRARY_ROOT"
2827 else
2828 MFC_LIBRARY_PATH=""
2831 AC_SUBST(ATL_INCLUDE_PATH)
2832 AC_SUBST(MFC_INCLUDE_PATH)
2833 AC_SUBST(MFC_LIBRARY_PATH)
2836 AC_LANG_C()
2838 dnl **** Generate output files ****
2840 MAKE_RULES=Make.rules
2841 AC_SUBST_FILE(MAKE_RULES)
2843 AC_OUTPUT([
2844 Make.rules
2845 ##WINEMAKER_PROJECTS##
2848 echo
2849 echo "Configure finished. Do 'make' to build the project."
2850 echo
2852 dnl Local Variables:
2853 dnl comment-start: "dnl "
2854 dnl comment-end: ""
2855 dnl comment-start-skip: "\\bdnl\\b\\s *"
2856 dnl compile-command: "autoconf"
2857 dnl End:
2858 --- Make.rules.in ---
2859 # Copyright 2000 Francois Gouget for CodeWeavers
2860 # fgouget@codeweavers.com
2862 # Global rules shared by all makefiles -*-Makefile-*-
2864 # Each individual makefile must define the following variables:
2865 # WINE_INCLUDE_ROOT: Wine's headers location
2866 # WINE_LIBRARY_ROOT: Wine's libraries location
2867 # TOPOBJDIR : top-level object directory
2868 # SRCDIR : source directory for this module
2870 # Each individual makefile may define the following additional variables:
2872 # SUBDIRS : subdirectories that contain a Makefile
2873 # DLLS : WineLib libraries to be built
2874 # EXES : WineLib executables to be built
2876 # CEXTRA : extra c flags (e.g. '-Wall')
2877 # CXXEXTRA : extra c++ flags (e.g. '-Wall')
2878 # WRCEXTRA : extra wrc flags (e.g. '-p _SysRes')
2879 # DEFINES : defines (e.g. -DSTRICT)
2880 # INCLUDE_PATH : additional include path
2881 # LIBRARY_PATH : additional library path
2882 # LIBRARIES : additional Unix libraries to link with
2884 # C_SRCS : C sources for the module
2885 # CXX_SRCS : C++ sources for the module
2886 # RC_SRCS : resource source files
2887 # SPEC_SRCS : interface definition files
2890 # Where is Wine
2892 WINE_INCLUDE_ROOT = @WINE_INCLUDE_ROOT@
2893 WINE_INCLUDE_PATH = @WINE_INCLUDE_PATH@
2894 WINE_LIBRARY_ROOT = @WINE_LIBRARY_ROOT@
2895 WINE_LIBRARY_PATH = @WINE_LIBRARY_PATH@
2897 LD_PATH = @LD_PATH@
2899 # Where are the MFC
2901 ATL_INCLUDE_ROOT = @ATL_INCLUDE_ROOT@
2902 ATL_INCLUDE_PATH = @ATL_INCLUDE_PATH@
2903 MFC_INCLUDE_ROOT = @MFC_INCLUDE_ROOT@
2904 MFC_INCLUDE_PATH = @MFC_INCLUDE_PATH@
2905 MFC_LIBRARY_ROOT = @MFC_LIBRARY_ROOT@
2906 MFC_LIBRARY_PATH = @MFC_LIBRARY_PATH@
2908 # First some useful definitions
2910 SHELL = /bin/sh
2911 CC = @CC@
2912 CPP = @CPP@
2913 WRC = @WRC@
2914 CFLAGS = @CFLAGS@
2915 CXXFLAGS = @CXXFLAGS@
2916 WRCFLAGS = -r -L
2917 OPTIONS = @OPTIONS@ -D_REENTRANT -DWINELIB
2918 X_CFLAGS = @X_CFLAGS@
2919 X_LIBS = @X_LIBS@
2920 XLIB = @X_PRE_LIBS@ @XLIB@ @X_EXTRA_LIBS@
2921 DLL_LINK = @DLL_LINK@
2922 LIBS = @LIBS@ $(LIBRARY_PATH)
2923 YACC = @YACC@
2924 LEX = @LEX@
2925 LEXLIB = @LEXLIB@
2926 LN_S = @LN_S@
2927 ALLFLAGS = $(DEFINES) -I$(SRCDIR) $(WINE_INCLUDE_PATH) $(INCLUDE_PATH)
2928 ALLCFLAGS = $(CFLAGS) $(CEXTRA) $(OPTIONS) $(X_CFLAGS) $(ALLFLAGS)
2929 ALLCXXFLAGS=$(CXXFLAGS) $(CXXEXTRA) $(OPTIONS) $(X_CFLAGS) $(ALLFLAGS)
2930 ALLWRCFLAGS=$(WRCFLAGS) $(WRCEXTRA) $(OPTIONS) $(ALLFLAGS)
2931 LDCOMBINE = ld -r
2932 LDSHARED = @LDSHARED@
2933 LDXXSHARED= @LDXXSHARED@
2934 LDDLLFLAGS= @LDDLLFLAGS@
2935 STRIP = strip
2936 STRIPFLAGS= --strip-unneeded
2937 RM = rm -f
2938 MV = mv
2939 MKDIR = mkdir -p
2940 WINE = @WINE@
2941 WINEBUILD = @WINEBUILD@
2942 @SET_MAKE@
2944 # Installation infos
2946 INSTALL = @INSTALL@
2947 INSTALL_PROGRAM = @INSTALL_PROGRAM@
2948 INSTALL_DATA = @INSTALL_DATA@
2949 prefix = @prefix@
2950 exec_prefix = @exec_prefix@
2951 bindir = @bindir@
2952 libdir = @libdir@
2953 infodir = @infodir@
2954 mandir = @mandir@
2955 prog_manext = 1
2956 conf_manext = 5
2958 OBJS = $(C_SRCS:.c=.o) $(CXX_SRCS:.cpp=.o) \
2959 $(SPEC_SRCS:.spec=.spec.o)
2960 CLEAN_FILES = *.spec.c y.tab.c y.tab.h lex.yy.c \
2961 core *.orig *.rej \
2962 \\\#*\\\# *~ *% .\\\#*
2964 # Implicit rules
2966 .SUFFIXES: .cpp .rc .res .tmp.o .spec .spec.c .spec.o
2968 .c.o:
2969 $(CC) -c $(ALLCFLAGS) -o $@ $<
2971 .cpp.o:
2972 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2974 .cxx.o:
2975 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2977 .rc.res:
2978 $(LD_PATH) $(WRC) $(ALLWRCFLAGS) -o $@ $<
2980 .PHONY: all install uninstall clean distclean depend dummy
2982 # 'all' target first in case the enclosing Makefile didn't define any target
2984 all: Makefile
2986 # Rules for makefile
2988 Makefile: Makefile.in $(TOPSRCDIR)/configure
2989 @echo Makefile is older than $?, please rerun $(TOPSRCDIR)/configure
2990 @exit 1
2992 # Rules for cleaning
2994 $(SUBDIRS:%=%/__clean__): dummy
2995 cd `dirname $@` && $(MAKE) clean
2997 $(EXTRASUBDIRS:%=%/__clean__): dummy
2998 -cd `dirname $@` && $(RM) $(CLEAN_FILES)
3000 clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
3001 $(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(OBJS) $(SPEC_SRCS:.spec=.tmp.o) $(EXES) $(EXES:%=%.so) $(DLLS)
3003 # Rules for installing
3005 $(SUBDIRS:%=%/__install__): dummy
3006 cd `dirname $@` && $(MAKE) install
3008 $(SUBDIRS:%=%/__uninstall__): dummy
3009 cd `dirname $@` && $(MAKE) uninstall
3011 # Misc. rules
3013 $(SUBDIRS): dummy
3014 @cd $@ && $(MAKE)
3016 dummy:
3018 # End of global rules
3019 --- wrapper.c ---
3021 * Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
3024 #include <dlfcn.h>
3025 #include <windows.h>
3030 * Describe the wrapped application
3034 * This is either CUIEXE for a console based application or
3035 * GUIEXE for a regular windows application.
3037 #define APP_TYPE ##WINEMAKER_APP_TYPE##
3040 * This is the application library's base name, i.e. 'hello' if the
3041 * library is called 'libhello.so'.
3043 static char* appName = ##WINEMAKER_APP_NAME##;
3046 * This is the name of the application's Windows module. If left NULL
3047 * then appName is used.
3049 static char* appModule = NULL;
3052 * This is the application's entry point. This is usually "WinMain" for a
3053 * GUIEXE and 'main' for a CUIEXE application.
3055 static char* appInit = ##WINEMAKER_APP_INIT##;
3058 * This is either non-NULL for MFC-based applications and is the name of the
3059 * MFC's module. This is the module in which we will take the 'WinMain'
3060 * function.
3062 static char* mfcModule = ##WINEMAKER_APP_MFC##;
3067 * Implement the main.
3070 #if APP_TYPE == GUIEXE
3071 typedef int WINAPI (*WinMainFunc)(HINSTANCE hInstance, HINSTANCE hPrevInstance,
3072 PSTR szCmdLine, int iCmdShow);
3073 #else
3074 typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp);
3075 #endif
3077 #if APP_TYPE == GUIEXE
3078 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
3079 PSTR szCmdLine, int iCmdShow)
3080 #else
3081 int WINAPI Main(int argc, char** argv, char** envp)
3082 #endif
3084 void* appLibrary;
3085 HINSTANCE hApp,hMFC,hMain;
3086 void* appMain;
3087 char* libName;
3088 int retcode;
3090 /* Load the application's library */
3091 libName=(char*)malloc(strlen(appName)+5+3+1);
3092 /* FIXME: we should get the wrapper's path and use that as the base for
3093 * the library
3095 sprintf(libName,"./lib%s.so",appName);
3096 appLibrary=dlopen(libName,RTLD_NOW);
3097 if (appLibrary==NULL) {
3098 sprintf(libName,"lib%s.so",appName);
3099 appLibrary=dlopen(libName,RTLD_NOW);
3101 if (appLibrary==NULL) {
3102 char format[]="Could not load the %s library:\r\n%s";
3103 char* error;
3104 char* msg;
3106 error=dlerror();
3107 msg=(char*)malloc(strlen(format)+strlen(libName)+strlen(error));
3108 sprintf(msg,format,libName,error);
3109 MessageBox(NULL,msg,"dlopen error",MB_OK);
3110 free(msg);
3111 return 1;
3114 /* Then if this application is MFC based, load the MFC module */
3115 /* FIXME: I'm not sure this is really necessary */
3116 if (mfcModule!=NULL) {
3117 hMFC=LoadLibrary(mfcModule);
3118 if (hMFC==NULL) {
3119 char format[]="Could not load the MFC module %s (%d)";
3120 char* msg;
3122 msg=(char*)malloc(strlen(format)+strlen(mfcModule)+11);
3123 sprintf(msg,format,mfcModule,GetLastError());
3124 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
3125 free(msg);
3126 return 1;
3128 /* MFC is a special case: the WinMain is in the MFC library,
3129 * instead of the application's library.
3131 hMain=hMFC;
3132 } else {
3133 hMFC=NULL;
3136 /* Load the application's module */
3137 if (appModule==NULL) {
3138 appModule=appName;
3140 hApp=LoadLibrary(appModule);
3141 if (hApp==NULL) {
3142 char format[]="Could not load the application's module %s (%d)";
3143 char* msg;
3145 msg=(char*)malloc(strlen(format)+strlen(appModule)+11);
3146 sprintf(msg,format,appModule,GetLastError());
3147 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
3148 free(msg);
3149 return 1;
3150 } else if (hMain==NULL) {
3151 hMain=hApp;
3154 /* Get the address of the application's entry point */
3155 appMain=(WinMainFunc*)GetProcAddress(hMain, appInit);
3156 if (appMain==NULL) {
3157 char format[]="Could not get the address of %s (%d)";
3158 char* msg;
3160 msg=(char*)malloc(strlen(format)+strlen(appInit)+11);
3161 sprintf(msg,format,appInit,GetLastError());
3162 MessageBox(NULL,msg,"GetProcAddress error",MB_OK);
3163 free(msg);
3164 return 1;
3167 /* And finally invoke the application's entry point */
3168 #if APP_TYPE == GUIEXE
3169 retcode=(*((WinMainFunc)appMain))(hApp,hPrevInstance,szCmdLine,iCmdShow);
3170 #else
3171 retcode=(*((MainFunc)appMain))(argc,argv,envp);
3172 #endif
3174 /* Cleanup and done */
3175 FreeLibrary(hApp);
3176 if (hMFC!=NULL) {
3177 FreeLibrary(hMFC);
3179 dlclose(appLibrary);
3180 free(libName);
3182 return retcode;