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