2021-01-08 14:23:16 +03:00
|
|
|
CFLAGS ?= -g -O3 -Wall -Wextra -pedantic -Wno-unused-parameter
|
2020-12-26 03:32:21 +03:00
|
|
|
|
2021-01-08 14:23:16 +03:00
|
|
|
TARGET = kuroko
|
2021-01-21 03:11:55 +03:00
|
|
|
OBJS = $(patsubst %.c, %.o, $(filter-out src/module_% src/rline.c src/kuroko.c,$(sort $(wildcard src/*.c))))
|
|
|
|
MODULES = $(patsubst src/module_%.c, modules/%.so, $(sort $(wildcard src/module_*.c)))
|
2021-01-21 12:45:16 +03:00
|
|
|
HEADERS = $(wildcard src/*.h)
|
2020-12-31 09:48:39 +03:00
|
|
|
|
2021-01-08 14:23:16 +03:00
|
|
|
ifndef KRK_ENABLE_STATIC
|
2021-01-21 15:07:38 +03:00
|
|
|
CFLAGS += -fPIC
|
2021-01-19 06:38:52 +03:00
|
|
|
ifeq (,$(findstring mingw,$(CC)))
|
2021-01-21 15:07:38 +03:00
|
|
|
LDFLAGS += -Wl,-rpath -Wl,'$$ORIGIN' -L.
|
2021-01-19 06:38:52 +03:00
|
|
|
LDLIBS += -ldl -lkuroko
|
|
|
|
else
|
2021-01-19 17:28:26 +03:00
|
|
|
CFLAGS += -Wno-format
|
2021-01-19 06:38:52 +03:00
|
|
|
LDLIBS += libkuroko.so
|
|
|
|
endif
|
2020-12-31 09:48:39 +03:00
|
|
|
all: ${TARGET} ${MODULES}
|
2021-01-08 14:23:16 +03:00
|
|
|
KUROKO_LIBS = libkuroko.so
|
|
|
|
else
|
|
|
|
CFLAGS +=-DSTATIC_ONLY
|
|
|
|
LDFLAGS += -static
|
|
|
|
all: ${TARGET}
|
2021-01-21 03:11:55 +03:00
|
|
|
OBJS += src/kuroko.o
|
2021-01-08 14:23:16 +03:00
|
|
|
KUROKO_LIBS = ${OBJS}
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifndef KRK_DISABLE_RLINE
|
2021-01-21 03:11:55 +03:00
|
|
|
KUROKO_LIBS += src/rline.o
|
2021-01-08 14:23:16 +03:00
|
|
|
else
|
|
|
|
CFLAGS += -DNO_RLINE
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifndef KRK_DISABLE_DEBUG
|
|
|
|
CFLAGS += -DDEBUG
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifdef KRK_ENABLE_BUNDLE
|
|
|
|
MODULES =
|
2021-01-21 03:11:55 +03:00
|
|
|
KUROKO_LIBS += $(patsubst %.c,%.o,$(sort $(wildcard src/module_*.c)))
|
2021-01-08 14:23:16 +03:00
|
|
|
CFLAGS += -DBUNDLE_LIBS=1
|
2021-01-20 16:35:16 +03:00
|
|
|
LDLIBS += -lm
|
2021-01-08 14:23:16 +03:00
|
|
|
endif
|
|
|
|
|
|
|
|
.PHONY: help
|
|
|
|
|
|
|
|
help:
|
|
|
|
@echo "Configuration options available:"
|
|
|
|
@echo " KRK_DISABLE_RLINE=1 Do not build with the rich line editing library enabled."
|
|
|
|
@echo " KRK_DISABLE_DEBUG=1 Disable debugging features (might be faster)."
|
|
|
|
@echo " KRK_ENABLE_STATIC=1 Build a single static binary."
|
|
|
|
@echo " KRK_ENABLE_BUNDLE=1 Link C modules directly into the interpreter."
|
|
|
|
|
2021-01-21 03:11:55 +03:00
|
|
|
kuroko: src/kuroko.o ${KUROKO_LIBS}
|
|
|
|
${CC} ${CFLAGS} ${LDFLAGS} -o $@ src/kuroko.o ${KUROKO_LIBS} ${LDLIBS}
|
2020-12-31 09:48:39 +03:00
|
|
|
|
2021-01-21 12:45:16 +03:00
|
|
|
%.o: ${HEADERS}
|
2021-01-08 10:53:17 +03:00
|
|
|
|
2021-01-21 03:11:55 +03:00
|
|
|
modules/%.so: src/module_%.c libkuroko.so
|
2021-01-21 15:07:38 +03:00
|
|
|
${CC} ${CFLAGS} ${LDFLAGS} -shared -o $@ $< ${LDLIBS}
|
2020-12-26 03:32:21 +03:00
|
|
|
|
2021-01-21 03:11:55 +03:00
|
|
|
modules/math.so: src/module_math.c libkuroko.so
|
2021-01-21 15:07:38 +03:00
|
|
|
${CC} ${CFLAGS} ${LDFLAGS} -shared -o $@ $< -lm ${LDLIBS}
|
2021-01-16 04:18:19 +03:00
|
|
|
|
2021-01-02 08:51:01 +03:00
|
|
|
libkuroko.so: ${OBJS}
|
2021-01-21 15:07:38 +03:00
|
|
|
${CC} ${CFLAGS} ${LDFLAGS} -shared -o $@ ${OBJS}
|
2021-01-02 08:51:01 +03:00
|
|
|
|
2021-01-21 03:11:55 +03:00
|
|
|
src/builtins.c: src/builtins.krk
|
|
|
|
echo "const char krk_builtinsSrc[] = " > $@
|
|
|
|
cat $< | sed s'/\(.*\)/\"\0\\n\"/' >> $@
|
|
|
|
echo ";" >> $@
|
2020-12-29 12:04:02 +03:00
|
|
|
|
2020-12-26 03:32:21 +03:00
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
2021-01-21 03:11:55 +03:00
|
|
|
@rm -f ${OBJS} ${TARGET} ${MODULES} libkuroko.so src/*.o kuroko.exe
|
2020-12-26 03:32:21 +03:00
|
|
|
|
2021-01-21 12:45:16 +03:00
|
|
|
tags: $(wildcard src/*.c) $(wildcard src/*.h)
|
|
|
|
@ctags --c-kinds=+lx src/*.c src/*.h
|
2021-01-04 15:49:23 +03:00
|
|
|
|
|
|
|
.PHONY: test
|
|
|
|
|
|
|
|
test:
|
2021-01-08 10:40:43 +03:00
|
|
|
@for i in test/*.krk; do echo $$i; KUROKO_TEST_ENV=1 ./kuroko $$i > $$i.expect; done
|
2021-01-09 08:01:21 +03:00
|
|
|
@git diff --exit-code test/*.expect
|
2021-01-12 01:34:42 +03:00
|
|
|
|
|
|
|
stress-test:
|
|
|
|
@for i in test/*.krk; do echo $$i; KUROKO_TEST_ENV=1 valgrind ./kuroko -g $$i > $$i.expect; done
|
|
|
|
@git diff --exit-code test/*.expect
|