6 vecho
() { ${vecho-:} "$*"; }
7 digest
() { cat $
* |
cksum; } 2>/dev
/null
8 die
() { echo "$*" >&2; exit 111; }
9 partmsg
() { echo "$(test $? -eq 0 || echo "fail
")$(($(now) - $S)) sec"; }
19 mjobs
=$
(getconf _NPROCESSORS_ONLN ||
echo 1);;
20 Linux
) mjobs
=$
(getconf _NPROCESSORS_ONLN ||
echo 1);;
21 OpenBSD
) mjobs
=$
(getconf NPROCESSORS_ONLN ||
echo 1);;
22 *) die $
(uname
) is not supported
;;
25 test -n "${1-}" || die
"usage: $0 build-directory"
30 muinc
="-I $mudir/include -I $mudir/thirdparty/freetype/include"
32 test -d "$mudir" || die muPDF not found
, consult $
(dirname $0)/BUILDING
34 mkdir
-p $outd/{$wsid,lablGL
}
37 isfresh
() { test -r "$1.past" && .
"$1.past" && test "$k" = "$2"; }
40 mulibs
="$mudir/build/$mbt/libmupdf.a" # $mudir/build/$mbt/libmupdf-third.a
42 keycmd
="(cd $mudir && make -q build=$mbt libs && echo); digest $mulibs"
43 isfresh
"$mulibs" "$(eval $keycmd)" ||
(
44 make -C "$mudir" build
=$mbt -j $mjobs libs
45 echo "k='$(eval $keycmd)'" >$mudir/build
/$mbt/libmupdf.a.past
46 ) && vecho
"fresh mupdf"
53 lablGL
/*) incs1
="$incs1 lablGL";;
54 main.cmo
) incs1
="$incs1 $wsid lablGL";;
55 glutils.cmo|listview.cmo
) incs1
="$incs1 lablGL";;
59 incs
="$incs -I $srcd/$i -I $outd/$i"
61 echo "-I $srcd -I $outd $incs"
67 *) f
="-g -strict-sequence -strict-formats -w @A";;
74 version.o
) f
=-DLLPP_VERSION=$ver;;
76 f
="-g -std=c99 -O2 $muinc -Wall -Werror -Wextra -pedantic"
77 f
="$f -DCACHE_PAGEREFS -DKeySym=uint32_t"
78 $darwin && f
="$f -DCIDER -D_GNU_SOURCE" \
79 || f
="$f -D_POSIX_C_SOURCE";;
80 */keysym2ucs.o
) f
="-O2 -include inttypes.h -DKeySym=uint32_t";;
81 */ml_
*.o
) f
="-g -Wno-pointer-sign -O2";;
84 ! $darwin || f
="$f -DGL_SILENCE_DEPRECATION"
89 echo "-I $(ocamlc -where) -g -Wall -Werror -O2 -DGL_SILENCE_DEPRECATION"
92 overs
="$(ocamlc -vnum 2>/dev/null)" || overs
=""
93 test "$overs" = "4.09" ||
{
94 url
=https
://caml.inria.fr
/pub
/distrib
/ocaml-4.09
/ocaml-4.09
.0.
tar.xz
95 txz
=$outd/$
(basename $url)
96 isfresh
$txz $url ||
{
97 executable_p
() { command -v "$1" >/dev
/null
2>&1; }
98 if executable_p wget
; then dl
() { wget
-q "$1" -O "$2"; }
99 elif executable_p curl
; then dl
() { curl
-L "$1" -o "$2"; }
100 else die
"no program to fetch remote urls found"
103 echo "k=$url" >$txz.past
104 } && vecho
"fresh $txz"
105 absprefix
=$
(cd $outd &>/dev
/null
; pwd -P)
106 export PATH
=$absprefix/bin
:$PATH
107 isfresh
$absprefix/bin
/ocamlc
"$url" ||
(
110 cd $outd/${bn%.tar.xz}
111 .
/configure
--disable-ocamldoc --enable-debugger=no
--prefix=$absprefix
114 echo "k='$url'" >$absprefix/bin
/ocamlc.past
115 ) && vecho
"fresh ocamlc"
116 overs
=$
(ocamlc
-vnum 2>/dev
/null
)
120 grep -q "$3" $outd/ordered ||
{
122 echo "$3" >>"$outd/ordered"
133 local cmd
="ocamlc -depend -bytecode -one-line $(oincs $o) $s"
134 local keycmd
="digest $o $s"
135 isfresh
"$o.depl" "$overs$cmd$(eval $keycmd)" ||
{
136 eval "$cmd || die '$cmd' failed" |
{
141 test "$O" = "$D" ||
{
145 *) dd=$outd/${d#$srcd/};;
147 printf "$dd " >>"$o.depl"
150 } || die
"$cmd failed"
151 echo "k='$overs$cmd$(eval $keycmd)'" >"$o.depl.past"
153 vecho
"fresh $o.depl"
154 for d
in $
(< $o.depl
); do
155 bocaml
${d#$outd/} $
((n
+1))
159 cmd
="ocamlc $(oflags $o) -c -o $o $s"
160 keycmd
="digest $o $s $(< $o.depl)"
161 isfresh
"$o" "$overs$cmd$(eval $keycmd)" ||
{
162 printf "%*.s%s -> %s\n" $n '' "${s#$srcd/}" "${o#$outd/}"
163 eval "$cmd || die '$cmd failed'"
164 echo "k='$overs$cmd$(eval $keycmd)'" >"$o.past"
165 } && vecho
"fresh '$o'"
172 local wocmi
="${o%.cmi}"
175 case ${wocmi#$outd/} in
177 s
=$outd/confstruct.ml
178 o
=$outd/confstruct.cmo
;;
180 test "$o" = "$wocmi" && s
=$srcd/${o%.cmo}.ml || s
=$srcd/$wocmi.mli
183 expr >/dev
/null
"$cycle" : ".*$o" && die cycle
$o || cycle
="$cycle$o"
186 wsi
) s
="$srcd/$wsid/wsi.ml";;
187 help) s
="$srcd/help.ml";;
188 */glMisc
) s
="$srcd/lablGL/glMisc.ml";;
189 */glTex
) s
="$srcd/lablGL/glTex.ml";;
193 bocaml1
$n "$s" "$outd/${s1%.ml}.cmo" "${o#$outd/}"
200 local s
=$srcd/${1%.o}.c
201 local cc
=${LLPP_CC:+-cc $LLPP_CC }
202 local cmd
="ocamlc $cc-ccopt \"$(cflags $o) -MMD -MF $o.dep -MT_ -o $o\" $s"
203 test -r $o.dep
&& read _ d
<$o.dep || d
=
204 local keycmd
='digest $o $d'
205 isfresh
"$o" "$cmd$(eval $keycmd)" ||
{
206 printf "%s -> %s\n" "${s#$srcd/}" "${o#$outd/}"
207 eval "$cmd || die '$cmd failed'"
209 echo "k='$cmd$(eval $keycmd)'" >"$o.past"
210 } && vecho
"fresh $o"
215 local s
=$srcd/${1%.o}.m
216 local cmd
="$mcomp $(mflags $o) -MD -MF $o.dep -MT_ -c -o $o $s"
217 test -r $o.dep
&& read _ d
<$o.dep || d
=
218 local keycmd
='digest $o $d'
219 isfresh
"$o" "$cmd$(eval $keycmd)" ||
{
220 printf "%s -> %s\n" "${s#$srcd/}" "${o#$outd/}"
221 eval "$cmd || die '$cmd failed'"
223 echo "k='$cmd$(eval $keycmd)'" >"$o.past"
224 } && vecho
"fresh $o"
227 ver
=$
(cd $srcd && git describe
--tags --dirty) || ver
=unknown
229 cmd
="(. $srcd/genconfstr.sh >$outd/confstruct.ml)"
230 keycmd
="digest $srcd/genconfstr.sh $outd/confstruct.ml"
231 isfresh
"$outd/confstruct.ml" "$cmd$(eval $keycmd)" ||
{
232 echo "generating $outd/confstruct.ml"
233 eval "$cmd || die genconfstr.sh failed"
234 echo "k='$cmd$(eval $keycmd)'" > "$outd/confstruct.ml.past"
235 } && vecho
"fresh $outd/confstruct.ml"
247 *) die
"unknown doc type";;
249 for m
in llpp llppac llpphtml
; do
250 src
=$srcd/adoc
/$m.adoc
252 conf
="$srcd/man/asciidoc.conf"
253 keycmd
="digest $out $src $conf"
254 cmd
="a2x -D $md -d manpage -f $doct $src"
255 isfresh
"$out" "$cmd$(eval $keycmd)" ||
{
257 eval "$cmd || die '$cmd failed'"
258 echo "k='$cmd$(eval $keycmd)'" >"$out.past"
259 } && vecho
"fresh $out"
262 completions
) die
"not yet";;
264 *) die
"no clue - '$target'";;
271 for m
in link cutils version
; do
273 cobjs
="$cobjs $outd/$m.o"
275 for m
in ml_gl ml_glarray ml_raw
; do
277 cobjs
="$cobjs $outd/lablGL/$m.o"
280 libs
="str.cma unix.cma"
281 clibs
="-L$mudir/build/$mbt -lmupdf -lmupdf-third -lpthread"
283 mcomp
=$
(ocamlc
-config |
grep bytecomp_c_co |
{ read _ c
; echo $c; })
284 clibs
="$clibs -framework Cocoa -framework OpenGL"
285 cobjs
="$cobjs $outd/wsi/cocoa/cocoa.o"
286 bobjc wsi
/cocoa
/cocoa.o
288 clibs
="$clibs -lGL -lX11"
289 cobjs
="$cobjs $outd/wsi/x11/keysym2ucs.o $outd/wsi/x11/xlib.o"
290 bocamlc wsi
/x11
/keysym2ucs.o
291 bocamlc wsi
/x11
/xlib.o
294 ord
=$
(grep -v \.cmi
$outd/ordered
)
295 cmd
="ocamlc -custom $libs -o $outd/llpp $cobjs $(echo $ord) -cclib \"$clibs\""
296 keycmd
="digest $outd/llpp $cobjs $ord $mulibs"
297 isfresh
"$outd/llpp" "$cmd$(eval $keycmd)" ||
{
298 echo linking
$outd/llpp
299 eval "$cmd || die '$cmd failed'"
300 echo "k='$cmd$(eval $keycmd)'" >"$outd/llpp.past"
301 } && vecho
"fresh llpp"
304 out
="$outd/llpp.app/Contents/Info.plist"
305 keycmd
="digest $out $srcd/wsi/cocoa/genplist.sh; echo $ver"
306 isfresh
$out "$(eval $keycmd)" ||
{
309 echo "generating $out"
310 (.
$srcd/wsi
/cocoa
/genplist.sh
) >"$out"
311 echo "k='$(eval $keycmd)'" >"$out.past"
312 } && vecho
"fresh plist"
314 out
=$outd/llpp.app
/Contents
/MacOS
/llpp
315 keycmd
="digest $out $outd/llpp"
316 isfresh
$out "$(eval $keycmd)" ||
{
318 mkdir
-p "$(dirname $out)"
320 echo "k='$(eval $keycmd)'" >"$out.past"
321 } && vecho
"fresh bundle"