From a29e717fd7f9bf31fe4219f0044041837823230d Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 20 Jun 2019 16:33:28 -0400 Subject: [PATCH] Start working to a full meson build. One build system instead of three for Make + Meson + build_win.bat. --- Makefile | 6 ++--- meson.build | 44 +++++++++++++++++++++++++++---- meson_options.txt | 17 ++++++++++++ src/{include => conf}/janetconf.h | 13 ++++++--- 4 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 meson_options.txt rename src/{include => conf}/janetconf.h (91%) diff --git a/Makefile b/Makefile index 4abe0ecc..e71c2933 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ MANPATH?=$(PREFIX)/share/man/man1/ PKG_CONFIG_PATH?=$(PREFIX)/lib/pkgconfig DEBUGGER=gdb -CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -fpic -O2 -fvisibility=hidden \ +CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fpic -O2 -fvisibility=hidden \ -DJANET_BUILD=$(JANET_BUILD) LDFLAGS=-rdynamic @@ -60,7 +60,7 @@ all: $(JANET_TARGET) $(JANET_LIBRARY) $(JANET_STATIC_LIBRARY) ##### Name Files ##### ###################### -JANET_HEADERS=src/include/janet.h src/include/janetconf.h +JANET_HEADERS=src/include/janet.h src/conf/janetconf.h JANET_LOCAL_HEADERS=src/core/util.h \ src/core/state.h \ @@ -252,7 +252,7 @@ callgrind: $(JANET_TARGET) dist: build/janet-dist.tar.gz build/janet-%.tar.gz: $(JANET_TARGET) \ - src/include/janet.h src/include/janetconf.h \ + src/include/janet.h src/conf/janetconf.h \ janet.1 LICENSE CONTRIBUTING.md $(JANET_LIBRARY) $(JANET_STATIC_LIBRARY) \ build/doc.html README.md build/janet.c tar -czvf $@ $^ diff --git a/meson.build b/meson.build index d3e33e1b..100aaafa 100644 --- a/meson.build +++ b/meson.build @@ -18,8 +18,11 @@ # 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', 'b_lundef=false', 'default_library=both'], - version : '1.0.0') +project('janet', 'c', + default_options : ['c_std=c99', 'b_lundef=false', 'default_library=both', + 'strip=true', 'optimization=2', 'werror=true', + 'debug=false'], + version : '1.0.0-dev') # Global settings janet_path = join_paths(get_option('prefix'), get_option('libdir'), 'janet') @@ -30,11 +33,42 @@ cc = meson.get_compiler('c') m_dep = cc.find_library('m', required : false) dl_dep = cc.find_library('dl', required : false) -# Some options +# Link options add_project_link_arguments('-rdynamic', language : 'c') +# Generate custom janetconf.h +conf = configuration_data() +version_parts = meson.project_version().split('.') +last_parts = version_parts[2].split('-') +if last_parts.length() > 1 + conf.set_quoted('JANET_VERSION_EXTRA', '-' + last_parts[1]) +else + conf.set_quoted('JANET_VERSION_EXTRA', '') +endif +conf.set('JANET_VERSION_MAJOR', version_parts[0].to_int()) +conf.set('JANET_VERSION_MINOR', version_parts[1].to_int()) +conf.set('JANET_VERSION_PATCH', last_parts[0].to_int()) +conf.set_quoted('JANET_VERSION', meson.project_version()) +# Use options +conf.set_quoted('JANET_BUILD', get_option('build_hash')) +conf.set('JANET_NO_NANBOX', not get_option('nanbox')) +conf.set('JANET_SINGLE_THREADED', not get_option('single_threaded')) +conf.set('JANET_NO_DYNAMIC_MODULES', not get_option('dynamic_modules')) +conf.set('JANET_NO_DOCSTRINGS', not get_option('docstrings')) +conf.set('JANET_NO_SOURCEMAPS', not get_option('sourcemaps')) +conf.set('JANET_NO_ASSEMBLER', not get_option('assembler')) +conf.set('JANET_NO_PEG', not get_option('peg')) +conf.set('JANET_NO_TYPED_ARRAY', not get_option('typed_array')) +conf.set('JANET_NO_INT_TYPES', not get_option('int_types')) +conf.set('JANET_RECURSION_GUARD', get_option('recursion_guard')) +conf.set('JANET_MAX_PROTO_DEPTH', get_option('max_proto_depth')) +conf.set('JANET_MAX_MACRO_EXPAND', get_option('max_macro_expand')) +conf.set('JANET_STACK_MAX', get_option('stack_max')) +jconf = configure_file(output : 'janetconf.h', + configuration : conf) + # Include directories -incdir = include_directories('src/include') +incdir = include_directories(['src/include', '.']) # Building generated sources xxd = executable('xxd', 'tools/xxd.c', native : true) @@ -186,7 +220,7 @@ janet_dep = declare_dependency(include_directories : incdir, # Installation install_man('janet.1') -install_headers('src/include/janet.h', 'src/include/janetconf.h', subdir: 'janet') +install_headers(['src/include/janet.h', jconf], subdir: 'janet') janet_libs = [ 'auxlib/cook.janet', 'auxlib/path.janet' diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 00000000..615d80b0 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,17 @@ +option('build_hash', type : 'string', value : 'meson') + +option('single_threaded', type : 'boolean', value : false) +option('nanbox', type : 'boolean', value : true) +option('dynamic_modules', type : 'boolean', value : true) +option('docstrings', type : 'boolean', value : true) +option('sourcemaps', type : 'boolean', value : true) +option('reduced_os', type : 'boolean', value : true) +option('assembler', type : 'boolean', value : true) +option('peg', type : 'boolean', value : true) +option('typed_array', type : 'boolean', value : true) +option('int_types', type : 'boolean', value : true) + +option('recursion_guard', type : 'integer', min : 10, max : 8000, value : 1024) +option('max_proto_depth', type : 'integer', min : 10, max : 8000, value : 200) +option('max_macro_expand', type : 'integer', min : 1, max : 8000, value : 200) +option('stack_max', type : 'integer', min : 8096, max : 1000000000, value : 16384) diff --git a/src/include/janetconf.h b/src/conf/janetconf.h similarity index 91% rename from src/include/janetconf.h rename to src/conf/janetconf.h index d90fe0ad..4db17718 100644 --- a/src/include/janetconf.h +++ b/src/conf/janetconf.h @@ -20,7 +20,8 @@ * IN THE SOFTWARE. */ -/* Configure Janet. Edit this file to customize the build */ +/* This is an example janetconf.h file. This will be usually generated + * by the build system. */ #ifndef JANETCONF_H #define JANETCONF_H @@ -39,13 +40,17 @@ /* #define JANET_NO_NANBOX */ /* #define JANET_API __attribute__((visibility ("default"))) */ +/* These settings should be specified before amalgamation is + * built. */ +/* #define JANET_NO_DOCSTRINGS */ +/* #define JANET_NO_SOURCEMAPS */ +/* #define JANET_REDUCED_OS */ + +/* Other settings */ /* #define JANET_NO_ASSEMBLER */ /* #define JANET_NO_PEG */ /* #define JANET_NO_TYPED_ARRAY */ /* #define JANET_NO_INT_TYPES */ -/* #define JANET_NO_DOCSTRINGS */ -/* #define JANET_NO_SOURCEMAPS */ -/* #define JANET_REDUCED_OS */ /* #define JANET_OUT_OF_MEMORY do { printf("janet out of memory\n"); exit(1); } while (0) */ /* #define JANET_RECURSION_GUARD 1024 */ /* #define JANET_MAX_PROTO_DEPTH 200 */