wined3d: Color keying emulation.
[wine/multimedia.git] / tools / winapi / msvcmaker
blob53c37fbc026c541f1c1655f20c61ab5f63a4b826
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 beginning 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|msacm|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);
94 push @makefile_in_files, "libs/wine/Makefile.in";
95 push @makefile_in_files, "libs/unicode/Makefile.in";
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;
130 if($makefile_in_file eq "loader/Makefile.in") {
131 next;
134 while($again || defined(my $line = <IN>)) {
135 if(!$again) {
136 chomp $line;
137 if($lookahead) {
138 $lookahead = 0;
139 $_ .= "\n" . $line;
140 } else {
141 $_ = $line;
143 } else {
144 $again = 0;
147 s/^\s*?(.*?)\s*$/$1/; # remove whitespace at beginning and end of line
148 s/^(.*?)\s*#.*$/$1/; # remove comments
149 /^$/ && next; # skip empty lines
151 if(s/\\$/ /s) {
152 $lookahead = 1;
153 next;
156 if(/^MODULE\s*=\s*([\w\.]+)$/) {
157 $module = $1;
159 if($module eq "none") {
160 if($makefile_in_file eq "tools/winebuild/Makefile.in") {
161 $module = "winebuild.exe";
162 } else {
163 next MAKEFILE_IN;
166 } elsif(/^LIBRARY\s*=\s*(\S+)\s*$/) {
167 $module = $1 . "\.lib";
168 } elsif(/^TOPOBJDIR\s*=\s*(\S+)\s*$/) {
169 $topobjdir = $1;
170 } elsif (/^TESTDLL\s*=\s*(\S+)\s*$/) {
171 $testdll = $1;
172 } elsif (/^IMPORTS\s*=\s*/) {
173 push @imports, grep !/^ntdll$/, split /\s+/s, $';
174 } elsif (/^EXTRALIBS\s*=\s*/) {
175 push @imports, map { /^-l(dxerr8|dxerr9|dxguid|strmiids|uuid)$/ ? $1 : () } split /\s+/s, $';
176 } elsif (/^CTESTS\s*=\s*/) {
177 my @files = split /\s+/s, $';
179 my $dir = $makefile_in_file;
180 $dir =~ s/\/Makefile\.in$//;
182 my $dsp_file = $testdll;
183 $dsp_file =~ s/\.(dll|drv)$/_test.dsp/;
184 $dsp_file = "$dir/$dsp_file";
186 $wine_test_dsp_files{$dsp_file}{files} = [@files, "testlist.c"];
187 $wine_test_dsp_files{$dsp_file}{imports} = [@imports];
188 } elsif(/^(\w+)\s*=\s*/) {
189 my $var = $1;
190 my @files = split /\s+/s, $';
192 @files = map {
193 if(/^\$\((\w+):\%=(.*?)\%(.*?)\)$/) {
194 my @list = @{$vars{$1}};
195 my $prefix = $2;
196 my $suffix = $3;
197 foreach my $item (@list) {
198 $item = "$prefix$item$suffix";
200 @list;
201 } elsif(/^\$\(TOPOBJDIR\)(.*?)$/) {
202 "$topobjdir$1";
203 } elsif(/^\$/) {
204 print STDERR "unknown variable '$_'\n" if 0;
206 } else {
209 } @files;
211 $vars{$var} = \@files;
215 close(IN);
217 next if !$module;
219 my $c_srcs = [];
220 my $source_files = [];
221 if(exists($vars{C_SRCS})) {
222 $c_srcs = [sort(@{$vars{C_SRCS}})];
223 $source_files = [sort(@{$vars{C_SRCS}})];
226 my $header_files = [];
227 if(exists($vars{H_SRCS})) {
228 $header_files = [sort(@{$vars{H_SRCS}})];
231 my $resource_files = [];
232 if(exists($vars{RC_SRCS})) {
233 $resource_files = [sort(@{$vars{RC_SRCS}})];
236 my $project = $module;
237 $project =~ s/\.(?:dll|exe|lib)$//;
238 $project =~ y/./_/;
240 my $type;
241 if($module =~ /\.exe$/) {
242 $type = "exe";
243 } elsif($module =~ /\.lib$/) {
244 $type = "lib";
245 } else {
246 $type = "dll";
249 my $dsp_file = $makefile_in_file;
250 $dsp_file =~ s/Makefile.in$/$project.dsp/;
252 if($module eq "gdi32.dll") {
253 foreach my $dir (@gdi32_dirs) {
254 my $dir2 = $dir;
255 $dir2 =~ s%^.*?/([^/]+)$%$1%;
257 my $module = "gdi32_$dir2.lib";
258 $module =~ s%/%_%g;
260 my $project = "gdi32_$dir2";
261 $project =~ s%/%_%g;
263 my $type = "lib";
264 my $dsp_file = "$dir/$project.dsp";
266 ($source_files, my $local_source_files) = filter_files($source_files, "$dir2/");
267 ($header_files, my $local_header_files) = filter_files($header_files, "$dir2/");
268 ($resource_files, my $local_resource_files) = filter_files($resource_files, "$dir2/");
270 $modules{$module}{wine} = 1;
271 $modules{$module}{winetest} = 0;
272 $modules{$module}{project} = $project;
273 $modules{$module}{type} = $type;
274 $modules{$module}{dsp_file} = $dsp_file;
275 $modules{$module}{c_srcs} = $c_srcs;
276 $modules{$module}{source_files} = $local_source_files;
277 $modules{$module}{header_files} = $local_header_files;
278 $modules{$module}{resource_files} = $local_resource_files;
279 $modules{$module}{imports} = [];
283 $modules{$module}{wine} = 1;
284 $modules{$module}{winetest} = 0;
285 $modules{$module}{project} = $project;
286 $modules{$module}{type} = $type;
287 $modules{$module}{dsp_file} = $dsp_file;
288 $modules{$module}{c_srcs} = $c_srcs;
289 $modules{$module}{source_files} = $source_files;
290 $modules{$module}{header_files} = $header_files;
291 $modules{$module}{resource_files} = $resource_files;
292 $modules{$module}{imports} = [];
295 $wine_test_dsp_files{"wineruntests.dsp"}{files} = ["runtests.c"];
296 $wine_test_dsp_files{"wineruntests.dsp"}{imports} = [];
298 $wine_test_dsp_files{"winetest.dsp"}{files} = [
299 'include/wine/exception.h',
300 'include/wine/test.h',
301 'include/wine/unicode.h',
302 'winetest.c'
304 $wine_test_dsp_files{"winetest.dsp"}{imports} = [];
306 my %runtests = ();
308 foreach my $dsp_file (keys(%wine_test_dsp_files)) {
309 my $project = $dsp_file;
310 $project =~ s%^(?:.*?/)?([^/]+)\.dsp$%$1%;
312 my @files = @{$wine_test_dsp_files{$dsp_file}{files}};
313 my @imports = @{$wine_test_dsp_files{$dsp_file}{imports}};
315 my $type;
316 my $c_srcs = [];
317 my $source_files = [];
318 my $header_files = [];
319 my $resource_files = [];
321 my @tests = ();
323 if ($project eq "winetest") {
324 $type = "lib";
325 $c_srcs = [@files];
326 $source_files = [@files];
327 $header_files = [];
328 $resource_files = [];
329 } elsif ($project eq "wineruntests") {
330 $type = "exe";
331 $c_srcs = [@files];
332 $source_files = [@files];
333 $header_files = [];
334 $resource_files = [];
335 } else {
336 $type = "exe";
337 $c_srcs = [@files];
338 $source_files = [@files];
339 $header_files = [];
340 $resource_files = [];
342 @tests = map {
343 if (/^testlist\.c$/) {
345 } else {
346 s/\.c$//;
349 } @files;
351 $runtests{$dsp_file} = [@tests];
353 my $module = "$project.$type";
355 $modules{$module}{wine} = 0;
356 $modules{$module}{winetest} = 1;
358 $modules{$module}{project} = $project;
359 $modules{$module}{type} = $type;
360 $modules{$module}{dsp_file} = $dsp_file;
361 $modules{$module}{c_srcs} = $c_srcs;
362 $modules{$module}{source_files} = $source_files;
363 $modules{$module}{header_files} = $header_files;
364 $modules{$module}{resource_files} = $resource_files;
365 $modules{$module}{imports} = [@imports];
367 $modules{$module}{tests} = [@tests];
370 foreach my $module (sort(keys(%modules))) {
371 if($module =~ /^(?:ttydrv.dll|x11drv.dll)$/) {
372 delete $modules{$module};
376 my @modules = ();
377 foreach my $module (sort(keys(%modules))) {
378 if (($options->wine && $modules{$module}{wine}) ||
379 ($options->winetest && $modules{$module}{winetest}))
381 push @modules, $module;
385 my $progress_output;
386 my $progress_current = 0;
387 my $progress_max = scalar(@modules);
389 foreach my $module (@modules) {
390 my $dsp_file = $modules{$module}{dsp_file};
391 replace_file("$wine_dir/$dsp_file", \&_generate_dsp, $module);
394 sub _generate_dsp($$) {
395 local *OUT = shift;
397 my $module = shift;
399 my $dsp_file = $modules{$module}{dsp_file};
400 my $project = $modules{$module}{project};
401 my @imports = @{$modules{$module}{imports}};
403 my $lib = ($modules{$module}{type} eq "lib");
404 my $dll = ($modules{$module}{type} eq "dll");
405 my $exe = ($modules{$module}{type} eq "exe");
407 my $console = $exe; # FIXME: Not always correct
409 my $msvc_wine_dir = do {
410 my @parts = split(m%/%, $dsp_file);
411 if($#parts == 1) {
412 "..";
413 } elsif($#parts == 2) {
414 "..\\..";
415 } else {
416 "..\\..\\..";
419 my $wine_include_dir = "$msvc_wine_dir\\include";
421 $progress_current++;
422 $output->progress("$dsp_file (file $progress_current of $progress_max)");
424 my @c_srcs = @{$modules{$module}{c_srcs}};
425 my @source_files = @{$modules{$module}{source_files}};
426 my @header_files = @{$modules{$module}{header_files}};
427 my @resource_files = @{$modules{$module}{resource_files}};
429 if ($project !~ /^wine(?:_unicode|build|runtests|test)?$/ &&
430 $project !~ /^(?:gdi32)_.+?$/ &&
431 $project !~ /_test$/)
433 push @source_files, "$project.spec";
434 # push @source_files, "$project.spec.c";
435 @source_files = sort(@source_files);
438 my $no_cpp = 1;
439 my $no_msvc_headers = 1;
440 if ($project =~ /^wine(?:runtests|test)$/ || $project =~ /_test$/) {
441 $no_msvc_headers = 0;
444 my @cfgs;
446 push @cfgs, "$project - Win32";
448 if (!$no_cpp) {
449 my @_cfgs;
450 foreach my $cfg (@cfgs) {
451 push @_cfgs, "$cfg C";
452 push @_cfgs, "$cfg C++";
454 @cfgs = @_cfgs;
457 if (!$no_release) {
458 my @_cfgs;
459 foreach my $cfg (@cfgs) {
460 push @_cfgs, "$cfg Debug";
461 push @_cfgs, "$cfg Release";
463 @cfgs = @_cfgs;
466 if (!$no_msvc_headers) {
467 my @_cfgs;
468 foreach my $cfg (@cfgs) {
469 push @_cfgs, "$cfg MSVC Headers";
470 push @_cfgs, "$cfg Wine Headers";
472 @cfgs = @_cfgs;
475 my $default_cfg = $cfgs[$#cfgs];
477 print OUT "# Microsoft Developer Studio Project File - Name=\"$project\" - Package Owner=<4>\r\n";
478 print OUT "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n";
479 print OUT "# ** DO NOT EDIT **\r\n";
480 print OUT "\r\n";
482 if ($lib) {
483 print OUT "# TARGTYPE \"Win32 (x86) Static Library\" 0x0104\r\n";
484 } elsif ($dll) {
485 print OUT "# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\r\n";
486 } else {
487 print OUT "# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n";
489 print OUT "\r\n";
491 print OUT "CFG=$default_cfg\r\n";
492 print OUT "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n";
493 print OUT "!MESSAGE use the Export Makefile command and run\r\n";
494 print OUT "!MESSAGE \r\n";
495 print OUT "!MESSAGE NMAKE /f \"$project.mak\".\r\n";
496 print OUT "!MESSAGE \r\n";
497 print OUT "!MESSAGE You can specify a configuration when running NMAKE\r\n";
498 print OUT "!MESSAGE by defining the macro CFG on the command line. For example:\r\n";
499 print OUT "!MESSAGE \r\n";
500 print OUT "!MESSAGE NMAKE /f \"$project.mak\" CFG=\"$default_cfg\"\r\n";
501 print OUT "!MESSAGE \r\n";
502 print OUT "!MESSAGE Possible choices for configuration are:\r\n";
503 print OUT "!MESSAGE \r\n";
504 foreach my $cfg (@cfgs) {
505 if ($lib) {
506 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Static Library\")\r\n";
507 } elsif ($dll) {
508 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n";
509 } else {
510 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Console Application\")\r\n";
513 print OUT "!MESSAGE \r\n";
514 print OUT "\r\n";
516 print OUT "# Begin Project\r\n";
517 print OUT "# PROP AllowPerConfigDependencies 0\r\n";
518 print OUT "# PROP Scc_ProjName \"\"\r\n";
519 print OUT "# PROP Scc_LocalPath \"\"\r\n";
520 print OUT "CPP=cl.exe\r\n";
521 print OUT "MTL=midl.exe\r\n" if !$lib && !$exe;
522 print OUT "RSC=rc.exe\r\n";
524 my $n = 0;
526 my $output_dir;
527 foreach my $cfg (@cfgs) {
528 if($#cfgs == 0) {
529 # Nothing
530 } elsif($n == 0) {
531 print OUT "!IF \"\$(CFG)\" == \"$cfg\"\r\n";
532 print OUT "\r\n";
533 } else {
534 print OUT "\r\n";
535 print OUT "!ELSEIF \"\$(CFG)\" == \"$cfg\"\r\n";
536 print OUT "\r\n";
539 my $debug = ($cfg !~ /Release/);
540 my $msvc_headers = ($cfg =~ /MSVC Headers/);
542 print OUT "# PROP BASE Use_MFC 0\r\n";
544 if($debug) {
545 print OUT "# PROP BASE Use_Debug_Libraries 1\r\n";
546 } else {
547 print OUT "# PROP BASE Use_Debug_Libraries 0\r\n";
550 $output_dir = $cfg;
551 $output_dir =~ s/^$project - //;
552 $output_dir =~ s/ /_/g;
553 $output_dir =~ s/C\+\+/Cxx/g;
554 if($output_prefix_dir) {
555 $output_dir = "$output_prefix_dir\\$output_dir";
558 print OUT "# PROP BASE Output_Dir \"$output_dir\"\r\n";
559 print OUT "# PROP BASE Intermediate_Dir \"$output_dir\"\r\n";
561 print OUT "# PROP BASE Target_Dir \"\"\r\n";
563 print OUT "# PROP Use_MFC 0\r\n";
564 if($debug) {
565 print OUT "# PROP Use_Debug_Libraries 1\r\n";
566 } else {
567 print OUT "# PROP Use_Debug_Libraries 0\r\n";
569 print OUT "# PROP Output_Dir \"$output_dir\"\r\n";
570 print OUT "# PROP Intermediate_Dir \"$output_dir\"\r\n";
572 print OUT "# PROP Ignore_Export_Lib 0\r\n" if $dll;
573 print OUT "# PROP Target_Dir \"\"\r\n";
575 my @defines;
576 if($debug) {
577 if($lib || $exe) {
578 print OUT "# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od";
579 @defines = (qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 _DEBUG _MBCS _LIB));
580 } else {
581 print OUT "# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od";
582 @defines = (qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 _DEBUG _WINDOWS _MBCS _USRDLL), ("\U${project}\E_EXPORTS"));
584 } else {
585 if($lib || $exe) {
586 print OUT "# ADD BASE CPP /nologo /W3 /GX /O2";
587 @defines = (qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 NDEBUG _MBCS _LIB));
588 } else {
589 print OUT "# ADD BASE CPP /nologo /MT /W3 /GX /O2";
590 @defines = (qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 NDEBUG _WINDOWS _MBCS _USRDLL), ("\U${project}\E_EXPORTS"));
594 foreach my $define (@defines) {
595 print OUT " /D \"$define\"";
597 print OUT " /YX" if $lib || $exe;
598 print OUT " /FD";
599 print OUT " /GZ" if $debug;
600 print OUT " " if $debug && ($lib || $exe);
601 print OUT " /c";
602 print OUT "\r\n";
604 my @defines2;
605 if($debug) {
606 if($lib) {
607 print OUT "# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od";
608 @defines2 = qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 _DEBUG _WINDOWS _MBCS _LIB);
609 } else {
610 print OUT "# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od";
611 @defines2 = qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 _DEBUG WIN32 _WINDOWS _MBCS _USRDLL);
613 } else {
614 if($lib) {
615 print OUT "# ADD CPP /nologo /MT /W3 /GX /O2";
616 @defines2 = qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 NDEBUG _WINDOWS _MBCS _LIB);
617 } else {
618 print OUT "# ADD CPP /nologo /MT /W3 /GX /O2";
619 @defines2 = qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 NDEBUG WIN32 _WINDOWS _MBCS _USRDLL);
623 my @includes = ();
624 if($wine) {
625 push @defines2, "_\U${project}\E_";
626 push @defines2, qw(__WINESRC__) if $project !~ /^(?:wine(?:build|test)|.*?_test)$/;
627 if ($msvc_headers) {
628 push @defines2, qw(__WINE_USE_NATIVE_HEADERS);
630 my $output_dir2 = $output_dir;
631 $output_dir =~ s/\\/\\\\/g;
632 push @defines2, "__WINETEST_OUTPUT_DIR=\\\"$output_dir\\\"";
633 push @defines2, qw(__i386__ _X86_);
635 if($project =~ /^gdi32_(?:enhmfdrv|mfdrv)$/) {
636 push @includes, "..";
639 if ($project =~ /_test$/) {
640 push @includes, "$msvc_wine_dir\\$output_dir";
643 if (!$msvc_headers || $project eq "winetest") {
644 push @includes, $wine_include_dir;
648 if($wine) {
649 foreach my $include (@includes) {
650 if ($include !~ /[\\\"]/) {
651 print OUT " /I \"$include\"";
652 } else {
653 print OUT " /I $include";
658 foreach my $define (@defines2) {
659 if ($define !~ /[\\\"]/) {
660 print OUT " /D \"$define\"";
661 } else {
662 print OUT " /D $define";
665 print OUT " /D inline=__inline" if $wine;
666 print OUT " /D \"__STDC__\"" if 0 && $wine;
668 print OUT " /YX" if $lib;
669 print OUT " /FR" if !$lib;
670 print OUT " /FD";
671 print OUT " /GZ" if $debug;
672 print OUT " " if $debug && $lib;
673 print OUT " /c";
674 print OUT " /TP" if !$no_cpp;
675 print OUT "\r\n";
677 if($debug) {
678 print OUT "# SUBTRACT CPP /X /YX\r\n" if $dll;
679 print OUT "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
680 print OUT "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
681 print OUT "# ADD BASE RSC /l 0x41d /d \"_DEBUG\"\r\n";
682 print OUT "# ADD RSC /l 0x41d";
683 if($wine) {
684 foreach my $include (@includes) {
685 print OUT " /i \"$include\"";
688 print OUT " /d \"_DEBUG\"\r\n";
689 } else {
690 print OUT "# SUBTRACT CPP /YX\r\n" if $dll;
691 print OUT "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
692 print OUT "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
693 print OUT "# ADD BASE RSC /l 0x41d /d \"NDEBUG\"\r\n";
694 print OUT "# ADD RSC /l 0x41d";
695 if($wine) {
696 foreach my $include (@includes) {
697 print OUT " /i \"$include\"";
700 print OUT "/d \"NDEBUG\"\r\n";
702 print OUT "BSC32=bscmake.exe\r\n";
703 print OUT "# ADD BASE BSC32 /nologo\r\n";
704 print OUT "# ADD BSC32 /nologo\r\n";
706 if($exe || $dll) {
707 print OUT "LINK32=link.exe\r\n";
708 print OUT "# ADD BASE LINK32 ";
709 my @libraries = qw(kernel32.lib user32.lib gdi32.lib winspool.lib
710 comdlg32.lib advapi32.lib shell32.lib ole32.lib
711 oleaut32.lib uuid.lib odbc32.lib odbccp32.lib);
712 foreach my $library (@libraries) {
713 print OUT "$library ";
715 print OUT " /nologo";
716 print OUT " /dll" if $dll;
717 print OUT " /subsystem:console" if $console;
718 print OUT " /debug" if $debug;
719 print OUT " /machine:I386";
720 print OUT " /pdbtype:sept" if $debug;
721 print OUT "\r\n";
723 print OUT "# ADD LINK32";
724 print OUT " /nologo";
725 print OUT " libcmt.lib" if $project =~ /^ntdll$/; # FIXME: Kludge
726 foreach my $import (@imports) {
727 print OUT " $import.lib" if ($import ne "msvcrt");
729 print OUT " /dll" if $dll;
730 print OUT " /subsystem:console" if $console;
731 print OUT " /debug" if $debug;
732 print OUT " /machine:I386";
733 print OUT " /nodefaultlib" if $project =~ /^ntdll$/; # FIXME: Kludge
734 print OUT " /def:\"$project.def\"" if $dll;
735 print OUT " /pdbtype:sept" if $debug;
736 print OUT "\r\n";
737 } else {
738 print OUT "LIB32=link.exe -lib\r\n";
739 print OUT "# ADD BASE LIB32 /nologo\r\n";
740 print OUT "# ADD LIB32 /nologo\r\n";
743 $n++;
746 if($#cfgs != 0) {
747 print OUT "\r\n";
748 print OUT "!ENDIF \r\n";
749 print OUT "\r\n";
752 if ($project eq "winebuild") {
753 print OUT "# Begin Special Build Tool\r\n";
754 print OUT "SOURCE=\"\$(InputPath)\"\r\n";
755 print OUT "PostBuild_Desc=Copying wine.lib and wine_unicode.lib ...\r\n";
756 print OUT "PostBuild_Cmds=";
757 print OUT "copy ..\\..\\libs\\wine\\$output_dir\\wine.lib \$(OutDir)\t";
758 print OUT "copy ..\\..\\libs\\unicode\\$output_dir\\wine_unicode.lib \$(OutDir)\r\n";
759 print OUT "# End Special Build Tool\r\n";
761 print OUT "# Begin Target\r\n";
762 print OUT "\r\n";
763 foreach my $cfg (@cfgs) {
764 print OUT "# Name \"$cfg\"\r\n";
767 print OUT "# Begin Group \"Source Files\"\r\n";
768 print OUT "\r\n";
769 print OUT "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
771 foreach my $source_file (@source_files) {
772 $source_file =~ s%/%\\%g;
773 if($source_file !~ /^\./) {
774 $source_file = ".\\$source_file";
777 if($source_file =~ /^(.*?)\.spec$/) {
778 my $basename = $1;
780 $basename = "$basename.dll" if $basename !~ /\..{1,3}$/;
781 my $dbg_c_file = "$basename.dbg.c";
783 print OUT "# Begin Source File\r\n";
784 print OUT "\r\n";
785 print OUT "SOURCE=$dbg_c_file\r\n";
786 print OUT "# End Source File\r\n";
789 print OUT "# Begin Source File\r\n";
790 print OUT "\r\n";
792 print OUT "SOURCE=$source_file\r\n";
794 if($source_file =~ /^(.*?)\.spec$/) {
795 my $basename = $1;
797 my $spec_file = $source_file;
798 my $def_file = "$basename.def";
800 $basename = "$basename.dll" if $basename !~ /\..{1,3}$/;
801 my $dbg_file = "$basename.dbg";
802 my $dbg_c_file = "$basename.dbg.c";
804 my $srcdir = "."; # FIXME: Is this really always correct?
806 print OUT "# Begin Custom Build\r\n";
807 print OUT "InputPath=$spec_file\r\n";
808 print OUT "\r\n";
809 print OUT "BuildCmds= \\\r\n";
810 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe --def $spec_file > $def_file \\\r\n";
812 if($project =~ /^ntdll$/) {
813 my $n = 0;
814 foreach my $c_src (@c_srcs) {
815 if($n++ > 0) {
816 print OUT "\techo $c_src >> $dbg_file \\\r\n";
817 } else {
818 print OUT "\techo $c_src > $dbg_file \\\r\n";
821 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe";
822 print OUT " -o $dbg_c_file --debug -C$srcdir $dbg_file \\\r\n";
823 } else {
824 my $c_srcs = join(" ", grep(/\.c$/, @c_srcs));
826 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe";
827 print OUT " -o $dbg_c_file --debug -C$srcdir $c_srcs \\\r\n";
830 print OUT "\t\r\n";
831 print OUT "\r\n";
832 print OUT "\"$def_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
833 print OUT " \$(BuildCmds)\r\n";
834 print OUT "\r\n";
835 print OUT "\"$dbg_c_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
836 print OUT " \$(BuildCmds)\r\n";
837 print OUT "# End Custom Build\r\n";
838 } elsif($source_file =~ /([^\\]*?\.h)$/) {
839 my $h_file = $1;
841 foreach my $cfg (@cfgs) {
842 if($#cfgs == 0) {
843 # Nothing
844 } elsif($n == 0) {
845 print OUT "!IF \"\$(CFG)\" == \"$cfg\"\r\n";
846 print OUT "\r\n";
847 } else {
848 print OUT "\r\n";
849 print OUT "!ELSEIF \"\$(CFG)\" == \"$cfg\"\r\n";
850 print OUT "\r\n";
853 $output_dir = $cfg;
854 $output_dir =~ s/^$project - //;
855 $output_dir =~ s/ /_/g;
856 $output_dir =~ s/C\+\+/Cxx/g;
857 if($output_prefix_dir) {
858 $output_dir = "$output_prefix_dir\\$output_dir";
861 print OUT "# Begin Custom Build\r\n";
862 print OUT "OutDir=$output_dir\r\n";
863 print OUT "InputPath=$source_file\r\n";
864 print OUT "\r\n";
865 print OUT "\"\$(OutDir)\\wine\\$h_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
866 print OUT "\tcopy \"\$(InputPath)\" \"\$(OutDir)\\wine\"\r\n";
867 print OUT "\r\n";
868 print OUT "# End Custom Build\r\n";
871 if($#cfgs != 0) {
872 print OUT "\r\n";
873 print OUT "!ENDIF \r\n";
874 print OUT "\r\n";
878 print OUT "# End Source File\r\n";
880 print OUT "# End Group\r\n";
882 print OUT "# Begin Group \"Header Files\"\r\n";
883 print OUT "\r\n";
884 print OUT "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
885 foreach my $header_file (@header_files) {
886 print OUT "# Begin Source File\r\n";
887 print OUT "\r\n";
888 print OUT "SOURCE=.\\$header_file\r\n";
889 print OUT "# End Source File\r\n";
891 print OUT "# End Group\r\n";
895 print OUT "# Begin Group \"Resource Files\"\r\n";
896 print OUT "\r\n";
897 print OUT "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
898 foreach my $resource_file (@resource_files) {
899 print OUT "# Begin Source File\r\n";
900 print OUT "\r\n";
901 print OUT "SOURCE=.\\$resource_file\r\n";
902 print OUT "# End Source File\r\n";
904 print OUT "# End Group\r\n";
906 print OUT "# End Target\r\n";
907 print OUT "# End Project\r\n";
909 close(OUT);
912 sub _generate_dsw_header($) {
913 local *OUT = shift;
915 print OUT "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n";
916 print OUT "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n";
917 print OUT "\r\n";
920 sub _generate_dsw_project($$$$) {
921 local *OUT = shift;
923 my $project = shift;
924 my $dsp_file = shift;
925 my @dependencies = @{(shift)};
927 $dsp_file = "./$dsp_file";
928 $dsp_file =~ y%/%\\%;
930 @dependencies = sort(@dependencies);
932 print OUT "###############################################################################\r\n";
933 print OUT "\r\n";
934 print OUT "Project: \"$project\"=$dsp_file - Package Owner=<4>\r\n";
935 print OUT "\r\n";
936 print OUT "Package=<5>\r\n";
937 print OUT "{{{\r\n";
938 print OUT "}}}\r\n";
939 print OUT "\r\n";
940 print OUT "Package=<4>\r\n";
941 print OUT "{{{\r\n";
942 foreach my $dependency (@dependencies) {
943 print OUT " Begin Project Dependency\r\n";
944 print OUT " Project_Dep_Name $dependency\r\n";
945 print OUT " End Project Dependency\r\n";
947 print OUT "}}}\r\n";
948 print OUT "\r\n";
951 sub _generate_dsw_footer($) {
952 local *OUT = shift;
954 print OUT "###############################################################################\r\n";
955 print OUT "\r\n";
956 print OUT "Global:\r\n";
957 print OUT "\r\n";
958 print OUT "Package=<5>\r\n";
959 print OUT "{{{\r\n";
960 print OUT "}}}\r\n";
961 print OUT "\r\n";
962 print OUT "Package=<3>\r\n";
963 print OUT "{{{\r\n";
964 print OUT "}}}\r\n";
965 print OUT "\r\n";
966 print OUT "###############################################################################\r\n";
967 print OUT "\r\n";
970 if ($options->wine) {
971 my $dsw_file = "wine.dsw";
972 $output->progress("$dsw_file");
973 replace_file("$wine_dir/$dsw_file", \&_generate_wine_dsw);
976 sub _generate_wine_dsw($) {
977 local *OUT = shift;
979 _generate_dsw_header(\*OUT);
980 foreach my $module (sort(keys(%modules))) {
981 next if $module =~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
983 my $project = $modules{$module}{project};
984 my $dsp_file = $modules{$module}{dsp_file};
986 my @dependencies;
987 if($project =~ /^wine(?:_unicode)?$/) {
988 @dependencies = ();
989 } elsif($project =~ /^winebuild$/) {
990 @dependencies = ("wine", "wine_unicode");
991 } elsif($project =~ /^(?:gdi32)_.+?$/) {
992 @dependencies = ();
993 } else {
994 @dependencies = ("wine", "wine_unicode", "winebuild");
997 if($project =~ /^gdi32$/) {
998 foreach my $dir (@gdi32_dirs) {
999 my $dir2 = $dir;
1000 $dir2 =~ s%^.*?/([^/]+)$%$1%;
1002 my $module = "gdi32_$dir2";
1003 $module =~ s%/%_%g;
1004 push @dependencies, $module;
1008 _generate_dsw_project(\*OUT, $project, $dsp_file, \@dependencies);
1010 _generate_dsw_footer(\*OUT);
1012 return 1;
1015 if ($options->winetest) {
1016 my $dsw_file = "winetest.dsw";
1017 $output->progress("$dsw_file");
1018 replace_file("$wine_dir/$dsw_file", \&_generate_winetest_dsw);
1021 sub _generate_winetest_dsw($) {
1022 local *OUT = shift;
1024 _generate_dsw_header(\*OUT);
1026 my @runtests_dependencies = ();
1027 foreach my $module (sort(keys(%modules))) {
1028 next if $module !~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1029 next if $module eq "wineruntests";
1031 my $project = $modules{$module}{project};
1033 push @runtests_dependencies, $project;
1036 foreach my $module (sort(keys(%modules))) {
1037 next if $module !~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1039 my $project = $modules{$module}{project};
1040 my $dsp_file = $modules{$module}{dsp_file};
1042 my @dependencies;
1043 if($project =~ /^winetest$/) {
1044 @dependencies = ();
1045 } elsif($project =~ /^wineruntests$/) {
1046 @dependencies = @runtests_dependencies;
1047 } else {
1048 @dependencies = ("winetest");
1051 _generate_dsw_project(\*OUT, $project, $dsp_file, \@dependencies);
1054 _generate_dsw_footer(\*OUT);
1057 if ($options->winetest) {
1058 foreach my $module (sort(keys(%modules))) {
1059 next if $module !~ /_test\.exe$/;
1061 my $project = $modules{$module}{project};
1062 my $dsp_file = $modules{$module}{dsp_file};
1063 my @tests = @{$modules{$module}{tests}};
1065 my $testlist_c = $dsp_file;
1066 $testlist_c =~ s%[^/]*\.dsp$%testlist.c%;
1068 replace_file("$wine_dir/$testlist_c", \&_generate_testlist_c, \@tests);
1072 # ***** Keep in sync with tools/make_ctests *****
1073 sub _generate_testlist_c($$) {
1074 local *OUT = shift;
1076 my @tests = @{(shift)};
1078 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n";
1079 print OUT "\n";
1080 print OUT "/* stdarg.h is needed for Winelib */\n";
1081 print OUT "#include <stdarg.h>\n";
1082 print OUT "#include <stdio.h>\n";
1083 print OUT "#include <stdlib.h>\n";
1084 print OUT "#include \"windef.h\"\n";
1085 print OUT "#include \"winbase.h\"\n";
1086 print OUT "\n";
1087 print OUT "#define STANDALONE\n";
1088 print OUT "#include \"wine/test.h\"\n";
1089 print OUT "\n";
1090 foreach my $test (@tests) {
1091 print OUT "extern void func_$test(void);\n";
1093 print OUT "\n";
1094 print OUT "const struct test winetest_testlist[] =\n";
1095 print OUT "{\n";
1096 foreach my $test (@tests) {
1097 print OUT " { \"$test\", func_$test },\n";
1099 print OUT " { 0, 0 }\n";
1100 print OUT "};\n";
1103 if ($options->winetest) {
1104 replace_file("$wine_dir/runtests.c", \&_generate_runtests_c);
1107 sub _generate_runtests_c($) {
1108 local *OUT = shift;
1110 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n";
1112 print OUT "\n";
1113 print OUT "#include <stdio.h>\n";
1114 print OUT "#include <stdlib.h>\n";
1115 print OUT "\n";
1117 print OUT "int main(int argc, char *argv[])\n";
1118 print OUT "{\n";
1119 print OUT " char output_dir[] = __WINETEST_OUTPUT_DIR;\n";
1120 print OUT " char command[4096];\n";
1121 print OUT "\n";
1122 foreach my $dsp_file (keys(%runtests)) {
1123 my @tests = @{$runtests{$dsp_file}};
1125 my $project = $dsp_file;
1126 $project =~ s%^(.*?)/?([^/]+)\.dsp$%$2%;
1127 my $dir = $1;
1128 $dir =~ s%/%\\\\%g;
1130 foreach my $test (@tests) {
1131 print OUT " sprintf(command, \"$dir\\\\%s\\\\$project.exe $test\", output_dir);\n";
1132 print OUT " system(command);\n";
1133 print OUT "\n";
1136 print OUT " return 0;\n";
1137 print OUT "}\n";
1140 if ($options->winetest) {
1141 replace_file("$wine_dir/winetest.c", \&_generate_winetest_c);
1144 sub _generate_winetest_c($) {
1145 local *OUT = shift;
1147 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n\n";
1149 print OUT "/* Force the linker to generate a .lib file */\n";
1150 print OUT "void __wine_dummy_lib_function()\n{\n}\n\n";
1153 if ($options->wine) {
1154 my $config_h = "include/config.h";
1156 $output->progress("$config_h");
1158 replace_file("$wine_dir/$config_h", \&_generate_config_h);
1161 sub _generate_config_h($) {
1162 local *OUT = shift;
1164 print OUT "#define __WINE_CONFIG_H\n";
1165 print OUT "\n";
1167 my @headers = qw(direct.h fcntl.h io.h string.h process.h);
1168 foreach my $header (@headers) {
1169 $header =~ y/\.\//__/;
1170 print OUT "#define HAVE_\U$header\E\n";
1171 print OUT "\n";
1174 my @functions = qw(
1175 _alldiv _allmul _allrem _aulldiv _aullrem
1176 _access _chdir _close _lseek _mkdir _open _pclose _popen _read _rmdir _write _stat
1177 _snprintf _spawnvp _stricmp _strnicmp _vsnprintf _wcsicmp
1178 ecvt fcvt gcvt
1179 memmove
1180 strerror
1181 wcslen
1183 foreach my $function (@functions) {
1184 print OUT "#define HAVE_\U$function\E 1\n";
1185 print OUT "\n";
1188 if(0) {
1189 print OUT "#define NEED_STDCALL_DECORATION 1\n";
1190 print OUT "\n";
1193 print OUT "#define X_DISPLAY_MISSING 1\n";
1194 print OUT "\n";
1196 print OUT "/* Define to a macro to generate an assembly function directive */\n";
1197 print OUT "#define __ASM_FUNC(name) \"\"\n";
1198 print OUT "\n";
1200 print OUT "/* Define to a macro to generate an assembly name from a C symbol */\n";
1201 print OUT "#define __ASM_NAME(name) name\n";
1202 print OUT "\n";
1204 print OUT "/* Define to the assembler keyword used to specify a word value */\n";
1205 print OUT "#define __ASM_SHORT \".short\"\n";
1206 print OUT "\n";
1208 print OUT "/* Define to the assembler keyword used to specify an ASCII string */\n";
1209 print OUT "#define __ASM_STRING \".string\"\n";
1210 print OUT "\n";
1212 print OUT "/* Define to the address where bug reports for this package should be sent. */\n";
1213 print OUT "#define PACKAGE_BUGREPORT \"\"\n";
1214 print OUT "\n";
1216 print OUT "/* Define to the full name of this package. */\n";
1217 print OUT "#define PACKAGE_NAME \"Wine\"\n";
1218 print OUT "\n";
1220 print OUT "/* Define to the full name and version of this package. */\n";
1221 print OUT "#define PACKAGE_STRING \"Wine YYYYMMDD\"\n";
1222 print OUT "\n";
1224 print OUT "/* Define to the one symbol short name of this package. */\n";
1225 print OUT "#define PACKAGE_TARNAME \"wine\"\n";
1226 print OUT "\n";
1228 print OUT "/* Define to the version of this package. */\n";
1229 print OUT "#define PACKAGE_VERSION \"YYYYMMDD\"\n";
1230 print OUT "\n";
1232 close(OUT);