Skip to content

Commit

Permalink
build.sh: deduplicate cc -dM -E output and automate __BLST_NO_ASM__.
Browse files Browse the repository at this point in the history
  • Loading branch information
dot-asm committed Dec 10, 2023
1 parent 4e136da commit b555988
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ if [ "x$CROSS_COMPILE" = "x" ]; then
else { print $1 } }'`
fi

if [ -z "${CROSS_COMPILE}${AR}" ] && \
(${CC} -dM -E -x c /dev/null) 2>/dev/null | grep -q clang; then
predefs=`(${CC} ${CFLAGS} -dM -E -x c /dev/null || true) 2>/dev/null`

if [ -z "${CROSS_COMPILE}${AR}" ] && echo ${predefs} | grep -q clang; then
search_dirs=`${CC} -print-search-dirs | awk -F= '/^programs:/{print$2}' | \
(sed -E -e 's/([a-z]):\\\/\/\1\//gi' -e 'y/\\\;/\/:/' 2>/dev/null || true)`
if [ -n "$search_dirs" ] && \
Expand All @@ -79,14 +80,17 @@ if [ -z "${CROSS_COMPILE}${AR}" ] && \
fi
AR=${AR:-${CROSS_COMPILE}ar}

if (${CC} ${CFLAGS} -dM -E -x c /dev/null) 2>/dev/null | grep -q x86_64; then
if echo ${predefs} | grep -q x86_64; then
if (grep -q -e '^flags.*\badx\b' /proc/cpuinfo) 2>/dev/null; then
cflags="-D__ADX__ $cflags"
fi
fi
if (${CC} ${CFLAGS} -dM -E -x c /dev/null) 2>/dev/null | grep -q __AVX__; then
if echo ${predefs} | grep -q __AVX__; then
cflags="$cflags -mno-avx" # avoid costly transitions
fi
if echo ${predefs} | grep -q 'x86_64\|aarch64'; then :; else
cflags="$cflags -D__BLST_NO_ASM__"
fi

CFLAGS="$CFLAGS $cflags"
TMPDIR=${TMPDIR:-/tmp}
Expand Down

0 comments on commit b555988

Please sign in to comment.