6 vecho
() { ${vecho-:} "$*"; }
7 digest
() { cksum 2>/dev
/null $
* |
while read h _
; do printf $h; done; }
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 && git describe --tags --dirty); 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 wsi
/$wsid/*) incs1
="$incs1 $wsid";;
55 main.cmo
) incs1
="$incs1 $wsid lablGL";;
56 glutils.cmo|listview.cmo
) incs1
="$incs1 lablGL";;
60 incs
="$incs -I $srcd/$i -I $outd/$i"
62 echo "-I $srcd -I $outd $incs"
68 *) f
="-g -strict-sequence -strict-formats -w @A";;
75 version.o
) f
='-DLLPP_VERSION="'$ver'"';;
77 f
="-g -std=c99 -O2 $muinc -Wall -Werror -Wextra -pedantic"
78 f
="$f -DCACHE_PAGEREFS -DKeySym=uint32_t"
79 $darwin && f
="$f -DCIDER -D_GNU_SOURCE" \
80 || f
="$f -D_POSIX_C_SOURCE";;
81 */keysym2ucs.o
) f
="-O2 -include inttypes.h -DKeySym=uint32_t";;
82 */ml_
*.o
) f
="-g -Wno-pointer-sign -O2";;
88 mflags
() { echo "-I $(ocamlc -where) -g -Wall -Werror -O2"; }
90 overs
="$(ocamlc -vnum 2>/dev/null)" || overs
=""
91 test "$overs" = "4.07.0" ||
{
92 url
=https
://caml.inria.fr
/pub
/distrib
/ocaml-4.07
/ocaml-4.07
.0+rc1.
tar.xz
93 txz
=$outd/$
(basename $url)
94 isfresh
$txz $url ||
{
95 executable_p
() { command -v "$1" >/dev
/null
2>&1; }
96 if executable_p wget
; then dl
() { wget
-q "$1" -O "$2"; }
97 elif executable_p curl
; then dl
() { curl
-L "$1" -o "$2"; }
98 else die
"no program to fetch remote urls found"
101 echo "k=$url" >$txz.past
102 } && vecho
"fresh $txz"
103 absprefix
=$
(cd $outd &>/dev
/null
; pwd -P)
104 export PATH
=$absprefix/bin
:$PATH
105 isfresh
$absprefix/bin
/ocamlc
"$url" ||
(
108 cd $outd/${bn%.tar.xz}
109 .
/configure
-prefix $absprefix \
110 -no-graph -no-debugger -no-ocamldoc -no-native-compiler
113 echo "k='$url'" >$absprefix/bin
/ocamlc.past
114 ) && vecho
"fresh ocamlc"
115 overs
=$
(ocamlc
-vnum 2>/dev
/null
)
119 grep -q "$3" $outd/ordered ||
{
121 echo "$3" >>"$outd/ordered"
132 local cmd
="ocamlc -depend -bytecode -one-line $(oincs $o) $s"
133 local keycmd
="digest $o $s"
134 isfresh
"$o.depl" "$overs$cmd$(eval $keycmd)" ||
{
135 eval "$cmd || die '$cmd' failed" |
{
140 test "$O" = "$D" ||
{
144 *) dd=$outd/${d#$srcd/};;
146 printf "$dd " >>"$o.depl"
149 } || die
"$cmd failed"
150 echo "k='$overs$cmd$(eval $keycmd)'" >"$o.depl.past"
152 vecho
"fresh $o.depl"
153 for d
in $
(< $o.depl
); do
154 bocaml
${d#$outd/} $
((n
+1))
158 cmd
="ocamlc $(oflags $o) -c -o $o $s"
159 keycmd
="digest $o $s $(< $o.depl)"
160 isfresh
"$o" "$overs$cmd$(eval $keycmd)" ||
{
161 printf "%*.s%s -> %s\n" $n '' "${s#$srcd/}" "${o#$outd/}"
162 eval "$cmd || die '$cmd failed'"
163 echo "k='$overs$cmd$(eval $keycmd)'" >"$o.past"
164 } && vecho
"fresh '$o'"
171 local wocmi
="${o%.cmi}"
174 case ${wocmi#$outd/} in
176 s
=$outd/confstruct.ml
177 o
=$outd/confstruct.cmo
;;
179 test "$o" = "$wocmi" && s
=$srcd/${o%.cmo}.ml || s
=$srcd/$wocmi.mli
182 expr >/dev
/null
"$cycle" : ".*$o" && die cycle
$o || cycle
="$cycle$o"
185 wsi
) s
="$srcd/$wsid/wsi.ml";;
186 help) s
="$srcd/help.ml";;
187 */glMisc
) s
="$srcd/lablGL/glMisc.ml";;
188 */glTex
) s
="$srcd/lablGL/glTex.ml";;
192 bocaml1
$n "$s" "$outd/${s1%.ml}.cmo" "${o#$outd/}"
199 local s
=$srcd/${1%.o}.c
200 local cmd
="ocamlc -ccopt \"$(cflags $o) -MMD -MF $o.dep -MT_ -o $o\" $s"
201 test -r $o.dep
&& read _ d
<$o.dep || d
=
202 local keycmd
='digest $o $d'
203 isfresh
"$o" "$cmd$(eval $keycmd)" ||
{
204 printf "%s -> %s\n" "${s#$srcd/}" "${o#$outd/}"
205 eval "$cmd || die '$cmd failed'"
207 echo "k='$cmd$(eval $keycmd)'" >"$o.past"
208 } && vecho
"fresh $o"
213 local s
=$srcd/${1%.o}.m
214 local cmd
="$mcomp $(mflags $o) -MMD -MF $o.dep -MT_ -c -o $o $s"
215 test -r $o.dep
&& read _ d
<$o.dep || d
=
216 local keycmd
='digest $o $d'
217 isfresh
"$o" "$cmd$(eval $keycmd)" ||
{
218 printf "%s -> %s\n" "${s#$srcd/}" "${o#$outd/}"
219 eval "$cmd || die '$cmd failed'"
221 echo "k='$cmd$(eval $keycmd)'" >"$o.past"
222 } && vecho
"fresh $o"
225 ver
=$
(cd $srcd && git describe
--tags --dirty) || ver
=unknown
227 cmd
="(. $srcd/genconfstr.sh >$outd/confstruct.ml)"
228 keycmd
="digest $srcd/genconfstr.sh $outd/confstruct.ml"
229 isfresh
"$outd/confstruct.ml" "$cmd$(eval $keycmd)" ||
{
230 echo "generating $outd/confstruct.ml"
231 eval "$cmd || die genconfstr.sh failed"
232 echo "k='$cmd$(eval $keycmd)'" > "$outd/confstruct.ml.past"
233 } && vecho
"fresh $outd/confstruct.ml"
245 *) die
"unknown doc type";;
247 for m
in llpp llppac llpphtml
; do
248 src
=$srcd/adoc
/$m.adoc
250 conf
="$srcd/man/asciidoc.conf"
251 keycmd
="digest $out $src $conf"
252 cmd
="a2x -D $md -d manpage -f $doct $src"
253 isfresh
"$out" "$cmd$(eval $keycmd)" ||
{
255 eval "$cmd || die '$cmd failed'"
256 echo "k='$cmd$(eval $keycmd)'" >"$out.past"
257 } && vecho
"fresh $out"
260 completions
) die
"not yet";;
262 *) die
"no clue - '$target'";;
269 for m
in link cutils version
; do
271 cobjs
="$cobjs $outd/$m.o"
273 for m
in ml_gl ml_glarray ml_raw
; do
275 cobjs
="$cobjs $outd/lablGL/$m.o"
278 libs
="str.cma unix.cma"
279 clibs
="-L$mudir/build/$mbt -lmupdf -lmupdf-third -lpthread"
281 mcomp
=$
(ocamlc
-config |
grep bytecomp_c_co |
{ read _ c
; echo $c; })
282 clibs
="$clibs -framework Cocoa -framework OpenGL"
283 cobjs
="$cobjs $outd/wsi/cocoa/cocoa.o"
284 bobjc wsi
/cocoa
/cocoa.o
286 clibs
="$clibs -lGL -lX11"
287 cobjs
="$cobjs $outd/wsi/x11/keysym2ucs.o $outd/wsi/x11/xlib.o"
288 bocamlc wsi
/x11
/keysym2ucs.o
289 bocamlc wsi
/x11
/xlib.o
292 ord
=$
(grep -v \.cmi
$outd/ordered
)
293 cmd
="ocamlc -custom $libs -o $outd/llpp $cobjs $(echo $ord) -cclib \"$clibs\""
294 keycmd
="digest $outd/llpp $cobjs $ord $mulibs"
295 isfresh
"$outd/llpp" "$cmd$(eval $keycmd)" ||
{
296 echo linking
$outd/llpp
297 eval "$cmd || die '$cmd failed'"
298 echo "k='$cmd$(eval $keycmd)'" >"$outd/llpp.past"
299 } && vecho
"fresh llpp"
302 out
="$outd/llpp.app/Contents/Info.plist"
303 keycmd
="digest $out $srcd/wsi/cocoa/genplist.sh; echo $ver"
304 isfresh
$out "$(eval $keycmd)" ||
{
307 echo "generating $out"
308 (.
$srcd/wsi
/cocoa
/genplist.sh
) >"$out"
309 echo "k='$(eval $keycmd)'" >"$out.past"
310 } && vecho
"fresh plist"
312 out
=$outd/llpp.app
/Contents
/MacOS
/llpp
313 keycmd
="digest $out $outd/llpp"
314 isfresh
$out "$(eval $keycmd)" ||
{
316 mkdir
-p "$(dirname $out)"
318 echo "k='$(eval $keycmd)'" >"$out.past"
319 } && vecho
"fresh bundle"