diff options
| author | 2019-03-22 18:07:10 -0400 | |
|---|---|---|
| committer | 2019-03-22 18:07:10 -0400 | |
| commit | 25aa7a26c53b5a71796609e06e9c72c212c2b4eb (patch) | |
| tree | 7558357117785b64febba2d379b42854fc400c40 | |
| parent | Add janetconf.h for configuring builds. (diff) | |
Add experimental meson build.
Should help with IDE integration.
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | build_win.bat | 1 | ||||
| -rw-r--r-- | meson.build | 142 | ||||
| -rw-r--r-- | src/boot/boot.c | 8 | ||||
| -rw-r--r-- | src/boot/boot.janet | 11 | ||||
| -rw-r--r-- | src/core/core.janet | 2 | ||||
| -rw-r--r-- | src/core/corelib.c | 2 |
8 files changed, 163 insertions, 6 deletions
@@ -4,6 +4,7 @@ dst janet !*/**/janet /build +/builddir /Build /Release /Debug @@ -77,7 +77,7 @@ build/janet_boot: $(JANET_BOOT_OBJECTS) # Now the reason we bootstrap in the first place build/core_image.c: build/janet_boot - JANET_PATH=$(JANET_PATH) build/janet_boot + build/janet_boot $@ JANET_PATH $(JANET_PATH) ########################################################## ##### The main interpreter program and shared object ##### diff --git a/build_win.bat b/build_win.bat index c30d7fd3..c1639e42 100644 --- a/build_win.bat +++ b/build_win.bat @@ -125,6 +125,7 @@ copy README.md dist\README.md copy janet.lib dist\janet.lib copy janet.exp dist\janet.exp copy src\include\janet.h dist\janet.h +copy src\include\janetconf.h dist\janetconf.h copy tools\cook.janet dist\cook.janet copy tools\highlight.janet dist\highlight.janet exit /b 0 diff --git a/meson.build b/meson.build new file mode 100644 index 00000000..34c0c5c5 --- /dev/null +++ b/meson.build @@ -0,0 +1,142 @@ +# Copyright (c) 2019 Calvin Rose and contributors +# +# 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. + +project('janet', 'c', default_options : ['c_std=c99']) + +# Link math library on all systems +cc = meson.get_compiler('c') +m_dep = cc.find_library('m', required : false) +dl_dep = cc.find_library('dl', required : false) + +# Some options +add_project_arguments('-DJANET_BUILD="meson"', language : 'c') + +# Include directories +incdir = include_directories('src/include') + +# Building generated sources +xxd = executable('xxd', 'tools/xxd.c') +gen = generator(xxd, + output : '@BASENAME@.gen.c', + arguments : ['@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@']) +core_gen = gen.process('src/core/core.janet', extra_args: 'janet_gen_core') +boot_gen = gen.process('src/boot/boot.janet', extra_args: 'janet_gen_boot') +init_gen = gen.process('src/mainclient/init.janet', extra_args: 'janet_gen_init') + +core_src = [ + 'src/core/abstract.c', + 'src/core/array.c', + 'src/core/asm.c', + 'src/core/buffer.c', + 'src/core/bytecode.c', + 'src/core/capi.c', + 'src/core/cfuns.c', + 'src/core/compile.c', + 'src/core/corelib.c', + 'src/core/debug.c', + 'src/core/emit.c', + 'src/core/fiber.c', + 'src/core/gc.c', + 'src/core/inttypes.c', + 'src/core/io.c', + 'src/core/marsh.c', + 'src/core/math.c', + 'src/core/os.c', + 'src/core/parse.c', + 'src/core/peg.c', + 'src/core/pp.c', + 'src/core/regalloc.c', + 'src/core/run.c', + 'src/core/specials.c', + 'src/core/string.c', + 'src/core/strtod.c', + 'src/core/struct.c', + 'src/core/symcache.c', + 'src/core/table.c', + 'src/core/tuple.c', + 'src/core/typedarray.c', + 'src/core/util.c', + 'src/core/value.c', + 'src/core/vector.c', + 'src/core/vm.c', + 'src/core/wrap.c' +] + +boot_src = [ + 'src/boot/array_test.c', + 'src/boot/boot.c', + 'src/boot/buffer_test.c', + 'src/boot/number_test.c', + 'src/boot/system_test.c', + 'src/boot/table_test.c', +] + +mainclient_src = [ + 'src/mainclient/line.c', + 'src/mainclient/main.c' +] + +# Build boot binary +janet_boot = executable('janet_boot', core_src, boot_src, core_gen, boot_gen, + c_args : '-DJANET_BOOTSTRAP', + dependencies : [m_dep, dl_dep]) + +# Build core image +core_image = custom_target('core_image', + input : [janet_boot], + output : 'core_image.gen.c', + command : [janet_boot, '@OUTPUT@', + 'JANET_PATH', join_paths(get_option('libdir'), 'janet')]) + +libjanet = shared_library('janet', core_src, core_image, + dependencies : [m_dep, dl_dep], + install : true) +janet_mainclient = executable('janet', core_src, core_image, init_gen, mainclient_src, + dependencies : [m_dep, dl_dep], + install : true) + +# Tests +test_files = [ + 'test/suite0.janet', + 'test/suite1.janet', + 'test/suite2.janet', + 'test/suite3.janet', + 'test/suite4.janet', + 'test/suite5.janet', + 'test/suite6.janet' +] +foreach t : test_files + test(t, janet_mainclient, args : files([t]), workdir : meson.current_source_dir()) +endforeach + +# Repl +run_target('repl', command : [janet_mainclient]) + +# Installation +install_man('janet.1') +install_headers('src/include/janet.h', 'src/include/janetconf.h') +janet_libs = [ + 'src/include/janet.h', + 'src/include/janetconf.h' + 'tools/bars.janet', + 'tools/cook.janet', + 'tools/highlight.janet' +] +install_data(sources : janet_libs) diff --git a/src/boot/boot.c b/src/boot/boot.c index a0fd46ac..42bae7b7 100644 --- a/src/boot/boot.c +++ b/src/boot/boot.c @@ -26,7 +26,7 @@ extern const unsigned char *janet_gen_boot; extern int32_t janet_gen_boot_size; -int main() { +int main(int argc, const char **argv) { /* Init janet */ janet_init(); @@ -46,6 +46,12 @@ int main() { env = janet_core_env(NULL); + /* Create args tuple */ + JanetArray *args = janet_array(argc); + for (int i = 0; i < argc; i++) + janet_array_push(args, janet_cstringv(argv[i])); + janet_def(env, "process/args", janet_wrap_array(args), "Command line arguments."); + /* Run bootstrap script to generate core image */ status = janet_dobytes(env, janet_gen_boot, janet_gen_boot_size, "boot.janet", NULL); diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 9d1f31fc..37a9eeff 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -16,6 +16,15 @@ # everything else goes. Cfunctions and abstracts will be referenced from a registry # table which will be generated on janet startup. (do + + # Get process options + (def- process/opts @{}) + (each [k v] (partition 2 (tuple/slice process/args 2)) + (put process/opts k v)) + + # Set up default config from arguments + (set module/*syspath* (or (process/opts "JANET_PATH") "")) + (def image (let [env-pairs (pairs (env-lookup *env*)) essential-pairs (filter (fn [[k v]] (or (cfunction? v) (abstract? v))) env-pairs) lookup (table ;(mapcat identity essential-pairs)) @@ -26,7 +35,7 @@ # can be compiled and linked statically into the main janet library # and example client. (def chunks (string/bytes image)) - (def image-file (file/open "build/core_image.c" :w)) + (def image-file (file/open (process/args 1) :w)) (file/write image-file "#ifndef JANET_AMALG\n" "#include <janet.h>\n" diff --git a/src/core/core.janet b/src/core/core.janet index cb7f1158..f7178c8e 100644 --- a/src/core/core.janet +++ b/src/core/core.janet @@ -1584,7 +1584,7 @@ "The path where globally installed libraries are located. The default is set at build time and is /usr/local/lib/janet on linux/posix, and on Windows is C:/Janet/Library." - (or (os/getenv "JANET_PATH") "")) + "") (defn- fexists [path] (def f (file/open path)) diff --git a/src/core/corelib.c b/src/core/corelib.c index 81b47c89..6437c1e3 100644 --- a/src/core/corelib.c +++ b/src/core/corelib.c @@ -831,12 +831,10 @@ JanetTable *janet_core_env(JanetTable *replacements) { janet_lib_inttypes(env); #endif - #ifdef JANET_BOOTSTRAP /* Run bootstrap source */ janet_dobytes(env, janet_gen_core, janet_gen_core_size, "core.janet", NULL); #else - /* Unmarshal from core image */ Janet marsh_out = janet_unmarshal( janet_core_image, |
