1 package Generators
::Vcproj
;
6 use Digest::SHA qw(sha256_hex);
9 our(@ISA, @EXPORT, @EXPORT_OK, @AVAILABLE);
13 push @EXPORT_OK, qw(generate);
16 sub generate_guid
($) {
17 my $hex = sha256_hex
($_[0]);
18 $hex =~ s/^(.{8})(.{4})(.{4})(.{4})(.{12}).*/{$1-$2-$3-$4-$5}/;
24 my ($git_dir, $out_dir, $rel_dir, %build_structure) = @_;
25 my @libs = @
{$build_structure{"LIBS"}};
27 createLibProject
($_, $git_dir, $out_dir, $rel_dir, \
%build_structure);
30 my @apps = @
{$build_structure{"APPS"}};
32 createAppProject
($_, $git_dir, $out_dir, $rel_dir, \
%build_structure);
35 createGlueProject
($git_dir, $out_dir, $rel_dir, %build_structure);
39 sub createLibProject
{
40 my ($libname, $git_dir, $out_dir, $rel_dir, $build_structure) = @_;
41 print "Generate $libname vcproj lib project\n";
42 $rel_dir = "..\\$rel_dir";
43 $rel_dir =~ s/\//\\/g
;
45 my $target = $libname;
49 my $uuid = generate_guid
($libname);
50 $$build_structure{"LIBS_${target}_GUID"} = $uuid;
52 my @srcs = sort(map("$rel_dir\\$_", @
{$$build_structure{"LIBS_${libname}_SOURCES"}}));
58 my $defines = join(",", sort(@
{$$build_structure{"LIBS_${libname}_DEFINES"}}));
59 my $includes= join(";", sort(map(""$rel_dir\\$_"", @
{$$build_structure{"LIBS_${libname}_INCLUDES"}})));
60 my $cflags = join(" ", sort(@
{$$build_structure{"LIBS_${libname}_CFLAGS"}}));
61 $cflags =~ s/\"/"/g;
62 $cflags =~ s/</</g;
63 $cflags =~ s/>/>/g;
65 my $cflags_debug = $cflags;
66 $cflags_debug =~ s/-MT/-MTd/;
67 $cflags_debug =~ s/-O.//;
69 my $cflags_release = $cflags;
70 $cflags_release =~ s/-MTd/-MT/;
72 my @tmp = @
{$$build_structure{"LIBS_${libname}_LFLAGS"}};
77 $_ =~ s/^-L/-LIBPATH:$rel_dir\//;
81 my $lflags = join(" ", sort(@tmp));
84 $defines =~ s/\"/\\"/g;
85 $defines =~ s/</</g;
86 $defines =~ s/>/>/g;
89 mkdir "$target" || die "Could not create the directory $target for lib project!\n";
90 open F
, ">$target/$target.vcproj" || die "Could not open $target/$target.pro for writing!\n";
93 <?xml version
="1.0" encoding
= "Windows-1252"?
>
95 ProjectType
="Visual C++"
108 OutputDirectory
="$rel_dir"
109 ConfigurationType
="4"
111 IntermediateDirectory
="\$(ProjectDir)\$(ConfigurationName)"
114 Name
="VCPreBuildEventTool"
117 Name
="VCCustomBuildTool"
120 Name
="VCXMLDataGeneratorTool"
126 Name
="VCCLCompilerTool"
127 AdditionalOptions
="$cflags_debug"
129 InlineFunctionExpansion
="1"
130 AdditionalIncludeDirectories
="$includes"
131 PreprocessorDefinitions
="WIN32,_DEBUG,$defines"
132 MinimalRebuild
="true"
134 UsePrecompiledHeader
="0"
135 ProgramDataBaseFileName
="\$(IntDir)\\\$(TargetName).pdb"
137 DebugInformationFormat
="3"
140 Name
="VCManagedResourceCompilerTool"
143 Name
="VCResourceCompilerTool"
146 Name
="VCPreLinkEventTool"
149 Name
="VCLibrarianTool"
150 SuppressStartupBanner
="true"
165 Name
="VCPostBuildEventTool"
170 OutputDirectory
="$rel_dir"
171 ConfigurationType
="4"
173 WholeProgramOptimization
="1"
174 IntermediateDirectory
="\$(ProjectDir)\$(ConfigurationName)"
177 Name
="VCPreBuildEventTool"
180 Name
="VCCustomBuildTool"
183 Name
="VCXMLDataGeneratorTool"
189 Name
="VCCLCompilerTool"
190 AdditionalOptions
="$cflags_release"
192 InlineFunctionExpansion
="1"
193 EnableIntrinsicFunctions
="true"
194 AdditionalIncludeDirectories
="$includes"
195 PreprocessorDefinitions
="WIN32,NDEBUG,$defines"
197 EnableFunctionLevelLinking
="true"
198 UsePrecompiledHeader
="0"
199 ProgramDataBaseFileName
="\$(IntDir)\\\$(TargetName).pdb"
201 DebugInformationFormat
="3"
204 Name
="VCManagedResourceCompilerTool"
207 Name
="VCResourceCompilerTool"
210 Name
="VCPreLinkEventTool"
213 Name
="VCLibrarianTool"
214 SuppressStartupBanner
="true"
229 Name
="VCPostBuildEventTool"
236 Filter
="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
237 UniqueIdentifier
="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
250 </VisualStudioProject
>
255 sub createAppProject
{
256 my ($appname, $git_dir, $out_dir, $rel_dir, $build_structure) = @_;
257 print "Generate $appname vcproj app project\n";
258 $rel_dir = "..\\$rel_dir";
259 $rel_dir =~ s/\//\\/g
;
261 my $target = $appname;
263 $target =~ s/\.exe//;
265 my $uuid = generate_guid
($appname);
266 $$build_structure{"APPS_${target}_GUID"} = $uuid;
268 my @srcs = sort(map("$rel_dir\\$_", @
{$$build_structure{"APPS_${appname}_SOURCES"}}));
274 my $defines = join(",", sort(@
{$$build_structure{"APPS_${appname}_DEFINES"}}));
275 my $includes= join(";", sort(map(""$rel_dir\\$_"", @
{$$build_structure{"APPS_${appname}_INCLUDES"}})));
276 my $cflags = join(" ", sort(@
{$$build_structure{"APPS_${appname}_CFLAGS"}}));
277 $cflags =~ s/\"/"/g;
278 $cflags =~ s/</</g;
279 $cflags =~ s/>/>/g;
281 my $cflags_debug = $cflags;
282 $cflags_debug =~ s/-MT/-MTd/;
283 $cflags_debug =~ s/-O.//;
285 my $cflags_release = $cflags;
286 $cflags_release =~ s/-MTd/-MT/;
289 foreach (sort(@
{$$build_structure{"APPS_${appname}_LIBS"}})) {
293 my @tmp = @
{$$build_structure{"APPS_${appname}_LFLAGS"}};
298 $_ =~ s/^-L/-LIBPATH:$rel_dir\//;
302 my $lflags = join(" ", sort(@tmp)) . " -LIBPATH:$rel_dir";
305 $defines =~ s/\"/\\"/g;
306 $defines =~ s/</</g;
307 $defines =~ s/>/>/g;
309 $defines =~ s/\\\\/\\/g;
310 $includes =~ s/-I//g;
311 mkdir "$target" || die "Could not create the directory $target for lib project!\n";
312 open F
, ">$target/$target.vcproj" || die "Could not open $target/$target.pro for writing!\n";
315 <?xml version
="1.0" encoding
= "Windows-1252"?
>
317 ProjectType
="Visual C++"
330 OutputDirectory
="$rel_dir"
331 ConfigurationType
="1"
333 IntermediateDirectory
="\$(ProjectDir)\$(ConfigurationName)"
336 Name
="VCPreBuildEventTool"
339 Name
="VCCustomBuildTool"
342 Name
="VCXMLDataGeneratorTool"
348 Name
="VCCLCompilerTool"
349 AdditionalOptions
="$cflags_debug"
351 InlineFunctionExpansion
="1"
352 AdditionalIncludeDirectories
="$includes"
353 PreprocessorDefinitions
="WIN32,_DEBUG,$defines"
354 MinimalRebuild
="true"
356 UsePrecompiledHeader
="0"
357 ProgramDataBaseFileName
="\$(IntDir)\\\$(TargetName).pdb"
359 DebugInformationFormat
="3"
362 Name
="VCManagedResourceCompilerTool"
365 Name
="VCResourceCompilerTool"
368 Name
="VCPreLinkEventTool"
372 AdditionalDependencies
="$libs"
373 AdditionalOptions
="$lflags"
375 GenerateDebugInformation
="true"
392 Name
="VCPostBuildEventTool"
397 OutputDirectory
="$rel_dir"
398 ConfigurationType
="1"
400 WholeProgramOptimization
="1"
401 IntermediateDirectory
="\$(ProjectDir)\$(ConfigurationName)"
404 Name
="VCPreBuildEventTool"
407 Name
="VCCustomBuildTool"
410 Name
="VCXMLDataGeneratorTool"
416 Name
="VCCLCompilerTool"
417 AdditionalOptions
="$cflags_release"
419 InlineFunctionExpansion
="1"
420 EnableIntrinsicFunctions
="true"
421 AdditionalIncludeDirectories
="$includes"
422 PreprocessorDefinitions
="WIN32,NDEBUG,$defines"
424 EnableFunctionLevelLinking
="true"
425 UsePrecompiledHeader
="0"
426 ProgramDataBaseFileName
="\$(IntDir)\\\$(TargetName).pdb"
428 DebugInformationFormat
="3"
431 Name
="VCManagedResourceCompilerTool"
434 Name
="VCResourceCompilerTool"
437 Name
="VCPreLinkEventTool"
441 AdditionalDependencies
="$libs"
442 AdditionalOptions
="$lflags"
444 GenerateDebugInformation
="true"
447 OptimizeReferences
="2"
448 EnableCOMDATFolding
="2"
463 Name
="VCPostBuildEventTool"
470 Filter
="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
471 UniqueIdentifier
="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
484 </VisualStudioProject
>
489 sub createGlueProject
{
490 my ($git_dir, $out_dir, $rel_dir, %build_structure) = @_;
491 print "Generate solutions file\n";
492 $rel_dir = "..\\$rel_dir";
493 $rel_dir =~ s/\//\\/g
;
494 my $SLN_HEAD = "Microsoft Visual Studio Solution File, Format Version 10.00\n# Visual Studio 2008\n";
495 my $SLN_PRE = "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = ";
496 my $SLN_POST = "\nEndProject\n";
498 my @libs = @
{$build_structure{"LIBS"}};
507 my @apps = @
{$build_structure{"APPS"}};
520 open F
, ">git.sln" || die "Could not open git.sln for writing!\n";
524 my $uuid_libgit = $build_structure{"LIBS_libgit_GUID"};
525 my $uuid_xdiff_lib = $build_structure{"LIBS_xdiff_lib_GUID"};
528 my $uuid = $build_structure{"APPS_${appname}_GUID"};
530 print F
"\"${appname}\", \"${appname}\\${appname}.vcproj\", \"${uuid}\"\n";
531 print F
" ProjectSection(ProjectDependencies) = postProject\n";
532 print F
" ${uuid_libgit} = ${uuid_libgit}\n";
533 print F
" ${uuid_xdiff_lib} = ${uuid_xdiff_lib}\n";
534 print F
" EndProjectSection";
539 my $uuid = $build_structure{"LIBS_${libname}_GUID"};
541 print F
"\"${libname}\", \"${libname}\\${libname}.vcproj\", \"${uuid}\"";
547 GlobalSection
(SolutionConfigurationPlatforms
) = preSolution
548 Debug
|Win32
= Debug
|Win32
549 Release
|Win32
= Release
|Win32
553 GlobalSection
(ProjectConfigurationPlatforms
) = postSolution
557 my $uuid = $build_structure{"APPS_${appname}_GUID"};
558 print F
"\t\t${uuid}.Debug|Win32.ActiveCfg = Debug|Win32\n";
559 print F
"\t\t${uuid}.Debug|Win32.Build.0 = Debug|Win32\n";
560 print F
"\t\t${uuid}.Release|Win32.ActiveCfg = Release|Win32\n";
561 print F
"\t\t${uuid}.Release|Win32.Build.0 = Release|Win32\n";
565 my $uuid = $build_structure{"LIBS_${libname}_GUID"};
566 print F
"\t\t${uuid}.Debug|Win32.ActiveCfg = Debug|Win32\n";
567 print F
"\t\t${uuid}.Debug|Win32.Build.0 = Debug|Win32\n";
568 print F
"\t\t${uuid}.Release|Win32.ActiveCfg = Release|Win32\n";
569 print F
"\t\t${uuid}.Release|Win32.Build.0 = Release|Win32\n";