The link command specifies which version of the C library to link with
[wine/multimedia.git] / tools / winapi / msvcmaker
blobb19ad14fc1c623f09d398cd4e6098610bb8ae3ad
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{"wineruntests.dsp"}{files} = ["runtests.c"];
347 $wine_test_dsp_files{"wineruntests.dsp"}{imports} = [];
349 $wine_test_dsp_files{"winetest.dsp"}{files} = [
350 'include/wine/exception.h',
351 'include/wine/test.h',
352 'include/wine/unicode.h'
354 $wine_test_dsp_files{"winetest.dsp"}{imports} = [];
356 my %runtests = ();
358 foreach my $dsp_file (keys(%wine_test_dsp_files)) {
359 my $project = $dsp_file;
360 $project =~ s%^(?:.*?/)?([^/]+)\.dsp$%$1%;
362 my @files = @{$wine_test_dsp_files{$dsp_file}{files}};
363 my @imports = @{$wine_test_dsp_files{$dsp_file}{imports}};
365 my $type;
366 my $c_srcs = [];
367 my $source_files = [];
368 my $header_files = [];
369 my $resource_files = [];
371 my @tests = ();
373 if ($project eq "winetest") {
374 $type = "lib";
375 $c_srcs = [@files];
376 $source_files = [@files];
377 $header_files = [];
378 $resource_files = [];
379 } elsif ($project eq "wineruntests") {
380 $type = "exe";
381 $c_srcs = [@files];
382 $source_files = [@files];
383 $header_files = [];
384 $resource_files = [];
385 } else {
386 $type = "exe";
387 $c_srcs = [@files];
388 $source_files = [@files];
389 $header_files = [];
390 $resource_files = [];
392 @tests = map {
393 if (/^testlist\.c$/) {
395 } else {
396 s/\.c$//;
399 } @files;
401 $runtests{$dsp_file} = [@tests];
403 my $module = "$project.$type";
405 $modules{$module}{wine} = 0;
406 $modules{$module}{winetest} = 1;
408 $modules{$module}{project} = $project;
409 $modules{$module}{type} = $type;
410 $modules{$module}{dsp_file} = $dsp_file;
411 $modules{$module}{c_srcs} = $c_srcs;
412 $modules{$module}{source_files} = $source_files;
413 $modules{$module}{header_files} = $header_files;
414 $modules{$module}{resource_files} = $resource_files;
415 $modules{$module}{imports} = [@imports];
417 $modules{$module}{tests} = [@tests];
420 foreach my $module (sort(keys(%modules))) {
421 if($module =~ /^(?:ttydrv.dll|x11drv.dll)$/) {
422 delete $modules{$module};
426 my @modules = ();
427 foreach my $module (sort(keys(%modules))) {
428 if (($options->wine && $modules{$module}{wine}) ||
429 ($options->winetest && $modules{$module}{winetest}))
431 push @modules, $module;
435 my $progress_output;
436 my $progress_current = 0;
437 my $progress_max = scalar(@modules);
439 foreach my $module (@modules) {
440 my $dsp_file = $modules{$module}{dsp_file};
441 replace_file("$wine_dir/$dsp_file", \&_generate_dsp, $module);
444 sub _generate_dsp {
445 local *OUT = shift;
447 my $module = shift;
449 my $dsp_file = $modules{$module}{dsp_file};
450 my $project = $modules{$module}{project};
451 my @imports = @{$modules{$module}{imports}};
453 my $lib = ($modules{$module}{type} eq "lib");
454 my $dll = ($modules{$module}{type} eq "dll");
455 my $exe = ($modules{$module}{type} eq "exe");
457 my $console = $exe; # FIXME: Not always correct
459 my $msvc_wine_dir = do {
460 my @parts = split(m%/%, $dsp_file);
461 if($#parts == 1) {
462 "..";
463 } elsif($#parts == 2) {
464 "..\\..";
465 } else {
466 "..\\..\\..";
469 my $wine_include_dir = "$msvc_wine_dir\\include";
471 $progress_current++;
472 $output->progress("$dsp_file (file $progress_current of $progress_max)");
474 my @c_srcs = @{$modules{$module}{c_srcs}};
475 my @source_files = @{$modules{$module}{source_files}};
476 my @header_files = @{$modules{$module}{header_files}};
477 my @resource_files = @{$modules{$module}{resource_files}};
479 if ($project !~ /^(?:wine(?:_unicode)?|wine(?:build|runtests|test))$/ &&
480 $project !~ /^(?:gdi32|ntdll|user32)_.+?$/ &&
481 $project !~ /_test$/)
483 push @source_files, "$project.spec";
484 # push @source_files, "$project.spec.c";
485 @source_files = sort(@source_files);
488 my $no_cpp = 1;
489 my $no_msvc_headers = 1;
490 if ($project =~ /^(?:wine(?:runtests|test))$/ || $project =~ /_test$/) {
491 $no_msvc_headers = 0;
494 my @cfgs;
496 push @cfgs, "$project - Win32";
498 if (!$no_cpp) {
499 my @_cfgs;
500 foreach my $cfg (@cfgs) {
501 push @_cfgs, "$cfg C";
502 push @_cfgs, "$cfg C++";
504 @cfgs = @_cfgs;
507 if (!$no_release) {
508 my @_cfgs;
509 foreach my $cfg (@cfgs) {
510 push @_cfgs, "$cfg Debug";
511 push @_cfgs, "$cfg Release";
513 @cfgs = @_cfgs;
516 if (!$no_msvc_headers) {
517 my @_cfgs;
518 foreach my $cfg (@cfgs) {
519 push @_cfgs, "$cfg MSVC Headers";
520 push @_cfgs, "$cfg Wine Headers";
522 @cfgs = @_cfgs;
525 my $default_cfg = $cfgs[$#cfgs];
527 print OUT "# Microsoft Developer Studio Project File - Name=\"$project\" - Package Owner=<4>\r\n";
528 print OUT "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n";
529 print OUT "# ** DO NOT EDIT **\r\n";
530 print OUT "\r\n";
532 if ($lib) {
533 print OUT "# TARGTYPE \"Win32 (x86) Static Library\" 0x0104\r\n";
534 } elsif ($dll) {
535 print OUT "# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\r\n";
536 } else {
537 print OUT "# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n";
539 print OUT "\r\n";
541 print OUT "CFG=$default_cfg\r\n";
542 print OUT "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n";
543 print OUT "!MESSAGE use the Export Makefile command and run\r\n";
544 print OUT "!MESSAGE \r\n";
545 print OUT "!MESSAGE NMAKE /f \"$project.mak\".\r\n";
546 print OUT "!MESSAGE \r\n";
547 print OUT "!MESSAGE You can specify a configuration when running NMAKE\r\n";
548 print OUT "!MESSAGE by defining the macro CFG on the command line. For example:\r\n";
549 print OUT "!MESSAGE \r\n";
550 print OUT "!MESSAGE NMAKE /f \"$project.mak\" CFG=\"$default_cfg\"\r\n";
551 print OUT "!MESSAGE \r\n";
552 print OUT "!MESSAGE Possible choices for configuration are:\r\n";
553 print OUT "!MESSAGE \r\n";
554 foreach my $cfg (@cfgs) {
555 if ($lib) {
556 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Static Library\")\r\n";
557 } elsif ($dll) {
558 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n";
559 } else {
560 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Console Application\")\r\n";
563 print OUT "!MESSAGE \r\n";
564 print OUT "\r\n";
566 print OUT "# Begin Project\r\n";
567 print OUT "# PROP AllowPerConfigDependencies 0\r\n";
568 print OUT "# PROP Scc_ProjName \"\"\r\n";
569 print OUT "# PROP Scc_LocalPath \"\"\r\n";
570 print OUT "CPP=cl.exe\r\n";
571 print OUT "MTL=midl.exe\r\n" if !$lib && !$exe;
572 print OUT "RSC=rc.exe\r\n";
574 my $n = 0;
576 my $output_dir;
577 foreach my $cfg (@cfgs) {
578 if($#cfgs == 0) {
579 # Nothing
580 } elsif($n == 0) {
581 print OUT "!IF \"\$(CFG)\" == \"$cfg\"\r\n";
582 print OUT "\r\n";
583 } else {
584 print OUT "\r\n";
585 print OUT "!ELSEIF \"\$(CFG)\" == \"$cfg\"\r\n";
586 print OUT "\r\n";
589 my $debug = ($cfg !~ /Release/);
590 my $msvc_headers = ($cfg =~ /MSVC Headers/);
592 print OUT "# PROP BASE Use_MFC 0\r\n";
594 if($debug) {
595 print OUT "# PROP BASE Use_Debug_Libraries 1\r\n";
596 } else {
597 print OUT "# PROP BASE Use_Debug_Libraries 0\r\n";
600 $output_dir = $cfg;
601 $output_dir =~ s/^$project - //;
602 $output_dir =~ s/ /_/g;
603 $output_dir =~ s/C\+\+/Cxx/g;
604 if($output_prefix_dir) {
605 $output_dir = "$output_prefix_dir\\$output_dir";
608 print OUT "# PROP BASE Output_Dir \"$output_dir\"\r\n";
609 print OUT "# PROP BASE Intermediate_Dir \"$output_dir\"\r\n";
611 print OUT "# PROP BASE Target_Dir \"\"\r\n";
613 print OUT "# PROP Use_MFC 0\r\n";
614 if($debug) {
615 print OUT "# PROP Use_Debug_Libraries 1\r\n";
616 } else {
617 print OUT "# PROP Use_Debug_Libraries 0\r\n";
619 print OUT "# PROP Output_Dir \"$output_dir\"\r\n";
620 print OUT "# PROP Intermediate_Dir \"$output_dir\"\r\n";
622 print OUT "# PROP Ignore_Export_Lib 0\r\n" if $dll;
623 print OUT "# PROP Target_Dir \"\"\r\n";
625 my @defines;
626 if($debug) {
627 if($lib || $exe) {
628 print OUT "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od";
629 @defines = (qw(WIN32 _DEBUG _MBCS _LIB));
630 } else {
631 print OUT "# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od";
632 @defines = (qw(WIN32 _DEBUG _WINDOWS _MBCS _USRDLL), ("\U${project}\E_EXPORTS"));
634 } else {
635 if($lib || $exe) {
636 print OUT "# ADD BASE CPP /nologo /W3 /GX /O2";
637 @defines = (qw(WIN32 NDEBUG _MBCS _LIB));
638 } else {
639 print OUT "# ADD BASE CPP /nologo /MT /W3 /GX /O2";
640 @defines = (qw(WIN32 NDEBUG _WINDOWS _MBCS _USRDLL), ("\U${project}\E_EXPORTS"));
644 foreach my $define (@defines) {
645 print OUT " /D \"$define\"";
647 print OUT " /YX" if $lib || $exe;
648 print OUT " /FD";
649 print OUT " /GZ" if $debug;
650 print OUT " " if $debug && ($lib || $exe);
651 print OUT " /c";
652 print OUT "\r\n";
654 my @defines2;
655 if($debug) {
656 if($lib) {
657 print OUT "# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od";
658 @defines2 = qw(WIN32 _DEBUG _WINDOWS _MBCS _LIB);
659 } else {
660 print OUT "# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od";
661 @defines2 = qw(_DEBUG WIN32 _WINDOWS _MBCS _USRDLL);
663 } else {
664 if($lib) {
665 print OUT "# ADD CPP /nologo /MT /W3 /GX /O2";
666 @defines2 = qw(WIN32 NDEBUG _WINDOWS _MBCS _LIB);
667 } else {
668 print OUT "# ADD CPP /nologo /MT /W3 /GX /O2";
669 @defines2 = qw(NDEBUG WIN32 _WINDOWS _MBCS _USRDLL);
673 my @includes = ();
674 if($wine) {
675 push @defines2, "_\U${project}\E_";
676 push @defines2, qw(__WINE__) if $project !~ /^(?:wine(?:build|test)|.*?_test)$/;
677 push @defines2, qw(__WINE_USE_MSVCRT);
678 my $output_dir2 = $output_dir;
679 $output_dir =~ s/\\/\\\\/g;
680 push @defines2, "__WINETEST_OUTPUT_DIR=\\\"$output_dir\\\"";
681 push @defines2, qw(__i386__ _X86_);
683 if($project =~ /^gdi32_(?:enhmfdrv|mfdrv|win16drv)$/) {
684 push @includes, "..";
687 if($project =~ /^user32_(?:controls|windows)$/) {
688 push @includes, "..\\dlls\\user";
691 if($project =~ /^user32_dde$/) {
692 push @includes, "..";
695 if ($project =~ /_test$/) {
696 push @includes, "$msvc_wine_dir\\$output_dir";
699 if (!$msvc_headers || $project =~ /^winetest$/) {
700 push @includes, $wine_include_dir;
704 if($wine) {
705 foreach my $include (@includes) {
706 if ($include !~ /[\\\"]/) {
707 print OUT " /I \"$include\"";
708 } else {
709 print OUT " /I $include";
714 foreach my $define (@defines2) {
715 if ($define !~ /[\\\"]/) {
716 print OUT " /D \"$define\"";
717 } else {
718 print OUT " /D $define";
721 print OUT " /D inline=__inline" if $wine;
722 print OUT " /D \"__STDC__\"" if 0 && $wine;
724 print OUT " /YX" if $lib;
725 print OUT " /FR" if !$lib;
726 print OUT " /FD";
727 print OUT " /GZ" if $debug;
728 print OUT " " if $debug && $lib;
729 print OUT " /c";
730 print OUT " /TP" if !$no_cpp;
731 print OUT "\r\n";
733 if($debug) {
734 print OUT "# SUBTRACT CPP /X /YX\r\n" if $dll;
735 print OUT "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
736 print OUT "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
737 print OUT "# ADD BASE RSC /l 0x41d /d \"_DEBUG\"\r\n";
738 print OUT "# ADD RSC /l 0x41d";
739 if($wine) {
740 foreach my $include (@includes) {
741 print OUT " /i \"$include\"";
744 print OUT " /d \"_DEBUG\"\r\n";
745 } else {
746 print OUT "# SUBTRACT CPP /YX\r\n" if $dll;
747 print OUT "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
748 print OUT "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
749 print OUT "# ADD BASE RSC /l 0x41d /d \"NDEBUG\"\r\n";
750 print OUT "# ADD RSC /l 0x41d";
751 if($wine) {
752 foreach my $include (@includes) {
753 print OUT " /i \"$include\"";
756 print OUT "/d \"NDEBUG\"\r\n";
758 print OUT "BSC32=bscmake.exe\r\n";
759 print OUT "# ADD BASE BSC32 /nologo\r\n";
760 print OUT "# ADD BSC32 /nologo\r\n";
762 if($exe || $dll) {
763 print OUT "LINK32=link.exe\r\n";
764 print OUT "# ADD BASE LINK32 ";
765 my @libraries = qw(kernel32.lib user32.lib gdi32.lib winspool.lib
766 comdlg32.lib advapi32.lib shell32.lib ole32.lib
767 oleaut32.lib uuid.lib odbc32.lib odbccp32.lib);
768 foreach my $library (@libraries) {
769 print OUT "$library ";
771 print OUT " /nologo";
772 print OUT " /dll" if $dll;
773 print OUT " /subsystem:console" if $console;
774 print OUT " /debug" if $debug;
775 print OUT " /machine:I386";
776 print OUT " /pdbtype:sept" if $debug;
777 print OUT "\r\n";
779 print OUT "# ADD LINK32";
780 print OUT " /nologo";
781 print OUT " libcmt.lib" if $project =~ /^ntdll$/; # FIXME: Kludge
782 foreach my $import (@imports) {
783 print OUT " $import.lib" if ($import ne "msvcrt");
785 print OUT " /dll" if $dll;
786 print OUT " /subsystem:console" if $console;
787 print OUT " /debug" if $debug;
788 print OUT " /machine:I386";
789 print OUT " /nodefaultlib" if $project =~ /^ntdll$/; # FIXME: Kludge
790 print OUT " /def:\"$project.def\"" if $dll;
791 print OUT " /pdbtype:sept" if $debug;
792 print OUT "\r\n";
793 } else {
794 print OUT "LIB32=link.exe -lib\r\n";
795 print OUT "# ADD BASE LIB32 /nologo\r\n";
796 print OUT "# ADD LIB32 /nologo\r\n";
799 $n++;
802 if($#cfgs != 0) {
803 print OUT "\r\n";
804 print OUT "!ENDIF \r\n";
805 print OUT "\r\n";
808 if ($project eq "winebuild") {
809 print OUT "# Begin Special Build Tool\r\n";
810 print OUT "SOURCE=\"\$(InputPath)\"\r\n";
811 print OUT "PostBuild_Desc=Copying wine.dll and wine_unicode.dll ...\r\n";
812 print OUT "PostBuild_Cmds=";
813 print OUT "copy ..\\..\\library\\$output_dir\\wine.dll \$(OutDir)\t";
814 print OUT "copy ..\\..\\unicode\\$output_dir\\wine_unicode.dll \$(OutDir)\r\n";
815 print OUT "# End Special Build Tool\r\n";
817 print OUT "# Begin Target\r\n";
818 print OUT "\r\n";
819 foreach my $cfg (@cfgs) {
820 print OUT "# Name \"$cfg\"\r\n";
823 print OUT "# Begin Group \"Source Files\"\r\n";
824 print OUT "\r\n";
825 print OUT "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
827 foreach my $source_file (@source_files) {
828 $source_file =~ s%/%\\%g;
829 if($source_file !~ /^\./) {
830 $source_file = ".\\$source_file";
833 if($source_file =~ /^(.*?)\.spec$/) {
834 my $basename = $1;
836 $basename = "$basename.dll" if $basename !~ /\..{1,3}$/;
837 my $dbg_c_file = "$basename.dbg.c";
839 print OUT "# Begin Source File\r\n";
840 print OUT "\r\n";
841 print OUT "SOURCE=$dbg_c_file\r\n";
842 print OUT "# End Source File\r\n";
845 print OUT "# Begin Source File\r\n";
846 print OUT "\r\n";
848 print OUT "SOURCE=$source_file\r\n";
850 if($source_file =~ /^(.*?)\.spec$/) {
851 my $basename = $1;
853 my $spec_file = $source_file;
854 my $def_file = "$basename.def";
856 $basename = "$basename.dll" if $basename !~ /\..{1,3}$/;
857 my $dbg_file = "$basename.dbg";
858 my $dbg_c_file = "$basename.dbg.c";
860 my $srcdir = "."; # FIXME: Is this really always correct?
862 print OUT "# Begin Custom Build\r\n";
863 print OUT "InputPath=$spec_file\r\n";
864 print OUT "\r\n";
865 print OUT "BuildCmds= \\\r\n";
866 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe -def $spec_file > $def_file \\\r\n";
868 if($project =~ /^ntdll$/) {
869 my $n = 0;
870 foreach my $c_src (@c_srcs) {
871 if($n++ > 0) {
872 print OUT "\techo $c_src >> $dbg_file \\\r\n";
873 } else {
874 print OUT "\techo $c_src > $dbg_file \\\r\n";
877 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe";
878 print OUT " -o $dbg_c_file -debug -C$srcdir $dbg_file \\\r\n";
879 } else {
880 my $c_srcs = join(" ", grep(/\.c$/, @c_srcs));
882 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe";
883 print OUT " -o $dbg_c_file -debug -C$srcdir $c_srcs \\\r\n";
886 print OUT "\t\r\n";
887 print OUT "\r\n";
888 print OUT "\"$def_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
889 print OUT " \$(BuildCmds)\r\n";
890 print OUT "\r\n";
891 print OUT "\"$dbg_c_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
892 print OUT " \$(BuildCmds)\r\n";
893 print OUT "# End Custom Build\r\n";
894 } elsif($source_file =~ /([^\\]*?\.h)$/) {
895 my $h_file = $1;
897 foreach my $cfg (@cfgs) {
898 if($#cfgs == 0) {
899 # Nothing
900 } elsif($n == 0) {
901 print OUT "!IF \"\$(CFG)\" == \"$cfg\"\r\n";
902 print OUT "\r\n";
903 } else {
904 print OUT "\r\n";
905 print OUT "!ELSEIF \"\$(CFG)\" == \"$cfg\"\r\n";
906 print OUT "\r\n";
909 $output_dir = $cfg;
910 $output_dir =~ s/^$project - //;
911 $output_dir =~ s/ /_/g;
912 $output_dir =~ s/C\+\+/Cxx/g;
913 if($output_prefix_dir) {
914 $output_dir = "$output_prefix_dir\\$output_dir";
917 print OUT "# Begin Custom Build\r\n";
918 print OUT "OutDir=$output_dir\r\n";
919 print OUT "InputPath=$source_file\r\n";
920 print OUT "\r\n";
921 print OUT "\"\$(OutDir)\\wine\\$h_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
922 print OUT "\tcopy \$(InputPath) \$(OutDir)\\wine\r\n";
923 print OUT "\r\n";
924 print OUT "# End Custom Build\r\n";
927 if($#cfgs != 0) {
928 print OUT "\r\n";
929 print OUT "!ENDIF \r\n";
930 print OUT "\r\n";
934 print OUT "# End Source File\r\n";
936 print OUT "# End Group\r\n";
938 print OUT "# Begin Group \"Header Files\"\r\n";
939 print OUT "\r\n";
940 print OUT "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
941 foreach my $header_file (@header_files) {
942 print OUT "# Begin Source File\r\n";
943 print OUT "\r\n";
944 print OUT "SOURCE=.\\$header_file\r\n";
945 print OUT "# End Source File\r\n";
947 print OUT "# End Group\r\n";
951 print OUT "# Begin Group \"Resource Files\"\r\n";
952 print OUT "\r\n";
953 print OUT "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
954 foreach my $resource_file (@resource_files) {
955 print OUT "# Begin Source File\r\n";
956 print OUT "\r\n";
957 print OUT "SOURCE=.\\$resource_file\r\n";
958 print OUT "# End Source File\r\n";
960 print OUT "# End Group\r\n";
962 print OUT "# End Target\r\n";
963 print OUT "# End Project\r\n";
965 close(OUT);
968 sub _generate_dsw_header {
969 local *OUT = shift;
971 print OUT "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n";
972 print OUT "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n";
973 print OUT "\r\n";
976 sub _generate_dsw_project {
977 local *OUT = shift;
979 my $project = shift;
980 my $dsp_file = shift;
981 my @dependencies = @{(shift)};
983 $dsp_file = "./$dsp_file";
984 $dsp_file =~ y%/%\\%;
986 @dependencies = sort(@dependencies);
988 print OUT "###############################################################################\r\n";
989 print OUT "\r\n";
990 print OUT "Project: \"$project\"=$dsp_file - Package Owner=<4>\r\n";
991 print OUT "\r\n";
992 print OUT "Package=<5>\r\n";
993 print OUT "{{{\r\n";
994 print OUT "}}}\r\n";
995 print OUT "\r\n";
996 print OUT "Package=<4>\r\n";
997 print OUT "{{{\r\n";
998 foreach my $dependency (@dependencies) {
999 print OUT " Begin Project Dependency\r\n";
1000 print OUT " Project_Dep_Name $dependency\r\n";
1001 print OUT " End Project Dependency\r\n";
1003 print OUT "}}}\r\n";
1004 print OUT "\r\n";
1007 sub _generate_dsw_footer {
1008 local *OUT = shift;
1010 print OUT "###############################################################################\r\n";
1011 print OUT "\r\n";
1012 print OUT "Global:\r\n";
1013 print OUT "\r\n";
1014 print OUT "Package=<5>\r\n";
1015 print OUT "{{{\r\n";
1016 print OUT "}}}\r\n";
1017 print OUT "\r\n";
1018 print OUT "Package=<3>\r\n";
1019 print OUT "{{{\r\n";
1020 print OUT "}}}\r\n";
1021 print OUT "\r\n";
1022 print OUT "###############################################################################\r\n";
1023 print OUT "\r\n";
1026 if ($options->wine) {
1027 my $dsw_file = "wine.dsw";
1028 $output->progress("$dsw_file");
1029 replace_file("$wine_dir/$dsw_file", \&_generate_wine_dsw);
1032 sub _generate_wine_dsw {
1033 local *OUT = shift;
1035 _generate_dsw_header(\*OUT);
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 =~ /^wine(?:_unicode)?$/) {
1044 @dependencies = ();
1045 } elsif($project =~ /^winebuild$/) {
1046 @dependencies = ("wine", "wine_unicode");
1047 } elsif($project =~ /^(?:gdi32|ntdll|user32)_.+?$/) {
1048 @dependencies = ();
1049 } else {
1050 @dependencies = ("wine", "wine_unicode", "winebuild");
1053 if($project =~ /^gdi32$/) {
1054 foreach my $dir (@gdi32_dirs) {
1055 my $dir2 = $dir;
1056 $dir2 =~ s%^.*?/([^/]+)$%$1%;
1058 my $module = "gdi32_$dir2";
1059 $module =~ s%/%_%g;
1060 push @dependencies, $module;
1062 } elsif($project =~ /^ntdll$/) {
1063 foreach my $dir (@ntdll_dirs) {
1064 my $module = "ntdll_$dir";
1065 $module =~ s%/%_%g;
1066 push @dependencies, $module;
1068 } elsif($project =~ /^user32$/) {
1069 foreach my $dir (@user32_dirs) {
1070 my $dir2 = $dir;
1071 $dir2 =~ s%^.*?/([^/]+)$%$1%;
1073 my $module = "user32_$dir2";
1074 $module =~ s%/%_%g;
1075 push @dependencies, $module;
1079 _generate_dsw_project(\*OUT, $project, $dsp_file, \@dependencies);
1081 _generate_dsw_footer(\*OUT);
1083 return 1;
1086 if ($options->winetest) {
1087 my $dsw_file = "winetest.dsw";
1088 $output->progress("$dsw_file");
1089 replace_file("$wine_dir/$dsw_file", \&_generate_winetest_dsw);
1092 sub _generate_winetest_dsw {
1093 local *OUT = shift;
1095 _generate_dsw_header(\*OUT);
1097 my @runtests_dependencies = ();
1098 foreach my $module (sort(keys(%modules))) {
1099 next if $module !~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1100 next if $module eq "wineruntests";
1102 my $project = $modules{$module}{project};
1104 push @runtests_dependencies, $project;
1107 foreach my $module (sort(keys(%modules))) {
1108 next if $module !~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1110 my $project = $modules{$module}{project};
1111 my $dsp_file = $modules{$module}{dsp_file};
1113 my @dependencies;
1114 if($project =~ /^winetest$/) {
1115 @dependencies = ();
1116 } elsif($project =~ /^wineruntests$/) {
1117 @dependencies = @runtests_dependencies;
1118 } else {
1119 @dependencies = ("winetest");
1122 _generate_dsw_project(\*OUT, $project, $dsp_file, \@dependencies);
1125 _generate_dsw_footer(\*OUT);
1128 if ($options->winetest) {
1129 foreach my $module (sort(keys(%modules))) {
1130 next if $module !~ /_test\.exe$/;
1132 my $project = $modules{$module}{project};
1133 my $dsp_file = $modules{$module}{dsp_file};
1134 my @tests = @{$modules{$module}{tests}};
1136 my $testlist_c = $dsp_file;
1137 $testlist_c =~ s%[^/]*\.dsp$%testlist.c%;
1139 replace_file("$wine_dir/$testlist_c", \&_generate_testlist_c, \@tests);
1143 sub _generate_testlist_c {
1144 local *OUT = shift;
1146 my @tests = @{(shift)};
1148 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n";
1149 print OUT "\n";
1150 print OUT "#include <stdio.h>\n";
1151 print OUT "#include <stdlib.h>\n";
1152 print OUT "#include \"windef.h\"\n";
1153 print OUT "#include \"winbase.h\"\n";
1154 print OUT "\n";
1155 foreach my $test (@tests) {
1156 print OUT "extern void func_$test(void);\n";
1158 print OUT "\n";
1159 print OUT "struct test\n";
1160 print OUT "{\n";
1161 print OUT " const char *name;\n";
1162 print OUT " void (*func)(void);\n";
1163 print OUT "};\n";
1164 print OUT "\n";
1165 print OUT "static const struct test winetest_testlist[] =\n";
1166 print OUT "{\n";
1167 foreach my $test (@tests) {
1168 print OUT " { \"$test\", func_$test },\n";
1170 print OUT " { 0, 0 }\n";
1171 print OUT "};\n";
1172 print OUT "\n";
1173 print OUT "#define WINETEST_WANT_MAIN\n";
1174 print OUT "#include \"wine/test.h\"\n";
1177 if ($options->winetest) {
1178 replace_file("$wine_dir/runtests.c", \&_generate_runtests_c);
1181 sub _generate_runtests_c {
1182 local *OUT = shift;
1184 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n";
1186 print OUT "\n";
1187 print OUT "#include <stdio.h>\n";
1188 print OUT "#include <stdlib.h>\n";
1189 print OUT "\n";
1191 print OUT "int main(int argc, char *argv[])\n";
1192 print OUT "{\n";
1193 print OUT " char output_dir[] = __WINETEST_OUTPUT_DIR;\n";
1194 print OUT " char command[4096];\n";
1195 print OUT "\n";
1196 foreach my $dsp_file (keys(%runtests)) {
1197 my @tests = @{$runtests{$dsp_file}};
1199 my $project = $dsp_file;
1200 $project =~ s%^(.*?)/?([^/]+)\.dsp$%$2%;
1201 my $dir = $1;
1202 $dir =~ s%/%\\\\%g;
1204 foreach my $test (@tests) {
1205 print OUT " sprintf(command, \"$dir\\\\%s\\\\$project.exe $test\", output_dir);\n";
1206 print OUT " system(command);\n";
1207 print OUT "\n";
1210 print OUT " return 0;\n";
1211 print OUT "}\n";
1215 if ($options->wine) {
1216 my $config_h = "include/config.h";
1218 $output->progress("$config_h");
1220 replace_file("$wine_dir/$config_h", \&_generate_config_h);
1223 sub _generate_config_h {
1224 local *OUT = shift;
1226 print OUT "#define __WINE_CONFIG_H\n";
1227 print OUT "\n";
1229 my @headers = qw(direct.h io.h);
1230 foreach my $header (@headers) {
1231 $header =~ y/\.\//__/;
1232 print OUT "#define HAVE_\U$header\E\n";
1233 print OUT "\n";
1236 my @functions = qw(
1237 _alldiv _allmul _allrem _aulldiv _aullrem
1238 _access _chdir _close _lseek _mkdir _open _pclose _popen _read _rmdir _write _stat
1239 _snprintf _stricmp _strnicmp _vsnprintf _wcsicmp wcslen
1240 ecvt fcvt gcvt
1241 strerror
1243 foreach my $function (@functions) {
1244 print OUT "#define HAVE_\U$function\E 1\n";
1245 print OUT "\n";
1248 if(0) {
1249 print OUT "#define NEED_STDCALL_DECORATION 1\n";
1250 print OUT "\n";
1253 print OUT "#define X_DISPLAY_MISSING 1\n";
1254 print OUT "\n";
1256 print OUT "/* Define to a macro to generate an assembly function directive */\n";
1257 print OUT "#define __ASM_FUNC(name) \"\"\n";
1258 print OUT "\n";
1260 print OUT "/* Define to a macro to generate an assembly name from a C symbol */\n";
1261 print OUT "#define __ASM_NAME(name) name\n";
1262 print OUT "\n";
1264 print OUT "/* Define to the address where bug reports for this package should be sent. */\n";
1265 print OUT "#define PACKAGE_BUGREPORT \"\"\n";
1266 print OUT "\n";
1268 print OUT "/* Define to the full name of this package. */\n";
1269 print OUT "#define PACKAGE_NAME \"Wine\"\n";
1270 print OUT "\n";
1272 print OUT "/* Define to the full name and version of this package. */\n";
1273 print OUT "#define PACKAGE_STRING \"Wine YYYYMMDD\"\n";
1274 print OUT "\n";
1276 print OUT "/* Define to the one symbol short name of this package. */\n";
1277 print OUT "#define PACKAGE_TARNAME \"wine\"\n";
1278 print OUT "\n";
1280 print OUT "/* Define to the version of this package. */\n";
1281 print OUT "#define PACKAGE_VERSION \"YYYYMMDD\"\n";
1282 print OUT "\n";
1284 close(OUT);