summaryrefslogtreecommitdiffstats
path: root/configure
blob: 2c7ef4b00b359ae5d4bad33ff02d236067e560cf (plain)
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#! /bin/sh
#
# pro-archman
# configure
# Configuration script to generate Makefile.
#
# Copyright (C) 2011-2013 Patrick "P. J." McDermott
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

package_name='pro-archman'
package_version='1.1.0'
package_description='ProteanOS Archive Manager'
package_library='pro-archman'

srcdir="$(cd "${0%/*}" && pwd)"
prefix='/usr/local'
bindir='${prefix}/bin'
libdir='${prefix}/share'
pkglibdir='${libdir}/${package_library}'
datadir='${prefix}/share'
mandir='${datadir}/man'
man1dir='${mandir}/man1'
localedir='${datadir}/locale'

quiet='false'
missing_deps='false'
dep_cmds='
sh
make
'

long_opts_with_args='
srcdir
prefix
bindir
libdir
pkglibdir
datadir
mandir
man1dir
localedir
'

features="
${dep_cmds}
${dep_libs}
${opt_dep_cmds}
${opt_dep_libs}
"

subst_vars="
package_name
package_version
package_description
package_library
${long_opts_with_args}
${features}
"

main()
{
	parse_options "${@}"
	shift ${optind}
	if [ ${#} -ne 0 ]; then
		print_usage
		exit
	fi

	for dep in ${dep_cmds}; do
		dep_name="$(printf '%s' "${dep}" | tr -c '[a-z0-9]' '_')"
		dep_val="$(eval printf \'%s\' \"\$\{"${dep_name}"\}\")"
		if [ -z "${dep_val}" ]; then
			find_dep_cmd "${dep}" || missing_deps='true'
		fi
	done
	for dep in ${dep_libs}; do
		dep_name="$(printf '%s' "${dep}" | tr -c '[a-z0-9]' '_')"
		dep_val="$(eval printf \'%s\' \"\$\{"${dep_name}"\}\")"
		if [ -z "${dep_val}" ]; then
			find_dep_lib "${dep}" || missing_deps='true'
		fi
	done
	for dep in ${opt_dep_cmds}; do
		dep_name="$(printf '%s' "${dep}" | tr -c '[a-z0-9]' '_')"
		dep_val="$(eval printf \'%s\' \"\$\{"${dep_name}"\}\")"
		if [ -z "${dep_val}" ]; then
			find_dep_cmd "${dep}"
		fi
	done
	for dep in ${opt_dep_libs}; do
		dep_name="$(printf '%s' "${dep}" | tr -c '[a-z0-9]' '_')"
		dep_val="$(eval printf \'%s\' \"\$\{"${dep_name}"\}\")"
		if [ -z "${dep_val}" ]; then
			find_dep_lib "${dep}"
		fi
	done

	if ${missing_deps}; then
		cat <<EOF

Some dependencies could not be found.
Please make sure all dependencies are installed and try again.

EOF
		exit 1
	fi

	write_makefiles

	printf '\nConfiguration complete!\n\n'
}

print_usage()
{
	printf 'Usage: %s [OPTION]...\n' "${0}"
}

print_help()
{
	cat <<EOF
\`configure' configures ${package_name} ${package_version} to adapt to many \
kinds of systems.

$(print_usage)

Configuration:
  -h, --help              display this help and exit
  -V, --version           display version information and exit
  -q, --quiet             do not print \`checking ...' messages
      --srcdir=SRCDIR     find the sources in SRCDIR
                          default: configure dir

Installation directories:
  --prefix=PREFIX         install files under PREFIX
                          default: /usr/local
  --bindir=BINDIR         install scripts in BINDIR
                          default: PREFIX/bin
  --libdir=LIBDIR         install library scripts in LIBDIR
                          default: PREFIX/share
  --pkglibdir=PKGLIBDIR   install package library scripts in PKGLIBDIR
                          default: LIBDIR/${package_library}
  --datadir=DATADIR       expect to find data in DATADIR
                          default: PREFIX/share
  --mandir=MANDIR         install manual pages in MANDIR
                          default: DATADIR/man
  --man1dir=MAN1DIR       install section 1 manual pages in MAN1DIR
                          default: MANDIR/man1
  --localedir=LOCALEDIR   install locales in LOCALEDIR
                          default: DATADIR/locale

Dependencies:
  --with-sh=PATH          use sh at PATH
EOF
}

print_version()
{
	cat <<EOF
${package_name} ${package_version} configure
Not generated by GNU Autoconf

Copyright (C) 2011-2013 Patrick "P. J." McDermott
License: GNU GPL version 2 or later <http://www.gnu.org/licenses/gpl.html>.
This configure script is free software: you can redistribute and/or modify it.
There is NO WARRANTY, to the extent permitted by law.
EOF
}

parse_options()
{
	optind=0

	for _opt; do

		# Handle arguments of "--opt arg" options.
		if [ -n "${_prev}" ]; then
			eval "${_prev}"=\"\$\{_opt\}\"
			_prev=''
			continue
		fi

		# Detect "--opt=arg" and "--opt arg" options.
		case "${_opt}" in
			*=*)
				_optarg="${_opt#*=}"
				_opt="${_opt%=*}"
				_optarg_set='true'
				;;
			*)
				_optarg_set='false'
				;;
		esac

		# Handle short and long options.
		case "${_opt}" in
			--)
				break
				;;
			-h|--help)
				print_help
				exit 0
				;;
			-V|--version)
				print_version
				exit 0
				;;
			-q|--quiet)
				quiet='true'
				continue
				;;
		esac

		# Anything beyond this point should be a long option.
		case "${_opt}" in
			--with-*)
				_opt="${_opt#--with-}"
				_opts="${features}"
				_type='package'
				;;
			--*)
				_opt="${_opt#--}"
				_opts="${long_opts_with_args}"
				_type='option'
				;;
			*)
				break
				;;
		esac

		grep "^${_opt}\$" >/dev/null 2>&1 <<EOF
"${_opts}"
EOF
		if [ ${?} -ne 0 ]; then
			printf 'warning: unrecognized %s name: %s\n' \
				"${_type}" "${_opt}" >&2
		elif ${_optarg_set}; then
			_opt="$(printf '%s' "${_opt}" | tr -c '[a-z0-9]' '_')"
			eval "${_opt}"=\"\$\{_optarg\}\"
		else
			_prev="${_opt}"
		fi

		optind=$(($optind + 1))

	done
}

find_dep_cmd()
{
	_dep="${1}"

	${quiet} || printf 'checking for %s... ' "${_dep}"

	IFS=':'

	for _element in ${PATH}; do
		unset IFS
		: ${_element=-.}
		if [ -f "${_element}/${_dep}" -a -x "${_element}/${_dep}" ]; then
			${quiet} || printf '%s/%s\n' "${_element}" "${_dep}"
			_var="$(printf '%s' "${_dep}" | tr -c '[a-z0-9]' '_')"
			eval "${_var}"=\"${_element}/${_dep}\"
			return 0
		fi
	done

	unset IFS

	${quiet} || printf 'not found\n'
	return 1
}

find_dep_lib()
{
	_dep="${1}"

	${quiet} || printf 'checking for %s... ' "${_dep}"

	for _element in $(eval printf \'%s\' \""${libdir}"\") ${PATH}; do
		: ${_element=-.}
		if [ -d "${_element}/${_dep}" ]; then
			${quiet} || printf '%s/%s\n' "${_element}" "${_dep}"
			_var="$(printf '%s' "${_dep}" | tr -c '[a-z0-9]' '_')"
			eval "${_var}"=\"${_element}/${_dep}\"
			return 0
		fi
	done

	${quiet} || printf 'not found\n'
	return 1
}

write_makefiles()
{
	mkdir -p src lib lib/cmd locale man tests

	# Make a script to edit input makefiles.
	_sed_script=''
	for _var in ${subst_vars}; do
		_var="$(printf '%s' "${_var}" | tr -c '[a-z0-9]' '_')"
		_val="$(eval printf \'%s\' \"\$\{"${_var}"\}\")"
		_sed_script="${_sed_script}s&@${_var}@&${_val}&g;"
	done

	sed "${_sed_script}" "${srcdir}/Makefile.in" >'Makefile'
}

main "${@}"