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 # If we don't find the file referenced by an include, lower it
62 my $opt_lower_include;
65 # Options for the 'Source' method
68 # Specifies that we have only one target so that all sources relate
69 # to this target. By default this variable is left undefined which
70 # means winemaker should try to find out by itself what the targets
71 # are. If not undefined then this contains the name of the default
72 # target (without the extension).
73 my $opt_single_target;
76 # If '$opt_single_target' has been specified then this is the type of
77 # that target. Otherwise it specifies whether the default target type
78 # is guiexe or cuiexe.
82 # Contains the default set of flags to be used when creating a new target.
86 # If true then winemaker should ask questions to the user as it goes
88 my $opt_is_interactive;
89 my $opt_ask_project_options;
90 my $opt_ask_target_options;
93 # If false then winemaker should not generate any file, i.e.
94 # no makefiles, but also no .spec files, no configure.in, etc.
95 my $opt_no_generated_files;
98 # Specifies not to print the banner if set.
105 # Target modelization
109 # The description of a target is stored in an array. The constants
110 # below identify what is stored at each index of the array.
113 # This is the name of the target.
117 # Defines the type of target we want to build. See the TT_xxx
122 # Defines the target's enty point, i.e. the function that is called
127 # This is a bitfield containing flags refining the way the target
128 # should be handled. See the TF_xxx constants below
132 # This is a reference to an array containing the list of the
133 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
137 my $T_SOURCES_MISC=7;
140 # This is a reference to an array containing the list of macro
145 # This is a reference to an array containing the list of directory
146 # names that constitute the include path
147 my $T_INCLUDE_PATH=9;
150 # Same as T_INCLUDE_PATH but for the library search path
151 my $T_LIBRARY_PATH=10;
154 # The list of Windows libraries to import
158 # The list of Unix libraries to link with
162 # The list of dependencies between targets
166 # The following constants define the recognized types of target
169 # This is not a real target. This type of target is used to collect
170 # the sources that don't seem to belong to any other target. Thus no
171 # real target is generated for them, we just put the sources of the
172 # fake target in the global source list.
176 # For executables in the windows subsystem
180 # For executables in the console subsystem
184 # For dynamically linked libraries
188 # The following constants further refine how the target should be handled
191 # This target needs a wrapper
195 # This target is a wrapper
199 # This target is an MFC-based target
203 # Initialize a target:
204 # - set the target type to TT_SETTINGS, i.e. no real target will
210 @$target[$T_TYPE]=$TT_SETTINGS;
211 # leaving $T_INIT undefined
212 @$target[$T_FLAGS]=$opt_flags;
213 @$target[$T_SOURCES_C]=[];
214 @$target[$T_SOURCES_CXX]=[];
215 @$target[$T_SOURCES_RC]=[];
216 @$target[$T_SOURCES_MISC]=[];
217 @$target[$T_DEFINES]=[];
218 @$target[$T_INCLUDE_PATH]=[];
219 @$target[$T_LIBRARY_PATH]=[];
220 @$target[$T_IMPORTS]=[];
221 @$target[$T_LIBRARIES]=[];
222 @$target[$T_DEPENDS]=[];
228 if ($type == $TT_GUIEXE) {
230 } elsif ($type == $TT_CUIEXE) {
232 } elsif ($type == $TT_DLL) {
241 # Project modelization
245 # First we have the notion of project. A project is described by an
246 # array (since we don't have structs in perl). The constants below
247 # identify what is stored at each index of the array.
250 # This is the path in which this project is located. In other
251 # words, this is the path to the Makefile.
255 # This index contains a reference to an array containing the project-wide
256 # settings. The structure of that arrray is actually identical to that of
257 # a regular target since it can also contain extra sources.
261 # This index contains a reference to an array of targets for this
262 # project. Each target describes how an executable or library is to
263 # be built. For each target this description takes the same form as
264 # that of the project: an array. So this entry is an array of arrays.
268 # Initialize a project:
269 # - set the project's path
270 # - initialize the target list
271 # - create a default target (will be removed later if unnecessary)
277 my $project_settings=[];
278 target_init($project_settings);
280 @$project[$P_PATH]=$path;
281 @$project[$P_SETTINGS]=$project_settings;
282 @$project[$P_TARGETS]=[];
299 # Contains the list of all projects. This list tells us what are
300 # the subprojects of the main Makefile and where we have to generate
305 # This is the main project, i.e. the one in the "." directory.
306 # It may well be empty in which case the main Makefile will only
307 # call out subprojects.
311 # Contains the defaults for the include path, etc.
312 # We store the defaults as if this were a target except that we only
313 # exploit the defines, include path, library path, library list and misc
318 # If one of the projects requires the MFc then we set this global variable
319 # to true so that configure asks the user to provide a path tothe MFC
331 # Cleans up a name to make it an acceptable Makefile
337 $name =~ tr/a-zA-Z0-9_/_/c;
342 # Returns true is the specified pathname is absolute.
343 # Note: pathnames that start with a variable '$' or
344 # '~' are considered absolute.
349 return ($path =~ /^[\/~\$]/);
353 # Performs a binary search looking for the specified item
358 my $last=@{$array}-1;
361 while ($first<=$last) {
362 my $index=int(($first+$last)/2);
363 my $cmp=@$array[$index] cmp $item;
378 # 'Source'-based Project analysis
383 # Allows the user to specify makefile and target specific options
384 # - target: the structure in which to store the results
385 # - options: the string containing the options
386 sub source_set_options
391 #FIXME: we must deal with escaping of stuff and all
392 foreach $option (split / /,$options) {
393 if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
394 push @{@$target[$T_DEFINES]},$option;
395 } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
396 push @{@$target[$T_INCLUDE_PATH]},$option;
397 } elsif ($option =~ /^-L/) {
398 push @{@$target[$T_LIBRARY_PATH]},$option;
399 } elsif ($option =~ /^-i/) {
400 push @{@$target[$T_IMPORTS]},$';
401 } elsif ($option =~ /^-l/) {
402 push @{@$target[$T_LIBRARIES]},$';
403 } elsif (@$target[$T_TYPE] != $TT_DLL and
404 $option =~ /^--wrap/) {
405 print STDERR "warning: --wrap no longer supported, ignoring\n";
406 #@$target[$T_FLAGS]|=$TF_WRAP;
407 } elsif (@$target[$T_TYPE] != $TT_DLL and
408 $option =~ /^--nowrap/) {
409 @$target[$T_FLAGS]&=~$TF_WRAP;
410 } elsif ($option =~ /^--mfc/) {
411 @$target[$T_FLAGS]|=$TF_MFC;
412 #if (@$target[$T_TYPE] != $TT_DLL) {
413 # @$target[$T_FLAGS]|=$TF_WRAP;
415 } elsif ($option =~ /^--nomfc/) {
416 @$target[$T_FLAGS]&=~$TF_MFC;
417 #@$target[$T_FLAGS]&=~($TF_MFC|$TF_WRAP);
419 print STDERR "warning: unknown option \"$option\", ignoring it\n";
425 # Scans the specified directory to:
426 # - see if we should create a Makefile in this directory. We normally do
427 # so if we find a project file and sources
428 # - get a list of targets for this directory
429 # - get the list of source files
430 sub source_scan_directory
432 # a reference to the parent's project
433 my $parent_project=$_[0];
434 # the full relative path to the current directory, including a
435 # trailing '/', or an empty string if this is the top level directory
437 # the name of this directory, including a trailing '/', or an empty
438 # string if this is the top level directory
441 # reference to the project for this directory. May not be used
443 # list of targets found in the 'current' directory
445 # list of sources found in the current directory
450 # true if this directory contains a Windows project
451 my $has_win_project=0;
452 # If we don't find any executable/library then we might make up targets
453 # from the list of .dsp/.mak files we find since they usually have the
454 # same name as their target.
458 if (defined $opt_single_target or $dirname eq "") {
459 # Either there is a single target and thus a single project,
460 # or we are in the top level directory for which a project
462 $project=$parent_project;
465 project_init($project,$path);
467 my $project_settings=@$project[$P_SETTINGS];
469 # First find out what this directory contains:
470 # collect all sources, targets and subdirectories
471 my $directory=get_directory_contents($path);
472 foreach $dentry (@$directory) {
473 if ($dentry =~ /^\./) {
476 my $fullentry="$path$dentry";
477 if (-d "$fullentry") {
478 if ($dentry =~ /^(Release|Debug)/i) {
479 # These directories are often used to store the object files and the
480 # resulting executable/library. They should not contain anything else.
481 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
482 foreach $candidate (@candidates) {
483 if ($candidate =~ s/\.exe$//i) {
484 $targets{$candidate}=1;
485 } elsif ($candidate =~ s/^(.*)\.dll$/lib$1.so/i) {
486 $targets{$candidate}=1;
490 # Recursively scan this directory. Any source file that cannot be
491 # attributed to a project in one of the subdirectories will be attributed
493 source_scan_directory($project,"$fullentry/","$dentry/");
495 } elsif (-f "$fullentry") {
496 if ($dentry =~ s/\.exe$//i) {
498 } elsif ($dentry =~ s/^(.*)\.dll$/lib$1.so/i) {
500 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.spec\.c$/) {
501 push @sources_c,"$dentry";
502 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
503 if ($dentry =~ /^stdafx.cpp$/i) {
504 push @sources_misc,"$dentry";
505 @$project_settings[$T_FLAGS]|=$TF_MFC;
507 push @sources_cxx,"$dentry";
509 } elsif ($dentry =~ /\.rc$/i) {
510 push @sources_rc,"$dentry";
511 } elsif ($dentry =~ /\.(h|hxx|inl|rc2|dlg)$/i) {
512 push @sources_misc,"$dentry";
513 if ($dentry =~ /^stdafx.h$/i) {
514 @$project_settings[$T_FLAGS]|=$TF_MFC;
516 } elsif ($dentry =~ /\.dsp$/i) {
517 push @dsp_files,"$dentry";
519 } elsif ($dentry =~ /\.mak$/i) {
520 push @mak_files,"$dentry";
522 } elsif ($dentry =~ /^makefile/i) {
529 # If we have a single target then all we have to do is assign
530 # all the sources to it and we're done
531 # FIXME: does this play well with the --interactive mode?
532 if ($opt_single_target) {
533 my $target=@{@$project[$P_TARGETS]}[0];
534 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
535 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
536 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
537 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
541 my $source_count=@sources_c+@sources_cxx+@sources_rc+
542 @{@$project_settings[$T_SOURCES_C]}+
543 @{@$project_settings[$T_SOURCES_CXX]}+
544 @{@$project_settings[$T_SOURCES_RC]};
545 if ($source_count == 0) {
546 # A project without real sources is not a project, get out!
547 if ($project!=$parent_project) {
548 $parent_settings=@$parent_project[$P_SETTINGS];
549 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
550 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
554 #print "targets=",%targets,"\n";
555 #print "target_count=$target_count\n";
556 #print "has_win_project=$has_win_project\n";
557 #print "dirname=$dirname\n";
560 if (($has_win_project != 0) or ($dirname eq "")) {
561 # Deal with cases where we could not find any executable/library, and
562 # thus have no target, although we did find some sort of windows project.
563 $target_count=keys %targets;
564 if ($target_count == 0) {
565 # Try to come up with a target list based on .dsp/.mak files
567 if (@dsp_files > 0) {
568 $prj_list=\@dsp_files;
570 $prj_list=\@mak_files;
572 foreach $filename (@$prj_list) {
573 $filename =~ s/\.(dsp|mak)$//i;
574 if ($opt_target_type == $TT_DLL) {
575 $filename = "lib$filename.so";
577 $targets{$filename}=1;
579 $target_count=keys %targets;
580 if ($target_count == 0) {
581 # Still nothing, try the name of the directory
583 if ($dirname eq "") {
584 # Bad luck, this is the top level directory!
585 $name=(split /\//, cwd)[-1];
588 # Remove the trailing '/'. Also eliminate whatever is after the last
589 # '.' as it is likely to be meaningless (.orig, .new, ...)
590 $name =~ s+(/|\.[^.]*)$++;
591 if ($name eq "src") {
592 # 'src' is probably a subdirectory of the real project directory.
593 # Try again with the parent (if any).
595 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
598 $name=(split /\//, cwd)[-1];
602 $name =~ s+(/|\.[^.]*)$++;
603 if ($opt_target_type == $TT_DLL) {
604 $name = "lib$name.so";
610 # Ask confirmation to the user if he wishes so
611 if ($opt_is_interactive == $OPT_ASK_YES) {
612 my $target_list=join " ",keys %targets;
613 print "\n*** In ",($path?$path:"./"),"\n";
614 print "* winemaker found the following list of (potential) targets\n";
615 print "* $target_list\n";
616 print "* Type enter to use it as is, your own comma-separated list of\n";
617 print "* targets, 'none' to assign the source files to a parent directory,\n";
618 print "* or 'ignore' to ignore everything in this directory tree.\n";
619 print "* Target list:\n";
620 $target_list=<STDIN>;
622 if ($target_list eq "") {
623 # Keep the target list as is, i.e. do nothing
624 } elsif ($target_list eq "none") {
625 # Empty the target list
627 } elsif ($target_list eq "ignore") {
628 # Ignore this subtree altogether
632 foreach $target (split /,/,$target_list) {
635 # Also accept .exe and .dll as a courtesy
636 $target =~ s+(.*)\.dll$+lib$1.so+;
637 $target =~ s+\.exe$++;
644 # If we have no project at this level, then transfer all
645 # the sources to the parent project
646 $target_count=keys %targets;
647 if ($target_count == 0) {
648 if ($project!=$parent_project) {
649 my $parent_settings=@$parent_project[$P_SETTINGS];
650 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
651 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
652 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
653 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
654 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
659 # Otherwise add this project to the project list, except for
660 # the main project which is already in the list.
661 if ($dirname ne "") {
662 push @projects,$project;
665 # Ask for project-wide options
666 if ($opt_ask_project_options == $OPT_ASK_YES) {
668 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
671 if ((@$project_settings[$T_FLAGS] & $TF_WRAP)!=0) {
672 if ($flag_desc ne "") {
675 $flag_desc.="wrapped";
677 print "* Type any project-wide options (-D/-I/-L/-l/--mfc/--wrap),\n";
678 if (defined $flag_desc) {
679 print "* (currently $flag_desc)\n";
681 print "* or 'skip' to skip the target specific options,\n";
682 print "* or 'never' to not be asked this question again:\n";
685 if ($options eq "skip") {
686 $opt_ask_target_options=$OPT_ASK_SKIP;
687 } elsif ($options eq "never") {
688 $opt_ask_project_options="never";
690 source_set_options($project_settings,$options);
694 # - Create the targets
695 # - Check if we have both libraries and programs
696 # - Match each target with source files (sort in reverse
697 # alphabetical order to get the longest matches first)
698 my @local_imports=();
699 my @local_depends=();
701 foreach $target_name (sort { $b cmp $a } keys %targets) {
702 # Create the target...
705 target_init($target);
706 @$target[$T_NAME]=$target_name;
707 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
708 if ($target_name =~ /^lib(.*)\.so$/) {
709 @$target[$T_TYPE]=$TT_DLL;
710 @$target[$T_INIT]=get_default_init($TT_DLL);
711 @$target[$T_FLAGS]&=~$TF_WRAP;
713 push @local_depends,$target_name;
714 push @local_imports,$basename;
716 @$target[$T_TYPE]=$opt_target_type;
717 @$target[$T_INIT]=get_default_init($opt_target_type);
718 $basename=$target_name;
719 push @exe_list,$target;
721 # This is the default link list of Visual Studio, except for uuid and
722 # odbccp32 which we don't have in Wine. Also I add ntdll which seems
723 # necessary for WineLib.
724 my @std_imports=qw(advapi32.dll comdlg32.dll gdi32.dll kernel32.dll ntdll.dll odbc32.dll ole32 oleaut32.dll shell32.dll user32.dll winspool.drv);
725 @$target[$T_IMPORTS]=\@std_imports;
726 push @{@$project[$P_TARGETS]},$target;
728 # Ask for target-specific options
729 if ($opt_ask_target_options == $OPT_ASK_YES) {
731 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
734 if ((@$target[$T_FLAGS] & $TF_WRAP)!=0) {
735 if ($flag_desc ne "") {
740 $flag_desc.="wrapped";
742 if ($flag_desc ne "") {
745 print "* Specify any link option (-L/-l/--mfc/--wrap) specific to the target\n";
746 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
749 if ($options eq "never") {
750 $opt_ask_target_options=$OPT_ASK_NO;
752 source_set_options($target,$options);
755 if (@$target[$T_FLAGS] & $TF_MFC) {
756 @$project_settings[$T_FLAGS]|=$TF_MFC;
757 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
758 push @{@$target[$T_IMPORTS]},"mfc.dll";
759 # FIXME: Link with the MFC in the Unix sense, until we
760 # start exporting the functions properly.
761 push @{@$target[$T_LIBRARIES]},"mfc";
765 if ($target_count == 1) {
766 push @{@$target[$T_SOURCES_C]},@sources_c;
767 push @{@$target[$T_SOURCES_CXX]},@sources_cxx;
768 push @{@$target[$T_SOURCES_RC]},@sources_rc;
769 push @{@$target[$T_SOURCES_MISC]},@sources_misc;
775 foreach $source (@sources_c) {
776 if ($source =~ /^$basename/i) {
777 push @{@$target[$T_SOURCES_C]},$source;
781 foreach $source (@sources_cxx) {
782 if ($source =~ /^$basename/i) {
783 push @{@$target[$T_SOURCES_CXX]},$source;
787 foreach $source (@sources_rc) {
788 if ($source =~ /^$basename/i) {
789 push @{@$target[$T_SOURCES_RC]},$source;
793 foreach $source (@sources_misc) {
794 if ($source =~ /^$basename/i) {
795 push @{@$target[$T_SOURCES_MISC]},$source;
800 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
801 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
802 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
803 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
805 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
806 $opt_ask_target_options=$OPT_ASK_YES;
809 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
810 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
812 # The sources that did not match, if any, go to the extra
813 # source list of the project settings
814 foreach $source (@sources_c) {
816 push @{@$project_settings[$T_SOURCES_C]},$source;
819 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
820 foreach $source (@sources_cxx) {
822 push @{@$project_settings[$T_SOURCES_CXX]},$source;
825 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
826 foreach $source (@sources_rc) {
828 push @{@$project_settings[$T_SOURCES_RC]},$source;
831 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
832 foreach $source (@sources_misc) {
834 push @{@$project_settings[$T_SOURCES_MISC]},$source;
837 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
839 # Finally if we are building both libraries and programs in
840 # this directory, then the programs should be linked with all
842 if (@local_imports > 0 and @exe_list > 0) {
843 foreach $target (@exe_list) {
844 push @{@$target[$T_LIBRARY_PATH]},"-L.";
845 push @{@$target[$T_IMPORTS]},map { "$_.dll" } @local_imports;
846 # Also link in the Unix sense since none of the functions
848 push @{@$target[$T_LIBRARIES]},@local_imports;
849 push @{@$target[$T_DEPENDS]},@local_depends;
855 # Scan the source directories in search of things to build
858 my $main_target=@{$main_project[$P_TARGETS]}[0];
860 # If there's a single target then this is going to be the default target
861 if (defined $opt_single_target) {
862 if ($opt_target_type == $TT_DLL) {
863 @$main_target[$T_NAME]="lib$opt_single_target.so";
865 @$main_target[$T_NAME]="$opt_single_target";
867 @$main_target[$T_TYPE]=$opt_target_type;
870 # The main directory is always going to be there
871 push @projects,\@main_project;
873 # Now scan the directory tree looking for source files and, maybe, targets
874 print "Scanning the source directories...\n";
875 source_scan_directory(\@main_project,"","");
877 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
884 # 'vc.dsp'-based Project analysis
897 # Creating the wrapper targets
901 sub postprocess_targets
903 foreach $project (@projects) {
904 foreach $target (@{@$project[$P_TARGETS]}) {
905 if ((@$target[$T_FLAGS] & $TF_WRAP) != 0) {
907 target_init($wrapper);
908 @$wrapper[$T_NAME]=@$target[$T_NAME];
909 @$wrapper[$T_TYPE]=@$target[$T_TYPE];
910 @$wrapper[$T_INIT]=get_default_init(@$target[$T_TYPE]);
911 @$wrapper[$T_FLAGS]=$TF_WRAPPER | (@$target[$T_FLAGS] & $TF_MFC);
912 push @{@$wrapper[$T_SOURCES_C]},"@$wrapper[$T_NAME]_wrapper.c";
914 my $index=bsearch(@$target[$T_SOURCES_C],"@$wrapper[$T_NAME]_wrapper.c");
915 if (defined $index) {
916 splice(@{@$target[$T_SOURCES_C]},$index,1);
918 @$target[$T_NAME]="lib@$target[$T_NAME].so";
919 @$target[$T_TYPE]=$TT_DLL;
921 push @{@$project[$P_TARGETS]},$wrapper;
923 if ((@$target[$T_FLAGS] & $TF_MFC) != 0) {
924 @{@$project[$P_SETTINGS]}[$T_FLAGS]|=$TF_MFC;
940 # Performs a directory traversal and renames the files so that:
941 # - they have the case desired by the user
942 # - their extension is of the appropriate case
943 # - they don't contain annoying characters like ' ', '$', '#', ...
944 sub fix_file_and_directory_names
948 if (opendir(DIRECTORY, "$dirname")) {
949 foreach $dentry (readdir DIRECTORY) {
950 if ($dentry =~ /^\./ or $dentry eq "CVS") {
953 # Set $warn to 1 if the user should be warned of the renaming
956 # autoconf and make don't support these characters well
957 my $new_name=$dentry;
958 $new_name =~ s/[ \$]/_/g;
960 # Our Make.rules supports all-uppercase and all-lowercase extensions.
961 # The others must be fixed.
962 if (-f "$dirname/$new_name") {
963 if ($new_name =~ /\.cpp/i and $new_name !~ /\.(cpp|CPP)/) {
964 $new_name =~ s/\.cpp$/.cpp/i;
966 if ($new_name =~ s/\.cxx$/.cpp/i) {
969 if ($new_name =~ /\.rc/i and $new_name !~ /\.(rc|RC)/) {
970 $new_name =~ s/\.rc$/.rc/i;
972 # And this last one is to avoid confusion then running make
973 if ($new_name =~ s/^makefile$/makefile.win/) {
978 # Adjust the case to the user's preferences
979 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
980 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
982 $new_name=lc $new_name;
985 # And finally, perform the renaming
986 if ($new_name ne $dentry) {
988 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
990 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
991 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
992 print STDERR " $!\n";
996 if (-d "$dirname/$new_name") {
997 fix_file_and_directory_names("$dirname/$new_name");
1000 closedir(DIRECTORY);
1013 # This maps a directory name to a reference to an array listing
1014 # its contents (files and directories)
1018 # Retrieves the contents of the specified directory.
1019 # We either get it from the directories hashtable which acts as a
1020 # cache, or use opendir, readdir, closedir and store the result
1022 sub get_directory_contents
1027 #print "getting the contents of $dirname\n";
1029 # check for a cached version
1031 if ($dirname eq "") {
1034 $directory=$directories{$dirname};
1035 if (defined $directory) {
1036 #print "->@$directory\n";
1040 # Read this directory
1041 if (opendir(DIRECTORY, "$dirname")) {
1042 my @files=readdir DIRECTORY;
1043 closedir(DIRECTORY);
1046 # Return an empty list
1047 #print "error: cannot open $dirname\n";
1051 #print "->@$directory\n";
1052 $directories{$dirname}=$directory;
1057 # Try to find a file for the specified filename. The attempt is
1058 # case-insensitive which is why it's not trivial. If a match is
1059 # found then we return the pathname with the correct case.
1066 if ($dirname eq "" or $dirname eq ".") {
1068 } elsif ($dirname =~ m+^[^/]+) {
1069 $dirname=cwd . "/" . $dirname;
1071 if ($dirname !~ m+/$+) {
1075 foreach $component (@$path) {
1076 #print " looking for $component in \"$dirname\"\n";
1077 if ($component eq ".") {
1080 } elsif ($component eq "..") {
1082 $dirname=dirname($dirname) . "/";
1085 my $directory=get_directory_contents $dirname;
1087 foreach $dentry (@$directory) {
1088 if ($dentry =~ /^$component$/i) {
1089 $dirname.="$dentry/";
1090 $real_path.="$dentry/";
1095 if (!defined $found) {
1097 #print " could not find $component in $dirname\n";
1102 $real_path=~ s+/$++;
1103 #print " -> found $real_path\n";
1108 # Performs a case-insensitive search for the specified file in the
1110 # $line is the line number that should be referenced when an error occurs
1111 # $filename is the file we are looking for
1112 # $dirname is the directory of the file containing the '#include' directive
1113 # if '"' was used, it is an empty string otherwise
1114 # $project and $target specify part of the include path
1115 sub get_real_include_name
1123 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1124 # This is not a relative path, we cannot make any check
1125 my $warning="path:$filename";
1126 if (!defined $warnings{$warning}) {
1127 $warnings{$warning}="1";
1128 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1129 print STDERR "$line: $filename\n";
1132 # Here's how we proceed:
1133 # - split the filename we look for into its components
1134 # - then for each directory in the include path
1135 # - trace the directory components starting from that directory
1136 # - if we fail to find a match at any point then continue with
1137 # the next directory in the include path
1138 # - otherwise, rejoice, our quest is over.
1139 my @file_components=split /[\/\\]+/, $filename;
1140 #print " Searching for $filename from @$project[$P_PATH]\n";
1143 if ($dirname ne "") {
1144 # This is an 'include ""' -> look in dirname first.
1145 #print " in $dirname (include \"\")\n";
1146 $real_filename=search_from($dirname,\@file_components);
1147 if (defined $real_filename) {
1148 return $real_filename;
1151 my $project_settings=@$project[$P_SETTINGS];
1152 foreach $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1153 my $dirname=$include;
1155 if (!is_absolute($dirname)) {
1156 $dirname="@$project[$P_PATH]$dirname";
1158 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1160 #print " in $dirname\n";
1161 $real_filename=search_from("$dirname",\@file_components);
1162 if (defined $real_filename) {
1163 return $real_filename;
1166 my $dotdotpath=@$project[$P_PATH];
1167 $dotdotpath =~ s/[^\/]+/../g;
1168 foreach $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1169 my $dirname=$include;
1171 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1172 #print " in $dirname (global setting)\n";
1173 $real_filename=search_from("$dirname",\@file_components);
1174 if (defined $real_filename) {
1175 return $real_filename;
1179 $filename =~ s+\\\\+/+g; # in include ""
1180 $filename =~ s+\\+/+g; # in include <> !
1181 if ($opt_lower_include) {
1182 return lc "$filename";
1188 # 'Parses' a source file and fixes constructs that would not work with
1189 # Winelib. The parsing is rather simple and not all non-portable features
1190 # are corrected. The most important feature that is corrected is the case
1191 # and path separator of '#include' directives. This requires that each
1192 # source file be associated to a project & target so that the proper
1193 # include path is used.
1194 # Also note that the include path is relative to the directory in which the
1195 # compiler is run, i.e. that of the project, not to that of the file.
1201 $filename="@$project[$P_PATH]$filename";
1202 if (! -e $filename) {
1206 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1207 my $dirname=dirname($filename);
1209 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1213 print " $filename\n";
1214 #FIXME:assuming that because there is a .bak file, this is what we want is
1215 #probably flawed. Or is it???
1216 if (! -e "$filename.bak") {
1217 if (!copy("$filename","$filename.bak")) {
1218 print STDERR "error: unable to make a backup of $filename:\n";
1219 print STDERR " $!\n";
1223 if (!open(FILEI,"$filename.bak")) {
1224 print STDERR "error: unable to open $filename.bak for reading:\n";
1225 print STDERR " $!\n";
1228 if (!open(FILEO,">$filename")) {
1229 print STDERR "error: unable to open $filename for writing:\n";
1230 print STDERR " $!\n";
1235 my $rc_block_depth=0;
1236 my $rc_textinclude_state=0;
1240 if ($is_rc and !$is_mfc and /^(\s*\#\s*include\s*)\"afxres\.h\"/) {
1241 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1242 # the RC files it generates (even in non-MFC projects). So we replace
1243 # it with 'winres.h' its very close standard cousin so that non MFC
1244 # projects can compile in Wine without the MFC sources. This does not
1245 # harm VC but it will put 'afxres.h' back the next time the file is
1247 my $warning="mfc:afxres.h";
1248 if (!defined $warnings{$warning}) {
1249 $warnings{$warning}="1";
1250 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winres.h'\n";
1251 print STDERR "warning: the above warning is issued only once\n";
1253 print FILEO "/* winemaker: $1\"afxres.h\" */\n";
1254 print FILEO "$1\"winres.h\"$'";
1256 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1257 my $from_file=($2 eq "<"?"":$dirname);
1258 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1259 print FILEO "$1$2$real_include_name$4$'";
1260 $modified|=($real_include_name ne $3);
1261 } elsif (/^(\s*\#\s*pragma\s*pack\s*\((\s*push\s*,?)?\s*)(\w*)(\s*\))/) {
1262 my $pragma_header=$1;
1264 my $pragma_trailer=$4;
1265 #print "$pragma_header$size$pragma_trailer$'";
1266 #print "pragma push: size=$size\n";
1267 print FILEO "/* winemaker: $pragma_header$size$pragma_trailer */\n";
1269 if ($size eq "pop") {
1270 print FILEO "#include <poppack.h>$'";
1271 } elsif ($size eq "1") {
1272 print FILEO "#include <pshpack1.h>$'";
1273 } elsif ($size eq "2") {
1274 print FILEO "#include <pshpack2.h>$'";
1275 } elsif ($size eq "8") {
1276 print FILEO "#include <pshpack8.h>$'";
1277 } elsif ($size eq "4" or $size eq "") {
1278 print FILEO "#include <pshpack4.h>$'";
1280 my $warning="pack:$size";
1281 if (!defined $warnings{$warning}) {
1282 $warnings{$warning}="1";
1283 print STDERR "warning: assuming that the value of $size is 4 in\n";
1284 print STDERR "$line: $pragma_header$size$pragma_trailer\n";
1285 print STDERR "warning: the above warning is issued only once\n";
1287 print FILEO "#include <pshpack4.h>$'";
1291 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]+)([\">]?)/) {
1292 my $from_file=($5 eq "<"?"":$dirname);
1293 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
1294 print FILEO "$1$5$real_include_name$7$'";
1295 $modified|=($real_include_name ne $6);
1296 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1297 my $from_file=($2 eq "<"?"":$dirname);
1298 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1299 print FILEO "$1$2$real_include_name$4$'";
1300 $modified|=($real_include_name ne $3);
1301 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
1302 $rc_textinclude_state=1;
1304 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
1305 print FILEO "$1winres.h$2$'";
1307 } elsif (/^\s*BEGIN(\W.*)?$/) {
1308 $rc_textinclude_state|=2;
1311 } elsif (/^\s*END(\W.*)?$/) {
1312 $rc_textinclude_state=0;
1313 if ($rc_block_depth>0) {
1326 if ($opt_backup == 0 or $modified == 0) {
1327 if (!unlink("$filename.bak")) {
1328 print STDERR "error: unable to delete $filename.bak:\n";
1329 print STDERR " $!\n";
1335 # Analyzes each source file in turn to find and correct issues
1336 # that would cause it not to compile.
1339 print "Fixing the source files...\n";
1340 foreach $project (@projects) {
1341 foreach $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
1342 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1345 foreach $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
1346 fix_file($source,$project,$target);
1361 # Generates a target's .spec file
1362 sub generate_spec_file
1366 my $project_settings=$_[2];
1368 my $basename=@$target[$T_NAME];
1369 $basename =~ s+\.so$++;
1370 if (@$target[$T_FLAGS] & $TF_WRAP) {
1371 $basename =~ s+^lib++;
1372 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1373 $basename.="_wrapper";
1376 if (!open(FILEO,">$path$basename.spec")) {
1377 print STDERR "error: could not open \"$path$basename.spec\" for writing\n";
1378 print STDERR " $!\n";
1382 my $canon=canonize($basename);
1383 print FILEO "name $canon\n";
1384 print FILEO "type win32\n";
1385 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1386 print FILEO "mode guiexe\n";
1387 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1388 print FILEO "mode cuiexe\n";
1390 print FILEO "mode dll\n";
1392 if (defined @$target[$T_INIT] and ((@$target[$T_FLAGS] & $TF_WRAP) == 0)) {
1393 print FILEO "init @$target[$T_INIT]\n";
1395 if (@{@$target[$T_SOURCES_RC]} > 0) {
1396 if (@{@$target[$T_SOURCES_RC]} > 1) {
1397 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";
1399 my $rcname=@{@$target[$T_SOURCES_RC]}[0];
1400 $rcname =~ s+\.rc$++i;
1401 print FILEO "rsrc $rcname.res\n";
1405 foreach $library (@{$global_settings[$T_IMPORTS]}) {
1406 if (!defined $imports{$library}) {
1407 print FILEO "import $library\n";
1408 $imports{$library}=1;
1411 if (defined $project_settings) {
1412 foreach $library (@{@$project_settings[$T_IMPORTS]}) {
1413 if (!defined $imports{$library}) {
1414 print FILEO "import $library\n";
1415 $imports{$library}=1;
1419 foreach $library (@{@$target[$T_IMPORTS]}) {
1420 if (!defined $imports{$library}) {
1421 print FILEO "import $library\n";
1422 $imports{$library}=1;
1426 # Don't forget to export the 'Main' function for wrapped executables,
1427 # except for MFC ones!
1428 if (@$target[$T_FLAGS] == $TF_WRAP) {
1429 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1430 print FILEO "\n@ stdcall @$target[$T_INIT](long long ptr long) @$target[$T_INIT]\n";
1431 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1432 print FILEO "\n@ stdcall @$target[$T_INIT](long ptr ptr) @$target[$T_INIT]\n";
1434 print FILEO "\n@ stdcall @$target[$T_INIT](ptr long ptr) @$target[$T_INIT]\n";
1442 # Generates a target's wrapper file
1443 sub generate_wrapper_file
1448 if (!defined $templates{"wrapper.c"}) {
1449 print STDERR "winemaker: internal error: No template called 'wrapper.c'\n";
1453 if (!open(FILEO,">$path@$target[$T_NAME]_wrapper.c")) {
1454 print STDERR "error: unable to open \"$path$basename.c\" for writing:\n";
1455 print STDERR " $!\n";
1458 my $app_name="\"@$target[$T_NAME]\"";
1459 my $app_type=(@$target[$T_TYPE]==$TT_GUIEXE?"GUIEXE":"CUIEXE");
1460 my $app_init=(@$target[$T_TYPE]==$TT_GUIEXE?"\"WinMain\"":"\"main\"");
1461 my $app_mfc=(@$target[$T_FLAGS] & $TF_MFC?"\"mfc\"":NULL);
1462 foreach $line (@{$templates{"wrapper.c"}}) {
1463 $line =~ s/\#\#WINEMAKER_APP_NAME\#\#/$app_name/;
1464 $line =~ s/\#\#WINEMAKER_APP_TYPE\#\#/$app_type/;
1465 $line =~ s/\#\#WINEMAKER_APP_INIT\#\#/$app_init/;
1466 $line =~ s/\#\#WINEMAKER_APP_MFC\#\#/$app_mfc/;
1473 # A convenience function to generate all the lists (defines,
1474 # C sources, C++ source, etc.) in the Makefile
1484 printf FILEO "%-22s=",$name;
1486 if (defined $list) {
1487 foreach $item (@$list) {
1489 if (defined $data) {
1490 $value=&$data($item);
1496 print FILEO " $value";
1499 print FILEO " \\\n\t\t\t$value";
1510 # Generates a project's Makefile.in and all the target files
1511 sub generate_project_files
1514 my $project_settings=@$project[$P_SETTINGS];
1518 # Then sort the targets and separate the libraries from the programs
1519 foreach $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
1520 if (@$target[$T_TYPE] == $TT_DLL) {
1521 push @dll_list,$target;
1523 push @exe_list,$target;
1526 @$project[$P_TARGETS]=[];
1527 push @{@$project[$P_TARGETS]}, @dll_list;
1528 push @{@$project[$P_TARGETS]}, @exe_list;
1530 if (!open(FILEO,">@$project[$P_PATH]Makefile.in")) {
1531 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile.in\" for writing\n";
1532 print STDERR " $!\n";
1536 print FILEO "### Generated by Winemaker\n";
1539 print FILEO "### Generic autoconf variables\n\n";
1540 generate_list("TOPSRCDIR",1,[ "\@top_srcdir\@" ]);
1541 generate_list("TOPOBJDIR",1,[ "." ]);
1542 generate_list("SRCDIR",1,[ "\@srcdir\@" ]);
1543 generate_list("VPATH",1,[ "\@srcdir\@" ]);
1545 if (@$project[$P_PATH] eq "") {
1546 # This is the main project. It is also responsible for recursively
1547 # calling the other projects
1548 generate_list("SUBDIRS",1,\@projects,sub
1550 if ($_[0] != \@main_project) {
1551 my $subdir=@{$_[0]}[$P_PATH];
1555 # Eliminating the main project by returning undefined!
1558 if (@{@$project[$P_TARGETS]} > 0) {
1559 generate_list("DLLS",1,\@dll_list,sub
1561 return @{$_[0]}[$T_NAME];
1563 generate_list("EXES",1,\@exe_list,sub
1565 return "@{$_[0]}[$T_NAME]";
1567 print FILEO "\n\n\n";
1569 print FILEO "### Global settings\n\n";
1570 # Make it so that the project-wide settings override the global settings
1571 generate_list("DEFINES",0,@$project_settings[$T_DEFINES],sub
1575 generate_list("",1,$global_settings[$T_DEFINES],sub
1579 generate_list("INCLUDE_PATH",$no_extra,@$project_settings[$T_INCLUDE_PATH],sub
1583 generate_list("",1,$global_settings[$T_INCLUDE_PATH],sub
1585 if ($_[0] !~ /^-I/) {
1588 if (is_absolute($')) {
1591 return "-I\$(TOPSRCDIR)/$'";
1593 generate_list("LIBRARY_PATH",$no_extra,@$project_settings[$T_LIBRARY_PATH],sub
1597 generate_list("",1,$global_settings[$T_LIBRARY_PATH],sub
1599 if ($_[0] !~ /^-L/) {
1602 if (is_absolute($')) {
1605 return "-L\$(TOPSRCDIR)/$'";
1607 generate_list("LIBRARIES",$no_extra,@$project_settings[$T_LIBRARIES],sub
1611 generate_list("",1,$global_settings[$T_LIBRARIES],sub
1617 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
1618 @{@$project_settings[$T_SOURCES_CXX]}+
1619 @{@$project_settings[$T_SOURCES_RC]};
1620 my $no_extra=($extra_source_count == 0);
1622 print FILEO "### Extra source lists\n\n";
1623 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
1624 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
1625 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
1627 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
1628 print FILEO "\n\n\n";
1631 # Iterate over all the targets...
1632 foreach $target (@{@$project[$P_TARGETS]}) {
1633 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
1634 my $canon=canonize("@$target[$T_NAME]");
1636 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
1637 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
1638 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
1639 my $basename=@$target[$T_NAME];
1640 $basename =~ s+\.so$++;
1641 if (@$target[$T_FLAGS] & $TF_WRAP) {
1642 $basename =~ s+^lib++;
1643 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1644 $basename.="_wrapper";
1646 generate_list("${canon}_SPEC_SRCS",1,[ "$basename.spec"]);
1647 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH],sub
1651 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES],sub
1655 generate_list("${canon}_DEPENDS",1,@$target[$T_DEPENDS],sub
1660 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(EXTRA_OBJS)"]);
1661 print FILEO "\n\n\n";
1663 print FILEO "### Global source lists\n\n";
1664 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
1666 my $canon=canonize(@{$_[0]}[$T_NAME]);
1668 return "\$(${canon}_C_SRCS)";
1671 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
1673 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
1675 my $canon=canonize(@{$_[0]}[$T_NAME]);
1677 return "\$(${canon}_CXX_SRCS)";
1680 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
1682 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
1684 my $canon=canonize(@{$_[0]}[$T_NAME]);
1686 return "\$(${canon}_RC_SRCS)";
1689 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
1691 generate_list("SPEC_SRCS",1,@$project[$P_TARGETS],sub
1693 my $canon=canonize(@{$_[0]}[$T_NAME]);
1695 return "\$(${canon}_SPEC_SRCS)";
1698 print FILEO "\n\n\n";
1700 print FILEO "### Generic autoconf targets\n\n";
1701 print FILEO "all: ";
1702 if (@$project[$P_PATH] eq "") {
1703 print FILEO "\$(SUBDIRS)";
1705 if (@{@$project[$P_TARGETS]} > 0) {
1706 print FILEO "\$(DLLS) \$(EXES:%=%.so)";
1709 print FILEO "\@MAKE_RULES\@\n";
1711 print FILEO "install::\n";
1712 if (@$project[$P_PATH] eq "") {
1713 # This is the main project. It is also responsible for recursively
1714 # calling the other projects
1715 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) install) || exit 1; done\n";
1717 if (@{@$project[$P_TARGETS]} > 0) {
1718 print FILEO "\tfor i in \$(EXES); do \$(INSTALL_PROGRAM) \$\$i \$(bindir); done\n";
1719 print FILEO "\tfor i in \$(EXES:%=%.so) \$(DLLS); do \$(INSTALL_LIBRARY) \$\$i \$(libdir); done\n";
1722 print FILEO "uninstall::\n";
1723 if (@$project[$P_PATH] eq "") {
1724 # This is the main project. It is also responsible for recursively
1725 # calling the other projects
1726 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) uninstall) || exit 1; done\n";
1728 if (@{@$project[$P_TARGETS]} > 0) {
1729 print FILEO "\tfor i in \$(EXES); do \$(RM) \$(bindir)/\$\$i;done\n";
1730 print FILEO "\tfor i in \$(EXES:%=%.so) \$(DLLS); do \$(RM) \$(libdir)/\$\$i;done\n";
1732 print FILEO "\n\n\n";
1734 if (@{@$project[$P_TARGETS]} > 0) {
1735 print FILEO "### Target specific build rules\n\n";
1736 foreach $target (@{@$project[$P_TARGETS]}) {
1737 my $canon=canonize("@$target[$T_NAME]");
1739 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.tmp.o): \$(${canon}_OBJS)\n";
1740 print FILEO "\t\$(LDCOMBINE) \$(${canon}_OBJS) -o \$\@\n";
1741 print FILEO "\t-\$(STRIP) \$(STRIPFLAGS) \$\@\n";
1743 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.spec.c): \$(${canon}_SPEC_SRCS:.spec) \$(${canon}_SPEC_SRCS:.spec=.tmp.o) \$(${canon}_RC_SRCS:.rc=.res)\n";
1744 print FILEO "\t\$(WINEBUILD) -fPIC \$(${canon}_LIBRARY_PATH) \$(WINE_LIBRARY_PATH) -sym \$(${canon}_SPEC_SRCS:.spec=.tmp.o) -o \$\@ -spec \$(${canon}_SPEC_SRCS)\n";
1746 my $t_name=@$target[$T_NAME];
1747 if (@$target[$T_TYPE]!=$TT_DLL) {
1750 print FILEO "$t_name: \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_OBJS) \$(${canon}_DEPENDS) \n";
1751 print FILEO "\t\$(LDSHARED) \$(LDDLLFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_LIBRARY_PATH) \$(${canon}_LIBRARIES:%=-l%) \$(DLL_LINK) \$(LIBS)\n";
1752 if (@$target[$T_TYPE] ne $TT_DLL) {
1753 print FILEO "\ttest -e @$target[$T_NAME] || \$(LN_S) \$(WINE) @$target[$T_NAME]\n";
1760 foreach $target (@{@$project[$P_TARGETS]}) {
1761 generate_spec_file(@$project[$P_PATH],$target,$project_settings);
1762 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1763 generate_wrapper_file(@$project[$P_PATH],$target);
1769 # Perform the replacements in the template configure files
1770 # Return 1 for success, 0 for failure
1771 sub generate_configure
1774 my $a_source_file=$_[1];
1776 if (!defined $templates{$filename}) {
1777 if ($filename ne "configure") {
1778 print STDERR "winemaker: internal error: No template called '$filename'\n";
1783 if (!open(FILEO,">$filename")) {
1784 print STDERR "error: unable to open \"$filename\" for writing:\n";
1785 print STDERR " $!\n";
1788 foreach $line (@{$templates{$filename}}) {
1789 if ($line =~ /^\#\#WINEMAKER_PROJECTS\#\#$/) {
1790 foreach $project (@projects) {
1791 print FILEO "@$project[$P_PATH]Makefile\n";
1794 $line =~ s+\#\#WINEMAKER_SOURCE\#\#+$a_source_file+;
1795 $line =~ s+\#\#WINEMAKER_NEEDS_MFC\#\#+$needs_mfc+;
1803 sub generate_generic
1807 if (!defined $templates{$filename}) {
1808 print STDERR "winemaker: internal error: No template called '$filename'\n";
1811 if (!open(FILEO,">$filename")) {
1812 print STDERR "error: unable to open \"$filename\" for writing:\n";
1813 print STDERR " $!\n";
1816 foreach $line (@{$templates{$filename}}) {
1823 # Generates the global files:
1827 sub generate_global_files
1829 generate_generic("Make.rules.in");
1831 # Get the name of a source file for configure.in
1833 search_a_file: foreach $project (@projects) {
1834 foreach $target (@{@$project[$P_TARGETS]}, @$project[$P_SETTINGS]) {
1835 $a_source_file=@{@$target[$T_SOURCES_C]}[0];
1836 if (!defined $a_source_file) {
1837 $a_source_file=@{@$target[$T_SOURCES_CXX]}[0];
1839 if (!defined $a_source_file) {
1840 $a_source_file=@{@$target[$T_SOURCES_RC]}[0];
1842 if (defined $a_source_file) {
1843 $a_source_file="@$project[$P_PATH]$a_source_file";
1849 generate_configure("configure.in",$a_source_file);
1850 unlink("configure");
1851 if (generate_configure("configure",$a_source_file) == 0) {
1854 # Add execute permission to configure for whoever has the right to read it
1855 my @st=stat("configure");
1858 $mode|=($mode & 0444) >>2;
1859 chmod($mode,"configure");
1861 print "warning: could not generate the configure script. You need to run autoconf\n";
1867 sub generate_read_templates
1872 if (/^--- ((\w\.?)+) ---$/) {
1874 if (defined $templates{$filename}) {
1875 print STDERR "winemaker: internal error: There is more than one template for $filename\n";
1879 $templates{$filename}=$file;
1881 } elsif (defined $file) {
1888 # This is where we finally generate files. In fact this method does not
1889 # do anything itself but calls the methods that do the actual work.
1892 print "Generating project files...\n";
1893 generate_read_templates();
1894 generate_global_files();
1896 foreach $project (@projects) {
1897 my $path=@$project[$P_PATH];
1904 generate_project_files($project);
1917 $opt_lower=$OPT_LOWER_UPPERCASE;
1918 $opt_lower_include=1;
1920 # $opt_single_target=<undefined>
1921 $opt_target_type=$TT_GUIEXE;
1923 $opt_is_interactive=$OPT_ASK_NO;
1924 $opt_ask_project_options=$OPT_ASK_NO;
1925 $opt_ask_target_options=$OPT_ASK_NO;
1926 $opt_no_generated_files=0;
1937 project_init(\@main_project,"");
1940 my $arg=shift @ARGV;
1942 if ($arg eq "--nobanner") {
1944 } elsif ($arg eq "--backup") {
1946 } elsif ($arg eq "--nobackup") {
1948 } elsif ($arg eq "--single-target") {
1949 $opt_single_target=shift @ARGV;
1950 } elsif ($arg eq "--lower-none") {
1951 $opt_lower=$OPT_LOWER_NONE;
1952 } elsif ($arg eq "--lower-all") {
1953 $opt_lower=$OPT_LOWER_ALL;
1954 } elsif ($arg eq "--lower-uppercase") {
1955 $opt_lower=$OPT_LOWER_UPPERCASE;
1956 } elsif ($arg eq "--lower-include") {
1957 $opt_lower_include=1;
1958 } elsif ($arg eq "--nolower-include") {
1959 $opt_lower_include=0;
1960 } elsif ($arg eq "--generated-files") {
1961 $opt_no_generated_files=0;
1962 } elsif ($arg eq "--nogenerated-files") {
1963 $opt_no_generated_files=1;
1965 } elsif ($arg =~ /^-D/) {
1966 push @{$global_settings[$T_DEFINES]},$arg;
1967 } elsif ($arg =~ /^-I/) {
1968 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
1969 } elsif ($arg =~ /^-L/) {
1970 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
1971 } elsif ($arg =~ /^-i/) {
1972 push @{$global_settings[$T_IMPORTS]},$';
1973 } elsif ($arg =~ /^-l/) {
1974 push @{$global_settings[$T_LIBRARIES]},$';
1976 # 'Source'-based method options
1977 } elsif ($arg eq "--dll") {
1978 $opt_target_type=$TT_DLL;
1979 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
1980 $opt_target_type=$TT_GUIEXE;
1981 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
1982 $opt_target_type=$TT_CUIEXE;
1983 } elsif ($arg eq "--interactive") {
1984 $opt_is_interactive=$OPT_ASK_YES;
1985 $opt_ask_project_options=$OPT_ASK_YES;
1986 $opt_ask_target_options=$OPT_ASK_YES;
1987 } elsif ($arg eq "--wrap") {
1988 print STDERR "warning: --wrap no longer supported, ignoring the option\n";
1989 #$opt_flags|=$TF_WRAP;
1990 } elsif ($arg eq "--nowrap") {
1991 $opt_flags&=~$TF_WRAP;
1992 } elsif ($arg eq "--mfc") {
1993 $opt_flags|=$TF_MFC;
1994 #$opt_flags|=$TF_MFC|$TF_WRAP;
1996 } elsif ($arg eq "--nomfc") {
1997 $opt_flags&=~($TF_MFC|$TF_WRAP);
2002 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2003 print STDERR "Unknown option: $arg\n";
2010 if ($opt_no_banner == 0 or defined $usage) {
2011 print "Winemaker $version\n";
2012 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2015 if (defined $usage) {
2016 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup]\n";
2017 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2018 print STDERR " [--lower-include|--nolower-include]\n";
2019 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2020 print STDERR " [--wrap|--nowrap] [--mfc|--nomfc]\n";
2021 print STDERR " [-Dmacro[=defn]] [-Idir] [-Ldir] [-idll] [-llibrary]\n";
2022 print STDERR " [--interactive] [--single-target name]\n";
2023 print STDERR " [--generated-files|--nogenerated-files]\n";
2027 # Fix the file and directory names
2028 fix_file_and_directory_names(".");
2030 # Scan the sources to identify the projects and targets
2033 # Create targets for wrappers, etc.
2034 postprocess_targets();
2036 # Fix the source files
2039 # Generate the Makefile and the spec file
2040 if (! $opt_no_generated_files) {
2046 --- configure.in ---
2047 dnl Process this file with autoconf to produce a configure script.
2048 dnl Author: Michael Patra <micky@marie.physik.tu-berlin.de>
2049 dnl <patra@itp1.physik.tu-berlin.de>
2050 dnl Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2052 AC_REVISION([configure.in 1.00])
2053 AC_INIT(##WINEMAKER_SOURCE##)
2055 NEEDS_MFC=##WINEMAKER_NEEDS_MFC##
2057 dnl **** Command-line arguments ****
2061 dnl **** Check for some programs ****
2070 AC_PATH_PROG(LDCONFIG, ldconfig, true, /sbin:/usr/sbin:$PATH)
2072 dnl **** Check for some libraries ****
2074 dnl Check for -lm for BeOS
2075 AC_CHECK_LIB(m,sqrt)
2076 dnl Check for -li386 for NetBSD and OpenBSD
2077 AC_CHECK_LIB(i386,i386_set_ldt)
2078 dnl Check for -lossaudio for NetBSD
2079 AC_CHECK_LIB(ossaudio,_oss_ioctl)
2080 dnl Check for -lw for Solaris
2081 AC_CHECK_LIB(w,iswalnum)
2082 dnl Check for -lnsl for Solaris
2083 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))
2084 dnl Check for -lsocket for Solaris
2085 AC_CHECK_FUNCS(connect,,AC_CHECK_LIB(socket,connect))
2086 dnl Check for -lxpg4 for FreeBSD
2087 AC_CHECK_LIB(xpg4,setrunelocale)
2088 dnl Check for -lmmap for OS/2
2089 AC_CHECK_LIB(mmap,mmap)
2090 dnl Check for openpty
2091 AC_CHECK_FUNCS(openpty,,
2092 AC_CHECK_LIB(util,openpty,
2093 AC_DEFINE(HAVE_OPENPTY)
2097 AC_CHECK_HEADERS(dlfcn.h,
2098 AC_CHECK_FUNCS(dlopen,
2099 AC_DEFINE(HAVE_DL_API),
2100 AC_CHECK_LIB(dl,dlopen,
2101 AC_DEFINE(HAVE_DL_API)
2107 dnl **** Check which curses lib to use ***
2108 if test "$CURSES" = "yes"
2110 AC_CHECK_HEADERS(ncurses.h)
2111 if test "$ac_cv_header_ncurses_h" = "yes"
2113 AC_CHECK_LIB(ncurses,waddch)
2115 if test "$ac_cv_lib_ncurses_waddch" = "yes"
2117 AC_CHECK_LIB(ncurses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2118 AC_CHECK_LIB(ncurses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2120 AC_CHECK_HEADERS(curses.h)
2121 if test "$ac_cv_header_curses_h" = "yes"
2123 AC_CHECK_LIB(curses,waddch)
2124 if test "$ac_cv_lib_curses_waddch" = "yes"
2126 AC_CHECK_LIB(curses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2127 AC_CHECK_LIB(curses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2133 dnl **** If ln -s doesn't work, use cp instead ****
2134 if test "$ac_cv_prog_LN_S" = "ln -s"; then : ; else LN_S=cp ; fi
2136 dnl **** Check for gcc strength-reduce bug ****
2138 if test "x${GCC}" = "xyes"
2140 AC_CACHE_CHECK( "for gcc strength-reduce bug", ac_cv_c_gcc_strength_bug,
2143 static int Array[[3]];
2146 for(i=0; i<B; i++) Array[[i]] = i - 3;
2147 exit( Array[[1]] != -2 );
2149 ac_cv_c_gcc_strength_bug="no",
2150 ac_cv_c_gcc_strength_bug="yes",
2151 ac_cv_c_gcc_strength_bug="yes") )
2152 if test "$ac_cv_c_gcc_strength_bug" = "yes"
2154 CFLAGS="$CFLAGS -fno-strength-reduce"
2158 dnl **** Check for underscore on external symbols ****
2160 AC_CACHE_CHECK("whether external symbols need an underscore prefix",
2161 ac_cv_c_extern_prefix,
2163 LIBS="conftest_asm.s $LIBS"
2164 cat > conftest_asm.s <<EOF
2169 AC_TRY_LINK([extern int ac_test;],[if (ac_test) return 1],
2170 ac_cv_c_extern_prefix="yes",ac_cv_c_extern_prefix="no")
2172 if test "$ac_cv_c_extern_prefix" = "yes"
2174 AC_DEFINE(NEED_UNDERSCORE_PREFIX)
2177 dnl **** Check for working dll ****
2181 AC_CACHE_CHECK("whether we can build a Linux dll",
2183 [saved_cflags=$CFLAGS
2184 CFLAGS="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0,-Bsymbolic"
2185 AC_TRY_LINK(,[return 1],ac_cv_c_dll_linux="yes",ac_cv_c_dll_linux="no")
2186 CFLAGS=$saved_cflags
2188 if test "$ac_cv_c_dll_linux" = "yes"
2190 LDSHARED="\$(CC) -shared -Wl,-rpath,\$(libdir)"
2191 LDDLLFLAGS="-Wl,-Bsymbolic"
2193 AC_CACHE_CHECK(whether we can build a UnixWare (Solaris) dll,
2194 ac_cv_c_dll_unixware,
2195 [saved_cflags=$CFLAGS
2196 CFLAGS="$CFLAGS -fPIC -Wl,-G,-h,conftest.so.1.0,-B,symbolic"
2197 AC_TRY_LINK(,[return 1],ac_cv_c_dll_unixware="yes",ac_cv_c_dll_unixware="no")
2198 CFLAGS=$saved_cflags
2200 if test "$ac_cv_c_dll_unixware" = "yes"
2202 LDSHARED="\$(CC) -Wl,-G \$(SONAME:%=-Wl,h,\$(libdir)/%)"#FIXME: why SONAME here?
2203 LDDLLFLAGS="-Wl,-B,symbolic"
2205 AC_CACHE_CHECK("whether we can build a NetBSD dll",
2207 [saved_cflags=$CFLAGS
2208 CFLAGS="$CFLAGS -fPIC -Wl,-Bshareable,-Bforcearchive"
2209 AC_TRY_LINK(,[return 1],ac_cv_c_dll_netbsd="yes",ac_cv_c_dll_netbsd="no")
2210 CFLAGS=$saved_cflags
2212 if test "$ac_cv_c_dll_netbsd" = "yes"
2214 LDSHARED="\$(CC) -Wl,-Bshareable,-Bforcearchive"
2215 LDDLLFLAGS="" #FIXME
2219 if test "$ac_cv_c_dll_linux" = "no" -a "$ac_cv_c_dll_unixware" = "no" -a "$ac_cv_c_dll_netbsd" = "no"
2221 AC_MSG_ERROR([Could not find how to build a dynamically linked library])
2224 CFLAGS="$CFLAGS -fPIC"
2225 DLL_LINK="\$(WINE_LIBRARY_PATH) \$(LIBRARY_PATH) \$(LIBRARIES:%=-l%) -lwine -lwine_unicode"
2229 AC_SUBST(LDDLLFLAGS)
2231 dnl *** check for the need to define __i386__
2233 AC_CACHE_CHECK("whether we need to define __i386__",ac_cv_cpp_def_i386,
2234 AC_EGREP_CPP(yes,[#if (defined(i386) || defined(__i386)) && !defined(__i386__)
2237 ac_cv_cpp_def_i386="yes", ac_cv_cpp_def_i386="no"))
2238 if test "$ac_cv_cpp_def_i386" = "yes"
2240 CFLAGS="$CFLAGS -D__i386__"
2243 dnl $GCC is set by autoconf
2245 if test "$GCC" = "yes"
2247 GCC_NO_BUILTIN="-fno-builtin"
2249 AC_SUBST(GCC_NO_BUILTIN)
2251 dnl **** Test Winelib-related features of the C++ compiler
2253 if test "x${GCC}" = "xyes"
2255 OLDCXXFLAGS="$CXXFLAGS";
2256 CXXFLAGS="-fpermissive";
2257 AC_CACHE_CHECK("for g++ -fpermissive option", has_gxx_permissive,
2259 for (int i=0;i<2;i++);
2262 [has_gxx_permissive="yes"],
2263 [has_gxx_permissive="no"])
2265 CXXFLAGS="-fno-for-scope";
2266 AC_CACHE_CHECK("for g++ -fno-for-scope option", has_gxx_no_for_scope,
2268 for (int i=0;i<2;i++);
2271 [has_gxx_no_for_scope="yes"],
2272 [has_gxx_no_for_scope="no"])
2274 CXXFLAGS="$OLDCXXFLAGS";
2275 if test "$has_gxx_permissive" = "yes"
2277 CXXFLAGS="$CXXFLAGS -fpermissive"
2279 if test "$has_gxx_no_for_scope" = "yes"
2281 CXXFLAGS="$CXXFLAGS -fno-for-scope"
2286 dnl **** Test Winelib-related features of the C compiler
2289 dnl **** Macros for finding a headers/libraries in a collection of places
2291 dnl AC_PATH_HEADER(variable,header,action-if-not-found,default-locations)
2292 dnl Note that the above may set variable to an empty value if the header is
2293 dnl already in the include path
2294 AC_DEFUN(AC_PATH_HEADER,[
2295 AC_MSG_CHECKING([for $2])
2296 AC_CACHE_VAL(ac_cv_path_$1,
2299 ac_dummy="ifelse([$4], , :/usr/local/include, [$4])"
2300 save_CPPFLAGS="$CPPFLAGS"
2301 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2302 for ac_dir in $ac_dummy; do
2304 if test -z "$ac_dir"
2306 CPPFLAGS="$save_CPPFLAGS"
2308 CPPFLAGS="-I$ac_dir $save_CPPFLAGS"
2310 AC_TRY_COMPILE([#include <$2>],,ac_found=1;ac_cv_path_$1="$ac_dir";break)
2312 CPPFLAGS="$save_CPPFLAGS"
2313 ifelse([$3],,,[if test -z "$ac_found"
2320 if test -n "$ac_found" -o -n "[$]$1"
2322 AC_MSG_RESULT([$]$1)
2329 dnl AC_PATH_LIBRARY(variable,libraries,extra libs,action-if-not-found,default-locations)
2330 AC_DEFUN(AC_PATH_LIBRARY,[
2331 AC_MSG_CHECKING([for $2])
2332 AC_CACHE_VAL(ac_cv_path_$1,
2335 ac_dummy="ifelse([$5], , :/usr/local/lib, [$5])"
2337 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2338 for ac_dir in $ac_dummy; do
2340 if test -z "$ac_dir"
2342 LIBS="$2 $3 $save_LIBS"
2344 LIBS="-L$ac_dir $2 $3 $save_LIBS"
2346 AC_TRY_LINK(,,ac_found=1;ac_cv_path_$1="$ac_dir";break)
2349 ifelse([$4],,,[if test -z "$ac_found"
2356 if test -n "$ac_found" -o -n "[$]$1"
2358 AC_MSG_RESULT([$]$1)
2365 dnl **** Try to find where winelib is located ****
2367 WINE_INCLUDE_ROOT="";
2368 WINE_INCLUDE_PATH="";
2369 WINE_LIBRARY_ROOT="";
2370 WINE_LIBRARY_PATH="";
2377 [ --with-wine=DIR the Wine package (or sources) is in DIR],
2378 [if test "$withval" != "no"; then
2379 WINE_ROOT="$withval";
2386 if test -n "$WINE_ROOT"
2388 WINE_INCLUDE_ROOT="$WINE_ROOT/include";
2389 WINE_LIBRARY_ROOT="$WINE_ROOT";
2390 WINE_TOOL_PATH="$WINE_ROOT:$WINE_ROOT/bin:$WINE_ROOT/tools/wrc:$WINE_ROOT/tools/winebuild:$PATH";
2393 AC_ARG_WITH(wine-includes,
2394 [ --with-wine-includes=DIR the Wine includes are in DIR],
2395 [if test "$withval" != "no"; then
2396 WINE_INCLUDES="$withval";
2400 if test -n "$WINE_INCLUDES"
2402 WINE_INCLUDE_ROOT="$WINE_INCLUDES";
2405 AC_ARG_WITH(wine-libraries,
2406 [ --with-wine-libraries=DIR the Wine libraries are in DIR],
2407 [if test "$withval" != "no"; then
2408 WINE_LIBRARIES="$withval";
2412 if test -n "$WINE_LIBRARIES"
2414 WINE_LIBRARY_ROOT="$WINE_LIBRARIES";
2417 AC_ARG_WITH(wine-tools,
2418 [ --with-wine-tools=DIR the Wine tools are in DIR],
2419 [if test "$withval" != "no"; then
2420 WINE_TOOLS="$withval";
2424 if test -n "$WINE_TOOLS"
2426 WINE_TOOL_PATH="$WINE_TOOLS:$WINE_TOOLS/wrc:$WINE_TOOLS/winebuild";
2429 if test -z "$WINE_INCLUDE_ROOT"
2431 WINE_INCLUDE_ROOT=":/usr/include/wine:/usr/local/include/wine:/opt/wine/include";
2433 AC_PATH_HEADER(WINE_INCLUDE_ROOT,windef.h,[
2434 AC_MSG_ERROR([Could not find the Wine includes])
2435 ],$WINE_INCLUDE_ROOT)
2436 if test -n "$WINE_INCLUDE_ROOT"
2438 WINE_INCLUDE_PATH="-I$WINE_INCLUDE_ROOT"
2440 WINE_INCLUDE_PATH=""
2443 if test -z "$WINE_LIBRARY_ROOT"
2445 WINE_LIBRARY_ROOT=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib";
2447 WINE_LIBRARY_ROOT="$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/lib";
2449 AC_PATH_LIBRARY(WINE_LIBRARY_ROOT,[-lwine],[-lutil],[
2450 AC_MSG_ERROR([Could not find the Wine libraries (libwine.so)])
2451 ],$WINE_LIBRARY_ROOT)
2452 if test -n "$WINE_LIBRARY_ROOT"
2454 WINE_LIBRARY_PATH="-L$WINE_LIBRARY_ROOT"
2456 WINE_LIBRARY_PATH=""
2458 AC_PATH_LIBRARY(LIBNTDLL_PATH,[-lntdll],[$WINE_LIBRARY_PATH -lwine -lwine_unicode -lncurses -ldl -lutil],[
2459 AC_MSG_ERROR([Could not find the Wine libraries (libntdll.so)])
2460 ],[$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/dlls])
2461 if test -n "$LIBNTDLL_PATH" -a "-L$LIBNTDLL_PATH" != "$WINE_LIBRARY_PATH"
2463 WINE_LIBRARY_PATH="$WINE_LIBRARY_PATH -L$LIBNTDLL_PATH"
2466 if test -z "$WINE_TOOL_PATH"
2468 WINE_TOOL_PATH="$PATH:/usr/local/bin:/opt/wine/bin";
2470 AC_PATH_PROG(WINE,wine,,$WINE_TOOL_PATH)
2473 AC_MSG_ERROR([Could not find Wine's wine tool])
2475 AC_PATH_PROG(WINEBUILD,winebuild,,$WINE_TOOL_PATH)
2476 if test -z "$WINEBUILD"
2478 AC_MSG_ERROR([Could not find Wine's winebuild tool])
2480 AC_PATH_PROG(WRC,wrc,,$WINE_TOOL_PATH)
2483 AC_MSG_ERROR([Could not find Wine's wrc tool])
2486 AC_SUBST(WINE_INCLUDE_PATH)
2487 AC_SUBST(WINE_LIBRARY_PATH)
2489 dnl **** Try to find where the MFC are located ****
2492 if test "x$NEEDS_MFC" = "x1"
2494 ATL_INCLUDE_ROOT="";
2495 ATL_INCLUDE_PATH="";
2496 MFC_INCLUDE_ROOT="";
2497 MFC_INCLUDE_PATH="";
2498 MFC_LIBRARY_ROOT="";
2499 MFC_LIBRARY_PATH="";
2502 [ --with-mfc=DIR the MFC package (or sources) is in DIR],
2503 [if test "$withval" != "no"; then
2504 MFC_ROOT="$withval";
2511 if test -n "$MFC_ROOT"
2513 ATL_INCLUDE_ROOT="$MFC_ROOT";
2514 MFC_INCLUDE_ROOT="$MFC_ROOT";
2515 MFC_LIBRARY_ROOT="$MFC_ROOT";
2518 AC_ARG_WITH(atl-includes,
2519 [ --with-atl-includes=DIR the ATL includes are in DIR],
2520 [if test "$withval" != "no"; then
2521 ATL_INCLUDES="$withval";
2525 if test -n "$ATL_INCLUDES"
2527 ATL_INCLUDE_ROOT="$ATL_INCLUDES";
2530 AC_ARG_WITH(mfc-includes,
2531 [ --with-mfc-includes=DIR the MFC includes are in DIR],
2532 [if test "$withval" != "no"; then
2533 MFC_INCLUDES="$withval";
2537 if test -n "$MFC_INCLUDES"
2539 MFC_INCLUDE_ROOT="$MFC_INCLUDES";
2542 AC_ARG_WITH(mfc-libraries,
2543 [ --with-mfc-libraries=DIR the MFC libraries are in DIR],
2544 [if test "$withval" != "no"; then
2545 MFC_LIBRARIES="$withval";
2549 if test -n "$MFC_LIBRARIES"
2551 MFC_LIBRARY_ROOT="$MFC_LIBRARIES";
2554 OLDCPPFLAGS="$CPPFLAGS"
2555 dnl FIXME: We should not have defines in any of the include paths
2556 CPPFLAGS="$WINE_INCLUDE_PATH -I$WINE_INCLUDE_ROOT/mixedcrt -D_DLL -D_MT $CPPFLAGS"
2557 ATL_INCLUDE_PATH="-I\$(WINE_INCLUDE_ROOT)/mixedcrt -D_DLL -D_MT"
2558 if test -z "$ATL_INCLUDE_ROOT"
2560 ATL_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/atl:/usr/include/atl:/usr/local/include/atl:/opt/mfc/include/atl:/opt/atl/include"
2562 ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT:$ATL_INCLUDE_ROOT/atl:$ATL_INCLUDE_ROOT/atl/include"
2564 AC_PATH_HEADER(ATL_INCLUDE_ROOT,atldef.h,[
2565 AC_MSG_ERROR([Could not find the ATL includes])
2566 ],$ATL_INCLUDE_ROOT)
2567 if test -n "$ATL_INCLUDE_ROOT"
2569 ATL_INCLUDE_PATH="$ATL_INCLUDE_PATH -I$ATL_INCLUDE_ROOT"
2572 MFC_INCLUDE_PATH="$ATL_INCLUDE_PATH"
2573 if test -z "$MFC_INCLUDE_ROOT"
2575 MFC_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/mfc:/usr/include/mfc:/usr/local/include/mfc:/opt/mfc/include/mfc:/opt/mfc/include"
2577 MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT:$MFC_INCLUDE_ROOT/mfc:$MFC_INCLUDE_ROOT/mfc/include"
2579 AC_PATH_HEADER(MFC_INCLUDE_ROOT,afx.h,[
2580 AC_MSG_ERROR([Could not find the MFC includes])
2581 ],$MFC_INCLUDE_ROOT)
2582 if test -n "$MFC_INCLUDE_ROOT" -a "$ATL_INCLUDE_ROOT" != "$MFC_INCLUDE_ROOT"
2584 MFC_INCLUDE_PATH="$MFC_INCLUDE_PATH -I$MFC_INCLUDE_ROOT"
2586 CPPFLAGS="$OLDCPPFLAGS"
2588 if test -z "$MFC_LIBRARY_ROOT"
2590 MFC_LIBRARY_ROOT=":$WINE_LIBRARY_ROOT:/usr/lib/mfc:/usr/local/lib:/usr/local/lib/mfc:/opt/mfc/lib";
2592 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT:$MFC_LIBRARY_ROOT/lib:$MFC_LIBRARY_ROOT/mfc/src";
2594 AC_PATH_LIBRARY(MFC_LIBRARY_ROOT,[-lmfc],[$WINE_LIBRARY_PATH -lwine -lwine_unicode],[
2595 AC_MSG_ERROR([Could not find the MFC library])
2596 ],$MFC_LIBRARY_ROOT)
2597 if test -n "$MFC_LIBRARY_ROOT" -a "$MFC_LIBRARY_ROOT" != "$WINE_LIBRARY_ROOT"
2599 MFC_LIBRARY_PATH="-L$MFC_LIBRARY_ROOT"
2604 AC_SUBST(ATL_INCLUDE_PATH)
2605 AC_SUBST(MFC_INCLUDE_PATH)
2606 AC_SUBST(MFC_LIBRARY_PATH)
2611 dnl **** Generate output files ****
2613 MAKE_RULES=Make.rules
2614 AC_SUBST_FILE(MAKE_RULES)
2618 ##WINEMAKER_PROJECTS##
2622 echo "Configure finished. Do 'make' to build the project."
2625 dnl Local Variables:
2626 dnl comment-start: "dnl "
2628 dnl comment-start-skip: "\\bdnl\\b\\s *"
2629 dnl compile-command: "autoconf"
2631 --- Make.rules.in ---
2632 # Copyright 2000 Francois Gouget for CodeWeavers
2633 # fgouget@codeweavers.com
2635 # Global rules shared by all makefiles -*-Makefile-*-
2637 # Each individual makefile must define the following variables:
2638 # WINE_INCLUDE_ROOT: Wine's headers location
2639 # WINE_LIBRARY_ROOT: Wine's libraries location
2640 # TOPOBJDIR : top-level object directory
2641 # SRCDIR : source directory for this module
2643 # Each individual makefile may define the following additional variables:
2645 # SUBDIRS : subdirectories that contain a Makefile
2646 # DLLS : WineLib libraries to be built
2647 # EXES : WineLib executables to be built
2649 # CEXTRA : extra c flags (e.g. '-Wall')
2650 # CXXEXTRA : extra c++ flags (e.g. '-Wall')
2651 # WRCEXTRA : extra wrc flags (e.g. '-p _SysRes')
2652 # DEFINES : defines (e.g. -DSTRICT)
2653 # INCLUDE_PATH : additional include path
2654 # LIBRARY_PATH : additional library path
2655 # LIBRARIES : additional Unix libraries to link with
2657 # C_SRCS : C sources for the module
2658 # CXX_SRCS : C++ sources for the module
2659 # RC_SRCS : resource source files
2660 # SPEC_SRCS : interface definition files
2665 WINE_INCLUDE_ROOT = @WINE_INCLUDE_ROOT@
2666 WINE_INCLUDE_PATH = @WINE_INCLUDE_PATH@
2667 WINE_LIBRARY_ROOT = @WINE_LIBRARY_ROOT@
2668 WINE_LIBRARY_PATH = @WINE_LIBRARY_PATH@
2672 ATL_INCLUDE_ROOT = @ATL_INCLUDE_ROOT@
2673 ATL_INCLUDE_PATH = @ATL_INCLUDE_PATH@
2674 MFC_INCLUDE_ROOT = @MFC_INCLUDE_ROOT@
2675 MFC_INCLUDE_PATH = @MFC_INCLUDE_PATH@
2676 MFC_LIBRARY_ROOT = @MFC_LIBRARY_ROOT@
2677 MFC_LIBRARY_PATH = @MFC_LIBRARY_PATH@
2679 # First some useful definitions
2685 CXXFLAGS = @CXXFLAGS@
2686 OPTIONS = @OPTIONS@ -D_REENTRANT -DWINELIB
2687 X_CFLAGS = @X_CFLAGS@
2689 XLIB = @X_PRE_LIBS@ @XLIB@ @X_EXTRA_LIBS@
2690 DLL_LINK = @DLL_LINK@
2691 LIBS = @LIBS@ $(LIBRARY_PATH)
2696 DIVINCL = -I$(SRCDIR) $(WINE_INCLUDE_PATH) $(INCLUDE_PATH)
2697 ALLCFLAGS = $(DIVINCL) $(CFLAGS) $(CEXTRA) $(OPTIONS) $(X_CFLAGS) $(DEFINES)
2698 ALLCXXFLAGS = $(DIVINCL) $(CXXFLAGS) $(CXXEXTRA) $(OPTIONS) $(X_CFLAGS) $(DEFINES)
2700 LDSHARED = @LDSHARED@
2701 LDDLLFLAGS= @LDDLLFLAGS@
2703 STRIPFLAGS= --strip-unneeded
2708 WINEBUILD = @WINEBUILD@
2713 # Installation infos
2716 INSTALL_PROGRAM = @INSTALL_PROGRAM@
2717 INSTALL_DATA = @INSTALL_DATA@
2719 exec_prefix = @exec_prefix@
2726 CLEAN_FILES = *.o *.a *.so \\\#*\\\# *~ *% .\\\#* *.orig *.rej \
2727 *.spec.c y.tab.c y.tab.h lex.yy.c core
2729 OBJS = $(SPEC_SRCS:.spec=.spec.o) $(C_SRCS:.c=.o) $(CXX_SRCS:.cpp=.o)
2733 .SUFFIXES: .C .cpp .CPP .cxx .CXX .rc .RC .res .tmp.o .spec .spec.c .spec.o
2736 $(CC) -c $(ALLCFLAGS) -o $@ $<
2739 $(CC) -c $(ALLCFLAGS) -o $@ $<
2742 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2745 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2748 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2751 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2754 $(WRC) $(WRCFLAGS) $(WRCEXTRA) $(DIVINCL) -o $@ $<
2757 $(WRC) $(WRCFLAGS) $(WRCEXTRA) $(DIVINCL) -o $@ $<
2759 .PHONY: all install uninstall clean distclean depend dummy
2761 # 'all' target first in case the enclosing Makefile didn't define any target
2765 # Rules for makefile
2767 Makefile: Makefile.in $(TOPSRCDIR)/configure
2768 @echo Makefile is older than $?, please rerun $(TOPSRCDIR)/configure
2771 # Rules for cleaning
2773 $(SUBDIRS:%=%/__clean__): dummy
2774 cd `dirname $@` && $(MAKE) clean
2776 $(EXTRASUBDIRS:%=%/__clean__): dummy
2777 -cd `dirname $@` && $(RM) $(CLEAN_FILES)
2779 clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
2780 $(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(EXES) $(EXES:%=%.so) $(DLLS)
2782 # Rules for installing
2784 $(SUBDIRS:%=%/__install__): dummy
2785 cd `dirname $@` && $(MAKE) install
2787 $(SUBDIRS:%=%/__uninstall__): dummy
2788 cd `dirname $@` && $(MAKE) uninstall
2797 # End of global rules
2800 * Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2804 #include <windows.h>
2809 * Describe the wrapped application
2813 * This is either CUIEXE for a console based application or
2814 * GUIEXE for a regular windows application.
2816 #define APP_TYPE ##WINEMAKER_APP_TYPE##
2819 * This is the application library's base name, i.e. 'hello' if the
2820 * library is called 'libhello.so'.
2822 static char* appName = ##WINEMAKER_APP_NAME##;
2825 * This is the name of the application's Windows module. If left NULL
2826 * then appName is used.
2828 static char* appModule = NULL;
2831 * This is the application's entry point. This is usually "WinMain" for a
2832 * GUIEXE and 'main' for a CUIEXE application.
2834 static char* appInit = ##WINEMAKER_APP_INIT##;
2837 * This is either non-NULL for MFC-based applications and is the name of the
2838 * MFC's module. This is the module in which we will take the 'WinMain'
2841 static char* mfcModule = ##WINEMAKER_APP_MFC##;
2846 * Implement the main.
2849 #if APP_TYPE == GUIEXE
2850 typedef int WINAPI (*WinMainFunc)(HINSTANCE hInstance, HINSTANCE hPrevInstance,
2851 PSTR szCmdLine, int iCmdShow);
2853 typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp);
2856 #if APP_TYPE == GUIEXE
2857 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
2858 PSTR szCmdLine, int iCmdShow)
2860 int WINAPI Main(int argc, char** argv, char** envp)
2864 HINSTANCE hApp,hMFC,hMain;
2869 /* Load the application's library */
2870 libName=(char*)malloc(strlen(appName)+5+3+1);
2871 /* FIXME: we should get the wrapper's path and use that as the base for
2874 sprintf(libName,"./lib%s.so",appName);
2875 appLibrary=dlopen(libName,RTLD_NOW);
2876 if (appLibrary==NULL) {
2877 sprintf(libName,"lib%s.so",appName);
2878 appLibrary=dlopen(libName,RTLD_NOW);
2880 if (appLibrary==NULL) {
2881 char format[]="Could not load the %s library:\r\n%s";
2886 msg=(char*)malloc(strlen(format)+strlen(libName)+strlen(error));
2887 sprintf(msg,format,libName,error);
2888 MessageBox(NULL,msg,"dlopen error",MB_OK);
2893 /* Then if this application is MFC based, load the MFC module */
2894 /* FIXME: I'm not sure this is really necessary */
2895 if (mfcModule!=NULL) {
2896 hMFC=LoadLibrary(mfcModule);
2898 char format[]="Could not load the MFC module %s (%d)";
2901 msg=(char*)malloc(strlen(format)+strlen(mfcModule)+11);
2902 sprintf(msg,format,mfcModule,GetLastError());
2903 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
2907 /* MFC is a special case: the WinMain is in the MFC library,
2908 * instead of the application's library.
2915 /* Load the application's module */
2916 if (appModule==NULL) {
2919 hApp=LoadLibrary(appModule);
2921 char format[]="Could not load the application's module %s (%d)";
2924 msg=(char*)malloc(strlen(format)+strlen(appModule)+11);
2925 sprintf(msg,format,appModule,GetLastError());
2926 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
2929 } else if (hMain==NULL) {
2933 /* Get the address of the application's entry point */
2934 appMain=(WinMainFunc*)GetProcAddress(hMain, appInit);
2935 if (appMain==NULL) {
2936 char format[]="Could not get the address of %s (%d)";
2939 msg=(char*)malloc(strlen(format)+strlen(appInit)+11);
2940 sprintf(msg,format,appInit,GetLastError());
2941 MessageBox(NULL,msg,"GetProcAddress error",MB_OK);
2946 /* And finally invoke the application's entry point */
2947 #if APP_TYPE == GUIEXE
2948 retcode=(*((WinMainFunc)appMain))(hApp,hPrevInstance,szCmdLine,iCmdShow);
2950 retcode=(*((MainFunc)appMain))(argc,argv,envp);
2953 /* Cleanup and done */
2958 dlclose(appLibrary);