diff --git a/.gitignore b/.gitignore index 8af84ea..e9cdfd3 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,7 @@ # custom bin/ +tmp/ gen_asm.s # Visual Studio noise @@ -56,4 +57,7 @@ gen_asm.s # Allow our release libraries !lib/**/*.lib -!lib/**/*.a \ No newline at end of file +!lib/**/*.a + +# vs code +.vscode/ \ No newline at end of file diff --git a/Makefile b/Makefile index ada91bc..e9b8e68 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ LD = $(PLATFORM_PREFIX)ld AR = $(PLATFORM_PREFIX)ar endif # run c preprocessor with any cflags to get cross compilation result, then run regular compile in native -ABI := $(shell set -x; mkdir -p bin; $(CC) -E $(CFLAGS) $(CPPFLAGS) -o bin/get_abi.c get_abi.c && $(OLDCC) -o bin/get_abi bin/get_abi.c && bin/get_abi) +ABI := $(shell ./abiname.sh "$(CC)" "$(CFLAGS)") ifndef ABI $(error Could not determine platform) else @@ -37,11 +37,11 @@ $(LIB)/libstackman.a: lib $(obj) .PHONY: lib clean lib: - mkdir -p $(LIB) + mkdir -p $(LIB) bin clean: rm -f src/*.o tests/*.o - rm -f bin/* + rm -f bin/* tmp DEBUG = #-DDEBUG_DUMP diff --git a/abiname.sh b/abiname.sh new file mode 100755 index 0000000..8894471 --- /dev/null +++ b/abiname.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +# this script compiles and runs src/abiname.c which merely prints +# out the name of the abi. This can be used by makefiles to identify +# the correct library path to use to link the library +# Instead of just compiling and running, we will use the provided compiler +# and flags to just invoke the pre-processor. We then use the default +# compiler and linker to compile and link it. This ensures that the +# script works in cross-compilation environments and can actually +# run the provided code. +set -eu +here=$(dirname "$0") +mkdir -p "${here}/tmp" +tmp=$(mktemp "${here}/tmp/abinameXXX.c") + +#1 create the preprocessed file +CC=${1:-cc} +CFLAGS=${2:-} +${CC} ${CFLAGS} -E -I "${here}/src" -o "${tmp}" "${here}/src/abiname.c" +#2 compile resulting file +cc -o "${tmp}.out" "${tmp}" +#3 run it +"${tmp}.out" \ No newline at end of file diff --git a/get_abi.c b/src/abiname.c similarity index 100% rename from get_abi.c rename to src/abiname.c