From b4ddbd0097cb446bdcc4468e51d3351508be5157 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 29 Apr 2021 14:04:18 -0500 Subject: [PATCH] Address #670 - Allow modifying jpm to link to extra libraries. --- CHANGELOG.md | 1 + jpm | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcd5cd0c..c4433024 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to this project will be documented in this file. ## ??? - Unreleased +- Expose `JANET_OUT_OF_MEMORY` as part of the Janet API. - Add `native-deps` option to `decalre-native` in `jpm`. This lets native libraries link to other native libraries when building with jpm. - Remove the `tarray` module. The functionality of typed arrays will be moved to an external module diff --git a/jpm b/jpm index fe53ac41..47f27885 100755 --- a/jpm +++ b/jpm @@ -51,6 +51,12 @@ :libpath (try-real (string exe-dir "/../lib")) :binpath exe-dir}) +# If janetconf.h has been modified such that core janet functions and macros require +# linking to external libraries, modify this. +# +# Example - (def- extra-lflags ["-lmimalloc"]) +(def- extra-lflags []) + ###END### # Default based on janet binary location @@ -363,10 +369,10 @@ # executables. (def janet-lflags (case (os/which) - :macos ["-ldl" "-lm" ;thread-flags] - :windows [;thread-flags] - :linux ["-lm" "-ldl" "-lrt" ;thread-flags] - ["-lm" ;thread-flags])) + :macos ["-ldl" "-lm" ;thread-flags ;extra-lflags] + :windows [;thread-flags ;extra-lflags] + :linux ["-lm" "-ldl" "-lrt" ;thread-flags ;extra-lflags] + ["-lm" ;thread-flags ;extra-lflags])) (def janet-ldflags []) (def janet-cflags []) @@ -534,13 +540,15 @@ ;(if (opts :static) [] dynamic-lflags)]) (def deplibs (get opts :native-deps [])) (def dep-ldflags (seq [x :in deplibs] (string (dyn :modpath JANET_MODPATH) sep x modext))) + # Use import libs on windows - we need an import lib to link natives to other natives. + (def dep-importlibs (seq [x :in deplibs] (string (dyn :modpath JANET_MODPATH) sep x ".lib"))) (def ldflags [;(opt opts :ldflags []) ;dep-ldflags]) (rule target objects (check-cc) (print "linking " target "...") (create-dirs target) (if is-win - (shell linker ;ldflags (string "/OUT:" target) ;objects (win-import-library) ;lflags) + (shell linker ;ldflags (string "/OUT:" target) ;objects (win-import-library) ;dep-importlibs ;lflags) (shell linker ;cflags ;ldflags `-o` target ;objects ;lflags)))) (defn- archive-c