export procnetdev_version, get_dev_fields, get_name from
[oss-qm-packages.git] / configure.sh
blob9859b59024def3ebbacd71a25e7248ab0c97a78d
1 #!/usr/bin/env bash
3 # Configure.sh Generates interactively a config.h from config.in
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.
9 # Usage: Install.sh [--nobackup] [--test]
11 # Version: Install.sh 1.65 (1996-01-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
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.
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.
29 # Make sure we're really running bash.
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.
36 CONFIG=config.h
37 MAKECONFIG=config.make
40 [ -z "$BASH" ] && { echo "Configure requires bash" 1>&2; exit 1; }
42 # Disable filename globbing once and for all.
43 # Enable function cacheing.
44 set -f -h
46 # set up reading of config file
47 if [ "$#" != "1" ] || [ ! -f "$1" ]; then
48 echo "usage: $0 configfile" 1>&2
49 exit 1
51 exec 7<$1
52 config_fd_redir='<&7'
55 # readln reads a line into $ans.
57 # readln prompt default
59 function readln()
61 echo -n "$1"
62 IFS='@' read ans || exit 1
63 [ -z "$ans" ] && ans=$2
66 # bool processes a boolean argument
68 # bool tail
70 function bool()
72 # Slimier hack to get bash to rescan a line.
73 eval "set -- $1"
74 ans=""
75 while [ "$ans" != "y" -a "$ans" != "n" ]
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}
86 raw_input_line="bool '$1' $2 $ans"
87 eval "$2=$ans"
90 # int processes an integer argument
92 # int tail
94 function int()
96 # Slimier hack to get bash to rescan a line.
97 eval "set -- $1"
98 ans="x"
99 while [ $[$ans+0] != "$ans" ];
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"
109 # Make sure we start out with a clean slate.
111 > config.new
112 > ${CONFIG}
113 > ${MAKECONFIG}
115 stack=''
116 branch='t'
118 while IFS='@' eval read raw_input_line ${config_fd_redir}
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
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}
135 prevcmd="*"
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
164 esac
166 echo "$raw_input_line" >>config.new
167 done
168 [ "$prevcmd" = "*" ] && echo " */" >>${CONFIG}
170 [ -z "$stack" ] || echo "Error! Unterminated if." 1>&2
172 mv config.new config.status
173 exit 0