- encode/decode X509_NAMEs for simple string encodings, with tests
[wine/testsucceed.git] / tools / winapi / msvcmaker
blobb4ff362051c8e088d4ceae1518785e582f4d4cad
1 #! /usr/bin/perl -w
3 # Copyright 2002 Patrik Stridvall
5 use strict;
7 BEGIN {
8 $0 =~ m%^(.*?/?tools)/winapi/msvcmaker$%;
9 require "$1/winapi/setup.pm";
12 use setup qw($current_dir $wine_dir);
13 use lib $setup::winapi_dir;
14 use config qw(get_spec_files get_makefile_in_files);
15 use output qw($output);
16 use util qw(replace_file);
18 use msvcmaker_options qw($options);
20 if($options->progress) {
21 $output->enable_progress;
22 } else {
23 $output->disable_progress;
26 ########################################################################
27 # main
29 my @spec_files = get_spec_files("winelib");
30 my @makefile_in_files = get_makefile_in_files("winelib");
32 my $wine = 1;
34 my $output_prefix_dir = "Output";
35 my $no_release = 1;
37 my %modules;
39 sub read_spec_file($) {
40 my $spec_file = shift;
42 my $module = $spec_file;
43 $module =~ s%^.*?([^/]+)\.spec$%$1%;
44 $module .= ".dll" if $module !~ /\./;
46 my $type = "win32";
48 open(IN, "< $wine_dir/$spec_file");
50 my $header = 1;
51 my $lookahead = 0;
52 while($lookahead || defined($_ = <IN>)) {
53 $lookahead = 0;
55 s/^\s*?(.*?)\s*$/$1/; # remove whitespace at begining and end of line
56 s/^(.*?)\s*#.*$/$1/; # remove comments
57 /^$/ && next; # skip empty lines
59 if($header) {
60 if(/^(?:\d+|@)/) {
61 $header = 0;
62 $lookahead = 1;
64 next;
67 if(/^(\d+|@)\s+pascal(?:16)?/) {
68 $type = "win16";
69 last;
72 close(IN);
74 # FIXME: Kludge
75 if($module =~ /^(?:(?:imm|ole2conv|ole2prox|ole2thk|rasapi16|windebug)\.dll|comm\.drv)$/) {
76 $type = "win16";
79 if($type eq "win32") {
80 $modules{$module}{module} = $module;
81 $modules{$module}{type} = $type;
82 $modules{$module}{spec_file} = $spec_file;
86 if ($options->wine || $options->winetest) {
87 foreach my $spec_file (@spec_files) {
88 read_spec_file($spec_file);
92 my @gdi32_dirs = qw(dlls/gdi/enhmfdrv dlls/gdi/mfdrv);
94 push @makefile_in_files, "tools/winebuild/Makefile.in";
96 sub filter_files($$) {
97 my $files = shift;
98 my $filter = shift;
100 my $filtered_files = [];
101 my $rest_of_files = [];
102 foreach my $file (@$files) {
103 if($file =~ /$filter/) {
104 $file =~ s%.*?([^/]+)$%./$1%; # FIXME: Kludge
105 push @$filtered_files, $file;
106 } else {
107 push @$rest_of_files, $file;
110 return ($rest_of_files, $filtered_files);
113 my %wine_test_dsp_files;
115 MAKEFILE_IN: foreach my $makefile_in_file (@makefile_in_files) {
116 open(IN, "< $wine_dir/$makefile_in_file");
118 my $topobjdir;
119 my $module;
120 my $testdll;
121 my @imports;
123 my %vars;
125 my $again = 0;
126 my $lookahead = 0;
127 while($again || defined(my $line = <IN>)) {
128 if(!$again) {
129 chomp $line;
130 if($lookahead) {
131 $lookahead = 0;
132 $_ .= "\n" . $line;
133 } else {
134 $_ = $line;
136 } else {
137 $again = 0;
140 s/^\s*?(.*?)\s*$/$1/; # remove whitespace at begining and end of line
141 s/^(.*?)\s*#.*$/$1/; # remove comments
142 /^$/ && next; # skip empty lines
144 if(s/\\$/ /s) {
145 $lookahead = 1;
146 next;
149 if(/^MODULE\s*=\s*([\w\.]+)$/) {
150 $module = $1;
152 if($module eq "none") {
153 if($makefile_in_file eq "library/Makefile.in") {
154 $module = "wine.dll";
155 } elsif($makefile_in_file eq "unicode/Makefile.in") {
156 $module = "wine_unicode.dll";
157 } elsif($makefile_in_file eq "tools/winebuild/Makefile.in") {
158 $module = "winebuild.exe";
159 } else {
160 next MAKEFILE_IN;
163 } elsif(/^TOPOBJDIR\s*=\s*(\S+)\s*$/) {
164 $topobjdir = $1;
165 } elsif (/^TESTDLL\s*=\s*(\S+)\s*$/) {
166 $testdll = $1;
167 } elsif (/^IMPORTS\s*=\s*/) {
168 push @imports, grep !/^ntdll$/, split /\s+/s, $';
169 } elsif (/^EXTRALIBS\s*=\s*/) {
170 push @imports, map { /^-l(dxerr8|dxerr9|dxguid|strmiids|uuid)$/ ? $1 : () } split /\s+/s, $';
171 } elsif (/^CTESTS\s*=\s*/) {
172 my @files = split /\s+/s, $';
174 my $dir = $makefile_in_file;
175 $dir =~ s/\/Makefile\.in$//;
177 my $dsp_file = $testdll;
178 $dsp_file =~ s/\.(dll|drv)$/_test.dsp/;
179 $dsp_file = "$dir/$dsp_file";
181 $wine_test_dsp_files{$dsp_file}{files} = [@files, "testlist.c"];
182 $wine_test_dsp_files{$dsp_file}{imports} = [@imports];
183 } elsif(/^(\w+)\s*=\s*/) {
184 my $var = $1;
185 my @files = split /\s+/s, $';
187 @files = map {
188 if(/^\$\((\w+):\%=(.*?)\%(.*?)\)$/) {
189 my @list = @{$vars{$1}};
190 my $prefix = $2;
191 my $suffix = $3;
192 foreach my $item (@list) {
193 $item = "$prefix$item$suffix";
195 @list;
196 } elsif(/^\$\(TOPOBJDIR\)(.*?)$/) {
197 "$topobjdir$1";
198 } elsif(/^\$/) {
199 print STDERR "unknown variable '$_'\n" if 0;
201 } else {
204 } @files;
206 $vars{$var} = \@files;
210 close(IN);
212 next if !$module;
214 my $c_srcs = [];
215 my $source_files = [];
216 if(exists($vars{C_SRCS})) {
217 $c_srcs = [sort(@{$vars{C_SRCS}})];
218 $source_files = [sort(@{$vars{C_SRCS}})];
221 my $header_files = [];
222 if(exists($vars{H_SRCS})) {
223 $header_files = [sort(@{$vars{H_SRCS}})];
226 my $resource_files = [];
227 if(exists($vars{RC_SRCS})) {
228 $resource_files = [sort(@{$vars{RC_SRCS}})];
231 my $project = $module;
232 $project =~ s/\.(?:dll|exe|lib)$//;
233 $project =~ y/./_/;
235 my $type;
236 if($module =~ /\.exe$/) {
237 $type = "exe";
238 } elsif($module =~ /\.lib$/) {
239 $type = "lib";
240 } else {
241 $type = "dll";
244 my $dsp_file = $makefile_in_file;
245 $dsp_file =~ s/Makefile.in$/$project.dsp/;
247 if($module eq "gdi32.dll") {
248 foreach my $dir (@gdi32_dirs) {
249 my $dir2 = $dir;
250 $dir2 =~ s%^.*?/([^/]+)$%$1%;
252 my $module = "gdi32_$dir2.lib";
253 $module =~ s%/%_%g;
255 my $project = "gdi32_$dir2";
256 $project =~ s%/%_%g;
258 my $type = "lib";
259 my $dsp_file = "$dir/$project.dsp";
261 ($source_files, my $local_source_files) = filter_files($source_files, "$dir2/");
262 ($header_files, my $local_header_files) = filter_files($header_files, "$dir2/");
263 ($resource_files, my $local_resource_files) = filter_files($resource_files, "$dir2/");
265 $modules{$module}{wine} = 1;
266 $modules{$module}{winetest} = 0;
267 $modules{$module}{project} = $project;
268 $modules{$module}{type} = $type;
269 $modules{$module}{dsp_file} = $dsp_file;
270 $modules{$module}{c_srcs} = $c_srcs;
271 $modules{$module}{source_files} = $local_source_files;
272 $modules{$module}{header_files} = $local_header_files;
273 $modules{$module}{resource_files} = $local_resource_files;
274 $modules{$module}{imports} = [];
278 $modules{$module}{wine} = 1;
279 $modules{$module}{winetest} = 0;
280 $modules{$module}{project} = $project;
281 $modules{$module}{type} = $type;
282 $modules{$module}{dsp_file} = $dsp_file;
283 $modules{$module}{c_srcs} = $c_srcs;
284 $modules{$module}{source_files} = $source_files;
285 $modules{$module}{header_files} = $header_files;
286 $modules{$module}{resource_files} = $resource_files;
287 $modules{$module}{imports} = [];
290 $wine_test_dsp_files{"wineruntests.dsp"}{files} = ["runtests.c"];
291 $wine_test_dsp_files{"wineruntests.dsp"}{imports} = [];
293 $wine_test_dsp_files{"winetest.dsp"}{files} = [
294 'include/wine/exception.h',
295 'include/wine/test.h',
296 'include/wine/unicode.h',
297 'winetest.c'
299 $wine_test_dsp_files{"winetest.dsp"}{imports} = [];
301 my %runtests = ();
303 foreach my $dsp_file (keys(%wine_test_dsp_files)) {
304 my $project = $dsp_file;
305 $project =~ s%^(?:.*?/)?([^/]+)\.dsp$%$1%;
307 my @files = @{$wine_test_dsp_files{$dsp_file}{files}};
308 my @imports = @{$wine_test_dsp_files{$dsp_file}{imports}};
310 my $type;
311 my $c_srcs = [];
312 my $source_files = [];
313 my $header_files = [];
314 my $resource_files = [];
316 my @tests = ();
318 if ($project eq "winetest") {
319 $type = "lib";
320 $c_srcs = [@files];
321 $source_files = [@files];
322 $header_files = [];
323 $resource_files = [];
324 } elsif ($project eq "wineruntests") {
325 $type = "exe";
326 $c_srcs = [@files];
327 $source_files = [@files];
328 $header_files = [];
329 $resource_files = [];
330 } else {
331 $type = "exe";
332 $c_srcs = [@files];
333 $source_files = [@files];
334 $header_files = [];
335 $resource_files = [];
337 @tests = map {
338 if (/^testlist\.c$/) {
340 } else {
341 s/\.c$//;
344 } @files;
346 $runtests{$dsp_file} = [@tests];
348 my $module = "$project.$type";
350 $modules{$module}{wine} = 0;
351 $modules{$module}{winetest} = 1;
353 $modules{$module}{project} = $project;
354 $modules{$module}{type} = $type;
355 $modules{$module}{dsp_file} = $dsp_file;
356 $modules{$module}{c_srcs} = $c_srcs;
357 $modules{$module}{source_files} = $source_files;
358 $modules{$module}{header_files} = $header_files;
359 $modules{$module}{resource_files} = $resource_files;
360 $modules{$module}{imports} = [@imports];
362 $modules{$module}{tests} = [@tests];
365 foreach my $module (sort(keys(%modules))) {
366 if($module =~ /^(?:ttydrv.dll|x11drv.dll)$/) {
367 delete $modules{$module};
371 my @modules = ();
372 foreach my $module (sort(keys(%modules))) {
373 if (($options->wine && $modules{$module}{wine}) ||
374 ($options->winetest && $modules{$module}{winetest}))
376 push @modules, $module;
380 my $progress_output;
381 my $progress_current = 0;
382 my $progress_max = scalar(@modules);
384 foreach my $module (@modules) {
385 my $dsp_file = $modules{$module}{dsp_file};
386 replace_file("$wine_dir/$dsp_file", \&_generate_dsp, $module);
389 sub _generate_dsp($$) {
390 local *OUT = shift;
392 my $module = shift;
394 my $dsp_file = $modules{$module}{dsp_file};
395 my $project = $modules{$module}{project};
396 my @imports = @{$modules{$module}{imports}};
398 my $lib = ($modules{$module}{type} eq "lib");
399 my $dll = ($modules{$module}{type} eq "dll");
400 my $exe = ($modules{$module}{type} eq "exe");
402 my $console = $exe; # FIXME: Not always correct
404 my $msvc_wine_dir = do {
405 my @parts = split(m%/%, $dsp_file);
406 if($#parts == 1) {
407 "..";
408 } elsif($#parts == 2) {
409 "..\\..";
410 } else {
411 "..\\..\\..";
414 my $wine_include_dir = "$msvc_wine_dir\\include";
416 $progress_current++;
417 $output->progress("$dsp_file (file $progress_current of $progress_max)");
419 my @c_srcs = @{$modules{$module}{c_srcs}};
420 my @source_files = @{$modules{$module}{source_files}};
421 my @header_files = @{$modules{$module}{header_files}};
422 my @resource_files = @{$modules{$module}{resource_files}};
424 if ($project !~ /^wine(?:_unicode|build|runtests|test)?$/ &&
425 $project !~ /^(?:gdi32)_.+?$/ &&
426 $project !~ /_test$/)
428 push @source_files, "$project.spec";
429 # push @source_files, "$project.spec.c";
430 @source_files = sort(@source_files);
433 my $no_cpp = 1;
434 my $no_msvc_headers = 1;
435 if ($project =~ /^wine(?:runtests|test)$/ || $project =~ /_test$/) {
436 $no_msvc_headers = 0;
439 my @cfgs;
441 push @cfgs, "$project - Win32";
443 if (!$no_cpp) {
444 my @_cfgs;
445 foreach my $cfg (@cfgs) {
446 push @_cfgs, "$cfg C";
447 push @_cfgs, "$cfg C++";
449 @cfgs = @_cfgs;
452 if (!$no_release) {
453 my @_cfgs;
454 foreach my $cfg (@cfgs) {
455 push @_cfgs, "$cfg Debug";
456 push @_cfgs, "$cfg Release";
458 @cfgs = @_cfgs;
461 if (!$no_msvc_headers) {
462 my @_cfgs;
463 foreach my $cfg (@cfgs) {
464 push @_cfgs, "$cfg MSVC Headers";
465 push @_cfgs, "$cfg Wine Headers";
467 @cfgs = @_cfgs;
470 my $default_cfg = $cfgs[$#cfgs];
472 print OUT "# Microsoft Developer Studio Project File - Name=\"$project\" - Package Owner=<4>\r\n";
473 print OUT "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n";
474 print OUT "# ** DO NOT EDIT **\r\n";
475 print OUT "\r\n";
477 if ($lib) {
478 print OUT "# TARGTYPE \"Win32 (x86) Static Library\" 0x0104\r\n";
479 } elsif ($dll) {
480 print OUT "# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\r\n";
481 } else {
482 print OUT "# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n";
484 print OUT "\r\n";
486 print OUT "CFG=$default_cfg\r\n";
487 print OUT "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n";
488 print OUT "!MESSAGE use the Export Makefile command and run\r\n";
489 print OUT "!MESSAGE \r\n";
490 print OUT "!MESSAGE NMAKE /f \"$project.mak\".\r\n";
491 print OUT "!MESSAGE \r\n";
492 print OUT "!MESSAGE You can specify a configuration when running NMAKE\r\n";
493 print OUT "!MESSAGE by defining the macro CFG on the command line. For example:\r\n";
494 print OUT "!MESSAGE \r\n";
495 print OUT "!MESSAGE NMAKE /f \"$project.mak\" CFG=\"$default_cfg\"\r\n";
496 print OUT "!MESSAGE \r\n";
497 print OUT "!MESSAGE Possible choices for configuration are:\r\n";
498 print OUT "!MESSAGE \r\n";
499 foreach my $cfg (@cfgs) {
500 if ($lib) {
501 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Static Library\")\r\n";
502 } elsif ($dll) {
503 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n";
504 } else {
505 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Console Application\")\r\n";
508 print OUT "!MESSAGE \r\n";
509 print OUT "\r\n";
511 print OUT "# Begin Project\r\n";
512 print OUT "# PROP AllowPerConfigDependencies 0\r\n";
513 print OUT "# PROP Scc_ProjName \"\"\r\n";
514 print OUT "# PROP Scc_LocalPath \"\"\r\n";
515 print OUT "CPP=cl.exe\r\n";
516 print OUT "MTL=midl.exe\r\n" if !$lib && !$exe;
517 print OUT "RSC=rc.exe\r\n";
519 my $n = 0;
521 my $output_dir;
522 foreach my $cfg (@cfgs) {
523 if($#cfgs == 0) {
524 # Nothing
525 } elsif($n == 0) {
526 print OUT "!IF \"\$(CFG)\" == \"$cfg\"\r\n";
527 print OUT "\r\n";
528 } else {
529 print OUT "\r\n";
530 print OUT "!ELSEIF \"\$(CFG)\" == \"$cfg\"\r\n";
531 print OUT "\r\n";
534 my $debug = ($cfg !~ /Release/);
535 my $msvc_headers = ($cfg =~ /MSVC Headers/);
537 print OUT "# PROP BASE Use_MFC 0\r\n";
539 if($debug) {
540 print OUT "# PROP BASE Use_Debug_Libraries 1\r\n";
541 } else {
542 print OUT "# PROP BASE Use_Debug_Libraries 0\r\n";
545 $output_dir = $cfg;
546 $output_dir =~ s/^$project - //;
547 $output_dir =~ s/ /_/g;
548 $output_dir =~ s/C\+\+/Cxx/g;
549 if($output_prefix_dir) {
550 $output_dir = "$output_prefix_dir\\$output_dir";
553 print OUT "# PROP BASE Output_Dir \"$output_dir\"\r\n";
554 print OUT "# PROP BASE Intermediate_Dir \"$output_dir\"\r\n";
556 print OUT "# PROP BASE Target_Dir \"\"\r\n";
558 print OUT "# PROP Use_MFC 0\r\n";
559 if($debug) {
560 print OUT "# PROP Use_Debug_Libraries 1\r\n";
561 } else {
562 print OUT "# PROP Use_Debug_Libraries 0\r\n";
564 print OUT "# PROP Output_Dir \"$output_dir\"\r\n";
565 print OUT "# PROP Intermediate_Dir \"$output_dir\"\r\n";
567 print OUT "# PROP Ignore_Export_Lib 0\r\n" if $dll;
568 print OUT "# PROP Target_Dir \"\"\r\n";
570 my @defines;
571 if($debug) {
572 if($lib || $exe) {
573 print OUT "# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od";
574 @defines = (qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 _DEBUG _MBCS _LIB));
575 } else {
576 print OUT "# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od";
577 @defines = (qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 _DEBUG _WINDOWS _MBCS _USRDLL), ("\U${project}\E_EXPORTS"));
579 } else {
580 if($lib || $exe) {
581 print OUT "# ADD BASE CPP /nologo /W3 /GX /O2";
582 @defines = (qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 NDEBUG _MBCS _LIB));
583 } else {
584 print OUT "# ADD BASE CPP /nologo /MT /W3 /GX /O2";
585 @defines = (qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 NDEBUG _WINDOWS _MBCS _USRDLL), ("\U${project}\E_EXPORTS"));
589 foreach my $define (@defines) {
590 print OUT " /D \"$define\"";
592 print OUT " /YX" if $lib || $exe;
593 print OUT " /FD";
594 print OUT " /GZ" if $debug;
595 print OUT " " if $debug && ($lib || $exe);
596 print OUT " /c";
597 print OUT "\r\n";
599 my @defines2;
600 if($debug) {
601 if($lib) {
602 print OUT "# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od";
603 @defines2 = qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 _DEBUG _WINDOWS _MBCS _LIB);
604 } else {
605 print OUT "# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od";
606 @defines2 = qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 _DEBUG WIN32 _WINDOWS _MBCS _USRDLL);
608 } else {
609 if($lib) {
610 print OUT "# ADD CPP /nologo /MT /W3 /GX /O2";
611 @defines2 = qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 NDEBUG _WINDOWS _MBCS _LIB);
612 } else {
613 print OUT "# ADD CPP /nologo /MT /W3 /GX /O2";
614 @defines2 = qw(WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600 NDEBUG WIN32 _WINDOWS _MBCS _USRDLL);
618 my @includes = ();
619 if($wine) {
620 push @defines2, "_\U${project}\E_";
621 push @defines2, qw(__WINESRC__) if $project !~ /^(?:wine(?:build|test)|.*?_test)$/;
622 if ($msvc_headers) {
623 push @defines2, qw(__WINE_USE_NATIVE_HEADERS);
625 my $output_dir2 = $output_dir;
626 $output_dir =~ s/\\/\\\\/g;
627 push @defines2, "__WINETEST_OUTPUT_DIR=\\\"$output_dir\\\"";
628 push @defines2, qw(__i386__ _X86_);
630 if($project =~ /^gdi32_(?:enhmfdrv|mfdrv)$/) {
631 push @includes, "..";
634 if ($project =~ /_test$/) {
635 push @includes, "$msvc_wine_dir\\$output_dir";
638 if (!$msvc_headers || $project eq "winetest") {
639 push @includes, $wine_include_dir;
643 if($wine) {
644 foreach my $include (@includes) {
645 if ($include !~ /[\\\"]/) {
646 print OUT " /I \"$include\"";
647 } else {
648 print OUT " /I $include";
653 foreach my $define (@defines2) {
654 if ($define !~ /[\\\"]/) {
655 print OUT " /D \"$define\"";
656 } else {
657 print OUT " /D $define";
660 print OUT " /D inline=__inline" if $wine;
661 print OUT " /D \"__STDC__\"" if 0 && $wine;
663 print OUT " /YX" if $lib;
664 print OUT " /FR" if !$lib;
665 print OUT " /FD";
666 print OUT " /GZ" if $debug;
667 print OUT " " if $debug && $lib;
668 print OUT " /c";
669 print OUT " /TP" if !$no_cpp;
670 print OUT "\r\n";
672 if($debug) {
673 print OUT "# SUBTRACT CPP /X /YX\r\n" if $dll;
674 print OUT "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
675 print OUT "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
676 print OUT "# ADD BASE RSC /l 0x41d /d \"_DEBUG\"\r\n";
677 print OUT "# ADD RSC /l 0x41d";
678 if($wine) {
679 foreach my $include (@includes) {
680 print OUT " /i \"$include\"";
683 print OUT " /d \"_DEBUG\"\r\n";
684 } else {
685 print OUT "# SUBTRACT CPP /YX\r\n" if $dll;
686 print OUT "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
687 print OUT "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
688 print OUT "# ADD BASE RSC /l 0x41d /d \"NDEBUG\"\r\n";
689 print OUT "# ADD RSC /l 0x41d";
690 if($wine) {
691 foreach my $include (@includes) {
692 print OUT " /i \"$include\"";
695 print OUT "/d \"NDEBUG\"\r\n";
697 print OUT "BSC32=bscmake.exe\r\n";
698 print OUT "# ADD BASE BSC32 /nologo\r\n";
699 print OUT "# ADD BSC32 /nologo\r\n";
701 if($exe || $dll) {
702 print OUT "LINK32=link.exe\r\n";
703 print OUT "# ADD BASE LINK32 ";
704 my @libraries = qw(kernel32.lib user32.lib gdi32.lib winspool.lib
705 comdlg32.lib advapi32.lib shell32.lib ole32.lib
706 oleaut32.lib uuid.lib odbc32.lib odbccp32.lib);
707 foreach my $library (@libraries) {
708 print OUT "$library ";
710 print OUT " /nologo";
711 print OUT " /dll" if $dll;
712 print OUT " /subsystem:console" if $console;
713 print OUT " /debug" if $debug;
714 print OUT " /machine:I386";
715 print OUT " /pdbtype:sept" if $debug;
716 print OUT "\r\n";
718 print OUT "# ADD LINK32";
719 print OUT " /nologo";
720 print OUT " libcmt.lib" if $project =~ /^ntdll$/; # FIXME: Kludge
721 foreach my $import (@imports) {
722 print OUT " $import.lib" if ($import ne "msvcrt");
724 print OUT " /dll" if $dll;
725 print OUT " /subsystem:console" if $console;
726 print OUT " /debug" if $debug;
727 print OUT " /machine:I386";
728 print OUT " /nodefaultlib" if $project =~ /^ntdll$/; # FIXME: Kludge
729 print OUT " /def:\"$project.def\"" if $dll;
730 print OUT " /pdbtype:sept" if $debug;
731 print OUT "\r\n";
732 } else {
733 print OUT "LIB32=link.exe -lib\r\n";
734 print OUT "# ADD BASE LIB32 /nologo\r\n";
735 print OUT "# ADD LIB32 /nologo\r\n";
738 $n++;
741 if($#cfgs != 0) {
742 print OUT "\r\n";
743 print OUT "!ENDIF \r\n";
744 print OUT "\r\n";
747 if ($project eq "winebuild") {
748 print OUT "# Begin Special Build Tool\r\n";
749 print OUT "SOURCE=\"\$(InputPath)\"\r\n";
750 print OUT "PostBuild_Desc=Copying wine.dll and wine_unicode.dll ...\r\n";
751 print OUT "PostBuild_Cmds=";
752 print OUT "copy ..\\..\\library\\$output_dir\\wine.dll \$(OutDir)\t";
753 print OUT "copy ..\\..\\unicode\\$output_dir\\wine_unicode.dll \$(OutDir)\r\n";
754 print OUT "# End Special Build Tool\r\n";
756 print OUT "# Begin Target\r\n";
757 print OUT "\r\n";
758 foreach my $cfg (@cfgs) {
759 print OUT "# Name \"$cfg\"\r\n";
762 print OUT "# Begin Group \"Source Files\"\r\n";
763 print OUT "\r\n";
764 print OUT "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
766 foreach my $source_file (@source_files) {
767 $source_file =~ s%/%\\%g;
768 if($source_file !~ /^\./) {
769 $source_file = ".\\$source_file";
772 if($source_file =~ /^(.*?)\.spec$/) {
773 my $basename = $1;
775 $basename = "$basename.dll" if $basename !~ /\..{1,3}$/;
776 my $dbg_c_file = "$basename.dbg.c";
778 print OUT "# Begin Source File\r\n";
779 print OUT "\r\n";
780 print OUT "SOURCE=$dbg_c_file\r\n";
781 print OUT "# End Source File\r\n";
784 print OUT "# Begin Source File\r\n";
785 print OUT "\r\n";
787 print OUT "SOURCE=$source_file\r\n";
789 if($source_file =~ /^(.*?)\.spec$/) {
790 my $basename = $1;
792 my $spec_file = $source_file;
793 my $def_file = "$basename.def";
795 $basename = "$basename.dll" if $basename !~ /\..{1,3}$/;
796 my $dbg_file = "$basename.dbg";
797 my $dbg_c_file = "$basename.dbg.c";
799 my $srcdir = "."; # FIXME: Is this really always correct?
801 print OUT "# Begin Custom Build\r\n";
802 print OUT "InputPath=$spec_file\r\n";
803 print OUT "\r\n";
804 print OUT "BuildCmds= \\\r\n";
805 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe --def $spec_file > $def_file \\\r\n";
807 if($project =~ /^ntdll$/) {
808 my $n = 0;
809 foreach my $c_src (@c_srcs) {
810 if($n++ > 0) {
811 print OUT "\techo $c_src >> $dbg_file \\\r\n";
812 } else {
813 print OUT "\techo $c_src > $dbg_file \\\r\n";
816 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe";
817 print OUT " -o $dbg_c_file --debug -C$srcdir $dbg_file \\\r\n";
818 } else {
819 my $c_srcs = join(" ", grep(/\.c$/, @c_srcs));
821 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe";
822 print OUT " -o $dbg_c_file --debug -C$srcdir $c_srcs \\\r\n";
825 print OUT "\t\r\n";
826 print OUT "\r\n";
827 print OUT "\"$def_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
828 print OUT " \$(BuildCmds)\r\n";
829 print OUT "\r\n";
830 print OUT "\"$dbg_c_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
831 print OUT " \$(BuildCmds)\r\n";
832 print OUT "# End Custom Build\r\n";
833 } elsif($source_file =~ /([^\\]*?\.h)$/) {
834 my $h_file = $1;
836 foreach my $cfg (@cfgs) {
837 if($#cfgs == 0) {
838 # Nothing
839 } elsif($n == 0) {
840 print OUT "!IF \"\$(CFG)\" == \"$cfg\"\r\n";
841 print OUT "\r\n";
842 } else {
843 print OUT "\r\n";
844 print OUT "!ELSEIF \"\$(CFG)\" == \"$cfg\"\r\n";
845 print OUT "\r\n";
848 $output_dir = $cfg;
849 $output_dir =~ s/^$project - //;
850 $output_dir =~ s/ /_/g;
851 $output_dir =~ s/C\+\+/Cxx/g;
852 if($output_prefix_dir) {
853 $output_dir = "$output_prefix_dir\\$output_dir";
856 print OUT "# Begin Custom Build\r\n";
857 print OUT "OutDir=$output_dir\r\n";
858 print OUT "InputPath=$source_file\r\n";
859 print OUT "\r\n";
860 print OUT "\"\$(OutDir)\\wine\\$h_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
861 print OUT "\tcopy \"\$(InputPath)\" \"\$(OutDir)\\wine\"\r\n";
862 print OUT "\r\n";
863 print OUT "# End Custom Build\r\n";
866 if($#cfgs != 0) {
867 print OUT "\r\n";
868 print OUT "!ENDIF \r\n";
869 print OUT "\r\n";
873 print OUT "# End Source File\r\n";
875 print OUT "# End Group\r\n";
877 print OUT "# Begin Group \"Header Files\"\r\n";
878 print OUT "\r\n";
879 print OUT "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
880 foreach my $header_file (@header_files) {
881 print OUT "# Begin Source File\r\n";
882 print OUT "\r\n";
883 print OUT "SOURCE=.\\$header_file\r\n";
884 print OUT "# End Source File\r\n";
886 print OUT "# End Group\r\n";
890 print OUT "# Begin Group \"Resource Files\"\r\n";
891 print OUT "\r\n";
892 print OUT "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
893 foreach my $resource_file (@resource_files) {
894 print OUT "# Begin Source File\r\n";
895 print OUT "\r\n";
896 print OUT "SOURCE=.\\$resource_file\r\n";
897 print OUT "# End Source File\r\n";
899 print OUT "# End Group\r\n";
901 print OUT "# End Target\r\n";
902 print OUT "# End Project\r\n";
904 close(OUT);
907 sub _generate_dsw_header($) {
908 local *OUT = shift;
910 print OUT "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n";
911 print OUT "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n";
912 print OUT "\r\n";
915 sub _generate_dsw_project($$$$) {
916 local *OUT = shift;
918 my $project = shift;
919 my $dsp_file = shift;
920 my @dependencies = @{(shift)};
922 $dsp_file = "./$dsp_file";
923 $dsp_file =~ y%/%\\%;
925 @dependencies = sort(@dependencies);
927 print OUT "###############################################################################\r\n";
928 print OUT "\r\n";
929 print OUT "Project: \"$project\"=$dsp_file - Package Owner=<4>\r\n";
930 print OUT "\r\n";
931 print OUT "Package=<5>\r\n";
932 print OUT "{{{\r\n";
933 print OUT "}}}\r\n";
934 print OUT "\r\n";
935 print OUT "Package=<4>\r\n";
936 print OUT "{{{\r\n";
937 foreach my $dependency (@dependencies) {
938 print OUT " Begin Project Dependency\r\n";
939 print OUT " Project_Dep_Name $dependency\r\n";
940 print OUT " End Project Dependency\r\n";
942 print OUT "}}}\r\n";
943 print OUT "\r\n";
946 sub _generate_dsw_footer($) {
947 local *OUT = shift;
949 print OUT "###############################################################################\r\n";
950 print OUT "\r\n";
951 print OUT "Global:\r\n";
952 print OUT "\r\n";
953 print OUT "Package=<5>\r\n";
954 print OUT "{{{\r\n";
955 print OUT "}}}\r\n";
956 print OUT "\r\n";
957 print OUT "Package=<3>\r\n";
958 print OUT "{{{\r\n";
959 print OUT "}}}\r\n";
960 print OUT "\r\n";
961 print OUT "###############################################################################\r\n";
962 print OUT "\r\n";
965 if ($options->wine) {
966 my $dsw_file = "wine.dsw";
967 $output->progress("$dsw_file");
968 replace_file("$wine_dir/$dsw_file", \&_generate_wine_dsw);
971 sub _generate_wine_dsw($) {
972 local *OUT = shift;
974 _generate_dsw_header(\*OUT);
975 foreach my $module (sort(keys(%modules))) {
976 next if $module =~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
978 my $project = $modules{$module}{project};
979 my $dsp_file = $modules{$module}{dsp_file};
981 my @dependencies;
982 if($project =~ /^wine(?:_unicode)?$/) {
983 @dependencies = ();
984 } elsif($project =~ /^winebuild$/) {
985 @dependencies = ("wine", "wine_unicode");
986 } elsif($project =~ /^(?:gdi32)_.+?$/) {
987 @dependencies = ();
988 } else {
989 @dependencies = ("wine", "wine_unicode", "winebuild");
992 if($project =~ /^gdi32$/) {
993 foreach my $dir (@gdi32_dirs) {
994 my $dir2 = $dir;
995 $dir2 =~ s%^.*?/([^/]+)$%$1%;
997 my $module = "gdi32_$dir2";
998 $module =~ s%/%_%g;
999 push @dependencies, $module;
1003 _generate_dsw_project(\*OUT, $project, $dsp_file, \@dependencies);
1005 _generate_dsw_footer(\*OUT);
1007 return 1;
1010 if ($options->winetest) {
1011 my $dsw_file = "winetest.dsw";
1012 $output->progress("$dsw_file");
1013 replace_file("$wine_dir/$dsw_file", \&_generate_winetest_dsw);
1016 sub _generate_winetest_dsw($) {
1017 local *OUT = shift;
1019 _generate_dsw_header(\*OUT);
1021 my @runtests_dependencies = ();
1022 foreach my $module (sort(keys(%modules))) {
1023 next if $module !~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1024 next if $module eq "wineruntests";
1026 my $project = $modules{$module}{project};
1028 push @runtests_dependencies, $project;
1031 foreach my $module (sort(keys(%modules))) {
1032 next if $module !~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1034 my $project = $modules{$module}{project};
1035 my $dsp_file = $modules{$module}{dsp_file};
1037 my @dependencies;
1038 if($project =~ /^winetest$/) {
1039 @dependencies = ();
1040 } elsif($project =~ /^wineruntests$/) {
1041 @dependencies = @runtests_dependencies;
1042 } else {
1043 @dependencies = ("winetest");
1046 _generate_dsw_project(\*OUT, $project, $dsp_file, \@dependencies);
1049 _generate_dsw_footer(\*OUT);
1052 if ($options->winetest) {
1053 foreach my $module (sort(keys(%modules))) {
1054 next if $module !~ /_test\.exe$/;
1056 my $project = $modules{$module}{project};
1057 my $dsp_file = $modules{$module}{dsp_file};
1058 my @tests = @{$modules{$module}{tests}};
1060 my $testlist_c = $dsp_file;
1061 $testlist_c =~ s%[^/]*\.dsp$%testlist.c%;
1063 replace_file("$wine_dir/$testlist_c", \&_generate_testlist_c, \@tests);
1067 # ***** Keep in sync with tools/make_ctests *****
1068 sub _generate_testlist_c($$) {
1069 local *OUT = shift;
1071 my @tests = @{(shift)};
1073 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n";
1074 print OUT "\n";
1075 print OUT "/* stdarg.h is needed for Winelib */\n";
1076 print OUT "#include <stdarg.h>\n";
1077 print OUT "#include <stdio.h>\n";
1078 print OUT "#include <stdlib.h>\n";
1079 print OUT "#include \"windef.h\"\n";
1080 print OUT "#include \"winbase.h\"\n";
1081 print OUT "\n";
1082 foreach my $test (@tests) {
1083 print OUT "extern void func_$test(void);\n";
1085 print OUT "\n";
1086 print OUT "struct test\n";
1087 print OUT "{\n";
1088 print OUT " const char *name;\n";
1089 print OUT " void (*func)(void);\n";
1090 print OUT "};\n";
1091 print OUT "\n";
1092 print OUT "static const struct test winetest_testlist[] =\n";
1093 print OUT "{\n";
1094 foreach my $test (@tests) {
1095 print OUT " { \"$test\", func_$test },\n";
1097 print OUT " { 0, 0 }\n";
1098 print OUT "};\n";
1099 print OUT "\n";
1100 print OUT "#define WINETEST_WANT_MAIN\n";
1101 print OUT "#include \"wine/test.h\"\n";
1104 if ($options->winetest) {
1105 replace_file("$wine_dir/runtests.c", \&_generate_runtests_c);
1108 sub _generate_runtests_c($) {
1109 local *OUT = shift;
1111 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n";
1113 print OUT "\n";
1114 print OUT "#include <stdio.h>\n";
1115 print OUT "#include <stdlib.h>\n";
1116 print OUT "\n";
1118 print OUT "int main(int argc, char *argv[])\n";
1119 print OUT "{\n";
1120 print OUT " char output_dir[] = __WINETEST_OUTPUT_DIR;\n";
1121 print OUT " char command[4096];\n";
1122 print OUT "\n";
1123 foreach my $dsp_file (keys(%runtests)) {
1124 my @tests = @{$runtests{$dsp_file}};
1126 my $project = $dsp_file;
1127 $project =~ s%^(.*?)/?([^/]+)\.dsp$%$2%;
1128 my $dir = $1;
1129 $dir =~ s%/%\\\\%g;
1131 foreach my $test (@tests) {
1132 print OUT " sprintf(command, \"$dir\\\\%s\\\\$project.exe $test\", output_dir);\n";
1133 print OUT " system(command);\n";
1134 print OUT "\n";
1137 print OUT " return 0;\n";
1138 print OUT "}\n";
1141 if ($options->winetest) {
1142 replace_file("$wine_dir/winetest.c", \&_generate_winetest_c);
1145 sub _generate_winetest_c($) {
1146 local *OUT = shift;
1148 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n\n";
1150 print OUT "/* Force the linker to generate a .lib file */\n";
1151 print OUT "void __wine_dummy_lib_function()\n{\n}\n\n";
1154 if ($options->wine) {
1155 my $config_h = "include/config.h";
1157 $output->progress("$config_h");
1159 replace_file("$wine_dir/$config_h", \&_generate_config_h);
1162 sub _generate_config_h($) {
1163 local *OUT = shift;
1165 print OUT "#define __WINE_CONFIG_H\n";
1166 print OUT "\n";
1168 my @headers = qw(direct.h fcntl.h io.h string.h process.h);
1169 foreach my $header (@headers) {
1170 $header =~ y/\.\//__/;
1171 print OUT "#define HAVE_\U$header\E\n";
1172 print OUT "\n";
1175 my @functions = qw(
1176 _alldiv _allmul _allrem _aulldiv _aullrem
1177 _access _chdir _close _lseek _mkdir _open _pclose _popen _read _rmdir _write _stat
1178 _snprintf _spawnvp _stricmp _strnicmp _vsnprintf _wcsicmp
1179 ecvt fcvt gcvt
1180 memmove
1181 strerror
1182 wcslen
1184 foreach my $function (@functions) {
1185 print OUT "#define HAVE_\U$function\E 1\n";
1186 print OUT "\n";
1189 if(0) {
1190 print OUT "#define NEED_STDCALL_DECORATION 1\n";
1191 print OUT "\n";
1194 print OUT "#define X_DISPLAY_MISSING 1\n";
1195 print OUT "\n";
1197 print OUT "/* Define to a macro to generate an assembly function directive */\n";
1198 print OUT "#define __ASM_FUNC(name) \"\"\n";
1199 print OUT "\n";
1201 print OUT "/* Define to a macro to generate an assembly name from a C symbol */\n";
1202 print OUT "#define __ASM_NAME(name) name\n";
1203 print OUT "\n";
1205 print OUT "/* Define to the assembler keyword used to specify a word value */\n";
1206 print OUT "#define __ASM_SHORT \".short\"\n";
1207 print OUT "\n";
1209 print OUT "/* Define to the assembler keyword used to specify an ASCII string */\n";
1210 print OUT "#define __ASM_STRING \".string\"\n";
1211 print OUT "\n";
1213 print OUT "/* Define to the address where bug reports for this package should be sent. */\n";
1214 print OUT "#define PACKAGE_BUGREPORT \"\"\n";
1215 print OUT "\n";
1217 print OUT "/* Define to the full name of this package. */\n";
1218 print OUT "#define PACKAGE_NAME \"Wine\"\n";
1219 print OUT "\n";
1221 print OUT "/* Define to the full name and version of this package. */\n";
1222 print OUT "#define PACKAGE_STRING \"Wine YYYYMMDD\"\n";
1223 print OUT "\n";
1225 print OUT "/* Define to the one symbol short name of this package. */\n";
1226 print OUT "#define PACKAGE_TARNAME \"wine\"\n";
1227 print OUT "\n";
1229 print OUT "/* Define to the version of this package. */\n";
1230 print OUT "#define PACKAGE_VERSION \"YYYYMMDD\"\n";
1231 print OUT "\n";
1233 close(OUT);