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