File: cpusupport.sh

package info (click to toggle)
scrypt 1.2.0%2Bgit.3.c1a9826-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 456 kB
  • ctags: 328
  • sloc: ansic: 3,307; sh: 391; makefile: 103
file content (48 lines) | stat: -rwxr-xr-x 1,349 bytes parent folder | download | duplicates (5)
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
# Should be sourced by `command -p sh path/to/cpusupport.sh "$PATH"` from
# within a Makefile.
if ! [ ${PATH} = "$1" ]; then
	echo "WARNING: POSIX violation: $SHELL's command -p resets \$PATH" 1>&2
	PATH=$1
fi
# Standard output should be written to cpusupport-config.h, which is both a
# C header file defining CPUSUPPORT_ARCH_FEATURE macros and sourceable sh
# code which sets CFLAGS_ARCH_FEATURE environment variables.
SRCDIR=`command -p dirname "$0"`

feature() {
	ARCH=$1
	FEATURE=$2
	shift 2;
	if ! [ -f ${SRCDIR}/cpusupport-$ARCH-$FEATURE.c ]; then
		return
	fi
	printf "Checking if compiler supports $ARCH $FEATURE feature..." 1>&2
	for CFLAG in "$@"; do
		if ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L ${CFLAG}	\
		    ${SRCDIR}/cpusupport-$ARCH-$FEATURE.c 2>/dev/null; then
			rm -f a.out
			break;
		fi
		CFLAG=NOTSUPPORTED;
	done
	case $CFLAG in
	NOTSUPPORTED)
		echo " no" 1>&2
		;;
	"")
		echo " yes" 1>&2
		echo "#define CPUSUPPORT_${ARCH}_${FEATURE} 1"
		;;
	*)
		echo " yes, via $CFLAG" 1>&2
		echo "#define CPUSUPPORT_${ARCH}_${FEATURE} 1"
		echo "#ifdef cpusupport_dummy"
		echo "export CFLAGS_${ARCH}_${FEATURE}=\"${CFLAG}\""
		echo "#endif"
		;;
	esac
}

feature X86 CPUID ""
feature X86 SSE2 "" "-msse2" "-msse2 -Wno-cast-align"
feature X86 AESNI "" "-maes" "-maes -Wno-cast-align" "-maes -Wno-missing-prototypes -Wno-cast-qual"