winebuild: Don't segfault when run without arguments.
[wine] / tools / winapi / msvcmaker
1 #! /usr/bin/perl -w
2
3 # Copyright 2002 Patrik Stridvall
4
5 use strict;
6
7 BEGIN {
8     $0 =~ m%^(.*?/?tools)/winapi/msvcmaker$%;
9     require "$1/winapi/setup.pm";
10 }
11
12 use setup qw($current_dir $wine_dir);
13 use lib $setup::winapi_dir;
14 use config qw(get_spec_files get_makefile_in_files);
15 use output qw($output);
16 use util qw(replace_file);
17
18 use msvcmaker_options qw($options);
19
20 if($options->progress) {
21     $output->enable_progress;
22 } else {
23     $output->disable_progress;
24 }
25
26 ########################################################################
27 # main
28
29 my @spec_files = get_spec_files("winelib");
30 my @makefile_in_files = get_makefile_in_files("winelib");
31
32 my $wine = 1;
33
34 my $output_prefix_dir = "Output";
35 my $no_release = 1;
36
37 my %modules;
38
39 # These DLLs don't have a hope of compiling properly
40 my @unix_dependent_dlls = qw(iphlpapi mountmgr.sys ntdll mswsock opengl32
41                              secur32 winex11 wnaspi32 ws2_32);
42
43 sub is_unix_dependent_dll($) {
44     my $dll = shift;
45
46     foreach my $unix_only_dll (@unix_dependent_dlls) {
47         if($dll eq $unix_only_dll) {
48             return 1;
49         }
50     }
51
52     return 0;
53 }
54
55 sub read_spec_file($) {
56     my $spec_file = shift;
57
58     my $module = $spec_file;
59     $module =~ s%^.*?([^/]+)\.spec$%$1%;
60     $module .= ".dll" if $module !~ /\./;
61
62     my $type = "win32";
63
64     open(IN, "< $wine_dir/$spec_file") || die "Error: Can't open $wine_dir/$spec_file: $!\n";
65
66     my $header = 1;
67     my $lookahead = 0;
68     while($lookahead || defined($_ = <IN>)) {
69         $lookahead = 0;
70
71         s/^\s*?(.*?)\s*$/$1/; # remove whitespace at beginning and end of line
72         s/^(.*?)\s*#.*$/$1/;  # remove comments
73         /^$/ && next;         # skip empty lines
74
75         if($header)  {
76             if(/^(?:\d+|@)/) {
77                 $header = 0;
78                 $lookahead = 1;
79             }
80             next;
81         }
82
83         if(/^(\d+|@)\s+pascal(?:16)?/) {
84             $type = "win16";
85             last;
86         }
87     }
88     close(IN);
89
90     # FIXME: Kludge
91     if($module =~ /^(?:(?:imm|ole2conv|ole2prox|ole2thk|rasapi16|msacm|windebug)\.dll|comm\.drv)$/) {
92         $type = "win16";
93     }
94
95     if($type eq "win32") {
96         $modules{$module}{module} = $module;
97         $modules{$module}{type} = $type;
98         $modules{$module}{spec_file} = $spec_file;
99     }
100 }
101
102 if ($options->wine || $options->winetest) {
103     foreach my $spec_file (@spec_files) {
104         my $dll = $spec_file;
105         $dll =~ s%dlls/([^/]+)/[^/]+\.spec%$1%;
106         if(!is_unix_dependent_dll($dll)) {
107             read_spec_file($spec_file);
108         }
109     }
110 }
111
112 my @gdi32_dirs = qw(dlls/gdi32/enhmfdrv dlls/gdi32/mfdrv);
113
114 push @makefile_in_files, "libs/wine/Makefile.in";
115 push @makefile_in_files, "tools/winebuild/Makefile.in";
116
117 sub filter_files($$) {
118     my $files = shift;
119     my $filter = shift;
120
121     my $filtered_files = [];
122     my $rest_of_files = [];
123     foreach my $file (@$files) {
124         if($file =~ /$filter/) {
125             $file =~ s%.*?([^/]+)$%./$1%; # FIXME: Kludge
126             push @$filtered_files, $file;
127         } else {
128             push @$rest_of_files, $file;
129         }
130     }
131     return ($rest_of_files, $filtered_files);
132 }
133
134 my %wine_test_dsp_files;
135
136 MAKEFILE_IN: foreach my $makefile_in_file (@makefile_in_files) {
137     open(IN, "< $wine_dir/$makefile_in_file") || die "Error: Can't open $wine_dir/$makefile_in_file: $!\n";
138
139     my $topobjdir;
140     my $module;
141     my $testdll;
142     my @imports;
143     my $type;
144     my $dll;
145
146     my %vars;
147
148     my $again = 0;
149     my $lookahead = 0;
150
151     $dll = $makefile_in_file;
152     $dll =~ s%dlls/([^/]+)/Makefile\.in%$1%;
153
154     if($makefile_in_file eq "loader/Makefile.in" ||
155        is_unix_dependent_dll($dll)) {
156         next;
157     }
158
159     while($again || defined(my $line = <IN>)) {
160         if(!$again) {
161             chomp $line;
162             if($lookahead) {
163                 $lookahead = 0;
164                 $_ .= " " . $line;
165             } else {
166                 $_ = $line;
167             }
168         } else {
169             $again = 0;
170         }
171
172         s/^\s*?(.*?)\s*$/$1/; # remove whitespace at beginning and end of line
173         s/^(.*?)\s*#.*$/$1/;  # remove comments
174         /^$/ && next;         # skip empty lines
175
176         if(s/\\$/ /s) {
177             $lookahead = 1;
178             next;
179         }
180
181         if(/^MODULE\s*=\s*([\w\.]+)$/) {
182             $module = $1;
183
184             if($module eq "none") {
185                 if($makefile_in_file eq "tools/winebuild/Makefile.in") {
186                     $module = "winebuild.exe";
187                 } elsif ($makefile_in_file eq "include/Makefile.in") {
188                     $module = "include.lib";
189                 } else {
190                     next MAKEFILE_IN;
191                 }
192             }
193         } elsif (/^\@MAKE_IMPLIB_RULES\@/) {
194             $type = "lib";
195         } elsif(/^TOPOBJDIR\s*=\s*(\S+)\s*$/) {
196             $topobjdir = $1;
197         } elsif (/^TESTDLL\s*=\s*(\S+)\s*$/) {
198             $testdll = $1;
199         } elsif (/^IMPORTS\s*=\s*/) {
200             push @imports, grep !/^ntdll$/, split /\s+/s, $';
201         } elsif (/^DELAYIMPORTS\s*=\s*/) {
202             push @imports, $;
203         } elsif (/^EXTRALIBS\s*=\s*/) {
204             push @imports, map { /^-l(dxerr8|dxerr9|dxguid|strmiids|uuid)$/ ? $1 : () } split /\s+/s, $';
205         } elsif (/^CTESTS\s*=\s*/ || ( ($makefile_in_file =~ /\/tests\/Makefile\.in$/) && /^C_SRCS\s*=\s*/ ) ) {
206             my @files = split /\s+/s, $';
207
208             my $dir = $makefile_in_file;
209             $dir =~ s/\/Makefile\.in$//;
210
211             my $dsp_file = $testdll;
212             $dsp_file =~ s/\.(dll|drv)$/_test.dsp/;
213             $dsp_file = "$dir/$dsp_file";
214
215             $wine_test_dsp_files{$dsp_file}{files} = [@files, "testlist.c"];
216             $wine_test_dsp_files{$dsp_file}{imports} = [@imports];
217         } elsif(/^(\w+)\s*=\s*/) {
218             my $var = $1;
219             my @files = split /\s+/s, $';
220
221             @files = map {
222                 if(/^\$\((\w+):\%=(.*?)\%(.*?)\)$/) {
223                     my @list = @{$vars{$1}};
224                     my $prefix = $2;
225                     my $suffix = $3;
226                     foreach my $item (@list) {
227                         $item = "$prefix$item$suffix";
228                     }
229                     @list;
230                 } elsif(/^\$\(TOPOBJDIR\)(.*?)$/) {
231                     "$topobjdir$1";
232                 } elsif(/^\$/) {
233                     print STDERR "unknown variable '$_'\n" if 0;
234                     ();
235                 } else {
236                     $_;
237                 }
238             } @files;
239
240             $vars{$var} = \@files;
241         }
242     }
243
244     close(IN);
245
246     if (!$module && $makefile_in_file eq "libs/wine/Makefile.in") {
247         $module = "wine.lib";
248     }
249
250     next if !$module;
251
252     my $c_srcs = [];
253     my $source_files = [];
254     if(exists($vars{C_SRCS})) {
255         $c_srcs = [sort(@{$vars{C_SRCS}})];
256         $source_files = [sort(@{$vars{C_SRCS}})];
257     }
258
259     my $header_files = [];
260     if(exists($vars{H_SRCS})) {
261         $header_files = [sort(@{$vars{H_SRCS}})];
262     }
263
264     my $resource_files = [];
265     if(exists($vars{RC_SRCS})) {
266         $resource_files = [sort(@{$vars{RC_SRCS}})];
267     }
268
269     my $idl_h_files = [];
270     if(exists($vars{IDL_H_SRCS})) {
271         $idl_h_files = [sort(@{$vars{IDL_H_SRCS}})];
272     }
273
274     my $idl_c_files = [];
275     if(exists($vars{IDL_C_SRCS})) {
276         $idl_c_files = [sort(@{$vars{IDL_C_SRCS}})];
277     }
278
279     my $idl_s_files = [];
280     if(exists($vars{IDL_S_SRCS})) {
281         $idl_s_files = [sort(@{$vars{IDL_S_SRCS}})];
282     }
283
284     my $idl_p_files = [];
285     if(exists($vars{IDL_P_SRCS})) {
286         $idl_p_files = [sort(@{$vars{IDL_P_SRCS}})];
287     }
288
289     my $idl_tlb_files = [];
290     if(exists($vars{IDL_TLB_SRCS})) {
291         $idl_tlb_files = [sort(@{$vars{IDL_TLB_SRCS}})];
292     }
293
294     my $extradefs;
295     if(exists($vars{EXTRADEFS})) {
296         $extradefs = $vars{EXTRADEFS};
297     }
298
299     my $project = $module;
300     $project =~ s/\.(?:dll|exe|lib)$//;
301     $project =~ y/./_/;
302
303     if($module =~ /\.exe$/) {
304         $type = "exe";
305     } elsif($module =~ /\.lib$/) {
306         $type = "lib";
307     } elsif(!$type) {
308         $type = "dll";
309     }
310
311     my $dsp_file = $makefile_in_file;
312     $dsp_file =~ s/Makefile.in$/$project.dsp/;
313
314     if($module eq "gdi32.dll") {
315         foreach my $dir (@gdi32_dirs) {
316             my $dir2 = $dir;
317             $dir2 =~ s%^.*?/([^/]+)$%$1%;
318
319             my $module = "gdi32_$dir2.lib";
320             $module =~ s%/%_%g;
321
322             my $project = "gdi32_$dir2";
323             $project =~ s%/%_%g;
324
325             my $type = "lib";
326             my $dsp_file = "$dir/$project.dsp";
327
328             ($source_files, my $local_source_files) = filter_files($source_files, "$dir2/");
329             ($header_files, my $local_header_files) = filter_files($header_files, "$dir2/");
330             ($resource_files, my $local_resource_files) = filter_files($resource_files, "$dir2/");
331             ($idl_h_files, my $local_idl_h_files) = filter_files($idl_h_files, "$dir2/");
332
333             $modules{$module}{wine} = 1;
334             $modules{$module}{winetest} = 0;
335             $modules{$module}{project} = $project;
336             $modules{$module}{type} = $type;
337             $modules{$module}{dsp_file} = $dsp_file;
338             $modules{$module}{c_srcs} = $c_srcs;
339             $modules{$module}{source_files} = $local_source_files;
340             $modules{$module}{header_files} = $local_header_files;
341             $modules{$module}{resource_files} = $local_resource_files;
342             $modules{$module}{imports} = [];
343             $modules{$module}{idl_h_files} = $local_idl_h_files;
344             $modules{$module}{idl_c_files} = [];
345             $modules{$module}{idl_s_files} = [];
346             $modules{$module}{idl_p_files} = [];
347             $modules{$module}{idl_tlb_files} = [];
348             $modules{$module}{extradefs} = $extradefs if $extradefs;
349         }
350     }
351
352     $modules{$module}{wine} = 1;
353     $modules{$module}{winetest} = 0;
354     $modules{$module}{project} = $project;
355     $modules{$module}{type} = $type;
356     $modules{$module}{dsp_file} = $dsp_file;
357     $modules{$module}{c_srcs} = $c_srcs;
358     $modules{$module}{source_files} = $source_files;
359     $modules{$module}{header_files} = $header_files;
360     $modules{$module}{resource_files} = $resource_files;
361     $modules{$module}{imports} = [@imports];
362     $modules{$module}{idl_h_files} = $idl_h_files;
363     $modules{$module}{idl_c_files} = $idl_c_files;
364     $modules{$module}{idl_s_files} = $idl_s_files;
365     $modules{$module}{idl_p_files} = $idl_p_files;
366     $modules{$module}{idl_tlb_files} = $idl_tlb_files;
367     $modules{$module}{extradefs} = $extradefs if $extradefs;
368 }
369
370 $wine_test_dsp_files{"wineruntests.dsp"}{files} = ["runtests.c"];
371 $wine_test_dsp_files{"wineruntests.dsp"}{imports} = [];
372
373 $wine_test_dsp_files{"winetest.dsp"}{files} = [
374   'include/wine/exception.h',
375   'include/wine/test.h',
376   'include/wine/unicode.h',
377   'winetest.c'
378 ];
379 $wine_test_dsp_files{"winetest.dsp"}{imports} = [];
380
381 my %runtests = ();
382
383 foreach my $dsp_file (keys(%wine_test_dsp_files)) {
384     my $project = $dsp_file;
385     $project =~ s%^(?:.*?/)?([^/]+)\.dsp$%$1%;
386
387     my @files = @{$wine_test_dsp_files{$dsp_file}{files}};
388     my @imports = @{$wine_test_dsp_files{$dsp_file}{imports}};
389
390     my $type;
391     my $c_srcs = [];
392     my $source_files = [];
393     my $header_files = [];
394     my $resource_files = [];
395     my $idl_h_files = [];
396
397     my @tests = ();
398
399     if ($project eq "winetest") {
400         $type = "lib";
401         $c_srcs = [@files];
402         $source_files = [@files];
403         $header_files = [];
404         $resource_files = [];
405     } elsif ($project eq "wineruntests") {
406         $type = "exe";
407         $c_srcs = [@files];
408         $source_files = [@files];
409         $header_files = [];
410         $resource_files = [];
411     } else {
412         $type = "exe";
413         $c_srcs = [@files];
414         $source_files = [@files];
415         $header_files = [];
416         $resource_files = [];
417         
418         @tests = map {
419             if (/^testlist\.c$/) {
420                 ();
421             } else {
422                 s/\.c$//;
423                 $_;
424             }
425         } @files;
426
427         $runtests{$dsp_file} = [@tests];
428     }
429     my $module = "$project.$type";
430
431     $modules{$module}{wine} = 0;
432     $modules{$module}{winetest} = 1;
433
434     $modules{$module}{project} = $project;
435     $modules{$module}{type} = $type;
436     $modules{$module}{dsp_file} = $dsp_file;
437     $modules{$module}{c_srcs} = $c_srcs;
438     $modules{$module}{source_files} = $source_files;
439     $modules{$module}{header_files} = $header_files;
440     $modules{$module}{resource_files} = $resource_files;
441     $modules{$module}{imports} = [@imports];
442     $modules{$module}{idl_h_files} = [];
443     $modules{$module}{idl_c_files} = [];
444     $modules{$module}{idl_s_files} = [];
445     $modules{$module}{idl_p_files} = [];
446     $modules{$module}{idl_tlb_files} = [];
447
448     $modules{$module}{tests} = [@tests];
449 }
450
451 foreach my $module (sort(keys(%modules))) {
452     if($module =~ /^(?:ttydrv.dll|x11drv.dll)$/) {
453         delete $modules{$module};
454     }
455 }
456
457 my @modules = ();
458 foreach my $module (sort(keys(%modules))) {
459     if (($options->wine && $modules{$module}{wine}) ||
460         ($options->winetest && $modules{$module}{winetest}))
461     {
462         push @modules, $module;
463     }
464 }
465
466 my $progress_output;
467 my $progress_current = 0;
468 my $progress_max = scalar(@modules);
469
470 foreach my $module (@modules) {
471     my $dsp_file = $modules{$module}{dsp_file};
472     replace_file("$wine_dir/$dsp_file", \&_generate_dsp, $module);
473 }
474
475 sub output_dsp_idl_rules($$$) {
476     my $wine_include_dir = shift;
477     my $ext = shift;
478     my @idl_src_files = @{(shift)};
479
480     foreach my $idl_src_file (@idl_src_files) {
481         $idl_src_file =~ s%/%\\%g;
482         if($idl_src_file !~ /^\./) {
483             $idl_src_file = ".\\$idl_src_file";
484         }
485
486         print OUT "# Begin Source File\r\n";
487         print OUT "\r\n";
488
489         print OUT "SOURCE=$idl_src_file\r\n";
490
491         my $basename = $idl_src_file;
492         $basename =~ s/\.idl$//;
493
494         print OUT "# PROP Ignore_Default_Tool 1\r\n";
495         print OUT "# Begin Custom Build\r\n";
496         print OUT "InputPath=$idl_src_file\r\n";
497         print OUT "\r\n";
498         print OUT "BuildCmds= \\\r\n";
499         print OUT "\tmidl /nologo /I $wine_include_dir $idl_src_file ";
500         if ($ext eq ".h") {
501             print OUT "/client none /server none /notlb /h ";
502         } elsif ($ext eq "_c.c") {
503             print OUT "/server none /notlb /cstub ";
504         } elsif ($ext eq "_s.c") {
505             print OUT "/client none /notlb /sstub ";
506         } elsif ($ext eq "_p.c") {
507             print OUT "/client none /server none /notlb /proxy ";
508         } elsif ($ext eq ".tlb") {
509             print OUT "/client none /server none /tlb ";
510         }
511         print OUT "$basename$ext\r\n";
512         print OUT "\r\n";
513         print OUT "\"$basename$ext\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
514         print OUT "   \$(BuildCmds)\r\n";
515         print OUT "# End Custom Build\r\n";
516
517         print OUT "# End Source File\r\n";
518     }
519 }
520
521 sub _generate_dsp($$) {
522     local *OUT = shift;
523
524     my $module = shift;
525
526     my $dsp_file = $modules{$module}{dsp_file};
527     my $project = $modules{$module}{project};
528     my @imports = @{$modules{$module}{imports}};
529
530     my $lib = ($modules{$module}{type} eq "lib");
531     my $dll = ($modules{$module}{type} eq "dll");
532     my $exe = ($modules{$module}{type} eq "exe");
533
534     my $console = $exe; # FIXME: Not always correct
535
536     my $msvc_wine_dir = do {
537         my @parts = split(m%/%, $dsp_file);
538         if($#parts == 1) {
539             "..";
540         } elsif($#parts == 2) {
541             "..\\..";
542         } else {
543             "..\\..\\..";
544         }
545     };
546     my $wine_include_dir = "$msvc_wine_dir\\include";
547
548     $progress_current++;
549     $output->progress("$dsp_file (file $progress_current of $progress_max)");
550
551     my $base_module = $module;
552         $base_module =~ s/\.(?:dll)$//;
553
554     my @c_srcs = @{$modules{$module}{c_srcs}};
555     my @source_files = @{$modules{$module}{source_files}};
556     my @header_files = @{$modules{$module}{header_files}};
557     my @resource_files = @{$modules{$module}{resource_files}};
558     my @idl_h_files = @{$modules{$module}{idl_h_files}};
559     my @idl_c_files = @{$modules{$module}{idl_c_files}};
560     my @idl_s_files = @{$modules{$module}{idl_s_files}};
561     my @idl_p_files = @{$modules{$module}{idl_p_files}};
562     my @idl_tlb_files = @{$modules{$module}{idl_tlb_files}};
563
564     if ($project !~ /^wine(?:build|runtests|test)?$/ &&
565         $project !~ /^(?:gdi32)_.+?$/ &&
566         $project !~ /_test$/ &&
567         !$lib)
568     {
569         push @source_files, "$base_module.spec";
570         @source_files = sort(@source_files);
571     }
572
573     my $no_cpp = 1;
574     my $no_msvc_headers = 1;
575     if ($project =~ /^wine(?:runtests|test)$/ || $project =~ /_test$/) {
576         $no_msvc_headers = 0;
577     }
578
579     my @cfgs;
580
581     push @cfgs, "$project - Win32";
582
583     if (!$no_cpp) {
584         my @_cfgs;
585         foreach my $cfg (@cfgs) {
586             push @_cfgs, "$cfg C";
587             push @_cfgs, "$cfg C++";
588         }
589         @cfgs = @_cfgs;
590     }
591
592     if (!$no_release) {
593         my @_cfgs;
594         foreach my $cfg (@cfgs) {
595             push @_cfgs, "$cfg Debug";
596             push @_cfgs, "$cfg Release";
597         }
598         @cfgs = @_cfgs;
599     } else {
600         my @_cfgs;
601         foreach my $cfg (@cfgs) {
602             push @_cfgs, "$cfg Debug";
603         }
604         @cfgs = @_cfgs;
605     }
606
607     if (!$no_msvc_headers) {
608         my @_cfgs;
609         foreach my $cfg (@cfgs) {
610             push @_cfgs, "$cfg MSVC Headers";
611             push @_cfgs, "$cfg Wine Headers";
612         }
613         @cfgs = @_cfgs;
614     }
615
616     my $default_cfg = $cfgs[$#cfgs];
617
618     print OUT "# Microsoft Developer Studio Project File - Name=\"$project\" - Package Owner=<4>\r\n";
619     print OUT "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n";
620     print OUT "# ** DO NOT EDIT **\r\n";
621     print OUT "\r\n";
622
623     if ($lib) {
624         print OUT "# TARGTYPE \"Win32 (x86) Static Library\" 0x0104\r\n";
625     } elsif ($dll) {
626         print OUT "# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\r\n";
627     } else {
628         print OUT "# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n";
629     }
630     print OUT "\r\n";
631
632     print OUT "CFG=$default_cfg\r\n";
633     print OUT "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n";
634     print OUT "!MESSAGE use the Export Makefile command and run\r\n";
635     print OUT "!MESSAGE \r\n";
636     print OUT "!MESSAGE NMAKE /f \"$project.mak\".\r\n";
637     print OUT "!MESSAGE \r\n";
638     print OUT "!MESSAGE You can specify a configuration when running NMAKE\r\n";
639     print OUT "!MESSAGE by defining the macro CFG on the command line. For example:\r\n";
640     print OUT "!MESSAGE \r\n";
641     print OUT "!MESSAGE NMAKE /f \"$project.mak\" CFG=\"$default_cfg\"\r\n";
642     print OUT "!MESSAGE \r\n";
643     print OUT "!MESSAGE Possible choices for configuration are:\r\n";
644     print OUT "!MESSAGE \r\n";
645     foreach my $cfg (@cfgs) {
646         if ($lib) {
647             print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Static Library\")\r\n";
648         } elsif ($dll) {
649             print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n";
650         } else {
651             print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Console Application\")\r\n";
652         }
653     }
654     print OUT "!MESSAGE \r\n";
655     print OUT "\r\n";
656
657     print OUT "# Begin Project\r\n";
658     print OUT "# PROP AllowPerConfigDependencies 0\r\n";
659     print OUT "# PROP Scc_ProjName \"\"\r\n";
660     print OUT "# PROP Scc_LocalPath \"\"\r\n";
661     print OUT "CPP=cl.exe\r\n";
662     print OUT "MTL=midl.exe\r\n" if !$lib && !$exe;
663     print OUT "RSC=rc.exe\r\n";
664     print OUT "\r\n";
665
666     my $n = 0;
667
668     my $output_dir;
669     foreach my $cfg (@cfgs) {
670         if($#cfgs == 0) {
671             # Nothing
672         } elsif($n == 0) {
673             print OUT "!IF  \"\$(CFG)\" == \"$cfg\"\r\n";
674             print OUT "\r\n";
675         } else {
676             print OUT "\r\n";
677             print OUT "!ELSEIF  \"\$(CFG)\" == \"$cfg\"\r\n";
678             print OUT "\r\n";
679         }
680
681         my $debug = ($cfg !~ /Release/);
682         my $msvc_headers = ($cfg =~ /MSVC Headers/);
683
684         print OUT "# PROP BASE Use_MFC 0\r\n";
685
686         if($debug) {
687             print OUT "# PROP BASE Use_Debug_Libraries 1\r\n";
688         } else {
689             print OUT "# PROP BASE Use_Debug_Libraries 0\r\n";
690         }
691
692         $output_dir = $cfg;
693         $output_dir =~ s/^$project - //;
694         $output_dir =~ s/ /_/g;
695         $output_dir =~ s/C\+\+/Cxx/g;
696         if($output_prefix_dir) {
697             $output_dir = "$output_prefix_dir\\$output_dir";
698         }
699
700         print OUT "# PROP BASE Output_Dir \"$output_dir\"\r\n";
701         print OUT "# PROP BASE Intermediate_Dir \"$output_dir\"\r\n";
702
703         print OUT "# PROP BASE Target_Dir \"\"\r\n";
704
705         print OUT "# PROP Use_MFC 0\r\n";
706         if($debug) {
707             print OUT "# PROP Use_Debug_Libraries 1\r\n";
708         } else {
709             print OUT "# PROP Use_Debug_Libraries 0\r\n";
710         }
711         print OUT "# PROP Output_Dir \"$output_dir\"\r\n";
712         print OUT "# PROP Intermediate_Dir \"$output_dir\"\r\n";
713
714         print OUT "# PROP Ignore_Export_Lib 0\r\n" if $dll;
715         print OUT "# PROP Target_Dir \"\"\r\n";
716
717         print OUT "# ADD BASE CPP /nologo ";
718         my @defines = qw(WINVER=0x0600 _WIN32_WINNT=0x0600 _WIN32_IE=0x0700 WIN32);
719         if($debug) {
720             if($lib || $exe) {
721                 push @defines, qw(_DEBUG _MBCS _LIB);
722             } else {
723                 print OUT "/MDd ";
724                 push @defines, qw(_DEBUG _WINDOWS _MBCS _USRDLL);
725             }
726             print OUT "/W3 /Gm /GX /Zi /Od";
727         } else {
728             if($lib || $exe) {
729                 push @defines, qw(NDEBUG _MBCS _LIB);
730             } else {
731                 print OUT "/MD ";
732                 push @defines, qw(NDEBUG _WINDOWS _MBCS _USRDLL);
733             }
734             print OUT "/W3 /GX /O2";
735         }
736
737         foreach my $define (@defines) {
738             if ($define !~ /=/) {
739                 print OUT " /D \"$define\"";
740             } else {
741                 print OUT " /D $define";
742             }
743         }
744         print OUT " /YX" if $lib || $exe;
745         print OUT " /FD";
746         print OUT " /GZ" if $debug;
747         print OUT " /c";
748         print OUT "\r\n";
749
750         my @defines2 = qw(_CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE
751                           USE_COMPILER_EXCEPTIONS _USE_MATH_DEFINES
752                           WINVER=0x0600 _WIN32_WINNT=0x0600 _WIN32_IE=0x0700);
753         if($debug) {
754             if($lib) {
755                 print OUT "# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od";
756                 push @defines2, qw(WIN32 _DEBUG _WINDOWS _MBCS _LIB);
757             } else {
758                 print OUT "# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od";
759                 push @defines2, qw(_DEBUG WIN32 _WINDOWS _MBCS _USRDLL);
760             }
761         } else {
762             if($lib) {
763                 print OUT "# ADD CPP /nologo /MD /W3 /GX /O2";
764                 push @defines2, qw(WIN32 NDEBUG _WINDOWS _MBCS _LIB);
765             } else {
766                 print OUT "# ADD CPP /nologo /MD /W3 /GX /O2";
767                 push @defines2, qw(NDEBUG WIN32 _WINDOWS _MBCS _USRDLL);
768             }
769         }
770
771         my @includes = ();
772         if($wine) {
773             push @defines2, qw(__WINESRC__) if $project !~ /^(?:wine(?:build|test)|.*?_test)$/;
774             if ($msvc_headers) {
775                 push @defines2, qw(__WINE_USE_NATIVE_HEADERS);
776             }
777             my $output_dir2 = $output_dir;
778             $output_dir2 =~ s/\\/\\\\/g;
779             push @defines2, "__WINETEST_OUTPUT_DIR=\\\"$output_dir2\\\"";
780             push @defines2, qw(__i386__ _X86_);
781
782             if ($project eq "wine") {
783                 push @defines2, "WINE_UNICODE_API=";
784             }
785
786             if ($project =~ /_test$/) {
787                 push @includes, "$msvc_wine_dir\\$output_dir";
788             }
789
790             if (!$msvc_headers || $project eq "winetest") {
791                 push @includes, $wine_include_dir;
792             }
793         }
794
795         if($wine) {
796             foreach my $include (@includes) {
797                 print OUT " /I \"$include\"";
798             }
799         }
800
801         foreach my $define (@defines2) {
802             if ($define !~ /=/) {
803                 print OUT " /D \"$define\"";
804             } else {
805                 print OUT " /D $define";
806             }
807         }
808         print OUT " /D inline=__inline" if $wine;
809         print OUT " /D \"__STDC__\"" if 0 && $wine;
810
811         if(exists($modules{$module}{extradefs})) {
812             print OUT " @{$modules{$module}{extradefs}} ";
813         }
814
815         print OUT " /YX" if $lib;
816         print OUT " /FR" if !$lib;
817         print OUT " /FD";
818         print OUT " /GZ" if $debug;
819         print OUT " /c";
820         print OUT " /TP" if !$no_cpp;
821         print OUT "\r\n";
822
823         if($debug) {
824             print OUT "# SUBTRACT CPP /X /YX\r\n" if $dll;
825             print OUT "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
826             print OUT "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
827             print OUT "# ADD BASE RSC /l 0x41d /d \"_DEBUG\"\r\n";
828             print OUT "# ADD RSC /l 0x41d";
829             if($wine) {
830                 foreach my $include (@includes) {
831                     print OUT " /i \"$include\"";
832                 }
833             }
834             print OUT " /d \"_DEBUG\"\r\n";
835         } else {
836             print OUT "# SUBTRACT CPP /YX\r\n" if $dll;
837             print OUT "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
838             print OUT "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
839             print OUT "# ADD BASE RSC /l 0x41d /d \"NDEBUG\"\r\n";
840             print OUT "# ADD RSC /l 0x41d";
841             if($wine) {
842                 foreach my $include (@includes) {
843                     print OUT " /i \"$include\"";
844                 }
845             }
846             print OUT "/d \"NDEBUG\"\r\n";
847         }
848         print OUT "BSC32=bscmake.exe\r\n";
849         print OUT "# ADD BASE BSC32 /nologo\r\n";
850         print OUT "# ADD BSC32 /nologo\r\n";
851
852         if($exe || $dll) {
853             print OUT "LINK32=link.exe\r\n";
854             print OUT "# ADD BASE LINK32";
855             my @libraries = qw(kernel32.lib user32.lib gdi32.lib winspool.lib
856                                comdlg32.lib advapi32.lib shell32.lib ole32.lib
857                                oleaut32.lib uuid.lib odbc32.lib odbccp32.lib);
858             foreach my $library (@libraries) {
859                 print OUT " $library";
860             }
861             print OUT " /nologo";
862             print OUT " /dll" if $dll;
863             print OUT " /subsystem:console" if $console;
864             print OUT " /debug" if $debug;
865             print OUT " /machine:I386";
866             print OUT " /pdbtype:sept" if $debug;
867             print OUT "\r\n";
868
869             print OUT "# ADD LINK32";
870             print OUT " libcmt.lib" if $project =~ /^ntdll$/; # FIXME: Kludge
871             foreach my $import (@imports) {
872                 print OUT " $import.lib" if ($import ne "msvcrt");
873             }
874             print OUT " /nologo";
875             print OUT " /dll" if $dll;
876             print OUT " /subsystem:console" if $console;
877             print OUT " /debug" if $debug;
878             print OUT " /machine:I386";
879             print OUT " /nodefaultlib" if $project =~ /^ntdll$/; # FIXME: Kludge
880             print OUT " /def:\"$project.def\"" if $dll;
881             print OUT " /pdbtype:sept" if $debug;
882             print OUT "\r\n";
883         } else {
884             print OUT "LIB32=link.exe -lib\r\n";
885             print OUT "# ADD BASE LIB32 /nologo\r\n";
886             print OUT "# ADD LIB32 /nologo\r\n";
887         }
888
889         $n++;
890     }
891
892     if($#cfgs != 0) {
893         print OUT "\r\n";
894         print OUT "!ENDIF \r\n";
895         print OUT "\r\n";
896     }
897
898     print OUT "# Begin Target\r\n";
899     print OUT "\r\n";
900     foreach my $cfg (@cfgs) {
901         print OUT "# Name \"$cfg\"\r\n";
902     }
903
904     print OUT "# Begin Group \"Source Files\"\r\n";
905     print OUT "\r\n";
906     print OUT "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
907
908     if ($project eq "winebuild") {
909         for my $ source_file ("getopt.c", "getopt1.c", "mkstemps.c")
910         {
911             print OUT "# Begin Source File\r\n";
912             print OUT "\r\n";
913             print OUT "SOURCE=..\\..\\libs\\port\\$source_file\r\n";
914             print OUT "# End Source File\r\n";
915         }
916     }
917
918     foreach my $source_file (@source_files) {
919         $source_file =~ s%/%\\%g;
920         if($source_file !~ /^\./) {
921             $source_file = ".\\$source_file";
922         }
923
924         print OUT "# Begin Source File\r\n";
925         print OUT "\r\n";
926
927         print OUT "SOURCE=$source_file\r\n";
928
929         if ($project eq "wine" && $source_file eq ".\\config.c") {
930             print OUT "# ADD CPP /D BINDIR=\\\"\\\" /D DLLDIR=\\\"\\\" /D LIB_TO_BINDIR=\\\"\\\" /D LIB_TO_DLLDIR=\\\"\\\" /D BIN_TO_DLLDIR=\\\"\\\" /D LIB_TO_DATADIR=\\\"\\\" /D BIN_TO_DATADIR=\\\"\\\"\r\n";
931         }
932
933         if($source_file =~ /^(.*?)\.spec$/) {
934             my $basename = $1;
935
936             my $spec_file = $source_file;
937             my $def_file = "$basename.def";
938
939             my $srcdir = "."; # FIXME: Is this really always correct?
940
941             print OUT "# Begin Custom Build\r\n";
942             print OUT "InputPath=$spec_file\r\n";
943             print OUT "\r\n";
944             print OUT "BuildCmds= \\\r\n";
945             print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe -w --def -k -o $def_file --export $spec_file\r\n";
946             print OUT "\r\n";
947             print OUT "\"$def_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
948             print OUT "   \$(BuildCmds)\r\n";
949             print OUT "# End Custom Build\r\n";
950         } elsif($source_file =~ /([^\\]*?\.h)$/) {
951             my $h_file = $1;
952
953             foreach my $cfg (@cfgs) {
954                 if($#cfgs == 0) {
955                     # Nothing
956                 } elsif($n == 0) {
957                     print OUT "!IF  \"\$(CFG)\" == \"$cfg\"\r\n";
958                     print OUT "\r\n";
959                 } else {
960                     print OUT "\r\n";
961                     print OUT "!ELSEIF  \"\$(CFG)\" == \"$cfg\"\r\n";
962                     print OUT "\r\n";
963                 }
964
965                 $output_dir = $cfg;
966                 $output_dir =~ s/^$project - //;
967                 $output_dir =~ s/ /_/g;
968                 $output_dir =~ s/C\+\+/Cxx/g;
969                 if($output_prefix_dir) {
970                     $output_dir = "$output_prefix_dir\\$output_dir";
971                 }
972
973                 print OUT "# Begin Custom Build\r\n";
974                 print OUT "OutDir=$output_dir\r\n";
975                 print OUT "InputPath=$source_file\r\n";
976                 print OUT "\r\n";
977                 print OUT "\"\$(OutDir)\\wine\\$h_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
978                 print OUT "\tcopy \"\$(InputPath)\" \"\$(OutDir)\\wine\"\r\n";
979                 print OUT "\r\n";
980                 print OUT "# End Custom Build\r\n";
981             }
982
983             if($#cfgs != 0) {
984                 print OUT "\r\n";
985                 print OUT "!ENDIF \r\n";
986                 print OUT "\r\n";
987             }
988         }
989
990         print OUT "# End Source File\r\n";
991     }
992
993     output_dsp_idl_rules $wine_include_dir, ".h", \@idl_h_files;
994     output_dsp_idl_rules $wine_include_dir, "_c.c", \@idl_c_files;
995     output_dsp_idl_rules $wine_include_dir, "_s.c", \@idl_s_files;
996     output_dsp_idl_rules $wine_include_dir, "_p.c", \@idl_p_files;
997     # Hack - stdole2.idl cannot be compiled with midl
998     if($project ne "include") {
999         output_dsp_idl_rules $wine_include_dir, ".tlb", \@idl_tlb_files;
1000     }
1001
1002     print OUT "# End Group\r\n";
1003
1004     print OUT "# Begin Group \"Header Files\"\r\n";
1005     print OUT "\r\n";
1006     print OUT "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
1007     foreach my $header_file (@header_files) {
1008         print OUT "# Begin Source File\r\n";
1009         print OUT "\r\n";
1010         print OUT "SOURCE=.\\$header_file\r\n";
1011         print OUT "# End Source File\r\n";
1012     }
1013     print OUT "# End Group\r\n";
1014
1015
1016
1017     print OUT "# Begin Group \"Resource Files\"\r\n";
1018     print OUT "\r\n";
1019     print OUT "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
1020     foreach my $resource_file (@resource_files) {
1021         print OUT "# Begin Source File\r\n";
1022         print OUT "\r\n";
1023         print OUT "SOURCE=.\\$resource_file\r\n";
1024         print OUT "# End Source File\r\n";
1025     }
1026     print OUT "# End Group\r\n";
1027
1028     print OUT "# End Target\r\n";
1029     print OUT "# End Project\r\n";
1030
1031     close(OUT);
1032 }
1033
1034 sub _generate_dsw_header($) {
1035     local *OUT = shift;
1036
1037     print OUT "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n";
1038     print OUT "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n";
1039     print OUT "\r\n";
1040 }
1041
1042 sub _generate_dsw_project($$$$) {
1043     local *OUT = shift;
1044
1045     my $project = shift;
1046     my $dsp_file = shift;
1047     my @dependencies = @{(shift)};
1048
1049     $dsp_file = "./$dsp_file";
1050     $dsp_file =~ y%/%\\%;
1051     
1052     @dependencies = sort(@dependencies);
1053
1054     print OUT "###############################################################################\r\n";
1055     print OUT "\r\n";
1056     print OUT "Project: \"$project\"=$dsp_file - Package Owner=<4>\r\n";
1057     print OUT "\r\n";
1058     print OUT "Package=<5>\r\n";
1059     print OUT "{{{\r\n";
1060     print OUT "}}}\r\n";
1061     print OUT "\r\n";
1062     print OUT "Package=<4>\r\n";
1063     print OUT "{{{\r\n";
1064     foreach my $dependency (@dependencies) {
1065         print OUT "    Begin Project Dependency\r\n";
1066         print OUT "    Project_Dep_Name $dependency\r\n";
1067         print OUT "    End Project Dependency\r\n";
1068     }
1069     print OUT "}}}\r\n";
1070     print OUT "\r\n";
1071 }
1072
1073 sub _generate_dsw_footer($) {
1074     local *OUT = shift;
1075
1076     print OUT "###############################################################################\r\n";
1077     print OUT "\r\n";
1078     print OUT "Global:\r\n";
1079     print OUT "\r\n";
1080     print OUT "Package=<5>\r\n";
1081     print OUT "{{{\r\n";
1082     print OUT "}}}\r\n";
1083     print OUT "\r\n";
1084     print OUT "Package=<3>\r\n";
1085     print OUT "{{{\r\n";
1086     print OUT "}}}\r\n";
1087     print OUT "\r\n";
1088     print OUT "###############################################################################\r\n";
1089     print OUT "\r\n";
1090 }
1091
1092 if ($options->wine) {
1093     my $dsw_file = "wine.dsw";
1094     $output->progress("$dsw_file");
1095     replace_file("$wine_dir/$dsw_file", \&_generate_wine_dsw);
1096 }
1097
1098 sub _generate_wine_dsw($) {
1099     local *OUT = shift;
1100
1101     _generate_dsw_header(\*OUT);
1102     foreach my $module (sort(keys(%modules))) {
1103         next if $module =~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1104
1105         my $project = $modules{$module}{project};
1106         my $dsp_file = $modules{$module}{dsp_file};
1107
1108         my @dependencies;
1109         if($project eq "wine") {
1110             @dependencies = ();
1111         } elsif($project eq "winebuild") {
1112             @dependencies = ("wine");
1113         } elsif($project =~ /^(?:gdi32)_.+?$/) {
1114             @dependencies = ();
1115         } else {
1116             @dependencies = ("wine", "include", "winebuild");
1117         }
1118
1119         if($project =~ /^gdi32$/) {
1120             foreach my $dir (@gdi32_dirs) {
1121                 my $dir2 = $dir;
1122                 $dir2 =~ s%^.*?/([^/]+)$%$1%;
1123
1124                 my $module = "gdi32_$dir2";
1125                 $module =~ s%/%_%g;
1126                 push @dependencies, $module;
1127             }
1128         }
1129
1130         _generate_dsw_project(\*OUT, $project, $dsp_file, \@dependencies);
1131     }
1132     _generate_dsw_footer(\*OUT);
1133
1134     return 1;
1135 }
1136
1137 if ($options->winetest) {
1138     my $dsw_file = "winetest.dsw";
1139     $output->progress("$dsw_file");
1140     replace_file("$wine_dir/$dsw_file", \&_generate_winetest_dsw);
1141 }
1142
1143 sub _generate_winetest_dsw($) {
1144     local *OUT = shift;
1145
1146     _generate_dsw_header(\*OUT);
1147
1148     my @runtests_dependencies = ();
1149     foreach my $module (sort(keys(%modules))) {
1150         next if $module !~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1151         next if $module eq "wineruntests";
1152
1153         my $project = $modules{$module}{project};
1154
1155         push @runtests_dependencies, $project;
1156     }
1157
1158     foreach my $module (sort(keys(%modules))) {
1159         next if $module !~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1160
1161         my $project = $modules{$module}{project};
1162         my $dsp_file = $modules{$module}{dsp_file};
1163
1164         my @dependencies;
1165         if($project =~ /^winetest$/) {
1166             @dependencies = ();
1167         } elsif($project =~ /^wineruntests$/) {
1168             @dependencies = @runtests_dependencies;
1169         } else {
1170             @dependencies = ("winetest");
1171         }
1172
1173         _generate_dsw_project(\*OUT, $project, $dsp_file, \@dependencies);
1174     }
1175
1176     _generate_dsw_footer(\*OUT);
1177 }
1178
1179 if ($options->winetest) {
1180     foreach my $module (sort(keys(%modules))) {
1181         next if $module !~ /_test\.exe$/;
1182
1183         my $project = $modules{$module}{project};
1184         my $dsp_file = $modules{$module}{dsp_file};
1185         my @tests = @{$modules{$module}{tests}};
1186
1187         my $testlist_c = $dsp_file;
1188         $testlist_c =~ s%[^/]*\.dsp$%testlist.c%;
1189
1190         replace_file("$wine_dir/$testlist_c", \&_generate_testlist_c, \@tests);
1191     }
1192 }
1193
1194 # ***** Keep in sync with tools/make_ctests *****
1195 sub _generate_testlist_c($$) {
1196     local *OUT = shift;
1197
1198     my @tests = @{(shift)};
1199
1200     print OUT "/* Automatically generated file; DO NOT EDIT!! */\n";
1201     print OUT "\n";
1202     print OUT "/* stdarg.h is needed for Winelib */\n";
1203     print OUT "#include <stdarg.h>\n";
1204     print OUT "#include <stdio.h>\n";
1205     print OUT "#include <stdlib.h>\n";
1206     print OUT "#include \"windef.h\"\n";
1207     print OUT "#include \"winbase.h\"\n";
1208     print OUT "\n";
1209     print OUT "#define STANDALONE\n";
1210     print OUT "#include \"wine/test.h\"\n";
1211     print OUT "\n";
1212     foreach my $test (@tests) {
1213         print OUT "extern void func_$test(void);\n";
1214     }
1215     print OUT "\n";
1216     print OUT "const struct test winetest_testlist[] =\n";
1217     print OUT "{\n";
1218     foreach my $test (@tests) {
1219         print OUT "    { \"$test\", func_$test },\n";
1220     }
1221     print OUT "    { 0, 0 }\n";
1222     print OUT "};\n";
1223 }
1224
1225 if ($options->winetest) {
1226     replace_file("$wine_dir/runtests.c", \&_generate_runtests_c);
1227 }
1228
1229 sub _generate_runtests_c($) {
1230     local *OUT = shift;
1231
1232     print OUT "/* Automatically generated file; DO NOT EDIT!! */\n";
1233
1234     print OUT "\n";
1235     print OUT "#include <stdio.h>\n";
1236     print OUT "#include <stdlib.h>\n";
1237     print OUT "\n";
1238
1239     print OUT "int main(int argc, char *argv[])\n";
1240     print OUT "{\n";
1241     print OUT "    char output_dir[] = __WINETEST_OUTPUT_DIR;\n";
1242     print OUT "    char command[4096];\n";
1243     print OUT "\n";
1244     foreach my $dsp_file (keys(%runtests)) {
1245         my @tests =  @{$runtests{$dsp_file}};
1246
1247         my $project = $dsp_file;
1248         $project =~ s%^(.*?)/?([^/]+)\.dsp$%$2%;
1249         my $dir = $1;
1250         $dir =~ s%/%\\\\%g; 
1251
1252         foreach my $test (@tests) {
1253             print OUT "    sprintf(command, \"$dir\\\\%s\\\\$project.exe $test\", output_dir);\n";
1254             print OUT "    system(command);\n";
1255             print OUT "\n";
1256         }
1257     }
1258     print OUT "    return 0;\n";
1259     print OUT "}\n";
1260 }
1261
1262 if ($options->winetest) {
1263     replace_file("$wine_dir/winetest.c", \&_generate_winetest_c);
1264 }
1265
1266 sub _generate_winetest_c($) {
1267     local *OUT = shift;
1268
1269     print OUT "/* Automatically generated file; DO NOT EDIT!! */\n\n";
1270
1271     print OUT "/* Force the linker to generate a .lib file */\n";
1272     print OUT "void __wine_dummy_lib_function(void)\n{\n}\n\n";
1273 }
1274
1275 if ($options->wine) {
1276     my $config_h = "include/config.h";
1277
1278     $output->progress("$config_h");
1279
1280     replace_file("$wine_dir/$config_h", \&_generate_config_h);
1281 }
1282
1283 sub _generate_config_h($) {
1284     local *OUT = shift;
1285     my @defines;
1286
1287     print OUT "#define __WINE_CONFIG_H\n";
1288     print OUT "\n";
1289
1290     my @headers = qw(direct.h float.h memory.h io.h stdlib.h string.h process.h sys/stat.h sys/types.h);
1291     foreach my $header (@headers) {
1292         $header =~ y/\.\//__/;
1293         push @defines, "HAVE_\U$header\E 1";
1294     }
1295
1296     my @functions = qw(
1297         _pclose _popen _snprintf _spawnvp _stricmp _strnicmp _strdup
1298         _strtoi64 _strtoui64 _vsnprintf
1299         chsize memmove strdup spawnvp strerror vsnprintf
1300     );
1301     foreach my $function (@functions) {
1302         push @defines, "HAVE_\U$function\E 1";
1303     }
1304
1305     my @types = qw(
1306         long_long off_t size_t
1307     );
1308     foreach my $type (@types) {
1309         push @defines, "HAVE_\U$type\E 1";
1310     }
1311
1312     foreach my $define (sort(@defines)) {
1313         print OUT "#define $define\n";
1314         print OUT "\n";
1315     }
1316
1317     print OUT "/* Define to the address where bug reports for this package should be sent. */\n";
1318     print OUT "#define PACKAGE_BUGREPORT \"\"\n";
1319     print OUT "\n";
1320
1321     print OUT "/* Define to the full name of this package. */\n";
1322     print OUT "#define PACKAGE_NAME \"Wine\"\n";
1323     print OUT "\n";
1324
1325     print OUT "/* Define to the full name and version of this package. */\n";
1326     print OUT "#define PACKAGE_STRING \"Wine YYYYMMDD\"\n";
1327     print OUT "\n";
1328
1329     print OUT "/* Define to the one symbol short name of this package. */\n";
1330     print OUT "#define PACKAGE_TARNAME \"wine\"\n";
1331     print OUT "\n";
1332
1333     print OUT "/* Define to the version of this package. */\n";
1334     print OUT "#define PACKAGE_VERSION \"YYYYMMDD\"\n";
1335     print OUT "\n";
1336
1337     print OUT "#define X_DISPLAY_MISSING 1\n";
1338     print OUT "\n";
1339
1340     print OUT "/* Define to a macro to generate an assembly function directive */\n";
1341     print OUT "#define __ASM_FUNC(name) \"\"\n";
1342     print OUT "\n";
1343
1344     print OUT "/* Define to a macro to generate an assembly name from a C symbol */\n";
1345     print OUT "#define __ASM_NAME(name) name\n";
1346     print OUT "\n";
1347
1348     close(OUT);
1349 }