3 # Copyright 2002 Patrik Stridvall
9 $0 =~ m
%^(.*?
/?tools)/winapi
/msvcmaker
$%;
10 require "$1/winapi/setup.pm";
13 use setup
qw($current_dir $wine_dir);
14 use lib $setup::winapi_dir;
15 use config qw(get_spec_files get_makefile_in_files);
16 use output
qw($output);
17 use util qw(replace_file);
19 use msvcmaker_options
qw($options);
21 if($options->progress) {
22 $output->enable_progress;
24 $output->disable_progress;
27 ########################################################################
30 my @spec_files = get_spec_files("winelib");
31 my @makefile_in_files = get_makefile_in_files("winelib");
35 my $output_prefix_dir = "Output";
40 # These DLLs don't have a hope of compiling properly
41 my @unix_dependent_dlls = qw(iphlpapi mountmgr.sys ntdll mswsock opengl32
42 secur32 winex11 wnaspi32 ws2_32);
44 sub is_unix_dependent_dll
($) {
47 foreach my $unix_only_dll (@unix_dependent_dlls) {
48 if($dll eq $unix_only_dll) {
56 sub read_spec_file
($) {
57 my $spec_file = shift;
59 my $module = $spec_file;
60 $module =~ s
%^.*?
([^/]+)\
.spec
$%$1%;
61 $module .= ".dll" if $module !~ /\./;
65 open(IN
, "< $wine_dir/$spec_file") || die "Error: Can't open $wine_dir/$spec_file: $!\n";
69 while($lookahead || defined($_ = <IN
>)) {
72 s/^\s*?(.*?)\s*$/$1/; # remove whitespace at beginning and end of line
73 s/^(.*?)\s*#.*$/$1/; # remove comments
74 /^$/ && next; # skip empty lines
84 if(/^(\d+|@)\s+pascal(?:16)?/) {
92 if($module =~ /^(?:(?:imm|ole2conv|ole2prox|ole2thk|rasapi16|msacm|windebug)\.dll|comm\.drv)$/) {
96 if($type eq "win32") {
97 $modules{$module}{module
} = $module;
98 $modules{$module}{type
} = $type;
99 $modules{$module}{spec_file
} = $spec_file;
103 if ($options->wine || $options->winetest) {
104 foreach my $spec_file (@spec_files) {
105 my $dll = $spec_file;
106 $dll =~ s
%dlls/([^/]+)/[^/]+\
.spec
%$1%;
107 if(!is_unix_dependent_dll
($dll)) {
108 read_spec_file
($spec_file);
113 my @gdi32_dirs = qw(dlls/gdi32/enhmfdrv dlls/gdi32/mfdrv);
115 push @makefile_in_files, "libs/wine/Makefile.in";
116 push @makefile_in_files, "tools/winebuild/Makefile.in";
118 sub filter_files
($$) {
122 my $filtered_files = [];
123 my $rest_of_files = [];
124 foreach my $file (@
$files) {
125 if($file =~ /$filter/) {
126 $file =~ s
%.*?
([^/]+)$%./$1%; # FIXME: Kludge
127 push @
$filtered_files, $file;
129 push @
$rest_of_files, $file;
132 return ($rest_of_files, $filtered_files);
135 my %wine_test_dsp_files;
137 MAKEFILE_IN
: foreach my $makefile_in_file (@makefile_in_files) {
138 open(IN
, "< $wine_dir/$makefile_in_file") || die "Error: Can't open $wine_dir/$makefile_in_file: $!\n";
152 $dll = $makefile_in_file;
153 $dll =~ s
%dlls/([^/]+)/Makefile\
.in%$1%;
155 if($makefile_in_file eq "loader/Makefile.in" ||
156 is_unix_dependent_dll
($dll)) {
160 while($again || defined(my $line = <IN
>)) {
173 s/^\s*?(.*?)\s*$/$1/; # remove whitespace at beginning and end of line
174 s/^(.*?)\s*#.*$/$1/; # remove comments
175 /^$/ && next; # skip empty lines
182 if(/^MODULE\s*=\s*([\w\.-]+)$/) {
184 } elsif (/^\@MAKE_IMPLIB_RULES\@/) {
186 } elsif(/^TOPOBJDIR\s*=\s*(\S+)\s*$/) {
188 } elsif (/^TESTDLL\s*=\s*(\S+)\s*$/) {
190 } elsif (/^IMPORTS\s*=\s*/) {
191 push @imports, grep !/^ntdll$/, split /\s+/s, $';
192 } elsif (/^DELAYIMPORTS\s*=\s*/) {
194 } elsif (/^EXTRALIBS\s*=\s*/) {
195 push @imports, map { /^-l(dxerr8|dxerr9|dxguid|strmiids|uuid)$/ ? $1 : () } split /\s+/s, $';
196 } elsif (/^CTESTS\s*=\s*/ || ( ($makefile_in_file =~ /\/tests\
/Makefile\.in$/) && /^C_SRCS\s*=\s*/ ) ) {
197 my @files = split /\s+/s, $';
199 my $dir = $makefile_in_file;
200 $dir =~ s/\/Makefile\.in$//;
202 my $dsp_file = $testdll;
203 $dsp_file =~ s/\.(dll|drv|ocx)$/_test.dsp/;
204 $dsp_file = "$dir/$dsp_file";
206 $wine_test_dsp_files{$dsp_file}{files} = [@files, "testlist.c"];
207 $wine_test_dsp_files{$dsp_file}{imports} = [@imports];
208 } elsif(/^(\w+)\s*=\s*/) {
210 my @files = split /\s+/s, $';
213 if(/^\$\((\w+):\%=(.*?)\%(.*?)\)$/) {
214 my @list = @
{$vars{$1}};
217 foreach my $item (@list) {
218 $item = "$prefix$item$suffix";
221 } elsif(/^\$\(TOPOBJDIR\)(.*?)$/) {
224 print STDERR
"unknown variable '$_'\n" if 0;
231 $vars{$var} = \
@files;
238 if ($makefile_in_file eq "libs/wine/Makefile.in") {
239 $module = "wine.lib";
240 } elsif ($makefile_in_file eq "tools/winebuild/Makefile.in") {
241 $module = "winebuild.exe";
248 my $source_files = [];
249 if(exists($vars{C_SRCS
})) {
250 $c_srcs = [sort(@
{$vars{C_SRCS
}})];
251 $source_files = [sort(@
{$vars{C_SRCS
}})];
254 my $header_files = [];
255 if(exists($vars{H_SRCS
})) {
256 $header_files = [sort(@
{$vars{H_SRCS
}})];
259 my $resource_files = [];
260 if(exists($vars{RC_SRCS
})) {
261 $resource_files = [sort(@
{$vars{RC_SRCS
}})];
264 my $idl_h_files = [];
265 if(exists($vars{IDL_H_SRCS
})) {
266 $idl_h_files = [sort(@
{$vars{IDL_H_SRCS
}})];
269 my $idl_c_files = [];
270 if(exists($vars{IDL_C_SRCS
})) {
271 $idl_c_files = [sort(@
{$vars{IDL_C_SRCS
}})];
274 my $idl_s_files = [];
275 if(exists($vars{IDL_S_SRCS
})) {
276 $idl_s_files = [sort(@
{$vars{IDL_S_SRCS
}})];
279 my $idl_p_files = [];
280 if(exists($vars{IDL_P_SRCS
})) {
281 $idl_p_files = [sort(@
{$vars{IDL_P_SRCS
}})];
284 my $idl_tlb_files = [];
285 if(exists($vars{IDL_TLB_SRCS
})) {
286 $idl_tlb_files = [sort(@
{$vars{IDL_TLB_SRCS
}})];
290 if(exists($vars{EXTRADEFS
})) {
291 $extradefs = $vars{EXTRADEFS
};
294 my $project = $module;
295 $project =~ s/\.(?:dll|exe|lib)$//;
298 if($module =~ /\.exe$/) {
300 } elsif($module =~ /\.lib$/) {
306 my $dsp_file = $makefile_in_file;
307 $dsp_file =~ s/Makefile.in$/$project.dsp/;
309 if($module eq "gdi32.dll") {
310 foreach my $dir (@gdi32_dirs) {
312 $dir2 =~ s
%^.*?
/([^/]+)$%$1%;
314 my $module = "gdi32_$dir2.lib";
317 my $project = "gdi32_$dir2";
321 my $dsp_file = "$dir/$project.dsp";
323 ($source_files, my $local_source_files) = filter_files
($source_files, "$dir2/");
324 ($header_files, my $local_header_files) = filter_files
($header_files, "$dir2/");
325 ($resource_files, my $local_resource_files) = filter_files
($resource_files, "$dir2/");
326 ($idl_h_files, my $local_idl_h_files) = filter_files
($idl_h_files, "$dir2/");
328 $modules{$module}{wine
} = 1;
329 $modules{$module}{winetest
} = 0;
330 $modules{$module}{project
} = $project;
331 $modules{$module}{type
} = $type;
332 $modules{$module}{dsp_file
} = $dsp_file;
333 $modules{$module}{c_srcs
} = $c_srcs;
334 $modules{$module}{source_files
} = $local_source_files;
335 $modules{$module}{header_files
} = $local_header_files;
336 $modules{$module}{resource_files
} = $local_resource_files;
337 $modules{$module}{imports
} = [];
338 $modules{$module}{idl_h_files
} = $local_idl_h_files;
339 $modules{$module}{idl_c_files
} = [];
340 $modules{$module}{idl_s_files
} = [];
341 $modules{$module}{idl_p_files
} = [];
342 $modules{$module}{idl_tlb_files
} = [];
343 $modules{$module}{extradefs
} = $extradefs if $extradefs;
347 $modules{$module}{wine
} = 1;
348 $modules{$module}{winetest
} = 0;
349 $modules{$module}{project
} = $project;
350 $modules{$module}{type
} = $type;
351 $modules{$module}{dsp_file
} = $dsp_file;
352 $modules{$module}{c_srcs
} = $c_srcs;
353 $modules{$module}{source_files
} = $source_files;
354 $modules{$module}{header_files
} = $header_files;
355 $modules{$module}{resource_files
} = $resource_files;
356 $modules{$module}{imports
} = [@imports];
357 $modules{$module}{idl_h_files
} = $idl_h_files;
358 $modules{$module}{idl_c_files
} = $idl_c_files;
359 $modules{$module}{idl_s_files
} = $idl_s_files;
360 $modules{$module}{idl_p_files
} = $idl_p_files;
361 $modules{$module}{idl_tlb_files
} = $idl_tlb_files;
362 $modules{$module}{extradefs
} = $extradefs if $extradefs;
365 $wine_test_dsp_files{"wineruntests.dsp"}{files
} = ["runtests.c"];
366 $wine_test_dsp_files{"wineruntests.dsp"}{imports
} = [];
368 $wine_test_dsp_files{"winetest.dsp"}{files
} = [
369 'include/wine/exception.h',
370 'include/wine/test.h',
371 'include/wine/unicode.h',
374 $wine_test_dsp_files{"winetest.dsp"}{imports
} = [];
378 foreach my $dsp_file (keys(%wine_test_dsp_files)) {
379 my $project = $dsp_file;
380 $project =~ s
%^(?
:.*?
/)?([^/]+)\
.dsp
$%$1%;
382 my @files = @
{$wine_test_dsp_files{$dsp_file}{files
}};
383 my @imports = @
{$wine_test_dsp_files{$dsp_file}{imports
}};
387 my $source_files = [];
388 my $header_files = [];
389 my $resource_files = [];
390 my $idl_h_files = [];
394 if ($project eq "winetest") {
397 $source_files = [@files];
399 $resource_files = [];
400 } elsif ($project eq "wineruntests") {
403 $source_files = [@files];
405 $resource_files = [];
409 $source_files = [@files];
411 $resource_files = [];
414 if (/^testlist\.c$/) {
422 $runtests{$dsp_file} = [@tests];
424 my $module = "$project.$type";
426 $modules{$module}{wine
} = 0;
427 $modules{$module}{winetest
} = 1;
429 $modules{$module}{project
} = $project;
430 $modules{$module}{type
} = $type;
431 $modules{$module}{dsp_file
} = $dsp_file;
432 $modules{$module}{c_srcs
} = $c_srcs;
433 $modules{$module}{source_files
} = $source_files;
434 $modules{$module}{header_files
} = $header_files;
435 $modules{$module}{resource_files
} = $resource_files;
436 $modules{$module}{imports
} = [@imports];
437 $modules{$module}{idl_h_files
} = [];
438 $modules{$module}{idl_c_files
} = [];
439 $modules{$module}{idl_s_files
} = [];
440 $modules{$module}{idl_p_files
} = [];
441 $modules{$module}{idl_tlb_files
} = [];
443 $modules{$module}{tests
} = [@tests];
446 foreach my $module (sort(keys(%modules))) {
447 if($module =~ /^(?:ttydrv.dll|x11drv.dll)$/) {
448 delete $modules{$module};
453 foreach my $module (sort(keys(%modules))) {
454 if (($options->wine && $modules{$module}{wine
}) ||
455 ($options->winetest && $modules{$module}{winetest
}))
457 push @modules, $module;
462 my $progress_current = 0;
463 my $progress_max = scalar(@modules);
465 foreach my $module (@modules) {
466 my $dsp_file = $modules{$module}{dsp_file
};
467 replace_file
("$wine_dir/$dsp_file", \
&_generate_dsp
, $module);
470 sub output_dsp_idl_rules
($$$) {
471 my $wine_include_dir = shift;
473 my @idl_src_files = @
{(shift)};
475 foreach my $idl_src_file (@idl_src_files) {
476 $idl_src_file =~ s
%/%\\%g;
477 if($idl_src_file !~ /^\./) {
478 $idl_src_file = ".\\$idl_src_file";
481 print OUT
"# Begin Source File\r\n";
484 print OUT
"SOURCE=$idl_src_file\r\n";
486 my $basename = $idl_src_file;
487 $basename =~ s/\.idl$//;
489 print OUT
"# PROP Ignore_Default_Tool 1\r\n";
490 print OUT
"# Begin Custom Build\r\n";
491 print OUT
"InputPath=$idl_src_file\r\n";
493 print OUT
"BuildCmds= \\\r\n";
494 print OUT
"\tmidl /nologo /I $wine_include_dir $idl_src_file ";
496 print OUT
"/client none /server none /notlb /h ";
497 } elsif ($ext eq "_c.c") {
498 print OUT
"/server none /notlb /cstub ";
499 } elsif ($ext eq "_s.c") {
500 print OUT
"/client none /notlb /sstub ";
501 } elsif ($ext eq "_p.c") {
502 print OUT
"/client none /server none /notlb /proxy ";
503 } elsif ($ext eq ".tlb") {
504 print OUT
"/client none /server none /tlb ";
506 print OUT
"$basename$ext\r\n";
508 print OUT
"\"$basename$ext\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
509 print OUT
" \$(BuildCmds)\r\n";
510 print OUT
"# End Custom Build\r\n";
512 print OUT
"# End Source File\r\n";
516 sub _generate_dsp
($$) {
521 my $dsp_file = $modules{$module}{dsp_file
};
522 my $project = $modules{$module}{project
};
523 my @imports = @
{$modules{$module}{imports
}};
525 my $lib = ($modules{$module}{type
} eq "lib");
526 my $dll = ($modules{$module}{type
} eq "dll");
527 my $exe = ($modules{$module}{type
} eq "exe");
529 my $console = $exe; # FIXME: Not always correct
531 my $msvc_wine_dir = do {
532 my @parts = split(m
%/%, $dsp_file);
535 } elsif($#parts == 2) {
541 my $wine_include_dir = "$msvc_wine_dir\\include";
544 $output->progress("$dsp_file (file $progress_current of $progress_max)");
546 my $base_module = $module;
547 $base_module =~ s/\.(?:dll)$//;
549 my @c_srcs = @
{$modules{$module}{c_srcs
}};
550 my @source_files = @
{$modules{$module}{source_files
}};
551 my @header_files = @
{$modules{$module}{header_files
}};
552 my @resource_files = @
{$modules{$module}{resource_files
}};
553 my @idl_h_files = @
{$modules{$module}{idl_h_files
}};
554 my @idl_c_files = @
{$modules{$module}{idl_c_files
}};
555 my @idl_s_files = @
{$modules{$module}{idl_s_files
}};
556 my @idl_p_files = @
{$modules{$module}{idl_p_files
}};
557 my @idl_tlb_files = @
{$modules{$module}{idl_tlb_files
}};
559 if ($project !~ /^wine(?:build|runtests|test)?$/ &&
560 $project !~ /^(?:gdi32)_.+?$/ &&
561 $project !~ /_test$/ &&
564 push @source_files, "$base_module.spec";
565 @source_files = sort(@source_files);
569 my $no_msvc_headers = 1;
570 if ($project =~ /^wine(?:runtests|test)$/ || $project =~ /_test$/) {
571 $no_msvc_headers = 0;
576 push @cfgs, "$project - Win32";
580 foreach my $cfg (@cfgs) {
581 push @_cfgs, "$cfg C";
582 push @_cfgs, "$cfg C++";
589 foreach my $cfg (@cfgs) {
590 push @_cfgs, "$cfg Debug";
591 push @_cfgs, "$cfg Release";
596 foreach my $cfg (@cfgs) {
597 push @_cfgs, "$cfg Debug";
602 if (!$no_msvc_headers) {
604 foreach my $cfg (@cfgs) {
605 push @_cfgs, "$cfg MSVC Headers";
606 push @_cfgs, "$cfg Wine Headers";
611 my $default_cfg = $cfgs[$#cfgs];
613 print OUT
"# Microsoft Developer Studio Project File - Name=\"$project\" - Package Owner=<4>\r\n";
614 print OUT
"# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n";
615 print OUT
"# ** DO NOT EDIT **\r\n";
619 print OUT
"# TARGTYPE \"Win32 (x86) Static Library\" 0x0104\r\n";
621 print OUT
"# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\r\n";
623 print OUT
"# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n";
627 print OUT
"CFG=$default_cfg\r\n";
628 print OUT
"!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n";
629 print OUT
"!MESSAGE use the Export Makefile command and run\r\n";
630 print OUT
"!MESSAGE \r\n";
631 print OUT
"!MESSAGE NMAKE /f \"$project.mak\".\r\n";
632 print OUT
"!MESSAGE \r\n";
633 print OUT
"!MESSAGE You can specify a configuration when running NMAKE\r\n";
634 print OUT
"!MESSAGE by defining the macro CFG on the command line. For example:\r\n";
635 print OUT
"!MESSAGE \r\n";
636 print OUT
"!MESSAGE NMAKE /f \"$project.mak\" CFG=\"$default_cfg\"\r\n";
637 print OUT
"!MESSAGE \r\n";
638 print OUT
"!MESSAGE Possible choices for configuration are:\r\n";
639 print OUT
"!MESSAGE \r\n";
640 foreach my $cfg (@cfgs) {
642 print OUT
"!MESSAGE \"$cfg\" (based on \"Win32 (x86) Static Library\")\r\n";
644 print OUT
"!MESSAGE \"$cfg\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n";
646 print OUT
"!MESSAGE \"$cfg\" (based on \"Win32 (x86) Console Application\")\r\n";
649 print OUT
"!MESSAGE \r\n";
652 print OUT
"# Begin Project\r\n";
653 print OUT
"# PROP AllowPerConfigDependencies 0\r\n";
654 print OUT
"# PROP Scc_ProjName \"\"\r\n";
655 print OUT
"# PROP Scc_LocalPath \"\"\r\n";
656 print OUT
"CPP=cl.exe\r\n";
657 print OUT
"MTL=midl.exe\r\n" if !$lib && !$exe;
658 print OUT
"RSC=rc.exe\r\n";
664 foreach my $cfg (@cfgs) {
668 print OUT
"!IF \"\$(CFG)\" == \"$cfg\"\r\n";
672 print OUT
"!ELSEIF \"\$(CFG)\" == \"$cfg\"\r\n";
676 my $debug = ($cfg !~ /Release/);
677 my $msvc_headers = ($cfg =~ /MSVC Headers/);
679 print OUT
"# PROP BASE Use_MFC 0\r\n";
682 print OUT
"# PROP BASE Use_Debug_Libraries 1\r\n";
684 print OUT
"# PROP BASE Use_Debug_Libraries 0\r\n";
688 $output_dir =~ s/^$project - //;
689 $output_dir =~ s/ /_/g;
690 $output_dir =~ s/C\+\+/Cxx/g;
691 if($output_prefix_dir) {
692 $output_dir = "$output_prefix_dir\\$output_dir";
695 print OUT
"# PROP BASE Output_Dir \"$output_dir\"\r\n";
696 print OUT
"# PROP BASE Intermediate_Dir \"$output_dir\"\r\n";
698 print OUT
"# PROP BASE Target_Dir \"\"\r\n";
700 print OUT
"# PROP Use_MFC 0\r\n";
702 print OUT
"# PROP Use_Debug_Libraries 1\r\n";
704 print OUT
"# PROP Use_Debug_Libraries 0\r\n";
706 print OUT
"# PROP Output_Dir \"$output_dir\"\r\n";
707 print OUT
"# PROP Intermediate_Dir \"$output_dir\"\r\n";
709 print OUT
"# PROP Ignore_Export_Lib 0\r\n" if $dll;
710 print OUT
"# PROP Target_Dir \"\"\r\n";
712 print OUT
"# ADD BASE CPP /nologo ";
713 my @defines = qw(WINVER=0x0600 _WIN32_WINNT=0x0600 _WIN32_IE=0x0700 WIN32);
716 push @defines, qw(_DEBUG _MBCS _LIB);
719 push @defines, qw(_DEBUG _WINDOWS _MBCS _USRDLL);
721 print OUT
"/W3 /Gm /GX /Zi /Od";
724 push @defines, qw(NDEBUG _MBCS _LIB);
727 push @defines, qw(NDEBUG _WINDOWS _MBCS _USRDLL);
729 print OUT
"/W3 /GX /O2";
732 foreach my $define (@defines) {
733 if ($define !~ /=/) {
734 print OUT
" /D \"$define\"";
736 print OUT
" /D $define";
739 print OUT
" /YX" if $lib || $exe;
741 print OUT
" /GZ" if $debug;
745 my @defines2 = qw(_CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE
746 USE_COMPILER_EXCEPTIONS _USE_MATH_DEFINES
747 WINVER=0x0600 _WIN32_WINNT=0x0600 _WIN32_IE=0x0700);
750 print OUT
"# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od";
751 push @defines2, qw(WIN32 _DEBUG _WINDOWS _MBCS _LIB);
753 print OUT
"# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od";
754 push @defines2, qw(_DEBUG WIN32 _WINDOWS _MBCS _USRDLL);
758 print OUT
"# ADD CPP /nologo /MD /W3 /GX /O2";
759 push @defines2, qw(WIN32 NDEBUG _WINDOWS _MBCS _LIB);
761 print OUT
"# ADD CPP /nologo /MD /W3 /GX /O2";
762 push @defines2, qw(NDEBUG WIN32 _WINDOWS _MBCS _USRDLL);
768 push @defines2, qw(__WINESRC__) if $project !~ /^(?:wine(?:build|test)|.*?_test)$/;
770 push @defines2, qw(__WINE_USE_NATIVE_HEADERS);
772 my $output_dir2 = $output_dir;
773 $output_dir2 =~ s/\\/\\\\/g;
774 push @defines2, "__WINETEST_OUTPUT_DIR=\\\"$output_dir2\\\"";
775 push @defines2, qw(__i386__ _X86_);
777 if ($project eq "wine") {
778 push @defines2, "WINE_UNICODE_API=";
781 if ($project =~ /_test$/) {
782 push @includes, "$msvc_wine_dir\\$output_dir";
785 if (!$msvc_headers || $project eq "winetest") {
786 push @includes, $wine_include_dir;
791 foreach my $include (@includes) {
792 print OUT
" /I \"$include\"";
796 foreach my $define (@defines2) {
797 if ($define !~ /=/) {
798 print OUT
" /D \"$define\"";
800 print OUT
" /D $define";
803 print OUT
" /D inline=__inline" if $wine;
804 print OUT
" /D \"__STDC__\"" if 0 && $wine;
806 if(exists($modules{$module}{extradefs
})) {
807 print OUT
" @{$modules{$module}{extradefs}} ";
810 print OUT
" /YX" if $lib;
811 print OUT
" /FR" if !$lib;
813 print OUT
" /GZ" if $debug;
815 print OUT
" /TP" if !$no_cpp;
819 print OUT
"# SUBTRACT CPP /X /YX\r\n" if $dll;
820 print OUT
"# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
821 print OUT
"# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
822 print OUT
"# ADD BASE RSC /l 0x41d /d \"_DEBUG\"\r\n";
823 print OUT
"# ADD RSC /l 0x41d";
825 foreach my $include (@includes) {
826 print OUT
" /i \"$include\"";
829 print OUT
" /d \"_DEBUG\"\r\n";
831 print OUT
"# SUBTRACT CPP /YX\r\n" if $dll;
832 print OUT
"# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
833 print OUT
"# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
834 print OUT
"# ADD BASE RSC /l 0x41d /d \"NDEBUG\"\r\n";
835 print OUT
"# ADD RSC /l 0x41d";
837 foreach my $include (@includes) {
838 print OUT
" /i \"$include\"";
841 print OUT
"/d \"NDEBUG\"\r\n";
843 print OUT
"BSC32=bscmake.exe\r\n";
844 print OUT
"# ADD BASE BSC32 /nologo\r\n";
845 print OUT
"# ADD BSC32 /nologo\r\n";
848 print OUT
"LINK32=link.exe\r\n";
849 print OUT
"# ADD BASE LINK32";
850 my @libraries = qw(kernel32.lib user32.lib gdi32.lib winspool.lib
851 comdlg32.lib advapi32.lib shell32.lib ole32.lib
852 oleaut32.lib uuid.lib odbc32.lib odbccp32.lib);
853 foreach my $library (@libraries) {
854 print OUT
" $library";
856 print OUT
" /nologo";
857 print OUT
" /dll" if $dll;
858 print OUT
" /subsystem:console" if $console;
859 print OUT
" /debug" if $debug;
860 print OUT
" /machine:I386";
861 print OUT
" /pdbtype:sept" if $debug;
864 print OUT
"# ADD LINK32";
865 print OUT
" libcmt.lib" if $project =~ /^ntdll$/; # FIXME: Kludge
866 foreach my $import (@imports) {
867 print OUT
" $import.lib" if ($import ne "msvcrt");
869 print OUT
" /nologo";
870 print OUT
" /dll" if $dll;
871 print OUT
" /subsystem:console" if $console;
872 print OUT
" /debug" if $debug;
873 print OUT
" /machine:I386";
874 print OUT
" /nodefaultlib" if $project =~ /^ntdll
$/; # FIXME: Kludge
875 print OUT
" /def:\"$project.def\"" if $dll;
876 print OUT
" /pdbtype:sept" if $debug;
879 print OUT
"LIB32=link.exe -lib\r\n";
880 print OUT
"# ADD BASE LIB32 /nologo\r\n";
881 print OUT
"# ADD LIB32 /nologo\r\n";
889 print OUT
"!ENDIF \r\n";
893 print OUT
"# Begin Target\r\n";
895 foreach my $cfg (@cfgs) {
896 print OUT
"# Name \"$cfg\"\r\n";
899 print OUT
"# Begin Group \"Source Files\"\r\n";
901 print OUT
"# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
903 if ($project eq "winebuild") {
904 for my $ source_file
("getopt.c", "getopt1.c", "mkstemps.c")
906 print OUT
"# Begin Source File\r\n";
908 print OUT
"SOURCE=..\\..\\libs\\port\\$source_file\r\n";
909 print OUT
"# End Source File\r\n";
913 foreach my $source_file (@source_files) {
914 $source_file =~ s
%/%\\%g;
915 if($source_file !~ /^\./) {
916 $source_file = ".\\$source_file";
919 print OUT
"# Begin Source File\r\n";
922 print OUT
"SOURCE=$source_file\r\n";
924 if ($project eq "wine" && $source_file eq ".\\config.c") {
925 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";
928 if($source_file =~ /^(.*?)\.spec$/) {
931 my $spec_file = $source_file;
932 my $def_file = "$basename.def";
934 my $srcdir = "."; # FIXME: Is this really always correct?
936 print OUT
"# Begin Custom Build\r\n";
937 print OUT
"InputPath=$spec_file\r\n";
939 print OUT
"BuildCmds= \\\r\n";
940 print OUT
"\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe -w --def -k -o $def_file --export $spec_file\r\n";
942 print OUT
"\"$def_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
943 print OUT
" \$(BuildCmds)\r\n";
944 print OUT
"# End Custom Build\r\n";
945 } elsif($source_file =~ /([^\\]*?\.h)$/) {
948 foreach my $cfg (@cfgs) {
952 print OUT
"!IF \"\$(CFG)\" == \"$cfg\"\r\n";
956 print OUT
"!ELSEIF \"\$(CFG)\" == \"$cfg\"\r\n";
961 $output_dir =~ s/^$project - //;
962 $output_dir =~ s/ /_/g;
963 $output_dir =~ s/C\+\+/Cxx/g;
964 if($output_prefix_dir) {
965 $output_dir = "$output_prefix_dir\\$output_dir";
968 print OUT
"# Begin Custom Build\r\n";
969 print OUT
"OutDir=$output_dir\r\n";
970 print OUT
"InputPath=$source_file\r\n";
972 print OUT
"\"\$(OutDir)\\wine\\$h_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
973 print OUT
"\tcopy \"\$(InputPath)\" \"\$(OutDir)\\wine\"\r\n";
975 print OUT
"# End Custom Build\r\n";
980 print OUT
"!ENDIF \r\n";
985 print OUT
"# End Source File\r\n";
988 output_dsp_idl_rules
$wine_include_dir, ".h", \
@idl_h_files;
989 output_dsp_idl_rules
$wine_include_dir, "_c.c", \
@idl_c_files;
990 output_dsp_idl_rules
$wine_include_dir, "_s.c", \
@idl_s_files;
991 output_dsp_idl_rules
$wine_include_dir, "_p.c", \
@idl_p_files;
992 # Hack - stdole2.idl cannot be compiled with midl
993 if($project ne "include") {
994 output_dsp_idl_rules
$wine_include_dir, ".tlb", \
@idl_tlb_files;
997 print OUT
"# End Group\r\n";
999 print OUT
"# Begin Group \"Header Files\"\r\n";
1001 print OUT
"# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
1002 foreach my $header_file (@header_files) {
1003 print OUT
"# Begin Source File\r\n";
1005 print OUT
"SOURCE=.\\$header_file\r\n";
1006 print OUT
"# End Source File\r\n";
1008 print OUT
"# End Group\r\n";
1012 print OUT
"# Begin Group \"Resource Files\"\r\n";
1014 print OUT
"# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
1015 foreach my $resource_file (@resource_files) {
1016 print OUT
"# Begin Source File\r\n";
1018 print OUT
"SOURCE=.\\$resource_file\r\n";
1019 print OUT
"# End Source File\r\n";
1021 print OUT
"# End Group\r\n";
1023 print OUT
"# End Target\r\n";
1024 print OUT
"# End Project\r\n";
1029 sub _generate_dsw_header
($) {
1032 print OUT
"Microsoft Developer Studio Workspace File, Format Version 6.00\r\n";
1033 print OUT
"# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n";
1037 sub _generate_dsw_project
($$$$) {
1040 my $project = shift;
1041 my $dsp_file = shift;
1042 my @dependencies = @
{(shift)};
1044 $dsp_file = "./$dsp_file";
1045 $dsp_file =~ y
%/%\\%;
1047 @dependencies = sort(@dependencies);
1049 print OUT
"###############################################################################\r\n";
1051 print OUT
"Project: \"$project\"=$dsp_file - Package Owner=<4>\r\n";
1053 print OUT
"Package=<5>\r\n";
1054 print OUT
"{{{\r\n";
1055 print OUT
"}}}\r\n";
1057 print OUT
"Package=<4>\r\n";
1058 print OUT
"{{{\r\n";
1059 foreach my $dependency (@dependencies) {
1060 print OUT
" Begin Project Dependency\r\n";
1061 print OUT
" Project_Dep_Name $dependency\r\n";
1062 print OUT
" End Project Dependency\r\n";
1064 print OUT
"}}}\r\n";
1068 sub _generate_dsw_footer
($) {
1071 print OUT
"###############################################################################\r\n";
1073 print OUT
"Global:\r\n";
1075 print OUT
"Package=<5>\r\n";
1076 print OUT
"{{{\r\n";
1077 print OUT
"}}}\r\n";
1079 print OUT
"Package=<3>\r\n";
1080 print OUT
"{{{\r\n";
1081 print OUT
"}}}\r\n";
1083 print OUT
"###############################################################################\r\n";
1087 if ($options->wine) {
1088 my $dsw_file = "wine.dsw";
1089 $output->progress("$dsw_file");
1090 replace_file
("$wine_dir/$dsw_file", \
&_generate_wine_dsw
);
1093 sub _generate_wine_dsw
($) {
1096 _generate_dsw_header
(\
*OUT
);
1097 foreach my $module (sort(keys(%modules))) {
1098 next if $module =~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1100 my $project = $modules{$module}{project
};
1101 my $dsp_file = $modules{$module}{dsp_file
};
1104 if($project eq "wine") {
1106 } elsif($project eq "winebuild") {
1107 @dependencies = ("wine");
1108 } elsif($project =~ /^(?:gdi32)_.+?$/) {
1111 @dependencies = ("wine", "include", "winebuild");
1114 if($project =~ /^gdi32$/) {
1115 foreach my $dir (@gdi32_dirs) {
1117 $dir2 =~ s
%^.*?
/([^/]+)$%$1%;
1119 my $module = "gdi32_$dir2";
1121 push @dependencies, $module;
1125 _generate_dsw_project
(\
*OUT
, $project, $dsp_file, \
@dependencies);
1127 _generate_dsw_footer
(\
*OUT
);
1132 if ($options->winetest) {
1133 my $dsw_file = "winetest.dsw";
1134 $output->progress("$dsw_file");
1135 replace_file
("$wine_dir/$dsw_file", \
&_generate_winetest_dsw
);
1138 sub _generate_winetest_dsw
($) {
1141 _generate_dsw_header
(\
*OUT
);
1143 my @runtests_dependencies = ();
1144 foreach my $module (sort(keys(%modules))) {
1145 next if $module !~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1146 next if $module eq "wineruntests";
1148 my $project = $modules{$module}{project
};
1150 push @runtests_dependencies, $project;
1153 foreach my $module (sort(keys(%modules))) {
1154 next if $module !~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1156 my $project = $modules{$module}{project
};
1157 my $dsp_file = $modules{$module}{dsp_file
};
1160 if($project =~ /^winetest$/) {
1162 } elsif($project =~ /^wineruntests$/) {
1163 @dependencies = @runtests_dependencies;
1165 @dependencies = ("winetest");
1168 _generate_dsw_project
(\
*OUT
, $project, $dsp_file, \
@dependencies);
1171 _generate_dsw_footer
(\
*OUT
);
1174 if ($options->winetest) {
1175 foreach my $module (sort(keys(%modules))) {
1176 next if $module !~ /_test\.exe$/;
1178 my $project = $modules{$module}{project
};
1179 my $dsp_file = $modules{$module}{dsp_file
};
1180 my @tests = @
{$modules{$module}{tests
}};
1182 my $testlist_c = $dsp_file;
1183 $testlist_c =~ s
%[^/]*\
.dsp
$%testlist.c
%;
1185 replace_file
("$wine_dir/$testlist_c", \
&_generate_testlist_c
, \
@tests);
1189 # ***** Keep in sync with tools/make_ctests *****
1190 sub _generate_testlist_c
($$) {
1193 my @tests = @
{(shift)};
1195 print OUT
"/* Automatically generated file; DO NOT EDIT!! */\n";
1197 print OUT
"/* stdarg.h is needed for Winelib */\n";
1198 print OUT
"#include <stdarg.h>\n";
1199 print OUT
"#include <stdio.h>\n";
1200 print OUT
"#include <stdlib.h>\n";
1201 print OUT
"#include \"windef.h\"\n";
1202 print OUT
"#include \"winbase.h\"\n";
1204 print OUT
"#define STANDALONE\n";
1205 print OUT
"#include \"wine/test.h\"\n";
1207 foreach my $test (@tests) {
1208 print OUT
"extern void func_$test(void);\n";
1211 print OUT
"const struct test winetest_testlist[] =\n";
1213 foreach my $test (@tests) {
1214 print OUT
" { \"$test\", func_$test },\n";
1216 print OUT
" { 0, 0 }\n";
1220 if ($options->winetest) {
1221 replace_file
("$wine_dir/runtests.c", \
&_generate_runtests_c
);
1224 sub _generate_runtests_c
($) {
1227 print OUT
"/* Automatically generated file; DO NOT EDIT!! */\n";
1230 print OUT
"#include <stdio.h>\n";
1231 print OUT
"#include <stdlib.h>\n";
1234 print OUT
"int main(int argc, char *argv[])\n";
1236 print OUT
" char output_dir[] = __WINETEST_OUTPUT_DIR;\n";
1237 print OUT
" char command[4096];\n";
1239 foreach my $dsp_file (keys(%runtests)) {
1240 my @tests = @
{$runtests{$dsp_file}};
1242 my $project = $dsp_file;
1243 $project =~ s
%^(.*?
)/?([^/]+)\
.dsp
$%$2%;
1247 foreach my $test (@tests) {
1248 print OUT
" sprintf(command, \"$dir\\\\%s\\\\$project.exe $test\", output_dir);\n";
1249 print OUT
" system(command);\n";
1253 print OUT
" return 0;\n";
1257 if ($options->winetest) {
1258 replace_file
("$wine_dir/winetest.c", \
&_generate_winetest_c
);
1261 sub _generate_winetest_c
($) {
1264 print OUT
"/* Automatically generated file; DO NOT EDIT!! */\n\n";
1266 print OUT
"/* Force the linker to generate a .lib file */\n";
1267 print OUT
"void __wine_dummy_lib_function(void)\n{\n}\n\n";
1270 if ($options->wine) {
1271 my $config_h = "include/config.h";
1273 $output->progress("$config_h");
1275 replace_file
("$wine_dir/$config_h", \
&_generate_config_h
);
1278 sub _generate_config_h
($) {
1282 print OUT
"#define __WINE_CONFIG_H\n";
1285 my @headers = qw(direct.h float.h memory.h io.h stdlib.h string.h process.h sys/stat.h sys/types.h);
1286 foreach my $header (@headers) {
1287 $header =~ y/\.\//__
/;
1288 push @defines, "HAVE_\U$header\E 1";
1292 _pclose _popen _snprintf _spawnvp _stricmp _strnicmp _strdup
1293 _strtoi64 _strtoui64 _vsnprintf
1294 chsize memmove strdup spawnvp strerror vsnprintf
1296 foreach my $function (@functions) {
1297 push @defines, "HAVE_\U$function\E 1";
1301 long_long off_t size_t
1303 foreach my $type (@types) {
1304 push @defines, "HAVE_\U$type\E 1";
1307 foreach my $define (sort(@defines)) {
1308 print OUT
"#define $define\n";
1312 print OUT
"/* Define to the address where bug reports for this package should be sent. */\n";
1313 print OUT
"#define PACKAGE_BUGREPORT \"\"\n";
1316 print OUT
"/* Define to the full name of this package. */\n";
1317 print OUT
"#define PACKAGE_NAME \"Wine\"\n";
1320 print OUT
"/* Define to the full name and version of this package. */\n";
1321 print OUT
"#define PACKAGE_STRING \"Wine YYYYMMDD\"\n";
1324 print OUT
"/* Define to the one symbol short name of this package. */\n";
1325 print OUT
"#define PACKAGE_TARNAME \"wine\"\n";
1328 print OUT
"/* Define to the version of this package. */\n";
1329 print OUT
"#define PACKAGE_VERSION \"YYYYMMDD\"\n";
1332 print OUT
"#define X_DISPLAY_MISSING 1\n";
1335 print OUT
"/* Define to a macro to generate an assembly function directive */\n";
1336 print OUT
"#define __ASM_FUNC(name) \"\"\n";
1339 print OUT
"/* Define to a macro to generate an assembly name from a C symbol */\n";
1340 print OUT
"#define __ASM_NAME(name) name\n";