src/test/resources/golden-sample/configure

changeset 87
60bd4f61e89f
parent 86
ad0f22720c50
child 88
0a663c3692a0
equal deleted inserted replaced
86:ad0f22720c50 87:60bd4f61e89f
1 #!/bin/sh
2
3 # create temporary directory
4 TEMP_DIR=".tmp-`uname -n`"
5 rm -Rf "$TEMP_DIR"
6 if mkdir -p "$TEMP_DIR"; then
7 :
8 else
9 echo "Cannot create tmp dir $TEMP_DIR"
10 echo "Abort"
11 exit 1
12 fi
13 touch "$TEMP_DIR/options"
14 touch "$TEMP_DIR/features"
15
16 # define standard variables
17 PREFIX=/usr
18 EPREFIX=
19 BINDIR=
20 SBINDIR=
21 LIBDIR=
22 LIBEXECDIR=
23 DATADIR=
24 SYSCONFDIR=
25 SHAREDSTATEDIR=
26 LOCALSTATEDIR=
27 INCLUDEDIR=
28 INFODIR=
29 MANDIR=
30
31 # custom variables
32 HOST=`uname -n`
33 PREFIX="`pwd`/work"
34 INSTALL_DIR="$PREFIX"
35
36 # features
37 FEATURE_PG=auto
38
39 # clean abort
40 abort_configure()
41 {
42 rm -Rf "$TEMP_DIR"
43 exit 1
44 }
45
46 # help text
47 printhelp()
48 {
49 echo "Usage: $0 [OPTIONS]..."
50 cat << __EOF__
51 Installation directories:
52 --prefix=PREFIX path prefix for architecture-independent files
53 [/usr]
54 --exec-prefix=EPREFIX path prefix for architecture-dependent files
55 [PREFIX]
56
57 --bindir=DIR user executables [EPREFIX/bin]
58 --sbindir=DIR system admin executables [EPREFIX/sbin]
59 --libexecdir=DIR program executables [EPREFIX/libexec]
60 --sysconfdir=DIR system configuration files [PREFIX/etc]
61 --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
62 --localstatedir=DIR modifiable single-machine data [PREFIX/var]
63 --libdir=DIR object code libraries [EPREFIX/lib]
64 --includedir=DIR C header files [PREFIX/include]
65 --datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
66 --datadir=DIR read-only architecture-independent data [DATAROOTDIR]
67 --infodir=DIR info documentation [DATAROOTDIR/info]
68 --mandir=DIR man documentation [DATAROOTDIR/man]
69
70 Optional Features:
71 --disable-pg
72
73 __EOF__
74 }
75
76 #
77 # parse arguments
78 #
79 BUILD_TYPE="default"
80 for ARG in "$@"
81 do
82 case "$ARG" in
83 "--prefix="*) PREFIX=${ARG#--prefix=} ;;
84 "--exec-prefix="*) EPREFIX=${ARG#--exec-prefix=} ;;
85 "--bindir="*) BINDIR=${ARG#----bindir=} ;;
86 "--sbindir="*) SBINDIR=${ARG#--sbindir=} ;;
87 "--libdir="*) LIBDIR=${ARG#--libdir=} ;;
88 "--libexecdir="*) LIBEXECDIR=${ARG#--libexecdir=} ;;
89 "--datadir="*) DATADIR=${ARG#--datadir=} ;;
90 "--sysconfdir="*) SYSCONFDIR=${ARG#--sysconfdir=} ;;
91 "--sharedstatedir="*) SHAREDSTATEDIR=${ARG#--sharedstatedir=} ;;
92 "--localstatedir="*) LOCALSTATEDIR=${ARG#--localstatedir=} ;;
93 "--includedir="*) INCLUDEDIR=${ARG#--includedir=} ;;
94 "--infodir="*) INFODIR=${ARG#--infodir=} ;;
95 "--mandir"*) MANDIR=${ARG#--mandir} ;;
96 "--help"*) printhelp; abort_configure ;;
97 "--debug") BUILD_TYPE="debug" ;;
98 "--release") BUILD_TYPE="release" ;;
99 "--enable-pg") FEATURE_PG=on ;;
100 "--disable-pg") unset FEATURE_PG ;;
101 "-"*) echo "unknown option: $ARG"; abort_configure ;;
102 esac
103 done
104
105
106 # set dir variables
107 : ${EPREFIX:="$PREFIX"}
108 : ${BINDIR:="$EPREFIX/bin"}
109 : ${SBINDIR:="$EPREFIX/sbin"}
110 : ${LIBDIR:="$EPREFIX/lib"}
111 : ${LIBEXECDIR:="$EPREFIX/libexec"}
112 : ${DATADIR:="$PREFIX/share"}
113 : ${SYSCONFDIR:="$PREFIX/etc"}
114 : ${SHAREDSTATEDIR:="$PREFIX/com"}
115 : ${LOCALSTATEDIR:="$PREFIX/var"}
116 : ${INCLUDEDIR:="$PREFIX/include"}
117 : ${INFODIR:="$PREFIX/info"}
118 : ${MANDIR:="$PREFIX/man"}
119
120 # Test for availability of pkg-config
121 PKG_CONFIG=`command -v pkg-config`
122 : ${PKG_CONFIG:="false"}
123
124 # Simple uname based platform detection
125 # $PLATFORM is used for platform dependent dependency selection
126 OS=`uname -s`
127 OS_VERSION=`uname -r`
128 printf "detect platform... "
129 if [ "$OS" = "SunOS" ]; then
130 PLATFORM="solaris sunos unix svr4"
131 fi
132 if [ "$OS" = "Linux" ]; then
133 PLATFORM="linux unix"
134 fi
135 if [ "$OS" = "FreeBSD" ]; then
136 PLATFORM="freebsd bsd unix"
137 fi
138 if [ "$OS" = "Darwin" ]; then
139 PLATFORM="macos osx bsd unix"
140 fi
141 if echo "$OS" | grep -i "MINGW" > /dev/null; then
142 PLATFORM="windows mingw"
143 fi
144 : ${PLATFORM:="unix"}
145
146 PLATFORM_NAME=`echo "$PLATFORM" | cut -f1 -d' ' -`
147 echo "$PLATFORM_NAME"
148
149 isplatform()
150 {
151 for p in $PLATFORM
152 do
153 if [ "$p" = "$1" ]; then
154 return 0
155 fi
156 done
157 return 1
158 }
159 notisplatform()
160 {
161 for p in $PLATFORM
162 do
163 if [ "$p" = "$1" ]; then
164 return 1
165 fi
166 done
167 return 0
168 }
169
170
171 # generate vars.mk
172 cat > "$TEMP_DIR/vars.mk" << __EOF__
173 PREFIX="$PREFIX"
174 EPREFIX="$EPREFIX"
175 BINDIR="$BINDIR"
176 SBINDIR="$SBINDIR"
177 LIBDIR="$LIBDIR"
178 LIBEXECDIR="$LIBEXECDIR"
179 DATADIR="$DATADIR"
180 SYSCONFDIR="$SYSCONFDIR"
181 SHAREDSTATEDIR="$SHAREDSTATEDIR"
182 LOCALSTATEDIR="$LOCALSTATEDIR"
183 INCLUDEDIR="$INCLUDEDIR"
184 INFODIR="$INFODIR"
185 MANDIR="$MANDIR"
186 HOST="$HOST"
187 PREFIX="$PREFIX"
188 INSTALL_DIR="$INSTALL_DIR"
189 __EOF__
190 sort -u -o "$TEMP_DIR/vars.mk" "$TEMP_DIR/vars.mk"
191
192
193 # toolchain detection utilities
194 . make/toolchain.sh
195
196 #
197 # DEPENDENCIES
198 #
199
200 # check languages
201 lang_c=
202 lang_cpp=
203 if detect_cpp_compiler ; then
204 lang_cpp=1
205 fi
206 if detect_c_compiler ; then
207 lang_c=1
208 fi
209
210 # create buffer for make variables required by dependencies
211 echo > "$TEMP_DIR/make.mk"
212
213 test_pkg_config()
214 {
215 if "$PKG_CONFIG" --exists "$1" ; then :
216 else return 1 ; fi
217 if [ -z "$2" ] || "$PKG_CONFIG" --atleast-version="$2" "$1" ; then :
218 else return 1 ; fi
219 if [ -z "$3" ] || "$PKG_CONFIG" --exact-version="$3" "$1" ; then :
220 else return 1 ; fi
221 if [ -z "$4" ] || "$PKG_CONFIG" --max-version="$4" "$1" ; then :
222 else return 1 ; fi
223 return 0
224 }
225
226 dependency_error_cpp()
227 {
228 printf "checking for cpp... "
229 # dependency cpp
230 while true
231 do
232 if [ -z "$lang_cpp" ] ; then
233 break
234 fi
235 echo yes
236 return 1
237 done
238
239 echo no
240 return 0
241 }
242 dependency_error_libpq()
243 {
244 printf "checking for libpq... "
245 # dependency libpq
246 while true
247 do
248 if [ -z "$PKG_CONFIG" ]; then
249 break
250 fi
251 if test_pkg_config "libpq" "" "" "" ; then
252 TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags libpq`"
253 TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs libpq`"
254 else
255 break
256 fi
257 echo yes
258 return 1
259 done
260
261 echo no
262 return 0
263 }
264 dependency_error_openssl()
265 {
266 printf "checking for openssl... "
267 # dependency openssl
268 while true
269 do
270 if [ -z "$lang_c" ] ; then
271 break
272 fi
273 if [ -z "$PKG_CONFIG" ]; then
274 break
275 fi
276 if test_pkg_config "openssl" "" "" "" ; then
277 TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags openssl`"
278 TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs openssl`"
279 else
280 break
281 fi
282 echo yes
283 return 1
284 done
285
286 # dependency openssl platform="bsd"
287 while true
288 do
289 if notisplatform "bsd"; then
290 break
291 fi
292 TEMP_LDFLAGS="$TEMP_LDFLAGS -lssl -lcrypto"
293 echo yes
294 return 1
295 done
296
297 echo no
298 return 0
299 }
300 dependency_error_libxml2()
301 {
302 printf "checking for libxml2... "
303 # dependency libxml2 platform="macos"
304 while true
305 do
306 if notisplatform "macos"; then
307 break
308 fi
309 if tmp_flags=`xml2-config --cflags` ; then
310 TEMP_CFLAGS="$TEMP_CFLAGS $tmp_flags"
311 else
312 break
313 fi
314 if tmp_flags=`xml2-config --libs` ; then
315 TEMP_LDFLAGS="$TEMP_LDFLAGS $tmp_flags"
316 else
317 break
318 fi
319 echo yes
320 return 1
321 done
322
323 # dependency libxml2
324 while true
325 do
326 if [ -z "$PKG_CONFIG" ]; then
327 break
328 fi
329 if test_pkg_config "libxml-2.0" "" "" "" ; then
330 TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags libxml-2.0`"
331 TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs libxml-2.0`"
332 else
333 break
334 fi
335 echo yes
336 return 1
337 done
338
339 echo no
340 return 0
341 }
342
343
344
345
346 # start collecting dependency information
347 echo > "$TEMP_DIR/flags.mk"
348
349 DEPENDENCIES_FAILED=
350 ERROR=0
351 # unnamed dependencies
352 TEMP_CFLAGS=
353 TEMP_CXXFLAGS=
354 TEMP_LDFLAGS=
355 while true
356 do
357 while true
358 do
359 if [ -z "$lang_c" ] ; then
360 ERROR=1
361 break
362 fi
363
364 break
365 done
366 break
367 done
368
369 # add general dependency flags to flags.mk
370 echo "# general flags" >> "$TEMP_DIR/flags.mk"
371 if [ -n "${TEMP_CFLAGS}" -a -n "$lang_c" ]; then
372 echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk"
373 fi
374 if [ -n "${TEMP_CXXFLAGS}" -a -n "$lang_cpp" ]; then
375 echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk"
376 fi
377 if [ -n "${TEMP_LDFLAGS}" ]; then
378 echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk"
379 fi
380
381 #
382 # OPTION VALUES
383 #
384
385 #
386 # TARGETS
387 #
388
389 echo >> "$TEMP_DIR/flags.mk"
390 echo "configuring global target"
391 echo "# flags for unnamed target" >> "$TEMP_DIR/flags.mk"
392 TEMP_CFLAGS=
393 TEMP_CXXFLAGS=
394 TEMP_LDFLAGS=
395
396 if dependency_error_libxml2; then
397 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED libxml2 "
398 ERROR=1
399 fi
400 if dependency_error_openssl; then
401 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED openssl "
402 ERROR=1
403 fi
404
405 # Features
406 if [ -n "$FEATURE_PG" ]; then
407 # check dependency
408 if dependency_error_libpq ; then
409 # "auto" features can fail and are just disabled in this case
410 if [ "$FEATURE_PG" = "auto" ]; then
411 DISABLE_FEATURE_PG=1
412 else
413 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED libpq "
414 ERROR=1
415 fi
416 fi
417 # check dependency
418 if dependency_error_cpp ; then
419 # "auto" features can fail and are just disabled in this case
420 if [ "$FEATURE_PG" = "auto" ]; then
421 DISABLE_FEATURE_PG=1
422 else
423 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED cpp "
424 ERROR=1
425 fi
426 fi
427 if [ -n "$DISABLE_FEATURE_PG" ]; then
428 unset FEATURE_PG
429 fi
430 fi
431
432
433 if [ -n "${TEMP_CFLAGS}" -a -n "$lang_c" ]; then
434 echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk"
435 fi
436 if [ -n "${TEMP_CXXFLAGS}" -a -n "$lang_cpp" ]; then
437 echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk"
438 fi
439 if [ "$BUILD_TYPE" = "debug" ]; then
440 if [ -n "$lang_c" ]; then
441 echo 'CFLAGS += ${DEBUG_CC_FLAGS}' >> "$TEMP_DIR/flags.mk"
442 fi
443 if [ -n "$lang_cpp" ]; then
444 echo 'CXXFLAGS += ${DEBUG_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk"
445 fi
446 fi
447 if [ "$BUILD_TYPE" = "release" ]; then
448 if [ -n "$lang_c" ]; then
449 echo 'CFLAGS += ${RELEASE_CC_FLAGS}' >> "$TEMP_DIR/flags.mk"
450 fi
451 if [ -n "$lang_cpp" ]; then
452 echo 'CXXFLAGS += ${RELEASE_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk"
453 fi
454 fi
455 if [ -n "${TEMP_LDFLAGS}" ]; then
456 echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk"
457 fi
458
459
460 # final result
461 if [ $ERROR -ne 0 ]; then
462 echo
463 echo "Error: Unresolved dependencies"
464 echo "$DEPENDENCIES_FAILED"
465 abort_configure
466 fi
467
468 echo "configure finished"
469 echo
470 echo "Build Config:"
471 echo " PREFIX: $PREFIX"
472 echo " TOOLCHAIN: $TOOLCHAIN_NAME"
473 echo "Features:"
474 if [ -n "$FEATURE_PG" ]; then
475 echo " pg: on"
476 else
477 echo " pg: off"
478 fi
479 echo
480
481 # generate the config.mk file
482 cat > "$TEMP_DIR/config.mk" << __EOF__
483 #
484 # config.mk generated by configure
485 #
486
487 __EOF__
488 write_toolchain_defaults "$TEMP_DIR/toolchain.mk"
489 cat "$TEMP_DIR/vars.mk" "$TEMP_DIR/toolchain.mk" "$TEMP_DIR/flags.mk" "$TEMP_DIR/make.mk" > config.mk
490 rm -Rf "$TEMP_DIR"
491
492

mercurial