Blame sysinfo/host/host.sh

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