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
38 isfresh
() { test -r "$1.past" && .
"$1.past" && test "$k" = "$2"; }
40 mulibs
="$mudir/build/native/libmupdf.a" # $mudir/build/native/libmupdf-third.a
41 keycmd
="(cd $mudir && git describe --tags --dirty); digest $mulibs"
42 isfresh
"$mulibs" "$(eval $keycmd)" ||
(
43 make -C "$mudir" build
=native
-j $mjobs libs
44 echo "k='$(eval $keycmd)'" >$mudir/build
/native
/libmupdf.a.past
45 ) && vecho
"fresh mupdf"
52 lablGL
/*) incs1
="$incs1 lablGL";;
53 wsi
/$wsid/*) incs1
="$incs1 $wsid";;
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";;
87 mflags
() { echo "-I $(ocamlc -where) -g -Wall -Werror -O2"; }
89 overs
="$(ocamlc -vnum 2>/dev/null)" || overs
=""
90 test "$overs" = "4.06.1" ||
{
91 url
=http
://caml.inria.fr
/pub
/distrib
/ocaml-4.06
/ocaml-4.06
.1.
tar.xz
92 txz
=$outd/$
(basename $url)
93 isfresh
$txz $url ||
{
94 executable_p
() { command -v "$1" >/dev
/null
2>&1; }
95 if executable_p wget
; then dl
() { wget
-q "$1" -O "$2"; }
96 elif executable_p curl
; then dl
() { curl
-L "$1" -o "$2"; }
97 else die
"no program to fetch remote urls found"
100 echo "k=$url" >$txz.past
101 } && vecho
"fresh $txz"
102 absprefix
=$
(cd $outd &>/dev
/null
; pwd -P)
103 export PATH
=$absprefix/bin
:$PATH
104 isfresh
$absprefix/bin
/ocamlc
"$url" ||
(
107 cd $outd/${bn%.tar.xz}
108 .
/configure
-prefix $absprefix \
109 -no-graph -no-debugger -no-ocamldoc -no-native-compiler
112 echo "k='$url'" >$absprefix/bin
/ocamlc.past
113 ) && vecho
"fresh ocamlc"
114 overs
=$
(ocamlc
-vnum 2>/dev
/null
)
118 grep -q "$3" $outd/ordered ||
{
120 echo "$3" >>"$outd/ordered"
131 local cmd
="ocamlc -depend -bytecode -one-line $(oincs $o) $s"
132 local keycmd
="digest $o $s"
133 isfresh
"$o.depl" "$overs$cmd$(eval $keycmd)" ||
{
134 eval "$cmd || die '$cmd' failed" |
{
139 test "$O" = "$D" ||
{
143 *) dd=$outd/${d#$srcd/};;
145 printf "$dd " >>"$o.depl"
148 } || die
"$cmd failed"
149 echo "k='$overs$cmd$(eval $keycmd)'" >"$o.depl.past"
151 vecho
"fresh $o.depl"
152 for d
in $
(< $o.depl
); do
153 bocaml
${d#$outd/} $
((n
+1))
157 cmd
="ocamlc $(oflags $o) -c -o $o $s"
158 keycmd
="digest $o $s $(< $o.depl)"
159 isfresh
"$o" "$overs$cmd$(eval $keycmd)" ||
{
160 printf "%*.s%s -> %s\n" $n '' "${s#$srcd/}" "${o#$outd/}"
161 eval "$cmd || die '$cmd failed'"
162 echo "k='$overs$cmd$(eval $keycmd)'" >"$o.past"
163 } && vecho
"fresh '$o'"
169 local wocmi
="${o%.cmi}"
171 case ${wocmi#$outd/} in
173 s
=$outd/confstruct.ml
174 o
=$outd/confstruct.cmo
;;
176 test "$o" = "$wocmi" && s
=$srcd/${o%.cmo}.ml || s
=$srcd/$wocmi.mli
181 wsi
) s
="$srcd/$wsid/wsi.ml";;
182 help) s
="$srcd/help.ml";;
183 */glMisc
) s
="$srcd/lablGL/glMisc.ml";;
184 */glTex
) s
="$srcd/lablGL/glTex.ml";;
188 bocaml1
$n "$s" "$outd/${s1%.ml}.cmo" "${o#$outd/}"
194 local s
=$srcd/${1%.o}.c
195 local cmd
="ocamlc -ccopt \"$(cflags $o) -MMD -MF $o.dep -MT_ -o $o\" $s"
196 test -r $o.dep
&& read _ d
<$o.dep || d
=
197 local keycmd
='digest $o $d'
198 isfresh
"$o" "$cmd$(eval $keycmd)" ||
{
199 printf "%s -> %s\n" "${s#$srcd/}" "${o#$outd/}"
200 eval "$cmd || die '$cmd failed'"
202 echo "k='$cmd$(eval $keycmd)'" >"$o.past"
203 } && vecho
"fresh $o"
208 local s
=$srcd/${1%.o}.m
209 local cmd
="$mcomp $(mflags $o) -MMD -MF $o.dep -MT_ -c -o $o $s"
210 test -r $o.dep
&& read _ d
<$o.dep || d
=
211 local keycmd
='digest $o $d'
212 isfresh
"$o" "$cmd$(eval $keycmd)" ||
{
213 printf "%s -> %s\n" "${s#$srcd/}" "${o#$outd/}"
214 eval "$cmd || die '$cmd failed'"
216 echo "k='$cmd$(eval $keycmd)'" >"$o.past"
217 } && vecho
"fresh $o"
220 ver
=$
(cd $srcd && git describe
--tags --dirty) || ver
=unknown
222 cmd
="(. $srcd/genconfstr.sh >$outd/confstruct.ml)"
223 keycmd
="digest $srcd/genconfstr.sh $outd/confstruct.ml"
224 isfresh
"$outd/confstruct.ml" "$cmd$(eval $keycmd)" ||
{
225 echo "generating $outd/confstruct.ml"
226 eval "$cmd || die genconfstr.sh failed"
227 echo "k='$cmd$(eval $keycmd)'" > "$outd/confstruct.ml.past"
228 } && vecho
"fresh $outd/confstruct.ml"
240 *) die
"unknown doc type";;
242 for m
in llpp llppac llpphtml
; do
243 src
=$srcd/adoc
/$m.adoc
245 conf
="$srcd/man/asciidoc.conf"
246 keycmd
="digest $out $src $conf"
247 cmd
="a2x -D $md -d manpage -f $doct $src"
248 isfresh
"$out" "$cmd$(eval $keycmd)" ||
{
250 eval "$cmd || die '$cmd failed'"
251 echo "k='$cmd$(eval $keycmd)'" >"$out.past"
252 } && vecho
"fresh $out"
255 completions
) die
"not yet";;
257 *) die
"no clue - '$target'";;
264 for m
in link cutils version
; do
266 cobjs
="$cobjs $outd/$m.o"
268 for m
in ml_gl ml_glarray ml_raw
; do
270 cobjs
="$cobjs $outd/lablGL/$m.o"
273 libs
="str.cma unix.cma"
274 clibs
="-L$mudir/build/native -lmupdf -lmupdf-third -lpthread"
276 mcomp
=$
(ocamlc
-config |
grep bytecomp_c_co |
{ read _ c
; echo $c; })
277 clibs
="$clibs -framework Cocoa -framework OpenGL"
278 cobjs
="$cobjs $outd/wsi/cocoa/cocoa.o"
279 bobjc wsi
/cocoa
/cocoa.o
281 clibs
="$clibs -lGL -lX11"
282 cobjs
="$cobjs $outd/wsi/x11/keysym2ucs.o $outd/wsi/x11/xlib.o"
283 bocamlc wsi
/x11
/keysym2ucs.o
284 bocamlc wsi
/x11
/xlib.o
287 ord
=$
(grep -v \.cmi
$outd/ordered
)
288 cmd
="ocamlc -custom $libs -o $outd/llpp $cobjs $(echo $ord) -cclib \"$clibs\""
289 keycmd
="digest $outd/llpp $cobjs $ord $mulibs"
290 isfresh
"$outd/llpp" "$cmd$(eval $keycmd)" ||
{
291 echo linking
$outd/llpp
292 eval "$cmd || die '$cmd failed'"
293 echo "k='$cmd$(eval $keycmd)'" >"$outd/llpp.past"
294 } && vecho
"fresh llpp"
297 out
="$outd/llpp.app/Contents/Info.plist"
298 keycmd
="digest $out $srcd/wsi/cocoa/genplist.sh; echo $ver"
299 isfresh
$out "$(eval $keycmd)" ||
{
302 echo "generating $out"
303 (.
$srcd/wsi
/cocoa
/genplist.sh
) >"$out"
304 echo "k='$(eval $keycmd)'" >"$out.past"
305 } && vecho
"fresh plist"
307 out
=$outd/llpp.app
/Contents
/MacOS
/llpp
308 keycmd
="digest $out $outd/llpp"
309 isfresh
$out "$(eval $keycmd)" ||
{
311 mkdir
-p "$(dirname $out)"
313 echo "k='$(eval $keycmd)'" >"$out.past"
314 } && vecho
"fresh bundle"