-
Notifications
You must be signed in to change notification settings - Fork 39
/
configure
executable file
·203 lines (173 loc) · 4.55 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
#! /bin/sh
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy
# of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
set -e
readonly PROGNAME="${0##*/}"
readonly SRCDIR="$(cd "$(dirname "${0}")" && pwd -P)"
# Settings that end up in the Makefile.
CARGO=cargo
CLEANFILES=target
FEATURES=
GOPATH="$(pwd)/.gopath"
GOROOT=
IS_BMAKE=
IS_GNUMAKE=
PREFIX=
DISTCLEANFILES="Makefile go.sum ${GOPATH}"
# List of variables exposed to the Makefile.
MK_VARS="CARGO CLEANFILES DISTCLEANFILES FEATURES GOPATH GOROOT PREFIX"
# List of variables replaced in the Makefile.
MK_SUBSTS="IS_BMAKE IS_GNUMAKE"
err() {
echo "${PROGNAME}: E: ${@}" 1>&2
exit 1
}
info() {
echo "${PROGNAME}: I: ${@}" 1>&2
}
find_prog() {
local prog="${1}"; shift
local oldifs="${IFS}"
IFS=:
set -- ${PATH}
IFS="${oldifs}"
while [ ${#} -gt 0 ]; do
if [ -x "${1}/${prog}" ]; then
echo "${1}/${prog}"
return 0
else
shift
fi
done
return 1
}
find_progs() {
while [ ${#} -gt 0 ]; do
if find_prog "${1}"; then
return 0
else
shift
fi
done
return 1
}
setup_cargo() {
local user_override="${1}"; shift
if [ -n "${user_override}" ]; then
[ -e "${user_override}" ] || err "cargo not found in" \
"${user_override}; bogus argument to --cargo?"
CARGO="${user_override}"
else
local cargo="$(find_progs cargo)"
[ -n "${cargo}" ] || err "Cannot find cargo in path; pass" \
"--cargo=/path/to/cargo to configure"
CARGO="${cargo}"
fi
info "Using Cargo from: ${CARGO}"
}
# Installs git hooks into the git directory provided in git_dir.
setup_git() {
local git_dir="${1}"; shift
cd "${git_dir}/hooks"
for hook in ../../admin/pre-commit; do
info "Installing git hook ${hook##*/}"
ln -s -f "${hook}" .
done
cd - >/dev/null 2>&1
}
setup_go() {
local user_override="${1}"; shift
if [ -n "${user_override}" ]; then
[ "${user_override}" = none ] || GOROOT="${user_override}"
else
local go="$(find_progs go)"
[ -n "${go}" ] && GOROOT="$(dirname "$(dirname "${go}")")"
fi
if [ -z "${GOROOT}" ]; then
info "Go not found; cannot run integration tests"
else
info "Using Go with GOROOT: ${GOROOT}"
GOPATH="${GOPATH}" "${GOROOT}/bin/go" mod download
GOPATH="${GOPATH}" "${GOROOT}/bin/go" install golang.org/x/lint/golint
fi
}
setup_make() {
IS_BMAKE=#
IS_GNUMAKE=#
if make --version >/dev/null 2>&1; then
info "make is GNU Make"
IS_GNUMAKE=
else
info "make is bmake"
IS_BMAKE=
fi
}
setup_prefix() {
local prefix="${1:-/usr/local}"; shift
info "Installation prefix is ${prefix}"
PREFIX="${prefix}"
}
setup_vscode() {
{
echo '// AUTOMATICALLY GENERATED!!!'
echo '// EDIT settings.json.in INSTEAD'
sed \
-e "s,__GOPATH__,${GOPATH},g" \
-e "s,__GOROOT__,${GOROOT},g" \
-e "s,__TOOLS_GOPATH__,$(pwd)/.gopath-tools,g" \
.vscode/settings.json.in
} >.vscode/settings.json
}
generate_makefile() {
local src="${1}"; shift
local dest="${1}"; shift
info "Generating ${dest}"
echo "# AUTOMATICALLY GENERATED; DO NOT EDIT!" >"${dest}.tmp"
for var in ${MK_VARS}; do
local value
eval "value=\"\$${var}\""
echo "${var} = ${value}" >>"${dest}.tmp"
done
local substs=
for var in ${MK_SUBSTS}; do
local value
eval "value=\"\$${var}\""
substs="${substs} -e s,@${var}@,${value},g"
done
sed ${substs} "${src}" >>"${dest}.tmp"
mv "${dest}.tmp" "${dest}"
}
main() {
cd "${SRCDIR}"
local cargo=
local goroot=
local prefix=
for arg in "${@}"; do
case "${arg}" in
--cargo=*) cargo="${arg#*=}" ;;
--features=*) FEATURES="${arg#*=}" ;;
--goroot=*) goroot="${arg#*=}" ;;
--prefix=*) prefix="${arg#*=}" ;;
*) err "Unknown argument ${arg}" ;;
esac
done
setup_cargo "${cargo}"
[ -d .git ] && setup_git .git
setup_go "${goroot}"
setup_make
setup_prefix "${prefix}"
setup_vscode
generate_makefile Makefile.in Makefile
}
main "${@}"