1
0
mirror of https://github.com/janet-lang/janet synced 2025-12-16 13:38:06 +00:00

Add some more bindings for jpm for future proofing.

This commit is contained in:
Calvin Rose
2020-06-14 11:01:07 -05:00
parent 0b114d680e
commit 80f29ae859

52
jpm
View File

@@ -310,26 +310,30 @@
# Detect threads # Detect threads
(def env (fiber/getenv (fiber/current))) (def env (fiber/getenv (fiber/current)))
(def threads? (not (not (env 'thread/new)))) (def threads? (not (not (env 'thread/new))))
# Default libraries to link
(def- thread-flags (def- thread-flags
(if is-win [] (if is-win []
(if threads? ["-lpthread"] []))) (if threads? ["-lpthread"] [])))
# lflags needed for the janet binary. # flags needed for the janet binary and compiling standalone
# executables.
(def janet-lflags (def janet-lflags
(case (os/which) (case (os/which)
:macos ["-ldl" "-lm" ;thread-flags] :macos ["-ldl" "-lm" ;thread-flags]
:windows [;thread-flags] :windows [;thread-flags]
:linux ["-lm" "-ldl" "-lrt" ;thread-flags] :linux ["-lm" "-ldl" "-lrt" ;thread-flags]
["-lm" ;thread-flags])) ["-lm" ;thread-flags]))
(def janet-ldflags [])
(def janet-cflags [])
# Default flags for natives, but not required # Default flags for natives, but not required
# How can we better detect the need for -pthread?
# we probably want to better detect compiler
(def default-lflags (if is-win ["/nologo"] [])) (def default-lflags (if is-win ["/nologo"] []))
(def default-cflags (def default-cflags
(if is-win (if is-win
["/nologo" "/MD"] ["/nologo" "/MD"]
["-std=c99" "-Wall" "-Wextra"])) ["-std=c99" "-Wall" "-Wextra"]))
(def default-ldflags [])
# 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.
@@ -339,7 +343,7 @@
["-fPIC"])) ["-fPIC"]))
(def- dynamic-lflags (def- dynamic-lflags
(if is-win (if is-win
["/DLL" ;thread-flags] ["/DLL"]
(if is-mac (if is-mac
["-shared" "-undefined" "dynamic_lookup" ;thread-flags] ["-shared" "-undefined" "dynamic_lookup" ;thread-flags]
["-shared" ;thread-flags]))) ["-shared" ;thread-flags])))
@@ -385,8 +389,8 @@
"Generate strings for adding custom defines to the compiler." "Generate strings for adding custom defines to the compiler."
[define value] [define value]
(if value (if value
(string (if is-win "/D" "-D") define "=" value) (string "-D" define "=" value)
(string (if is-win "/D" "-D") define))) (string "-D" define)))
(defn- make-defines (defn- make-defines
"Generate many defines. Takes a dictionary of defines. If a value is "Generate many defines. Takes a dictionary of defines. If a value is
@@ -398,8 +402,8 @@
"Generate the c flags from the input options." "Generate the c flags from the input options."
[opts] [opts]
@[;(opt opts :cflags default-cflags) @[;(opt opts :cflags default-cflags)
(string (if is-win "/I" "-I") (dyn :headerpath JANET_HEADERPATH)) (string "-I" (dyn :headerpath JANET_HEADERPATH))
(string (if is-win "/O" "-O") (opt opts :optimize 2))]) (string "-O" (opt opts :optimize 2))])
(defn- entry-name (defn- entry-name
"Name of symbol that enters static compilation of a module." "Name of symbol that enters static compilation of a module."
@@ -585,7 +589,8 @@ int main(int argc, const char **argv) {
# Create executable's janet image # Create executable's janet image
(def cimage_dest (string dest ".c")) (def cimage_dest (string dest ".c"))
(rule dest [source] (def no-compile (opts :no-compile))
(rule (if no-compile cimage_dest dest) [source]
(check-cc) (check-cc)
(print "generating executable c source...") (print "generating executable c source...")
(create-dirs dest) (create-dirs dest)
@@ -641,11 +646,11 @@ int main(int argc, const char **argv) {
# Append main function # Append main function
(spit cimage_dest (make-bin-source declarations lookup-into-invocations) :ab) (spit cimage_dest (make-bin-source declarations lookup-into-invocations) :ab)
# Compile and link final exectable # Compile and link final exectable
(do (unless no-compile
(def cc (opt opts :compiler default-compiler)) (def cc (opt opts :compiler default-compiler))
(def ldflags [;dep-ldflags ;(opt opts :ldflags [])]) (def ldflags [;dep-ldflags ;(opt opts :ldflags []) ;janet-ldflags])
(def lflags [;static-libs (libjanet) ;dep-lflags ;(opt opts :lflags default-lflags) ;janet-lflags]) (def lflags [;static-libs (libjanet) ;dep-lflags ;(opt opts :lflags default-lflags) ;janet-lflags])
(def cflags (getcflags opts)) (def cflags [;(getcflags opts) ;janet-cflags])
(def defines (make-defines (opt opts :defines {}))) (def defines (make-defines (opt opts :defines {})))
(print "compiling and linking " dest "...") (print "compiling and linking " dest "...")
(if is-win (if is-win
@@ -884,17 +889,22 @@ int main(int argc, const char **argv) {
is marshalled into bytecode which is then embedded in a final executable for distribution.\n\n is marshalled into bytecode which is then embedded in a final executable for distribution.\n\n
This executable can be installed as well to the --binpath given." This executable can be installed as well to the --binpath given."
[&keys {:install install :name name :entry entry :headers headers [&keys {:install install :name name :entry entry :headers headers
:cflags cflags :lflags lflags :deps deps :ldflags ldflags}] :cflags cflags :lflags lflags :deps deps :ldflags ldflags
:no-compile no-compile}]
(def name (if is-win (string name ".exe") name)) (def name (if is-win (string name ".exe") name))
(def dest (string "build" sep name)) (def dest (string "build" sep name))
(create-executable @{:cflags cflags :lflags lflags :ldflags ldflags} entry dest) (create-executable @{:cflags cflags :lflags lflags :ldflags ldflags :no-compile no-compile} entry dest)
(add-dep "build" dest) (if no-compile
(when headers (let [cdest (string dest ".c")]
(each h headers (add-dep dest h))) (add-dep "build" cdest))
(when deps (do
(each d deps (add-dep dest d))) (add-dep "build" dest)
(when install (when headers
(install-rule dest (dyn :binpath JANET_BINPATH)))) (each h headers (add-dep dest h)))
(when deps
(each d deps (add-dep dest d)))
(when install
(install-rule dest (dyn :binpath JANET_BINPATH))))))
(defn declare-binscript (defn declare-binscript
"Declare a janet file to be installed as an executable script. Creates "Declare a janet file to be installed as an executable script. Creates