2018-03-18 18:03:26 +00:00
|
|
|
# Copyright (c) 2018 Calvin Rose
|
|
|
|
#
|
|
|
|
# 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:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# 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-10-31 20:21:21 +00:00
|
|
|
JANET_VERSION?="\"commit-$(shell git log --pretty=format:'%h' -n 1)\""
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-08-23 02:12:47 +00:00
|
|
|
#CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -fpic -g
|
2018-10-31 20:21:21 +00:00
|
|
|
CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -fpic -O2 -fvisibility=hidden \
|
2018-11-15 23:56:06 +00:00
|
|
|
-DJANET_VERSION=$(JANET_VERSION) \
|
|
|
|
-DJANET_NONANBOX
|
2018-09-10 18:56:39 +00:00
|
|
|
CLIBS=-lm -ldl
|
2018-09-06 02:18:42 +00:00
|
|
|
JANET_TARGET=janet
|
|
|
|
JANET_LIBRARY=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-05-22 02:08:16 +00:00
|
|
|
UNAME:=$(shell uname -s)
|
2018-06-26 18:10:17 +00:00
|
|
|
LDCONFIG:=ldconfig
|
2018-05-22 02:08:16 +00:00
|
|
|
ifeq ($(UNAME), Darwin)
|
|
|
|
# Add other macos/clang flags
|
2018-06-26 18:10:17 +00:00
|
|
|
LDCONFIG:=
|
2018-05-22 02:08:16 +00:00
|
|
|
else
|
|
|
|
CFLAGS:=$(CFLAGS) -rdynamic
|
2018-09-10 18:56:39 +00:00
|
|
|
CLIBS:=$(CLIBS) -lrt
|
2018-05-22 02:08:16 +00:00
|
|
|
endif
|
|
|
|
|
2018-03-18 18:03:26 +00:00
|
|
|
# Source headers
|
2018-09-06 02:18:42 +00:00
|
|
|
JANET_GENERATED_HEADERS= \
|
2018-07-04 04:17:34 +00:00
|
|
|
src/include/generated/core.h \
|
|
|
|
src/include/generated/init.h
|
2018-09-06 02:18:42 +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-09-06 02:18:42 +00:00
|
|
|
JANET_CORE_SOURCES=$(sort $(wildcard src/core/*.c))
|
|
|
|
JANET_MAINCLIENT_SOURCES=$(sort $(wildcard src/mainclient/*.c))
|
2018-10-17 03:08:26 +00:00
|
|
|
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
|
|
|
|
|
|
|
###################################
|
|
|
|
##### The code generator tool #####
|
|
|
|
###################################
|
|
|
|
|
|
|
|
xxd: src/tools/xxd.c
|
|
|
|
$(CC) $< -o $@
|
|
|
|
|
|
|
|
#############################
|
|
|
|
##### Generated Headers #####
|
|
|
|
#############################
|
|
|
|
|
2018-09-06 02:18:42 +00:00
|
|
|
src/include/generated/init.h: src/mainclient/init.janet xxd
|
|
|
|
./xxd $< $@ janet_gen_init
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-10-17 03:08:26 +00:00
|
|
|
src/include/generated/webinit.h: src/webclient/webinit.janet xxd
|
|
|
|
./xxd $< $@ janet_gen_webinit
|
|
|
|
|
2018-09-06 02:18:42 +00:00
|
|
|
src/include/generated/core.h: src/core/core.janet xxd
|
|
|
|
./xxd $< $@ janet_gen_core
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-07-04 03:07:35 +00:00
|
|
|
# Only a few files depend on the generated headers
|
2018-07-04 04:17:34 +00:00
|
|
|
src/core/corelib.o: src/include/generated/core.h
|
2018-07-04 03:07:35 +00:00
|
|
|
src/mainclient/main.o: src/include/generated/init.h
|
|
|
|
|
2018-05-15 01:52:51 +00:00
|
|
|
##########################################################
|
|
|
|
##### The main interpreter program and shared object #####
|
|
|
|
##########################################################
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-09-06 02:18:42 +00:00
|
|
|
JANET_ALL_SOURCES=$(JANET_CORE_SOURCES) \
|
|
|
|
$(JANET_MAINCLIENT_SOURCES)
|
2018-05-15 01:52:51 +00:00
|
|
|
|
2018-09-06 02:18:42 +00:00
|
|
|
JANET_CORE_OBJECTS=$(patsubst %.c,%.o,$(JANET_CORE_SOURCES))
|
|
|
|
JANET_ALL_OBJECTS=$(patsubst %.c,%.o,$(JANET_ALL_SOURCES))
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-09-06 02:18:42 +00:00
|
|
|
%.o: %.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-09-06 02:18:42 +00:00
|
|
|
$(JANET_TARGET): $(JANET_ALL_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-11-15 23:56:06 +00:00
|
|
|
EMCCFLAGS=-std=c99 -Wall -Wextra -Isrc/include -O2 \
|
|
|
|
-s EXTRA_EXPORTED_RUNTIME_METHODS='["cwrap"]' \
|
|
|
|
-s ALLOW_MEMORY_GROWTH=1 -s WASM=1 \
|
|
|
|
-DJANET_VERSION=$(JANET_VERSION)
|
2018-10-17 03:08:26 +00:00
|
|
|
JANET_EMTARGET=janet.js
|
|
|
|
JANET_WEB_SOURCES=$(JANET_CORE_SOURCES) $(JANET_WEBCLIENT_SOURCES)
|
|
|
|
JANET_EMOBJECTS=$(patsubst %.c,%.bc,$(JANET_WEB_SOURCES))
|
|
|
|
|
|
|
|
# Only a few files depend on generated headers
|
|
|
|
src/core/corelib.bc: src/include/generated/core.h
|
|
|
|
src/webclient/main.bc: src/include/generated/webinit.h
|
|
|
|
|
|
|
|
%.bc: %.c $(JANET_HEADERS) $(JANET_LOCAL_HEADERS)
|
|
|
|
$(EMCC) $(EMCCFLAGS) -o $@ -c $<
|
|
|
|
|
|
|
|
$(JANET_EMTARGET): $(JANET_EMOBJECTS)
|
|
|
|
$(EMCC) $(EMCCFLAGS) -shared -o $@ $^
|
2018-03-18 18:03:26 +00:00
|
|
|
|
|
|
|
###################
|
|
|
|
##### Testing #####
|
|
|
|
###################
|
|
|
|
|
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
|
|
|
|
2018-09-06 02:18:42 +00:00
|
|
|
valgrind: $(JANET_TARGET)
|
|
|
|
valgrind --leak-check=full -v ./$(JANET_TARGET)
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-09-06 02:18:42 +00:00
|
|
|
test: $(JANET_TARGET)
|
|
|
|
./$(JANET_TARGET) test/suite0.janet
|
|
|
|
./$(JANET_TARGET) test/suite1.janet
|
|
|
|
./$(JANET_TARGET) test/suite2.janet
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-09-06 02:18:42 +00:00
|
|
|
valtest: $(JANET_TARGET)
|
|
|
|
valgrind --leak-check=full -v ./$(JANET_TARGET) test/suite0.janet
|
|
|
|
valgrind --leak-check=full -v ./$(JANET_TARGET) test/suite1.janet
|
|
|
|
valgrind --leak-check=full -v ./$(JANET_TARGET) test/suite2.janet
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-06-23 23:19:26 +00:00
|
|
|
###################
|
|
|
|
##### Natives #####
|
|
|
|
###################
|
|
|
|
|
2018-09-06 02:18:42 +00:00
|
|
|
natives: $(JANET_TARGET)
|
2018-08-26 15:28:51 +00:00
|
|
|
$(MAKE) -C natives/json
|
2018-06-23 23:19:26 +00:00
|
|
|
$(MAKE) -j 8 -C natives/sqlite3
|
|
|
|
|
2018-07-17 02:55:45 +00:00
|
|
|
clean-natives:
|
2018-08-26 15:28:51 +00:00
|
|
|
$(MAKE) -C natives/json clean
|
2018-07-17 02:55:45 +00:00
|
|
|
$(MAKE) -C natives/sqlite3 clean
|
|
|
|
|
2018-03-18 18:03:26 +00:00
|
|
|
#################
|
|
|
|
##### Other #####
|
|
|
|
#################
|
|
|
|
|
|
|
|
clean:
|
2018-09-06 02:18:42 +00:00
|
|
|
-rm $(JANET_TARGET)
|
2018-10-17 03:08:26 +00:00
|
|
|
-rm $(JANET_LIBRARY)
|
|
|
|
-rm src/**/*.o src/**/*.bc vgcore.* *.js *.wasm *.html
|
2018-09-06 02:18:42 +00:00
|
|
|
-rm $(JANET_GENERATED_HEADERS)
|
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-09-06 02:18:42 +00:00
|
|
|
cp $(JANET_TARGET) $(BINDIR)/$(JANET_TARGET)
|
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-09-06 02:18:42 +00:00
|
|
|
cp $(JANET_LIBRARY) $(LIBDIR)/$(JANET_LIBRARY)
|
2018-06-26 18:10:17 +00:00
|
|
|
$(LDCONFIG)
|
2018-03-18 18:03:26 +00:00
|
|
|
|
2018-08-26 15:28:51 +00:00
|
|
|
install-libs: natives
|
2018-11-15 22:44:30 +00:00
|
|
|
mkdir -p $(JANET_PATH)
|
|
|
|
cp -r lib $(JANET_PATH)
|
2018-09-06 02:18:42 +00:00
|
|
|
cp natives/*/*.so $(JANET_PATH)
|
2018-08-26 15:28:51 +00:00
|
|
|
|
2018-03-18 18:03:26 +00:00
|
|
|
uninstall:
|
2018-09-06 02:18:42 +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
|
|
|
|
|
|
|
.PHONY: clean install repl debug valgrind test valtest install uninstall
|