textclient: test to see whether iconv requires -liconv in ldflags. Now it should...
[citadel.git] / citadel / configure
1 #!/bin/sh
2
3 # CONFIGURE SCRIPT FOR CITADEL SERVER
4 # This file is part of "conf-IG-ure"
5 # Copyright (C) 2016-2022 by Art Cancro
6 #
7 # This program is open source software.  Use, duplication, and/or
8 # disclosure are subject to the GNU General Purpose License version 3.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 echo 
16 echo Running the configure script to create config.mk
17 echo
18
19 # Parse the command line arguments
20 for x in $*
21 do
22         a=$1
23         k=`echo $a | awk -F= ' { print $1 } '`
24         v=`echo $a | awk -F= ' { print $2 } '`
25
26         case $k in
27                 --prefix)
28                         PREFIX=$v
29                 ;;
30                 --ctdldir)
31                         CTDLDIR=$v
32                 ;;
33                 *)
34                         echo $0 : unknown option $k
35                         echo
36                         echo Valid options are:
37                         echo '  --ctdldir=DIR           Install Citadel server to DIR [/usr/local/citadel]'
38                         exit 1
39                 ;;
40         esac
41         shift
42 done
43
44 # Set any missing values (FIXME remove the ultra-fatal -W options when finished converting from autotools)
45
46 # Accept PREFIX as a substitute for CTDLDIR, but only if CTDLDIR is not already set
47 [ "$CTDLDIR" = "" ] && [ "$PREFIX" != "" ] && CTDLDIR=$PREFIX
48
49 # Configure the directory into which Citadel Server will be installed.
50 [ "$CTDLDIR" = "" ] && CTDLDIR=/usr/local/citadel
51
52 # Permit override of CFLAGS and LDFLAGS using environment variables
53 [ "$CFLAGS" = "" ]      && CFLAGS='-ggdb -Werror -Wfatal-errors -Wno-discarded-qualifiers'
54 [ "$LDFLAGS" = "" ]     && LDFLAGS=''
55
56 ########################################################################
57 # Test for OpenSSL
58 ########################################################################
59 echo Testing for OpenSSL...
60 tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/configure.$$
61 tempcc=${tempfile}.c
62 cat >$tempcc <<!
63 #include <openssl/ssl.h>
64 int main(int argc, char **argv) {
65         SSL_load_error_strings();
66         exit(0);
67 }
68 !
69 cc $tempcc -lssl -lcrypto -o $tempfile && $tempfile && {
70         CFLAGS=${CFLAGS}' -DHAVE_OPENSSL'
71         LDFLAGS=${LDFLAGS}' -lssl -lcrypto -lz'
72 } || {
73         echo Citadel Server requires OpenSSL which is not present.
74         exit 2
75 }
76
77
78 ########################################################################
79 # Test for iconv
80 ########################################################################
81 echo Testing for iconv...
82 tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/configure.$$
83 tempcc=${tempfile}.c
84 cat >$tempcc <<!
85 #include <stdlib.h>
86 #include <unistd.h>
87 #include <stdio.h>
88 #include <iconv.h>
89 int main(int argc, char **argv) {
90         size_t wow = iconv(NULL, NULL, NULL, NULL, NULL);
91         return(0);
92 }
93 !
94
95 cc $tempcc -o $tempfile && {
96         ICONV='yes'
97         echo iconv.h is present and requires no additional libraries
98 } || {
99         echo Trying again with -liconv...
100         cc $tempcc -liconv -o $tempfile && {
101                 ICONV='yes'
102                 LDFLAGS=${LDFLAGS}' -liconv'
103         } || {
104                 echo Citadel Server requires iconv character set conversion.
105                 exit 1
106         }
107 }
108
109
110 # FIXME do a real build id here
111 CFLAGS=${CFLAGS}' -DBUILD_ID=\"unknown\"'
112
113 # Output the config.mk
114
115 (
116         echo # config.mk is generated by configure
117         echo "CTDLDIR := ${CTDLDIR}"
118         echo "CFLAGS := ${CFLAGS}"
119         echo "LDFLAGS := ${LDFLAGS}"
120 ) >config.mk
121
122 cat config.mk
123 echo