Makefile: fix LDFLAGS order
[rofl0r-ixchat.git] / configure
blob711e154b4e101e6857e6484af6f3690dcbcdb140
1 #!/bin/sh
3 prefix=/usr/local
5 libs=`cat << EOF
6 glib-2.0
7 gtk+-2.0
8 gtk+-x11-2.0
9 EOF
11 clear_config() {
12 rm -f config.mak 2>/dev/null
15 add_config() {
16 printf "%s\n" "$1" >> config.mak
19 add_cflags() {
20 add_config "CFLAGS += $1"
23 add_ldflags() {
24 add_config "LDFLAGS += $1"
27 get_pkgconf_cflags() {
28 pkg-config --cflags "$1" 2>/dev/null
31 get_pkgconf_ldflags() {
32 pkg-config --libs "$1" 2>/dev/null
35 add_pkgconf_cflags() {
36 fallback="$2"
37 flags=$(get_pkgconf_cflags "$1")
38 [ -z "$flags" ] && flags="$fallback"
39 add_cflags "$flags"
42 add_pkgconf_ldflags() {
43 fallback="$2"
44 flags=$(get_pkgconf_ldflags "$1")
45 [ -z "$flags" ] && flags="$fallback"
46 add_ldflags "$flags"
49 add_lib() {
50 add_pkgconf_cflags "$1" "$2"
51 add_pkgconf_ldflags "$1" "$3"
54 check_program() {
55 program="$1"
56 needed="$2"
57 result=$(which "$program" 2>/dev/null)
58 if [ "$needed" = "1" ] && [ -z "$result" ] ; then
59 echo "error: needed program $program not found" >&2
60 kill -9 $$
62 printf "%s\n" "$program"
65 pdisable() {
66 local a="$1"
67 printf "--enable-%s[=yes/no/auto]\tenable %s %s [default: auto]\n" "$a" "$a" "$2"
70 usage() {
71 echo "supported arguments"
72 echo "--help show this text"
73 echo "--prefix=/path default: $prefix"
74 echo "--exec_prefix=/path default: $prefix/bin"
75 echo "--bindir=/path default: $prefix/bin"
76 echo "--libdir=/path default: $prefix/lib"
77 echo "--includedir=/path default: $prefix/include"
78 echo "--sysconfdir=/path default: $prefix/etc"
79 echo
80 for i in libsexy gtkspell ; do pdisable $i "library usage" ; done
81 echo
82 for i in python tcl perl ; do pdisable $i plugin ; done
83 echo
84 echo "NOTE: the auto detection of the scripting language plugins"
85 echo "works only for non-crosscompile scenarios because the authors of those languages"
86 echo "stubbornly require you to execute the interpreter in a specific way to query"
87 echo "the necessary flags rather than relying on standardtools like pkgconfig."
88 echo "because of that, if set to yes, the required C/LDFLAGS for the plugins need to be passed"
89 echo "manually to configure using PERL_CFLAGS=... PY_LDFLAGS=... TCL_CFLAGS=... /configure ..."
90 echo
91 exit 1
94 ismac() {
95 uname -s | grep Darwin >/dev/null
98 isbsd() {
99 uname -s | grep BSD >/dev/null
102 spliteq() {
103 arg=$1
104 echo "${arg#*=}"
105 #alternatives echo "$arg" | cut -d= -f2-
106 # or echo "$arg" | sed 's/[^=]*=//'
109 check_feature() {
110 local f="$1"
111 local res=
112 case "$2" in
113 --enable-$f) res=yes;;
114 --disable-$f) res=no;;
115 --enable-$f=*) res=`spliteq $2`;;
116 esac
117 [ -n "$res" ] && eval $3=$res
120 parsearg() {
121 for i in python perl tcl libsexy gtkspell ; do check_feature $i "$1" feature_$i ; done
122 case "$1" in
123 --prefix=*) prefix=`spliteq $1`;;
124 --exec_prefix=*) exec_prefix=`spliteq $1`;;
125 --bindir=*) bindir=`spliteq $1`;;
126 --libdir=*) libdir=`spliteq $1`;;
127 --includedir=*) includedir=`spliteq $1`;;
128 --sysconfdir=*) sysconfdir=`spliteq $1`;;
129 --help) usage;;
130 esac
133 fail() { printf "%s\n" "$1" >&2 ; exit 1 ; }
135 # Get a temporary filename
137 set -C
138 while : ; do i=$(($i+1))
139 tmpc="./conf$$-$PPID-$i.c"
140 2>|/dev/null > "$tmpc" && break
141 test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
142 done
143 set +C
144 trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP
146 check_compile() {
147 printf "checking %s ... " "$1"
148 printf "$3" > "$tmpc"
149 local res=0
150 $CC $OUR_CPPFLAGS $CPPFLAGS $2 $CFLAGS "$tmpc" $OUR_LDFLAGS -o /dev/null >/dev/null 2>&1 \
151 || res=1
152 test x$res = x0 && \
153 { printf "yes\n" ; test x"$2" = x || OUR_CPPFLAGS="$OUR_CPPFLAGS $2" ; } \
154 || printf "no\n"
155 return $res
158 check_define() {
159 printf "checking whether \$CC defines %s ... " "$1"
160 local res=1
161 $CC $OUR_CPPFLAGS $CPPFLAGS $CFLAGS -dM -E - </dev/null | grep "$1" >/dev/null && res=0
162 test x$res = x0 && printf "yes\n" || printf "no\n"
163 return $res
166 check_compile_run() {
167 printf "checking %s ... " "$1"
168 printf "$2" > "$tmpc"
169 local res=0
170 $CC $OUR_CPPFLAGS $CPPFLAGS $CFLAGS "$tmpc" -o "$tmpc".out >/dev/null 2>&1 \
171 || res=1
172 test x$res = x0 && { "$tmpc".out || res=1 ; }
173 rm -f "$tmpc".out
174 test x$res = x0 && printf "yes\n" || printf "no\n"
175 return $res
178 check_link_silent() {
179 printf "$2" > "$tmpc"
180 $CC $OUR_CPPFLAGS $CPPFLAGS $1 $CFLAGS "$tmpc" -o /dev/null >/dev/null 2>&1
183 check_link() {
184 printf "checking %s ... " "$1"
185 local res=0
186 check_link_silent "$2" "$3" || res=1
187 test x$res = x0 && printf "yes\n" || printf "no\n"
188 return $res
191 test -z "$CC" && CC=cc
193 check_compile 'whether C compiler works' '' 'int main() {return 0;}' || fail 'error: install a C compiler and library'
194 check_compile 'whether we have memrchr()' "-DGNU_SOURCE -DHAVE_MEMRCHR" \
195 '#define _GNU_SOURCE\n#include <string.h>\nint main() {\nvoid *p = memrchr("foo", 0, 3);\nreturn 0;}'
197 check_link 'whether we have ssl lib and headers' '-lssl -lcrypto' \
198 "#include <openssl/ssl.h>\nint main() { return 0; }" || \
199 fail 'ssl library not found'
200 OUR_LDFLAGS='-lssl -lcrypto'
202 check_compile 'whether we have SSL_CTX_get_ssl_method()' \
203 '-DHAVE_SSL_CTX_get_ssl_method' \
204 "#include <openssl/ssl.h>\nint main() { SSL_CTX *c = 0; (void)SSL_CTX_get_ssl_method(c); return 0;}"
206 check_compile 'whether we have DH_set0_pqg()' \
207 '-DHAVE_DH_set0_pqg' \
208 "#include <openssl/ssl.h>\nint main() { DH *c = 0; (void)DH_set0_pqg(c,0,0,0); return 0;}"
210 check_compile 'whether we have DH_get0_pub_key()' \
211 '-DHAVE_DH_get0_pub_key' \
212 "#include <openssl/ssl.h>\nint main() { DH *c = 0; (void)DH_get0_pub_key(c); return 0;}"
214 for i in python perl tcl libsexy gtkspell ; do eval feature_$i=auto ; done
215 while true ; do
216 case $1 in
217 -*) parsearg "$1"; shift;;
218 *) break ;;
219 esac
220 done
222 [ -z "$exec_prefix" ] && exec_prefix=$prefix
223 [ -z "$libdir" ] && libdir=$prefix/lib
224 [ -z "$includedir" ] && includedir=$prefix/include
225 [ -z "$sysconfdir" ] && sysconfdir=$prefix/etc
226 [ -z "$bindir" ] && bindir=$exec_prefix/bin
227 [ -z "$CC" ] && CC=cc
229 clear_config
231 add_config "prefix = $prefix"
232 add_config "exec_prefix = $exec_prefix"
233 add_config "bindir = $bindir"
234 add_config "libdir = $libdir"
235 add_config "includedir = $includedir"
236 add_config "sysconfdir = $sysconfdir"
238 add_config "CC ?= $CC"
240 [ -z "$CPPFLAGS" ] || add_config "USER_CPPFLAGS = $CPPFLAGS"
241 [ -z "$OUR_CPPFLAGS" ] || add_config "USER_CPPFLAGS += $OUR_CPPFLAGS"
242 [ -z "$CFLAGS" ] || add_config "USER_CFLAGS = $CFLAGS"
243 [ -z "$LDFLAGS" ] || add_config "USER_LDFLAGS = $LDFLAGS"
245 add_cflags "-DXCHATLIBDIR=\\\"$libdir/xchat\\\""
246 add_cflags "-DXCHATSHAREDIR=\\\"$prefix/share/xchat\\\""
247 add_cflags "-DUSE_OPENSSL"
249 for lib in $libs ; do add_lib "$lib" ; done
250 add_lib openssl "" "-lssl -lcrypto"
252 prog1=$(check_program "gdk-pixbuf-csource" 1)
253 add_config "PIXMAPCONVERT = $prog1"
255 for i in libsexy gtkspell ; do
256 eval enabled=\${feature_$i}
257 printf "checking whether to use library $i..."
258 if [ "$enabled" = yes ] || [ "$enabled" = auto ] ; then
259 l=$i
260 [ $l = gtkspell ] && l=gtkspell-2.0
261 spell_flags=$(get_pkgconf_cflags $l)
262 if [ ! -z "$spell_flags" ] ; then
263 add_cflags "$spell_flags"
264 spell_flags=$(get_pkgconf_ldflags $i)
265 add_ldflags "$spell_flags"
266 if [ "$i" = "libsexy" ] ; then
267 add_cflags "-DUSE_LIBSEXY"
268 else
269 add_cflags "-DUSE_GTKSPELL"
271 printf "yes\n"
272 else
273 if [ "$enabled" = yes ] ; then
274 printf "error: $i requested but not found!"
275 exit 1
277 printf "no\n"
280 done
282 # plugin stuff ...
284 use_plugin=
286 printf "checking whether to use perl plugin..."
287 if [ "$feature_perl" = auto ] ; then
288 perl=$(check_program "perl" 0)
289 if [ -n "$perl" ] ; then
290 PERL_CFLAGS=`$perl -MExtUtils::Embed -e ccopts 2>/dev/null`
291 PERL_LDFLAGS=`$perl -MExtUtils::Embed -e ldopts 2>/dev/null | sed 's/-lgdbm //'`
292 feature_perl=yes
295 if [ "$feature_perl" = yes ] ; then
296 printf "yes\n"
297 add_config "PERL_CFLAGS = $PERL_CFLAGS"
298 add_config "PERL_LDFLAGS = $PERL_LDFLAGS"
299 add_config "PLUGINS += perl.so"
300 # there are actually 2 plugins, "old" and new, but all scripts i've seen only use old
301 add_cflags "-DOLD_PERL"
302 use_plugin=1
303 else
304 printf "no\n"
306 printf "checking whether to use tcl plugin..."
307 if [ "$feature_tcl" = auto ] ; then
308 tcl=$(check_program "tclsh" 0)
309 if [ -n "$tcl" ] ; then
310 TCL_CFLAGS=$(get_pkgconf_cflags tcl)
311 TCL_LDFLAGS=$(get_pkgconf_ldflags tcl)
312 tcl_error=
313 # tcl 8.5 does not come with a pkgconfig file
314 # tcl 8.6. comes with a buggy one that fails to include its own library
315 # https://sourceforge.net/tracker/?func=detail&aid=3598298&group_id=10894&atid=110894
316 # hopefully tcl 8.7 will come with a *working* pkgconfig file ...
317 # until that happens, we need to fall back to its proprietary tclConfig system.
318 if [ -z "$TCL_LDFLAGS" ] || ! echo "$TCL_LDFLAGS" | grep "[-]ltcl" > /dev/null ; then
319 tcl_found=
320 for i in "$libdir" "$prefix"/lib/ "$prefix"/lib64/ /lib /lib64 /usr/lib /usr/lib64 ; do
321 printf "searching tclConfig.sh in $i ... "
322 if [ -e "$i"/tclConfig.sh ] ; then
323 . "$i"/tclConfig.sh
324 TCL_LDFLAGS="$TCL_LIB_SPEC $TCL_LIBS"
325 tcl_found=1
326 break
328 done
329 if [ -z "$tcl_found" ] ; then
330 tcl_error=1
333 [ -z "$tcl_error" ] && feature_tcl=yes
336 if [ "$feature_tcl" = yes ] ; then
337 printf "yes\n"
338 add_config "TCL_CFLAGS = $TCL_CFLAGS"
339 add_config "TCL_LDFLAGS = $TCL_LDFLAGS"
340 add_config "PLUGINS += tcl.so"
341 use_plugin=1
342 else
343 printf "no\n"
345 printf "checking whether to use python plugin..."
346 if [ "$feature_python" = auto ] ; then
347 python=$(check_program "python" 0)
348 if [ -n "$python" ] ; then
349 PY_CFLAGS=$(get_pkgconf_cflags python)
350 [ -z "$PY_CFLAGS" ] && PY_CFLAGS=$(get_pkgconf_cflags python-2.7)
351 if [ -z "$PY_CFLAGS" ] ; then
352 for i in "$prefix" /usr /usr/local/ ; do
353 printf "searching Python.h in $i/include/python2.7 ... "
354 if [ -e "$i"/include/python2.7/Python.h ] ; then
355 PY_CFLAGS=-I"$i"/include/python2.7
356 printf "SUCCESS\n"
357 break;
358 else
359 printf "FAIL\n"
361 done
363 PY_LDFLAGS=$(get_pkgconf_ldflags python)
364 [ -z "$PY_LDFLAGS" ] && PY_LDFLAGS=$(get_pkgconf_ldflags python-2.7)
365 [ -z "$PY_LDFLAGS" ] && PY_LDFLAGS=-lpython2.7
366 [ ! -z "$PY_CFLAGS" ] && feature_python=yes
369 if [ "$feature_python" = yes ] ; then
370 printf "yes\n"
371 printf "WARNING: python plugin needs environment variable PYTHONHOME\n"
372 printf " set to python's prefix.\n"
373 printf " lack of that environment variable will cause ixchat exitting\n"
374 printf " when the plugin is loaded.\n"
375 printf " on sabotage linux, use \"PYTHONHOME=/ ixchat\"\n"
376 printf " to launch the program.\n"
377 add_config "PY_CFLAGS = $PY_CFLAGS"
378 add_config "PY_LDFLAGS = $PY_LDFLAGS"
379 add_config "PLUGINS += python.so"
380 use_plugin=1
381 else
382 printf "no\n"
385 if [ "$use_plugin" = 1 ] ; then
386 add_cflags "-DUSE_PLUGIN"
389 if isbsd || ismac ; then
390 add_config "INSTALL_FLAGS=-m"
393 add_cflags "\$(USER_CPPFLAGS) \$(USER_CFLAGS)"
394 add_ldflags "\$(USER_LDFLAGS)"
395 echo done, now run make \&\& make install