diff --git a/bundle/build.janet b/bundle/build.janet new file mode 100644 index 0000000..9bfa042 --- /dev/null +++ b/bundle/build.janet @@ -0,0 +1,53 @@ +(import "/spork/cc" :as cc) + +(defn main + [& argv] + (os/mkdir "build") + (os/mkdir "build/objects") + + (def suffix + (case (os/which) + :windows ".dll" + ".so")) + + (def asuffix + (case (os/which) + :windows ".lib" + ".a")) + + (def cc + (case (os/which) + :windows cc/msvc-compile-and-link-shared + cc/compile-and-link-shared)) + + (def static-cc + (case (os/which) + :windows cc/msvc-compile-and-make-archive + cc/compile-and-make-archive)) + + (when (= :windows (os/which)) + (cc/msvc-find) + (assert (cc/msvc-setup?)) + (setdyn cc/*msvc-libs* @[(cc/msvc-janet-import-lib)])) + + (defn make1 + [name & other-srcs] + (def from (string "src/" name ".c")) + (def to (string "build/" name suffix)) + (def toa (string "build/" name asuffix)) + (cc to from ;other-srcs) + (static-cc toa from ;other-srcs)) + + (setdyn cc/*visit* cc/visit-execute-if-stale) + (setdyn cc/*build-dir* "build/objects") + (make1 "crc") + (make1 "json") + (make1 "cmath") + (make1 "utf8") + (make1 "rawterm") + (make1 "tarray") + (make1 "base64") + (setdyn cc/*defines* {"_LARGEFILE64_SOURCE" true}) + (make1 "zip" "deps/miniz/miniz.c") + + (print "done!")) diff --git a/bundle/clean.janet b/bundle/clean.janet new file mode 100644 index 0000000..7b4f1df --- /dev/null +++ b/bundle/clean.janet @@ -0,0 +1,5 @@ +(import "/spork/sh" :as sh) + +(defn main + [&] + (sh/rm "build")) diff --git a/bundle/init.janet b/bundle/init.janet index 77a039c..38bdeed 100644 --- a/bundle/init.janet +++ b/bundle/init.janet @@ -1,5 +1,15 @@ -(import "/spork/cc" :as cc) -(import "/spork/sh" :as sh) +(import ./test) +(import ./build :as b) +(import ./clean :as c) + +(defn clean [&] + (c/main)) + +(defn check [&] + (test/main)) + +(defn build [&] + (b/main)) (defn install [m &] (bundle/add-file m "src/tarray.h" "tarray.h") @@ -11,68 +21,3 @@ (def f (string "build/" file)) (when (= (os/stat f :mode) :file) (bundle/add-file m f (string "spork/" file))))) - -(defn clean [&] - (sh/rm "build")) - -(defn test [&] - (var failure-count 0) - (each suite (sorted (os/dir "test")) - (when (string/has-prefix? "suite-" suite) - (eprint "Running suite " suite) - (def result (os/execute [(dyn *executable*) (string "test/" suite)] :p)) - (if-not (zero? result) (++ failure-count)))) - (if (zero? failure-count) - (eprint "All Passed.") - (do (eprintf "Failures: %v" failure-count) (os/exit 1)))) - -(defn build [&] - (os/mkdir "build") - (os/mkdir "build/objects") - - (def suffix - (case (os/which) - :windows ".dll" - ".so")) - - (def asuffix - (case (os/which) - :windows ".lib" - ".a")) - - (def cc - (case (os/which) - :windows cc/msvc-compile-and-link-shared - cc/compile-and-link-shared)) - - (def static-cc - (case (os/which) - :windows cc/msvc-compile-and-make-archive - cc/compile-and-make-archive)) - - (when (= :windows (os/which)) - (cc/msvc-find) - (assert (cc/msvc-setup?)) - (setdyn cc/*msvc-libs* @[(cc/msvc-janet-import-lib)])) - - (defn make1 - [name & other-srcs] - (def from (string "src/" name ".c")) - (def to (string "build/" name suffix)) - (def toa (string "build/" name asuffix)) - (cc to from ;other-srcs) - (static-cc toa from ;other-srcs)) - - (setdyn cc/*visit* cc/visit-execute-if-stale) - (setdyn cc/*build-dir* "build/objects") - (make1 "crc") - (make1 "json") - (make1 "cmath") - (make1 "utf8") - (make1 "rawterm") - (make1 "tarray") - (make1 "base64") - (setdyn cc/*defines* {"_LARGEFILE64_SOURCE" true}) - (make1 "zip" "deps/miniz/miniz.c") - - (print "done!")) diff --git a/bundle/test.janet b/bundle/test.janet new file mode 100644 index 0000000..fdab27b --- /dev/null +++ b/bundle/test.janet @@ -0,0 +1,16 @@ +# +# Run test scripts, and error if any fail. +# Pass through any args +# + +(defn main [& argv] + (def failures-array @[]) + (each suite (sorted (os/dir "test")) + (when (string/has-prefix? "suite-" suite) + (eprint "Running suite " suite) + (def result (os/execute [(dyn *executable*) (string "test/" suite) ;argv] :p)) + (if-not (zero? result) + (array/push failures-array suite)))) + (if (empty? failures-array) + (eprint "All Passed.") + (errorf "Failures in: %s" (string/join failures-array ", "))))