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
() { test -r "$1.past" && .
"$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 -w @A";;
73 f
="-g -std=c99 -O2 $muinc -Wall -Werror -Wextra -pedantic-errors"
75 version.o
) f
='-DLLPP_VERSION="'$ver'"';;
77 $darwin && f
="$f -D__COCOA__ -D_GNU_SOURCE" \
78 || f
="$f -D_POSIX_C_SOURCE" ;;
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 -Wall -Werror -Wno-deprecated -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 -vnum 2>/dev/null)" || overs
=""
92 test "$overs" = "4.06.1" ||
{
93 url
=http
://caml.inria.fr
/pub
/distrib
/ocaml-4.06
/ocaml-4.06
.1.
tar.xz
94 txz
=$outd/$
(basename $url)
95 isfresh
$txz $url ||
{
96 executable_p
() { command -v "$1" >/dev
/null
2>&1; }
97 if executable_p wget
; then dl
() { wget
-q "$1" -O "$2"; }
98 elif executable_p curl
; then dl
() { curl
-L "$1" -o "$2"; }
99 else die
"no program to fetch remote urls found"
102 echo "k=$url" >$txz.past
103 } && vecho
"fresh $txz"
104 absprefix
=$
(cd $outd &>/dev
/null
; pwd -P)
105 export PATH
=$absprefix/bin
:$PATH
106 isfresh
$absprefix/bin
/ocamlc
"$url" ||
(
109 cd $outd/${bn%.tar.xz}
110 .
/configure
-prefix $absprefix \
111 -no-graph -no-debugger -no-ocamldoc -no-native-compiler
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 $incs $s"
134 local keycmd
="digest $o $s"
135 isfresh
"$o.depl" "$overs$cmd$(eval $keycmd)" ||
{
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'"
171 local wocmi
="${o%.cmi}"
173 case ${wocmi#$outd/} in
175 s
=$outd/confstruct.ml
176 o
=$outd/confstruct.cmo
179 test "$o" = "$wocmi" && s
=$srcd/${o%.cmo}.ml || s
=$srcd/$wocmi.mli
185 wsi
) s
="$srcd/$wsi/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/}"
198 local s
=$srcd/${1%.o}.c
199 local cmd
="ocamlc -ccopt \"$(cflags $o) -MMD -MF $o.dep -MT_ -o $o\" $s"
200 test -r $o.dep
&& read _ d
<$o.dep || d
=
201 local keycmd
='digest $o $d'
202 isfresh
"$o" "$cmd$(eval $keycmd)" ||
{
203 printf "%s -> %s\n" "${s#$srcd/}" "${o#$outd/}"
204 eval "$cmd || die '$cmd failed'"
206 echo "k='$cmd$(eval $keycmd)'" >"$o.past"
207 } && vecho
"fresh $o"
212 local s
=$srcd/${1%.o}.m
213 local cmd
="$mcomp $(mflags $o) -MMD -MF $o.dep -MT_ -c -o $o $s"
214 test -r $o.dep
&& read _ d
<$o.dep || d
=
215 local keycmd
='digest $o $d'
216 isfresh
"$o" "$cmd$(eval $keycmd)" ||
{
217 printf "%s -> %s\n" "${s#$srcd/}" "${o#$outd/}"
218 eval "$cmd || die '$cmd failed'"
220 echo "k='$cmd$(eval $keycmd)'" >"$o.past"
221 } && vecho
"fresh $o"
224 ver
=$
(cd $srcd && git describe
--tags --dirty) || ver
=unknown
226 cmd
="(. $srcd/genconfstr.sh >$outd/confstruct.ml)"
227 keycmd
="digest $srcd/genconfstr.sh $outd/confstruct.ml"
228 isfresh
"$outd/confstruct.ml" "$cmd$(eval $keycmd)" ||
{
230 eval "$cmd || die genconfstr.sh failed"
231 echo "k='$cmd$(eval $keycmd)'" > "$outd/confstruct.ml.past"
232 } && vecho
"fresh $outd/confstruct.ml"
244 *) die
"unknown doc type";;
246 for m
in llpp llppac llpphtml
; do
247 src
=$srcd/adoc
/$m.adoc
249 conf
="$srcd/man/asciidoc.conf"
250 keycmd
="digest $out $src $conf"
251 cmd
="a2x -D $md -d manpage -f $doct $src"
252 isfresh
"$out" "$cmd$(eval $keycmd)" ||
{
254 eval "$cmd || die '$cmd failed'"
255 echo "k='$cmd$(eval $keycmd)'" >"$out.past"
256 } && vecho
"fresh $out"
259 completions
) die
"not yet";;
261 *) die
"no clue - '$target'";;
268 for m
in link cutils version
; do
270 cobjs
="$cobjs $outd/$m.o"
272 for m
in ml_gl ml_glarray ml_raw
; do
274 cobjs
="$cobjs $outd/lablGL/$m.o"
277 libs
="str.cma unix.cma"
278 clibs
="-L$mudir/build/native -lmupdf -lmupdf-third -lpthread"
280 mcomp
=$
(ocamlc
-config |
grep bytecomp_c_co |
{ read _ c
; echo $c; })
281 clibs
="$clibs -framework Cocoa -framework OpenGL"
282 bobjc wsi
/osx
/wsicocoa.o
283 cobjs
="$cobjs $outd/wsi/osx/wsicocoa.o"
285 clibs
="$clibs -lGL -lX11"
286 cobjs
="$cobjs $outd/wsi/x11/keysym2ucs.o"
287 bocamlc wsi
/x11
/keysym2ucs.o
290 ord
=$
(grep -v \.cmi
$outd/ordered
)
291 cmd
="ocamlc -custom $libs -o $outd/llpp $cobjs $(echo $ord) -cclib \"$clibs\""
292 keycmd
="digest $outd/llpp $cobjs $ord $mulibs"
293 isfresh
"$outd/llpp" "$cmd$(eval $keycmd)" ||
{
294 echo linking
$outd/llpp
295 eval "$cmd || die '$cmd failed'"
296 echo "k='$cmd$(eval $keycmd)'" >"$outd/llpp.past"
297 } && vecho
"fresh llpp"
300 out
="$outd/llpp.app/Contents/Info.plist"
301 keycmd
="digest $out $srcd/wsi/osx/genplist.sh"
302 isfresh
$out "$(eval $keycmd)" ||
{
303 shortver
=$
(echo $ver |
{ IFS
='-' read s _
; echo ${s#v}; })
306 (.
$srcd/wsi
/osx
/genplist.sh
) >"$out"
307 echo "k='$(eval $keycmd)'" >"$out.past"
308 } && vecho
"fresh plist"
310 out
=$outd/llpp.app
/Contents
/MacOS
/llpp
311 keycmd
="digest $out $outd/llpp"
312 isfresh
$out "$(eval $keycmd)" ||
{
313 echo "bundling llpp.app"
314 mkdir
-p "$(dirname $out)"
316 echo "k='$(eval $keycmd)'" >"$out.past"
317 } && vecho
"fresh bundle"