Blame sysinfo/host/host.sh

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