blob: 6eba7afffd3ea97d52e9620ea1105fd336a20604 [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#
Francois Gouget3c6c20f2001-03-23 19:07:59 +00006my $version="0.5.7";
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 Gougetafa36ce2001-03-01 22:11:10 +0000408 @$target[$T_FLAGS]|=$TF_WRAP;
Francois Gougeta106edb2000-11-10 22:29:11 +0000409 } elsif (@$target[$T_TYPE] != $TT_DLL and
Francois Gouget82747b72000-11-25 01:38:39 +0000410 $option =~ /^--nowrap/) {
Francois Gougeta106edb2000-11-10 22:29:11 +0000411 @$target[$T_FLAGS]&=~$TF_WRAP;
412 } elsif ($option =~ /^--mfc/) {
Francois Gouget755bb922000-11-05 05:23:39 +0000413 @$target[$T_FLAGS]|=$TF_MFC;
Francois Gougetafa36ce2001-03-01 22:11:10 +0000414 if (@$target[$T_TYPE] != $TT_DLL) {
415 @$target[$T_FLAGS]|=$TF_WRAP;
416 }
Francois Gouget82747b72000-11-25 01:38:39 +0000417 } elsif ($option =~ /^--nomfc/) {
418 @$target[$T_FLAGS]&=~$TF_MFC;
Francois Gougetafa36ce2001-03-01 22:11:10 +0000419 @$target[$T_FLAGS]&=~($TF_MFC|$TF_WRAP);
Francois Gouget755bb922000-11-05 05:23:39 +0000420 } else {
Francois Gouget3af251e2000-11-30 20:36:04 +0000421 print STDERR "error: unknown option \"$option\"\n";
422 return 0;
Francois Gouget755bb922000-11-05 05:23:39 +0000423 }
424 }
Francois Gouget3af251e2000-11-30 20:36:04 +0000425 return 1;
Francois Gouget755bb922000-11-05 05:23:39 +0000426}
427
428##
429# Scans the specified directory to:
430# - see if we should create a Makefile in this directory. We normally do
431# so if we find a project file and sources
432# - get a list of targets for this directory
433# - get the list of source files
434sub source_scan_directory
435{
436 # a reference to the parent's project
437 my $parent_project=$_[0];
438 # the full relative path to the current directory, including a
439 # trailing '/', or an empty string if this is the top level directory
440 my $path=$_[1];
441 # the name of this directory, including a trailing '/', or an empty
442 # string if this is the top level directory
443 my $dirname=$_[2];
Francois Gouget3266b882001-03-03 00:17:11 +0000444 # if set then no targets will be looked for and the sources will all
445 # end up in the parent_project's 'misc' bucket
446 my $no_target=$_[3];
Francois Gouget755bb922000-11-05 05:23:39 +0000447
448 # reference to the project for this directory. May not be used
449 my $project;
450 # list of targets found in the 'current' directory
451 my %targets;
452 # list of sources found in the current directory
453 my @sources_c=();
454 my @sources_cxx=();
455 my @sources_rc=();
456 my @sources_misc=();
457 # true if this directory contains a Windows project
458 my $has_win_project=0;
459 # If we don't find any executable/library then we might make up targets
460 # from the list of .dsp/.mak files we find since they usually have the
461 # same name as their target.
462 my @dsp_files=();
463 my @mak_files=();
464
465 if (defined $opt_single_target or $dirname eq "") {
466 # Either there is a single target and thus a single project,
467 # or we are in the top level directory for which a project
468 # already exists
469 $project=$parent_project;
470 } else {
471 $project=[];
472 project_init($project,$path);
473 }
Francois Gougeta106edb2000-11-10 22:29:11 +0000474 my $project_settings=@$project[$P_SETTINGS];
Francois Gouget755bb922000-11-05 05:23:39 +0000475
476 # First find out what this directory contains:
477 # collect all sources, targets and subdirectories
478 my $directory=get_directory_contents($path);
479 foreach $dentry (@$directory) {
480 if ($dentry =~ /^\./) {
481 next;
482 }
483 my $fullentry="$path$dentry";
484 if (-d "$fullentry") {
485 if ($dentry =~ /^(Release|Debug)/i) {
486 # These directories are often used to store the object files and the
487 # resulting executable/library. They should not contain anything else.
488 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
489 foreach $candidate (@candidates) {
490 if ($candidate =~ s/\.exe$//i) {
491 $targets{$candidate}=1;
492 } elsif ($candidate =~ s/^(.*)\.dll$/lib$1.so/i) {
493 $targets{$candidate}=1;
494 }
495 }
Francois Gouget4ec10592000-12-02 20:12:45 +0000496 } elsif ($dentry =~ /^include/i) {
497 # This directory must contain headers we're going to need
498 push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
Francois Gouget3266b882001-03-03 00:17:11 +0000499 source_scan_directory($project,"$fullentry/","$dentry/",1);
Francois Gouget755bb922000-11-05 05:23:39 +0000500 } else {
501 # Recursively scan this directory. Any source file that cannot be
Francois Gouget3266b882001-03-03 00:17:11 +0000502 # attributed to a project in one of the subdirectories will be
503 # attributed to this project.
504 source_scan_directory($project,"$fullentry/","$dentry/",$no_target);
Francois Gouget755bb922000-11-05 05:23:39 +0000505 }
506 } elsif (-f "$fullentry") {
507 if ($dentry =~ s/\.exe$//i) {
508 $targets{$dentry}=1;
509 } elsif ($dentry =~ s/^(.*)\.dll$/lib$1.so/i) {
510 $targets{$dentry}=1;
511 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.spec\.c$/) {
512 push @sources_c,"$dentry";
513 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
Francois Gougeta106edb2000-11-10 22:29:11 +0000514 if ($dentry =~ /^stdafx.cpp$/i) {
515 push @sources_misc,"$dentry";
Francois Gouget82747b72000-11-25 01:38:39 +0000516 @$project_settings[$T_FLAGS]|=$TF_MFC;
Francois Gougeta106edb2000-11-10 22:29:11 +0000517 } else {
518 push @sources_cxx,"$dentry";
519 }
Francois Gouget755bb922000-11-05 05:23:39 +0000520 } elsif ($dentry =~ /\.rc$/i) {
521 push @sources_rc,"$dentry";
Francois Gouget3c6c20f2001-03-23 19:07:59 +0000522 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
Francois Gouget755bb922000-11-05 05:23:39 +0000523 push @sources_misc,"$dentry";
Francois Gougeta106edb2000-11-10 22:29:11 +0000524 if ($dentry =~ /^stdafx.h$/i) {
Francois Gouget82747b72000-11-25 01:38:39 +0000525 @$project_settings[$T_FLAGS]|=$TF_MFC;
Francois Gougeta106edb2000-11-10 22:29:11 +0000526 }
Francois Gouget755bb922000-11-05 05:23:39 +0000527 } elsif ($dentry =~ /\.dsp$/i) {
528 push @dsp_files,"$dentry";
529 $has_win_project=1;
530 } elsif ($dentry =~ /\.mak$/i) {
531 push @mak_files,"$dentry";
532 $has_win_project=1;
533 } elsif ($dentry =~ /^makefile/i) {
534 $has_win_project=1;
535 }
536 }
537 }
538 closedir(DIRECTORY);
539
540 # If we have a single target then all we have to do is assign
541 # all the sources to it and we're done
542 # FIXME: does this play well with the --interactive mode?
543 if ($opt_single_target) {
544 my $target=@{@$project[$P_TARGETS]}[0];
545 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
546 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
547 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
548 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
549 return;
550 }
Francois Gouget3266b882001-03-03 00:17:11 +0000551 if ($no_target) {
552 my $parent_settings=@$parent_project[$P_SETTINGS];
553 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
554 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
555 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
556 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
Francois Gouget647bb8f2001-04-20 18:26:35 +0000557 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
Francois Gouget3266b882001-03-03 00:17:11 +0000558 return;
559 }
Francois Gouget755bb922000-11-05 05:23:39 +0000560
Francois Gouget755bb922000-11-05 05:23:39 +0000561 my $source_count=@sources_c+@sources_cxx+@sources_rc+
562 @{@$project_settings[$T_SOURCES_C]}+
563 @{@$project_settings[$T_SOURCES_CXX]}+
564 @{@$project_settings[$T_SOURCES_RC]};
565 if ($source_count == 0) {
566 # A project without real sources is not a project, get out!
567 if ($project!=$parent_project) {
Francois Gouget3266b882001-03-03 00:17:11 +0000568 my $parent_settings=@$parent_project[$P_SETTINGS];
Francois Gouget755bb922000-11-05 05:23:39 +0000569 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
570 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
571 }
572 return;
573 }
574 #print "targets=",%targets,"\n";
575 #print "target_count=$target_count\n";
576 #print "has_win_project=$has_win_project\n";
577 #print "dirname=$dirname\n";
578
579 my $target_count;
580 if (($has_win_project != 0) or ($dirname eq "")) {
581 # Deal with cases where we could not find any executable/library, and
582 # thus have no target, although we did find some sort of windows project.
583 $target_count=keys %targets;
584 if ($target_count == 0) {
585 # Try to come up with a target list based on .dsp/.mak files
586 my $prj_list;
587 if (@dsp_files > 0) {
588 $prj_list=\@dsp_files;
589 } else {
590 $prj_list=\@mak_files;
591 }
592 foreach $filename (@$prj_list) {
593 $filename =~ s/\.(dsp|mak)$//i;
594 if ($opt_target_type == $TT_DLL) {
595 $filename = "lib$filename.so";
596 }
597 $targets{$filename}=1;
598 }
599 $target_count=keys %targets;
600 if ($target_count == 0) {
601 # Still nothing, try the name of the directory
602 my $name;
603 if ($dirname eq "") {
604 # Bad luck, this is the top level directory!
605 $name=(split /\//, cwd)[-1];
606 } else {
607 $name=$dirname;
608 # Remove the trailing '/'. Also eliminate whatever is after the last
609 # '.' as it is likely to be meaningless (.orig, .new, ...)
610 $name =~ s+(/|\.[^.]*)$++;
611 if ($name eq "src") {
612 # 'src' is probably a subdirectory of the real project directory.
613 # Try again with the parent (if any).
614 my $parent=$path;
615 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
616 $name=$parent;
617 } else {
618 $name=(split /\//, cwd)[-1];
619 }
620 }
621 }
622 $name =~ s+(/|\.[^.]*)$++;
623 if ($opt_target_type == $TT_DLL) {
624 $name = "lib$name.so";
625 }
626 $targets{$name}=1;
627 }
628 }
629
630 # Ask confirmation to the user if he wishes so
631 if ($opt_is_interactive == $OPT_ASK_YES) {
632 my $target_list=join " ",keys %targets;
Francois Gougetfb5b5902000-11-30 20:34:39 +0000633 print "\n*** In ",($path?$path:"./"),"\n";
Francois Gougeta106edb2000-11-10 22:29:11 +0000634 print "* winemaker found the following list of (potential) targets\n";
635 print "* $target_list\n";
636 print "* Type enter to use it as is, your own comma-separated list of\n";
637 print "* targets, 'none' to assign the source files to a parent directory,\n";
638 print "* or 'ignore' to ignore everything in this directory tree.\n";
639 print "* Target list:\n";
Francois Gouget755bb922000-11-05 05:23:39 +0000640 $target_list=<STDIN>;
641 chomp $target_list;
642 if ($target_list eq "") {
643 # Keep the target list as is, i.e. do nothing
644 } elsif ($target_list eq "none") {
645 # Empty the target list
646 undef %targets;
647 } elsif ($target_list eq "ignore") {
648 # Ignore this subtree altogether
649 return;
650 } else {
651 undef %targets;
652 foreach $target (split /,/,$target_list) {
653 $target =~ s+^\s*++;
654 $target =~ s+\s*$++;
655 # Also accept .exe and .dll as a courtesy
656 $target =~ s+(.*)\.dll$+lib$1.so+;
657 $target =~ s+\.exe$++;
658 $targets{$target}=1;
659 }
660 }
661 }
662 }
663
664 # If we have no project at this level, then transfer all
665 # the sources to the parent project
666 $target_count=keys %targets;
667 if ($target_count == 0) {
668 if ($project!=$parent_project) {
669 my $parent_settings=@$parent_project[$P_SETTINGS];
670 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
671 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
672 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
673 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
674 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
675 }
676 return;
677 }
678
679 # Otherwise add this project to the project list, except for
680 # the main project which is already in the list.
681 if ($dirname ne "") {
682 push @projects,$project;
683 }
684
685 # Ask for project-wide options
686 if ($opt_ask_project_options == $OPT_ASK_YES) {
Francois Gougeta106edb2000-11-10 22:29:11 +0000687 my $flag_desc="";
688 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
689 $flag_desc="mfc";
690 }
691 if ((@$project_settings[$T_FLAGS] & $TF_WRAP)!=0) {
692 if ($flag_desc ne "") {
693 $flag_desc.=", ";
694 }
695 $flag_desc.="wrapped";
696 }
Francois Gouget3af251e2000-11-30 20:36:04 +0000697 print "* Type any project-wide options (-D/-I/-L/-i/-l/--mfc/--wrap),\n";
Francois Gougeta106edb2000-11-10 22:29:11 +0000698 if (defined $flag_desc) {
699 print "* (currently $flag_desc)\n";
700 }
701 print "* or 'skip' to skip the target specific options,\n";
702 print "* or 'never' to not be asked this question again:\n";
Francois Gouget3af251e2000-11-30 20:36:04 +0000703 while (1) {
704 my $options=<STDIN>;
705 chomp $options;
706 if ($options eq "skip") {
707 $opt_ask_target_options=$OPT_ASK_SKIP;
708 last;
709 } elsif ($options eq "never") {
710 $opt_ask_project_options=$OPT_ASK_NO;
711 last;
712 } elsif (source_set_options($project_settings,$options)) {
713 last;
714 }
715 print "Please re-enter the options:\n";
Francois Gouget755bb922000-11-05 05:23:39 +0000716 }
717 }
718
719 # - Create the targets
720 # - Check if we have both libraries and programs
721 # - Match each target with source files (sort in reverse
722 # alphabetical order to get the longest matches first)
723 my @local_imports=();
724 my @local_depends=();
Francois Gougetbe859592000-11-15 22:12:20 +0000725 my @exe_list=();
Francois Gouget755bb922000-11-05 05:23:39 +0000726 foreach $target_name (sort { $b cmp $a } keys %targets) {
727 # Create the target...
728 my $basename;
729 my $target=[];
730 target_init($target);
731 @$target[$T_NAME]=$target_name;
Francois Gougeta106edb2000-11-10 22:29:11 +0000732 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
Francois Gouget755bb922000-11-05 05:23:39 +0000733 if ($target_name =~ /^lib(.*)\.so$/) {
734 @$target[$T_TYPE]=$TT_DLL;
735 @$target[$T_INIT]=get_default_init($TT_DLL);
736 @$target[$T_FLAGS]&=~$TF_WRAP;
737 $basename=$1;
738 push @local_depends,$target_name;
739 push @local_imports,$basename;
740 } else {
741 @$target[$T_TYPE]=$opt_target_type;
742 @$target[$T_INIT]=get_default_init($opt_target_type);
743 $basename=$target_name;
Francois Gougetbe859592000-11-15 22:12:20 +0000744 push @exe_list,$target;
Francois Gouget755bb922000-11-05 05:23:39 +0000745 }
Francois Gouget73995e22000-12-15 22:58:55 +0000746 # This is the default link list of Visual Studio, except odbccp32
747 # which we don't have in Wine. Also I add ntdll which seems
Francois Gouget4ec10592000-12-02 20:12:45 +0000748 # necessary for Winelib.
Francois Gouget49fc3172001-03-10 19:15:16 +0000749 my @std_imports=qw(advapi32.dll comdlg32.dll gdi32.dll kernel32.dll ntdll.dll odbc32.dll ole32.dll oleaut32.dll shell32.dll user32.dll winspool.drv);
Francois Gougetbe859592000-11-15 22:12:20 +0000750 @$target[$T_IMPORTS]=\@std_imports;
Francois Gouget755bb922000-11-05 05:23:39 +0000751 push @{@$project[$P_TARGETS]},$target;
752
753 # Ask for target-specific options
754 if ($opt_ask_target_options == $OPT_ASK_YES) {
Francois Gougeta106edb2000-11-10 22:29:11 +0000755 my $flag_desc="";
756 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
757 $flag_desc=" (mfc";
758 }
759 if ((@$target[$T_FLAGS] & $TF_WRAP)!=0) {
760 if ($flag_desc ne "") {
761 $flag_desc.=", ";
762 } else {
763 $flag_desc=" (";
764 }
765 $flag_desc.="wrapped";
766 }
767 if ($flag_desc ne "") {
768 $flag_desc.=")";
769 }
Francois Gouget3af251e2000-11-30 20:36:04 +0000770 print "* Specify any link option (-L/-i/-l/--mfc/--wrap) specific to the target\n";
Francois Gougeta106edb2000-11-10 22:29:11 +0000771 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
Francois Gouget3af251e2000-11-30 20:36:04 +0000772 while (1) {
773 my $options=<STDIN>;
774 chomp $options;
775 if ($options eq "never") {
776 $opt_ask_target_options=$OPT_ASK_NO;
777 last;
778 } elsif (source_set_options($target,$options)) {
779 last;
780 }
781 print "Please re-enter the options:\n";
Francois Gouget755bb922000-11-05 05:23:39 +0000782 }
783 }
784 if (@$target[$T_FLAGS] & $TF_MFC) {
785 @$project_settings[$T_FLAGS]|=$TF_MFC;
786 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
Francois Gougetbe859592000-11-15 22:12:20 +0000787 push @{@$target[$T_IMPORTS]},"mfc.dll";
788 # FIXME: Link with the MFC in the Unix sense, until we
789 # start exporting the functions properly.
790 push @{@$target[$T_LIBRARIES]},"mfc";
Francois Gouget755bb922000-11-05 05:23:39 +0000791 }
792
793 # Match sources...
794 if ($target_count == 1) {
Francois Gouget4ec10592000-12-02 20:12:45 +0000795 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
796 @$project_settings[$T_SOURCES_C]=[];
Francois Gouget755bb922000-11-05 05:23:39 +0000797 @sources_c=();
Francois Gouget4ec10592000-12-02 20:12:45 +0000798
799 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
800 @$project_settings[$T_SOURCES_CXX]=[];
Francois Gouget755bb922000-11-05 05:23:39 +0000801 @sources_cxx=();
Francois Gouget4ec10592000-12-02 20:12:45 +0000802
803 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
804 @$project_settings[$T_SOURCES_RC]=[];
Francois Gouget755bb922000-11-05 05:23:39 +0000805 @sources_rc=();
Francois Gouget4ec10592000-12-02 20:12:45 +0000806
807 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
808 # No need for sorting these sources
809 @$project_settings[$T_SOURCES_MISC]=[];
Francois Gouget755bb922000-11-05 05:23:39 +0000810 @sources_misc=();
811 } else {
812 foreach $source (@sources_c) {
813 if ($source =~ /^$basename/i) {
814 push @{@$target[$T_SOURCES_C]},$source;
815 $source="";
816 }
817 }
818 foreach $source (@sources_cxx) {
819 if ($source =~ /^$basename/i) {
820 push @{@$target[$T_SOURCES_CXX]},$source;
821 $source="";
822 }
823 }
824 foreach $source (@sources_rc) {
825 if ($source =~ /^$basename/i) {
826 push @{@$target[$T_SOURCES_RC]},$source;
827 $source="";
828 }
829 }
830 foreach $source (@sources_misc) {
831 if ($source =~ /^$basename/i) {
832 push @{@$target[$T_SOURCES_MISC]},$source;
833 $source="";
834 }
835 }
836 }
837 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
838 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
839 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
840 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
841 }
842 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
843 $opt_ask_target_options=$OPT_ASK_YES;
844 }
845
846 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
847 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
848 }
849 # The sources that did not match, if any, go to the extra
850 # source list of the project settings
851 foreach $source (@sources_c) {
852 if ($source ne "") {
853 push @{@$project_settings[$T_SOURCES_C]},$source;
854 }
855 }
856 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
857 foreach $source (@sources_cxx) {
858 if ($source ne "") {
859 push @{@$project_settings[$T_SOURCES_CXX]},$source;
860 }
861 }
862 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
863 foreach $source (@sources_rc) {
864 if ($source ne "") {
865 push @{@$project_settings[$T_SOURCES_RC]},$source;
866 }
867 }
868 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
869 foreach $source (@sources_misc) {
870 if ($source ne "") {
871 push @{@$project_settings[$T_SOURCES_MISC]},$source;
872 }
873 }
874 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
875
876 # Finally if we are building both libraries and programs in
877 # this directory, then the programs should be linked with all
878 # the libraries
Francois Gougetbe859592000-11-15 22:12:20 +0000879 if (@local_imports > 0 and @exe_list > 0) {
880 foreach $target (@exe_list) {
Francois Gougeta106edb2000-11-10 22:29:11 +0000881 push @{@$target[$T_LIBRARY_PATH]},"-L.";
Francois Gougetbe859592000-11-15 22:12:20 +0000882 push @{@$target[$T_IMPORTS]},map { "$_.dll" } @local_imports;
883 # Also link in the Unix sense since none of the functions
884 # will be exported.
885 push @{@$target[$T_LIBRARIES]},@local_imports;
Francois Gouget755bb922000-11-05 05:23:39 +0000886 push @{@$target[$T_DEPENDS]},@local_depends;
887 }
888 }
889}
890
891##
892# Scan the source directories in search of things to build
893sub source_scan
894{
Francois Gouget755bb922000-11-05 05:23:39 +0000895 # If there's a single target then this is going to be the default target
896 if (defined $opt_single_target) {
François Gouget38b3ac52001-01-11 20:17:42 +0000897 # Create the main target
898 my $main_target=[];
899 target_init($main_target);
Francois Gouget755bb922000-11-05 05:23:39 +0000900 if ($opt_target_type == $TT_DLL) {
901 @$main_target[$T_NAME]="lib$opt_single_target.so";
902 } else {
903 @$main_target[$T_NAME]="$opt_single_target";
904 }
905 @$main_target[$T_TYPE]=$opt_target_type;
François Gouget38b3ac52001-01-11 20:17:42 +0000906
907 # Add it to the list
908 push @{$main_project[$P_TARGETS]},$main_target;
Francois Gouget755bb922000-11-05 05:23:39 +0000909 }
910
911 # The main directory is always going to be there
912 push @projects,\@main_project;
913
914 # Now scan the directory tree looking for source files and, maybe, targets
915 print "Scanning the source directories...\n";
Francois Gouget3266b882001-03-03 00:17:11 +0000916 source_scan_directory(\@main_project,"","",0);
Francois Gouget755bb922000-11-05 05:23:39 +0000917
918 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
919}
920
921
922
923#####
924#
925# 'vc.dsp'-based Project analysis
926#
927#####
928
929#sub analyze_vc_dsp
930#{
931#
932#}
933
934
935
936#####
937#
938# Creating the wrapper targets
939#
940#####
941
Francois Gougeta106edb2000-11-10 22:29:11 +0000942sub postprocess_targets
Francois Gouget755bb922000-11-05 05:23:39 +0000943{
944 foreach $project (@projects) {
945 foreach $target (@{@$project[$P_TARGETS]}) {
946 if ((@$target[$T_FLAGS] & $TF_WRAP) != 0) {
947 my $wrapper=[];
948 target_init($wrapper);
949 @$wrapper[$T_NAME]=@$target[$T_NAME];
950 @$wrapper[$T_TYPE]=@$target[$T_TYPE];
951 @$wrapper[$T_INIT]=get_default_init(@$target[$T_TYPE]);
952 @$wrapper[$T_FLAGS]=$TF_WRAPPER | (@$target[$T_FLAGS] & $TF_MFC);
Francois Gouget3c6c20f2001-03-23 19:07:59 +0000953 @$wrapper[$T_IMPORTS]=[ "kernel32.dll", "ntdll.dll", "user32.dll" ];
Francois Gouget755bb922000-11-05 05:23:39 +0000954 push @{@$wrapper[$T_SOURCES_C]},"@$wrapper[$T_NAME]_wrapper.c";
955
956 my $index=bsearch(@$target[$T_SOURCES_C],"@$wrapper[$T_NAME]_wrapper.c");
957 if (defined $index) {
958 splice(@{@$target[$T_SOURCES_C]},$index,1);
959 }
960 @$target[$T_NAME]="lib@$target[$T_NAME].so";
961 @$target[$T_TYPE]=$TT_DLL;
962
963 push @{@$project[$P_TARGETS]},$wrapper;
964 }
Francois Gougeta106edb2000-11-10 22:29:11 +0000965 if ((@$target[$T_FLAGS] & $TF_MFC) != 0) {
966 @{@$project[$P_SETTINGS]}[$T_FLAGS]|=$TF_MFC;
967 $needs_mfc=1;
968 }
Francois Gouget755bb922000-11-05 05:23:39 +0000969 }
970 }
971}
972
973
974
975#####
976#
977# Source search
978#
979#####
980
981##
982# Performs a directory traversal and renames the files so that:
983# - they have the case desired by the user
984# - their extension is of the appropriate case
985# - they don't contain annoying characters like ' ', '$', '#', ...
986sub fix_file_and_directory_names
987{
988 my $dirname=$_[0];
989
990 if (opendir(DIRECTORY, "$dirname")) {
991 foreach $dentry (readdir DIRECTORY) {
992 if ($dentry =~ /^\./ or $dentry eq "CVS") {
993 next;
994 }
995 # Set $warn to 1 if the user should be warned of the renaming
996 my $warn=0;
997
998 # autoconf and make don't support these characters well
999 my $new_name=$dentry;
1000 $new_name =~ s/[ \$]/_/g;
1001
Francois Gouget3af251e2000-11-30 20:36:04 +00001002 # Only all lowercase extensions are supported (because of the
1003 # transformations ':.c=.o') .
Francois Gouget755bb922000-11-05 05:23:39 +00001004 if (-f "$dirname/$new_name") {
Francois Gouget3af251e2000-11-30 20:36:04 +00001005 if ($new_name =~ /\.C$/) {
1006 $new_name =~ s/\.C$/.c/;
1007 }
1008 if ($new_name =~ /\.cpp$/i) {
Francois Gouget755bb922000-11-05 05:23:39 +00001009 $new_name =~ s/\.cpp$/.cpp/i;
1010 }
1011 if ($new_name =~ s/\.cxx$/.cpp/i) {
1012 $warn=1;
1013 }
Francois Gouget3af251e2000-11-30 20:36:04 +00001014 if ($new_name =~ /\.rc$/i) {
Francois Gouget755bb922000-11-05 05:23:39 +00001015 $new_name =~ s/\.rc$/.rc/i;
1016 }
1017 # And this last one is to avoid confusion then running make
1018 if ($new_name =~ s/^makefile$/makefile.win/) {
1019 $warn=1;
1020 }
1021 }
1022
1023 # Adjust the case to the user's preferences
1024 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1025 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1026 ) {
1027 $new_name=lc $new_name;
1028 }
1029
1030 # And finally, perform the renaming
1031 if ($new_name ne $dentry) {
1032 if ($warn) {
1033 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1034 }
1035 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1036 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1037 print STDERR " $!\n";
1038 $new_name=$dentry;
1039 }
1040 }
1041 if (-d "$dirname/$new_name") {
1042 fix_file_and_directory_names("$dirname/$new_name");
1043 }
1044 }
1045 closedir(DIRECTORY);
1046 }
1047}
1048
1049
1050
1051#####
1052#
1053# Source fixup
1054#
1055#####
1056
1057##
1058# This maps a directory name to a reference to an array listing
1059# its contents (files and directories)
1060my %directories;
1061
1062##
1063# Retrieves the contents of the specified directory.
1064# We either get it from the directories hashtable which acts as a
1065# cache, or use opendir, readdir, closedir and store the result
1066# in the hashtable.
1067sub get_directory_contents
1068{
1069 my $dirname=$_[0];
1070 my $directory;
1071
1072 #print "getting the contents of $dirname\n";
1073
1074 # check for a cached version
1075 $dirname =~ s+/$++;
1076 if ($dirname eq "") {
1077 $dirname=cwd;
1078 }
1079 $directory=$directories{$dirname};
1080 if (defined $directory) {
1081 #print "->@$directory\n";
1082 return $directory;
1083 }
1084
1085 # Read this directory
1086 if (opendir(DIRECTORY, "$dirname")) {
1087 my @files=readdir DIRECTORY;
1088 closedir(DIRECTORY);
1089 $directory=\@files;
1090 } else {
1091 # Return an empty list
1092 #print "error: cannot open $dirname\n";
1093 my @files;
1094 $directory=\@files;
1095 }
1096 #print "->@$directory\n";
1097 $directories{$dirname}=$directory;
1098 return $directory;
1099}
1100
1101##
1102# Try to find a file for the specified filename. The attempt is
1103# case-insensitive which is why it's not trivial. If a match is
1104# found then we return the pathname with the correct case.
1105sub search_from
1106{
1107 my $dirname=$_[0];
1108 my $path=$_[1];
1109 my $real_path="";
1110
1111 if ($dirname eq "" or $dirname eq ".") {
1112 $dirname=cwd;
1113 } elsif ($dirname =~ m+^[^/]+) {
1114 $dirname=cwd . "/" . $dirname;
1115 }
1116 if ($dirname !~ m+/$+) {
1117 $dirname.="/";
1118 }
1119
1120 foreach $component (@$path) {
Francois Gougetb4302952000-11-07 20:27:16 +00001121 #print " looking for $component in \"$dirname\"\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001122 if ($component eq ".") {
1123 # Pass it as is
1124 $real_path.="./";
1125 } elsif ($component eq "..") {
1126 # Go up one level
1127 $dirname=dirname($dirname) . "/";
1128 $real_path.="../";
1129 } else {
Francois Gouget3fafafa2001-04-23 18:16:13 +00001130 # The file/directory may have been renamed before. Also try to
1131 # match the renamed file.
1132 my $renamed=$component;
1133 $renamed =~ s/[ \$]/_/g;
1134 if ($renamed eq $component) {
1135 undef $renamed;
1136 }
1137
Francois Gouget755bb922000-11-05 05:23:39 +00001138 my $directory=get_directory_contents $dirname;
1139 my $found;
1140 foreach $dentry (@$directory) {
Francois Gouget3fafafa2001-04-23 18:16:13 +00001141 if ($dentry =~ /^$component$/i or
1142 (defined $renamed and $dentry =~ /^$renamed$/i)
1143 ) {
Francois Gouget755bb922000-11-05 05:23:39 +00001144 $dirname.="$dentry/";
1145 $real_path.="$dentry/";
1146 $found=1;
1147 last;
1148 }
1149 }
1150 if (!defined $found) {
1151 # Give up
Francois Gougetb4302952000-11-07 20:27:16 +00001152 #print " could not find $component in $dirname\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001153 return;
1154 }
1155 }
1156 }
1157 $real_path=~ s+/$++;
Francois Gougetb4302952000-11-07 20:27:16 +00001158 #print " -> found $real_path\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001159 return $real_path;
1160}
1161
1162##
1163# Performs a case-insensitive search for the specified file in the
1164# include path.
1165# $line is the line number that should be referenced when an error occurs
1166# $filename is the file we are looking for
1167# $dirname is the directory of the file containing the '#include' directive
1168# if '"' was used, it is an empty string otherwise
1169# $project and $target specify part of the include path
1170sub get_real_include_name
1171{
1172 my $line=$_[0];
1173 my $filename=$_[1];
1174 my $dirname=$_[2];
1175 my $project=$_[3];
1176 my $target=$_[4];
1177
1178 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1179 # This is not a relative path, we cannot make any check
1180 my $warning="path:$filename";
1181 if (!defined $warnings{$warning}) {
1182 $warnings{$warning}="1";
1183 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1184 print STDERR "$line: $filename\n";
1185 }
1186 } else {
1187 # Here's how we proceed:
1188 # - split the filename we look for into its components
1189 # - then for each directory in the include path
1190 # - trace the directory components starting from that directory
1191 # - if we fail to find a match at any point then continue with
1192 # the next directory in the include path
1193 # - otherwise, rejoice, our quest is over.
1194 my @file_components=split /[\/\\]+/, $filename;
Francois Gougetb4302952000-11-07 20:27:16 +00001195 #print " Searching for $filename from @$project[$P_PATH]\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001196
1197 my $real_filename;
1198 if ($dirname ne "") {
Francois Gougetb4302952000-11-07 20:27:16 +00001199 # This is an 'include ""' -> look in dirname first.
1200 #print " in $dirname (include \"\")\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001201 $real_filename=search_from($dirname,\@file_components);
1202 if (defined $real_filename) {
1203 return $real_filename;
1204 }
1205 }
1206 my $project_settings=@$project[$P_SETTINGS];
Francois Gougetb4302952000-11-07 20:27:16 +00001207 foreach $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1208 my $dirname=$include;
1209 $dirname=~ s+^-I++;
1210 if (!is_absolute($dirname)) {
1211 $dirname="@$project[$P_PATH]$dirname";
1212 } else {
Francois Gouget647bb8f2001-04-20 18:26:35 +00001213 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1214 $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
Francois Gougetb4302952000-11-07 20:27:16 +00001215 }
1216 #print " in $dirname\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001217 $real_filename=search_from("$dirname",\@file_components);
1218 if (defined $real_filename) {
1219 return $real_filename;
1220 }
1221 }
1222 my $dotdotpath=@$project[$P_PATH];
1223 $dotdotpath =~ s/[^\/]+/../g;
Francois Gougetb4302952000-11-07 20:27:16 +00001224 foreach $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1225 my $dirname=$include;
1226 $dirname=~ s+^-I++;
1227 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
Francois Gouget647bb8f2001-04-20 18:26:35 +00001228 $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
Francois Gougetb4302952000-11-07 20:27:16 +00001229 #print " in $dirname (global setting)\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001230 $real_filename=search_from("$dirname",\@file_components);
1231 if (defined $real_filename) {
1232 return $real_filename;
1233 }
1234 }
1235 }
1236 $filename =~ s+\\\\+/+g; # in include ""
1237 $filename =~ s+\\+/+g; # in include <> !
Francois Gougeta106edb2000-11-10 22:29:11 +00001238 if ($opt_lower_include) {
Francois Gouget755bb922000-11-05 05:23:39 +00001239 return lc "$filename";
1240 }
1241 return $filename;
1242}
1243
Francois Gougetc1159be2001-04-18 17:39:42 +00001244sub print_pack
1245{
1246 my $indent=$_[0];
1247 my $size=$_[1];
1248 my $trailer=$_[2];
1249
1250 if ($size =~ /^(1|2|4|8)$/) {
1251 print FILEO "$indent#include <pshpack$size.h>$trailer";
1252 } else {
1253 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1254 print FILEO "$indent#include <pshpack4.h>$trailer";
1255 }
1256}
1257
Francois Gouget755bb922000-11-05 05:23:39 +00001258##
1259# 'Parses' a source file and fixes constructs that would not work with
1260# Winelib. The parsing is rather simple and not all non-portable features
1261# are corrected. The most important feature that is corrected is the case
1262# and path separator of '#include' directives. This requires that each
1263# source file be associated to a project & target so that the proper
1264# include path is used.
Francois Gougetb4302952000-11-07 20:27:16 +00001265# Also note that the include path is relative to the directory in which the
1266# compiler is run, i.e. that of the project, not to that of the file.
Francois Gouget755bb922000-11-05 05:23:39 +00001267sub fix_file
1268{
1269 my $filename=$_[0];
1270 my $project=$_[1];
1271 my $target=$_[2];
1272 $filename="@$project[$P_PATH]$filename";
1273 if (! -e $filename) {
1274 return;
1275 }
1276
1277 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1278 my $dirname=dirname($filename);
1279 my $is_mfc=0;
1280 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1281 $is_mfc=1;
1282 }
1283
1284 print " $filename\n";
1285 #FIXME:assuming that because there is a .bak file, this is what we want is
1286 #probably flawed. Or is it???
1287 if (! -e "$filename.bak") {
1288 if (!copy("$filename","$filename.bak")) {
1289 print STDERR "error: unable to make a backup of $filename:\n";
1290 print STDERR " $!\n";
1291 return;
1292 }
1293 }
1294 if (!open(FILEI,"$filename.bak")) {
1295 print STDERR "error: unable to open $filename.bak for reading:\n";
1296 print STDERR " $!\n";
1297 return;
1298 }
1299 if (!open(FILEO,">$filename")) {
1300 print STDERR "error: unable to open $filename for writing:\n";
1301 print STDERR " $!\n";
1302 return;
1303 }
1304 my $line=0;
1305 my $modified=0;
1306 my $rc_block_depth=0;
1307 my $rc_textinclude_state=0;
Francois Gougetc1159be2001-04-18 17:39:42 +00001308 my @pack_stack;
Francois Gouget755bb922000-11-05 05:23:39 +00001309 while (<FILEI>) {
1310 $line++;
François Gougeta62703e2001-02-12 01:22:58 +00001311 s/\r\n$/\n/;
1312 if (!/\n$/) {
1313 # Make sure all files are '\n' terminated
1314 $_ .= "\n";
1315 }
Francois Gougetc1159be2001-04-18 17:39:42 +00001316 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
Francois Gouget755bb922000-11-05 05:23:39 +00001317 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1318 # the RC files it generates (even in non-MFC projects). So we replace
1319 # it with 'winres.h' its very close standard cousin so that non MFC
François Gougeta62703e2001-02-12 01:22:58 +00001320 # projects can compile in Wine without the MFC sources.
Francois Gouget755bb922000-11-05 05:23:39 +00001321 my $warning="mfc:afxres.h";
1322 if (!defined $warnings{$warning}) {
1323 $warnings{$warning}="1";
1324 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winres.h'\n";
1325 print STDERR "warning: the above warning is issued only once\n";
1326 }
Francois Gougetc1159be2001-04-18 17:39:42 +00001327 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
1328 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winres.h' */\n";
1329 print FILEO "$1$2\"winres.h\"$'";
Francois Gouget755bb922000-11-05 05:23:39 +00001330 $modified=1;
Francois Gougetc1159be2001-04-18 17:39:42 +00001331
Francois Gouget755bb922000-11-05 05:23:39 +00001332 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1333 my $from_file=($2 eq "<"?"":$dirname);
1334 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1335 print FILEO "$1$2$real_include_name$4$'";
1336 $modified|=($real_include_name ne $3);
Francois Gougetc1159be2001-04-18 17:39:42 +00001337
1338 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
1339 # Pragma pack handling
1340 #
1341 # pack_stack is an array of references describing the stack of
1342 # pack directives currently in effect. Each directive if described
1343 # by a reference to an array containing:
1344 # - "push" for pack(push,...) directives, "" otherwise
1345 # - the directive's identifier at index 1
1346 # - the directive's alignement value at index 2
1347 #
1348 # Don't believe a word of what the documentation says: it's all wrong.
1349 # The code below is based on the actual behavior of Visual C/C++ 6.
1350 my $pack_indent=$1;
1351 my $pack_header=$2;
1352 if (/^(\))/) {
1353 # pragma pack()
1354 # Pushes the default stack alignment
1355 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1356 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1357 print_pack($pack_indent,4,$');
1358 push @pack_stack, [ "", "", 4 ];
1359
1360 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
1361 # pragma pack(pop)
1362 # pragma pack(pop,n)
1363 # Goes up the stack until it finds a pack(push,...), and pops it
1364 # Ignores any pack(n) entry
1365 # Issues a warning if the pack is of the form pack(push,label)
1366 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1367 my $pack_comment=$';
Francois Gouget647bb8f2001-04-20 18:26:35 +00001368 $pack_comment =~ s/^\s*//;
Francois Gougetc1159be2001-04-18 17:39:42 +00001369 if ($pack_comment ne "") {
1370 print FILEO "$pack_indent$pack_comment";
1371 }
1372 while (1) {
1373 my $alignment=pop @pack_stack;
1374 if (!defined $alignment) {
1375 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
1376 last;
1377 }
1378 if (@$alignment[1]) {
1379 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
1380 }
1381 print FILEO "$pack_indent#include <poppack.h>\n";
1382 if (@$alignment[0]) {
1383 last;
1384 }
1385 }
1386
1387 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
1388 # pragma pack(pop,label[,n])
1389 # Goes up the stack until finding a pack(push,...) and pops it.
1390 # 'n', if specified, is ignored.
1391 # Ignores any pack(n) entry
1392 # Issues a warning if the label of the pack does not match,
1393 # or if it is in fact a pack(push,n)
1394 my $label=$2;
1395 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1396 my $pack_comment=$';
Francois Gouget647bb8f2001-04-20 18:26:35 +00001397 $pack_comment =~ s/^\s*//;
Francois Gougetc1159be2001-04-18 17:39:42 +00001398 if ($pack_comment ne "") {
1399 print FILEO "$pack_indent$pack_comment";
1400 }
1401 while (1) {
1402 my $alignment=pop @pack_stack;
1403 if (!defined $alignment) {
1404 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
1405 last;
1406 }
1407 if (@$alignment[1] and @$alignment[1] ne $label) {
1408 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
1409 }
1410 print FILEO "$pack_indent#include <poppack.h>\n";
1411 if (@$alignment[0]) {
1412 last;
1413 }
1414 }
1415
1416 } elsif (/^(push\s*\))/) {
1417 # pragma pack(push)
1418 # Push the current alignment
1419 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1420 if (@pack_stack > 0) {
1421 my $alignment=$pack_stack[$#pack_stack];
1422 print_pack($pack_indent,@$alignment[2],$');
1423 push @pack_stack, [ "push", "", @$alignment[2] ];
1424 } else {
1425 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1426 print_pack($pack_indent,4,$');
1427 push @pack_stack, [ "push", "", 4 ];
1428 }
1429
1430 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
1431 # pragma pack([push,]n)
1432 # Push new alignment n
1433 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1434 print_pack($pack_indent,$3,"$'");
1435 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
1436
1437 } elsif (/^((\w+)\s*\))/) {
1438 # pragma pack(label)
1439 # label must in fact be a macro that resolves to an integer
1440 # Then behaves like 'pragma pack(n)'
1441 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1442 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
1443 print_pack($pack_indent,4,$');
1444 push @pack_stack, [ "", "", 4 ];
1445
1446 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
1447 # pragma pack(push,label[,n])
1448 # Pushes a new label on the stack. It is possible to push the same
1449 # label multiple times. If 'n' is omitted then the alignment is
1450 # unchanged. Otherwise it becomes 'n'.
1451 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1452 my $size;
1453 if (defined $4) {
1454 $size=$4;
1455 } elsif (@pack_stack > 0) {
1456 my $alignment=$pack_stack[$#pack_stack];
1457 $size=@$alignment[2];
1458 } else {
1459 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1460 $size=4;
1461 }
1462 print_pack($pack_indent,$size,$');
1463 push @pack_stack, [ "push", $2, $size ];
1464
Francois Gouget755bb922000-11-05 05:23:39 +00001465 } else {
Francois Gougetc1159be2001-04-18 17:39:42 +00001466 # pragma pack(??? -> What's that?
1467 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
1468 print FILEO "$pack_indent$pack_header$_";
1469
Francois Gouget755bb922000-11-05 05:23:39 +00001470 }
Francois Gougetc1159be2001-04-18 17:39:42 +00001471 $modified=1;
1472
Francois Gouget755bb922000-11-05 05:23:39 +00001473 } elsif ($is_rc) {
Francois Gouget647bb8f2001-04-20 18:26:35 +00001474 if ($rc_block_depth == 0 and /^(\w+\s+(BITMAP|CURSOR|FONT|FONTDIR|ICON|MESSAGETABLE|TEXT|RTF)\s+((DISCARDABLE|FIXED|IMPURE|LOADONCALL|MOVEABLE|PRELOAD|PURE)\s+)*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
Francois Gouget755bb922000-11-05 05:23:39 +00001475 my $from_file=($5 eq "<"?"":$dirname);
1476 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
1477 print FILEO "$1$5$real_include_name$7$'";
1478 $modified|=($real_include_name ne $6);
Francois Gougetc1159be2001-04-18 17:39:42 +00001479
Francois Gouget755bb922000-11-05 05:23:39 +00001480 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
1481 my $from_file=($2 eq "<"?"":$dirname);
1482 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1483 print FILEO "$1$2$real_include_name$4$'";
1484 $modified|=($real_include_name ne $3);
Francois Gougetc1159be2001-04-18 17:39:42 +00001485
Francois Gouget755bb922000-11-05 05:23:39 +00001486 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
1487 $rc_textinclude_state=1;
1488 print FILEO;
Francois Gougetc1159be2001-04-18 17:39:42 +00001489
Francois Gouget755bb922000-11-05 05:23:39 +00001490 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
1491 print FILEO "$1winres.h$2$'";
1492 $modified=1;
Francois Gougetc1159be2001-04-18 17:39:42 +00001493
Francois Gouget755bb922000-11-05 05:23:39 +00001494 } elsif (/^\s*BEGIN(\W.*)?$/) {
1495 $rc_textinclude_state|=2;
1496 $rc_block_depth++;
1497 print FILEO;
Francois Gougetc1159be2001-04-18 17:39:42 +00001498
Francois Gouget755bb922000-11-05 05:23:39 +00001499 } elsif (/^\s*END(\W.*)?$/) {
1500 $rc_textinclude_state=0;
1501 if ($rc_block_depth>0) {
1502 $rc_block_depth--;
1503 }
1504 print FILEO;
Francois Gougetc1159be2001-04-18 17:39:42 +00001505
Francois Gouget755bb922000-11-05 05:23:39 +00001506 } else {
1507 print FILEO;
1508 }
Francois Gougetc1159be2001-04-18 17:39:42 +00001509
Francois Gouget755bb922000-11-05 05:23:39 +00001510 } else {
1511 print FILEO;
1512 }
1513 }
Francois Gougetc1159be2001-04-18 17:39:42 +00001514
Francois Gouget755bb922000-11-05 05:23:39 +00001515 close(FILEI);
1516 close(FILEO);
1517 if ($opt_backup == 0 or $modified == 0) {
1518 if (!unlink("$filename.bak")) {
1519 print STDERR "error: unable to delete $filename.bak:\n";
1520 print STDERR " $!\n";
1521 }
1522 }
1523}
1524
1525##
1526# Analyzes each source file in turn to find and correct issues
1527# that would cause it not to compile.
1528sub fix_source
1529{
1530 print "Fixing the source files...\n";
1531 foreach $project (@projects) {
1532 foreach $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
1533 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1534 next;
1535 }
1536 foreach $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
1537 fix_file($source,$project,$target);
1538 }
1539 }
1540 }
1541}
1542
1543
1544
1545#####
1546#
1547# File generation
1548#
1549#####
1550
1551##
1552# Generates a target's .spec file
1553sub generate_spec_file
1554{
1555 my $path=$_[0];
1556 my $target=$_[1];
1557 my $project_settings=$_[2];
1558
1559 my $basename=@$target[$T_NAME];
1560 $basename =~ s+\.so$++;
1561 if (@$target[$T_FLAGS] & $TF_WRAP) {
1562 $basename =~ s+^lib++;
1563 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1564 $basename.="_wrapper";
1565 }
1566
1567 if (!open(FILEO,">$path$basename.spec")) {
1568 print STDERR "error: could not open \"$path$basename.spec\" for writing\n";
1569 print STDERR " $!\n";
1570 return;
1571 }
1572
Francois Gougeta11664c2000-12-07 23:13:23 +00001573 my $module=$basename;
1574 $module =~ s+^lib++;
1575 $module=canonize($module);
1576 print FILEO "name $module\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001577 print FILEO "type win32\n";
1578 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1579 print FILEO "mode guiexe\n";
1580 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1581 print FILEO "mode cuiexe\n";
1582 } else {
1583 print FILEO "mode dll\n";
1584 }
1585 if (defined @$target[$T_INIT] and ((@$target[$T_FLAGS] & $TF_WRAP) == 0)) {
1586 print FILEO "init @$target[$T_INIT]\n";
1587 }
1588 if (@{@$target[$T_SOURCES_RC]} > 0) {
1589 if (@{@$target[$T_SOURCES_RC]} > 1) {
1590 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";
1591 }
1592 my $rcname=@{@$target[$T_SOURCES_RC]}[0];
1593 $rcname =~ s+\.rc$++i;
Francois Gouget3fafafa2001-04-23 18:16:13 +00001594 $rcname =~ s+([^/\w])+\\$1+g;
Francois Gouget755bb922000-11-05 05:23:39 +00001595 print FILEO "rsrc $rcname.res\n";
1596 }
1597 print FILEO "\n";
Francois Gougetbe859592000-11-15 22:12:20 +00001598 my %imports;
Francois Gouget755bb922000-11-05 05:23:39 +00001599 foreach $library (@{$global_settings[$T_IMPORTS]}) {
Francois Gougetbe859592000-11-15 22:12:20 +00001600 if (!defined $imports{$library}) {
1601 print FILEO "import $library\n";
1602 $imports{$library}=1;
1603 }
Francois Gouget755bb922000-11-05 05:23:39 +00001604 }
1605 if (defined $project_settings) {
1606 foreach $library (@{@$project_settings[$T_IMPORTS]}) {
Francois Gougetbe859592000-11-15 22:12:20 +00001607 if (!defined $imports{$library}) {
1608 print FILEO "import $library\n";
1609 $imports{$library}=1;
1610 }
Francois Gouget755bb922000-11-05 05:23:39 +00001611 }
1612 }
1613 foreach $library (@{@$target[$T_IMPORTS]}) {
Francois Gougetbe859592000-11-15 22:12:20 +00001614 if (!defined $imports{$library}) {
1615 print FILEO "import $library\n";
1616 $imports{$library}=1;
1617 }
Francois Gouget755bb922000-11-05 05:23:39 +00001618 }
1619
1620 # Don't forget to export the 'Main' function for wrapped executables,
1621 # except for MFC ones!
1622 if (@$target[$T_FLAGS] == $TF_WRAP) {
1623 if (@$target[$T_TYPE] == $TT_GUIEXE) {
1624 print FILEO "\n@ stdcall @$target[$T_INIT](long long ptr long) @$target[$T_INIT]\n";
1625 } elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
1626 print FILEO "\n@ stdcall @$target[$T_INIT](long ptr ptr) @$target[$T_INIT]\n";
1627 } else {
1628 print FILEO "\n@ stdcall @$target[$T_INIT](ptr long ptr) @$target[$T_INIT]\n";
1629 }
1630 }
1631
1632 close(FILEO);
1633}
1634
1635##
1636# Generates a target's wrapper file
1637sub generate_wrapper_file
1638{
1639 my $path=$_[0];
1640 my $target=$_[1];
1641
1642 if (!defined $templates{"wrapper.c"}) {
1643 print STDERR "winemaker: internal error: No template called 'wrapper.c'\n";
1644 return;
1645 }
1646
1647 if (!open(FILEO,">$path@$target[$T_NAME]_wrapper.c")) {
1648 print STDERR "error: unable to open \"$path$basename.c\" for writing:\n";
1649 print STDERR " $!\n";
1650 return;
1651 }
1652 my $app_name="\"@$target[$T_NAME]\"";
1653 my $app_type=(@$target[$T_TYPE]==$TT_GUIEXE?"GUIEXE":"CUIEXE");
1654 my $app_init=(@$target[$T_TYPE]==$TT_GUIEXE?"\"WinMain\"":"\"main\"");
1655 my $app_mfc=(@$target[$T_FLAGS] & $TF_MFC?"\"mfc\"":NULL);
1656 foreach $line (@{$templates{"wrapper.c"}}) {
Francois Gouget3c6c20f2001-03-23 19:07:59 +00001657 my $l=$line;
1658 $l =~ s/\#\#WINEMAKER_APP_NAME\#\#/$app_name/;
1659 $l =~ s/\#\#WINEMAKER_APP_TYPE\#\#/$app_type/;
1660 $l =~ s/\#\#WINEMAKER_APP_INIT\#\#/$app_init/;
1661 $l =~ s/\#\#WINEMAKER_APP_MFC\#\#/$app_mfc/;
1662 print FILEO $l;
Francois Gouget755bb922000-11-05 05:23:39 +00001663 }
1664 close(FILEO);
1665}
1666
1667##
1668# A convenience function to generate all the lists (defines,
1669# C sources, C++ source, etc.) in the Makefile
1670sub generate_list
1671{
1672 my $name=$_[0];
1673 my $last=$_[1];
1674 my $list=$_[2];
1675 my $data=$_[3];
Francois Gouget82747b72000-11-25 01:38:39 +00001676 my $first=$name;
Francois Gouget755bb922000-11-05 05:23:39 +00001677
1678 if ($name) {
Francois Gougetfb5b5902000-11-30 20:34:39 +00001679 printf FILEO "%-22s=",$name;
Francois Gouget755bb922000-11-05 05:23:39 +00001680 }
Francois Gouget82747b72000-11-25 01:38:39 +00001681 if (defined $list) {
Francois Gouget755bb922000-11-05 05:23:39 +00001682 foreach $item (@$list) {
1683 my $value;
1684 if (defined $data) {
1685 $value=&$data($item);
1686 } else {
1687 $value=$item;
1688 }
1689 if ($value ne "") {
Francois Gouget82747b72000-11-25 01:38:39 +00001690 if ($first) {
1691 print FILEO " $value";
1692 $first=0;
1693 } else {
1694 print FILEO " \\\n\t\t\t$value";
1695 }
Francois Gouget755bb922000-11-05 05:23:39 +00001696 }
1697 }
1698 }
1699 if ($last) {
Francois Gouget82747b72000-11-25 01:38:39 +00001700 print FILEO "\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001701 }
1702}
1703
1704##
1705# Generates a project's Makefile.in and all the target files
1706sub generate_project_files
1707{
1708 my $project=$_[0];
1709 my $project_settings=@$project[$P_SETTINGS];
Francois Gougetbe859592000-11-15 22:12:20 +00001710 my @dll_list=();
1711 my @exe_list=();
Francois Gouget755bb922000-11-05 05:23:39 +00001712
1713 # Then sort the targets and separate the libraries from the programs
1714 foreach $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
1715 if (@$target[$T_TYPE] == $TT_DLL) {
Francois Gougetbe859592000-11-15 22:12:20 +00001716 push @dll_list,$target;
Francois Gouget755bb922000-11-05 05:23:39 +00001717 } else {
Francois Gougetbe859592000-11-15 22:12:20 +00001718 push @exe_list,$target;
Francois Gouget755bb922000-11-05 05:23:39 +00001719 }
1720 }
1721 @$project[$P_TARGETS]=[];
Francois Gougetbe859592000-11-15 22:12:20 +00001722 push @{@$project[$P_TARGETS]}, @dll_list;
1723 push @{@$project[$P_TARGETS]}, @exe_list;
Francois Gouget755bb922000-11-05 05:23:39 +00001724
1725 if (!open(FILEO,">@$project[$P_PATH]Makefile.in")) {
1726 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile.in\" for writing\n";
1727 print STDERR " $!\n";
1728 return;
1729 }
1730
Francois Gougetbe859592000-11-15 22:12:20 +00001731 print FILEO "### Generated by Winemaker\n";
1732 print FILEO "\n\n";
1733
Francois Gouget755bb922000-11-05 05:23:39 +00001734 print FILEO "### Generic autoconf variables\n\n";
Francois Gougetfb5b5902000-11-30 20:34:39 +00001735 generate_list("TOPSRCDIR",1,[ "\@top_srcdir\@" ]);
1736 generate_list("TOPOBJDIR",1,[ "." ]);
1737 generate_list("SRCDIR",1,[ "\@srcdir\@" ]);
1738 generate_list("VPATH",1,[ "\@srcdir\@" ]);
Francois Gouget755bb922000-11-05 05:23:39 +00001739 print FILEO "\n";
1740 if (@$project[$P_PATH] eq "") {
1741 # This is the main project. It is also responsible for recursively
1742 # calling the other projects
1743 generate_list("SUBDIRS",1,\@projects,sub
1744 {
1745 if ($_[0] != \@main_project) {
1746 my $subdir=@{$_[0]}[$P_PATH];
1747 $subdir =~ s+/$++;
1748 return $subdir;
1749 }
1750 # Eliminating the main project by returning undefined!
1751 });
1752 }
1753 if (@{@$project[$P_TARGETS]} > 0) {
Francois Gouget35246cb2001-05-07 18:19:57 +00001754 generate_list("DLLS",1,\@dll_list,sub
Francois Gouget755bb922000-11-05 05:23:39 +00001755 {
1756 return @{$_[0]}[$T_NAME];
1757 });
Francois Gouget35246cb2001-05-07 18:19:57 +00001758 generate_list("EXES",1,\@exe_list,sub
Francois Gouget755bb922000-11-05 05:23:39 +00001759 {
Francois Gougetbe859592000-11-15 22:12:20 +00001760 return "@{$_[0]}[$T_NAME]";
Francois Gouget755bb922000-11-05 05:23:39 +00001761 });
Francois Gouget82747b72000-11-25 01:38:39 +00001762 print FILEO "\n\n\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001763
1764 print FILEO "### Global settings\n\n";
1765 # Make it so that the project-wide settings override the global settings
Francois Gouget35246cb2001-05-07 18:19:57 +00001766 generate_list("DEFINES",0,@$project_settings[$T_DEFINES]);
1767 generate_list("",1,$global_settings[$T_DEFINES]);
1768 generate_list("INCLUDE_PATH",$no_extra,@$project_settings[$T_INCLUDE_PATH]);
1769 generate_list("",1,$global_settings[$T_INCLUDE_PATH],sub
Francois Gouget755bb922000-11-05 05:23:39 +00001770 {
Francois Gouget35246cb2001-05-07 18:19:57 +00001771 if ($_[0] !~ /^-I/ or is_absolute($')) {
Francois Gouget755bb922000-11-05 05:23:39 +00001772 return "$_[0]";
1773 }
Francois Gougetfb5b5902000-11-30 20:34:39 +00001774 return "-I\$(TOPSRCDIR)/$'";
Francois Gouget755bb922000-11-05 05:23:39 +00001775 });
Francois Gouget35246cb2001-05-07 18:19:57 +00001776 generate_list("LIBRARY_PATH",$no_extra,@$project_settings[$T_LIBRARY_PATH]);
1777 generate_list("",1,$global_settings[$T_LIBRARY_PATH],sub
Francois Gouget755bb922000-11-05 05:23:39 +00001778 {
Francois Gouget35246cb2001-05-07 18:19:57 +00001779 if ($_[0] !~ /^-L/ or is_absolute($')) {
Francois Gouget755bb922000-11-05 05:23:39 +00001780 return "$_[0]";
1781 }
Francois Gougetfb5b5902000-11-30 20:34:39 +00001782 return "-L\$(TOPSRCDIR)/$'";
Francois Gouget755bb922000-11-05 05:23:39 +00001783 });
Francois Gouget35246cb2001-05-07 18:19:57 +00001784 generate_list("LIBRARIES",$no_extra,@$project_settings[$T_LIBRARIES]);
1785 generate_list("",1,$global_settings[$T_LIBRARIES]);
Francois Gouget755bb922000-11-05 05:23:39 +00001786 print FILEO "\n\n";
1787
1788 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
1789 @{@$project_settings[$T_SOURCES_CXX]}+
1790 @{@$project_settings[$T_SOURCES_RC]};
1791 my $no_extra=($extra_source_count == 0);
1792 if (!$no_extra) {
1793 print FILEO "### Extra source lists\n\n";
1794 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
1795 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
1796 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
Francois Gouget82747b72000-11-25 01:38:39 +00001797 print FILEO "\n";
1798 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
1799 print FILEO "\n\n\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001800 }
Francois Gouget35246cb2001-05-07 18:19:57 +00001801
Francois Gouget755bb922000-11-05 05:23:39 +00001802 # Iterate over all the targets...
1803 foreach $target (@{@$project[$P_TARGETS]}) {
Francois Gouget82747b72000-11-25 01:38:39 +00001804 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001805 my $canon=canonize("@$target[$T_NAME]");
1806 $canon =~ s+_so$++;
1807 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
1808 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
1809 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
1810 my $basename=@$target[$T_NAME];
1811 $basename =~ s+\.so$++;
1812 if (@$target[$T_FLAGS] & $TF_WRAP) {
1813 $basename =~ s+^lib++;
1814 } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) {
1815 $basename.="_wrapper";
1816 }
Francois Gouget35246cb2001-05-07 18:19:57 +00001817 generate_list("${canon}_SPEC_SRCS",1,[ "$basename.spec" ]);
1818 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]);
1819 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]);
1820 generate_list("${canon}_DEPENDS",1,@$target[$T_DEPENDS]);
Francois Gouget82747b72000-11-25 01:38:39 +00001821 print FILEO "\n";
1822 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(EXTRA_OBJS)"]);
1823 print FILEO "\n\n\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001824 }
1825 print FILEO "### Global source lists\n\n";
Francois Gouget35246cb2001-05-07 18:19:57 +00001826 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
Francois Gouget755bb922000-11-05 05:23:39 +00001827 {
1828 my $canon=canonize(@{$_[0]}[$T_NAME]);
1829 $canon =~ s+_so$++;
1830 return "\$(${canon}_C_SRCS)";
1831 });
1832 if (!$no_extra) {
1833 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
1834 }
Francois Gouget35246cb2001-05-07 18:19:57 +00001835 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
Francois Gouget755bb922000-11-05 05:23:39 +00001836 {
1837 my $canon=canonize(@{$_[0]}[$T_NAME]);
1838 $canon =~ s+_so$++;
1839 return "\$(${canon}_CXX_SRCS)";
1840 });
1841 if (!$no_extra) {
1842 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
1843 }
Francois Gouget35246cb2001-05-07 18:19:57 +00001844 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
Francois Gouget755bb922000-11-05 05:23:39 +00001845 {
1846 my $canon=canonize(@{$_[0]}[$T_NAME]);
1847 $canon =~ s+_so$++;
1848 return "\$(${canon}_RC_SRCS)";
1849 });
1850 if (!$no_extra) {
Francois Gouget82747b72000-11-25 01:38:39 +00001851 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
Francois Gouget755bb922000-11-05 05:23:39 +00001852 }
Francois Gouget35246cb2001-05-07 18:19:57 +00001853 generate_list("SPEC_SRCS",1,@$project[$P_TARGETS],sub
Francois Gouget755bb922000-11-05 05:23:39 +00001854 {
1855 my $canon=canonize(@{$_[0]}[$T_NAME]);
1856 $canon =~ s+_so$++;
1857 return "\$(${canon}_SPEC_SRCS)";
1858 });
Francois Gouget755bb922000-11-05 05:23:39 +00001859 }
Francois Gouget82747b72000-11-25 01:38:39 +00001860 print FILEO "\n\n\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001861
1862 print FILEO "### Generic autoconf targets\n\n";
Francois Gouget27c3b592001-05-29 20:50:58 +00001863 print FILEO "all:";
Francois Gouget755bb922000-11-05 05:23:39 +00001864 if (@$project[$P_PATH] eq "") {
Francois Gouget27c3b592001-05-29 20:50:58 +00001865 print FILEO " \$(SUBDIRS)";
Francois Gouget755bb922000-11-05 05:23:39 +00001866 }
Francois Gouget82747b72000-11-25 01:38:39 +00001867 if (@{@$project[$P_TARGETS]} > 0) {
Francois Gouget27c3b592001-05-29 20:50:58 +00001868 print FILEO " \$(DLLS) \$(EXES:%=%.so)";
Francois Gouget82747b72000-11-25 01:38:39 +00001869 }
1870 print FILEO "\n\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001871 print FILEO "\@MAKE_RULES\@\n";
1872 print FILEO "\n";
1873 print FILEO "install::\n";
1874 if (@$project[$P_PATH] eq "") {
1875 # This is the main project. It is also responsible for recursively
1876 # calling the other projects
1877 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) install) || exit 1; done\n";
1878 }
1879 if (@{@$project[$P_TARGETS]} > 0) {
Francois Gougetbe859592000-11-15 22:12:20 +00001880 print FILEO "\tfor i in \$(EXES); do \$(INSTALL_PROGRAM) \$\$i \$(bindir); done\n";
Francois Gouget27e7f282001-06-04 02:50:29 +00001881 print FILEO "\tfor i in \$(EXES:%=%.so) \$(DLLS); do \$(INSTALL_PROGRAM) \$\$i \$(libdir); done\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001882 }
1883 print FILEO "\n";
1884 print FILEO "uninstall::\n";
1885 if (@$project[$P_PATH] eq "") {
1886 # This is the main project. It is also responsible for recursively
1887 # calling the other projects
1888 print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) uninstall) || exit 1; done\n";
1889 }
1890 if (@{@$project[$P_TARGETS]} > 0) {
Francois Gougetbe859592000-11-15 22:12:20 +00001891 print FILEO "\tfor i in \$(EXES); do \$(RM) \$(bindir)/\$\$i;done\n";
1892 print FILEO "\tfor i in \$(EXES:%=%.so) \$(DLLS); do \$(RM) \$(libdir)/\$\$i;done\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001893 }
1894 print FILEO "\n\n\n";
Francois Gouget35246cb2001-05-07 18:19:57 +00001895
Francois Gouget755bb922000-11-05 05:23:39 +00001896 if (@{@$project[$P_TARGETS]} > 0) {
1897 print FILEO "### Target specific build rules\n\n";
1898 foreach $target (@{@$project[$P_TARGETS]}) {
1899 my $canon=canonize("@$target[$T_NAME]");
1900 $canon =~ s/_so$//;
Francois Gougetbe859592000-11-15 22:12:20 +00001901 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.tmp.o): \$(${canon}_OBJS)\n";
1902 print FILEO "\t\$(LDCOMBINE) \$(${canon}_OBJS) -o \$\@\n";
1903 print FILEO "\t-\$(STRIP) \$(STRIPFLAGS) \$\@\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001904 print FILEO "\n";
Francois Gougetbe859592000-11-15 22:12:20 +00001905 print FILEO "\$(${canon}_SPEC_SRCS:.spec=.spec.c): \$(${canon}_SPEC_SRCS:.spec) \$(${canon}_SPEC_SRCS:.spec=.tmp.o) \$(${canon}_RC_SRCS:.rc=.res)\n";
Francois Gouget35246cb2001-05-07 18:19:57 +00001906 print FILEO "\t\$(LD_PATH) \$(WINEBUILD) -fPIC \$(${canon}_LIBRARY_PATH) \$(WINE_LIBRARY_PATH) -sym \$(${canon}_SPEC_SRCS:.spec=.tmp.o) -o \$\@ -spec \$(SRCDIR)/\$(${canon}_SPEC_SRCS)\n";
Francois Gougetbe859592000-11-15 22:12:20 +00001907 print FILEO "\n";
1908 my $t_name=@$target[$T_NAME];
1909 if (@$target[$T_TYPE]!=$TT_DLL) {
1910 $t_name.=".so";
Francois Gouget755bb922000-11-05 05:23:39 +00001911 }
Francois Gougetbe859592000-11-15 22:12:20 +00001912 print FILEO "$t_name: \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_OBJS) \$(${canon}_DEPENDS) \n";
Francois Gouget8d0e1e72001-03-04 01:03:55 +00001913 if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
1914 print FILEO "\t\$(LDXXSHARED)";
1915 } else {
1916 print FILEO "\t\$(LDSHARED)";
1917 }
1918 print FILEO " \$(LDDLLFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_LIBRARY_PATH) \$(${canon}_LIBRARIES:%=-l%) \$(DLL_LINK) \$(LIBS)\n";
Francois Gougetbe859592000-11-15 22:12:20 +00001919 if (@$target[$T_TYPE] ne $TT_DLL) {
1920 print FILEO "\ttest -e @$target[$T_NAME] || \$(LN_S) \$(WINE) @$target[$T_NAME]\n";
Francois Gouget82747b72000-11-25 01:38:39 +00001921 }
1922 print FILEO "\n\n";
Francois Gouget755bb922000-11-05 05:23:39 +00001923 }
1924 }
1925 close(FILEO);
Francois Gouget35246cb2001-05-07 18:19:57 +00001926
Francois Gouget755bb922000-11-05 05:23:39 +00001927 foreach $target (@{@$project[$P_TARGETS]}) {
1928 generate_spec_file(@$project[$P_PATH],$target,$project_settings);
1929 if (@$target[$T_FLAGS] & $TF_WRAPPER) {
1930 generate_wrapper_file(@$project[$P_PATH],$target);
1931 }
1932 }
1933}
1934
1935##
1936# Perform the replacements in the template configure files
1937# Return 1 for success, 0 for failure
1938sub generate_configure
1939{
1940 my $filename=$_[0];
1941 my $a_source_file=$_[1];
1942
1943 if (!defined $templates{$filename}) {
1944 if ($filename ne "configure") {
1945 print STDERR "winemaker: internal error: No template called '$filename'\n";
1946 }
1947 return 0;
1948 }
1949
1950 if (!open(FILEO,">$filename")) {
1951 print STDERR "error: unable to open \"$filename\" for writing:\n";
1952 print STDERR " $!\n";
1953 return 0;
1954 }
1955 foreach $line (@{$templates{$filename}}) {
1956 if ($line =~ /^\#\#WINEMAKER_PROJECTS\#\#$/) {
1957 foreach $project (@projects) {
1958 print FILEO "@$project[$P_PATH]Makefile\n";
1959 }
1960 } else {
1961 $line =~ s+\#\#WINEMAKER_SOURCE\#\#+$a_source_file+;
1962 $line =~ s+\#\#WINEMAKER_NEEDS_MFC\#\#+$needs_mfc+;
1963 print FILEO $line;
1964 }
1965 }
1966 close(FILEO);
1967 return 1;
1968}
1969
1970sub generate_generic
1971{
1972 my $filename=$_[0];
1973
1974 if (!defined $templates{$filename}) {
1975 print STDERR "winemaker: internal error: No template called '$filename'\n";
1976 return;
1977 }
1978 if (!open(FILEO,">$filename")) {
1979 print STDERR "error: unable to open \"$filename\" for writing:\n";
1980 print STDERR " $!\n";
1981 return;
1982 }
1983 foreach $line (@{$templates{$filename}}) {
1984 print FILEO $line;
1985 }
1986 close(FILEO);
1987}
1988
1989##
1990# Generates the global files:
1991# configure
1992# configure.in
1993# Make.rules.in
1994sub generate_global_files
1995{
1996 generate_generic("Make.rules.in");
1997
1998 # Get the name of a source file for configure.in
1999 my $a_source_file;
2000 search_a_file: foreach $project (@projects) {
Francois Gougeta106edb2000-11-10 22:29:11 +00002001 foreach $target (@{@$project[$P_TARGETS]}, @$project[$P_SETTINGS]) {
Francois Gouget755bb922000-11-05 05:23:39 +00002002 $a_source_file=@{@$target[$T_SOURCES_C]}[0];
2003 if (!defined $a_source_file) {
2004 $a_source_file=@{@$target[$T_SOURCES_CXX]}[0];
2005 }
2006 if (!defined $a_source_file) {
2007 $a_source_file=@{@$target[$T_SOURCES_RC]}[0];
2008 }
2009 if (defined $a_source_file) {
2010 $a_source_file="@$project[$P_PATH]$a_source_file";
2011 last search_a_file;
2012 }
2013 }
2014 }
François Gougetc1f016b2001-01-10 22:43:21 +00002015 if (!defined $a_source_file) {
2016 $a_source_file="Makefile.in";
2017 }
Francois Gouget755bb922000-11-05 05:23:39 +00002018
2019 generate_configure("configure.in",$a_source_file);
2020 unlink("configure");
2021 if (generate_configure("configure",$a_source_file) == 0) {
2022 system("autoconf");
2023 }
2024 # Add execute permission to configure for whoever has the right to read it
2025 my @st=stat("configure");
François Gouget38b3ac52001-01-11 20:17:42 +00002026 if (@st) {
Francois Gouget755bb922000-11-05 05:23:39 +00002027 my $mode=$st[2];
2028 $mode|=($mode & 0444) >>2;
2029 chmod($mode,"configure");
2030 } else {
2031 print "warning: could not generate the configure script. You need to run autoconf\n";
2032 }
2033}
2034
2035##
2036#
2037sub generate_read_templates
2038{
2039 my $file;
2040
2041 while (<DATA>) {
2042 if (/^--- ((\w\.?)+) ---$/) {
2043 my $filename=$1;
2044 if (defined $templates{$filename}) {
2045 print STDERR "winemaker: internal error: There is more than one template for $filename\n";
2046 undef $file;
2047 } else {
2048 $file=[];
2049 $templates{$filename}=$file;
2050 }
2051 } elsif (defined $file) {
2052 push @$file, $_;
2053 }
2054 }
2055}
2056
2057##
2058# This is where we finally generate files. In fact this method does not
2059# do anything itself but calls the methods that do the actual work.
2060sub generate
2061{
2062 print "Generating project files...\n";
2063 generate_read_templates();
2064 generate_global_files();
2065
2066 foreach $project (@projects) {
2067 my $path=@$project[$P_PATH];
2068 if ($path eq "") {
2069 $path=".";
2070 } else {
2071 $path =~ s+/$++;
2072 }
2073 print " $path\n";
2074 generate_project_files($project);
2075 }
2076}
2077
2078
2079
2080#####
2081#
2082# Option defaults
2083#
2084#####
2085
2086$opt_backup=1;
2087$opt_lower=$OPT_LOWER_UPPERCASE;
Francois Gougeta106edb2000-11-10 22:29:11 +00002088$opt_lower_include=1;
Francois Gouget755bb922000-11-05 05:23:39 +00002089
François Gougetc1f016b2001-01-10 22:43:21 +00002090# $opt_work_dir=<undefined>
Francois Gouget755bb922000-11-05 05:23:39 +00002091# $opt_single_target=<undefined>
2092$opt_target_type=$TT_GUIEXE;
2093$opt_flags=0;
2094$opt_is_interactive=$OPT_ASK_NO;
2095$opt_ask_project_options=$OPT_ASK_NO;
2096$opt_ask_target_options=$OPT_ASK_NO;
Francois Gougeta106edb2000-11-10 22:29:11 +00002097$opt_no_generated_files=0;
Francois Gouget755bb922000-11-05 05:23:39 +00002098$opt_no_banner=0;
2099
2100
2101
2102#####
2103#
2104# Main
2105#
2106#####
2107
François Gouget38b3ac52001-01-11 20:17:42 +00002108sub print_banner
2109{
2110 print "Winemaker $version\n";
2111 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2112}
2113
2114sub usage
2115{
2116 print_banner();
2117 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup]\n";
2118 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2119 print STDERR " [--lower-include|--nolower-include]\n";
2120 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2121 print STDERR " [--wrap|--nowrap] [--mfc|--nomfc]\n";
2122 print STDERR " [-Dmacro[=defn]] [-Idir] [-Ldir] [-idll] [-llibrary]\n";
2123 print STDERR " [--interactive] [--single-target name]\n";
2124 print STDERR " [--generated-files|--nogenerated-files]\n";
2125 print STDERR " work_directory\n";
2126 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2127 print STDERR "the specified directory so that they can be compiled with Winelib. During this\n";
2128 print STDERR "process it will modify and rename some of the files in that directory.\n";
2129 print STDERR "\tPlease read the manual page before use.\n";
2130 exit (2);
2131}
2132
2133
Francois Gouget755bb922000-11-05 05:23:39 +00002134project_init(\@main_project,"");
2135
2136while (@ARGV>0) {
2137 my $arg=shift @ARGV;
2138 # General options
2139 if ($arg eq "--nobanner") {
2140 $opt_no_banner=1;
2141 } elsif ($arg eq "--backup") {
2142 $opt_backup=1;
2143 } elsif ($arg eq "--nobackup") {
2144 $opt_backup=0;
2145 } elsif ($arg eq "--single-target") {
2146 $opt_single_target=shift @ARGV;
2147 } elsif ($arg eq "--lower-none") {
2148 $opt_lower=$OPT_LOWER_NONE;
2149 } elsif ($arg eq "--lower-all") {
2150 $opt_lower=$OPT_LOWER_ALL;
2151 } elsif ($arg eq "--lower-uppercase") {
2152 $opt_lower=$OPT_LOWER_UPPERCASE;
Francois Gougeta106edb2000-11-10 22:29:11 +00002153 } elsif ($arg eq "--lower-include") {
2154 $opt_lower_include=1;
Francois Gouget82747b72000-11-25 01:38:39 +00002155 } elsif ($arg eq "--nolower-include") {
Francois Gougeta106edb2000-11-10 22:29:11 +00002156 $opt_lower_include=0;
2157 } elsif ($arg eq "--generated-files") {
2158 $opt_no_generated_files=0;
Francois Gouget82747b72000-11-25 01:38:39 +00002159 } elsif ($arg eq "--nogenerated-files") {
Francois Gougeta106edb2000-11-10 22:29:11 +00002160 $opt_no_generated_files=1;
Francois Gouget755bb922000-11-05 05:23:39 +00002161
2162 } elsif ($arg =~ /^-D/) {
2163 push @{$global_settings[$T_DEFINES]},$arg;
2164 } elsif ($arg =~ /^-I/) {
2165 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2166 } elsif ($arg =~ /^-L/) {
2167 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
Francois Gougetbe859592000-11-15 22:12:20 +00002168 } elsif ($arg =~ /^-i/) {
Francois Gouget755bb922000-11-05 05:23:39 +00002169 push @{$global_settings[$T_IMPORTS]},$';
Francois Gougetbe859592000-11-15 22:12:20 +00002170 } elsif ($arg =~ /^-l/) {
2171 push @{$global_settings[$T_LIBRARIES]},$';
Francois Gouget755bb922000-11-05 05:23:39 +00002172
2173 # 'Source'-based method options
2174 } elsif ($arg eq "--dll") {
2175 $opt_target_type=$TT_DLL;
2176 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2177 $opt_target_type=$TT_GUIEXE;
2178 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2179 $opt_target_type=$TT_CUIEXE;
2180 } elsif ($arg eq "--interactive") {
2181 $opt_is_interactive=$OPT_ASK_YES;
2182 $opt_ask_project_options=$OPT_ASK_YES;
2183 $opt_ask_target_options=$OPT_ASK_YES;
2184 } elsif ($arg eq "--wrap") {
Francois Gougetafa36ce2001-03-01 22:11:10 +00002185 $opt_flags|=$TF_WRAP;
Francois Gouget755bb922000-11-05 05:23:39 +00002186 } elsif ($arg eq "--nowrap") {
2187 $opt_flags&=~$TF_WRAP;
2188 } elsif ($arg eq "--mfc") {
Francois Gougetbe859592000-11-15 22:12:20 +00002189 $opt_flags|=$TF_MFC;
Francois Gougetafa36ce2001-03-01 22:11:10 +00002190 $opt_flags|=$TF_MFC|$TF_WRAP;
Francois Gouget755bb922000-11-05 05:23:39 +00002191 $needs_mfc=1;
2192 } elsif ($arg eq "--nomfc") {
2193 $opt_flags&=~($TF_MFC|$TF_WRAP);
2194 $needs_mfc=0;
2195
2196 # Catch errors
2197 } else {
2198 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
François Gougetc1f016b2001-01-10 22:43:21 +00002199 if (!defined $opt_work_dir) {
2200 $opt_work_dir=$arg;
2201 } else {
2202 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
François Gouget38b3ac52001-01-11 20:17:42 +00002203 usage();
François Gougetc1f016b2001-01-10 22:43:21 +00002204 }
2205 } else {
François Gouget38b3ac52001-01-11 20:17:42 +00002206 usage();
Francois Gouget755bb922000-11-05 05:23:39 +00002207 }
Francois Gouget755bb922000-11-05 05:23:39 +00002208 }
2209}
2210
François Gougetc1f016b2001-01-10 22:43:21 +00002211if (!defined $opt_work_dir) {
2212 print STDERR "error: you must specify the directory containing the sources to be converted\n";
François Gouget38b3ac52001-01-11 20:17:42 +00002213 usage();
François Gougetc1f016b2001-01-10 22:43:21 +00002214} elsif (!chdir $opt_work_dir) {
2215 print STDERR "error: could not chdir to the work directory\n";
2216 print STDERR " $!\n";
François Gouget38b3ac52001-01-11 20:17:42 +00002217 usage();
François Gougetc1f016b2001-01-10 22:43:21 +00002218}
2219
François Gouget38b3ac52001-01-11 20:17:42 +00002220if ($opt_no_banner == 0) {
2221 print_banner();
Francois Gouget755bb922000-11-05 05:23:39 +00002222}
2223
2224# Fix the file and directory names
2225fix_file_and_directory_names(".");
2226
2227# Scan the sources to identify the projects and targets
2228source_scan();
2229
Francois Gougeta106edb2000-11-10 22:29:11 +00002230# Create targets for wrappers, etc.
2231postprocess_targets();
Francois Gouget755bb922000-11-05 05:23:39 +00002232
2233# Fix the source files
2234fix_source();
2235
2236# Generate the Makefile and the spec file
Francois Gougeta106edb2000-11-10 22:29:11 +00002237if (! $opt_no_generated_files) {
Francois Gouget755bb922000-11-05 05:23:39 +00002238 generate();
2239}
2240
2241
2242__DATA__
2243--- configure.in ---
2244dnl Process this file with autoconf to produce a configure script.
2245dnl Author: Michael Patra <micky@marie.physik.tu-berlin.de>
2246dnl <patra@itp1.physik.tu-berlin.de>
2247dnl Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2248
2249AC_REVISION([configure.in 1.00])
2250AC_INIT(##WINEMAKER_SOURCE##)
2251
2252NEEDS_MFC=##WINEMAKER_NEEDS_MFC##
2253
2254dnl **** Command-line arguments ****
2255
2256AC_SUBST(OPTIONS)
2257
2258dnl **** Check for some programs ****
2259
2260AC_PROG_MAKE_SET
2261AC_PROG_CC
2262AC_PROG_CXX
2263AC_PROG_CPP
Francois Gouget755bb922000-11-05 05:23:39 +00002264AC_PROG_LN_S
Francois Gouget755bb922000-11-05 05:23:39 +00002265
2266dnl **** Check for some libraries ****
2267
2268dnl Check for -lm for BeOS
2269AC_CHECK_LIB(m,sqrt)
Francois Gouget755bb922000-11-05 05:23:39 +00002270dnl Check for -lw for Solaris
2271AC_CHECK_LIB(w,iswalnum)
2272dnl Check for -lnsl for Solaris
2273AC_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))
2274dnl Check for -lsocket for Solaris
2275AC_CHECK_FUNCS(connect,,AC_CHECK_LIB(socket,connect))
Francois Gouget755bb922000-11-05 05:23:39 +00002276
2277dnl **** If ln -s doesn't work, use cp instead ****
2278if test "$ac_cv_prog_LN_S" = "ln -s"; then : ; else LN_S=cp ; fi
2279
2280dnl **** Check for gcc strength-reduce bug ****
2281
2282if test "x${GCC}" = "xyes"
2283then
2284 AC_CACHE_CHECK( "for gcc strength-reduce bug", ac_cv_c_gcc_strength_bug,
2285 AC_TRY_RUN([
2286int main(void) {
2287 static int Array[[3]];
2288 unsigned int B = 3;
2289 int i;
2290 for(i=0; i<B; i++) Array[[i]] = i - 3;
2291 exit( Array[[1]] != -2 );
2292}],
2293 ac_cv_c_gcc_strength_bug="no",
2294 ac_cv_c_gcc_strength_bug="yes",
2295 ac_cv_c_gcc_strength_bug="yes") )
2296 if test "$ac_cv_c_gcc_strength_bug" = "yes"
2297 then
2298 CFLAGS="$CFLAGS -fno-strength-reduce"
2299 fi
2300fi
2301
2302dnl **** Check for underscore on external symbols ****
2303
2304AC_CACHE_CHECK("whether external symbols need an underscore prefix",
2305 ac_cv_c_extern_prefix,
2306[saved_libs=$LIBS
2307LIBS="conftest_asm.s $LIBS"
2308cat > conftest_asm.s <<EOF
2309 .globl _ac_test
2310_ac_test:
2311 .long 0
2312EOF
2313AC_TRY_LINK([extern int ac_test;],[if (ac_test) return 1],
2314 ac_cv_c_extern_prefix="yes",ac_cv_c_extern_prefix="no")
2315LIBS=$saved_libs])
2316if test "$ac_cv_c_extern_prefix" = "yes"
2317then
2318 AC_DEFINE(NEED_UNDERSCORE_PREFIX)
2319fi
2320
2321dnl **** Check for working dll ****
2322
2323LDSHARED=""
Francois Gouget8d0e1e72001-03-04 01:03:55 +00002324LDXXSHARED=""
Francois Gougetbe859592000-11-15 22:12:20 +00002325LDDLLFLAGS=""
Francois Gouget755bb922000-11-05 05:23:39 +00002326AC_CACHE_CHECK("whether we can build a Linux dll",
2327 ac_cv_c_dll_linux,
2328[saved_cflags=$CFLAGS
Francois Gougetbe859592000-11-15 22:12:20 +00002329CFLAGS="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0,-Bsymbolic"
Francois Gouget755bb922000-11-05 05:23:39 +00002330AC_TRY_LINK(,[return 1],ac_cv_c_dll_linux="yes",ac_cv_c_dll_linux="no")
2331CFLAGS=$saved_cflags
2332])
2333if test "$ac_cv_c_dll_linux" = "yes"
2334then
Francois Gougetbe859592000-11-15 22:12:20 +00002335 LDSHARED="\$(CC) -shared -Wl,-rpath,\$(libdir)"
Francois Gouget8d0e1e72001-03-04 01:03:55 +00002336 LDXXSHARED="\$(CXX) -shared -Wl,-rpath,\$(libdir)"
Francois Gougetbe859592000-11-15 22:12:20 +00002337 LDDLLFLAGS="-Wl,-Bsymbolic"
Francois Gouget755bb922000-11-05 05:23:39 +00002338else
2339 AC_CACHE_CHECK(whether we can build a UnixWare (Solaris) dll,
2340 ac_cv_c_dll_unixware,
2341 [saved_cflags=$CFLAGS
Francois Gougetbe859592000-11-15 22:12:20 +00002342 CFLAGS="$CFLAGS -fPIC -Wl,-G,-h,conftest.so.1.0,-B,symbolic"
Francois Gouget755bb922000-11-05 05:23:39 +00002343 AC_TRY_LINK(,[return 1],ac_cv_c_dll_unixware="yes",ac_cv_c_dll_unixware="no")
2344 CFLAGS=$saved_cflags
2345 ])
2346 if test "$ac_cv_c_dll_unixware" = "yes"
2347 then
Francois Gouget8d0e1e72001-03-04 01:03:55 +00002348 LDSHARED="\$(CC) -Wl,-G"
2349 LDXXSHARED="\$(CXX) -Wl,-G"
Francois Gougetbe859592000-11-15 22:12:20 +00002350 LDDLLFLAGS="-Wl,-B,symbolic"
Francois Gouget755bb922000-11-05 05:23:39 +00002351 else
2352 AC_CACHE_CHECK("whether we can build a NetBSD dll",
2353 ac_cv_c_dll_netbsd,
2354 [saved_cflags=$CFLAGS
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002355 CFLAGS="$CFLAGS -fPIC -Wl,-Bshareable,-Bforcearchive"
Francois Gouget755bb922000-11-05 05:23:39 +00002356 AC_TRY_LINK(,[return 1],ac_cv_c_dll_netbsd="yes",ac_cv_c_dll_netbsd="no")
2357 CFLAGS=$saved_cflags
2358 ])
2359 if test "$ac_cv_c_dll_netbsd" = "yes"
2360 then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002361 LDSHARED="\$(CC) -Wl,-Bshareable,-Bforcearchive"
Francois Gouget8d0e1e72001-03-04 01:03:55 +00002362 LDXXSHARED="\$(CXX) -Wl,-Bshareable,-Bforcearchive"
Francois Gougetbe859592000-11-15 22:12:20 +00002363 LDDLLFLAGS="" #FIXME
Francois Gouget755bb922000-11-05 05:23:39 +00002364 fi
2365 fi
2366fi
2367if test "$ac_cv_c_dll_linux" = "no" -a "$ac_cv_c_dll_unixware" = "no" -a "$ac_cv_c_dll_netbsd" = "no"
2368then
2369 AC_MSG_ERROR([Could not find how to build a dynamically linked library])
2370fi
2371
Francois Gougetbe859592000-11-15 22:12:20 +00002372CFLAGS="$CFLAGS -fPIC"
Alexandre Julliardc4d11762000-12-27 19:06:44 +00002373DLL_LINK="\$(WINE_LIBRARY_PATH) \$(LIBRARY_PATH) \$(LIBRARIES:%=-l%) -lwine -lwine_unicode -lwine_uuid"
Francois Gouget755bb922000-11-05 05:23:39 +00002374
2375AC_SUBST(DLL_LINK)
Francois Gouget755bb922000-11-05 05:23:39 +00002376AC_SUBST(LDSHARED)
Francois Gouget8d0e1e72001-03-04 01:03:55 +00002377AC_SUBST(LDXXSHARED)
Francois Gougetbe859592000-11-15 22:12:20 +00002378AC_SUBST(LDDLLFLAGS)
Francois Gouget755bb922000-11-05 05:23:39 +00002379
2380dnl *** check for the need to define __i386__
2381
2382AC_CACHE_CHECK("whether we need to define __i386__",ac_cv_cpp_def_i386,
2383 AC_EGREP_CPP(yes,[#if (defined(i386) || defined(__i386)) && !defined(__i386__)
2384yes
2385#endif],
2386 ac_cv_cpp_def_i386="yes", ac_cv_cpp_def_i386="no"))
2387if test "$ac_cv_cpp_def_i386" = "yes"
2388then
2389 CFLAGS="$CFLAGS -D__i386__"
2390fi
2391
2392dnl $GCC is set by autoconf
2393GCC_NO_BUILTIN=""
2394if test "$GCC" = "yes"
2395then
2396 GCC_NO_BUILTIN="-fno-builtin"
2397fi
2398AC_SUBST(GCC_NO_BUILTIN)
2399
2400dnl **** Test Winelib-related features of the C++ compiler
2401AC_LANG_CPLUSPLUS()
2402if test "x${GCC}" = "xyes"
2403then
2404 OLDCXXFLAGS="$CXXFLAGS";
2405 CXXFLAGS="-fpermissive";
2406 AC_CACHE_CHECK("for g++ -fpermissive option", has_gxx_permissive,
2407 AC_TRY_COMPILE(,[
2408 for (int i=0;i<2;i++);
2409 i=0;
2410 ],
2411 [has_gxx_permissive="yes"],
2412 [has_gxx_permissive="no"])
2413 )
2414 CXXFLAGS="-fno-for-scope";
2415 AC_CACHE_CHECK("for g++ -fno-for-scope option", has_gxx_no_for_scope,
2416 AC_TRY_COMPILE(,[
2417 for (int i=0;i<2;i++);
2418 i=0;
2419 ],
2420 [has_gxx_no_for_scope="yes"],
2421 [has_gxx_no_for_scope="no"])
2422 )
2423 CXXFLAGS="$OLDCXXFLAGS";
2424 if test "$has_gxx_permissive" = "yes"
2425 then
2426 CXXFLAGS="$CXXFLAGS -fpermissive"
2427 fi
2428 if test "$has_gxx_no_for_scope" = "yes"
2429 then
2430 CXXFLAGS="$CXXFLAGS -fno-for-scope"
2431 fi
2432fi
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002433AC_LANG_C()
Francois Gouget755bb922000-11-05 05:23:39 +00002434
2435dnl **** Test Winelib-related features of the C compiler
2436dnl none for now
2437
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002438dnl **** Macros for finding a headers/libraries in a collection of places
2439
2440dnl AC_PATH_HEADER(variable,header,action-if-not-found,default-locations)
2441dnl Note that the above may set variable to an empty value if the header is
2442dnl already in the include path
2443AC_DEFUN(AC_PATH_HEADER,[
2444AC_MSG_CHECKING([for $2])
2445AC_CACHE_VAL(ac_cv_path_$1,
2446[
2447 ac_found=
2448 ac_dummy="ifelse([$4], , :/usr/local/include, [$4])"
2449 save_CPPFLAGS="$CPPFLAGS"
2450 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2451 for ac_dir in $ac_dummy; do
2452 IFS="$ac_save_ifs"
2453 if test -z "$ac_dir"
2454 then
2455 CPPFLAGS="$save_CPPFLAGS"
2456 else
2457 CPPFLAGS="-I$ac_dir $save_CPPFLAGS"
2458 fi
2459 AC_TRY_COMPILE([#include <$2>],,ac_found=1;ac_cv_path_$1="$ac_dir";break)
2460 done
2461 CPPFLAGS="$save_CPPFLAGS"
2462 ifelse([$3],,,[if test -z "$ac_found"
2463 then
2464 $3
2465 fi
2466 ])
2467])
2468$1="$ac_cv_path_$1"
2469if test -n "$ac_found" -o -n "[$]$1"
2470then
2471 AC_MSG_RESULT([$]$1)
2472else
2473 AC_MSG_RESULT(no)
2474fi
2475AC_SUBST($1)
2476])
2477
2478dnl AC_PATH_LIBRARY(variable,libraries,extra libs,action-if-not-found,default-locations)
2479AC_DEFUN(AC_PATH_LIBRARY,[
2480AC_MSG_CHECKING([for $2])
2481AC_CACHE_VAL(ac_cv_path_$1,
2482[
2483 ac_found=
2484 ac_dummy="ifelse([$5], , :/usr/local/lib, [$5])"
2485 save_LIBS="$LIBS"
2486 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
2487 for ac_dir in $ac_dummy; do
2488 IFS="$ac_save_ifs"
2489 if test -z "$ac_dir"
2490 then
2491 LIBS="$2 $3 $save_LIBS"
2492 else
2493 LIBS="-L$ac_dir $2 $3 $save_LIBS"
2494 fi
2495 AC_TRY_LINK(,,ac_found=1;ac_cv_path_$1="$ac_dir";break)
2496 done
2497 LIBS="$save_LIBS"
2498 ifelse([$4],,,[if test -z "$ac_found"
2499 then
2500 $4
2501 fi
2502 ])
2503])
2504$1="$ac_cv_path_$1"
2505if test -n "$ac_found" -o -n "[$]$1"
2506then
2507 AC_MSG_RESULT([$]$1)
2508else
2509 AC_MSG_RESULT(no)
2510fi
2511AC_SUBST($1)
2512])
2513
Francois Gouget755bb922000-11-05 05:23:39 +00002514dnl **** Try to find where winelib is located ****
2515
Francois Gougetd5549962001-03-16 16:39:02 +00002516LD_PATH="";
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002517WINE_INCLUDE_ROOT="";
2518WINE_INCLUDE_PATH="";
2519WINE_LIBRARY_ROOT="";
2520WINE_LIBRARY_PATH="";
2521WINE_TOOL_PATH="";
Francois Gougetbe859592000-11-15 22:12:20 +00002522WINE="";
Francois Gouget755bb922000-11-05 05:23:39 +00002523WINEBUILD="";
2524WRC="";
2525
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002526AC_ARG_WITH(wine,
2527[ --with-wine=DIR the Wine package (or sources) is in DIR],
Francois Gouget755bb922000-11-05 05:23:39 +00002528[if test "$withval" != "no"; then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002529 WINE_ROOT="$withval";
2530 WINE_INCLUDES="";
2531 WINE_LIBRARIES="";
2532 WINE_TOOLS="";
Francois Gouget755bb922000-11-05 05:23:39 +00002533else
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002534 WINE_ROOT="";
Francois Gouget755bb922000-11-05 05:23:39 +00002535fi])
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002536if test -n "$WINE_ROOT"
Francois Gouget755bb922000-11-05 05:23:39 +00002537then
François Gougetba5bb0b2001-01-09 20:50:34 +00002538 WINE_INCLUDE_ROOT="$WINE_ROOT/include:$WINE_ROOT/include/wine";
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002539 WINE_LIBRARY_ROOT="$WINE_ROOT";
2540 WINE_TOOL_PATH="$WINE_ROOT:$WINE_ROOT/bin:$WINE_ROOT/tools/wrc:$WINE_ROOT/tools/winebuild:$PATH";
Francois Gouget755bb922000-11-05 05:23:39 +00002541fi
2542
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002543AC_ARG_WITH(wine-includes,
2544[ --with-wine-includes=DIR the Wine includes are in DIR],
Francois Gouget755bb922000-11-05 05:23:39 +00002545[if test "$withval" != "no"; then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002546 WINE_INCLUDES="$withval";
Francois Gouget755bb922000-11-05 05:23:39 +00002547else
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002548 WINE_INCLUDES="";
Francois Gouget755bb922000-11-05 05:23:39 +00002549fi])
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002550if test -n "$WINE_INCLUDES"
Francois Gouget755bb922000-11-05 05:23:39 +00002551then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002552 WINE_INCLUDE_ROOT="$WINE_INCLUDES";
Francois Gouget755bb922000-11-05 05:23:39 +00002553fi
2554
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002555AC_ARG_WITH(wine-libraries,
2556[ --with-wine-libraries=DIR the Wine libraries are in DIR],
Francois Gouget755bb922000-11-05 05:23:39 +00002557[if test "$withval" != "no"; then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002558 WINE_LIBRARIES="$withval";
Francois Gouget755bb922000-11-05 05:23:39 +00002559else
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002560 WINE_LIBRARIES="";
Francois Gouget755bb922000-11-05 05:23:39 +00002561fi])
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002562if test -n "$WINE_LIBRARIES"
Francois Gouget755bb922000-11-05 05:23:39 +00002563then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002564 WINE_LIBRARY_ROOT="$WINE_LIBRARIES";
Francois Gouget755bb922000-11-05 05:23:39 +00002565fi
2566
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002567AC_ARG_WITH(wine-tools,
2568[ --with-wine-tools=DIR the Wine tools are in DIR],
Francois Gouget755bb922000-11-05 05:23:39 +00002569[if test "$withval" != "no"; then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002570 WINE_TOOLS="$withval";
Francois Gouget755bb922000-11-05 05:23:39 +00002571else
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002572 WINE_TOOLS="";
Francois Gouget755bb922000-11-05 05:23:39 +00002573fi])
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002574if test -n "$WINE_TOOLS"
Francois Gouget755bb922000-11-05 05:23:39 +00002575then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002576 WINE_TOOL_PATH="$WINE_TOOLS:$WINE_TOOLS/wrc:$WINE_TOOLS/winebuild";
Francois Gouget755bb922000-11-05 05:23:39 +00002577fi
2578
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002579if test -z "$WINE_INCLUDE_ROOT"
Francois Gouget755bb922000-11-05 05:23:39 +00002580then
François Gougetba5bb0b2001-01-09 20:50:34 +00002581 WINE_INCLUDE_ROOT=":/usr/include/wine:/usr/local/include/wine:/opt/wine/include:/opt/wine/include/wine";
Francois Gouget755bb922000-11-05 05:23:39 +00002582fi
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002583AC_PATH_HEADER(WINE_INCLUDE_ROOT,windef.h,[
2584 AC_MSG_ERROR([Could not find the Wine includes])
2585],$WINE_INCLUDE_ROOT)
2586if test -n "$WINE_INCLUDE_ROOT"
Francois Gouget755bb922000-11-05 05:23:39 +00002587then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002588 WINE_INCLUDE_PATH="-I$WINE_INCLUDE_ROOT"
Francois Gouget755bb922000-11-05 05:23:39 +00002589else
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002590 WINE_INCLUDE_PATH=""
Francois Gouget755bb922000-11-05 05:23:39 +00002591fi
2592
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002593if test -z "$WINE_LIBRARY_ROOT"
2594then
2595 WINE_LIBRARY_ROOT=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib";
2596else
2597 WINE_LIBRARY_ROOT="$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/lib";
2598fi
2599AC_PATH_LIBRARY(WINE_LIBRARY_ROOT,[-lwine],[-lutil],[
2600 AC_MSG_ERROR([Could not find the Wine libraries (libwine.so)])
2601],$WINE_LIBRARY_ROOT)
2602if test -n "$WINE_LIBRARY_ROOT"
2603then
2604 WINE_LIBRARY_PATH="-L$WINE_LIBRARY_ROOT"
2605else
2606 WINE_LIBRARY_PATH=""
2607fi
2608AC_PATH_LIBRARY(LIBNTDLL_PATH,[-lntdll],[$WINE_LIBRARY_PATH -lwine -lwine_unicode -lncurses -ldl -lutil],[
2609 AC_MSG_ERROR([Could not find the Wine libraries (libntdll.so)])
2610],[$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/dlls])
2611if test -n "$LIBNTDLL_PATH" -a "-L$LIBNTDLL_PATH" != "$WINE_LIBRARY_PATH"
2612then
2613 WINE_LIBRARY_PATH="$WINE_LIBRARY_PATH -L$LIBNTDLL_PATH"
2614fi
Francois Gougetd5549962001-03-16 16:39:02 +00002615if test -n "$WINE_LIBRARY_PATH"
2616then
2617 LD_PATH="LD_LIBRARY_PATH=\"`echo $WINE_LIBRARY_PATH | sed -e 's/ *-L/:/g' -e 's/^://' -e 's/ *$//'`:\$\$LD_LIBRARY_PATH\""
2618fi
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002619
2620if test -z "$WINE_TOOL_PATH"
2621then
2622 WINE_TOOL_PATH="$PATH:/usr/local/bin:/opt/wine/bin";
2623fi
Francois Gougetbe859592000-11-15 22:12:20 +00002624AC_PATH_PROG(WINE,wine,,$WINE_TOOL_PATH)
2625if test -z "$WINE"
2626then
2627 AC_MSG_ERROR([Could not find Wine's wine tool])
2628fi
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002629AC_PATH_PROG(WINEBUILD,winebuild,,$WINE_TOOL_PATH)
Francois Gouget755bb922000-11-05 05:23:39 +00002630if test -z "$WINEBUILD"
2631then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002632 AC_MSG_ERROR([Could not find Wine's winebuild tool])
Francois Gouget755bb922000-11-05 05:23:39 +00002633fi
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002634AC_PATH_PROG(WRC,wrc,,$WINE_TOOL_PATH)
Francois Gouget755bb922000-11-05 05:23:39 +00002635if test -z "$WRC"
2636then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002637 AC_MSG_ERROR([Could not find Wine's wrc tool])
Francois Gouget755bb922000-11-05 05:23:39 +00002638fi
2639
Francois Gougetd5549962001-03-16 16:39:02 +00002640AC_SUBST(LD_PATH)
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002641AC_SUBST(WINE_INCLUDE_PATH)
2642AC_SUBST(WINE_LIBRARY_PATH)
Francois Gouget755bb922000-11-05 05:23:39 +00002643
2644dnl **** Try to find where the MFC are located ****
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002645AC_LANG_CPLUSPLUS()
Francois Gouget755bb922000-11-05 05:23:39 +00002646
2647if test "x$NEEDS_MFC" = "x1"
2648then
2649 ATL_INCLUDE_ROOT="";
2650 ATL_INCLUDE_PATH="";
2651 MFC_INCLUDE_ROOT="";
2652 MFC_INCLUDE_PATH="";
2653 MFC_LIBRARY_ROOT="";
2654 MFC_LIBRARY_PATH="";
2655
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002656 AC_ARG_WITH(mfc,
2657 [ --with-mfc=DIR the MFC package (or sources) is in DIR],
Francois Gouget755bb922000-11-05 05:23:39 +00002658 [if test "$withval" != "no"; then
2659 MFC_ROOT="$withval";
2660 ATL_INCLUDES="";
2661 MFC_INCLUDES="";
2662 MFC_LIBRARIES="";
2663 else
2664 MFC_ROOT="";
2665 fi])
2666 if test -n "$MFC_ROOT"
2667 then
2668 ATL_INCLUDE_ROOT="$MFC_ROOT";
2669 MFC_INCLUDE_ROOT="$MFC_ROOT";
2670 MFC_LIBRARY_ROOT="$MFC_ROOT";
2671 fi
2672
2673 AC_ARG_WITH(atl-includes,
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002674 [ --with-atl-includes=DIR the ATL includes are in DIR],
Francois Gouget755bb922000-11-05 05:23:39 +00002675 [if test "$withval" != "no"; then
2676 ATL_INCLUDES="$withval";
2677 else
2678 ATL_INCLUDES="";
2679 fi])
2680 if test -n "$ATL_INCLUDES"
2681 then
2682 ATL_INCLUDE_ROOT="$ATL_INCLUDES";
2683 fi
2684
2685 AC_ARG_WITH(mfc-includes,
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002686 [ --with-mfc-includes=DIR the MFC includes are in DIR],
Francois Gouget755bb922000-11-05 05:23:39 +00002687 [if test "$withval" != "no"; then
2688 MFC_INCLUDES="$withval";
2689 else
2690 MFC_INCLUDES="";
2691 fi])
2692 if test -n "$MFC_INCLUDES"
2693 then
2694 MFC_INCLUDE_ROOT="$MFC_INCLUDES";
2695 fi
2696
2697 AC_ARG_WITH(mfc-libraries,
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002698 [ --with-mfc-libraries=DIR the MFC libraries are in DIR],
Francois Gouget755bb922000-11-05 05:23:39 +00002699 [if test "$withval" != "no"; then
2700 MFC_LIBRARIES="$withval";
2701 else
2702 MFC_LIBRARIES="";
2703 fi])
2704 if test -n "$MFC_LIBRARIES"
2705 then
2706 MFC_LIBRARY_ROOT="$MFC_LIBRARIES";
2707 fi
2708
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002709 OLDCPPFLAGS="$CPPFLAGS"
2710 dnl FIXME: We should not have defines in any of the include paths
2711 CPPFLAGS="$WINE_INCLUDE_PATH -I$WINE_INCLUDE_ROOT/mixedcrt -D_DLL -D_MT $CPPFLAGS"
2712 ATL_INCLUDE_PATH="-I\$(WINE_INCLUDE_ROOT)/mixedcrt -D_DLL -D_MT"
Francois Gouget755bb922000-11-05 05:23:39 +00002713 if test -z "$ATL_INCLUDE_ROOT"
2714 then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002715 ATL_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/atl:/usr/include/atl:/usr/local/include/atl:/opt/mfc/include/atl:/opt/atl/include"
2716 else
2717 ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT:$ATL_INCLUDE_ROOT/atl:$ATL_INCLUDE_ROOT/atl/include"
Francois Gouget755bb922000-11-05 05:23:39 +00002718 fi
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002719 AC_PATH_HEADER(ATL_INCLUDE_ROOT,atldef.h,[
2720 AC_MSG_ERROR([Could not find the ATL includes])
2721 ],$ATL_INCLUDE_ROOT)
2722 if test -n "$ATL_INCLUDE_ROOT"
Francois Gouget755bb922000-11-05 05:23:39 +00002723 then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002724 ATL_INCLUDE_PATH="$ATL_INCLUDE_PATH -I$ATL_INCLUDE_ROOT"
Francois Gouget755bb922000-11-05 05:23:39 +00002725 fi
Francois Gouget755bb922000-11-05 05:23:39 +00002726
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002727 MFC_INCLUDE_PATH="$ATL_INCLUDE_PATH"
Francois Gouget755bb922000-11-05 05:23:39 +00002728 if test -z "$MFC_INCLUDE_ROOT"
2729 then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002730 MFC_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/mfc:/usr/include/mfc:/usr/local/include/mfc:/opt/mfc/include/mfc:/opt/mfc/include"
2731 else
2732 MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT:$MFC_INCLUDE_ROOT/mfc:$MFC_INCLUDE_ROOT/mfc/include"
Francois Gouget755bb922000-11-05 05:23:39 +00002733 fi
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002734 AC_PATH_HEADER(MFC_INCLUDE_ROOT,afx.h,[
2735 AC_MSG_ERROR([Could not find the MFC includes])
2736 ],$MFC_INCLUDE_ROOT)
2737 if test -n "$MFC_INCLUDE_ROOT" -a "$ATL_INCLUDE_ROOT" != "$MFC_INCLUDE_ROOT"
Francois Gouget755bb922000-11-05 05:23:39 +00002738 then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002739 MFC_INCLUDE_PATH="$MFC_INCLUDE_PATH -I$MFC_INCLUDE_ROOT"
Francois Gouget755bb922000-11-05 05:23:39 +00002740 fi
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002741 CPPFLAGS="$OLDCPPFLAGS"
Francois Gouget755bb922000-11-05 05:23:39 +00002742
2743 if test -z "$MFC_LIBRARY_ROOT"
2744 then
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002745 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 +00002746 else
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002747 MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT:$MFC_LIBRARY_ROOT/lib:$MFC_LIBRARY_ROOT/mfc/src";
Francois Gouget755bb922000-11-05 05:23:39 +00002748 fi
Francois Gouget82747b72000-11-25 01:38:39 +00002749 AC_PATH_LIBRARY(MFC_LIBRARY_ROOT,[-lmfc],[$WINE_LIBRARY_PATH -lwine -lwine_unicode],[
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002750 AC_MSG_ERROR([Could not find the MFC library])
2751 ],$MFC_LIBRARY_ROOT)
2752 if test -n "$MFC_LIBRARY_ROOT" -a "$MFC_LIBRARY_ROOT" != "$WINE_LIBRARY_ROOT"
2753 then
2754 MFC_LIBRARY_PATH="-L$MFC_LIBRARY_ROOT"
2755 else
2756 MFC_LIBRARY_PATH=""
2757 fi
Francois Gouget755bb922000-11-05 05:23:39 +00002758
Francois Gouget755bb922000-11-05 05:23:39 +00002759 AC_SUBST(ATL_INCLUDE_PATH)
Francois Gouget755bb922000-11-05 05:23:39 +00002760 AC_SUBST(MFC_INCLUDE_PATH)
Francois Gouget755bb922000-11-05 05:23:39 +00002761 AC_SUBST(MFC_LIBRARY_PATH)
2762fi
2763
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002764AC_LANG_C()
2765
Francois Gouget755bb922000-11-05 05:23:39 +00002766dnl **** Generate output files ****
2767
2768MAKE_RULES=Make.rules
2769AC_SUBST_FILE(MAKE_RULES)
2770
2771AC_OUTPUT([
2772Make.rules
2773##WINEMAKER_PROJECTS##
2774 ])
2775
2776echo
2777echo "Configure finished. Do 'make' to build the project."
2778echo
2779
2780dnl Local Variables:
2781dnl comment-start: "dnl "
2782dnl comment-end: ""
2783dnl comment-start-skip: "\\bdnl\\b\\s *"
2784dnl compile-command: "autoconf"
2785dnl End:
2786--- Make.rules.in ---
2787# Copyright 2000 Francois Gouget for CodeWeavers
2788# fgouget@codeweavers.com
2789#
2790# Global rules shared by all makefiles -*-Makefile-*-
2791#
2792# Each individual makefile must define the following variables:
Francois Gouget755bb922000-11-05 05:23:39 +00002793# TOPOBJDIR : top-level object directory
2794# SRCDIR : source directory for this module
2795#
2796# Each individual makefile may define the following additional variables:
2797#
2798# SUBDIRS : subdirectories that contain a Makefile
Francois Gougetbe859592000-11-15 22:12:20 +00002799# DLLS : WineLib libraries to be built
2800# EXES : WineLib executables to be built
Francois Gouget755bb922000-11-05 05:23:39 +00002801#
2802# CEXTRA : extra c flags (e.g. '-Wall')
2803# CXXEXTRA : extra c++ flags (e.g. '-Wall')
2804# WRCEXTRA : extra wrc flags (e.g. '-p _SysRes')
2805# DEFINES : defines (e.g. -DSTRICT)
2806# INCLUDE_PATH : additional include path
2807# LIBRARY_PATH : additional library path
Francois Gougetbe859592000-11-15 22:12:20 +00002808# LIBRARIES : additional Unix libraries to link with
Francois Gouget755bb922000-11-05 05:23:39 +00002809#
2810# C_SRCS : C sources for the module
2811# CXX_SRCS : C++ sources for the module
2812# RC_SRCS : resource source files
2813# SPEC_SRCS : interface definition files
2814
2815
Francois Gougetd5549962001-03-16 16:39:02 +00002816# Where is Wine
Francois Gouget755bb922000-11-05 05:23:39 +00002817
Francois Gouget7f1ab7a2000-11-13 04:13:22 +00002818WINE_INCLUDE_ROOT = @WINE_INCLUDE_ROOT@
2819WINE_INCLUDE_PATH = @WINE_INCLUDE_PATH@
2820WINE_LIBRARY_ROOT = @WINE_LIBRARY_ROOT@
2821WINE_LIBRARY_PATH = @WINE_LIBRARY_PATH@
Francois Gouget755bb922000-11-05 05:23:39 +00002822
Francois Gougetd5549962001-03-16 16:39:02 +00002823LD_PATH = @LD_PATH@
2824
Francois Gouget755bb922000-11-05 05:23:39 +00002825# Where are the MFC
2826
2827ATL_INCLUDE_ROOT = @ATL_INCLUDE_ROOT@
2828ATL_INCLUDE_PATH = @ATL_INCLUDE_PATH@
2829MFC_INCLUDE_ROOT = @MFC_INCLUDE_ROOT@
2830MFC_INCLUDE_PATH = @MFC_INCLUDE_PATH@
2831MFC_LIBRARY_ROOT = @MFC_LIBRARY_ROOT@
2832MFC_LIBRARY_PATH = @MFC_LIBRARY_PATH@
2833
2834# First some useful definitions
2835
2836SHELL = /bin/sh
2837CC = @CC@
2838CPP = @CPP@
Francois Gouget27c3b592001-05-29 20:50:58 +00002839CXX = @CXX@
Francois Gouget3af251e2000-11-30 20:36:04 +00002840WRC = @WRC@
Francois Gouget755bb922000-11-05 05:23:39 +00002841CFLAGS = @CFLAGS@
2842CXXFLAGS = @CXXFLAGS@
Francois Gouget3af251e2000-11-30 20:36:04 +00002843WRCFLAGS = -r -L
Francois Gouget755bb922000-11-05 05:23:39 +00002844OPTIONS = @OPTIONS@ -D_REENTRANT -DWINELIB
Francois Gouget755bb922000-11-05 05:23:39 +00002845DLL_LINK = @DLL_LINK@
2846LIBS = @LIBS@ $(LIBRARY_PATH)
Francois Gouget755bb922000-11-05 05:23:39 +00002847LN_S = @LN_S@
Francois Gouget3af251e2000-11-30 20:36:04 +00002848ALLFLAGS = $(DEFINES) -I$(SRCDIR) $(WINE_INCLUDE_PATH) $(INCLUDE_PATH)
Francois Gouget27e7f282001-06-04 02:50:29 +00002849ALLCFLAGS = $(CFLAGS) $(CEXTRA) $(OPTIONS) $(ALLFLAGS)
2850ALLCXXFLAGS=$(CXXFLAGS) $(CXXEXTRA) $(OPTIONS) $(ALLFLAGS)
Francois Gouget3af251e2000-11-30 20:36:04 +00002851ALLWRCFLAGS=$(WRCFLAGS) $(WRCEXTRA) $(OPTIONS) $(ALLFLAGS)
Francois Gouget755bb922000-11-05 05:23:39 +00002852LDCOMBINE = ld -r
2853LDSHARED = @LDSHARED@
Francois Gougetc1159be2001-04-18 17:39:42 +00002854LDXXSHARED= @LDXXSHARED@
Francois Gougetbe859592000-11-15 22:12:20 +00002855LDDLLFLAGS= @LDDLLFLAGS@
2856STRIP = strip
2857STRIPFLAGS= --strip-unneeded
Francois Gouget755bb922000-11-05 05:23:39 +00002858RM = rm -f
2859MV = mv
2860MKDIR = mkdir -p
Francois Gougetbe859592000-11-15 22:12:20 +00002861WINE = @WINE@
Francois Gouget755bb922000-11-05 05:23:39 +00002862WINEBUILD = @WINEBUILD@
Francois Gouget755bb922000-11-05 05:23:39 +00002863@SET_MAKE@
2864
2865# Installation infos
2866
Francois Gouget27e7f282001-06-04 02:50:29 +00002867INSTALL = install
2868INSTALL_PROGRAM = $(INSTALL)
2869INSTALL_DATA = $(INSTALL) -m 644
Francois Gouget755bb922000-11-05 05:23:39 +00002870prefix = @prefix@
2871exec_prefix = @exec_prefix@
2872bindir = @bindir@
2873libdir = @libdir@
2874infodir = @infodir@
2875mandir = @mandir@
2876prog_manext = 1
2877conf_manext = 5
Francois Gouget755bb922000-11-05 05:23:39 +00002878
Francois Gouget3af251e2000-11-30 20:36:04 +00002879OBJS = $(C_SRCS:.c=.o) $(CXX_SRCS:.cpp=.o) \
2880 $(SPEC_SRCS:.spec=.spec.o)
2881CLEAN_FILES = *.spec.c y.tab.c y.tab.h lex.yy.c \
2882 core *.orig *.rej \
2883 \\\#*\\\# *~ *% .\\\#*
Francois Gouget755bb922000-11-05 05:23:39 +00002884
Francois Gouget755bb922000-11-05 05:23:39 +00002885# Implicit rules
2886
Francois Gouget3af251e2000-11-30 20:36:04 +00002887.SUFFIXES: .cpp .rc .res .tmp.o .spec .spec.c .spec.o
Francois Gouget755bb922000-11-05 05:23:39 +00002888
2889.c.o:
2890 $(CC) -c $(ALLCFLAGS) -o $@ $<
2891
Francois Gouget755bb922000-11-05 05:23:39 +00002892.cpp.o:
2893 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2894
Francois Gouget755bb922000-11-05 05:23:39 +00002895.cxx.o:
2896 $(CXX) -c $(ALLCXXFLAGS) -o $@ $<
2897
Francois Gouget755bb922000-11-05 05:23:39 +00002898.rc.res:
Francois Gougetd5549962001-03-16 16:39:02 +00002899 $(LD_PATH) $(WRC) $(ALLWRCFLAGS) -o $@ $<
Francois Gouget755bb922000-11-05 05:23:39 +00002900
2901.PHONY: all install uninstall clean distclean depend dummy
2902
2903# 'all' target first in case the enclosing Makefile didn't define any target
2904
2905all: Makefile
2906
2907# Rules for makefile
2908
2909Makefile: Makefile.in $(TOPSRCDIR)/configure
2910 @echo Makefile is older than $?, please rerun $(TOPSRCDIR)/configure
2911 @exit 1
2912
2913# Rules for cleaning
2914
2915$(SUBDIRS:%=%/__clean__): dummy
2916 cd `dirname $@` && $(MAKE) clean
2917
2918$(EXTRASUBDIRS:%=%/__clean__): dummy
2919 -cd `dirname $@` && $(RM) $(CLEAN_FILES)
2920
2921clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
Francois Gougeta11664c2000-12-07 23:13:23 +00002922 $(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(OBJS) $(SPEC_SRCS:.spec=.tmp.o) $(EXES) $(EXES:%=%.so) $(DLLS)
Francois Gouget755bb922000-11-05 05:23:39 +00002923
2924# Rules for installing
2925
2926$(SUBDIRS:%=%/__install__): dummy
2927 cd `dirname $@` && $(MAKE) install
2928
2929$(SUBDIRS:%=%/__uninstall__): dummy
2930 cd `dirname $@` && $(MAKE) uninstall
2931
2932# Misc. rules
2933
2934$(SUBDIRS): dummy
2935 @cd $@ && $(MAKE)
2936
2937dummy:
2938
2939# End of global rules
2940--- wrapper.c ---
2941/*
2942 * Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2943 */
2944
2945#include <dlfcn.h>
2946#include <windows.h>
2947
2948
2949
2950/*
2951 * Describe the wrapped application
2952 */
2953
2954/**
2955 * This is either CUIEXE for a console based application or
2956 * GUIEXE for a regular windows application.
2957 */
2958#define APP_TYPE ##WINEMAKER_APP_TYPE##
2959
2960/**
2961 * This is the application library's base name, i.e. 'hello' if the
2962 * library is called 'libhello.so'.
2963 */
2964static char* appName = ##WINEMAKER_APP_NAME##;
2965
2966/**
2967 * This is the name of the application's Windows module. If left NULL
2968 * then appName is used.
2969 */
2970static char* appModule = NULL;
2971
2972/**
2973 * This is the application's entry point. This is usually "WinMain" for a
2974 * GUIEXE and 'main' for a CUIEXE application.
2975 */
2976static char* appInit = ##WINEMAKER_APP_INIT##;
2977
2978/**
2979 * This is either non-NULL for MFC-based applications and is the name of the
2980 * MFC's module. This is the module in which we will take the 'WinMain'
2981 * function.
2982 */
2983static char* mfcModule = ##WINEMAKER_APP_MFC##;
2984
2985
2986
2987/*
2988 * Implement the main.
2989 */
2990
2991#if APP_TYPE == GUIEXE
2992typedef int WINAPI (*WinMainFunc)(HINSTANCE hInstance, HINSTANCE hPrevInstance,
2993 PSTR szCmdLine, int iCmdShow);
2994#else
2995typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp);
2996#endif
2997
2998#if APP_TYPE == GUIEXE
2999int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
3000 PSTR szCmdLine, int iCmdShow)
3001#else
3002int WINAPI Main(int argc, char** argv, char** envp)
3003#endif
3004{
3005 void* appLibrary;
3006 HINSTANCE hApp,hMFC,hMain;
3007 void* appMain;
3008 char* libName;
3009 int retcode;
3010
3011 /* Load the application's library */
3012 libName=(char*)malloc(strlen(appName)+5+3+1);
3013 /* FIXME: we should get the wrapper's path and use that as the base for
3014 * the library
3015 */
3016 sprintf(libName,"./lib%s.so",appName);
3017 appLibrary=dlopen(libName,RTLD_NOW);
3018 if (appLibrary==NULL) {
3019 sprintf(libName,"lib%s.so",appName);
3020 appLibrary=dlopen(libName,RTLD_NOW);
3021 }
3022 if (appLibrary==NULL) {
3023 char format[]="Could not load the %s library:\r\n%s";
3024 char* error;
3025 char* msg;
3026
3027 error=dlerror();
3028 msg=(char*)malloc(strlen(format)+strlen(libName)+strlen(error));
3029 sprintf(msg,format,libName,error);
3030 MessageBox(NULL,msg,"dlopen error",MB_OK);
3031 free(msg);
3032 return 1;
3033 }
3034
3035 /* Then if this application is MFC based, load the MFC module */
3036 /* FIXME: I'm not sure this is really necessary */
3037 if (mfcModule!=NULL) {
3038 hMFC=LoadLibrary(mfcModule);
3039 if (hMFC==NULL) {
3040 char format[]="Could not load the MFC module %s (%d)";
3041 char* msg;
3042
3043 msg=(char*)malloc(strlen(format)+strlen(mfcModule)+11);
3044 sprintf(msg,format,mfcModule,GetLastError());
3045 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
3046 free(msg);
3047 return 1;
3048 }
3049 /* MFC is a special case: the WinMain is in the MFC library,
3050 * instead of the application's library.
3051 */
3052 hMain=hMFC;
3053 } else {
3054 hMFC=NULL;
3055 }
3056
3057 /* Load the application's module */
3058 if (appModule==NULL) {
3059 appModule=appName;
3060 }
3061 hApp=LoadLibrary(appModule);
3062 if (hApp==NULL) {
3063 char format[]="Could not load the application's module %s (%d)";
3064 char* msg;
3065
3066 msg=(char*)malloc(strlen(format)+strlen(appModule)+11);
3067 sprintf(msg,format,appModule,GetLastError());
3068 MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
3069 free(msg);
3070 return 1;
3071 } else if (hMain==NULL) {
3072 hMain=hApp;
3073 }
3074
3075 /* Get the address of the application's entry point */
3076 appMain=(WinMainFunc*)GetProcAddress(hMain, appInit);
3077 if (appMain==NULL) {
3078 char format[]="Could not get the address of %s (%d)";
3079 char* msg;
3080
3081 msg=(char*)malloc(strlen(format)+strlen(appInit)+11);
3082 sprintf(msg,format,appInit,GetLastError());
3083 MessageBox(NULL,msg,"GetProcAddress error",MB_OK);
3084 free(msg);
3085 return 1;
3086 }
3087
3088 /* And finally invoke the application's entry point */
3089#if APP_TYPE == GUIEXE
3090 retcode=(*((WinMainFunc)appMain))(hApp,hPrevInstance,szCmdLine,iCmdShow);
3091#else
3092 retcode=(*((MainFunc)appMain))(argc,argv,envp);
3093#endif
3094
3095 /* Cleanup and done */
3096 FreeLibrary(hApp);
3097 if (hMFC!=NULL) {
3098 FreeLibrary(hMFC);
3099 }
3100 dlclose(appLibrary);
3101 free(libName);
3102
3103 return retcode;
3104}