build: Support --srcdir build.
[mes.git] / install.sh
1 #! /bin/sh
2
3 set -e
4
5 . build-aux/trace.sh
6
7 # use bash or lose if pipes fail
8 [ -n "$BASH" ] && set -o pipefail
9
10 SHELL=${SHELL-$(command -v sh)}
11 prefix=${prefix-/usr/local}
12 top_builddest=${top_builddest-}
13 top_builddir=${top_buildir-.}
14 abs_top_srcdir=${abs_top_srcdir-$PWD}
15 abs_top_builddir=${abs_top_builddir-$PWD}
16
17 MES_PREFIX=${MES_PREFIX-$prefix/share/mes}
18 MES_SEED=${MES_SEED-../MES-SEED}
19 TINYCC_SEED=${TINYCC_SEED-../TINYCC-SEED}
20
21 GUILE=${GUILE-$(command -v guile)} || true
22 if [ -z "$GUILE" -o "$GUILE" = true ]; then
23     GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-2.2}
24 else
25     GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-$(guile -c '(display (effective-version))')}
26 fi
27 bindir=${bindir-$prefix/bin}
28 datadir=${datadir-$prefix/share/mes}
29 docdir=${docdir-$prefix/share/doc/mes}
30 infodir=${infodir-$prefix/share/info}
31 mandir=${mandir-$prefix/share/man}
32 moduledir=${moduledir-$datadir/module}
33 guile_site_dir=${guile_site_dir-$prefix/share/guile/site/$GUILE_EFFECTIVE_VERSION}
34 guile_site_ccache_dir=${guile_site_ccache_dir-$prefix/lib/guile/$GUILE_EFFECTIVE_VERSION/site-ccache}
35
36 mkdir -p $DESTDIR$bindir
37 cp ${top_builddest}src/mes $DESTDIR$bindir/mes
38 cp ${top_builddest}scripts/mescc $DESTDIR$bindir/mescc
39
40 sed \
41     -e "s,^#! /bin/sh,#! $SHELL," \
42     scripts/diff.scm > $DESTDIR$bindir/diff.scm
43 chmod -w+x $DESTDIR$bindir/diff.scm
44
45 mkdir -p $docdir
46
47 if [ -n "$PERL" -a -n "$GIT" ]\
48        && $PERL -v > /dev/null\
49        && $GIT --status > /dev/null; then
50     $PERL build-aux/gitlog-to-changelog --srcdir=. > ${top_builddest}ChangeLog
51 fi
52
53 cp\
54     AUTHORS\
55     BOOTSTRAP\
56     COPYING\
57     HACKING\
58     INSTALL\
59     NEWS\
60     README\
61     $DESTDIR$docdir
62
63 if [ -f ${top_builddest}ChangeLog ]; then
64     cp ${top_builddest}ChangeLog $DESTDIR$docdir
65 else
66     cp ChangeLog $DESTDIR$docdir
67 fi
68
69 if [ -f ${top_builddest}ChangeLog ]; then
70     cp ${top_builddest}ChangeLog $docdir
71 else
72     cp ChangeLog $docdir
73 fi
74
75 mkdir -p $DESTDIR$MES_PREFIX
76 tar -cf- include lib | tar -xf- -C $DESTDIR$MES_PREFIX
77 tar -cf- scaffold --exclude='*.gcc*' --exclude='*.mes*' | tar -xf- -C $DESTDIR$MES_PREFIX
78 tar -cf- ${top_builddest}lib | tar -xf- -C $DESTDIR$MES_PREFIX
79 tar -cf- --exclude='*.go' module | tar -xf- -C $DESTDIR$MES_PREFIX
80 tar -cf- -C mes module | tar -xf- -C $DESTDIR$MES_PREFIX
81
82 mkdir -p $DESTDIR$guile_site_dir
83 mkdir -p $DESTDIR$guile_site_ccache_dir
84 tar -cf- -C module --exclude='*.go' . | tar -xf- -C $DESTDIR$guile_site_dir
85 tar -cf- -C ${top_builddest}module --exclude='*.scm' . | tar -xf- -C $DESTDIR$guile_site_ccache_dir
86
87 if [ -f ${top_builddest}doc/mes.info ]; then
88     mkdir -p $DESTDIR$infodir
89     tar -cf- ${top_builddest}doc/mes.info* doc/images | tar -xf- --strip-components=1 -C $DESTDIR$infodir
90     install-info --info-dir=$DESTDIR$infodir ${top_builddest}doc/mes.info
91 fi
92
93 if [ -f ${top_builddest}doc/mes.1 ]; then
94     mkdir -p $DESTDIR$mandir/man1
95     cp ${top_builddest}doc/mes.1 $DESTDIR$mandir/man1/
96 fi
97
98 if [ -f ${top_builddest}doc/mescc.1 ]; then
99     mkdir -p $DESTDIR$mandir/man1
100     cp ${top_builddest}doc/mescc.1 $DESTDIR$mandir/man1/
101 fi