2021-04-10 10:09:07 +03:00
|
|
|
CFLAGS ?= -g -O2 -Wall -Wextra -pedantic -Wno-unused-parameter
|
2020-12-26 03:32:21 +03:00
|
|
|
|
2021-03-22 03:22:39 +03:00
|
|
|
CFLAGS += -Isrc
|
2021-04-09 15:50:44 +03:00
|
|
|
LDFLAGS += -L.
|
2021-03-22 03:22:39 +03:00
|
|
|
|
2021-01-08 14:23:16 +03:00
|
|
|
TARGET = kuroko
|
2021-04-27 15:41:33 +03:00
|
|
|
OBJS = $(patsubst %.c, %.o, $(filter-out src/kuroko.c,$(sort $(wildcard src/*.c))))
|
2021-04-09 15:50:44 +03:00
|
|
|
SOOBJS = $(patsubst %.o, %.lo, $(OBJS))
|
2021-04-27 15:41:33 +03:00
|
|
|
MODULES = $(patsubst src/modules/module_%.c, modules/%.so, $(sort $(wildcard src/modules/module_*.c)))
|
2021-03-22 03:22:39 +03:00
|
|
|
HEADERS = $(wildcard src/kuroko/*.h)
|
2021-02-12 05:48:50 +03:00
|
|
|
TOOLS = $(patsubst tools/%.c, krk-%, $(sort $(wildcard tools/*.c)))
|
2021-03-24 14:53:02 +03:00
|
|
|
GENMODS = modules/codecs/sbencs.krk modules/codecs/dbdata.krk
|
2021-04-09 15:58:20 +03:00
|
|
|
BIN_OBJS = libkuroko.a
|
2021-02-09 12:51:09 +03:00
|
|
|
|
|
|
|
# These are used by the install target. We call the local kuroko to get the
|
|
|
|
# version string to use for the final library, so, uh, probably don't
|
|
|
|
# try to do that in a cross-compile environment...
|
2021-02-08 11:36:03 +03:00
|
|
|
VERSION = $(shell ./kuroko --version | sed 's/.* //')
|
|
|
|
SONAME = libkuroko-$(VERSION).so
|
|
|
|
KRKMODS = $(wildcard modules/*.krk modules/*/*.krk modules/*/*/*.krk)
|
2020-12-31 09:48:39 +03:00
|
|
|
|
2021-04-09 15:50:44 +03:00
|
|
|
all: ${TARGET} ${MODULES} ${TOOLS} ${GENMODS}
|
|
|
|
|
|
|
|
ifeq (,$(findstring mingw,$(CC)))
|
2021-04-10 14:02:34 +03:00
|
|
|
CFLAGS += -pthread
|
2021-04-09 15:50:44 +03:00
|
|
|
LDLIBS += -ldl -lpthread
|
|
|
|
BIN_FLAGS = -rdynamic
|
|
|
|
LIBRARY = libkuroko.so
|
|
|
|
ifeq (Darwin,$(shell uname -s))
|
|
|
|
MODLIBS += -undefined dynamic_lookup -DKRK_MEDIOCRE_TLS
|
2021-02-08 11:36:03 +03:00
|
|
|
endif
|
2021-01-19 06:38:52 +03:00
|
|
|
else
|
2021-04-10 14:02:34 +03:00
|
|
|
CFLAGS += -Wno-format -static-libgcc -pthread
|
2021-04-09 15:50:44 +03:00
|
|
|
${SOOBJS}: CFLAGS += -DKRKINLIB
|
|
|
|
BIN_OBJS =
|
|
|
|
LIBRARY = libkuroko.dll
|
|
|
|
kuroko: LDLIBS = -lkuroko
|
|
|
|
kuroko: ${LIBRARY}
|
|
|
|
MODLIBS += -lkuroko
|
|
|
|
modules/socket.so: MODLIBS += -lws2_32
|
2021-02-09 12:51:09 +03:00
|
|
|
endif
|
|
|
|
|
2021-04-09 15:50:44 +03:00
|
|
|
ifdef KRK_DISABLE_DOCS
|
2021-03-20 03:29:32 +03:00
|
|
|
CFLAGS += -DKRK_NO_DOCUMENTATION -Wno-unused-value
|
|
|
|
endif
|
|
|
|
|
2021-01-08 14:23:16 +03:00
|
|
|
ifndef KRK_DISABLE_RLINE
|
2021-04-09 15:50:44 +03:00
|
|
|
BIN_OBJS += src/vendor/rline.o
|
2021-01-08 14:23:16 +03:00
|
|
|
else
|
2021-02-08 11:36:03 +03:00
|
|
|
CFLAGS += -DNO_RLINE
|
2021-01-08 14:23:16 +03:00
|
|
|
endif
|
|
|
|
|
2021-04-12 06:05:35 +03:00
|
|
|
ifdef KRK_DISABLE_DEBUG
|
|
|
|
CFLAGS += -DKRK_DISABLE_DEBUG
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifdef KRK_DISABLE_THREADS
|
|
|
|
CFLAGS += -DKRK_DISABLE_THREADS
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifdef KRK_NO_DISASSEMBLY
|
|
|
|
CFLAGS += -DKRK_NO_DISASSEMBLY=1
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifdef KRK_NO_TRACING
|
|
|
|
CFLAGS += -DKRK_NO_TRACING=1
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifdef KRK_NO_SCAN_TRACING
|
|
|
|
CFLAGS += -DKRK_NO_SCAN_TRACING=1
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifdef KRK_NO_STRESS_GC
|
|
|
|
CFLAGS += -DKRK_NO_STRESS_GC=1
|
2021-01-08 14:23:16 +03:00
|
|
|
endif
|
|
|
|
|
|
|
|
.PHONY: help
|
|
|
|
|
|
|
|
help:
|
|
|
|
@echo "Configuration options available:"
|
2021-04-12 06:05:35 +03:00
|
|
|
@echo " KRK_NO_... Compile without support for debugging features..."
|
|
|
|
@echo " DISASSEMBLY=1 Do not enable disassembly at compile time."
|
|
|
|
@echo " TRACING=1 Do not enable runtime tracing."
|
|
|
|
@echo " SCAN_TRACING=1 Do not enable lexer debugging."
|
|
|
|
@echo " STRESS_GC=1 Do not enable eager GC stress testing."
|
|
|
|
@echo " KRK_DISABLE_THREADS=1 Disable threads on platforms that otherwise support them."
|
2021-01-08 14:23:16 +03:00
|
|
|
@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)."
|
2021-04-09 15:50:44 +03:00
|
|
|
@echo " KRK_DISABLE_DOCS=1 Do not include docstrings for builtins."
|
2021-02-12 05:48:50 +03:00
|
|
|
@echo ""
|
|
|
|
@echo "Available tools: ${TOOLS}"
|
2021-01-08 14:23:16 +03:00
|
|
|
|
2021-04-09 15:50:44 +03:00
|
|
|
kuroko: src/kuroko.c ${BIN_OBJS} ${HEADERS}
|
|
|
|
${CC} ${CFLAGS} ${LDFLAGS} ${BIN_FLAGS} -o $@ $< ${BIN_OBJS} ${LDLIBS}
|
|
|
|
|
|
|
|
krk-%: tools/%.c ${LIBRARY} ${HEADERS}
|
|
|
|
${CC} -Itools ${CFLAGS} ${LDFLAGS} -o $@ $< -lkuroko
|
|
|
|
|
|
|
|
libkuroko.so: ${SOOBJS} ${HEADERS}
|
|
|
|
${CC} ${CFLAGS} ${LDFLAGS} -fPIC -shared -o $@ ${SOOBJS} ${LDLIBS}
|
2020-12-31 09:48:39 +03:00
|
|
|
|
2021-04-25 05:25:24 +03:00
|
|
|
WINLIBS= -l:libwinpthread.a
|
|
|
|
libkuroko.dll: ${SOOBJS} ${HEADERS}
|
2021-04-09 15:50:44 +03:00
|
|
|
${CC} ${CFLAGS} ${LDFLAGS} -fPIC -shared -o $@ ${SOOBJS} ${WINLIBS} -Wl,--export-all-symbols,--out-implib,libkuroko.a
|
2021-02-12 05:48:50 +03:00
|
|
|
|
2021-04-09 15:50:44 +03:00
|
|
|
libkuroko.a: ${OBJS}
|
|
|
|
${AR} ${ARFLAGS} $@ ${OBJS}
|
2021-02-09 12:51:09 +03:00
|
|
|
|
2021-04-09 15:50:44 +03:00
|
|
|
%.o: %.c ${HEADERS}
|
|
|
|
${CC} ${CFLAGS} -c -o $@ $<
|
2021-01-08 10:53:17 +03:00
|
|
|
|
2021-04-09 15:50:44 +03:00
|
|
|
%.lo: %.c ${HEADERS}
|
|
|
|
${CC} ${CFLAGS} -fPIC -c -o $@ $<
|
2020-12-26 03:32:21 +03:00
|
|
|
|
2021-04-09 15:50:44 +03:00
|
|
|
modules/math.so: MODLIBS += -lm
|
2021-04-27 15:41:33 +03:00
|
|
|
modules/%.so: src/modules/module_%.c ${LIBRARY}
|
2021-04-09 15:50:44 +03:00
|
|
|
${CC} ${CFLAGS} ${LDFLAGS} -fPIC -shared -o $@ $< ${LDLIBS} ${MODLIBS}
|
2021-01-16 04:18:19 +03:00
|
|
|
|
2021-03-24 15:23:41 +03:00
|
|
|
modules/codecs/sbencs.krk: tools/codectools/gen_sbencs.krk tools/codectools/encodings.json tools/codectools/indexes.json | kuroko
|
2021-03-24 14:53:02 +03:00
|
|
|
./kuroko tools/codectools/gen_sbencs.krk
|
|
|
|
|
2021-03-24 15:23:41 +03:00
|
|
|
modules/codecs/dbdata.krk: tools/codectools/gen_dbdata.krk tools/codectools/encodings.json tools/codectools/indexes.json | kuroko
|
2021-03-24 14:53:02 +03:00
|
|
|
./kuroko tools/codectools/gen_dbdata.krk
|
|
|
|
|
2020-12-26 03:32:21 +03:00
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
2021-04-09 15:50:44 +03:00
|
|
|
-rm -f ${OBJS} ${SOOBJS} ${TARGET} ${MODULES}
|
|
|
|
-rm -f libkuroko.so libkuroko.a libkuroko.dll *.so.debug
|
|
|
|
-rm -f src/*.o src/*.lo src/vendor/*.o
|
|
|
|
-rm -f kuroko.exe ${TOOLS} $(patsubst %,%.exe,${TOOLS})
|
|
|
|
-rm -rf docs/html *.dSYM modules/*.dSYM
|
2020-12-26 03:32:21 +03:00
|
|
|
|
2021-01-21 12:45:16 +03:00
|
|
|
tags: $(wildcard src/*.c) $(wildcard src/*.h)
|
2021-03-24 14:49:20 +03:00
|
|
|
@ctags --c-kinds=+lx src/*.c src/*.h src/kuroko/*.h src/vendor/*.h
|
2021-01-04 15:49:23 +03:00
|
|
|
|
2021-02-09 12:51:09 +03:00
|
|
|
# Test targets run against all .krk files in the test/ directory, writing
|
|
|
|
# stdout to `.expect` files, and then comparing with `git`.
|
|
|
|
# To update the tests if changes are expected, run `make test` and commit the result.
|
2021-04-14 16:25:22 +03:00
|
|
|
.PHONY: test stress-test update-tests bench
|
2021-01-04 15:49:23 +03:00
|
|
|
test:
|
2021-02-23 08:01:55 +03:00
|
|
|
@for i in test/*.krk; do echo $$i; KUROKO_TEST_ENV=1 $(TESTWRAPPER) ./kuroko $$i > $$i.actual; diff $$i.expect $$i.actual || exit 1; rm $$i.actual; done
|
|
|
|
|
|
|
|
update-tests:
|
2021-02-09 12:51:09 +03:00
|
|
|
@for i in test/*.krk; do echo $$i; KUROKO_TEST_ENV=1 $(TESTWRAPPER) ./kuroko $$i > $$i.expect; done
|
2021-01-12 01:34:42 +03:00
|
|
|
|
2021-02-09 12:51:09 +03:00
|
|
|
# You can also set TESTWRAPPER to other things to run the tests in other tools.
|
2021-01-12 01:34:42 +03:00
|
|
|
stress-test:
|
2021-02-09 12:51:09 +03:00
|
|
|
$(MAKE) TESTWRAPPER='valgrind' test
|
2021-01-31 05:00:01 +03:00
|
|
|
|
2021-04-14 16:25:22 +03:00
|
|
|
bench:
|
|
|
|
@echo "Kuroko:"
|
|
|
|
@for i in bench/*.krk; do ./kuroko "$$i"; done
|
|
|
|
@echo "CPython:"
|
|
|
|
@for i in bench/*.py; do python3 "$$i"; done
|
2021-04-16 13:58:05 +03:00
|
|
|
@echo "Micropython:"
|
|
|
|
@for i in bench/*.py; do micropython -X heapsize=128M "$$i"; done
|
2021-04-14 16:25:22 +03:00
|
|
|
|
2021-02-24 05:22:18 +03:00
|
|
|
# Really should be up to you to set, not us...
|
|
|
|
multiarch ?= $(shell gcc -print-multiarch)
|
2021-02-08 11:36:03 +03:00
|
|
|
prefix ?= /usr/local
|
|
|
|
exec_prefix ?= $(prefix)
|
|
|
|
includedir ?= $(prefix)/include
|
|
|
|
bindir ?= $(exec_prefix)/bin
|
2021-02-24 05:22:18 +03:00
|
|
|
ifeq (/usr,$(prefix))
|
|
|
|
libdir ?= $(exec_prefix)/lib/$(multiarch)
|
|
|
|
else
|
|
|
|
libdir ?= $(exec_prefix)/lib
|
|
|
|
endif
|
2021-02-08 11:36:03 +03:00
|
|
|
INSTALL = install
|
|
|
|
INSTALL_PROGRAM=$(INSTALL)
|
|
|
|
INSTALL_DATA=$(INSTALL) -m 644
|
|
|
|
|
|
|
|
.PHONY: install
|
2021-03-24 14:53:02 +03:00
|
|
|
install: all libkuroko.so ${HEADERS} $(KRKMODS) $(MODULES)
|
2021-02-24 06:54:54 +03:00
|
|
|
@echo "Creating directories..."
|
2021-02-08 11:36:03 +03:00
|
|
|
$(INSTALL) -d $(DESTDIR)$(includedir)/kuroko
|
|
|
|
$(INSTALL) -d $(DESTDIR)$(bindir)
|
|
|
|
$(INSTALL) -d $(DESTDIR)$(libdir)
|
|
|
|
$(INSTALL) -d $(DESTDIR)$(bindir)/../lib/kuroko
|
|
|
|
$(INSTALL) -d $(DESTDIR)$(bindir)/../lib/kuroko/syntax
|
|
|
|
$(INSTALL) -d $(DESTDIR)$(bindir)/../lib/kuroko/foo/bar
|
2021-03-24 15:26:52 +03:00
|
|
|
$(INSTALL) -d $(DESTDIR)$(bindir)/../lib/kuroko/codecs
|
2021-02-24 06:54:54 +03:00
|
|
|
@echo "Installing programs..."
|
2021-02-08 11:36:03 +03:00
|
|
|
$(INSTALL_PROGRAM) kuroko $(DESTDIR)$(bindir)/kuroko
|
2021-02-24 06:54:54 +03:00
|
|
|
$(INSTALL_PROGRAM) $(TOOLS) $(DESTDIR)$(bindir)/
|
|
|
|
@echo "Installing libraries..."
|
2021-02-08 11:36:03 +03:00
|
|
|
$(INSTALL_PROGRAM) libkuroko.so $(DESTDIR)$(libdir)/$(SONAME)
|
|
|
|
ln -s -f $(SONAME) $(DESTDIR)$(libdir)/libkuroko.so
|
2021-04-09 15:50:44 +03:00
|
|
|
$(INSTALL_DATA) libkuroko.a $(DESTDIR)$(libdir)/
|
2021-02-24 06:54:54 +03:00
|
|
|
@echo "Installing source modules..."
|
2021-02-08 11:36:03 +03:00
|
|
|
$(INSTALL_DATA) modules/*.krk $(DESTDIR)$(bindir)/../lib/kuroko/
|
|
|
|
$(INSTALL_DATA) modules/foo/*.krk $(DESTDIR)$(bindir)/../lib/kuroko/foo/
|
|
|
|
$(INSTALL_DATA) modules/foo/bar/*.krk $(DESTDIR)$(bindir)/../lib/kuroko/foo/bar/
|
|
|
|
$(INSTALL_DATA) modules/syntax/*.krk $(DESTDIR)$(bindir)/../lib/kuroko/syntax/
|
2021-03-24 14:53:02 +03:00
|
|
|
$(INSTALL_DATA) modules/codecs/*.krk $(DESTDIR)$(bindir)/../lib/kuroko/codecs/
|
2021-02-08 11:36:03 +03:00
|
|
|
$(INSTALL_PROGRAM) $(MODULES) $(DESTDIR)$(bindir)/../lib/kuroko/
|
2021-02-24 06:54:54 +03:00
|
|
|
@echo "Installing headers..."
|
|
|
|
$(INSTALL_DATA) ${HEADERS} $(DESTDIR)$(includedir)/kuroko/
|
2021-02-24 05:22:18 +03:00
|
|
|
@echo "You may need to run 'ldconfig'."
|
2021-02-08 11:36:03 +03:00
|
|
|
|
|
|
|
install-strip: all
|
|
|
|
$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
|
|
|
|
|
2021-02-23 04:50:37 +03:00
|
|
|
LIBCMIN = $(shell readelf -a libkuroko.so kuroko krk-* modules/*.so | grep GLIBC_ | grep Version | sed s"/.*GLIBC_//" | sed s"/ .*//" | sort --version-sort | tail -1)
|
|
|
|
|
2021-02-09 12:51:09 +03:00
|
|
|
# The deb target piggybacks off the install target, creating a temporary DESTDIR
|
|
|
|
# to install into with 'prefix' as /usr, packages that with fpm, and removes DESTDIR
|
2021-01-31 05:00:01 +03:00
|
|
|
.PHONY: deb
|
|
|
|
deb: kuroko libkuroko.so
|
2021-02-08 11:36:03 +03:00
|
|
|
$(eval DESTDIR := $(shell mktemp -d))
|
|
|
|
$(MAKE) prefix=/usr DESTDIR='$(DESTDIR)' install-strip
|
|
|
|
fpm -s dir -C $(DESTDIR) -t deb \
|
|
|
|
-n "kuroko" \
|
|
|
|
-m "K. Lange <klange@toaruos.org>" \
|
|
|
|
--description "Bytecode-compiled interpreted dynamic programming language." \
|
|
|
|
--url "https://kuroko-lang.github.io/" \
|
2021-04-09 11:47:32 +03:00
|
|
|
--license "MIT" \
|
2021-02-08 11:36:03 +03:00
|
|
|
--category "devel" \
|
2021-02-23 04:50:37 +03:00
|
|
|
-d "libc6 (>= $(LIBCMIN))" \
|
2021-02-08 11:36:03 +03:00
|
|
|
--version $(VERSION) \
|
|
|
|
--iteration 0 \
|
|
|
|
--directories $(libdir)/kuroko
|
|
|
|
rm -r $(DESTDIR)
|
2021-02-20 08:10:36 +03:00
|
|
|
|
|
|
|
.PHONY: docs
|
|
|
|
docs: kuroko
|
|
|
|
./kuroko tools/gendoc.krk
|
|
|
|
doxygen docs/Doxyfile
|
2021-03-26 16:45:51 +03:00
|
|
|
|
2021-03-29 03:26:24 +03:00
|
|
|
.PHONY: deploy-docs
|
|
|
|
deploy-docs: docs
|
|
|
|
cp -r docs/html/* ../kuroko-lang.github.io/docs/
|
|
|
|
|
2021-03-26 16:45:51 +03:00
|
|
|
.PHONY: cloc
|
|
|
|
cloc:
|
|
|
|
cloc --read-lang-def docs/cloc.txt --vcs git
|