xref: /freebsd/contrib/ntp/sntp/scripts/genLocInfo (revision 5f0216bd883edee71bf81051e3c20505e4820903)
1#! /bin/sh
2
3args=`getopt d:f:v $*`
4set -- $args
5
6LF=
7V=": "
8
9for i
10do
11    case "$i" in
12     -d) sdir="$2" ; shift 2 ;;
13     -f) locfile="$2" ; shift 2 ;;
14     -v) V= ; shift ;;
15     --) shift ; break ;;
16    esac
17done
18
19case "$sdir" in
20 '')
21    sdir=.
22esac
23
24case "$locfile" in
25 */*)
26    LF=$locfile
27    ;;
28 '')
29    ;;
30 *)
31    lf=loc/$locfile
32    if test -f $lf
33    then
34	LF=$lf
35    fi
36    ;;
37esac
38
39# If we have a file to use (ie, LF is not empty) then look for one.
40case "$LF" in
41 '')
42    PATH=$PATH:libevent/build-aux
43    export PATH
44    set `scripts/cvo.sh @osname@ @osver@` || exit 1
45
46    CVO_OSNAME=$1
47    CVO_OSVER=$2
48
49    x=$CVO_OSVER
50
51    while true
52    do
53	case "$x" in
54	 '') break ;;
55	esac
56lf=loc/$CVO_OSNAME$x
57${V}echo "Looking for <$lf>" >&2
58	if test -f $lf
59	then
60	    LF=$lf
61	    break
62	fi
63	case "$x" in
64	 *.*) x=`echo $x | sed -e 's/\.[^.]*$//'` ;;
65	 *) x= ;;
66	esac
67    done
68    case "$LF" in
69     '')
70	lf=loc/$CVO_OSNAME
71${V}echo "Looking for <$lf>" >&2
72	if test -f $lf
73	then
74	    LF=$lf
75	fi
76	;;
77    esac
78    # Handle some "aliases"
79    case "$LF" in
80     '')
81	case "$CVO_OSNAME" in
82	 redhat* | fedora*)
83	    lf=loc/redhat
84${V}echo "Looking for <$lf>" >&2
85	    if test -f $lf
86	    then
87		LF=$lf
88	    fi
89	    ;;
90	esac
91	;;
92    esac
93
94    # This might be a good place to see if uname returns "Linux",
95    # and if so, use a generic file for that.
96    case "$LF" in
97     '')
98	case "`uname`" in
99	 Linux)
100	    lf=loc/linux
101${V}echo "Looking for <$lf>" >&2
102	    if test -f $lf
103	    then
104		LF=$lf
105	    fi
106	    ;;
107	esac
108	;;
109    esac
110
111    # Finally, 'legacy'
112    case "$LF" in
113     '')
114	lf=loc/legacy
115${V}echo "Looking for <$lf>" >&2
116	if test -f $lf
117	then
118	    LF=$lf
119	fi
120	;;
121    esac
122
123    case "$LF" in
124     '')
125	echo "No loc/XXX file found!" >&2
126	exit 1
127	;;
128    esac
129    ;;
130esac
131
132${V}echo "Using <$LF>" >&2
133echo "GENLOCINFOFILE=$LF"
134
135###
136
137rm -f $sdir/genLocInfo.rc?
138
139oIFS=$IFS
140IFS=","
141
142while true
143do
144    if read c d s x
145    then
146	# echo "Got <$c><$d><$s><$x>" >&2
147	case "$c" in
148	 \#*) continue ;;
149	esac
150	case "$x" in
151	 '') ;;
152	 *) echo "Unrecognized input: <$c,$d,$s,$x>" >&2
153	    touch $sdir/genLocInfo.rc1
154	    continue
155	    ;;
156	esac
157	case "$c,$d,$s" in
158	 [Mm][Aa][Nn],,)
159	    echo "MANTAGFMT=man"
160	    continue
161	    ;;
162	 [Mm][Dd][Oo][Cc],,)
163	    echo "MANTAGFMT=mdoc"
164	    continue
165	    ;;
166	esac
167
168	case "$c,$d,$s" in
169	 *,bin,*)  DB=bin ; DL= ; DS= ; NI= ;;
170	 *,libexec,*)  DB= ; DL=libexec ; DS= ; NI= ;;
171	 *,noinst,*)  DB= ; DL= ; DS= ; NI=noinst ;;
172	 *,sbin,*) DB= ; DL= ; DS=sbin ; NI= ;;
173	 *) echo "Unrecognized input: <$c,$d,$s>" >&2
174	    touch $sdir/genLocInfo.rc1
175	    continue
176	    ;;
177	esac
178	case "$c,$d,$s" in
179	 *,*,1) ;;
180	 *,*,1m) ;;
181	 *,*,1M) ;;
182	 *,*,8) ;;
183	 *) echo "Unrecognized input: <$c,$d,$s>" >&2
184	    touch $sdir/genLocInfo.rc1
185	    continue
186	    ;;
187	esac
188
189	# Should be OK, mostly...
190	C=`echo $c | sed -e 'y/abcdefghijklmnopqrstuvwxyz-/ABCDEFGHIJKLMNOPQRSTUVWXYZ_/'`
191	# echo "c: <$c>, C: <$C>, DB: <$DB>, DL: <$DL>, DS: <$DS>" >&2
192
193	case "$d" in
194	 bin)
195	    eval ${C}_DB=$c
196	    eval ${C}_DL=
197	    eval ${C}_DS=
198	    eval ${C}_NI=
199	    ;;
200	 libexec)
201	    eval ${C}_DB=
202	    eval ${C}_DL=$c
203	    eval ${C}_DS=
204	    eval ${C}_NI=
205	    ;;
206	 noinst)
207	    eval ${C}_DB=
208	    eval ${C}_DL=
209	    eval ${C}_DS=
210	    eval ${C}_NI=$c
211	    ;;
212	 sbin)
213	    eval ${C}_DB=
214	    eval ${C}_DL=
215	    eval ${C}_DS=$c
216	    eval ${C}_NI=
217	    ;;
218	 *) echo "$0: installdir <$d> must be bin, sbin, libexec, or noinst" >&2
219	    exit 1
220	    ;;
221	esac
222	eval ${C}_MS=$s
223
224	# echo "<$c> gets installed in <$d> with a <$s> manpage suffix" >&2
225	# echo "${C}_DB is <`eval echo '$'${C}_DB`>" >&2
226	# echo "${C}_DL is <`eval echo '$'${C}_DL`>" >&2
227	# echo "${C}_DS is <`eval echo '$'${C}_DS`>" >&2
228	# echo "${C}_NI is <`eval echo '$'${C}_NI`>" >&2
229	# echo "${C}_MS is <`eval echo '$'${C}_MS`>" >&2
230	echo "${C}_DB=`eval echo '$'${C}_DB`"
231	echo "${C}_DL=`eval echo '$'${C}_DL`"
232	echo "${C}_DS=`eval echo '$'${C}_DS`"
233	echo "${C}_NI=`eval echo '$'${C}_NI`"
234	echo "${C}_MS=`eval echo '$'${C}_MS`"
235
236	touch $sdir/genLocInfo.rc0
237    else
238	break
239    fi
240done < $LF
241IFS=$oIFS
242
243if test -f $sdir/genLocInfo.rc1
244then
245    rm $sdir/genLocInfo.rc?
246    exit 1
247fi
248
249if test -f $sdir/genLocInfo.rc0
250then
251    rm $sdir/genLocInfo.rc?
252    echo 'GENLOCINFO=OK'
253    exit 0
254fi
255
256exit 1
257