1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-26 00:10:27 +00:00

Switch to out of source build on unix/linux.

This commit is contained in:
Calvin Rose 2018-12-09 17:37:11 -05:00
parent bb918d0fda
commit 6f64b0c152
3 changed files with 56 additions and 76 deletions

View File

@ -2,7 +2,7 @@ language: c
script: script:
- make - make
- make test - make test
- make janet-${TRAVIS_TAG}-${TRAVIS_OS_NAME}.tar.gz - make build/janet-${TRAVIS_TAG}-${TRAVIS_OS_NAME}.tar.gz
compiler: compiler:
- clang - clang
- gcc - gcc
@ -14,7 +14,7 @@ deploy:
provider: releases provider: releases
api_key: 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= 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 draft: true
skip_cleanup: true skip_cleanup: true
on: on:

View File

@ -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 \ CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -fpic -O2 -fvisibility=hidden \
-DJANET_BUILD=$(JANET_BUILD) -DJANET_BUILD=$(JANET_BUILD)
CLIBS=-lm -ldl CLIBS=-lm -ldl
JANET_TARGET=janet JANET_TARGET=build/janet
JANET_LIBRARY=libjanet.so JANET_LIBRARY=build/libjanet.so
JANET_PATH?=/usr/local/lib/janet JANET_PATH?=/usr/local/lib/janet
DEBUGGER=gdb DEBUGGER=gdb
@ -47,14 +47,16 @@ else
CLIBS:=$(CLIBS) -lrt CLIBS:=$(CLIBS) -lrt
endif endif
$(shell mkdir -p build/core build/mainclient build/webclient)
# Source headers # Source headers
JANET_HEADERS=$(sort $(wildcard src/include/janet/*.h)) JANET_HEADERS=$(sort $(wildcard src/include/janet/*.h))
JANET_LOCAL_HEADERS=$(sort $(wildcard src/*/*.h)) JANET_LOCAL_HEADERS=$(sort $(wildcard src/*/*.h))
# Source files # Source files
JANET_CORE_SOURCES=$(sort $(wildcard src/core/*.c)) src/core/core.gen.c JANET_CORE_SOURCES=$(sort $(wildcard src/core/*.c))
JANET_MAINCLIENT_SOURCES=$(sort $(wildcard src/mainclient/*.c)) src/mainclient/init.gen.c JANET_MAINCLIENT_SOURCES=$(sort $(wildcard src/mainclient/*.c))
JANET_WEBCLIENT_SOURCES=$(sort $(wildcard src/webclient/*.c)) src/webclient/webinit.gen.c JANET_WEBCLIENT_SOURCES=$(sort $(wildcard src/webclient/*.c))
all: $(JANET_TARGET) $(JANET_LIBRARY) all: $(JANET_TARGET) $(JANET_LIBRARY)
@ -62,16 +64,16 @@ all: $(JANET_TARGET) $(JANET_LIBRARY)
##### The main interpreter program and shared object ##### ##### The main interpreter program and shared object #####
########################################################## ##########################################################
JANET_ALL_SOURCES=$(JANET_CORE_SOURCES) \ JANET_CORE_OBJECTS=$(patsubst src/%.c,build/%.o,$(JANET_CORE_SOURCES)) build/core.gen.o
$(JANET_MAINCLIENT_SOURCES) JANET_MAINCLIENT_OBJECTS=$(patsubst src/%.c,build/%.o,$(JANET_MAINCLIENT_SOURCES)) build/init.gen.o
JANET_CORE_OBJECTS=$(patsubst %.c,%.o,$(JANET_CORE_SOURCES)) %.gen.o: %.gen.c
JANET_ALL_OBJECTS=$(patsubst %.c,%.o,$(JANET_ALL_SOURCES))
%.o: %.c $(JANET_HEADERS) $(JANET_LOCAL_HEADERS)
$(CC) $(CFLAGS) -o $@ -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) $(CC) $(CFLAGS) -o $@ $^ $(CLIBS)
$(JANET_LIBRARY): $(JANET_CORE_OBJECTS) $(JANET_LIBRARY): $(JANET_CORE_OBJECTS)
@ -82,44 +84,54 @@ $(JANET_LIBRARY): $(JANET_CORE_OBJECTS)
###################### ######################
EMCC=emcc 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 EXTRA_EXPORTED_RUNTIME_METHODS='["cwrap"]' \
-s ALLOW_MEMORY_GROWTH=1 \ -s ALLOW_MEMORY_GROWTH=1 \
-s AGGRESSIVE_VARIABLE_ELIMINATION=1 \ -s AGGRESSIVE_VARIABLE_ELIMINATION=1 \
-DJANET_BUILD=$(JANET_BUILD) -DJANET_BUILD=$(JANET_BUILD)
JANET_EMTARGET=janet.js JANET_EMTARGET=build/janet.js
JANET_WEB_SOURCES=$(JANET_CORE_SOURCES) $(JANET_WEBCLIENT_SOURCES) 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) %.gen.bc: %.gen.c
$(EMCC) $(EMCCFLAGS) -o $@ -c $< $(EMCC) $(EMCFLAGS) -o $@ -c $<
build/%.bc: src/%.c $(JANET_HEADERS) $(JANET_LOCAL_HEADERS)
$(EMCC) $(EMCFLAGS) -o $@ -c $<
$(JANET_EMTARGET): $(JANET_EMOBJECTS) $(JANET_EMTARGET): $(JANET_EMOBJECTS)
$(EMCC) $(EMCCFLAGS) -shared -o $@ $^ $(EMCC) $(EMCFLAGS) -shared -o $@ $^
emscripten: $(JANET_EMTARGET)
############################# #############################
##### Generated C files ##### ##### Generated C files #####
############################# #############################
xxd: src/tools/xxd.c build/xxd: src/tools/xxd.c
$(CC) $< -o $@ $(CC) $< -o $@
%.gen.c: %.janet xxd build/core.gen.c: src/core/core.janet build/xxd
./xxd $< $@ janet_gen_$(*F) 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 ##### ##### Testing #####
################### ###################
TEST_SOURCES=$(wildcard ctest/*.c) TEST_SOURCES=$(wildcard ctest/*.c)
TEST_OBJECTS=$(patsubst %.c,%.o,$(TEST_SOURCES)) TEST_OBJECTS=$(patsubst ctest/%.c,build/%.o,$(TEST_SOURCES))
TEST_PROGRAMS=$(patsubst %.c,%.out,$(TEST_SOURCES)) TEST_PROGRAMS=$(patsubst ctest/%.c,build/%.out,$(TEST_SOURCES))
TEST_SCRIPTS=$(wildcard test/suite*.janet) TEST_SCRIPTS=$(wildcard test/suite*.janet)
ctest/%.o: ctest/%.c $(JANET_HEADERS) build/%.o: ctest/%.c $(JANET_HEADERS)
$(CC) $(CFLAGS) -o $@ -c $< $(CC) $(CFLAGS) -o $@ -c $<
ctest/%.out: ctest/%.o $(JANET_CORE_OBJECTS) build/%.out: build/%.o $(JANET_CORE_OBJECTS)
$(CC) $(CFLAGS) -o $@ $^ $(CLIBS) $(CC) $(CFLAGS) -o $@ $^ $(CLIBS)
repl: $(JANET_TARGET) repl: $(JANET_TARGET)
@ -132,13 +144,13 @@ valgrind: $(JANET_TARGET)
valgrind --leak-check=full -v ./$(JANET_TARGET) valgrind --leak-check=full -v ./$(JANET_TARGET)
test: $(JANET_TARGET) $(TEST_PROGRAMS) 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 for f in test/*.janet; do ./$(JANET_TARGET) "$$f" || exit; done
VALGRIND_COMMAND=valgrind --leak-check=full -v VALGRIND_COMMAND=valgrind --leak-check=full -v
valtest: $(JANET_TARGET) $(TEST_PROGRAMS) 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 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/json clean
$(MAKE) -C natives/sqlite3 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 ##### ##### 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: clean:
-rm $(JANET_TARGET) -rm -rf build
-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
install: $(JANET_TARGET) install: $(JANET_TARGET)
mkdir -p $(BINDIR) mkdir -p $(BINDIR)
@ -193,5 +204,5 @@ uninstall:
-rm -rf $(INCLUDEDIR) -rm -rf $(INCLUDEDIR)
$(LDCONFIG) $(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) $(TEST_PROGRAM_PHONIES) $(TEST_PROGRAM_VALPHONIES)

View File

@ -106,7 +106,7 @@ before compilation.
### Unix-like ### 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 ```sh
cd somewhere/my/projects/janet cd somewhere/my/projects/janet
@ -142,43 +142,12 @@ or [Visual Studio Build Tools](https://visualstudio.microsoft.com/thank-you-down
### Emscripten ### Emscripten
To build janet for the web via [Emscripten](https://kripken.github.io/emscripten-site/), make sure you 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. `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, 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. Building with emscripten on windows is currently unsupported.
## Examples ## Examples
See the examples directory for some example janet code. 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"))
<sqlite3.connection 0x5561A138C470>
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
```