Skip to content

Dev #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

# custom
bin/
tmp/
gen_asm.s

# Visual Studio noise
Expand All @@ -56,4 +57,7 @@ gen_asm.s

# Allow our release libraries
!lib/**/*.lib
!lib/**/*.a
!lib/**/*.a

# vs code
.vscode/
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
23 changes: 23 additions & 0 deletions abiname.sh
Original file line number Diff line number Diff line change
@@ -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"
File renamed without changes.