orbea / zippy / sofort

Forked from zippy/sofort 2 years ago
Clone

Blame sysinfo/host/host.sh

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