Fix the "mode.mode & MODE_APASS" vs "mode.apass[0]" bug another place.
[ircu2.10.12-pk.git] / tools / transition
1 #!/bin/sh
2 #
3 # IRC - Internet Relay Chat, tools/transition
4 # Copyright (C) 2001 Kevin L. Mitchell <klmitch@mit.edu>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 1, or (at your option)
9 # any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #
20 # $Id: transition,v 1.1 2001-06-21 23:28:53 kev Exp $
21
22 # Better than having evals all over the place
23 setvar () {
24     eval $1=\$2
25 }
26 getvar () {
27     eval echo \$$1
28 }
29
30 # Set up an echo that doesn't newline-terminate
31 if test x`echo -n` = x-n; then
32     echo_n () {
33         echo "$@"'\c'
34     }
35 else
36     echo_n () {
37         echo -n "$@"
38     }
39 fi
40
41 # Debugging notices, enabled only if $DEBUG has something in it
42 if test x"$DEBUG" = x; then
43     deb () {
44         :
45     }
46     deb_n () {
47         :
48     }
49 else
50     deb () {
51         echo "$@"
52     }
53     deb_n () {
54         echo_n "$@"
55     }
56 fi
57
58 # Get base directory; first step, how were we called?
59 case $0 in
60 */*)
61     basedir=`echo $0 | sed -e 's@/[^/]*@@g'`
62     ;;
63
64 *)
65     basedir=`pwd`
66     ;;
67 esac
68
69 # Now locate the ircd subdirectory
70 if test -d $basedir/ircd; then
71     :
72 elif test -d $basedir/../ircd; then
73     basedir=$basedir/..
74 elif test -d ./ircd; then
75     basedir=`pwd`
76 else
77     echo "Cannot find base ircd directory!" >&2
78     exit 1
79 fi
80
81 # Finally, canonicalize it
82 cwd=`pwd`
83 cd $basedir
84 basedir=`pwd`
85 cd $cwd
86
87 deb "Base directory: $basedir"
88
89 # This is where our ./configure-parsable results will go
90 cache_file=$basedir/config.cache
91
92 # Now locate .config and config.cache
93 config_in=
94 config_cache_in=
95
96 # If the config subdirectory isn't there anymore, don't bother checking there
97 if test -d $basedir/config; then
98     if test -r $basedir/config/.config; then
99         config_in=$basedir/config/.config
100     fi
101
102     if test -r $basedir/config/config.cache; then
103         config_cache_in=$basedir/config/config.cache
104     fi
105 fi
106
107 # Last ditch effort...try ../.config
108 if test x"$config_in" = x; then
109     if test -r $basedir/../.config; then
110         config_in=$basedir/../.config
111     else
112         echo "Cannot find original .config file!" >&2
113         exit 2
114     fi
115 fi
116
117 # Last ditch effort...try ../.config.cache
118 if test x"$config_cache_in" = x; then
119     if test -r $basedir/../.config.cache; then
120         config_cache_in=$basedir/../.config.cache
121     else
122         echo "Cannot find original config.cache file!" >&2
123         exit 3
124     fi
125 fi
126
127 # Now load the two data files
128 echo "Loading old config.cache file $config_cache_in"
129 . $config_cache_in
130 echo "Loading old .config file $config_in"
131 . $config_in
132
133 # Now we have to track down the defaults so we will know what to generate
134 # F-lines for
135 if test ! -r $basedir/ircd/ircd_features.c; then
136     echo "Cannot find default features!" >&2
137     exit 4
138 fi
139
140 echo_n "Loading feature default values; please be patient... "
141 deb ""
142 features=
143 exec 4<$basedir/ircd/ircd_features.c
144 while read line <&4; do
145     # if a line has '(' but not ')', then we hang them until we find the
146     # matching ')'; this is not robust!
147     if test x"$hangline" != x; then
148         line="$hangline $line"
149         hangline=
150     fi
151
152     if test x"`echo "$line" | grep '(' 2>/dev/null`" != x -a \
153             x"`echo "$line" | grep ')' 2>/dev/null`" = x; then
154         hangline=$line
155         continue
156     fi
157
158     # Now we process the line we read...
159     case $line in
160     \#*) # We want to ignore the #define, since it's a false positive
161         ;;
162
163     F_[NIBS]*) # Found one of the feature define macros
164         type=`echo "$line" | sed -e 's/^F_\([NIBS]\).*$/\1/g'`
165         arglist=`echo "$line" | sed -e 's/^F_[NIBS](\(.*\)),.*/\1/g' \
166                  -e 's/ | /|/g'`
167
168         # Now we must parse the arguments
169         tIFS=$IFS
170         IFS=,$IFS
171         name=
172         value=
173         argnum=0
174         for arg in $arglist; do
175             case $type$argnum in
176                 [NIBS]0) # First argument is always the name of the feature
177                     name=$arg
178                     ;;
179
180                 I2) # Second argument of F_I() is the numerical value
181                     value=$arg
182                     ;;
183
184                 B2) # Second argument of F_B() is a numerical value
185                     # We must convert this numerical value to "y" or "n"
186                     if test x"$arg" = x0; then
187                         value=n
188                     else
189                         value=y
190                     fi
191                     ;;
192
193                 [ST]2) # Second argument of F_S() is a string value; must
194                        # take into account unquoted possibilities, though
195                     dequote=`echo "$arg" | sed -e 's/^"\(.*\)"$/\1/g'`
196                     if test x"$dequote" = x"$arg"; then
197                         type=T
198                         value=$arg
199                     else
200                         value=$dequote
201                     fi
202                     ;;
203             esac
204
205             # Next time through, we'll be testing the next argument
206             argnum=`expr $argnum + 1`
207         done
208         IFS=$tIFS
209
210         deb "Loaded feature \"$name\" of type \"$type\"; default: \"$value\""
211
212         # Store the information we extracted
213         setvar type_$name $type
214         setvar def_$name "$value"
215
216         # Keep a list of features we've checked
217         features="$features $name"
218         ;;
219     esac
220 done
221 exec 4<&-
222 echo "done"
223
224 echo "Converting some options that are still compile-time"
225
226 unet_cv_prefix=`echo $SPATH | sed -e 's@/bin/ircd@@g'`
227 deb "Installation directory (derived from SPATH)... $unet_cv_prefix"
228
229 deb_n "Enable debugging (DEBUGMODE)... "
230 if test x"$DEBUGMODE" = xy; then
231     unet_cv_enable_debug=yes
232 else
233     unet_cv_enable_debug=no
234 fi
235 deb "$unet_cv_enable_debug"
236
237 deb_n "Enable assertion checking (CONFIG_NDEBUG)... "
238 if test x"$CONFIG_NDEBUG" = xy; then
239     unet_cv_enable_asserts=yes
240 else
241     unet_cv_enable_asserts=no
242 fi
243 deb "$unet_cv_enable_asserts"
244
245 deb_n "Force inlining of some critical functions (FORCEINLINE)... "
246 if test x"$FORCEINLINE" = xy; then
247     unet_cv_enable_inlines=yes
248 else
249     unet_cv_enable_inlines=no
250 fi
251 deb "$unet_cv_enable_inlines"
252
253 unet_cv_with_symlink=$SYMLINK
254 deb "Symlink name (SYMLINK)... $unet_cv_with_symlink"
255
256 unet_cv_with_mode=$IRCDMODE
257 deb "Binary permissions (IRCDMODE)... $unet_cv_with_mode"
258
259 unet_cv_with_owner=$IRCDOWN
260 deb "Binary owner (IRCDOWN)... $unet_cv_with_owner"
261
262 unet_cv_with_group=$IRCDGRP
263 deb "Binary group owner (IRCDGRP)... $unet_cv_with_group"
264
265 unet_cv_with_domain=$DOMAINNAME
266 deb "Local domain name (DOMAINNAME)... $unet_cv_with_domain"
267
268 deb_n "Enable CHROOT operation (CHROOTDIR)... "
269 if test x"$CHROOTDIR" = xy; then
270     deb_n "yes, path "
271     unet_cv_with_chroot=$DPATH
272 else
273     unet_cv_with_chroot=no
274 fi
275 deb "$unet_cv_with_chroot"
276
277 unet_cv_with_dpath=$DPATH
278 deb "Data path (DPATH)... $unet_cv_with_dpath"
279
280 unet_cv_with_cpath=$CPATH
281 deb "Configuration file (CPATH)... $unet_cv_with_cpath"
282
283 # LPATH may not be set; if it's not, we'll just ignore it here and let
284 # ./configure fill it in appropriately
285 if test x"$LPATH" != x; then
286     unet_cv_with_lpath=$LPATH
287     deb "Debug log file (LPATH)... $unet_cv_with_lpath"
288 fi
289
290 unet_cv_with_maxcon=$MAXCONNECTIONS
291 deb "Maximum number of connections (MAXCONNECTIONS)... $unet_cv_with_maxcon"
292
293 # Shouldn't run ./configure before the transition script, but we can deal
294 if test -r "$cache_file"; then
295     echo "WARNING: Destroying new config.cache file $cache_file" >&2
296     rm $cache_file
297 fi
298
299 # Create the cache file...
300 echo "Creating new config.cache file $cache_file"
301 > $cache_file
302
303 # This section is copied from a GNU autoconf-generated configure script
304 ###############################################################################
305 cat > confcache <<\EOF
306 # This file is a shell script that caches the results of configure
307 # tests run on this system so they can be shared between configure
308 # scripts and configure runs.  It is not useful on other systems.
309 # If it contains results you don't want to keep, you may remove or edit it.
310 #
311 # By default, configure uses ./config.cache as the cache file,
312 # creating it if it does not exist already.  You can give configure
313 # the --cache-file=FILE option to use a different cache file; that is
314 # what configure does when it calls configure scripts in
315 # subdirectories, so they share the cache.
316 # Giving --cache-file=/dev/null disables caching, for debugging configure.
317 # config.status only pays attention to the cache file if you give it the
318 # --recheck option to rerun configure.
319 #
320 EOF
321 # The following way of writing the cache mishandles newlines in values,
322 # but we know of no workaround that is simple, portable, and efficient.
323 # So, don't put newlines in cache variables' values.
324 # Ultrix sh set writes to stderr and can't be redirected directly,
325 # and sets the high bit in the cache file unless we assign to the vars.
326 (set) 2>&1 |
327   case `(ac_space=' '; set | grep ac_space) 2>&1` in
328   *ac_space=\ *)
329     # `set' does not quote correctly, so add quotes (double-quote substitution
330     # turns \\\\ into \\, and sed turns \\ into \).
331     sed -n \
332       -e "s/'/'\\\\''/g" \
333       -e "s/^\\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\\)=\\(.*\\)/\\1=\${\\1='\\2'}/p"
334     ;;
335   *)
336     # `set' quotes correctly as required by POSIX, so do not add quotes.
337     sed -n -e 's/^\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\)=\(.*\)/\1=${\1=\2}/p'
338     ;;
339   esac >> confcache
340 if cmp -s $cache_file confcache; then
341   :
342 else
343   if test -w $cache_file; then
344     echo "updating cache $cache_file"
345     cat confcache > $cache_file
346   else
347     echo "not updating unwritable cache $cache_file"
348   fi
349 fi
350 rm -f confcache
351 ###############################################################################
352
353 # If they ran ./configure before, there'll be a config.status hanging around;
354 # if so, we can run that to integrate the config.cache we just generated.
355 if test -x $basedir/config.status; then
356     echo "Running $basedir/config.status to update configuration"
357     cwd=`pwd`
358     cd $basedir
359     # Have to run it twice to get the Makefile recreated
360     ./config.status --recheck
361     ./config.status
362     cd $cwd
363 fi
364
365 # Now we need to track down ircd.conf so we can add the F-lines.
366 echo_n "Locating IRCD configuration file... "
367 case $unet_cv_with_cpath in
368 /*) # CPATH is absolute
369     conf_file=$unet_cv_with_cpath
370     ;;
371
372 *) # CPATH is relative to DPATH
373     conf_file=$unet_cv_with_dpath/$unet_cv_with_cpath
374     ;;
375 esac
376 # suppress duplicate '/'
377 conf_file=`echo "$conf_file" | sed -e 's@//*@/@g'`
378 echo "$conf_file"
379
380 # if we can't find the .conf, use "flines.conf" in the base directory (so
381 # they'll be easy to find).
382 if test ! -r $conf_file; then
383     fline_conf=yes
384     conf_file=$basedir/flines.conf
385     if test ! -r $conf_file; then
386         > $conf_file
387     fi
388     echo "WARNING: Unable to read ircd.conf; you will need to add the" >&2
389     echo "         F-lines manually.  For your convenience, they will be" >&2
390     echo "         placed in $conf_file." >&2
391 fi
392
393 # here's where we take the old .config and compare it to the feature defaults
394 echo_n "Building feature table... "
395 for feature in $features; do
396     defval=`getvar def_$feature`
397     value=`getvar $feature`
398
399     if test x"$value" = x -o x"$value" = x"$defval"; then
400         setvar FEAT_$feature $defval
401     else
402         setvar FEAT_$feature $value
403     fi
404 done
405
406 # We won't add an F-line for DOMAINNAME, since (hopefully) the right one is
407 # already compiled in
408 FEAT_DOMAINNAME=DOMAINNAME
409
410 # Have to make sure we have a RANDOM_SEED to enhance randomness...
411 FEAT_RANDOM_SEED=$RANDOM_SEED
412
413 # This feature changed names to be consistent...
414 FEAT_OPER_LBADCHAN=$LOCAL_BADCHAN
415
416 # DEFAULT_LIST_PARAM is perhaps the most complicated to transition, but
417 # this'll do the trick...
418 if test x"$CONFIG_LIST" = xy; then
419     FEAT_DEFAULT_LIST_PARAM=$DEFAULT_LIST_PARAM
420 else
421     FEAT_DEFAULT_LIST_PARAM=0
422 fi
423
424 echo "done"
425
426 # Now we just generate the F-lines
427 echo_n "Generating F-lines... "
428 exec 4>>$conf_file
429
430 # The various log files are set up first--these are all that were defined
431 # in u2.10.10.pl15
432 if test x"$CONFIG_LOG_WHOX" = xy; then
433     echo "F:LOG:WHO:FILE:$WPATH" >&4
434 fi
435 if test x"$CONFIG_LOG_GLINES" = xy; then
436     echo "F:LOG:GLINE:FILE:$GPATH" >&4
437 fi
438 if test x"$CONFIG_LOG_USERS" = xy; then
439     echo "F:LOG:USER:FILE:$FNAME_USERLOG" >&4
440 fi
441 if test x"$CONFIG_LOG_OPERS" = xy; then
442     echo "F:LOG:OPER:FILE:$FNAME_OPERLOG" >&4
443 fi
444
445 # Now we traverse the entire feature table and compare values with their
446 # defaults
447 for feature in $features; do
448     type=`getvar type_$feature`
449     defval=`getvar def_$feature`
450     value=`getvar FEAT_$feature`
451
452     if test x"$defval" != x"$value"; then
453         if test x"$type" = xB; then
454             # Must map booleans yet again; I prefer TRUE/FALSE
455             if test x"$value" = xy; then
456                 value=TRUE
457             else
458                 value=FALSE
459             fi
460         fi
461
462         # Write the F-line
463         echo "F:$feature:$value" >&4
464     fi
465 done
466 exec 4>&-
467 echo "done"
468
469 echo_n "Transition is complete."
470 if test ! -r $basedir/config.status; then
471     echo_n "  You should now run ./configure."
472 fi
473
474 echo ""
475
476 if test x"$fline_conf" = xyes; then
477     echo "Don't forget to add the F-lines to your ircd.conf.  They can be"
478     echo "found in $conf_file."
479 else
480     echo "Don't forget to verify the F-lines in your ircd.conf!"
481 fi