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

Change pthreads linking with jpm, make, and meson.

Try to add pthread deps when compiling programs with jpm.
This commit is contained in:
Calvin Rose 2019-11-27 14:52:20 -06:00
parent e542ba7e4d
commit 8a91c52fa2
3 changed files with 19 additions and 10 deletions

View File

@ -28,7 +28,7 @@ INCLUDEDIR?=$(PREFIX)/include
BINDIR?=$(PREFIX)/bin BINDIR?=$(PREFIX)/bin
LIBDIR?=$(PREFIX)/lib LIBDIR?=$(PREFIX)/lib
JANET_BUILD?="\"$(shell git log --pretty=format:'%h' -n 1)\"" JANET_BUILD?="\"$(shell git log --pretty=format:'%h' -n 1)\""
CLIBS=-lm CLIBS=-lm -lpthread
JANET_TARGET=build/janet JANET_TARGET=build/janet
JANET_LIBRARY=build/libjanet.so JANET_LIBRARY=build/libjanet.so
JANET_STATIC_LIBRARY=build/libjanet.a JANET_STATIC_LIBRARY=build/libjanet.a
@ -37,7 +37,7 @@ MANPATH?=$(PREFIX)/share/man/man1/
PKG_CONFIG_PATH?=$(LIBDIR)/pkgconfig PKG_CONFIG_PATH?=$(LIBDIR)/pkgconfig
DEBUGGER=gdb DEBUGGER=gdb
CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fPIC -O2 -fvisibility=hidden -pthread \ CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fPIC -O2 -fvisibility=hidden \
-DJANET_BUILD=$(JANET_BUILD) -DJANET_BUILD=$(JANET_BUILD)
LDFLAGS=-rdynamic LDFLAGS=-rdynamic

View File

@ -112,6 +112,10 @@
(def default-linker (if is-win "link" "cc")) (def default-linker (if is-win "link" "cc"))
(def default-archiver (if is-win "lib" "ar")) (def default-archiver (if is-win "lib" "ar"))
# Detect threads
(def env (fiber/getenv (fiber/current)))
(def threads? (not (not (env 'threads/from-image))))
# Default flags for natives, but not required # Default flags for natives, but not required
(def default-lflags (if is-win ["/nologo"] [])) (def default-lflags (if is-win ["/nologo"] []))
(def default-cflags (def default-cflags
@ -119,6 +123,10 @@
["/nologo" "/MD"] ["/nologo" "/MD"]
["-std=c99" "-Wall" "-Wextra"])) ["-std=c99" "-Wall" "-Wextra"]))
# Link to pthreads
(def- thread-flags (if is-win [] (if threads? ["-lpthread"] [])))
# Required flags for dynamic libraries. These # Required flags for dynamic libraries. These
# are used no matter what for dynamic libraries. # are used no matter what for dynamic libraries.
(def- dynamic-cflags (def- dynamic-cflags
@ -127,10 +135,10 @@
["-fPIC"])) ["-fPIC"]))
(def- dynamic-lflags (def- dynamic-lflags
(if is-win (if is-win
["/DLL"] ["/DLL" ;thread-flags]
(if is-mac (if is-mac
["-shared" "-undefined" "dynamic_lookup"] ["-shared" "-undefined" "dynamic_lookup" ;thread-flags]
["-shared"]))) ["-shared" ;thread-flags])))
(defn- opt (defn- opt
"Get an option, allowing overrides via dynamic bindings AND some "Get an option, allowing overrides via dynamic bindings AND some

View File

@ -30,6 +30,7 @@ header_path = join_paths(get_option('prefix'), get_option('includedir'), 'janet'
cc = meson.get_compiler('c') cc = meson.get_compiler('c')
m_dep = cc.find_library('m', required : false) m_dep = cc.find_library('m', required : false)
dl_dep = cc.find_library('dl', required : false) dl_dep = cc.find_library('dl', required : false)
thread_dep = dependency('threads')
# Link options # Link options
if build_machine.system() != 'windows' if build_machine.system() != 'windows'
@ -156,7 +157,7 @@ mainclient_src = [
janet_boot = executable('janet-boot', core_src, boot_src, boot_gen, janet_boot = executable('janet-boot', core_src, boot_src, boot_gen,
include_directories : incdir, include_directories : incdir,
c_args : '-DJANET_BOOTSTRAP', c_args : '-DJANET_BOOTSTRAP',
dependencies : [m_dep, dl_dep], dependencies : [m_dep, dl_dep, thread_dep],
native : true) native : true)
# Build core image # Build core image
@ -167,7 +168,7 @@ core_image = custom_target('core_image',
libjanet = library('janet', core_src, core_image, libjanet = library('janet', core_src, core_image,
include_directories : incdir, include_directories : incdir,
dependencies : [m_dep, dl_dep], dependencies : [m_dep, dl_dep, thread_dep],
install : true) install : true)
# Extra c flags - adding -fvisibility=hidden matches the Makefile and # Extra c flags - adding -fvisibility=hidden matches the Makefile and
@ -187,14 +188,14 @@ endif
janet_mainclient = executable('janet', core_src, core_image, mainclient_src, janet_mainclient = executable('janet', core_src, core_image, mainclient_src,
include_directories : incdir, include_directories : incdir,
dependencies : [m_dep, dl_dep], dependencies : [m_dep, dl_dep, thread_dep],
c_args : extra_native_cflags, c_args : extra_native_cflags,
install : true) install : true)
if meson.is_cross_build() if meson.is_cross_build()
janet_nativeclient = executable('janet-native', core_src, core_image, mainclient_src, janet_nativeclient = executable('janet-native', core_src, core_image, mainclient_src,
include_directories : incdir, include_directories : incdir,
dependencies : [m_dep, dl_dep], dependencies : [m_dep, dl_dep, thread_dep],
c_args : extra_cross_cflags, c_args : extra_cross_cflags,
native : true) native : true)
else else
@ -224,7 +225,7 @@ amalg_shell = custom_target('amalg-shell',
# Amalgamated client # Amalgamated client
janet_amalgclient = executable('janet-amalg', amalg, amalg_shell, janet_amalgclient = executable('janet-amalg', amalg, amalg_shell,
include_directories : incdir, include_directories : incdir,
dependencies : [m_dep, dl_dep], dependencies : [m_dep, dl_dep, thread_dep],
build_by_default : false) build_by_default : false)
# Tests # Tests