build: Support $DESTDIR.
[mes.git] / install.sh
1 #! /bin/sh
2
3 set -e
4 set -o pipefail
5
6 if [ -n "$BUILD_DEBUG" ]; then
7     set -x
8 fi
9
10 SHELL=${SHELL-$(command -v sh)}
11 PREFIX=${PREFIX-/usr/local}
12 MES_PREFIX=${MES_PREFIX-$PREFIX/share/mes}
13 MES_SEED=${MES_SEED-../mes-seed}
14 TINYCC_SEED=${TINYCC_SEED-../tinycc-seed}
15
16 mkdir -p $DESTDIR$PREFIX/bin
17 cp src/mes $DESTDIR$PREFIX/bin/mes
18
19 mkdir -p $DESTDIR$PREFIX/lib
20 mkdir -p $DESTDIR$MES_PREFIX/lib
21 cp scripts/mescc $DESTDIR$PREFIX/bin/mescc
22
23 mkdir -p $DESTDIR$MES_PREFIX
24 tar -cf- doc guile include lib module scaffold | tar -xf- -C $DESTDIR$MES_PREFIX
25
26 GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-2.2}
27 DATADIR=${MODULEDIR-$PREFIX/share/mes}
28 DOCDIR=${MODULEDIR-$PREFIX/share/doc/mes}
29 MODULEDIR=${MODULEDIR-$DATADIR/module}
30 GUILEDIR=${MODULEDIR-$PREFIX/share/guile/site/$GUILE_EFFECTIVE_VERSION}
31 GODIR=${GODIR-$PREFIX/lib/guile/$GUILE_EFFECTIVE_VERSION/site-ccache}
32 DOCDIR=${MODULEDIR-$PREFIX/share/doc/mes}
33
34 chmod +w $DESTDIR$PREFIX/bin/mescc
35 sed \
36     -e "s,^#! /bin/sh,#! $SHELL," \
37     -e "s,module/,$MODULEDIR/," \
38     -e "s,@DATADIR@,$DATADIR,g" \
39     -e "s,@DOCDIR@,$DOCDIR,g" \
40     -e "s,@GODIR@,$GODIR,g" \
41     -e "s,@GUILEDIR@,$GUILEDIR,g" \
42     -e "s,@MODULEDIR@,$MODULEDIR,g" \
43     -e "s,@PREFIX@,$PREFIX,g" \
44     -e "s,@VERSION@,$VERSION,g" \
45     scripts/mescc > $DESTDIR$PREFIX/bin/mescc
46 chmod +w $DESTDIR$MODULEDIR/mes/boot-0.scm
47 sed \
48     -e "s,^#! /bin/sh,#! $SHELL," \
49     -e "s,module/,$MODULEDIR/," \
50     -e "s,@DATADIR@,$DATADIR,g" \
51     -e "s,@DOCDIR@,$DOCDIR,g" \
52     -e "s,@GODIR@,$GODIR,g" \
53     -e "s,@GUILEDIR@,$GUILEDIR,g" \
54     -e "s,@MODULEDIR@,$MODULEDIR,g" \
55     -e "s,@PREFIX@,$PREFIX,g" \
56     -e "s,@VERSION@,$VERSION,g" \
57     module/mes/boot-0.scm > $DESTDIR$MODULEDIR/mes/boot-0.scm
58
59 sed \
60     -e "s,^#! /bin/sh,#! $SHELL," \
61     scripts/diff.scm > $DESTDIR$PREFIX/bin/diff.scm
62 chmod -w+x $DESTDIR$PREFIX/bin/diff.scm
63
64 if [ -f doc/mes.info ]; then
65     mkdir -p $DESTDIR$PREFIX/share/info
66     install-info --info-dir=$DESTDIR$PREFIX/share/info doc/mes.info
67     tar -cf- doc/mes.info* | tar -xf- --strip-components=1 -C $DESTDIR$PREFIX/share/info
68 fi
69
70 if [ -f doc/mes.1 ]; then
71     mkdir -p $DESTDIR$PREFIX/man/man1
72     cp doc/mes.1 $DESTDIR$PREFIX/man/man1/
73 fi
74
75 if [ -f doc/mescc.1 ]; then
76     mkdir -p $DESTDIR$PREFIX/man/man1
77     cp doc/mescc.1 $DESTDIR$PREFIX/man/man1/
78 fi