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);;
28 Linux
) mjobs
=$
(getconf _NPROCESSORS_ONLN ||
echo 1);;
29 OpenBSD
) mjobs
=$
(getconf NPROCESSORS_ONLN ||
echo 1);;
30 *) die $
(uname
) is not supported
;;
33 test -n "${1-}" || die
"usage: $0 build-directory"
38 muinc
="-I $mudir/include -I $mudir/thirdparty/freetype/include"
40 test -d "$mudir" || die muPDF not found
, consult $
(dirname $0)/BUILDING
46 isfresh
() { test -r "$1.past" && .
"$1.past" && test "$k" = "$2"; }
48 mulibs
="$mudir/build/native/libmupdf.a" # $mudir/build/native/libmupdf-third.a
49 keycmd
="(cd $mudir && git describe --tags --dirty); digest $mulibs"
50 isfresh
"$mulibs" "$(eval $keycmd)" ||
(
51 make -C "$mudir" build
=native
-j $mjobs libs
52 echo "k='$(eval $keycmd)'" >$mudir/build
/native
/libmupdf.a.past
53 ) && vecho
"fresh mupdf"
60 lablGL
/*) incs1
="$incs1 lablGL";;
61 wsi
/$wsid/*) incs1
="$incs1 $wsid";;
62 main.cmo
) incs1
="$incs1 $wsid lablGL";;
63 glutils.cmo|listview.cmo
) incs1
="$incs1 lablGL";;
67 incs
="$incs -I $srcd/$i -I $outd/$i"
69 echo "-I $srcd -I $outd $incs"
75 *) f
="-g -strict-sequence -strict-formats -w @A";;
82 version.o
) f
='-DLLPP_VERSION="'$ver'"';;
84 f
="-g -std=c99 -O2 $muinc -Wall -Werror -Wextra -pedantic"
85 f
="$f -DCACHE_PAGEREFS"
86 $darwin && f
="$f -D__COCOA__ -D_GNU_SOURCE" \
87 || f
="$f -D_POSIX_C_SOURCE";;
88 */keysym2ucs.o
) f
="-O2 -include inttypes.h -DKeySym=uint32_t";;
89 */ml_
*.o
) f
="-g -Wno-pointer-sign -O2";;
95 mflags
() { echo "-I $(ocamlc -where) -g -Wall -Werror -O2"; }
97 overs
="$(ocamlc -vnum 2>/dev/null)" || overs
=""
98 test "$overs" = "4.06.1" ||
{
99 url
=http
://caml.inria.fr
/pub
/distrib
/ocaml-4.06
/ocaml-4.06
.1.
tar.xz
100 txz
=$outd/$
(basename $url)
101 isfresh
$txz $url ||
{
102 executable_p
() { command -v "$1" >/dev
/null
2>&1; }
103 if executable_p wget
; then dl
() { wget
-q "$1" -O "$2"; }
104 elif executable_p curl
; then dl
() { curl
-L "$1" -o "$2"; }
105 else die
"no program to fetch remote urls found"
108 echo "k=$url" >$txz.past
109 } && vecho
"fresh $txz"
110 absprefix
=$
(cd $outd &>/dev
/null
; pwd -P)
111 export PATH
=$absprefix/bin
:$PATH
112 isfresh
$absprefix/bin
/ocamlc
"$url" ||
(
115 cd $outd/${bn%.tar.xz}
116 .
/configure
-prefix $absprefix \
117 -no-graph -no-debugger -no-ocamldoc -no-native-compiler
120 echo "k='$url'" >$absprefix/bin
/ocamlc.past
121 ) && vecho
"fresh ocamlc"
122 overs
=$
(ocamlc
-vnum 2>/dev
/null
)
126 grep -q "$3" $outd/ordered ||
{
128 echo "$3" >>"$outd/ordered"
139 local cmd
="ocamlc -depend -bytecode -one-line $(oincs $o) $s"
140 local keycmd
="digest $o $s"
141 isfresh
"$o.depl" "$overs$cmd$(eval $keycmd)" ||
{
142 eval "$cmd || die '$cmd' failed" |
{
147 test "$O" = "$D" ||
{
151 *) dd=$outd/${d#$srcd/};;
153 printf "$dd " >>"$o.depl"
156 } || die
"$cmd failed"
157 echo "k='$overs$cmd$(eval $keycmd)'" >"$o.depl.past"
159 vecho
"fresh $o.depl"
160 for d
in $
(< $o.depl
); do
161 bocaml
${d#$outd/} $
((n
+1))
165 cmd
="ocamlc $(oflags $o) -c -o $o $s"
166 keycmd
="digest $o $s $(< $o.depl)"
167 isfresh
"$o" "$overs$cmd$(eval $keycmd)" ||
{
168 printf "%*.s%s -> %s\n" $n '' "${s#$srcd/}" "${o#$outd/}"
169 eval "$cmd || die '$cmd failed'"
170 echo "k='$overs$cmd$(eval $keycmd)'" >"$o.past"
171 } && vecho
"fresh '$o'"
177 local wocmi
="${o%.cmi}"
179 case ${wocmi#$outd/} in
181 s
=$outd/confstruct.ml
182 o
=$outd/confstruct.cmo
;;
184 test "$o" = "$wocmi" && s
=$srcd/${o%.cmo}.ml || s
=$srcd/$wocmi.mli
189 wsi
) s
="$srcd/$wsid/wsi.ml";;
190 help) s
="$srcd/help.ml";;
191 */glMisc
) s
="$srcd/lablGL/glMisc.ml";;
192 */glTex
) s
="$srcd/lablGL/glTex.ml";;
196 bocaml1
$n "$s" "$outd/${s1%.ml}.cmo" "${o#$outd/}"
202 local s
=$srcd/${1%.o}.c
203 local cmd
="ocamlc -ccopt \"$(cflags $o) -MMD -MF $o.dep -MT_ -o $o\" $s"
204 test -r $o.dep
&& read _ d
<$o.dep || d
=
205 local keycmd
='digest $o $d'
206 isfresh
"$o" "$cmd$(eval $keycmd)" ||
{
207 printf "%s -> %s\n" "${s#$srcd/}" "${o#$outd/}"
208 eval "$cmd || die '$cmd failed'"
210 echo "k='$cmd$(eval $keycmd)'" >"$o.past"
211 } && vecho
"fresh $o"
216 local s
=$srcd/${1%.o}.m
217 local cmd
="$mcomp $(mflags $o) -MMD -MF $o.dep -MT_ -c -o $o $s"
218 test -r $o.dep
&& read _ d
<$o.dep || d
=
219 local keycmd
='digest $o $d'
220 isfresh
"$o" "$cmd$(eval $keycmd)" ||
{
221 printf "%s -> %s\n" "${s#$srcd/}" "${o#$outd/}"
222 eval "$cmd || die '$cmd failed'"
224 echo "k='$cmd$(eval $keycmd)'" >"$o.past"
225 } && vecho
"fresh $o"
228 ver
=$
(cd $srcd && git describe
--tags --dirty) || ver
=unknown
230 cmd
="(. $srcd/genconfstr.sh >$outd/confstruct.ml)"
231 keycmd
="digest $srcd/genconfstr.sh $outd/confstruct.ml"
232 isfresh
"$outd/confstruct.ml" "$cmd$(eval $keycmd)" ||
{
234 eval "$cmd || die genconfstr.sh failed"
235 echo "k='$cmd$(eval $keycmd)'" > "$outd/confstruct.ml.past"
236 } && vecho
"fresh $outd/confstruct.ml"
248 *) die
"unknown doc type";;
250 for m
in llpp llppac llpphtml
; do
251 src
=$srcd/adoc
/$m.adoc
253 conf
="$srcd/man/asciidoc.conf"
254 keycmd
="digest $out $src $conf"
255 cmd
="a2x -D $md -d manpage -f $doct $src"
256 isfresh
"$out" "$cmd$(eval $keycmd)" ||
{
258 eval "$cmd || die '$cmd failed'"
259 echo "k='$cmd$(eval $keycmd)'" >"$out.past"
260 } && vecho
"fresh $out"
263 completions
) die
"not yet";;
265 *) die
"no clue - '$target'";;
272 for m
in link cutils version
; do
274 cobjs
="$cobjs $outd/$m.o"
276 for m
in ml_gl ml_glarray ml_raw
; do
278 cobjs
="$cobjs $outd/lablGL/$m.o"
281 libs
="str.cma unix.cma"
282 clibs
="-L$mudir/build/native -lmupdf -lmupdf-third -lpthread"
284 mcomp
=$
(ocamlc
-config |
grep bytecomp_c_co |
{ read _ c
; echo $c; })
285 clibs
="$clibs -framework Cocoa -framework OpenGL"
286 bobjc wsi
/cocoa
/wsicocoa.o
287 cobjs
="$cobjs $outd/wsi/cocoa/wsicocoa.o"
289 clibs
="$clibs -lGL -lX11"
290 cobjs
="$cobjs $outd/wsi/x11/keysym2ucs.o"
291 bocamlc wsi
/x11
/keysym2ucs.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"
306 isfresh
$out "$(eval $keycmd)" ||
{
307 shortver
=$
(echo $ver |
{ IFS
='-' read s _
; echo ${s#v}; })
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"