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);
653 print "project_settings: defines=@{@$project_settings[$T_DEFINES]}\n";
654 print "project_settings: includes=@{@$project_settings[$T_INCLUDE_PATH]}\n";
658 # - Create the targets
659 # - Check if we have both libraries and programs
660 # - Match each target with source files (sort in reverse
661 # alphabetical order to get the longest matches first)
662 my @local_imports=();
663 my @local_depends=();
665 foreach $target_name (sort { $b cmp $a } keys %targets) {
666 # Create the target...
669 target_init($target);
670 @$target[$T_NAME]=$target_name;
671 if ($target_name =~ /^lib(.*)\.so$/) {
672 @$target[$T_TYPE]=$TT_DLL;
673 @$target[$T_INIT]=get_default_init($TT_DLL);
674 @$target[$T_FLAGS]&=~$TF_WRAP;
676 push @local_depends,$target_name;
677 push @local_imports,$basename;
679 @$target[$T_TYPE]=$opt_target_type;
680 @$target[$T_INIT]=get_default_init($opt_target_type);
681 $basename=$target_name;
682 push @program_list,$target;
684 push @{@$project[$P_TARGETS]},$target;
686 # Ask for target-specific options
687 if ($opt_ask_target_options == $OPT_ASK_YES) {
688 print "Specify any link option (-L/-l) specific to the target \"$target_name\"\n";
689 print " or 'never' to not be asked this question again:\n";
692 if ($options eq "never") {
693 $opt_ask_target_options=$OPT_ASK_NO;
695 source_set_options($target,$options);
698 if (@$target[$T_FLAGS] & $TF_MFC) {
699 @$project_settings[$T_FLAGS]|=$TF_MFC;
700 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
701 push @{@$target[$T_IMPORTS]},"mfc";
705 if ($target_count == 1) {
706 push @{@$target[$T_SOURCES_C]},@sources_c;
707 push @{@$target[$T_SOURCES_CXX]},@sources_cxx;
708 push @{@$target[$T_SOURCES_RC]},@sources_rc;
709 push @{@$target[$T_SOURCES_MISC]},@sources_misc;
715 foreach $source (@sources_c) {
716 if ($source =~ /^$basename/i) {
717 push @{@$target[$T_SOURCES_C]},$source;
721 foreach $source (@sources_cxx) {
722 if ($source =~ /^$basename/i) {
723 push @{@$target[$T_SOURCES_CXX]},$source;
727 foreach $source (@sources_rc) {
728 if ($source =~ /^$basename/i) {
729 push @{@$target[$T_SOURCES_RC]},$source;
733 foreach $source (@sources_misc) {
734 if ($source =~ /^$basename/i) {
735 push @{@$target[$T_SOURCES_MISC]},$source;
740 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
741 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
742 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
743 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
745 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
746 $opt_ask_target_options=$OPT_ASK_YES;
749 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
750 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
752 # The sources that did not match, if any, go to the extra
753 # source list of the project settings
754 foreach $source (@sources_c) {
756 push @{@$project_settings[$T_SOURCES_C]},$source;
759 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
760 foreach $source (@sources_cxx) {
762 push @{@$project_settings[$T_SOURCES_CXX]},$source;
765 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
766 foreach $source (@sources_rc) {
768 push @{@$project_settings[$T_SOURCES_RC]},$source;
771 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
772 foreach $source (@sources_misc) {
774 push @{@$project_settings[$T_SOURCES_MISC]},$source;
777 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
779 # Finally if we are building both libraries and programs in
780 # this directory, then the programs should be linked with all
782 if (@local_imports > 0 and @program_list > 0) {
783 foreach $target (@program_list) {
784 push @{@$target[$T_LIBRARY_PATH]},".";
785 push @{@$target[$T_IMPORTS]},@local_imports;
786 push @{@$target[$T_DEPENDS]},@local_depends;
792 # Scan the source directories in search of things to build
795 my $main_target=@{$main_project[$P_TARGETS]}[0];
797 # If there's a single target then this is going to be the default target
798 if (defined $opt_single_target) {
799 if ($opt_target_type == $TT_DLL) {
800 @$main_target[$T_NAME]="lib$opt_single_target.so";
802 @$main_target[$T_NAME]="$opt_single_target";
804 @$main_target[$T_TYPE]=$opt_target_type;
807 # The main directory is always going to be there
808 push @projects,\@main_project;
810 # Now scan the directory tree looking for source files and, maybe, targets
811 print "Scanning the source directories...\n";
812 source_scan_directory(\@main_project,"","");
814 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
821 # 'vc.dsp'-based Project analysis
834 # Creating the wrapper targets
840 foreach $project (@projects) {
841 foreach $target (@{@$project[$P_TARGETS]}) {
842 if ((@$target[$T_FLAGS] & $TF_WRAP) != 0) {
844 target_init($wrapper);
845 @$wrapper[$T_NAME]=@$target[$T_NAME];
846 @$wrapper[$T_TYPE]=@$target[$T_TYPE];
847 @$wrapper[$T_INIT]=get_default_init(@$target[$T_TYPE]);
848 @$wrapper[$T_FLAGS]=$TF_WRAPPER | (@$target[$T_FLAGS] & $TF_MFC);
849 push @{@$wrapper[$T_SOURCES_C]},"@$wrapper[$T_NAME]_wrapper.c";
851 my $index=bsearch(@$target[$T_SOURCES_C],"@$wrapper[$T_NAME]_wrapper.c");
852 if (defined $index) {
853 splice(@{@$target[$T_SOURCES_C]},$index,1);
855 @$target[$T_NAME]="lib@$target[$T_NAME].so";
856 @$target[$T_TYPE]=$TT_DLL;
858 push @{@$project[$P_TARGETS]},$wrapper;
873 # Performs a directory traversal and renames the files so that:
874 # - they have the case desired by the user
875 # - their extension is of the appropriate case
876 # - they don't contain annoying characters like ' ', '$', '#', ...
877 sub fix_file_and_directory_names
881 if (opendir(DIRECTORY, "$dirname")) {
882 foreach $dentry (readdir DIRECTORY) {
883 if ($dentry =~ /^\./ or $dentry eq "CVS") {
886 # Set $warn to 1 if the user should be warned of the renaming
889 # autoconf and make don't support these characters well
890 my $new_name=$dentry;
891 $new_name =~ s/[ \$]/_/g;
893 # Our Make.rules supports all-uppercase and all-lowercase extensions.
894 # The others must be fixed.
895 if (-f "$dirname/$new_name") {
896 if ($new_name =~ /\.cpp/i and $new_name !~ /\.(cpp|CPP)/) {
897 $new_name =~ s/\.cpp$/.cpp/i;
899 if ($new_name =~ s/\.cxx$/.cpp/i) {
902 if ($new_name =~ /\.rc/i and $new_name !~ /\.(rc|RC)/) {
903 $new_name =~ s/\.rc$/.rc/i;
905 # And this last one is to avoid confusion then running make
906 if ($new_name =~ s/^makefile$/makefile.win/) {
911 # Adjust the case to the user's preferences
912 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
913 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
915 $new_name=lc $new_name;
918 # And finally, perform the renaming
919 if ($new_name ne $dentry) {
921 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
923 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
924 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
925 print STDERR " $!\n";
929 if (-d "$dirname/$new_name") {
930 fix_file_and_directory_names("$dirname/$new_name");
946 # This maps a directory name to a reference to an array listing
947 # its contents (files and directories)
951 # Retrieves the contents of the specified directory.
952 # We either get it from the directories hashtable which acts as a
953 # cache, or use opendir, readdir, closedir and store the result
955 sub get_directory_contents
960 #print "getting the contents of $dirname\n";
962 # check for a cached version
964 if ($dirname eq "") {
967 $directory=$directories{$dirname};
968 if (defined $directory) {
969 #print "->@$directory\n";
973 # Read this directory
974 if (opendir(DIRECTORY, "$dirname")) {
975 my @files=readdir DIRECTORY;
979 # Return an empty list
980 #print "error: cannot open $dirname\n";
984 #print "->@$directory\n";
985 $directories{$dirname}=$directory;
990 # Try to find a file for the specified filename. The attempt is
991 # case-insensitive which is why it's not trivial. If a match is
992 # found then we return the pathname with the correct case.
999 if ($dirname eq "" or $dirname eq ".") {
1001 } elsif ($dirname =~ m+^[^/]+) {
1002 $dirname=cwd . "/" . $dirname;
1004 if ($dirname !~ m+/$+) {
1008 foreach $component (@$path) {
1009 #print " looking for $component in \"$dirname\"\n";
1010 if ($component eq ".") {
1013 } elsif ($component eq "..") {
1015 $dirname=dirname($dirname) . "/";
1018 my $directory=get_directory_contents $dirname;
1020 foreach $dentry (@$directory) {
1021 if ($dentry =~ /^$component$/i) {
1022 $dirname.="$dentry/";
1023 $real_path.="$dentry/";
1028 if (!defined $found) {
1030 #print " could not find $component in $dirname\n";
1035 $real_path=~ s+/$++;
1036 #print " ->found $real_path\n";
1041 # Performs a case-insensitive search for the specified file in the
1043 # $line is the line number that should be referenced when an error occurs
1044 # $filename is the file we are looking for
1045 # $dirname is the directory of the file containing the '#include' directive
1046 # if '"' was used, it is an empty string otherwise
1047 # $project and $target specify part of the include path
1048 sub get_real_include_name
1056 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1057 # This is not a relative path, we cannot make any check
1058 my $warning="path:$filename";
1059 if (!defined $warnings{$warning}) {
1060 $warnings{$warning}="1";
1061 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1062 print STDERR "$line: $filename\n";
1065 # Here's how we proceed:
1066 # - split the filename we look for into its components
1067 # - then for each directory in the include path
1068 # - trace the directory components starting from that directory
1069 # - if we fail to find a match at any point then continue with
1070 # the next directory in the include path
1071 # - otherwise, rejoice, our quest is over.
1072 my @file_components=split /[\/\\]+/, $filename;
1073 #print "Searching for $filename from @$project[$P_PATH]\n";
1076 if ($dirname ne "") {
1077 #print " in $dirname (include \"\")\n";
1078 $real_filename=search_from($dirname,\@file_components);
1079 if (defined $real_filename) {
1080 return $real_filename;
1083 my $project_settings=@$project[$P_SETTINGS];
1084 foreach $dirname (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1085 #print " in $dirname\n";
1086 $real_filename=search_from("$dirname",\@file_components);
1087 if (defined $real_filename) {
1088 return $real_filename;
1091 my $dotdotpath=@$project[$P_PATH];
1092 $dotdotpath =~ s/[^\/]+/../g;
1093 foreach $dirname (@{$global_settings[$T_INCLUDE_PATH]}) {
1095 if (!is_absolute($dirname)) {
1096 $ipath="$dotdotpath$dirname";
1100 #print " in $ipath (global setting)\n";
1101 $real_filename=search_from("$dirname",\@file_components);
1102 if (defined $real_filename) {
1103 return $real_filename;
1107 $filename =~ s+\\\\+/+g; # in include ""
1108 $filename =~ s+\\+/+g; # in include <> !
1109 if ($filename =~ /^[A-Z_.\/\\]*$/) {
1110 #FIXME: should this depend on --lower-uppercase & co???
1111 return lc "$filename";
1117 # 'Parses' a source file and fixes constructs that would not work with
1118 # Winelib. The parsing is rather simple and not all non-portable features
1119 # are corrected. The most important feature that is corrected is the case
1120 # and path separator of '#include' directives. This requires that each
1121 # source file be associated to a project & target so that the proper
1122 # include path is used.
1128 $filename="@$project[$P_PATH]$filename";
1129 if (! -e $filename) {
1133 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1134 my $dirname=dirname($filename);
1136 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1140 print " $filename\n";
1141 #FIXME:assuming that because there is a .bak file, this is what we want is
1142 #probably flawed. Or is it???
1143 if (! -e "$filename.bak") {
1144 if (!copy("$filename","$filename.bak")) {
1145 print STDERR "error: unable to make a backup of $filename:\n";
1146 print STDERR " $!\n";
1150 if (!open(FILEI,"$filename.bak")) {
1151 print STDERR "error: unable to open $filename.bak for reading:\n";
1152 print STDERR " $!\n";
1155 if (!open(FILEO,">$filename")) {
1156 print STDERR "error: unable to open $filename for writing:\n";
1157 print STDERR " $!\n";
1162 my $rc_block_depth=0;
1163 my $rc_textinclude_state=0;
1167 if ($is_rc and !$is_mfc and /^(\s*\#\s*include\s*)\"afxres\.h\"/) {
1168 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1169 # the RC files it generates (even in non-MFC projects). So we replace
1170 # it with 'winres.h' its very close standard cousin so that non MFC
1171 # projects can compile in Wine without the MFC sources. This does not
1172 # harm VC but it will put 'afxres.h' back the next time the file is
1174 my $warning="mfc:afxres.h";
1175 if (!defined $warnings{$warning}) {
1176 $warnings{$warning}="1";
1177 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winres.h'\n";
1178 print STDERR "warning: the above warning is issued only once\n";
1180 print FILEO "/* winemaker: $1\"afxres.h\" */\n";
1181 print FILEO "$1\"winres.h\"$'";
1183 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1184 my $from_file=($2 eq "<"?"":$dirname);
1185 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1186 print FILEO "$1$2$real_include_name$4$'";
1187 $modified|=($real_include_name ne $3);
1188 } elsif (/^(\s*\#\s*pragma\s*pack\s*\((\s*push\s*,?)?\s*)(\w*)(\s*\))/) {
1189 my $pragma_header=$1;
1191 my $pragma_trailer=$4;
1192 #print "$pragma_header$size$pragma_trailer$'";
1193 #print "pragma push: size=$size\n";
1194 print FILEO "/* winemaker: $pragma_header$size$pragma_trailer */\n";
1196 if ($size eq "pop") {
1197 print FILEO "#include <poppack.h>$'";
1198 } elsif ($size eq "1") {
1199 print FILEO "#include <pshpack1.h>$'";
1200 } elsif ($size eq "2") {
1201 print FILEO "#include <pshpack2.h>$'";
1202 } elsif ($size eq "8") {
1203 print FILEO "#include <pshpack8.h>$'";
1204 } elsif ($size eq "4" or $size eq "") {
1205 print FILEO "#include <pshpack4.h>$'";
1207 my $warning="pack:$size";
1208 if (!defined $warnings{$warning}) {
1209 $warnings{$warning}="1";
1210 print STDERR "warning: assuming that the value of $size is 4 in\n";
1211 print STDERR "$line: $pragma_header$size$pragma_trailer\n";
1212 print STDERR "warning: the above warning is issued only once\n";
1214 print FILEO "#include <pshpack4.h>$'";
1218 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]+)([\">]?)/) {
1219 my $from_file=($5 eq "<"?"":$dirname);
1220 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
1221 print FILEO "$1$5$real_include_name$7$'";
1222 $modified|=($real_include_name ne $6);
1223 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1224 my $from_file=($2 eq "<"?"":$dirname);
1225 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1226 print FILEO "$1$2$real_include_name$4$'";
1227 $modified|=($real_include_name ne $3);
1228 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
1229 $rc_textinclude_state=1;
1231 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
1232 print FILEO "$1winres.h$2$'";
1234 } elsif (/^\s*BEGIN(\W.*)?$/) {
1235 $rc_textinclude_state|=2;
1238 } elsif (/^\s*END(\W.*)?$/) {
1239 $rc_textinclude_state=0;
1240 if ($rc_block_depth>0) {
1253 if ($opt_backup == 0 or $modified == 0) {
1254 if (!unlink("$filename.bak")) {
1255 print STDERR "error: unable to delete $filename.bak:\n";
1256 print STDERR " $!\n";
1262 # Analyzes each source file in turn to find and correct issues
1263 # that would cause it not to compile.
1266 print "Fixing the source files...\n";
1267 foreach $project (@projects) {
1268 foreach $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
1269 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1272 foreach $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
1273 fix_file($source,$project,$target);
1288 # Generates a target's .spec file
1289 sub generate_spec_file
1293 my $project_settings=$_[2];
1295 my $basename=@$target[$T_NAME];
1296 $basename =~ s+\.so$++;
1297 if (@$target[$T_FLAGS] & $TF_WRAP) {
1298 $basename =~ s+^lib++;
1299 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1300 $basename.="_wrapper";
1303 if (!open(FILEO,">$path$basename.spec")) {
1304 print STDERR "error: could not open \"$path$basename.spec\" for writing\n";
1305 print STDERR " $!\n";
1309 my $canon=canonize($basename);
1310 print FILEO "name $canon\n";
1311 print FILEO "type win32\n";
1312 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1313 print FILEO "mode guiexe\n";
1314 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1315 print FILEO "mode cuiexe\n";
1317 print FILEO "mode dll\n";
1319 if (defined @$target[$T_INIT] and ((@$target[$T_FLAGS] & $TF_WRAP) == 0)) {
1320 print FILEO "init @$target[$T_INIT]\n";
1322 if (@{@$target[$T_SOURCES_RC]} > 0) {
1323 if (@{@$target[$T_SOURCES_RC]} > 1) {
1324 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";
1326 my $rcname=@{@$target[$T_SOURCES_RC]}[0];
1327 $rcname =~ s+\.rc$++i;
1328 print FILEO "rsrc $rcname.res\n";
1331 # FIXME: we should try to remove duplicates in the import list
1332 foreach $library (@{$global_settings[$T_IMPORTS]}) {
1333 print FILEO "import $library\n";
1335 if (defined $project_settings) {
1336 foreach $library (@{@$project_settings[$T_IMPORTS]}) {
1337 print FILEO "import $library\n";
1340 foreach $library (@{@$target[$T_IMPORTS]}) {
1341 print FILEO "import $library\n";
1344 # Don't forget to export the 'Main' function for wrapped executables,
1345 # except for MFC ones!
1346 if (@$target[$T_FLAGS] == $TF_WRAP) {
1347 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1348 print FILEO "\n@ stdcall @$target[$T_INIT](long long ptr long) @$target[$T_INIT]\n";
1349 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1350 print FILEO "\n@ stdcall @$target[$T_INIT](long ptr ptr) @$target[$T_INIT]\n";
1352 print FILEO "\n@ stdcall @$target[$T_INIT](ptr long ptr) @$target[$T_INIT]\n";
1360 # Generates a target's wrapper file
1361 sub generate_wrapper_file
1366 if (!defined $templates{"wrapper.c"}) {
1367 print STDERR "winemaker: internal error: No template called 'wrapper.c'\n";
1371 if (!open(FILEO,">$path@$target[$T_NAME]_wrapper.c")) {
1372 print STDERR "error: unable to open \"$path$basename.c\" for writing:\n";
1373 print STDERR " $!\n";
1376 my $app_name="\"@$target[$T_NAME]\"";
1377 my $app_type=(@$target[$T_TYPE]==$TT_GUIEXE?"GUIEXE":"CUIEXE");
1378 my $app_init=(@$target[$T_TYPE]==$TT_GUIEXE?"\"WinMain\"":"\"main\"");
1379 my $app_mfc=(@$target[$T_FLAGS] & $TF_MFC?"\"mfc\"":NULL);
1380 foreach $line (@{$templates{"wrapper.c"}}) {
1381 $line =~ s/\#\#WINEMAKER_APP_NAME\#\#/$app_name/;
1382 $line =~ s/\#\#WINEMAKER_APP_TYPE\#\#/$app_type/;
1383 $line =~ s/\#\#WINEMAKER_APP_INIT\#\#/$app_init/;
1384 $line =~ s/\#\#WINEMAKER_APP_MFC\#\#/$app_mfc/;
1391 # A convenience function to generate all the lists (defines,
1392 # C sources, C++ source, etc.) in the Makefile
1401 printf FILEO "%-9s =",$name;
1403 if (defined $list and @$list > 0) {
1404 foreach $item (@$list) {
1406 if (defined $data) {
1407 $value=&$data($item);
1412 print FILEO " \\\n\t$value";
1422 # Generates a project's Makefile.in and all the target files
1423 sub generate_project_files
1426 my $project_settings=@$project[$P_SETTINGS];
1427 my @library_list=();
1428 my @program_list=();
1430 # Then sort the targets and separate the libraries from the programs
1431 foreach $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
1432 if (@$target[$T_TYPE] == $TT_DLL) {
1433 push @library_list,$target;
1435 push @program_list,$target;
1438 @$project[$P_TARGETS]=[];
1439 push @{@$project[$P_TARGETS]}, @library_list;
1440 push @{@$project[$P_TARGETS]}, @program_list;
1442 if (!open(FILEO,">@$project[$P_PATH]Makefile.in")) {
1443 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile.in\" for writing\n";
1444 print STDERR " $!\n";
1448 print FILEO "### Generic autoconf variables\n\n";
1449 print FILEO "TOPSRCDIR = \@top_srcdir\@\n";
1450 print FILEO "TOPOBJDIR = .\n";
1451 print FILEO "SRCDIR = \@srcdir\@\n";
1452 print FILEO "VPATH = \@srcdir\@\n";
1454 if (@$project[$P_PATH] eq "") {
1455 # This is the main project. It is also responsible for recursively
1456 # calling the other projects
1457 generate_list("SUBDIRS",1,\@projects,sub
1459 if ($_[0] != \@main_project) {
1460 my $subdir=@{$_[0]}[$P_PATH];
1464 # Eliminating the main project by returning undefined!
1467 if (@{@$project[$P_TARGETS]} > 0) {
1468 generate_list("LIBRARIES",1,\@library_list,sub
1470 return @{$_[0]}[$T_NAME];
1472 generate_list("PROGRAMS",1,\@program_list,sub
1474 return @{$_[0]}[$T_NAME];
1478 print FILEO "### Global settings\n\n";
1479 # Make it so that the project-wide settings override the global settings
1480 generate_list("DEFINES",0,@$project_settings[$T_DEFINES],sub
1484 generate_list("",1,$global_settings[$T_DEFINES],sub
1488 generate_list("INCLUDE_PATH",$no_extra,@$project_settings[$T_INCLUDE_PATH],sub
1492 generate_list("",1,$global_settings[$T_INCLUDE_PATH],sub
1494 if ($_[0] !~ /^-I/) {
1497 if (is_absolute($')) {
1500 return "\$(TOPSRCDIR)/$_[0]";
1502 generate_list("LIBRARY_PATH",$no_extra,@$project_settings[$T_LIBRARY_PATH],sub
1506 generate_list("",1,$global_settings[$T_LIBRARY_PATH],sub
1508 if ($_[0] !~ /^-L/) {
1511 if (is_absolute($')) {
1514 return "\$(TOPSRCDIR)/$_[0]";
1516 generate_list("IMPORTS",$no_extra,@$project_settings[$T_IMPORTS],sub
1520 generate_list("",1,$global_settings[$T_IMPORTS],sub
1526 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
1527 @{@$project_settings[$T_SOURCES_CXX]}+
1528 @{@$project_settings[$T_SOURCES_RC]};
1529 my $no_extra=($extra_source_count == 0);
1531 print FILEO "### Extra source lists\n\n";
1532 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
1533 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
1534 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
1535 print FILEO "EXTRA_OBJS = \$(EXTRA_C_SRCS:.c=.o) \$(EXTRA_CXX_SRCS:.cpp=.o)\n";
1539 # Iterate over all the targets...
1540 foreach $target (@{@$project[$P_TARGETS]}) {
1541 print FILEO "\n### @$target[$T_NAME] sources and settings\n\n";
1542 my $canon=canonize("@$target[$T_NAME]");
1544 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
1545 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
1546 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
1547 my $basename=@$target[$T_NAME];
1548 $basename =~ s+\.so$++;
1549 if (@$target[$T_FLAGS] & $TF_WRAP) {
1550 $basename =~ s+^lib++;
1551 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1552 $basename.="_wrapper";
1554 generate_list("${canon}_SPEC_SRCS",1,[ "$basename.spec"]);
1555 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH],sub
1559 generate_list("${canon}_IMPORTS",1,@$target[$T_IMPORTS],sub
1563 generate_list("${canon}_DEPENDS",1,@$target[$T_DEPENDS],sub
1567 print FILEO "${canon}_OBJS = \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_C_SRCS:.c=.o) \$(${canon}_CXX_SRCS:.cpp=.o) \$(EXTRA_OBJS)\n";
1570 print FILEO "### Global source lists\n\n";
1571 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
1573 my $canon=canonize(@{$_[0]}[$T_NAME]);
1575 return "\$(${canon}_C_SRCS)";
1578 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
1580 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
1582 my $canon=canonize(@{$_[0]}[$T_NAME]);
1584 return "\$(${canon}_CXX_SRCS)";
1587 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
1589 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
1591 my $canon=canonize(@{$_[0]}[$T_NAME]);
1593 return "\$(${canon}_RC_SRCS)";
1596 generate_list("",1,@$project_settings[$T_SOURCES_RC]);
1598 generate_list("SPEC_SRCS",1,@$project[$P_TARGETS],sub
1600 my $canon=canonize(@{$_[0]}[$T_NAME]);
1602 return "\$(${canon}_SPEC_SRCS)";
1607 print FILEO "### Generic autoconf targets\n\n";
1608 if (@$project[$P_PATH] eq "") {
1609 print FILEO "all: \$(SUBDIRS) \$(LIBRARIES) \$(PROGRAMS)\n";
1611 print FILEO "all: \$(LIBRARIES) \$(PROGRAMS)\n";
1614 print FILEO "\@MAKE_RULES\@\n";
1616 print FILEO "install::\n";
1617 if (@$project[$P_PATH] eq "") {
1618 # This is the main project. It is also responsible for recursively
1619 # calling the other projects
1620 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) install) || exit 1; done\n";
1622 if (@{@$project[$P_TARGETS]} > 0) {
1623 print FILEO "\tfor i in \$(PROGRAMS); do \$(INSTALL_PROGRAM) \$\$i \$(bindir); done\n";
1624 print FILEO "\tfor i in \$(LIBRARIES); do \$(INSTALL_LIBRARY) \$\$i \$(libdir); done\n";
1627 print FILEO "uninstall::\n";
1628 if (@$project[$P_PATH] eq "") {
1629 # This is the main project. It is also responsible for recursively
1630 # calling the other projects
1631 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) uninstall) || exit 1; done\n";
1633 if (@{@$project[$P_TARGETS]} > 0) {
1634 print FILEO "\tfor i in \$(PROGRAMS); do \$(RM) \$(bindir)/\$\$i;done\n";
1635 print FILEO "\tfor i in \$(LIBRARIES); do \$(RM) \$(libdir)/\$\$i;done\n";
1637 print FILEO "\n\n\n";
1639 if (@{@$project[$P_TARGETS]} > 0) {
1640 print FILEO "### Target specific build rules\n\n";
1641 foreach $target (@{@$project[$P_TARGETS]}) {
1642 my $canon=canonize("@$target[$T_NAME]");
1644 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.spec.c): \$(${canon}_RC_SRCS:.rc=.res)\n";
1646 print FILEO "@$target[$T_NAME]: \$(${canon}_OBJS) \$(${canon}_DEPENDS) \n";
1647 if (@$target[$T_TYPE] eq $TT_DLL) {
1648 print FILEO "\t\$(LDSHARED) -shared -Wl,-soname,\$\@ -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(${canon}_IMPORTS:%=-l%) \$(DLL_LINK) \$(LIBS)\n";
1650 print FILEO "\t\$(CC) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(${canon}_IMPORTS:%=-l%) \$(DLL_LINK) \$(LIBS)\n";
1657 foreach $target (@{@$project[$P_TARGETS]}) {
1658 generate_spec_file(@$project[$P_PATH],$target,$project_settings);
1659 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1660 generate_wrapper_file(@$project[$P_PATH],$target);
1666 # Perform the replacements in the template configure files
1667 # Return 1 for success, 0 for failure
1668 sub generate_configure
1671 my $a_source_file=$_[1];
1673 if (!defined $templates{$filename}) {
1674 if ($filename ne "configure") {
1675 print STDERR "winemaker: internal error: No template called '$filename'\n";
1680 if (!open(FILEO,">$filename")) {
1681 print STDERR "error: unable to open \"$filename\" for writing:\n";
1682 print STDERR " $!\n";
1685 foreach $line (@{$templates{$filename}}) {
1686 if ($line =~ /^\#\#WINEMAKER_PROJECTS\#\#$/) {
1687 foreach $project (@projects) {
1688 print FILEO "@$project[$P_PATH]Makefile\n";
1691 $line =~ s+\#\#WINEMAKER_SOURCE\#\#+$a_source_file+;
1692 $line =~ s+\#\#WINEMAKER_NEEDS_MFC\#\#+$needs_mfc+;
1700 sub generate_generic
1704 if (!defined $templates{$filename}) {
1705 print STDERR "winemaker: internal error: No template called '$filename'\n";
1708 if (!open(FILEO,">$filename")) {
1709 print STDERR "error: unable to open \"$filename\" for writing:\n";
1710 print STDERR " $!\n";
1713 foreach $line (@{$templates{$filename}}) {
1720 # Generates the global files:
1724 sub generate_global_files
1726 generate_generic("Make.rules.in");
1728 # Get the name of a source file for configure.in
1730 search_a_file: foreach $project (@projects) {
1731 foreach $target (@{@$project[$P_TARGETS]}) {
1732 $a_source_file=@{@$target[$T_SOURCES_C]}[0];
1733 if (!defined $a_source_file) {
1734 $a_source_file=@{@$target[$T_SOURCES_CXX]}[0];
1736 if (!defined $a_source_file) {
1737 $a_source_file=@{@$target[$T_SOURCES_RC]}[0];
1739 if (defined $a_source_file) {
1740 $a_source_file="@$project[$P_PATH]$a_source_file";
1746 generate_configure("configure.in",$a_source_file);
1747 unlink("configure");
1748 if (generate_configure("configure",$a_source_file) == 0) {
1751 # Add execute permission to configure for whoever has the right to read it
1752 my @st=stat("configure");
1755 $mode|=($mode & 0444) >>2;
1756 chmod($mode,"configure");
1758 print "warning: could not generate the configure script. You need to run autoconf\n";
1764 sub generate_read_templates
1769 if (/^--- ((\w\.?)+) ---$/) {
1771 if (defined $templates{$filename}) {
1772 print STDERR "winemaker: internal error: There is more than one template for $filename\n";
1776 $templates{$filename}=$file;
1778 } elsif (defined $file) {
1785 # This is where we finally generate files. In fact this method does not
1786 # do anything itself but calls the methods that do the actual work.
1789 print "Generating project files...\n";
1790 generate_read_templates();
1791 generate_global_files();
1793 foreach $project (@projects) {
1794 my $path=@$project[$P_PATH];
1801 generate_project_files($project);
1814 $opt_lower=$OPT_LOWER_UPPERCASE;
1816 # $opt_single_target=<undefined>
1817 $opt_target_type=$TT_GUIEXE;
1819 $opt_is_interactive=$OPT_ASK_NO;
1820 $opt_ask_project_options=$OPT_ASK_NO;
1821 $opt_ask_target_options=$OPT_ASK_NO;
1833 project_init(\@main_project,"");
1836 my $arg=shift @ARGV;
1838 if ($arg eq "--nobanner") {
1840 } elsif ($arg eq "--backup") {
1842 } elsif ($arg eq "--nobackup") {
1844 } elsif ($arg eq "--single-target") {
1845 $opt_single_target=shift @ARGV;
1846 } elsif ($arg eq "--lower-none") {
1847 $opt_lower=$OPT_LOWER_NONE;
1848 } elsif ($arg eq "--lower-all") {
1849 $opt_lower=$OPT_LOWER_ALL;
1850 } elsif ($arg eq "--lower-uppercase") {
1851 $opt_lower=$OPT_LOWER_UPPERCASE;
1852 } elsif ($arg eq "--no-makefile") {
1855 } elsif ($arg =~ /^-D/) {
1856 push @{$global_settings[$T_DEFINES]},$arg;
1857 } elsif ($arg =~ /^-I/) {
1858 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
1859 } elsif ($arg =~ /^-L/) {
1860 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
1861 } elsif ($arg =~ /^-l/) {
1862 push @{$global_settings[$T_IMPORTS]},$';
1864 # 'Source'-based method options
1865 } elsif ($arg eq "--dll") {
1866 $opt_target_type=$TT_DLL;
1867 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
1868 $opt_target_type=$TT_GUIEXE;
1869 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
1870 $opt_target_type=$TT_CUIEXE;
1871 } elsif ($arg eq "--interactive") {
1872 $opt_is_interactive=$OPT_ASK_YES;
1873 $opt_ask_project_options=$OPT_ASK_YES;
1874 $opt_ask_target_options=$OPT_ASK_YES;
1875 } elsif ($arg eq "--wrap") {
1876 $opt_flags|=$TF_WRAP;
1877 } elsif ($arg eq "--nowrap") {
1878 $opt_flags&=~$TF_WRAP;
1879 } elsif ($arg eq "--mfc") {
1880 $opt_flags|=$TF_MFC|$TF_WRAP;
1882 } elsif ($arg eq "--nomfc") {
1883 $opt_flags&=~($TF_MFC|$TF_WRAP);
1888 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
1889 print STDERR "Unknown option: $arg\n";
1896 if ($opt_no_banner == 0 or defined $usage) {
1897 print "Winemaker $version\n";
1898 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
1901 if (defined $usage) {
1902 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup]\n";
1903 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
1904 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
1905 print STDERR " [--wrap|--nowrap] [--mfc|--nomfc]\n";
1906 print STDERR " [-Dmacro[=defn]] [-Idir] [-Ldir] [-llibrary]\n";
1907 print STDERR " [--interactive] [--single-target name]\n";
1911 # Fix the file and directory names
1912 fix_file_and_directory_names(".");
1914 # Scan the sources to identify the projects and targets
1917 # Create targets for wrappers
1920 # Fix the source files
1923 # Generate the Makefile and the spec file
1924 if (! $opt_no_makefile) {
1930 --- configure.in ---
1931 dnl Process this file with autoconf to produce a configure script.
1932 dnl Author: Michael Patra <micky@marie.physik.tu-berlin.de>
1933 dnl <patra@itp1.physik.tu-berlin.de>
1934 dnl Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
1936 AC_REVISION([configure.in 1.00])
1937 AC_INIT(##WINEMAKER_SOURCE##)
1939 NEEDS_MFC=##WINEMAKER_NEEDS_MFC##
1941 dnl **** Command-line arguments ****
1945 dnl **** Check for some programs ****
1954 AC_PATH_PROG(LDCONFIG, ldconfig, true, /sbin:/usr/sbin:$PATH)
1956 dnl **** Check for some libraries ****
1958 dnl Check for -lm for BeOS
1959 AC_CHECK_LIB(m,sqrt)
1960 dnl Check for -li386 for NetBSD and OpenBSD
1961 AC_CHECK_LIB(i386,i386_set_ldt)
1962 dnl Check for -lossaudio for NetBSD
1963 AC_CHECK_LIB(ossaudio,_oss_ioctl)
1964 dnl Check for -lw for Solaris
1965 AC_CHECK_LIB(w,iswalnum)
1966 dnl Check for -lnsl for Solaris
1967 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))
1968 dnl Check for -lsocket for Solaris
1969 AC_CHECK_FUNCS(connect,,AC_CHECK_LIB(socket,connect))
1970 dnl Check for -lxpg4 for FreeBSD
1971 AC_CHECK_LIB(xpg4,setrunelocale)
1972 dnl Check for -lmmap for OS/2
1973 AC_CHECK_LIB(mmap,mmap)
1974 dnl Check for openpty
1975 AC_CHECK_FUNCS(openpty,,
1976 AC_CHECK_LIB(util,openpty,
1977 AC_DEFINE(HAVE_OPENPTY)
1981 AC_CHECK_HEADERS(dlfcn.h,
1982 AC_CHECK_FUNCS(dlopen,
1983 AC_DEFINE(HAVE_DL_API),
1984 AC_CHECK_LIB(dl,dlopen,
1985 AC_DEFINE(HAVE_DL_API)
1996 dnl **** Check which curses lib to use ***
1997 if test "$CURSES" = "yes"
1999 AC_CHECK_HEADERS(ncurses.h)
2000 if test "$ac_cv_header_ncurses_h" = "yes"
2002 AC_CHECK_LIB(ncurses,waddch)
2004 if test "$ac_cv_lib_ncurses_waddch" = "yes"
2006 AC_CHECK_LIB(ncurses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2007 AC_CHECK_LIB(ncurses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2009 AC_CHECK_HEADERS(curses.h)
2010 if test "$ac_cv_header_curses_h" = "yes"
2012 AC_CHECK_LIB(curses,waddch)
2013 if test "$ac_cv_lib_curses_waddch" = "yes"
2015 AC_CHECK_LIB(curses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2016 AC_CHECK_LIB(curses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2022 dnl **** If ln -s doesn't work, use cp instead ****
2023 if test "$ac_cv_prog_LN_S" = "ln -s"; then : ; else LN_S=cp ; fi
2025 dnl **** Check for gcc strength-reduce bug ****
2027 if test "x${GCC}" = "xyes"
2029 AC_CACHE_CHECK( "for gcc strength-reduce bug", ac_cv_c_gcc_strength_bug,
2032 static int Array[[3]];
2035 for(i=0; i<B; i++) Array[[i]] = i - 3;
2036 exit( Array[[1]] != -2 );
2038 ac_cv_c_gcc_strength_bug="no",
2039 ac_cv_c_gcc_strength_bug="yes",
2040 ac_cv_c_gcc_strength_bug="yes") )
2041 if test "$ac_cv_c_gcc_strength_bug" = "yes"
2043 CFLAGS="$CFLAGS -fno-strength-reduce"
2047 dnl **** Check for underscore on external symbols ****
2049 AC_CACHE_CHECK("whether external symbols need an underscore prefix",
2050 ac_cv_c_extern_prefix,
2052 LIBS="conftest_asm.s $LIBS"
2053 cat > conftest_asm.s <<EOF
2058 AC_TRY_LINK([extern int ac_test;],[if (ac_test) return 1],
2059 ac_cv_c_extern_prefix="yes",ac_cv_c_extern_prefix="no")
2061 if test "$ac_cv_c_extern_prefix" = "yes"
2063 AC_DEFINE(NEED_UNDERSCORE_PREFIX)
2066 dnl **** Check for working dll ****
2069 AC_CACHE_CHECK("whether we can build a Linux dll",
2071 [saved_cflags=$CFLAGS
2072 CFLAGS="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0"
2073 AC_TRY_LINK(,[return 1],ac_cv_c_dll_linux="yes",ac_cv_c_dll_linux="no")
2074 CFLAGS=$saved_cflags
2076 if test "$ac_cv_c_dll_linux" = "yes"
2078 LDSHARED="\$(CC) -shared -Wl,-soname,\$(SONAME),-rpath,\$(libdir)"
2080 AC_CACHE_CHECK(whether we can build a UnixWare (Solaris) dll,
2081 ac_cv_c_dll_unixware,
2082 [saved_cflags=$CFLAGS
2083 CFLAGS="$CFLAGS -fPIC -Wl,-G,-h,conftest.so.1.0"
2084 AC_TRY_LINK(,[return 1],ac_cv_c_dll_unixware="yes",ac_cv_c_dll_unixware="no")
2085 CFLAGS=$saved_cflags
2087 if test "$ac_cv_c_dll_unixware" = "yes"
2089 LDSHARED="\$(CC) -Wl,-G,-h,\$(libdir)/\$(SONAME)"
2091 AC_CACHE_CHECK("whether we can build a NetBSD dll",
2093 [saved_cflags=$CFLAGS
2094 CFLAGS="$CFLAGS -fPIC -Bshareable -Bforcearchive"
2095 AC_TRY_LINK(,[return 1],ac_cv_c_dll_netbsd="yes",ac_cv_c_dll_netbsd="no")
2096 CFLAGS=$saved_cflags
2098 if test "$ac_cv_c_dll_netbsd" = "yes"
2100 LDSHARED="ld -Bshareable -Bforcearchive"
2104 if test "$ac_cv_c_dll_linux" = "no" -a "$ac_cv_c_dll_unixware" = "no" -a "$ac_cv_c_dll_netbsd" = "no"
2106 AC_MSG_ERROR([Could not find how to build a dynamically linked library])
2110 DLL_LINK="\$(WINELIB_LIBRARY_PATH) \$(DLLS:%=-l%) \$(IMPORTS:%=-l%) -lwine -lwine_unicode"
2116 dnl *** check for the need to define __i386__
2118 AC_CACHE_CHECK("whether we need to define __i386__",ac_cv_cpp_def_i386,
2119 AC_EGREP_CPP(yes,[#if (defined(i386) || defined(__i386)) && !defined(__i386__)
2122 ac_cv_cpp_def_i386="yes", ac_cv_cpp_def_i386="no"))
2123 if test "$ac_cv_cpp_def_i386" = "yes"
2125 CFLAGS="$CFLAGS -D__i386__"
2128 dnl $GCC is set by autoconf
2130 if test "$GCC" = "yes"
2132 GCC_NO_BUILTIN="-fno-builtin"
2134 AC_SUBST(GCC_NO_BUILTIN)
2136 dnl **** Test Winelib-related features of the C++ compiler
2138 if test "x${GCC}" = "xyes"
2140 OLDCXXFLAGS="$CXXFLAGS";
2141 CXXFLAGS="-fpermissive";
2142 AC_CACHE_CHECK("for g++ -fpermissive option", has_gxx_permissive,
2144 for (int i=0;i<2;i++);
2147 [has_gxx_permissive="yes"],
2148 [has_gxx_permissive="no"])
2150 CXXFLAGS="-fno-for-scope";
2151 AC_CACHE_CHECK("for g++ -fno-for-scope option", has_gxx_no_for_scope,
2153 for (int i=0;i<2;i++);
2156 [has_gxx_no_for_scope="yes"],
2157 [has_gxx_no_for_scope="no"])
2159 CXXFLAGS="$OLDCXXFLAGS";
2160 if test "$has_gxx_permissive" = "yes"
2162 CXXFLAGS="$CXXFLAGS -fpermissive"
2164 if test "$has_gxx_no_for_scope" = "yes"
2166 CXXFLAGS="$CXXFLAGS -fno-for-scope"
2170 dnl **** Test Winelib-related features of the C compiler
2173 dnl **** Try to find where winelib is located ****
2175 dnl This section is implemented using custom code since autoconf does not
2176 dnl provide a standard method. Here is how other people have tried to
2177 dnl solve the same (or similar) problem.
2178 dnl See: http://www.geocrawler.com/archives/3/402/1999/4/50/2131449/
2179 dnl or http://www.geocrawler.com/archives/3/402/1999/4/50/2131443/
2180 dnl ftp://ftp.slac.stanford.edu/users/langston/autoconf/smr_macros-0.09.tar.gz
2181 dnl or http://www.geocrawler.com/archives/3/402/1999/4/50/2131452/
2182 dnl or http://www.geocrawler.com/archives/3/402/1999/4/50/2131446/
2184 WINELIB_INCLUDE_ROOT="";
2185 WINELIB_INCLUDE_PATH="";
2186 WINELIB_LIBRARY_ROOT="";
2187 WINELIB_LIBRARY_PATH="";
2188 WINELIB_TOOL_PATH="";
2192 AC_ARG_WITH(winelib-root,
2193 [ --with-winelib-root=DIR take the Winelib includes, libraries and tools from this directory],
2194 [if test "$withval" != "no"; then
2195 WINELIB_ROOT="$withval";
2196 WINELIB_INCLUDES="";
2197 WINELIB_LIBRARIES="";
2202 if test -n "$WINELIB_ROOT"
2204 WINELIB_INCLUDE_ROOT="$WINELIB_ROOT/include";
2205 WINELIB_LIBRARY_ROOT="$WINELIB_ROOT";
2206 WINELIB_TOOL_PATH="$WINELIB_ROOT:$WINELIB_ROOT/bin:$WINELIB_ROOT/tools/wrc:$WINELIB_ROOT/tools/winebuild:$PATH";
2209 AC_ARG_WITH(winelib-includes,
2210 [ --with-winelib-includes=DIR take the Winelib includes from this directory],
2211 [if test "$withval" != "no"; then
2212 WINELIB_INCLUDES="$withval";
2214 WINELIB_INCLUDES="";
2216 if test -n "$WINELIB_INCLUDES"
2218 WINELIB_INCLUDE_ROOT="$WINELIB_INCLUDES";
2221 AC_ARG_WITH(winelib-libraries,
2222 [ --with-winelib-libraries=DIR take the Winelib libraries from this directory],
2223 [if test "$withval" != "no"; then
2224 WINELIB_LIBRARIES="$withval";
2226 WINELIB_LIBRARIES="";
2228 if test -n "$WINELIB_LIBRARIES"
2230 WINELIB_LIBRARY_ROOT="$WINELIB_LIBRARIES";
2233 AC_ARG_WITH(winelib-tools,
2234 [ --with-winelib-tools=DIR take the Winelib tools from this directory],
2235 [if test "$withval" != "no"; then
2236 WINELIB_TOOLS="$withval";
2240 if test -n "$WINELIB_TOOLS"
2242 WINELIB_TOOL_PATH="$WINELIB_TOOLS:$WINELIB_TOOLS/wrc:$WINELIB_TOOLS/winebuild";
2245 if test -z "$WINELIB_INCLUDE_ROOT"
2247 WINELIB_INCLUDE_ROOT="/usr/include/wine";
2249 if test ! -f "$WINELIB_INCLUDE_ROOT/windows.h"
2251 AC_MSG_ERROR([Could not find the Winelib includes])
2253 WINELIB_INCLUDE_PATH="-I$WINELIB_INCLUDE_ROOT"
2255 if test -z "$WINELIB_LIBRARY_ROOT"
2257 WINELIB_LIBRARY_ROOT="/usr/lib/wine";
2259 if test ! -f "$WINELIB_LIBRARY_ROOT/libwine.so"
2261 if test -f "$WINELIB_LIBRARY_ROOT/lib/libwine.so"
2263 WINELIB_LIBRARY_ROOT="$WINELIB_LIBRARY_ROOT/lib";
2265 AC_MSG_ERROR([Could not find the Winelib libraries (libwine)])
2268 if test -f "$WINELIB_LIBRARY_ROOT/libkernel32.so"
2270 WINELIB_LIBRARY_PATH="-L$WINELIB_LIBRARY_ROOT";
2272 if test -f "$WINELIB_LIBRARY_ROOT/dlls/libkernel32.so"
2274 WINELIB_LIBRARY_PATH="-L$WINELIB_LIBRARY_ROOT -L$WINELIB_LIBRARY_ROOT/dlls";
2276 AC_MSG_ERROR([Could not find the Winelib libraries (libkernel32)])
2280 AC_PATH_PROG(WINEBUILD,winebuild,,$WINELIB_TOOL_PATH)
2281 if test -z "$WINEBUILD"
2283 AC_MSG_ERROR([Could not find Winelib's winebuild tool])
2285 AC_PATH_PROG(WRC,wrc,,$WINELIB_TOOL_PATH)
2288 AC_MSG_ERROR([Could not find Winelib's wrc tool])
2291 AC_SUBST(WINELIB_INCLUDE_ROOT)
2292 AC_SUBST(WINELIB_INCLUDE_PATH)
2293 AC_SUBST(WINELIB_LIBRARY_ROOT)
2294 AC_SUBST(WINELIB_LIBRARY_PATH)
2296 dnl **** Try to find where the MFC are located ****
2298 if test "x$NEEDS_MFC" = "x1"
2300 ATL_INCLUDE_ROOT="";
2301 ATL_INCLUDE_PATH="";
2302 MFC_INCLUDE_ROOT="";
2303 MFC_INCLUDE_PATH="";
2304 MFC_LIBRARY_ROOT="";
2305 MFC_LIBRARY_PATH="";
2307 AC_ARG_WITH(mfc-root,
2308 [ --with-mfc-root=DIR take the MFC includes and libraries from this directory],
2309 [if test "$withval" != "no"; then
2310 MFC_ROOT="$withval";
2317 if test -n "$MFC_ROOT"
2319 ATL_INCLUDE_ROOT="$MFC_ROOT";
2320 MFC_INCLUDE_ROOT="$MFC_ROOT";
2321 MFC_LIBRARY_ROOT="$MFC_ROOT";
2324 AC_ARG_WITH(atl-includes,
2325 [ --with-atl-includes=DIR take the ATL includes from this directory],
2326 [if test "$withval" != "no"; then
2327 ATL_INCLUDES="$withval";
2331 if test -n "$ATL_INCLUDES"
2333 ATL_INCLUDE_ROOT="$ATL_INCLUDES";
2336 AC_ARG_WITH(mfc-includes,
2337 [ --with-mfc-includes=DIR take the MFC includes from this directory],
2338 [if test "$withval" != "no"; then
2339 MFC_INCLUDES="$withval";
2343 if test -n "$MFC_INCLUDES"
2345 MFC_INCLUDE_ROOT="$MFC_INCLUDES";
2348 AC_ARG_WITH(mfc-libraries,
2349 [ --with-mfc-libraries=DIR take the MFC libraries from this directory],
2350 [if test "$withval" != "no"; then
2351 MFC_LIBRARIES="$withval";
2355 if test -n "$MFC_LIBRARIES"
2357 MFC_LIBRARY_ROOT="$MFC_LIBRARIES";
2360 dnl FIXME: We should have an include path and just iterate through it.
2361 dnl These tests become ugly.
2362 if test -z "$ATL_INCLUDE_ROOT"
2364 ATL_INCLUDE_ROOT="/usr/include";
2366 if test ! -f "$ATL_INCLUDE_ROOT/atlbase.h"
2368 if test -f "$ATL_INCLUDE_ROOT/atl/atlbase.h"
2370 ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT/mfc"
2372 if test -f "$ATL_INCLUDE_ROOT/atl/include/atlbase.h"
2374 ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT/mfc/include"
2376 AC_MSG_ERROR([Could not find the ATL includes])
2380 ATL_INCLUDE_PATH="-I$ATL_INCLUDE_ROOT"
2382 if test -z "$MFC_INCLUDE_ROOT"
2384 MFC_INCLUDE_ROOT="/usr/include";
2386 if test ! -f "$MFC_INCLUDE_ROOT/afx.h"
2388 if test -f "$MFC_INCLUDE_ROOT/mfc/afx.h"
2390 MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT/mfc"
2392 if test -f "$MFC_INCLUDE_ROOT/mfc/include/afx.h"
2394 MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT/mfc/include"
2396 AC_MSG_ERROR([Could not find the MFC includes])
2400 MFC_INCLUDE_PATH="-D_DLL -D_MT -I$MFC_INCLUDE_ROOT -I\$(WINELIB_INCLUDE_ROOT)/mixedcrt"
2402 if test -z "$MFC_LIBRARY_ROOT"
2404 MFC_LIBRARY_ROOT="/usr/lib/mfc";
2406 if test -f "$MFC_LIBRARY_ROOT/libmfc.so"
2408 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT";
2410 if test -f "$MFC_LIBRARY_ROOT/lib/libmfc.so"
2412 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT/lib";
2414 if test -f "$MFC_LIBRARY_ROOT/mfc/src/libmfc.so"
2416 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT/mfc/src";
2418 AC_MSG_ERROR([Could not find the MFC library (libmfc)])
2422 MFC_LIBRARY_PATH="-L$MFC_LIBRARY_ROOT"
2424 AC_SUBST(ATL_INCLUDE_ROOT)
2425 AC_SUBST(ATL_INCLUDE_PATH)
2426 AC_SUBST(MFC_INCLUDE_ROOT)
2427 AC_SUBST(MFC_INCLUDE_PATH)
2428 AC_SUBST(MFC_LIBRARY_ROOT)
2429 AC_SUBST(MFC_LIBRARY_PATH)
2432 dnl **** Generate output files ****
2434 MAKE_RULES=Make.rules
2435 AC_SUBST_FILE(MAKE_RULES)
2439 ##WINEMAKER_PROJECTS##
2443 echo "Configure finished. Do 'make' to build the project."
2446 dnl Local Variables:
2447 dnl comment-start: "dnl "
2449 dnl comment-start-skip: "\\bdnl\\b\\s *"
2450 dnl compile-command: "autoconf"
2452 --- Make.rules.in ---
2453 # Copyright 2000 Francois Gouget for CodeWeavers
2454 # fgouget@codeweavers.com
2456 # Global rules shared by all makefiles -*-Makefile-*-
2458 # Each individual makefile must define the following variables:
2459 # WINELIB_INCLUDE_ROOT: Winelib includes location
2460 # WINELIB_LIBRARY_ROOT: Winelib libraries location
2461 # TOPOBJDIR : top-level object directory
2462 # SRCDIR : source directory for this module
2464 # Each individual makefile may define the following additional variables:
2466 # SUBDIRS : subdirectories that contain a Makefile
2467 # LIBRARIES : libraries to be built
2468 # PROGRAMS : programs to be built
2470 # CEXTRA : extra c flags (e.g. '-Wall')
2471 # CXXEXTRA : extra c++ flags (e.g. '-Wall')
2472 # WRCEXTRA : extra wrc flags (e.g. '-p _SysRes')
2473 # DEFINES : defines (e.g. -DSTRICT)
2474 # INCLUDE_PATH : additional include path
2475 # LIBRARY_PATH : additional library path
2476 # IMPORTS : additional libraries to link with
2478 # C_SRCS : C sources for the module
2479 # CXX_SRCS : C++ sources for the module
2480 # RC_SRCS : resource source files
2481 # SPEC_SRCS : interface definition files
2486 WINELIB_INCLUDE_ROOT = @WINELIB_INCLUDE_ROOT@
2487 WINELIB_INCLUDE_PATH = @WINELIB_INCLUDE_PATH@
2488 WINELIB_LIBRARY_ROOT = @WINELIB_LIBRARY_ROOT@
2489 WINELIB_LIBRARY_PATH = @WINELIB_LIBRARY_PATH@
2493 ATL_INCLUDE_ROOT = @ATL_INCLUDE_ROOT@
2494 ATL_INCLUDE_PATH = @ATL_INCLUDE_PATH@
2495 MFC_INCLUDE_ROOT = @MFC_INCLUDE_ROOT@
2496 MFC_INCLUDE_PATH = @MFC_INCLUDE_PATH@
2497 MFC_LIBRARY_ROOT = @MFC_LIBRARY_ROOT@
2498 MFC_LIBRARY_PATH = @MFC_LIBRARY_PATH@
2500 # First some useful definitions
2506 CXXFLAGS = @CXXFLAGS@
2507 OPTIONS = @OPTIONS@ -D_REENTRANT -DWINELIB
2508 X_CFLAGS = @X_CFLAGS@
2510 XLIB = @X_PRE_LIBS@ @XLIB@ @X_EXTRA_LIBS@
2511 DLL_LINK = @DLL_LINK@
2512 LIBS = @LIBS@ $(LIBRARY_PATH)
2517 DIVINCL = -I$(SRCDIR) $(WINELIB_INCLUDE_PATH) $(INCLUDE_PATH)
2518 ALLCFLAGS = $(DIVINCL) $(CFLAGS) $(CEXTRA) $(OPTIONS) $(X_CFLAGS) $(DEFINES)
2519 ALLCXXFLAGS = $(DIVINCL) $(CXXFLAGS) $(CXXEXTRA) $(OPTIONS) $(X_CFLAGS) $(DEFINES)
2521 LDSHARED = @LDSHARED@
2525 WINEBUILD = @WINEBUILD@
2530 # Installation infos
2533 INSTALL_PROGRAM = @INSTALL_PROGRAM@
2534 INSTALL_DATA = @INSTALL_DATA@
2536 exec_prefix = @exec_prefix@
2543 CLEAN_FILES = *.o *.a *.so \\\#*\\\# *~ *% .\\\#* *.orig *.rej \
2544 *.spec.c y.tab.c y.tab.h lex.yy.c core
2546 OBJS = $(SPEC_SRCS:.spec=.spec.o) $(C_SRCS:.c=.o) $(CXX_SRCS:.cpp=.o)
2616 .SUFFIXES: .C .cpp .CPP .cxx .CXX .rc .RC .res .spec .spec.c .spec.o
2619 $(CC) -c $(ALLCFLAGS) -o $@ $<
2622 $(CC) -c $(ALLCFLAGS) -o $@ $<
2625 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2628 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2631 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2634 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2637 $(WINEBUILD) @DLLFLAGS@ -o $@ -spec $<
2640 $(CC) -c $(ALLCFLAGS) @GCC_NO_BUILTIN@ -o $@ $<
2643 $(WRC) $(WRCFLAGS) $(WRCEXTRA) $(DIVINCL) -o $@ $<
2646 $(WRC) $(WRCFLAGS) $(WRCEXTRA) $(DIVINCL) -o $@ $<
2648 .PHONY: all install uninstall clean distclean depend dummy
2650 # 'all' target first in case the enclosing Makefile didn't define any target
2654 # Rules for makefile
2656 Makefile: Makefile.in $(TOPSRCDIR)/configure
2657 @echo Makefile is older than $?, please rerun $(TOPSRCDIR)/configure
2660 # Rules for cleaning
2662 $(SUBDIRS:%=%/__clean__): dummy
2663 cd `dirname $@` && $(MAKE) clean
2665 $(EXTRASUBDIRS:%=%/__clean__): dummy
2666 -cd `dirname $@` && $(RM) $(CLEAN_FILES)
2668 clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
2669 $(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(LIBRARIES) $(PROGRAMS)
2671 # Rules for installing
2673 $(SUBDIRS:%=%/__install__): dummy
2674 cd `dirname $@` && $(MAKE) install
2676 $(SUBDIRS:%=%/__uninstall__): dummy
2677 cd `dirname $@` && $(MAKE) uninstall
2686 # End of global rules
2689 * Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2693 #include <windows.h>
2698 * Describe the wrapped application
2702 * This is either CUIEXE for a console based application or
2703 * GUIEXE for a regular windows application.
2705 #define APP_TYPE ##WINEMAKER_APP_TYPE##
2708 * This is the application library's base name, i.e. 'hello' if the
2709 * library is called 'libhello.so'.
2711 static char* appName = ##WINEMAKER_APP_NAME##;
2714 * This is the name of the application's Windows module. If left NULL
2715 * then appName is used.
2717 static char* appModule = NULL;
2720 * This is the application's entry point. This is usually "WinMain" for a
2721 * GUIEXE and 'main' for a CUIEXE application.
2723 static char* appInit = ##WINEMAKER_APP_INIT##;
2726 * This is either non-NULL for MFC-based applications and is the name of the
2727 * MFC's module. This is the module in which we will take the 'WinMain'
2730 static char* mfcModule = ##WINEMAKER_APP_MFC##;
2735 * Implement the main.
2738 #if APP_TYPE == GUIEXE
2739 typedef int WINAPI (*WinMainFunc)(HINSTANCE hInstance, HINSTANCE hPrevInstance,
2740 PSTR szCmdLine, int iCmdShow);
2742 typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp);
2745 #if APP_TYPE == GUIEXE
2746 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
2747 PSTR szCmdLine, int iCmdShow)
2749 int WINAPI Main(int argc, char** argv, char** envp)
2753 HINSTANCE hApp,hMFC,hMain;
2758 /* Load the application's library */
2759 libName=(char*)malloc(strlen(appName)+5+3+1);
2760 /* FIXME: we should get the wrapper's path and use that as the base for
2763 sprintf(libName,"./lib%s.so",appName);
2764 appLibrary=dlopen(libName,RTLD_NOW);
2765 if (appLibrary==NULL) {
2766 sprintf(libName,"lib%s.so",appName);
2767 appLibrary=dlopen(libName,RTLD_NOW);
2769 if (appLibrary==NULL) {
2770 char format[]="Could not load the %s library:\r\n%s";
2775 msg=(char*)malloc(strlen(format)+strlen(libName)+strlen(error));
2776 sprintf(msg,format,libName,error);
2777 MessageBox(NULL,msg,"dlopen error",MB_OK);
2782 /* Then if this application is MFC based, load the MFC module */
2783 /* FIXME: I'm not sure this is really necessary */
2784 if (mfcModule!=NULL) {
2785 hMFC=LoadLibrary(mfcModule);
2787 char format[]="Could not load the MFC module %s (%d)";
2790 msg=(char*)malloc(strlen(format)+strlen(mfcModule)+11);
2791 sprintf(msg,format,mfcModule,GetLastError());
2792 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
2796 /* MFC is a special case: the WinMain is in the MFC library,
2797 * instead of the application's library.
2804 /* Load the application's module */
2805 if (appModule==NULL) {
2808 hApp=LoadLibrary(appModule);
2810 char format[]="Could not load the application's module %s (%d)";
2813 msg=(char*)malloc(strlen(format)+strlen(appModule)+11);
2814 sprintf(msg,format,appModule,GetLastError());
2815 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
2818 } else if (hMain==NULL) {
2822 /* Get the address of the application's entry point */
2823 appMain=(WinMainFunc*)GetProcAddress(hMain, appInit);
2824 if (appMain==NULL) {
2825 char format[]="Could not get the address of %s (%d)";
2828 msg=(char*)malloc(strlen(format)+strlen(appInit)+11);
2829 sprintf(msg,format,appInit,GetLastError());
2830 MessageBox(NULL,msg,"GetProcAddress error",MB_OK);
2835 /* And finally invoke the application's entry point */
2836 #if APP_TYPE == GUIEXE
2837 retcode=(*((WinMainFunc)appMain))(hApp,hPrevInstance,szCmdLine,iCmdShow);
2839 retcode=(*((MainFunc)appMain))(argc,argv,envp);
2842 /* Cleanup and done */
2847 dlclose(appLibrary);