3 # Copyright 2002 Patrik Stridvall
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;
23 $output->disable_progress;
26 ########################################################################
29 my @spec_files = get_spec_files("winelib");
30 my @makefile_in_files = get_makefile_in_files("winelib");
34 my $output_prefix_dir = "Output";
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 !~ /\./;
48 open(IN, "< $wine_dir/$spec_file");
52 while($lookahead || defined($_ = <IN>)) {
55 s/^\s*?(.*?)\s*$/$1/; # remove whitespace at begining and end of line
56 s/^(.*?)\s*#.*$/$1/; # remove comments
57 /^$/ && next; # skip empty lines
67 if(/^(\d+|@)\s+pascal(?:16)?/) {
75 if($module =~ /^(?:(?:imm|ole2conv|ole2prox|ole2thk|rasapi16|windebug)\.dll|comm\.drv)$/) {
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);
93 my @ntdll_dirs = qw(misc);
94 my @user32_dirs = qw(dlls/user/dde windows);
96 push @makefile_in_files, "tools/winebuild/Makefile.in";
98 sub filter_files($$) {
102 my $filtered_files = [];
103 my $rest_of_files = [];
104 foreach my $file (@$files) {
105 if($file =~ /$filter/) {
106 $file =~ s%.*?([^/]+)$%./$1%; # FIXME: Kludge
107 push @$filtered_files, $file;
109 push @$rest_of_files, $file;
112 return ($rest_of_files, $filtered_files);
115 my %wine_test_dsp_files;
117 MAKEFILE_IN: foreach my $makefile_in_file (@makefile_in_files) {
118 open(IN, "< $wine_dir/$makefile_in_file");
129 while($again || defined(my $line = <IN>)) {
142 s/^\s*?(.*?)\s*$/$1/; # remove whitespace at begining and end of line
143 s/^(.*?)\s*#.*$/$1/; # remove comments
144 /^$/ && next; # skip empty lines
151 if(/^MODULE\s*=\s*([\w\.]+)$/) {
154 if($module eq "none") {
155 if($makefile_in_file eq "library/Makefile.in") {
156 $module = "wine.dll";
157 } elsif($makefile_in_file eq "unicode/Makefile.in") {
158 $module = "wine_unicode.dll";
159 } elsif($makefile_in_file eq "tools/winebuild/Makefile.in") {
160 $module = "winebuild.exe";
165 } elsif(/^TOPOBJDIR\s*=\s*(\S+)\s*$/) {
167 } elsif (/^TESTDLL\s*=\s*(\S+)\s*$/) {
169 } elsif (/^IMPORTS\s*=\s*/) {
170 push @imports, grep !/^ntdll$/, split /\s+/s, $';
171 } elsif (/^EXTRALIBS\s*=\s*/) {
172 push @imports, map { /^-l(dxerr8|dxerr9|dxguid|strmiids|uuid)$/ ? $1 : () } split /\s+/s, $';
173 } elsif (/^CTESTS\s*=\s*/) {
174 my @files = split /\s+/s, $';
176 my $dir = $makefile_in_file;
177 $dir =~ s/\/Makefile\.in$//;
179 my $dsp_file = $testdll;
180 $dsp_file =~ s/\.(dll|drv)$/_test.dsp/;
181 $dsp_file = "$dir/$dsp_file";
183 $wine_test_dsp_files{$dsp_file}{files} = [@files, "testlist.c"];
184 $wine_test_dsp_files{$dsp_file}{imports} = [@imports];
185 } elsif(/^(\w+)\s*=\s*/) {
187 my @files = split /\s+/s, $';
190 if(/^\$\((\w+):\%=(.*?)\%(.*?)\)$/) {
191 my @list = @{$vars{$1}};
194 foreach my $item (@list) {
195 $item = "$prefix$item$suffix";
198 } elsif(/^\$\(TOPOBJDIR\)(.*?)$/) {
201 print STDERR "unknown variable '$_'\n" if 0;
208 $vars{$var} = \@files;
217 my $source_files = [];
218 if(exists($vars{C_SRCS})) {
219 $c_srcs = [sort(@{$vars{C_SRCS}})];
220 $source_files = [sort(@{$vars{C_SRCS}})];
223 my $header_files = [];
224 if(exists($vars{H_SRCS})) {
225 $header_files = [sort(@{$vars{H_SRCS}})];
228 my $resource_files = [];
229 if(exists($vars{RC_SRCS})) {
230 $resource_files = [sort(@{$vars{RC_SRCS}})];
233 my $project = $module;
234 $project =~ s/\.(?:dll|exe|lib)$//;
238 if($module =~ /\.exe$/) {
240 } elsif($module =~ /\.lib$/) {
246 my $dsp_file = $makefile_in_file;
247 $dsp_file =~ s/Makefile.in$/$project.dsp/;
249 if($module eq "gdi32.dll") {
250 foreach my $dir (@gdi32_dirs) {
252 $dir2 =~ s%^.*?/([^/]+)$%$1%;
254 my $module = "gdi32_$dir2.lib";
257 my $project = "gdi32_$dir2";
261 my $dsp_file = "$dir/$project.dsp";
263 ($source_files, my $local_source_files) = filter_files($source_files, "$dir2/");
264 ($header_files, my $local_header_files) = filter_files($header_files, "$dir2/");
265 ($resource_files, my $local_resource_files) = filter_files($resource_files, "$dir2/");
267 $modules{$module}{wine} = 1;
268 $modules{$module}{winetest} = 0;
269 $modules{$module}{project} = $project;
270 $modules{$module}{type} = $type;
271 $modules{$module}{dsp_file} = $dsp_file;
272 $modules{$module}{c_srcs} = $c_srcs;
273 $modules{$module}{source_files} = $local_source_files;
274 $modules{$module}{header_files} = $local_header_files;
275 $modules{$module}{resource_files} = $local_resource_files;
276 $modules{$module}{imports} = [];
278 } elsif($module eq "ntdll.dll") {
279 foreach my $dir (@ntdll_dirs) {
280 my $module = "ntdll_$dir.lib";
283 my $project = "ntdll_$dir";
287 my $dsp_file = "$dir/$project.dsp";
289 ($source_files, my $local_source_files) = filter_files($source_files, "/$dir/");
290 ($header_files, my $local_header_files) = filter_files($header_files, "/$dir/");
291 ($resource_files, my $local_resource_files) = filter_files($resource_files, "/$dir/");
293 $modules{$module}{wine} = 1;
294 $modules{$module}{winetest} = 0;
295 $modules{$module}{project} = $project;
296 $modules{$module}{type} = $type;
297 $modules{$module}{dsp_file} = $dsp_file;
298 $modules{$module}{c_srcs} = $c_srcs;
299 $modules{$module}{source_files} = $local_source_files;
300 $modules{$module}{header_files} = $local_header_files;
301 $modules{$module}{resource_files} = $local_resource_files;
302 $modules{$module}{imports} = [];
304 } elsif($module eq "user32.dll") {
305 foreach my $dir (@user32_dirs) {
307 $dir2 =~ s%^.*?/([^/]+)$%$1%;
309 my $module = "user32_$dir2.lib";
312 my $project = "user32_$dir2";
316 my $dsp_file = "$dir/$project.dsp";
318 ($source_files, my $local_source_files) = filter_files($source_files, "$dir2/");
319 ($header_files, my $local_header_files) = filter_files($header_files, "$dir2/");
320 ($resource_files, my $local_resource_files) = filter_files($resource_files, "$dir2/");
322 $modules{$module}{wine} = 1;
323 $modules{$module}{winetest} = 0;
324 $modules{$module}{project} = $project;
325 $modules{$module}{type} = $type;
326 $modules{$module}{dsp_file} = $dsp_file;
327 $modules{$module}{c_srcs} = $c_srcs;
328 $modules{$module}{source_files} = $local_source_files;
329 $modules{$module}{header_files} = $local_header_files;
330 $modules{$module}{resource_files} = $local_resource_files;
331 $modules{$module}{imports} = [];
335 $modules{$module}{wine} = 1;
336 $modules{$module}{winetest} = 0;
337 $modules{$module}{project} = $project;
338 $modules{$module}{type} = $type;
339 $modules{$module}{dsp_file} = $dsp_file;
340 $modules{$module}{c_srcs} = $c_srcs;
341 $modules{$module}{source_files} = $source_files;
342 $modules{$module}{header_files} = $header_files;
343 $modules{$module}{resource_files} = $resource_files;
344 $modules{$module}{imports} = [];
347 $wine_test_dsp_files{"wineruntests.dsp"}{files} = ["runtests.c"];
348 $wine_test_dsp_files{"wineruntests.dsp"}{imports} = [];
350 $wine_test_dsp_files{"winetest.dsp"}{files} = [
351 'include/wine/exception.h',
352 'include/wine/test.h',
353 'include/wine/unicode.h',
356 $wine_test_dsp_files{"winetest.dsp"}{imports} = [];
360 foreach my $dsp_file (keys(%wine_test_dsp_files)) {
361 my $project = $dsp_file;
362 $project =~ s%^(?:.*?/)?([^/]+)\.dsp$%$1%;
364 my @files = @{$wine_test_dsp_files{$dsp_file}{files}};
365 my @imports = @{$wine_test_dsp_files{$dsp_file}{imports}};
369 my $source_files = [];
370 my $header_files = [];
371 my $resource_files = [];
375 if ($project eq "winetest") {
378 $source_files = [@files];
380 $resource_files = [];
381 } elsif ($project eq "wineruntests") {
384 $source_files = [@files];
386 $resource_files = [];
390 $source_files = [@files];
392 $resource_files = [];
395 if (/^testlist\.c$/) {
403 $runtests{$dsp_file} = [@tests];
405 my $module = "$project.$type";
407 $modules{$module}{wine} = 0;
408 $modules{$module}{winetest} = 1;
410 $modules{$module}{project} = $project;
411 $modules{$module}{type} = $type;
412 $modules{$module}{dsp_file} = $dsp_file;
413 $modules{$module}{c_srcs} = $c_srcs;
414 $modules{$module}{source_files} = $source_files;
415 $modules{$module}{header_files} = $header_files;
416 $modules{$module}{resource_files} = $resource_files;
417 $modules{$module}{imports} = [@imports];
419 $modules{$module}{tests} = [@tests];
422 foreach my $module (sort(keys(%modules))) {
423 if($module =~ /^(?:ttydrv.dll|x11drv.dll)$/) {
424 delete $modules{$module};
429 foreach my $module (sort(keys(%modules))) {
430 if (($options->wine && $modules{$module}{wine}) ||
431 ($options->winetest && $modules{$module}{winetest}))
433 push @modules, $module;
438 my $progress_current = 0;
439 my $progress_max = scalar(@modules);
441 foreach my $module (@modules) {
442 my $dsp_file = $modules{$module}{dsp_file};
443 replace_file("$wine_dir/$dsp_file", \&_generate_dsp, $module);
446 sub _generate_dsp($$) {
451 my $dsp_file = $modules{$module}{dsp_file};
452 my $project = $modules{$module}{project};
453 my @imports = @{$modules{$module}{imports}};
455 my $lib = ($modules{$module}{type} eq "lib");
456 my $dll = ($modules{$module}{type} eq "dll");
457 my $exe = ($modules{$module}{type} eq "exe");
459 my $console = $exe; # FIXME: Not always correct
461 my $msvc_wine_dir = do {
462 my @parts = split(m%/%, $dsp_file);
465 } elsif($#parts == 2) {
471 my $wine_include_dir = "$msvc_wine_dir\\include";
474 $output->progress("$dsp_file (file $progress_current of $progress_max)");
476 my @c_srcs = @{$modules{$module}{c_srcs}};
477 my @source_files = @{$modules{$module}{source_files}};
478 my @header_files = @{$modules{$module}{header_files}};
479 my @resource_files = @{$modules{$module}{resource_files}};
481 if ($project !~ /^(?:wine(?:_unicode)?|wine(?:build|runtests|test))$/ &&
482 $project !~ /^(?:gdi32|ntdll|user32)_.+?$/ &&
483 $project !~ /_test$/)
485 push @source_files, "$project.spec";
486 # push @source_files, "$project.spec.c";
487 @source_files = sort(@source_files);
491 my $no_msvc_headers = 1;
492 if ($project =~ /^(?:wine(?:runtests|test))$/ || $project =~ /_test$/) {
493 $no_msvc_headers = 0;
498 push @cfgs, "$project - Win32";
502 foreach my $cfg (@cfgs) {
503 push @_cfgs, "$cfg C";
504 push @_cfgs, "$cfg C++";
511 foreach my $cfg (@cfgs) {
512 push @_cfgs, "$cfg Debug";
513 push @_cfgs, "$cfg Release";
518 if (!$no_msvc_headers) {
520 foreach my $cfg (@cfgs) {
521 push @_cfgs, "$cfg MSVC Headers";
522 push @_cfgs, "$cfg Wine Headers";
527 my $default_cfg = $cfgs[$#cfgs];
529 print OUT "# Microsoft Developer Studio Project File - Name=\"$project\" - Package Owner=<4>\r\n";
530 print OUT "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n";
531 print OUT "# ** DO NOT EDIT **\r\n";
535 print OUT "# TARGTYPE \"Win32 (x86) Static Library\" 0x0104\r\n";
537 print OUT "# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\r\n";
539 print OUT "# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n";
543 print OUT "CFG=$default_cfg\r\n";
544 print OUT "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n";
545 print OUT "!MESSAGE use the Export Makefile command and run\r\n";
546 print OUT "!MESSAGE \r\n";
547 print OUT "!MESSAGE NMAKE /f \"$project.mak\".\r\n";
548 print OUT "!MESSAGE \r\n";
549 print OUT "!MESSAGE You can specify a configuration when running NMAKE\r\n";
550 print OUT "!MESSAGE by defining the macro CFG on the command line. For example:\r\n";
551 print OUT "!MESSAGE \r\n";
552 print OUT "!MESSAGE NMAKE /f \"$project.mak\" CFG=\"$default_cfg\"\r\n";
553 print OUT "!MESSAGE \r\n";
554 print OUT "!MESSAGE Possible choices for configuration are:\r\n";
555 print OUT "!MESSAGE \r\n";
556 foreach my $cfg (@cfgs) {
558 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Static Library\")\r\n";
560 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n";
562 print OUT "!MESSAGE \"$cfg\" (based on \"Win32 (x86) Console Application\")\r\n";
565 print OUT "!MESSAGE \r\n";
568 print OUT "# Begin Project\r\n";
569 print OUT "# PROP AllowPerConfigDependencies 0\r\n";
570 print OUT "# PROP Scc_ProjName \"\"\r\n";
571 print OUT "# PROP Scc_LocalPath \"\"\r\n";
572 print OUT "CPP=cl.exe\r\n";
573 print OUT "MTL=midl.exe\r\n" if !$lib && !$exe;
574 print OUT "RSC=rc.exe\r\n";
579 foreach my $cfg (@cfgs) {
583 print OUT "!IF \"\$(CFG)\" == \"$cfg\"\r\n";
587 print OUT "!ELSEIF \"\$(CFG)\" == \"$cfg\"\r\n";
591 my $debug = ($cfg !~ /Release/);
592 my $msvc_headers = ($cfg =~ /MSVC Headers/);
594 print OUT "# PROP BASE Use_MFC 0\r\n";
597 print OUT "# PROP BASE Use_Debug_Libraries 1\r\n";
599 print OUT "# PROP BASE Use_Debug_Libraries 0\r\n";
603 $output_dir =~ s/^$project - //;
604 $output_dir =~ s/ /_/g;
605 $output_dir =~ s/C\+\+/Cxx/g;
606 if($output_prefix_dir) {
607 $output_dir = "$output_prefix_dir\\$output_dir";
610 print OUT "# PROP BASE Output_Dir \"$output_dir\"\r\n";
611 print OUT "# PROP BASE Intermediate_Dir \"$output_dir\"\r\n";
613 print OUT "# PROP BASE Target_Dir \"\"\r\n";
615 print OUT "# PROP Use_MFC 0\r\n";
617 print OUT "# PROP Use_Debug_Libraries 1\r\n";
619 print OUT "# PROP Use_Debug_Libraries 0\r\n";
621 print OUT "# PROP Output_Dir \"$output_dir\"\r\n";
622 print OUT "# PROP Intermediate_Dir \"$output_dir\"\r\n";
624 print OUT "# PROP Ignore_Export_Lib 0\r\n" if $dll;
625 print OUT "# PROP Target_Dir \"\"\r\n";
630 print OUT "# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od";
631 @defines = (qw(WIN32 _DEBUG _MBCS _LIB));
633 print OUT "# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od";
634 @defines = (qw(_WIN32_WINNT=0x0501 _WIN32_IE=0x0600 WIN32 _DEBUG _WINDOWS _MBCS _USRDLL), ("\U${project}\E_EXPORTS"));
638 print OUT "# ADD BASE CPP /nologo /W3 /GX /O2";
639 @defines = (qw(WIN32 NDEBUG _MBCS _LIB));
641 print OUT "# ADD BASE CPP /nologo /MT /W3 /GX /O2";
642 @defines = (qw(WIN32 NDEBUG _WINDOWS _MBCS _USRDLL), ("\U${project}\E_EXPORTS"));
646 foreach my $define (@defines) {
647 print OUT " /D \"$define\"";
649 print OUT " /YX" if $lib || $exe;
651 print OUT " /GZ" if $debug;
652 print OUT " " if $debug && ($lib || $exe);
659 print OUT "# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od";
660 @defines2 = qw(WIN32 _DEBUG _WINDOWS _MBCS _LIB);
662 print OUT "# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od";
663 @defines2 = qw(_DEBUG WIN32 _WINDOWS _MBCS _USRDLL);
667 print OUT "# ADD CPP /nologo /MT /W3 /GX /O2";
668 @defines2 = qw(WIN32 NDEBUG _WINDOWS _MBCS _LIB);
670 print OUT "# ADD CPP /nologo /MT /W3 /GX /O2";
671 @defines2 = qw(NDEBUG WIN32 _WINDOWS _MBCS _USRDLL);
677 push @defines2, "_\U${project}\E_";
678 push @defines2, qw(__WINESRC__) if $project !~ /^(?:wine(?:build|test)|.*?_test)$/;
680 push @defines2, qw(__WINE_USE_NATIVE_HEADERS);
682 my $output_dir2 = $output_dir;
683 $output_dir =~ s/\\/\\\\/g;
684 push @defines2, "__WINETEST_OUTPUT_DIR=\\\"$output_dir\\\"";
685 push @defines2, qw(__i386__ _X86_);
687 if($project =~ /^gdi32_(?:enhmfdrv|mfdrv|win16drv)$/) {
688 push @includes, "..";
691 if($project =~ /^user32_(?:windows)$/) {
692 push @includes, "..\\dlls\\user";
695 if($project =~ /^user32_dde$/) {
696 push @includes, "..";
699 if ($project =~ /_test$/) {
700 push @includes, "$msvc_wine_dir\\$output_dir";
703 if (!$msvc_headers || $project =~ /^winetest$/) {
704 push @includes, $wine_include_dir;
709 foreach my $include (@includes) {
710 if ($include !~ /[\\\"]/) {
711 print OUT " /I \"$include\"";
713 print OUT " /I $include";
718 foreach my $define (@defines2) {
719 if ($define !~ /[\\\"]/) {
720 print OUT " /D \"$define\"";
722 print OUT " /D $define";
725 print OUT " /D inline=__inline" if $wine;
726 print OUT " /D \"__STDC__\"" if 0 && $wine;
728 print OUT " /YX" if $lib;
729 print OUT " /FR" if !$lib;
731 print OUT " /GZ" if $debug;
732 print OUT " " if $debug && $lib;
734 print OUT " /TP" if !$no_cpp;
738 print OUT "# SUBTRACT CPP /X /YX\r\n" if $dll;
739 print OUT "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
740 print OUT "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" if $dll;
741 print OUT "# ADD BASE RSC /l 0x41d /d \"_DEBUG\"\r\n";
742 print OUT "# ADD RSC /l 0x41d";
744 foreach my $include (@includes) {
745 print OUT " /i \"$include\"";
748 print OUT " /d \"_DEBUG\"\r\n";
750 print OUT "# SUBTRACT CPP /YX\r\n" if $dll;
751 print OUT "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
752 print OUT "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" if $dll;
753 print OUT "# ADD BASE RSC /l 0x41d /d \"NDEBUG\"\r\n";
754 print OUT "# ADD RSC /l 0x41d";
756 foreach my $include (@includes) {
757 print OUT " /i \"$include\"";
760 print OUT "/d \"NDEBUG\"\r\n";
762 print OUT "BSC32=bscmake.exe\r\n";
763 print OUT "# ADD BASE BSC32 /nologo\r\n";
764 print OUT "# ADD BSC32 /nologo\r\n";
767 print OUT "LINK32=link.exe\r\n";
768 print OUT "# ADD BASE LINK32 ";
769 my @libraries = qw(kernel32.lib user32.lib gdi32.lib winspool.lib
770 comdlg32.lib advapi32.lib shell32.lib ole32.lib
771 oleaut32.lib uuid.lib odbc32.lib odbccp32.lib);
772 foreach my $library (@libraries) {
773 print OUT "$library ";
775 print OUT " /nologo";
776 print OUT " /dll" if $dll;
777 print OUT " /subsystem:console" if $console;
778 print OUT " /debug" if $debug;
779 print OUT " /machine:I386";
780 print OUT " /pdbtype:sept" if $debug;
783 print OUT "# ADD LINK32";
784 print OUT " /nologo";
785 print OUT " libcmt.lib" if $project =~ /^ntdll$/; # FIXME: Kludge
786 foreach my $import (@imports) {
787 print OUT " $import.lib" if ($import ne "msvcrt");
789 print OUT " /dll" if $dll;
790 print OUT " /subsystem:console" if $console;
791 print OUT " /debug" if $debug;
792 print OUT " /machine:I386";
793 print OUT " /nodefaultlib" if $project =~ /^ntdll$/; # FIXME: Kludge
794 print OUT " /def:\"$project.def\"" if $dll;
795 print OUT " /pdbtype:sept" if $debug;
798 print OUT "LIB32=link.exe -lib\r\n";
799 print OUT "# ADD BASE LIB32 /nologo\r\n";
800 print OUT "# ADD LIB32 /nologo\r\n";
808 print OUT "!ENDIF \r\n";
812 if ($project eq "winebuild") {
813 print OUT "# Begin Special Build Tool\r\n";
814 print OUT "SOURCE=\"\$(InputPath)\"\r\n";
815 print OUT "PostBuild_Desc=Copying wine.dll and wine_unicode.dll ...\r\n";
816 print OUT "PostBuild_Cmds=";
817 print OUT "copy ..\\..\\library\\$output_dir\\wine.dll \$(OutDir)\t";
818 print OUT "copy ..\\..\\unicode\\$output_dir\\wine_unicode.dll \$(OutDir)\r\n";
819 print OUT "# End Special Build Tool\r\n";
821 print OUT "# Begin Target\r\n";
823 foreach my $cfg (@cfgs) {
824 print OUT "# Name \"$cfg\"\r\n";
827 print OUT "# Begin Group \"Source Files\"\r\n";
829 print OUT "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
831 foreach my $source_file (@source_files) {
832 $source_file =~ s%/%\\%g;
833 if($source_file !~ /^\./) {
834 $source_file = ".\\$source_file";
837 if($source_file =~ /^(.*?)\.spec$/) {
840 $basename = "$basename.dll" if $basename !~ /\..{1,3}$/;
841 my $dbg_c_file = "$basename.dbg.c";
843 print OUT "# Begin Source File\r\n";
845 print OUT "SOURCE=$dbg_c_file\r\n";
846 print OUT "# End Source File\r\n";
849 print OUT "# Begin Source File\r\n";
852 print OUT "SOURCE=$source_file\r\n";
854 if($source_file =~ /^(.*?)\.spec$/) {
857 my $spec_file = $source_file;
858 my $def_file = "$basename.def";
860 $basename = "$basename.dll" if $basename !~ /\..{1,3}$/;
861 my $dbg_file = "$basename.dbg";
862 my $dbg_c_file = "$basename.dbg.c";
864 my $srcdir = "."; # FIXME: Is this really always correct?
866 print OUT "# Begin Custom Build\r\n";
867 print OUT "InputPath=$spec_file\r\n";
869 print OUT "BuildCmds= \\\r\n";
870 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe --def $spec_file > $def_file \\\r\n";
872 if($project =~ /^ntdll$/) {
874 foreach my $c_src (@c_srcs) {
876 print OUT "\techo $c_src >> $dbg_file \\\r\n";
878 print OUT "\techo $c_src > $dbg_file \\\r\n";
881 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe";
882 print OUT " -o $dbg_c_file --debug -C$srcdir $dbg_file \\\r\n";
884 my $c_srcs = join(" ", grep(/\.c$/, @c_srcs));
886 print OUT "\t..\\..\\tools\\winebuild\\$output_dir\\winebuild.exe";
887 print OUT " -o $dbg_c_file --debug -C$srcdir $c_srcs \\\r\n";
892 print OUT "\"$def_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
893 print OUT " \$(BuildCmds)\r\n";
895 print OUT "\"$dbg_c_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
896 print OUT " \$(BuildCmds)\r\n";
897 print OUT "# End Custom Build\r\n";
898 } elsif($source_file =~ /([^\\]*?\.h)$/) {
901 foreach my $cfg (@cfgs) {
905 print OUT "!IF \"\$(CFG)\" == \"$cfg\"\r\n";
909 print OUT "!ELSEIF \"\$(CFG)\" == \"$cfg\"\r\n";
914 $output_dir =~ s/^$project - //;
915 $output_dir =~ s/ /_/g;
916 $output_dir =~ s/C\+\+/Cxx/g;
917 if($output_prefix_dir) {
918 $output_dir = "$output_prefix_dir\\$output_dir";
921 print OUT "# Begin Custom Build\r\n";
922 print OUT "OutDir=$output_dir\r\n";
923 print OUT "InputPath=$source_file\r\n";
925 print OUT "\"\$(OutDir)\\wine\\$h_file\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\r\n";
926 print OUT "\tcopy \"\$(InputPath)\" \"\$(OutDir)\\wine\"\r\n";
928 print OUT "# End Custom Build\r\n";
933 print OUT "!ENDIF \r\n";
938 print OUT "# End Source File\r\n";
940 print OUT "# End Group\r\n";
942 print OUT "# Begin Group \"Header Files\"\r\n";
944 print OUT "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
945 foreach my $header_file (@header_files) {
946 print OUT "# Begin Source File\r\n";
948 print OUT "SOURCE=.\\$header_file\r\n";
949 print OUT "# End Source File\r\n";
951 print OUT "# End Group\r\n";
955 print OUT "# Begin Group \"Resource Files\"\r\n";
957 print OUT "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
958 foreach my $resource_file (@resource_files) {
959 print OUT "# Begin Source File\r\n";
961 print OUT "SOURCE=.\\$resource_file\r\n";
962 print OUT "# End Source File\r\n";
964 print OUT "# End Group\r\n";
966 print OUT "# End Target\r\n";
967 print OUT "# End Project\r\n";
972 sub _generate_dsw_header($) {
975 print OUT "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n";
976 print OUT "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n";
980 sub _generate_dsw_project($$$$) {
984 my $dsp_file = shift;
985 my @dependencies = @{(shift)};
987 $dsp_file = "./$dsp_file";
988 $dsp_file =~ y%/%\\%;
990 @dependencies = sort(@dependencies);
992 print OUT "###############################################################################\r\n";
994 print OUT "Project: \"$project\"=$dsp_file - Package Owner=<4>\r\n";
996 print OUT "Package=<5>\r\n";
1000 print OUT "Package=<4>\r\n";
1001 print OUT "{{{\r\n";
1002 foreach my $dependency (@dependencies) {
1003 print OUT " Begin Project Dependency\r\n";
1004 print OUT " Project_Dep_Name $dependency\r\n";
1005 print OUT " End Project Dependency\r\n";
1007 print OUT "}}}\r\n";
1011 sub _generate_dsw_footer($) {
1014 print OUT "###############################################################################\r\n";
1016 print OUT "Global:\r\n";
1018 print OUT "Package=<5>\r\n";
1019 print OUT "{{{\r\n";
1020 print OUT "}}}\r\n";
1022 print OUT "Package=<3>\r\n";
1023 print OUT "{{{\r\n";
1024 print OUT "}}}\r\n";
1026 print OUT "###############################################################################\r\n";
1030 if ($options->wine) {
1031 my $dsw_file = "wine.dsw";
1032 $output->progress("$dsw_file");
1033 replace_file("$wine_dir/$dsw_file", \&_generate_wine_dsw);
1036 sub _generate_wine_dsw($) {
1039 _generate_dsw_header(\*OUT);
1040 foreach my $module (sort(keys(%modules))) {
1041 next if $module =~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1043 my $project = $modules{$module}{project};
1044 my $dsp_file = $modules{$module}{dsp_file};
1047 if($project =~ /^wine(?:_unicode)?$/) {
1049 } elsif($project =~ /^winebuild$/) {
1050 @dependencies = ("wine", "wine_unicode");
1051 } elsif($project =~ /^(?:gdi32|ntdll|user32)_.+?$/) {
1054 @dependencies = ("wine", "wine_unicode", "winebuild");
1057 if($project =~ /^gdi32$/) {
1058 foreach my $dir (@gdi32_dirs) {
1060 $dir2 =~ s%^.*?/([^/]+)$%$1%;
1062 my $module = "gdi32_$dir2";
1064 push @dependencies, $module;
1066 } elsif($project =~ /^ntdll$/) {
1067 foreach my $dir (@ntdll_dirs) {
1068 my $module = "ntdll_$dir";
1070 push @dependencies, $module;
1072 } elsif($project =~ /^user32$/) {
1073 foreach my $dir (@user32_dirs) {
1075 $dir2 =~ s%^.*?/([^/]+)$%$1%;
1077 my $module = "user32_$dir2";
1079 push @dependencies, $module;
1083 _generate_dsw_project(\*OUT, $project, $dsp_file, \@dependencies);
1085 _generate_dsw_footer(\*OUT);
1090 if ($options->winetest) {
1091 my $dsw_file = "winetest.dsw";
1092 $output->progress("$dsw_file");
1093 replace_file("$wine_dir/$dsw_file", \&_generate_winetest_dsw);
1096 sub _generate_winetest_dsw($) {
1099 _generate_dsw_header(\*OUT);
1101 my @runtests_dependencies = ();
1102 foreach my $module (sort(keys(%modules))) {
1103 next if $module !~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1104 next if $module eq "wineruntests";
1106 my $project = $modules{$module}{project};
1108 push @runtests_dependencies, $project;
1111 foreach my $module (sort(keys(%modules))) {
1112 next if $module !~ /(?:winetest\.lib|wineruntests\.exe|_test\.exe)$/;
1114 my $project = $modules{$module}{project};
1115 my $dsp_file = $modules{$module}{dsp_file};
1118 if($project =~ /^winetest$/) {
1120 } elsif($project =~ /^wineruntests$/) {
1121 @dependencies = @runtests_dependencies;
1123 @dependencies = ("winetest");
1126 _generate_dsw_project(\*OUT, $project, $dsp_file, \@dependencies);
1129 _generate_dsw_footer(\*OUT);
1132 if ($options->winetest) {
1133 foreach my $module (sort(keys(%modules))) {
1134 next if $module !~ /_test\.exe$/;
1136 my $project = $modules{$module}{project};
1137 my $dsp_file = $modules{$module}{dsp_file};
1138 my @tests = @{$modules{$module}{tests}};
1140 my $testlist_c = $dsp_file;
1141 $testlist_c =~ s%[^/]*\.dsp$%testlist.c%;
1143 replace_file("$wine_dir/$testlist_c", \&_generate_testlist_c, \@tests);
1147 # ***** Keep in sync with tools/make_ctests *****
1148 sub _generate_testlist_c($$) {
1151 my @tests = @{(shift)};
1153 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n";
1155 print OUT "/* stdarg.h is needed for Winelib */\n";
1156 print OUT "#include <stdarg.h>\n";
1157 print OUT "#include <stdio.h>\n";
1158 print OUT "#include <stdlib.h>\n";
1159 print OUT "#include \"windef.h\"\n";
1160 print OUT "#include \"winbase.h\"\n";
1162 foreach my $test (@tests) {
1163 print OUT "extern void func_$test(void);\n";
1166 print OUT "struct test\n";
1168 print OUT " const char *name;\n";
1169 print OUT " void (*func)(void);\n";
1172 print OUT "static const struct test winetest_testlist[] =\n";
1174 foreach my $test (@tests) {
1175 print OUT " { \"$test\", func_$test },\n";
1177 print OUT " { 0, 0 }\n";
1180 print OUT "#define WINETEST_WANT_MAIN\n";
1181 print OUT "#include \"wine/test.h\"\n";
1184 if ($options->winetest) {
1185 replace_file("$wine_dir/runtests.c", \&_generate_runtests_c);
1188 sub _generate_runtests_c($) {
1191 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n";
1194 print OUT "#include <stdio.h>\n";
1195 print OUT "#include <stdlib.h>\n";
1198 print OUT "int main(int argc, char *argv[])\n";
1200 print OUT " char output_dir[] = __WINETEST_OUTPUT_DIR;\n";
1201 print OUT " char command[4096];\n";
1203 foreach my $dsp_file (keys(%runtests)) {
1204 my @tests = @{$runtests{$dsp_file}};
1206 my $project = $dsp_file;
1207 $project =~ s%^(.*?)/?([^/]+)\.dsp$%$2%;
1211 foreach my $test (@tests) {
1212 print OUT " sprintf(command, \"$dir\\\\%s\\\\$project.exe $test\", output_dir);\n";
1213 print OUT " system(command);\n";
1217 print OUT " return 0;\n";
1221 if ($options->winetest) {
1222 replace_file("$wine_dir/winetest.c", \&_generate_winetest_c);
1225 sub _generate_winetest_c($) {
1228 print OUT "/* Automatically generated file; DO NOT EDIT!! */\n\n";
1230 print OUT "/* Force the linker to generate a .lib file */\n";
1231 print OUT "void __wine_dummy_lib_function()\n{\n}\n\n";
1234 if ($options->wine) {
1235 my $config_h = "include/config.h";
1237 $output->progress("$config_h");
1239 replace_file("$wine_dir/$config_h", \&_generate_config_h);
1242 sub _generate_config_h($) {
1245 print OUT "#define __WINE_CONFIG_H\n";
1248 my @headers = qw(direct.h fcntl.h io.h string.h process.h);
1249 foreach my $header (@headers) {
1250 $header =~ y/\.\//__/;
1251 print OUT "#define HAVE_\U$header\E\n";
1256 _alldiv _allmul _allrem _aulldiv _aullrem
1257 _access _chdir _close _lseek _mkdir _open _pclose _popen _read _rmdir _write _stat
1258 _snprintf _spawnvp _stricmp _strnicmp _vsnprintf _wcsicmp
1264 foreach my $function (@functions) {
1265 print OUT "#define HAVE_\U$function\E 1\n";
1270 print OUT "#define NEED_STDCALL_DECORATION 1\n";
1274 print OUT "#define X_DISPLAY_MISSING 1\n";
1277 print OUT "/* Define to a macro to generate an assembly function directive */\n";
1278 print OUT "#define __ASM_FUNC(name) \"\"\n";
1281 print OUT "/* Define to a macro to generate an assembly name from a C symbol */\n";
1282 print OUT "#define __ASM_NAME(name) name\n";
1285 print OUT "/* Define to the assembler keyword used to specify a word value */";
1286 print OUT "define __ASM_SHORT \".short\"";
1289 print OUT "/* Define to the assembler keyword used to specify an ASCII string */";
1290 print OUT "#define __ASM_STRING \".string\"";
1293 print OUT "/* Define to the address where bug reports for this package should be sent. */\n";
1294 print OUT "#define PACKAGE_BUGREPORT \"\"\n";
1297 print OUT "/* Define to the full name of this package. */\n";
1298 print OUT "#define PACKAGE_NAME \"Wine\"\n";
1301 print OUT "/* Define to the full name and version of this package. */\n";
1302 print OUT "#define PACKAGE_STRING \"Wine YYYYMMDD\"\n";
1305 print OUT "/* Define to the one symbol short name of this package. */\n";
1306 print OUT "#define PACKAGE_TARNAME \"wine\"\n";
1309 print OUT "/* Define to the version of this package. */\n";
1310 print OUT "#define PACKAGE_VERSION \"YYYYMMDD\"\n";