From 6ae5a9be60cfff4c8fcd31cfec08458e81455934 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sat, 5 Oct 2019 10:38:58 -0500 Subject: [PATCH] Add -fvisibility in Makefile, provide meson example commands. Shaves off 10 kb in binary. Also -fpic -> -fPIC in Makefile and jpm. --- Makefile | 2 +- README.md | 19 +++++++++++++++++++ auxbin/jpm | 2 +- meson.build | 17 +++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c7a89359..c66720a5 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ MANPATH?=$(PREFIX)/share/man/man1/ PKG_CONFIG_PATH?=$(LIBDIR)/pkgconfig DEBUGGER=gdb -CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fpic -O2 -fvisibility=hidden \ +CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fPIC -O2 -fvisibility=hidden \ -DJANET_BUILD=$(JANET_BUILD) LDFLAGS=-rdynamic diff --git a/README.md b/README.md index f897c191..de10b7bc 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,25 @@ is maybe more convenient and flexible for integrating into existing pipelines. Meson also provides much better IDE integration than Make or batch files, as well as support for cross compilation. +For the impatient, building with Meson is as simple as follows. The options provided to +`meson setup` below emulate Janet's Makefile. + +```sh +git clone https://github.com/janet-lang/janet.git +cd janet +meson setup build \ + --buildtype release \ + --optimization 2 \ + -Dgit_hash=$(git log --pretty=format:'%h' -n 1) +ninja -C build + +# Run the binary +build/janet + +# Installation +ninja -C build install +``` + ## Development Janet can be hacked on with pretty much any environment you like, but for IDE diff --git a/auxbin/jpm b/auxbin/jpm index 71866f43..120632eb 100755 --- a/auxbin/jpm +++ b/auxbin/jpm @@ -124,7 +124,7 @@ (def- dynamic-cflags (if is-win [] - ["-fpic"])) + ["-fPIC"])) (def- dynamic-lflags (if is-win ["/DLL"] diff --git a/meson.build b/meson.build index a1cb2913..0c7e7b41 100644 --- a/meson.build +++ b/meson.build @@ -170,15 +170,32 @@ libjanet = library('janet', core_src, core_image, dependencies : [m_dep, dl_dep], install : true) +# Extra c flags - adding -fvisibility=hidden matches the Makefile and +# shaves off about 10k on linux x64, likely similar on other platforms. +native_cc = meson.get_compiler('c', native: true) +cross_cc = meson.get_compiler('c', native: false) +if native_cc.has_argument('-fvisibility=hidden') + extra_native_cflags = ['-fvisibility=hidden'] +else + extra_native_cflags = [] +endif +if cross_cc.has_argument('-fvisibility=hidden') + extra_cross_cflags = ['-fvisibility=hidden'] +else + extra_cross_cflags = [] +endif + janet_mainclient = executable('janet', core_src, core_image, init_gen, mainclient_src, include_directories : incdir, dependencies : [m_dep, dl_dep], + c_args : extra_native_cflags, install : true) if meson.is_cross_build() janet_nativeclient = executable('janet-native', core_src, core_image, init_gen, mainclient_src, include_directories : incdir, dependencies : [m_dep, dl_dep], + c_args : extra_cross_cflags, native : true) else janet_nativeclient = janet_mainclient