blob: 9a23d0f249e9a1855961609a962429e239400ca5 [file] [log] [blame]
Francois Gouget755bb922000-11-05 05:23:39 +00001#!/usr/bin/perl -w
2
3# Copyright 2000 Francois Gouget for CodeWeavers
4# fgouget@codeweavers.com
5#
François Gouget38b3ac52001-01-11 20:17:42 +00006my $version="0.5.5";
Francois Gouget755bb922000-11-05 05:23:39 +00007
8use Cwd;
9use File::Basename;
10use File::Copy;
11
12
13
14#####
15#
16# Options
17#
18#####
19
20# The following constants define what we do with the case of filenames
21
22##
23# Never rename a file to lowercase
24my $OPT_LOWER_NONE=0;
25
26##
27# Rename all files to lowercase
28my $OPT_LOWER_ALL=1;
29
30##
31# Rename only files that are all uppercase to lowercase
32my $OPT_LOWER_UPPERCASE=2;
33
34
35# The following constants define whether to ask questions or not
36
37##
38# No (synonym of never)
39my $OPT_ASK_NO=0;
40
41##
42# Yes (always)
43my $OPT_ASK_YES=1;
44
45##
46# Skip the questions till the end of this scope
47my $OPT_ASK_SKIP=-1;
48
49
50# General options
51
52##
François Gougetc1f016b2001-01-10 22:43:21 +000053# This is the directory in which winemaker will operate.
54my $opt_work_dir;
55
56##
Francois Gouget755bb922000-11-05 05:23:39 +000057# Make a backup of the files
58my $opt_backup;
59
60##
61# Defines which files to rename
62my $opt_lower;
63
Francois Gougeta106edb2000-11-10 22:29:11 +000064##
65# If we don't find the file referenced by an include, lower it
66my $opt_lower_include;
67
Francois Gouget755bb922000-11-05 05:23:39 +000068
69# Options for the 'Source' method
70
71##
72# Specifies that we have only one target so that all sources relate
73# to this target. By default this variable is left undefined which
74# means winemaker should try to find out by itself what the targets
75# are. If not undefined then this contains the name of the default
76# target (without the extension).
77my $opt_single_target;
78
79##
80# If '$opt_single_target' has been specified then this is the type of
81# that target. Otherwise it specifies whether the default target type
82# is guiexe or cuiexe.
83my $opt_target_type;
84
85##
86# Contains the default set of flags to be used when creating a new target.
87my $opt_flags;
88
89##
90# If true then winemaker should ask questions to the user as it goes
91# along.
92my $opt_is_interactive;
93my $opt_ask_project_options;
94my $opt_ask_target_options;
95
96##
Francois Gougeta106edb2000-11-10 22:29:11 +000097# If false then winemaker should not generate any file, i.e.
98# no makefiles, but also no .spec files, no configure.in, etc.
99my $opt_no_generated_files;
Francois Gouget755bb922000-11-05 05:23:39 +0000100
101##
102# Specifies not to print the banner if set.
103my $opt_no_banner;
104
105
106
107#####
108#
109# Target modelization
110#
111#####
112
113# The description of a target is stored in an array. The constants
114# below identify what is stored at each index of the array.
115
116##
117# This is the name of the target.
118my $T_NAME=0;
119
120##
121# Defines the type of target we want to build. See the TT_xxx
122# constants below
123my $T_TYPE=1;
124
125##
126# Defines the target's enty point, i.e. the function that is called
127# on startup.
128my $T_INIT=2;
129
130##
131# This is a bitfield containing flags refining the way the target
132# should be handled. See the TF_xxx constants below
Francois Gougetbe859592000-11-15 22:12:20 +0000133my $T_FLAGS=3;
Francois Gouget755bb922000-11-05 05:23:39 +0000134
135##
136# This is a reference to an array containing the list of the
137# resp. C, C++, RC, other (.h, .hxx, etc.) source files.
Francois Gougetbe859592000-11-15 22:12:20 +0000138my $T_SOURCES_C=4;
139my $T_SOURCES_CXX=5;
140my $T_SOURCES_RC=6;
141my $T_SOURCES_MISC=7;
Francois Gouget755bb922000-11-05 05:23:39 +0000142
143##
144# This is a reference to an array containing the list of macro
145# definitions
Francois Gougetbe859592000-11-15 22:12:20 +0000146my $T_DEFINES=8;
Francois Gouget755bb922000-11-05 05:23:39 +0000147
148##
149# This is a reference to an array containing the list of directory
150# names that constitute the include path
Francois Gougetbe859592000-11-15 22:12:20 +0000151my $T_INCLUDE_PATH=9;
Francois Gouget755bb922000-11-05 05:23:39 +0000152
153##
154# Same as T_INCLUDE_PATH but for the library search path
Francois Gougetbe859592000-11-15 22:12:20 +0000155my $T_LIBRARY_PATH=10;
Francois Gouget755bb922000-11-05 05:23:39 +0000156
157##
Francois Gougetbe859592000-11-15 22:12:20 +0000158# The list of Windows libraries to import
159my $T_IMPORTS=11;
160
161##
162# The list of Unix libraries to link with
163my $T_LIBRARIES=12;
Francois Gouget755bb922000-11-05 05:23:39 +0000164
165##
166# The list of dependencies between targets
Francois Gougetbe859592000-11-15 22:12:20 +0000167my $T_DEPENDS=13;
Francois Gouget755bb922000-11-05 05:23:39 +0000168
169
170# The following constants define the recognized types of target
171
172##
173# This is not a real target. This type of target is used to collect
174# the sources that don't seem to belong to any other target. Thus no
175# real target is generated for them, we just put the sources of the
176# fake target in the global source list.
177my $TT_SETTINGS=0;
178
179##
180# For executables in the windows subsystem
181my $TT_GUIEXE=1;
182
183##
184# For executables in the console subsystem
185my $TT_CUIEXE=2;
186
187##
188# For dynamically linked libraries
189my $TT_DLL=3;
190
191
192# The following constants further refine how the target should be handled
193
194##
195# This target needs a wrapper
196my $TF_WRAP=1;
197
198##
199# This target is a wrapper
200my $TF_WRAPPER=2;
201
202##
203# This target is an MFC-based target
204my $TF_MFC=4;
205
206##
207# Initialize a target:
208# - set the target type to TT_SETTINGS, i.e. no real target will
209# be generated.
210sub target_init
211{
212 my $target=$_[0];
213
214 @$target[$T_TYPE]=$TT_SETTINGS;
215 # leaving $T_INIT undefined
216 @$target[$T_FLAGS]=$opt_flags;
217 @$target[$T_SOURCES_C]=[];
218 @$target[$T_SOURCES_CXX]=[];
219 @$target[$T_SOURCES_RC]=[];
220 @$target[$T_SOURCES_MISC]=[];
221 @$target[$T_DEFINES]=[];
222 @$target[$T_INCLUDE_PATH]=[];
223 @$target[$T_LIBRARY_PATH]=[];
224 @$target[$T_IMPORTS]=[];
Francois Gougetbe859592000-11-15 22:12:20 +0000225 @$target[$T_LIBRARIES]=[];
Francois Gouget755bb922000-11-05 05:23:39 +0000226 @$target[$T_DEPENDS]=[];
227}
228
229sub get_default_init
230{
231 my $type=$_[0];
232 if ($type == $TT_GUIEXE) {
233 return "WinMain";
234 } elsif ($type == $TT_CUIEXE) {
235 return "main";
236 } elsif ($type == $TT_DLL) {
237 return "DllMain";
238 }
239}
240
241
242
243#####
244#
245# Project modelization
246#
247#####
248
249# First we have the notion of project. A project is described by an
250# array (since we don't have structs in perl). The constants below
251# identify what is stored at each index of the array.
252
253##
254# This is the path in which this project is located. In other
255# words, this is the path to the Makefile.
256my $P_PATH=0;
257
258##
259# This index contains a reference to an array containing the project-wide
260# settings. The structure of that arrray is actually identical to that of
261# a regular target since it can also contain extra sources.
262my $P_SETTINGS=1;
263
264##
265# This index contains a reference to an array of targets for this
266# project. Each target describes how an executable or library is to
267# be built. For each target this description takes the same form as
268# that of the project: an array. So this entry is an array of arrays.
269my $P_TARGETS=2;
270
271##
272# Initialize a project:
273# - set the project's path
274# - initialize the target list
275# - create a default target (will be removed later if unnecessary)
276sub project_init
277{
278 my $project=$_[0];
279 my $path=$_[1];
280
281 my $project_settings=[];
282 target_init($project_settings);
283
284 @$project[$P_PATH]=$path;
285 @$project[$P_SETTINGS]=$project_settings;
286 @$project[$P_TARGETS]=[];
287}
288
289
290
291#####
292#
293# Global variables
294#
295#####
296
Francois Gouget755bb922000-11-05 05:23:39 +0000297my %warnings;
298
299my %templates;
300
301##
302# Contains the list of all projects. This list tells us what are
303# the subprojects of the main Makefile and where we have to generate
304# Makefiles.
305my @projects=();
306
307##
308# This is the main project, i.e. the one in the "." directory.
309# It may well be empty in which case the main Makefile will only
310# call out subprojects.
311my @main_project;
312
313##
314# Contains the defaults for the include path, etc.
315# We store the defaults as if this were a target except that we only
316# exploit the defines, include path, library path, library list and misc
317# sources fields.
318my @global_settings;
319
320##
321# If one of the projects requires the MFc then we set this global variable
322# to true so that configure asks the user to provide a path tothe MFC
323my $needs_mfc=0;
324
325
326
327#####
328#
329# Utility functions
330#
331#####
332
333##
334# Cleans up a name to make it an acceptable Makefile
335# variable name.
336sub canonize
337{
338 my $name=$_[0];
339
340 $name =~ tr/a-zA-Z0-9_/_/c;
341 return $name;
342}
343
344##
345# Returns true is the specified pathname is absolute.
346# Note: pathnames that start with a variable '$' or
347# '~' are considered absolute.
348sub is_absolute
349{
350 my $path=$_[0];
351
352 return ($path =~ /^[\/~\$]/);
353}
354
355##
356# Performs a binary search looking for the specified item
357sub bsearch
358{
359 my $array=$_[0];
360 my $item=$_[1];
361 my $last=@{$array}-1;
362 my $first=0;
363
364 while ($first<=$last) {
365 my $index=int(($first+$last)/2);
366 my $cmp=@$array[$index] cmp $item;
367 if ($cmp<0) {
368 $first=$index+1;
369 } elsif ($cmp>0) {
370 $last=$index-1;
371 } else {
372 return $index;
373 }
374 }
375}
376
377
378
379#####
380#
381# 'Source'-based Project analysis
382#
383#####
384
385##
386# Allows the user to specify makefile and target specific options
387# - target: the structure in which to store the results
388# - options: the string containing the options
389sub source_set_options
390{
391 my $target=$_[0];
392 my $options=$_[1];
393
394 #FIXME: we must deal with escaping of stuff and all
395 foreach $option (split / /,$options) {
396 if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
397 push @{@$target[$T_DEFINES]},$option;
398 } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
399 push @{@$target[$T_INCLUDE_PATH]},$option;
400 } elsif ($option =~ /^-L/) {
401 push @{@$target[$T_LIBRARY_PATH]},$option;
Francois Gougetbe859592000-11-15 22:12:20 +0000402 } elsif ($option =~ /^-i/) {
Francois Gouget755bb922000-11-05 05:23:39 +0000403 push @{@$target[$T_IMPORTS]},$';
Francois Gougetbe859592000-11-15 22:12:20 +0000404 } elsif ($option =~ /^-l/) {
405 push @{@$target[$T_LIBRARIES]},$';
Francois Gougeta106edb2000-11-10 22:29:11 +0000406 } elsif (@$target[$T_TYPE] != $TT_DLL and
Francois Gouget755bb922000-11-05 05:23:39 +0000407 $option =~ /^--wrap/) {
Francois Gougetbe859592000-11-15 22:12:20 +0000408 print STDERR "warning: --wrap no longer supported, ignoring\n";
409 #@$target[$T_FLAGS]|=$TF_WRAP;
Francois Gougeta106edb2000-11-10 22:29:11 +0000410 } elsif (@$target[$T_TYPE] != $TT_DLL and
Francois Gouget82747b72000-11-25 01:38:39 +0000411 $option =~ /^--nowrap/) {
Francois Gougeta106edb2000-11-10 22:29:11 +0000412 @$target[$T_FLAGS]&=~$TF_WRAP;
413 } elsif ($option =~ /^--mfc/) {
Francois Gouget755bb922000-11-05 05:23:39 +0000414 @$target[$T_FLAGS]|=$TF_MFC;
Francois Gougetbe859592000-11-15 22:12:20 +0000415 #if (@$target[$T_TYPE] != $TT_DLL) {
416 # @$target[$T_FLAGS]|=$TF_WRAP;
417 #}
Francois Gouget82747b72000-11-25 01:38:39 +0000418 } elsif ($option =~ /^--nomfc/) {
419 @$target[$T_FLAGS]&=~$TF_MFC;
420 #@$target[$T_FLAGS]&=~($TF_MFC|$TF_WRAP);
Francois Gouget755bb922000-11-05 05:23:39 +0000421 } else {
Francois Gouget3af251e2000-11-30 20:36:04 +0000422 print STDERR "error: unknown option \"$option\"\n";
423 return 0;
Francois Gouget755bb922000-11-05 05:23:39 +0000424 }
425 }
Francois Gouget3af251e2000-11-30 20:36:04 +0000426 return 1;
Francois Gouget755bb922000-11-05 05:23:39 +0000427}
428
429##
430# Scans the specified directory to:
431# - see if we should create a Makefile in this directory. We normally do
432# so if we find a project file and sources
433# - get a list of targets for this directory
434# - get the list of source files
435sub source_scan_directory
436{
437 # a reference to the parent's project
438 my $parent_project=$_[0];
439 # the full relative path to the current directory, including a
440 # trailing '/', or an empty string if this is the top level directory
441 my $path=$_[1];
442 # the name of this directory, including a trailing '/', or an empty
443 # string if this is the top level directory
444 my $dirname=$_[2];
445
446 # reference to the project for this directory. May not be used
447 my $project;
448 # list of targets found in the 'current' directory
449 my %targets;
450 # list of sources found in the current directory
451 my @sources_c=();
452 my @sources_cxx=();
453 my @sources_rc=();
454 my @sources_misc=();
455 # true if this directory contains a Windows project
456 my $has_win_project=0;
457 # If we don't find any executable/library then we might make up targets
458 # from the list of .dsp/.mak files we find since they usually have the
459 # same name as their target.
460 my @dsp_files=();
461 my @mak_files=();
462
463 if (defined $opt_single_target or $dirname eq "") {
464 # Either there is a single target and thus a single project,
465 # or we are in the top level directory for which a project
466 # already exists
467 $project=$parent_project;
468 } else {
469 $project=[];
470 project_init($project,$path);
471 }
Francois Gougeta106edb2000-11-10 22:29:11 +0000472 my $project_settings=@$project[$P_SETTINGS];
Francois Gouget755bb922000-11-05 05:23:39 +0000473
474 # First find out what this directory contains:
475 # collect all sources, targets and subdirectories
476 my $directory=get_directory_contents($path);
477 foreach $dentry (@$directory) {
478 if ($dentry =~ /^\./) {
479 next;
480 }
481 my $fullentry="$path$dentry";
482 if (-d "$fullentry") {
483 if ($dentry =~ /^(Release|Debug)/i) {
484 # These directories are often used to store the object files and the
485 # resulting executable/library. They should not contain anything else.
486 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
487 foreach $candidate (@candidates) {
488 if ($candidate =~ s/\.exe$//i) {
489 $targets{$candidate}=1;
490 } elsif ($candidate =~ s/^(.*)\.dll$/lib$1.so/i) {
491 $targets{$candidate}=1;
492 }
493 }
Francois Gouget4ec10592000-12-02 20:12:45 +0000494 } elsif ($dentry =~ /^include/i) {
495 # This directory must contain headers we're going to need
496 push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
Francois Gouget755bb922000-11-05 05:23:39 +0000497 } else {
498 # Recursively scan this directory. Any source file that cannot be
499 # attributed to a project in one of the subdirectories will be attributed
500 # to this project.
501 source_scan_directory($project,"$fullentry/","$dentry/");
502 }
503 } elsif (-f "$fullentry") {
504 if ($dentry =~ s/\.exe$//i) {
505 $targets{$dentry}=1;
506 } elsif ($dentry =~ s/^(.*)\.dll$/lib$1.so/i) {
507 $targets{$dentry}=1;
508 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.spec\.c$/) {
509 push @sources_c,"$dentry";
510 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
Francois Gougeta106edb2000-11-10 22:29:11 +0000511 if ($dentry =~ /^stdafx.cpp$/i) {
512 push @sources_misc,"$dentry";
Francois Gouget82747b72000-11-25 01:38:39 +0000513 @$project_settings[$T_FLAGS]|=$TF_MFC;
Francois Gougeta106edb2000-11-10 22:29:11 +0000514 } else {
515 push @sources_cxx,"$dentry";
516 }
Francois Gouget755bb922000-11-05 05:23:39 +0000517 } elsif ($dentry =~ /\.rc$/i) {
518 push @sources_rc,"$dentry";
519 } elsif ($dentry =~ /\.(h|hxx|inl|rc2|dlg)$/i) {
520 push @sources_misc,"$dentry";
Francois Gougeta106edb2000-11-10 22:29:11 +0000521 if ($dentry =~ /^stdafx.h$/i) {
Francois Gouget82747b72000-11-25 01:38:39 +0000522 @$project_settings[$T_FLAGS]|=$TF_MFC;
Francois Gougeta106edb2000-11-10 22:29:11 +0000523 }
Francois Gouget755bb922000-11-05 05:23:39 +0000524 } elsif ($dentry =~ /\.dsp$/i) {
525 push @dsp_files,"$dentry";
526 $has_win_project=1;
527 } elsif ($dentry =~ /\.mak$/i) {
528 push @mak_files,"$dentry";
529 $has_win_project=1;
530 } elsif ($dentry =~ /^makefile/i) {
531 $has_win_project=1;
532 }
533 }
534 }
535 closedir(DIRECTORY);
536
537 # If we have a single target then all we have to do is assign
538 # all the sources to it and we're done
539 # FIXME: does this play well with the --interactive mode?
540 if ($opt_single_target) {
541 my $target=@{@$project[$P_TARGETS]}[0];
542 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
543 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
544 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
545 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
546 return;
547 }
548
Francois Gouget755bb922000-11-05 05:23:39 +0000549 my $source_count=@sources_c+@sources_cxx+@sources_rc+
550 @{@$project_settings[$T_SOURCES_C]}+
551 @{@$project_settings[$T_SOURCES_CXX]}+
552 @{@$project_settings[$T_SOURCES_RC]};
553 if ($source_count == 0) {
554 # A project without real sources is not a project, get out!
555 if ($project!=$parent_project) {
556 $parent_settings=@$parent_project[$P_SETTINGS];
557 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
558 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
559 }
560 return;
561 }
562 #print "targets=",%targets,"\n";
563 #print "target_count=$target_count\n";
564 #print "has_win_project=$has_win_project\n";
565 #print "dirname=$dirname\n";
566
567 my $target_count;
568 if (($has_win_project != 0) or ($dirname eq "")) {
569 # Deal with cases where we could not find any executable/library, and
570 # thus have no target, although we did find some sort of windows project.
571 $target_count=keys %targets;
572 if ($target_count == 0) {
573 # Try to come up with a target list based on .dsp/.mak files
574 my $prj_list;
575 if (@dsp_files > 0) {
576 $prj_list=\@dsp_files;
577 } else {
578 $prj_list=\@mak_files;
579 }
580 foreach $filename (@$prj_list) {
581 $filename =~ s/\.(dsp|mak)$//i;
582 if ($opt_target_type == $TT_DLL) {
583 $filename = "lib$filename.so";
584 }
585 $targets{$filename}=1;
586 }
587 $target_count=keys %targets;
588 if ($target_count == 0) {
589 # Still nothing, try the name of the directory
590 my $name;
591 if ($dirname eq "") {
592 # Bad luck, this is the top level directory!
593 $name=(split /\//, cwd)[-1];
594 } else {
595 $name=$dirname;
596 # Remove the trailing '/'. Also eliminate whatever is after the last
597 # '.' as it is likely to be meaningless (.orig, .new, ...)
598 $name =~ s+(/|\.[^.]*)$++;
599 if ($name eq "src") {
600 # 'src' is probably a subdirectory of the real project directory.
601 # Try again with the parent (if any).
602 my $parent=$path;
603 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
604 $name=$parent;
605 } else {
606 $name=(split /\//, cwd)[-1];
607 }
608 }
609 }
610 $name =~ s+(/|\.[^.]*)$++;
611 if ($opt_target_type == $TT_DLL) {
612 $name = "lib$name.so";
613 }
614 $targets{$name}=1;
615 }
616 }
617
618 # Ask confirmation to the user if he wishes so
619 if ($opt_is_interactive == $OPT_ASK_YES) {
620 my $target_list=join " ",keys %targets;
Francois Gougetfb5b5902000-11-30 20:34:39 +0000621 print "\n*** In ",($path?$path:"./"),"\n";
Francois Gougeta106edb2000-11-10 22:29:11 +0000622 print "* winemaker found the following list of (potential) targets\n";
623 print "* $target_list\n";
624 print "* Type enter to use it as is, your own comma-separated list of\n";
625 print "* targets, 'none' to assign the source files to a parent directory,\n";
626 print "* or 'ignore' to ignore everything in this directory tree.\n";
627 print "* Target list:\n";
Francois Gouget755bb922000-11-05 05:23:39 +0000628 $target_list=<STDIN>;
629 chomp $target_list;
630 if ($target_list eq "") {
631 # Keep the target list as is, i.e. do nothing
632 } elsif ($target_list eq "none") {
633 # Empty the target list
634 undef %targets;
635 } elsif ($target_list eq "ignore") {
636 # Ignore this subtree altogether
637 return;
638 } else {
639 undef %targets;
640 foreach $target (split /,/,$target_list) {
641 $target =~ s+^\s*++;
642 $target =~ s+\s*$++;
643 # Also accept .exe and .dll as a courtesy
644 $target =~ s+(.*)\.dll$+lib$1.so+;
645 $target =~ s+\.exe$++;
646 $targets{$target}=1;
647 }
648 }
649 }
650 }
651
652 # If we have no project at this level, then transfer all
653 # the sources to the parent project
654 $target_count=keys %targets;
655 if ($target_count == 0) {
656 if ($project!=$parent_project) {
657 my $parent_settings=@$parent_project[$P_SETTINGS];
658 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
659 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
660 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
661 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
662 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
663 }
664 return;
665 }
666
667 # Otherwise add this project to the project list, except for
668 # the main project which is already in the list.
669 if ($dirname ne "") {
670 push @projects,$project;
671 }
672
673 # Ask for project-wide options
674 if ($opt_ask_project_options == $OPT_ASK_YES) {
Francois Gougeta106edb2000-11-10 22:29:11 +0000675 my $flag_desc="";
676 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
677 $flag_desc="mfc";
678 }
679 if ((@$project_settings[$T_FLAGS] & $TF_WRAP)!=0) {
680 if ($flag_desc ne "") {
681 $flag_desc.=", ";
682 }
683 $flag_desc.="wrapped";
684 }
Francois Gouget3af251e2000-11-30 20:36:04 +0000685 print "* Type any project-wide options (-D/-I/-L/-i/-l/--mfc/--wrap),\n";
Francois Gougeta106edb2000-11-10 22:29:11 +0000686 if (defined $flag_desc) {
687 print "* (currently $flag_desc)\n";
688 }
689 print "* or 'skip' to skip the target specific options,\n";
690 print "* or 'never' to not be asked this question again:\n";
Francois Gouget3af251e2000-11-30 20:36:04 +0000691 while (1) {
692 my $options=<STDIN>;
693 chomp $options;
694 if ($options eq "skip") {
695 $opt_ask_target_options=$OPT_ASK_SKIP;
696 last;
697 } elsif ($options eq "never") {
698 $opt_ask_project_options=$OPT_ASK_NO;
699 last;
700 } elsif (source_set_options($project_settings,$options)) {
701 last;
702 }
703 print "Please re-enter the options:\n";
Francois Gouget755bb922000-11-05 05:23:39 +0000704 }
705 }
706
707 # - Create the targets
708 # - Check if we have both libraries and programs
709 # - Match each target with source files (sort in reverse
710 # alphabetical order to get the longest matches first)
711 my @local_imports=();
712 my @local_depends=();
Francois Gougetbe859592000-11-15 22:12:20 +0000713 my @exe_list=();
Francois Gouget755bb922000-11-05 05:23:39 +0000714 foreach $target_name (sort { $b cmp $a } keys %targets) {
715 # Create the target...
716 my $basename;
717 my $target=[];
718 target_init($target);
719 @$target[$T_NAME]=$target_name;
Francois Gougeta106edb2000-11-10 22:29:11 +0000720 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
Francois Gouget755bb922000-11-05 05:23:39 +0000721 if ($target_name =~ /^lib(.*)\.so$/) {
722 @$target[$T_TYPE]=$TT_DLL;
723 @$target[$T_INIT]=get_default_init($TT_DLL);
724 @$target[$T_FLAGS]&=~$TF_WRAP;
725 $basename=$1;
726 push @local_depends,$target_name;
727 push @local_imports,$basename;
728 } else {
729 @$target[$T_TYPE]=$opt_target_type;
730 @$target[$T_INIT]=get_default_init($opt_target_type);
731 $basename=$target_name;
Francois Gougetbe859592000-11-15 22:12:20 +0000732 push @exe_list,$target;
Francois Gouget755bb922000-11-05 05:23:39 +0000733 }
Francois Gouget73995e22000-12-15 22:58:55 +0000734 # This is the default link list of Visual Studio, except odbccp32
735 # which we don't have in Wine. Also I add ntdll which seems
Francois Gouget4ec10592000-12-02 20:12:45 +0000736 # necessary for Winelib.
Francois Gougetbe859592000-11-15 22:12:20 +0000737 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);
738 @$target[$T_IMPORTS]=\@std_imports;
Francois Gouget755bb922000-11-05 05:23:39 +0000739 push @{@$project[$P_TARGETS]},$target;
740
741 # Ask for target-specific options
742 if ($opt_ask_target_options == $OPT_ASK_YES) {
Francois Gougeta106edb2000-11-10 22:29:11 +0000743 my $flag_desc="";
744 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
745 $flag_desc=" (mfc";
746 }
747 if ((@$target[$T_FLAGS] & $TF_WRAP)!=0) {
748 if ($flag_desc ne "") {
749 $flag_desc.=", ";
750 } else {
751 $flag_desc=" (";
752 }
753 $flag_desc.="wrapped";
754 }
755 if ($flag_desc ne "") {
756 $flag_desc.=")";
757 }
Francois Gouget3af251e2000-11-30 20:36:04 +0000758 print "* Specify any link option (-L/-i/-l/--mfc/--wrap) specific to the target\n";
Francois Gougeta106edb2000-11-10 22:29:11 +0000759 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
Francois Gouget3af251e2000-11-30 20:36:04 +0000760 while (1) {
761 my $options=<STDIN>;
762 chomp $options;
763 if ($options eq "never") {
764 $opt_ask_target_options=$OPT_ASK_NO;
765 last;
766 } elsif (source_set_options($target,$options)) {
767 last;
768 }
769 print "Please re-enter the options:\n";
Francois Gouget755bb922000-11-05 05:23:39 +0000770 }
771 }
772 if (@$target[$T_FLAGS] & $TF_MFC) {
773 @$project_settings[$T_FLAGS]|=$TF_MFC;
774 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
Francois Gougetbe859592000-11-15 22:12:20 +0000775 push @{@$target[$T_IMPORTS]},"mfc.dll";
776 # FIXME: Link with the MFC in the Unix sense, until we
777 # start exporting the functions properly.
778 push @{@$target[$T_LIBRARIES]},"mfc";
Francois Gouget755bb922000-11-05 05:23:39 +0000779 }
780
781 # Match sources...
782 if ($target_count == 1) {
Francois Gouget4ec10592000-12-02 20:12:45 +0000783 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
784 @$project_settings[$T_SOURCES_C]=[];
Francois Gouget755bb922000-11-05 05:23:39 +0000785 @sources_c=();
Francois Gouget4ec10592000-12-02 20:12:45 +0000786
787 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
788 @$project_settings[$T_SOURCES_CXX]=[];
Francois Gouget755bb922000-11-05 05:23:39 +0000789 @sources_cxx=();
Francois Gouget4ec10592000-12-02 20:12:45 +0000790
791 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
792 @$project_settings[$T_SOURCES_RC]=[];
Francois Gouget755bb922000-11-05 05:23:39 +0000793 @sources_rc=();
Francois Gouget4ec10592000-12-02 20:12:45 +0000794
795 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
796 # No need for sorting these sources
797 @$project_settings[$T_SOURCES_MISC]=[];
Francois Gouget755bb922000-11-05 05:23:39 +0000798 @sources_misc=();
799 } else {
800 foreach $source (@sources_c) {
801 if ($source =~ /^$basename/i) {
802 push @{@$target[$T_SOURCES_C]},$source;
803 $source="";
804 }
805 }
806 foreach $source (@sources_cxx) {
807 if ($source =~ /^$basename/i) {
808 push @{@$target[$T_SOURCES_CXX]},$source;
809 $source="";
810 }
811 }
812 foreach $source (@sources_rc) {
813 if ($source =~ /^$basename/i) {
814 push @{@$target[$T_SOURCES_RC]},$source;
815 $source="";
816 }
817 }
818 foreach $source (@sources_misc) {
819 if ($source =~ /^$basename/i) {
820 push @{@$target[$T_SOURCES_MISC]},$source;
821 $source="";
822 }
823 }
824 }
825 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
826 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
827 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
828 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
829 }
830 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
831 $opt_ask_target_options=$OPT_ASK_YES;
832 }
833
834 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
835 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
836 }
837 # The sources that did not match, if any, go to the extra
838 # source list of the project settings
839 foreach $source (@sources_c) {
840 if ($source ne "") {
841 push @{@$project_settings[$T_SOURCES_C]},$source;
842 }
843 }
844 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
845 foreach $source (@sources_cxx) {
846 if ($source ne "") {
847 push @{@$project_settings[$T_SOURCES_CXX]},$source;
848 }
849 }
850 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
851 foreach $source (@sources_rc) {
852 if ($source ne "") {
853 push @{@$project_settings[$T_SOURCES_RC]},$source;
854 }
855 }
856 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
857 foreach $source (@sources_misc) {
858 if ($source ne "") {
859 push @{@$project_settings[$T_SOURCES_MISC]},$source;
860 }
861 }
862 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
863
864 # Finally if we are building both libraries and programs in
865 # this directory, then the programs should be linked with all
866 # the libraries
Francois Gougetbe859592000-11-15 22:12:20 +0000867 if (@local_imports > 0 and @exe_list > 0) {
868 foreach $target (@exe_list) {
Francois Gougeta106edb2000-11-10 22:29:11 +0000869 push @{@$target[$T_LIBRARY_PATH]},"-L.";
Francois Gougetbe859592000-11-15 22:12:20 +0000870 push @{@$target[$T_IMPORTS]},map { "$_.dll" } @local_imports;
871 # Also link in the Unix sense since none of the functions
872 # will be exported.
873 push @{@$target[$T_LIBRARIES]},@local_imports;
Francois Gouget755bb922000-11-05 05:23:39 +0000874 push @{@$target[$T_DEPENDS]},@local_depends;
875 }
876 }
877}
878
879##
880# Scan the source directories in search of things to build
881sub source_scan
882{
Francois Gouget755bb922000-11-05 05:23:39 +0000883 # If there's a single target then this is going to be the default target
884 if (defined $opt_single_target) {
François Gouget38b3ac52001-01-11 20:17:42 +0000885 # Create the main target
886 my $main_target=[];
887 target_init($main_target);
Francois Gouget755bb922000-11-05 05:23:39 +0000888 if ($opt_target_type == $TT_DLL) {
889 @$main_target[$T_NAME]="lib$opt_single_target.so";
890 } else {
891 @$main_target[$T_NAME]="$opt_single_target";
892 }
893 @$main_target[$T_TYPE]=$opt_target_type;
François Gouget38b3ac52001-01-11 20:17:42 +0000894
895 # Add it to the list
896 push @{$main_project[$P_TARGETS]},$main_target;
Francois Gouget755bb922000-11-05 05:23:39 +0000897 }
898
899 # The main directory is always going to be there
900 push @projects,\@main_project;
901
902 # Now scan the directory tree looking for source files and, maybe, targets
903 print "Scanning the source directories...\n";
904 source_scan_directory(\@main_project,"","");
905
906 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
907}
908
909
910
911#####
912#
913# 'vc.dsp'-based Project analysis
914#
915#####
916
917#sub analyze_vc_dsp
918#{
919#
920#}
921
922
923
924#####
925#
926# Creating the wrapper targets
927#
928#####
929
Francois Gougeta106edb2000-11-10 22:29:11 +0000930sub postprocess_targets
Francois Gouget755bb922000-11-05 05:23:39 +0000931{
932 foreach $project (@projects) {
933 foreach $target (@{@$project[$P_TARGETS]}) {
934 if ((@$target[$T_FLAGS] & $TF_WRAP) != 0) {
935 my $wrapper=[];
936 target_init($wrapper);
937 @$wrapper[$T_NAME]=@$target[$T_NAME];
938 @$wrapper[$T_TYPE]=@$target[$T_TYPE];
939 @$wrapper[$T_INIT]=get_default_init(@$target[$T_TYPE]);
940 @$wrapper[$T_FLAGS]=$TF_WRAPPER | (@$target[$T_FLAGS] & $TF_MFC);
941 push @{@$wrapper[$T_SOURCES_C]},"@$wrapper[$T_NAME]_wrapper.c";
942
943 my $index=bsearch(@$target[$T_SOURCES_C],"@$wrapper[$T_NAME]_wrapper.c");
944 if (defined $index) {
945 splice(@{@$target[$T_SOURCES_C]},$index,1);
946 }
947 @$target[$T_NAME]="lib@$target[$T_NAME].so";
948 @$target[$T_TYPE]=$TT_DLL;
949
950 push @{@$project[$P_TARGETS]},$wrapper;
951 }
Francois Gougeta106edb2000-11-10 22:29:11 +0000952 if ((@$target[$T_FLAGS] & $TF_MFC) != 0) {
953 @{@$project[$P_SETTINGS]}[$T_FLAGS]|=$TF_MFC;
954 $needs_mfc=1;
955 }
Francois Gouget755bb922000-11-05 05:23:39 +0000956 }
957 }
958}
959
960
961
962#####
963#
964# Source search
965#
966#####
967
968##
969# Performs a directory traversal and renames the files so that:
970# - they have the case desired by the user
971# - their extension is of the appropriate case
972# - they don't contain annoying characters like ' ', '$', '#', ...
973sub fix_file_and_directory_names
974{
975 my $dirname=$_[0];
976
977 if (opendir(DIRECTORY, "$dirname")) {
978 foreach $dentry (readdir DIRECTORY) {
979 if ($dentry =~ /^\./ or $dentry eq "CVS") {
980 next;
981 }
982 # Set $warn to 1 if the user should be warned of the renaming
983 my $warn=0;
984
985 # autoconf and make don't support these characters well
986 my $new_name=$dentry;
987 $new_name =~ s/[ \$]/_/g;
988
Francois Gouget3af251e2000-11-30 20:36:04 +0000989 # Only all lowercase extensions are supported (because of the
990 # transformations ':.c=.o') .
Francois Gouget755bb922000-11-05 05:23:39 +0000991 if (-f "$dirname/$new_name") {
Francois Gouget3af251e2000-11-30 20:36:04 +0000992 if ($new_name =~ /\.C$/) {
993 $new_name =~ s/\.C$/.c/;
994 }
995 if ($new_name =~ /\.cpp$/i) {
Francois Gouget755bb922000-11-05 05:23:39 +0000996 $new_name =~ s/\.cpp$/.cpp/i;
997 }
998 if ($new_name =~ s/\.cxx$/.cpp/i) {
999 $warn=1;
1000 }
Francois Gouget3af251e2000-11-30 20:36:04 +00001001 if ($new_name =~ /\.rc$/i) {
Francois Gouget755bb922000-11-05 05:23:39 +00001002 $new_name =~ s/\.rc$/.rc/i;
1003 }
1004 # And this last one is to avoid confusion then running make
1005 if ($new_name =~ s/^makefile$/makefile.win/) {
1006 $warn=1;
1007 }
1008 }
1009
1010 # Adjust the case to the user's preferences
1011 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1012 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1013 ) {
1014 $new_name=lc $new_name;
1015 }
1016
1017 # And finally, perform the renaming
1018 if ($new_name ne $dentry) {
1019 if ($warn) {
1020 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1021 }
1022 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1023 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1024 print STDERR " $!\n";
1025 $new_name=$dentry;
1026 }
1027 }
1028 if (-d "$dirname/$new_name") {
1029 fix_file_and_directory_names("$dirname/$new_name");
1030 }
1031 }
1032 closedir(DIRECTORY);
1033 }
1034}
1035
1036
1037
1038#####
1039#
1040# Source fixup
1041#
1042#####
1043
1044##
1045# This maps a directory name to a reference to an array listing
1046# its contents (files and directories)
1047my %directories;
1048
1049##
1050# Retrieves the contents of the specified directory.
1051# We either get it from the directories hashtable which acts as a
1052# cache, or use opendir, readdir, closedir and store the result
1053# in the hashtable.
1054sub get_directory_contents
1055{
1056 my $dirname=$_[0];
1057 my $directory;
1058
1059 #print "getting the contents of $dirname\n";
1060
1061 # check for a cached version
1062 $dirname =~ s+/$++;
1063 if ($dirname eq "") {
1064 $dirname=cwd;
1065 }
1066 $directory=$directories{$dirname};
1067 if (defined $directory) {
1068 #print "->@$directory\n";
1069 return $directory;
1070 }
1071
1072 # Read this directory
1073 if (opendir(DIRECTORY, "$dirname")) {
1074 my @files=readdir DIRECTORY;
1075 closedir(DIRECTORY);
1076 $directory=\@files;
1077 } else {
1078 # Return an empty list
1079 #print "error: cannot open $dirname\n";
1080 my @files;
1081 $directory=\@files;
1082 }
1083 #print "->@$directory\n";
1084 $directories{$dirname}=$directory;
1085 return $directory;
1086}
1087
1088##
1089# Try to find a file for the specified filename. The attempt is
1090# case-insensitive which is why it's not trivial. If a match is
1091# found then we return the pathname with the correct case.
1092sub search_from
1093{
1094 my $dirname=$_[0];
1095 my $path=$_[1];
1096 my $real_path="";
1097
1098 if ($dirname eq "" or $dirname eq ".") {
1099 $dirname=cwd;
1100 } elsif ($dirname =~ m+^[^/]+) {
1101 $dirname=cwd . "/" . $dirname;
1102 }
1103 if ($dirname !~ m+/$+) {
1104 $dirname.="/";
1105 }
1106
1107 foreach $component (@$path) {
Francois Gougetb4302952000-11-07 20:27:16 +00001108 #print " looking for $component in \"$dirname\"\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001109 if ($component eq ".") {
1110 # Pass it as is
1111 $real_path.="./";
1112 } elsif ($component eq "..") {
1113 # Go up one level
1114 $dirname=dirname($dirname) . "/";
1115 $real_path.="../";
1116 } else {
1117 my $directory=get_directory_contents $dirname;
1118 my $found;
1119 foreach $dentry (@$directory) {
1120 if ($dentry =~ /^$component$/i) {
1121 $dirname.="$dentry/";
1122 $real_path.="$dentry/";
1123 $found=1;
1124 last;
1125 }
1126 }
1127 if (!defined $found) {
1128 # Give up
Francois Gougetb4302952000-11-07 20:27:16 +00001129 #print " could not find $component in $dirname\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001130 return;
1131 }
1132 }
1133 }
1134 $real_path=~ s+/$++;
Francois Gougetb4302952000-11-07 20:27:16 +00001135 #print " -> found $real_path\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001136 return $real_path;
1137}
1138
1139##
1140# Performs a case-insensitive search for the specified file in the
1141# include path.
1142# $line is the line number that should be referenced when an error occurs
1143# $filename is the file we are looking for
1144# $dirname is the directory of the file containing the '#include' directive
1145# if '"' was used, it is an empty string otherwise
1146# $project and $target specify part of the include path
1147sub get_real_include_name
1148{
1149 my $line=$_[0];
1150 my $filename=$_[1];
1151 my $dirname=$_[2];
1152 my $project=$_[3];
1153 my $target=$_[4];
1154
1155 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1156 # This is not a relative path, we cannot make any check
1157 my $warning="path:$filename";
1158 if (!defined $warnings{$warning}) {
1159 $warnings{$warning}="1";
1160 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1161 print STDERR "$line: $filename\n";
1162 }
1163 } else {
1164 # Here's how we proceed:
1165 # - split the filename we look for into its components
1166 # - then for each directory in the include path
1167 # - trace the directory components starting from that directory
1168 # - if we fail to find a match at any point then continue with
1169 # the next directory in the include path
1170 # - otherwise, rejoice, our quest is over.
1171 my @file_components=split /[\/\\]+/, $filename;
Francois Gougetb4302952000-11-07 20:27:16 +00001172 #print " Searching for $filename from @$project[$P_PATH]\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001173
1174 my $real_filename;
1175 if ($dirname ne "") {
Francois Gougetb4302952000-11-07 20:27:16 +00001176 # This is an 'include ""' -> look in dirname first.
1177 #print " in $dirname (include \"\")\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001178 $real_filename=search_from($dirname,\@file_components);
1179 if (defined $real_filename) {
1180 return $real_filename;
1181 }
1182 }
1183 my $project_settings=@$project[$P_SETTINGS];
Francois Gougetb4302952000-11-07 20:27:16 +00001184 foreach $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1185 my $dirname=$include;
1186 $dirname=~ s+^-I++;
1187 if (!is_absolute($dirname)) {
1188 $dirname="@$project[$P_PATH]$dirname";
1189 } else {
1190 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1191 }
1192 #print " in $dirname\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001193 $real_filename=search_from("$dirname",\@file_components);
1194 if (defined $real_filename) {
1195 return $real_filename;
1196 }
1197 }
1198 my $dotdotpath=@$project[$P_PATH];
1199 $dotdotpath =~ s/[^\/]+/../g;
Francois Gougetb4302952000-11-07 20:27:16 +00001200 foreach $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1201 my $dirname=$include;
1202 $dirname=~ s+^-I++;
1203 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1204 #print " in $dirname (global setting)\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001205 $real_filename=search_from("$dirname",\@file_components);
1206 if (defined $real_filename) {
1207 return $real_filename;
1208 }
1209 }
1210 }
1211 $filename =~ s+\\\\+/+g; # in include ""
1212 $filename =~ s+\\+/+g; # in include <> !
Francois Gougeta106edb2000-11-10 22:29:11 +00001213 if ($opt_lower_include) {
Francois Gouget755bb922000-11-05 05:23:39 +00001214 return lc "$filename";
1215 }
1216 return $filename;
1217}
1218
1219##
1220# 'Parses' a source file and fixes constructs that would not work with
1221# Winelib. The parsing is rather simple and not all non-portable features
1222# are corrected. The most important feature that is corrected is the case
1223# and path separator of '#include' directives. This requires that each
1224# source file be associated to a project & target so that the proper
1225# include path is used.
Francois Gougetb4302952000-11-07 20:27:16 +00001226# Also note that the include path is relative to the directory in which the
1227# compiler is run, i.e. that of the project, not to that of the file.
Francois Gouget755bb922000-11-05 05:23:39 +00001228sub fix_file
1229{
1230 my $filename=$_[0];
1231 my $project=$_[1];
1232 my $target=$_[2];
1233 $filename="@$project[$P_PATH]$filename";
1234 if (! -e $filename) {
1235 return;
1236 }
1237
1238 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1239 my $dirname=dirname($filename);
1240 my $is_mfc=0;
1241 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1242 $is_mfc=1;
1243 }
1244
1245 print " $filename\n";
1246 #FIXME:assuming that because there is a .bak file, this is what we want is
1247 #probably flawed. Or is it???
1248 if (! -e "$filename.bak") {
1249 if (!copy("$filename","$filename.bak")) {
1250 print STDERR "error: unable to make a backup of $filename:\n";
1251 print STDERR " $!\n";
1252 return;
1253 }
1254 }
1255 if (!open(FILEI,"$filename.bak")) {
1256 print STDERR "error: unable to open $filename.bak for reading:\n";
1257 print STDERR " $!\n";
1258 return;
1259 }
1260 if (!open(FILEO,">$filename")) {
1261 print STDERR "error: unable to open $filename for writing:\n";
1262 print STDERR " $!\n";
1263 return;
1264 }
1265 my $line=0;
1266 my $modified=0;
1267 my $rc_block_depth=0;
1268 my $rc_textinclude_state=0;
1269 while (<FILEI>) {
1270 $line++;
1271 $_ =~ s/\r\n$/\n/;
1272 if ($is_rc and !$is_mfc and /^(\s*\#\s*include\s*)\"afxres\.h\"/) {
1273 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1274 # the RC files it generates (even in non-MFC projects). So we replace
1275 # it with 'winres.h' its very close standard cousin so that non MFC
1276 # projects can compile in Wine without the MFC sources. This does not
1277 # harm VC but it will put 'afxres.h' back the next time the file is
1278 # edited.
1279 my $warning="mfc:afxres.h";
1280 if (!defined $warnings{$warning}) {
1281 $warnings{$warning}="1";
1282 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winres.h'\n";
1283 print STDERR "warning: the above warning is issued only once\n";
1284 }
1285 print FILEO "/* winemaker: $1\"afxres.h\" */\n";
1286 print FILEO "$1\"winres.h\"$'";
1287 $modified=1;
1288 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1289 my $from_file=($2 eq "<"?"":$dirname);
1290 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1291 print FILEO "$1$2$real_include_name$4$'";
1292 $modified|=($real_include_name ne $3);
1293 } elsif (/^(\s*\#\s*pragma\s*pack\s*\((\s*push\s*,?)?\s*)(\w*)(\s*\))/) {
1294 my $pragma_header=$1;
1295 my $size=$3;
1296 my $pragma_trailer=$4;
1297 #print "$pragma_header$size$pragma_trailer$'";
1298 #print "pragma push: size=$size\n";
1299 print FILEO "/* winemaker: $pragma_header$size$pragma_trailer */\n";
1300 $line++;
1301 if ($size eq "pop") {
1302 print FILEO "#include <poppack.h>$'";
1303 } elsif ($size eq "1") {
1304 print FILEO "#include <pshpack1.h>$'";
1305 } elsif ($size eq "2") {
1306 print FILEO "#include <pshpack2.h>$'";
1307 } elsif ($size eq "8") {
1308 print FILEO "#include <pshpack8.h>$'";
1309 } elsif ($size eq "4" or $size eq "") {
1310 print FILEO "#include <pshpack4.h>$'";
1311 } else {
1312 my $warning="pack:$size";
1313 if (!defined $warnings{$warning}) {
1314 $warnings{$warning}="1";
1315 print STDERR "warning: assuming that the value of $size is 4 in\n";
1316 print STDERR "$line: $pragma_header$size$pragma_trailer\n";
1317 print STDERR "warning: the above warning is issued only once\n";
1318 }
1319 print FILEO "#include <pshpack4.h>$'";
1320 $modified=1;
1321 }
1322 } elsif ($is_rc) {
1323 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]+)([\">]?)/) {
1324 my $from_file=($5 eq "<"?"":$dirname);
1325 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
1326 print FILEO "$1$5$real_include_name$7$'";
1327 $modified|=($real_include_name ne $6);
1328 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1329 my $from_file=($2 eq "<"?"":$dirname);
1330 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1331 print FILEO "$1$2$real_include_name$4$'";
1332 $modified|=($real_include_name ne $3);
1333 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
1334 $rc_textinclude_state=1;
1335 print FILEO;
1336 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
1337 print FILEO "$1winres.h$2$'";
1338 $modified=1;
1339 } elsif (/^\s*BEGIN(\W.*)?$/) {
1340 $rc_textinclude_state|=2;
1341 $rc_block_depth++;
1342 print FILEO;
1343 } elsif (/^\s*END(\W.*)?$/) {
1344 $rc_textinclude_state=0;
1345 if ($rc_block_depth>0) {
1346 $rc_block_depth--;
1347 }
1348 print FILEO;
1349 } else {
1350 print FILEO;
1351 }
1352 } else {
1353 print FILEO;
1354 }
1355 }
1356 close(FILEI);
1357 close(FILEO);
1358 if ($opt_backup == 0 or $modified == 0) {
1359 if (!unlink("$filename.bak")) {
1360 print STDERR "error: unable to delete $filename.bak:\n";
1361 print STDERR " $!\n";
1362 }
1363 }
1364}
1365
1366##
1367# Analyzes each source file in turn to find and correct issues
1368# that would cause it not to compile.
1369sub fix_source
1370{
1371 print "Fixing the source files...\n";
1372 foreach $project (@projects) {
1373 foreach $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
1374 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1375 next;
1376 }
1377 foreach $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
1378 fix_file($source,$project,$target);
1379 }
1380 }
1381 }
1382}
1383
1384
1385
1386#####
1387#
1388# File generation
1389#
1390#####
1391
1392##
1393# Generates a target's .spec file
1394sub generate_spec_file
1395{
1396 my $path=$_[0];
1397 my $target=$_[1];
1398 my $project_settings=$_[2];
1399
1400 my $basename=@$target[$T_NAME];
1401 $basename =~ s+\.so$++;
1402 if (@$target[$T_FLAGS] & $TF_WRAP) {
1403 $basename =~ s+^lib++;
1404 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1405 $basename.="_wrapper";
1406 }
1407
1408 if (!open(FILEO,">$path$basename.spec")) {
1409 print STDERR "error: could not open \"$path$basename.spec\" for writing\n";
1410 print STDERR " $!\n";
1411 return;
1412 }
1413
Francois Gougeta11664c2000-12-07 23:13:23 +00001414 my $module=$basename;
1415 $module =~ s+^lib++;
1416 $module=canonize($module);
1417 print FILEO "name $module\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001418 print FILEO "type win32\n";
1419 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1420 print FILEO "mode guiexe\n";
1421 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1422 print FILEO "mode cuiexe\n";
1423 } else {
1424 print FILEO "mode dll\n";
1425 }
1426 if (defined @$target[$T_INIT] and ((@$target[$T_FLAGS] & $TF_WRAP) == 0)) {
1427 print FILEO "init @$target[$T_INIT]\n";
1428 }
1429 if (@{@$target[$T_SOURCES_RC]} > 0) {
1430 if (@{@$target[$T_SOURCES_RC]} > 1) {
1431 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";
1432 }
1433 my $rcname=@{@$target[$T_SOURCES_RC]}[0];
1434 $rcname =~ s+\.rc$++i;
1435 print FILEO "rsrc $rcname.res\n";
1436 }
1437 print FILEO "\n";
Francois Gougetbe859592000-11-15 22:12:20 +00001438 my %imports;
Francois Gouget755bb922000-11-05 05:23:39 +00001439 foreach $library (@{$global_settings[$T_IMPORTS]}) {
Francois Gougetbe859592000-11-15 22:12:20 +00001440 if (!defined $imports{$library}) {
1441 print FILEO "import $library\n";
1442 $imports{$library}=1;
1443 }
Francois Gouget755bb922000-11-05 05:23:39 +00001444 }
1445 if (defined $project_settings) {
1446 foreach $library (@{@$project_settings[$T_IMPORTS]}) {
Francois Gougetbe859592000-11-15 22:12:20 +00001447 if (!defined $imports{$library}) {
1448 print FILEO "import $library\n";
1449 $imports{$library}=1;
1450 }
Francois Gouget755bb922000-11-05 05:23:39 +00001451 }
1452 }
1453 foreach $library (@{@$target[$T_IMPORTS]}) {
Francois Gougetbe859592000-11-15 22:12:20 +00001454 if (!defined $imports{$library}) {
1455 print FILEO "import $library\n";
1456 $imports{$library}=1;
1457 }
Francois Gouget755bb922000-11-05 05:23:39 +00001458 }
1459
1460 # Don't forget to export the 'Main' function for wrapped executables,
1461 # except for MFC ones!
1462 if (@$target[$T_FLAGS] == $TF_WRAP) {
1463 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1464 print FILEO "\n@ stdcall @$target[$T_INIT](long long ptr long) @$target[$T_INIT]\n";
1465 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1466 print FILEO "\n@ stdcall @$target[$T_INIT](long ptr ptr) @$target[$T_INIT]\n";
1467 } else {
1468 print FILEO "\n@ stdcall @$target[$T_INIT](ptr long ptr) @$target[$T_INIT]\n";
1469 }
1470 }
1471
1472 close(FILEO);
1473}
1474
1475##
1476# Generates a target's wrapper file
1477sub generate_wrapper_file
1478{
1479 my $path=$_[0];
1480 my $target=$_[1];
1481
1482 if (!defined $templates{"wrapper.c"}) {
1483 print STDERR "winemaker: internal error: No template called 'wrapper.c'\n";
1484 return;
1485 }
1486
1487 if (!open(FILEO,">$path@$target[$T_NAME]_wrapper.c")) {
1488 print STDERR "error: unable to open \"$path$basename.c\" for writing:\n";
1489 print STDERR " $!\n";
1490 return;
1491 }
1492 my $app_name="\"@$target[$T_NAME]\"";
1493 my $app_type=(@$target[$T_TYPE]==$TT_GUIEXE?"GUIEXE":"CUIEXE");
1494 my $app_init=(@$target[$T_TYPE]==$TT_GUIEXE?"\"WinMain\"":"\"main\"");
1495 my $app_mfc=(@$target[$T_FLAGS] & $TF_MFC?"\"mfc\"":NULL);
1496 foreach $line (@{$templates{"wrapper.c"}}) {
1497 $line =~ s/\#\#WINEMAKER_APP_NAME\#\#/$app_name/;
1498 $line =~ s/\#\#WINEMAKER_APP_TYPE\#\#/$app_type/;
1499 $line =~ s/\#\#WINEMAKER_APP_INIT\#\#/$app_init/;
1500 $line =~ s/\#\#WINEMAKER_APP_MFC\#\#/$app_mfc/;
1501 print FILEO $line;
1502 }
1503 close(FILEO);
1504}
1505
1506##
1507# A convenience function to generate all the lists (defines,
1508# C sources, C++ source, etc.) in the Makefile
1509sub generate_list
1510{
1511 my $name=$_[0];
1512 my $last=$_[1];
1513 my $list=$_[2];
1514 my $data=$_[3];
Francois Gouget82747b72000-11-25 01:38:39 +00001515 my $first=$name;
Francois Gouget755bb922000-11-05 05:23:39 +00001516
1517 if ($name) {
Francois Gougetfb5b5902000-11-30 20:34:39 +00001518 printf FILEO "%-22s=",$name;
Francois Gouget755bb922000-11-05 05:23:39 +00001519 }
Francois Gouget82747b72000-11-25 01:38:39 +00001520 if (defined $list) {
Francois Gouget755bb922000-11-05 05:23:39 +00001521 foreach $item (@$list) {
1522 my $value;
1523 if (defined $data) {
1524 $value=&$data($item);
1525 } else {
1526 $value=$item;
1527 }
1528 if ($value ne "") {
Francois Gouget82747b72000-11-25 01:38:39 +00001529 if ($first) {
1530 print FILEO " $value";
1531 $first=0;
1532 } else {
1533 print FILEO " \\\n\t\t\t$value";
1534 }
Francois Gouget755bb922000-11-05 05:23:39 +00001535 }
1536 }
1537 }
1538 if ($last) {
Francois Gouget82747b72000-11-25 01:38:39 +00001539 print FILEO "\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001540 }
1541}
1542
1543##
1544# Generates a project's Makefile.in and all the target files
1545sub generate_project_files
1546{
1547 my $project=$_[0];
1548 my $project_settings=@$project[$P_SETTINGS];
Francois Gougetbe859592000-11-15 22:12:20 +00001549 my @dll_list=();
1550 my @exe_list=();
Francois Gouget755bb922000-11-05 05:23:39 +00001551
1552 # Then sort the targets and separate the libraries from the programs
1553 foreach $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
1554 if (@$target[$T_TYPE] == $TT_DLL) {
Francois Gougetbe859592000-11-15 22:12:20 +00001555 push @dll_list,$target;
Francois Gouget755bb922000-11-05 05:23:39 +00001556 } else {
Francois Gougetbe859592000-11-15 22:12:20 +00001557 push @exe_list,$target;
Francois Gouget755bb922000-11-05 05:23:39 +00001558 }
1559 }
1560 @$project[$P_TARGETS]=[];
Francois Gougetbe859592000-11-15 22:12:20 +00001561 push @{@$project[$P_TARGETS]}, @dll_list;
1562 push @{@$project[$P_TARGETS]}, @exe_list;
Francois Gouget755bb922000-11-05 05:23:39 +00001563
1564 if (!open(FILEO,">@$project[$P_PATH]Makefile.in")) {
1565 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile.in\" for writing\n";
1566 print STDERR " $!\n";
1567 return;
1568 }
1569
Francois Gougetbe859592000-11-15 22:12:20 +00001570 print FILEO "### Generated by Winemaker\n";
1571 print FILEO "\n\n";
1572
Francois Gouget755bb922000-11-05 05:23:39 +00001573 print FILEO "### Generic autoconf variables\n\n";
Francois Gougetfb5b5902000-11-30 20:34:39 +00001574 generate_list("TOPSRCDIR",1,[ "\@top_srcdir\@" ]);
1575 generate_list("TOPOBJDIR",1,[ "." ]);
1576 generate_list("SRCDIR",1,[ "\@srcdir\@" ]);
1577 generate_list("VPATH",1,[ "\@srcdir\@" ]);
Francois Gouget755bb922000-11-05 05:23:39 +00001578 print FILEO "\n";
1579 if (@$project[$P_PATH] eq "") {
1580 # This is the main project. It is also responsible for recursively
1581 # calling the other projects
1582 generate_list("SUBDIRS",1,\@projects,sub
1583 {
1584 if ($_[0] != \@main_project) {
1585 my $subdir=@{$_[0]}[$P_PATH];
1586 $subdir =~ s+/$++;
1587 return $subdir;
1588 }
1589 # Eliminating the main project by returning undefined!
1590 });
1591 }
1592 if (@{@$project[$P_TARGETS]} > 0) {
Francois Gougetbe859592000-11-15 22:12:20 +00001593 generate_list("DLLS",1,\@dll_list,sub
Francois Gouget755bb922000-11-05 05:23:39 +00001594 {
1595 return @{$_[0]}[$T_NAME];
1596 });
Francois Gougetbe859592000-11-15 22:12:20 +00001597 generate_list("EXES",1,\@exe_list,sub
Francois Gouget755bb922000-11-05 05:23:39 +00001598 {
Francois Gougetbe859592000-11-15 22:12:20 +00001599 return "@{$_[0]}[$T_NAME]";
Francois Gouget755bb922000-11-05 05:23:39 +00001600 });
Francois Gouget82747b72000-11-25 01:38:39 +00001601 print FILEO "\n\n\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001602
1603 print FILEO "### Global settings\n\n";
1604 # Make it so that the project-wide settings override the global settings
1605 generate_list("DEFINES",0,@$project_settings[$T_DEFINES],sub
1606 {
1607 return "$_[0]";
1608 });
1609 generate_list("",1,$global_settings[$T_DEFINES],sub
1610 {
1611 return "$_[0]";
1612 });
1613 generate_list("INCLUDE_PATH",$no_extra,@$project_settings[$T_INCLUDE_PATH],sub
1614 {
1615 return "$_[0]";
1616 });
1617 generate_list("",1,$global_settings[$T_INCLUDE_PATH],sub
1618 {
1619 if ($_[0] !~ /^-I/) {
1620 return "$_[0]";
1621 }
1622 if (is_absolute($')) {
1623 return "$_[0]";
1624 }
Francois Gougetfb5b5902000-11-30 20:34:39 +00001625 return "-I\$(TOPSRCDIR)/$'";
Francois Gouget755bb922000-11-05 05:23:39 +00001626 });
1627 generate_list("LIBRARY_PATH",$no_extra,@$project_settings[$T_LIBRARY_PATH],sub
1628 {
1629 return "$_[0]";
1630 });
1631 generate_list("",1,$global_settings[$T_LIBRARY_PATH],sub
1632 {
1633 if ($_[0] !~ /^-L/) {
1634 return "$_[0]";
1635 }
1636 if (is_absolute($')) {
1637 return "$_[0]";
1638 }
Francois Gougetfb5b5902000-11-30 20:34:39 +00001639 return "-L\$(TOPSRCDIR)/$'";
Francois Gouget755bb922000-11-05 05:23:39 +00001640 });
Francois Gougetbe859592000-11-15 22:12:20 +00001641 generate_list("LIBRARIES",$no_extra,@$project_settings[$T_LIBRARIES],sub
Francois Gouget755bb922000-11-05 05:23:39 +00001642 {
1643 return "$_[0]";
1644 });
Francois Gougetbe859592000-11-15 22:12:20 +00001645 generate_list("",1,$global_settings[$T_LIBRARIES],sub
Francois Gouget755bb922000-11-05 05:23:39 +00001646 {
1647 return "$_[0]";
1648 });
1649 print FILEO "\n\n";
1650
1651 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
1652 @{@$project_settings[$T_SOURCES_CXX]}+
1653 @{@$project_settings[$T_SOURCES_RC]};
1654 my $no_extra=($extra_source_count == 0);
1655 if (!$no_extra) {
1656 print FILEO "### Extra source lists\n\n";
1657 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
1658 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
1659 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
Francois Gouget82747b72000-11-25 01:38:39 +00001660 print FILEO "\n";
1661 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
1662 print FILEO "\n\n\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001663 }
1664
1665 # Iterate over all the targets...
1666 foreach $target (@{@$project[$P_TARGETS]}) {
Francois Gouget82747b72000-11-25 01:38:39 +00001667 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001668 my $canon=canonize("@$target[$T_NAME]");
1669 $canon =~ s+_so$++;
1670 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
1671 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
1672 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
1673 my $basename=@$target[$T_NAME];
1674 $basename =~ s+\.so$++;
1675 if (@$target[$T_FLAGS] & $TF_WRAP) {
1676 $basename =~ s+^lib++;
1677 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1678 $basename.="_wrapper";
1679 }
1680 generate_list("${canon}_SPEC_SRCS",1,[ "$basename.spec"]);
1681 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH],sub
1682 {
1683 return "$_[0]";
1684 });
Francois Gougetbe859592000-11-15 22:12:20 +00001685 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES],sub
Francois Gouget755bb922000-11-05 05:23:39 +00001686 {
1687 return "$_[0]";
1688 });
1689 generate_list("${canon}_DEPENDS",1,@$target[$T_DEPENDS],sub
1690 {
1691 return "$_[0]";
1692 });
Francois Gouget82747b72000-11-25 01:38:39 +00001693 print FILEO "\n";
1694 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(EXTRA_OBJS)"]);
1695 print FILEO "\n\n\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001696 }
1697 print FILEO "### Global source lists\n\n";
1698 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
1699 {
1700 my $canon=canonize(@{$_[0]}[$T_NAME]);
1701 $canon =~ s+_so$++;
1702 return "\$(${canon}_C_SRCS)";
1703 });
1704 if (!$no_extra) {
1705 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
1706 }
1707 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
1708 {
1709 my $canon=canonize(@{$_[0]}[$T_NAME]);
1710 $canon =~ s+_so$++;
1711 return "\$(${canon}_CXX_SRCS)";
1712 });
1713 if (!$no_extra) {
1714 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
1715 }
1716 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
1717 {
1718 my $canon=canonize(@{$_[0]}[$T_NAME]);
1719 $canon =~ s+_so$++;
1720 return "\$(${canon}_RC_SRCS)";
1721 });
1722 if (!$no_extra) {
Francois Gouget82747b72000-11-25 01:38:39 +00001723 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
Francois Gouget755bb922000-11-05 05:23:39 +00001724 }
1725 generate_list("SPEC_SRCS",1,@$project[$P_TARGETS],sub
1726 {
1727 my $canon=canonize(@{$_[0]}[$T_NAME]);
1728 $canon =~ s+_so$++;
1729 return "\$(${canon}_SPEC_SRCS)";
1730 });
Francois Gouget755bb922000-11-05 05:23:39 +00001731 }
Francois Gouget82747b72000-11-25 01:38:39 +00001732 print FILEO "\n\n\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001733
1734 print FILEO "### Generic autoconf targets\n\n";
Francois Gouget82747b72000-11-25 01:38:39 +00001735 print FILEO "all: ";
Francois Gouget755bb922000-11-05 05:23:39 +00001736 if (@$project[$P_PATH] eq "") {
Francois Gouget82747b72000-11-25 01:38:39 +00001737 print FILEO "\$(SUBDIRS)";
Francois Gouget755bb922000-11-05 05:23:39 +00001738 }
Francois Gouget82747b72000-11-25 01:38:39 +00001739 if (@{@$project[$P_TARGETS]} > 0) {
Francois Gougetfb5b5902000-11-30 20:34:39 +00001740 print FILEO "\$(DLLS) \$(EXES:%=%.so)";
Francois Gouget82747b72000-11-25 01:38:39 +00001741 }
1742 print FILEO "\n\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001743 print FILEO "\@MAKE_RULES\@\n";
1744 print FILEO "\n";
1745 print FILEO "install::\n";
1746 if (@$project[$P_PATH] eq "") {
1747 # This is the main project. It is also responsible for recursively
1748 # calling the other projects
1749 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) install) || exit 1; done\n";
1750 }
1751 if (@{@$project[$P_TARGETS]} > 0) {
Francois Gougetbe859592000-11-15 22:12:20 +00001752 print FILEO "\tfor i in \$(EXES); do \$(INSTALL_PROGRAM) \$\$i \$(bindir); done\n";
1753 print FILEO "\tfor i in \$(EXES:%=%.so) \$(DLLS); do \$(INSTALL_LIBRARY) \$\$i \$(libdir); done\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001754 }
1755 print FILEO "\n";
1756 print FILEO "uninstall::\n";
1757 if (@$project[$P_PATH] eq "") {
1758 # This is the main project. It is also responsible for recursively
1759 # calling the other projects
1760 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) uninstall) || exit 1; done\n";
1761 }
1762 if (@{@$project[$P_TARGETS]} > 0) {
Francois Gougetbe859592000-11-15 22:12:20 +00001763 print FILEO "\tfor i in \$(EXES); do \$(RM) \$(bindir)/\$\$i;done\n";
1764 print FILEO "\tfor i in \$(EXES:%=%.so) \$(DLLS); do \$(RM) \$(libdir)/\$\$i;done\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001765 }
1766 print FILEO "\n\n\n";
1767
1768 if (@{@$project[$P_TARGETS]} > 0) {
1769 print FILEO "### Target specific build rules\n\n";
1770 foreach $target (@{@$project[$P_TARGETS]}) {
1771 my $canon=canonize("@$target[$T_NAME]");
1772 $canon =~ s/_so$//;
Francois Gougetbe859592000-11-15 22:12:20 +00001773 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.tmp.o): \$(${canon}_OBJS)\n";
1774 print FILEO "\t\$(LDCOMBINE) \$(${canon}_OBJS) -o \$\@\n";
1775 print FILEO "\t-\$(STRIP) \$(STRIPFLAGS) \$\@\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001776 print FILEO "\n";
Francois Gougetbe859592000-11-15 22:12:20 +00001777 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.spec.c): \$(${canon}_SPEC_SRCS:.spec) \$(${canon}_SPEC_SRCS:.spec=.tmp.o) \$(${canon}_RC_SRCS:.rc=.res)\n";
1778 print FILEO "\t\$(WINEBUILD) -fPIC \$(${canon}_LIBRARY_PATH) \$(WINE_LIBRARY_PATH) -sym \$(${canon}_SPEC_SRCS:.spec=.tmp.o) -o \$\@ -spec \$(${canon}_SPEC_SRCS)\n";
1779 print FILEO "\n";
1780 my $t_name=@$target[$T_NAME];
1781 if (@$target[$T_TYPE]!=$TT_DLL) {
1782 $t_name.=".so";
Francois Gouget755bb922000-11-05 05:23:39 +00001783 }
Francois Gougetbe859592000-11-15 22:12:20 +00001784 print FILEO "$t_name: \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_OBJS) \$(${canon}_DEPENDS) \n";
1785 print FILEO "\t\$(LDSHARED) \$(LDDLLFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_LIBRARY_PATH) \$(${canon}_LIBRARIES:%=-l%) \$(DLL_LINK) \$(LIBS)\n";
1786 if (@$target[$T_TYPE] ne $TT_DLL) {
1787 print FILEO "\ttest -e @$target[$T_NAME] || \$(LN_S) \$(WINE) @$target[$T_NAME]\n";
Francois Gouget82747b72000-11-25 01:38:39 +00001788 }
1789 print FILEO "\n\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001790 }
1791 }
1792 close(FILEO);
1793
1794 foreach $target (@{@$project[$P_TARGETS]}) {
1795 generate_spec_file(@$project[$P_PATH],$target,$project_settings);
1796 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1797 generate_wrapper_file(@$project[$P_PATH],$target);
1798 }
1799 }
1800}
1801
1802##
1803# Perform the replacements in the template configure files
1804# Return 1 for success, 0 for failure
1805sub generate_configure
1806{
1807 my $filename=$_[0];
1808 my $a_source_file=$_[1];
1809
1810 if (!defined $templates{$filename}) {
1811 if ($filename ne "configure") {
1812 print STDERR "winemaker: internal error: No template called '$filename'\n";
1813 }
1814 return 0;
1815 }
1816
1817 if (!open(FILEO,">$filename")) {
1818 print STDERR "error: unable to open \"$filename\" for writing:\n";
1819 print STDERR " $!\n";
1820 return 0;
1821 }
1822 foreach $line (@{$templates{$filename}}) {
1823 if ($line =~ /^\#\#WINEMAKER_PROJECTS\#\#$/) {
1824 foreach $project (@projects) {
1825 print FILEO "@$project[$P_PATH]Makefile\n";
1826 }
1827 } else {
1828 $line =~ s+\#\#WINEMAKER_SOURCE\#\#+$a_source_file+;
1829 $line =~ s+\#\#WINEMAKER_NEEDS_MFC\#\#+$needs_mfc+;
1830 print FILEO $line;
1831 }
1832 }
1833 close(FILEO);
1834 return 1;
1835}
1836
1837sub generate_generic
1838{
1839 my $filename=$_[0];
1840
1841 if (!defined $templates{$filename}) {
1842 print STDERR "winemaker: internal error: No template called '$filename'\n";
1843 return;
1844 }
1845 if (!open(FILEO,">$filename")) {
1846 print STDERR "error: unable to open \"$filename\" for writing:\n";
1847 print STDERR " $!\n";
1848 return;
1849 }
1850 foreach $line (@{$templates{$filename}}) {
1851 print FILEO $line;
1852 }
1853 close(FILEO);
1854}
1855
1856##
1857# Generates the global files:
1858# configure
1859# configure.in
1860# Make.rules.in
1861sub generate_global_files
1862{
1863 generate_generic("Make.rules.in");
1864
1865 # Get the name of a source file for configure.in
1866 my $a_source_file;
1867 search_a_file: foreach $project (@projects) {
Francois Gougeta106edb2000-11-10 22:29:11 +00001868 foreach $target (@{@$project[$P_TARGETS]}, @$project[$P_SETTINGS]) {
Francois Gouget755bb922000-11-05 05:23:39 +00001869 $a_source_file=@{@$target[$T_SOURCES_C]}[0];
1870 if (!defined $a_source_file) {
1871 $a_source_file=@{@$target[$T_SOURCES_CXX]}[0];
1872 }
1873 if (!defined $a_source_file) {
1874 $a_source_file=@{@$target[$T_SOURCES_RC]}[0];
1875 }
1876 if (defined $a_source_file) {
1877 $a_source_file="@$project[$P_PATH]$a_source_file";
1878 last search_a_file;
1879 }
1880 }
1881 }
François Gougetc1f016b2001-01-10 22:43:21 +00001882 if (!defined $a_source_file) {
1883 $a_source_file="Makefile.in";
1884 }
Francois Gouget755bb922000-11-05 05:23:39 +00001885
1886 generate_configure("configure.in",$a_source_file);
1887 unlink("configure");
1888 if (generate_configure("configure",$a_source_file) == 0) {
1889 system("autoconf");
1890 }
1891 # Add execute permission to configure for whoever has the right to read it
1892 my @st=stat("configure");
François Gouget38b3ac52001-01-11 20:17:42 +00001893 if (@st) {
Francois Gouget755bb922000-11-05 05:23:39 +00001894 my $mode=$st[2];
1895 $mode|=($mode & 0444) >>2;
1896 chmod($mode,"configure");
1897 } else {
1898 print "warning: could not generate the configure script. You need to run autoconf\n";
1899 }
1900}
1901
1902##
1903#
1904sub generate_read_templates
1905{
1906 my $file;
1907
1908 while (<DATA>) {
1909 if (/^--- ((\w\.?)+) ---$/) {
1910 my $filename=$1;
1911 if (defined $templates{$filename}) {
1912 print STDERR "winemaker: internal error: There is more than one template for $filename\n";
1913 undef $file;
1914 } else {
1915 $file=[];
1916 $templates{$filename}=$file;
1917 }
1918 } elsif (defined $file) {
1919 push @$file, $_;
1920 }
1921 }
1922}
1923
1924##
1925# This is where we finally generate files. In fact this method does not
1926# do anything itself but calls the methods that do the actual work.
1927sub generate
1928{
1929 print "Generating project files...\n";
1930 generate_read_templates();
1931 generate_global_files();
1932
1933 foreach $project (@projects) {
1934 my $path=@$project[$P_PATH];
1935 if ($path eq "") {
1936 $path=".";
1937 } else {
1938 $path =~ s+/$++;
1939 }
1940 print " $path\n";
1941 generate_project_files($project);
1942 }
1943}
1944
1945
1946
1947#####
1948#
1949# Option defaults
1950#
1951#####
1952
1953$opt_backup=1;
1954$opt_lower=$OPT_LOWER_UPPERCASE;
Francois Gougeta106edb2000-11-10 22:29:11 +00001955$opt_lower_include=1;
Francois Gouget755bb922000-11-05 05:23:39 +00001956
François Gougetc1f016b2001-01-10 22:43:21 +00001957# $opt_work_dir=<undefined>
Francois Gouget755bb922000-11-05 05:23:39 +00001958# $opt_single_target=<undefined>
1959$opt_target_type=$TT_GUIEXE;
1960$opt_flags=0;
1961$opt_is_interactive=$OPT_ASK_NO;
1962$opt_ask_project_options=$OPT_ASK_NO;
1963$opt_ask_target_options=$OPT_ASK_NO;
Francois Gougeta106edb2000-11-10 22:29:11 +00001964$opt_no_generated_files=0;
Francois Gouget755bb922000-11-05 05:23:39 +00001965$opt_no_banner=0;
1966
1967
1968
1969#####
1970#
1971# Main
1972#
1973#####
1974
François Gouget38b3ac52001-01-11 20:17:42 +00001975sub print_banner
1976{
1977 print "Winemaker $version\n";
1978 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
1979}
1980
1981sub usage
1982{
1983 print_banner();
1984 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup]\n";
1985 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
1986 print STDERR " [--lower-include|--nolower-include]\n";
1987 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
1988 print STDERR " [--wrap|--nowrap] [--mfc|--nomfc]\n";
1989 print STDERR " [-Dmacro[=defn]] [-Idir] [-Ldir] [-idll] [-llibrary]\n";
1990 print STDERR " [--interactive] [--single-target name]\n";
1991 print STDERR " [--generated-files|--nogenerated-files]\n";
1992 print STDERR " work_directory\n";
1993 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
1994 print STDERR "the specified directory so that they can be compiled with Winelib. During this\n";
1995 print STDERR "process it will modify and rename some of the files in that directory.\n";
1996 print STDERR "\tPlease read the manual page before use.\n";
1997 exit (2);
1998}
1999
2000
Francois Gouget755bb922000-11-05 05:23:39 +00002001project_init(\@main_project,"");
2002
2003while (@ARGV>0) {
2004 my $arg=shift @ARGV;
2005 # General options
2006 if ($arg eq "--nobanner") {
2007 $opt_no_banner=1;
2008 } elsif ($arg eq "--backup") {
2009 $opt_backup=1;
2010 } elsif ($arg eq "--nobackup") {
2011 $opt_backup=0;
2012 } elsif ($arg eq "--single-target") {
2013 $opt_single_target=shift @ARGV;
2014 } elsif ($arg eq "--lower-none") {
2015 $opt_lower=$OPT_LOWER_NONE;
2016 } elsif ($arg eq "--lower-all") {
2017 $opt_lower=$OPT_LOWER_ALL;
2018 } elsif ($arg eq "--lower-uppercase") {
2019 $opt_lower=$OPT_LOWER_UPPERCASE;
Francois Gougeta106edb2000-11-10 22:29:11 +00002020 } elsif ($arg eq "--lower-include") {
2021 $opt_lower_include=1;
Francois Gouget82747b72000-11-25 01:38:39 +00002022 } elsif ($arg eq "--nolower-include") {
Francois Gougeta106edb2000-11-10 22:29:11 +00002023 $opt_lower_include=0;
2024 } elsif ($arg eq "--generated-files") {
2025 $opt_no_generated_files=0;
Francois Gouget82747b72000-11-25 01:38:39 +00002026 } elsif ($arg eq "--nogenerated-files") {
Francois Gougeta106edb2000-11-10 22:29:11 +00002027 $opt_no_generated_files=1;
Francois Gouget755bb922000-11-05 05:23:39 +00002028
2029 } elsif ($arg =~ /^-D/) {
2030 push @{$global_settings[$T_DEFINES]},$arg;
2031 } elsif ($arg =~ /^-I/) {
2032 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2033 } elsif ($arg =~ /^-L/) {
2034 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
Francois Gougetbe859592000-11-15 22:12:20 +00002035 } elsif ($arg =~ /^-i/) {
Francois Gouget755bb922000-11-05 05:23:39 +00002036 push @{$global_settings[$T_IMPORTS]},$';
Francois Gougetbe859592000-11-15 22:12:20 +00002037 } elsif ($arg =~ /^-l/) {
2038 push @{$global_settings[$T_LIBRARIES]},$';
Francois Gouget755bb922000-11-05 05:23:39 +00002039
2040 # 'Source'-based method options
2041 } elsif ($arg eq "--dll") {
2042 $opt_target_type=$TT_DLL;
2043 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2044 $opt_target_type=$TT_GUIEXE;
2045 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2046 $opt_target_type=$TT_CUIEXE;
2047 } elsif ($arg eq "--interactive") {
2048 $opt_is_interactive=$OPT_ASK_YES;
2049 $opt_ask_project_options=$OPT_ASK_YES;
2050 $opt_ask_target_options=$OPT_ASK_YES;
2051 } elsif ($arg eq "--wrap") {
Francois Gougetbe859592000-11-15 22:12:20 +00002052 print STDERR "warning: --wrap no longer supported, ignoring the option\n";
2053 #$opt_flags|=$TF_WRAP;
Francois Gouget755bb922000-11-05 05:23:39 +00002054 } elsif ($arg eq "--nowrap") {
2055 $opt_flags&=~$TF_WRAP;
2056 } elsif ($arg eq "--mfc") {
Francois Gougetbe859592000-11-15 22:12:20 +00002057 $opt_flags|=$TF_MFC;
2058 #$opt_flags|=$TF_MFC|$TF_WRAP;
Francois Gouget755bb922000-11-05 05:23:39 +00002059 $needs_mfc=1;
2060 } elsif ($arg eq "--nomfc") {
2061 $opt_flags&=~($TF_MFC|$TF_WRAP);
2062 $needs_mfc=0;
2063
2064 # Catch errors
2065 } else {
2066 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
François Gougetc1f016b2001-01-10 22:43:21 +00002067 if (!defined $opt_work_dir) {
2068 $opt_work_dir=$arg;
2069 } else {
2070 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
François Gouget38b3ac52001-01-11 20:17:42 +00002071 usage();
François Gougetc1f016b2001-01-10 22:43:21 +00002072 }
2073 } else {
François Gouget38b3ac52001-01-11 20:17:42 +00002074 usage();
Francois Gouget755bb922000-11-05 05:23:39 +00002075 }
Francois Gouget755bb922000-11-05 05:23:39 +00002076 }
2077}
2078
François Gougetc1f016b2001-01-10 22:43:21 +00002079if (!defined $opt_work_dir) {
2080 print STDERR "error: you must specify the directory containing the sources to be converted\n";
François Gouget38b3ac52001-01-11 20:17:42 +00002081 usage();
François Gougetc1f016b2001-01-10 22:43:21 +00002082} elsif (!chdir $opt_work_dir) {
2083 print STDERR "error: could not chdir to the work directory\n";
2084 print STDERR " $!\n";
François Gouget38b3ac52001-01-11 20:17:42 +00002085 usage();
François Gougetc1f016b2001-01-10 22:43:21 +00002086}
2087
François Gouget38b3ac52001-01-11 20:17:42 +00002088if ($opt_no_banner == 0) {
2089 print_banner();
Francois Gouget755bb922000-11-05 05:23:39 +00002090}
2091
2092# Fix the file and directory names
2093fix_file_and_directory_names(".");
2094
2095# Scan the sources to identify the projects and targets
2096source_scan();
2097
Francois Gougeta106edb2000-11-10 22:29:11 +00002098# Create targets for wrappers, etc.
2099postprocess_targets();
Francois Gouget755bb922000-11-05 05:23:39 +00002100
2101# Fix the source files
2102fix_source();
2103
2104# Generate the Makefile and the spec file
Francois Gougeta106edb2000-11-10 22:29:11 +00002105if (! $opt_no_generated_files) {
Francois Gouget755bb922000-11-05 05:23:39 +00002106 generate();
2107}
2108
2109
2110__DATA__
2111--- configure.in ---
2112dnl Process this file with autoconf to produce a configure script.
2113dnl Author: Michael Patra <micky@marie.physik.tu-berlin.de>
2114dnl <patra@itp1.physik.tu-berlin.de>
2115dnl Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2116
2117AC_REVISION([configure.in 1.00])
2118AC_INIT(##WINEMAKER_SOURCE##)
2119
2120NEEDS_MFC=##WINEMAKER_NEEDS_MFC##
2121
2122dnl **** Command-line arguments ****
2123
2124AC_SUBST(OPTIONS)
2125
2126dnl **** Check for some programs ****
2127
2128AC_PROG_MAKE_SET
2129AC_PROG_CC
2130AC_PROG_CXX
2131AC_PROG_CPP
2132AC_PATH_XTRA
2133AC_PROG_RANLIB
2134AC_PROG_LN_S
2135AC_PATH_PROG(LDCONFIG, ldconfig, true, /sbin:/usr/sbin:$PATH)
2136
2137dnl **** Check for some libraries ****
2138
2139dnl Check for -lm for BeOS
2140AC_CHECK_LIB(m,sqrt)
2141dnl Check for -li386 for NetBSD and OpenBSD
2142AC_CHECK_LIB(i386,i386_set_ldt)
2143dnl Check for -lossaudio for NetBSD
2144AC_CHECK_LIB(ossaudio,_oss_ioctl)
2145dnl Check for -lw for Solaris
2146AC_CHECK_LIB(w,iswalnum)
2147dnl Check for -lnsl for Solaris
2148AC_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))
2149dnl Check for -lsocket for Solaris
2150AC_CHECK_FUNCS(connect,,AC_CHECK_LIB(socket,connect))
2151dnl Check for -lxpg4 for FreeBSD
2152AC_CHECK_LIB(xpg4,setrunelocale)
2153dnl Check for -lmmap for OS/2
2154AC_CHECK_LIB(mmap,mmap)
2155dnl Check for openpty
2156AC_CHECK_FUNCS(openpty,,
2157 AC_CHECK_LIB(util,openpty,
2158 AC_DEFINE(HAVE_OPENPTY)
2159 LIBS="$LIBS -lutil"
2160 ))
2161
2162AC_CHECK_HEADERS(dlfcn.h,
2163 AC_CHECK_FUNCS(dlopen,
2164 AC_DEFINE(HAVE_DL_API),
2165 AC_CHECK_LIB(dl,dlopen,
2166 AC_DEFINE(HAVE_DL_API)
2167 LIBS="$LIBS -ldl",
2168 )
2169 ),
2170)
Francois Gouget755bb922000-11-05 05:23:39 +00002171
2172dnl **** Check which curses lib to use ***
2173if test "$CURSES" = "yes"
2174then
2175 AC_CHECK_HEADERS(ncurses.h)
2176 if test "$ac_cv_header_ncurses_h" = "yes"
2177 then
2178 AC_CHECK_LIB(ncurses,waddch)
2179 fi
2180 if test "$ac_cv_lib_ncurses_waddch" = "yes"
2181 then
2182 AC_CHECK_LIB(ncurses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2183 AC_CHECK_LIB(ncurses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2184 else
2185 AC_CHECK_HEADERS(curses.h)
2186 if test "$ac_cv_header_curses_h" = "yes"
2187 then
2188 AC_CHECK_LIB(curses,waddch)
2189 if test "$ac_cv_lib_curses_waddch" = "yes"
2190 then
2191 AC_CHECK_LIB(curses,resizeterm,AC_DEFINE(HAVE_RESIZETERM))
2192 AC_CHECK_LIB(curses,getbkgd,AC_DEFINE(HAVE_GETBKGD))
2193 fi
2194 fi
2195 fi
2196fi
2197
2198dnl **** If ln -s doesn't work, use cp instead ****
2199if test "$ac_cv_prog_LN_S" = "ln -s"; then : ; else LN_S=cp ; fi
2200
2201dnl **** Check for gcc strength-reduce bug ****
2202
2203if test "x${GCC}" = "xyes"
2204then
2205 AC_CACHE_CHECK( "for gcc strength-reduce bug", ac_cv_c_gcc_strength_bug,
2206 AC_TRY_RUN([
2207int main(void) {
2208 static int Array[[3]];
2209 unsigned int B = 3;
2210 int i;
2211 for(i=0; i<B; i++) Array[[i]] = i - 3;
2212 exit( Array[[1]] != -2 );
2213}],
2214 ac_cv_c_gcc_strength_bug="no",
2215 ac_cv_c_gcc_strength_bug="yes",
2216 ac_cv_c_gcc_strength_bug="yes") )
2217 if test "$ac_cv_c_gcc_strength_bug" = "yes"
2218 then
2219 CFLAGS="$CFLAGS -fno-strength-reduce"
2220 fi
2221fi
2222
2223dnl **** Check for underscore on external symbols ****
2224
2225AC_CACHE_CHECK("whether external symbols need an underscore prefix",
2226 ac_cv_c_extern_prefix,
2227[saved_libs=$LIBS
2228LIBS="conftest_asm.s $LIBS"
2229cat > conftest_asm.s <<EOF
2230 .globl _ac_test
2231_ac_test:
2232 .long 0
2233EOF
2234AC_TRY_LINK([extern int ac_test;],[if (ac_test) return 1],
2235 ac_cv_c_extern_prefix="yes",ac_cv_c_extern_prefix="no")
2236LIBS=$saved_libs])
2237if test "$ac_cv_c_extern_prefix" = "yes"
2238then
2239 AC_DEFINE(NEED_UNDERSCORE_PREFIX)
2240fi
2241
2242dnl **** Check for working dll ****
2243
2244LDSHARED=""
Francois Gougetbe859592000-11-15 22:12:20 +00002245LDDLLFLAGS=""
Francois Gouget755bb922000-11-05 05:23:39 +00002246AC_CACHE_CHECK("whether we can build a Linux dll",
2247 ac_cv_c_dll_linux,
2248[saved_cflags=$CFLAGS
Francois Gougetbe859592000-11-15 22:12:20 +00002249CFLAGS="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0,-Bsymbolic"
Francois Gouget755bb922000-11-05 05:23:39 +00002250AC_TRY_LINK(,[return 1],ac_cv_c_dll_linux="yes",ac_cv_c_dll_linux="no")
2251CFLAGS=$saved_cflags
2252])
2253if test "$ac_cv_c_dll_linux" = "yes"
2254then
Francois Gougetbe859592000-11-15 22:12:20 +00002255 LDSHARED="\$(CC) -shared -Wl,-rpath,\$(libdir)"
2256 LDDLLFLAGS="-Wl,-Bsymbolic"
Francois Gouget755bb922000-11-05 05:23:39 +00002257else
2258 AC_CACHE_CHECK(whether we can build a UnixWare (Solaris) dll,
2259 ac_cv_c_dll_unixware,
2260 [saved_cflags=$CFLAGS
Francois Gougetbe859592000-11-15 22:12:20 +00002261 CFLAGS="$CFLAGS -fPIC -Wl,-G,-h,conftest.so.1.0,-B,symbolic"
Francois Gouget755bb922000-11-05 05:23:39 +00002262 AC_TRY_LINK(,[return 1],ac_cv_c_dll_unixware="yes",ac_cv_c_dll_unixware="no")
2263 CFLAGS=$saved_cflags
2264 ])
2265 if test "$ac_cv_c_dll_unixware" = "yes"
2266 then
Francois Gougetbe859592000-11-15 22:12:20 +00002267 LDSHARED="\$(CC) -Wl,-G \$(SONAME:%=-Wl,h,\$(libdir)/%)"#FIXME: why SONAME here?
2268 LDDLLFLAGS="-Wl,-B,symbolic"
Francois Gouget755bb922000-11-05 05:23:39 +00002269 else
2270 AC_CACHE_CHECK("whether we can build a NetBSD dll",
2271 ac_cv_c_dll_netbsd,
2272 [saved_cflags=$CFLAGS
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002273 CFLAGS="$CFLAGS -fPIC -Wl,-Bshareable,-Bforcearchive"
Francois Gouget755bb922000-11-05 05:23:39 +00002274 AC_TRY_LINK(,[return 1],ac_cv_c_dll_netbsd="yes",ac_cv_c_dll_netbsd="no")
2275 CFLAGS=$saved_cflags
2276 ])
2277 if test "$ac_cv_c_dll_netbsd" = "yes"
2278 then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002279 LDSHARED="\$(CC) -Wl,-Bshareable,-Bforcearchive"
Francois Gougetbe859592000-11-15 22:12:20 +00002280 LDDLLFLAGS="" #FIXME
Francois Gouget755bb922000-11-05 05:23:39 +00002281 fi
2282 fi
2283fi
2284if test "$ac_cv_c_dll_linux" = "no" -a "$ac_cv_c_dll_unixware" = "no" -a "$ac_cv_c_dll_netbsd" = "no"
2285then
2286 AC_MSG_ERROR([Could not find how to build a dynamically linked library])
2287fi
2288
Francois Gougetbe859592000-11-15 22:12:20 +00002289CFLAGS="$CFLAGS -fPIC"
Alexandre Julliardc4d11762000-12-27 19:06:44 +00002290DLL_LINK="\$(WINE_LIBRARY_PATH) \$(LIBRARY_PATH) \$(LIBRARIES:%=-l%) -lwine -lwine_unicode -lwine_uuid"
Francois Gouget755bb922000-11-05 05:23:39 +00002291
2292AC_SUBST(DLL_LINK)
Francois Gouget755bb922000-11-05 05:23:39 +00002293AC_SUBST(LDSHARED)
Francois Gougetbe859592000-11-15 22:12:20 +00002294AC_SUBST(LDDLLFLAGS)
Francois Gouget755bb922000-11-05 05:23:39 +00002295
2296dnl *** check for the need to define __i386__
2297
2298AC_CACHE_CHECK("whether we need to define __i386__",ac_cv_cpp_def_i386,
2299 AC_EGREP_CPP(yes,[#if (defined(i386) || defined(__i386)) && !defined(__i386__)
2300yes
2301#endif],
2302 ac_cv_cpp_def_i386="yes", ac_cv_cpp_def_i386="no"))
2303if test "$ac_cv_cpp_def_i386" = "yes"
2304then
2305 CFLAGS="$CFLAGS -D__i386__"
2306fi
2307
2308dnl $GCC is set by autoconf
2309GCC_NO_BUILTIN=""
2310if test "$GCC" = "yes"
2311then
2312 GCC_NO_BUILTIN="-fno-builtin"
2313fi
2314AC_SUBST(GCC_NO_BUILTIN)
2315
2316dnl **** Test Winelib-related features of the C++ compiler
2317AC_LANG_CPLUSPLUS()
2318if test "x${GCC}" = "xyes"
2319then
2320 OLDCXXFLAGS="$CXXFLAGS";
2321 CXXFLAGS="-fpermissive";
2322 AC_CACHE_CHECK("for g++ -fpermissive option", has_gxx_permissive,
2323 AC_TRY_COMPILE(,[
2324 for (int i=0;i<2;i++);
2325 i=0;
2326 ],
2327 [has_gxx_permissive="yes"],
2328 [has_gxx_permissive="no"])
2329 )
2330 CXXFLAGS="-fno-for-scope";
2331 AC_CACHE_CHECK("for g++ -fno-for-scope option", has_gxx_no_for_scope,
2332 AC_TRY_COMPILE(,[
2333 for (int i=0;i<2;i++);
2334 i=0;
2335 ],
2336 [has_gxx_no_for_scope="yes"],
2337 [has_gxx_no_for_scope="no"])
2338 )
2339 CXXFLAGS="$OLDCXXFLAGS";
2340 if test "$has_gxx_permissive" = "yes"
2341 then
2342 CXXFLAGS="$CXXFLAGS -fpermissive"
2343 fi
2344 if test "$has_gxx_no_for_scope" = "yes"
2345 then
2346 CXXFLAGS="$CXXFLAGS -fno-for-scope"
2347 fi
2348fi
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002349AC_LANG_C()
Francois Gouget755bb922000-11-05 05:23:39 +00002350
2351dnl **** Test Winelib-related features of the C compiler
2352dnl none for now
2353
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002354dnl **** Macros for finding a headers/libraries in a collection of places
2355
2356dnl AC_PATH_HEADER(variable,header,action-if-not-found,default-locations)
2357dnl Note that the above may set variable to an empty value if the header is
2358dnl already in the include path
2359AC_DEFUN(AC_PATH_HEADER,[
2360AC_MSG_CHECKING([for $2])
2361AC_CACHE_VAL(ac_cv_path_$1,
2362[
2363 ac_found=
2364 ac_dummy="ifelse([$4], , :/usr/local/include, [$4])"
2365 save_CPPFLAGS="$CPPFLAGS"
2366 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2367 for ac_dir in $ac_dummy; do
2368 IFS="$ac_save_ifs"
2369 if test -z "$ac_dir"
2370 then
2371 CPPFLAGS="$save_CPPFLAGS"
2372 else
2373 CPPFLAGS="-I$ac_dir $save_CPPFLAGS"
2374 fi
2375 AC_TRY_COMPILE([#include <$2>],,ac_found=1;ac_cv_path_$1="$ac_dir";break)
2376 done
2377 CPPFLAGS="$save_CPPFLAGS"
2378 ifelse([$3],,,[if test -z "$ac_found"
2379 then
2380 $3
2381 fi
2382 ])
2383])
2384$1="$ac_cv_path_$1"
2385if test -n "$ac_found" -o -n "[$]$1"
2386then
2387 AC_MSG_RESULT([$]$1)
2388else
2389 AC_MSG_RESULT(no)
2390fi
2391AC_SUBST($1)
2392])
2393
2394dnl AC_PATH_LIBRARY(variable,libraries,extra libs,action-if-not-found,default-locations)
2395AC_DEFUN(AC_PATH_LIBRARY,[
2396AC_MSG_CHECKING([for $2])
2397AC_CACHE_VAL(ac_cv_path_$1,
2398[
2399 ac_found=
2400 ac_dummy="ifelse([$5], , :/usr/local/lib, [$5])"
2401 save_LIBS="$LIBS"
2402 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2403 for ac_dir in $ac_dummy; do
2404 IFS="$ac_save_ifs"
2405 if test -z "$ac_dir"
2406 then
2407 LIBS="$2 $3 $save_LIBS"
2408 else
2409 LIBS="-L$ac_dir $2 $3 $save_LIBS"
2410 fi
2411 AC_TRY_LINK(,,ac_found=1;ac_cv_path_$1="$ac_dir";break)
2412 done
2413 LIBS="$save_LIBS"
2414 ifelse([$4],,,[if test -z "$ac_found"
2415 then
2416 $4
2417 fi
2418 ])
2419])
2420$1="$ac_cv_path_$1"
2421if test -n "$ac_found" -o -n "[$]$1"
2422then
2423 AC_MSG_RESULT([$]$1)
2424else
2425 AC_MSG_RESULT(no)
2426fi
2427AC_SUBST($1)
2428])
2429
Francois Gouget755bb922000-11-05 05:23:39 +00002430dnl **** Try to find where winelib is located ****
2431
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002432WINE_INCLUDE_ROOT="";
2433WINE_INCLUDE_PATH="";
2434WINE_LIBRARY_ROOT="";
2435WINE_LIBRARY_PATH="";
2436WINE_TOOL_PATH="";
Francois Gougetbe859592000-11-15 22:12:20 +00002437WINE="";
Francois Gouget755bb922000-11-05 05:23:39 +00002438WINEBUILD="";
2439WRC="";
2440
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002441AC_ARG_WITH(wine,
2442[ --with-wine=DIR the Wine package (or sources) is in DIR],
Francois Gouget755bb922000-11-05 05:23:39 +00002443[if test "$withval" != "no"; then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002444 WINE_ROOT="$withval";
2445 WINE_INCLUDES="";
2446 WINE_LIBRARIES="";
2447 WINE_TOOLS="";
Francois Gouget755bb922000-11-05 05:23:39 +00002448else
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002449 WINE_ROOT="";
Francois Gouget755bb922000-11-05 05:23:39 +00002450fi])
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002451if test -n "$WINE_ROOT"
Francois Gouget755bb922000-11-05 05:23:39 +00002452then
François Gougetba5bb0b2001-01-09 20:50:34 +00002453 WINE_INCLUDE_ROOT="$WINE_ROOT/include:$WINE_ROOT/include/wine";
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002454 WINE_LIBRARY_ROOT="$WINE_ROOT";
2455 WINE_TOOL_PATH="$WINE_ROOT:$WINE_ROOT/bin:$WINE_ROOT/tools/wrc:$WINE_ROOT/tools/winebuild:$PATH";
Francois Gouget755bb922000-11-05 05:23:39 +00002456fi
2457
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002458AC_ARG_WITH(wine-includes,
2459[ --with-wine-includes=DIR the Wine includes are in DIR],
Francois Gouget755bb922000-11-05 05:23:39 +00002460[if test "$withval" != "no"; then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002461 WINE_INCLUDES="$withval";
Francois Gouget755bb922000-11-05 05:23:39 +00002462else
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002463 WINE_INCLUDES="";
Francois Gouget755bb922000-11-05 05:23:39 +00002464fi])
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002465if test -n "$WINE_INCLUDES"
Francois Gouget755bb922000-11-05 05:23:39 +00002466then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002467 WINE_INCLUDE_ROOT="$WINE_INCLUDES";
Francois Gouget755bb922000-11-05 05:23:39 +00002468fi
2469
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002470AC_ARG_WITH(wine-libraries,
2471[ --with-wine-libraries=DIR the Wine libraries are in DIR],
Francois Gouget755bb922000-11-05 05:23:39 +00002472[if test "$withval" != "no"; then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002473 WINE_LIBRARIES="$withval";
Francois Gouget755bb922000-11-05 05:23:39 +00002474else
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002475 WINE_LIBRARIES="";
Francois Gouget755bb922000-11-05 05:23:39 +00002476fi])
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002477if test -n "$WINE_LIBRARIES"
Francois Gouget755bb922000-11-05 05:23:39 +00002478then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002479 WINE_LIBRARY_ROOT="$WINE_LIBRARIES";
Francois Gouget755bb922000-11-05 05:23:39 +00002480fi
2481
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002482AC_ARG_WITH(wine-tools,
2483[ --with-wine-tools=DIR the Wine tools are in DIR],
Francois Gouget755bb922000-11-05 05:23:39 +00002484[if test "$withval" != "no"; then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002485 WINE_TOOLS="$withval";
Francois Gouget755bb922000-11-05 05:23:39 +00002486else
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002487 WINE_TOOLS="";
Francois Gouget755bb922000-11-05 05:23:39 +00002488fi])
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002489if test -n "$WINE_TOOLS"
Francois Gouget755bb922000-11-05 05:23:39 +00002490then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002491 WINE_TOOL_PATH="$WINE_TOOLS:$WINE_TOOLS/wrc:$WINE_TOOLS/winebuild";
Francois Gouget755bb922000-11-05 05:23:39 +00002492fi
2493
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002494if test -z "$WINE_INCLUDE_ROOT"
Francois Gouget755bb922000-11-05 05:23:39 +00002495then
François Gougetba5bb0b2001-01-09 20:50:34 +00002496 WINE_INCLUDE_ROOT=":/usr/include/wine:/usr/local/include/wine:/opt/wine/include:/opt/wine/include/wine";
Francois Gouget755bb922000-11-05 05:23:39 +00002497fi
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002498AC_PATH_HEADER(WINE_INCLUDE_ROOT,windef.h,[
2499 AC_MSG_ERROR([Could not find the Wine includes])
2500],$WINE_INCLUDE_ROOT)
2501if test -n "$WINE_INCLUDE_ROOT"
Francois Gouget755bb922000-11-05 05:23:39 +00002502then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002503 WINE_INCLUDE_PATH="-I$WINE_INCLUDE_ROOT"
Francois Gouget755bb922000-11-05 05:23:39 +00002504else
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002505 WINE_INCLUDE_PATH=""
Francois Gouget755bb922000-11-05 05:23:39 +00002506fi
2507
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002508if test -z "$WINE_LIBRARY_ROOT"
2509then
2510 WINE_LIBRARY_ROOT=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib";
2511else
2512 WINE_LIBRARY_ROOT="$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/lib";
2513fi
2514AC_PATH_LIBRARY(WINE_LIBRARY_ROOT,[-lwine],[-lutil],[
2515 AC_MSG_ERROR([Could not find the Wine libraries (libwine.so)])
2516],$WINE_LIBRARY_ROOT)
2517if test -n "$WINE_LIBRARY_ROOT"
2518then
2519 WINE_LIBRARY_PATH="-L$WINE_LIBRARY_ROOT"
2520else
2521 WINE_LIBRARY_PATH=""
2522fi
2523AC_PATH_LIBRARY(LIBNTDLL_PATH,[-lntdll],[$WINE_LIBRARY_PATH -lwine -lwine_unicode -lncurses -ldl -lutil],[
2524 AC_MSG_ERROR([Could not find the Wine libraries (libntdll.so)])
2525],[$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/dlls])
2526if test -n "$LIBNTDLL_PATH" -a "-L$LIBNTDLL_PATH" != "$WINE_LIBRARY_PATH"
2527then
2528 WINE_LIBRARY_PATH="$WINE_LIBRARY_PATH -L$LIBNTDLL_PATH"
2529fi
2530
2531if test -z "$WINE_TOOL_PATH"
2532then
2533 WINE_TOOL_PATH="$PATH:/usr/local/bin:/opt/wine/bin";
2534fi
Francois Gougetbe859592000-11-15 22:12:20 +00002535AC_PATH_PROG(WINE,wine,,$WINE_TOOL_PATH)
2536if test -z "$WINE"
2537then
2538 AC_MSG_ERROR([Could not find Wine's wine tool])
2539fi
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002540AC_PATH_PROG(WINEBUILD,winebuild,,$WINE_TOOL_PATH)
Francois Gouget755bb922000-11-05 05:23:39 +00002541if test -z "$WINEBUILD"
2542then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002543 AC_MSG_ERROR([Could not find Wine's winebuild tool])
Francois Gouget755bb922000-11-05 05:23:39 +00002544fi
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002545AC_PATH_PROG(WRC,wrc,,$WINE_TOOL_PATH)
Francois Gouget755bb922000-11-05 05:23:39 +00002546if test -z "$WRC"
2547then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002548 AC_MSG_ERROR([Could not find Wine's wrc tool])
Francois Gouget755bb922000-11-05 05:23:39 +00002549fi
2550
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002551AC_SUBST(WINE_INCLUDE_PATH)
2552AC_SUBST(WINE_LIBRARY_PATH)
Francois Gouget755bb922000-11-05 05:23:39 +00002553
2554dnl **** Try to find where the MFC are located ****
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002555AC_LANG_CPLUSPLUS()
Francois Gouget755bb922000-11-05 05:23:39 +00002556
2557if test "x$NEEDS_MFC" = "x1"
2558then
2559 ATL_INCLUDE_ROOT="";
2560 ATL_INCLUDE_PATH="";
2561 MFC_INCLUDE_ROOT="";
2562 MFC_INCLUDE_PATH="";
2563 MFC_LIBRARY_ROOT="";
2564 MFC_LIBRARY_PATH="";
2565
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002566 AC_ARG_WITH(mfc,
2567 [ --with-mfc=DIR the MFC package (or sources) is in DIR],
Francois Gouget755bb922000-11-05 05:23:39 +00002568 [if test "$withval" != "no"; then
2569 MFC_ROOT="$withval";
2570 ATL_INCLUDES="";
2571 MFC_INCLUDES="";
2572 MFC_LIBRARIES="";
2573 else
2574 MFC_ROOT="";
2575 fi])
2576 if test -n "$MFC_ROOT"
2577 then
2578 ATL_INCLUDE_ROOT="$MFC_ROOT";
2579 MFC_INCLUDE_ROOT="$MFC_ROOT";
2580 MFC_LIBRARY_ROOT="$MFC_ROOT";
2581 fi
2582
2583 AC_ARG_WITH(atl-includes,
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002584 [ --with-atl-includes=DIR the ATL includes are in DIR],
Francois Gouget755bb922000-11-05 05:23:39 +00002585 [if test "$withval" != "no"; then
2586 ATL_INCLUDES="$withval";
2587 else
2588 ATL_INCLUDES="";
2589 fi])
2590 if test -n "$ATL_INCLUDES"
2591 then
2592 ATL_INCLUDE_ROOT="$ATL_INCLUDES";
2593 fi
2594
2595 AC_ARG_WITH(mfc-includes,
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002596 [ --with-mfc-includes=DIR the MFC includes are in DIR],
Francois Gouget755bb922000-11-05 05:23:39 +00002597 [if test "$withval" != "no"; then
2598 MFC_INCLUDES="$withval";
2599 else
2600 MFC_INCLUDES="";
2601 fi])
2602 if test -n "$MFC_INCLUDES"
2603 then
2604 MFC_INCLUDE_ROOT="$MFC_INCLUDES";
2605 fi
2606
2607 AC_ARG_WITH(mfc-libraries,
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002608 [ --with-mfc-libraries=DIR the MFC libraries are in DIR],
Francois Gouget755bb922000-11-05 05:23:39 +00002609 [if test "$withval" != "no"; then
2610 MFC_LIBRARIES="$withval";
2611 else
2612 MFC_LIBRARIES="";
2613 fi])
2614 if test -n "$MFC_LIBRARIES"
2615 then
2616 MFC_LIBRARY_ROOT="$MFC_LIBRARIES";
2617 fi
2618
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002619 OLDCPPFLAGS="$CPPFLAGS"
2620 dnl FIXME: We should not have defines in any of the include paths
2621 CPPFLAGS="$WINE_INCLUDE_PATH -I$WINE_INCLUDE_ROOT/mixedcrt -D_DLL -D_MT $CPPFLAGS"
2622 ATL_INCLUDE_PATH="-I\$(WINE_INCLUDE_ROOT)/mixedcrt -D_DLL -D_MT"
Francois Gouget755bb922000-11-05 05:23:39 +00002623 if test -z "$ATL_INCLUDE_ROOT"
2624 then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002625 ATL_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/atl:/usr/include/atl:/usr/local/include/atl:/opt/mfc/include/atl:/opt/atl/include"
2626 else
2627 ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT:$ATL_INCLUDE_ROOT/atl:$ATL_INCLUDE_ROOT/atl/include"
Francois Gouget755bb922000-11-05 05:23:39 +00002628 fi
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002629 AC_PATH_HEADER(ATL_INCLUDE_ROOT,atldef.h,[
2630 AC_MSG_ERROR([Could not find the ATL includes])
2631 ],$ATL_INCLUDE_ROOT)
2632 if test -n "$ATL_INCLUDE_ROOT"
Francois Gouget755bb922000-11-05 05:23:39 +00002633 then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002634 ATL_INCLUDE_PATH="$ATL_INCLUDE_PATH -I$ATL_INCLUDE_ROOT"
Francois Gouget755bb922000-11-05 05:23:39 +00002635 fi
Francois Gouget755bb922000-11-05 05:23:39 +00002636
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002637 MFC_INCLUDE_PATH="$ATL_INCLUDE_PATH"
Francois Gouget755bb922000-11-05 05:23:39 +00002638 if test -z "$MFC_INCLUDE_ROOT"
2639 then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002640 MFC_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/mfc:/usr/include/mfc:/usr/local/include/mfc:/opt/mfc/include/mfc:/opt/mfc/include"
2641 else
2642 MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT:$MFC_INCLUDE_ROOT/mfc:$MFC_INCLUDE_ROOT/mfc/include"
Francois Gouget755bb922000-11-05 05:23:39 +00002643 fi
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002644 AC_PATH_HEADER(MFC_INCLUDE_ROOT,afx.h,[
2645 AC_MSG_ERROR([Could not find the MFC includes])
2646 ],$MFC_INCLUDE_ROOT)
2647 if test -n "$MFC_INCLUDE_ROOT" -a "$ATL_INCLUDE_ROOT" != "$MFC_INCLUDE_ROOT"
Francois Gouget755bb922000-11-05 05:23:39 +00002648 then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002649 MFC_INCLUDE_PATH="$MFC_INCLUDE_PATH -I$MFC_INCLUDE_ROOT"
Francois Gouget755bb922000-11-05 05:23:39 +00002650 fi
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002651 CPPFLAGS="$OLDCPPFLAGS"
Francois Gouget755bb922000-11-05 05:23:39 +00002652
2653 if test -z "$MFC_LIBRARY_ROOT"
2654 then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002655 MFC_LIBRARY_ROOT=":$WINE_LIBRARY_ROOT:/usr/lib/mfc:/usr/local/lib:/usr/local/lib/mfc:/opt/mfc/lib";
Francois Gouget755bb922000-11-05 05:23:39 +00002656 else
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002657 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT:$MFC_LIBRARY_ROOT/lib:$MFC_LIBRARY_ROOT/mfc/src";
Francois Gouget755bb922000-11-05 05:23:39 +00002658 fi
Francois Gouget82747b72000-11-25 01:38:39 +00002659 AC_PATH_LIBRARY(MFC_LIBRARY_ROOT,[-lmfc],[$WINE_LIBRARY_PATH -lwine -lwine_unicode],[
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002660 AC_MSG_ERROR([Could not find the MFC library])
2661 ],$MFC_LIBRARY_ROOT)
2662 if test -n "$MFC_LIBRARY_ROOT" -a "$MFC_LIBRARY_ROOT" != "$WINE_LIBRARY_ROOT"
2663 then
2664 MFC_LIBRARY_PATH="-L$MFC_LIBRARY_ROOT"
2665 else
2666 MFC_LIBRARY_PATH=""
2667 fi
Francois Gouget755bb922000-11-05 05:23:39 +00002668
Francois Gouget755bb922000-11-05 05:23:39 +00002669 AC_SUBST(ATL_INCLUDE_PATH)
Francois Gouget755bb922000-11-05 05:23:39 +00002670 AC_SUBST(MFC_INCLUDE_PATH)
Francois Gouget755bb922000-11-05 05:23:39 +00002671 AC_SUBST(MFC_LIBRARY_PATH)
2672fi
2673
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002674AC_LANG_C()
2675
Francois Gouget755bb922000-11-05 05:23:39 +00002676dnl **** Generate output files ****
2677
2678MAKE_RULES=Make.rules
2679AC_SUBST_FILE(MAKE_RULES)
2680
2681AC_OUTPUT([
2682Make.rules
2683##WINEMAKER_PROJECTS##
2684 ])
2685
2686echo
2687echo "Configure finished. Do 'make' to build the project."
2688echo
2689
2690dnl Local Variables:
2691dnl comment-start: "dnl "
2692dnl comment-end: ""
2693dnl comment-start-skip: "\\bdnl\\b\\s *"
2694dnl compile-command: "autoconf"
2695dnl End:
2696--- Make.rules.in ---
2697# Copyright 2000 Francois Gouget for CodeWeavers
2698# fgouget@codeweavers.com
2699#
2700# Global rules shared by all makefiles -*-Makefile-*-
2701#
2702# Each individual makefile must define the following variables:
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002703# WINE_INCLUDE_ROOT: Wine's headers location
2704# WINE_LIBRARY_ROOT: Wine's libraries location
Francois Gouget755bb922000-11-05 05:23:39 +00002705# TOPOBJDIR : top-level object directory
2706# SRCDIR : source directory for this module
2707#
2708# Each individual makefile may define the following additional variables:
2709#
2710# SUBDIRS : subdirectories that contain a Makefile
Francois Gougetbe859592000-11-15 22:12:20 +00002711# DLLS : WineLib libraries to be built
2712# EXES : WineLib executables to be built
Francois Gouget755bb922000-11-05 05:23:39 +00002713#
2714# CEXTRA : extra c flags (e.g. '-Wall')
2715# CXXEXTRA : extra c++ flags (e.g. '-Wall')
2716# WRCEXTRA : extra wrc flags (e.g. '-p _SysRes')
2717# DEFINES : defines (e.g. -DSTRICT)
2718# INCLUDE_PATH : additional include path
2719# LIBRARY_PATH : additional library path
Francois Gougetbe859592000-11-15 22:12:20 +00002720# LIBRARIES : additional Unix libraries to link with
Francois Gouget755bb922000-11-05 05:23:39 +00002721#
2722# C_SRCS : C sources for the module
2723# CXX_SRCS : C++ sources for the module
2724# RC_SRCS : resource source files
2725# SPEC_SRCS : interface definition files
2726
2727
2728# Where is Winelib
2729
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002730WINE_INCLUDE_ROOT = @WINE_INCLUDE_ROOT@
2731WINE_INCLUDE_PATH = @WINE_INCLUDE_PATH@
2732WINE_LIBRARY_ROOT = @WINE_LIBRARY_ROOT@
2733WINE_LIBRARY_PATH = @WINE_LIBRARY_PATH@
Francois Gouget755bb922000-11-05 05:23:39 +00002734
2735# Where are the MFC
2736
2737ATL_INCLUDE_ROOT = @ATL_INCLUDE_ROOT@
2738ATL_INCLUDE_PATH = @ATL_INCLUDE_PATH@
2739MFC_INCLUDE_ROOT = @MFC_INCLUDE_ROOT@
2740MFC_INCLUDE_PATH = @MFC_INCLUDE_PATH@
2741MFC_LIBRARY_ROOT = @MFC_LIBRARY_ROOT@
2742MFC_LIBRARY_PATH = @MFC_LIBRARY_PATH@
2743
2744# First some useful definitions
2745
2746SHELL = /bin/sh
2747CC = @CC@
2748CPP = @CPP@
Francois Gouget3af251e2000-11-30 20:36:04 +00002749WRC = @WRC@
Francois Gouget755bb922000-11-05 05:23:39 +00002750CFLAGS = @CFLAGS@
2751CXXFLAGS = @CXXFLAGS@
Francois Gouget3af251e2000-11-30 20:36:04 +00002752WRCFLAGS = -r -L
Francois Gouget755bb922000-11-05 05:23:39 +00002753OPTIONS = @OPTIONS@ -D_REENTRANT -DWINELIB
2754X_CFLAGS = @X_CFLAGS@
2755X_LIBS = @X_LIBS@
2756XLIB = @X_PRE_LIBS@ @XLIB@ @X_EXTRA_LIBS@
2757DLL_LINK = @DLL_LINK@
2758LIBS = @LIBS@ $(LIBRARY_PATH)
2759YACC = @YACC@
2760LEX = @LEX@
2761LEXLIB = @LEXLIB@
2762LN_S = @LN_S@
Francois Gouget3af251e2000-11-30 20:36:04 +00002763ALLFLAGS = $(DEFINES) -I$(SRCDIR) $(WINE_INCLUDE_PATH) $(INCLUDE_PATH)
2764ALLCFLAGS = $(CFLAGS) $(CEXTRA) $(OPTIONS) $(X_CFLAGS) $(ALLFLAGS)
2765ALLCXXFLAGS=$(CXXFLAGS) $(CXXEXTRA) $(OPTIONS) $(X_CFLAGS) $(ALLFLAGS)
2766ALLWRCFLAGS=$(WRCFLAGS) $(WRCEXTRA) $(OPTIONS) $(ALLFLAGS)
Francois Gouget755bb922000-11-05 05:23:39 +00002767LDCOMBINE = ld -r
2768LDSHARED = @LDSHARED@
Francois Gougetbe859592000-11-15 22:12:20 +00002769LDDLLFLAGS= @LDDLLFLAGS@
2770STRIP = strip
2771STRIPFLAGS= --strip-unneeded
Francois Gouget755bb922000-11-05 05:23:39 +00002772RM = rm -f
2773MV = mv
2774MKDIR = mkdir -p
Francois Gougetbe859592000-11-15 22:12:20 +00002775WINE = @WINE@
Francois Gouget755bb922000-11-05 05:23:39 +00002776WINEBUILD = @WINEBUILD@
Francois Gouget755bb922000-11-05 05:23:39 +00002777@SET_MAKE@
2778
2779# Installation infos
2780
2781INSTALL = @INSTALL@
2782INSTALL_PROGRAM = @INSTALL_PROGRAM@
2783INSTALL_DATA = @INSTALL_DATA@
2784prefix = @prefix@
2785exec_prefix = @exec_prefix@
2786bindir = @bindir@
2787libdir = @libdir@
2788infodir = @infodir@
2789mandir = @mandir@
2790prog_manext = 1
2791conf_manext = 5
Francois Gouget755bb922000-11-05 05:23:39 +00002792
Francois Gouget3af251e2000-11-30 20:36:04 +00002793OBJS = $(C_SRCS:.c=.o) $(CXX_SRCS:.cpp=.o) \
2794 $(SPEC_SRCS:.spec=.spec.o)
2795CLEAN_FILES = *.spec.c y.tab.c y.tab.h lex.yy.c \
2796 core *.orig *.rej \
2797 \\\#*\\\# *~ *% .\\\#*
Francois Gouget755bb922000-11-05 05:23:39 +00002798
Francois Gouget755bb922000-11-05 05:23:39 +00002799# Implicit rules
2800
Francois Gouget3af251e2000-11-30 20:36:04 +00002801.SUFFIXES: .cpp .rc .res .tmp.o .spec .spec.c .spec.o
Francois Gouget755bb922000-11-05 05:23:39 +00002802
2803.c.o:
2804 $(CC) -c $(ALLCFLAGS) -o $@ $<
2805
Francois Gouget755bb922000-11-05 05:23:39 +00002806.cpp.o:
2807 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2808
Francois Gouget755bb922000-11-05 05:23:39 +00002809.cxx.o:
2810 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2811
Francois Gouget755bb922000-11-05 05:23:39 +00002812.rc.res:
Francois Gouget3af251e2000-11-30 20:36:04 +00002813 $(WRC) $(ALLWRCFLAGS) -o $@ $<
Francois Gouget755bb922000-11-05 05:23:39 +00002814
2815.PHONY: all install uninstall clean distclean depend dummy
2816
2817# 'all' target first in case the enclosing Makefile didn't define any target
2818
2819all: Makefile
2820
2821# Rules for makefile
2822
2823Makefile: Makefile.in $(TOPSRCDIR)/configure
2824 @echo Makefile is older than $?, please rerun $(TOPSRCDIR)/configure
2825 @exit 1
2826
2827# Rules for cleaning
2828
2829$(SUBDIRS:%=%/__clean__): dummy
2830 cd `dirname $@` && $(MAKE) clean
2831
2832$(EXTRASUBDIRS:%=%/__clean__): dummy
2833 -cd `dirname $@` && $(RM) $(CLEAN_FILES)
2834
2835clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
Francois Gougeta11664c2000-12-07 23:13:23 +00002836 $(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(OBJS) $(SPEC_SRCS:.spec=.tmp.o) $(EXES) $(EXES:%=%.so) $(DLLS)
Francois Gouget755bb922000-11-05 05:23:39 +00002837
2838# Rules for installing
2839
2840$(SUBDIRS:%=%/__install__): dummy
2841 cd `dirname $@` && $(MAKE) install
2842
2843$(SUBDIRS:%=%/__uninstall__): dummy
2844 cd `dirname $@` && $(MAKE) uninstall
2845
2846# Misc. rules
2847
2848$(SUBDIRS): dummy
2849 @cd $@ && $(MAKE)
2850
2851dummy:
2852
2853# End of global rules
2854--- wrapper.c ---
2855/*
2856 * Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2857 */
2858
2859#include <dlfcn.h>
2860#include <windows.h>
2861
2862
2863
2864/*
2865 * Describe the wrapped application
2866 */
2867
2868/**
2869 * This is either CUIEXE for a console based application or
2870 * GUIEXE for a regular windows application.
2871 */
2872#define APP_TYPE ##WINEMAKER_APP_TYPE##
2873
2874/**
2875 * This is the application library's base name, i.e. 'hello' if the
2876 * library is called 'libhello.so'.
2877 */
2878static char* appName = ##WINEMAKER_APP_NAME##;
2879
2880/**
2881 * This is the name of the application's Windows module. If left NULL
2882 * then appName is used.
2883 */
2884static char* appModule = NULL;
2885
2886/**
2887 * This is the application's entry point. This is usually "WinMain" for a
2888 * GUIEXE and 'main' for a CUIEXE application.
2889 */
2890static char* appInit = ##WINEMAKER_APP_INIT##;
2891
2892/**
2893 * This is either non-NULL for MFC-based applications and is the name of the
2894 * MFC's module. This is the module in which we will take the 'WinMain'
2895 * function.
2896 */
2897static char* mfcModule = ##WINEMAKER_APP_MFC##;
2898
2899
2900
2901/*
2902 * Implement the main.
2903 */
2904
2905#if APP_TYPE == GUIEXE
2906typedef int WINAPI (*WinMainFunc)(HINSTANCE hInstance, HINSTANCE hPrevInstance,
2907 PSTR szCmdLine, int iCmdShow);
2908#else
2909typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp);
2910#endif
2911
2912#if APP_TYPE == GUIEXE
2913int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
2914 PSTR szCmdLine, int iCmdShow)
2915#else
2916int WINAPI Main(int argc, char** argv, char** envp)
2917#endif
2918{
2919 void* appLibrary;
2920 HINSTANCE hApp,hMFC,hMain;
2921 void* appMain;
2922 char* libName;
2923 int retcode;
2924
2925 /* Load the application's library */
2926 libName=(char*)malloc(strlen(appName)+5+3+1);
2927 /* FIXME: we should get the wrapper's path and use that as the base for
2928 * the library
2929 */
2930 sprintf(libName,"./lib%s.so",appName);
2931 appLibrary=dlopen(libName,RTLD_NOW);
2932 if (appLibrary==NULL) {
2933 sprintf(libName,"lib%s.so",appName);
2934 appLibrary=dlopen(libName,RTLD_NOW);
2935 }
2936 if (appLibrary==NULL) {
2937 char format[]="Could not load the %s library:\r\n%s";
2938 char* error;
2939 char* msg;
2940
2941 error=dlerror();
2942 msg=(char*)malloc(strlen(format)+strlen(libName)+strlen(error));
2943 sprintf(msg,format,libName,error);
2944 MessageBox(NULL,msg,"dlopen error",MB_OK);
2945 free(msg);
2946 return 1;
2947 }
2948
2949 /* Then if this application is MFC based, load the MFC module */
2950 /* FIXME: I'm not sure this is really necessary */
2951 if (mfcModule!=NULL) {
2952 hMFC=LoadLibrary(mfcModule);
2953 if (hMFC==NULL) {
2954 char format[]="Could not load the MFC module %s (%d)";
2955 char* msg;
2956
2957 msg=(char*)malloc(strlen(format)+strlen(mfcModule)+11);
2958 sprintf(msg,format,mfcModule,GetLastError());
2959 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
2960 free(msg);
2961 return 1;
2962 }
2963 /* MFC is a special case: the WinMain is in the MFC library,
2964 * instead of the application's library.
2965 */
2966 hMain=hMFC;
2967 } else {
2968 hMFC=NULL;
2969 }
2970
2971 /* Load the application's module */
2972 if (appModule==NULL) {
2973 appModule=appName;
2974 }
2975 hApp=LoadLibrary(appModule);
2976 if (hApp==NULL) {
2977 char format[]="Could not load the application's module %s (%d)";
2978 char* msg;
2979
2980 msg=(char*)malloc(strlen(format)+strlen(appModule)+11);
2981 sprintf(msg,format,appModule,GetLastError());
2982 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
2983 free(msg);
2984 return 1;
2985 } else if (hMain==NULL) {
2986 hMain=hApp;
2987 }
2988
2989 /* Get the address of the application's entry point */
2990 appMain=(WinMainFunc*)GetProcAddress(hMain, appInit);
2991 if (appMain==NULL) {
2992 char format[]="Could not get the address of %s (%d)";
2993 char* msg;
2994
2995 msg=(char*)malloc(strlen(format)+strlen(appInit)+11);
2996 sprintf(msg,format,appInit,GetLastError());
2997 MessageBox(NULL,msg,"GetProcAddress error",MB_OK);
2998 free(msg);
2999 return 1;
3000 }
3001
3002 /* And finally invoke the application's entry point */
3003#if APP_TYPE == GUIEXE
3004 retcode=(*((WinMainFunc)appMain))(hApp,hPrevInstance,szCmdLine,iCmdShow);
3005#else
3006 retcode=(*((MainFunc)appMain))(argc,argv,envp);
3007#endif
3008
3009 /* Cleanup and done */
3010 FreeLibrary(hApp);
3011 if (hMFC!=NULL) {
3012 FreeLibrary(hMFC);
3013 }
3014 dlclose(appLibrary);
3015 free(libName);
3016
3017 return retcode;
3018}