configure

changeset 204
e870a7c8f223
parent 109
8a0a7754f123
child 206
f5bdca63bbe7
equal deleted inserted replaced
203:7fe53d5d587c 204:e870a7c8f223
1 #!/bin/sh 1 #!/bin/sh
2 # 2
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 HOST=`uname -n`
4 # 4 PREFIX=`pwd`/work
5 # Copyright 2013 Olaf Wintermann. All rights reserved. 5 INSTALL_DIR=$PREFIX
6 # 6
7 # Redistribution and use in source and binary forms, with or without 7 EPREFIX=$PREFIX
8 # modification, are permitted provided that the following conditions are met: 8
9 # 9 BINDIR=
10 # 1. Redistributions of source code must retain the above copyright 10 SBINDIR=
11 # notice, this list of conditions and the following disclaimer. 11 LIBDIR=
12 # 12 LIBEXECDIR=
13 # 2. Redistributions in binary form must reproduce the above copyright 13 DATADIR=
14 # notice, this list of conditions and the following disclaimer in the 14 SYSCONFDIR=
15 # documentation and/or other materials provided with the distribution. 15 SHAREDSTATEDIR=
16 # 16 LOCALSTATEDIR=
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 INCLUDEDIR=
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 INFODIR=
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 MANDIR=
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
28 #
29
30 #
31 # TODO: parse arguments
32 #
33 20
34 OS=`uname -s` 21 OS=`uname -s`
35 HOST=`uname -n` 22 OS_VERSION=`uname -r`
36 INSTALL_DIR=`pwd`/work 23
37 24 TEMP_DIR=".tmp-`uname -n`"
38 LIBS_CFLAGS=`pkg-config --cflags libxml-2.0 openssl` 25 mkdir -p $TEMP_DIR
39 LIBS_LDFLAGS=`pkg-config --libs libxml-2.0 openssl` 26 if [ $? -ne 0 ]; then
40 27 echo "Cannot create tmp dir"
41 # create config.mk 28 echo "Abort"
42 echo "generate config.mk" 29 fi
43 30 touch $TEMP_DIR/options
44 cat > config.mk << __EOF__ 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 if [[ $ARG == --prefix=* ]]; then
71 PREFIX=${ARG:9}
72 elif [[ $ARG = --exec-prefix=* ]]; then
73 EPREFIX=${ARG:14}
74 elif [[ $ARG = --bindir=* ]]; then
75 BINDIR=${ARG:9}
76 elif [[ $ARG = --sbindir=* ]]; then
77 SBINDIR=${ARG:10}
78 elif [[ $ARG = --libdir=* ]]; then
79 LIBDIR=${ARG:9}
80 elif [[ $ARG = --libexecdir=* ]]; then
81 LIBEXECDIR=${ARG:13}
82 elif [[ $ARG = --datadir=* ]]; then
83 DATADIR=${ARG:10}
84 elif [[ $ARG = --sysconfdir=* ]]; then
85 SYSCONFDIR=${ARG:13}
86 elif [[ $ARG = --sharedstatedir=* ]]; then
87 SHAREDSTATEDIR=${ARG:17}
88 elif [[ $ARG = --localstatedir=* ]]; then
89 LOCALSTATEDIR=${ARG:16}
90 elif [[ $ARG = --includedir=* ]]; then
91 INCLUDEDIR=${ARG:12}
92 elif [[ $ARG = --infodir=* ]]; then
93 INFODIR=${ARG:10}
94 elif [[ $ARG = --mandir=* ]]; then
95 MANDIR=${ARG:9}
96 elif [ $ARG = "--help" ]; then
97 printhelp
98 exit 0
99 elif [[ $ARG == --enable-pg ]]; then
100 FEATURE_PG=on
101 elif [[ $ARG == --disable-pg ]]; then
102 unset FEATURE_PG
103 fi
104 done
105
106 # set dir variables
107 if [ -z $BINDIR ]; then
108 BINDIR=$EPREFIX/bin
109 fi
110 if [ -z $SBINDIR ]; then
111 SBINDIR=$EPREFIX/sbin
112 fi
113 if [ -z $LIBDIR ]; then
114 LIBDIR=$EPREFIX/lib
115 fi
116 if [ -z $LIBEXEC ]; then
117 LIBEXECDIR=$EPREFIX/libexec
118 fi
119 if [ -z $DATADIR ]; then
120 DATADIR=$PREFIX/share
121 fi
122 if [ -z $SYSCONFDIR]; then
123 SYSCONFDIR=$PREFIX/etc
124 fi
125 if [ -z $SHAREDSTATEDIR ]; then
126 SHAREDSTATEDIR=$PREFIX/com
127 fi
128 if [ -z $LOCALSTATEDIR ]; then
129 LOCALSTATEDIR=$PREFIX/var
130 fi
131 if [ -z $INCLUDEDIR ]; then
132 INCLUDEDIR=$PREFIX/include
133 fi
134 if [ -z $INFODIR ]; then
135 INFODIR=$PREFIX/info
136 fi
137 if [ -z $MANDIR ]; then
138 MANDIR=$PREFIX/man
139 fi
140
141 which pkg-config > /dev/null
142 if [ $? -ne 0 ]; then
143 PKG_CONFIG=pkg-config
144 else
145 PKG_CONFIG=false
146 fi
147
148 # Simple uname based platform detection
149 # $PLATFORM is used for platform dependent dependency selection
150 printf "detect platform... "
151 if [ $OS = SunOS ]; then
152 PLATFORM="solaris sunos unix svr4"
153 fi
154 if [ $OS = Linux ]; then
155 PLATFORM="linux unix"
156 fi
157 if [ $OS = FreeBSD ]; then
158 PLATFORM="freebsd bsd unix"
159 fi
160 if [ $OS = Darwin ]; then
161 PLATFORM="macos osx bsd unix"
162 fi
163 echo $OS | grep "MINGW" > /dev/null
164 if [ $? -eq 0 ]; then
165 PLATFORM="windows mingw"
166 fi
167
168 if [ -z "$PLATFORM" ]; then
169 PLATFORM="unix"
170 fi
171
172 for p in $PLATFORM
173 do
174 PLATFORM_NAME=$p
175 break
176 done
177 echo $PLATFORM_NAME
178
179 isplatform()
180 {
181 for p in $PLATFORM
182 do
183 if [ $p = $1 ]; then
184 return 0
185 fi
186 done
187 return 1
188 }
189
190 # generate config.mk and config.h
191 cat > $TEMP_DIR/config.mk << __EOF__
45 # 192 #
46 # config.mk generated by configure 193 # config.mk generated by configure
47 # 194 #
48 195
49 INSTALL_DIR = $INSTALL_DIR 196 # general vars
50 HOST = $HOST 197 HOST=$HOST
51 198 PREFIX=$PREFIX
52 __EOF__ 199 INSTALL_DIR=$INSTALL_DIR
53 200
54 # platform 201 EPREFIX=$EPREFIX
55 202
56 if [ $OS = SunOS ]; then 203 BINDIR=$BINDIR
57 CCONF=suncc.mk 204 SBINDIR=$SBINDIR
58 PLATFORM=solaris.mk 205 LIBDIR=$LIBDIR
59 fi 206 LIBEXECDIR=$LIBEXECDIR
60 207 DATADIR=$DATADIR
61 if [ $OS = Linux ]; then 208 SYSCONFDIR=$SYSCONFDIR
62 if `type clang > /dev/null`; then 209 SHAREDSTATEDIR=$SHAREDSTATEDIR
63 CCONF=clang.mk 210 LOCALSTATEDIR=$LOCALSTATEDIR
64 else 211 INCLUDEDIR=$INCLUDEDIR
65 CCONF=gcc.mk 212 INFODIR=$INFODIR
66 fi 213 MANDIR=$MANDIR
67 PLATFORM=linux.mk 214
68 fi 215 __EOF__
69 216
70 if [ $OS = Darwin ]; then 217 echo > $TEMP_DIR/make.mk
71 CCONF=clang.mk 218
72 PLATFORM=osx.mk 219 ENV_CFLAGS=$CFLAGS
73 fi 220 ENV_LDFLAGS=$LDFLAGS
74 221 ENV_CXXFLAGS=$CXXFLAGS
75 ISBSD=`echo $OS | grep -c BSD` 222
76 if [ $ISBSD = 1 ]; then 223 # Toolchain detection
77 if `type clang > /dev/null`; then 224 # this will insert make vars to config.mk
78 CCONF=clang.mk 225 source make/toolchain.sh
79 else 226
80 CCONF=gcc.mk 227 # add user specified flags to config.mk
81 fi 228 echo >> $TEMP_DIR/config.mk
82 PLATFORM=bsd.mk 229 if [[ ! -z ${ENV_CFLAGS} ]]; then
83 fi 230 echo "CFLAGS += $ENV_CFLAGS" >> $TEMP_DIR/config.mk
84 231 fi
85 echo " 232 if [[ ! -z ${ENV_CXXFLAGS} ]]; then
86 include \$(BUILD_ROOT)/make/$CCONF 233 echo "CXXFLAGS += $ENV_CXXFLAGS" >> $TEMP_DIR/config.mk
87 include \$(BUILD_ROOT)/make/$PLATFORM 234 fi
88 235 if [[ ! -z ${ENV_LDFLAGS} ]]; then
89 CFLAGS += $LIBS_CFLAGS 236 echo "LDFLAGS += $ENV_LDFLAGS" >> $TEMP_DIR/config.mk
90 LDFLAGS += $LIBS_LDFLAGS 237 fi
91 238
92 " >> config.mk 239 #
93 240 # DEPENDENCIES
94 241 #
95 242
243 dependency_libpq()
244 {
245 printf "checking for libpq... "
246 # dependency libpq
247 while true
248 do
249 if [ -z "PKG_CONFIG" ]; then
250 break
251 fi
252 if ! pkg-config libpq ; then
253 break
254 fi
255 CFLAGS+=" `pkg-config --cflags libpq`"
256 LDFLAGS+=" `pkg-config --libs libpq`"
257 echo yes
258 return 0
259 done
260
261 echo no
262 return 1
263 }
264 dependency_openssl()
265 {
266 printf "checking for openssl... "
267 # dependency openssl
268 while true
269 do
270 if [ -z "PKG_CONFIG" ]; then
271 break
272 fi
273 if ! pkg-config openssl ; then
274 break
275 fi
276 CFLAGS+=" `pkg-config --cflags openssl`"
277 LDFLAGS+=" `pkg-config --libs openssl`"
278 echo yes
279 return 0
280 done
281
282 echo no
283 return 1
284 }
285 dependency_libxml2()
286 {
287 printf "checking for libxml2... "
288 # dependency libxml2
289 while true
290 do
291 if [ -z "PKG_CONFIG" ]; then
292 break
293 fi
294 if ! pkg-config libxml-2.0 ; then
295 break
296 fi
297 CFLAGS+=" `pkg-config --cflags libxml-2.0`"
298 LDFLAGS+=" `pkg-config --libs libxml-2.0`"
299 echo yes
300 return 0
301 done
302
303 echo no
304 return 1
305 }
306
307 DEPENDENCIES_FAILED=
308 ERROR=0
309 # general dependencies
310 CFLAGS=
311 LDFLAGS=
312 while true
313 do
314 if ! isplatform "linux"; then
315 break
316 fi
317 while true
318 do
319
320 CFLAGS+="-DLINUX"
321 LDFLAGS+="-lpthread -ldl -lm -lldap"
322 cat >> $TEMP_DIR/make.mk << __EOF__
323 # platform dependend source files
324 PLATFORM_DAEMONOBJ = event_linux.o
325
326 # platform dependend vars
327 OBJ_EXT = .o
328 LIB_EXT = .so
329 APP_EXT =
330
331 __EOF__
332
333 break
334 done
335
336 break
337 done
338 while true
339 do
340 if ! isplatform "bsd"; then
341 break
342 fi
343 if isplatform "macos"; then
344 break
345 fi
346 while true
347 do
348
349 CFLAGS+="-DBSD"
350 LDFLAGS+="-lpthread -lm -lldap"
351 cat >> $TEMP_DIR/make.mk << __EOF__
352 # platform dependend source files
353 PLATFORM_DAEMONOBJ = event_bsd.o
354
355 # platform dependend vars
356 OBJ_EXT = .o
357 LIB_EXT = .so
358 APP_EXT =
359
360 __EOF__
361
362 break
363 done
364
365 break
366 done
367 while true
368 do
369 if ! isplatform "macos"; then
370 break
371 fi
372 while true
373 do
374
375 CFLAGS+="-DBSD -DOSX"
376 LDFLAGS+="-lpthread -ldl -lm -lldap"
377 cat >> $TEMP_DIR/make.mk << __EOF__
378 # platform dependend source files
379 PLATFORM_DAEMONOBJ = event_bsd.o
380
381 # platform dependend vars
382 OBJ_EXT = .o
383 LIB_EXT = .dylib
384 APP_EXT =
385
386 __EOF__
387
388 break
389 done
390
391 break
392 done
393 while true
394 do
395 if ! isplatform "solaris"; then
396 break
397 fi
398 while true
399 do
400
401 CFLAGS+="-DSOLARIS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS"
402 LDFLAGS+="-lsocket -lnsl -lsendfile -lposix4 -lpthread -ldl -lm -lmd -lldap"
403 cat >> $TEMP_DIR/make.mk << __EOF__
404 # platform dependend source files
405 PLATFORM_DAEMONOBJ = event_solaris.o
406
407 # platform dependend vars
408 OBJ_EXT = .o
409 LIB_EXT = .so
410 APP_EXT =
411
412 __EOF__
413
414 break
415 done
416
417 break
418 done
419
420 # add general dependency flags to config.mk
421 echo >> $TEMP_DIR/config.mk
422 if [[ ! -z ${CFLAGS} ]]; then
423 echo "CFLAGS += $CFLAGS" >> $TEMP_DIR/config.mk
424 fi
425 if [[ ! -z ${CXXFLAGS} ]]; then
426 echo "CXXFLAGS += $CXXFLAGS" >> $TEMP_DIR/config.mk
427 fi
428 if [[ ! -z ${LDFLAGS} ]]; then
429 echo "LDFLAGS += $LDFLAGS" >> $TEMP_DIR/config.mk
430 fi
431
432 #
433 # OPTION VALUES
434 #
435
436 #
437 # TARGETS
438 #
439 CFLAGS=
440 CXXFLAGS=
441 LDFLAGS=
442
443 # Target
444 CFLAGS=
445 LDFLAGS=
446 CXXFLAGS=
447
448 dependency_libxml2
449 if [ $? -ne 0 ]; then
450 DEPENDENCIES_FAILED+="libxml2 "
451 ERROR=1
452 fi
453 dependency_openssl
454 if [ $? -ne 0 ]; then
455 DEPENDENCIES_FAILED+="openssl "
456 ERROR=1
457 fi
458
459
460 echo >> $TEMP_DIR/config.mk
461 if [[ ! -z ${CFLAGS} ]]; then
462 echo "CFLAGS += $CFLAGS" >> $TEMP_DIR/config.mk
463 fi
464 if [[ ! -z ${CXXFLAGS} ]]; then
465 echo "CXXFLAGS += $CXXFLAGS" >> $TEMP_DIR/config.mk
466 fi
467 if [[ ! -z ${LDFLAGS} ]]; then
468 echo "LDFLAGS += $LDFLAGS" >> $TEMP_DIR/config.mk
469 fi
470
471 if [ $ERROR -ne 0 ]; then
472 echo
473 echo "Error: Unresolved dependencies"
474 echo $DEPENCIES_FAILED
475 rm -Rf $TEMP_DIR
476 exit 1
477 fi
478
479 echo "configure finished"
480 echo
481 echo "Build Config:"
482 echo " PREFIX: $PREFIX"
483 echo " TOOLCHAIN: $TOOLCHAIN_NAME"
484 echo
485 cat $TEMP_DIR/config.mk $TEMP_DIR/make.mk > config.mk
486 rm -Rf $TEMP_DIR
487
488

mercurial