-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_version.sh
46 lines (41 loc) · 1.63 KB
/
build_version.sh
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
GIT_BRANCH=`git branch | grep "*" | sed 's/\*//'`
LOG_VERSION=`git log -1 | grep commit | awk '{print $2}'`
AUTHOR=`git config user.email`
GIT_URL=`git remote -v | grep push | head -n 1 |awk '{print $2}'`
BUILD_DATE=`date`
BUILD_HOSTNAME=`hostname`
GCC_VERSION=`gcc --version | head -n 1`
KERNEL=`uname -r | head -n 1`
build_header () {
echo "#include <iostream>"
echo "#include <string>"
echo ""
}
build_var () {
echo ""
echo "static const std::string GIT_BRANCH=\"$GIT_BRANCH\"; "
echo "static const std::string LOG_VERSION=\"$LOG_VERSION\"; "
echo "static const std::string AUTHOR=\"$AUTHOR\"; "
echo "static const std::string GIT_URL=\"$GIT_URL\"; "
echo "static const std::string BUILD_DATE=\"$BUILD_DATE\"; "
echo "static const std::string BUILD_HOSTNAME=\"$BUILD_HOSTNAME\"; "
echo "static const std::string GCC_VERSION=\"$GCC_VERSION\"; "
echo "static const std::string KERNEL=\"$KERNEL\"; "
echo ""
}
build_print_func () {
echo "void PrintVersion() {"
echo " std::cout << \"Author:\" << AUTHOR << std::endl;"
echo " std::cout << \"Git:\" << GIT_URL << std::endl;"
echo " std::cout << \"Branch:\" << GIT_BRANCH << std::endl;"
echo " std::cout << \"Date:\" << BUILD_DATE << std::endl;"
echo " std::cout << \"Version:\" << LOG_VERSION << std::endl;"
echo " std::cout << \"Host:\" << BUILD_HOSTNAME << std::endl;"
echo " std::cout << \"Gcc:\" << GCC_VERSION << std::endl;"
echo " std::cout << \"Kernel:\" << KERNEL<< std::endl;"
echo "}"
}
test -e kernel/src/version.h && rm kernel/src/version.h
build_header > kernel/src/version.h
build_var >> kernel/src/version.h
build_print_func >> kernel/src/version.h