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