-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathversion.sh
More file actions
executable file
·39 lines (31 loc) · 987 Bytes
/
version.sh
File metadata and controls
executable file
·39 lines (31 loc) · 987 Bytes
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
#!/bin/sh
# Generate version information from git
GIT_SHA1="00000000"
GIT_DIRTY="0"
# Check if we're in a git repository
if command -v git >/dev/null 2>&1 && [ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1; then
# Get the short SHA1
GIT_SHA1=$(git rev-parse --short=8 HEAD 2>/dev/null || echo "00000000")
# Check if working directory is dirty
git diff-index --quiet HEAD -- 2>/dev/null
if [ $? -ne 0 ]; then
GIT_DIRTY="1"
else
GIT_DIRTY="0"
fi
fi
# Generate the header file
cat > version.h.tmp << EOF
/* This file is automatically generated by version.sh */
#ifndef MEMTIER_VERSION_H
#define MEMTIER_VERSION_H
#define MEMTIER_GIT_SHA1 "$GIT_SHA1"
#define MEMTIER_GIT_DIRTY "$GIT_DIRTY"
#endif /* MEMTIER_VERSION_H */
EOF
# Only update version.h if it changed (to avoid unnecessary recompilation)
if [ ! -f version.h ] || ! cmp -s version.h.tmp version.h; then
mv version.h.tmp version.h
else
rm -f version.h.tmp
fi