Generate version.c in MSVC project

This commit is contained in:
Thomas Bernard 2018-02-20 02:50:43 +01:00
parent ae03cdfc34
commit d1426c61c5
7 changed files with 148 additions and 4 deletions

View File

@ -0,0 +1,64 @@
' VBScript to retrieve GIT "revision" and generate version.c
' Copyright 2018 Thomas Bernard
Set WshShell = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
versionfile = "..\..\src\version.c"
On Error Resume Next
Function GetRevision()
GetRevision = "unknown"
Err.Clear
Set oExec = WshShell.Exec("git rev-list --count 1af8c74f53110e349d8f0d19b14599281913f71f..")
If Err.Number = 0 Then
' Wait till the application is finished ...
Do While oExec.Status = 0
Loop
If oExec.ExitCode = 0 Then
GetRevision = oExec.StdOut.ReadLine()
End If
End If
End Function
Function GetBranch()
GetBranch = "unknown"
Err.Clear
Set oExec = WshShell.Exec("git rev-parse --abbrev-ref HEAD")
If Err.Number = 0 Then
' Wait till the application is finished ...
Do While oExec.Status = 0
Loop
If oExec.ExitCode = 0 Then
GetBranch = oExec.StdOut.ReadLine()
End If
End If
End Function
GIT_REVISION = GetRevision()
GIT_BRANCH = GetBranch()
'Wscript.Echo "GIT_REVISION=" & GIT_REVISION & Chr(13) & Chr(10) & "GIT_BRANCH=" & GIT_BRANCH
revision = GIT_REVISION
If GIT_BRANCH <> "unknown" And GIT_BRANCH <> "master" Then
revision = revision & "-" & GIT_BRANCH
End If
'Wscript.Echo revision
NeedWrite = True
Err.Clear
Set f = FSO.OpenTextFile(versionfile, 1, False) ' 1 = Read
If Err.Number = 0 Then
line = f.ReadLine
i = InStr(line, Chr(34)) + 1
j = InStr(i, line, Chr(34))
oldrevision = Mid(line, i, j - i)
If revision = oldrevision Then
NeedWrite = False
End If
f.Close
End If
If NeedWrite Then
Set f = FSO.OpenTextFile(versionfile, 2, True) ' 2 = Write
f.WriteLine "char SVN_revision[]=" & Chr(34) & revision & Chr(34) & ";"
f.Close
End If

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{056D84A3-08C5-4A2A-A24B-D2E6D00D9552}</ProjectGuid>
<Keyword>MakeFileProj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<NMakeBuildCommandLine>generateversion.vbs</NMakeBuildCommandLine>
<NMakeOutput>..\..\src\version.c</NMakeOutput>
<NMakeCleanCommandLine>del ..\..\src\version.c</NMakeCleanCommandLine>
<NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<NMakeBuildCommandLine>generateversion.vbs</NMakeBuildCommandLine>
<NMakeOutput>..\..\src\version.c</NMakeOutput>
<NMakeCleanCommandLine>del ..\..\src\version.c</NMakeCleanCommandLine>
<NMakePreprocessorDefinitions>WIN32;NDEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
</PropertyGroup>
<ItemDefinitionGroup>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Fichiers sources">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Fichiers d%27en-tête">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Fichiers de ressources">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
</Project>

View File

@ -2,6 +2,11 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual C++ Express 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grafx2", "grafx2.vcxproj", "{2C23F950-9403-4871-848E-7E98BE9BD565}"
ProjectSection(ProjectDependencies) = postProject
{056D84A3-08C5-4A2A-A24B-D2E6D00D9552} = {056D84A3-08C5-4A2A-A24B-D2E6D00D9552}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "generateversion", "generateversion.vcxproj", "{056D84A3-08C5-4A2A-A24B-D2E6D00D9552}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -13,6 +18,10 @@ Global
{2C23F950-9403-4871-848E-7E98BE9BD565}.Debug|Win32.Build.0 = Debug|Win32
{2C23F950-9403-4871-848E-7E98BE9BD565}.Release|Win32.ActiveCfg = Release|Win32
{2C23F950-9403-4871-848E-7E98BE9BD565}.Release|Win32.Build.0 = Release|Win32
{056D84A3-08C5-4A2A-A24B-D2E6D00D9552}.Debug|Win32.ActiveCfg = Debug|Win32
{056D84A3-08C5-4A2A-A24B-D2E6D00D9552}.Debug|Win32.Build.0 = Debug|Win32
{056D84A3-08C5-4A2A-A24B-D2E6D00D9552}.Release|Win32.ActiveCfg = Release|Win32
{056D84A3-08C5-4A2A-A24B-D2E6D00D9552}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -194,6 +194,7 @@
<ClCompile Include="..\..\src\tiles.c" />
<ClCompile Include="..\..\src\transform.c" />
<ClCompile Include="..\..\src\unicode.c" />
<ClCompile Include="..\..\src\version.c" />
<ClCompile Include="..\..\src\windows.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -337,5 +337,8 @@
<ClCompile Include="..\..\src\unicode.c">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="..\..\src\version.c">
<Filter>Fichiers sources</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -63,10 +63,7 @@
#include "factory.h"
extern char Program_version[]; // generated in pversion.c
extern char SVN_revision[]; // generated in pversion.c
#ifdef _MSC_VER//TODO TEMP
#define SVN_revision "MSC_0000"
#endif
extern char SVN_revision[]; // generated in version.c
// Recherche un raccourci clavier:
word * Shortcut(word shortcut_number)