Bump version to 1.53
[platform/upstream/net-tools.git] / configure.sh
1 #!/bin/bash
2 #
3 # Configure.sh  Generates interactively a config.h from config.in
4 #
5 # net-tools     A collection of programs that form the base set of the
6 #               NET-3 Networking Distribution for the LINUX operating
7 #               system.
8 #
9 # Usage:        Install.sh [--nobackup] [--test]
10 #
11 # Version:      Install.sh 1.65 (1996-01-12)
12 #
13 # Authors:      Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
14 #               Johannes Grosen, <grosen@argv.cs.ndsu.nodak.edu>
15 #               Copyright 1988-1993 MicroWalt Corporation
16 #
17 # Modified:
18 #        {1.65} Bernd eckes Eckenfels <net-tools@lina.inka.de>
19 #               some layout cleanups, slattach/plipconfig removed.
20 #               --test for testinstallations added.
21 #
22 #               This program is free software; you can redistribute it
23 #               and/or  modify it under  the terms of  the GNU General
24 #               Public  License as  published  by  the  Free  Software
25 #               Foundation;  either  version 2 of the License, or  (at
26 #               your option) any later version.
27 #
28 #
29 # Make sure we're really running bash.
30 #
31 # I would really have preferred to write this script in a language with
32 # better string handling, but alas, bash is the only scripting language
33 # that I can be reasonable sure everybody has on their Linux machine.
34 #
35
36 CONFIG=config.h
37 MAKECONFIG=config.make
38
39
40 [ -z "$BASH" ] && { echo "Configure requires bash" 1>&2; exit 1; }
41
42 # Disable filename globbing once and for all.
43 # Enable function cacheing.
44 set -f -h
45
46 #
47 # readln reads a line into $ans.
48 #
49 #       readln prompt default
50 #
51 function readln()
52 {
53   echo -n "$1"
54   IFS='@' read ans </dev/tty || exit 1
55   [ -z "$ans" ] && ans=$2
56 }
57
58 # bool processes a boolean argument
59 #
60 #       bool tail
61 #
62 function bool()
63 {
64   # Slimier hack to get bash to rescan a line.
65   eval "set -- $1"
66   ans=""
67   while [ "$ans" != "y" -a "$ans" != "n" ]
68   do
69         readln "$1 ($2) [$3] " "$3"
70   done
71   if [ "$ans" = "y" ]; then
72         echo "#define $2 1" >>${CONFIG}
73         echo "$2=1" >>${MAKECONFIG}
74     else
75         echo "#define $2 0" >>${CONFIG}
76         echo "# $2=0" >> ${MAKECONFIG}
77   fi
78   raw_input_line="bool '$1' $2 $ans"
79   eval "$2=$ans"
80 }
81
82 # int processes an integer argument
83 #
84 #       int tail
85 #
86 function int()
87 {
88   # Slimier hack to get bash to rescan a line.
89   eval "set -- $1"
90   ans="x"
91   while [ $[$ans+0] != "$ans" ];
92   do
93         readln "$1 ($2) [$3] " "$3"
94   done
95   echo "#define $2 ($ans)" >>${CONFIG}
96   raw_input_line="int '$1' $2 $ans"
97   eval "$2=$ans"
98 }
99
100   #
101   # Make sure we start out with a clean slate.
102   #
103   > config.new
104   > ${CONFIG}
105   > ${MAKECONFIG}
106
107   stack=''
108   branch='t'
109
110   while IFS='@' read raw_input_line
111   do
112         # Slimy hack to get bash to rescan a line.
113         read cmd rest <<-END_OF_COMMAND
114                 $raw_input_line
115         END_OF_COMMAND
116
117         if [ "$cmd" = "*" ]; then
118                 if [ "$branch" = "t" ]; then
119                         echo "$raw_input_line"
120                         # echo "# $rest" >>$CONFIG
121                         if [ "$prevcmd" != "*" ]; then
122                                 echo >>${CONFIG}
123                                 echo "/* $rest" >>${CONFIG}
124                         else
125                                 echo " * $rest" >>${CONFIG}
126                         fi
127                         prevcmd="*"
128                 fi
129         else
130                 [ "$prevcmd" = "*" ] && echo " */" >>${CONFIG}
131                 prevcmd=""
132                 case "$cmd" in
133                 =)      [ "$branch" = "t" ] && echo "$rest" >>${CONFIG};;
134                 :)      [ "$branch" = "t" ] && echo "$raw_input_line" ;;
135                 int)    [ "$branch" = "t" ] && int "$rest" ;;
136                 bool)   [ "$branch" = "t" ] && bool "$rest" ;;
137                 exec)   [ "$branch" = "t" ] && ( sh -c "$rest" ) ;;
138                 if)     stack="$branch $stack"
139                         if [ "$branch" = "t" ] && eval "$rest"; then
140                                 branch=t
141                         else
142                                 branch=f
143                         fi ;;
144                 else)   if [ "$branch" = "t" ]; then
145                                 branch=f
146                         else
147                                 read branch rest <<-END_OF_STACK
148                                         $stack
149                                 END_OF_STACK
150                         fi ;;
151                 fi)     [ -z "$stack" ] && echo "Error!  Extra fi." 1>&2
152                         read branch stack <<-END_OF_STACK
153                                 $stack
154                         END_OF_STACK
155                         ;;
156                 esac
157         fi
158         echo "$raw_input_line" >>config.new
159   done
160   [ "$prevcmd" = "*" ] && echo " */" >>${CONFIG}
161
162   [ -z "$stack" ] || echo "Error!  Untermiated if." 1>&2
163
164   mv config.new config.status
165   exit 0