create-dist.sh: do not hardcode paths
[rofl0r-ixchat.git] / configure
blob5d6924e88fd9efe4948a7ce908700aa651f3a1a7
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 for i in python perl tcl libsexy gtkspell ; do eval feature_$i=auto ; done
134 while true ; do
135 case $1 in
136 -*) parsearg "$1"; shift;;
137 *) break ;;
138 esac
139 done
141 [ -z "$exec_prefix" ] && exec_prefix=$prefix
142 [ -z "$libdir" ] && libdir=$prefix/lib
143 [ -z "$includedir" ] && includedir=$prefix/include
144 [ -z "$sysconfdir" ] && sysconfdir=$prefix/etc
145 [ -z "$bindir" ] && bindir=$exec_prefix/bin
146 [ -z "$CC" ] && CC=cc
148 clear_config
150 add_config "prefix = $prefix"
151 add_config "exec_prefix = $exec_prefix"
152 add_config "bindir = $bindir"
153 add_config "libdir = $libdir"
154 add_config "includedir = $includedir"
155 add_config "sysconfdir = $sysconfdir"
157 add_config "CC ?= $CC"
158 [ -z "$CPPFLAGS" ] || add_config "CPPFLAGS ?= $CPPFLAGS"
159 [ -z "$CFLAGS" ] || add_config "CFLAGS ?= $CFLAGS"
161 add_cflags "-DXCHATLIBDIR=\\\"$libdir/xchat\\\""
162 add_cflags "-DXCHATSHAREDIR=\\\"$prefix/share/xchat\\\""
163 add_cflags "-DUSE_OPENSSL"
165 for lib in $libs ; do add_lib "$lib" ; done
166 add_lib openssl "" "-lssl -lcrypto"
168 prog1=$(check_program "gdk-pixbuf-csource" 1)
169 add_config "PIXMAPCONVERT = $prog1"
171 for i in libsexy gtkspell ; do
172 eval enabled=\${feature_$i}
173 printf "checking whether to use library $i..."
174 if [ "$enabled" = yes ] || [ "$enabled" = auto ] ; then
175 local l=$i
176 [ $l = gtkspell ] && l=gtkspell-2.0
177 spell_flags=$(get_pkgconf_cflags $l)
178 if [ ! -z "$spell_flags" ] ; then
179 add_cflags "$spell_flags"
180 spell_flags=$(get_pkgconf_ldflags $i)
181 add_ldflags "$spell_flags"
182 [ "$i" = "libsexy" ] add_cflags "-DUSE_LIBSEXY" || add_cflags "-DUSE_GTKSPELL"
183 printf "yes\n"
184 else
185 printf "no\n"
188 done
190 # plugin stuff ...
192 use_plugin=
194 printf "checking whether to use perl plugin..."
195 if [ "$feature_perl" = auto ] ; then
196 perl=$(check_program "perl" 0)
197 if [ -n "$perl" ] ; then
198 PERL_CFLAGS=`$perl -MExtUtils::Embed -e ccopts 2>/dev/null`
199 PERL_LDFLAGS=`$perl -MExtUtils::Embed -e ldopts 2>/dev/null | sed 's/-lgdbm //'`
200 feature_perl=yes
203 if [ "$feature_perl" = yes ] ; then
204 printf "yes\n"
205 add_config "PERL_CFLAGS = $PERL_CFLAGS"
206 add_config "PERL_LDFLAGS = $PERL_LDFLAGS"
207 add_config "PLUGINS += perl.so"
208 # there are actually 2 plugins, "old" and new, but all scripts i've seen only use old
209 add_cflags "-DOLD_PERL"
210 use_plugin=1
211 else
212 printf "no\n"
214 printf "checking whether to use tcl plugin..."
215 if [ "$feature_tcl" = auto ] ; then
216 tcl=$(check_program "tclsh" 0)
217 if [ -n "$tcl" ] ; then
218 TCL_CFLAGS=$(get_pkgconf_cflags tcl)
219 TCL_LDFLAGS=$(get_pkgconf_ldflags tcl)
220 tcl_error=
221 # tcl 8.5 does not come with a pkgconfig file
222 # tcl 8.6. comes with a buggy one that fails to include its own library
223 # https://sourceforge.net/tracker/?func=detail&aid=3598298&group_id=10894&atid=110894
224 # hopefully tcl 8.7 will come with a *working* pkgconfig file ...
225 # until that happens, we need to fall back to its proprietary tclConfig system.
226 if [ -z "$TCL_LDFLAGS" ] || ! echo "$TCL_LDFLAGS" | grep "[-]ltcl" > /dev/null ; then
227 tcl_found=
228 for i in "$libdir" "$prefix"/lib/ "$prefix"/lib64/ /lib /lib64 /usr/lib /usr/lib64 ; do
229 printf "searching tclConfig.sh in $i ... "
230 if [ -e "$i"/tclConfig.sh ] ; then
231 . "$i"/tclConfig.sh
232 TCL_LDFLAGS="$TCL_LIB_SPEC $TCL_LIBS"
233 tcl_found=1
234 break
236 done
237 if [ -z "$tcl_found" ] ; then
238 tcl_error=1
241 [ -z "$tcl_error" ] && feature_tcl=yes
244 if [ "$feature_tcl" = yes ] ; then
245 printf "yes\n"
246 add_config "TCL_CFLAGS = $TCL_CFLAGS"
247 add_config "TCL_LDFLAGS = $TCL_LDFLAGS"
248 add_config "PLUGINS += tcl.so"
249 use_plugin=1
250 else
251 printf "no\n"
253 printf "checking whether to use python plugin..."
254 if [ "$feature_python" = auto ] ; then
255 python=$(check_program "python" 0)
256 if [ -n "$python" ] ; then
257 PY_CFLAGS=$(get_pkgconf_cflags python)
258 [ -z "$PY_CFLAGS" ] && PY_CFLAGS=$(get_pkgconf_cflags python-2.7)
259 if [ -z "$PY_CFLAGS" ] ; then
260 for i in "$prefix" /usr /usr/local/ ; do
261 printf "searching Python.h in $i/include/python2.7 ... "
262 if [ -e "$i"/include/python2.7/Python.h ] ; then
263 PY_CFLAGS=-I"$i"/include/python2.7
264 printf "SUCCESS\n"
265 break;
266 else
267 printf "FAIL\n"
269 done
271 PY_LDFLAGS=$(get_pkgconf_ldflags python)
272 [ -z "$PY_LDFLAGS" ] && PY_LDFLAGS=$(get_pkgconf_ldflags python-2.7)
273 [ -z "$PY_LDFLAGS" ] && PY_LDFLAGS=-lpython2.7
274 [ ! -z "$PY_CFLAGS" ] && feature_python=yes
277 if [ "$feature_python" = yes ] ; then
278 printf "yes\n"
279 printf "WARNING: python plugin needs environment variable PYTHONHOME\n"
280 printf " set to python's prefix.\n"
281 printf " lack of that environment variable will cause ixchat exitting\n"
282 printf " when the plugin is loaded.\n"
283 printf " on sabotage linux, use \"PYTHONHOME=/ ixchat\"\n"
284 printf " to launch the program.\n"
285 add_config "PY_CFLAGS = $PY_CFLAGS"
286 add_config "PY_LDFLAGS = $PY_LDFLAGS"
287 add_config "PLUGINS += python.so"
288 use_plugin=1
289 else
290 printf "no\n"
293 if [ "$use_plugin" = 1 ] ; then
294 add_cflags "-DUSE_PLUGIN"
297 if isbsd || ismac ; then
298 add_config "INSTALL_FLAGS=-m"
302 echo done, now run make \&\& make install