Mercurial > hg > openttd
changeset 7564:0f45d5223c87 draft
(svn r11089) -Codechange: add revision detection to MSVC.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Wed, 12 Sep 2007 07:11:48 +0000 (2007-09-12) |
parents | 417e3ca82c7d |
children | a65f68a1c928 |
files | Makefile.src.in config.lib projects/determineversion.vbs projects/openttd.vcproj projects/openttd.vcproj.in projects/openttd_vs80.vcproj projects/openttd_vs80.vcproj.in source.list src/network/network.cpp src/network/network.h src/ottdres.rc src/ottdres.rc.in src/rev.cpp.in |
diffstat | 13 files changed, 287 insertions(+), 142 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile.src.in +++ b/Makefile.src.in @@ -249,15 +249,15 @@ $(BIN_DIR)/$(TTD): $(TTD) $(Q)cp $< $@ -$(TTD): rev.o $(OBJS) $(CONFIG_CACHE_LINKER) +$(TTD): $(OBJS) $(CONFIG_CACHE_LINKER) $(E) '$(STAGE) Linking $@' ifeq ($(OS), PSP) # Because of a bug in the PSP GCC tools, linking via CXX results # in total chaos and more problems then you can handle. So we need # CC to link OpenTTD for PSP - $(Q)$(CC_HOST) $(LDFLAGS) rev.o $(OBJS) $(LIBS) -o $@ + $(Q)$(CC_HOST) $(LDFLAGS) $(OBJS) $(LIBS) -o $@ else - $(Q)$(CXX_HOST) $(LDFLAGS) rev.o $(OBJS) $(LIBS) -o $@ + $(Q)$(CXX_HOST) $(LDFLAGS) $(OBJS) $(LIBS) -o $@ endif ifdef STRIP $(Q)$(STRIP) $@ @@ -275,19 +275,11 @@ # Revision files -rev.cpp: $(CONFIG_CACHE_VERSION) -# setting the revision number in a place, there the binary can read it - @echo 'extern const char _openttd_revision[] = "$(REV)";' > rev.cpp -# Some additions for MorphOS versions tag -ifeq ($(OS),MORPHOS) - @echo '#ifdef __MORPHOS__' >> rev.cpp - @echo 'extern const char morphos_versions_tag[] = "\\0$$VER: OpenTTD $(REV) ('`date +%d.%m.%y`') (C) OpenTTD Team [MorphOS, PowerPC]";' >> rev.cpp - @echo '#endif' >> rev.cpp -endif +$(SRC_DIR)/rev.cpp: $(CONFIG_CACHE_VERSION) $(SRC_DIR)/rev.cpp.in + $(Q)cat $(SRC_DIR)/rev.cpp.in | sed "s#@@VERSION@@#$(REV)#g;s#@@DATE@@#`date +%d.%m.%y`#g" > $(SRC_DIR)/rev.cpp -rev.o: rev.cpp $(FILE_DEP) - $(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.cpp=%.cpp)' - $(Q)$(CXX_HOST) $(CFLAGS) -c -o $@ $< +$(SRC_DIR)/ottdres.rc: $(CONFIG_CACHE_VERSION) $(SRC_DIR)/ottdres.rc.in + $(Q)cat $(SRC_DIR)/ottdres.rc.in | sed "s#@@VERSION@@#$(REV)#g;s#@@DATE@@#`date +%d.%m.%y`#g" > $(SRC_DIR)/ottdres.rc FORCE: @@ -295,10 +287,10 @@ clean: $(E) '$(STAGE) Cleaning up object files' - $(Q)rm -f $(DEPS) $(OBJS) $(TTD) $(TTD:%=$(BIN_DIR)/%) $(CONFIG_CACHE_COMPILER) $(CONFIG_CACHE_LINKER) $(CONFIG_CACHE_ENDIAN) $(CONFIG_CACHE_SOURCE) $(ENDIAN_TARGETS) rev.o rev.cpp + $(Q)rm -f $(DEPS) $(OBJS) $(TTD) $(TTD:%=$(BIN_DIR)/%) $(CONFIG_CACHE_COMPILER) $(CONFIG_CACHE_LINKER) $(CONFIG_CACHE_ENDIAN) $(CONFIG_CACHE_SOURCE) $(ENDIAN_TARGETS) mrproper: clean - $(Q)rm -f rev.cpp + $(Q)rm -f $(SRC_DIR)/rev.cpp $(SRC_DIR)/ottdres.rc %.o: @echo '$(STAGE) No such source-file: $(@:%.o=%).[c|cpp|mm|rc]'
--- a/config.lib +++ b/config.lib @@ -745,7 +745,7 @@ # General CFlags for BUILD CFLAGS_BUILD="" # General CFlags for HOST - CFLAGS="$CFLAGS -D$os -DWITH_REV" + CFLAGS="$CFLAGS -D$os" # CFlags for HOST and C-Compiler CC_FLAGS="" # Libs to compile. In fact this is just LDFLAGS
new file mode 100644 --- /dev/null +++ b/projects/determineversion.vbs @@ -0,0 +1,129 @@ +Option Explicit + +Dim FSO +Set FSO = CreateObject("Scripting.FileSystemObject") + +Sub FindReplaceInFile(filename, to_find, replacement) + Dim file, data + Set file = FSO.OpenTextFile(filename, 1, 0, 0) + data = file.ReadAll + file.Close + data = Replace(data, to_find, replacement) + Set file = FSO.CreateTextFile(FileName, -1, 0) + file.Write data + file.Close +End Sub + +Sub UpdateFile(version, cur_date, filename) + FSO.CopyFile filename & ".in", filename + FindReplaceInFile filename, "@@VERSION@@", version + FindReplaceInFile filename, "@@DATE@@", cur_date +End Sub + +Sub UpdateFiles(version) + Dim cur_date + cur_date = DatePart("D", Date) & "." & DatePart("M", Date) & "." & DatePart("YYYY", Date) + UpdateFile version, cur_date, "../src/rev.cpp" + UpdateFile version, cur_date, "../src/ottdres.rc" +End Sub + +Function DetermineSVNVersion() + Dim WshShell, version, url, oExec + Set WshShell = CreateObject("WScript.Shell") + On Error Resume Next + + ' Try TortoiseSVN + ' Get the directory where TortoiseSVN (should) reside(s) + Dim sTortoise + sTortoise = WshShell.RegRead("HKLM\SOFTWARE\TortoiseSVN\Directory") + + Dim file + ' Write some "magic" to a temporary file so we can acquire the svn revision/state + Set file = FSO.CreateTextFile("tsvn_tmp", -1, 0) + file.WriteLine "$WCREV$$WCMODS?M:$" + file.WriteLine "$WCURL$" + file.Close + Set oExec = WshShell.Exec(sTortoise & "\bin\SubWCRev.exe ../src tsvn_tmp tsvn_tmp") + ' Wait till the application is finished ... + Do + OExec.StdOut.ReadLine() + Loop While Not OExec.StdOut.atEndOfStream + + Set file = FSO.OpenTextFile("tsvn_tmp", 1, 0, 0) + version = file.ReadLine + url = file.ReadLine + file.Close + + Set file = FSO.GetFile("tsvn_tmp") + file.Delete + + ' Looks like there is no TortoiseSVN installed either. Then we don't know it. + If InStr(version, "$") Then + ' Reset error and version + Err.Clear + version = "norev000" + ' Do we have subversion installed? Check immediatelly whether we've got a modified WC. + Set oExec = WshShell.Exec("svnversion ../src") + If Err.Number = 0 Then + Dim modified + If InStr(OExec.StdOut.ReadLine(), "M") Then + modified = "M" + Else + modified = "" + End If + + ' Set the environment to english + WshShell.Environment("PROCESS")("LANG") = "en" + + ' And use svn info to get the correct revision and branch information. + Set oExec = WshShell.Exec("svn info ../src") + If Err.Number = 0 Then + Dim line + Do + line = OExec.StdOut.ReadLine() + If InStr(line, "URL") Then + url = line + End If + If InStr(line, "Last Changed Rev") Then + version = Mid(line, 19) & modified + End If + Loop While Not OExec.StdOut.atEndOfStream + End If + End If + End If + + If version <> "norev000" Then + If InStr(url, "branches") Then + url = Mid(url, InStr(url, "branches") + 8) + url = Mid(url, 1, InStr(2, url, "/") - 1) + version = version & Replace(url, "/", "-") + End If + End If + + DetermineSVNVersion = version +End Function + +Function IsCachedVersion(version) + Dim cache_file, cached_version + cached_version = "" + Set cache_file = FSO.OpenTextFile("../config.cache.version", 1, True, 0) + If Not cache_file.atEndOfStream Then + cached_version = cache_file.ReadLine() + End If + cache_file.Close + + If version <> cached_version Then + Set cache_file = fso.CreateTextFile("../config.cache.version", True) + cache_file.WriteLine(version) + cache_file.Close + IsCachedVersion = False + Else + IsCachedVersion = True + End If +End Function + +Dim version +version = DetermineSVNVersion +If Not (IsCachedVersion(version) And FSO.FileExists("../src/rev.cpp") And FSO.FileExists("../src/ottdres.rc")) Then + UpdateFiles version +End If
--- a/projects/openttd.vcproj +++ b/projects/openttd.vcproj @@ -73,7 +73,9 @@ <Tool Name="VCPostBuildEventTool"/> <Tool - Name="VCPreBuildEventTool"/> + Name="VCPreBuildEventTool" + Description="Determining version number" + CommandLine="$(InputDir)/determineversion.vbs"/> <Tool Name="VCPreLinkEventTool"/> <Tool @@ -135,7 +137,9 @@ <Tool Name="VCPostBuildEventTool"/> <Tool - Name="VCPreBuildEventTool"/> + Name="VCPreBuildEventTool" + Description="Determining version number" + CommandLine="$(InputDir)/determineversion.vbs"/> <Tool Name="VCPreLinkEventTool"/> <Tool @@ -320,6 +324,9 @@ RelativePath=".\..\src\rail.cpp"> </File> <File + RelativePath=".\..\src\rev.cpp"> + </File> + <File RelativePath=".\..\src\saveload.cpp"> </File> <File
--- a/projects/openttd.vcproj.in +++ b/projects/openttd.vcproj.in @@ -73,7 +73,9 @@ <Tool Name="VCPostBuildEventTool"/> <Tool - Name="VCPreBuildEventTool"/> + Name="VCPreBuildEventTool" + Description="Determining version number" + CommandLine="$(InputDir)/determineversion.vbs"/> <Tool Name="VCPreLinkEventTool"/> <Tool @@ -135,7 +137,9 @@ <Tool Name="VCPostBuildEventTool"/> <Tool - Name="VCPreBuildEventTool"/> + Name="VCPreBuildEventTool" + Description="Determining version number" + CommandLine="$(InputDir)/determineversion.vbs"/> <Tool Name="VCPreLinkEventTool"/> <Tool
--- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -33,6 +33,8 @@ > <Tool Name="VCPreBuildEventTool" + Description="Determining version number" + CommandLine="$(InputDir)/determineversion.vbs" /> <Tool Name="VCCustomBuildTool" @@ -144,6 +146,8 @@ > <Tool Name="VCPreBuildEventTool" + Description="Determining version number" + CommandLine="$(InputDir)/determineversion.vbs" /> <Tool Name="VCCustomBuildTool" @@ -255,6 +259,8 @@ > <Tool Name="VCPreBuildEventTool" + Description="Determining version number" + CommandLine="$(InputDir)/determineversion.vbs" /> <Tool Name="VCCustomBuildTool" @@ -350,6 +356,8 @@ > <Tool Name="VCPreBuildEventTool" + Description="Determining version number" + CommandLine="$(InputDir)/determineversion.vbs" /> <Tool Name="VCCustomBuildTool" @@ -656,6 +664,10 @@ > </File> <File + RelativePath=".\..\src\rev.cpp" + > + </File> + <File RelativePath=".\..\src\saveload.cpp" > </File>
--- a/projects/openttd_vs80.vcproj.in +++ b/projects/openttd_vs80.vcproj.in @@ -33,6 +33,8 @@ > <Tool Name="VCPreBuildEventTool" + Description="Determining version number" + CommandLine="$(InputDir)/determineversion.vbs" /> <Tool Name="VCCustomBuildTool" @@ -144,6 +146,8 @@ > <Tool Name="VCPreBuildEventTool" + Description="Determining version number" + CommandLine="$(InputDir)/determineversion.vbs" /> <Tool Name="VCCustomBuildTool" @@ -255,6 +259,8 @@ > <Tool Name="VCPreBuildEventTool" + Description="Determining version number" + CommandLine="$(InputDir)/determineversion.vbs" /> <Tool Name="VCCustomBuildTool" @@ -350,6 +356,8 @@ > <Tool Name="VCPreBuildEventTool" + Description="Determining version number" + CommandLine="$(InputDir)/determineversion.vbs" /> <Tool Name="VCCustomBuildTool"
--- a/source.list +++ b/source.list @@ -57,6 +57,7 @@ players.cpp queue.cpp rail.cpp +rev.cpp saveload.cpp screenshot.cpp #if SDL
--- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -3,15 +3,7 @@ #include "../stdafx.h" #include "network_data.h" -#if defined(WITH_REV) - extern const char _openttd_revision[]; -#elif defined(WITH_REV_HACK) - #define WITH_REV - extern const char _openttd_revision[] = WITH_REV_HACK; -#else - extern const char _openttd_revision[] = NOREV_STRING; -#endif - +extern const char _openttd_revision[]; #ifdef ENABLE_NETWORK @@ -1463,8 +1455,6 @@ /** * Checks whether the given version string is compatible with our version. - * It'll check the first NETWORK_REVISION_LENGTH - 1 characters (-1 for '\0') - * against the current version and the NOREV_STRING. * @param other the version string to compare to */ bool IsNetworkCompatibleVersion(const char *other)
--- a/src/network/network.h +++ b/src/network/network.h @@ -3,8 +3,6 @@ #ifndef NETWORK_H #define NETWORK_H -#define NOREV_STRING "norev000" - #ifdef ENABLE_NETWORK #include "../player.h"
deleted file mode 100644 --- a/src/ottdres.rc +++ /dev/null @@ -1,107 +0,0 @@ -//Microsoft Developer Studio generated resource script. -// -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "resource.h" -#define APSTUDIO_HIDDEN_SYMBOLS -#include "windows.h" -#undef APSTUDIO_HIDDEN_SYMBOLS -#ifdef MSVC -#include "winres.h" -#else -#include "afxres.h" -#endif - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// Neutral (Default) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEUD) -#ifdef _WIN32 -LANGUAGE LANG_NEUTRAL, SUBLANG_DEFAULT -#pragma code_page(1252) -#endif //_WIN32 - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -100 ICON DISCARDABLE "../media/openttd.ico" -101 ICON DISCARDABLE "../media/mainicon.ico" - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -100 DIALOG DISCARDABLE 0, 0, 305, 77 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Fatal Application Failure" -FONT 8, "MS Sans Serif" -BEGIN - PUSHBUTTON "&Close",12,7,58,50,14 - PUSHBUTTON "&Submit report",14,81,58,68,14,WS_DISABLED - PUSHBUTTON "&Emergency save",13,155,58,68,14 - PUSHBUTTON "",15,243,58,55,14 - EDITTEXT 11,7,79,291,118,ES_MULTILINE | ES_READONLY | WS_VSCROLL | - WS_HSCROLL | NOT WS_TABSTOP - LTEXT "",10,36,7,262,43 - ICON 100,IDC_STATIC,9,9,20,20 -END - - -#ifndef _MAC -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 0,5,99,0 - PRODUCTVERSION 0,5,99,0 - FILEFLAGSMASK 0x3fL -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x1L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "000004b0" - BEGIN - VALUE "Comments", "This program is licensed under the GNU General Public License.\0" - VALUE "CompanyName", "OpenTTD Development Team\0" - VALUE "FileDescription", "OpenTTD\0" - VALUE "FileVersion", "Development Version\0" - VALUE "InternalName", "openttd\0" - VALUE "LegalCopyright", "Copyright � OpenTTD Developers 2002-2007. All Rights Reserved.\0" - VALUE "LegalTrademarks", "\0" - VALUE "OriginalFilename", "openttd.exe\0" - VALUE "PrivateBuild", "\0" - VALUE "ProductName", "OpenTTD\0" - VALUE "ProductVersion", "Development Version\0" - VALUE "SpecialBuild", "-\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0, 1200 - END -END - -#endif // !_MAC - -#endif // Neutral (Default) resources -/////////////////////////////////////////////////////////////////////////////
new file mode 100644 --- /dev/null +++ b/src/ottdres.rc.in @@ -0,0 +1,107 @@ +//Microsoft Developer Studio generated resource script. +// +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "resource.h" +#define APSTUDIO_HIDDEN_SYMBOLS +#include "windows.h" +#undef APSTUDIO_HIDDEN_SYMBOLS +#ifdef MSVC +#include "winres.h" +#else +#include "afxres.h" +#endif + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// Neutral (Default) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEUD) +#ifdef _WIN32 +LANGUAGE LANG_NEUTRAL, SUBLANG_DEFAULT +#pragma code_page(1252) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +100 ICON DISCARDABLE "../media/openttd.ico" +101 ICON DISCARDABLE "../media/mainicon.ico" + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +100 DIALOG DISCARDABLE 0, 0, 305, 77 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Fatal Application Failure" +FONT 8, "MS Sans Serif" +BEGIN + PUSHBUTTON "&Close",12,7,58,50,14 + PUSHBUTTON "&Submit report",14,81,58,68,14,WS_DISABLED + PUSHBUTTON "&Emergency save",13,155,58,68,14 + PUSHBUTTON "",15,243,58,55,14 + EDITTEXT 11,7,79,291,118,ES_MULTILINE | ES_READONLY | WS_VSCROLL | + WS_HSCROLL | NOT WS_TABSTOP + LTEXT "",10,36,7,262,43 + ICON 100,IDC_STATIC,9,9,20,20 +END + + +#ifndef _MAC +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 0,5,99,0 + PRODUCTVERSION 0,5,99,0 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "Comments", "This program is licensed under the GNU General Public License.\0" + VALUE "CompanyName", "OpenTTD Development Team\0" + VALUE "FileDescription", "OpenTTD\0" + VALUE "FileVersion", "Development @@VERSION@@\0" + VALUE "InternalName", "openttd\0" + VALUE "LegalCopyright", "Copyright � OpenTTD Developers 2002-2007. All Rights Reserved.\0" + VALUE "LegalTrademarks", "\0" + VALUE "OriginalFilename", "openttd.exe\0" + VALUE "PrivateBuild", "\0" + VALUE "ProductName", "OpenTTD\0" + VALUE "ProductVersion", "Development @@VERSION@@\0" + VALUE "SpecialBuild", "-\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1200 + END +END + +#endif // !_MAC + +#endif // Neutral (Default) resources +/////////////////////////////////////////////////////////////////////////////