diff options
| author | 2025-03-24 18:49:46 -0500 | |
|---|---|---|
| committer | 2025-03-24 18:49:46 -0500 | |
| commit | cf15d03a797177829e8947fe82dda846d4d076f2 (patch) | |
| tree | 7e3a6f1ec407454c6c1b0482f1413d13e16540d2 | |
| parent | Add more features to the simple project in pm. (diff) | |
Move pathing autodetection to cc.janet.janet-pm-config
Also add some checks for important files like janet.h to
make sure that the resulting paths are correct.
| -rwxr-xr-x | bin/janet-pm | 3 | ||||
| -rw-r--r-- | man/janet-pm.1 | 10 | ||||
| -rw-r--r-- | spork/cc.janet | 66 | ||||
| -rw-r--r-- | spork/declare-cc.janet | 44 | ||||
| -rw-r--r-- | spork/pm-config.janet | 2 |
5 files changed, 70 insertions, 55 deletions
diff --git a/bin/janet-pm b/bin/janet-pm index 8810851..95f0b3c 100755 --- a/bin/janet-pm +++ b/bin/janet-pm @@ -87,9 +87,6 @@ janet-pm inherits all of the environment variables used by janet, as well some of its own. Many of these are only used in support of building bundles that use a project.janet. - JANET_BINPATH - Where to install executables and scripts. By default, will store them at in $SYSPATH/bin. - JANET_BUILD_DIR Where to create build outputs when building a bundle has a project.janet. Defaults to _build. diff --git a/man/janet-pm.1 b/man/janet-pm.1 index 97ac245..83f8f79 100644 --- a/man/janet-pm.1 +++ b/man/janet-pm.1 @@ -107,11 +107,6 @@ Install all bundles in the given lockfile. janet-pm inherits all of the environment variables used by janet, as well some of its own. Many of these are only used in support of building bundles that use a project.janet. -.B JANET_BINPATH -.RS -Where to install executables and scripts. By default, will store them at in $SYSPATH/bin. -.RE - .B JANET_BUILD_DIR .RS Where to create build outputs when building a bundle has a project.janet. Defaults to _build. @@ -139,11 +134,6 @@ The directory that the MSVC toolchain will use to find janet.h, janet.dll, and l there is a non-standard windows install or possibly multiple Janet versions installed. .RE -.B JANET_MANPATH -.RS -Where to install manpages. By default, will store them at in $SYSPATH/man. -.RE - .B JANET_OFFLINE .RS If set to 1, true, on, etc., will only look at packages in the local cache. diff --git a/spork/cc.janet b/spork/cc.janet index d0b60ff..98832f4 100644 --- a/spork/cc.janet +++ b/spork/cc.janet @@ -56,6 +56,52 @@ (defdyn *c++-std* "C++ standard to use as a 2 digit number, defaults to 11 on GCC-like compilers, 14 on msvc.") (defdyn *rules* "Rules to use with visit-add-rule") (defdyn *vcvars-cache* "Where to cache vcvars once we have calculated them") +(defdyn *janet-prefix* "Path prefix used to detect where to find libjanet, janet.h, etc.") + +### +### Prefix detection +### + +(defn get-unix-prefix + "Auto-detect what prefix to use for finding libjanet.so, headers, etc. on unix systems" + [] + (if-let [p (dyn *janet-prefix*)] (break p)) + (var result nil) + (each test [(os/getenv "JANET_PREFIX") + (os/getenv "PREFIX") + (path/join (dyn *syspath*) ".." "..") + (path/join (dyn *syspath*) "..") + (dyn *syspath*) + "/usr/" + "/usr/local" + "/"] + (when test + (def headercheck (path/join test "include" "janet.h")) + (when (os/stat headercheck :mode) + (set result test) + (break)))) + (assert result "no prefix discovered for janet headers!") + (setdyn *janet-prefix* result) + result) + +(defn get-windows-prefix + "Auto-detect install location on windows systems with a default install. This is the directory containing Library, C, docs, bin, etc." + [] + (if-let [p (dyn *janet-prefix*)] (break p)) + (var result nil) + (each test [(os/getenv "JANET_PREFIX") + (os/getenv "PREFIX") + (path/join (dyn *syspath*) ".." "..") + (path/join (dyn *syspath*) "..") + (dyn *syspath*)] + (when test + (def headercheck (path/join test "C" "janet.h")) + (when (os/stat headercheck :mode) + (set result test) + (break)))) + (assert result "no prefix discovered for janet headers!") + (setdyn *janet-prefix* result) + result) ### ### Universal helpers for all toolchains @@ -79,32 +125,26 @@ (defn- lib-path [] "Guess a library path based on the current system path" - (def sp (dyn *syspath* ".")) - (def parts (path/parts sp)) - (if (= "janet" (last parts)) - (path/abspath (string sp "/..")) - (path/abspath "."))) + (def prefix (get-unix-prefix)) + (path/join prefix "lib")) (defn- include-path [] "Guess a header path based on the current system path" - (def lp (lib-path)) - (if lp - (path/join lp "../include"))) + (def prefix (get-unix-prefix)) + (path/join prefix "include")) (defn- msvc-cpath "Guess a library and header path for msvc with a defualt Janet windows install." [] (when-let [p (dyn *msvc-cpath*)] (break p)) (when-let [p (os/getenv "JANET_LIBPATH")] (break p)) - (def sp (dyn *syspath* ".")) - (def parts (path/parts sp)) - (if (= "Library" (last parts)) - (path/abspath (string sp "\\..\\C\\")))) + (def wp (get-windows-prefix)) + (path/join wp "C")) (defn msvc-janet-import-lib "Get path to the installed Janet import lib. This import lib is needed when create dlls for natives." [] - (string (msvc-cpath) "\\janet.lib")) + (path/join (msvc-cpath) "janet.lib")) (defn- default-exec [&]) (defn- exec diff --git a/spork/declare-cc.janet b/spork/declare-cc.janet index a650d9c..8a828a6 100644 --- a/spork/declare-cc.janet +++ b/spork/declare-cc.janet @@ -19,9 +19,6 @@ (import ./sh) (import ./pm-config) -(defdyn *binpath* "Path to install scripts and executables to") -(defdyn *manpath* "Path to install man pages to") -(defdyn *prefix* "Path prefix used to detect where to find libjanet, janet.h, etc.") (defdyn *install-manifest* "Bound to the bundle manifest during a bundle/install.") (defdyn *toolchain* "Force a given toolchain. If unset, will auto-detect.") (defdyn *build-root* "Root build directory that will contain all built artifacts") @@ -29,27 +26,13 @@ (defn- build-root [] (dyn *build-root* "_build")) (defn- build-dir [] (path/join (build-root) (dyn cc/*build-type* :release))) (defn- get-rules [] (dyn cc/*rules* (curenv))) -(defn- bindir [] (or (dyn *binpath*) (path/join (dyn *syspath*) "bin"))) -(defn- mandir [] (or (dyn *manpath*) (path/join (dyn *syspath*) "man"))) +(defn- bindir [] (path/join (dyn *syspath*) "bin")) +(defn- mandir [] (path/join (dyn *syspath*) "man")) (defn- mkbin [] (def x (bindir)) (fn :make-bin [] (sh/create-dirs x))) (defn- mkman [] (def x (mandir)) (fn :make-man [] (sh/create-dirs x))) (defn- bindir-rel [] (path/relpath (dyn *syspath*) (bindir))) (defn- mandir-rel [] (path/relpath (dyn *syspath*) (mandir))) -(defn- get-prefix - "Auto-detect what prefix to use for finding libjanet.so, headers, etc." - [] - (if-let [p (dyn *prefix*)] (break p)) - (var result nil) - (each test [(path/join (dyn *syspath*) "..") "/usr/" "/usr/local"] - (def headercheck (path/join test "include" "janet.h")) - (when (os/stat headercheck :mode) - (set result test) - (break))) - (assert result "no prefix discovered for janet headers!") - (setdyn *prefix* result) - result) - (defn- is-win-or-mingw [] (def tos (dyn cc/*target-os* (os/which))) @@ -791,17 +774,24 @@ int main(int argc, const char **argv) { # Extra command line options for building executable statically linked with libjanet (def msvc-libs-extra @[]) - (def prefix (if (= toolchain :msvc) (dyn *syspath*) (get-prefix))) - (def headerpath (path/join prefix "include")) - (def libpath (path/join prefix "lib")) - (def libjanet (path/join libpath "libjanet.a")) - (def msvc-libjanet (path/join (os/getenv "JANET_LIBPATH" "") "libjanet.lib")) (def other-cflags @[]) (if (= toolchain :msvc) (do - (array/push other-cflags (string "/I" headerpath)) + (def libpath (os/getenv "JANET_LIBPATH" "")) + (def msvc-libjanet (path/join libpath "libjanet.lib")) + (def janeth (path/join libpath "janet.h")) + (assert (= (os/stat janeth :mode) :file) "janet.h not found in expected location, possible misconfiguration") + (assert (= (os/stat msvc-libjanet :mode) :file) "libjanet.lib not found in expected location, possible misconfiguration") + (array/push other-cflags (string "/I" libpath)) (array/push msvc-libs-extra msvc-libjanet)) (do + (def prefix (cc/get-unix-prefix)) + (def headerpath (path/join prefix "include")) + (def libpath (path/join prefix "lib")) + (def libjanet (path/join libpath "libjanet.a")) + (def janeth (path/join headerpath "janet.h")) + (assert (= (os/stat janeth :mode) :file) "janet.h not found in expected location, possible misconfiguration") + (assert (= (os/stat libjanet :mode) :file) "libjanet.a not found in expected location, possible misconfiguration") (array/push other-cflags (string "-I" headerpath) (string "-L" libpath)) (array/push dep-libs libjanet))) @@ -878,8 +868,8 @@ int main(int argc, const char **argv) { (def- path (require "./path")) (defn jpm-shim-env "Create an environment table that can evaluate project.janet files" - [] - (def e (curenv)) + [&opt e] + (default e (curenv)) (pm-config/read-env-variables e) # TODO - one for one naming with jpm (merge-module e sh) diff --git a/spork/pm-config.janet b/spork/pm-config.janet index b8b2c85..4e07b2b 100644 --- a/spork/pm-config.janet +++ b/spork/pm-config.janet @@ -51,8 +51,6 @@ (default env (curenv)) (when (get env :is-configured) (break)) (set1 env :prefix "JANET_PREFIX") - (set1 env :binpath "JANET_BINPATH") - (set1 env :manpath "JANET_MANPATH") (set1 env :gitpath "JANET_GIT") (set1 env :curlpath "JANET_CURL") (set1 env :tarpath "JANET_TAR") |
