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