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