From ec503314c3473a27e94551765073c6792a444876 Mon Sep 17 00:00:00 2001 From: Jaromil Date: Mon, 21 Oct 2024 08:41:19 +0200 Subject: [PATCH 1/5] CI test for macos builds --- .github/workflows/main.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7876675..b46344c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -94,6 +94,22 @@ jobs: run: | .\cjit.exe test\hello.c + osx-native-test: + name: 🍎 OSX native test + needs: [reuse, c-lint] + runs-on: "macos-latest" + steps: + - uses: actions/checkout@v4 + # - name: install dependencies + # run: | + # choco install --no-progress -r -y upx + - name: Build native Apple/OSX command executable + run: | + gmake osx + - name: Run tests + run: | + .\cjit.command test\hello.c + semantic-release: name: 🤖 Semantic release needs: [musl-test] From 655562325ed430423d3345fb6bc61c7b7a6fc4ac Mon Sep 17 00:00:00 2001 From: Jaromil Date: Sun, 20 Oct 2024 23:14:27 +0200 Subject: [PATCH 2/5] various fixes to build on osx some temporary fixes should be branched into compile time detection: gsed use or tinycc dynamic linked libs. --- GNUmakefile | 3 +++ build/embed-libtcc1.sh | 4 ++-- build/osx.mk | 24 ++++++++++++++++++++++++ lib/tinycc/Makefile | 6 +++--- src/kilo.c | 2 +- 5 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 build/osx.mk diff --git a/GNUmakefile b/GNUmakefile index 7adcf84..79245e2 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -30,6 +30,9 @@ linux-x86: ## 🐧 Build a dynamically linked cjit using libs found on Linux x86 win-wsl: ## 🪟 Build cjit.exe for WIN64 on an Ubuntu WSL VM using gcc-mingw-w64 $(MAKE) -f build/win-wsl.mk +osx: ## Build cjit.command for Apple/OSX using clang static + $(MAKE) -f build/osx.mk + _: ## ------: ## __ Debugging targets diff --git a/build/embed-libtcc1.sh b/build/embed-libtcc1.sh index d95258a..cae3e2a 100644 --- a/build/embed-libtcc1.sh +++ b/build/embed-libtcc1.sh @@ -15,5 +15,5 @@ command -v xxd > /dev/null || { echo "// $lib" > $dst xxd -i $lib >> $dst -sed -i 's/unsigned char lib_tinycc_libtcc1_a/const unsigned char libtcc1/' $dst -sed -i 's/unsigned int lib_tinycc_libtcc1_a_len/const unsigned int libtcc1_len/' $dst +gsed -i 's/unsigned char lib_tinycc_libtcc1_a/const unsigned char libtcc1/' $dst +gsed -i 's/unsigned int lib_tinycc_libtcc1_a_len/const unsigned int libtcc1_len/' $dst diff --git a/build/osx.mk b/build/osx.mk new file mode 100644 index 0000000..ccdb067 --- /dev/null +++ b/build/osx.mk @@ -0,0 +1,24 @@ +include build/init.mk + +cc := clang + + +cflags := -Wall -O3 +cflags += -Isrc -Ilib/tinycc +# cflags += -DLIBC_GNU -D_GNU_SOURCE + +ldadd+=lib/tinycc/libtcc.a + +all: deps cjit.command + +cjit.command: ${SOURCES} + $(cc) $(cflags) -o $@ $(SOURCES) ${ldflags} ${ldadd} + +deps: lib/tinycc/libtcc.a src/embed-libtcc1.c + +# tinycc_config += --with-libgcc +# tinycc_config += --enable-static --extra-cflags=-static --extra-ldflags=-static + + + +include build/deps.mk diff --git a/lib/tinycc/Makefile b/lib/tinycc/Makefile index 1c81ba1..487d9c9 100644 --- a/lib/tinycc/Makefile +++ b/lib/tinycc/Makefile @@ -40,12 +40,12 @@ ifdef CONFIG_WIN32 NATIVE_TARGET = $(ARCH)-win$(if $(findstring arm,$(ARCH)),ce,32) else CFG = -unx - LIBS+=-lm +# LIBS+=-lm ifneq ($(CONFIG_ldl),no) - LIBS+=-ldl +# LIBS+=-ldl endif ifneq ($(CONFIG_pthread),no) - LIBS+=-lpthread +# LIBS+=-lpthread endif # make libtcc as static or dynamic library? ifeq ($(CONFIG_static),no) diff --git a/src/kilo.c b/src/kilo.c index c0728a8..277262d 100644 --- a/src/kilo.c +++ b/src/kilo.c @@ -1364,6 +1364,7 @@ void editorMoveCursor(int key) { void editorProcessKeypress(int fd) { /* When the file is modified, requires Ctrl-q to be pressed N times * before actually quitting. */ + char ed_cmd[200]="/usr/bin/editor "; int c = editorReadKey(fd); switch(c) { case ENTER: /* Enter */ @@ -1383,7 +1384,6 @@ void editorProcessKeypress(int fd) { editorSave(); break; case CTRL_E: /* Ctrl-e */ - char ed_cmd[200]="/usr/bin/editor "; E.dirty++; editorSave(); strcat(ed_cmd, E.filename); From 8b929d52946c0c6f01457d0a5b73d0195c050da8 Mon Sep 17 00:00:00 2001 From: Jaromil Date: Mon, 21 Oct 2024 15:58:42 +0200 Subject: [PATCH 3/5] sed inplace invokation moved to makefiles --- .github/workflows/main.yml | 4 ++-- build/embed-headers.sh | 7 ++++--- build/embed-libtcc1.sh | 5 +++-- build/embed-musl-libc.sh | 5 +++-- build/musl.mk | 9 +++++++-- build/osx.mk | 6 +++++- build/win-native.mk | 4 ++++ 7 files changed, 28 insertions(+), 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b46344c..1191bba 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -105,10 +105,10 @@ jobs: # choco install --no-progress -r -y upx - name: Build native Apple/OSX command executable run: | - gmake osx + make osx - name: Run tests run: | - .\cjit.command test\hello.c + ./cjit.command test/hello.c semantic-release: name: 🤖 Semantic release diff --git a/build/embed-headers.sh b/build/embed-headers.sh index 2151934..47781b4 100644 --- a/build/embed-headers.sh +++ b/build/embed-headers.sh @@ -59,8 +59,9 @@ if [ "$1" = "win" ]; then } fi -sed -i 's/unsigned char/const char/' $dst -sed -i 's/unsigned int/const unsigned int/' $dst +sed_inplace() { if [[ "$OSTYPE" == "darwin"* ]]; then sed -i'' "$*"; else sed -i "$*"; fi } +sed_inplace -e 's/unsigned char/const char/' $dst +sed_inplace -e 's/unsigned int/const unsigned int/' $dst ([ "$1" = "code" ] || [ "$2" = "code" ]) && { >&2 echo "Externs to declare:" @@ -71,4 +72,4 @@ sed -i 's/unsigned int/const unsigned int/' $dst rm -f $externs $calls } ->&2 echo "Done generating src/embed-headers.c" \ No newline at end of file +>&2 echo "Done generating src/embed-headers.c" diff --git a/build/embed-libtcc1.sh b/build/embed-libtcc1.sh index cae3e2a..004ecee 100644 --- a/build/embed-libtcc1.sh +++ b/build/embed-libtcc1.sh @@ -15,5 +15,6 @@ command -v xxd > /dev/null || { echo "// $lib" > $dst xxd -i $lib >> $dst -gsed -i 's/unsigned char lib_tinycc_libtcc1_a/const unsigned char libtcc1/' $dst -gsed -i 's/unsigned int lib_tinycc_libtcc1_a_len/const unsigned int libtcc1_len/' $dst +# sed_inplace() { if [[ "$OSTYPE" == "darwin"* ]]; then sed -i'' "$*"; else sed -i w$*; fi } +# sed_inplace -e 's/unsigned char lib_tinycc_libtcc1_a/const unsigned char libtcc1/' $dst +# sed_inplace -e 's/unsigned int lib_tinycc_libtcc1_a_len/const unsigned int libtcc1_len/' $dst diff --git a/build/embed-musl-libc.sh b/build/embed-musl-libc.sh index 1e0af82..e1807cc 100644 --- a/build/embed-musl-libc.sh +++ b/build/embed-musl-libc.sh @@ -15,5 +15,6 @@ command -v xxd > /dev/null || { echo "// $lib" > $dst xxd -i $lib >> $dst -sed -i 's/unsigned char _lib_x86_64_linux_musl_libc_so/const unsigned char musl_libc/' $dst -sed -i 's/unsigned int _lib_x86_64_linux_musl_libc_so_len/const unsigned int musl_libc_len/' $dst +# sed_inplace() { if [[ "$OSTYPE" == "darwin"* ]]; then sed -i'' "$*"; else sed -i $*; fi } +# sed_inplace -e 's/unsigned char _lib_x86_64_linux_musl_libc_so/const unsigned char musl_libc/' $dst +# sed_inplace -e 's/unsigned int _lib_x86_64_linux_musl_libc_so_len/const unsigned int musl_libc_len/' $dst diff --git a/build/musl.mk b/build/musl.mk index f890845..376f2c4 100644 --- a/build/musl.mk +++ b/build/musl.mk @@ -1,7 +1,8 @@ +CC := musl-gcc + include build/init.mk -cc := musl-gcc -cflags := -Wall -static -Os +cflags := -Wall -static -O2 ${cflags_stack_protect} cflags += -Isrc -Ilib/tinycc -DLIBC_MUSL -nostdlib -DREPL_SUPPORTED ldadd := lib/tinycc/libtcc.a /usr/lib/x86_64-linux-musl/crt1.o /usr/lib/x86_64-linux-musl/libc.a @@ -14,6 +15,10 @@ cjit: ${SOURCES} $(cc) $(cflags) -o $@ $(SOURCES) ${ldadd} deps: lib/tinycc/libtcc.a src/embed-musl-libc.c src/embed-libtcc1.c + sed -i 's/unsigned char _lib_x86_64_linux_musl_libc_so/const unsigned char musl_libc/' src/embed-musl-libc.c + sed -i 's/unsigned int _lib_x86_64_linux_musl_libc_so_len/const unsigned int musl_libc_len/' src/embed-musl-libc.c + sed -i 's/unsigned char lib_tinycc_libtcc1_a/const unsigned char libtcc1/' src/embed-libtcc1.c + sed -i 's/unsigned int lib_tinycc_libtcc1_a_len/const unsigned int libtcc1_len/' src/embed-libtcc1.c tinycc_config += --config-musl --enable-static tynycc_config += --extra-cflags=-static --extra-ldflags=-static diff --git a/build/osx.mk b/build/osx.mk index ccdb067..0d8d617 100644 --- a/build/osx.mk +++ b/build/osx.mk @@ -7,7 +7,7 @@ cflags := -Wall -O3 cflags += -Isrc -Ilib/tinycc # cflags += -DLIBC_GNU -D_GNU_SOURCE -ldadd+=lib/tinycc/libtcc.a +ldadd += lib/tinycc/libtcc.a all: deps cjit.command @@ -15,6 +15,10 @@ cjit.command: ${SOURCES} $(cc) $(cflags) -o $@ $(SOURCES) ${ldflags} ${ldadd} deps: lib/tinycc/libtcc.a src/embed-libtcc1.c + sed -i'' -e 's/unsigned char lib_tinycc_libtcc1_a/const unsigned char libtcc1/' src/embed-libtcc1.c + sed -i'' -e 's/unsigned int lib_tinycc_libtcc1_a_len/const unsigned int libtcc1_len/' src/embed-libtcc1.c + +# src/embed-headers.c # tinycc_config += --with-libgcc # tinycc_config += --enable-static --extra-cflags=-static --extra-ldflags=-static diff --git a/build/win-native.mk b/build/win-native.mk index c7d55f0..5c6475c 100755 --- a/build/win-native.mk +++ b/build/win-native.mk @@ -37,7 +37,11 @@ cjit.exe: ${SOURCES} src/embed-libtcc1.c: $(info Embedding libtcc1: ${embed_libtcc1}) sh build/embed-libtcc1.sh ${embed_libtcc1} + sed -i 's/unsigned char lib_tinycc_libtcc1_a/const unsigned char libtcc1/' src/embed-libtcc1.c + sed -i 's/unsigned int lib_tinycc_libtcc1_a_len/const unsigned int libtcc1_len/' src/embed-libtcc1.c src/embed-headers.c: $(info Embedding tinycc headers) bash build/embed-headers.sh win + sed -i 's/unsigned char/const char/' src/embed-headers.c + sed -i 's/unsigned int/const unsigned int/' src/embed-headers.c From d3bcee60374e51c8b122871934683c88db682986 Mon Sep 17 00:00:00 2001 From: Jaromil Date: Mon, 21 Oct 2024 20:52:45 +0200 Subject: [PATCH 4/5] feat: add apple osx release binary --- .github/workflows/main.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1191bba..2327178 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -183,6 +183,22 @@ jobs: path: | cjit.exe + osx-native-test: + name: 🍎 OSX native test + needs: [semantic-release] + runs-on: "macos-latest" + steps: + - uses: actions/checkout@v4 + - name: Build native Apple/OSX command executable + run: | + make osx + - name: Upload artifact apple-osx + uses: actions/upload-artifact@v4 + with: + name: release-osx-native + path: | + cjit.command + draft-binary-release: name: 📦 Pack release needs: [semantic-release, musl-release, win-native-release] From 86c4ddaf2f3db840aa8a2cb23baf4bfb4c7fc85a Mon Sep 17 00:00:00 2001 From: Jaromil Date: Mon, 21 Oct 2024 21:02:43 +0200 Subject: [PATCH 5/5] fix: makefile cleanups --- .github/workflows/main.yml | 27 ++++++++------------------- GNUmakefile | 6 +++++- build/deps.mk | 10 ++++++++-- build/init.mk | 11 +++++------ build/linux.mk | 16 ++++++++-------- build/musl.mk | 21 +++++++-------------- build/osx.mk | 36 ++++++++++++++++++++++-------------- build/win-native.mk | 7 ++++--- build/win-wsl.mk | 35 ++++++++++++++++++++--------------- src/kilo.c | 4 ---- 10 files changed, 87 insertions(+), 86 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2327178..5c797f7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -85,11 +85,7 @@ jobs: # choco install --no-progress -r -y upx - name: Build native windows exe for x86_64 run: | - cd .\lib\tinycc - bash configure --targetos=WIN32 --config-backtrace=no - make libtcc.a libtcc1.a - cd ..\.. - make -f build/win-native.mk + make win-native - name: Run tests run: | .\cjit.exe test\hello.c @@ -105,7 +101,7 @@ jobs: # choco install --no-progress -r -y upx - name: Build native Apple/OSX command executable run: | - make osx + make apple-osx - name: Run tests run: | ./cjit.command test/hello.c @@ -147,10 +143,10 @@ jobs: build/release-intro.md - name: Install build deps run: | - sudo apt install -qy make musl-tools musl-dev gcc-mingw-w64 + sudo apt install -qy make musl-tools musl-dev - name: Build x86_64 with musl-system run: | - make musl-linux + make musl-linux RELEASE=1 - name: Upload artifact linux-amd64 uses: actions/upload-artifact@v4 with: @@ -166,16 +162,9 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 - # - name: install dependencies - # run: | - # choco install --no-progress -r -y upx - name: Build native windows exe for x86_64 run: | - cd .\lib\tinycc - bash configure --targetos=WIN32 --config-backtrace=no - make libtcc.a libtcc1.a - cd ..\.. - make -f build/win-native.mk + make win-native RELEASE=1 - name: Upload artifact windows-amd64 uses: actions/upload-artifact@v4 with: @@ -183,15 +172,15 @@ jobs: path: | cjit.exe - osx-native-test: - name: 🍎 OSX native test + osx-native-release: + name: 🍎 OSX native binary release build needs: [semantic-release] runs-on: "macos-latest" steps: - uses: actions/checkout@v4 - name: Build native Apple/OSX command executable run: | - make osx + make apple-osx RELEASE=1 - name: Upload artifact apple-osx uses: actions/upload-artifact@v4 with: diff --git a/GNUmakefile b/GNUmakefile index 79245e2..b34fff7 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -30,7 +30,11 @@ linux-x86: ## 🐧 Build a dynamically linked cjit using libs found on Linux x86 win-wsl: ## 🪟 Build cjit.exe for WIN64 on an Ubuntu WSL VM using gcc-mingw-w64 $(MAKE) -f build/win-wsl.mk -osx: ## Build cjit.command for Apple/OSX using clang static +win-native: ## 🪟 Build cjit.exe for WIN64 on Windows Server + cd ./lib/tinycc; bash configure --targetos=WIN32 --config-backtrace=no; make libtcc.a libtcc1.a + $(MAKE) -f build/win-native.mk + +apple-osx: ## 🍎 Build cjit.command for Apple/OSX using clang static $(MAKE) -f build/osx.mk _: ## diff --git a/build/deps.mk b/build/deps.mk index 331d51d..b5f617c 100644 --- a/build/deps.mk +++ b/build/deps.mk @@ -8,14 +8,20 @@ src/embed-musl-libc.c: bash build/embed-musl-libc.sh + sed -i 's/unsigned char _lib_x86_64_linux_musl_libc_so/const unsigned char musl_libc/' src/embed-musl-libc.c + sed -i 's/unsigned int _lib_x86_64_linux_musl_libc_so_len/const unsigned int musl_libc_len/' src/embed-musl-libc.c src/embed-libtcc1.c: - $(info Embedding libtcc1: ${embed_libtcc1}) - bash build/embed-libtcc1.sh ${embed_libtcc1} + $(info Embedding libtcc1: lib/tinycc/libtcc1.a) + bash build/embed-libtcc1.sh lib/tinycc/libtcc1.a + @sed -i 's/unsigned char lib_tinycc_libtcc1_a/const unsigned char libtcc1/' src/embed-libtcc1.c + @sed -i 's/unsigned int lib_tinycc_libtcc1_a_len/const unsigned int libtcc1_len/' src/embed-libtcc1.c src/embed-headers.c: $(info Embedding tinycc headers) bash build/embed-headers.sh + sed -i 's/unsigned char/const char/' src/embed-headers.c + sed -i 's/unsigned int/const unsigned int/' src/embed-headers.c lib/tinycc/libtcc.a: cd lib/tinycc && ./configure ${tinycc_config} diff --git a/build/init.mk b/build/init.mk index 7006fc4..724996e 100644 --- a/build/init.mk +++ b/build/init.mk @@ -13,22 +13,21 @@ endif CFLAGS ?= -Og -ggdb -DDEBUG=1 -Wall -Wextra +cflags_stack_protect := -fstack-protector-all -D_FORTIFY_SOURCE=2 -fno-strict-overflow + ifdef RELEASE - CFLAGS := -O2 -fomit-frame-pointer + CFLAGS := -O2 -fomit-frame-pointer ${cflags_stack_protect} endif cflags := ${CFLAGS} -Isrc -Ilib/tinycc -cflags_stack_protect := -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-headers.o src/kilo.o + src/embed-libtcc1.o src/embed-headers.o ldadd := lib/tinycc/libtcc.a -embed_libtcc1 := lib/tinycc/libtcc1.a - tinycc_config ?= --cc=${cc} --extra-cflags="${cflags}" --extra-ldflags="${ldflags}" + ifdef DEBUG tinycc_config += --debug endif diff --git a/build/linux.mk b/build/linux.mk index 6675c6a..3fc6b86 100644 --- a/build/linux.mk +++ b/build/linux.mk @@ -1,22 +1,22 @@ include build/init.mk cc := gcc + cflags += -DLIBC_GNU -D_GNU_SOURCE -DREPL_SUPPORTED -ldadd+=lib/tinycc/libtcc.a + +SOURCES += src/kilo.o ifdef ASAN - cflags += -O0 -ggdb -DDEBUG=1 -fno-omit-frame-pointer -fsanitize=address - ldflags += -fsanitize=address -static-libasan + cflags := -Og -ggdb -DDEBUG=1 -fno-omit-frame-pointer -fsanitize=address + ldflags := -fsanitize=address -static-libasan # tinycc_config += --extra-ldflags="${ldflags}" endif -all: deps cjit +tinycc_config += --with-libgcc + +all: lib/tinycc/libtcc.a cjit cjit: ${SOURCES} $(cc) $(cflags) -o $@ $(SOURCES) ${ldflags} ${ldadd} -deps: lib/tinycc/libtcc.a - -tinycc_config += --with-libgcc - include build/deps.mk diff --git a/build/musl.mk b/build/musl.mk index 376f2c4..25d2930 100644 --- a/build/musl.mk +++ b/build/musl.mk @@ -3,26 +3,19 @@ CC := musl-gcc include build/init.mk cflags := -Wall -static -O2 ${cflags_stack_protect} -cflags += -Isrc -Ilib/tinycc -DLIBC_MUSL -nostdlib -DREPL_SUPPORTED +cflags += -Isrc -Ilib/tinycc -DLIBC_MUSL -nostdlib +cflags += -DREPL_SUPPORTED ldadd := lib/tinycc/libtcc.a /usr/lib/x86_64-linux-musl/crt1.o /usr/lib/x86_64-linux-musl/libc.a -SOURCES += src/embed-musl-libc.o +SOURCES += src/embed-musl-libc.o src/kilo.o -all: deps cjit +tinycc_config += --config-musl --enable-static +tynycc_config += --extra-cflags=-static --extra-ldflags=-static + +all: lib/tinycc/libtcc.a cjit cjit: ${SOURCES} $(cc) $(cflags) -o $@ $(SOURCES) ${ldadd} -deps: lib/tinycc/libtcc.a src/embed-musl-libc.c src/embed-libtcc1.c - sed -i 's/unsigned char _lib_x86_64_linux_musl_libc_so/const unsigned char musl_libc/' src/embed-musl-libc.c - sed -i 's/unsigned int _lib_x86_64_linux_musl_libc_so_len/const unsigned int musl_libc_len/' src/embed-musl-libc.c - sed -i 's/unsigned char lib_tinycc_libtcc1_a/const unsigned char libtcc1/' src/embed-libtcc1.c - sed -i 's/unsigned int lib_tinycc_libtcc1_a_len/const unsigned int libtcc1_len/' src/embed-libtcc1.c - -tinycc_config += --config-musl --enable-static -tynycc_config += --extra-cflags=-static --extra-ldflags=-static -# check: -# ./cjit test/hello.c - include build/deps.mk diff --git a/build/osx.mk b/build/osx.mk index 0d8d617..79a74ad 100644 --- a/build/osx.mk +++ b/build/osx.mk @@ -2,27 +2,35 @@ include build/init.mk cc := clang - -cflags := -Wall -O3 -cflags += -Isrc -Ilib/tinycc -# cflags += -DLIBC_GNU -D_GNU_SOURCE - -ldadd += lib/tinycc/libtcc.a - all: deps cjit.command cjit.command: ${SOURCES} $(cc) $(cflags) -o $@ $(SOURCES) ${ldflags} ${ldadd} -deps: lib/tinycc/libtcc.a src/embed-libtcc1.c - sed -i'' -e 's/unsigned char lib_tinycc_libtcc1_a/const unsigned char libtcc1/' src/embed-libtcc1.c - sed -i'' -e 's/unsigned int lib_tinycc_libtcc1_a_len/const unsigned int libtcc1_len/' src/embed-libtcc1.c +.c.o: + $(cc) \ + $(cflags) \ + -c $< -o $@ \ + -DVERSION=\"${VERSION}\" \ + -DCURRENT_YEAR=\"${CURRENT_YEAR}\" -# src/embed-headers.c +deps: lib/tinycc/libtcc.a src/embed-libtcc1.c src/embed-headers.c -# tinycc_config += --with-libgcc -# tinycc_config += --enable-static --extra-cflags=-static --extra-ldflags=-static +## Custom deps targets for osx due to different sed +lib/tinycc/libtcc.a: + cd lib/tinycc && ./configure ${tinycc_config} + ${MAKE} -C lib/tinycc libtcc.a + ${MAKE} -C lib/tinycc libtcc1.a +src/embed-libtcc1.c: + $(info Embedding libtcc1) + sh build/embed-libtcc1.sh lib/tinycc/libtcc1.a$ + sed -i'' -e 's/unsigned char lib_tinycc_libtcc1_a/const unsigned char libtcc1/' src/embed-libtcc1.c + sed -i'' -e 's/unsigned int lib_tinycc_libtcc1_a_len/const unsigned int libtcc1_len/' src/embed-libtcc1.c -include build/deps.mk +src/embed-headers.c: + $(info Embedding tinycc headers) + bash build/embed-headers.sh win + sed -i'' -e 's/unsigned char/const char/' src/embed-headers.c + sed -i'' -e 's/unsigned int/const unsigned int/' src/embed-headers.c diff --git a/build/win-native.mk b/build/win-native.mk index 5c6475c..517c3a0 100755 --- a/build/win-native.mk +++ b/build/win-native.mk @@ -22,7 +22,8 @@ ldflags += -static-libgcc ldadd := lib/tinycc/libtcc.a -lshlwapi -# embed_libtcc1 := .\lib\tinycc\x86_64-win32-libtcc1.a +# The libtcc is built by the calling GNUmakefile +# to: lib/tinycc/libtcc.a cjit.exe: ${SOURCES} $(cc) $(cflags) -o $@ $(SOURCES) ${ldflags} ${ldadd} @@ -35,8 +36,8 @@ cjit.exe: ${SOURCES} -DCURRENT_YEAR=\"${CURRENT_YEAR}\" src/embed-libtcc1.c: - $(info Embedding libtcc1: ${embed_libtcc1}) - sh build/embed-libtcc1.sh ${embed_libtcc1} + $(info Embedding libtcc1) + sh build/embed-libtcc1.sh lib/tinycc/libtcc1.a sed -i 's/unsigned char lib_tinycc_libtcc1_a/const unsigned char libtcc1/' src/embed-libtcc1.c sed -i 's/unsigned int lib_tinycc_libtcc1_a_len/const unsigned int libtcc1_len/' src/embed-libtcc1.c diff --git a/build/win-wsl.mk b/build/win-wsl.mk index db93e09..9753091 100644 --- a/build/win-wsl.mk +++ b/build/win-wsl.mk @@ -13,7 +13,8 @@ ldadd += -lrpcrt4 -lshlwapi ldflags += -static-libgcc -# embed_libtcc1 := lib/tinycc/x86_64-win32-libtcc1.a +tinycc_config += --targetos=WIN32 --config-backtrace=no --enable-cross +tinycc_config += --ar=${ar} all: deps cjit.exe @@ -21,18 +22,22 @@ cjit.exe: ${SOURCES} ./build/stamp-exe.sh $(cc) $(cflags) -o $@ $(SOURCES) cjit.res ${ldflags} ${ldadd} -# upx-ucl -q $@ -# somehow upx compression helps the binary to function: it -# accidentally fixes some headers that are malformed out of mingw - -tinycc_config += --targetos=WIN32 --config-backtrace=no --enable-cross -tinycc_config += --ar=${ar} - deps: - cd lib/tinycc && ./configure ${tinycc_config} - $(MAKE) -C lib/tinycc cross-x86_64-win32 - ${MAKE} -C lib/tinycc libtcc.a - ${MAKE} -C lib/tinycc libtcc1.a - mv lib/tinycc/x86_64-win32-libtcc1.a lib/tinycc/libtcc1.a - -include build/deps.mk + @cd lib/tinycc && ./configure ${tinycc_config} + @$(MAKE) -C lib/tinycc cross-x86_64-win32 + @${MAKE} -C lib/tinycc libtcc.a + @${MAKE} -C lib/tinycc libtcc1.a + @mv lib/tinycc/x86_64-win32-libtcc1.a lib/tinycc/libtcc1.a + @bash build/embed-libtcc1.sh lib/tinycc/libtcc1.a + @sed -i 's/unsigned char lib_tinycc_libtcc1_a/const unsigned char libtcc1/' src/embed-libtcc1.c + @sed -i 's/unsigned int lib_tinycc_libtcc1_a_len/const unsigned int libtcc1_len/' src/embed-libtcc1.c + @bash build/embed-headers.sh win + @sed -i 's/unsigned char/const char/' src/embed-headers.c + @sed -i 's/unsigned int/const unsigned int/' src/embed-headers.c + +.c.o: + $(cc) \ + $(cflags) \ + -c $< -o $@ \ + -DVERSION=\"${VERSION}\" \ + -DCURRENT_YEAR=\"${CURRENT_YEAR}\" diff --git a/src/kilo.c b/src/kilo.c index 277262d..2cd7037 100644 --- a/src/kilo.c +++ b/src/kilo.c @@ -31,8 +31,6 @@ * */ - -#ifdef REPL_SUPPORTED #ifdef __linux__ #define _POSIX_C_SOURCE 200809L #endif @@ -1494,5 +1492,3 @@ void editorSetCheckCallback(int (*cb)(void *ctx, const char *code, char **err_ms void editorSetCompilerContext(void *ctx) { E.compiler_cb_ctx = ctx; } - -#endif //REPL_SUPPORTED