From 9a537aa53fe6eab92a499d2ed7012f9ce25e7bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sat, 26 Dec 2020 11:20:14 +0000 Subject: [PATCH 1/2] A dedicated script to find the abiname --- .gitignore | 6 +++++- Makefile | 4 ++-- abiname.sh | 23 +++++++++++++++++++++++ get_abi.c => src/abiname.c | 0 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100755 abiname.sh rename get_abi.c => src/abiname.c (100%) diff --git a/.gitignore b/.gitignore index 446be5a..8854428 100644 --- a/.gitignore +++ b/.gitignore @@ -53,6 +53,7 @@ dkms.conf # custom bin/ +tmp/ gen_asm.s # Visual Studio noise @@ -64,4 +65,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 93b0fef..5acd3e1 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ CFLAGS += $(NO_CET) CXXFLAGS += $(NO_CET) # run c preprocessor with any cflags to get cross compilation result, then run regular compile in native -ABI := $(shell mkdir -p bin; $(CC) -E $(CFLAGS) $(CPPFLAGS) -o bin/get_abi.c get_abi.c && $(CC) -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 @@ -34,7 +34,7 @@ lib: 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 From dd3c5689aa81040ebde9465f34c0363ce672f548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sat, 26 Dec 2020 11:44:20 +0000 Subject: [PATCH 2/2] create bin folder from Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f868f1e..e9b8e68 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ $(LIB)/libstackman.a: lib $(obj) .PHONY: lib clean lib: - mkdir -p $(LIB) + mkdir -p $(LIB) bin clean: rm -f src/*.o tests/*.o