From 17f9223d14bd7d0a71608eccfd45772df0a3a685 Mon Sep 17 00:00:00 2001 From: Chloe Kudryavtsev Date: Sun, 16 Apr 2023 16:08:20 -0400 Subject: meta: improve build system use pkg-config! the main concern at this point is whether or not adding a "--static" is safe. if you don't add "--static", there's no guarantee of static linking. however, if you do add "--static" but not all of the libraries in question are available in static form, it will fail to build. the likely correct way to approach this is to use an env var. furthermore, I'm not entirely sure as to how/whether the link flags get passed on to upstream packages. --- project.janet | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/project.janet b/project.janet index 7c6f59a..6bc1246 100644 --- a/project.janet +++ b/project.janet @@ -6,10 +6,39 @@ :repo "https://github.com/CosmicToast/jurl.git" :dependencies ["spork"]) +(declare-source + :source ["jurl"]) + +# --- jurl/native +(defn- execute + [& args] + (try + (let [p (os/spawn args :p {:out :pipe :err :pipe}) + r (os/proc-wait p)] + {:status r + :out (:read (p :out) :all) + :err (:read (p :err) :all)}) + ([e] {:status false + :error e}))) +(def pkgconf (let [bin? |(if ((execute $) :status) $ false) + bin (or (bin? "pkgconf") (bin? "pkg-config"))] + (fn pkgconf + [defval & args] + (if bin + (string/split " " (-> bin + (execute ;args) + (get :out) + (string/trim))) + defval)))) +(def curl-cflags (pkgconf [] + "libcurl" "--cflags" "--static")) +(def curl-ldflags (pkgconf ["-lcurl"] + "libcurl" "--libs" "--static")) + (declare-native :name "jurl/native" - :cflags [;default-cflags] - :lflags [;default-lflags "-lcurl"] + :cflags [;default-cflags ;curl-cflags] + :ldflags [;default-lflags ;curl-ldflags] :headers ["src/jurl.h"] :source ["src/main.c" "src/jurl.c" @@ -21,6 +50,3 @@ "src/mime.c" "src/setopt.c" "src/util.c"]) - -(declare-source - :source ["jurl"]) -- cgit v1.2.3