|
13 | 13 | (defdyn *cmakepath* "What cmake command to use") |
14 | 14 | (defdyn *ninjapath* "What ninja command to use") |
15 | 15 |
|
16 | | -(def- cfltk-lib |
17 | | - (if (= (os/which) :windows) |
18 | | - "cfltk2.lib" |
19 | | - "cfltk2.a")) |
20 | | - |
21 | 16 | (defn- cmake |
22 | 17 | "Make a call to cmake." |
23 | 18 | [& args] |
| 19 | + (printf "cmake %j" args) |
24 | 20 | (sh/exec (dyn *cmakepath* "cmake") ;args)) |
25 | 21 |
|
26 | 22 | (defn- update-submodules [] |
27 | 23 | (pm/git "submodule" "update" "--init" "--recursive")) |
28 | 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 | + |
| 35 | +(def- cfltk-lib |
| 36 | + (string (lib-prefix) "cfltk2" (lib-suffix))) |
| 37 | + |
| 38 | +(def- fltk-build-dir (string/format "_build/cfltk-build/fltk/lib")) |
| 39 | +(def- fltk-libs |
| 40 | + (do |
| 41 | + (var results @[]) |
| 42 | + (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 | + results)) |
| 45 | + |
29 | 46 | (def- cfltk-build-dir (string/format "_build/cfltk-build")) |
| 47 | + |
30 | 48 | (def- fltk-flags @["-DFLTK_USE_SYSTEM_LIBJPEG=OFF" |
31 | 49 | "-DFLTK_USE_SYSTEM_LIBPNG=OFF" |
32 | 50 | "-DFLTK_USE_SYSTEM_ZLIB=OFF" |
33 | 51 | "-DFLTK_BUILD_FORMS=ON"]) |
34 | | -(def- cfltk-flags @["-B" cfltk-build-dir "-S" "cfltk" "-G" "Ninja" "-DCMAKE_BUILD_TYPE=Release" "-DCFLTK_USE_OPENGL=ON" "-DFLTK_BUILD_EXAMPLES=OFF"]) |
| 52 | +(def- cfltk-flags @["-B" cfltk-build-dir "-S" "cfltk" "-G" "Ninja" |
| 53 | + "-DCMAKE_BUILD_TYPE=Release" "-DCFLTK_USE_OPENGL=ON" "-DFLTK_BUILD_EXAMPLES=OFF"]) |
35 | 54 |
|
36 | 55 | (when (= (os/which) :linux) |
37 | 56 | (array/push fltk-flags "-DCFLTK_USE_FPIC=ON") |
|
40 | 59 | (def- cmake-flags (array/concat cfltk-flags fltk-flags)) |
41 | 60 | (def- cmake-build-flags @["--build" cfltk-build-dir "--parallel" "--config" "Release"]) |
42 | 61 |
|
| 62 | +(defn- copy-static-libs [] |
| 63 | + (sh/copy (string/format "%s/%s" cfltk-build-dir cfltk-lib) (string/format "./jfltk/%s" cfltk-lib)) |
| 64 | + (loop [fname :in fltk-libs] |
| 65 | + (let [fullname (string/format "%s/%s" fltk-build-dir fname) |
| 66 | + outname (string/format "./jfltk/%s" fname)] |
| 67 | + (when (sh/exists? fullname) |
| 68 | + (sh/copy fullname outname ))))) |
| 69 | + |
| 70 | +(defn- clean-static-libs [] |
| 71 | + (loop [fname :in (sh/list-all-files "jfltk")] |
| 72 | + (when (string/has-suffix? (lib-suffix) fname) |
| 73 | + (sh/rm fname)))) |
| 74 | + |
43 | 75 | (defn build-cfltk [] |
44 | 76 | (unless (and (sh/exists? "cfltk") (sh/exists? "cfltk/fltk")) |
45 | 77 | (update-submodules)) |
| 78 | + # remove old static libs, might be stale |
| 79 | + (clean-static-libs) |
46 | 80 | (unless (sh/exists? (string/format "%s/%s" cfltk-build-dir cfltk-lib)) |
47 | 81 | (unless (sh/exists? (string/format "%s/%s" cfltk-build-dir "build.ninja")) |
48 | 82 | (cmake ;cmake-flags)) |
49 | | - (cmake ;cmake-build-flags))) |
| 83 | + (do (cmake ;cmake-build-flags))) |
| 84 | + # copy static libs, assuming they have been built |
| 85 | + (copy-static-libs)) |
50 | 86 |
|
51 | 87 | (set-command "cmake" *cmakepath*) |
52 | 88 | (set-command "ninja" *ninjapath*) |
|
63 | 99 |
|
64 | 100 | (def- fltk-config (path/join (os/cwd) (string/format "%s/fltk/fltk-config" cfltk-build-dir))) |
65 | 101 |
|
66 | | -(def- windows-fltk-libs |
| 102 | +(def- windows-fltk-link-libs |
67 | 103 | @[cfltk-lib-path "cfltk2.lib" fltk-lib-path |
68 | 104 | "fltk.lib" "fltk_forms.lib" "fltk_gl.lib" "fltk_images.lib" "fltk_png.lib" "fltk_jpeg.lib" "fltk_z.lib" |
69 | 105 | "glu32.lib" "opengl32.lib" "ole32.lib" "uuid.lib" "comctl32.lib" "gdi32.lib" "gdiplus.lib" |
70 | 106 | "user32.lib" "shell32.lib" "comdlg32.lib" "ws2_32.lib" "winspool.lib"]) |
71 | 107 |
|
72 | | -(defn fltk-libs [] |
| 108 | +(defn fltk-link-libs [] |
73 | 109 | (if (sh/exists? fltk-config) |
74 | 110 | (if (not (= (os/which) :windows)) |
75 | 111 | (do |
76 | 112 | (def out (sh/exec-slurp fltk-config "--use-gl" "--use-images" "--use-glut" "--use-forms" "--use-cairo" "--ldflags")) |
77 | 113 | (string/split " " out)) |
78 | 114 | @[]) |
79 | 115 | (do (build-cfltk) |
80 | | - (fltk-libs)))) |
| 116 | + (fltk-link-libs)))) |
| 117 | + |
| 118 | +(defn gen-lflags [] |
| 119 | + (if (= (os/which) :windows) |
| 120 | + windows-fltk-link-libs |
| 121 | + (array/join @[cfltk-lib-path "-lcfltk2"] (fltk-link-libs)))) |
81 | 122 |
|
82 | 123 | (defdyn *lflags* "Linker flags") |
83 | | -(setdyn *lflags* (if (= (os/which) :windows) |
84 | | - windows-fltk-libs |
85 | | - (array/join @[cfltk-lib-path "-lcfltk2"] (fltk-libs)))) |
| 124 | +(setdyn *lflags* (gen-lflags)) |
| 125 | + |
| 126 | +(task "pre-build" ["build-cfltk" "create-flags"]) |
86 | 127 |
|
87 | 128 | (dofile "project.janet" :env (jpm-shim-env)) |
88 | 129 |
|
89 | | -(task "pre-build" ["build-cfltk"]) |
90 | | -(task "build-cfltk" [] (build-cfltk)) |
| 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)) |
| 150 | + |
| 151 | + |
0 commit comments