2019-01-24 05:26:57 +00:00
|
|
|
# Copyright (c) 2019 Calvin Rose
|
2018-12-08 19:17:03 +00:00
|
|
|
#
|
2018-03-18 18:03:26 +00:00
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to
|
|
|
|
# deal in the Software without restriction, including without limitation the
|
|
|
|
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
# sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
2018-12-08 19:17:03 +00:00
|
|
|
#
|
2018-03-18 18:03:26 +00:00
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
# all copies or substantial portions of the Software.
|
2018-12-08 19:17:03 +00:00
|
|
|
#
|
2018-03-18 18:03:26 +00:00
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
# IN THE SOFTWARE.
|
|
|
|
|
|
|
|
################################
|
|
|
|
##### Set global variables #####
|
|
|
|
################################
|
|
|
|
|
2018-09-10 18:21:08 +00:00
|
|
|
PREFIX?=/usr/local
|
2018-05-15 01:52:51 +00:00
|
|
|
|
2018-09-06 02:18:42 +00:00
|
|
|
INCLUDEDIR=$(PREFIX)/include/janet
|
2018-05-15 01:52:51 +00:00
|
|
|
LIBDIR=$(PREFIX)/lib
|
2018-03-18 18:03:26 +00:00
|
|
|
BINDIR=$(PREFIX)/bin
|
2018-12-08 19:17:03 +00:00
|
|
|
JANET_BUILD?="\"$(shell git log --pretty=format:'%h' -n 1)\""
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2019-01-15 02:46:36 +00:00
|
|
|
CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -fpic -O2 -fvisibility=hidden \
|
2018-12-08 19:17:03 +00:00
|
|
|
-DJANET_BUILD=$(JANET_BUILD)
|
2019-02-16 00:02:14 +00:00
|
|
|
CLIBS=-lm
|
2018-12-09 22:37:11 +00:00
|
|
|
JANET_TARGET=build/janet
|
|
|
|
JANET_LIBRARY=build/libjanet.so
|
2018-11-15 22:44:30 +00:00
|
|
|
JANET_PATH?=/usr/local/lib/janet
|
2018-03-18 18:03:26 +00:00
|
|
|
DEBUGGER=gdb
|
|
|
|
|
2018-11-29 00:56:58 +00:00
|
|
|
UNAME:=$(shell uname -s)
|
|
|
|
LDCONFIG:=ldconfig
|
2018-12-08 19:17:03 +00:00
|
|
|
ifeq ($(UNAME), Darwin)
|
2018-11-29 00:56:58 +00:00
|
|
|
# Add other macos/clang flags
|
|
|
|
LDCONFIG:=
|
2019-02-16 00:02:14 +00:00
|
|
|
CLIBS:=$(CLIBS) -ldl
|
|
|
|
else ifeq ($(UNAME), OpenBSD)
|
|
|
|
# pass ...
|
2018-11-29 00:56:58 +00:00
|
|
|
else
|
|
|
|
CFLAGS:=$(CFLAGS) -rdynamic
|
2019-02-16 00:02:14 +00:00
|
|
|
CLIBS:=$(CLIBS) -lrt -ldl
|
2018-11-29 00:56:58 +00:00
|
|
|
endif
|
2018-05-22 02:08:16 +00:00
|
|
|
|
2019-02-08 05:44:30 +00:00
|
|
|
$(shell mkdir -p build/core build/mainclient build/webclient build/boot)
|
2018-12-09 22:37:11 +00:00
|
|
|
|
2018-03-18 18:03:26 +00:00
|
|
|
# Source headers
|
2018-11-29 00:56:58 +00:00
|
|
|
JANET_HEADERS=$(sort $(wildcard src/include/janet/*.h))
|
|
|
|
JANET_LOCAL_HEADERS=$(sort $(wildcard src/*/*.h))
|
2018-03-18 18:03:26 +00:00
|
|
|
|
|
|
|
# Source files
|
2018-12-09 22:37:11 +00:00
|
|
|
JANET_CORE_SOURCES=$(sort $(wildcard src/core/*.c))
|
|
|
|
JANET_MAINCLIENT_SOURCES=$(sort $(wildcard src/mainclient/*.c))
|
|
|
|
JANET_WEBCLIENT_SOURCES=$(sort $(wildcard src/webclient/*.c))
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-09-06 02:18:42 +00:00
|
|
|
all: $(JANET_TARGET) $(JANET_LIBRARY)
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2019-02-08 05:44:30 +00:00
|
|
|
##################################################################
|
|
|
|
##### The bootstrap interpreter that compiles the core image #####
|
|
|
|
##################################################################
|
|
|
|
|
|
|
|
JANET_BOOT_OBJECTS=$(patsubst src/%.c,build/%.boot.o,$(JANET_CORE_SOURCES) src/boot/boot.c) \
|
|
|
|
build/core.gen.o \
|
|
|
|
build/boot.gen.o
|
|
|
|
|
|
|
|
build/%.boot.o: src/%.c
|
|
|
|
$(CC) $(CFLAGS) -DJANET_BOOTSTRAP -o $@ -c $<
|
|
|
|
|
|
|
|
build/janet_boot: $(JANET_BOOT_OBJECTS)
|
|
|
|
$(CC) $(CFLAGS) -DJANET_BOOTSTRAP -o $@ $^ $(CLIBS)
|
|
|
|
|
|
|
|
# Now the reason we bootstrap in the first place
|
|
|
|
build/core_image.c: build/janet_boot
|
|
|
|
build/janet_boot
|
|
|
|
|
2018-05-15 01:52:51 +00:00
|
|
|
##########################################################
|
|
|
|
##### The main interpreter program and shared object #####
|
|
|
|
##########################################################
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2019-02-08 05:44:30 +00:00
|
|
|
JANET_CORE_OBJECTS=$(patsubst src/%.c,build/%.o,$(JANET_CORE_SOURCES)) build/core_image.o
|
2018-12-09 22:37:11 +00:00
|
|
|
JANET_MAINCLIENT_OBJECTS=$(patsubst src/%.c,build/%.o,$(JANET_MAINCLIENT_SOURCES)) build/init.gen.o
|
2018-05-15 01:52:51 +00:00
|
|
|
|
2019-02-08 05:44:30 +00:00
|
|
|
# Compile the core image generated by the bootstrap build
|
|
|
|
build/core_image.o: build/core_image.c $(JANET_HEADERS) $(JANET_LOCAL_HEADERS)
|
2018-12-09 22:37:11 +00:00
|
|
|
$(CC) $(CFLAGS) -o $@ -c $<
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-12-09 22:37:11 +00:00
|
|
|
build/%.o: src/%.c $(JANET_HEADERS) $(JANET_LOCAL_HEADERS)
|
2018-05-10 15:11:18 +00:00
|
|
|
$(CC) $(CFLAGS) -o $@ -c $<
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-12-09 22:37:11 +00:00
|
|
|
$(JANET_TARGET): $(JANET_CORE_OBJECTS) $(JANET_MAINCLIENT_OBJECTS)
|
2018-10-17 03:08:26 +00:00
|
|
|
$(CC) $(CFLAGS) -o $@ $^ $(CLIBS)
|
2018-05-15 01:52:51 +00:00
|
|
|
|
2018-09-06 02:18:42 +00:00
|
|
|
$(JANET_LIBRARY): $(JANET_CORE_OBJECTS)
|
2018-10-17 03:08:26 +00:00
|
|
|
$(CC) $(CFLAGS) -shared -o $@ $^ $(CLIBS)
|
|
|
|
|
|
|
|
######################
|
|
|
|
##### Emscripten #####
|
|
|
|
######################
|
|
|
|
|
|
|
|
EMCC=emcc
|
2018-12-09 22:37:11 +00:00
|
|
|
EMCFLAGS=-std=c99 -Wall -Wextra -Isrc/include -O2 \
|
2018-11-15 23:56:06 +00:00
|
|
|
-s EXTRA_EXPORTED_RUNTIME_METHODS='["cwrap"]' \
|
2018-11-26 14:02:07 +00:00
|
|
|
-s ALLOW_MEMORY_GROWTH=1 \
|
|
|
|
-s AGGRESSIVE_VARIABLE_ELIMINATION=1 \
|
2018-12-08 19:17:03 +00:00
|
|
|
-DJANET_BUILD=$(JANET_BUILD)
|
2018-12-09 22:37:11 +00:00
|
|
|
JANET_EMTARGET=build/janet.js
|
2018-10-17 03:08:26 +00:00
|
|
|
JANET_WEB_SOURCES=$(JANET_CORE_SOURCES) $(JANET_WEBCLIENT_SOURCES)
|
2018-12-09 22:37:11 +00:00
|
|
|
JANET_EMOBJECTS=$(patsubst src/%.c,build/%.bc,$(JANET_WEB_SOURCES)) \
|
2019-02-08 16:04:33 +00:00
|
|
|
build/webinit.gen.bc build/core_image.bc
|
2018-12-09 22:37:11 +00:00
|
|
|
|
|
|
|
%.gen.bc: %.gen.c
|
|
|
|
$(EMCC) $(EMCFLAGS) -o $@ -c $<
|
2019-02-08 16:04:33 +00:00
|
|
|
|
|
|
|
build/core_image.bc: build/core_image.c $(JANET_HEADERS) $(JANET_LOCAL_HEADERS)
|
|
|
|
$(EMCC) $(EMCFLAGS) -o $@ -c $<
|
2018-10-17 03:08:26 +00:00
|
|
|
|
2018-12-09 22:37:11 +00:00
|
|
|
build/%.bc: src/%.c $(JANET_HEADERS) $(JANET_LOCAL_HEADERS)
|
|
|
|
$(EMCC) $(EMCFLAGS) -o $@ -c $<
|
2018-10-17 03:08:26 +00:00
|
|
|
|
|
|
|
$(JANET_EMTARGET): $(JANET_EMOBJECTS)
|
2018-12-09 22:37:11 +00:00
|
|
|
$(EMCC) $(EMCFLAGS) -shared -o $@ $^
|
|
|
|
|
|
|
|
emscripten: $(JANET_EMTARGET)
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-12-06 19:30:11 +00:00
|
|
|
#############################
|
|
|
|
##### Generated C files #####
|
|
|
|
#############################
|
|
|
|
|
2019-02-08 05:44:30 +00:00
|
|
|
%.gen.o: %.gen.c
|
|
|
|
$(CC) $(CFLAGS) -o $@ -c $<
|
|
|
|
|
2018-12-09 22:49:00 +00:00
|
|
|
build/xxd: tools/xxd.c
|
2018-12-06 19:30:11 +00:00
|
|
|
$(CC) $< -o $@
|
|
|
|
|
2018-12-09 22:37:11 +00:00
|
|
|
build/core.gen.c: src/core/core.janet build/xxd
|
|
|
|
build/xxd $< $@ janet_gen_core
|
|
|
|
build/init.gen.c: src/mainclient/init.janet build/xxd
|
|
|
|
build/xxd $< $@ janet_gen_init
|
|
|
|
build/webinit.gen.c: src/webclient/webinit.janet build/xxd
|
|
|
|
build/xxd $< $@ janet_gen_webinit
|
2019-02-08 05:44:30 +00:00
|
|
|
build/boot.gen.c: src/boot/boot.janet build/xxd
|
|
|
|
build/xxd $< $@ janet_gen_boot
|
2018-12-06 19:30:11 +00:00
|
|
|
|
2019-01-24 05:15:58 +00:00
|
|
|
########################
|
|
|
|
##### Amalgamation #####
|
|
|
|
########################
|
|
|
|
|
2019-02-08 05:44:30 +00:00
|
|
|
amalg: build/janet.c build/janet.h build/core_image.c
|
2019-01-24 05:15:58 +00:00
|
|
|
|
|
|
|
build/janet.c: $(JANET_LOCAL_HEADERS) $(JANET_CORE_SOURCES) tools/amalg.janet $(JANET_TARGET)
|
|
|
|
$(JANET_TARGET) tools/amalg.janet > $@
|
|
|
|
|
|
|
|
build/janet.h: src/include/janet/janet.h
|
|
|
|
cp $< $@
|
|
|
|
|
2018-03-18 18:03:26 +00:00
|
|
|
###################
|
|
|
|
##### Testing #####
|
|
|
|
###################
|
|
|
|
|
2018-12-02 20:29:21 +00:00
|
|
|
TEST_SCRIPTS=$(wildcard test/suite*.janet)
|
2018-11-18 18:56:27 +00:00
|
|
|
|
2018-09-06 02:18:42 +00:00
|
|
|
repl: $(JANET_TARGET)
|
|
|
|
./$(JANET_TARGET)
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-09-06 02:18:42 +00:00
|
|
|
debug: $(JANET_TARGET)
|
|
|
|
$(DEBUGGER) ./$(JANET_TARGET)
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2019-01-06 17:32:44 +00:00
|
|
|
VALGRIND_COMMAND=valgrind --leak-check=full
|
|
|
|
|
2018-09-06 02:18:42 +00:00
|
|
|
valgrind: $(JANET_TARGET)
|
2019-01-06 17:32:44 +00:00
|
|
|
$(VALGRIND_COMMAND) ./$(JANET_TARGET)
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-11-18 18:56:27 +00:00
|
|
|
test: $(JANET_TARGET) $(TEST_PROGRAMS)
|
2018-12-02 20:29:21 +00:00
|
|
|
for f in test/*.janet; do ./$(JANET_TARGET) "$$f" || exit; done
|
|
|
|
|
2018-11-18 18:56:27 +00:00
|
|
|
valtest: $(JANET_TARGET) $(TEST_PROGRAMS)
|
2018-12-02 20:29:21 +00:00
|
|
|
for f in test/*.janet; do $(VALGRIND_COMMAND) ./$(JANET_TARGET) "$$f" || exit; done
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2019-01-07 02:49:24 +00:00
|
|
|
callgrind: $(JANET_TARGET)
|
|
|
|
for f in test/*.janet; do valgrind --tool=callgrind ./$(JANET_TARGET) "$$f" || exit; done
|
|
|
|
|
2018-12-09 22:37:11 +00:00
|
|
|
########################
|
|
|
|
##### Distribution #####
|
|
|
|
########################
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-12-09 22:37:11 +00:00
|
|
|
dist: build/janet-dist.tar.gz
|
2018-12-08 21:17:34 +00:00
|
|
|
|
2018-12-09 22:37:11 +00:00
|
|
|
build/janet-%.tar.gz: $(JANET_TARGET) src/include/janet/janet.h \
|
2018-12-18 03:48:37 +00:00
|
|
|
janet.1 LICENSE CONTRIBUTING.md $(JANET_LIBRARY) \
|
2019-01-28 16:50:33 +00:00
|
|
|
build/doc.html README.md build/janet.c
|
2018-12-08 21:17:34 +00:00
|
|
|
tar -czvf $@ $^
|
|
|
|
|
2018-12-17 06:41:11 +00:00
|
|
|
#########################
|
|
|
|
##### Documentation #####
|
|
|
|
#########################
|
|
|
|
|
|
|
|
docs: build/doc.html
|
|
|
|
|
2018-12-25 22:37:52 +00:00
|
|
|
build/doc.html: $(JANET_TARGET) tools/gendoc.janet
|
|
|
|
$(JANET_TARGET) tools/gendoc.janet > build/doc.html
|
2018-12-17 06:41:11 +00:00
|
|
|
|
2018-12-09 22:37:11 +00:00
|
|
|
#################
|
|
|
|
##### Other #####
|
|
|
|
#################
|
|
|
|
|
2019-01-09 00:59:54 +00:00
|
|
|
grammar: build/janet.tmLanguage
|
|
|
|
build/janet.tmLanguage: tools/tm_lang_gen.janet $(JANET_TARGET)
|
|
|
|
$(JANET_TARGET) $< > $@
|
|
|
|
|
2018-03-18 18:03:26 +00:00
|
|
|
clean:
|
2019-01-07 02:49:24 +00:00
|
|
|
-rm -rf build vgcore.* callgrind.*
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-09-06 02:18:42 +00:00
|
|
|
install: $(JANET_TARGET)
|
2018-09-10 18:21:08 +00:00
|
|
|
mkdir -p $(BINDIR)
|
2018-12-09 23:01:43 +00:00
|
|
|
cp $(JANET_TARGET) $(BINDIR)/janet
|
2018-05-15 01:52:51 +00:00
|
|
|
mkdir -p $(INCLUDEDIR)
|
2018-09-06 02:18:42 +00:00
|
|
|
cp $(JANET_HEADERS) $(INCLUDEDIR)
|
2018-09-10 18:21:08 +00:00
|
|
|
mkdir -p $(LIBDIR)
|
2018-12-09 23:01:43 +00:00
|
|
|
cp $(JANET_LIBRARY) $(LIBDIR)/libjanet.so
|
2018-12-25 20:39:24 +00:00
|
|
|
mkdir -p $(JANET_PATH)
|
|
|
|
cp tools/cook.janet $(JANET_PATH)
|
2019-01-18 04:43:46 +00:00
|
|
|
cp tools/highlight.janet $(JANET_PATH)
|
2018-11-18 14:35:41 +00:00
|
|
|
cp janet.1 /usr/local/share/man/man1/
|
|
|
|
mandb
|
2018-06-26 18:10:17 +00:00
|
|
|
$(LDCONFIG)
|
2018-03-18 18:03:26 +00:00
|
|
|
|
|
|
|
uninstall:
|
2018-12-09 23:01:43 +00:00
|
|
|
-rm $(BINDIR)/../$(JANET_TARGET)
|
|
|
|
-rm $(LIBDIR)/../$(JANET_LIBRARY)
|
2018-06-29 03:36:31 +00:00
|
|
|
-rm -rf $(INCLUDEDIR)
|
2018-06-26 18:10:17 +00:00
|
|
|
$(LDCONFIG)
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2019-01-24 05:15:58 +00:00
|
|
|
.PHONY: clean install repl debug valgrind test amalg \
|
2019-01-09 00:59:54 +00:00
|
|
|
valtest emscripten dist uninstall docs grammar \
|
2018-11-18 18:56:27 +00:00
|
|
|
$(TEST_PROGRAM_PHONIES) $(TEST_PROGRAM_VALPHONIES)
|