restructure configure so pkg-config derived SSL flags get used
[rofl0r-ixchat.git] / configure
blobad18f1821dc09a59ac6a46b59150d3123d08d413
1 #!/bin/sh
3 prefix=/usr/local
5 libs=`cat << EOF
6 glib-2.0
7 gmodule-2.0
8 gtk+-2.0
9 gtk+-x11-2.0
10 EOF
12 clear_config() {
13 rm -f config.mak 2>/dev/null
16 add_config() {
17 printf "%s\n" "$1" >> config.mak
20 add_cflags() {
21 add_config "CFLAGS += $1"
24 add_ldflags() {
25 add_config "LDFLAGS += $1"
28 get_pkgconf_cflags() {
29 pkg-config --cflags "$1" 2>/dev/null
32 get_pkgconf_ldflags() {
33 pkg-config --libs "$1" 2>/dev/null
36 add_pkgconf_cflags() {
37 fallback="$2"
38 flags=$(get_pkgconf_cflags "$1")
39 [ -z "$flags" ] && flags="$fallback"
40 add_cflags "$flags"
43 add_pkgconf_ldflags() {
44 fallback="$2"
45 flags=$(get_pkgconf_ldflags "$1")
46 [ -z "$flags" ] && flags="$fallback"
47 add_ldflags "$flags"
50 add_lib() {
51 add_pkgconf_cflags "$1" "$2"
52 ADD_LIB_CFLAGS="$flags"
53 add_pkgconf_ldflags "$1" "$3"
54 ADD_LIB_LDFLAGS="$flags"
57 check_program() {
58 program="$1"
59 needed="$2"
60 result=$(which "$program" 2>/dev/null)
61 if [ "$needed" = "1" ] && [ -z "$result" ] ; then
62 echo "error: needed program $program not found" >&2
63 kill -9 $$
65 printf "%s\n" "$program"
68 pdisable() {
69 local a="$1"
70 printf "--enable-%s[=yes/no/auto]\tenable %s %s [default: auto]\n" "$a" "$a" "$2"
73 usage() {
74 echo "supported arguments"
75 echo "--help show this text"
76 echo "--prefix=/path default: $prefix"
77 echo "--exec_prefix=/path default: $prefix/bin"
78 echo "--bindir=/path default: $prefix/bin"
79 echo "--libdir=/path default: $prefix/lib"
80 echo "--includedir=/path default: $prefix/include"
81 echo "--sysconfdir=/path default: $prefix/etc"
82 echo
83 for i in libsexy gtkspell ; do pdisable $i "library usage" ; done
84 echo
85 for i in python tcl perl ; do pdisable $i plugin ; done
86 echo
87 echo "NOTE: the auto detection of the scripting language plugins"
88 echo "works only for non-crosscompile scenarios because the authors of those languages"
89 echo "stubbornly require you to execute the interpreter in a specific way to query"
90 echo "the necessary flags rather than relying on standardtools like pkgconfig."
91 echo "because of that, if set to yes, the required C/LDFLAGS for the plugins need to be passed"
92 echo "manually to configure using PERL_CFLAGS=... PY_LDFLAGS=... TCL_CFLAGS=... /configure ..."
93 echo
94 exit 1
97 ismac() {
98 uname -s | grep Darwin >/dev/null
101 isbsd() {
102 uname -s | grep BSD >/dev/null
105 spliteq() {
106 arg=$1
107 echo "${arg#*=}"
108 #alternatives echo "$arg" | cut -d= -f2-
109 # or echo "$arg" | sed 's/[^=]*=//'
112 check_feature() {
113 local f="$1"
114 local res=
115 case "$2" in
116 --enable-$f) res=yes;;
117 --disable-$f) res=no;;
118 --enable-$f=*) res=`spliteq $2`;;
119 esac
120 [ -n "$res" ] && eval $3=$res
123 parsearg() {
124 for i in python perl tcl libsexy gtkspell ; do check_feature $i "$1" feature_$i ; done
125 case "$1" in
126 --prefix=*) prefix=`spliteq $1`;;
127 --exec_prefix=*) exec_prefix=`spliteq $1`;;
128 --bindir=*) bindir=`spliteq $1`;;
129 --libdir=*) libdir=`spliteq $1`;;
130 --includedir=*) includedir=`spliteq $1`;;
131 --sysconfdir=*) sysconfdir=`spliteq $1`;;
132 --help) usage;;
133 esac
136 fail() { printf "%s\n" "$1" >&2 ; exit 1 ; }
138 # Get a temporary filename
140 set -C
141 while : ; do i=$(($i+1))
142 tmpc="./conf$$-$PPID-$i.c"
143 2>|/dev/null > "$tmpc" && break
144 test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
145 done
146 set +C
147 trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP
149 check_compile() {
150 printf "checking %s ... " "$1"
151 printf "$3" > "$tmpc"
152 local res=0
153 $CC $TMP_FLAGS $OUR_CPPFLAGS $CPPFLAGS $2 $CFLAGS "$tmpc" $OUR_LDFLAGS -o /dev/null >/dev/null 2>&1 \
154 || res=1
155 test x$res = x0 && \
156 { printf "yes\n" ; test x"$2" = x || OUR_CPPFLAGS="$OUR_CPPFLAGS $2" ; } \
157 || printf "no\n"
158 return $res
161 check_define() {
162 printf "checking whether \$CC defines %s ... " "$1"
163 local res=1
164 $CC $TMP_FLAGS $OUR_CPPFLAGS $CPPFLAGS $CFLAGS -dM -E - </dev/null | grep "$1" >/dev/null && res=0
165 test x$res = x0 && printf "yes\n" || printf "no\n"
166 return $res
169 check_compile_run() {
170 printf "checking %s ... " "$1"
171 printf "$2" > "$tmpc"
172 local res=0
173 $CC $OUR_CPPFLAGS $CPPFLAGS $CFLAGS "$tmpc" -o "$tmpc".out >/dev/null 2>&1 \
174 || res=1
175 test x$res = x0 && { "$tmpc".out || res=1 ; }
176 rm -f "$tmpc".out
177 test x$res = x0 && printf "yes\n" || printf "no\n"
178 return $res
181 check_link_silent() {
182 printf "$2" > "$tmpc"
183 $CC $TMP_FLAGS $OUR_CPPFLAGS $CPPFLAGS $1 $CFLAGS "$tmpc" -o /dev/null >/dev/null 2>&1
186 check_link() {
187 printf "checking %s ... " "$1"
188 local res=0
189 check_link_silent "$2" "$3" || res=1
190 test x$res = x0 && printf "yes\n" || printf "no\n"
191 return $res
194 [ -z "$CC" ] && CC=cc
195 [ -z "$exec_prefix" ] && exec_prefix=$prefix
196 [ -z "$libdir" ] && libdir=$prefix/lib
197 [ -z "$includedir" ] && includedir=$prefix/include
198 [ -z "$sysconfdir" ] && sysconfdir=$prefix/etc
199 [ -z "$bindir" ] && bindir=$exec_prefix/bin
201 clear_config
203 add_config "prefix = $prefix"
204 add_config "exec_prefix = $exec_prefix"
205 add_config "bindir = $bindir"
206 add_config "libdir = $libdir"
207 add_config "includedir = $includedir"
208 add_config "sysconfdir = $sysconfdir"
210 add_config "CC ?= $CC"
212 [ -z "$CPPFLAGS" ] || add_config "USER_CPPFLAGS = $CPPFLAGS"
213 [ -z "$CFLAGS" ] || add_config "USER_CFLAGS = $CFLAGS"
214 [ -z "$LDFLAGS" ] || add_config "USER_LDFLAGS = $LDFLAGS"
217 check_compile 'whether C compiler works' '' 'int main() {return 0;}' || fail 'error: install a C compiler and library'
218 check_compile 'whether we have memrchr()' "-DGNU_SOURCE -DHAVE_MEMRCHR" \
219 '#define _GNU_SOURCE\n#include <string.h>\nint main() {\nvoid *p = memrchr("foo", 0, 3);\nreturn 0;}'
221 add_lib openssl "" "-lssl -lcrypto"
223 TMP_FLAGS="$ADD_LIB_CFLAGS"
224 check_link 'whether we have ssl lib and headers' "$ADD_LIB_LDFLAGS" \
225 "#include <openssl/ssl.h>\nint main() { return 0; }" || \
226 fail 'ssl library not found'
227 OUR_LDFLAGS="$ADD_LIB_LDFLAGS"
229 check_compile 'whether we have SSL_CTX_get_ssl_method()' \
230 '-DHAVE_SSL_CTX_get_ssl_method' \
231 "#include <openssl/ssl.h>\nint main() { SSL_CTX *c = 0; (void)SSL_CTX_get_ssl_method(c); return 0;}"
233 check_compile 'whether we have DH_set0_pqg()' \
234 '-DHAVE_DH_set0_pqg' \
235 "#include <openssl/ssl.h>\nint main() { DH *c = 0; (void)DH_set0_pqg(c,0,0,0); return 0;}"
237 check_compile 'whether we have DH_get0_pub_key()' \
238 '-DHAVE_DH_get0_pub_key' \
239 "#include <openssl/ssl.h>\nint main() { DH *c = 0; (void)DH_get0_pub_key(c); return 0;}"
240 TMP_FLAGS=
242 for i in python perl tcl libsexy gtkspell ; do eval feature_$i=auto ; done
243 while true ; do
244 case $1 in
245 -*) parsearg "$1"; shift;;
246 *) break ;;
247 esac
248 done
250 [ -z "$OUR_CPPFLAGS" ] || add_config "USER_CPPFLAGS += $OUR_CPPFLAGS"
253 add_cflags "-DXCHATLIBDIR=\\\"$libdir/xchat\\\""
254 add_cflags "-DXCHATSHAREDIR=\\\"$prefix/share/xchat\\\""
255 add_cflags "-DUSE_OPENSSL"
257 for lib in $libs ; do add_lib "$lib" ; done
259 check_link 'whether we have libdl' '-ldl' \
260 "int main() { return 0; }" && add_ldflags '-ldl'
262 prog1=$(check_program "gdk-pixbuf-csource" 1)
263 add_config "PIXMAPCONVERT = $prog1"
265 for i in libsexy gtkspell ; do
266 eval enabled=\${feature_$i}
267 printf "checking whether to use library $i..."
268 if [ "$enabled" = yes ] || [ "$enabled" = auto ] ; then
269 l=$i
270 [ $l = gtkspell ] && l=gtkspell-2.0
271 spell_flags=$(get_pkgconf_cflags $l)
272 if [ ! -z "$spell_flags" ] ; then
273 add_cflags "$spell_flags"
274 spell_flags=$(get_pkgconf_ldflags $i)
275 add_ldflags "$spell_flags"
276 if [ "$i" = "libsexy" ] ; then
277 add_cflags "-DUSE_LIBSEXY"
278 else
279 add_cflags "-DUSE_GTKSPELL"
281 printf "yes\n"
282 else
283 if [ "$enabled" = yes ] ; then
284 printf "error: $i requested but not found!"
285 exit 1
287 printf "no\n"
290 done
292 # plugin stuff ...
294 use_plugin=
296 printf "checking whether to use perl plugin..."
297 if [ "$feature_perl" = auto ] ; then
298 perl=$(check_program "perl" 0)
299 if [ -n "$perl" ] ; then
300 PERL_CFLAGS=`$perl -MExtUtils::Embed -e ccopts 2>/dev/null`
301 PERL_LDFLAGS=`$perl -MExtUtils::Embed -e ldopts 2>/dev/null | sed 's/-lgdbm //'`
302 feature_perl=yes
305 if [ "$feature_perl" = yes ] ; then
306 printf "yes\n"
307 add_config "PERL_CFLAGS = $PERL_CFLAGS"
308 add_config "PERL_LDFLAGS = $PERL_LDFLAGS"
309 add_config "PLUGINS += perl.so"
310 # there are actually 2 plugins, "old" and new, but all scripts i've seen only use old
311 add_cflags "-DOLD_PERL"
312 use_plugin=1
313 else
314 printf "no\n"
316 printf "checking whether to use tcl plugin..."
317 if [ "$feature_tcl" = auto ] ; then
318 tcl=$(check_program "tclsh" 0)
319 if [ -n "$tcl" ] ; then
320 TCL_CFLAGS=$(get_pkgconf_cflags tcl)
321 TCL_LDFLAGS=$(get_pkgconf_ldflags tcl)
322 tcl_error=
323 # tcl 8.5 does not come with a pkgconfig file
324 # tcl 8.6. comes with a buggy one that fails to include its own library
325 # https://sourceforge.net/tracker/?func=detail&aid=3598298&group_id=10894&atid=110894
326 # hopefully tcl 8.7 will come with a *working* pkgconfig file ...
327 # until that happens, we need to fall back to its proprietary tclConfig system.
328 if [ -z "$TCL_LDFLAGS" ] || ! echo "$TCL_LDFLAGS" | grep "[-]ltcl" > /dev/null ; then
329 tcl_found=
330 for i in "$libdir" "$prefix"/lib/ "$prefix"/lib64/ /lib /lib64 /usr/lib /usr/lib64 ; do
331 printf "searching tclConfig.sh in $i ... "
332 if [ -e "$i"/tclConfig.sh ] ; then
333 . "$i"/tclConfig.sh
334 TCL_LDFLAGS="$TCL_LIB_SPEC $TCL_LIBS"
335 tcl_found=1
336 break
338 done
339 if [ -z "$tcl_found" ] ; then
340 tcl_error=1
343 [ -z "$tcl_error" ] && feature_tcl=yes
346 if [ "$feature_tcl" = yes ] ; then
347 printf "yes\n"
348 add_config "TCL_CFLAGS = $TCL_CFLAGS"
349 add_config "TCL_LDFLAGS = $TCL_LDFLAGS"
350 add_config "PLUGINS += tcl.so"
351 use_plugin=1
352 else
353 printf "no\n"
355 printf "checking whether to use python plugin..."
356 if [ "$feature_python" = auto ] ; then
357 python=$(check_program "python" 0)
358 if [ -n "$python" ] ; then
359 PY_CFLAGS=$(get_pkgconf_cflags python)
360 [ -z "$PY_CFLAGS" ] && PY_CFLAGS=$(get_pkgconf_cflags python-2.7)
361 if [ -z "$PY_CFLAGS" ] ; then
362 for i in "$prefix" /usr /usr/local/ ; do
363 printf "searching Python.h in $i/include/python2.7 ... "
364 if [ -e "$i"/include/python2.7/Python.h ] ; then
365 PY_CFLAGS=-I"$i"/include/python2.7
366 printf "SUCCESS\n"
367 break;
368 else
369 printf "FAIL\n"
371 done
373 PY_LDFLAGS=$(get_pkgconf_ldflags python)
374 [ -z "$PY_LDFLAGS" ] && PY_LDFLAGS=$(get_pkgconf_ldflags python-2.7)
375 [ -z "$PY_LDFLAGS" ] && PY_LDFLAGS=-lpython2.7
376 [ ! -z "$PY_CFLAGS" ] && feature_python=yes
379 if [ "$feature_python" = yes ] ; then
380 printf "yes\n"
381 printf "WARNING: python plugin needs environment variable PYTHONHOME\n"
382 printf " set to python's prefix.\n"
383 printf " lack of that environment variable will cause ixchat exitting\n"
384 printf " when the plugin is loaded.\n"
385 printf " on sabotage linux, use \"PYTHONHOME=/ ixchat\"\n"
386 printf " to launch the program.\n"
387 add_config "PY_CFLAGS = $PY_CFLAGS"
388 add_config "PY_LDFLAGS = $PY_LDFLAGS"
389 add_config "PLUGINS += python.so"
390 use_plugin=1
391 else
392 printf "no\n"
395 if [ "$use_plugin" = 1 ] ; then
396 add_cflags "-DUSE_PLUGIN"
399 if isbsd || ismac ; then
400 add_config "INSTALL_FLAGS=-m"
403 add_cflags "\$(USER_CPPFLAGS) \$(USER_CFLAGS)"
404 add_ldflags "\$(USER_LDFLAGS)"
405 echo done, now run make \&\& make install