Skip to content

Commit

Permalink
fix: embed tinycc includes using tar
Browse files Browse the repository at this point in the history
will be extracted in the execution tmpdir on runtime
  • Loading branch information
jaromil committed Sep 29, 2024
1 parent 692aca4 commit 4a163c0
Show file tree
Hide file tree
Showing 5 changed files with 491 additions and 2 deletions.
3 changes: 3 additions & 0 deletions build/deps.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ src/embed-musl-libc.c:
src/embed-libtcc1.c:
sh build/embed-libtcc1.sh

src/embed-headers.c:
sh build/embed-headers.sh

lib/tinycc/libtcc.a:
cd lib/tinycc && ./configure ${tinycc_config} \
&& ${MAKE} libtcc.a libtcc1.a
Expand Down
19 changes: 19 additions & 0 deletions build/embed-headers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

includes=lib/tinycc/include
dst=src/embed-headers.c

tmptar=`mktemp`.tar
tar cf $tmptar ${includes}

command -v xxd > /dev/null || {
>&2 echo "Error not found: xxd binary not installed"
exit 1
}

echo "// ${includes}" > $dst
xxd -i $tmptar >> $dst
tmpvar=`echo $tmptar | sed 's/\//_/g; s/\./_/g'`
>&2 echo "$tmpvar"
sed -i 's/unsigned char '"$tmpvar"'/const unsigned char tinycc_headers/' $dst
sed -i 's/unsigned int '"$tmpvar"'/const unsigned int tinycc_headers_len/' $dst
5 changes: 3 additions & 2 deletions build/init.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ endif
cflags := ${CFLAGS} -Isrc -Ilib/tinycc
cflags += -fstack-protector-all -D_FORTIFY_SOURCE=2 -fno-strict-overflow

SOURCES := src/io.o src/file.o src/cflag.o \
src/cjit.o src/embed-libtcc1.o src/embed-musl-libc.o
SOURCES := src/io.o src/file.o src/cflag.o src/cjit.o \
src/embed-libtcc1.o src/embed-musl-libc.o src/embed-headers.o \
src/microtar.o

ldadd := lib/tinycc/libtcc.a

Expand Down
Loading

0 comments on commit 4a163c0

Please sign in to comment.