File: create_buildinfo.sh

package info (click to toggle)
xorp 1.8.5-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 28,560 kB
  • ctags: 54,995
  • sloc: cpp: 397,204; sh: 17,490; ansic: 17,029; python: 7,643; lex: 1,632; yacc: 1,474; awk: 956; makefile: 251; perl: 217; sed: 33
file content (127 lines) | stat: -rwxr-xr-x 3,519 bytes parent folder | download | duplicates (3)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/sh

# This script auto-creates the build_info.cc file.
# Used by: scons ... enable_buildinfo=yes
# to compile some build information into xorp.
#
#
# Usage:  ./libxorp/create_buildinfo.sh

# If build_info.cc is newer than create_buildinfo.sh, and
# if the git tag hasn't changed, then do not re-create
# build_info.cc

# Uses sed, git, date, and uname commands, if available.
# git history is only available if compiled within a git tree.

cd libxorp

BINFO=build_info.cc

if [ -f $BINFO ]
    then
    if [ create_buildinfo.sh -ot $BINFO ]
	then
	if [ -f last_git_md5sum.txt ]
	    then
	    git log -1 --pretty=format:%h > tst_git_md5sum.txt
	    if diff -q last_git_md5sum.txt tst_git_md5sum.txt > /dev/null
		then
		# Files are the same, do nothing.
		echo "Not re-creating $BINFO file."
		cd -
		exit 0
	    else
		echo "Re-creating $BINFO: md5sums changed."
	    fi
	else
	    echo "Re-creating $BINFO: old md5sum doesn't exist."
	fi
    else
	echo "Re-creating $BINFO: builder script newer than build_info.cc"
    fi
else
    echo "Creating $BINFO: file doesn't exist yet."
fi

cat build_info.prefix > $BINFO
if uname -mrspn > /dev/null 2>&1
    then
    echo "const char* BuildInfo::getBuildMachine() { return \"`uname -mrspn`\"; }" >> $BINFO
else
    echo "Warning:  uname -mrspn does not function on this system."
    echo "const char* BuildInfo::getBuildMachine() { return \"Unknown\"; }" >> $BINFO
fi
echo "" >> $BINFO

echo "const char* BuildInfo::getBuilder() { return \"${USER}\"; }" >> $BINFO
echo "" >> $BINFO

if date > /dev/null 2>&1
    then
    echo "const char* BuildInfo::getBuildDate() { return \"`date`\"; }" >> $BINFO
else
    echo "Warning:  'date' does not function on this system."
    echo "const char* BuildInfo::getBuildDate() { return \"Unknown\"; }" >> $BINFO
fi
echo "" >> $BINFO

if date '+%F %H:%M' > /dev/null 2>&1
    then
    echo "const char* BuildInfo::getShortBuildDate() { return \"`date '+%F %H:%M'`\"; }" >> $BINFO
else
    echo "Warning:  date +%F %H:%M does not function on this system."
    echo "const char* BuildInfo::getShortBuildDate() { return \"Unknown\"; }" >> $BINFO
fi
echo "" >> $BINFO

if which sed > /dev/null 2>&1 && which git > /dev/null 2>&1
    then
    if [ -x `which sed`  ] && [ -x `which git` ]
	then
	if git log -1 > /dev/null 2>&1
	    then
	    cat >> "${BINFO}" << EOF
const char* BuildInfo::getGitLog() { return
`git log -3 --abbrev=8 --abbrev-commit --pretty=oneline | sed -e 's|\\\\|\\\\\\\\|g' -e 's|"|\\\\"|g' -e 's|\(.*\)|"\1\\\n"|'`; }

EOF
	else
	    echo "NOTE:  Not a git repository, no git history in build-info."
	    cat >> "${BINFO}" << EOF
const char* BuildInfo::getGitLog() { return "Cannot detect, not a git repository"; }

EOF
	fi
    else
	echo "NOTE:  No functional sed and/or git, no git history in build-info."
	cat >> "${BINFO}" << EOF
const char* BuildInfo::getGitLog() { return "Cannot detect, sed and/or git is not executable"; }

EOF
    fi
else
    echo "NOTE:  No sed and/or git, no git history in build-info."
    cat >> "${BINFO}" << EOF
const char* BuildInfo::getGitLog() { return "Cannot detect, sed and/or git is not available"; }

EOF
fi


echo "const char* BuildInfo::getGitVersion() { return " >> $BINFO
if which git > /dev/null 2>&1
    then
    if git log -1 > /dev/null 2>&1
	then
	git log -1 --pretty=format:%h > last_git_md5sum.txt
	echo "\"`git log -1 --pretty=format:%h`\"; }" >> $BINFO
    else
	echo "\"00000000\"; }" >> $BINFO
    fi
else
    echo "\"00000000\"; }" >> $BINFO
fi

cd -
exit 0