OSDN Git Service

Fix no pic
[uclinux-h8/uClinux-dist.git] / user / net-tools / configure.sh
1 #!/usr/bin/env 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 # set up reading of config file
47 if [ "$#" != "1" ] || [ ! -f "$1" ]; then
48         echo "usage: $0 configfile" 1>&2
49         exit 1
50 fi
51 exec 7<$1
52 config_fd_redir='<&7'
53
54 #
55 # readln reads a line into $ans.
56 #
57 #       readln prompt default
58 #
59 function readln()
60 {
61   echo -n "$1"
62   IFS='@' read ans || exit 1
63   [ -z "$ans" ] && ans=$2
64 }
65
66 # bool processes a boolean argument
67 #
68 #       bool tail
69 #
70 function bool()
71 {
72   # Slimier hack to get bash to rescan a line.
73   eval "set -- $1"
74   ans=""
75   while [ "$ans" != "y" -a "$ans" != "n" ]
76   do
77         readln "$1 ($2) [$3] " "$3"
78   done
79   if [ "$ans" = "y" ]; then
80         echo "#define $2 1" >>${CONFIG}
81         echo "$2=1" >>${MAKECONFIG}
82     else
83         echo "#define $2 0" >>${CONFIG}
84         echo "# $2=0" >> ${MAKECONFIG}
85   fi
86   raw_input_line="bool '$1' $2 $ans"
87   eval "$2=$ans"
88 }
89
90 # int processes an integer argument
91 #
92 #       int tail
93 #
94 function int()
95 {
96   # Slimier hack to get bash to rescan a line.
97   eval "set -- $1"
98   ans="x"
99   while [ $[$ans+0] != "$ans" ];
100   do
101         readln "$1 ($2) [$3] " "$3"
102   done
103   echo "#define $2 ($ans)" >>${CONFIG}
104   raw_input_line="int '$1' $2 $ans"
105   eval "$2=$ans"
106 }
107
108   #
109   # Make sure we start out with a clean slate.
110   #
111   > config.new
112   > ${CONFIG}
113   > ${MAKECONFIG}
114
115   stack=''
116   branch='t'
117
118   while IFS='@' eval read raw_input_line ${config_fd_redir}
119   do
120         # Slimy hack to get bash to rescan a line.
121         read cmd rest <<-END_OF_COMMAND
122                 $raw_input_line
123         END_OF_COMMAND
124
125         if [ "$cmd" = "*" ]; then
126                 if [ "$branch" = "t" ]; then
127                         echo "$raw_input_line"
128                         # echo "# $rest" >>$CONFIG
129                         if [ "$prevcmd" != "*" ]; then
130                                 echo >>${CONFIG}
131                                 echo "/* $rest" >>${CONFIG}
132                         else
133                                 echo " * $rest" >>${CONFIG}
134                         fi
135                         prevcmd="*"
136                 fi
137         else
138                 [ "$prevcmd" = "*" ] && echo " */" >>${CONFIG}
139                 prevcmd=""
140                 case "$cmd" in
141                 =)      [ "$branch" = "t" ] && echo "$rest" >>${CONFIG};;
142                 :)      [ "$branch" = "t" ] && echo "$raw_input_line" ;;
143                 int)    [ "$branch" = "t" ] && int "$rest" ;;
144                 bool)   [ "$branch" = "t" ] && bool "$rest" ;;
145                 exec)   [ "$branch" = "t" ] && ( sh -c "$rest" ) ;;
146                 if)     stack="$branch $stack"
147                         if [ "$branch" = "t" ] && eval "$rest"; then
148                                 branch=t
149                         else
150                                 branch=f
151                         fi ;;
152                 else)   if [ "$branch" = "t" ]; then
153                                 branch=f
154                         else
155                                 read branch rest <<-END_OF_STACK
156                                         $stack
157                                 END_OF_STACK
158                         fi ;;
159                 fi)     [ -z "$stack" ] && echo "Error!  Extra fi." 1>&2
160                         read branch stack <<-END_OF_STACK
161                                 $stack
162                         END_OF_STACK
163                         ;;
164                 esac
165         fi
166         echo "$raw_input_line" >>config.new
167   done
168   [ "$prevcmd" = "*" ] && echo " */" >>${CONFIG}
169
170   [ -z "$stack" ] || echo "Error!  Unterminated if." 1>&2
171
172   mv config.new config.status
173   exit 0