Moved 'setup' to the utils directory and converted the build
[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                 --with-ssl)
34                         SSL=yes
35                 ;;
36                 --without-ssl)
37                         SSL=no
38                 ;;
39                 *)
40                         echo $0 : unknown option $k
41                         echo
42                         echo Valid options are:
43                         echo '  --ctdldir=DIR           Install Citadel server to DIR [/usr/local/citadel]'
44                         echo '  --with-ssl              Force build with OpenSSL support [normally autodetected]'
45                         echo '  --without-ssl           Force build without OpenSSL support [normally autodetected]'
46                         exit 1
47                 ;;
48         esac
49         shift
50 done
51
52 # Set any missing values (FIXME remove the ultra-fatal -W options when finished converting from autotools)
53
54 # Accept PREFIX as a substitute for CTDLDIR, but only if CTDLDIR is not already set
55 [ "$CTDLDIR" = "" ] && [ "$PREFIX" != "" ] && CTDLDIR=$PREFIX
56
57 # Configure the directory into which Citadel Server will be installed.
58 [ "$CTDLDIR" = "" ] && CTDLDIR=/usr/local/citadel
59
60 # Permit override of CFLAGS and LDFLAGS using environment variables
61 [ "$CFLAGS" = "" ]      && CFLAGS='-ggdb -Werror -Wfatal-errors -Wno-discarded-qualifiers'
62 [ "$LDFLAGS" = "" ]     && LDFLAGS=''
63
64 # Test for OpenSSL
65 [ "$SSL" != "yes" ] && [ "$SSL" != "no" ] && {
66         echo Testing for OpenSSL...
67         tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/configure.$$
68         tempcc=${tempfile}.c
69         cat >$tempcc <<!
70 #include <openssl/ssl.h>
71 int main(int argc, char **argv) {
72         SSL_load_error_strings();
73         exit(0);
74 }
75 !
76         SSL='no';
77         cc $tempcc -lssl -lcrypto -o $tempfile && $tempfile && SSL='yes'
78         rm -f $tempfile 2>/dev/null
79         rm -f $tempcc 2>/dev/null
80 }
81 echo SSL: $SSL
82 [ "$SSL" = "yes" ] && {
83         CFLAGS=${CFLAGS}' -DHAVE_OPENSSL'
84         LDFLAGS=${LDFLAGS}' -lssl -lcrypto -lz'
85 }
86
87 # FIXME do a real build id here
88 CFLAGS=${CFLAGS}' -DBUILD_ID=\"unknown\"'
89
90 # Output the config.mk
91
92 (
93         echo # config.mk is generated by configure
94         echo "CTDLDIR := ${CTDLDIR}"
95         echo "CFLAGS := ${CFLAGS}"
96         echo "LDFLAGS := ${LDFLAGS}"
97 ) >config.mk
98
99 cat config.mk
100 echo