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"
57 $wsi/wsi.cmo|
*) f
="-g -strict-sequence -strict-formats -w @A";;
64 version.o
) f
='-DLLPP_VERSION="'$ver'"';;
66 f
="-g -std=c99 -O2 $muinc -Wall -Werror -Wextra -pedantic"
67 f
="$f -DCACHE_PAGEREFS"
68 $darwin && f
="$f -D__COCOA__ -D_GNU_SOURCE" \
69 || f
="$f -D_POSIX_C_SOURCE" ;;
70 */keysym2ucs.o
) f
="-O2 -include inttypes.h -DKeySym=uint32_t";;
71 */ml_
*.o
) f
="-g -Wno-pointer-sign -O2";;
77 mflags
() { echo "-I $(ocamlc -where) -g -Wall -Werror -O2"; }
79 incs
="-I $srcd/lablGL -I $srcd/$wsi -I $srcd"
80 incs
="$incs -I $outd/lablGL -I $outd/$wsi -I $outd"
82 overs
="$(ocamlc -vnum 2>/dev/null)" || overs
=""
83 test "$overs" = "4.06.1" ||
{
84 url
=http
://caml.inria.fr
/pub
/distrib
/ocaml-4.06
/ocaml-4.06
.1.
tar.xz
85 txz
=$outd/$
(basename $url)
86 isfresh
$txz $url ||
{
87 executable_p
() { command -v "$1" >/dev
/null
2>&1; }
88 if executable_p wget
; then dl
() { wget
-q "$1" -O "$2"; }
89 elif executable_p curl
; then dl
() { curl
-L "$1" -o "$2"; }
90 else die
"no program to fetch remote urls found"
93 echo "k=$url" >$txz.past
94 } && vecho
"fresh $txz"
95 absprefix
=$
(cd $outd &>/dev
/null
; pwd -P)
96 export PATH
=$absprefix/bin
:$PATH
97 isfresh
$absprefix/bin
/ocamlc
"$url" ||
(
100 cd $outd/${bn%.tar.xz}
101 .
/configure
-prefix $absprefix \
102 -no-graph -no-debugger -no-ocamldoc -no-native-compiler
105 echo "k='$url'" >$absprefix/bin
/ocamlc.past
106 ) && vecho
"fresh ocamlc"
107 overs
=$
(ocamlc
-vnum 2>/dev
/null
)
111 grep -q "$3" $outd/ordered ||
{
113 echo "$3" >>"$outd/ordered"
124 local cmd
="ocamlc -depend -bytecode -one-line $incs $s"
125 local keycmd
="digest $o $s"
126 isfresh
"$o.depl" "$overs$cmd$(eval $keycmd)" ||
{
132 test "$O" = "$D" ||
{
136 *) dd=$outd/${d#$srcd/};;
138 printf "$dd " >>"$o.depl"
141 } || die
"$cmd failed"
142 echo "k='$overs$cmd$(eval $keycmd)'" >"$o.depl.past"
144 vecho
"fresh $o.depl"
145 for d
in $
(< $o.depl
); do
146 bocaml
${d#$outd/} $
((n
+1))
150 cmd
="ocamlc $(oflags $o) -c -o $o $s"
151 keycmd
="digest $o $s $(< $o.depl)"
152 isfresh
"$o" "$overs$cmd$(eval $keycmd)" ||
{
153 printf "%*.s%s -> %s\n" $n '' "${s#$srcd/}" "${o#$outd/}"
154 eval "$cmd || die '$cmd failed'"
155 echo "k='$overs$cmd$(eval $keycmd)'" >"$o.past"
156 } && vecho
"fresh '$o'"
162 local wocmi
="${o%.cmi}"
164 case ${wocmi#$outd/} in
166 s
=$outd/confstruct.ml
167 o
=$outd/confstruct.cmo
170 test "$o" = "$wocmi" && s
=$srcd/${o%.cmo}.ml || s
=$srcd/$wocmi.mli
176 wsi
) s
="$srcd/$wsi/wsi.ml";;
177 help) s
="$srcd/help.ml";;
178 */glMisc
) s
="$srcd/lablGL/glMisc.ml";;
179 */glTex
) s
="$srcd/lablGL/glTex.ml";;
183 bocaml1
$n "$s" "$outd/${s1%.ml}.cmo" "${o#$outd/}"
189 local s
=$srcd/${1%.o}.c
190 local cmd
="ocamlc -ccopt \"$(cflags $o) -MMD -MF $o.dep -MT_ -o $o\" $s"
191 test -r $o.dep
&& read _ d
<$o.dep || d
=
192 local keycmd
='digest $o $d'
193 isfresh
"$o" "$cmd$(eval $keycmd)" ||
{
194 printf "%s -> %s\n" "${s#$srcd/}" "${o#$outd/}"
195 eval "$cmd || die '$cmd failed'"
197 echo "k='$cmd$(eval $keycmd)'" >"$o.past"
198 } && vecho
"fresh $o"
203 local s
=$srcd/${1%.o}.m
204 local cmd
="$mcomp $(mflags $o) -MMD -MF $o.dep -MT_ -c -o $o $s"
205 test -r $o.dep
&& read _ d
<$o.dep || d
=
206 local keycmd
='digest $o $d'
207 isfresh
"$o" "$cmd$(eval $keycmd)" ||
{
208 printf "%s -> %s\n" "${s#$srcd/}" "${o#$outd/}"
209 eval "$cmd || die '$cmd failed'"
211 echo "k='$cmd$(eval $keycmd)'" >"$o.past"
212 } && vecho
"fresh $o"
215 ver
=$
(cd $srcd && git describe
--tags --dirty) || ver
=unknown
217 cmd
="(. $srcd/genconfstr.sh >$outd/confstruct.ml)"
218 keycmd
="digest $srcd/genconfstr.sh $outd/confstruct.ml"
219 isfresh
"$outd/confstruct.ml" "$cmd$(eval $keycmd)" ||
{
221 eval "$cmd || die genconfstr.sh failed"
222 echo "k='$cmd$(eval $keycmd)'" > "$outd/confstruct.ml.past"
223 } && vecho
"fresh $outd/confstruct.ml"
235 *) die
"unknown doc type";;
237 for m
in llpp llppac llpphtml
; do
238 src
=$srcd/adoc
/$m.adoc
240 conf
="$srcd/man/asciidoc.conf"
241 keycmd
="digest $out $src $conf"
242 cmd
="a2x -D $md -d manpage -f $doct $src"
243 isfresh
"$out" "$cmd$(eval $keycmd)" ||
{
245 eval "$cmd || die '$cmd failed'"
246 echo "k='$cmd$(eval $keycmd)'" >"$out.past"
247 } && vecho
"fresh $out"
250 completions
) die
"not yet";;
252 *) die
"no clue - '$target'";;
259 for m
in link cutils version
; do
261 cobjs
="$cobjs $outd/$m.o"
263 for m
in ml_gl ml_glarray ml_raw
; do
265 cobjs
="$cobjs $outd/lablGL/$m.o"
268 libs
="str.cma unix.cma"
269 clibs
="-L$mudir/build/native -lmupdf -lmupdf-third -lpthread"
271 mcomp
=$
(ocamlc
-config |
grep bytecomp_c_co |
{ read _ c
; echo $c; })
272 clibs
="$clibs -framework Cocoa -framework OpenGL"
273 bobjc wsi
/osx
/wsicocoa.o
274 cobjs
="$cobjs $outd/wsi/osx/wsicocoa.o"
276 clibs
="$clibs -lGL -lX11"
277 cobjs
="$cobjs $outd/wsi/x11/keysym2ucs.o"
278 bocamlc wsi
/x11
/keysym2ucs.o
281 ord
=$
(grep -v \.cmi
$outd/ordered
)
282 cmd
="ocamlc -custom $libs -o $outd/llpp $cobjs $(echo $ord) -cclib \"$clibs\""
283 keycmd
="digest $outd/llpp $cobjs $ord $mulibs"
284 isfresh
"$outd/llpp" "$cmd$(eval $keycmd)" ||
{
285 echo linking
$outd/llpp
286 eval "$cmd || die '$cmd failed'"
287 echo "k='$cmd$(eval $keycmd)'" >"$outd/llpp.past"
288 } && vecho
"fresh llpp"
291 out
="$outd/llpp.app/Contents/Info.plist"
292 keycmd
="digest $out $srcd/wsi/osx/genplist.sh"
293 isfresh
$out "$(eval $keycmd)" ||
{
294 shortver
=$
(echo $ver |
{ IFS
='-' read s _
; echo ${s#v}; })
297 (.
$srcd/wsi
/osx
/genplist.sh
) >"$out"
298 echo "k='$(eval $keycmd)'" >"$out.past"
299 } && vecho
"fresh plist"
301 out
=$outd/llpp.app
/Contents
/MacOS
/llpp
302 keycmd
="digest $out $outd/llpp"
303 isfresh
$out "$(eval $keycmd)" ||
{
305 mkdir
-p "$(dirname $out)"
307 echo "k='$(eval $keycmd)'" >"$out.past"
308 } && vecho
"fresh bundle"