-
Notifications
You must be signed in to change notification settings - Fork 244
/
gen_git_version.cmd
68 lines (58 loc) · 2.08 KB
/
gen_git_version.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@echo off
rem
rem This file is part of Foreign Linux.
rem
rem Copyright (C) 2014, 2015 Xiangyan Sun <[email protected]>
rem
rem This program is free software: you can redistribute it and/or modify
rem it under the terms of the GNU General Public License as published by
rem the Free Software Foundation, either version 3 of the License, or
rem (at your option) any later version.
rem
rem This program is distributed in the hope that it will be useful,
rem but WITHOUT ANY WARRANTY; without even the implied warranty of
rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
rem GNU General Public License for more details.
rem
rem You should have received a copy of the GNU General Public License
rem along with this program. If not, see <http://www.gnu.org/licenses/>.
rem
setlocal ENABLEDELAYEDEXPANSION
set HEADER_FILE=%~p0\src\version.h
if not defined GIT (
set GIT="git"
)
call !GIT! describe --tags > NUL 2> NUL
if errorlevel 1 (
rem git not in path and GIT environment variable not set.
rem Try default msysgit installation location.
set GIT="%ProgramFiles(x86)%\Git\bin\git.exe"
call !GIT! describe --tags > NUL 2> NUL
if errorlevel 1 (
rem Potential x64 version...
rem Visual Studio runs in 32bit mode, so %ProgramFiles%
rem points to "Program Files (x86)" which won't work.
rem Therefore we use a hack here.
set GIT="%ProgramFiles%\..\Program Files\Git\bin\git.exe"
)
)
call !GIT! describe --tags > NUL 2> NUL
if errorlevel 1 (
echo Git not found. Cannot update version.h file.
echo Make sure git is in your path or set the GIT environment variable.
echo We will now build as an unknown verison.
set VERSION=unknown-version
) else (
for /F %%i in ('call !GIT! describe --tags') do set VERSION=%%i
)
rem Don't modify the header if it already contains the current version
if exist "%HEADER_FILE%" (
findstr /C:"%VERSION%" "%HEADER_FILE%" > NUL 2> NUL
if not errorlevel 1 (
goto done
)
)
rem Generate the header file
echo /* Automatically generated by gen_git_version.cmd, do not modify */ > "%HEADER_FILE%"
echo #define GIT_VERSION "%VERSION%" >> "%HEADER_FILE%"
:done