- Updated it to support changes in Wine.
[wine/multimedia.git] / tools / winapi / msvcmaker
blob421768bd7c6b88b1b40696fc8544cb79b30c28b9
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 config qw(&file_directory &get_spec_files &get_makefile_in_files $current_dir $wine_dir);
13 use output qw($output);
14 use util qw(replace_file);
16 use msvcmaker_options qw($options);
18 if($options->progress) {
19 $output->enable_progress;
20 } else {
21 $output->disable_progress;
24 ########################################################################
25 # main
27 my @spec_files = get_spec_files("winelib");
28 my @makefile_in_files = get_makefile_in_files("winelib");
30 my $wine = 1;
32 my $output_prefix_dir = "Output";
33 my $no_release = 1;
35 if ($options->wine || $options->winetest) {
36 foreach my $spec_file (@spec_files) {
37 read_spec_file($spec_file);
41 my %modules;
43 sub read_spec_file {
44 my $spec_file = shift;
46 my $module = $spec_file;
47 $module =~ s%^.*?([^/]+)\.spec$%$1%;
48 $module .= ".dll" if $module !~ /\./;
50 my $type = "win32";
52 open(IN, "< $wine_dir/$spec_file");
54 my $header = 1;
55 my $lookahead = 0;
56 while($lookahead || defined($_ = <IN>)) {
57 $lookahead = 0;
59 s/^\s*?(.*?)\s*$/$1/; # remove whitespace at begining and end of line
60 s/^(.*?)\s*#.*$/$1/; # remove comments
61 /^$/ && next; # skip empty lines
63 if($header) {
64 if(/^\d+|@/) {
65 $header = 0;
66 $lookahead = 1;
68 next;
71 if(/^(\d+|@)\s+pascal(?:16)?/) {
72 $type = "win16";
73 last;
76 close(IN);
78 # FIXME: Kludge
79 if($module =~ /^(?:comm|imm|ole2conv|ole2prox|ole2thk|rasapi16|windebug)\.dll$/) {
80 $type = "win16";
83 if($type eq "win32") {
84 $modules{$module}{module} = $module;
85 $modules{$module}{type} = $type;
86 $modules{$module}{spec_file} = $spec_file;
90 my @gdi32_dirs = qw(dlls/gdi/enhmfdrv dlls/gdi/mfdrv dlls/gdi/win16drv graphics objects);
91 my @ntdll_dirs = qw(files if1632 loader/ne loader memory misc msdos ole relay32 scheduler win32);
92 my @user32_dirs = qw(controls dlls/user/dde windows);
94 push @makefile_in_files, "library/Makefile.in";
95 push @makefile_in_files, "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;
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 @imports = split /\s+/s, $';
171 @imports = grep !/^ntdll$/, @imports;
172 } elsif (/^CTESTS\s*=\s*/) {
173 my @files = split /\s+/s, $';
175 my $dir = $makefile_in_file;
176 $dir =~ s/\/Makefile\.in$//;
178 my $dsp_file = $testdll;
179 $dsp_file =~ s/\.dll$/_test.dsp/;
180 $dsp_file = "$dir/$dsp_file";
182 $wine_test_dsp_files{$dsp_file}{files} = [@files, "testlist.c"];
183 $wine_test_dsp_files{$dsp_file}{imports} = [@imports];
184 } elsif(/^(\w+)\s*=\s*/) {
185 my $var = $1;
186 my @files = split /\s+/s, $';
188 @files = map {
189 if(/^\$\((\w+):\%=(.*?)\%(.*?)\)$/) {
190 my @list = @{$vars{$1}};
191 my $prefix = $2;
192 my $suffix = $3;
193 foreach my $item (@list) {
194 $item = "$prefix$item$suffix";
196 @list;
197 } elsif(/^\$\(TOPOBJDIR\)(.*?)$/) {
198 "$topobjdir$1";
199 } elsif(/^\$/) {
200 print STDERR "unknown variable '$_'\n" if 0;
202 } else {
205 } @files;
207 $vars{$var} = \@files;
211 close(IN);
213 next if !$module;
215 my $c_srcs = [];
216 my $source_files = [];
217 if(exists($vars{C_SRCS})) {
218 $c_srcs = [sort(@{$vars{C_SRCS}})];
219 $source_files = [sort(@{$vars{C_SRCS}})];
222 my $header_files = [];
223 if(exists($vars{H_SRCS})) {
224 $header_files = [sort(@{$vars{H_SRCS}})];
227 my $resource_files = [];
228 if(exists($vars{RC_SRCS})) {
229 $resource_files = [sort(@{$vars{RC_SRCS}})];
232 my $project = $module;
233 $project =~ s/\.(?:dll|exe|lib)$//;
234 $project =~ y/./_/;
236 my $type;
237 if($module =~ /\.exe$/) {
238 $type = "exe";
239 } elsif($module =~ /\.lib$/) {
240 $type = "lib";
241 } else {
242 $type = "dll";
245 my $dsp_file = $makefile_in_file;
246 $dsp_file =~ s/Makefile.in$/$project.dsp/;
248 if($module eq "gdi32.dll") {
249 foreach my $dir (@gdi32_dirs) {
250 my $dir2 = $dir;
251 $dir2 =~ s%^.*?/([^/]+)$%$1%;
253 my $module = "gdi32_$dir2.lib";
254 $module =~ s%/%_%g;
256 my $project = "gdi32_$dir2";
257 $project =~ s%/%_%g;
259 my $type = "lib";
260 my $dsp_file = "$dir/$project.dsp";
262 ($source_files, my $local_source_files) = filter_files($source_files, "$dir2/");
263 ($header_files, my $local_header_files) = filter_files($header_files, "$dir2/");
264 ($resource_files, my $local_resource_files) = filter_files($resource_files, "$dir2/");
266 $modules{$module}{wine} = 1;
267 $modules{$module}{winetest} = 0;
268 $modules{$module}{project} = $project;
269 $modules{$module}{type} = $type;
270 $modules{$module}{dsp_file} = $dsp_file;
271 $modules{$module}{c_srcs} = $c_srcs;
272 $modules{$module}{source_files} = $local_source_files;
273 $modules{$module}{header_files} = $local_header_files;
274 $modules{$module}{resource_files} = $local_resource_files;
275 $modules{$module}{imports} = [];
277 } elsif($module eq "ntdll.dll") {
278 foreach my $dir (@ntdll_dirs) {
279 my $module = "ntdll_$dir.lib";
280 $module =~ s%/%_%g;
282 my $project = "ntdll_$dir";
283 $project =~ s%/%_%g;
285 my $type = "lib";
286 my $dsp_file = "$dir/$project.dsp";
288 ($source_files, my $local_source_files) = filter_files($source_files, "/$dir/");
289 ($header_files, my $local_header_files) = filter_files($header_files, "/$dir/");
290 ($resource_files, my $local_resource_files) = filter_files($resource_files, "/$dir/");
292 $modules{$module}{wine} = 1;
293 $modules{$module}{winetest} = 0;
294 $modules{$module}{project} = $project;
295 $modules{$module}{type} = $type;
296 $modules{$module}{dsp_file} = $dsp_file;
297 $modules{$module}{c_srcs} = $c_srcs;
298 $modules{$module}{source_files} = $local_source_files;
299 $modules{$module}{header_files} = $local_header_files;
300 $modules{$module}{resource_files} = $local_resource_files;
301 $modules{$module}{imports} = [];
303 } elsif($module eq "user32.dll") {
304 foreach my $dir (@user32_dirs) {
305 my $dir2 = $dir;
306 $dir2 =~ s%^.*?/([^/]+)$%$1%;
308 my $module = "user32_$dir2.lib";
309 $module =~ s%/%_%g;
311 my $project = "user32_$dir2";
312 $project =~ s%/%_%g;
314 my $type = "lib";
315 my $dsp_file = "$dir/$project.dsp";
317 ($source_files, my $local_source_files) = filter_files($source_files, "$dir2/");
318 ($header_files, my $local_header_files) = filter_files($header_files, "$dir2/");
319 ($resource_files, my $local_resource_files) = filter_files($resource_files, "$dir2/");
321 $modules{$module}{wine} = 1;
322 $modules{$module}{winetest} = 0;
323 $modules{$module}{project} = $project;
324 $modules{$module}{type} = $type;
325 $modules{$module}{dsp_file} = $dsp_file;
326 $modules{$module}{c_srcs} = $c_srcs;
327 $modules{$module}{source_files} = $local_source_files;
328 $modules{$module}{header_files} = $local_header_files;
329 $modules{$module}{resource_files} = $local_resource_files;
330 $modules{$module}{imports} = [];
334 $modules{$module}{wine} = 1;
335 $modules{$module}{winetest} = 0;
336 $modules{$module}{project} = $project;
337 $modules{$module}{type} = $type;
338 $modules{$module}{dsp_file} = $dsp_file;
339 $modules{$module}{c_srcs} = $c_srcs;
340 $modules{$module}{source_files} = $source_files;
341 $modules{$module}{header_files} = $header_files;
342 $modules{$module}{resource_files} = $resource_files;
343 $modules{$module}{imports} = [];
346 $wine_test_dsp_files{"programs/winetest/winetest.dsp"}{files} = [
347 '../../include/wine/exception.h',
348 '../../include/wine/test.h',
349 '../../include/wine/unicode.h'
351 $wine_test_dsp_files{"programs/winetest/winetest.dsp"}{imports} = [];
353 foreach my $dsp_file (keys(%wine_test_dsp_files)) {
354 my $project = $dsp_file;
355 $project =~ s%^.*?/([^/]+)\.dsp$%$1%;
357 my @files = @{$wine_test_dsp_files{$dsp_file}{files}};
358 my @imports = @{$wine_test_dsp_files{$dsp_file}{imports}};
360 my $type;
361 my $c_srcs = [];
362 my $source_files = [];
363 my $header_files = [];
364 my $resource_files = [];
366 my @tests = ();
368 if ($project eq "winetest") {
369 $type = "lib";
370 $c_srcs = [@files];
371 $source_files = [@files];
372 $header_files = [];
373 $resource_files = [];
374 } else {
375 $type = "exe";
376 $c_srcs = [@files];
377 $source_files = [@files];
378 $header_files = [];
379 $resource_files = [];
381 @tests = map {
382 if (/^testlist\.c$/) {
384 } else {
385 s/\.c$//;
388 } @files;
390 my $module = "$project.$type";
392 $modules{$module}{wine} = 0;
393 $modules{$module}{winetest} = 1;
395 $modules{$module}{project} = $project;
396 $modules{$module}{type} = $type;
397 $modules{$module}{dsp_file} = $dsp_file;
398 $modules{$module}{c_srcs} = $c_srcs;
399 $modules{$module}{source_files} = $source_files;
400 $modules{$module}{header_files} = $header_files;
401 $modules{$module}{resource_files} = $resource_files;
402 $modules{$module}{imports} = [@imports];
404 $modules{$module}{tests} = [@tests];
407 foreach my $module (sort(keys(%modules))) {
408 if($module =~ /^(?:ttydrv.dll|x11drv.dll)$/) {
409 delete $modules{$module};
413 my @modules = ();
414 foreach my $module (sort(keys(%modules))) {
415 if (($options->wine && $modules{$module}{wine}) ||
416 ($options->winetest && $modules{$module}{winetest}))
418 push @modules, $module;
422 my $progress_output;
423 my $progress_current = 0;
424 my $progress_max = scalar(@modules);
426 foreach my $module (@modules) {
427 my $dsp_file = $modules{$module}{dsp_file};
428 replace_file("$wine_dir/$dsp_file", \&_generate_dsp, $module);
431 sub _generate_dsp {
432 local *OUT = shift;
434 my $module = shift;
436 my $dsp_file = $modules{$module}{dsp_file};
437 my $project = $modules{$module}{project};
438 my @imports = @{$modules{$module}{imports}};
440 my $lib = ($modules{$module}{type} eq "lib");
441 my $dll = ($modules{$module}{type} eq "dll");
442 my $exe = ($modules{$module}{type} eq "exe");
444 my $console = $exe; # FIXME: Not always correct
446 my $msvc_wine_dir = do {
447 my @parts = split(m%/%, $dsp_file);
448 if($#parts == 1) {
449 "..";
450 } elsif($#parts == 2) {
451 "..\\..";
452 } else {
453 "..\\..\\..";
456 my $wine_include_dir = "$msvc_wine_dir\\include";
458 $progress_current++;
459 $output->progress("$dsp_file (file $progress_current of $progress_max)");
461 my @c_srcs = @{$modules{$module}{c_srcs}};
462 my @source_files = @{$modules{$module}{source_files}};
463 my @header_files = @{$modules{$module}{header_files}};
464 my @resource_files = @{$modules{$module}{resource_files}};
466 if ($project !~ /^(?:wine(?:_unicode)?|wine(?:build|test))$/ &&
467 $project !~ /^(?:gdi32|ntdll|user32)_.+?$/ &&
468 $project !~ /_test$/)
470 push @source_files, "$project.spec";
471 # push @source_files, "$project.spec.c";
472 @source_files = sort(@source_files);
475 my $no_cpp = 1;
476 my $no_msvc_headers = 1;
477 if ($project =~ /^(?:winetest)$/ || $project =~ /_test$/) {
478 $no_msvc_headers = 0;
481 my @cfgs;
483 push @cfgs, "$project - Win32";
485 if (!$no_cpp) {
486 my @_cfgs;
487 foreach my $cfg (@cfgs) {
488 push @_cfgs, "$cfg C";
489 push @_cfgs, "$cfg C++";
491 @cfgs = @_cfgs;
494 if (!$no_release) {
495 my @_cfgs;
496 foreach my $cfg (@cfgs) {
497 push @_cfgs, "$cfg Debug";
498 push @_cfgs, "$cfg Release";
500 @cfgs = @_cfgs;
503 if (!$no_msvc_headers) {
504 my @_cfgs;
505 foreach my $cfg (@cfgs) {
506 push @_cfgs, "$cfg MSVC Headers";
507 push @_cfgs, "$cfg Wine Headers";
509 @cfgs = @_cfgs;
512 my $default_cfg = $cfgs[$#cfgs];
514 print OUT "# Microsoft Developer Studio Project File - Name=\"$project\" - Package Owner=<4>\r\n";
515 print OUT "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n";
516 print OUT "# ** DO NOT EDIT **\r\n";
517 print OUT "\r\n";
519 if ($lib) {
520 print OUT "# TARGTYPE \"Win32 (x86) Static Library\" 0x0104\r\n";
521 } elsif ($dll) {
522 print OUT "# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\r\n";
523 } else {
524 print OUT "# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n";
526 print OUT "\r\n";
528 print OUT "CFG=$default_cfg\r\n";
529 print OUT "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n";
530 print OUT "!MESSAGE use the Export Makefile command and run\r\n";
531 print OUT "!MESSAGE \r\n";
532 print OUT "!MESSAGE NMAKE /f \"$project.mak\".\r\n";
533 print OUT "!MESSAGE \r\n";
534 print OUT "!MESSAGE You can specify a configuration when running NMAKE\r\n";
535 print OUT "!MESSAGE by defining the macro CFG on the command line. For example:\r\n";
536 print OUT "!MESSAGE \r\n";
537 print OUT "!MESSAGE NMAKE /f \"$project.mak\" CFG=\"$default_cfg\"\r\n";
538 print OUT "!MESSAGE \r\n";
539 print OUT "!MESSAGE Possible choices for configuration are:\r\n";
540 print OUT "!MESSAGE \r\n";
541 foreach my $cfg (@cfgs) {
542 if ($lib) {
543 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Static Library\")\r\n";
544 } elsif ($dll) {
545 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n";
546 } else {
547 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Console Application\")\r\n";
550 print OUT "!MESSAGE \r\n";
551 print OUT "\r\n";
553 print OUT "# Begin Project\r\n";
554 print OUT "# PROP AllowPerConfigDependencies 0\r\n";
555 print OUT "# PROP Scc_ProjName \"\"\r\n";
556 print OUT "# PROP Scc_LocalPath \"\"\r\n";
557 print OUT "CPP=cl.exe\r\n";
558 print OUT "MTL=midl.exe\r\n" if !$lib && !$exe;
559 print OUT "RSC=rc.exe\r\n";
561 my $n = 0;
563 my $output_dir;
564 foreach my $cfg (@cfgs) {
565 if($#cfgs == 0) {
566 # Nothing
567 } elsif($n == 0) {
568 print OUT "!IF \"\$(CFG)\" == \"$cfg\"\r\n";
569 print OUT "\r\n";
570 } else {
571 print OUT "\r\n";
572 print OUT "!ELSEIF \"\$(CFG)\" == \"$cfg\"\r\n";
573 print OUT "\r\n";
576 my $debug = ($cfg !~ /Release/);
577 my $msvc_headers = ($cfg =~ /MSVC Headers/);
579 print OUT "# PROP BASE Use_MFC 0\r\n";
581 if($debug) {
582 print OUT "# PROP BASE Use_Debug_Libraries 1\r\n";
583 } else {
584 print OUT "# PROP BASE Use_Debug_Libraries 0\r\n";
587 $output_dir = $cfg;
588 $output_dir =~ s/^$project - //;
589 $output_dir =~ s/ /_/g;
590 $output_dir =~ s/C\+\+/Cxx/g;
591 if($output_prefix_dir) {
592 $output_dir = "$output_prefix_dir\\$output_dir";
595 print OUT "# PROP BASE Output_Dir \"$output_dir\"\r\n";
596 print OUT "# PROP BASE Intermediate_Dir \"$output_dir\"\r\n";
598 print OUT "# PROP BASE Target_Dir \"\"\r\n";
600 print OUT "# PROP Use_MFC 0\r\n";
601 if($debug) {
602 print OUT "# PROP Use_Debug_Libraries 1\r\n";
603 } else {
604 print OUT "# PROP Use_Debug_Libraries 0\r\n";
606 print OUT "# PROP Output_Dir \"$output_dir\"\r\n";
607 print OUT "# PROP Intermediate_Dir \"$output_dir\"\r\n";
609 print OUT "# PROP Ignore_Export_Lib 0\r\n" if $dll;
610 print OUT "# PROP Target_Dir \"\"\r\n";
612 my @defines;
613 if($debug) {
614 if($lib || $exe) {
615 print OUT "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od";
616 @defines = (qw(WIN32 _DEBUG _MBCS _LIB));
617 } else {
618 print OUT "# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od";
619 @defines = (qw(WIN32 _DEBUG _WINDOWS _MBCS _USRDLL), ("\U${project}\E_EXPORTS"));
621 } else {
622 if($lib || $exe) {
623 print OUT "# ADD BASE CPP /nologo /W3 /GX /O2";
624 @defines = (qw(WIN32 NDEBUG _MBCS _LIB));
625 } else {
626 print OUT "# ADD BASE CPP /nologo /MT /W3 /GX /O2";
627 @defines = (qw(WIN32 NDEBUG _WINDOWS _MBCS _USRDLL), ("\U${project}\E_EXPORTS"));
631 foreach my $define (@defines) {
632 print OUT " /D \"$define\"";
634 print OUT " /YX" if $lib || $exe;
635 print OUT " /FD";
636 print OUT " /GZ" if $debug;
637 print OUT " " if $debug && ($lib || $exe);
638 print OUT " /c";
639 print OUT "\r\n";
641 my @defines2;
642 if($debug) {
643 if($lib) {
644 print OUT "# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od";
645 @defines2 = qw(WIN32 _DEBUG _WINDOWS _MBCS _LIB);
646 } else {
647 print OUT "# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od";
648 @defines2 = qw(_DEBUG WIN32 _WINDOWS _MBCS _USRDLL);
650 } else {
651 if($lib) {
652 print OUT "# ADD CPP /nologo /MT /W3 /GX /O2";
653 @defines2 = qw(WIN32 NDEBUG _WINDOWS _MBCS _LIB);
654 } else {
655 print OUT "# ADD CPP /nologo /MT /W3 /GX /O2";
656 @defines2 = qw(NDEBUG WIN32 _WINDOWS _MBCS _USRDLL);
660 my @includes = ();
661 if($wine) {
662 push @defines2, "_\U${project}\E_";
663 push @defines2, "__WINE__" if $project !~ /^(?:wine(?:build|test)|.*?_test)$/;
664 push @defines2, qw(__i386__ _X86_);
667 if($project =~ /^gdi32_(?:enhmfdrv|mfdrv|win16drv)$/) {
668 push @includes, "..";
671 if($project =~ /^user32_(?:controls|windows)$/) {
672 push @includes, "..\\dlls\\user";
675 if($project =~ /^user32_dde$/) {
676 push @includes, "..";
679 if ($project =~ /_test$/) {
680 push @includes, "$msvc_wine_dir\\programs\\winetest\\$output_dir";
683 if (!$msvc_headers || $project =~ /^winetest$/) {
684 push @includes, $wine_include_dir;
688 if($wine) {
689 foreach my $include (@includes) {
690 print OUT " /I \"$include\"";
694 foreach my $define (@defines2) {
695 print OUT " /D \"$define\"";
697 print OUT " /D inline=__inline" if $wine;
698 print OUT " /D \"__STDC__\"" if 0 && $wine;
700 print OUT " /YX" if $lib;
701 print OUT " /FR" if !$lib;
702 print OUT " /FD";
703 print OUT " /GZ" if $debug;
704 print OUT " " if $debug && $lib;
705 print OUT " /c";
706 print OUT " /TP" if !$no_cpp;
707 print OUT "\r\n";
709 if($debug) {
710 print OUT "# SUBTRACT CPP /X /YX\r\n" if $dll;
711 print OUT "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
712 print OUT "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
713 print OUT "# ADD BASE RSC /l 0x41d /d \"_DEBUG\"\r\n";
714 print OUT "# ADD RSC /l 0x41d";
715 if($wine) {
716 foreach my $include (@includes) {
717 print OUT " /i \"$include\"";
720 print OUT " /d \"_DEBUG\"\r\n";
721 } else {
722 print OUT "# SUBTRACT CPP /YX\r\n" if $dll;
723 print OUT "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
724 print OUT "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
725 print OUT "# ADD BASE RSC /l 0x41d /d \"NDEBUG\"\r\n";
726 print OUT "# ADD RSC /l 0x41d";
727 if($wine) {
728 foreach my $include (@includes) {
729 print OUT " /i \"$include\"";
732 print OUT "/d \"NDEBUG\"\r\n";
734 print OUT "BSC32=bscmake.exe\r\n";
735 print OUT "# ADD BASE BSC32 /nologo\r\n";
736 print OUT "# ADD BSC32 /nologo\r\n";
738 if($exe || $dll) {
739 print OUT "LINK32=link.exe\r\n";
740 print OUT "# ADD BASE LINK32 ";
741 my @libraries = qw(kernel32.lib user32.lib gdi32.lib winspool.lib
742 comdlg32.lib advapi32.lib shell32.lib ole32.lib
743 oleaut32.lib uuid.lib odbc32.lib odbccp32.lib);
744 foreach my $library (@libraries) {
745 print OUT "$library ";
747 print OUT " /nologo";
748 print OUT " /dll" if $dll;
749 print OUT " /subsystem:console" if $console;
750 print OUT " /debug" if $debug;
751 print OUT " /machine:I386";
752 print OUT " /pdbtype:sept" if $debug;
753 print OUT "\r\n";
755 print OUT "# ADD LINK32";
756 print OUT " /nologo";
757 print OUT " libcmt.lib" if $project =~ /^ntdll$/; # FIXME: Kludge
758 foreach my $import (@imports) {
759 print OUT " $import.lib";
761 print OUT " /dll" if $dll;
762 print OUT " /subsystem:console" if $console;
763 print OUT " /debug" if $debug;
764 print OUT " /machine:I386";
765 print OUT " /nodefaultlib" if $project =~ /^ntdll$/; # FIXME: Kludge
766 print OUT " /def:\"$project.def\"" if $dll;
767 print OUT " /pdbtype:sept" if $debug;
768 print OUT "\r\n";
769 } else {
770 print OUT "LIB32=link.exe -lib\r\n";
771 print OUT "# ADD BASE LIB32 /nologo\r\n";
772 print OUT "# ADD LIB32 /nologo\r\n";
775 $n++;
778 if($#cfgs != 0) {
779 print OUT "\r\n";
780 print OUT "!ENDIF \r\n";
781 print OUT "\r\n";
784 if ($project eq "winebuild") {
785 print OUT "# Begin Special Build Tool\r\n";
786 print OUT "SOURCE=\"\$(InputPath)\"\r\n";
787 print OUT "PostBuild_Desc=Copying wine.dll and wine_unicode.dll ...\r\n";
788 print OUT "PostBuild_Cmds=";
789 print OUT "copy ..\\..\\library\\$output_dir\\wine.dll \$(OutDir)\t";
790 print OUT "copy ..\\..\\unicode\\$output_dir\\wine_unicode.dll \$(OutDir)\r\n";
791 print OUT "# End Special Build Tool\r\n";
792 } elsif (0 && $project eq "winetest") {
793 print OUT "# Begin Special Build Tool\r\n";
794 print OUT "SOURCE=\"\$(InputPath)\"\r\n";
796 my @includes = qw(exception.h test.h unicode.h);
797 print OUT "PostBuild_Desc=Copying ";
798 foreach my $include (@includes) {
799 print OUT "wine\\$include ";
801 print OUT "...\r\n";
802 print OUT "PostBuild_Cmds=";
803 print OUT "mkdir \$(OutDir)\\wine\t";
804 foreach my $include (@includes) {
805 print OUT "\t";
806 print OUT "copy $msvc_wine_dir\\include\\wine\\$include \$(OutDir)\\wine";
808 print OUT "\r\n";
809 print OUT "# End Special Build Tool\r\n";
811 print OUT "# Begin Target\r\n";
812 print OUT "\r\n";
813 foreach my $cfg (@cfgs) {
814 print OUT "# Name \"$cfg\"\r\n";
817 print OUT "# Begin Group \"Source Files\"\r\n";
818 print OUT "\r\n";
819 print OUT "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
821 foreach my $source_file (@source_files) {
822 $source_file =~ s%/%\\%g;
823 if($source_file !~ /^\./) {
824 $source_file = ".\\$source_file";
827 if($source_file =~ /^(.*?)\.spec$/) {
828 my $basename = $1;
830 $basename = "$basename.dll" if $basename !~ /\..{1,3}$/;
831 my $dbg_c_file = "$basename.dbg.c";
833 print OUT "# Begin Source File\r\n";
834 print OUT "\r\n";
835 print OUT "SOURCE=$dbg_c_file\r\n";
836 print OUT "# End Source File\r\n";
839 print OUT "# Begin Source File\r\n";
840 print OUT "\r\n";
842 print OUT "SOURCE=$source_file\r\n";
844 if($source_file =~ /^(.*?)\.spec$/) {
845 my $basename = $1;
847 my $spec_file = $source_file;
848 my $def_file = "$basename.def";
850 $basename = "$basename.dll" if $basename !~ /\..{1,3}$/;
851 my $dbg_file = "$basename.dbg";
852 my $dbg_c_file = "$basename.dbg.c";
854 my $srcdir = "."; # FIXME: Is this really always correct?
856 print OUT "# Begin Custom Build\r\n";
857 print OUT "InputPath=$spec_file\r\n";
858 print OUT "\r\n";
859 print OUT "BuildCmds= \\\r\n";
860 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe -def $spec_file > $def_file \\\r\n";
862 if($project =~ /^ntdll$/) {
863 my $n = 0;
864 foreach my $c_src (@c_srcs) {
865 if($n++ > 0) {
866 print OUT "\techo $c_src >> $dbg_file \\\r\n";
867 } else {
868 print OUT "\techo $c_src > $dbg_file \\\r\n";
871 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe";
872 print OUT " -o $dbg_c_file -debug -C$srcdir $dbg_file \\\r\n";
873 } else {
874 my $c_srcs = join(" ", grep(/\.c$/, @c_srcs));
876 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe";
877 print OUT " -o $dbg_c_file -debug -C$srcdir $c_srcs \\\r\n";
880 print OUT "\t\r\n";
881 print OUT "\r\n";
882 print OUT "\"$def_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
883 print OUT " \$(BuildCmds)\r\n";
884 print OUT "\r\n";
885 print OUT "\"$dbg_c_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
886 print OUT " \$(BuildCmds)\r\n";
887 print OUT "# End Custom Build\r\n";
888 } elsif($source_file =~ /([^\\]*?\.h)$/) {
889 my $h_file = $1;
891 foreach my $cfg (@cfgs) {
892 if($#cfgs == 0) {
893 # Nothing
894 } elsif($n == 0) {
895 print OUT "!IF \"\$(CFG)\" == \"$cfg\"\r\n";
896 print OUT "\r\n";
897 } else {
898 print OUT "\r\n";
899 print OUT "!ELSEIF \"\$(CFG)\" == \"$cfg\"\r\n";
900 print OUT "\r\n";
903 $output_dir = $cfg;
904 $output_dir =~ s/^$project - //;
905 $output_dir =~ s/ /_/g;
906 $output_dir =~ s/C\+\+/Cxx/g;
907 if($output_prefix_dir) {
908 $output_dir = "$output_prefix_dir\\$output_dir";
911 print OUT "# Begin Custom Build\r\n";
912 print OUT "OutDir=$output_dir\r\n";
913 print OUT "InputPath=$source_file\r\n";
914 print OUT "\r\n";
915 print OUT "\"\$(OutDir)\\wine\\$h_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
916 print OUT "\tcopy \$(InputPath) \$(OutDir)\\wine\r\n";
917 print OUT "\r\n";
918 print OUT "# End Custom Build\r\n";
921 if($#cfgs != 0) {
922 print OUT "\r\n";
923 print OUT "!ENDIF \r\n";
924 print OUT "\r\n";
928 print OUT "# End Source File\r\n";
930 print OUT "# End Group\r\n";
932 print OUT "# Begin Group \"Header Files\"\r\n";
933 print OUT "\r\n";
934 print OUT "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
935 foreach my $header_file (@header_files) {
936 print OUT "# Begin Source File\r\n";
937 print OUT "\r\n";
938 print OUT "SOURCE=.\\$header_file\r\n";
939 print OUT "# End Source File\r\n";
941 print OUT "# End Group\r\n";
945 print OUT "# Begin Group \"Resource Files\"\r\n";
946 print OUT "\r\n";
947 print OUT "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
948 foreach my $resource_file (@resource_files) {
949 print OUT "# Begin Source File\r\n";
950 print OUT "\r\n";
951 print OUT "SOURCE=.\\$resource_file\r\n";
952 print OUT "# End Source File\r\n";
954 print OUT "# End Group\r\n";
956 print OUT "# End Target\r\n";
957 print OUT "# End Project\r\n";
959 close(OUT);
962 sub _generate_dsw_header {
963 local *OUT = shift;
965 print OUT "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n";
966 print OUT "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n";
967 print OUT "\r\n";
970 sub _generate_dsw_project {
971 local *OUT = shift;
973 my $project = shift;
974 my $dsp_file = shift;
975 my @dependencies = @{(shift)};
977 $dsp_file = "./$dsp_file";
978 $dsp_file =~ y%/%\\%;
980 @dependencies = sort(@dependencies);
982 print OUT "###############################################################################\r\n";
983 print OUT "\r\n";
984 print OUT "Project: \"$project\"=$dsp_file - Package Owner=<4>\r\n";
985 print OUT "\r\n";
986 print OUT "Package=<5>\r\n";
987 print OUT "{{{\r\n";
988 print OUT "}}}\r\n";
989 print OUT "\r\n";
990 print OUT "Package=<4>\r\n";
991 print OUT "{{{\r\n";
992 foreach my $dependency (@dependencies) {
993 print OUT " Begin Project Dependency\r\n";
994 print OUT " Project_Dep_Name $dependency\r\n";
995 print OUT " End Project Dependency\r\n";
997 print OUT "}}}\r\n";
998 print OUT "\r\n";
1001 sub _generate_dsw_footer {
1002 local *OUT = shift;
1004 print OUT "###############################################################################\r\n";
1005 print OUT "\r\n";
1006 print OUT "Global:\r\n";
1007 print OUT "\r\n";
1008 print OUT "Package=<5>\r\n";
1009 print OUT "{{{\r\n";
1010 print OUT "}}}\r\n";
1011 print OUT "\r\n";
1012 print OUT "Package=<3>\r\n";
1013 print OUT "{{{\r\n";
1014 print OUT "}}}\r\n";
1015 print OUT "\r\n";
1016 print OUT "###############################################################################\r\n";
1017 print OUT "\r\n";
1020 if ($options->wine) {
1021 my $dsw_file = "wine.dsw";
1022 $output->progress("$dsw_file");
1023 replace_file("$wine_dir/$dsw_file", \&_generate_wine_dsw);
1026 sub _generate_wine_dsw {
1027 local *OUT = shift;
1029 _generate_dsw_header(\*OUT);
1030 foreach my $module (sort(keys(%modules))) {
1031 next if $module =~ /(?:winetest\.lib|_test\.exe)$/;
1033 my $project = $modules{$module}{project};
1034 my $dsp_file = $modules{$module}{dsp_file};
1036 my @dependencies;
1037 if($project =~ /^wine(?:_unicode)?$/) {
1038 @dependencies = ();
1039 } elsif($project =~ /^winebuild$/) {
1040 @dependencies = ("wine", "wine_unicode");
1041 } elsif($project =~ /^(?:gdi32|ntdll|user32)_.+?$/) {
1042 @dependencies = ();
1043 } else {
1044 @dependencies = ("wine", "wine_unicode", "winebuild");
1047 if($project =~ /^gdi32$/) {
1048 foreach my $dir (@gdi32_dirs) {
1049 my $dir2 = $dir;
1050 $dir2 =~ s%^.*?/([^/]+)$%$1%;
1052 my $module = "gdi32_$dir2";
1053 $module =~ s%/%_%g;
1054 push @dependencies, $module;
1056 } elsif($project =~ /^ntdll$/) {
1057 foreach my $dir (@ntdll_dirs) {
1058 my $module = "ntdll_$dir";
1059 $module =~ s%/%_%g;
1060 push @dependencies, $module;
1062 } elsif($project =~ /^user32$/) {
1063 foreach my $dir (@user32_dirs) {
1064 my $dir2 = $dir;
1065 $dir2 =~ s%^.*?/([^/]+)$%$1%;
1067 my $module = "user32_$dir2";
1068 $module =~ s%/%_%g;
1069 push @dependencies, $module;
1073 _generate_dsw_project(\*OUT, $project, $dsp_file, \@dependencies);
1075 _generate_dsw_footer(\*OUT);
1077 return 1;
1080 if ($options->winetest) {
1081 my $dsw_file = "winetest.dsw";
1082 $output->progress("$dsw_file");
1083 replace_file("$wine_dir/$dsw_file", \&_generate_winetest_dsw);
1086 sub _generate_winetest_dsw {
1087 local *OUT = shift;
1089 _generate_dsw_header(\*OUT);
1091 foreach my $module (sort(keys(%modules))) {
1092 next if $module !~ /(?:winetest\.lib|_test\.exe)$/;
1094 my $project = $modules{$module}{project};
1095 my $dsp_file = $modules{$module}{dsp_file};
1097 my @dependencies;
1098 if($project =~ /^winetest$/) {
1099 @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 sub _generate_testlist_c {
1126 local *OUT = shift;
1128 my @tests = @{(shift)};
1130 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n";
1131 print OUT "\n";
1132 print OUT "#include <stdio.h>\n";
1133 print OUT "#include <stdlib.h>\n";
1134 print OUT "#include \"windef.h\"\n";
1135 print OUT "#include \"winbase.h\"\n";
1136 print OUT "\n";
1137 foreach my $test (@tests) {
1138 print OUT "extern void func_$test(void);\n";
1140 print OUT "\n";
1141 print OUT "struct test\n";
1142 print OUT "{\n";
1143 print OUT " const char *name;\n";
1144 print OUT " void (*func)(void);\n";
1145 print OUT "};\n";
1146 print OUT "\n";
1147 print OUT "static 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";
1154 print OUT "\n";
1155 print OUT "#define WINETEST_WANT_MAIN\n";
1156 print OUT "#include \"wine/test.h\"\n";
1159 if ($options->wine) {
1160 my $config_h = "include/config.h";
1162 $output->progress("$config_h");
1164 replace_file("$wine_dir/$config_h", \&_generate_config_h);
1167 sub _generate_config_h {
1168 local *OUT = shift;
1170 print OUT "#define __WINE_CONFIG_H\n";
1171 print OUT "\n";
1173 my @headers = qw(direct.h io.h);
1174 foreach my $header (@headers) {
1175 $header =~ y/\.\//__/;
1176 print OUT "#define HAVE_\U$header\E\n";
1177 print OUT "\n";
1180 my @functions = qw(
1181 _alldiv _allmul _allrem _aulldiv _aullrem
1182 _access _chdir _close _lseek _mkdir _open _pclose _popen _read _rmdir _write _stat
1183 _snprintf _stricmp _strnicmp _vsnprintf _wcsicmp wcslen
1184 ecvt fcvt gcvt
1185 strerror
1187 foreach my $function (@functions) {
1188 print OUT "#define HAVE_\U$function\E 1\n";
1189 print OUT "\n";
1192 if(0) {
1193 print OUT "#define NEED_STDCALL_DECORATION 1\n";
1194 print OUT "\n";
1197 print OUT "#define X_DISPLAY_MISSING 1\n";
1198 print OUT "\n";
1200 print OUT "/* Define to a macro to generate an assembly function directive */\n";
1201 print OUT "#define __ASM_FUNC(name) \"\"\n";
1202 print OUT "\n";
1204 print OUT "/* Define to a macro to generate an assembly name from a C symbol */\n";
1205 print OUT "#define __ASM_NAME(name) name\n";
1206 print OUT "\n";
1208 print OUT "/* Define to the address where bug reports for this package should be sent. */\n";
1209 print OUT "#define PACKAGE_BUGREPORT \"\"\n";
1210 print OUT "\n";
1212 print OUT "/* Define to the full name of this package. */\n";
1213 print OUT "#define PACKAGE_NAME \"Wine\"\n";
1214 print OUT "\n";
1216 print OUT "/* Define to the full name and version of this package. */\n";
1217 print OUT "#define PACKAGE_STRING \"Wine YYYYMMDD\"\n";
1218 print OUT "\n";
1220 print OUT "/* Define to the one symbol short name of this package. */\n";
1221 print OUT "#define PACKAGE_TARNAME \"wine\"\n";
1222 print OUT "\n";
1224 print OUT "/* Define to the version of this package. */\n";
1225 print OUT "#define PACKAGE_VERSION \"YYYYMMDD\"\n";
1226 print OUT "\n";
1228 close(OUT);