src/test/resources/golden-sample/configure

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

mercurial