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