user32: Avoid using CONST.
[wine/multimedia.git] / tools / winapi / msvcmaker
blob0c82420962d703f5f46a75d691888973b8989a3e
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 # These DLLs don't have a hope of compiling properly
40 my @unix_dependent_dlls = qw(iphlpapi mountmgr.sys ntdll mswsock opengl32
41 secur32 winex11 wnaspi32 ws2_32);
43 sub is_unix_dependent_dll($) {
44 my $dll = shift;
46 foreach my $unix_only_dll (@unix_dependent_dlls) {
47 if($dll eq $unix_only_dll) {
48 return 1;
52 return 0;
55 sub read_spec_file($) {
56 my $spec_file = shift;
58 my $module = $spec_file;
59 $module =~ s%^.*?([^/]+)\.spec$%$1%;
60 $module .= ".dll" if $module !~ /\./;
62 my $type = "win32";
64 open(IN, "< $wine_dir/$spec_file") || die "Error: Can't open $wine_dir/$spec_file: $!\n";
66 my $header = 1;
67 my $lookahead = 0;
68 while($lookahead || defined($_ = <IN>)) {
69 $lookahead = 0;
71 s/^\s*?(.*?)\s*$/$1/; # remove whitespace at beginning and end of line
72 s/^(.*?)\s*#.*$/$1/; # remove comments
73 /^$/ && next; # skip empty lines
75 if($header) {
76 if(/^(?:\d+|@)/) {
77 $header = 0;
78 $lookahead = 1;
80 next;
83 if(/^(\d+|@)\s+pascal(?:16)?/) {
84 $type = "win16";
85 last;
88 close(IN);
90 # FIXME: Kludge
91 if($module =~ /^(?:(?:imm|ole2conv|ole2prox|ole2thk|rasapi16|msacm|windebug)\.dll|comm\.drv)$/) {
92 $type = "win16";
95 if($type eq "win32") {
96 $modules{$module}{module} = $module;
97 $modules{$module}{type} = $type;
98 $modules{$module}{spec_file} = $spec_file;
102 if ($options->wine || $options->winetest) {
103 foreach my $spec_file (@spec_files) {
104 my $dll = $spec_file;
105 $dll =~ s%dlls/([^/]+)/[^/]+\.spec%$1%;
106 if(!is_unix_dependent_dll($dll)) {
107 read_spec_file($spec_file);
112 my @gdi32_dirs = qw(dlls/gdi32/enhmfdrv dlls/gdi32/mfdrv);
114 push @makefile_in_files, "libs/wine/Makefile.in";
115 push @makefile_in_files, "tools/winebuild/Makefile.in";
117 sub filter_files($$) {
118 my $files = shift;
119 my $filter = shift;
121 my $filtered_files = [];
122 my $rest_of_files = [];
123 foreach my $file (@$files) {
124 if($file =~ /$filter/) {
125 $file =~ s%.*?([^/]+)$%./$1%; # FIXME: Kludge
126 push @$filtered_files, $file;
127 } else {
128 push @$rest_of_files, $file;
131 return ($rest_of_files, $filtered_files);
134 my %wine_test_dsp_files;
136 MAKEFILE_IN: foreach my $makefile_in_file (@makefile_in_files) {
137 open(IN, "< $wine_dir/$makefile_in_file") || die "Error: Can't open $wine_dir/$makefile_in_file: $!\n";
139 my $topobjdir;
140 my $module;
141 my $testdll;
142 my @imports;
143 my $type;
144 my $dll;
146 my %vars;
148 my $again = 0;
149 my $lookahead = 0;
151 $dll = $makefile_in_file;
152 $dll =~ s%dlls/([^/]+)/Makefile\.in%$1%;
154 if($makefile_in_file eq "loader/Makefile.in" ||
155 is_unix_dependent_dll($dll)) {
156 next;
159 while($again || defined(my $line = <IN>)) {
160 if(!$again) {
161 chomp $line;
162 if($lookahead) {
163 $lookahead = 0;
164 $_ .= " " . $line;
165 } else {
166 $_ = $line;
168 } else {
169 $again = 0;
172 s/^\s*?(.*?)\s*$/$1/; # remove whitespace at beginning and end of line
173 s/^(.*?)\s*#.*$/$1/; # remove comments
174 /^$/ && next; # skip empty lines
176 if(s/\\$/ /s) {
177 $lookahead = 1;
178 next;
181 if(/^MODULE\s*=\s*([\w\.]+)$/) {
182 $module = $1;
183 } elsif (/^\@MAKE_IMPLIB_RULES\@/) {
184 $type = "lib";
185 } elsif(/^TOPOBJDIR\s*=\s*(\S+)\s*$/) {
186 $topobjdir = $1;
187 } elsif (/^TESTDLL\s*=\s*(\S+)\s*$/) {
188 $testdll = $1;
189 } elsif (/^IMPORTS\s*=\s*/) {
190 push @imports, grep !/^ntdll$/, split /\s+/s, $';
191 } elsif (/^DELAYIMPORTS\s*=\s*/) {
192 push @imports, $;
193 } elsif (/^EXTRALIBS\s*=\s*/) {
194 push @imports, map { /^-l(dxerr8|dxerr9|dxguid|strmiids|uuid)$/ ? $1 : () } split /\s+/s, $';
195 } elsif (/^CTESTS\s*=\s*/ || ( ($makefile_in_file =~ /\/tests\/Makefile\.in$/) && /^C_SRCS\s*=\s*/ ) ) {
196 my @files = split /\s+/s, $';
198 my $dir = $makefile_in_file;
199 $dir =~ s/\/Makefile\.in$//;
201 my $dsp_file = $testdll;
202 $dsp_file =~ s/\.(dll|drv)$/_test.dsp/;
203 $dsp_file = "$dir/$dsp_file";
205 $wine_test_dsp_files{$dsp_file}{files} = [@files, "testlist.c"];
206 $wine_test_dsp_files{$dsp_file}{imports} = [@imports];
207 } elsif(/^(\w+)\s*=\s*/) {
208 my $var = $1;
209 my @files = split /\s+/s, $';
211 @files = map {
212 if(/^\$\((\w+):\%=(.*?)\%(.*?)\)$/) {
213 my @list = @{$vars{$1}};
214 my $prefix = $2;
215 my $suffix = $3;
216 foreach my $item (@list) {
217 $item = "$prefix$item$suffix";
219 @list;
220 } elsif(/^\$\(TOPOBJDIR\)(.*?)$/) {
221 "$topobjdir$1";
222 } elsif(/^\$/) {
223 print STDERR "unknown variable '$_'\n" if 0;
225 } else {
228 } @files;
230 $vars{$var} = \@files;
234 close(IN);
236 if (!$module) {
237 if ($makefile_in_file eq "libs/wine/Makefile.in") {
238 $module = "wine.lib";
239 } elsif ($makefile_in_file eq "tools/winebuild/Makefile.in") {
240 $module = "winebuild.exe";
244 next if !$module;
246 my $c_srcs = [];
247 my $source_files = [];
248 if(exists($vars{C_SRCS})) {
249 $c_srcs = [sort(@{$vars{C_SRCS}})];
250 $source_files = [sort(@{$vars{C_SRCS}})];
253 my $header_files = [];
254 if(exists($vars{H_SRCS})) {
255 $header_files = [sort(@{$vars{H_SRCS}})];
258 my $resource_files = [];
259 if(exists($vars{RC_SRCS})) {
260 $resource_files = [sort(@{$vars{RC_SRCS}})];
263 my $idl_h_files = [];
264 if(exists($vars{IDL_H_SRCS})) {
265 $idl_h_files = [sort(@{$vars{IDL_H_SRCS}})];
268 my $idl_c_files = [];
269 if(exists($vars{IDL_C_SRCS})) {
270 $idl_c_files = [sort(@{$vars{IDL_C_SRCS}})];
273 my $idl_s_files = [];
274 if(exists($vars{IDL_S_SRCS})) {
275 $idl_s_files = [sort(@{$vars{IDL_S_SRCS}})];
278 my $idl_p_files = [];
279 if(exists($vars{IDL_P_SRCS})) {
280 $idl_p_files = [sort(@{$vars{IDL_P_SRCS}})];
283 my $idl_tlb_files = [];
284 if(exists($vars{IDL_TLB_SRCS})) {
285 $idl_tlb_files = [sort(@{$vars{IDL_TLB_SRCS}})];
288 my $extradefs;
289 if(exists($vars{EXTRADEFS})) {
290 $extradefs = $vars{EXTRADEFS};
293 my $project = $module;
294 $project =~ s/\.(?:dll|exe|lib)$//;
295 $project =~ y/./_/;
297 if($module =~ /\.exe$/) {
298 $type = "exe";
299 } elsif($module =~ /\.lib$/) {
300 $type = "lib";
301 } elsif(!$type) {
302 $type = "dll";
305 my $dsp_file = $makefile_in_file;
306 $dsp_file =~ s/Makefile.in$/$project.dsp/;
308 if($module eq "gdi32.dll") {
309 foreach my $dir (@gdi32_dirs) {
310 my $dir2 = $dir;
311 $dir2 =~ s%^.*?/([^/]+)$%$1%;
313 my $module = "gdi32_$dir2.lib";
314 $module =~ s%/%_%g;
316 my $project = "gdi32_$dir2";
317 $project =~ s%/%_%g;
319 my $type = "lib";
320 my $dsp_file = "$dir/$project.dsp";
322 ($source_files, my $local_source_files) = filter_files($source_files, "$dir2/");
323 ($header_files, my $local_header_files) = filter_files($header_files, "$dir2/");
324 ($resource_files, my $local_resource_files) = filter_files($resource_files, "$dir2/");
325 ($idl_h_files, my $local_idl_h_files) = filter_files($idl_h_files, "$dir2/");
327 $modules{$module}{wine} = 1;
328 $modules{$module}{winetest} = 0;
329 $modules{$module}{project} = $project;
330 $modules{$module}{type} = $type;
331 $modules{$module}{dsp_file} = $dsp_file;
332 $modules{$module}{c_srcs} = $c_srcs;
333 $modules{$module}{source_files} = $local_source_files;
334 $modules{$module}{header_files} = $local_header_files;
335 $modules{$module}{resource_files} = $local_resource_files;
336 $modules{$module}{imports} = [];
337 $modules{$module}{idl_h_files} = $local_idl_h_files;
338 $modules{$module}{idl_c_files} = [];
339 $modules{$module}{idl_s_files} = [];
340 $modules{$module}{idl_p_files} = [];
341 $modules{$module}{idl_tlb_files} = [];
342 $modules{$module}{extradefs} = $extradefs if $extradefs;
346 $modules{$module}{wine} = 1;
347 $modules{$module}{winetest} = 0;
348 $modules{$module}{project} = $project;
349 $modules{$module}{type} = $type;
350 $modules{$module}{dsp_file} = $dsp_file;
351 $modules{$module}{c_srcs} = $c_srcs;
352 $modules{$module}{source_files} = $source_files;
353 $modules{$module}{header_files} = $header_files;
354 $modules{$module}{resource_files} = $resource_files;
355 $modules{$module}{imports} = [@imports];
356 $modules{$module}{idl_h_files} = $idl_h_files;
357 $modules{$module}{idl_c_files} = $idl_c_files;
358 $modules{$module}{idl_s_files} = $idl_s_files;
359 $modules{$module}{idl_p_files} = $idl_p_files;
360 $modules{$module}{idl_tlb_files} = $idl_tlb_files;
361 $modules{$module}{extradefs} = $extradefs if $extradefs;
364 $wine_test_dsp_files{"wineruntests.dsp"}{files} = ["runtests.c"];
365 $wine_test_dsp_files{"wineruntests.dsp"}{imports} = [];
367 $wine_test_dsp_files{"winetest.dsp"}{files} = [
368 'include/wine/exception.h',
369 'include/wine/test.h',
370 'include/wine/unicode.h',
371 'winetest.c'
373 $wine_test_dsp_files{"winetest.dsp"}{imports} = [];
375 my %runtests = ();
377 foreach my $dsp_file (keys(%wine_test_dsp_files)) {
378 my $project = $dsp_file;
379 $project =~ s%^(?:.*?/)?([^/]+)\.dsp$%$1%;
381 my @files = @{$wine_test_dsp_files{$dsp_file}{files}};
382 my @imports = @{$wine_test_dsp_files{$dsp_file}{imports}};
384 my $type;
385 my $c_srcs = [];
386 my $source_files = [];
387 my $header_files = [];
388 my $resource_files = [];
389 my $idl_h_files = [];
391 my @tests = ();
393 if ($project eq "winetest") {
394 $type = "lib";
395 $c_srcs = [@files];
396 $source_files = [@files];
397 $header_files = [];
398 $resource_files = [];
399 } elsif ($project eq "wineruntests") {
400 $type = "exe";
401 $c_srcs = [@files];
402 $source_files = [@files];
403 $header_files = [];
404 $resource_files = [];
405 } else {
406 $type = "exe";
407 $c_srcs = [@files];
408 $source_files = [@files];
409 $header_files = [];
410 $resource_files = [];
412 @tests = map {
413 if (/^testlist\.c$/) {
415 } else {
416 s/\.c$//;
419 } @files;
421 $runtests{$dsp_file} = [@tests];
423 my $module = "$project.$type";
425 $modules{$module}{wine} = 0;
426 $modules{$module}{winetest} = 1;
428 $modules{$module}{project} = $project;
429 $modules{$module}{type} = $type;
430 $modules{$module}{dsp_file} = $dsp_file;
431 $modules{$module}{c_srcs} = $c_srcs;
432 $modules{$module}{source_files} = $source_files;
433 $modules{$module}{header_files} = $header_files;
434 $modules{$module}{resource_files} = $resource_files;
435 $modules{$module}{imports} = [@imports];
436 $modules{$module}{idl_h_files} = [];
437 $modules{$module}{idl_c_files} = [];
438 $modules{$module}{idl_s_files} = [];
439 $modules{$module}{idl_p_files} = [];
440 $modules{$module}{idl_tlb_files} = [];
442 $modules{$module}{tests} = [@tests];
445 foreach my $module (sort(keys(%modules))) {
446 if($module =~ /^(?:ttydrv.dll|x11drv.dll)$/) {
447 delete $modules{$module};
451 my @modules = ();
452 foreach my $module (sort(keys(%modules))) {
453 if (($options->wine && $modules{$module}{wine}) ||
454 ($options->winetest && $modules{$module}{winetest}))
456 push @modules, $module;
460 my $progress_output;
461 my $progress_current = 0;
462 my $progress_max = scalar(@modules);
464 foreach my $module (@modules) {
465 my $dsp_file = $modules{$module}{dsp_file};
466 replace_file("$wine_dir/$dsp_file", \&_generate_dsp, $module);
469 sub output_dsp_idl_rules($$$) {
470 my $wine_include_dir = shift;
471 my $ext = shift;
472 my @idl_src_files = @{(shift)};
474 foreach my $idl_src_file (@idl_src_files) {
475 $idl_src_file =~ s%/%\\%g;
476 if($idl_src_file !~ /^\./) {
477 $idl_src_file = ".\\$idl_src_file";
480 print OUT "# Begin Source File\r\n";
481 print OUT "\r\n";
483 print OUT "SOURCE=$idl_src_file\r\n";
485 my $basename = $idl_src_file;
486 $basename =~ s/\.idl$//;
488 print OUT "# PROP Ignore_Default_Tool 1\r\n";
489 print OUT "# Begin Custom Build\r\n";
490 print OUT "InputPath=$idl_src_file\r\n";
491 print OUT "\r\n";
492 print OUT "BuildCmds= \\\r\n";
493 print OUT "\tmidl /nologo /I $wine_include_dir $idl_src_file ";
494 if ($ext eq ".h") {
495 print OUT "/client none /server none /notlb /h ";
496 } elsif ($ext eq "_c.c") {
497 print OUT "/server none /notlb /cstub ";
498 } elsif ($ext eq "_s.c") {
499 print OUT "/client none /notlb /sstub ";
500 } elsif ($ext eq "_p.c") {
501 print OUT "/client none /server none /notlb /proxy ";
502 } elsif ($ext eq ".tlb") {
503 print OUT "/client none /server none /tlb ";
505 print OUT "$basename$ext\r\n";
506 print OUT "\r\n";
507 print OUT "\"$basename$ext\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
508 print OUT " \$(BuildCmds)\r\n";
509 print OUT "# End Custom Build\r\n";
511 print OUT "# End Source File\r\n";
515 sub _generate_dsp($$) {
516 local *OUT = shift;
518 my $module = shift;
520 my $dsp_file = $modules{$module}{dsp_file};
521 my $project = $modules{$module}{project};
522 my @imports = @{$modules{$module}{imports}};
524 my $lib = ($modules{$module}{type} eq "lib");
525 my $dll = ($modules{$module}{type} eq "dll");
526 my $exe = ($modules{$module}{type} eq "exe");
528 my $console = $exe; # FIXME: Not always correct
530 my $msvc_wine_dir = do {
531 my @parts = split(m%/%, $dsp_file);
532 if($#parts == 1) {
533 "..";
534 } elsif($#parts == 2) {
535 "..\\..";
536 } else {
537 "..\\..\\..";
540 my $wine_include_dir = "$msvc_wine_dir\\include";
542 $progress_current++;
543 $output->progress("$dsp_file (file $progress_current of $progress_max)");
545 my $base_module = $module;
546 $base_module =~ s/\.(?:dll)$//;
548 my @c_srcs = @{$modules{$module}{c_srcs}};
549 my @source_files = @{$modules{$module}{source_files}};
550 my @header_files = @{$modules{$module}{header_files}};
551 my @resource_files = @{$modules{$module}{resource_files}};
552 my @idl_h_files = @{$modules{$module}{idl_h_files}};
553 my @idl_c_files = @{$modules{$module}{idl_c_files}};
554 my @idl_s_files = @{$modules{$module}{idl_s_files}};
555 my @idl_p_files = @{$modules{$module}{idl_p_files}};
556 my @idl_tlb_files = @{$modules{$module}{idl_tlb_files}};
558 if ($project !~ /^wine(?:build|runtests|test)?$/ &&
559 $project !~ /^(?:gdi32)_.+?$/ &&
560 $project !~ /_test$/ &&
561 !$lib)
563 push @source_files, "$base_module.spec";
564 @source_files = sort(@source_files);
567 my $no_cpp = 1;
568 my $no_msvc_headers = 1;
569 if ($project =~ /^wine(?:runtests|test)$/ || $project =~ /_test$/) {
570 $no_msvc_headers = 0;
573 my @cfgs;
575 push @cfgs, "$project - Win32";
577 if (!$no_cpp) {
578 my @_cfgs;
579 foreach my $cfg (@cfgs) {
580 push @_cfgs, "$cfg C";
581 push @_cfgs, "$cfg C++";
583 @cfgs = @_cfgs;
586 if (!$no_release) {
587 my @_cfgs;
588 foreach my $cfg (@cfgs) {
589 push @_cfgs, "$cfg Debug";
590 push @_cfgs, "$cfg Release";
592 @cfgs = @_cfgs;
593 } else {
594 my @_cfgs;
595 foreach my $cfg (@cfgs) {
596 push @_cfgs, "$cfg Debug";
598 @cfgs = @_cfgs;
601 if (!$no_msvc_headers) {
602 my @_cfgs;
603 foreach my $cfg (@cfgs) {
604 push @_cfgs, "$cfg MSVC Headers";
605 push @_cfgs, "$cfg Wine Headers";
607 @cfgs = @_cfgs;
610 my $default_cfg = $cfgs[$#cfgs];
612 print OUT "# Microsoft Developer Studio Project File - Name=\"$project\" - Package Owner=<4>\r\n";
613 print OUT "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n";
614 print OUT "# ** DO NOT EDIT **\r\n";
615 print OUT "\r\n";
617 if ($lib) {
618 print OUT "# TARGTYPE \"Win32 (x86) Static Library\" 0x0104\r\n";
619 } elsif ($dll) {
620 print OUT "# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\r\n";
621 } else {
622 print OUT "# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n";
624 print OUT "\r\n";
626 print OUT "CFG=$default_cfg\r\n";
627 print OUT "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n";
628 print OUT "!MESSAGE use the Export Makefile command and run\r\n";
629 print OUT "!MESSAGE \r\n";
630 print OUT "!MESSAGE NMAKE /f \"$project.mak\".\r\n";
631 print OUT "!MESSAGE \r\n";
632 print OUT "!MESSAGE You can specify a configuration when running NMAKE\r\n";
633 print OUT "!MESSAGE by defining the macro CFG on the command line. For example:\r\n";
634 print OUT "!MESSAGE \r\n";
635 print OUT "!MESSAGE NMAKE /f \"$project.mak\" CFG=\"$default_cfg\"\r\n";
636 print OUT "!MESSAGE \r\n";
637 print OUT "!MESSAGE Possible choices for configuration are:\r\n";
638 print OUT "!MESSAGE \r\n";
639 foreach my $cfg (@cfgs) {
640 if ($lib) {
641 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Static Library\")\r\n";
642 } elsif ($dll) {
643 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n";
644 } else {
645 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Console Application\")\r\n";
648 print OUT "!MESSAGE \r\n";
649 print OUT "\r\n";
651 print OUT "# Begin Project\r\n";
652 print OUT "# PROP AllowPerConfigDependencies 0\r\n";
653 print OUT "# PROP Scc_ProjName \"\"\r\n";
654 print OUT "# PROP Scc_LocalPath \"\"\r\n";
655 print OUT "CPP=cl.exe\r\n";
656 print OUT "MTL=midl.exe\r\n" if !$lib && !$exe;
657 print OUT "RSC=rc.exe\r\n";
658 print OUT "\r\n";
660 my $n = 0;
662 my $output_dir;
663 foreach my $cfg (@cfgs) {
664 if($#cfgs == 0) {
665 # Nothing
666 } elsif($n == 0) {
667 print OUT "!IF \"\$(CFG)\" == \"$cfg\"\r\n";
668 print OUT "\r\n";
669 } else {
670 print OUT "\r\n";
671 print OUT "!ELSEIF \"\$(CFG)\" == \"$cfg\"\r\n";
672 print OUT "\r\n";
675 my $debug = ($cfg !~ /Release/);
676 my $msvc_headers = ($cfg =~ /MSVC Headers/);
678 print OUT "# PROP BASE Use_MFC 0\r\n";
680 if($debug) {
681 print OUT "# PROP BASE Use_Debug_Libraries 1\r\n";
682 } else {
683 print OUT "# PROP BASE Use_Debug_Libraries 0\r\n";
686 $output_dir = $cfg;
687 $output_dir =~ s/^$project - //;
688 $output_dir =~ s/ /_/g;
689 $output_dir =~ s/C\+\+/Cxx/g;
690 if($output_prefix_dir) {
691 $output_dir = "$output_prefix_dir\\$output_dir";
694 print OUT "# PROP BASE Output_Dir \"$output_dir\"\r\n";
695 print OUT "# PROP BASE Intermediate_Dir \"$output_dir\"\r\n";
697 print OUT "# PROP BASE Target_Dir \"\"\r\n";
699 print OUT "# PROP Use_MFC 0\r\n";
700 if($debug) {
701 print OUT "# PROP Use_Debug_Libraries 1\r\n";
702 } else {
703 print OUT "# PROP Use_Debug_Libraries 0\r\n";
705 print OUT "# PROP Output_Dir \"$output_dir\"\r\n";
706 print OUT "# PROP Intermediate_Dir \"$output_dir\"\r\n";
708 print OUT "# PROP Ignore_Export_Lib 0\r\n" if $dll;
709 print OUT "# PROP Target_Dir \"\"\r\n";
711 print OUT "# ADD BASE CPP /nologo ";
712 my @defines = qw(WINVER=0x0600 _WIN32_WINNT=0x0600 _WIN32_IE=0x0700 WIN32);
713 if($debug) {
714 if($lib || $exe) {
715 push @defines, qw(_DEBUG _MBCS _LIB);
716 } else {
717 print OUT "/MDd ";
718 push @defines, qw(_DEBUG _WINDOWS _MBCS _USRDLL);
720 print OUT "/W3 /Gm /GX /Zi /Od";
721 } else {
722 if($lib || $exe) {
723 push @defines, qw(NDEBUG _MBCS _LIB);
724 } else {
725 print OUT "/MD ";
726 push @defines, qw(NDEBUG _WINDOWS _MBCS _USRDLL);
728 print OUT "/W3 /GX /O2";
731 foreach my $define (@defines) {
732 if ($define !~ /=/) {
733 print OUT " /D \"$define\"";
734 } else {
735 print OUT " /D $define";
738 print OUT " /YX" if $lib || $exe;
739 print OUT " /FD";
740 print OUT " /GZ" if $debug;
741 print OUT " /c";
742 print OUT "\r\n";
744 my @defines2 = qw(_CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE
745 USE_COMPILER_EXCEPTIONS _USE_MATH_DEFINES
746 WINVER=0x0600 _WIN32_WINNT=0x0600 _WIN32_IE=0x0700);
747 if($debug) {
748 if($lib) {
749 print OUT "# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od";
750 push @defines2, qw(WIN32 _DEBUG _WINDOWS _MBCS _LIB);
751 } else {
752 print OUT "# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od";
753 push @defines2, qw(_DEBUG WIN32 _WINDOWS _MBCS _USRDLL);
755 } else {
756 if($lib) {
757 print OUT "# ADD CPP /nologo /MD /W3 /GX /O2";
758 push @defines2, qw(WIN32 NDEBUG _WINDOWS _MBCS _LIB);
759 } else {
760 print OUT "# ADD CPP /nologo /MD /W3 /GX /O2";
761 push @defines2, qw(NDEBUG WIN32 _WINDOWS _MBCS _USRDLL);
765 my @includes = ();
766 if($wine) {
767 push @defines2, qw(__WINESRC__) if $project !~ /^(?:wine(?:build|test)|.*?_test)$/;
768 if ($msvc_headers) {
769 push @defines2, qw(__WINE_USE_NATIVE_HEADERS);
771 my $output_dir2 = $output_dir;
772 $output_dir2 =~ s/\\/\\\\/g;
773 push @defines2, "__WINETEST_OUTPUT_DIR=\\\"$output_dir2\\\"";
774 push @defines2, qw(__i386__ _X86_);
776 if ($project eq "wine") {
777 push @defines2, "WINE_UNICODE_API=";
780 if ($project =~ /_test$/) {
781 push @includes, "$msvc_wine_dir\\$output_dir";
784 if (!$msvc_headers || $project eq "winetest") {
785 push @includes, $wine_include_dir;
789 if($wine) {
790 foreach my $include (@includes) {
791 print OUT " /I \"$include\"";
795 foreach my $define (@defines2) {
796 if ($define !~ /=/) {
797 print OUT " /D \"$define\"";
798 } else {
799 print OUT " /D $define";
802 print OUT " /D inline=__inline" if $wine;
803 print OUT " /D \"__STDC__\"" if 0 && $wine;
805 if(exists($modules{$module}{extradefs})) {
806 print OUT " @{$modules{$module}{extradefs}} ";
809 print OUT " /YX" if $lib;
810 print OUT " /FR" if !$lib;
811 print OUT " /FD";
812 print OUT " /GZ" if $debug;
813 print OUT " /c";
814 print OUT " /TP" if !$no_cpp;
815 print OUT "\r\n";
817 if($debug) {
818 print OUT "# SUBTRACT CPP /X /YX\r\n" if $dll;
819 print OUT "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
820 print OUT "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
821 print OUT "# ADD BASE RSC /l 0x41d /d \"_DEBUG\"\r\n";
822 print OUT "# ADD RSC /l 0x41d";
823 if($wine) {
824 foreach my $include (@includes) {
825 print OUT " /i \"$include\"";
828 print OUT " /d \"_DEBUG\"\r\n";
829 } else {
830 print OUT "# SUBTRACT CPP /YX\r\n" if $dll;
831 print OUT "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
832 print OUT "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
833 print OUT "# ADD BASE RSC /l 0x41d /d \"NDEBUG\"\r\n";
834 print OUT "# ADD RSC /l 0x41d";
835 if($wine) {
836 foreach my $include (@includes) {
837 print OUT " /i \"$include\"";
840 print OUT "/d \"NDEBUG\"\r\n";
842 print OUT "BSC32=bscmake.exe\r\n";
843 print OUT "# ADD BASE BSC32 /nologo\r\n";
844 print OUT "# ADD BSC32 /nologo\r\n";
846 if($exe || $dll) {
847 print OUT "LINK32=link.exe\r\n";
848 print OUT "# ADD BASE LINK32";
849 my @libraries = qw(kernel32.lib user32.lib gdi32.lib winspool.lib
850 comdlg32.lib advapi32.lib shell32.lib ole32.lib
851 oleaut32.lib uuid.lib odbc32.lib odbccp32.lib);
852 foreach my $library (@libraries) {
853 print OUT " $library";
855 print OUT " /nologo";
856 print OUT " /dll" if $dll;
857 print OUT " /subsystem:console" if $console;
858 print OUT " /debug" if $debug;
859 print OUT " /machine:I386";
860 print OUT " /pdbtype:sept" if $debug;
861 print OUT "\r\n";
863 print OUT "# ADD LINK32";
864 print OUT " libcmt.lib" if $project =~ /^ntdll$/; # FIXME: Kludge
865 foreach my $import (@imports) {
866 print OUT " $import.lib" if ($import ne "msvcrt");
868 print OUT " /nologo";
869 print OUT " /dll" if $dll;
870 print OUT " /subsystem:console" if $console;
871 print OUT " /debug" if $debug;
872 print OUT " /machine:I386";
873 print OUT " /nodefaultlib" if $project =~ /^ntdll$/; # FIXME: Kludge
874 print OUT " /def:\"$project.def\"" if $dll;
875 print OUT " /pdbtype:sept" if $debug;
876 print OUT "\r\n";
877 } else {
878 print OUT "LIB32=link.exe -lib\r\n";
879 print OUT "# ADD BASE LIB32 /nologo\r\n";
880 print OUT "# ADD LIB32 /nologo\r\n";
883 $n++;
886 if($#cfgs != 0) {
887 print OUT "\r\n";
888 print OUT "!ENDIF \r\n";
889 print OUT "\r\n";
892 print OUT "# Begin Target\r\n";
893 print OUT "\r\n";
894 foreach my $cfg (@cfgs) {
895 print OUT "# Name \"$cfg\"\r\n";
898 print OUT "# Begin Group \"Source Files\"\r\n";
899 print OUT "\r\n";
900 print OUT "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
902 if ($project eq "winebuild") {
903 for my $ source_file ("getopt.c", "getopt1.c", "mkstemps.c")
905 print OUT "# Begin Source File\r\n";
906 print OUT "\r\n";
907 print OUT "SOURCE=..\\..\\libs\\port\\$source_file\r\n";
908 print OUT "# End Source File\r\n";
912 foreach my $source_file (@source_files) {
913 $source_file =~ s%/%\\%g;
914 if($source_file !~ /^\./) {
915 $source_file = ".\\$source_file";
918 print OUT "# Begin Source File\r\n";
919 print OUT "\r\n";
921 print OUT "SOURCE=$source_file\r\n";
923 if ($project eq "wine" && $source_file eq ".\\config.c") {
924 print OUT "# ADD CPP /D BINDIR=\\\"\\\" /D DLLDIR=\\\"\\\" /D LIB_TO_BINDIR=\\\"\\\" /D LIB_TO_DLLDIR=\\\"\\\" /D BIN_TO_DLLDIR=\\\"\\\" /D LIB_TO_DATADIR=\\\"\\\" /D BIN_TO_DATADIR=\\\"\\\"\r\n";
927 if($source_file =~ /^(.*?)\.spec$/) {
928 my $basename = $1;
930 my $spec_file = $source_file;
931 my $def_file = "$basename.def";
933 my $srcdir = "."; # FIXME: Is this really always correct?
935 print OUT "# Begin Custom Build\r\n";
936 print OUT "InputPath=$spec_file\r\n";
937 print OUT "\r\n";
938 print OUT "BuildCmds= \\\r\n";
939 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe -w --def -k -o $def_file --export $spec_file\r\n";
940 print OUT "\r\n";
941 print OUT "\"$def_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
942 print OUT " \$(BuildCmds)\r\n";
943 print OUT "# End Custom Build\r\n";
944 } elsif($source_file =~ /([^\\]*?\.h)$/) {
945 my $h_file = $1;
947 foreach my $cfg (@cfgs) {
948 if($#cfgs == 0) {
949 # Nothing
950 } elsif($n == 0) {
951 print OUT "!IF \"\$(CFG)\" == \"$cfg\"\r\n";
952 print OUT "\r\n";
953 } else {
954 print OUT "\r\n";
955 print OUT "!ELSEIF \"\$(CFG)\" == \"$cfg\"\r\n";
956 print OUT "\r\n";
959 $output_dir = $cfg;
960 $output_dir =~ s/^$project - //;
961 $output_dir =~ s/ /_/g;
962 $output_dir =~ s/C\+\+/Cxx/g;
963 if($output_prefix_dir) {
964 $output_dir = "$output_prefix_dir\\$output_dir";
967 print OUT "# Begin Custom Build\r\n";
968 print OUT "OutDir=$output_dir\r\n";
969 print OUT "InputPath=$source_file\r\n";
970 print OUT "\r\n";
971 print OUT "\"\$(OutDir)\\wine\\$h_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
972 print OUT "\tcopy \"\$(InputPath)\" \"\$(OutDir)\\wine\"\r\n";
973 print OUT "\r\n";
974 print OUT "# End Custom Build\r\n";
977 if($#cfgs != 0) {
978 print OUT "\r\n";
979 print OUT "!ENDIF \r\n";
980 print OUT "\r\n";
984 print OUT "# End Source File\r\n";
987 output_dsp_idl_rules $wine_include_dir, ".h", \@idl_h_files;
988 output_dsp_idl_rules $wine_include_dir, "_c.c", \@idl_c_files;
989 output_dsp_idl_rules $wine_include_dir, "_s.c", \@idl_s_files;
990 output_dsp_idl_rules $wine_include_dir, "_p.c", \@idl_p_files;
991 # Hack - stdole2.idl cannot be compiled with midl
992 if($project ne "include") {
993 output_dsp_idl_rules $wine_include_dir, ".tlb", \@idl_tlb_files;
996 print OUT "# End Group\r\n";
998 print OUT "# Begin Group \"Header Files\"\r\n";
999 print OUT "\r\n";
1000 print OUT "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
1001 foreach my $header_file (@header_files) {
1002 print OUT "# Begin Source File\r\n";
1003 print OUT "\r\n";
1004 print OUT "SOURCE=.\\$header_file\r\n";
1005 print OUT "# End Source File\r\n";
1007 print OUT "# End Group\r\n";
1011 print OUT "# Begin Group \"Resource Files\"\r\n";
1012 print OUT "\r\n";
1013 print OUT "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
1014 foreach my $resource_file (@resource_files) {
1015 print OUT "# Begin Source File\r\n";
1016 print OUT "\r\n";
1017 print OUT "SOURCE=.\\$resource_file\r\n";
1018 print OUT "# End Source File\r\n";
1020 print OUT "# End Group\r\n";
1022 print OUT "# End Target\r\n";
1023 print OUT "# End Project\r\n";
1025 close(OUT);
1028 sub _generate_dsw_header($) {
1029 local *OUT = shift;
1031 print OUT "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n";
1032 print OUT "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n";
1033 print OUT "\r\n";
1036 sub _generate_dsw_project($$$$) {
1037 local *OUT = shift;
1039 my $project = shift;
1040 my $dsp_file = shift;
1041 my @dependencies = @{(shift)};
1043 $dsp_file = "./$dsp_file";
1044 $dsp_file =~ y%/%\\%;
1046 @dependencies = sort(@dependencies);
1048 print OUT "###############################################################################\r\n";
1049 print OUT "\r\n";
1050 print OUT "Project: \"$project\"=$dsp_file - Package Owner=<4>\r\n";
1051 print OUT "\r\n";
1052 print OUT "Package=<5>\r\n";
1053 print OUT "{{{\r\n";
1054 print OUT "}}}\r\n";
1055 print OUT "\r\n";
1056 print OUT "Package=<4>\r\n";
1057 print OUT "{{{\r\n";
1058 foreach my $dependency (@dependencies) {
1059 print OUT " Begin Project Dependency\r\n";
1060 print OUT " Project_Dep_Name $dependency\r\n";
1061 print OUT " End Project Dependency\r\n";
1063 print OUT "}}}\r\n";
1064 print OUT "\r\n";
1067 sub _generate_dsw_footer($) {
1068 local *OUT = shift;
1070 print OUT "###############################################################################\r\n";
1071 print OUT "\r\n";
1072 print OUT "Global:\r\n";
1073 print OUT "\r\n";
1074 print OUT "Package=<5>\r\n";
1075 print OUT "{{{\r\n";
1076 print OUT "}}}\r\n";
1077 print OUT "\r\n";
1078 print OUT "Package=<3>\r\n";
1079 print OUT "{{{\r\n";
1080 print OUT "}}}\r\n";
1081 print OUT "\r\n";
1082 print OUT "###############################################################################\r\n";
1083 print OUT "\r\n";
1086 if ($options->wine) {
1087 my $dsw_file = "wine.dsw";
1088 $output->progress("$dsw_file");
1089 replace_file("$wine_dir/$dsw_file", \&_generate_wine_dsw);
1092 sub _generate_wine_dsw($) {
1093 local *OUT = shift;
1095 _generate_dsw_header(\*OUT);
1096 foreach my $module (sort(keys(%modules))) {
1097 next if $module =~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1099 my $project = $modules{$module}{project};
1100 my $dsp_file = $modules{$module}{dsp_file};
1102 my @dependencies;
1103 if($project eq "wine") {
1104 @dependencies = ();
1105 } elsif($project eq "winebuild") {
1106 @dependencies = ("wine");
1107 } elsif($project =~ /^(?:gdi32)_.+?$/) {
1108 @dependencies = ();
1109 } else {
1110 @dependencies = ("wine", "include", "winebuild");
1113 if($project =~ /^gdi32$/) {
1114 foreach my $dir (@gdi32_dirs) {
1115 my $dir2 = $dir;
1116 $dir2 =~ s%^.*?/([^/]+)$%$1%;
1118 my $module = "gdi32_$dir2";
1119 $module =~ s%/%_%g;
1120 push @dependencies, $module;
1124 _generate_dsw_project(\*OUT, $project, $dsp_file, \@dependencies);
1126 _generate_dsw_footer(\*OUT);
1128 return 1;
1131 if ($options->winetest) {
1132 my $dsw_file = "winetest.dsw";
1133 $output->progress("$dsw_file");
1134 replace_file("$wine_dir/$dsw_file", \&_generate_winetest_dsw);
1137 sub _generate_winetest_dsw($) {
1138 local *OUT = shift;
1140 _generate_dsw_header(\*OUT);
1142 my @runtests_dependencies = ();
1143 foreach my $module (sort(keys(%modules))) {
1144 next if $module !~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1145 next if $module eq "wineruntests";
1147 my $project = $modules{$module}{project};
1149 push @runtests_dependencies, $project;
1152 foreach my $module (sort(keys(%modules))) {
1153 next if $module !~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1155 my $project = $modules{$module}{project};
1156 my $dsp_file = $modules{$module}{dsp_file};
1158 my @dependencies;
1159 if($project =~ /^winetest$/) {
1160 @dependencies = ();
1161 } elsif($project =~ /^wineruntests$/) {
1162 @dependencies = @runtests_dependencies;
1163 } else {
1164 @dependencies = ("winetest");
1167 _generate_dsw_project(\*OUT, $project, $dsp_file, \@dependencies);
1170 _generate_dsw_footer(\*OUT);
1173 if ($options->winetest) {
1174 foreach my $module (sort(keys(%modules))) {
1175 next if $module !~ /_test\.exe$/;
1177 my $project = $modules{$module}{project};
1178 my $dsp_file = $modules{$module}{dsp_file};
1179 my @tests = @{$modules{$module}{tests}};
1181 my $testlist_c = $dsp_file;
1182 $testlist_c =~ s%[^/]*\.dsp$%testlist.c%;
1184 replace_file("$wine_dir/$testlist_c", \&_generate_testlist_c, \@tests);
1188 # ***** Keep in sync with tools/make_ctests *****
1189 sub _generate_testlist_c($$) {
1190 local *OUT = shift;
1192 my @tests = @{(shift)};
1194 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n";
1195 print OUT "\n";
1196 print OUT "/* stdarg.h is needed for Winelib */\n";
1197 print OUT "#include <stdarg.h>\n";
1198 print OUT "#include <stdio.h>\n";
1199 print OUT "#include <stdlib.h>\n";
1200 print OUT "#include \"windef.h\"\n";
1201 print OUT "#include \"winbase.h\"\n";
1202 print OUT "\n";
1203 print OUT "#define STANDALONE\n";
1204 print OUT "#include \"wine/test.h\"\n";
1205 print OUT "\n";
1206 foreach my $test (@tests) {
1207 print OUT "extern void func_$test(void);\n";
1209 print OUT "\n";
1210 print OUT "const struct test winetest_testlist[] =\n";
1211 print OUT "{\n";
1212 foreach my $test (@tests) {
1213 print OUT " { \"$test\", func_$test },\n";
1215 print OUT " { 0, 0 }\n";
1216 print OUT "};\n";
1219 if ($options->winetest) {
1220 replace_file("$wine_dir/runtests.c", \&_generate_runtests_c);
1223 sub _generate_runtests_c($) {
1224 local *OUT = shift;
1226 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n";
1228 print OUT "\n";
1229 print OUT "#include <stdio.h>\n";
1230 print OUT "#include <stdlib.h>\n";
1231 print OUT "\n";
1233 print OUT "int main(int argc, char *argv[])\n";
1234 print OUT "{\n";
1235 print OUT " char output_dir[] = __WINETEST_OUTPUT_DIR;\n";
1236 print OUT " char command[4096];\n";
1237 print OUT "\n";
1238 foreach my $dsp_file (keys(%runtests)) {
1239 my @tests = @{$runtests{$dsp_file}};
1241 my $project = $dsp_file;
1242 $project =~ s%^(.*?)/?([^/]+)\.dsp$%$2%;
1243 my $dir = $1;
1244 $dir =~ s%/%\\\\%g;
1246 foreach my $test (@tests) {
1247 print OUT " sprintf(command, \"$dir\\\\%s\\\\$project.exe $test\", output_dir);\n";
1248 print OUT " system(command);\n";
1249 print OUT "\n";
1252 print OUT " return 0;\n";
1253 print OUT "}\n";
1256 if ($options->winetest) {
1257 replace_file("$wine_dir/winetest.c", \&_generate_winetest_c);
1260 sub _generate_winetest_c($) {
1261 local *OUT = shift;
1263 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n\n";
1265 print OUT "/* Force the linker to generate a .lib file */\n";
1266 print OUT "void __wine_dummy_lib_function(void)\n{\n}\n\n";
1269 if ($options->wine) {
1270 my $config_h = "include/config.h";
1272 $output->progress("$config_h");
1274 replace_file("$wine_dir/$config_h", \&_generate_config_h);
1277 sub _generate_config_h($) {
1278 local *OUT = shift;
1279 my @defines;
1281 print OUT "#define __WINE_CONFIG_H\n";
1282 print OUT "\n";
1284 my @headers = qw(direct.h float.h memory.h io.h stdlib.h string.h process.h sys/stat.h sys/types.h);
1285 foreach my $header (@headers) {
1286 $header =~ y/\.\//__/;
1287 push @defines, "HAVE_\U$header\E 1";
1290 my @functions = qw(
1291 _pclose _popen _snprintf _spawnvp _stricmp _strnicmp _strdup
1292 _strtoi64 _strtoui64 _vsnprintf
1293 chsize memmove strdup spawnvp strerror vsnprintf
1295 foreach my $function (@functions) {
1296 push @defines, "HAVE_\U$function\E 1";
1299 my @types = qw(
1300 long_long off_t size_t
1302 foreach my $type (@types) {
1303 push @defines, "HAVE_\U$type\E 1";
1306 foreach my $define (sort(@defines)) {
1307 print OUT "#define $define\n";
1308 print OUT "\n";
1311 print OUT "/* Define to the address where bug reports for this package should be sent. */\n";
1312 print OUT "#define PACKAGE_BUGREPORT \"\"\n";
1313 print OUT "\n";
1315 print OUT "/* Define to the full name of this package. */\n";
1316 print OUT "#define PACKAGE_NAME \"Wine\"\n";
1317 print OUT "\n";
1319 print OUT "/* Define to the full name and version of this package. */\n";
1320 print OUT "#define PACKAGE_STRING \"Wine YYYYMMDD\"\n";
1321 print OUT "\n";
1323 print OUT "/* Define to the one symbol short name of this package. */\n";
1324 print OUT "#define PACKAGE_TARNAME \"wine\"\n";
1325 print OUT "\n";
1327 print OUT "/* Define to the version of this package. */\n";
1328 print OUT "#define PACKAGE_VERSION \"YYYYMMDD\"\n";
1329 print OUT "\n";
1331 print OUT "#define X_DISPLAY_MISSING 1\n";
1332 print OUT "\n";
1334 print OUT "/* Define to a macro to generate an assembly function directive */\n";
1335 print OUT "#define __ASM_FUNC(name) \"\"\n";
1336 print OUT "\n";
1338 print OUT "/* Define to a macro to generate an assembly name from a C symbol */\n";
1339 print OUT "#define __ASM_NAME(name) name\n";
1340 print OUT "\n";
1342 close(OUT);