src/test/resources/golden-sample/configure

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

mercurial