-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathgenbuild
executable file
·36 lines (29 loc) · 1.07 KB
/
genbuild
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
#!/bin/bash
# generate build.h
# Just git info ?
if [ "$1" = "--git" ]; then
branch=`git status | grep '^On branch' | sed -e 's/On branch //'`
hash=`git rev-parse --short HEAD`
echo "#define PACHI_GIT_BRANCH \"$branch\""
echo "#define PACHI_GIT_HASH \"$hash\""
exit 0
fi
[ -n "$CC" ] && [ -n "$CFLAGS" ] || exit 1
date=`date +"%b %e %Y"`
compiler=`$CC --version | head -1`
# Find out actual compile flags used
# Don't use `` backquotes here or there'll be surprises.
cc1=$( $CC $CFLAGS -E -v - </dev/null 2>&1 | grep cc1 | head -1 | tr -d '\\"' )
# Target: try -march first
if echo "$cc1" | grep -q "march="; then
target=`echo "$cc1" | sed -e 's/.*-march=\([^ ]*\).*/\1/' `
else # -mcpu then ?
target=`echo "$cc1" | grep 'mcpu=' | sed -e 's/.*-mcpu=\([^ ]*\).*/\1/' `
fi
# XXX clang
CFLAGS=$( echo "$CFLAGS" | tr -d '\\"' )
echo "#define PACHI_BUILD_DATE \"$date\""
echo "#define PACHI_BUILD_TARGET \"$target\""
echo "#define PACHI_CFLAGS \"$CFLAGS\""
echo "#define PACHI_COMPILER \"$compiler\""
echo "#define PACHI_CC1 \"$cc1\""