6 vecho
() { ${vecho-:} "$*"; }
7 digest
() { cksum 2>/dev
/null $
* |
while read h _
; do printf $h; done; }
10 test $?
-eq 0 && msg
="ok" || msg
="ko"
11 echo "$msg $(($(now)-tstart)) sec"
27 mjobs
=$
(getconf _NPROCESSORS_ONLN ||
echo 1)
29 Linux
) mjobs
=$
(getconf _NPROCESSORS_ONLN ||
echo 1);;
30 OpenBSD
) mjobs
=$
(getconf NPROCESSORS_ONLN ||
echo 1);;
31 *) die $
(uname
) is not supported
;;
34 test -n "${1-}" || die
"usage: $0 build-directory"
39 muinc
="-I $mudir/include -I $mudir/thirdparty/freetype/include"
45 isfresh
() { .
2>/dev
/null
"$1.past" && test "$k" = "$2"; }
47 mulibs
="$mudir/build/native/libmupdf.a" # $mudir/build/native/libmupdf-third.a
48 keycmd
="(cd $mudir && git describe --tags --dirty); digest $mulibs"
49 isfresh
"$mulibs" "$(eval $keycmd)" ||
(
50 make -C "$mudir" build
=native
-j $mjobs libs
51 echo "k=\"$(eval $keycmd)\"" >$mudir/build
/native
/libmupdf.a.past
52 ) && vecho
"fresh mupdf"
65 |
$wsi/wsi.cmo
) # XXX confstruct?
66 f
="-g -strict-sequence -strict-formats -warn-error @A";;
73 f
="-g -std=c99 -O2 $muinc -Wall -Werror -Wextra -pedantic-errors"
75 version.o
) f
='-DLLPP_VERSION="'$ver'"';;
77 f
="$f -D_POSIX_C_SOURCE"
78 ! $darwin || f
="$f -D__COCOA__";;
79 */keysym2ucs.o
) f
="-O2 -include inttypes.h -DKeySym=uint32_t";;
80 */ml_
*.o
) f
="-g -Wno-pointer-sign -O2";;
86 mflags
() { echo "-I $(ocamlc -where) -g -O2"; }
88 incs
="-I $srcd/lablGL -I $srcd/$wsi -I $srcd"
89 incs
="$incs -I $outd/lablGL -I $outd/$wsi -I $outd"
91 overs
="$(ocamlc --version 2>/dev/null)" || overs
="0.0.0"
92 oversnum
="$(echo $overs | { IFS=. read a b _; echo $a$b; })"
94 test $oversnum -ge 406 ||
{
95 url
=http
://caml.inria.fr
/pub
/distrib
/ocaml-4.06
/ocaml-4.06
.1.
tar.xz
96 txz
=$outd/$
(basename $url)
97 isfresh
$txz $url ||
{
98 executable_p
() { command -v "$1" >/dev
/null
2>&1; }
99 if executable_p wget
; then dl
() { wget
-q "$1" -O "$2"; }
100 elif executable_p curl
; then dl
() { curl
-L "$1" -o "$2"; }
101 else die
"no program to fetch remote urls found"
104 echo "k=$url" >$txz.past
105 } && vecho
"fresh $txz"
106 absprefix
=$
(cd $outd &>/dev
/null
; pwd -P)
107 export PATH
=$absprefix/bin
:$PATH
108 isfresh
$absprefix/bin
/ocamlc
"$url" ||
(
111 cd $outd/${bn%.tar.xz}
112 .
/configure
-prefix $absprefix \
113 -no-graph -no-debugger -no-ocamldoc -no-native-compiler
116 echo "k='$url'" >$absprefix/bin
/ocamlc.past
117 ) && vecho
"fresh ocamlc"
118 overs
=$
(ocamlc
--version 2>/dev
/null
)
122 grep -q "$3" $outd/ordered ||
{
124 echo "$3" >>"$outd/ordered"
135 local cmd
="ocamlc -depend -bytecode -one-line $incs $s"
136 local keycmd
="digest $o $s"
137 isfresh
"$o.depl" "$overs$cmd$(eval $keycmd)" ||
{
143 test "$O" = "$D" ||
{
147 *) dd=$outd/${d#$srcd/};;
149 printf "$dd " >>"$o.depl"
152 } || die
"$cmd failed"
153 echo "k='$overs$cmd$(eval $keycmd)'" >"$o.depl.past"
155 vecho
"fresh $o.depl"
156 for d
in $
(< $o.depl
); do
157 bocaml
${d#$outd/} $
((n
+1))
161 cmd
="ocamlc $(oflags $o) -c -o $o $s"
162 keycmd
="digest $o $s $(< $o.depl)"
163 isfresh
"$o" "$overs$cmd$(eval $keycmd)" ||
{
164 printf "%*.s%s -> %s\n" $n '' "${s#$srcd/}" "${o#$outd/}"
165 eval "$cmd || die '$cmd failed'"
166 echo "k='$overs$cmd$(eval $keycmd)'" >"$o.past"
167 } && vecho
"fresh '$o'"
173 local wocmi
="${o%.cmi}"
175 case ${wocmi#$outd/} in
177 s
=$outd/confstruct.ml
178 o
=$outd/confstruct.cmo
181 test "$o" = "$wocmi" && s
=$srcd/${o%.cmo}.ml || s
=$srcd/$wocmi.mli
187 wsi
) s
="$srcd/$wsi/wsi.ml";;
188 help) s
="$srcd/help.ml";;
189 */glMisc
) s
="$srcd/lablGL/glMisc.ml";;
190 */glTex
) s
="$srcd/lablGL/glTex.ml";;
194 bocaml1
$n "$s" "$outd/${s1%.ml}.cmo" "${o#$outd/}"
200 local s
=$srcd/${1%.o}.c
201 local cmd
="ocamlc -ccopt \"$(cflags $o) -MMD -MF $o.dep -MT_ -o $o\" $s"
202 test -r $o.dep
&& read _ d
<$o.dep || d
=
203 local keycmd
='digest $o $d'
204 isfresh
"$o" "$cmd$(eval $keycmd)" ||
{
205 printf "%s -> %s\n" "${s#$srcd/}" "${o#$outd/}"
206 eval "$cmd || die '$cmd failed'"
208 echo "k='$cmd$(eval $keycmd)'" >"$o.past"
209 } && vecho
"fresh $o"
214 local s
=$srcd/${1%.o}.m
215 local cmd
="$mcomp $(mflags $o) -MMD -MF $o.dep -MT_ -c -o $o $s"
216 test -r $o.dep
&& read _ d
<$o.dep || d
=
217 local keycmd
='digest $o $d'
218 isfresh
"$o" "$cmd$(eval $keycmd)" ||
{
219 printf "%s -> %s\n" "${s#$srcd/}" "${o#$outd/}"
220 eval "$cmd || die '$cmd failed'"
222 echo "k='$cmd$(eval $keycmd)'" >"$o.past"
223 } && vecho
"fresh $o"
226 ver
=$
(cd $srcd && git describe
--tags --dirty) || ver
=unknown
228 cmd
="zsh $srcd/genconfstr.sh >$outd/confstruct.ml"
229 keycmd
="digest $srcd/genconfstr.sh $outd/confstruct.ml"
230 isfresh
"$outd/confstruct.ml" "$cmd$(eval $keycmd)" ||
{
232 eval "$cmd || die genconfstr.sh failed"
233 echo "k='$cmd$(eval $keycmd)'" > "$outd/confstruct.ml.past"
234 } && vecho
"fresh $outd/confstruct.ml"
246 *) die
"unknown doc type";;
248 for m
in llpp llppac llpphtml
; do
249 src
=$srcd/adoc
/$m.adoc
251 conf
="$srcd/man/asciidoc.conf"
252 keycmd
="digest $out $src $conf"
253 cmd
="a2x -D $md -d manpage -f $doct $src"
254 isfresh
"$out" "$cmd$(eval $keycmd)" ||
{
256 eval "$cmd || die '$cmd failed'"
257 echo "k='$cmd$(eval $keycmd)'" >"$out.past"
258 } && vecho
"fresh manual pages"
261 completions
) die
"not yet";;
263 *) die
"no clue - '$target'";;
270 for m
in link cutils version
; do
272 cobjs
="$cobjs $outd/$m.o"
275 libs
="str.cma unix.cma"
276 clibs
="-L$mudir/build/native -lmupdf -lmupdf-third -lpthread"
278 mcomp
=$
(ocamlc
-config |
grep bytecomp_c_co |
{ read _ c
; echo $c; })
279 clibs
="$clibs -framework Cocoa -framework OpenGL"
280 bobjc wsi
/osx
/wsicocoa.o
281 cobjs
="$cobjs $outd/wsi/osx/wsicocoa.o"
283 clibs
="$clibs -lGL -lX11"
284 cobjs
="$cobjs $outd/wsi/x11/keysym2ucs.o"
285 bocamlc wsi
/x11
/keysym2ucs.o
289 for f
in ml_gl ml_glarray ml_raw
; do
291 globjs
="$globjs $outd/lablGL/$f.o"
294 ord
=$
(grep -v \.cmi
$outd/ordered
)
295 cmd
="ocamlc -custom $libs -o $outd/llpp $cobjs $ord"
296 cmd
=$
(echo $cmd $globjs -cclib \"$clibs\")
297 keycmd
="digest $outd/llpp $cobjs $ord $mulibs"
298 isfresh
"$outd/llpp" "$cmd$(eval $keycmd)" ||
{
299 echo linking
$outd/llpp
300 eval "$cmd || die '$cmd failed'"
301 echo "k='$cmd$(eval $keycmd)'" >"$outd/llpp.past"
302 } && vecho
"fresh llpp"
305 out
="$outd/llpp.app/Contents/Info.plist"
306 keycmd
="digest $out $srcd/wsi/osx/genplist.sh"
307 isfresh
$out "$(eval $keycmd)" ||
{
308 shortver
=$
(echo $ver |
{ IFS
='-' read s _
; echo ${s#v}; })
311 .
$srcd/wsi
/osx
/genplist.sh
>"$out"
312 echo "k='$(eval $keycmd)'" >"$out.past"
313 } && vecho
"fresh plist"
315 out
=$outd/llpp.app
/Contents
/MacOS
/llpp
316 keycmd
="digest $out $outd/llpp"
317 isfresh
$out "$(eval $keycmd)" ||
{
318 mkdir
-p "$(dirname $out)"
320 echo "k='$(eval $keycmd)'" >"$out.past"
321 } && vecho
"fresh bundle"