From 348f30d4a9e7148166d2ff518b665e95f5f48ae0 Mon Sep 17 00:00:00 2001 From: Chloe Kudryavtsev Date: Sun, 16 Apr 2023 17:08:11 -0400 Subject: meta: test for ability to build statically --- project.janet | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/project.janet b/project.janet index b0e1994..643d00d 100644 --- a/project.janet +++ b/project.janet @@ -20,6 +20,15 @@ :err (:read (p :err) :all)}) ([e] {:status false :error e}))) +(defn- compiles? + [& flags] + (let [[inr inw] (os/pipe) + [_ out] (os/pipe) + [_ err] (os/pipe) + _ (:write inw "int main(){}")] + (zero? (os/execute ["cc" "-" "-xc" "-o/dev/null" ;flags] + :p + {:err err :in inr :out out})))) (def pkgconf (let [bin? |(if ((execute $) :status) $ false) bin (or (bin? "pkgconf") (bin? "pkg-config"))] (fn pkgconf @@ -38,11 +47,13 @@ ldflags (partial pkgconf ["-lcurl"] "libcurl" "--libs") curl-c (cflags) curl-l (ldflags) - scurl-c (cflags "--static") - scurl-l (cflags "--static")] - # TODO: test scurl-c and scurl-l to pass those if applicable - {:cflags curl-c - :ldflags curl-l})) + scurl-c (cflags "--static") + scurl-l (ldflags "--static")] + (if (compiles? ;scurl-c ;scurl-l) + {:cflags scurl-c + :ldflags scurl-l} + {:cflags curl-c + :ldflags curl-l}))) (declare-native :name "jurl/native" -- cgit v1.2.3