summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.in9
-rw-r--r--config.project2
-rwxr-xr-xsysinfo/host/host.sh82
3 files changed, 90 insertions, 3 deletions
diff --git a/Makefile.in b/Makefile.in
index 26365b4..1a71ee7 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -71,10 +71,10 @@ include $(PROJECT_DIR)/project/overrides.mk
$(APP_SRCS:%.c=%.o): CFLAGS_STATIC = $(CFLAGS_APP)
-src/%.lo: $(PROJECT_DIR)/src/%.c $(ALL_HEADERS)
+src/%.lo: $(PROJECT_DIR)/src/%.c $(ALL_HEADERS) host.tag
$(CC) -c -o $@ $< $(CFLAGS_SHARED)
-src/%.o: $(PROJECT_DIR)/src/%.c $(ALL_HEADERS)
+src/%.o: $(PROJECT_DIR)/src/%.c $(ALL_HEADERS) host.tag
$(CC) -c -o $@ $< $(CFLAGS_STATIC)
$(LIB_DIR)/%$(OS_LIB_SUFFIX):
@@ -165,12 +165,17 @@ dirs.tag:
mkdir -p $(LIB_DIR)
touch dirs.tag
+host.tag: Makefile
+ $(SHELL) $(PROJECT_DIR)/sysinfo/host/host.sh --compiler="$(CC)" --cflags="$(CFLAGS)"
+ touch host.tag
+
distclean: clean
rm -f Makefile
clean:
rm -f tree.tag
rm -f dirs.tag
+ rm -f host.tag
rm -f $(SHARED_OBJS)
rm -f $(STATIC_OBJS)
rm -f $(APP_OBJS)
diff --git a/config.project b/config.project
index 133ed4f..8d3fd41 100644
--- a/config.project
+++ b/config.project
@@ -27,7 +27,7 @@ mb_default_shell=sh
# switches
mb_default_cflags_debug=
-mb_default_cflags_common="-I\$(PROJECT_DIR)/src/internal -I\$(PROJECT_DIR)/include"
+mb_default_cflags_common="-I\$(PROJECT_DIR)/src/internal -I\$(PROJECT_DIR)/include -Ibuild"
mb_default_cflags_cmdline=
mb_default_cflags_config=
mb_default_cflags_sysroot=
diff --git a/sysinfo/host/host.sh b/sysinfo/host/host.sh
new file mode 100755
index 0000000..50186e7
--- /dev/null
+++ b/sysinfo/host/host.sh
@@ -0,0 +1,82 @@
+#!/bin/sh
+
+error_msg()
+{
+ echo $@ >&2
+}
+
+host_test()
+{
+ mb_hdrdir=$(pwd)/build
+ mkdir -p $mb_hdrdir || exit 2
+
+ if [ x"$mb_compiler" = x ]; then
+ echo "config error: compiler not set."
+ exit 2
+ fi
+
+ "$mb_compiler" -dM -E - < /dev/null > /dev/null && return 0
+
+ error_msg "config error: invalid compiler."
+ exit 2
+}
+
+host_endian_h()
+{
+ mb_header='endian.h'
+ rm -f "$mb_hdrdir"/$mb_header
+
+ # portable
+ "$mb_compiler" $mb_cflags \
+ --include=$mb_header -E - < /dev/null > /dev/null 2>/dev/null \
+ && return 0
+
+ # non-portable
+ mb_hosthdr=
+
+ [ -z $mb_hosthdr ] && "$mb_compiler" $mb_cflags \
+ --include='sys/'$mb_header -E - < /dev/null > /dev/null 2>/dev/null \
+ && mb_hosthdr='sys/'$mb_header
+
+ [ -z $mb_hosthdr ] && "$mb_compiler" $mb_cflags \
+ --include='machine/'$mb_header -E - < /dev/null > /dev/null 2>/dev/null \
+ && mb_hosthdr='machine/'$mb_header
+
+ if [ x"$mb_hosthdr" = x ]; then
+ error_msg "config error: could not find an alternate <$mb_header>."
+ exit 2
+ fi
+
+ printf "#include <%s>\\n" $mb_hosthdr > "$mb_hdrdir"/$mb_header || exit 2
+}
+
+
+# one: args
+for arg ; do
+ case "$arg" in
+ --help) usage
+ ;;
+ --compiler=*)
+ mb_compiler=${arg#*=}
+ ;;
+ --cflags=*)
+ mb_cflags=${arg#*=}
+ ;;
+ *)
+ error_msg ${arg#}: "unsupported config argument."
+ exit 2
+ ;;
+ esac
+done
+
+
+# two: test
+host_test
+
+
+# three: headers
+host_endian_h
+
+
+# all done
+exit 0