Fix file lossage in subdirectories of an 'include' directory (closes #163).
[wine/hacks.git] / tools / winemaker
blob6e79e11d3d09d1509ac8a59cef76a97aa8d8eeb5
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 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
558 return;
561 my $source_count=@sources_c+@sources_cxx+@sources_rc+
562 @{@$project_settings[$T_SOURCES_C]}+
563 @{@$project_settings[$T_SOURCES_CXX]}+
564 @{@$project_settings[$T_SOURCES_RC]};
565 if ($source_count == 0) {
566 # A project without real sources is not a project, get out!
567 if ($project!=$parent_project) {
568 my $parent_settings=@$parent_project[$P_SETTINGS];
569 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
570 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
572 return;
574 #print "targets=",%targets,"\n";
575 #print "target_count=$target_count\n";
576 #print "has_win_project=$has_win_project\n";
577 #print "dirname=$dirname\n";
579 my $target_count;
580 if (($has_win_project != 0) or ($dirname eq "")) {
581 # Deal with cases where we could not find any executable/library, and
582 # thus have no target, although we did find some sort of windows project.
583 $target_count=keys %targets;
584 if ($target_count == 0) {
585 # Try to come up with a target list based on .dsp/.mak files
586 my $prj_list;
587 if (@dsp_files > 0) {
588 $prj_list=\@dsp_files;
589 } else {
590 $prj_list=\@mak_files;
592 foreach $filename (@$prj_list) {
593 $filename =~ s/\.(dsp|mak)$//i;
594 if ($opt_target_type == $TT_DLL) {
595 $filename = "lib$filename.so";
597 $targets{$filename}=1;
599 $target_count=keys %targets;
600 if ($target_count == 0) {
601 # Still nothing, try the name of the directory
602 my $name;
603 if ($dirname eq "") {
604 # Bad luck, this is the top level directory!
605 $name=(split /\//, cwd)[-1];
606 } else {
607 $name=$dirname;
608 # Remove the trailing '/'. Also eliminate whatever is after the last
609 # '.' as it is likely to be meaningless (.orig, .new, ...)
610 $name =~ s+(/|\.[^.]*)$++;
611 if ($name eq "src") {
612 # 'src' is probably a subdirectory of the real project directory.
613 # Try again with the parent (if any).
614 my $parent=$path;
615 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
616 $name=$parent;
617 } else {
618 $name=(split /\//, cwd)[-1];
622 $name =~ s+(/|\.[^.]*)$++;
623 if ($opt_target_type == $TT_DLL) {
624 $name = "lib$name.so";
626 $targets{$name}=1;
630 # Ask confirmation to the user if he wishes so
631 if ($opt_is_interactive == $OPT_ASK_YES) {
632 my $target_list=join " ",keys %targets;
633 print "\n*** In ",($path?$path:"./"),"\n";
634 print "* winemaker found the following list of (potential) targets\n";
635 print "* $target_list\n";
636 print "* Type enter to use it as is, your own comma-separated list of\n";
637 print "* targets, 'none' to assign the source files to a parent directory,\n";
638 print "* or 'ignore' to ignore everything in this directory tree.\n";
639 print "* Target list:\n";
640 $target_list=<STDIN>;
641 chomp $target_list;
642 if ($target_list eq "") {
643 # Keep the target list as is, i.e. do nothing
644 } elsif ($target_list eq "none") {
645 # Empty the target list
646 undef %targets;
647 } elsif ($target_list eq "ignore") {
648 # Ignore this subtree altogether
649 return;
650 } else {
651 undef %targets;
652 foreach $target (split /,/,$target_list) {
653 $target =~ s+^\s*++;
654 $target =~ s+\s*$++;
655 # Also accept .exe and .dll as a courtesy
656 $target =~ s+(.*)\.dll$+lib$1.so+;
657 $target =~ s+\.exe$++;
658 $targets{$target}=1;
664 # If we have no project at this level, then transfer all
665 # the sources to the parent project
666 $target_count=keys %targets;
667 if ($target_count == 0) {
668 if ($project!=$parent_project) {
669 my $parent_settings=@$parent_project[$P_SETTINGS];
670 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
671 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
672 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
673 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
674 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
676 return;
679 # Otherwise add this project to the project list, except for
680 # the main project which is already in the list.
681 if ($dirname ne "") {
682 push @projects,$project;
685 # Ask for project-wide options
686 if ($opt_ask_project_options == $OPT_ASK_YES) {
687 my $flag_desc="";
688 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
689 $flag_desc="mfc";
691 if ((@$project_settings[$T_FLAGS] & $TF_WRAP)!=0) {
692 if ($flag_desc ne "") {
693 $flag_desc.=", ";
695 $flag_desc.="wrapped";
697 print "* Type any project-wide options (-D/-I/-L/-i/-l/--mfc/--wrap),\n";
698 if (defined $flag_desc) {
699 print "* (currently $flag_desc)\n";
701 print "* or 'skip' to skip the target specific options,\n";
702 print "* or 'never' to not be asked this question again:\n";
703 while (1) {
704 my $options=<STDIN>;
705 chomp $options;
706 if ($options eq "skip") {
707 $opt_ask_target_options=$OPT_ASK_SKIP;
708 last;
709 } elsif ($options eq "never") {
710 $opt_ask_project_options=$OPT_ASK_NO;
711 last;
712 } elsif (source_set_options($project_settings,$options)) {
713 last;
715 print "Please re-enter the options:\n";
719 # - Create the targets
720 # - Check if we have both libraries and programs
721 # - Match each target with source files (sort in reverse
722 # alphabetical order to get the longest matches first)
723 my @local_imports=();
724 my @local_depends=();
725 my @exe_list=();
726 foreach $target_name (sort { $b cmp $a } keys %targets) {
727 # Create the target...
728 my $basename;
729 my $target=[];
730 target_init($target);
731 @$target[$T_NAME]=$target_name;
732 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
733 if ($target_name =~ /^lib(.*)\.so$/) {
734 @$target[$T_TYPE]=$TT_DLL;
735 @$target[$T_INIT]=get_default_init($TT_DLL);
736 @$target[$T_FLAGS]&=~$TF_WRAP;
737 $basename=$1;
738 push @local_depends,$target_name;
739 push @local_imports,$basename;
740 } else {
741 @$target[$T_TYPE]=$opt_target_type;
742 @$target[$T_INIT]=get_default_init($opt_target_type);
743 $basename=$target_name;
744 push @exe_list,$target;
746 # This is the default link list of Visual Studio, except odbccp32
747 # which we don't have in Wine. Also I add ntdll which seems
748 # necessary for Winelib.
749 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);
750 @$target[$T_IMPORTS]=\@std_imports;
751 push @{@$project[$P_TARGETS]},$target;
753 # Ask for target-specific options
754 if ($opt_ask_target_options == $OPT_ASK_YES) {
755 my $flag_desc="";
756 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
757 $flag_desc=" (mfc";
759 if ((@$target[$T_FLAGS] & $TF_WRAP)!=0) {
760 if ($flag_desc ne "") {
761 $flag_desc.=", ";
762 } else {
763 $flag_desc=" (";
765 $flag_desc.="wrapped";
767 if ($flag_desc ne "") {
768 $flag_desc.=")";
770 print "* Specify any link option (-L/-i/-l/--mfc/--wrap) specific to the target\n";
771 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
772 while (1) {
773 my $options=<STDIN>;
774 chomp $options;
775 if ($options eq "never") {
776 $opt_ask_target_options=$OPT_ASK_NO;
777 last;
778 } elsif (source_set_options($target,$options)) {
779 last;
781 print "Please re-enter the options:\n";
784 if (@$target[$T_FLAGS] & $TF_MFC) {
785 @$project_settings[$T_FLAGS]|=$TF_MFC;
786 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
787 push @{@$target[$T_IMPORTS]},"mfc.dll";
788 # FIXME: Link with the MFC in the Unix sense, until we
789 # start exporting the functions properly.
790 push @{@$target[$T_LIBRARIES]},"mfc";
793 # Match sources...
794 if ($target_count == 1) {
795 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
796 @$project_settings[$T_SOURCES_C]=[];
797 @sources_c=();
799 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
800 @$project_settings[$T_SOURCES_CXX]=[];
801 @sources_cxx=();
803 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
804 @$project_settings[$T_SOURCES_RC]=[];
805 @sources_rc=();
807 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
808 # No need for sorting these sources
809 @$project_settings[$T_SOURCES_MISC]=[];
810 @sources_misc=();
811 } else {
812 foreach $source (@sources_c) {
813 if ($source =~ /^$basename/i) {
814 push @{@$target[$T_SOURCES_C]},$source;
815 $source="";
818 foreach $source (@sources_cxx) {
819 if ($source =~ /^$basename/i) {
820 push @{@$target[$T_SOURCES_CXX]},$source;
821 $source="";
824 foreach $source (@sources_rc) {
825 if ($source =~ /^$basename/i) {
826 push @{@$target[$T_SOURCES_RC]},$source;
827 $source="";
830 foreach $source (@sources_misc) {
831 if ($source =~ /^$basename/i) {
832 push @{@$target[$T_SOURCES_MISC]},$source;
833 $source="";
837 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
838 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
839 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
840 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
842 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
843 $opt_ask_target_options=$OPT_ASK_YES;
846 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
847 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
849 # The sources that did not match, if any, go to the extra
850 # source list of the project settings
851 foreach $source (@sources_c) {
852 if ($source ne "") {
853 push @{@$project_settings[$T_SOURCES_C]},$source;
856 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
857 foreach $source (@sources_cxx) {
858 if ($source ne "") {
859 push @{@$project_settings[$T_SOURCES_CXX]},$source;
862 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
863 foreach $source (@sources_rc) {
864 if ($source ne "") {
865 push @{@$project_settings[$T_SOURCES_RC]},$source;
868 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
869 foreach $source (@sources_misc) {
870 if ($source ne "") {
871 push @{@$project_settings[$T_SOURCES_MISC]},$source;
874 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
876 # Finally if we are building both libraries and programs in
877 # this directory, then the programs should be linked with all
878 # the libraries
879 if (@local_imports > 0 and @exe_list > 0) {
880 foreach $target (@exe_list) {
881 push @{@$target[$T_LIBRARY_PATH]},"-L.";
882 push @{@$target[$T_IMPORTS]},map { "$_.dll" } @local_imports;
883 # Also link in the Unix sense since none of the functions
884 # will be exported.
885 push @{@$target[$T_LIBRARIES]},@local_imports;
886 push @{@$target[$T_DEPENDS]},@local_depends;
892 # Scan the source directories in search of things to build
893 sub source_scan
895 # If there's a single target then this is going to be the default target
896 if (defined $opt_single_target) {
897 # Create the main target
898 my $main_target=[];
899 target_init($main_target);
900 if ($opt_target_type == $TT_DLL) {
901 @$main_target[$T_NAME]="lib$opt_single_target.so";
902 } else {
903 @$main_target[$T_NAME]="$opt_single_target";
905 @$main_target[$T_TYPE]=$opt_target_type;
907 # Add it to the list
908 push @{$main_project[$P_TARGETS]},$main_target;
911 # The main directory is always going to be there
912 push @projects,\@main_project;
914 # Now scan the directory tree looking for source files and, maybe, targets
915 print "Scanning the source directories...\n";
916 source_scan_directory(\@main_project,"","",0);
918 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
923 #####
925 # 'vc.dsp'-based Project analysis
927 #####
929 #sub analyze_vc_dsp
936 #####
938 # Creating the wrapper targets
940 #####
942 sub postprocess_targets
944 foreach $project (@projects) {
945 foreach $target (@{@$project[$P_TARGETS]}) {
946 if ((@$target[$T_FLAGS] & $TF_WRAP) != 0) {
947 my $wrapper=[];
948 target_init($wrapper);
949 @$wrapper[$T_NAME]=@$target[$T_NAME];
950 @$wrapper[$T_TYPE]=@$target[$T_TYPE];
951 @$wrapper[$T_INIT]=get_default_init(@$target[$T_TYPE]);
952 @$wrapper[$T_FLAGS]=$TF_WRAPPER | (@$target[$T_FLAGS] & $TF_MFC);
953 @$wrapper[$T_IMPORTS]=[ "kernel32.dll", "ntdll.dll", "user32.dll" ];
954 push @{@$wrapper[$T_SOURCES_C]},"@$wrapper[$T_NAME]_wrapper.c";
956 my $index=bsearch(@$target[$T_SOURCES_C],"@$wrapper[$T_NAME]_wrapper.c");
957 if (defined $index) {
958 splice(@{@$target[$T_SOURCES_C]},$index,1);
960 @$target[$T_NAME]="lib@$target[$T_NAME].so";
961 @$target[$T_TYPE]=$TT_DLL;
963 push @{@$project[$P_TARGETS]},$wrapper;
965 if ((@$target[$T_FLAGS] & $TF_MFC) != 0) {
966 @{@$project[$P_SETTINGS]}[$T_FLAGS]|=$TF_MFC;
967 $needs_mfc=1;
975 #####
977 # Source search
979 #####
982 # Performs a directory traversal and renames the files so that:
983 # - they have the case desired by the user
984 # - their extension is of the appropriate case
985 # - they don't contain annoying characters like ' ', '$', '#', ...
986 sub fix_file_and_directory_names
988 my $dirname=$_[0];
990 if (opendir(DIRECTORY, "$dirname")) {
991 foreach $dentry (readdir DIRECTORY) {
992 if ($dentry =~ /^\./ or $dentry eq "CVS") {
993 next;
995 # Set $warn to 1 if the user should be warned of the renaming
996 my $warn=0;
998 # autoconf and make don't support these characters well
999 my $new_name=$dentry;
1000 $new_name =~ s/[ \$]/_/g;
1002 # Only all lowercase extensions are supported (because of the
1003 # transformations ':.c=.o') .
1004 if (-f "$dirname/$new_name") {
1005 if ($new_name =~ /\.C$/) {
1006 $new_name =~ s/\.C$/.c/;
1008 if ($new_name =~ /\.cpp$/i) {
1009 $new_name =~ s/\.cpp$/.cpp/i;
1011 if ($new_name =~ s/\.cxx$/.cpp/i) {
1012 $warn=1;
1014 if ($new_name =~ /\.rc$/i) {
1015 $new_name =~ s/\.rc$/.rc/i;
1017 # And this last one is to avoid confusion then running make
1018 if ($new_name =~ s/^makefile$/makefile.win/) {
1019 $warn=1;
1023 # Adjust the case to the user's preferences
1024 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1025 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1027 $new_name=lc $new_name;
1030 # And finally, perform the renaming
1031 if ($new_name ne $dentry) {
1032 if ($warn) {
1033 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1035 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1036 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1037 print STDERR " $!\n";
1038 $new_name=$dentry;
1041 if (-d "$dirname/$new_name") {
1042 fix_file_and_directory_names("$dirname/$new_name");
1045 closedir(DIRECTORY);
1051 #####
1053 # Source fixup
1055 #####
1058 # This maps a directory name to a reference to an array listing
1059 # its contents (files and directories)
1060 my %directories;
1063 # Retrieves the contents of the specified directory.
1064 # We either get it from the directories hashtable which acts as a
1065 # cache, or use opendir, readdir, closedir and store the result
1066 # in the hashtable.
1067 sub get_directory_contents
1069 my $dirname=$_[0];
1070 my $directory;
1072 #print "getting the contents of $dirname\n";
1074 # check for a cached version
1075 $dirname =~ s+/$++;
1076 if ($dirname eq "") {
1077 $dirname=cwd;
1079 $directory=$directories{$dirname};
1080 if (defined $directory) {
1081 #print "->@$directory\n";
1082 return $directory;
1085 # Read this directory
1086 if (opendir(DIRECTORY, "$dirname")) {
1087 my @files=readdir DIRECTORY;
1088 closedir(DIRECTORY);
1089 $directory=\@files;
1090 } else {
1091 # Return an empty list
1092 #print "error: cannot open $dirname\n";
1093 my @files;
1094 $directory=\@files;
1096 #print "->@$directory\n";
1097 $directories{$dirname}=$directory;
1098 return $directory;
1102 # Try to find a file for the specified filename. The attempt is
1103 # case-insensitive which is why it's not trivial. If a match is
1104 # found then we return the pathname with the correct case.
1105 sub search_from
1107 my $dirname=$_[0];
1108 my $path=$_[1];
1109 my $real_path="";
1111 if ($dirname eq "" or $dirname eq ".") {
1112 $dirname=cwd;
1113 } elsif ($dirname =~ m+^[^/]+) {
1114 $dirname=cwd . "/" . $dirname;
1116 if ($dirname !~ m+/$+) {
1117 $dirname.="/";
1120 foreach $component (@$path) {
1121 #print " looking for $component in \"$dirname\"\n";
1122 if ($component eq ".") {
1123 # Pass it as is
1124 $real_path.="./";
1125 } elsif ($component eq "..") {
1126 # Go up one level
1127 $dirname=dirname($dirname) . "/";
1128 $real_path.="../";
1129 } else {
1130 my $directory=get_directory_contents $dirname;
1131 my $found;
1132 foreach $dentry (@$directory) {
1133 if ($dentry =~ /^$component$/i) {
1134 $dirname.="$dentry/";
1135 $real_path.="$dentry/";
1136 $found=1;
1137 last;
1140 if (!defined $found) {
1141 # Give up
1142 #print " could not find $component in $dirname\n";
1143 return;
1147 $real_path=~ s+/$++;
1148 #print " -> found $real_path\n";
1149 return $real_path;
1153 # Performs a case-insensitive search for the specified file in the
1154 # include path.
1155 # $line is the line number that should be referenced when an error occurs
1156 # $filename is the file we are looking for
1157 # $dirname is the directory of the file containing the '#include' directive
1158 # if '"' was used, it is an empty string otherwise
1159 # $project and $target specify part of the include path
1160 sub get_real_include_name
1162 my $line=$_[0];
1163 my $filename=$_[1];
1164 my $dirname=$_[2];
1165 my $project=$_[3];
1166 my $target=$_[4];
1168 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1169 # This is not a relative path, we cannot make any check
1170 my $warning="path:$filename";
1171 if (!defined $warnings{$warning}) {
1172 $warnings{$warning}="1";
1173 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1174 print STDERR "$line: $filename\n";
1176 } else {
1177 # Here's how we proceed:
1178 # - compute the 'renamed' filename (see renaming phase)
1179 # - split the filename we look for into its components
1180 # - then for each directory in the include path
1181 # - trace the directory components starting from that directory
1182 # - if we fail to find a match at any point then continue with
1183 # the next directory in the include path
1184 # - otherwise, rejoice, our quest is over.
1185 $filename =~ s/[ \$]/_/g;
1186 my @file_components=split /[\/\\]+/, $filename;
1187 #print " Searching for $filename from @$project[$P_PATH]\n";
1189 my $real_filename;
1190 if ($dirname ne "") {
1191 # This is an 'include ""' -> look in dirname first.
1192 #print " in $dirname (include \"\")\n";
1193 $real_filename=search_from($dirname,\@file_components);
1194 if (defined $real_filename) {
1195 return $real_filename;
1198 my $project_settings=@$project[$P_SETTINGS];
1199 foreach $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1200 my $dirname=$include;
1201 $dirname=~ s+^-I++;
1202 if (!is_absolute($dirname)) {
1203 $dirname="@$project[$P_PATH]$dirname";
1204 } else {
1205 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1206 $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
1208 #print " in $dirname\n";
1209 $real_filename=search_from("$dirname",\@file_components);
1210 if (defined $real_filename) {
1211 return $real_filename;
1214 my $dotdotpath=@$project[$P_PATH];
1215 $dotdotpath =~ s/[^\/]+/../g;
1216 foreach $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1217 my $dirname=$include;
1218 $dirname=~ s+^-I++;
1219 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1220 $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
1221 #print " in $dirname (global setting)\n";
1222 $real_filename=search_from("$dirname",\@file_components);
1223 if (defined $real_filename) {
1224 return $real_filename;
1228 $filename =~ s+\\\\+/+g; # in include ""
1229 $filename =~ s+\\+/+g; # in include <> !
1230 if ($opt_lower_include) {
1231 return lc "$filename";
1233 return $filename;
1236 sub print_pack
1238 my $indent=$_[0];
1239 my $size=$_[1];
1240 my $trailer=$_[2];
1242 if ($size =~ /^(1|2|4|8)$/) {
1243 print FILEO "$indent#include <pshpack$size.h>$trailer";
1244 } else {
1245 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1246 print FILEO "$indent#include <pshpack4.h>$trailer";
1251 # 'Parses' a source file and fixes constructs that would not work with
1252 # Winelib. The parsing is rather simple and not all non-portable features
1253 # are corrected. The most important feature that is corrected is the case
1254 # and path separator of '#include' directives. This requires that each
1255 # source file be associated to a project & target so that the proper
1256 # include path is used.
1257 # Also note that the include path is relative to the directory in which the
1258 # compiler is run, i.e. that of the project, not to that of the file.
1259 sub fix_file
1261 my $filename=$_[0];
1262 my $project=$_[1];
1263 my $target=$_[2];
1264 $filename="@$project[$P_PATH]$filename";
1265 if (! -e $filename) {
1266 return;
1269 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1270 my $dirname=dirname($filename);
1271 my $is_mfc=0;
1272 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1273 $is_mfc=1;
1276 print " $filename\n";
1277 #FIXME:assuming that because there is a .bak file, this is what we want is
1278 #probably flawed. Or is it???
1279 if (! -e "$filename.bak") {
1280 if (!copy("$filename","$filename.bak")) {
1281 print STDERR "error: unable to make a backup of $filename:\n";
1282 print STDERR " $!\n";
1283 return;
1286 if (!open(FILEI,"$filename.bak")) {
1287 print STDERR "error: unable to open $filename.bak for reading:\n";
1288 print STDERR " $!\n";
1289 return;
1291 if (!open(FILEO,">$filename")) {
1292 print STDERR "error: unable to open $filename for writing:\n";
1293 print STDERR " $!\n";
1294 return;
1296 my $line=0;
1297 my $modified=0;
1298 my $rc_block_depth=0;
1299 my $rc_textinclude_state=0;
1300 my @pack_stack;
1301 while (<FILEI>) {
1302 $line++;
1303 s/\r\n$/\n/;
1304 if (!/\n$/) {
1305 # Make sure all files are '\n' terminated
1306 $_ .= "\n";
1308 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
1309 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1310 # the RC files it generates (even in non-MFC projects). So we replace
1311 # it with 'winres.h' its very close standard cousin so that non MFC
1312 # projects can compile in Wine without the MFC sources.
1313 my $warning="mfc:afxres.h";
1314 if (!defined $warnings{$warning}) {
1315 $warnings{$warning}="1";
1316 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winres.h'\n";
1317 print STDERR "warning: the above warning is issued only once\n";
1319 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
1320 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winres.h' */\n";
1321 print FILEO "$1$2\"winres.h\"$'";
1322 $modified=1;
1324 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1325 my $from_file=($2 eq "<"?"":$dirname);
1326 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1327 print FILEO "$1$2$real_include_name$4$'";
1328 $modified|=($real_include_name ne $3);
1330 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
1331 # Pragma pack handling
1333 # pack_stack is an array of references describing the stack of
1334 # pack directives currently in effect. Each directive if described
1335 # by a reference to an array containing:
1336 # - "push" for pack(push,...) directives, "" otherwise
1337 # - the directive's identifier at index 1
1338 # - the directive's alignement value at index 2
1340 # Don't believe a word of what the documentation says: it's all wrong.
1341 # The code below is based on the actual behavior of Visual C/C++ 6.
1342 my $pack_indent=$1;
1343 my $pack_header=$2;
1344 if (/^(\))/) {
1345 # pragma pack()
1346 # Pushes the default stack alignment
1347 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1348 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1349 print_pack($pack_indent,4,$');
1350 push @pack_stack, [ "", "", 4 ];
1352 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
1353 # pragma pack(pop)
1354 # pragma pack(pop,n)
1355 # Goes up the stack until it finds a pack(push,...), and pops it
1356 # Ignores any pack(n) entry
1357 # Issues a warning if the pack is of the form pack(push,label)
1358 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1359 my $pack_comment=$';
1360 $pack_comment =~ s/^\s*//;
1361 if ($pack_comment ne "") {
1362 print FILEO "$pack_indent$pack_comment";
1364 while (1) {
1365 my $alignment=pop @pack_stack;
1366 if (!defined $alignment) {
1367 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
1368 last;
1370 if (@$alignment[1]) {
1371 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
1373 print FILEO "$pack_indent#include <poppack.h>\n";
1374 if (@$alignment[0]) {
1375 last;
1379 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
1380 # pragma pack(pop,label[,n])
1381 # Goes up the stack until finding a pack(push,...) and pops it.
1382 # 'n', if specified, is ignored.
1383 # Ignores any pack(n) entry
1384 # Issues a warning if the label of the pack does not match,
1385 # or if it is in fact a pack(push,n)
1386 my $label=$2;
1387 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1388 my $pack_comment=$';
1389 $pack_comment =~ s/^\s*//;
1390 if ($pack_comment ne "") {
1391 print FILEO "$pack_indent$pack_comment";
1393 while (1) {
1394 my $alignment=pop @pack_stack;
1395 if (!defined $alignment) {
1396 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
1397 last;
1399 if (@$alignment[1] and @$alignment[1] ne $label) {
1400 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
1402 print FILEO "$pack_indent#include <poppack.h>\n";
1403 if (@$alignment[0]) {
1404 last;
1408 } elsif (/^(push\s*\))/) {
1409 # pragma pack(push)
1410 # Push the current alignment
1411 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1412 if (@pack_stack > 0) {
1413 my $alignment=$pack_stack[$#pack_stack];
1414 print_pack($pack_indent,@$alignment[2],$');
1415 push @pack_stack, [ "push", "", @$alignment[2] ];
1416 } else {
1417 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1418 print_pack($pack_indent,4,$');
1419 push @pack_stack, [ "push", "", 4 ];
1422 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
1423 # pragma pack([push,]n)
1424 # Push new alignment n
1425 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1426 print_pack($pack_indent,$3,"$'");
1427 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
1429 } elsif (/^((\w+)\s*\))/) {
1430 # pragma pack(label)
1431 # label must in fact be a macro that resolves to an integer
1432 # Then behaves like 'pragma pack(n)'
1433 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1434 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
1435 print_pack($pack_indent,4,$');
1436 push @pack_stack, [ "", "", 4 ];
1438 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
1439 # pragma pack(push,label[,n])
1440 # Pushes a new label on the stack. It is possible to push the same
1441 # label multiple times. If 'n' is omitted then the alignment is
1442 # unchanged. Otherwise it becomes 'n'.
1443 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1444 my $size;
1445 if (defined $4) {
1446 $size=$4;
1447 } elsif (@pack_stack > 0) {
1448 my $alignment=$pack_stack[$#pack_stack];
1449 $size=@$alignment[2];
1450 } else {
1451 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1452 $size=4;
1454 print_pack($pack_indent,$size,$');
1455 push @pack_stack, [ "push", $2, $size ];
1457 } else {
1458 # pragma pack(??? -> What's that?
1459 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
1460 print FILEO "$pack_indent$pack_header$_";
1463 $modified=1;
1465 } elsif ($is_rc) {
1466 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]+)([\">]?)/) {
1467 my $from_file=($5 eq "<"?"":$dirname);
1468 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
1469 print FILEO "$1$5$real_include_name$7$'";
1470 $modified|=($real_include_name ne $6);
1472 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1473 my $from_file=($2 eq "<"?"":$dirname);
1474 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1475 print FILEO "$1$2$real_include_name$4$'";
1476 $modified|=($real_include_name ne $3);
1478 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
1479 $rc_textinclude_state=1;
1480 print FILEO;
1482 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
1483 print FILEO "$1winres.h$2$'";
1484 $modified=1;
1486 } elsif (/^\s*BEGIN(\W.*)?$/) {
1487 $rc_textinclude_state|=2;
1488 $rc_block_depth++;
1489 print FILEO;
1491 } elsif (/^\s*END(\W.*)?$/) {
1492 $rc_textinclude_state=0;
1493 if ($rc_block_depth>0) {
1494 $rc_block_depth--;
1496 print FILEO;
1498 } else {
1499 print FILEO;
1502 } else {
1503 print FILEO;
1507 close(FILEI);
1508 close(FILEO);
1509 if ($opt_backup == 0 or $modified == 0) {
1510 if (!unlink("$filename.bak")) {
1511 print STDERR "error: unable to delete $filename.bak:\n";
1512 print STDERR " $!\n";
1518 # Analyzes each source file in turn to find and correct issues
1519 # that would cause it not to compile.
1520 sub fix_source
1522 print "Fixing the source files...\n";
1523 foreach $project (@projects) {
1524 foreach $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
1525 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1526 next;
1528 foreach $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
1529 fix_file($source,$project,$target);
1537 #####
1539 # File generation
1541 #####
1544 # Generates a target's .spec file
1545 sub generate_spec_file
1547 my $path=$_[0];
1548 my $target=$_[1];
1549 my $project_settings=$_[2];
1551 my $basename=@$target[$T_NAME];
1552 $basename =~ s+\.so$++;
1553 if (@$target[$T_FLAGS] & $TF_WRAP) {
1554 $basename =~ s+^lib++;
1555 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1556 $basename.="_wrapper";
1559 if (!open(FILEO,">$path$basename.spec")) {
1560 print STDERR "error: could not open \"$path$basename.spec\" for writing\n";
1561 print STDERR " $!\n";
1562 return;
1565 my $module=$basename;
1566 $module =~ s+^lib++;
1567 $module=canonize($module);
1568 print FILEO "name $module\n";
1569 print FILEO "type win32\n";
1570 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1571 print FILEO "mode guiexe\n";
1572 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1573 print FILEO "mode cuiexe\n";
1574 } else {
1575 print FILEO "mode dll\n";
1577 if (defined @$target[$T_INIT] and ((@$target[$T_FLAGS] & $TF_WRAP) == 0)) {
1578 print FILEO "init @$target[$T_INIT]\n";
1580 if (@{@$target[$T_SOURCES_RC]} > 0) {
1581 if (@{@$target[$T_SOURCES_RC]} > 1) {
1582 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";
1584 my $rcname=@{@$target[$T_SOURCES_RC]}[0];
1585 $rcname =~ s+\.rc$++i;
1586 $rcname =~ s+([^/\w])+\\\1+g;
1587 print FILEO "rsrc $rcname.res\n";
1589 print FILEO "\n";
1590 my %imports;
1591 foreach $library (@{$global_settings[$T_IMPORTS]}) {
1592 if (!defined $imports{$library}) {
1593 print FILEO "import $library\n";
1594 $imports{$library}=1;
1597 if (defined $project_settings) {
1598 foreach $library (@{@$project_settings[$T_IMPORTS]}) {
1599 if (!defined $imports{$library}) {
1600 print FILEO "import $library\n";
1601 $imports{$library}=1;
1605 foreach $library (@{@$target[$T_IMPORTS]}) {
1606 if (!defined $imports{$library}) {
1607 print FILEO "import $library\n";
1608 $imports{$library}=1;
1612 # Don't forget to export the 'Main' function for wrapped executables,
1613 # except for MFC ones!
1614 if (@$target[$T_FLAGS] == $TF_WRAP) {
1615 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1616 print FILEO "\n@ stdcall @$target[$T_INIT](long long ptr long) @$target[$T_INIT]\n";
1617 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1618 print FILEO "\n@ stdcall @$target[$T_INIT](long ptr ptr) @$target[$T_INIT]\n";
1619 } else {
1620 print FILEO "\n@ stdcall @$target[$T_INIT](ptr long ptr) @$target[$T_INIT]\n";
1624 close(FILEO);
1628 # Generates a target's wrapper file
1629 sub generate_wrapper_file
1631 my $path=$_[0];
1632 my $target=$_[1];
1634 if (!defined $templates{"wrapper.c"}) {
1635 print STDERR "winemaker: internal error: No template called 'wrapper.c'\n";
1636 return;
1639 if (!open(FILEO,">$path@$target[$T_NAME]_wrapper.c")) {
1640 print STDERR "error: unable to open \"$path$basename.c\" for writing:\n";
1641 print STDERR " $!\n";
1642 return;
1644 my $app_name="\"@$target[$T_NAME]\"";
1645 my $app_type=(@$target[$T_TYPE]==$TT_GUIEXE?"GUIEXE":"CUIEXE");
1646 my $app_init=(@$target[$T_TYPE]==$TT_GUIEXE?"\"WinMain\"":"\"main\"");
1647 my $app_mfc=(@$target[$T_FLAGS] & $TF_MFC?"\"mfc\"":NULL);
1648 foreach $line (@{$templates{"wrapper.c"}}) {
1649 my $l=$line;
1650 $l =~ s/\#\#WINEMAKER_APP_NAME\#\#/$app_name/;
1651 $l =~ s/\#\#WINEMAKER_APP_TYPE\#\#/$app_type/;
1652 $l =~ s/\#\#WINEMAKER_APP_INIT\#\#/$app_init/;
1653 $l =~ s/\#\#WINEMAKER_APP_MFC\#\#/$app_mfc/;
1654 print FILEO $l;
1656 close(FILEO);
1660 # A convenience function to generate all the lists (defines,
1661 # C sources, C++ source, etc.) in the Makefile
1662 sub generate_list
1664 my $name=$_[0];
1665 my $last=$_[1];
1666 my $list=$_[2];
1667 my $data=$_[3];
1668 my $first=$name;
1670 if ($name) {
1671 printf FILEO "%-22s=",$name;
1673 if (defined $list) {
1674 foreach $item (@$list) {
1675 my $value;
1676 if (defined $data) {
1677 $value=&$data($item);
1678 } else {
1679 $value=$item;
1681 if ($value ne "") {
1682 if ($first) {
1683 print FILEO " $value";
1684 $first=0;
1685 } else {
1686 print FILEO " \\\n\t\t\t$value";
1691 if ($last) {
1692 print FILEO "\n";
1697 # Generates a project's Makefile.in and all the target files
1698 sub generate_project_files
1700 my $project=$_[0];
1701 my $project_settings=@$project[$P_SETTINGS];
1702 my @dll_list=();
1703 my @exe_list=();
1705 # Then sort the targets and separate the libraries from the programs
1706 foreach $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
1707 if (@$target[$T_TYPE] == $TT_DLL) {
1708 push @dll_list,$target;
1709 } else {
1710 push @exe_list,$target;
1713 @$project[$P_TARGETS]=[];
1714 push @{@$project[$P_TARGETS]}, @dll_list;
1715 push @{@$project[$P_TARGETS]}, @exe_list;
1717 if (!open(FILEO,">@$project[$P_PATH]Makefile.in")) {
1718 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile.in\" for writing\n";
1719 print STDERR " $!\n";
1720 return;
1723 print FILEO "### Generated by Winemaker\n";
1724 print FILEO "\n\n";
1726 print FILEO "### Generic autoconf variables\n\n";
1727 generate_list("TOPSRCDIR",1,[ "\@top_srcdir\@" ]);
1728 generate_list("TOPOBJDIR",1,[ "." ]);
1729 generate_list("SRCDIR",1,[ "\@srcdir\@" ]);
1730 generate_list("VPATH",1,[ "\@srcdir\@" ]);
1731 print FILEO "\n";
1732 if (@$project[$P_PATH] eq "") {
1733 # This is the main project. It is also responsible for recursively
1734 # calling the other projects
1735 generate_list("SUBDIRS",1,\@projects,sub
1737 if ($_[0] != \@main_project) {
1738 my $subdir=@{$_[0]}[$P_PATH];
1739 $subdir =~ s+/$++;
1740 return $subdir;
1742 # Eliminating the main project by returning undefined!
1745 if (@{@$project[$P_TARGETS]} > 0) {
1746 generate_list("DLLS",1,\@dll_list,sub
1748 return @{$_[0]}[$T_NAME];
1750 generate_list("EXES",1,\@exe_list,sub
1752 return "@{$_[0]}[$T_NAME]";
1754 print FILEO "\n\n\n";
1756 print FILEO "### Global settings\n\n";
1757 # Make it so that the project-wide settings override the global settings
1758 generate_list("DEFINES",0,@$project_settings[$T_DEFINES],sub
1760 return "$_[0]";
1762 generate_list("",1,$global_settings[$T_DEFINES],sub
1764 return "$_[0]";
1766 generate_list("INCLUDE_PATH",$no_extra,@$project_settings[$T_INCLUDE_PATH],sub
1768 return "$_[0]";
1770 generate_list("",1,$global_settings[$T_INCLUDE_PATH],sub
1772 if ($_[0] !~ /^-I/) {
1773 return "$_[0]";
1775 if (is_absolute($')) {
1776 return "$_[0]";
1778 return "-I\$(TOPSRCDIR)/$'";
1780 generate_list("LIBRARY_PATH",$no_extra,@$project_settings[$T_LIBRARY_PATH],sub
1782 return "$_[0]";
1784 generate_list("",1,$global_settings[$T_LIBRARY_PATH],sub
1786 if ($_[0] !~ /^-L/) {
1787 return "$_[0]";
1789 if (is_absolute($')) {
1790 return "$_[0]";
1792 return "-L\$(TOPSRCDIR)/$'";
1794 generate_list("LIBRARIES",$no_extra,@$project_settings[$T_LIBRARIES],sub
1796 return "$_[0]";
1798 generate_list("",1,$global_settings[$T_LIBRARIES],sub
1800 return "$_[0]";
1802 print FILEO "\n\n";
1804 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
1805 @{@$project_settings[$T_SOURCES_CXX]}+
1806 @{@$project_settings[$T_SOURCES_RC]};
1807 my $no_extra=($extra_source_count == 0);
1808 if (!$no_extra) {
1809 print FILEO "### Extra source lists\n\n";
1810 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
1811 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
1812 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
1813 print FILEO "\n";
1814 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
1815 print FILEO "\n\n\n";
1818 # Iterate over all the targets...
1819 foreach $target (@{@$project[$P_TARGETS]}) {
1820 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
1821 my $canon=canonize("@$target[$T_NAME]");
1822 $canon =~ s+_so$++;
1823 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
1824 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
1825 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
1826 my $basename=@$target[$T_NAME];
1827 $basename =~ s+\.so$++;
1828 if (@$target[$T_FLAGS] & $TF_WRAP) {
1829 $basename =~ s+^lib++;
1830 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1831 $basename.="_wrapper";
1833 generate_list("${canon}_SPEC_SRCS",1,[ "$basename.spec"]);
1834 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH],sub
1836 return "$_[0]";
1838 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES],sub
1840 return "$_[0]";
1842 generate_list("${canon}_DEPENDS",1,@$target[$T_DEPENDS],sub
1844 return "$_[0]";
1846 print FILEO "\n";
1847 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(EXTRA_OBJS)"]);
1848 print FILEO "\n\n\n";
1850 print FILEO "### Global source lists\n\n";
1851 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
1853 my $canon=canonize(@{$_[0]}[$T_NAME]);
1854 $canon =~ s+_so$++;
1855 return "\$(${canon}_C_SRCS)";
1857 if (!$no_extra) {
1858 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
1860 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
1862 my $canon=canonize(@{$_[0]}[$T_NAME]);
1863 $canon =~ s+_so$++;
1864 return "\$(${canon}_CXX_SRCS)";
1866 if (!$no_extra) {
1867 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
1869 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
1871 my $canon=canonize(@{$_[0]}[$T_NAME]);
1872 $canon =~ s+_so$++;
1873 return "\$(${canon}_RC_SRCS)";
1875 if (!$no_extra) {
1876 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
1878 generate_list("SPEC_SRCS",1,@$project[$P_TARGETS],sub
1880 my $canon=canonize(@{$_[0]}[$T_NAME]);
1881 $canon =~ s+_so$++;
1882 return "\$(${canon}_SPEC_SRCS)";
1885 print FILEO "\n\n\n";
1887 print FILEO "### Generic autoconf targets\n\n";
1888 print FILEO "all: ";
1889 if (@$project[$P_PATH] eq "") {
1890 print FILEO "\$(SUBDIRS)";
1892 if (@{@$project[$P_TARGETS]} > 0) {
1893 print FILEO "\$(DLLS) \$(EXES:%=%.so)";
1895 print FILEO "\n\n";
1896 print FILEO "\@MAKE_RULES\@\n";
1897 print FILEO "\n";
1898 print FILEO "install::\n";
1899 if (@$project[$P_PATH] eq "") {
1900 # This is the main project. It is also responsible for recursively
1901 # calling the other projects
1902 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) install) || exit 1; done\n";
1904 if (@{@$project[$P_TARGETS]} > 0) {
1905 print FILEO "\tfor i in \$(EXES); do \$(INSTALL_PROGRAM) \$\$i \$(bindir); done\n";
1906 print FILEO "\tfor i in \$(EXES:%=%.so) \$(DLLS); do \$(INSTALL_LIBRARY) \$\$i \$(libdir); done\n";
1908 print FILEO "\n";
1909 print FILEO "uninstall::\n";
1910 if (@$project[$P_PATH] eq "") {
1911 # This is the main project. It is also responsible for recursively
1912 # calling the other projects
1913 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) uninstall) || exit 1; done\n";
1915 if (@{@$project[$P_TARGETS]} > 0) {
1916 print FILEO "\tfor i in \$(EXES); do \$(RM) \$(bindir)/\$\$i;done\n";
1917 print FILEO "\tfor i in \$(EXES:%=%.so) \$(DLLS); do \$(RM) \$(libdir)/\$\$i;done\n";
1919 print FILEO "\n\n\n";
1921 if (@{@$project[$P_TARGETS]} > 0) {
1922 print FILEO "### Target specific build rules\n\n";
1923 foreach $target (@{@$project[$P_TARGETS]}) {
1924 my $canon=canonize("@$target[$T_NAME]");
1925 $canon =~ s/_so$//;
1926 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.tmp.o): \$(${canon}_OBJS)\n";
1927 print FILEO "\t\$(LDCOMBINE) \$(${canon}_OBJS) -o \$\@\n";
1928 print FILEO "\t-\$(STRIP) \$(STRIPFLAGS) \$\@\n";
1929 print FILEO "\n";
1930 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.spec.c): \$(${canon}_SPEC_SRCS:.spec) \$(${canon}_SPEC_SRCS:.spec=.tmp.o) \$(${canon}_RC_SRCS:.rc=.res)\n";
1931 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";
1932 print FILEO "\n";
1933 my $t_name=@$target[$T_NAME];
1934 if (@$target[$T_TYPE]!=$TT_DLL) {
1935 $t_name.=".so";
1937 print FILEO "$t_name: \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_OBJS) \$(${canon}_DEPENDS) \n";
1938 if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
1939 print FILEO "\t\$(LDXXSHARED)";
1940 } else {
1941 print FILEO "\t\$(LDSHARED)";
1943 print FILEO " \$(LDDLLFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_LIBRARY_PATH) \$(${canon}_LIBRARIES:%=-l%) \$(DLL_LINK) \$(LIBS)\n";
1944 if (@$target[$T_TYPE] ne $TT_DLL) {
1945 print FILEO "\ttest -e @$target[$T_NAME] || \$(LN_S) \$(WINE) @$target[$T_NAME]\n";
1947 print FILEO "\n\n";
1950 close(FILEO);
1952 foreach $target (@{@$project[$P_TARGETS]}) {
1953 generate_spec_file(@$project[$P_PATH],$target,$project_settings);
1954 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1955 generate_wrapper_file(@$project[$P_PATH],$target);
1961 # Perform the replacements in the template configure files
1962 # Return 1 for success, 0 for failure
1963 sub generate_configure
1965 my $filename=$_[0];
1966 my $a_source_file=$_[1];
1968 if (!defined $templates{$filename}) {
1969 if ($filename ne "configure") {
1970 print STDERR "winemaker: internal error: No template called '$filename'\n";
1972 return 0;
1975 if (!open(FILEO,">$filename")) {
1976 print STDERR "error: unable to open \"$filename\" for writing:\n";
1977 print STDERR " $!\n";
1978 return 0;
1980 foreach $line (@{$templates{$filename}}) {
1981 if ($line =~ /^\#\#WINEMAKER_PROJECTS\#\#$/) {
1982 foreach $project (@projects) {
1983 print FILEO "@$project[$P_PATH]Makefile\n";
1985 } else {
1986 $line =~ s+\#\#WINEMAKER_SOURCE\#\#+$a_source_file+;
1987 $line =~ s+\#\#WINEMAKER_NEEDS_MFC\#\#+$needs_mfc+;
1988 print FILEO $line;
1991 close(FILEO);
1992 return 1;
1995 sub generate_generic
1997 my $filename=$_[0];
1999 if (!defined $templates{$filename}) {
2000 print STDERR "winemaker: internal error: No template called '$filename'\n";
2001 return;
2003 if (!open(FILEO,">$filename")) {
2004 print STDERR "error: unable to open \"$filename\" for writing:\n";
2005 print STDERR " $!\n";
2006 return;
2008 foreach $line (@{$templates{$filename}}) {
2009 print FILEO $line;
2011 close(FILEO);
2015 # Generates the global files:
2016 # configure
2017 # configure.in
2018 # Make.rules.in
2019 sub generate_global_files
2021 generate_generic("Make.rules.in");
2023 # Get the name of a source file for configure.in
2024 my $a_source_file;
2025 search_a_file: foreach $project (@projects) {
2026 foreach $target (@{@$project[$P_TARGETS]}, @$project[$P_SETTINGS]) {
2027 $a_source_file=@{@$target[$T_SOURCES_C]}[0];
2028 if (!defined $a_source_file) {
2029 $a_source_file=@{@$target[$T_SOURCES_CXX]}[0];
2031 if (!defined $a_source_file) {
2032 $a_source_file=@{@$target[$T_SOURCES_RC]}[0];
2034 if (defined $a_source_file) {
2035 $a_source_file="@$project[$P_PATH]$a_source_file";
2036 last search_a_file;
2040 if (!defined $a_source_file) {
2041 $a_source_file="Makefile.in";
2044 generate_configure("configure.in",$a_source_file);
2045 unlink("configure");
2046 if (generate_configure("configure",$a_source_file) == 0) {
2047 system("autoconf");
2049 # Add execute permission to configure for whoever has the right to read it
2050 my @st=stat("configure");
2051 if (@st) {
2052 my $mode=$st[2];
2053 $mode|=($mode & 0444) >>2;
2054 chmod($mode,"configure");
2055 } else {
2056 print "warning: could not generate the configure script. You need to run autoconf\n";
2062 sub generate_read_templates
2064 my $file;
2066 while (<DATA>) {
2067 if (/^--- ((\w\.?)+) ---$/) {
2068 my $filename=$1;
2069 if (defined $templates{$filename}) {
2070 print STDERR "winemaker: internal error: There is more than one template for $filename\n";
2071 undef $file;
2072 } else {
2073 $file=[];
2074 $templates{$filename}=$file;
2076 } elsif (defined $file) {
2077 push @$file, $_;
2083 # This is where we finally generate files. In fact this method does not
2084 # do anything itself but calls the methods that do the actual work.
2085 sub generate
2087 print "Generating project files...\n";
2088 generate_read_templates();
2089 generate_global_files();
2091 foreach $project (@projects) {
2092 my $path=@$project[$P_PATH];
2093 if ($path eq "") {
2094 $path=".";
2095 } else {
2096 $path =~ s+/$++;
2098 print " $path\n";
2099 generate_project_files($project);
2105 #####
2107 # Option defaults
2109 #####
2111 $opt_backup=1;
2112 $opt_lower=$OPT_LOWER_UPPERCASE;
2113 $opt_lower_include=1;
2115 # $opt_work_dir=<undefined>
2116 # $opt_single_target=<undefined>
2117 $opt_target_type=$TT_GUIEXE;
2118 $opt_flags=0;
2119 $opt_is_interactive=$OPT_ASK_NO;
2120 $opt_ask_project_options=$OPT_ASK_NO;
2121 $opt_ask_target_options=$OPT_ASK_NO;
2122 $opt_no_generated_files=0;
2123 $opt_no_banner=0;
2127 #####
2129 # Main
2131 #####
2133 sub print_banner
2135 print "Winemaker $version\n";
2136 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2139 sub usage
2141 print_banner();
2142 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup]\n";
2143 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2144 print STDERR " [--lower-include|--nolower-include]\n";
2145 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2146 print STDERR " [--wrap|--nowrap] [--mfc|--nomfc]\n";
2147 print STDERR " [-Dmacro[=defn]] [-Idir] [-Ldir] [-idll] [-llibrary]\n";
2148 print STDERR " [--interactive] [--single-target name]\n";
2149 print STDERR " [--generated-files|--nogenerated-files]\n";
2150 print STDERR " work_directory\n";
2151 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2152 print STDERR "the specified directory so that they can be compiled with Winelib. During this\n";
2153 print STDERR "process it will modify and rename some of the files in that directory.\n";
2154 print STDERR "\tPlease read the manual page before use.\n";
2155 exit (2);
2159 project_init(\@main_project,"");
2161 while (@ARGV>0) {
2162 my $arg=shift @ARGV;
2163 # General options
2164 if ($arg eq "--nobanner") {
2165 $opt_no_banner=1;
2166 } elsif ($arg eq "--backup") {
2167 $opt_backup=1;
2168 } elsif ($arg eq "--nobackup") {
2169 $opt_backup=0;
2170 } elsif ($arg eq "--single-target") {
2171 $opt_single_target=shift @ARGV;
2172 } elsif ($arg eq "--lower-none") {
2173 $opt_lower=$OPT_LOWER_NONE;
2174 } elsif ($arg eq "--lower-all") {
2175 $opt_lower=$OPT_LOWER_ALL;
2176 } elsif ($arg eq "--lower-uppercase") {
2177 $opt_lower=$OPT_LOWER_UPPERCASE;
2178 } elsif ($arg eq "--lower-include") {
2179 $opt_lower_include=1;
2180 } elsif ($arg eq "--nolower-include") {
2181 $opt_lower_include=0;
2182 } elsif ($arg eq "--generated-files") {
2183 $opt_no_generated_files=0;
2184 } elsif ($arg eq "--nogenerated-files") {
2185 $opt_no_generated_files=1;
2187 } elsif ($arg =~ /^-D/) {
2188 push @{$global_settings[$T_DEFINES]},$arg;
2189 } elsif ($arg =~ /^-I/) {
2190 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2191 } elsif ($arg =~ /^-L/) {
2192 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2193 } elsif ($arg =~ /^-i/) {
2194 push @{$global_settings[$T_IMPORTS]},$';
2195 } elsif ($arg =~ /^-l/) {
2196 push @{$global_settings[$T_LIBRARIES]},$';
2198 # 'Source'-based method options
2199 } elsif ($arg eq "--dll") {
2200 $opt_target_type=$TT_DLL;
2201 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2202 $opt_target_type=$TT_GUIEXE;
2203 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2204 $opt_target_type=$TT_CUIEXE;
2205 } elsif ($arg eq "--interactive") {
2206 $opt_is_interactive=$OPT_ASK_YES;
2207 $opt_ask_project_options=$OPT_ASK_YES;
2208 $opt_ask_target_options=$OPT_ASK_YES;
2209 } elsif ($arg eq "--wrap") {
2210 $opt_flags|=$TF_WRAP;
2211 } elsif ($arg eq "--nowrap") {
2212 $opt_flags&=~$TF_WRAP;
2213 } elsif ($arg eq "--mfc") {
2214 $opt_flags|=$TF_MFC;
2215 $opt_flags|=$TF_MFC|$TF_WRAP;
2216 $needs_mfc=1;
2217 } elsif ($arg eq "--nomfc") {
2218 $opt_flags&=~($TF_MFC|$TF_WRAP);
2219 $needs_mfc=0;
2221 # Catch errors
2222 } else {
2223 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2224 if (!defined $opt_work_dir) {
2225 $opt_work_dir=$arg;
2226 } else {
2227 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2228 usage();
2230 } else {
2231 usage();
2236 if (!defined $opt_work_dir) {
2237 print STDERR "error: you must specify the directory containing the sources to be converted\n";
2238 usage();
2239 } elsif (!chdir $opt_work_dir) {
2240 print STDERR "error: could not chdir to the work directory\n";
2241 print STDERR " $!\n";
2242 usage();
2245 if ($opt_no_banner == 0) {
2246 print_banner();
2249 # Fix the file and directory names
2250 fix_file_and_directory_names(".");
2252 # Scan the sources to identify the projects and targets
2253 source_scan();
2255 # Create targets for wrappers, etc.
2256 postprocess_targets();
2258 # Fix the source files
2259 fix_source();
2261 # Generate the Makefile and the spec file
2262 if (! $opt_no_generated_files) {
2263 generate();
2267 __DATA__
2268 --- configure.in ---
2269 dnl Process this file with autoconf to produce a configure script.
2270 dnl Author: Michael Patra <micky@marie.physik.tu-berlin.de>
2271 dnl <patra@itp1.physik.tu-berlin.de>
2272 dnl Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2274 AC_REVISION([configure.in 1.00])
2275 AC_INIT(##WINEMAKER_SOURCE##)
2277 NEEDS_MFC=##WINEMAKER_NEEDS_MFC##
2279 dnl **** Command-line arguments ****
2281 AC_SUBST(OPTIONS)
2283 dnl **** Check for some programs ****
2285 AC_PROG_MAKE_SET
2286 AC_PROG_CC
2287 AC_PROG_CXX
2288 AC_PROG_CPP
2289 AC_PATH_XTRA
2290 AC_PROG_RANLIB
2291 AC_PROG_LN_S
2292 AC_PATH_PROG(LDCONFIG, ldconfig, true, /sbin:/usr/sbin:$PATH)
2294 dnl **** Check for some libraries ****
2296 dnl Check for -lm for BeOS
2297 AC_CHECK_LIB(m,sqrt)
2298 dnl Check for -li386 for NetBSD and OpenBSD
2299 AC_CHECK_LIB(i386,i386_set_ldt)
2300 dnl Check for -lossaudio for NetBSD
2301 AC_CHECK_LIB(ossaudio,_oss_ioctl)
2302 dnl Check for -lw for Solaris
2303 AC_CHECK_LIB(w,iswalnum)
2304 dnl Check for -lnsl for Solaris
2305 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))
2306 dnl Check for -lsocket for Solaris
2307 AC_CHECK_FUNCS(connect,,AC_CHECK_LIB(socket,connect))
2308 dnl Check for -lxpg4 for FreeBSD
2309 AC_CHECK_LIB(xpg4,setrunelocale)
2310 dnl Check for -lmmap for OS/2
2311 AC_CHECK_LIB(mmap,mmap)
2312 dnl Check for openpty
2313 AC_CHECK_FUNCS(openpty,,
2314 AC_CHECK_LIB(util,openpty,
2315 AC_DEFINE(HAVE_OPENPTY)
2316 LIBS="$LIBS -lutil"
2319 AC_CHECK_HEADERS(dlfcn.h,
2320 AC_CHECK_FUNCS(dlopen,
2321 AC_DEFINE(HAVE_DL_API),
2322 AC_CHECK_LIB(dl,dlopen,
2323 AC_DEFINE(HAVE_DL_API)
2324 LIBS="$LIBS -ldl",
2329 dnl **** Check which curses lib to use ***
2330 if test "$CURSES" = "yes"
2331 then
2332 AC_CHECK_HEADERS(ncurses.h)
2333 if test "$ac_cv_header_ncurses_h" = "yes"
2334 then
2335 AC_CHECK_LIB(ncurses,waddch)
2337 if test "$ac_cv_lib_ncurses_waddch" = "yes"
2338 then
2339 AC_CHECK_LIB(ncurses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2340 AC_CHECK_LIB(ncurses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2341 else
2342 AC_CHECK_HEADERS(curses.h)
2343 if test "$ac_cv_header_curses_h" = "yes"
2344 then
2345 AC_CHECK_LIB(curses,waddch)
2346 if test "$ac_cv_lib_curses_waddch" = "yes"
2347 then
2348 AC_CHECK_LIB(curses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2349 AC_CHECK_LIB(curses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2355 dnl **** If ln -s doesn't work, use cp instead ****
2356 if test "$ac_cv_prog_LN_S" = "ln -s"; then : ; else LN_S=cp ; fi
2358 dnl **** Check for gcc strength-reduce bug ****
2360 if test "x${GCC}" = "xyes"
2361 then
2362 AC_CACHE_CHECK( "for gcc strength-reduce bug", ac_cv_c_gcc_strength_bug,
2363 AC_TRY_RUN([
2364 int main(void) {
2365 static int Array[[3]];
2366 unsigned int B = 3;
2367 int i;
2368 for(i=0; i<B; i++) Array[[i]] = i - 3;
2369 exit( Array[[1]] != -2 );
2371 ac_cv_c_gcc_strength_bug="no",
2372 ac_cv_c_gcc_strength_bug="yes",
2373 ac_cv_c_gcc_strength_bug="yes") )
2374 if test "$ac_cv_c_gcc_strength_bug" = "yes"
2375 then
2376 CFLAGS="$CFLAGS -fno-strength-reduce"
2380 dnl **** Check for underscore on external symbols ****
2382 AC_CACHE_CHECK("whether external symbols need an underscore prefix",
2383 ac_cv_c_extern_prefix,
2384 [saved_libs=$LIBS
2385 LIBS="conftest_asm.s $LIBS"
2386 cat > conftest_asm.s <<EOF
2387 .globl _ac_test
2388 _ac_test:
2389 .long 0
2391 AC_TRY_LINK([extern int ac_test;],[if (ac_test) return 1],
2392 ac_cv_c_extern_prefix="yes",ac_cv_c_extern_prefix="no")
2393 LIBS=$saved_libs])
2394 if test "$ac_cv_c_extern_prefix" = "yes"
2395 then
2396 AC_DEFINE(NEED_UNDERSCORE_PREFIX)
2399 dnl **** Check for working dll ****
2401 LDSHARED=""
2402 LDXXSHARED=""
2403 LDDLLFLAGS=""
2404 AC_CACHE_CHECK("whether we can build a Linux dll",
2405 ac_cv_c_dll_linux,
2406 [saved_cflags=$CFLAGS
2407 CFLAGS="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0,-Bsymbolic"
2408 AC_TRY_LINK(,[return 1],ac_cv_c_dll_linux="yes",ac_cv_c_dll_linux="no")
2409 CFLAGS=$saved_cflags
2411 if test "$ac_cv_c_dll_linux" = "yes"
2412 then
2413 LDSHARED="\$(CC) -shared -Wl,-rpath,\$(libdir)"
2414 LDXXSHARED="\$(CXX) -shared -Wl,-rpath,\$(libdir)"
2415 LDDLLFLAGS="-Wl,-Bsymbolic"
2416 else
2417 AC_CACHE_CHECK(whether we can build a UnixWare (Solaris) dll,
2418 ac_cv_c_dll_unixware,
2419 [saved_cflags=$CFLAGS
2420 CFLAGS="$CFLAGS -fPIC -Wl,-G,-h,conftest.so.1.0,-B,symbolic"
2421 AC_TRY_LINK(,[return 1],ac_cv_c_dll_unixware="yes",ac_cv_c_dll_unixware="no")
2422 CFLAGS=$saved_cflags
2424 if test "$ac_cv_c_dll_unixware" = "yes"
2425 then
2426 LDSHARED="\$(CC) -Wl,-G"
2427 LDXXSHARED="\$(CXX) -Wl,-G"
2428 LDDLLFLAGS="-Wl,-B,symbolic"
2429 else
2430 AC_CACHE_CHECK("whether we can build a NetBSD dll",
2431 ac_cv_c_dll_netbsd,
2432 [saved_cflags=$CFLAGS
2433 CFLAGS="$CFLAGS -fPIC -Wl,-Bshareable,-Bforcearchive"
2434 AC_TRY_LINK(,[return 1],ac_cv_c_dll_netbsd="yes",ac_cv_c_dll_netbsd="no")
2435 CFLAGS=$saved_cflags
2437 if test "$ac_cv_c_dll_netbsd" = "yes"
2438 then
2439 LDSHARED="\$(CC) -Wl,-Bshareable,-Bforcearchive"
2440 LDXXSHARED="\$(CXX) -Wl,-Bshareable,-Bforcearchive"
2441 LDDLLFLAGS="" #FIXME
2445 if test "$ac_cv_c_dll_linux" = "no" -a "$ac_cv_c_dll_unixware" = "no" -a "$ac_cv_c_dll_netbsd" = "no"
2446 then
2447 AC_MSG_ERROR([Could not find how to build a dynamically linked library])
2450 CFLAGS="$CFLAGS -fPIC"
2451 DLL_LINK="\$(WINE_LIBRARY_PATH) \$(LIBRARY_PATH) \$(LIBRARIES:%=-l%) -lwine -lwine_unicode -lwine_uuid"
2453 AC_SUBST(DLL_LINK)
2454 AC_SUBST(LDSHARED)
2455 AC_SUBST(LDXXSHARED)
2456 AC_SUBST(LDDLLFLAGS)
2458 dnl *** check for the need to define __i386__
2460 AC_CACHE_CHECK("whether we need to define __i386__",ac_cv_cpp_def_i386,
2461 AC_EGREP_CPP(yes,[#if (defined(i386) || defined(__i386)) && !defined(__i386__)
2463 #endif],
2464 ac_cv_cpp_def_i386="yes", ac_cv_cpp_def_i386="no"))
2465 if test "$ac_cv_cpp_def_i386" = "yes"
2466 then
2467 CFLAGS="$CFLAGS -D__i386__"
2470 dnl $GCC is set by autoconf
2471 GCC_NO_BUILTIN=""
2472 if test "$GCC" = "yes"
2473 then
2474 GCC_NO_BUILTIN="-fno-builtin"
2476 AC_SUBST(GCC_NO_BUILTIN)
2478 dnl **** Test Winelib-related features of the C++ compiler
2479 AC_LANG_CPLUSPLUS()
2480 if test "x${GCC}" = "xyes"
2481 then
2482 OLDCXXFLAGS="$CXXFLAGS";
2483 CXXFLAGS="-fpermissive";
2484 AC_CACHE_CHECK("for g++ -fpermissive option", has_gxx_permissive,
2485 AC_TRY_COMPILE(,[
2486 for (int i=0;i<2;i++);
2487 i=0;
2489 [has_gxx_permissive="yes"],
2490 [has_gxx_permissive="no"])
2492 CXXFLAGS="-fno-for-scope";
2493 AC_CACHE_CHECK("for g++ -fno-for-scope option", has_gxx_no_for_scope,
2494 AC_TRY_COMPILE(,[
2495 for (int i=0;i<2;i++);
2496 i=0;
2498 [has_gxx_no_for_scope="yes"],
2499 [has_gxx_no_for_scope="no"])
2501 CXXFLAGS="$OLDCXXFLAGS";
2502 if test "$has_gxx_permissive" = "yes"
2503 then
2504 CXXFLAGS="$CXXFLAGS -fpermissive"
2506 if test "$has_gxx_no_for_scope" = "yes"
2507 then
2508 CXXFLAGS="$CXXFLAGS -fno-for-scope"
2511 AC_LANG_C()
2513 dnl **** Test Winelib-related features of the C compiler
2514 dnl none for now
2516 dnl **** Macros for finding a headers/libraries in a collection of places
2518 dnl AC_PATH_HEADER(variable,header,action-if-not-found,default-locations)
2519 dnl Note that the above may set variable to an empty value if the header is
2520 dnl already in the include path
2521 AC_DEFUN(AC_PATH_HEADER,[
2522 AC_MSG_CHECKING([for $2])
2523 AC_CACHE_VAL(ac_cv_path_$1,
2525 ac_found=
2526 ac_dummy="ifelse([$4], , :/usr/local/include, [$4])"
2527 save_CPPFLAGS="$CPPFLAGS"
2528 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2529 for ac_dir in $ac_dummy; do
2530 IFS="$ac_save_ifs"
2531 if test -z "$ac_dir"
2532 then
2533 CPPFLAGS="$save_CPPFLAGS"
2534 else
2535 CPPFLAGS="-I$ac_dir $save_CPPFLAGS"
2537 AC_TRY_COMPILE([#include <$2>],,ac_found=1;ac_cv_path_$1="$ac_dir";break)
2538 done
2539 CPPFLAGS="$save_CPPFLAGS"
2540 ifelse([$3],,,[if test -z "$ac_found"
2541 then
2546 $1="$ac_cv_path_$1"
2547 if test -n "$ac_found" -o -n "[$]$1"
2548 then
2549 AC_MSG_RESULT([$]$1)
2550 else
2551 AC_MSG_RESULT(no)
2553 AC_SUBST($1)
2556 dnl AC_PATH_LIBRARY(variable,libraries,extra libs,action-if-not-found,default-locations)
2557 AC_DEFUN(AC_PATH_LIBRARY,[
2558 AC_MSG_CHECKING([for $2])
2559 AC_CACHE_VAL(ac_cv_path_$1,
2561 ac_found=
2562 ac_dummy="ifelse([$5], , :/usr/local/lib, [$5])"
2563 save_LIBS="$LIBS"
2564 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2565 for ac_dir in $ac_dummy; do
2566 IFS="$ac_save_ifs"
2567 if test -z "$ac_dir"
2568 then
2569 LIBS="$2 $3 $save_LIBS"
2570 else
2571 LIBS="-L$ac_dir $2 $3 $save_LIBS"
2573 AC_TRY_LINK(,,ac_found=1;ac_cv_path_$1="$ac_dir";break)
2574 done
2575 LIBS="$save_LIBS"
2576 ifelse([$4],,,[if test -z "$ac_found"
2577 then
2582 $1="$ac_cv_path_$1"
2583 if test -n "$ac_found" -o -n "[$]$1"
2584 then
2585 AC_MSG_RESULT([$]$1)
2586 else
2587 AC_MSG_RESULT(no)
2589 AC_SUBST($1)
2592 dnl **** Try to find where winelib is located ****
2594 LD_PATH="";
2595 WINE_INCLUDE_ROOT="";
2596 WINE_INCLUDE_PATH="";
2597 WINE_LIBRARY_ROOT="";
2598 WINE_LIBRARY_PATH="";
2599 WINE_TOOL_PATH="";
2600 WINE="";
2601 WINEBUILD="";
2602 WRC="";
2604 AC_ARG_WITH(wine,
2605 [ --with-wine=DIR the Wine package (or sources) is in DIR],
2606 [if test "$withval" != "no"; then
2607 WINE_ROOT="$withval";
2608 WINE_INCLUDES="";
2609 WINE_LIBRARIES="";
2610 WINE_TOOLS="";
2611 else
2612 WINE_ROOT="";
2613 fi])
2614 if test -n "$WINE_ROOT"
2615 then
2616 WINE_INCLUDE_ROOT="$WINE_ROOT/include:$WINE_ROOT/include/wine";
2617 WINE_LIBRARY_ROOT="$WINE_ROOT";
2618 WINE_TOOL_PATH="$WINE_ROOT:$WINE_ROOT/bin:$WINE_ROOT/tools/wrc:$WINE_ROOT/tools/winebuild:$PATH";
2621 AC_ARG_WITH(wine-includes,
2622 [ --with-wine-includes=DIR the Wine includes are in DIR],
2623 [if test "$withval" != "no"; then
2624 WINE_INCLUDES="$withval";
2625 else
2626 WINE_INCLUDES="";
2627 fi])
2628 if test -n "$WINE_INCLUDES"
2629 then
2630 WINE_INCLUDE_ROOT="$WINE_INCLUDES";
2633 AC_ARG_WITH(wine-libraries,
2634 [ --with-wine-libraries=DIR the Wine libraries are in DIR],
2635 [if test "$withval" != "no"; then
2636 WINE_LIBRARIES="$withval";
2637 else
2638 WINE_LIBRARIES="";
2639 fi])
2640 if test -n "$WINE_LIBRARIES"
2641 then
2642 WINE_LIBRARY_ROOT="$WINE_LIBRARIES";
2645 AC_ARG_WITH(wine-tools,
2646 [ --with-wine-tools=DIR the Wine tools are in DIR],
2647 [if test "$withval" != "no"; then
2648 WINE_TOOLS="$withval";
2649 else
2650 WINE_TOOLS="";
2651 fi])
2652 if test -n "$WINE_TOOLS"
2653 then
2654 WINE_TOOL_PATH="$WINE_TOOLS:$WINE_TOOLS/wrc:$WINE_TOOLS/winebuild";
2657 if test -z "$WINE_INCLUDE_ROOT"
2658 then
2659 WINE_INCLUDE_ROOT=":/usr/include/wine:/usr/local/include/wine:/opt/wine/include:/opt/wine/include/wine";
2661 AC_PATH_HEADER(WINE_INCLUDE_ROOT,windef.h,[
2662 AC_MSG_ERROR([Could not find the Wine includes])
2663 ],$WINE_INCLUDE_ROOT)
2664 if test -n "$WINE_INCLUDE_ROOT"
2665 then
2666 WINE_INCLUDE_PATH="-I$WINE_INCLUDE_ROOT"
2667 else
2668 WINE_INCLUDE_PATH=""
2671 if test -z "$WINE_LIBRARY_ROOT"
2672 then
2673 WINE_LIBRARY_ROOT=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib";
2674 else
2675 WINE_LIBRARY_ROOT="$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/lib";
2677 AC_PATH_LIBRARY(WINE_LIBRARY_ROOT,[-lwine],[-lutil],[
2678 AC_MSG_ERROR([Could not find the Wine libraries (libwine.so)])
2679 ],$WINE_LIBRARY_ROOT)
2680 if test -n "$WINE_LIBRARY_ROOT"
2681 then
2682 WINE_LIBRARY_PATH="-L$WINE_LIBRARY_ROOT"
2683 else
2684 WINE_LIBRARY_PATH=""
2686 AC_PATH_LIBRARY(LIBNTDLL_PATH,[-lntdll],[$WINE_LIBRARY_PATH -lwine -lwine_unicode -lncurses -ldl -lutil],[
2687 AC_MSG_ERROR([Could not find the Wine libraries (libntdll.so)])
2688 ],[$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/dlls])
2689 if test -n "$LIBNTDLL_PATH" -a "-L$LIBNTDLL_PATH" != "$WINE_LIBRARY_PATH"
2690 then
2691 WINE_LIBRARY_PATH="$WINE_LIBRARY_PATH -L$LIBNTDLL_PATH"
2693 if test -n "$WINE_LIBRARY_PATH"
2694 then
2695 LD_PATH="LD_LIBRARY_PATH=\"`echo $WINE_LIBRARY_PATH | sed -e 's/ *-L/:/g' -e 's/^://' -e 's/ *$//'`:\$\$LD_LIBRARY_PATH\""
2698 if test -z "$WINE_TOOL_PATH"
2699 then
2700 WINE_TOOL_PATH="$PATH:/usr/local/bin:/opt/wine/bin";
2702 AC_PATH_PROG(WINE,wine,,$WINE_TOOL_PATH)
2703 if test -z "$WINE"
2704 then
2705 AC_MSG_ERROR([Could not find Wine's wine tool])
2707 AC_PATH_PROG(WINEBUILD,winebuild,,$WINE_TOOL_PATH)
2708 if test -z "$WINEBUILD"
2709 then
2710 AC_MSG_ERROR([Could not find Wine's winebuild tool])
2712 AC_PATH_PROG(WRC,wrc,,$WINE_TOOL_PATH)
2713 if test -z "$WRC"
2714 then
2715 AC_MSG_ERROR([Could not find Wine's wrc tool])
2718 AC_SUBST(LD_PATH)
2719 AC_SUBST(WINE_INCLUDE_PATH)
2720 AC_SUBST(WINE_LIBRARY_PATH)
2722 dnl **** Try to find where the MFC are located ****
2723 AC_LANG_CPLUSPLUS()
2725 if test "x$NEEDS_MFC" = "x1"
2726 then
2727 ATL_INCLUDE_ROOT="";
2728 ATL_INCLUDE_PATH="";
2729 MFC_INCLUDE_ROOT="";
2730 MFC_INCLUDE_PATH="";
2731 MFC_LIBRARY_ROOT="";
2732 MFC_LIBRARY_PATH="";
2734 AC_ARG_WITH(mfc,
2735 [ --with-mfc=DIR the MFC package (or sources) is in DIR],
2736 [if test "$withval" != "no"; then
2737 MFC_ROOT="$withval";
2738 ATL_INCLUDES="";
2739 MFC_INCLUDES="";
2740 MFC_LIBRARIES="";
2741 else
2742 MFC_ROOT="";
2743 fi])
2744 if test -n "$MFC_ROOT"
2745 then
2746 ATL_INCLUDE_ROOT="$MFC_ROOT";
2747 MFC_INCLUDE_ROOT="$MFC_ROOT";
2748 MFC_LIBRARY_ROOT="$MFC_ROOT";
2751 AC_ARG_WITH(atl-includes,
2752 [ --with-atl-includes=DIR the ATL includes are in DIR],
2753 [if test "$withval" != "no"; then
2754 ATL_INCLUDES="$withval";
2755 else
2756 ATL_INCLUDES="";
2757 fi])
2758 if test -n "$ATL_INCLUDES"
2759 then
2760 ATL_INCLUDE_ROOT="$ATL_INCLUDES";
2763 AC_ARG_WITH(mfc-includes,
2764 [ --with-mfc-includes=DIR the MFC includes are in DIR],
2765 [if test "$withval" != "no"; then
2766 MFC_INCLUDES="$withval";
2767 else
2768 MFC_INCLUDES="";
2769 fi])
2770 if test -n "$MFC_INCLUDES"
2771 then
2772 MFC_INCLUDE_ROOT="$MFC_INCLUDES";
2775 AC_ARG_WITH(mfc-libraries,
2776 [ --with-mfc-libraries=DIR the MFC libraries are in DIR],
2777 [if test "$withval" != "no"; then
2778 MFC_LIBRARIES="$withval";
2779 else
2780 MFC_LIBRARIES="";
2781 fi])
2782 if test -n "$MFC_LIBRARIES"
2783 then
2784 MFC_LIBRARY_ROOT="$MFC_LIBRARIES";
2787 OLDCPPFLAGS="$CPPFLAGS"
2788 dnl FIXME: We should not have defines in any of the include paths
2789 CPPFLAGS="$WINE_INCLUDE_PATH -I$WINE_INCLUDE_ROOT/mixedcrt -D_DLL -D_MT $CPPFLAGS"
2790 ATL_INCLUDE_PATH="-I\$(WINE_INCLUDE_ROOT)/mixedcrt -D_DLL -D_MT"
2791 if test -z "$ATL_INCLUDE_ROOT"
2792 then
2793 ATL_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/atl:/usr/include/atl:/usr/local/include/atl:/opt/mfc/include/atl:/opt/atl/include"
2794 else
2795 ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT:$ATL_INCLUDE_ROOT/atl:$ATL_INCLUDE_ROOT/atl/include"
2797 AC_PATH_HEADER(ATL_INCLUDE_ROOT,atldef.h,[
2798 AC_MSG_ERROR([Could not find the ATL includes])
2799 ],$ATL_INCLUDE_ROOT)
2800 if test -n "$ATL_INCLUDE_ROOT"
2801 then
2802 ATL_INCLUDE_PATH="$ATL_INCLUDE_PATH -I$ATL_INCLUDE_ROOT"
2805 MFC_INCLUDE_PATH="$ATL_INCLUDE_PATH"
2806 if test -z "$MFC_INCLUDE_ROOT"
2807 then
2808 MFC_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/mfc:/usr/include/mfc:/usr/local/include/mfc:/opt/mfc/include/mfc:/opt/mfc/include"
2809 else
2810 MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT:$MFC_INCLUDE_ROOT/mfc:$MFC_INCLUDE_ROOT/mfc/include"
2812 AC_PATH_HEADER(MFC_INCLUDE_ROOT,afx.h,[
2813 AC_MSG_ERROR([Could not find the MFC includes])
2814 ],$MFC_INCLUDE_ROOT)
2815 if test -n "$MFC_INCLUDE_ROOT" -a "$ATL_INCLUDE_ROOT" != "$MFC_INCLUDE_ROOT"
2816 then
2817 MFC_INCLUDE_PATH="$MFC_INCLUDE_PATH -I$MFC_INCLUDE_ROOT"
2819 CPPFLAGS="$OLDCPPFLAGS"
2821 if test -z "$MFC_LIBRARY_ROOT"
2822 then
2823 MFC_LIBRARY_ROOT=":$WINE_LIBRARY_ROOT:/usr/lib/mfc:/usr/local/lib:/usr/local/lib/mfc:/opt/mfc/lib";
2824 else
2825 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT:$MFC_LIBRARY_ROOT/lib:$MFC_LIBRARY_ROOT/mfc/src";
2827 AC_PATH_LIBRARY(MFC_LIBRARY_ROOT,[-lmfc],[$WINE_LIBRARY_PATH -lwine -lwine_unicode],[
2828 AC_MSG_ERROR([Could not find the MFC library])
2829 ],$MFC_LIBRARY_ROOT)
2830 if test -n "$MFC_LIBRARY_ROOT" -a "$MFC_LIBRARY_ROOT" != "$WINE_LIBRARY_ROOT"
2831 then
2832 MFC_LIBRARY_PATH="-L$MFC_LIBRARY_ROOT"
2833 else
2834 MFC_LIBRARY_PATH=""
2837 AC_SUBST(ATL_INCLUDE_PATH)
2838 AC_SUBST(MFC_INCLUDE_PATH)
2839 AC_SUBST(MFC_LIBRARY_PATH)
2842 AC_LANG_C()
2844 dnl **** Generate output files ****
2846 MAKE_RULES=Make.rules
2847 AC_SUBST_FILE(MAKE_RULES)
2849 AC_OUTPUT([
2850 Make.rules
2851 ##WINEMAKER_PROJECTS##
2854 echo
2855 echo "Configure finished. Do 'make' to build the project."
2856 echo
2858 dnl Local Variables:
2859 dnl comment-start: "dnl "
2860 dnl comment-end: ""
2861 dnl comment-start-skip: "\\bdnl\\b\\s *"
2862 dnl compile-command: "autoconf"
2863 dnl End:
2864 --- Make.rules.in ---
2865 # Copyright 2000 Francois Gouget for CodeWeavers
2866 # fgouget@codeweavers.com
2868 # Global rules shared by all makefiles -*-Makefile-*-
2870 # Each individual makefile must define the following variables:
2871 # WINE_INCLUDE_ROOT: Wine's headers location
2872 # WINE_LIBRARY_ROOT: Wine's libraries location
2873 # TOPOBJDIR : top-level object directory
2874 # SRCDIR : source directory for this module
2876 # Each individual makefile may define the following additional variables:
2878 # SUBDIRS : subdirectories that contain a Makefile
2879 # DLLS : WineLib libraries to be built
2880 # EXES : WineLib executables to be built
2882 # CEXTRA : extra c flags (e.g. '-Wall')
2883 # CXXEXTRA : extra c++ flags (e.g. '-Wall')
2884 # WRCEXTRA : extra wrc flags (e.g. '-p _SysRes')
2885 # DEFINES : defines (e.g. -DSTRICT)
2886 # INCLUDE_PATH : additional include path
2887 # LIBRARY_PATH : additional library path
2888 # LIBRARIES : additional Unix libraries to link with
2890 # C_SRCS : C sources for the module
2891 # CXX_SRCS : C++ sources for the module
2892 # RC_SRCS : resource source files
2893 # SPEC_SRCS : interface definition files
2896 # Where is Wine
2898 WINE_INCLUDE_ROOT = @WINE_INCLUDE_ROOT@
2899 WINE_INCLUDE_PATH = @WINE_INCLUDE_PATH@
2900 WINE_LIBRARY_ROOT = @WINE_LIBRARY_ROOT@
2901 WINE_LIBRARY_PATH = @WINE_LIBRARY_PATH@
2903 LD_PATH = @LD_PATH@
2905 # Where are the MFC
2907 ATL_INCLUDE_ROOT = @ATL_INCLUDE_ROOT@
2908 ATL_INCLUDE_PATH = @ATL_INCLUDE_PATH@
2909 MFC_INCLUDE_ROOT = @MFC_INCLUDE_ROOT@
2910 MFC_INCLUDE_PATH = @MFC_INCLUDE_PATH@
2911 MFC_LIBRARY_ROOT = @MFC_LIBRARY_ROOT@
2912 MFC_LIBRARY_PATH = @MFC_LIBRARY_PATH@
2914 # First some useful definitions
2916 SHELL = /bin/sh
2917 CC = @CC@
2918 CPP = @CPP@
2919 WRC = @WRC@
2920 CFLAGS = @CFLAGS@
2921 CXXFLAGS = @CXXFLAGS@
2922 WRCFLAGS = -r -L
2923 OPTIONS = @OPTIONS@ -D_REENTRANT -DWINELIB
2924 X_CFLAGS = @X_CFLAGS@
2925 X_LIBS = @X_LIBS@
2926 XLIB = @X_PRE_LIBS@ @XLIB@ @X_EXTRA_LIBS@
2927 DLL_LINK = @DLL_LINK@
2928 LIBS = @LIBS@ $(LIBRARY_PATH)
2929 YACC = @YACC@
2930 LEX = @LEX@
2931 LEXLIB = @LEXLIB@
2932 LN_S = @LN_S@
2933 ALLFLAGS = $(DEFINES) -I$(SRCDIR) $(WINE_INCLUDE_PATH) $(INCLUDE_PATH)
2934 ALLCFLAGS = $(CFLAGS) $(CEXTRA) $(OPTIONS) $(X_CFLAGS) $(ALLFLAGS)
2935 ALLCXXFLAGS=$(CXXFLAGS) $(CXXEXTRA) $(OPTIONS) $(X_CFLAGS) $(ALLFLAGS)
2936 ALLWRCFLAGS=$(WRCFLAGS) $(WRCEXTRA) $(OPTIONS) $(ALLFLAGS)
2937 LDCOMBINE = ld -r
2938 LDSHARED = @LDSHARED@
2939 LDXXSHARED= @LDXXSHARED@
2940 LDDLLFLAGS= @LDDLLFLAGS@
2941 STRIP = strip
2942 STRIPFLAGS= --strip-unneeded
2943 RM = rm -f
2944 MV = mv
2945 MKDIR = mkdir -p
2946 WINE = @WINE@
2947 WINEBUILD = @WINEBUILD@
2948 @SET_MAKE@
2950 # Installation infos
2952 INSTALL = @INSTALL@
2953 INSTALL_PROGRAM = @INSTALL_PROGRAM@
2954 INSTALL_DATA = @INSTALL_DATA@
2955 prefix = @prefix@
2956 exec_prefix = @exec_prefix@
2957 bindir = @bindir@
2958 libdir = @libdir@
2959 infodir = @infodir@
2960 mandir = @mandir@
2961 prog_manext = 1
2962 conf_manext = 5
2964 OBJS = $(C_SRCS:.c=.o) $(CXX_SRCS:.cpp=.o) \
2965 $(SPEC_SRCS:.spec=.spec.o)
2966 CLEAN_FILES = *.spec.c y.tab.c y.tab.h lex.yy.c \
2967 core *.orig *.rej \
2968 \\\#*\\\# *~ *% .\\\#*
2970 # Implicit rules
2972 .SUFFIXES: .cpp .rc .res .tmp.o .spec .spec.c .spec.o
2974 .c.o:
2975 $(CC) -c $(ALLCFLAGS) -o $@ $<
2977 .cpp.o:
2978 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2980 .cxx.o:
2981 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2983 .rc.res:
2984 $(LD_PATH) $(WRC) $(ALLWRCFLAGS) -o $@ $<
2986 .PHONY: all install uninstall clean distclean depend dummy
2988 # 'all' target first in case the enclosing Makefile didn't define any target
2990 all: Makefile
2992 # Rules for makefile
2994 Makefile: Makefile.in $(TOPSRCDIR)/configure
2995 @echo Makefile is older than $?, please rerun $(TOPSRCDIR)/configure
2996 @exit 1
2998 # Rules for cleaning
3000 $(SUBDIRS:%=%/__clean__): dummy
3001 cd `dirname $@` && $(MAKE) clean
3003 $(EXTRASUBDIRS:%=%/__clean__): dummy
3004 -cd `dirname $@` && $(RM) $(CLEAN_FILES)
3006 clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
3007 $(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(OBJS) $(SPEC_SRCS:.spec=.tmp.o) $(EXES) $(EXES:%=%.so) $(DLLS)
3009 # Rules for installing
3011 $(SUBDIRS:%=%/__install__): dummy
3012 cd `dirname $@` && $(MAKE) install
3014 $(SUBDIRS:%=%/__uninstall__): dummy
3015 cd `dirname $@` && $(MAKE) uninstall
3017 # Misc. rules
3019 $(SUBDIRS): dummy
3020 @cd $@ && $(MAKE)
3022 dummy:
3024 # End of global rules
3025 --- wrapper.c ---
3027 * Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
3030 #include <dlfcn.h>
3031 #include <windows.h>
3036 * Describe the wrapped application
3040 * This is either CUIEXE for a console based application or
3041 * GUIEXE for a regular windows application.
3043 #define APP_TYPE ##WINEMAKER_APP_TYPE##
3046 * This is the application library's base name, i.e. 'hello' if the
3047 * library is called 'libhello.so'.
3049 static char* appName = ##WINEMAKER_APP_NAME##;
3052 * This is the name of the application's Windows module. If left NULL
3053 * then appName is used.
3055 static char* appModule = NULL;
3058 * This is the application's entry point. This is usually "WinMain" for a
3059 * GUIEXE and 'main' for a CUIEXE application.
3061 static char* appInit = ##WINEMAKER_APP_INIT##;
3064 * This is either non-NULL for MFC-based applications and is the name of the
3065 * MFC's module. This is the module in which we will take the 'WinMain'
3066 * function.
3068 static char* mfcModule = ##WINEMAKER_APP_MFC##;
3073 * Implement the main.
3076 #if APP_TYPE == GUIEXE
3077 typedef int WINAPI (*WinMainFunc)(HINSTANCE hInstance, HINSTANCE hPrevInstance,
3078 PSTR szCmdLine, int iCmdShow);
3079 #else
3080 typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp);
3081 #endif
3083 #if APP_TYPE == GUIEXE
3084 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
3085 PSTR szCmdLine, int iCmdShow)
3086 #else
3087 int WINAPI Main(int argc, char** argv, char** envp)
3088 #endif
3090 void* appLibrary;
3091 HINSTANCE hApp,hMFC,hMain;
3092 void* appMain;
3093 char* libName;
3094 int retcode;
3096 /* Load the application's library */
3097 libName=(char*)malloc(strlen(appName)+5+3+1);
3098 /* FIXME: we should get the wrapper's path and use that as the base for
3099 * the library
3101 sprintf(libName,"./lib%s.so",appName);
3102 appLibrary=dlopen(libName,RTLD_NOW);
3103 if (appLibrary==NULL) {
3104 sprintf(libName,"lib%s.so",appName);
3105 appLibrary=dlopen(libName,RTLD_NOW);
3107 if (appLibrary==NULL) {
3108 char format[]="Could not load the %s library:\r\n%s";
3109 char* error;
3110 char* msg;
3112 error=dlerror();
3113 msg=(char*)malloc(strlen(format)+strlen(libName)+strlen(error));
3114 sprintf(msg,format,libName,error);
3115 MessageBox(NULL,msg,"dlopen error",MB_OK);
3116 free(msg);
3117 return 1;
3120 /* Then if this application is MFC based, load the MFC module */
3121 /* FIXME: I'm not sure this is really necessary */
3122 if (mfcModule!=NULL) {
3123 hMFC=LoadLibrary(mfcModule);
3124 if (hMFC==NULL) {
3125 char format[]="Could not load the MFC module %s (%d)";
3126 char* msg;
3128 msg=(char*)malloc(strlen(format)+strlen(mfcModule)+11);
3129 sprintf(msg,format,mfcModule,GetLastError());
3130 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
3131 free(msg);
3132 return 1;
3134 /* MFC is a special case: the WinMain is in the MFC library,
3135 * instead of the application's library.
3137 hMain=hMFC;
3138 } else {
3139 hMFC=NULL;
3142 /* Load the application's module */
3143 if (appModule==NULL) {
3144 appModule=appName;
3146 hApp=LoadLibrary(appModule);
3147 if (hApp==NULL) {
3148 char format[]="Could not load the application's module %s (%d)";
3149 char* msg;
3151 msg=(char*)malloc(strlen(format)+strlen(appModule)+11);
3152 sprintf(msg,format,appModule,GetLastError());
3153 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
3154 free(msg);
3155 return 1;
3156 } else if (hMain==NULL) {
3157 hMain=hApp;
3160 /* Get the address of the application's entry point */
3161 appMain=(WinMainFunc*)GetProcAddress(hMain, appInit);
3162 if (appMain==NULL) {
3163 char format[]="Could not get the address of %s (%d)";
3164 char* msg;
3166 msg=(char*)malloc(strlen(format)+strlen(appInit)+11);
3167 sprintf(msg,format,appInit,GetLastError());
3168 MessageBox(NULL,msg,"GetProcAddress error",MB_OK);
3169 free(msg);
3170 return 1;
3173 /* And finally invoke the application's entry point */
3174 #if APP_TYPE == GUIEXE
3175 retcode=(*((WinMainFunc)appMain))(hApp,hPrevInstance,szCmdLine,iCmdShow);
3176 #else
3177 retcode=(*((MainFunc)appMain))(argc,argv,envp);
3178 #endif
3180 /* Cleanup and done */
3181 FreeLibrary(hApp);
3182 if (hMFC!=NULL) {
3183 FreeLibrary(hMFC);
3185 dlclose(appLibrary);
3186 free(libName);
3188 return retcode;