diff --git a/.travis.yml b/.travis.yml index 04fe0728..2228f1c8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: c script: - make - make test -- make janet-${TRAVIS_TAG}-${TRAVIS_OS_NAME}.tar.gz +- make build/janet-${TRAVIS_TAG}-${TRAVIS_OS_NAME}.tar.gz compiler: - clang - gcc @@ -14,7 +14,7 @@ deploy: provider: releases api_key: secure: JSqAOTH1jmfVlbOuPO3BbY1BhPq+ddiBNPCxuAyKHoVwfO4eNAmq9COI+UwCMWY3dg+YlspufRwkHj//B7QQ6hPbSsKu+Mapu6gr/CAE/jxbfO/E98LkIkUwbGjplwtzw2kiBkHN/Bu6J5X76cwo4D8nwQ1JIcV3nWtoG87t7H4W0R4AYQkbLGAPylgUFr11YMPx2cRBBqCdLAGIrny7kQ/0cRBfkN81R/gUJv/q3OjmUvY7sALXp7mFdZb75QPSilKIDuVUU5hLvPYTeRl6cWI/M+m5SmGZx1rjv5S9Qaw070XoNyt9JAADtbOUnADKvDguDZIP1FCuT1Gb+cnJPzrvk6+OBU9s8UjCTFtgV+LKlhmRZcwV5YQBE94PKRMJNC6VvIWM7UeQ8Zhm1jmQS6ONNWbuoUAlkZP57NtDQa2x0GT2wkubNSQKlaY+6/gwTD9KAJIzaZG7HYXH7b+4g7VbccCyhDAtDZtXgrOIS4WAkNc8rWezRO4H0qHMyON9aCEb0eTE8hWIufbx6ymG4gUxnYO+AkrEYMCwQvU6lS8BsevkaMTVtSShqlQtJ9FRlmJA3MA2ONyqzQXJENqRydyVbpFrKSv+0HbMyhEc5BoKbt0QcTh/slouNV4eASNar/GKN7aP8XKGUeMwIoCcRpP+3ehmwX9SUw7Ah5S42pA= - file: janet-${TRAVIS_TAG}-${TRAVIS_OS_NAME}.tar.gz + file: build/janet-${TRAVIS_TAG}-${TRAVIS_OS_NAME}.tar.gz draft: true skip_cleanup: true on: diff --git a/Makefile b/Makefile index ff74977b..3e3f4e18 100644 --- a/Makefile +++ b/Makefile @@ -32,8 +32,8 @@ JANET_BUILD?="\"$(shell git log --pretty=format:'%h' -n 1)\"" CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -fpic -O2 -fvisibility=hidden \ -DJANET_BUILD=$(JANET_BUILD) CLIBS=-lm -ldl -JANET_TARGET=janet -JANET_LIBRARY=libjanet.so +JANET_TARGET=build/janet +JANET_LIBRARY=build/libjanet.so JANET_PATH?=/usr/local/lib/janet DEBUGGER=gdb @@ -47,14 +47,16 @@ else CLIBS:=$(CLIBS) -lrt endif +$(shell mkdir -p build/core build/mainclient build/webclient) + # Source headers JANET_HEADERS=$(sort $(wildcard src/include/janet/*.h)) JANET_LOCAL_HEADERS=$(sort $(wildcard src/*/*.h)) # Source files -JANET_CORE_SOURCES=$(sort $(wildcard src/core/*.c)) src/core/core.gen.c -JANET_MAINCLIENT_SOURCES=$(sort $(wildcard src/mainclient/*.c)) src/mainclient/init.gen.c -JANET_WEBCLIENT_SOURCES=$(sort $(wildcard src/webclient/*.c)) src/webclient/webinit.gen.c +JANET_CORE_SOURCES=$(sort $(wildcard src/core/*.c)) +JANET_MAINCLIENT_SOURCES=$(sort $(wildcard src/mainclient/*.c)) +JANET_WEBCLIENT_SOURCES=$(sort $(wildcard src/webclient/*.c)) all: $(JANET_TARGET) $(JANET_LIBRARY) @@ -62,16 +64,16 @@ all: $(JANET_TARGET) $(JANET_LIBRARY) ##### The main interpreter program and shared object ##### ########################################################## -JANET_ALL_SOURCES=$(JANET_CORE_SOURCES) \ - $(JANET_MAINCLIENT_SOURCES) +JANET_CORE_OBJECTS=$(patsubst src/%.c,build/%.o,$(JANET_CORE_SOURCES)) build/core.gen.o +JANET_MAINCLIENT_OBJECTS=$(patsubst src/%.c,build/%.o,$(JANET_MAINCLIENT_SOURCES)) build/init.gen.o -JANET_CORE_OBJECTS=$(patsubst %.c,%.o,$(JANET_CORE_SOURCES)) -JANET_ALL_OBJECTS=$(patsubst %.c,%.o,$(JANET_ALL_SOURCES)) - -%.o: %.c $(JANET_HEADERS) $(JANET_LOCAL_HEADERS) +%.gen.o: %.gen.c $(CC) $(CFLAGS) -o $@ -c $< -$(JANET_TARGET): $(JANET_ALL_OBJECTS) +build/%.o: src/%.c $(JANET_HEADERS) $(JANET_LOCAL_HEADERS) + $(CC) $(CFLAGS) -o $@ -c $< + +$(JANET_TARGET): $(JANET_CORE_OBJECTS) $(JANET_MAINCLIENT_OBJECTS) $(CC) $(CFLAGS) -o $@ $^ $(CLIBS) $(JANET_LIBRARY): $(JANET_CORE_OBJECTS) @@ -82,44 +84,54 @@ $(JANET_LIBRARY): $(JANET_CORE_OBJECTS) ###################### EMCC=emcc -EMCCFLAGS=-std=c99 -Wall -Wextra -Isrc/include -O2 \ +EMCFLAGS=-std=c99 -Wall -Wextra -Isrc/include -O2 \ -s EXTRA_EXPORTED_RUNTIME_METHODS='["cwrap"]' \ -s ALLOW_MEMORY_GROWTH=1 \ -s AGGRESSIVE_VARIABLE_ELIMINATION=1 \ -DJANET_BUILD=$(JANET_BUILD) -JANET_EMTARGET=janet.js +JANET_EMTARGET=build/janet.js JANET_WEB_SOURCES=$(JANET_CORE_SOURCES) $(JANET_WEBCLIENT_SOURCES) -JANET_EMOBJECTS=$(patsubst %.c,%.bc,$(JANET_WEB_SOURCES)) +JANET_EMOBJECTS=$(patsubst src/%.c,build/%.bc,$(JANET_WEB_SOURCES)) \ + build/webinit.gen.bc build/core.gen.bc -%.bc: %.c $(JANET_HEADERS) $(JANET_LOCAL_HEADERS) - $(EMCC) $(EMCCFLAGS) -o $@ -c $< +%.gen.bc: %.gen.c + $(EMCC) $(EMCFLAGS) -o $@ -c $< + +build/%.bc: src/%.c $(JANET_HEADERS) $(JANET_LOCAL_HEADERS) + $(EMCC) $(EMCFLAGS) -o $@ -c $< $(JANET_EMTARGET): $(JANET_EMOBJECTS) - $(EMCC) $(EMCCFLAGS) -shared -o $@ $^ + $(EMCC) $(EMCFLAGS) -shared -o $@ $^ + +emscripten: $(JANET_EMTARGET) ############################# ##### Generated C files ##### ############################# -xxd: src/tools/xxd.c +build/xxd: src/tools/xxd.c $(CC) $< -o $@ -%.gen.c: %.janet xxd - ./xxd $< $@ janet_gen_$(*F) +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 ################### ##### Testing ##### ################### TEST_SOURCES=$(wildcard ctest/*.c) -TEST_OBJECTS=$(patsubst %.c,%.o,$(TEST_SOURCES)) -TEST_PROGRAMS=$(patsubst %.c,%.out,$(TEST_SOURCES)) +TEST_OBJECTS=$(patsubst ctest/%.c,build/%.o,$(TEST_SOURCES)) +TEST_PROGRAMS=$(patsubst ctest/%.c,build/%.out,$(TEST_SOURCES)) TEST_SCRIPTS=$(wildcard test/suite*.janet) -ctest/%.o: ctest/%.c $(JANET_HEADERS) +build/%.o: ctest/%.c $(JANET_HEADERS) $(CC) $(CFLAGS) -o $@ -c $< -ctest/%.out: ctest/%.o $(JANET_CORE_OBJECTS) +build/%.out: build/%.o $(JANET_CORE_OBJECTS) $(CC) $(CFLAGS) -o $@ $^ $(CLIBS) repl: $(JANET_TARGET) @@ -132,13 +144,13 @@ valgrind: $(JANET_TARGET) valgrind --leak-check=full -v ./$(JANET_TARGET) test: $(JANET_TARGET) $(TEST_PROGRAMS) - for f in ctest/*.out; do "$$f" || exit; done + for f in build/*.out; do "$$f" || exit; done for f in test/*.janet; do ./$(JANET_TARGET) "$$f" || exit; done VALGRIND_COMMAND=valgrind --leak-check=full -v valtest: $(JANET_TARGET) $(TEST_PROGRAMS) - for f in ctest/*.out; do $(VALGRIND_COMMAND) "$$f" || exit; done + for f in build/*.out; do $(VALGRIND_COMMAND) "$$f" || exit; done for f in test/*.janet; do $(VALGRIND_COMMAND) ./$(JANET_TARGET) "$$f" || exit; done ################### @@ -153,23 +165,22 @@ clean-natives: $(MAKE) -C natives/json clean $(MAKE) -C natives/sqlite3 clean +######################## +##### Distribution ##### +######################## + +dist: build/janet-dist.tar.gz + +build/janet-%.tar.gz: $(JANET_TARGET) src/include/janet/janet.h \ + janet.1 LICENSE CONTRIBUTING.md $(JANET_LIBRARY) README.md + tar -czvf $@ $^ + ################# ##### Other ##### ################# -dist: janet-dist.tar.gz - -janet-%.tar.gz: $(JANET_TARGET) src/include/janet/janet.h \ - janet.1 LICENSE CONTRIBUTING.md $(JANET_LIBRARY) README.md - tar -czvf $@ $^ - clean: - -rm $(JANET_TARGET) - -rm $(JANET_LIBRARY) - -rm ctest/*.o ctest/*.out - -rm src/**/*.o src/**/*.bc vgcore.* *.js *.wasm *.html - -rm src/**/*.gen.c - -rm janet-*.tar.gz + -rm -rf build install: $(JANET_TARGET) mkdir -p $(BINDIR) @@ -193,5 +204,5 @@ uninstall: -rm -rf $(INCLUDEDIR) $(LDCONFIG) -.PHONY: clean install repl debug valgrind test valtest dist install uninstall \ +.PHONY: clean install repl debug valgrind test valtest emscripten dist install uninstall \ $(TEST_PROGRAM_PHONIES) $(TEST_PROGRAM_VALPHONIES) diff --git a/README.md b/README.md index 2fb26755..5fd5ebd9 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ before compilation. ### Unix-like -On most platforms, use Make to build janet. +On most platforms, use Make to build janet. The resulting binary will be in `build/janet`. ```sh cd somewhere/my/projects/janet @@ -142,43 +142,12 @@ or [Visual Studio Build Tools](https://visualstudio.microsoft.com/thank-you-down ### Emscripten To build janet for the web via [Emscripten](https://kripken.github.io/emscripten-site/), make sure you -have `emcc` installed and on your path. On a linux or macOS system, use `make janet.js` to build +have `emcc` installed and on your path. On a linux or macOS system, use `make emscripten` to build `janet.js` and `janet.wasm` - both are needed to run janet in a browser or in node. The JavaScript build is what runs the repl on the main website, -but really serves mainly as a proof of concept. Janet will run much slower in a browser. +but really serves mainly as a proof of concept. Janet will run slower in a browser. Building with emscripten on windows is currently unsupported. ## Examples See the examples directory for some example janet code. - -## SQLite bindings - -There are some sqlite3 bindings in the directory natives/sqlite3. They serve mostly as a -proof of concept external c library. To use, first compile the module with Make. - -```sh -make natives -``` - -Next, enter the repl and create a database and a table. - -``` -janet:1:> (import natives/sqlite3 :as sql) -nil -janet:2:> (def db (sql/open "test.db")) - -janet:3:> (sql/eval db `CREATE TABLE customers(id INTEGER PRIMARY KEY, name TEXT);`) -@[] -janet:4:> (sql/eval db `INSERT INTO customers VALUES(:id, :name);` {:name "John" :id 12345}) -@[] -janet:5:> (sql/eval db `SELECT * FROM customers;`) -@[{"id" 12345 "name" "John"}] -``` - -Finally, close the database connection when done with it. - -``` -janet:6:> (sql/close db) -nil -```