6 test "$unameN" = Darwin
&& {
15 if $
(expr >/dev
/null
"$(date --version 2>/dev/null)" : ".*GNU"); then
20 alias vecho
=${vecho-:}
21 command -v md5sum >/dev
/null || true
&& alias sum=md5sum
22 digest
() { sum "$@" 2>/dev
/null |
while read h _
; do printf $h; done; }
25 test $?
-eq 0 && msg
="ok" || msg
="ko"
26 echo "$msg $(echo "scale
=3; ($
(now
) - $tstart)/1" | bc -l) sec"
36 test $
(ocamlc
-version |
{ IFS
=.
read a b _
; echo $a$b; } ) -lt 406 && {
37 die OCaml version
4.06+ is required
40 test -n "${1-}" || die
"usage: $0 build-directory"
45 muinc
="-I $mudir/include -I $mudir/thirdparty/freetype/include"
48 test -e "$1" && test -r "$1.past" && {
56 main.cmo|utils.cmo|config.cmo|parser.cmo|wsi.cmi|
$wsi/wsi.cmo
)
57 f
="-g -strict-sequence -strict-formats -warn-error a";;
60 echo "-I lablGL -I $outd/lablGL -I $wsi -I $outd/$wsi -I $outd $f"
66 f
="-g -std=c99 -O2 $muinc -Wall -Werror -pedantic-errors"
67 $darwin && echo "$f -D__COCOA__" ||
echo $f;;
68 */ml_gl.o
) echo "-g -Wno-pointer-sign -O2";;
73 mflags
() { echo "-I $(ocamlc -where) -g -O2"; }
76 eval ocamlc
-depend -bytecode -one-line $incs $s |
{
78 for d
in $
(eval echo $depl); do
79 bocaml
${d#$srcd/} $
((n
+1))
82 cmd
="ocamlc $(oflags $o) -c -o $o $s"
84 grep -q "$o" $outd/ordered ||
{
85 echo "$o" >>"$outd/ordered"
86 isfresh
"$o" "$cmd$(eval $keycmd)" ||
{
87 printf "%*.s%s -> %s\n" $n '' "${s#$srcd/}" "$o"
89 echo "k='$cmd$(eval $keycmd)'" >"$o.past"
90 } && vecho
"fresh '$o'"
98 test ${wocmi%help.cmo} != $wocmi && {
102 test "$o" = "$wocmi" && s
=$srcd/${o%.cmo}.ml || s
=$srcd/$wocmi.mli
105 incs
="-I lablGL -I $outd/lablGL -I $wsi -I $outd/$wsi -I $outd"
112 cmd
="ocamlc -ccopt \"$(cflags $o) -MMD -MF $o.dep -MT_ -o $o\" $s"
113 test -r $o.dep
&& read _ d
<$o.dep || d
=
114 keycmd
='digest $o $d'
115 isfresh
"$o" "$cmd$(eval $keycmd)" ||
{
116 printf "%s -> %s\n" "${s#$srcd/}" "$o"
119 echo "k='$cmd$(eval $keycmd)'" >"$o.past"
120 } && vecho
"fresh $o"
126 cmd
="$mcomp $(mflags $o) -MMD -MF $o.dep -MT_ -c -o $o $s"
127 test -r $o.dep
&& read _ d
<$o.dep || d
=
128 keycmd
='digest $o $d'
129 isfresh
"$o" "$cmd$(eval $keycmd)" ||
{
130 printf "%s -> %s\n" "${s#$srcd/}" "$o"
133 echo "k='$cmd$(eval $keycmd)'" >"$o.past"
134 } && vecho
"fresh $o"
138 mkdir
-p $outd/lablGL
142 ocaml str.cma
-stdin $srcd/KEYS
<<EOF
143 let fixup = let open Str in
144 let dash = regexp {|\([^ ]*\) +- +\(.*\)|}
145 and head = regexp {|-----\(.*\)-----|} in fun s ->
146 String.escaped s |> global_replace dash {|\1\t\2|}
147 |> global_replace head {|\xc2\xb7\1|};;
148 let rec iter ic = match input_line ic with
149 | s -> Printf.printf "\"%s\";\\n" @@ fixup s; iter ic
150 | exception End_of_file -> ();;
151 Printf.printf "let keys = [\\n";
152 iter @@ open_in Sys.argv.(1);;
153 Printf.printf "] and version = \"$ver\";;"
157 ver
=$
(cd $srcd && git describe
--tags --dirty) ||
echo unknown
158 cmd
="mkhelp >$outd/help.ml"
159 keycmd
="digest $srcd/KEYS; echo $ver"
160 isfresh
"$outd/help.ml" '$cmd$(eval $keycmd)$ver' ||
{
162 echo "k='$cmd$(eval $keycmd)$ver'" >"$outd/help.ml.past"
163 } && vecho
"fresh $outd/help.ml"
170 for m
in llpp llppac llpphtml
; do
174 ketcmd
="digest $xml $man"
175 conf
="$srcd/man/asciidoc.conf"
176 cmd
="asciidoc -d manpage -b docbook -f $conf -o '$xml' '$man'"
177 isfresh
"$xml" "$cmd$(eval $keycmd)" ||
{
179 echo "k='$cmd$(eval $keycmd)'" >"$md/$m.past"
181 ketcmd
="digest $out $xml"
182 isfresh
"$out" "$cmd$(eval $keycmd)" ||
{
183 xmlto man
-o $md $xml
190 # following is disgusting (from "generalize everything" perspective),
191 # but generic method of derviving .ml's location from .mli's is not
192 # immediately obvious
193 for m
in lablGL
/glMisc.cmo lablGL
/glTex.cmo
$wsi/wsi.cmo main.cmo
; do
199 libs
="str.cma unix.cma"
200 clibs
="-L$mudir/build/native -lmupdf -lmupdfthird -lpthread"
202 mcomp
=$
(ocamlc
-config |
grep bytecomp_c_co |
{ read _ c
; echo $c; })
203 clibs
="$clibs -framework Cocoa -framework OpenGL"
205 cobjs
="$cobjs $outd/main_osx.o"
207 clibs
="$clibs -lGL -lX11"
211 for f
in ml_gl ml_glarray ml_raw
; do
213 globjs
="$globjs $outd/lablGL/$f.o"
216 ord
=$
(echo $
(grep -v \.cmi
$outd/ordered
))
217 cmd
="ocamlc -custom $libs -o $outd/llpp $cobjs $ord"
218 cmd
="$cmd $globjs -cclib \"$clibs\""
219 keycmd
="digest $outd/llpp $outd/link.o $ord"
220 isfresh
"$outd/llpp" "$cmd$(eval $keycmd)" ||
{
221 echo linking
$outd/llpp
222 eval $cmd ||
echo "$cmd failed"
223 echo "k='$cmd$(eval $keycmd)'" >"$outd/llpp.past"
224 } && vecho
"fresh llpp"
227 out
="$outd/llpp.app/Contents/Info.plist"
228 keycmd
="digest $out $srcd/misc/Info.plist.sh"
229 isfresh
$out "$(eval $keycmd)" ||
{
230 shortver
=$
(echo $ver |
{ IFS
='-' read s _
; echo ${s#v}; })
232 test -d "$d" || mkdir
-p "$d"
233 .
$srcd/misc
/Info.plist.sh
>"$out"
234 echo "k=$(eval $keycmd)" >"$out.past"
235 } && vecho
"fresh plist"
237 out
=$outd/llpp.app
/Contents
/MacOS
/llpp
238 keycmd
="digest $out $outd/llpp"
239 isfresh
$out "$(eval $keycmd)" ||
{
243 echo "k=$(eval $keycmd)" >"$out.past"
244 } && vecho
"fresh bundle"