]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - configure
Fixed dns queue stuff?
[user/henk/code/inspircd.git] / configure
1 #!/bin/sh
2 # InspIRCd Configuration Script
3 #
4 # Copyright 2003 The ChatSpike Development Team
5 # <brain@chatspike.net>
6 # <Craig@chatspike.net>
7 #
8 # $Id$
9 #
10 #
11 ########################################
12
13 echo "Configuring default values..."
14
15 ME=`pwd`
16 GCCVER=`gcc -dumpversion | cut -c 1`
17 GCC34=`gcc -dumpversion | cut -c 3`
18 CONFIG_DIR=$ME/conf
19 MODULE_DIR=$ME/modules
20 BINARY_DIR=$ME/bin
21 INSTALL=`which install`
22 OPTIMITEMP=0
23 OPTIMISATI="-g"
24 MAX_CLIENT_T=`ulimit -n`
25 NICK_LENGT=32
26 CHAN_LENGT=64
27 MAX_CHANNE=20
28 MAXI_MODES=20
29 OSNAME=`(uname -s) 2>/dev/null` || OSNAME="unknown"
30
31 if [ -z $MAX_CLIENT_T ] ; then
32         MAX_CLIENT_T=1024
33         SCAN_FAILED=1
34 fi
35
36
37 if [ "$1" = "-clean" -o "$2" = "-clean" ] ; then
38   `rm -rf .config.cache`
39 fi
40
41 if [ -e ".config.cache" -a -z "$CLEAN" ] ; then
42     . .config.cache 
43 fi
44
45 if [ "$1" = "-update" -o "$2" = "-update" ] ; then
46    # They wanna update their Makefile.. good for 'em
47    # Make sure .config.cache exists
48    if [ ! -e ".config.cache" ] ; then
49      echo "You have not run ./configure before. Please do this before trying to run the update script."
50      exit 0
51    fi
52    # Right, load the cache values
53    . .config.cache
54    # Check for modules
55
56    case "$OSNAME" in
57            FreeBSD)
58                    LDLIBS="-Ldl"
59                    FLAGS="-fPIC -frtti $OPTIMISATI"
60                    MAKEPROG="gmake"
61                    ;;
62            *)
63                    LDLIBS="-ldl"
64                    FLAGS="-fPIC -frtti $OPTIMISATI"
65                    MAKEPROG="make"
66                    ;;
67    esac
68
69    MODULES=""
70    for module in src/modules/*.cpp ; do
71            mod=`echo $module | sed 's/.cpp/.so/' | sed 's/src\/modules\///'`
72            MODULES="$MODULES $mod"
73    done
74
75    # Write the new makefile.
76    . .Makefile.inc
77    echo "Complete."
78    exit 1; 
79 fi
80
81
82 if [ -z $MAX_CLIENT ] ; then
83         MAX_CLIENT=$MAX_CLIENT_T
84 fi
85
86
87 c=""
88 n=""
89 if [ "`eval echo -e -n 'a'`" = "-n a" ] ; then
90         c="\c"
91 else
92         n="-n"
93 fi
94
95 exists () { # because some shells don't have test -e
96     if [ -f $1 -o -d $1 -o -p $1 -o -c $1 -o -b $1 ] ; then
97         return 0
98     else
99         return 1
100     fi
101 }
102
103 echo "#include <string.h>">.test.cpp
104 echo "#include <stdio.h>">>.test.cpp
105 echo "int main() { char a[10]; char b[10]; strlcpy(a,b,10); printf(\"%d\\n\",999); }" >>.test.cpp
106 g++ -o .test .test.cpp 2>&1
107 HAS_STRLCPY=`./.test 2>&1`
108 rm -f .test.cpp .test
109
110 clear
111 echo -e "'\033[1;33m####\033[0;37m:'\033[1;33m##\033[0;37m::: \033[1;33m##\033[0;37m::'\033[1;33m######\033[0;37m::'\033[1;33m########\033[0;37m::'\033[1;33m####\033[0;37m:'\033[1;33m########\033[0;37m:::'\033[1;33m######\033[0;37m::'\033[1;33m########\033[0;37m::"
112 echo -e ". \033[1;33m##\033[0;37m:: \033[1;33m###\033[0;37m:: \033[1;33m##\033[0;37m:'\033[1;33m##\033[0;37m... \033[1;33m##\033[0;37m: \033[1;33m##\033[0;37m.... \033[1;33m##\033[0;37m:. \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m.... \033[1;33m##\033[0;37m:'\033[1;33m##\033[0;37m... \033[1;33m##\033[0;37m: \033[1;33m##\033[0;37m.... \033[1;33m##\033[0;37m:"
113 echo -e ": \033[1;33m##\033[0;37m:: \033[1;33m####\033[0;37m: \033[1;33m##\033[0;37m: \033[1;33m##\033[0;37m:::..:: \033[1;33m##\033[0;37m:::: \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m:::: \033[1;33m##\033[0;37m: \033[1;33m##\033[0;37m:::..:: \033[1;33m##\033[0;37m:::: \033[1;33m##\033[0;37m:"
114 echo -e ": \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m \033[1;33m##\033[0;37m \033[1;33m##\033[0;37m:. \033[1;33m######\033[0;37m:: \033[1;33m########\033[0;37m::: \033[1;33m##\033[0;37m:: \033[1;33m########\033[0;37m:: \033[1;33m##\033[0;37m::::::: \033[1;33m##\033[0;37m:::: \033[1;33m##\033[0;37m:"
115 echo -e ": \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m. \033[1;33m####\033[0;37m::..... \033[1;33m##\033[0;37m: \033[1;33m##\033[0;37m.....:::: \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m.. \033[1;33m##\033[0;37m::: \033[1;33m##\033[0;37m::::::: \033[1;33m##\033[0;37m:::: \033[1;33m##\033[0;37m:"
116 echo -e ": \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m:. \033[1;33m###\033[0;37m:'\033[1;33m##\033[0;37m::: \033[1;33m##\033[0;37m: \033[1;33m##\033[0;37m::::::::: \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m::. \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m::: \033[1;33m##\033[0;37m: \033[1;33m##\033[0;37m:::: \033[1;33m##\033[0;37m:"
117 echo -e "'\033[1;33m####\033[0;37m: \033[1;33m##\033[0;37m::. \033[1;33m##\033[0;37m:. \033[1;33m######\033[0;37m:: \033[1;33m##\033[0;37m::::::::'\033[1;33m####\033[0;37m: \033[1;33m##\033[0;37m:::. \033[1;33m##\033[0;37m:. \033[1;33m######\033[0;37m:: \033[1;33m########\033[0;37m::"
118 echo -e "\033[0;37m\033[0;37m....::..::::..:::......:::..:::::::::....::..:::::..:::......:::........:::"
119 echo ""
120 echo -e "\033[1;37mWelcome to the InspIRCd Configuration program!"
121 echo ""
122 echo "*** If you are unsure of any of these values, leave it blank for    ***"
123 echo "*** standard settings that will work, and your server will run      ***"
124 echo "*** using them. If you are running this server as part of a         ***"
125 echo "*** larger network, you must consult with your network admins       ***"
126 echo "*** for the proper values to use, or server links will be unstable! ***"
127 echo -e "\033[0;37m"
128 echo -e "Press \033[1;37m<RETURN>\033[0;37m to accept the default for any option, or enter"
129 echo -e "a new value. Please note: You will \033[1;37mHAVE\033[0;37m to read the docs"
130 echo -e "dir, otherwise you won't have a config file!"
131 echo ""
132 echo -e "Your operating system is: \033[1;37m$OSNAME\033[0;37m (`uname -mnr`), fdmax: $MAX_CLIENT_T"
133 echo ""
134
135 #############################################################################
136
137     ok=0
138     asked=1
139     echo "In what directory are the configuration files?"
140     while [ $ok -eq 0 ] ; do
141         echo -e $n "[\033[1;32m$CONFIG_DIR\033[0;37m] -> $c"
142         if read INPUT ; then : ; else echo "" ; exit 1 ; fi
143         if [ ! "$INPUT" ] ; then
144             INPUT=$CONFIG_DIR
145             default=1
146         fi
147         if echo "$INPUT" | grep -q \[\'\"\\\] ; then
148             echo 'Please use a pathname without the characters: '\'' " \'
149         elif [ ! "$NO_DIR_CHECK" -a ! -d "$INPUT" ] ; then
150             if exists "$INPUT" ; then
151                 echo "$INPUT exists, but is not a directory!"
152             else
153                 echo "$INPUT does not exist.  Create it?"
154                 echo -e $n "[\033[1;32my\033[0;37m] $c"
155                 read YN
156                 if [ "$YN" != "n" ] ; then
157                     if mkdir -p "$INPUT" ; then
158                         ok=1
159                     fi
160                 fi
161             fi
162             else
163             ok=1
164         fi
165     done
166     CONFIG_DIR=$INPUT
167     echo ""
168
169
170 ##############################################################################
171
172     ok=0
173     asked=1
174     echo "In What directory are the modules to be compiled to?"
175     while [ $ok -eq 0 ] ; do
176         echo -e $n "[\033[1;32m$MODULE_DIR\033[0;37m] -> $c"
177         if read INPUT ; then : ; else echo "" ; exit 1 ; fi
178         if [ ! "$INPUT" ] ; then
179             INPUT=$MODULE_DIR
180             default=1
181         fi
182         if echo "$INPUT" | grep -q \[\'\"\\\] ; then
183             echo 'Please use a pathname without the characters: '\'' " \'
184         elif [ ! "$NO_DIR_CHECK" -a ! -d "$INPUT" ] ; then
185             if exists "$INPUT" ; then
186                 echo "$INPUT exists, but is not a directory!"
187             else
188                 echo "$INPUT does not exist.  Create it?"
189                 echo -e $n "[\033[1;32my\033[0;37m] $c"
190                 read YN
191                 if [ "$YN" != "n" ] ; then
192                     if mkdir -p "$INPUT" ; then
193                         ok=1
194                     fi
195                 fi
196             fi
197             else
198             ok=1
199         fi
200     done
201     MODULE_DIR=$INPUT
202     echo ""
203
204
205 ##############################################################################
206
207     ok=0
208     asked=1
209     echo "In what directory is the IRCd binary to be placed?"
210     while [ $ok -eq 0 ] ; do
211         echo -e $n "[\033[1;32m$BINARY_DIR\033[0;37m] -> $c"
212         if read INPUT ; then : ; else echo "" ; exit 1 ; fi
213         if [ ! "$INPUT" ] ; then
214             INPUT=$BINARY_DIR
215             default=1
216         fi
217         if echo "$INPUT" | grep -q \[\'\"\\\] ; then
218             echo 'Please use a pathname without the characters: '\'' " \'
219         elif [ ! "$NO_DIR_CHECK" -a ! -d "$INPUT" ] ; then
220             if exists "$INPUT" ; then
221                 echo "$INPUT exists, but is not a directory!"
222             else
223                 echo "$INPUT does not exist.  Create it?"
224                 echo -e $n "[\033[1;32my\033[0;37m] $c"
225                 read YN
226                 if [ "$YN" != "n" ] ; then
227                     if mkdir -p "$INPUT" ; then
228                         ok=1
229                     fi
230                 fi
231             fi
232             else
233             ok=1
234         fi
235     done
236     BINARY_DIR=$INPUT
237     echo ""
238
239 ###############################################################################
240 # Craigs Version 3 With slightly less Cheeze :p
241
242 cheeze=0
243 echo -e "Maximum number of clients at any one time (\033[1;32m1-$MAX_CLIENT_T\033[0;37m)?"
244 while [ "$cheeze" -eq "0" ] ; do
245         echo -e $n "[\033[1;32m$MAX_CLIENT\033[0;37m] -> $c"
246         read cc
247
248         if [ -z "$cc" ] ; then
249                 cc=$MAX_CLIENT
250         fi
251
252         case "$cc" in 
253                 [0-9]*)
254                         if [ "$cc" -gt "$MAX_CLIENT_T" -a -z "$SCAN_FAILED" ] ; then
255                                 echo -e "WARNING: Our scans have indicated that you are attempting"
256                                 echo -e "to use more sockets than there are avaliable. Are you sure"
257                                 echo -e "you wish to do this? It may cause the IRCd to malfunction [y/n]"
258                                 echo -e $n "[\033[1;32mn\033[0;37m] -> $c"
259                                 read YN
260                                 if [ "$YN" = "y" ] ; then
261                                         MAX_CLIENT=$cc
262                                         cheeze=1
263                                 else
264                                         echo ""
265                                         echo -e "Please enter the correct value (\033[1;32m1-$MAX_CLIENT_T\033[0;37m)"
266                                 fi
267                         else
268                                 echo $SCAN_FAILED
269                                 cheeze=1
270                                 MAX_CLIENT=$cc
271                         fi
272                         ;;
273                 *)
274                         echo ""
275                         echo "You must enter a number in this field. Please try again."
276                         ;;
277         esac
278 done
279 echo ""
280
281
282 ###############################################################################
283
284   cheeze=0
285   echo -e "What is the Maximum length of nicknames?"
286   while [ "$cheeze" -eq "0" ] ; do
287         echo -e $n "[\033[1;32m$NICK_LENGT\033[0;37m] -> $c"
288         read cc
289         if [ "$cc" ] ; then
290                 case "$cc" in
291                         [0-9]*)
292                         NICK_LENGT=$cc
293                         cheeze=1
294                         ;;
295                         *)
296                         echo ""
297                         echo "You Must Enter a Number in this field. Please Try Again."
298                         cheeze=0
299                         ;;
300                 esac
301         else
302                 cheeze=1
303         fi
304   done
305   echo ""
306
307 ###############################################################################
308
309   cheeze=0
310   echo -e "What is the Maximum length of channel names?"
311   while [ "$cheeze" -eq "0" ] ; do
312         echo -e $n "[\033[1;32m$MAX_CHANNE\033[0;37m] -> $c"
313         read cc
314         if [ "$cc" ] ; then
315                 case "$cc" in
316                         [0-9]*)
317                         MAX_CHANNE=$cc
318                         cheeze=1
319                         ;;
320                         *)
321                         echo ""
322                         echo "You Must Enter a Number in this field. Please Try Again."
323                         cheeze=0
324                         ;;
325                 esac
326         else
327                 cheeze=1
328         fi
329   done
330   echo ""
331
332 ###############################################################################
333
334   cheeze=0
335   echo -e "What is the Maximum number of mode changes in one line?"
336   while [ "$cheeze" -eq "0" ] ; do
337         echo -e $n "[\033[1;32m$MAXI_MODES\033[0;37m] -> $c"
338         read cc
339         if [ "$cc" ] ; then
340                 case "$cc" in
341                         [0-9]*)
342                         MAXI_MODES=$cc
343                         cheeze=1
344                         ;;
345                         *)
346                         echo ""
347                         echo "You Must Enter a Number in this field. Please Try Again."
348                         cheeze=0
349                         ;;
350                 esac
351         else
352                 cheeze=1
353         fi
354   done
355   echo ""
356
357 ###############################################################################
358 # Code Optimisation?
359
360   cheeze=0
361   echo -e "Enter the Level Of Binary optimisation. This is a number between 0 and 3 (inclusive)"
362   echo -e "The InspIRCd Team will _NOT_ support any bug reports above 0."
363   echo -e "Also note, the IRCd behaviour will be different depending on this value."
364   echo -e "Please read the documentation for more information."
365   echo -e ""
366   echo -e "The Higher the number, the more optimised your binary will be. This value will default to 0"
367   echo -e "If you either a) Dont enter a number, or b) Enter a value outside the range."
368   echo -e $n "[\033[1;32m$OPTIMITEMP\033[0;37m] -> $c"
369   read cc
370   if [ -z "$cc" ] ; then
371         cc=$OPTIMITEMP
372   fi
373   case "$cc" in
374         1)
375                 OPTIMITEMP=1
376                 OPTIMISATI="-O"
377                 ;;
378         2)
379                 OPTIMITEMP=2
380                 OPTIMISATI="-O2"
381                 ;;
382         3)
383                 OPTIMITEMP=3
384                 OPTIMISATI="-O3"
385                 ;;
386         *)
387                 OPTIMITEMP=0
388                 OPTIMISATI="-g"
389                 ;;
390   esac
391   echo ""
392
393 ###############################################################################
394
395
396 echo -e "\033[1;32mPre-build configuration is complete!\033[0;37m"
397 echo ""
398 echo -e "\033[0;37mConfig path:\033[1;32m\t\t\t$CONFIG_DIR"
399 echo -e "\033[0;37mModule path:\033[1;32m\t\t\t$MODULE_DIR"
400 echo -e "\033[0;37mMax connections:\033[1;32m\t\t$MAX_CLIENT"
401 echo -e "\033[0;37mMax User Channels\033[1;32m\t\t$MAX_CHANNE"
402 echo -e "\033[0;37mMax nickname length:\033[1;32m\t\t$NICK_LENGT"
403 echo -e "\033[0;37mMax channel length:\033[1;32m\t\t$CHAN_LENGT"
404 echo -e "\033[0;37mMax mode length:\033[1;32m\t\t$MAXI_MODES"
405 echo -e "\033[0;37mGCC Version Found:\033[1;32m\t\t$GCCVER.$GCC34"
406 echo -e "\033[0;37mOptimatizaton Flag:\033[1;32m\t\t$OPTIMISATI"
407 echo -e "\033[0;37m"
408
409 echo "Writing cache file for future ./configures ..."
410
411 COPY_CONF=0
412 if [ "$CONFIG_DIR" != "$ME/conf" ] ; then
413     COPY_CONF=1
414 fi
415
416
417 if [ -e ".config.cache" ] ; then
418         rm .config.cache
419 fi
420 echo "CONFIG_DIR=\"$CONFIG_DIR\"" >> .config.cache
421 echo "MODULE_DIR=\"$MODULE_DIR\"" >> .config.cache
422 echo "BINARY_DIR=\"$BINARY_DIR\"" >> .config.cache
423 echo "MAX_CLIENT=\"$MAX_CLIENT\"" >> .config.cache
424 echo "MAX_CHANNE=\"$MAX_CHANNE\"" >> .config.cache
425 echo "NICK_LENGT=\"$NICK_LENGT\"" >> .config.cache
426 echo "MAXI_MODES=\"$MAXI_MODES\"" >> .config.cache 
427 echo "OPTIMITEMP=\"$OPTIMITEMP\"" >> .config.cache
428 echo "OPTIMISATI=\"$OPTIMISATI\"" >> .config.cache
429 echo "GCC34=\"$GCC34\"" >> .config.cache
430 echo "HAS_STRLCPY=\"$HAS_STRLCPY\"" >> .config.cache
431 echo "COPY_CONF=\"$COPY_CONF\"" >> .config.cache
432
433 echo "Writing include/inspircd_config.h ..."
434
435 echo "/* Auto generated by configure, do not modify! */" >include/inspircd_config.h
436 echo "" >>include/inspircd_config.h
437 if [ "$GCCVER" -eq "3" ] ; then
438 echo "#define GCC3" >>include/inspircd_config.h
439         if [ "$GCC34" -gt "3" ] ; then
440                 echo "#define GCC34" >>include/inspircd_config.h
441         fi
442 fi
443 if [ "$HAS_STRLCPY" -eq "999" ] ; then
444         echo "#define HAS_STRLCPY" >>include/inspircd_config.h
445 fi
446 echo "#define SYSLOG_FACILITY LOG_DAEMON" >>include/inspircd_config.h
447 echo "#define SYSLOG_LEVEL LOG_NOTICE" >>include/inspircd_config.h
448 echo "#define CONFIG_FILE \"$CONFIG_DIR/inspircd.conf\"" >>include/inspircd_config.h
449 echo "#define MOD_PATH \"$MODULE_DIR\"" >>include/inspircd_config.h
450 echo "#define VERSION \"`sh ./src/version.sh`\"" >>include/inspircd_config.h
451 echo "#define MAXCLIENTS $MAX_CLIENT" >>include/inspircd_config.h
452 echo "#define NICKMAX $NICK_LENGT" >>include/inspircd_config.h
453 echo "#define CHANMAX $CHAN_LENGT" >>include/inspircd_config.h
454 echo "#define MAXCHANS $MAX_CHANNE" >>include/inspircd_config.h
455 echo "#define MAXMODES $MAXI_MODES" >>include/inspircd_config.h
456 echo "#define OPTIMISATION $OPTIMITEMP" >>include/inspircd_config.h
457 echo "#define SYSTEM \"`uname -n -s -r`\"" >>include/inspircd_config.h
458 echo "#define MAXBUF 514">>include/inspircd_config.h
459 touch include/inspircd_config.h
460
461 echo "Preparing Variables for the Makefile"
462
463 case "$OSNAME" in
464         FreeBSD)
465                 LDLIBS="-Ldl"
466                 FLAGS="-fPIC -frtti $OPTIMISATI"
467                 MAKEPROG="gmake"
468                 ;;
469         *)
470                 LDLIBS="-ldl"
471                 FLAGS="-fPIC -frtti $OPTIMISATI"
472                 MAKEPROG="make"
473                 ;;
474 esac
475
476 MODULES=""
477 for module in src/modules/*.cpp ; do
478         mod=`echo $module | sed 's/.cpp/.so/' | sed 's/src\/modules\///'`
479         MODULES="$MODULES $mod" 
480 done
481
482 echo -e "Writing \033[1;37m$OSNAME\033[0;37m makefile"
483 echo ""
484
485 . .Makefile.inc
486
487 echo ""
488
489 echo ""
490 echo "Do you want to compile the IRCd binaries?"
491 echo -e $n "[\033[1;32my\033[0;37m] $c"
492 read YN
493 if [ "$YN" != "n" ] ; then
494         echo ""
495         echo -e "\033[1;32mCompiling...\033[0;37m"
496         echo ""
497         cd $ME
498         $MAKEPROG
499         echo ""
500         echo "Done!"
501         echo ""
502 else
503         echo ""
504         echo "Done!"
505         echo ""
506         echo -e "To build your server with these settings, please type '\033[1;32mmake\033[0;37m' now."
507         echo ""
508         echo -e "*** \033[1;32mRemember to edit your configuration files!!!\033[0;37m ***"
509         echo ""
510 fi
511
512
513 echo ""
514 echo "Do you want to run the config file maker?"
515 echo -e $n "[\033[1;32my\033[0;37m] $c"
516 read YN
517 if [ "$YN" != "n" ] ; then
518         sh makeconf
519 fi
520
521 echo -e "*** \033[1;32mRemember to edit your configuration files!!!\033[0;37m ***"
522 echo ""