xref: /Universal-ctags/misc/tinst (revision e7b94675f3c160f277ded00fc32accb41854d009)
1#!/bin/sh
2#
3#   Copyright (C) 2014 Masatake YAMATO
4#
5#   This program is free software; you can redistribute it and/or modify
6#   it under the terms of the GNU General Public License as published by
7#   the Free Software Foundation; either version 2 of the License, or
8#   (at your option) any later version.
9#
10#   This program is distributed in the hope that it will be useful,
11#   but WITHOUT ANY WARRANTY; without even the implied warranty of
12#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#   GNU General Public License for more details.
14#
15#   You should have received a copy of the GNU General Public License
16#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18TINST_ROOT=
19
20ERROR ()
21{
22    local status=$1
23    local msg=$2
24    shift 2
25    echo "$msg" 1>&2
26    exit $status
27}
28
29MSG_title()
30{
31    printf '%-70s' "${1}"
32}
33
34MSG_passed()
35{
36    echo passed
37}
38
39MSG_failed()
40{
41    echo failed
42}
43
44MSG_done()
45{
46    echo done
47}
48
49
50T_existing()
51{
52    local f=$1
53    shift
54    local op
55    local r=0
56
57    for op in "$@"; do
58	case "$op" in
59	    -d)
60		MSG_title "The existence of $f as a directory"
61		;;
62	    -f)
63		MSG_title "The existence of $f as an file"
64		;;
65	    -r)
66		MSG_title "The read mode of $f"
67		;;
68	    -x)
69		MSG_title "The existence of $f as an executable"
70		;;
71	    *)
72		MSG_title "The existence of $f with $op operator"
73		;;
74	esac
75	if [ $op ${TINST_ROOT}/$f ]; then
76	    MSG_passed
77	else
78	    MSG_failed
79	    r=$(( r + 1 ))
80	fi
81    done
82    return ${r}
83}
84
85prepare()
86{
87    local srcdir=$1
88    local root=$2
89
90
91    MSG_title "Preparing installation tests"
92
93    if ! [ -e ${srcdir}/configure ]; then
94	ERROR 2 "cannot find configure script"
95    fi
96
97    mkdir -p "$root"
98
99    if ! [ -d "$root" ]; then
100	ERROR 2 "failed in directory creation: $roo"
101    fi
102
103    rm Makefile
104
105    if ! ${srcdir}/configure --prefix=$root > /dev/null; then
106	ERROR 2 "failed in running configure script $root"
107    fi
108
109    if ! [ -e Makefile ]; then
110	ERROR 2 "cannot find Makefile"
111    fi
112
113    if ! make > /dev/null; then
114	ERROR 2 "failed in building ctags"
115    fi
116
117    if ! make install > /dev/null; then
118	ERROR 2 "failed in installing ctags"
119    fi
120
121    MSG_done
122    return 0
123}
124
125cleanup()
126{
127    MSG_title "Cleanup installation tests"
128    MSG_done
129    return 0
130}
131
132check()
133{
134    T_existing /bin/ctags -f -x
135    T_existing /bin/readtags -f -x
136
137    T_existing /share/man/man1/ctags.1 -f -r
138}
139
140main()
141{
142    local srcdir
143    local root
144    local status
145
146    if [ $# = 2 ]; then
147	srcdir=$1
148	root=$2
149	shift 2
150    else
151	ERROR 2 "A installation root must be given as the first argument"
152    fi
153
154    prepare "${srcdir}" "${root}"
155
156    TINST_ROOT=${root}
157    check
158    status=$?
159
160    cleanup "${root}"
161
162    return $status
163}
164
165main "$@"
166