Blame sysinfo/host/host.sh

bd5bd5
#!/bin/sh
bd5bd5
bd5bd5
error_msg()
bd5bd5
{
bd5bd5
	echo $@ >&2
bd5bd5
}
bd5bd5
bd5bd5
host_test()
bd5bd5
{
bd5bd5
	mb_hdrdir=$(pwd)/build
bd5bd5
	mkdir -p $mb_hdrdir || exit 2
bd5bd5
bd5bd5
	if [ x"$mb_compiler" = x ]; then
bd5bd5
                echo "config error: compiler not set."
bd5bd5
		exit 2
bd5bd5
	fi
bd5bd5
8bc9e2
	$mb_compiler -dM -E - < /dev/null > /dev/null && return 0
bd5bd5
bd5bd5
	error_msg "config error: invalid compiler."
bd5bd5
	exit 2
bd5bd5
}
bd5bd5
bd5bd5
host_endian_h()
bd5bd5
{
bd5bd5
	mb_header='endian.h'
bd5bd5
	rm -f "$mb_hdrdir"/$mb_header
bd5bd5
bd5bd5
	# portable
92e39b
	printf "#include <$mb_header>" | $mb_compiler $mb_cflags \
92e39b
		-E - > /dev/null 2>/dev/null \
bd5bd5
		&& return 0
bd5bd5
bd5bd5
	# non-portable
bd5bd5
	mb_hosthdr=
bd5bd5
92e39b
	[ -z $mb_hosthdr ] && printf "#include <sys/$mb_header>" | $mb_compiler $mb_cflags \
92e39b
		-E - > /dev/null 2>/dev/null \
bd5bd5
		&& mb_hosthdr='sys/'$mb_header
bd5bd5
92e39b
	[ -z $mb_hosthdr ] && printf "#include <machine/$mb_header>" | $mb_compiler $mb_cflags \
92e39b
		-E - > /dev/null 2>/dev/null \
bd5bd5
		&& mb_hosthdr='machine/'$mb_header
bd5bd5
bd5bd5
	if [ x"$mb_hosthdr" = x ]; then
bd5bd5
		error_msg "config error: could not find an alternate <$mb_header>."
bd5bd5
		exit 2
bd5bd5
	fi
bd5bd5
bd5bd5
	printf "#include <%s>\\n" $mb_hosthdr > "$mb_hdrdir"/$mb_header || exit 2
bd5bd5
}
bd5bd5
bd5bd5
bd5bd5
# one: args
bd5bd5
for arg ; do
bd5bd5
	case "$arg" in
bd5bd5
		--help)	usage
bd5bd5
			;;
bd5bd5
		--compiler=*)
bd5bd5
			mb_compiler=${arg#*=}
bd5bd5
			;;
bd5bd5
		--cflags=*)
bd5bd5
			mb_cflags=${arg#*=}
bd5bd5
			;;
bd5bd5
		*)
bd5bd5
			error_msg ${arg#}: "unsupported config argument."
bd5bd5
			exit 2
bd5bd5
			;;
bd5bd5
	esac
bd5bd5
done
bd5bd5
bd5bd5
bd5bd5
# two: test
bd5bd5
host_test
bd5bd5
bd5bd5
bd5bd5
# three: headers
bd5bd5
host_endian_h
bd5bd5
bd5bd5
bd5bd5
# all done
bd5bd5
exit 0