This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
/
configure
executable file
·247 lines (210 loc) · 6.94 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/bin/sh
#/ Usage: ./configure [OPTION]... [VAR=VALUE]...
#/ configure shocco for installation on this system.
#/
#/ Options
#/ --development configure for local working copy development
#/
#/ Installation locations
#/ --prefix=PREFIX install files in PREFIX [/usr/local]
#/ --bindir=DIR user executables [PREFIX/bin]
#/ --sysconfdir=DIR system configuration files [PREFIX/etc]
#/ --datarootdir=DIR data file root [PREFIX/share]
#/ --datadir=DIR data files [DATAROOTDIR]
#/ --mandir=DIR man documentation [DATAROOTDIR/man]
warn () { echo "$@" 1>&2; }
longarg () { echo "$1" | sed "s/^$2=//"; }
# Argument Parsing
# ----------------
sourcedir="$(cd "$(dirname $0)" && pwd)"
develmode=false
while test $# -gt 0
do
case "$1" in
# Options
--develop|--development)
prefix="$sourcedir/work"
bindir="$sourcedir"
libexecdir="$sourcedir"
localstatedir="$prefix"
sysconfdir="$sourcedir"
datarootdir="$sourcedir"
datadir="$sourcedir"
mandir="$sourcedir/man"
develmode=true
shift
;;
# Installation locations:
--prefix) prefix="$2";shift;shift;;
--prefix=*) prefix="$(longarg "$1" --prefix)";shift;;
--bindir) bindir="$2";shift;shift;;
--bindir=*) bindir="$(longarg "$1" --bindir)";shift;;
--libexecdir) libexecdir="$2";shift;shift;;
--libexecdir=*) libexecdir="$(longarg "$1" --libexecdir)";shift;;
--localstatedir) localstatedir="$2";shift;shift;;
--localstatedir=*) localstatedir="$(longarg "$1" --localstatedir)";shift;;
--sysconfdir) sysconfdir="$2";shift;shift;;
--sysconfdir=*) sysconfdir="$(longarg "$1" --sysconfdir)";shift;;
--datarootdir) datarootdir="$2";shift;shift;;
--datarootdir=*) datarootdir="$(longarg "$1" --datarootdir)";shift;;
--datadir) datadir="$2";shift;shift;;
--datadir=*) datadir="$(longarg "$1" --datadir)";shift;;
--mandir) mandir="$2";shift;shift;;
--mandir=*) mandir="$(longarg "$1" --mandir)";shift;;
# Environment variables passed on command line:
[A-Z]*=*) name="${1%%=*}"
value="${1#*=}"
shift
eval "${name}='${value}'";;
# Bail out with usage otherwise.
*) grep '^#/' < "$0" | cut -c4-
exit 2;;
esac
done
# Finding Stuff Functions
# -----------------------
looking () { printf "looking $(echo $@)"; }
missing () { printf " (nope)\n"; }
ok () { printf " OK\n"; }
found () {
printf " (${1:-found})"
test -n "$2" && printf " $2"
printf "\n"
}
have () {
for f in "$@"
do
# if a whole command line was given, assume it exists
expr "$f" : '..* ' >/dev/null && {
echo "$f"
return 0
}
# look for the path with command(1)
_havepath=$(command -v "$f") || { continue; }
echo "$_havepath"
return 0
done
return 1
}
# Usage: stdutil <name> <variable> <path>...
stdutil () {
looking "for $1"; shift
_varname="$1"; shift
if _path=$(have "$@")
then found "$_path"
reconf $_varname "$_path"
else missing
reconf $_varname ""
fi
return 0
}
# Build up lists of config stuff to write to config.sh and config.mk
SHCONFIG=
MAKECONFIG=
reconf () {
SHCONFIG="$SHCONFIG
$1='$2'"
eval "$SHCONFIG"
MAKECONFIG="$MAKECONFIG
$1 = $2"
}
UNAME=$(uname 2>/dev/null)
HOST=$(hostname 2>/dev/null)
TIME=$(date 2>/dev/null)
: ${prefix:="/usr/local"}
: ${exec_prefix:="$prefix"}
: ${bindir:="$exec_prefix/bin"}
: ${libexecdir:="$exec_prefix/libexec"}
: ${localstatedir:="$prefix/var"}
: ${sysconfdir:="$prefix/etc"}
: ${datarootdir:="$prefix/share"}
: ${datadir:="$datarootdir"}
: ${mandir:="$datadir/man"}
: ${docdir:="$datadir/doc"}
reconf prefix "$prefix"
reconf exec_prefix "$exec_prefix"
reconf bindir "$bindir"
reconf libexecdir "$libexecdir"
reconf localstatedir "$localstatedir"
reconf sysconfdir "$sysconfdir"
reconf datarootdir "$datarootdir"
reconf datadir "$datadir"
reconf mandir "$mandir"
reconf develmode "$develmode"
PATH="$(getconf PATH 2>/dev/null || echo /usr/bin:/bin)"
PATH="$bindir:$PATH"
test -d "/usr/local" &&
PATH="$PATH:/usr/local/bin"
test "$UNAME" = Darwin -a -d /opt/local &&
PATH="$PATH:/opt/local/bin"
test -d /usr/pkg &&
PATH="$PATH:/usr/pkg/bin"
echo "building for ${UNAME:-unknown}" \
"on ${HOST:-localhost}" \
"at ${TIME:-a time unknown}"
looking "for /bin/sh"
SH=$(have /bin/sh) && {
if expr "$("$SH" --version 2>/dev/null)" : '.*bash' >/dev/null
then
found '' "oh ick, it looks like bash"
else
found
fi
} || missing
reconf SHELL "$SH"
stdutil bash BASH /bin/bash /usr/bin/bash bash
stdutil dash DASH /bin/dash /usr/bin/dash dash
stdutil sed SED /bin/sed /usr/bin/sed sed gsed
stdutil sort SORT /bin/sort /usr/bin/sort sort gsort
stdutil tr TR /usr/bin/tr tr gtr
stdutil cut CUT /usr/bin/cut cut gcut
stdutil csplit CSPLIT /usr/bin/csplit csplit gcsplit
stdutil mktemp MKTEMP /bin/mktemp mktemp gmktemp
if test "$UNAME" = Darwin
then stdutil open BROWSER /usr/bin/open
else stdutil xdg-open XDG_OPEN xdg-open
stdutil firefox FIREFOX firefox
reconf BROWSER "${XDG_OPEN:-$FIREFOX}"
fi
stdutil ronn RONN ronn $RONN
stdutil markdown MARKDOWN markdown Markdown.pl $MARKDOWN
stdutil perl PERL perl
stdutil pygmentize PYGMENTIZE pygmentize $PYGMENTIZE
set -e
eval "$SHCONFIG"
test -z "$RONN" &&
warn "warn: ronn is not installed. cannot rebuild manpages. no biggie."
test -z "$MARKDOWN" && {
warn "warn: no markdown found on PATH. installing Gruber's with shocco."
INSTALL_MARKDOWN=" (will be installed)"
MARKDOWN="$bindir/markdown"
reconf MARKDOWN "$MARKDOWN"
INSTALL_PREREQUISITES=install-markdown
}
reconf INSTALL_PREREQUISITES "$INSTALL_PREREQUISITES"
test -z "$PYGMENTIZE" && {
warn "fatal: no pygmentize found on PATH. install it and try again."
warn " see http://pygments.org/ for more information."
exit 3
}
echo "okay, looks like you have everything we need. generating config files."
echo writing config.mk...
cat <<EOF > config.mk
$MAKECONFIG
EOF
echo writing config.sh...
cat <<EOF > config.sh
# utility locations
$SHCONFIG
EOF
cat <<MESSAGE
configuration:
markdown: $MARKDOWN $INSTALL_MARKDOWN
pygmentize: $PYGMENTIZE
bindir: $bindir
mandir: $mandir
MESSAGE
if $develmode
then echo "okay. ready for development. run \`make' or \`make auto' to build."
else echo "okay. run \`make' to build and \`make install' to install."
fi