make.sh refined

posix_api
YuQing 2022-02-02 09:32:07 +08:00
parent 3f20211a52
commit 21cd3a9798
1 changed files with 19 additions and 4 deletions

23
make.sh
View File

@ -1,3 +1,9 @@
GCC_VERSION=$(gcc -dM -E - < /dev/null | grep -w __GNUC__ | awk '{print $NF;}')
if [ -z "$GCC_VERSION" ]; then
echo -e "gcc not found, please install gcc first\n" 1>&2
exit 2
fi
tmp_src_filename=fast_check_bits.c tmp_src_filename=fast_check_bits.c
cat <<EOF > $tmp_src_filename cat <<EOF > $tmp_src_filename
#include <stdio.h> #include <stdio.h>
@ -12,12 +18,22 @@ int main()
EOF EOF
gcc -D_FILE_OFFSET_BITS=64 -o a.out $tmp_src_filename gcc -D_FILE_OFFSET_BITS=64 -o a.out $tmp_src_filename
output=`./a.out` output=$(./a.out)
if [ $? -ne 0 ]; then
echo -e "Can't find a.out program\n" 1>&2
exit 2
fi
if [ -f /bin/expr ]; then if [ -f /bin/expr ]; then
EXPR=/bin/expr EXPR=/bin/expr
else elif [ -f /usr/bin/expr ]; then
EXPR=/usr/bin/expr EXPR=/usr/bin/expr
else
EXPR=$(which expr)
if [ $? -ne 0 ]; then
echo -e "Can't find expr program\n" 1>&2
exit 2
fi
fi fi
count=0 count=0
@ -32,7 +48,7 @@ for col in $output; do
off_bytes=$col off_bytes=$col
fi fi
count=`$EXPR $count + 1` count=$($EXPR $count + 1)
done done
/bin/rm -f a.out $tmp_src_filename /bin/rm -f a.out $tmp_src_filename
@ -56,7 +72,6 @@ DEBUG_FLAG=0
export CC=gcc export CC=gcc
CFLAGS='-Wall' CFLAGS='-Wall'
GCC_VERSION=$(gcc -dM -E - < /dev/null | grep -w __GNUC__ | awk '{print $NF;}')
if [ -n "$GCC_VERSION" ] && [ $GCC_VERSION -ge 7 ]; then if [ -n "$GCC_VERSION" ] && [ $GCC_VERSION -ge 7 ]; then
CFLAGS="$CFLAGS -Wformat-truncation=0 -Wformat-overflow=0" CFLAGS="$CFLAGS -Wformat-truncation=0 -Wformat-overflow=0"
fi fi