1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-25 07:50:27 +00:00

Make setting up stl easier. Add shared library output to Makefile.

This commit is contained in:
Calvin Rose 2018-05-14 21:52:51 -04:00
parent 80ae7e80e6
commit c6f79eca6d
4 changed files with 36 additions and 17 deletions

View File

@ -22,17 +22,21 @@
##### Set global variables #####
################################
PREFIX?=/usr/local
PREFIX?=/usr
INCLUDEDIR=$(PREFIX)/include/dst
LIBDIR=$(PREFIX)/lib
BINDIR=$(PREFIX)/bin
# CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -Wl,--dynamic-list=src/exported.list -s -O3
# TODO - when api is finalized, only export public symbols instead of using rdynamic
# which exports all symbols.
# which exports all symbols. Saves a few KB in binary.
CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -rdynamic -O2
CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -rdynamic -fpic -O2
CLIBS=-lm -ldl
PREFIX=/usr/local
DST_TARGET=dst
DST_LIBRARY=libdst.so
DEBUGGER=gdb
# Source headers
@ -51,7 +55,7 @@ DST_CORE_SOURCES=$(sort $(wildcard src/core/*.c))
DST_MAINCLIENT_SOURCES=$(sort $(wildcard src/mainclient/*.c))
DST_PARSER_SOURCES=$(sort $(wildcard src/parser/*.c))
all: $(DST_TARGET)
all: $(DST_TARGET) $(DST_LIBRARY)
###################################
##### The code generator tool #####
@ -70,24 +74,30 @@ src/mainclient/clientinit.gen.h: src/mainclient/init.dst xxd
src/compiler/dststlbootstrap.gen.h: src/compiler/boot.dst xxd
./xxd $< $@ dst_stl_bootstrap_gen
########################################
##### The main interpreter program #####
########################################
##########################################################
##### The main interpreter program and shared object #####
##########################################################
DST_ALL_SOURCES=$(DST_ASM_SOURCES) \
DST_LIB_SOURCES=$(DST_ASM_SOURCES) \
$(DST_COMPILER_SOURCES) \
$(DST_CONTEXT_SOURCES) \
$(DST_CORE_SOURCES) \
$(DST_MAINCLIENT_SOURCES) \
$(DST_PARSER_SOURCES)
DST_ALL_SOURCES=$(DST_LIB_SOURCES) \
$(DST_MAINCLIENT_SOURCES)
DST_LIB_OBJECTS=$(patsubst %.c,%.o,$(DST_LIB_SOURCES))
DST_ALL_OBJECTS=$(patsubst %.c,%.o,$(DST_ALL_SOURCES))
%.o: %.c $(DST_ALL_HEADERS)
$(CC) $(CFLAGS) -o $@ -c $<
$(DST_TARGET): $(DST_ALL_OBJECTS)
$(CC) $(CFLAGS) -o $(DST_TARGET) $(DST_ALL_OBJECTS) $(CLIBS)
$(CC) $(CFLAGS) -o $(DST_TARGET) $^ $(CLIBS)
$(DST_LIBRARY): $(DST_LIB_OBJECTS)
$(CC) $(CFLAGS) -shared -o $(DST_LIBRARY) $^ $(CLIBS)
###################
##### Testing #####
@ -108,6 +118,7 @@ test: $(DST_TARGET)
valtest: $(DST_TARGET)
valgrind --leak-check=full -v ./$(DST_TARGET) test/suite0.dst
valgrind --leak-check=full -v ./$(DST_TARGET) test/suite1.dst
#################
##### Other #####
@ -120,9 +131,16 @@ clean:
rm $(DST_GENERATED_HEADERS) || true
install: $(DST_TARGET)
cp $(DST_TARGET) $(BINDIR)/dst
cp $(DST_TARGET) $(BINDIR)/$(DST_TARGET)
mkdir -p $(INCLUDEDIR)
cp $(DST_HEADERS) $(INCLUDEDIR)
cp $(DST_LIBRARY) $(LIBDIR)/$(DST_LIBRARY)
ldconfig
uninstall:
rm $(BINDIR)/dst
rm $(BINDIR)/$(DST_TARGET)
rm $(LIBDIR)/$(DST_LIBRARY)
rm -rf $(INCLUDEDIR)
ldconfig
.PHONY: clean install repl debug valgrind test valtest install uninstall

View File

@ -60,7 +60,7 @@ static const DstReg cfuns[] = {
{NULL, NULL}
};
DstTable *dst_stl_env() {
DstTable *dst_stl_env(int flags) {
static uint32_t error_asm[] = {
DOP_ERROR
};
@ -112,6 +112,7 @@ DstTable *dst_stl_env() {
/* Run bootstrap source */
dst_dobytes(env, dst_stl_bootstrap_gen, sizeof(dst_stl_bootstrap_gen));
if (flags & DST_STL_NOGCROOT)
dst_gcunroot(dst_wrap_table(env));
return env;

View File

@ -195,7 +195,8 @@ Dst dst_env_resolve(DstTable *env, const char *name);
DstTable *dst_env_arg(DstArgs args);
/* STL */
DstTable *dst_stl_env(void);
#define DST_STL_NOGCROOT 1
DstTable *dst_stl_env(int flags);
/* C Function helpers */
int dst_arity_err(DstArgs args, int32_t n, const char *prefix);

View File

@ -33,8 +33,7 @@ int main(int argc, char **argv) {
/* Set up VM */
dst_init();
env = dst_stl_env();
dst_gcroot(dst_wrap_table(env));
env = dst_stl_env(0);
/* Create args tuple */
args = dst_array(argc);