3 # Copyright 2000 Francois Gouget for CodeWeavers
4 # fgouget@codeweavers.com
20 # The following constants define what we do with the case of filenames
23 # Never rename a file to lowercase
27 # Rename all files to lowercase
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)
46 # Skip the questions till the end of this scope
53 # Make a backup of the files
57 # Defines which files to rename
61 # Options for the 'Source' method
64 # Specifies that we have only one target so that all sources relate
65 # to this target. By default this variable is left undefined which
66 # means winemaker should try to find out by itself what the targets
67 # are. If not undefined then this contains the name of the default
68 # target (without the extension).
69 my $opt_single_target;
72 # If '$opt_single_target' has been specified then this is the type of
73 # that target. Otherwise it specifies whether the default target type
74 # is guiexe or cuiexe.
78 # Contains the default set of flags to be used when creating a new target.
82 # If true then winemaker should ask questions to the user as it goes
84 my $opt_is_interactive;
85 my $opt_ask_project_options;
86 my $opt_ask_target_options;
89 # If true then winemaker should not generate any file (mostly
90 # makefiles, thus the name, but also .spec files, configure.in, etc.)
94 # Specifies not to print the banner if set.
101 # Target modelization
105 # The description of a target is stored in an array. The constants
106 # below identify what is stored at each index of the array.
109 # This is the name of the target.
113 # Defines the type of target we want to build. See the TT_xxx
118 # Defines the target's enty point, i.e. the function that is called
123 # This is a bitfield containing flags refining the way the target
124 # should be handled. See the TF_xxx constants below
128 # This is a reference to an array containing the list of the
129 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
133 my $T_SOURCES_MISC=6;
136 # This is a reference to an array containing the list of macro
141 # This is a reference to an array containing the list of directory
142 # names that constitute the include path
143 my $T_INCLUDE_PATH=8;
146 # Same as T_INCLUDE_PATH but for the library search path
147 my $T_LIBRARY_PATH=9;
150 # The list of libraries to link with
154 # The list of dependencies between targets
158 # The following constants define the recognized types of target
161 # This is not a real target. This type of target is used to collect
162 # the sources that don't seem to belong to any other target. Thus no
163 # real target is generated for them, we just put the sources of the
164 # fake target in the global source list.
168 # For executables in the windows subsystem
172 # For executables in the console subsystem
176 # For dynamically linked libraries
180 # The following constants further refine how the target should be handled
183 # This target needs a wrapper
187 # This target is a wrapper
191 # This target is an MFC-based target
195 # Initialize a target:
196 # - set the target type to TT_SETTINGS, i.e. no real target will
202 @$target[$T_TYPE]=$TT_SETTINGS;
203 # leaving $T_INIT undefined
204 @$target[$T_FLAGS]=$opt_flags;
205 @$target[$T_SOURCES_C]=[];
206 @$target[$T_SOURCES_CXX]=[];
207 @$target[$T_SOURCES_RC]=[];
208 @$target[$T_SOURCES_MISC]=[];
209 @$target[$T_DEFINES]=[];
210 @$target[$T_INCLUDE_PATH]=[];
211 @$target[$T_LIBRARY_PATH]=[];
212 @$target[$T_IMPORTS]=[];
213 @$target[$T_DEPENDS]=[];
219 if ($type == $TT_GUIEXE) {
221 } elsif ($type == $TT_CUIEXE) {
223 } elsif ($type == $TT_DLL) {
232 # Project modelization
236 # First we have the notion of project. A project is described by an
237 # array (since we don't have structs in perl). The constants below
238 # identify what is stored at each index of the array.
241 # This is the path in which this project is located. In other
242 # words, this is the path to the Makefile.
246 # This index contains a reference to an array containing the project-wide
247 # settings. The structure of that arrray is actually identical to that of
248 # a regular target since it can also contain extra sources.
252 # This index contains a reference to an array of targets for this
253 # project. Each target describes how an executable or library is to
254 # be built. For each target this description takes the same form as
255 # that of the project: an array. So this entry is an array of arrays.
259 # Initialize a project:
260 # - set the project's path
261 # - initialize the target list
262 # - create a default target (will be removed later if unnecessary)
268 my $project_settings=[];
269 target_init($project_settings);
271 @$project[$P_PATH]=$path;
272 @$project[$P_SETTINGS]=$project_settings;
273 @$project[$P_TARGETS]=[];
290 # Contains the list of all projects. This list tells us what are
291 # the subprojects of the main Makefile and where we have to generate
296 # This is the main project, i.e. the one in the "." directory.
297 # It may well be empty in which case the main Makefile will only
298 # call out subprojects.
302 # Contains the defaults for the include path, etc.
303 # We store the defaults as if this were a target except that we only
304 # exploit the defines, include path, library path, library list and misc
309 # If one of the projects requires the MFc then we set this global variable
310 # to true so that configure asks the user to provide a path tothe MFC
322 # Cleans up a name to make it an acceptable Makefile
328 $name =~ tr/a-zA-Z0-9_/_/c;
333 # Returns true is the specified pathname is absolute.
334 # Note: pathnames that start with a variable '$' or
335 # '~' are considered absolute.
340 return ($path =~ /^[\/~\$]/);
344 # Performs a binary search looking for the specified item
349 my $last=@{$array}-1;
352 while ($first<=$last) {
353 my $index=int(($first+$last)/2);
354 my $cmp=@$array[$index] cmp $item;
369 # 'Source'-based Project analysis
374 # Allows the user to specify makefile and target specific options
375 # - target: the structure in which to store the results
376 # - options: the string containing the options
377 sub source_set_options
382 #FIXME: we must deal with escaping of stuff and all
383 foreach $option (split / /,$options) {
384 if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
385 push @{@$target[$T_DEFINES]},$option;
386 } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
387 push @{@$target[$T_INCLUDE_PATH]},$option;
388 } elsif ($option =~ /^-L/) {
389 push @{@$target[$T_LIBRARY_PATH]},$option;
390 } elsif ($option =~ /^-l/) {
391 push @{@$target[$T_IMPORTS]},$';
392 } elsif (@$target[$T_TYPE] != $TT_SETTINGS and
393 @$target[$T_TYPE] != $TT_DLL and
394 $option =~ /^--wrap/) {
395 @$target[$T_FLAGS]|=$TF_WRAP;
396 } elsif (@$target[$T_TYPE] != $TT_SETTINGS and $option =~ /^--mfc/) {
397 @$target[$T_FLAGS]|=$TF_MFC;
398 if (@$target[$T_TYPE] != $TT_DLL) {
399 @$target[$T_FLAGS]|=$TF_WRAP;
402 print STDERR "warning: unknown option \"$option\", ignoring it\n";
408 # Scans the specified directory to:
409 # - see if we should create a Makefile in this directory. We normally do
410 # so if we find a project file and sources
411 # - get a list of targets for this directory
412 # - get the list of source files
413 sub source_scan_directory
415 # a reference to the parent's project
416 my $parent_project=$_[0];
417 # the full relative path to the current directory, including a
418 # trailing '/', or an empty string if this is the top level directory
420 # the name of this directory, including a trailing '/', or an empty
421 # string if this is the top level directory
424 # reference to the project for this directory. May not be used
426 # list of targets found in the 'current' directory
428 # list of sources found in the current directory
433 # true if this directory contains a Windows project
434 my $has_win_project=0;
435 # If we don't find any executable/library then we might make up targets
436 # from the list of .dsp/.mak files we find since they usually have the
437 # same name as their target.
441 if (defined $opt_single_target or $dirname eq "") {
442 # Either there is a single target and thus a single project,
443 # or we are in the top level directory for which a project
445 $project=$parent_project;
448 project_init($project,$path);
451 # First find out what this directory contains:
452 # collect all sources, targets and subdirectories
453 my $directory=get_directory_contents($path);
454 foreach $dentry (@$directory) {
455 if ($dentry =~ /^\./) {
458 my $fullentry="$path$dentry";
459 if (-d "$fullentry") {
460 if ($dentry =~ /^(Release|Debug)/i) {
461 # These directories are often used to store the object files and the
462 # resulting executable/library. They should not contain anything else.
463 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
464 foreach $candidate (@candidates) {
465 if ($candidate =~ s/\.exe$//i) {
466 $targets{$candidate}=1;
467 } elsif ($candidate =~ s/^(.*)\.dll$/lib$1.so/i) {
468 $targets{$candidate}=1;
472 # Recursively scan this directory. Any source file that cannot be
473 # attributed to a project in one of the subdirectories will be attributed
475 source_scan_directory($project,"$fullentry/","$dentry/");
477 } elsif (-f "$fullentry") {
478 if ($dentry =~ s/\.exe$//i) {
480 } elsif ($dentry =~ s/^(.*)\.dll$/lib$1.so/i) {
482 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.spec\.c$/) {
483 push @sources_c,"$dentry";
484 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
485 push @sources_cxx,"$dentry";
486 } elsif ($dentry =~ /\.rc$/i) {
487 push @sources_rc,"$dentry";
488 } elsif ($dentry =~ /\.(h|hxx|inl|rc2|dlg)$/i) {
489 push @sources_misc,"$dentry";
490 } elsif ($dentry =~ /\.dsp$/i) {
491 push @dsp_files,"$dentry";
493 } elsif ($dentry =~ /\.mak$/i) {
494 push @mak_files,"$dentry";
496 } elsif ($dentry =~ /^makefile/i) {
503 # If we have a single target then all we have to do is assign
504 # all the sources to it and we're done
505 # FIXME: does this play well with the --interactive mode?
506 if ($opt_single_target) {
507 my $target=@{@$project[$P_TARGETS]}[0];
508 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
509 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
510 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
511 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
515 my $project_settings=@$project[$P_SETTINGS];
516 my $source_count=@sources_c+@sources_cxx+@sources_rc+
517 @{@$project_settings[$T_SOURCES_C]}+
518 @{@$project_settings[$T_SOURCES_CXX]}+
519 @{@$project_settings[$T_SOURCES_RC]};
520 if ($source_count == 0) {
521 # A project without real sources is not a project, get out!
522 if ($project!=$parent_project) {
523 $parent_settings=@$parent_project[$P_SETTINGS];
524 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
525 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
529 #print "targets=",%targets,"\n";
530 #print "target_count=$target_count\n";
531 #print "has_win_project=$has_win_project\n";
532 #print "dirname=$dirname\n";
535 if (($has_win_project != 0) or ($dirname eq "")) {
536 # Deal with cases where we could not find any executable/library, and
537 # thus have no target, although we did find some sort of windows project.
538 $target_count=keys %targets;
539 if ($target_count == 0) {
540 # Try to come up with a target list based on .dsp/.mak files
542 if (@dsp_files > 0) {
543 $prj_list=\@dsp_files;
545 $prj_list=\@mak_files;
547 foreach $filename (@$prj_list) {
548 $filename =~ s/\.(dsp|mak)$//i;
549 if ($opt_target_type == $TT_DLL) {
550 $filename = "lib$filename.so";
552 $targets{$filename}=1;
554 $target_count=keys %targets;
555 if ($target_count == 0) {
556 # Still nothing, try the name of the directory
558 if ($dirname eq "") {
559 # Bad luck, this is the top level directory!
560 $name=(split /\//, cwd)[-1];
563 # Remove the trailing '/'. Also eliminate whatever is after the last
564 # '.' as it is likely to be meaningless (.orig, .new, ...)
565 $name =~ s+(/|\.[^.]*)$++;
566 if ($name eq "src") {
567 # 'src' is probably a subdirectory of the real project directory.
568 # Try again with the parent (if any).
570 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
573 $name=(split /\//, cwd)[-1];
577 $name =~ s+(/|\.[^.]*)$++;
578 if ($opt_target_type == $TT_DLL) {
579 $name = "lib$name.so";
585 # Ask confirmation to the user if he wishes so
586 if ($opt_is_interactive == $OPT_ASK_YES) {
587 my $target_list=join " ",keys %targets;
588 print "\n*** In $path\n";
589 print "winemaker found the following list of (potential) targets\n";
590 print "$target_list\n";
591 print "Type enter to use it as is, your own comma-separated list of\n";
592 print "targets, 'none' to assign the source files to a parent directory,\n";
593 print "or 'ignore' to ignore everything in this directory tree.\n";
594 print "Target list:\n";
595 $target_list=<STDIN>;
597 if ($target_list eq "") {
598 # Keep the target list as is, i.e. do nothing
599 } elsif ($target_list eq "none") {
600 # Empty the target list
602 } elsif ($target_list eq "ignore") {
603 # Ignore this subtree altogether
607 foreach $target (split /,/,$target_list) {
610 # Also accept .exe and .dll as a courtesy
611 $target =~ s+(.*)\.dll$+lib$1.so+;
612 $target =~ s+\.exe$++;
619 # If we have no project at this level, then transfer all
620 # the sources to the parent project
621 $target_count=keys %targets;
622 if ($target_count == 0) {
623 if ($project!=$parent_project) {
624 my $parent_settings=@$parent_project[$P_SETTINGS];
625 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
626 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
627 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
628 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
629 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
634 # Otherwise add this project to the project list, except for
635 # the main project which is already in the list.
636 if ($dirname ne "") {
637 push @projects,$project;
640 # Ask for project-wide options
641 if ($opt_ask_project_options == $OPT_ASK_YES) {
642 print "Type any project-wide options (-D/-I/-L/-l),\n";
643 print "or 'skip' to skip the target specific options, or 'never' to not be\n";
644 print "asked this question again:\n";
647 if ($options eq "skip") {
648 $opt_ask_target_options=$OPT_ASK_SKIP;
649 } elsif ($options eq "never") {
650 $opt_ask_project_options="never";
652 source_set_options($project_settings,$options);
656 # - Create the targets
657 # - Check if we have both libraries and programs
658 # - Match each target with source files (sort in reverse
659 # alphabetical order to get the longest matches first)
660 my @local_imports=();
661 my @local_depends=();
663 foreach $target_name (sort { $b cmp $a } keys %targets) {
664 # Create the target...
667 target_init($target);
668 @$target[$T_NAME]=$target_name;
669 if ($target_name =~ /^lib(.*)\.so$/) {
670 @$target[$T_TYPE]=$TT_DLL;
671 @$target[$T_INIT]=get_default_init($TT_DLL);
672 @$target[$T_FLAGS]&=~$TF_WRAP;
674 push @local_depends,$target_name;
675 push @local_imports,$basename;
677 @$target[$T_TYPE]=$opt_target_type;
678 @$target[$T_INIT]=get_default_init($opt_target_type);
679 $basename=$target_name;
680 push @program_list,$target;
682 push @{@$project[$P_TARGETS]},$target;
684 # Ask for target-specific options
685 if ($opt_ask_target_options == $OPT_ASK_YES) {
686 print "Specify any link option (-L/-l) specific to the target \"$target_name\"\n";
687 print " or 'never' to not be asked this question again:\n";
690 if ($options eq "never") {
691 $opt_ask_target_options=$OPT_ASK_NO;
693 source_set_options($target,$options);
696 if (@$target[$T_FLAGS] & $TF_MFC) {
697 @$project_settings[$T_FLAGS]|=$TF_MFC;
698 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
699 push @{@$target[$T_IMPORTS]},"mfc";
703 if ($target_count == 1) {
704 push @{@$target[$T_SOURCES_C]},@sources_c;
705 push @{@$target[$T_SOURCES_CXX]},@sources_cxx;
706 push @{@$target[$T_SOURCES_RC]},@sources_rc;
707 push @{@$target[$T_SOURCES_MISC]},@sources_misc;
713 foreach $source (@sources_c) {
714 if ($source =~ /^$basename/i) {
715 push @{@$target[$T_SOURCES_C]},$source;
719 foreach $source (@sources_cxx) {
720 if ($source =~ /^$basename/i) {
721 push @{@$target[$T_SOURCES_CXX]},$source;
725 foreach $source (@sources_rc) {
726 if ($source =~ /^$basename/i) {
727 push @{@$target[$T_SOURCES_RC]},$source;
731 foreach $source (@sources_misc) {
732 if ($source =~ /^$basename/i) {
733 push @{@$target[$T_SOURCES_MISC]},$source;
738 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
739 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
740 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
741 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
743 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
744 $opt_ask_target_options=$OPT_ASK_YES;
747 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
748 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
750 # The sources that did not match, if any, go to the extra
751 # source list of the project settings
752 foreach $source (@sources_c) {
754 push @{@$project_settings[$T_SOURCES_C]},$source;
757 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
758 foreach $source (@sources_cxx) {
760 push @{@$project_settings[$T_SOURCES_CXX]},$source;
763 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
764 foreach $source (@sources_rc) {
766 push @{@$project_settings[$T_SOURCES_RC]},$source;
769 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
770 foreach $source (@sources_misc) {
772 push @{@$project_settings[$T_SOURCES_MISC]},$source;
775 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
777 # Finally if we are building both libraries and programs in
778 # this directory, then the programs should be linked with all
780 if (@local_imports > 0 and @program_list > 0) {
781 foreach $target (@program_list) {
782 push @{@$target[$T_LIBRARY_PATH]},".";
783 push @{@$target[$T_IMPORTS]},@local_imports;
784 push @{@$target[$T_DEPENDS]},@local_depends;
790 # Scan the source directories in search of things to build
793 my $main_target=@{$main_project[$P_TARGETS]}[0];
795 # If there's a single target then this is going to be the default target
796 if (defined $opt_single_target) {
797 if ($opt_target_type == $TT_DLL) {
798 @$main_target[$T_NAME]="lib$opt_single_target.so";
800 @$main_target[$T_NAME]="$opt_single_target";
802 @$main_target[$T_TYPE]=$opt_target_type;
805 # The main directory is always going to be there
806 push @projects,\@main_project;
808 # Now scan the directory tree looking for source files and, maybe, targets
809 print "Scanning the source directories...\n";
810 source_scan_directory(\@main_project,"","");
812 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
819 # 'vc.dsp'-based Project analysis
832 # Creating the wrapper targets
838 foreach $project (@projects) {
839 foreach $target (@{@$project[$P_TARGETS]}) {
840 if ((@$target[$T_FLAGS] & $TF_WRAP) != 0) {
842 target_init($wrapper);
843 @$wrapper[$T_NAME]=@$target[$T_NAME];
844 @$wrapper[$T_TYPE]=@$target[$T_TYPE];
845 @$wrapper[$T_INIT]=get_default_init(@$target[$T_TYPE]);
846 @$wrapper[$T_FLAGS]=$TF_WRAPPER | (@$target[$T_FLAGS] & $TF_MFC);
847 push @{@$wrapper[$T_SOURCES_C]},"@$wrapper[$T_NAME]_wrapper.c";
849 my $index=bsearch(@$target[$T_SOURCES_C],"@$wrapper[$T_NAME]_wrapper.c");
850 if (defined $index) {
851 splice(@{@$target[$T_SOURCES_C]},$index,1);
853 @$target[$T_NAME]="lib@$target[$T_NAME].so";
854 @$target[$T_TYPE]=$TT_DLL;
856 push @{@$project[$P_TARGETS]},$wrapper;
871 # Performs a directory traversal and renames the files so that:
872 # - they have the case desired by the user
873 # - their extension is of the appropriate case
874 # - they don't contain annoying characters like ' ', '$', '#', ...
875 sub fix_file_and_directory_names
879 if (opendir(DIRECTORY, "$dirname")) {
880 foreach $dentry (readdir DIRECTORY) {
881 if ($dentry =~ /^\./ or $dentry eq "CVS") {
884 # Set $warn to 1 if the user should be warned of the renaming
887 # autoconf and make don't support these characters well
888 my $new_name=$dentry;
889 $new_name =~ s/[ \$]/_/g;
891 # Our Make.rules supports all-uppercase and all-lowercase extensions.
892 # The others must be fixed.
893 if (-f "$dirname/$new_name") {
894 if ($new_name =~ /\.cpp/i and $new_name !~ /\.(cpp|CPP)/) {
895 $new_name =~ s/\.cpp$/.cpp/i;
897 if ($new_name =~ s/\.cxx$/.cpp/i) {
900 if ($new_name =~ /\.rc/i and $new_name !~ /\.(rc|RC)/) {
901 $new_name =~ s/\.rc$/.rc/i;
903 # And this last one is to avoid confusion then running make
904 if ($new_name =~ s/^makefile$/makefile.win/) {
909 # Adjust the case to the user's preferences
910 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
911 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
913 $new_name=lc $new_name;
916 # And finally, perform the renaming
917 if ($new_name ne $dentry) {
919 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
921 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
922 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
923 print STDERR " $!\n";
927 if (-d "$dirname/$new_name") {
928 fix_file_and_directory_names("$dirname/$new_name");
944 # This maps a directory name to a reference to an array listing
945 # its contents (files and directories)
949 # Retrieves the contents of the specified directory.
950 # We either get it from the directories hashtable which acts as a
951 # cache, or use opendir, readdir, closedir and store the result
953 sub get_directory_contents
958 #print "getting the contents of $dirname\n";
960 # check for a cached version
962 if ($dirname eq "") {
965 $directory=$directories{$dirname};
966 if (defined $directory) {
967 #print "->@$directory\n";
971 # Read this directory
972 if (opendir(DIRECTORY, "$dirname")) {
973 my @files=readdir DIRECTORY;
977 # Return an empty list
978 #print "error: cannot open $dirname\n";
982 #print "->@$directory\n";
983 $directories{$dirname}=$directory;
988 # Try to find a file for the specified filename. The attempt is
989 # case-insensitive which is why it's not trivial. If a match is
990 # found then we return the pathname with the correct case.
997 if ($dirname eq "" or $dirname eq ".") {
999 } elsif ($dirname =~ m+^[^/]+) {
1000 $dirname=cwd . "/" . $dirname;
1002 if ($dirname !~ m+/$+) {
1006 foreach $component (@$path) {
1007 #print " looking for $component in \"$dirname\"\n";
1008 if ($component eq ".") {
1011 } elsif ($component eq "..") {
1013 $dirname=dirname($dirname) . "/";
1016 my $directory=get_directory_contents $dirname;
1018 foreach $dentry (@$directory) {
1019 if ($dentry =~ /^$component$/i) {
1020 $dirname.="$dentry/";
1021 $real_path.="$dentry/";
1026 if (!defined $found) {
1028 #print " could not find $component in $dirname\n";
1033 $real_path=~ s+/$++;
1034 #print " -> found $real_path\n";
1039 # Performs a case-insensitive search for the specified file in the
1041 # $line is the line number that should be referenced when an error occurs
1042 # $filename is the file we are looking for
1043 # $dirname is the directory of the file containing the '#include' directive
1044 # if '"' was used, it is an empty string otherwise
1045 # $project and $target specify part of the include path
1046 sub get_real_include_name
1054 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1055 # This is not a relative path, we cannot make any check
1056 my $warning="path:$filename";
1057 if (!defined $warnings{$warning}) {
1058 $warnings{$warning}="1";
1059 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1060 print STDERR "$line: $filename\n";
1063 # Here's how we proceed:
1064 # - split the filename we look for into its components
1065 # - then for each directory in the include path
1066 # - trace the directory components starting from that directory
1067 # - if we fail to find a match at any point then continue with
1068 # the next directory in the include path
1069 # - otherwise, rejoice, our quest is over.
1070 my @file_components=split /[\/\\]+/, $filename;
1071 #print " Searching for $filename from @$project[$P_PATH]\n";
1074 if ($dirname ne "") {
1075 # This is an 'include ""' -> look in dirname first.
1076 #print " in $dirname (include \"\")\n";
1077 $real_filename=search_from($dirname,\@file_components);
1078 if (defined $real_filename) {
1079 return $real_filename;
1082 my $project_settings=@$project[$P_SETTINGS];
1083 foreach $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1084 my $dirname=$include;
1086 if (!is_absolute($dirname)) {
1087 $dirname="@$project[$P_PATH]$dirname";
1089 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1091 #print " in $dirname\n";
1092 $real_filename=search_from("$dirname",\@file_components);
1093 if (defined $real_filename) {
1094 return $real_filename;
1097 my $dotdotpath=@$project[$P_PATH];
1098 $dotdotpath =~ s/[^\/]+/../g;
1099 foreach $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1100 my $dirname=$include;
1102 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1103 #print " in $dirname (global setting)\n";
1104 $real_filename=search_from("$dirname",\@file_components);
1105 if (defined $real_filename) {
1106 return $real_filename;
1110 $filename =~ s+\\\\+/+g; # in include ""
1111 $filename =~ s+\\+/+g; # in include <> !
1112 if ($filename =~ /^[A-Z_.\/\\]*$/) {
1113 #FIXME: should this depend on --lower-uppercase & co???
1114 return lc "$filename";
1120 # 'Parses' a source file and fixes constructs that would not work with
1121 # Winelib. The parsing is rather simple and not all non-portable features
1122 # are corrected. The most important feature that is corrected is the case
1123 # and path separator of '#include' directives. This requires that each
1124 # source file be associated to a project & target so that the proper
1125 # include path is used.
1126 # Also note that the include path is relative to the directory in which the
1127 # compiler is run, i.e. that of the project, not to that of the file.
1133 $filename="@$project[$P_PATH]$filename";
1134 if (! -e $filename) {
1138 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1139 my $dirname=dirname($filename);
1141 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1145 print " $filename\n";
1146 #FIXME:assuming that because there is a .bak file, this is what we want is
1147 #probably flawed. Or is it???
1148 if (! -e "$filename.bak") {
1149 if (!copy("$filename","$filename.bak")) {
1150 print STDERR "error: unable to make a backup of $filename:\n";
1151 print STDERR " $!\n";
1155 if (!open(FILEI,"$filename.bak")) {
1156 print STDERR "error: unable to open $filename.bak for reading:\n";
1157 print STDERR " $!\n";
1160 if (!open(FILEO,">$filename")) {
1161 print STDERR "error: unable to open $filename for writing:\n";
1162 print STDERR " $!\n";
1167 my $rc_block_depth=0;
1168 my $rc_textinclude_state=0;
1172 if ($is_rc and !$is_mfc and /^(\s*\#\s*include\s*)\"afxres\.h\"/) {
1173 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1174 # the RC files it generates (even in non-MFC projects). So we replace
1175 # it with 'winres.h' its very close standard cousin so that non MFC
1176 # projects can compile in Wine without the MFC sources. This does not
1177 # harm VC but it will put 'afxres.h' back the next time the file is
1179 my $warning="mfc:afxres.h";
1180 if (!defined $warnings{$warning}) {
1181 $warnings{$warning}="1";
1182 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winres.h'\n";
1183 print STDERR "warning: the above warning is issued only once\n";
1185 print FILEO "/* winemaker: $1\"afxres.h\" */\n";
1186 print FILEO "$1\"winres.h\"$'";
1188 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1189 my $from_file=($2 eq "<"?"":$dirname);
1190 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1191 print FILEO "$1$2$real_include_name$4$'";
1192 $modified|=($real_include_name ne $3);
1193 } elsif (/^(\s*\#\s*pragma\s*pack\s*\((\s*push\s*,?)?\s*)(\w*)(\s*\))/) {
1194 my $pragma_header=$1;
1196 my $pragma_trailer=$4;
1197 #print "$pragma_header$size$pragma_trailer$'";
1198 #print "pragma push: size=$size\n";
1199 print FILEO "/* winemaker: $pragma_header$size$pragma_trailer */\n";
1201 if ($size eq "pop") {
1202 print FILEO "#include <poppack.h>$'";
1203 } elsif ($size eq "1") {
1204 print FILEO "#include <pshpack1.h>$'";
1205 } elsif ($size eq "2") {
1206 print FILEO "#include <pshpack2.h>$'";
1207 } elsif ($size eq "8") {
1208 print FILEO "#include <pshpack8.h>$'";
1209 } elsif ($size eq "4" or $size eq "") {
1210 print FILEO "#include <pshpack4.h>$'";
1212 my $warning="pack:$size";
1213 if (!defined $warnings{$warning}) {
1214 $warnings{$warning}="1";
1215 print STDERR "warning: assuming that the value of $size is 4 in\n";
1216 print STDERR "$line: $pragma_header$size$pragma_trailer\n";
1217 print STDERR "warning: the above warning is issued only once\n";
1219 print FILEO "#include <pshpack4.h>$'";
1223 if ($rc_block_depth == 0 and /^(\w+\s+(BITMAP|CURSOR|FONT|FONTDIR|ICON|MESSAGETABLE|TEXT)\s+((DISCARDABLE|FIXED|IMPURE|LOADONCALL|MOVEABLE|PRELOAD|PURE)\s+)*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1224 my $from_file=($5 eq "<"?"":$dirname);
1225 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
1226 print FILEO "$1$5$real_include_name$7$'";
1227 $modified|=($real_include_name ne $6);
1228 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1229 my $from_file=($2 eq "<"?"":$dirname);
1230 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1231 print FILEO "$1$2$real_include_name$4$'";
1232 $modified|=($real_include_name ne $3);
1233 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
1234 $rc_textinclude_state=1;
1236 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
1237 print FILEO "$1winres.h$2$'";
1239 } elsif (/^\s*BEGIN(\W.*)?$/) {
1240 $rc_textinclude_state|=2;
1243 } elsif (/^\s*END(\W.*)?$/) {
1244 $rc_textinclude_state=0;
1245 if ($rc_block_depth>0) {
1258 if ($opt_backup == 0 or $modified == 0) {
1259 if (!unlink("$filename.bak")) {
1260 print STDERR "error: unable to delete $filename.bak:\n";
1261 print STDERR " $!\n";
1267 # Analyzes each source file in turn to find and correct issues
1268 # that would cause it not to compile.
1271 print "Fixing the source files...\n";
1272 foreach $project (@projects) {
1273 foreach $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
1274 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1277 foreach $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
1278 fix_file($source,$project,$target);
1293 # Generates a target's .spec file
1294 sub generate_spec_file
1298 my $project_settings=$_[2];
1300 my $basename=@$target[$T_NAME];
1301 $basename =~ s+\.so$++;
1302 if (@$target[$T_FLAGS] & $TF_WRAP) {
1303 $basename =~ s+^lib++;
1304 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1305 $basename.="_wrapper";
1308 if (!open(FILEO,">$path$basename.spec")) {
1309 print STDERR "error: could not open \"$path$basename.spec\" for writing\n";
1310 print STDERR " $!\n";
1314 my $canon=canonize($basename);
1315 print FILEO "name $canon\n";
1316 print FILEO "type win32\n";
1317 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1318 print FILEO "mode guiexe\n";
1319 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1320 print FILEO "mode cuiexe\n";
1322 print FILEO "mode dll\n";
1324 if (defined @$target[$T_INIT] and ((@$target[$T_FLAGS] & $TF_WRAP) == 0)) {
1325 print FILEO "init @$target[$T_INIT]\n";
1327 if (@{@$target[$T_SOURCES_RC]} > 0) {
1328 if (@{@$target[$T_SOURCES_RC]} > 1) {
1329 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";
1331 my $rcname=@{@$target[$T_SOURCES_RC]}[0];
1332 $rcname =~ s+\.rc$++i;
1333 print FILEO "rsrc $rcname.res\n";
1336 # FIXME: we should try to remove duplicates in the import list
1337 foreach $library (@{$global_settings[$T_IMPORTS]}) {
1338 print FILEO "import $library\n";
1340 if (defined $project_settings) {
1341 foreach $library (@{@$project_settings[$T_IMPORTS]}) {
1342 print FILEO "import $library\n";
1345 foreach $library (@{@$target[$T_IMPORTS]}) {
1346 print FILEO "import $library\n";
1349 # Don't forget to export the 'Main' function for wrapped executables,
1350 # except for MFC ones!
1351 if (@$target[$T_FLAGS] == $TF_WRAP) {
1352 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1353 print FILEO "\n@ stdcall @$target[$T_INIT](long long ptr long) @$target[$T_INIT]\n";
1354 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1355 print FILEO "\n@ stdcall @$target[$T_INIT](long ptr ptr) @$target[$T_INIT]\n";
1357 print FILEO "\n@ stdcall @$target[$T_INIT](ptr long ptr) @$target[$T_INIT]\n";
1365 # Generates a target's wrapper file
1366 sub generate_wrapper_file
1371 if (!defined $templates{"wrapper.c"}) {
1372 print STDERR "winemaker: internal error: No template called 'wrapper.c'\n";
1376 if (!open(FILEO,">$path@$target[$T_NAME]_wrapper.c")) {
1377 print STDERR "error: unable to open \"$path$basename.c\" for writing:\n";
1378 print STDERR " $!\n";
1381 my $app_name="\"@$target[$T_NAME]\"";
1382 my $app_type=(@$target[$T_TYPE]==$TT_GUIEXE?"GUIEXE":"CUIEXE");
1383 my $app_init=(@$target[$T_TYPE]==$TT_GUIEXE?"\"WinMain\"":"\"main\"");
1384 my $app_mfc=(@$target[$T_FLAGS] & $TF_MFC?"\"mfc\"":NULL);
1385 foreach $line (@{$templates{"wrapper.c"}}) {
1386 $line =~ s/\#\#WINEMAKER_APP_NAME\#\#/$app_name/;
1387 $line =~ s/\#\#WINEMAKER_APP_TYPE\#\#/$app_type/;
1388 $line =~ s/\#\#WINEMAKER_APP_INIT\#\#/$app_init/;
1389 $line =~ s/\#\#WINEMAKER_APP_MFC\#\#/$app_mfc/;
1396 # A convenience function to generate all the lists (defines,
1397 # C sources, C++ source, etc.) in the Makefile
1406 printf FILEO "%-9s =",$name;
1408 if (defined $list and @$list > 0) {
1409 foreach $item (@$list) {
1411 if (defined $data) {
1412 $value=&$data($item);
1417 print FILEO " \\\n\t$value";
1427 # Generates a project's Makefile.in and all the target files
1428 sub generate_project_files
1431 my $project_settings=@$project[$P_SETTINGS];
1432 my @library_list=();
1433 my @program_list=();
1435 # Then sort the targets and separate the libraries from the programs
1436 foreach $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
1437 if (@$target[$T_TYPE] == $TT_DLL) {
1438 push @library_list,$target;
1440 push @program_list,$target;
1443 @$project[$P_TARGETS]=[];
1444 push @{@$project[$P_TARGETS]}, @library_list;
1445 push @{@$project[$P_TARGETS]}, @program_list;
1447 if (!open(FILEO,">@$project[$P_PATH]Makefile.in")) {
1448 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile.in\" for writing\n";
1449 print STDERR " $!\n";
1453 print FILEO "### Generic autoconf variables\n\n";
1454 print FILEO "TOPSRCDIR = \@top_srcdir\@\n";
1455 print FILEO "TOPOBJDIR = .\n";
1456 print FILEO "SRCDIR = \@srcdir\@\n";
1457 print FILEO "VPATH = \@srcdir\@\n";
1459 if (@$project[$P_PATH] eq "") {
1460 # This is the main project. It is also responsible for recursively
1461 # calling the other projects
1462 generate_list("SUBDIRS",1,\@projects,sub
1464 if ($_[0] != \@main_project) {
1465 my $subdir=@{$_[0]}[$P_PATH];
1469 # Eliminating the main project by returning undefined!
1472 if (@{@$project[$P_TARGETS]} > 0) {
1473 generate_list("LIBRARIES",1,\@library_list,sub
1475 return @{$_[0]}[$T_NAME];
1477 generate_list("PROGRAMS",1,\@program_list,sub
1479 return @{$_[0]}[$T_NAME];
1483 print FILEO "### Global settings\n\n";
1484 # Make it so that the project-wide settings override the global settings
1485 generate_list("DEFINES",0,@$project_settings[$T_DEFINES],sub
1489 generate_list("",1,$global_settings[$T_DEFINES],sub
1493 generate_list("INCLUDE_PATH",$no_extra,@$project_settings[$T_INCLUDE_PATH],sub
1497 generate_list("",1,$global_settings[$T_INCLUDE_PATH],sub
1499 if ($_[0] !~ /^-I/) {
1502 if (is_absolute($')) {
1505 return "\$(TOPSRCDIR)/$_[0]";
1507 generate_list("LIBRARY_PATH",$no_extra,@$project_settings[$T_LIBRARY_PATH],sub
1511 generate_list("",1,$global_settings[$T_LIBRARY_PATH],sub
1513 if ($_[0] !~ /^-L/) {
1516 if (is_absolute($')) {
1519 return "\$(TOPSRCDIR)/$_[0]";
1521 generate_list("IMPORTS",$no_extra,@$project_settings[$T_IMPORTS],sub
1525 generate_list("",1,$global_settings[$T_IMPORTS],sub
1531 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
1532 @{@$project_settings[$T_SOURCES_CXX]}+
1533 @{@$project_settings[$T_SOURCES_RC]};
1534 my $no_extra=($extra_source_count == 0);
1536 print FILEO "### Extra source lists\n\n";
1537 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
1538 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
1539 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
1540 print FILEO "EXTRA_OBJS = \$(EXTRA_C_SRCS:.c=.o) \$(EXTRA_CXX_SRCS:.cpp=.o)\n";
1544 # Iterate over all the targets...
1545 foreach $target (@{@$project[$P_TARGETS]}) {
1546 print FILEO "\n### @$target[$T_NAME] sources and settings\n\n";
1547 my $canon=canonize("@$target[$T_NAME]");
1549 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
1550 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
1551 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
1552 my $basename=@$target[$T_NAME];
1553 $basename =~ s+\.so$++;
1554 if (@$target[$T_FLAGS] & $TF_WRAP) {
1555 $basename =~ s+^lib++;
1556 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1557 $basename.="_wrapper";
1559 generate_list("${canon}_SPEC_SRCS",1,[ "$basename.spec"]);
1560 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH],sub
1564 generate_list("${canon}_IMPORTS",1,@$target[$T_IMPORTS],sub
1568 generate_list("${canon}_DEPENDS",1,@$target[$T_DEPENDS],sub
1572 print FILEO "${canon}_OBJS = \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_C_SRCS:.c=.o) \$(${canon}_CXX_SRCS:.cpp=.o) \$(EXTRA_OBJS)\n";
1575 print FILEO "### Global source lists\n\n";
1576 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
1578 my $canon=canonize(@{$_[0]}[$T_NAME]);
1580 return "\$(${canon}_C_SRCS)";
1583 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
1585 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
1587 my $canon=canonize(@{$_[0]}[$T_NAME]);
1589 return "\$(${canon}_CXX_SRCS)";
1592 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
1594 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
1596 my $canon=canonize(@{$_[0]}[$T_NAME]);
1598 return "\$(${canon}_RC_SRCS)";
1601 generate_list("",1,@$project_settings[$T_SOURCES_RC]);
1603 generate_list("SPEC_SRCS",1,@$project[$P_TARGETS],sub
1605 my $canon=canonize(@{$_[0]}[$T_NAME]);
1607 return "\$(${canon}_SPEC_SRCS)";
1612 print FILEO "### Generic autoconf targets\n\n";
1613 if (@$project[$P_PATH] eq "") {
1614 print FILEO "all: \$(SUBDIRS) \$(LIBRARIES) \$(PROGRAMS)\n";
1616 print FILEO "all: \$(LIBRARIES) \$(PROGRAMS)\n";
1619 print FILEO "\@MAKE_RULES\@\n";
1621 print FILEO "install::\n";
1622 if (@$project[$P_PATH] eq "") {
1623 # This is the main project. It is also responsible for recursively
1624 # calling the other projects
1625 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) install) || exit 1; done\n";
1627 if (@{@$project[$P_TARGETS]} > 0) {
1628 print FILEO "\tfor i in \$(PROGRAMS); do \$(INSTALL_PROGRAM) \$\$i \$(bindir); done\n";
1629 print FILEO "\tfor i in \$(LIBRARIES); do \$(INSTALL_LIBRARY) \$\$i \$(libdir); done\n";
1632 print FILEO "uninstall::\n";
1633 if (@$project[$P_PATH] eq "") {
1634 # This is the main project. It is also responsible for recursively
1635 # calling the other projects
1636 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) uninstall) || exit 1; done\n";
1638 if (@{@$project[$P_TARGETS]} > 0) {
1639 print FILEO "\tfor i in \$(PROGRAMS); do \$(RM) \$(bindir)/\$\$i;done\n";
1640 print FILEO "\tfor i in \$(LIBRARIES); do \$(RM) \$(libdir)/\$\$i;done\n";
1642 print FILEO "\n\n\n";
1644 if (@{@$project[$P_TARGETS]} > 0) {
1645 print FILEO "### Target specific build rules\n\n";
1646 foreach $target (@{@$project[$P_TARGETS]}) {
1647 my $canon=canonize("@$target[$T_NAME]");
1649 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.spec.c): \$(${canon}_RC_SRCS:.rc=.res)\n";
1651 print FILEO "@$target[$T_NAME]: \$(${canon}_OBJS) \$(${canon}_DEPENDS) \n";
1652 if (@$target[$T_TYPE] eq $TT_DLL) {
1653 print FILEO "\t\$(LDSHARED) -shared -Wl,-soname,\$\@ -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(${canon}_IMPORTS:%=-l%) \$(DLL_LINK) \$(LIBS)\n";
1655 print FILEO "\t\$(CC) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(${canon}_IMPORTS:%=-l%) \$(DLL_LINK) \$(LIBS)\n";
1662 foreach $target (@{@$project[$P_TARGETS]}) {
1663 generate_spec_file(@$project[$P_PATH],$target,$project_settings);
1664 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1665 generate_wrapper_file(@$project[$P_PATH],$target);
1671 # Perform the replacements in the template configure files
1672 # Return 1 for success, 0 for failure
1673 sub generate_configure
1676 my $a_source_file=$_[1];
1678 if (!defined $templates{$filename}) {
1679 if ($filename ne "configure") {
1680 print STDERR "winemaker: internal error: No template called '$filename'\n";
1685 if (!open(FILEO,">$filename")) {
1686 print STDERR "error: unable to open \"$filename\" for writing:\n";
1687 print STDERR " $!\n";
1690 foreach $line (@{$templates{$filename}}) {
1691 if ($line =~ /^\#\#WINEMAKER_PROJECTS\#\#$/) {
1692 foreach $project (@projects) {
1693 print FILEO "@$project[$P_PATH]Makefile\n";
1696 $line =~ s+\#\#WINEMAKER_SOURCE\#\#+$a_source_file+;
1697 $line =~ s+\#\#WINEMAKER_NEEDS_MFC\#\#+$needs_mfc+;
1705 sub generate_generic
1709 if (!defined $templates{$filename}) {
1710 print STDERR "winemaker: internal error: No template called '$filename'\n";
1713 if (!open(FILEO,">$filename")) {
1714 print STDERR "error: unable to open \"$filename\" for writing:\n";
1715 print STDERR " $!\n";
1718 foreach $line (@{$templates{$filename}}) {
1725 # Generates the global files:
1729 sub generate_global_files
1731 generate_generic("Make.rules.in");
1733 # Get the name of a source file for configure.in
1735 search_a_file: foreach $project (@projects) {
1736 foreach $target (@{@$project[$P_TARGETS]}) {
1737 $a_source_file=@{@$target[$T_SOURCES_C]}[0];
1738 if (!defined $a_source_file) {
1739 $a_source_file=@{@$target[$T_SOURCES_CXX]}[0];
1741 if (!defined $a_source_file) {
1742 $a_source_file=@{@$target[$T_SOURCES_RC]}[0];
1744 if (defined $a_source_file) {
1745 $a_source_file="@$project[$P_PATH]$a_source_file";
1751 generate_configure("configure.in",$a_source_file);
1752 unlink("configure");
1753 if (generate_configure("configure",$a_source_file) == 0) {
1756 # Add execute permission to configure for whoever has the right to read it
1757 my @st=stat("configure");
1760 $mode|=($mode & 0444) >>2;
1761 chmod($mode,"configure");
1763 print "warning: could not generate the configure script. You need to run autoconf\n";
1769 sub generate_read_templates
1774 if (/^--- ((\w\.?)+) ---$/) {
1776 if (defined $templates{$filename}) {
1777 print STDERR "winemaker: internal error: There is more than one template for $filename\n";
1781 $templates{$filename}=$file;
1783 } elsif (defined $file) {
1790 # This is where we finally generate files. In fact this method does not
1791 # do anything itself but calls the methods that do the actual work.
1794 print "Generating project files...\n";
1795 generate_read_templates();
1796 generate_global_files();
1798 foreach $project (@projects) {
1799 my $path=@$project[$P_PATH];
1806 generate_project_files($project);
1819 $opt_lower=$OPT_LOWER_UPPERCASE;
1821 # $opt_single_target=<undefined>
1822 $opt_target_type=$TT_GUIEXE;
1824 $opt_is_interactive=$OPT_ASK_NO;
1825 $opt_ask_project_options=$OPT_ASK_NO;
1826 $opt_ask_target_options=$OPT_ASK_NO;
1838 project_init(\@main_project,"");
1841 my $arg=shift @ARGV;
1843 if ($arg eq "--nobanner") {
1845 } elsif ($arg eq "--backup") {
1847 } elsif ($arg eq "--nobackup") {
1849 } elsif ($arg eq "--single-target") {
1850 $opt_single_target=shift @ARGV;
1851 } elsif ($arg eq "--lower-none") {
1852 $opt_lower=$OPT_LOWER_NONE;
1853 } elsif ($arg eq "--lower-all") {
1854 $opt_lower=$OPT_LOWER_ALL;
1855 } elsif ($arg eq "--lower-uppercase") {
1856 $opt_lower=$OPT_LOWER_UPPERCASE;
1857 } elsif ($arg eq "--no-makefile") {
1860 } elsif ($arg =~ /^-D/) {
1861 push @{$global_settings[$T_DEFINES]},$arg;
1862 } elsif ($arg =~ /^-I/) {
1863 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
1864 } elsif ($arg =~ /^-L/) {
1865 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
1866 } elsif ($arg =~ /^-l/) {
1867 push @{$global_settings[$T_IMPORTS]},$';
1869 # 'Source'-based method options
1870 } elsif ($arg eq "--dll") {
1871 $opt_target_type=$TT_DLL;
1872 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
1873 $opt_target_type=$TT_GUIEXE;
1874 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
1875 $opt_target_type=$TT_CUIEXE;
1876 } elsif ($arg eq "--interactive") {
1877 $opt_is_interactive=$OPT_ASK_YES;
1878 $opt_ask_project_options=$OPT_ASK_YES;
1879 $opt_ask_target_options=$OPT_ASK_YES;
1880 } elsif ($arg eq "--wrap") {
1881 $opt_flags|=$TF_WRAP;
1882 } elsif ($arg eq "--nowrap") {
1883 $opt_flags&=~$TF_WRAP;
1884 } elsif ($arg eq "--mfc") {
1885 $opt_flags|=$TF_MFC|$TF_WRAP;
1887 } elsif ($arg eq "--nomfc") {
1888 $opt_flags&=~($TF_MFC|$TF_WRAP);
1893 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
1894 print STDERR "Unknown option: $arg\n";
1901 if ($opt_no_banner == 0 or defined $usage) {
1902 print "Winemaker $version\n";
1903 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
1906 if (defined $usage) {
1907 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup]\n";
1908 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
1909 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
1910 print STDERR " [--wrap|--nowrap] [--mfc|--nomfc]\n";
1911 print STDERR " [-Dmacro[=defn]] [-Idir] [-Ldir] [-llibrary]\n";
1912 print STDERR " [--interactive] [--single-target name]\n";
1916 # Fix the file and directory names
1917 fix_file_and_directory_names(".");
1919 # Scan the sources to identify the projects and targets
1922 # Create targets for wrappers
1925 # Fix the source files
1928 # Generate the Makefile and the spec file
1929 if (! $opt_no_makefile) {
1935 --- configure.in ---
1936 dnl Process this file with autoconf to produce a configure script.
1937 dnl Author: Michael Patra <micky@marie.physik.tu-berlin.de>
1938 dnl <patra@itp1.physik.tu-berlin.de>
1939 dnl Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
1941 AC_REVISION([configure.in 1.00])
1942 AC_INIT(##WINEMAKER_SOURCE##)
1944 NEEDS_MFC=##WINEMAKER_NEEDS_MFC##
1946 dnl **** Command-line arguments ****
1950 dnl **** Check for some programs ****
1959 AC_PATH_PROG(LDCONFIG, ldconfig, true, /sbin:/usr/sbin:$PATH)
1961 dnl **** Check for some libraries ****
1963 dnl Check for -lm for BeOS
1964 AC_CHECK_LIB(m,sqrt)
1965 dnl Check for -li386 for NetBSD and OpenBSD
1966 AC_CHECK_LIB(i386,i386_set_ldt)
1967 dnl Check for -lossaudio for NetBSD
1968 AC_CHECK_LIB(ossaudio,_oss_ioctl)
1969 dnl Check for -lw for Solaris
1970 AC_CHECK_LIB(w,iswalnum)
1971 dnl Check for -lnsl for Solaris
1972 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))
1973 dnl Check for -lsocket for Solaris
1974 AC_CHECK_FUNCS(connect,,AC_CHECK_LIB(socket,connect))
1975 dnl Check for -lxpg4 for FreeBSD
1976 AC_CHECK_LIB(xpg4,setrunelocale)
1977 dnl Check for -lmmap for OS/2
1978 AC_CHECK_LIB(mmap,mmap)
1979 dnl Check for openpty
1980 AC_CHECK_FUNCS(openpty,,
1981 AC_CHECK_LIB(util,openpty,
1982 AC_DEFINE(HAVE_OPENPTY)
1986 AC_CHECK_HEADERS(dlfcn.h,
1987 AC_CHECK_FUNCS(dlopen,
1988 AC_DEFINE(HAVE_DL_API),
1989 AC_CHECK_LIB(dl,dlopen,
1990 AC_DEFINE(HAVE_DL_API)
2001 dnl **** Check which curses lib to use ***
2002 if test "$CURSES" = "yes"
2004 AC_CHECK_HEADERS(ncurses.h)
2005 if test "$ac_cv_header_ncurses_h" = "yes"
2007 AC_CHECK_LIB(ncurses,waddch)
2009 if test "$ac_cv_lib_ncurses_waddch" = "yes"
2011 AC_CHECK_LIB(ncurses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2012 AC_CHECK_LIB(ncurses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2014 AC_CHECK_HEADERS(curses.h)
2015 if test "$ac_cv_header_curses_h" = "yes"
2017 AC_CHECK_LIB(curses,waddch)
2018 if test "$ac_cv_lib_curses_waddch" = "yes"
2020 AC_CHECK_LIB(curses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2021 AC_CHECK_LIB(curses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2027 dnl **** If ln -s doesn't work, use cp instead ****
2028 if test "$ac_cv_prog_LN_S" = "ln -s"; then : ; else LN_S=cp ; fi
2030 dnl **** Check for gcc strength-reduce bug ****
2032 if test "x${GCC}" = "xyes"
2034 AC_CACHE_CHECK( "for gcc strength-reduce bug", ac_cv_c_gcc_strength_bug,
2037 static int Array[[3]];
2040 for(i=0; i<B; i++) Array[[i]] = i - 3;
2041 exit( Array[[1]] != -2 );
2043 ac_cv_c_gcc_strength_bug="no",
2044 ac_cv_c_gcc_strength_bug="yes",
2045 ac_cv_c_gcc_strength_bug="yes") )
2046 if test "$ac_cv_c_gcc_strength_bug" = "yes"
2048 CFLAGS="$CFLAGS -fno-strength-reduce"
2052 dnl **** Check for underscore on external symbols ****
2054 AC_CACHE_CHECK("whether external symbols need an underscore prefix",
2055 ac_cv_c_extern_prefix,
2057 LIBS="conftest_asm.s $LIBS"
2058 cat > conftest_asm.s <<EOF
2063 AC_TRY_LINK([extern int ac_test;],[if (ac_test) return 1],
2064 ac_cv_c_extern_prefix="yes",ac_cv_c_extern_prefix="no")
2066 if test "$ac_cv_c_extern_prefix" = "yes"
2068 AC_DEFINE(NEED_UNDERSCORE_PREFIX)
2071 dnl **** Check for working dll ****
2074 AC_CACHE_CHECK("whether we can build a Linux dll",
2076 [saved_cflags=$CFLAGS
2077 CFLAGS="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0"
2078 AC_TRY_LINK(,[return 1],ac_cv_c_dll_linux="yes",ac_cv_c_dll_linux="no")
2079 CFLAGS=$saved_cflags
2081 if test "$ac_cv_c_dll_linux" = "yes"
2083 LDSHARED="\$(CC) -shared -Wl,-soname,\$(SONAME),-rpath,\$(libdir)"
2085 AC_CACHE_CHECK(whether we can build a UnixWare (Solaris) dll,
2086 ac_cv_c_dll_unixware,
2087 [saved_cflags=$CFLAGS
2088 CFLAGS="$CFLAGS -fPIC -Wl,-G,-h,conftest.so.1.0"
2089 AC_TRY_LINK(,[return 1],ac_cv_c_dll_unixware="yes",ac_cv_c_dll_unixware="no")
2090 CFLAGS=$saved_cflags
2092 if test "$ac_cv_c_dll_unixware" = "yes"
2094 LDSHARED="\$(CC) -Wl,-G,-h,\$(libdir)/\$(SONAME)"
2096 AC_CACHE_CHECK("whether we can build a NetBSD dll",
2098 [saved_cflags=$CFLAGS
2099 CFLAGS="$CFLAGS -fPIC -Bshareable -Bforcearchive"
2100 AC_TRY_LINK(,[return 1],ac_cv_c_dll_netbsd="yes",ac_cv_c_dll_netbsd="no")
2101 CFLAGS=$saved_cflags
2103 if test "$ac_cv_c_dll_netbsd" = "yes"
2105 LDSHARED="ld -Bshareable -Bforcearchive"
2109 if test "$ac_cv_c_dll_linux" = "no" -a "$ac_cv_c_dll_unixware" = "no" -a "$ac_cv_c_dll_netbsd" = "no"
2111 AC_MSG_ERROR([Could not find how to build a dynamically linked library])
2115 DLL_LINK="\$(WINELIB_LIBRARY_PATH) \$(DLLS:%=-l%) \$(IMPORTS:%=-l%) -lwine -lwine_unicode"
2121 dnl *** check for the need to define __i386__
2123 AC_CACHE_CHECK("whether we need to define __i386__",ac_cv_cpp_def_i386,
2124 AC_EGREP_CPP(yes,[#if (defined(i386) || defined(__i386)) && !defined(__i386__)
2127 ac_cv_cpp_def_i386="yes", ac_cv_cpp_def_i386="no"))
2128 if test "$ac_cv_cpp_def_i386" = "yes"
2130 CFLAGS="$CFLAGS -D__i386__"
2133 dnl $GCC is set by autoconf
2135 if test "$GCC" = "yes"
2137 GCC_NO_BUILTIN="-fno-builtin"
2139 AC_SUBST(GCC_NO_BUILTIN)
2141 dnl **** Test Winelib-related features of the C++ compiler
2143 if test "x${GCC}" = "xyes"
2145 OLDCXXFLAGS="$CXXFLAGS";
2146 CXXFLAGS="-fpermissive";
2147 AC_CACHE_CHECK("for g++ -fpermissive option", has_gxx_permissive,
2149 for (int i=0;i<2;i++);
2152 [has_gxx_permissive="yes"],
2153 [has_gxx_permissive="no"])
2155 CXXFLAGS="-fno-for-scope";
2156 AC_CACHE_CHECK("for g++ -fno-for-scope option", has_gxx_no_for_scope,
2158 for (int i=0;i<2;i++);
2161 [has_gxx_no_for_scope="yes"],
2162 [has_gxx_no_for_scope="no"])
2164 CXXFLAGS="$OLDCXXFLAGS";
2165 if test "$has_gxx_permissive" = "yes"
2167 CXXFLAGS="$CXXFLAGS -fpermissive"
2169 if test "$has_gxx_no_for_scope" = "yes"
2171 CXXFLAGS="$CXXFLAGS -fno-for-scope"
2175 dnl **** Test Winelib-related features of the C compiler
2178 dnl **** Try to find where winelib is located ****
2180 dnl This section is implemented using custom code since autoconf does not
2181 dnl provide a standard method. Here is how other people have tried to
2182 dnl solve the same (or similar) problem.
2183 dnl See: http://www.geocrawler.com/archives/3/402/1999/4/50/2131449/
2184 dnl or http://www.geocrawler.com/archives/3/402/1999/4/50/2131443/
2185 dnl ftp://ftp.slac.stanford.edu/users/langston/autoconf/smr_macros-0.09.tar.gz
2186 dnl or http://www.geocrawler.com/archives/3/402/1999/4/50/2131452/
2187 dnl or http://www.geocrawler.com/archives/3/402/1999/4/50/2131446/
2189 WINELIB_INCLUDE_ROOT="";
2190 WINELIB_INCLUDE_PATH="";
2191 WINELIB_LIBRARY_ROOT="";
2192 WINELIB_LIBRARY_PATH="";
2193 WINELIB_TOOL_PATH="";
2197 AC_ARG_WITH(winelib-root,
2198 [ --with-winelib-root=DIR take the Winelib includes, libraries and tools from this directory],
2199 [if test "$withval" != "no"; then
2200 WINELIB_ROOT="$withval";
2201 WINELIB_INCLUDES="";
2202 WINELIB_LIBRARIES="";
2207 if test -n "$WINELIB_ROOT"
2209 WINELIB_INCLUDE_ROOT="$WINELIB_ROOT/include";
2210 WINELIB_LIBRARY_ROOT="$WINELIB_ROOT";
2211 WINELIB_TOOL_PATH="$WINELIB_ROOT:$WINELIB_ROOT/bin:$WINELIB_ROOT/tools/wrc:$WINELIB_ROOT/tools/winebuild:$PATH";
2214 AC_ARG_WITH(winelib-includes,
2215 [ --with-winelib-includes=DIR take the Winelib includes from this directory],
2216 [if test "$withval" != "no"; then
2217 WINELIB_INCLUDES="$withval";
2219 WINELIB_INCLUDES="";
2221 if test -n "$WINELIB_INCLUDES"
2223 WINELIB_INCLUDE_ROOT="$WINELIB_INCLUDES";
2226 AC_ARG_WITH(winelib-libraries,
2227 [ --with-winelib-libraries=DIR take the Winelib libraries from this directory],
2228 [if test "$withval" != "no"; then
2229 WINELIB_LIBRARIES="$withval";
2231 WINELIB_LIBRARIES="";
2233 if test -n "$WINELIB_LIBRARIES"
2235 WINELIB_LIBRARY_ROOT="$WINELIB_LIBRARIES";
2238 AC_ARG_WITH(winelib-tools,
2239 [ --with-winelib-tools=DIR take the Winelib tools from this directory],
2240 [if test "$withval" != "no"; then
2241 WINELIB_TOOLS="$withval";
2245 if test -n "$WINELIB_TOOLS"
2247 WINELIB_TOOL_PATH="$WINELIB_TOOLS:$WINELIB_TOOLS/wrc:$WINELIB_TOOLS/winebuild";
2250 if test -z "$WINELIB_INCLUDE_ROOT"
2252 WINELIB_INCLUDE_ROOT="/usr/include/wine";
2254 if test ! -f "$WINELIB_INCLUDE_ROOT/windows.h"
2256 AC_MSG_ERROR([Could not find the Winelib includes])
2258 WINELIB_INCLUDE_PATH="-I$WINELIB_INCLUDE_ROOT"
2260 if test -z "$WINELIB_LIBRARY_ROOT"
2262 WINELIB_LIBRARY_ROOT="/usr/lib/wine";
2264 if test ! -f "$WINELIB_LIBRARY_ROOT/libwine.so"
2266 if test -f "$WINELIB_LIBRARY_ROOT/lib/libwine.so"
2268 WINELIB_LIBRARY_ROOT="$WINELIB_LIBRARY_ROOT/lib";
2270 AC_MSG_ERROR([Could not find the Winelib libraries (libwine)])
2273 if test -f "$WINELIB_LIBRARY_ROOT/libkernel32.so"
2275 WINELIB_LIBRARY_PATH="-L$WINELIB_LIBRARY_ROOT";
2277 if test -f "$WINELIB_LIBRARY_ROOT/dlls/libkernel32.so"
2279 WINELIB_LIBRARY_PATH="-L$WINELIB_LIBRARY_ROOT -L$WINELIB_LIBRARY_ROOT/dlls";
2281 AC_MSG_ERROR([Could not find the Winelib libraries (libkernel32)])
2285 AC_PATH_PROG(WINEBUILD,winebuild,,$WINELIB_TOOL_PATH)
2286 if test -z "$WINEBUILD"
2288 AC_MSG_ERROR([Could not find Winelib's winebuild tool])
2290 AC_PATH_PROG(WRC,wrc,,$WINELIB_TOOL_PATH)
2293 AC_MSG_ERROR([Could not find Winelib's wrc tool])
2296 AC_SUBST(WINELIB_INCLUDE_ROOT)
2297 AC_SUBST(WINELIB_INCLUDE_PATH)
2298 AC_SUBST(WINELIB_LIBRARY_ROOT)
2299 AC_SUBST(WINELIB_LIBRARY_PATH)
2301 dnl **** Try to find where the MFC are located ****
2303 if test "x$NEEDS_MFC" = "x1"
2305 ATL_INCLUDE_ROOT="";
2306 ATL_INCLUDE_PATH="";
2307 MFC_INCLUDE_ROOT="";
2308 MFC_INCLUDE_PATH="";
2309 MFC_LIBRARY_ROOT="";
2310 MFC_LIBRARY_PATH="";
2312 AC_ARG_WITH(mfc-root,
2313 [ --with-mfc-root=DIR take the MFC includes and libraries from this directory],
2314 [if test "$withval" != "no"; then
2315 MFC_ROOT="$withval";
2322 if test -n "$MFC_ROOT"
2324 ATL_INCLUDE_ROOT="$MFC_ROOT";
2325 MFC_INCLUDE_ROOT="$MFC_ROOT";
2326 MFC_LIBRARY_ROOT="$MFC_ROOT";
2329 AC_ARG_WITH(atl-includes,
2330 [ --with-atl-includes=DIR take the ATL includes from this directory],
2331 [if test "$withval" != "no"; then
2332 ATL_INCLUDES="$withval";
2336 if test -n "$ATL_INCLUDES"
2338 ATL_INCLUDE_ROOT="$ATL_INCLUDES";
2341 AC_ARG_WITH(mfc-includes,
2342 [ --with-mfc-includes=DIR take the MFC includes from this directory],
2343 [if test "$withval" != "no"; then
2344 MFC_INCLUDES="$withval";
2348 if test -n "$MFC_INCLUDES"
2350 MFC_INCLUDE_ROOT="$MFC_INCLUDES";
2353 AC_ARG_WITH(mfc-libraries,
2354 [ --with-mfc-libraries=DIR take the MFC libraries from this directory],
2355 [if test "$withval" != "no"; then
2356 MFC_LIBRARIES="$withval";
2360 if test -n "$MFC_LIBRARIES"
2362 MFC_LIBRARY_ROOT="$MFC_LIBRARIES";
2365 dnl FIXME: We should have an include path and just iterate through it.
2366 dnl These tests become ugly.
2367 if test -z "$ATL_INCLUDE_ROOT"
2369 ATL_INCLUDE_ROOT="/usr/include";
2371 if test ! -f "$ATL_INCLUDE_ROOT/atlbase.h"
2373 if test -f "$ATL_INCLUDE_ROOT/atl/atlbase.h"
2375 ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT/atl"
2377 if test -f "$ATL_INCLUDE_ROOT/atl/include/atlbase.h"
2379 ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT/atl/include"
2381 AC_MSG_ERROR([Could not find the ATL includes])
2385 ATL_INCLUDE_PATH="-I$ATL_INCLUDE_ROOT"
2387 if test -z "$MFC_INCLUDE_ROOT"
2389 MFC_INCLUDE_ROOT="/usr/include";
2391 if test ! -f "$MFC_INCLUDE_ROOT/afx.h"
2393 if test -f "$MFC_INCLUDE_ROOT/mfc/afx.h"
2395 MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT/mfc"
2397 if test -f "$MFC_INCLUDE_ROOT/mfc/include/afx.h"
2399 MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT/mfc/include"
2401 AC_MSG_ERROR([Could not find the MFC includes])
2405 MFC_INCLUDE_PATH="-D_DLL -D_MT -I$ATL_INCLUDE_ROOT -I$MFC_INCLUDE_ROOT -I\$(WINELIB_INCLUDE_ROOT)/mixedcrt"
2407 if test -z "$MFC_LIBRARY_ROOT"
2409 MFC_LIBRARY_ROOT="/usr/lib/mfc";
2411 if test -f "$MFC_LIBRARY_ROOT/libmfc.so"
2413 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT";
2415 if test -f "$MFC_LIBRARY_ROOT/lib/libmfc.so"
2417 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT/lib";
2419 if test -f "$MFC_LIBRARY_ROOT/mfc/src/libmfc.so"
2421 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT/mfc/src";
2423 AC_MSG_ERROR([Could not find the MFC library (libmfc)])
2427 MFC_LIBRARY_PATH="-L$MFC_LIBRARY_ROOT"
2429 AC_SUBST(ATL_INCLUDE_ROOT)
2430 AC_SUBST(ATL_INCLUDE_PATH)
2431 AC_SUBST(MFC_INCLUDE_ROOT)
2432 AC_SUBST(MFC_INCLUDE_PATH)
2433 AC_SUBST(MFC_LIBRARY_ROOT)
2434 AC_SUBST(MFC_LIBRARY_PATH)
2437 dnl **** Generate output files ****
2439 MAKE_RULES=Make.rules
2440 AC_SUBST_FILE(MAKE_RULES)
2444 ##WINEMAKER_PROJECTS##
2448 echo "Configure finished. Do 'make' to build the project."
2451 dnl Local Variables:
2452 dnl comment-start: "dnl "
2454 dnl comment-start-skip: "\\bdnl\\b\\s *"
2455 dnl compile-command: "autoconf"
2457 --- Make.rules.in ---
2458 # Copyright 2000 Francois Gouget for CodeWeavers
2459 # fgouget@codeweavers.com
2461 # Global rules shared by all makefiles -*-Makefile-*-
2463 # Each individual makefile must define the following variables:
2464 # WINELIB_INCLUDE_ROOT: Winelib includes location
2465 # WINELIB_LIBRARY_ROOT: Winelib libraries location
2466 # TOPOBJDIR : top-level object directory
2467 # SRCDIR : source directory for this module
2469 # Each individual makefile may define the following additional variables:
2471 # SUBDIRS : subdirectories that contain a Makefile
2472 # LIBRARIES : libraries to be built
2473 # PROGRAMS : programs to be built
2475 # CEXTRA : extra c flags (e.g. '-Wall')
2476 # CXXEXTRA : extra c++ flags (e.g. '-Wall')
2477 # WRCEXTRA : extra wrc flags (e.g. '-p _SysRes')
2478 # DEFINES : defines (e.g. -DSTRICT)
2479 # INCLUDE_PATH : additional include path
2480 # LIBRARY_PATH : additional library path
2481 # IMPORTS : additional libraries to link with
2483 # C_SRCS : C sources for the module
2484 # CXX_SRCS : C++ sources for the module
2485 # RC_SRCS : resource source files
2486 # SPEC_SRCS : interface definition files
2491 WINELIB_INCLUDE_ROOT = @WINELIB_INCLUDE_ROOT@
2492 WINELIB_INCLUDE_PATH = @WINELIB_INCLUDE_PATH@
2493 WINELIB_LIBRARY_ROOT = @WINELIB_LIBRARY_ROOT@
2494 WINELIB_LIBRARY_PATH = @WINELIB_LIBRARY_PATH@
2498 ATL_INCLUDE_ROOT = @ATL_INCLUDE_ROOT@
2499 ATL_INCLUDE_PATH = @ATL_INCLUDE_PATH@
2500 MFC_INCLUDE_ROOT = @MFC_INCLUDE_ROOT@
2501 MFC_INCLUDE_PATH = @MFC_INCLUDE_PATH@
2502 MFC_LIBRARY_ROOT = @MFC_LIBRARY_ROOT@
2503 MFC_LIBRARY_PATH = @MFC_LIBRARY_PATH@
2505 # First some useful definitions
2511 CXXFLAGS = @CXXFLAGS@
2512 OPTIONS = @OPTIONS@ -D_REENTRANT -DWINELIB
2513 X_CFLAGS = @X_CFLAGS@
2515 XLIB = @X_PRE_LIBS@ @XLIB@ @X_EXTRA_LIBS@
2516 DLL_LINK = @DLL_LINK@
2517 LIBS = @LIBS@ $(LIBRARY_PATH)
2522 DIVINCL = -I$(SRCDIR) $(WINELIB_INCLUDE_PATH) $(INCLUDE_PATH)
2523 ALLCFLAGS = $(DIVINCL) $(CFLAGS) $(CEXTRA) $(OPTIONS) $(X_CFLAGS) $(DEFINES)
2524 ALLCXXFLAGS = $(DIVINCL) $(CXXFLAGS) $(CXXEXTRA) $(OPTIONS) $(X_CFLAGS) $(DEFINES)
2526 LDSHARED = @LDSHARED@
2530 WINEBUILD = @WINEBUILD@
2535 # Installation infos
2538 INSTALL_PROGRAM = @INSTALL_PROGRAM@
2539 INSTALL_DATA = @INSTALL_DATA@
2541 exec_prefix = @exec_prefix@
2548 CLEAN_FILES = *.o *.a *.so \\\#*\\\# *~ *% .\\\#* *.orig *.rej \
2549 *.spec.c y.tab.c y.tab.h lex.yy.c core
2551 OBJS = $(SPEC_SRCS:.spec=.spec.o) $(C_SRCS:.c=.o) $(CXX_SRCS:.cpp=.o)
2621 .SUFFIXES: .C .cpp .CPP .cxx .CXX .rc .RC .res .spec .spec.c .spec.o
2624 $(CC) -c $(ALLCFLAGS) -o $@ $<
2627 $(CC) -c $(ALLCFLAGS) -o $@ $<
2630 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2633 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2636 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2639 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2642 $(WINEBUILD) @DLLFLAGS@ -o $@ -spec $<
2645 $(CC) -c $(ALLCFLAGS) @GCC_NO_BUILTIN@ -o $@ $<
2648 $(WRC) $(WRCFLAGS) $(WRCEXTRA) $(DIVINCL) -o $@ $<
2651 $(WRC) $(WRCFLAGS) $(WRCEXTRA) $(DIVINCL) -o $@ $<
2653 .PHONY: all install uninstall clean distclean depend dummy
2655 # 'all' target first in case the enclosing Makefile didn't define any target
2659 # Rules for makefile
2661 Makefile: Makefile.in $(TOPSRCDIR)/configure
2662 @echo Makefile is older than $?, please rerun $(TOPSRCDIR)/configure
2665 # Rules for cleaning
2667 $(SUBDIRS:%=%/__clean__): dummy
2668 cd `dirname $@` && $(MAKE) clean
2670 $(EXTRASUBDIRS:%=%/__clean__): dummy
2671 -cd `dirname $@` && $(RM) $(CLEAN_FILES)
2673 clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
2674 $(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(LIBRARIES) $(PROGRAMS)
2676 # Rules for installing
2678 $(SUBDIRS:%=%/__install__): dummy
2679 cd `dirname $@` && $(MAKE) install
2681 $(SUBDIRS:%=%/__uninstall__): dummy
2682 cd `dirname $@` && $(MAKE) uninstall
2691 # End of global rules
2694 * Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2698 #include <windows.h>
2703 * Describe the wrapped application
2707 * This is either CUIEXE for a console based application or
2708 * GUIEXE for a regular windows application.
2710 #define APP_TYPE ##WINEMAKER_APP_TYPE##
2713 * This is the application library's base name, i.e. 'hello' if the
2714 * library is called 'libhello.so'.
2716 static char* appName = ##WINEMAKER_APP_NAME##;
2719 * This is the name of the application's Windows module. If left NULL
2720 * then appName is used.
2722 static char* appModule = NULL;
2725 * This is the application's entry point. This is usually "WinMain" for a
2726 * GUIEXE and 'main' for a CUIEXE application.
2728 static char* appInit = ##WINEMAKER_APP_INIT##;
2731 * This is either non-NULL for MFC-based applications and is the name of the
2732 * MFC's module. This is the module in which we will take the 'WinMain'
2735 static char* mfcModule = ##WINEMAKER_APP_MFC##;
2740 * Implement the main.
2743 #if APP_TYPE == GUIEXE
2744 typedef int WINAPI (*WinMainFunc)(HINSTANCE hInstance, HINSTANCE hPrevInstance,
2745 PSTR szCmdLine, int iCmdShow);
2747 typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp);
2750 #if APP_TYPE == GUIEXE
2751 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
2752 PSTR szCmdLine, int iCmdShow)
2754 int WINAPI Main(int argc, char** argv, char** envp)
2758 HINSTANCE hApp,hMFC,hMain;
2763 /* Load the application's library */
2764 libName=(char*)malloc(strlen(appName)+5+3+1);
2765 /* FIXME: we should get the wrapper's path and use that as the base for
2768 sprintf(libName,"./lib%s.so",appName);
2769 appLibrary=dlopen(libName,RTLD_NOW);
2770 if (appLibrary==NULL) {
2771 sprintf(libName,"lib%s.so",appName);
2772 appLibrary=dlopen(libName,RTLD_NOW);
2774 if (appLibrary==NULL) {
2775 char format[]="Could not load the %s library:\r\n%s";
2780 msg=(char*)malloc(strlen(format)+strlen(libName)+strlen(error));
2781 sprintf(msg,format,libName,error);
2782 MessageBox(NULL,msg,"dlopen error",MB_OK);
2787 /* Then if this application is MFC based, load the MFC module */
2788 /* FIXME: I'm not sure this is really necessary */
2789 if (mfcModule!=NULL) {
2790 hMFC=LoadLibrary(mfcModule);
2792 char format[]="Could not load the MFC module %s (%d)";
2795 msg=(char*)malloc(strlen(format)+strlen(mfcModule)+11);
2796 sprintf(msg,format,mfcModule,GetLastError());
2797 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
2801 /* MFC is a special case: the WinMain is in the MFC library,
2802 * instead of the application's library.
2809 /* Load the application's module */
2810 if (appModule==NULL) {
2813 hApp=LoadLibrary(appModule);
2815 char format[]="Could not load the application's module %s (%d)";
2818 msg=(char*)malloc(strlen(format)+strlen(appModule)+11);
2819 sprintf(msg,format,appModule,GetLastError());
2820 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
2823 } else if (hMain==NULL) {
2827 /* Get the address of the application's entry point */
2828 appMain=(WinMainFunc*)GetProcAddress(hMain, appInit);
2829 if (appMain==NULL) {
2830 char format[]="Could not get the address of %s (%d)";
2833 msg=(char*)malloc(strlen(format)+strlen(appInit)+11);
2834 sprintf(msg,format,appInit,GetLastError());
2835 MessageBox(NULL,msg,"GetProcAddress error",MB_OK);
2840 /* And finally invoke the application's entry point */
2841 #if APP_TYPE == GUIEXE
2842 retcode=(*((WinMainFunc)appMain))(hApp,hPrevInstance,szCmdLine,iCmdShow);
2844 retcode=(*((MainFunc)appMain))(argc,argv,envp);
2847 /* Cleanup and done */
2852 dlclose(appLibrary);