winmm/tests: Fix the failures on Win9x and WinMe.
[wine/hacks.git] / tools / winapi / msvcmaker
blob91ea656a31d31ca0a4204de300a5960f1e4092d3
1 #! /usr/bin/perl -w
3 # Copyright 2002 Patrik Stridvall
5 use strict;
7 BEGIN {
8 $0 =~ m%^(.*?/?tools)/winapi/msvcmaker$%;
9 require "$1/winapi/setup.pm";
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);
18 use msvcmaker_options qw($options);
20 if($options->progress) {
21 $output->enable_progress;
22 } else {
23 $output->disable_progress;
26 ########################################################################
27 # main
29 my @spec_files = get_spec_files("winelib");
30 my @makefile_in_files = get_makefile_in_files("winelib");
32 my $wine = 1;
34 my $output_prefix_dir = "Output";
35 my $no_release = 1;
37 my %modules;
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);
43 sub is_unix_dependent_dll($) {
44 my $dll = shift;
46 foreach my $unix_only_dll (@unix_dependent_dlls) {
47 if($dll eq $unix_only_dll) {
48 return 1;
52 return 0;
55 sub read_spec_file($) {
56 my $spec_file = shift;
58 my $module = $spec_file;
59 $module =~ s%^.*?([^/]+)\.spec$%$1%;
60 $module .= ".dll" if $module !~ /\./;
62 my $type = "win32";
64 open(IN, "< $wine_dir/$spec_file") || die "Error: Can't open $wine_dir/$spec_file: $!\n";
66 my $header = 1;
67 my $lookahead = 0;
68 while($lookahead || defined($_ = <IN>)) {
69 $lookahead = 0;
71 s/^\s*?(.*?)\s*$/$1/; # remove whitespace at beginning and end of line
72 s/^(.*?)\s*#.*$/$1/; # remove comments
73 /^$/ && next; # skip empty lines
75 if($header) {
76 if(/^(?:\d+|@)/) {
77 $header = 0;
78 $lookahead = 1;
80 next;
83 if(/^(\d+|@)\s+pascal(?:16)?/) {
84 $type = "win16";
85 last;
88 close(IN);
90 # FIXME: Kludge
91 if($module =~ /^(?:(?:imm|ole2conv|ole2prox|ole2thk|rasapi16|msacm|windebug)\.dll|comm\.drv)$/) {
92 $type = "win16";
95 if($type eq "win32") {
96 $modules{$module}{module} = $module;
97 $modules{$module}{type} = $type;
98 $modules{$module}{spec_file} = $spec_file;
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);
112 my @gdi32_dirs = qw(dlls/gdi32/enhmfdrv dlls/gdi32/mfdrv);
114 push @makefile_in_files, "libs/wine/Makefile.in";
115 push @makefile_in_files, "tools/winebuild/Makefile.in";
117 sub filter_files($$) {
118 my $files = shift;
119 my $filter = shift;
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;
131 return ($rest_of_files, $filtered_files);
134 my %wine_test_dsp_files;
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";
139 my $topobjdir;
140 my $module;
141 my $testdll;
142 my @imports;
143 my $type;
144 my $dll;
146 my %vars;
148 my $again = 0;
149 my $lookahead = 0;
151 $dll = $makefile_in_file;
152 $dll =~ s%dlls/([^/]+)/Makefile\.in%$1%;
154 if($makefile_in_file eq "loader/Makefile.in" ||
155 is_unix_dependent_dll($dll)) {
156 next;
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;
168 } else {
169 $again = 0;
172 s/^\s*?(.*?)\s*$/$1/; # remove whitespace at beginning and end of line
173 s/^(.*?)\s*#.*$/$1/; # remove comments
174 /^$/ && next; # skip empty lines
176 if(s/\\$/ /s) {
177 $lookahead = 1;
178 next;
181 if(/^MODULE\s*=\s*([\w\.]+)$/) {
182 $module = $1;
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;
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*/) {
206 my @files = split /\s+/s, $';
208 my $dir = $makefile_in_file;
209 $dir =~ s/\/Makefile\.in$//;
211 my $dsp_file = $testdll;
212 $dsp_file =~ s/\.(dll|drv)$/_test.dsp/;
213 $dsp_file = "$dir/$dsp_file";
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, $';
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";
229 @list;
230 } elsif(/^\$\(TOPOBJDIR\)(.*?)$/) {
231 "$topobjdir$1";
232 } elsif(/^\$/) {
233 print STDERR "unknown variable '$_'\n" if 0;
235 } else {
238 } @files;
240 $vars{$var} = \@files;
244 close(IN);
246 if (!$module && $makefile_in_file eq "libs/wine/Makefile.in") {
247 $module = "wine.lib";
250 next if !$module;
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}})];
259 my $header_files = [];
260 if(exists($vars{H_SRCS})) {
261 $header_files = [sort(@{$vars{H_SRCS}})];
264 my $resource_files = [];
265 if(exists($vars{RC_SRCS})) {
266 $resource_files = [sort(@{$vars{RC_SRCS}})];
269 my $idl_h_files = [];
270 if(exists($vars{IDL_H_SRCS})) {
271 $idl_h_files = [sort(@{$vars{IDL_H_SRCS}})];
274 my $extradefs;
275 if(exists($vars{EXTRADEFS})) {
276 $extradefs = $vars{EXTRADEFS};
279 my $project = $module;
280 $project =~ s/\.(?:dll|exe|lib)$//;
281 $project =~ y/./_/;
283 if($module =~ /\.exe$/) {
284 $type = "exe";
285 } elsif($module =~ /\.lib$/) {
286 $type = "lib";
287 } elsif(!$type) {
288 $type = "dll";
291 my $dsp_file = $makefile_in_file;
292 $dsp_file =~ s/Makefile.in$/$project.dsp/;
294 if($module eq "gdi32.dll") {
295 foreach my $dir (@gdi32_dirs) {
296 my $dir2 = $dir;
297 $dir2 =~ s%^.*?/([^/]+)$%$1%;
299 my $module = "gdi32_$dir2.lib";
300 $module =~ s%/%_%g;
302 my $project = "gdi32_$dir2";
303 $project =~ s%/%_%g;
305 my $type = "lib";
306 my $dsp_file = "$dir/$project.dsp";
308 ($source_files, my $local_source_files) = filter_files($source_files, "$dir2/");
309 ($header_files, my $local_header_files) = filter_files($header_files, "$dir2/");
310 ($resource_files, my $local_resource_files) = filter_files($resource_files, "$dir2/");
311 ($idl_h_files, my $local_idl_h_files) = filter_files($idl_h_files, "$dir2/");
313 $modules{$module}{wine} = 1;
314 $modules{$module}{winetest} = 0;
315 $modules{$module}{project} = $project;
316 $modules{$module}{type} = $type;
317 $modules{$module}{dsp_file} = $dsp_file;
318 $modules{$module}{c_srcs} = $c_srcs;
319 $modules{$module}{source_files} = $local_source_files;
320 $modules{$module}{header_files} = $local_header_files;
321 $modules{$module}{resource_files} = $local_resource_files;
322 $modules{$module}{imports} = [];
323 $modules{$module}{idl_h_files} = $local_idl_h_files;
324 $modules{$module}{extradefs} = $extradefs if $extradefs;
328 $modules{$module}{wine} = 1;
329 $modules{$module}{winetest} = 0;
330 $modules{$module}{project} = $project;
331 $modules{$module}{type} = $type;
332 $modules{$module}{dsp_file} = $dsp_file;
333 $modules{$module}{c_srcs} = $c_srcs;
334 $modules{$module}{source_files} = $source_files;
335 $modules{$module}{header_files} = $header_files;
336 $modules{$module}{resource_files} = $resource_files;
337 $modules{$module}{imports} = [@imports];
338 $modules{$module}{idl_h_files} = $idl_h_files;
339 $modules{$module}{extradefs} = $extradefs if $extradefs;
342 $wine_test_dsp_files{"wineruntests.dsp"}{files} = ["runtests.c"];
343 $wine_test_dsp_files{"wineruntests.dsp"}{imports} = [];
345 $wine_test_dsp_files{"winetest.dsp"}{files} = [
346 'include/wine/exception.h',
347 'include/wine/test.h',
348 'include/wine/unicode.h',
349 'winetest.c'
351 $wine_test_dsp_files{"winetest.dsp"}{imports} = [];
353 my %runtests = ();
355 foreach my $dsp_file (keys(%wine_test_dsp_files)) {
356 my $project = $dsp_file;
357 $project =~ s%^(?:.*?/)?([^/]+)\.dsp$%$1%;
359 my @files = @{$wine_test_dsp_files{$dsp_file}{files}};
360 my @imports = @{$wine_test_dsp_files{$dsp_file}{imports}};
362 my $type;
363 my $c_srcs = [];
364 my $source_files = [];
365 my $header_files = [];
366 my $resource_files = [];
367 my $idl_h_files = [];
369 my @tests = ();
371 if ($project eq "winetest") {
372 $type = "lib";
373 $c_srcs = [@files];
374 $source_files = [@files];
375 $header_files = [];
376 $resource_files = [];
377 } elsif ($project eq "wineruntests") {
378 $type = "exe";
379 $c_srcs = [@files];
380 $source_files = [@files];
381 $header_files = [];
382 $resource_files = [];
383 } else {
384 $type = "exe";
385 $c_srcs = [@files];
386 $source_files = [@files];
387 $header_files = [];
388 $resource_files = [];
390 @tests = map {
391 if (/^testlist\.c$/) {
393 } else {
394 s/\.c$//;
397 } @files;
399 $runtests{$dsp_file} = [@tests];
401 my $module = "$project.$type";
403 $modules{$module}{wine} = 0;
404 $modules{$module}{winetest} = 1;
406 $modules{$module}{project} = $project;
407 $modules{$module}{type} = $type;
408 $modules{$module}{dsp_file} = $dsp_file;
409 $modules{$module}{c_srcs} = $c_srcs;
410 $modules{$module}{source_files} = $source_files;
411 $modules{$module}{header_files} = $header_files;
412 $modules{$module}{resource_files} = $resource_files;
413 $modules{$module}{imports} = [@imports];
414 $modules{$module}{idl_h_files} = [];
416 $modules{$module}{tests} = [@tests];
419 foreach my $module (sort(keys(%modules))) {
420 if($module =~ /^(?:ttydrv.dll|x11drv.dll)$/) {
421 delete $modules{$module};
425 my @modules = ();
426 foreach my $module (sort(keys(%modules))) {
427 if (($options->wine && $modules{$module}{wine}) ||
428 ($options->winetest && $modules{$module}{winetest}))
430 push @modules, $module;
434 my $progress_output;
435 my $progress_current = 0;
436 my $progress_max = scalar(@modules);
438 foreach my $module (@modules) {
439 my $dsp_file = $modules{$module}{dsp_file};
440 replace_file("$wine_dir/$dsp_file", \&_generate_dsp, $module);
443 sub _generate_dsp($$) {
444 local *OUT = shift;
446 my $module = shift;
448 my $dsp_file = $modules{$module}{dsp_file};
449 my $project = $modules{$module}{project};
450 my @imports = @{$modules{$module}{imports}};
452 my $lib = ($modules{$module}{type} eq "lib");
453 my $dll = ($modules{$module}{type} eq "dll");
454 my $exe = ($modules{$module}{type} eq "exe");
456 my $console = $exe; # FIXME: Not always correct
458 my $msvc_wine_dir = do {
459 my @parts = split(m%/%, $dsp_file);
460 if($#parts == 1) {
461 "..";
462 } elsif($#parts == 2) {
463 "..\\..";
464 } else {
465 "..\\..\\..";
468 my $wine_include_dir = "$msvc_wine_dir\\include";
470 $progress_current++;
471 $output->progress("$dsp_file (file $progress_current of $progress_max)");
473 my $base_module = $module;
474 $base_module =~ s/\.(?:dll)$//;
476 my @c_srcs = @{$modules{$module}{c_srcs}};
477 my @source_files = @{$modules{$module}{source_files}};
478 my @header_files = @{$modules{$module}{header_files}};
479 my @resource_files = @{$modules{$module}{resource_files}};
480 my @idl_h_files = @{$modules{$module}{idl_h_files}};
482 if ($project !~ /^wine(?:build|runtests|test)?$/ &&
483 $project !~ /^(?:gdi32)_.+?$/ &&
484 $project !~ /_test$/ &&
485 !$lib)
487 push @source_files, "$base_module.spec";
488 @source_files = sort(@source_files);
491 my $no_cpp = 1;
492 my $no_msvc_headers = 1;
493 if ($project =~ /^wine(?:runtests|test)$/ || $project =~ /_test$/) {
494 $no_msvc_headers = 0;
497 my @cfgs;
499 push @cfgs, "$project - Win32";
501 if (!$no_cpp) {
502 my @_cfgs;
503 foreach my $cfg (@cfgs) {
504 push @_cfgs, "$cfg C";
505 push @_cfgs, "$cfg C++";
507 @cfgs = @_cfgs;
510 if (!$no_release) {
511 my @_cfgs;
512 foreach my $cfg (@cfgs) {
513 push @_cfgs, "$cfg Debug";
514 push @_cfgs, "$cfg Release";
516 @cfgs = @_cfgs;
519 if (!$no_msvc_headers) {
520 my @_cfgs;
521 foreach my $cfg (@cfgs) {
522 push @_cfgs, "$cfg MSVC Headers";
523 push @_cfgs, "$cfg Wine Headers";
525 @cfgs = @_cfgs;
528 my $default_cfg = $cfgs[$#cfgs];
530 print OUT "# Microsoft Developer Studio Project File - Name=\"$project\" - Package Owner=<4>\r\n";
531 print OUT "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n";
532 print OUT "# ** DO NOT EDIT **\r\n";
533 print OUT "\r\n";
535 if ($lib) {
536 print OUT "# TARGTYPE \"Win32 (x86) Static Library\" 0x0104\r\n";
537 } elsif ($dll) {
538 print OUT "# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\r\n";
539 } else {
540 print OUT "# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n";
542 print OUT "\r\n";
544 print OUT "CFG=$default_cfg\r\n";
545 print OUT "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n";
546 print OUT "!MESSAGE use the Export Makefile command and run\r\n";
547 print OUT "!MESSAGE \r\n";
548 print OUT "!MESSAGE NMAKE /f \"$project.mak\".\r\n";
549 print OUT "!MESSAGE \r\n";
550 print OUT "!MESSAGE You can specify a configuration when running NMAKE\r\n";
551 print OUT "!MESSAGE by defining the macro CFG on the command line. For example:\r\n";
552 print OUT "!MESSAGE \r\n";
553 print OUT "!MESSAGE NMAKE /f \"$project.mak\" CFG=\"$default_cfg\"\r\n";
554 print OUT "!MESSAGE \r\n";
555 print OUT "!MESSAGE Possible choices for configuration are:\r\n";
556 print OUT "!MESSAGE \r\n";
557 foreach my $cfg (@cfgs) {
558 if ($lib) {
559 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Static Library\")\r\n";
560 } elsif ($dll) {
561 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n";
562 } else {
563 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Console Application\")\r\n";
566 print OUT "!MESSAGE \r\n";
567 print OUT "\r\n";
569 print OUT "# Begin Project\r\n";
570 print OUT "# PROP AllowPerConfigDependencies 0\r\n";
571 print OUT "# PROP Scc_ProjName \"\"\r\n";
572 print OUT "# PROP Scc_LocalPath \"\"\r\n";
573 print OUT "CPP=cl.exe\r\n";
574 print OUT "MTL=midl.exe\r\n" if !$lib && !$exe;
575 print OUT "RSC=rc.exe\r\n";
576 print OUT "\r\n";
578 my $n = 0;
580 my $output_dir;
581 foreach my $cfg (@cfgs) {
582 if($#cfgs == 0) {
583 # Nothing
584 } elsif($n == 0) {
585 print OUT "!IF \"\$(CFG)\" == \"$cfg\"\r\n";
586 print OUT "\r\n";
587 } else {
588 print OUT "\r\n";
589 print OUT "!ELSEIF \"\$(CFG)\" == \"$cfg\"\r\n";
590 print OUT "\r\n";
593 my $debug = ($cfg !~ /Release/);
594 my $msvc_headers = ($cfg =~ /MSVC Headers/);
596 print OUT "# PROP BASE Use_MFC 0\r\n";
598 if($debug) {
599 print OUT "# PROP BASE Use_Debug_Libraries 1\r\n";
600 } else {
601 print OUT "# PROP BASE Use_Debug_Libraries 0\r\n";
604 $output_dir = $cfg;
605 $output_dir =~ s/^$project - //;
606 $output_dir =~ s/ /_/g;
607 $output_dir =~ s/C\+\+/Cxx/g;
608 if($output_prefix_dir) {
609 $output_dir = "$output_prefix_dir\\$output_dir";
612 print OUT "# PROP BASE Output_Dir \"$output_dir\"\r\n";
613 print OUT "# PROP BASE Intermediate_Dir \"$output_dir\"\r\n";
615 print OUT "# PROP BASE Target_Dir \"\"\r\n";
617 print OUT "# PROP Use_MFC 0\r\n";
618 if($debug) {
619 print OUT "# PROP Use_Debug_Libraries 1\r\n";
620 } else {
621 print OUT "# PROP Use_Debug_Libraries 0\r\n";
623 print OUT "# PROP Output_Dir \"$output_dir\"\r\n";
624 print OUT "# PROP Intermediate_Dir \"$output_dir\"\r\n";
626 print OUT "# PROP Ignore_Export_Lib 0\r\n" if $dll;
627 print OUT "# PROP Target_Dir \"\"\r\n";
629 print OUT "# ADD BASE CPP /nologo ";
630 my @defines = qw(WINVER=0x0600 _WIN32_WINNT=0x0600 _WIN32_IE=0x0700 WIN32);
631 if($debug) {
632 if($lib || $exe) {
633 push @defines, qw(_DEBUG _MBCS _LIB);
634 } else {
635 print OUT "/MDd ";
636 push @defines, qw(_DEBUG _WINDOWS _MBCS _USRDLL);
638 print OUT "/W3 /Gm /GX /Zi /Od";
639 } else {
640 if($lib || $exe) {
641 push @defines, qw(NDEBUG _MBCS _LIB);
642 } else {
643 print OUT "/MD ";
644 push @defines, qw(NDEBUG _WINDOWS _MBCS _USRDLL);
646 print OUT "/W3 /GX /O2";
649 foreach my $define (@defines) {
650 if ($define !~ /=/) {
651 print OUT " /D \"$define\"";
652 } else {
653 print OUT " /D $define";
656 print OUT " /YX" if $lib || $exe;
657 print OUT " /FD";
658 print OUT " /GZ" if $debug;
659 print OUT " /c";
660 print OUT "\r\n";
662 my @defines2 = qw(_CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE
663 USE_COMPILER_EXCEPTIONS _USE_MATH_DEFINES
664 WINVER=0x0600 _WIN32_WINNT=0x0600 _WIN32_IE=0x0700);
665 if($debug) {
666 if($lib) {
667 print OUT "# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od";
668 push @defines2, qw(WIN32 _DEBUG _WINDOWS _MBCS _LIB);
669 } else {
670 print OUT "# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od";
671 push @defines2, qw(_DEBUG WIN32 _WINDOWS _MBCS _USRDLL);
673 } else {
674 if($lib) {
675 print OUT "# ADD CPP /nologo /MD /W3 /GX /O2";
676 push @defines2, qw(WIN32 NDEBUG _WINDOWS _MBCS _LIB);
677 } else {
678 print OUT "# ADD CPP /nologo /MD /W3 /GX /O2";
679 push @defines2, qw(NDEBUG WIN32 _WINDOWS _MBCS _USRDLL);
683 my @includes = ();
684 if($wine) {
685 push @defines2, qw(__WINESRC__) if $project !~ /^(?:wine(?:build|test)|.*?_test)$/;
686 if ($msvc_headers) {
687 push @defines2, qw(__WINE_USE_NATIVE_HEADERS);
689 my $output_dir2 = $output_dir;
690 $output_dir2 =~ s/\\/\\\\/g;
691 push @defines2, "__WINETEST_OUTPUT_DIR=\\\"$output_dir2\\\"";
692 push @defines2, qw(__i386__ _X86_);
694 if ($project eq "wine") {
695 push @defines2, "WINE_UNICODE_API=";
698 if ($project =~ /_test$/) {
699 push @includes, "$msvc_wine_dir\\$output_dir";
702 if (!$msvc_headers || $project eq "winetest") {
703 push @includes, $wine_include_dir;
707 if($wine) {
708 foreach my $include (@includes) {
709 print OUT " /I \"$include\"";
713 foreach my $define (@defines2) {
714 if ($define !~ /=/) {
715 print OUT " /D \"$define\"";
716 } else {
717 print OUT " /D $define";
720 print OUT " /D inline=__inline" if $wine;
721 print OUT " /D \"__STDC__\"" if 0 && $wine;
723 if(exists($modules{$module}{extradefs})) {
724 print OUT " @{$modules{$module}{extradefs}} ";
727 print OUT " /YX" if $lib;
728 print OUT " /FR" if !$lib;
729 print OUT " /FD";
730 print OUT " /GZ" if $debug;
731 print OUT " /c";
732 print OUT " /TP" if !$no_cpp;
733 print OUT "\r\n";
735 if($debug) {
736 print OUT "# SUBTRACT CPP /X /YX\r\n" if $dll;
737 print OUT "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
738 print OUT "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
739 print OUT "# ADD BASE RSC /l 0x41d /d \"_DEBUG\"\r\n";
740 print OUT "# ADD RSC /l 0x41d";
741 if($wine) {
742 foreach my $include (@includes) {
743 print OUT " /i \"$include\"";
746 print OUT " /d \"_DEBUG\"\r\n";
747 } else {
748 print OUT "# SUBTRACT CPP /YX\r\n" if $dll;
749 print OUT "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
750 print OUT "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
751 print OUT "# ADD BASE RSC /l 0x41d /d \"NDEBUG\"\r\n";
752 print OUT "# ADD RSC /l 0x41d";
753 if($wine) {
754 foreach my $include (@includes) {
755 print OUT " /i \"$include\"";
758 print OUT "/d \"NDEBUG\"\r\n";
760 print OUT "BSC32=bscmake.exe\r\n";
761 print OUT "# ADD BASE BSC32 /nologo\r\n";
762 print OUT "# ADD BSC32 /nologo\r\n";
764 if($exe || $dll) {
765 print OUT "LINK32=link.exe\r\n";
766 print OUT "# ADD BASE LINK32";
767 my @libraries = qw(kernel32.lib user32.lib gdi32.lib winspool.lib
768 comdlg32.lib advapi32.lib shell32.lib ole32.lib
769 oleaut32.lib uuid.lib odbc32.lib odbccp32.lib);
770 foreach my $library (@libraries) {
771 print OUT " $library";
773 print OUT " /nologo";
774 print OUT " /dll" if $dll;
775 print OUT " /subsystem:console" if $console;
776 print OUT " /debug" if $debug;
777 print OUT " /machine:I386";
778 print OUT " /pdbtype:sept" if $debug;
779 print OUT "\r\n";
781 print OUT "# ADD LINK32";
782 print OUT " libcmt.lib" if $project =~ /^ntdll$/; # FIXME: Kludge
783 foreach my $import (@imports) {
784 print OUT " $import.lib" if ($import ne "msvcrt");
786 print OUT " /nologo";
787 print OUT " /dll" if $dll;
788 print OUT " /subsystem:console" if $console;
789 print OUT " /debug" if $debug;
790 print OUT " /machine:I386";
791 print OUT " /nodefaultlib" if $project =~ /^ntdll$/; # FIXME: Kludge
792 print OUT " /def:\"$project.def\"" if $dll;
793 print OUT " /pdbtype:sept" if $debug;
794 print OUT "\r\n";
795 } else {
796 print OUT "LIB32=link.exe -lib\r\n";
797 print OUT "# ADD BASE LIB32 /nologo\r\n";
798 print OUT "# ADD LIB32 /nologo\r\n";
801 $n++;
804 if($#cfgs != 0) {
805 print OUT "\r\n";
806 print OUT "!ENDIF \r\n";
807 print OUT "\r\n";
810 print OUT "# Begin Target\r\n";
811 print OUT "\r\n";
812 foreach my $cfg (@cfgs) {
813 print OUT "# Name \"$cfg\"\r\n";
816 print OUT "# Begin Group \"Source Files\"\r\n";
817 print OUT "\r\n";
818 print OUT "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
820 if ($project eq "winebuild") {
821 for my $ source_file ("getopt.c", "getopt1.c", "mkstemps.c")
823 print OUT "# Begin Source File\r\n";
824 print OUT "\r\n";
825 print OUT "SOURCE=..\\..\\libs\\port\\$source_file\r\n";
826 print OUT "# End Source File\r\n";
830 foreach my $source_file (@source_files) {
831 $source_file =~ s%/%\\%g;
832 if($source_file !~ /^\./) {
833 $source_file = ".\\$source_file";
836 print OUT "# Begin Source File\r\n";
837 print OUT "\r\n";
839 print OUT "SOURCE=$source_file\r\n";
841 if ($project eq "wine" && $source_file eq ".\\config.c") {
842 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";
845 if($source_file =~ /^(.*?)\.spec$/) {
846 my $basename = $1;
848 my $spec_file = $source_file;
849 my $def_file = "$basename.def";
851 my $srcdir = "."; # FIXME: Is this really always correct?
853 print OUT "# Begin Custom Build\r\n";
854 print OUT "InputPath=$spec_file\r\n";
855 print OUT "\r\n";
856 print OUT "BuildCmds= \\\r\n";
857 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe -w --def -k -o $def_file --export $spec_file\r\n";
858 print OUT "\r\n";
859 print OUT "\"$def_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
860 print OUT " \$(BuildCmds)\r\n";
861 print OUT "# End Custom Build\r\n";
862 } elsif($source_file =~ /([^\\]*?\.h)$/) {
863 my $h_file = $1;
865 foreach my $cfg (@cfgs) {
866 if($#cfgs == 0) {
867 # Nothing
868 } elsif($n == 0) {
869 print OUT "!IF \"\$(CFG)\" == \"$cfg\"\r\n";
870 print OUT "\r\n";
871 } else {
872 print OUT "\r\n";
873 print OUT "!ELSEIF \"\$(CFG)\" == \"$cfg\"\r\n";
874 print OUT "\r\n";
877 $output_dir = $cfg;
878 $output_dir =~ s/^$project - //;
879 $output_dir =~ s/ /_/g;
880 $output_dir =~ s/C\+\+/Cxx/g;
881 if($output_prefix_dir) {
882 $output_dir = "$output_prefix_dir\\$output_dir";
885 print OUT "# Begin Custom Build\r\n";
886 print OUT "OutDir=$output_dir\r\n";
887 print OUT "InputPath=$source_file\r\n";
888 print OUT "\r\n";
889 print OUT "\"\$(OutDir)\\wine\\$h_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
890 print OUT "\tcopy \"\$(InputPath)\" \"\$(OutDir)\\wine\"\r\n";
891 print OUT "\r\n";
892 print OUT "# End Custom Build\r\n";
895 if($#cfgs != 0) {
896 print OUT "\r\n";
897 print OUT "!ENDIF \r\n";
898 print OUT "\r\n";
902 print OUT "# End Source File\r\n";
905 foreach my $idl_h_file (@idl_h_files) {
906 $idl_h_file =~ s%/%\\%g;
907 if($idl_h_file !~ /^\./) {
908 $idl_h_file = ".\\$idl_h_file";
911 print OUT "# Begin Source File\r\n";
912 print OUT "\r\n";
914 print OUT "SOURCE=$idl_h_file\r\n";
916 my $basename = $idl_h_file;
917 $basename =~ s/\.idl$//;
919 print OUT "# PROP Ignore_Default_Tool 1\r\n";
920 print OUT "# Begin Custom Build\r\n";
921 print OUT "InputPath=$idl_h_file\r\n";
922 print OUT "\r\n";
923 print OUT "BuildCmds= \\\r\n";
924 print OUT "\tmidl /nologo /I $wine_include_dir /client none /server none /notlb $idl_h_file /h $basename.h\r\n";
925 print OUT "\r\n";
926 print OUT "\"$basename.h\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
927 print OUT " \$(BuildCmds)\r\n";
928 print OUT "# End Custom Build\r\n";
930 print OUT "# End Source File\r\n";
933 print OUT "# End Group\r\n";
935 print OUT "# Begin Group \"Header Files\"\r\n";
936 print OUT "\r\n";
937 print OUT "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
938 foreach my $header_file (@header_files) {
939 print OUT "# Begin Source File\r\n";
940 print OUT "\r\n";
941 print OUT "SOURCE=.\\$header_file\r\n";
942 print OUT "# End Source File\r\n";
944 print OUT "# End Group\r\n";
948 print OUT "# Begin Group \"Resource Files\"\r\n";
949 print OUT "\r\n";
950 print OUT "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
951 foreach my $resource_file (@resource_files) {
952 print OUT "# Begin Source File\r\n";
953 print OUT "\r\n";
954 print OUT "SOURCE=.\\$resource_file\r\n";
955 print OUT "# End Source File\r\n";
957 print OUT "# End Group\r\n";
959 print OUT "# End Target\r\n";
960 print OUT "# End Project\r\n";
962 close(OUT);
965 sub _generate_dsw_header($) {
966 local *OUT = shift;
968 print OUT "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n";
969 print OUT "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n";
970 print OUT "\r\n";
973 sub _generate_dsw_project($$$$) {
974 local *OUT = shift;
976 my $project = shift;
977 my $dsp_file = shift;
978 my @dependencies = @{(shift)};
980 $dsp_file = "./$dsp_file";
981 $dsp_file =~ y%/%\\%;
983 @dependencies = sort(@dependencies);
985 print OUT "###############################################################################\r\n";
986 print OUT "\r\n";
987 print OUT "Project: \"$project\"=$dsp_file - Package Owner=<4>\r\n";
988 print OUT "\r\n";
989 print OUT "Package=<5>\r\n";
990 print OUT "{{{\r\n";
991 print OUT "}}}\r\n";
992 print OUT "\r\n";
993 print OUT "Package=<4>\r\n";
994 print OUT "{{{\r\n";
995 foreach my $dependency (@dependencies) {
996 print OUT " Begin Project Dependency\r\n";
997 print OUT " Project_Dep_Name $dependency\r\n";
998 print OUT " End Project Dependency\r\n";
1000 print OUT "}}}\r\n";
1001 print OUT "\r\n";
1004 sub _generate_dsw_footer($) {
1005 local *OUT = shift;
1007 print OUT "###############################################################################\r\n";
1008 print OUT "\r\n";
1009 print OUT "Global:\r\n";
1010 print OUT "\r\n";
1011 print OUT "Package=<5>\r\n";
1012 print OUT "{{{\r\n";
1013 print OUT "}}}\r\n";
1014 print OUT "\r\n";
1015 print OUT "Package=<3>\r\n";
1016 print OUT "{{{\r\n";
1017 print OUT "}}}\r\n";
1018 print OUT "\r\n";
1019 print OUT "###############################################################################\r\n";
1020 print OUT "\r\n";
1023 if ($options->wine) {
1024 my $dsw_file = "wine.dsw";
1025 $output->progress("$dsw_file");
1026 replace_file("$wine_dir/$dsw_file", \&_generate_wine_dsw);
1029 sub _generate_wine_dsw($) {
1030 local *OUT = shift;
1032 _generate_dsw_header(\*OUT);
1033 foreach my $module (sort(keys(%modules))) {
1034 next if $module =~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1036 my $project = $modules{$module}{project};
1037 my $dsp_file = $modules{$module}{dsp_file};
1039 my @dependencies;
1040 if($project eq "wine") {
1041 @dependencies = ();
1042 } elsif($project eq "winebuild") {
1043 @dependencies = ("wine");
1044 } elsif($project =~ /^(?:gdi32)_.+?$/) {
1045 @dependencies = ();
1046 } else {
1047 @dependencies = ("wine", "include", "winebuild");
1050 if($project =~ /^gdi32$/) {
1051 foreach my $dir (@gdi32_dirs) {
1052 my $dir2 = $dir;
1053 $dir2 =~ s%^.*?/([^/]+)$%$1%;
1055 my $module = "gdi32_$dir2";
1056 $module =~ s%/%_%g;
1057 push @dependencies, $module;
1061 _generate_dsw_project(\*OUT, $project, $dsp_file, \@dependencies);
1063 _generate_dsw_footer(\*OUT);
1065 return 1;
1068 if ($options->winetest) {
1069 my $dsw_file = "winetest.dsw";
1070 $output->progress("$dsw_file");
1071 replace_file("$wine_dir/$dsw_file", \&_generate_winetest_dsw);
1074 sub _generate_winetest_dsw($) {
1075 local *OUT = shift;
1077 _generate_dsw_header(\*OUT);
1079 my @runtests_dependencies = ();
1080 foreach my $module (sort(keys(%modules))) {
1081 next if $module !~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1082 next if $module eq "wineruntests";
1084 my $project = $modules{$module}{project};
1086 push @runtests_dependencies, $project;
1089 foreach my $module (sort(keys(%modules))) {
1090 next if $module !~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1092 my $project = $modules{$module}{project};
1093 my $dsp_file = $modules{$module}{dsp_file};
1095 my @dependencies;
1096 if($project =~ /^winetest$/) {
1097 @dependencies = ();
1098 } elsif($project =~ /^wineruntests$/) {
1099 @dependencies = @runtests_dependencies;
1100 } else {
1101 @dependencies = ("winetest");
1104 _generate_dsw_project(\*OUT, $project, $dsp_file, \@dependencies);
1107 _generate_dsw_footer(\*OUT);
1110 if ($options->winetest) {
1111 foreach my $module (sort(keys(%modules))) {
1112 next if $module !~ /_test\.exe$/;
1114 my $project = $modules{$module}{project};
1115 my $dsp_file = $modules{$module}{dsp_file};
1116 my @tests = @{$modules{$module}{tests}};
1118 my $testlist_c = $dsp_file;
1119 $testlist_c =~ s%[^/]*\.dsp$%testlist.c%;
1121 replace_file("$wine_dir/$testlist_c", \&_generate_testlist_c, \@tests);
1125 # ***** Keep in sync with tools/make_ctests *****
1126 sub _generate_testlist_c($$) {
1127 local *OUT = shift;
1129 my @tests = @{(shift)};
1131 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n";
1132 print OUT "\n";
1133 print OUT "/* stdarg.h is needed for Winelib */\n";
1134 print OUT "#include <stdarg.h>\n";
1135 print OUT "#include <stdio.h>\n";
1136 print OUT "#include <stdlib.h>\n";
1137 print OUT "#include \"windef.h\"\n";
1138 print OUT "#include \"winbase.h\"\n";
1139 print OUT "\n";
1140 print OUT "#define STANDALONE\n";
1141 print OUT "#include \"wine/test.h\"\n";
1142 print OUT "\n";
1143 foreach my $test (@tests) {
1144 print OUT "extern void func_$test(void);\n";
1146 print OUT "\n";
1147 print OUT "const struct test winetest_testlist[] =\n";
1148 print OUT "{\n";
1149 foreach my $test (@tests) {
1150 print OUT " { \"$test\", func_$test },\n";
1152 print OUT " { 0, 0 }\n";
1153 print OUT "};\n";
1156 if ($options->winetest) {
1157 replace_file("$wine_dir/runtests.c", \&_generate_runtests_c);
1160 sub _generate_runtests_c($) {
1161 local *OUT = shift;
1163 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n";
1165 print OUT "\n";
1166 print OUT "#include <stdio.h>\n";
1167 print OUT "#include <stdlib.h>\n";
1168 print OUT "\n";
1170 print OUT "int main(int argc, char *argv[])\n";
1171 print OUT "{\n";
1172 print OUT " char output_dir[] = __WINETEST_OUTPUT_DIR;\n";
1173 print OUT " char command[4096];\n";
1174 print OUT "\n";
1175 foreach my $dsp_file (keys(%runtests)) {
1176 my @tests = @{$runtests{$dsp_file}};
1178 my $project = $dsp_file;
1179 $project =~ s%^(.*?)/?([^/]+)\.dsp$%$2%;
1180 my $dir = $1;
1181 $dir =~ s%/%\\\\%g;
1183 foreach my $test (@tests) {
1184 print OUT " sprintf(command, \"$dir\\\\%s\\\\$project.exe $test\", output_dir);\n";
1185 print OUT " system(command);\n";
1186 print OUT "\n";
1189 print OUT " return 0;\n";
1190 print OUT "}\n";
1193 if ($options->winetest) {
1194 replace_file("$wine_dir/winetest.c", \&_generate_winetest_c);
1197 sub _generate_winetest_c($) {
1198 local *OUT = shift;
1200 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n\n";
1202 print OUT "/* Force the linker to generate a .lib file */\n";
1203 print OUT "void __wine_dummy_lib_function(void)\n{\n}\n\n";
1206 if ($options->wine) {
1207 my $config_h = "include/config.h";
1209 $output->progress("$config_h");
1211 replace_file("$wine_dir/$config_h", \&_generate_config_h);
1214 sub _generate_config_h($) {
1215 local *OUT = shift;
1216 my @defines;
1218 print OUT "#define __WINE_CONFIG_H\n";
1219 print OUT "\n";
1221 my @headers = qw(direct.h float.h memory.h io.h stdlib.h string.h process.h sys/stat.h sys/types.h);
1222 foreach my $header (@headers) {
1223 $header =~ y/\.\//__/;
1224 push @defines, "HAVE_\U$header\E 1";
1227 my @functions = qw(
1228 _pclose _popen _snprintf _spawnvp _stricmp _strnicmp _strdup
1229 _strtoi64 _strtoui64 _vsnprintf
1230 chsize memmove strdup spawnvp strerror vsnprintf
1232 foreach my $function (@functions) {
1233 push @defines, "HAVE_\U$function\E 1";
1236 my @types = qw(
1237 long_long off_t size_t
1239 foreach my $type (@types) {
1240 push @defines, "HAVE_\U$type\E 1";
1243 foreach my $define (sort(@defines)) {
1244 print OUT "#define $define\n";
1245 print OUT "\n";
1248 print OUT "/* Define to the address where bug reports for this package should be sent. */\n";
1249 print OUT "#define PACKAGE_BUGREPORT \"\"\n";
1250 print OUT "\n";
1252 print OUT "/* Define to the full name of this package. */\n";
1253 print OUT "#define PACKAGE_NAME \"Wine\"\n";
1254 print OUT "\n";
1256 print OUT "/* Define to the full name and version of this package. */\n";
1257 print OUT "#define PACKAGE_STRING \"Wine YYYYMMDD\"\n";
1258 print OUT "\n";
1260 print OUT "/* Define to the one symbol short name of this package. */\n";
1261 print OUT "#define PACKAGE_TARNAME \"wine\"\n";
1262 print OUT "\n";
1264 print OUT "/* Define to the version of this package. */\n";
1265 print OUT "#define PACKAGE_VERSION \"YYYYMMDD\"\n";
1266 print OUT "\n";
1268 print OUT "#define X_DISPLAY_MISSING 1\n";
1269 print OUT "\n";
1271 print OUT "/* Define to a macro to generate an assembly function directive */\n";
1272 print OUT "#define __ASM_FUNC(name) \"\"\n";
1273 print OUT "\n";
1275 print OUT "/* Define to a macro to generate an assembly name from a C symbol */\n";
1276 print OUT "#define __ASM_NAME(name) name\n";
1277 print OUT "\n";
1279 close(OUT);