Define "WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600" for all
[wine/multimedia.git] / tools / winapi / msvcmaker
blob8e77194c1271cf532008296fe4840b9ac4652f5b
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 sub read_spec_file($) {
40 my $spec_file = shift;
42 my $module = $spec_file;
43 $module =~ s%^.*?([^/]+)\.spec$%$1%;
44 $module .= ".dll" if $module !~ /\./;
46 my $type = "win32";
48 open(IN, "< $wine_dir/$spec_file");
50 my $header = 1;
51 my $lookahead = 0;
52 while($lookahead || defined($_ = <IN>)) {
53 $lookahead = 0;
55 s/^\s*?(.*?)\s*$/$1/; # remove whitespace at begining and end of line
56 s/^(.*?)\s*#.*$/$1/; # remove comments
57 /^$/ && next; # skip empty lines
59 if($header) {
60 if(/^(?:\d+|@)/) {
61 $header = 0;
62 $lookahead = 1;
64 next;
67 if(/^(\d+|@)\s+pascal(?:16)?/) {
68 $type = "win16";
69 last;
72 close(IN);
74 # FIXME: Kludge
75 if($module =~ /^(?:(?:imm|ole2conv|ole2prox|ole2thk|rasapi16|windebug)\.dll|comm\.drv)$/) {
76 $type = "win16";
79 if($type eq "win32") {
80 $modules{$module}{module} = $module;
81 $modules{$module}{type} = $type;
82 $modules{$module}{spec_file} = $spec_file;
86 if ($options->wine || $options->winetest) {
87 foreach my $spec_file (@spec_files) {
88 read_spec_file($spec_file);
92 my @gdi32_dirs = qw(dlls/gdi/enhmfdrv dlls/gdi/mfdrv);
93 my @ntdll_dirs = qw(misc);
94 my @user32_dirs = qw(dlls/user/dde windows);
96 push @makefile_in_files, "tools/winebuild/Makefile.in";
98 sub filter_files($$) {
99 my $files = shift;
100 my $filter = shift;
102 my $filtered_files = [];
103 my $rest_of_files = [];
104 foreach my $file (@$files) {
105 if($file =~ /$filter/) {
106 $file =~ s%.*?([^/]+)$%./$1%; # FIXME: Kludge
107 push @$filtered_files, $file;
108 } else {
109 push @$rest_of_files, $file;
112 return ($rest_of_files, $filtered_files);
115 my %wine_test_dsp_files;
117 MAKEFILE_IN: foreach my $makefile_in_file (@makefile_in_files) {
118 open(IN, "< $wine_dir/$makefile_in_file");
120 my $topobjdir;
121 my $module;
122 my $testdll;
123 my @imports;
125 my %vars;
127 my $again = 0;
128 my $lookahead = 0;
129 while($again || defined(my $line = <IN>)) {
130 if(!$again) {
131 chomp $line;
132 if($lookahead) {
133 $lookahead = 0;
134 $_ .= "\n" . $line;
135 } else {
136 $_ = $line;
138 } else {
139 $again = 0;
142 s/^\s*?(.*?)\s*$/$1/; # remove whitespace at begining and end of line
143 s/^(.*?)\s*#.*$/$1/; # remove comments
144 /^$/ && next; # skip empty lines
146 if(s/\\$/ /s) {
147 $lookahead = 1;
148 next;
151 if(/^MODULE\s*=\s*([\w\.]+)$/) {
152 $module = $1;
154 if($module eq "none") {
155 if($makefile_in_file eq "library/Makefile.in") {
156 $module = "wine.dll";
157 } elsif($makefile_in_file eq "unicode/Makefile.in") {
158 $module = "wine_unicode.dll";
159 } elsif($makefile_in_file eq "tools/winebuild/Makefile.in") {
160 $module = "winebuild.exe";
161 } else {
162 next MAKEFILE_IN;
165 } elsif(/^TOPOBJDIR\s*=\s*(\S+)\s*$/) {
166 $topobjdir = $1;
167 } elsif (/^TESTDLL\s*=\s*(\S+)\s*$/) {
168 $testdll = $1;
169 } elsif (/^IMPORTS\s*=\s*/) {
170 push @imports, grep !/^ntdll$/, split /\s+/s, $';
171 } elsif (/^EXTRALIBS\s*=\s*/) {
172 push @imports, map { /^-l(dxerr8|dxerr9|dxguid|strmiids|uuid)$/ ? $1 : () } split /\s+/s, $';
173 } elsif (/^CTESTS\s*=\s*/) {
174 my @files = split /\s+/s, $';
176 my $dir = $makefile_in_file;
177 $dir =~ s/\/Makefile\.in$//;
179 my $dsp_file = $testdll;
180 $dsp_file =~ s/\.(dll|drv)$/_test.dsp/;
181 $dsp_file = "$dir/$dsp_file";
183 $wine_test_dsp_files{$dsp_file}{files} = [@files, "testlist.c"];
184 $wine_test_dsp_files{$dsp_file}{imports} = [@imports];
185 } elsif(/^(\w+)\s*=\s*/) {
186 my $var = $1;
187 my @files = split /\s+/s, $';
189 @files = map {
190 if(/^\$\((\w+):\%=(.*?)\%(.*?)\)$/) {
191 my @list = @{$vars{$1}};
192 my $prefix = $2;
193 my $suffix = $3;
194 foreach my $item (@list) {
195 $item = "$prefix$item$suffix";
197 @list;
198 } elsif(/^\$\(TOPOBJDIR\)(.*?)$/) {
199 "$topobjdir$1";
200 } elsif(/^\$/) {
201 print STDERR "unknown variable '$_'\n" if 0;
203 } else {
206 } @files;
208 $vars{$var} = \@files;
212 close(IN);
214 next if !$module;
216 my $c_srcs = [];
217 my $source_files = [];
218 if(exists($vars{C_SRCS})) {
219 $c_srcs = [sort(@{$vars{C_SRCS}})];
220 $source_files = [sort(@{$vars{C_SRCS}})];
223 my $header_files = [];
224 if(exists($vars{H_SRCS})) {
225 $header_files = [sort(@{$vars{H_SRCS}})];
228 my $resource_files = [];
229 if(exists($vars{RC_SRCS})) {
230 $resource_files = [sort(@{$vars{RC_SRCS}})];
233 my $project = $module;
234 $project =~ s/\.(?:dll|exe|lib)$//;
235 $project =~ y/./_/;
237 my $type;
238 if($module =~ /\.exe$/) {
239 $type = "exe";
240 } elsif($module =~ /\.lib$/) {
241 $type = "lib";
242 } else {
243 $type = "dll";
246 my $dsp_file = $makefile_in_file;
247 $dsp_file =~ s/Makefile.in$/$project.dsp/;
249 if($module eq "gdi32.dll") {
250 foreach my $dir (@gdi32_dirs) {
251 my $dir2 = $dir;
252 $dir2 =~ s%^.*?/([^/]+)$%$1%;
254 my $module = "gdi32_$dir2.lib";
255 $module =~ s%/%_%g;
257 my $project = "gdi32_$dir2";
258 $project =~ s%/%_%g;
260 my $type = "lib";
261 my $dsp_file = "$dir/$project.dsp";
263 ($source_files, my $local_source_files) = filter_files($source_files, "$dir2/");
264 ($header_files, my $local_header_files) = filter_files($header_files, "$dir2/");
265 ($resource_files, my $local_resource_files) = filter_files($resource_files, "$dir2/");
267 $modules{$module}{wine} = 1;
268 $modules{$module}{winetest} = 0;
269 $modules{$module}{project} = $project;
270 $modules{$module}{type} = $type;
271 $modules{$module}{dsp_file} = $dsp_file;
272 $modules{$module}{c_srcs} = $c_srcs;
273 $modules{$module}{source_files} = $local_source_files;
274 $modules{$module}{header_files} = $local_header_files;
275 $modules{$module}{resource_files} = $local_resource_files;
276 $modules{$module}{imports} = [];
278 } elsif($module eq "ntdll.dll") {
279 foreach my $dir (@ntdll_dirs) {
280 my $module = "ntdll_$dir.lib";
281 $module =~ s%/%_%g;
283 my $project = "ntdll_$dir";
284 $project =~ s%/%_%g;
286 my $type = "lib";
287 my $dsp_file = "$dir/$project.dsp";
289 ($source_files, my $local_source_files) = filter_files($source_files, "/$dir/");
290 ($header_files, my $local_header_files) = filter_files($header_files, "/$dir/");
291 ($resource_files, my $local_resource_files) = filter_files($resource_files, "/$dir/");
293 $modules{$module}{wine} = 1;
294 $modules{$module}{winetest} = 0;
295 $modules{$module}{project} = $project;
296 $modules{$module}{type} = $type;
297 $modules{$module}{dsp_file} = $dsp_file;
298 $modules{$module}{c_srcs} = $c_srcs;
299 $modules{$module}{source_files} = $local_source_files;
300 $modules{$module}{header_files} = $local_header_files;
301 $modules{$module}{resource_files} = $local_resource_files;
302 $modules{$module}{imports} = [];
304 } elsif($module eq "user32.dll") {
305 foreach my $dir (@user32_dirs) {
306 my $dir2 = $dir;
307 $dir2 =~ s%^.*?/([^/]+)$%$1%;
309 my $module = "user32_$dir2.lib";
310 $module =~ s%/%_%g;
312 my $project = "user32_$dir2";
313 $project =~ s%/%_%g;
315 my $type = "lib";
316 my $dsp_file = "$dir/$project.dsp";
318 ($source_files, my $local_source_files) = filter_files($source_files, "$dir2/");
319 ($header_files, my $local_header_files) = filter_files($header_files, "$dir2/");
320 ($resource_files, my $local_resource_files) = filter_files($resource_files, "$dir2/");
322 $modules{$module}{wine} = 1;
323 $modules{$module}{winetest} = 0;
324 $modules{$module}{project} = $project;
325 $modules{$module}{type} = $type;
326 $modules{$module}{dsp_file} = $dsp_file;
327 $modules{$module}{c_srcs} = $c_srcs;
328 $modules{$module}{source_files} = $local_source_files;
329 $modules{$module}{header_files} = $local_header_files;
330 $modules{$module}{resource_files} = $local_resource_files;
331 $modules{$module}{imports} = [];
335 $modules{$module}{wine} = 1;
336 $modules{$module}{winetest} = 0;
337 $modules{$module}{project} = $project;
338 $modules{$module}{type} = $type;
339 $modules{$module}{dsp_file} = $dsp_file;
340 $modules{$module}{c_srcs} = $c_srcs;
341 $modules{$module}{source_files} = $source_files;
342 $modules{$module}{header_files} = $header_files;
343 $modules{$module}{resource_files} = $resource_files;
344 $modules{$module}{imports} = [];
347 $wine_test_dsp_files{"wineruntests.dsp"}{files} = ["runtests.c"];
348 $wine_test_dsp_files{"wineruntests.dsp"}{imports} = [];
350 $wine_test_dsp_files{"winetest.dsp"}{files} = [
351 'include/wine/exception.h',
352 'include/wine/test.h',
353 'include/wine/unicode.h',
354 'winetest.c'
356 $wine_test_dsp_files{"winetest.dsp"}{imports} = [];
358 my %runtests = ();
360 foreach my $dsp_file (keys(%wine_test_dsp_files)) {
361 my $project = $dsp_file;
362 $project =~ s%^(?:.*?/)?([^/]+)\.dsp$%$1%;
364 my @files = @{$wine_test_dsp_files{$dsp_file}{files}};
365 my @imports = @{$wine_test_dsp_files{$dsp_file}{imports}};
367 my $type;
368 my $c_srcs = [];
369 my $source_files = [];
370 my $header_files = [];
371 my $resource_files = [];
373 my @tests = ();
375 if ($project eq "winetest") {
376 $type = "lib";
377 $c_srcs = [@files];
378 $source_files = [@files];
379 $header_files = [];
380 $resource_files = [];
381 } elsif ($project eq "wineruntests") {
382 $type = "exe";
383 $c_srcs = [@files];
384 $source_files = [@files];
385 $header_files = [];
386 $resource_files = [];
387 } else {
388 $type = "exe";
389 $c_srcs = [@files];
390 $source_files = [@files];
391 $header_files = [];
392 $resource_files = [];
394 @tests = map {
395 if (/^testlist\.c$/) {
397 } else {
398 s/\.c$//;
401 } @files;
403 $runtests{$dsp_file} = [@tests];
405 my $module = "$project.$type";
407 $modules{$module}{wine} = 0;
408 $modules{$module}{winetest} = 1;
410 $modules{$module}{project} = $project;
411 $modules{$module}{type} = $type;
412 $modules{$module}{dsp_file} = $dsp_file;
413 $modules{$module}{c_srcs} = $c_srcs;
414 $modules{$module}{source_files} = $source_files;
415 $modules{$module}{header_files} = $header_files;
416 $modules{$module}{resource_files} = $resource_files;
417 $modules{$module}{imports} = [@imports];
419 $modules{$module}{tests} = [@tests];
422 foreach my $module (sort(keys(%modules))) {
423 if($module =~ /^(?:ttydrv.dll|x11drv.dll)$/) {
424 delete $modules{$module};
428 my @modules = ();
429 foreach my $module (sort(keys(%modules))) {
430 if (($options->wine && $modules{$module}{wine}) ||
431 ($options->winetest && $modules{$module}{winetest}))
433 push @modules, $module;
437 my $progress_output;
438 my $progress_current = 0;
439 my $progress_max = scalar(@modules);
441 foreach my $module (@modules) {
442 my $dsp_file = $modules{$module}{dsp_file};
443 replace_file("$wine_dir/$dsp_file", \&_generate_dsp, $module);
446 sub _generate_dsp($$) {
447 local *OUT = shift;
449 my $module = shift;
451 my $dsp_file = $modules{$module}{dsp_file};
452 my $project = $modules{$module}{project};
453 my @imports = @{$modules{$module}{imports}};
455 my $lib = ($modules{$module}{type} eq "lib");
456 my $dll = ($modules{$module}{type} eq "dll");
457 my $exe = ($modules{$module}{type} eq "exe");
459 my $console = $exe; # FIXME: Not always correct
461 my $msvc_wine_dir = do {
462 my @parts = split(m%/%, $dsp_file);
463 if($#parts == 1) {
464 "..";
465 } elsif($#parts == 2) {
466 "..\\..";
467 } else {
468 "..\\..\\..";
471 my $wine_include_dir = "$msvc_wine_dir\\include";
473 $progress_current++;
474 $output->progress("$dsp_file (file $progress_current of $progress_max)");
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}};
481 if ($project !~ /^wine(?:_unicode|build|runtests|test)?$/ &&
482 $project !~ /^(?:gdi32|ntdll|user32)_.+?$/ &&
483 $project !~ /_test$/)
485 push @source_files, "$project.spec";
486 # push @source_files, "$project.spec.c";
487 @source_files = sort(@source_files);
490 my $no_cpp = 1;
491 my $no_msvc_headers = 1;
492 if ($project =~ /^wine(?:runtests|test)$/ || $project =~ /_test$/) {
493 $no_msvc_headers = 0;
496 my @cfgs;
498 push @cfgs, "$project - Win32";
500 if (!$no_cpp) {
501 my @_cfgs;
502 foreach my $cfg (@cfgs) {
503 push @_cfgs, "$cfg C";
504 push @_cfgs, "$cfg C++";
506 @cfgs = @_cfgs;
509 if (!$no_release) {
510 my @_cfgs;
511 foreach my $cfg (@cfgs) {
512 push @_cfgs, "$cfg Debug";
513 push @_cfgs, "$cfg Release";
515 @cfgs = @_cfgs;
518 if (!$no_msvc_headers) {
519 my @_cfgs;
520 foreach my $cfg (@cfgs) {
521 push @_cfgs, "$cfg MSVC Headers";
522 push @_cfgs, "$cfg Wine Headers";
524 @cfgs = @_cfgs;
527 my $default_cfg = $cfgs[$#cfgs];
529 print OUT "# Microsoft Developer Studio Project File - Name=\"$project\" - Package Owner=<4>\r\n";
530 print OUT "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n";
531 print OUT "# ** DO NOT EDIT **\r\n";
532 print OUT "\r\n";
534 if ($lib) {
535 print OUT "# TARGTYPE \"Win32 (x86) Static Library\" 0x0104\r\n";
536 } elsif ($dll) {
537 print OUT "# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\r\n";
538 } else {
539 print OUT "# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n";
541 print OUT "\r\n";
543 print OUT "CFG=$default_cfg\r\n";
544 print OUT "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n";
545 print OUT "!MESSAGE use the Export Makefile command and run\r\n";
546 print OUT "!MESSAGE \r\n";
547 print OUT "!MESSAGE NMAKE /f \"$project.mak\".\r\n";
548 print OUT "!MESSAGE \r\n";
549 print OUT "!MESSAGE You can specify a configuration when running NMAKE\r\n";
550 print OUT "!MESSAGE by defining the macro CFG on the command line. For example:\r\n";
551 print OUT "!MESSAGE \r\n";
552 print OUT "!MESSAGE NMAKE /f \"$project.mak\" CFG=\"$default_cfg\"\r\n";
553 print OUT "!MESSAGE \r\n";
554 print OUT "!MESSAGE Possible choices for configuration are:\r\n";
555 print OUT "!MESSAGE \r\n";
556 foreach my $cfg (@cfgs) {
557 if ($lib) {
558 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Static Library\")\r\n";
559 } elsif ($dll) {
560 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n";
561 } else {
562 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Console Application\")\r\n";
565 print OUT "!MESSAGE \r\n";
566 print OUT "\r\n";
568 print OUT "# Begin Project\r\n";
569 print OUT "# PROP AllowPerConfigDependencies 0\r\n";
570 print OUT "# PROP Scc_ProjName \"\"\r\n";
571 print OUT "# PROP Scc_LocalPath \"\"\r\n";
572 print OUT "CPP=cl.exe\r\n";
573 print OUT "MTL=midl.exe\r\n" if !$lib && !$exe;
574 print OUT "RSC=rc.exe\r\n";
576 my $n = 0;
578 my $output_dir;
579 foreach my $cfg (@cfgs) {
580 if($#cfgs == 0) {
581 # Nothing
582 } elsif($n == 0) {
583 print OUT "!IF \"\$(CFG)\" == \"$cfg\"\r\n";
584 print OUT "\r\n";
585 } else {
586 print OUT "\r\n";
587 print OUT "!ELSEIF \"\$(CFG)\" == \"$cfg\"\r\n";
588 print OUT "\r\n";
591 my $debug = ($cfg !~ /Release/);
592 my $msvc_headers = ($cfg =~ /MSVC Headers/);
594 print OUT "# PROP BASE Use_MFC 0\r\n";
596 if($debug) {
597 print OUT "# PROP BASE Use_Debug_Libraries 1\r\n";
598 } else {
599 print OUT "# PROP BASE Use_Debug_Libraries 0\r\n";
602 $output_dir = $cfg;
603 $output_dir =~ s/^$project - //;
604 $output_dir =~ s/ /_/g;
605 $output_dir =~ s/C\+\+/Cxx/g;
606 if($output_prefix_dir) {
607 $output_dir = "$output_prefix_dir\\$output_dir";
610 print OUT "# PROP BASE Output_Dir \"$output_dir\"\r\n";
611 print OUT "# PROP BASE Intermediate_Dir \"$output_dir\"\r\n";
613 print OUT "# PROP BASE Target_Dir \"\"\r\n";
615 print OUT "# PROP Use_MFC 0\r\n";
616 if($debug) {
617 print OUT "# PROP Use_Debug_Libraries 1\r\n";
618 } else {
619 print OUT "# PROP Use_Debug_Libraries 0\r\n";
621 print OUT "# PROP Output_Dir \"$output_dir\"\r\n";
622 print OUT "# PROP Intermediate_Dir \"$output_dir\"\r\n";
624 print OUT "# PROP Ignore_Export_Lib 0\r\n" if $dll;
625 print OUT "# PROP Target_Dir \"\"\r\n";
627 my @defines;
628 if($debug) {
629 if($lib || $exe) {
630 print OUT "# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od";
631 @defines = (qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 _DEBUG _MBCS _LIB));
632 } else {
633 print OUT "# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od";
634 @defines = (qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 _DEBUG _WINDOWS _MBCS _USRDLL), ("\U${project}\E_EXPORTS"));
636 } else {
637 if($lib || $exe) {
638 print OUT "# ADD BASE CPP /nologo /W3 /GX /O2";
639 @defines = (qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 NDEBUG _MBCS _LIB));
640 } else {
641 print OUT "# ADD BASE CPP /nologo /MT /W3 /GX /O2";
642 @defines = (qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 NDEBUG _WINDOWS _MBCS _USRDLL), ("\U${project}\E_EXPORTS"));
646 foreach my $define (@defines) {
647 print OUT " /D \"$define\"";
649 print OUT " /YX" if $lib || $exe;
650 print OUT " /FD";
651 print OUT " /GZ" if $debug;
652 print OUT " " if $debug && ($lib || $exe);
653 print OUT " /c";
654 print OUT "\r\n";
656 my @defines2;
657 if($debug) {
658 if($lib) {
659 print OUT "# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od";
660 @defines2 = qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 _DEBUG _WINDOWS _MBCS _LIB);
661 } else {
662 print OUT "# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od";
663 @defines2 = qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 _DEBUG WIN32 _WINDOWS _MBCS _USRDLL);
665 } else {
666 if($lib) {
667 print OUT "# ADD CPP /nologo /MT /W3 /GX /O2";
668 @defines2 = qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 NDEBUG _WINDOWS _MBCS _LIB);
669 } else {
670 print OUT "# ADD CPP /nologo /MT /W3 /GX /O2";
671 @defines2 = qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 NDEBUG WIN32 _WINDOWS _MBCS _USRDLL);
675 my @includes = ();
676 if($wine) {
677 push @defines2, "_\U${project}\E_";
678 push @defines2, qw(__WINESRC__) if $project !~ /^(?:wine(?:build|test)|.*?_test)$/;
679 if ($msvc_headers) {
680 push @defines2, qw(__WINE_USE_NATIVE_HEADERS);
682 my $output_dir2 = $output_dir;
683 $output_dir =~ s/\\/\\\\/g;
684 push @defines2, "__WINETEST_OUTPUT_DIR=\\\"$output_dir\\\"";
685 push @defines2, qw(__i386__ _X86_);
687 if($project =~ /^gdi32_(?:enhmfdrv|mfdrv)$/) {
688 push @includes, "..";
691 if($project eq "user32_windows") {
692 push @includes, "..\\dlls\\user";
695 if($project eq "user32_dde") {
696 push @includes, "..";
699 if ($project =~ /_test$/) {
700 push @includes, "$msvc_wine_dir\\$output_dir";
703 if (!$msvc_headers || $project eq "winetest") {
704 push @includes, $wine_include_dir;
708 if($wine) {
709 foreach my $include (@includes) {
710 if ($include !~ /[\\\"]/) {
711 print OUT " /I \"$include\"";
712 } else {
713 print OUT " /I $include";
718 foreach my $define (@defines2) {
719 if ($define !~ /[\\\"]/) {
720 print OUT " /D \"$define\"";
721 } else {
722 print OUT " /D $define";
725 print OUT " /D inline=__inline" if $wine;
726 print OUT " /D \"__STDC__\"" if 0 && $wine;
728 print OUT " /YX" if $lib;
729 print OUT " /FR" if !$lib;
730 print OUT " /FD";
731 print OUT " /GZ" if $debug;
732 print OUT " " if $debug && $lib;
733 print OUT " /c";
734 print OUT " /TP" if !$no_cpp;
735 print OUT "\r\n";
737 if($debug) {
738 print OUT "# SUBTRACT CPP /X /YX\r\n" if $dll;
739 print OUT "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
740 print OUT "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
741 print OUT "# ADD BASE RSC /l 0x41d /d \"_DEBUG\"\r\n";
742 print OUT "# ADD RSC /l 0x41d";
743 if($wine) {
744 foreach my $include (@includes) {
745 print OUT " /i \"$include\"";
748 print OUT " /d \"_DEBUG\"\r\n";
749 } else {
750 print OUT "# SUBTRACT CPP /YX\r\n" if $dll;
751 print OUT "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
752 print OUT "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
753 print OUT "# ADD BASE RSC /l 0x41d /d \"NDEBUG\"\r\n";
754 print OUT "# ADD RSC /l 0x41d";
755 if($wine) {
756 foreach my $include (@includes) {
757 print OUT " /i \"$include\"";
760 print OUT "/d \"NDEBUG\"\r\n";
762 print OUT "BSC32=bscmake.exe\r\n";
763 print OUT "# ADD BASE BSC32 /nologo\r\n";
764 print OUT "# ADD BSC32 /nologo\r\n";
766 if($exe || $dll) {
767 print OUT "LINK32=link.exe\r\n";
768 print OUT "# ADD BASE LINK32 ";
769 my @libraries = qw(kernel32.lib user32.lib gdi32.lib winspool.lib
770 comdlg32.lib advapi32.lib shell32.lib ole32.lib
771 oleaut32.lib uuid.lib odbc32.lib odbccp32.lib);
772 foreach my $library (@libraries) {
773 print OUT "$library ";
775 print OUT " /nologo";
776 print OUT " /dll" if $dll;
777 print OUT " /subsystem:console" if $console;
778 print OUT " /debug" if $debug;
779 print OUT " /machine:I386";
780 print OUT " /pdbtype:sept" if $debug;
781 print OUT "\r\n";
783 print OUT "# ADD LINK32";
784 print OUT " /nologo";
785 print OUT " libcmt.lib" if $project =~ /^ntdll$/; # FIXME: Kludge
786 foreach my $import (@imports) {
787 print OUT " $import.lib" if ($import ne "msvcrt");
789 print OUT " /dll" if $dll;
790 print OUT " /subsystem:console" if $console;
791 print OUT " /debug" if $debug;
792 print OUT " /machine:I386";
793 print OUT " /nodefaultlib" if $project =~ /^ntdll$/; # FIXME: Kludge
794 print OUT " /def:\"$project.def\"" if $dll;
795 print OUT " /pdbtype:sept" if $debug;
796 print OUT "\r\n";
797 } else {
798 print OUT "LIB32=link.exe -lib\r\n";
799 print OUT "# ADD BASE LIB32 /nologo\r\n";
800 print OUT "# ADD LIB32 /nologo\r\n";
803 $n++;
806 if($#cfgs != 0) {
807 print OUT "\r\n";
808 print OUT "!ENDIF \r\n";
809 print OUT "\r\n";
812 if ($project eq "winebuild") {
813 print OUT "# Begin Special Build Tool\r\n";
814 print OUT "SOURCE=\"\$(InputPath)\"\r\n";
815 print OUT "PostBuild_Desc=Copying wine.dll and wine_unicode.dll ...\r\n";
816 print OUT "PostBuild_Cmds=";
817 print OUT "copy ..\\..\\library\\$output_dir\\wine.dll \$(OutDir)\t";
818 print OUT "copy ..\\..\\unicode\\$output_dir\\wine_unicode.dll \$(OutDir)\r\n";
819 print OUT "# End Special Build Tool\r\n";
821 print OUT "# Begin Target\r\n";
822 print OUT "\r\n";
823 foreach my $cfg (@cfgs) {
824 print OUT "# Name \"$cfg\"\r\n";
827 print OUT "# Begin Group \"Source Files\"\r\n";
828 print OUT "\r\n";
829 print OUT "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
831 foreach my $source_file (@source_files) {
832 $source_file =~ s%/%\\%g;
833 if($source_file !~ /^\./) {
834 $source_file = ".\\$source_file";
837 if($source_file =~ /^(.*?)\.spec$/) {
838 my $basename = $1;
840 $basename = "$basename.dll" if $basename !~ /\..{1,3}$/;
841 my $dbg_c_file = "$basename.dbg.c";
843 print OUT "# Begin Source File\r\n";
844 print OUT "\r\n";
845 print OUT "SOURCE=$dbg_c_file\r\n";
846 print OUT "# End Source File\r\n";
849 print OUT "# Begin Source File\r\n";
850 print OUT "\r\n";
852 print OUT "SOURCE=$source_file\r\n";
854 if($source_file =~ /^(.*?)\.spec$/) {
855 my $basename = $1;
857 my $spec_file = $source_file;
858 my $def_file = "$basename.def";
860 $basename = "$basename.dll" if $basename !~ /\..{1,3}$/;
861 my $dbg_file = "$basename.dbg";
862 my $dbg_c_file = "$basename.dbg.c";
864 my $srcdir = "."; # FIXME: Is this really always correct?
866 print OUT "# Begin Custom Build\r\n";
867 print OUT "InputPath=$spec_file\r\n";
868 print OUT "\r\n";
869 print OUT "BuildCmds= \\\r\n";
870 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe --def $spec_file > $def_file \\\r\n";
872 if($project =~ /^ntdll$/) {
873 my $n = 0;
874 foreach my $c_src (@c_srcs) {
875 if($n++ > 0) {
876 print OUT "\techo $c_src >> $dbg_file \\\r\n";
877 } else {
878 print OUT "\techo $c_src > $dbg_file \\\r\n";
881 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe";
882 print OUT " -o $dbg_c_file --debug -C$srcdir $dbg_file \\\r\n";
883 } else {
884 my $c_srcs = join(" ", grep(/\.c$/, @c_srcs));
886 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe";
887 print OUT " -o $dbg_c_file --debug -C$srcdir $c_srcs \\\r\n";
890 print OUT "\t\r\n";
891 print OUT "\r\n";
892 print OUT "\"$def_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
893 print OUT " \$(BuildCmds)\r\n";
894 print OUT "\r\n";
895 print OUT "\"$dbg_c_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
896 print OUT " \$(BuildCmds)\r\n";
897 print OUT "# End Custom Build\r\n";
898 } elsif($source_file =~ /([^\\]*?\.h)$/) {
899 my $h_file = $1;
901 foreach my $cfg (@cfgs) {
902 if($#cfgs == 0) {
903 # Nothing
904 } elsif($n == 0) {
905 print OUT "!IF \"\$(CFG)\" == \"$cfg\"\r\n";
906 print OUT "\r\n";
907 } else {
908 print OUT "\r\n";
909 print OUT "!ELSEIF \"\$(CFG)\" == \"$cfg\"\r\n";
910 print OUT "\r\n";
913 $output_dir = $cfg;
914 $output_dir =~ s/^$project - //;
915 $output_dir =~ s/ /_/g;
916 $output_dir =~ s/C\+\+/Cxx/g;
917 if($output_prefix_dir) {
918 $output_dir = "$output_prefix_dir\\$output_dir";
921 print OUT "# Begin Custom Build\r\n";
922 print OUT "OutDir=$output_dir\r\n";
923 print OUT "InputPath=$source_file\r\n";
924 print OUT "\r\n";
925 print OUT "\"\$(OutDir)\\wine\\$h_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
926 print OUT "\tcopy \"\$(InputPath)\" \"\$(OutDir)\\wine\"\r\n";
927 print OUT "\r\n";
928 print OUT "# End Custom Build\r\n";
931 if($#cfgs != 0) {
932 print OUT "\r\n";
933 print OUT "!ENDIF \r\n";
934 print OUT "\r\n";
938 print OUT "# End Source File\r\n";
940 print OUT "# End Group\r\n";
942 print OUT "# Begin Group \"Header Files\"\r\n";
943 print OUT "\r\n";
944 print OUT "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
945 foreach my $header_file (@header_files) {
946 print OUT "# Begin Source File\r\n";
947 print OUT "\r\n";
948 print OUT "SOURCE=.\\$header_file\r\n";
949 print OUT "# End Source File\r\n";
951 print OUT "# End Group\r\n";
955 print OUT "# Begin Group \"Resource Files\"\r\n";
956 print OUT "\r\n";
957 print OUT "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
958 foreach my $resource_file (@resource_files) {
959 print OUT "# Begin Source File\r\n";
960 print OUT "\r\n";
961 print OUT "SOURCE=.\\$resource_file\r\n";
962 print OUT "# End Source File\r\n";
964 print OUT "# End Group\r\n";
966 print OUT "# End Target\r\n";
967 print OUT "# End Project\r\n";
969 close(OUT);
972 sub _generate_dsw_header($) {
973 local *OUT = shift;
975 print OUT "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n";
976 print OUT "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n";
977 print OUT "\r\n";
980 sub _generate_dsw_project($$$$) {
981 local *OUT = shift;
983 my $project = shift;
984 my $dsp_file = shift;
985 my @dependencies = @{(shift)};
987 $dsp_file = "./$dsp_file";
988 $dsp_file =~ y%/%\\%;
990 @dependencies = sort(@dependencies);
992 print OUT "###############################################################################\r\n";
993 print OUT "\r\n";
994 print OUT "Project: \"$project\"=$dsp_file - Package Owner=<4>\r\n";
995 print OUT "\r\n";
996 print OUT "Package=<5>\r\n";
997 print OUT "{{{\r\n";
998 print OUT "}}}\r\n";
999 print OUT "\r\n";
1000 print OUT "Package=<4>\r\n";
1001 print OUT "{{{\r\n";
1002 foreach my $dependency (@dependencies) {
1003 print OUT " Begin Project Dependency\r\n";
1004 print OUT " Project_Dep_Name $dependency\r\n";
1005 print OUT " End Project Dependency\r\n";
1007 print OUT "}}}\r\n";
1008 print OUT "\r\n";
1011 sub _generate_dsw_footer($) {
1012 local *OUT = shift;
1014 print OUT "###############################################################################\r\n";
1015 print OUT "\r\n";
1016 print OUT "Global:\r\n";
1017 print OUT "\r\n";
1018 print OUT "Package=<5>\r\n";
1019 print OUT "{{{\r\n";
1020 print OUT "}}}\r\n";
1021 print OUT "\r\n";
1022 print OUT "Package=<3>\r\n";
1023 print OUT "{{{\r\n";
1024 print OUT "}}}\r\n";
1025 print OUT "\r\n";
1026 print OUT "###############################################################################\r\n";
1027 print OUT "\r\n";
1030 if ($options->wine) {
1031 my $dsw_file = "wine.dsw";
1032 $output->progress("$dsw_file");
1033 replace_file("$wine_dir/$dsw_file", \&_generate_wine_dsw);
1036 sub _generate_wine_dsw($) {
1037 local *OUT = shift;
1039 _generate_dsw_header(\*OUT);
1040 foreach my $module (sort(keys(%modules))) {
1041 next if $module =~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1043 my $project = $modules{$module}{project};
1044 my $dsp_file = $modules{$module}{dsp_file};
1046 my @dependencies;
1047 if($project =~ /^wine(?:_unicode)?$/) {
1048 @dependencies = ();
1049 } elsif($project =~ /^winebuild$/) {
1050 @dependencies = ("wine", "wine_unicode");
1051 } elsif($project =~ /^(?:gdi32|ntdll|user32)_.+?$/) {
1052 @dependencies = ();
1053 } else {
1054 @dependencies = ("wine", "wine_unicode", "winebuild");
1057 if($project =~ /^gdi32$/) {
1058 foreach my $dir (@gdi32_dirs) {
1059 my $dir2 = $dir;
1060 $dir2 =~ s%^.*?/([^/]+)$%$1%;
1062 my $module = "gdi32_$dir2";
1063 $module =~ s%/%_%g;
1064 push @dependencies, $module;
1066 } elsif($project =~ /^ntdll$/) {
1067 foreach my $dir (@ntdll_dirs) {
1068 my $module = "ntdll_$dir";
1069 $module =~ s%/%_%g;
1070 push @dependencies, $module;
1072 } elsif($project =~ /^user32$/) {
1073 foreach my $dir (@user32_dirs) {
1074 my $dir2 = $dir;
1075 $dir2 =~ s%^.*?/([^/]+)$%$1%;
1077 my $module = "user32_$dir2";
1078 $module =~ s%/%_%g;
1079 push @dependencies, $module;
1083 _generate_dsw_project(\*OUT, $project, $dsp_file, \@dependencies);
1085 _generate_dsw_footer(\*OUT);
1087 return 1;
1090 if ($options->winetest) {
1091 my $dsw_file = "winetest.dsw";
1092 $output->progress("$dsw_file");
1093 replace_file("$wine_dir/$dsw_file", \&_generate_winetest_dsw);
1096 sub _generate_winetest_dsw($) {
1097 local *OUT = shift;
1099 _generate_dsw_header(\*OUT);
1101 my @runtests_dependencies = ();
1102 foreach my $module (sort(keys(%modules))) {
1103 next if $module !~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1104 next if $module eq "wineruntests";
1106 my $project = $modules{$module}{project};
1108 push @runtests_dependencies, $project;
1111 foreach my $module (sort(keys(%modules))) {
1112 next if $module !~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1114 my $project = $modules{$module}{project};
1115 my $dsp_file = $modules{$module}{dsp_file};
1117 my @dependencies;
1118 if($project =~ /^winetest$/) {
1119 @dependencies = ();
1120 } elsif($project =~ /^wineruntests$/) {
1121 @dependencies = @runtests_dependencies;
1122 } else {
1123 @dependencies = ("winetest");
1126 _generate_dsw_project(\*OUT, $project, $dsp_file, \@dependencies);
1129 _generate_dsw_footer(\*OUT);
1132 if ($options->winetest) {
1133 foreach my $module (sort(keys(%modules))) {
1134 next if $module !~ /_test\.exe$/;
1136 my $project = $modules{$module}{project};
1137 my $dsp_file = $modules{$module}{dsp_file};
1138 my @tests = @{$modules{$module}{tests}};
1140 my $testlist_c = $dsp_file;
1141 $testlist_c =~ s%[^/]*\.dsp$%testlist.c%;
1143 replace_file("$wine_dir/$testlist_c", \&_generate_testlist_c, \@tests);
1147 # ***** Keep in sync with tools/make_ctests *****
1148 sub _generate_testlist_c($$) {
1149 local *OUT = shift;
1151 my @tests = @{(shift)};
1153 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n";
1154 print OUT "\n";
1155 print OUT "/* stdarg.h is needed for Winelib */\n";
1156 print OUT "#include <stdarg.h>\n";
1157 print OUT "#include <stdio.h>\n";
1158 print OUT "#include <stdlib.h>\n";
1159 print OUT "#include \"windef.h\"\n";
1160 print OUT "#include \"winbase.h\"\n";
1161 print OUT "\n";
1162 foreach my $test (@tests) {
1163 print OUT "extern void func_$test(void);\n";
1165 print OUT "\n";
1166 print OUT "struct test\n";
1167 print OUT "{\n";
1168 print OUT " const char *name;\n";
1169 print OUT " void (*func)(void);\n";
1170 print OUT "};\n";
1171 print OUT "\n";
1172 print OUT "static const struct test winetest_testlist[] =\n";
1173 print OUT "{\n";
1174 foreach my $test (@tests) {
1175 print OUT " { \"$test\", func_$test },\n";
1177 print OUT " { 0, 0 }\n";
1178 print OUT "};\n";
1179 print OUT "\n";
1180 print OUT "#define WINETEST_WANT_MAIN\n";
1181 print OUT "#include \"wine/test.h\"\n";
1184 if ($options->winetest) {
1185 replace_file("$wine_dir/runtests.c", \&_generate_runtests_c);
1188 sub _generate_runtests_c($) {
1189 local *OUT = shift;
1191 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n";
1193 print OUT "\n";
1194 print OUT "#include <stdio.h>\n";
1195 print OUT "#include <stdlib.h>\n";
1196 print OUT "\n";
1198 print OUT "int main(int argc, char *argv[])\n";
1199 print OUT "{\n";
1200 print OUT " char output_dir[] = __WINETEST_OUTPUT_DIR;\n";
1201 print OUT " char command[4096];\n";
1202 print OUT "\n";
1203 foreach my $dsp_file (keys(%runtests)) {
1204 my @tests = @{$runtests{$dsp_file}};
1206 my $project = $dsp_file;
1207 $project =~ s%^(.*?)/?([^/]+)\.dsp$%$2%;
1208 my $dir = $1;
1209 $dir =~ s%/%\\\\%g;
1211 foreach my $test (@tests) {
1212 print OUT " sprintf(command, \"$dir\\\\%s\\\\$project.exe $test\", output_dir);\n";
1213 print OUT " system(command);\n";
1214 print OUT "\n";
1217 print OUT " return 0;\n";
1218 print OUT "}\n";
1221 if ($options->winetest) {
1222 replace_file("$wine_dir/winetest.c", \&_generate_winetest_c);
1225 sub _generate_winetest_c($) {
1226 local *OUT = shift;
1228 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n\n";
1230 print OUT "/* Force the linker to generate a .lib file */\n";
1231 print OUT "void __wine_dummy_lib_function()\n{\n}\n\n";
1234 if ($options->wine) {
1235 my $config_h = "include/config.h";
1237 $output->progress("$config_h");
1239 replace_file("$wine_dir/$config_h", \&_generate_config_h);
1242 sub _generate_config_h($) {
1243 local *OUT = shift;
1245 print OUT "#define __WINE_CONFIG_H\n";
1246 print OUT "\n";
1248 my @headers = qw(direct.h fcntl.h io.h string.h process.h);
1249 foreach my $header (@headers) {
1250 $header =~ y/\.\//__/;
1251 print OUT "#define HAVE_\U$header\E\n";
1252 print OUT "\n";
1255 my @functions = qw(
1256 _alldiv _allmul _allrem _aulldiv _aullrem
1257 _access _chdir _close _lseek _mkdir _open _pclose _popen _read _rmdir _write _stat
1258 _snprintf _spawnvp _stricmp _strnicmp _vsnprintf _wcsicmp
1259 ecvt fcvt gcvt
1260 memmove
1261 strerror
1262 wcslen
1264 foreach my $function (@functions) {
1265 print OUT "#define HAVE_\U$function\E 1\n";
1266 print OUT "\n";
1269 if(0) {
1270 print OUT "#define NEED_STDCALL_DECORATION 1\n";
1271 print OUT "\n";
1274 print OUT "#define X_DISPLAY_MISSING 1\n";
1275 print OUT "\n";
1277 print OUT "/* Define to a macro to generate an assembly function directive */\n";
1278 print OUT "#define __ASM_FUNC(name) \"\"\n";
1279 print OUT "\n";
1281 print OUT "/* Define to a macro to generate an assembly name from a C symbol */\n";
1282 print OUT "#define __ASM_NAME(name) name\n";
1283 print OUT "\n";
1285 print OUT "/* Define to the assembler keyword used to specify a word value */\n";
1286 print OUT "#define __ASM_SHORT \".short\"\n";
1287 print OUT "\n";
1289 print OUT "/* Define to the assembler keyword used to specify an ASCII string */\n";
1290 print OUT "#define __ASM_STRING \".string\"\n";
1291 print OUT "\n";
1293 print OUT "/* Define to the address where bug reports for this package should be sent. */\n";
1294 print OUT "#define PACKAGE_BUGREPORT \"\"\n";
1295 print OUT "\n";
1297 print OUT "/* Define to the full name of this package. */\n";
1298 print OUT "#define PACKAGE_NAME \"Wine\"\n";
1299 print OUT "\n";
1301 print OUT "/* Define to the full name and version of this package. */\n";
1302 print OUT "#define PACKAGE_STRING \"Wine YYYYMMDD\"\n";
1303 print OUT "\n";
1305 print OUT "/* Define to the one symbol short name of this package. */\n";
1306 print OUT "#define PACKAGE_TARNAME \"wine\"\n";
1307 print OUT "\n";
1309 print OUT "/* Define to the version of this package. */\n";
1310 print OUT "#define PACKAGE_VERSION \"YYYYMMDD\"\n";
1311 print OUT "\n";
1313 close(OUT);