|
1 | | -(if (dyn :install-time-syspath) |
2 | | - (use @install-time-syspath/spork/declare-cc) |
3 | | - (use spork/declare-cc)) |
| 1 | +(use spork/declare-cc) |
4 | 2 |
|
5 | | -(setdyn :verbose true) |
6 | | -(def- build-type "release") |
| 3 | +# force default to release unless specifically requested |
| 4 | +(when (not (os/getenv "JANET_BUILD_TYPE")) |
| 5 | + (setdyn :build-type :release)) |
| 6 | + |
| 7 | +# pull info.jdn so we don't duplicate symbols there and |
| 8 | +# in declare-project below |
| 9 | +(def info (-> (slurp "./bundle/info.jdn") parse)) |
| 10 | + |
| 11 | +(declare-project |
| 12 | + :name (info :name) |
| 13 | + :description (info :description) |
| 14 | + :version (info :version) |
| 15 | + :dependencies (info :jpm-dependencies)) |
| 16 | + |
| 17 | +########### |
| 18 | +(try |
| 19 | + (import janet-native-tools :as jnt) |
| 20 | + ([err fib] |
| 21 | + (print "please run `janet-pm deps` or `jeep prep` first"))) |
7 | 22 |
|
8 | 23 | (import spork/pm) |
9 | 24 | (import spork/sh) |
10 | 25 | (import spork/path) |
11 | 26 | (use ./utils) |
12 | 27 |
|
13 | | -(defdyn *cmakepath* "What cmake command to use") |
14 | | -(defdyn *ninjapath* "What ninja command to use") |
15 | | - |
16 | | -(defn- cmake |
17 | | - "Make a call to cmake." |
18 | | - [& args] |
19 | | - (printf "cmake %j" args) |
20 | | - (sh/exec (dyn *cmakepath* "cmake") ;args)) |
| 28 | +# make sure we can find cmake and make |
| 29 | +(jnt/require-git) |
| 30 | +(jnt/require-cmake) |
| 31 | +(jnt/require-ninja) |
21 | 32 |
|
22 | 33 | (defn- update-submodules [] |
23 | | - (pm/git "submodule" "update" "--init" "--recursive")) |
24 | | - |
25 | | -(defn- lib-prefix [] |
26 | | - (if (= (os/which) :windows) |
27 | | - "" |
28 | | - "lib")) |
29 | | - |
30 | | -(defn- lib-suffix [] |
31 | | - (if (= (os/which) :windows) |
32 | | - ".lib" |
33 | | - ".a")) |
| 34 | + (jnt/git "submodule" "update" "--init" "--recursive")) |
34 | 35 |
|
35 | 36 | (def- cfltk-lib |
36 | | - (string (lib-prefix) "cfltk2" (lib-suffix))) |
| 37 | + (string (jnt/gen-static-libname "cfltk2"))) |
37 | 38 |
|
38 | 39 | (def- fltk-build-dir (string/format "_build/cfltk-build/fltk/lib")) |
39 | 40 | (def- fltk-libs |
40 | 41 | (do |
41 | 42 | (var results @[]) |
42 | 43 | (loop [item :in ["fltk" "fltk_gl" "fltk_forms" "fltk_images" "fltk_png" "fltk_jpeg" "fltk_z"]] |
43 | | - (array/push results (string (lib-prefix) item (lib-suffix)))) |
| 44 | + (array/push results (string (jnt/gen-static-libname item)))) |
44 | 45 | results)) |
45 | 46 |
|
46 | 47 | (def- cfltk-build-dir (string/format "_build/cfltk-build")) |
|
57 | 58 | (array/push fltk-flags "-DFLTK_BACKEND_WAYLAND=ON")) |
58 | 59 |
|
59 | 60 | (def- cmake-flags (array/concat cfltk-flags fltk-flags)) |
60 | | -(def- cmake-build-flags @["--build" cfltk-build-dir "--parallel" "--config" "Release"]) |
| 61 | + |
| 62 | +(def [build-cfltk clean-cfltk] |
| 63 | + (jnt/declare-cmake :name "cfltk" |
| 64 | + :source-dir "cfltk" |
| 65 | + :build-dir cfltk-build-dir |
| 66 | + :cmake-flags cmake-flags)) |
61 | 67 |
|
62 | 68 | (defn- copy-static-libs [] |
63 | 69 | (sh/copy (string/format "%s/%s" cfltk-build-dir cfltk-lib) (string/format "./jfltk/%s" cfltk-lib)) |
64 | 70 | (loop [fname :in fltk-libs] |
65 | 71 | (let [fullname (string/format "%s/%s" fltk-build-dir fname) |
66 | 72 | outname (string/format "./jfltk/%s" fname)] |
67 | 73 | (when (sh/exists? fullname) |
68 | | - (sh/copy fullname outname ))))) |
| 74 | + (sh/copy fullname outname))))) |
69 | 75 |
|
70 | 76 | (defn- clean-static-libs [] |
71 | 77 | (loop [fname :in (sh/list-all-files "jfltk")] |
72 | | - (when (string/has-suffix? (lib-suffix) fname) |
73 | | - (sh/rm fname)))) |
74 | | - |
75 | | -(defn build-cfltk [] |
76 | | - (unless (and (sh/exists? "cfltk") (sh/exists? "cfltk/fltk")) |
77 | | - (update-submodules)) |
78 | | - # remove old static libs, might be stale |
79 | | - (clean-static-libs) |
80 | | - (unless (sh/exists? (string/format "%s/%s" cfltk-build-dir cfltk-lib)) |
81 | | - (unless (sh/exists? (string/format "%s/%s" cfltk-build-dir "build.ninja")) |
82 | | - (cmake ;cmake-flags)) |
83 | | - (do (cmake ;cmake-build-flags))) |
84 | | - # copy static libs, assuming they have been built |
85 | | - (copy-static-libs)) |
86 | | - |
87 | | -(set-command "cmake" *cmakepath*) |
88 | | -(set-command "ninja" *ninjapath*) |
| 78 | + (each libname fltk-libs |
| 79 | + (when (string/has-suffix? libname fname) |
| 80 | + (sh/rm fname))))) |
| 81 | + |
| 82 | +(task "build-cfltk" [] |
| 83 | + (update-submodules) |
| 84 | + (clean-static-libs) |
| 85 | + (build-cfltk) |
| 86 | + (copy-static-libs)) |
| 87 | + |
| 88 | +(task "pre-build" ["build-cfltk"]) |
| 89 | + |
| 90 | +(task "clean-cfltk" [] (clean-cfltk)) |
89 | 91 |
|
90 | 92 | (var cfltk-lib-path nil) |
91 | 93 | (var fltk-lib-path nil) |
|
105 | 107 | "glu32.lib" "opengl32.lib" "ole32.lib" "uuid.lib" "comctl32.lib" "gdi32.lib" "gdiplus.lib" |
106 | 108 | "user32.lib" "shell32.lib" "comdlg32.lib" "ws2_32.lib" "winspool.lib"]) |
107 | 109 |
|
108 | | -(defn fltk-link-libs [] |
| 110 | +(defn- fltk-link-libs [] |
109 | 111 | (if (sh/exists? fltk-config) |
110 | 112 | (if (not (= (os/which) :windows)) |
111 | 113 | (do |
112 | 114 | (def out (sh/exec-slurp fltk-config "--use-gl" "--use-images" "--use-glut" "--use-forms" "--use-cairo" "--ldflags")) |
113 | 115 | (string/split " " out)) |
114 | 116 | @[]) |
115 | 117 | (do (build-cfltk) |
116 | | - (fltk-link-libs)))) |
| 118 | + (fltk-link-libs)))) |
117 | 119 |
|
118 | | -(defn gen-lflags [] |
| 120 | +(defn- gen-lflags [] |
119 | 121 | (if (= (os/which) :windows) |
120 | 122 | windows-fltk-link-libs |
121 | 123 | (array/join @[cfltk-lib-path "-lcfltk2"] (fltk-link-libs)))) |
122 | 124 |
|
123 | | -(defdyn *lflags* "Linker flags") |
124 | | -(setdyn *lflags* (gen-lflags)) |
125 | | - |
126 | | -(task "pre-build" ["build-cfltk" "create-flags"]) |
| 125 | +(var cppflags nil) |
| 126 | +(def- lflags (gen-lflags)) |
| 127 | +(case (os/which) |
| 128 | + :windows (set cppflags @["/bigobj" "-I./cfltk/include" "-DCFLTK_USE_GL" "-DFLTK_BUILD_FORMS"]) |
| 129 | + :macos (set cppflags @["-I./cfltk/include" "-DCFLTK_USE_GL" "-DFLTK_BUILD_FORMS"]) |
| 130 | + :linux (set cppflags @["-fPIC" "-I./cfltk/include" "-DCFLTK_USE_GL" "-DFLTK_BUILD_FORMS"])) |
127 | 131 |
|
128 | | -(dofile "project.janet" :env (jpm-shim-env)) |
| 132 | +(declare-source |
| 133 | + :source ["jfltk"]) |
129 | 134 |
|
130 | | -(task "build-cfltk" [] |
131 | | - (build-cfltk)) |
132 | | - |
133 | | -# this creates a file in jfltk that can be used to get to the |
134 | | -# platform specific linker flags to compile Janet+FLTK apps into |
135 | | -# full executables. Have a look in "examples/" for an example |
136 | | -(task "create-flags" [] |
137 | | - (def flags (gen-lflags)) |
138 | | - (var real-flags @[]) |
139 | | - (loop [item :in flags] |
140 | | - (if (and (string/has-prefix? "-L" item) (not (string/find "/usr" item))) |
141 | | - (array/push real-flags '(get-libdir)) |
142 | | - (array/push real-flags item))) |
143 | | - (def fname (string (os/cwd) "/jfltk/flags.janet")) |
144 | | - (def ofs (file/open fname :w)) |
145 | | - (file/write ofs "(import spork/path)\n") |
146 | | - (file/write ofs "(defn get-libdir [] (string \"-L\" (path/abspath (path/dirname (dyn *current-file*)))))\n") |
147 | | - (file/write ofs (string/format "(def lflags %j)\n" real-flags)) |
148 | | - (file/write ofs "(defn print-lflags [] (pp lflags))\n") |
149 | | - (file/close ofs)) |
| 135 | +(declare-native |
| 136 | + :name "jfltk/widgets" |
| 137 | + :source @["c/module.cpp"] |
| 138 | + :c++flags cppflags |
| 139 | + :lflags lflags) |
150 | 140 |
|
| 141 | +# create a new task to run the ldflags fixup |
| 142 | +(task "fix-up-ldflags" [] (jnt/fix-up-ldflags "jfltk" "widgets.meta.janet")) |
151 | 143 |
|
| 144 | +# attach this task to the post-install hook |
| 145 | +(task "post-install" ["fix-up-ldflags"]) |
0 commit comments