firasuke / cross / slibtool

Forked from cross/slibtool a month ago
Clone

Blame sysinfo/host/host.sh

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