-
Notifications
You must be signed in to change notification settings - Fork 2
/
:mkcmd
executable file
·289 lines (271 loc) · 5.67 KB
/
:mkcmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
CLEAN="rm -f *.o"
asource=$source
places=${places-/etc/places}
if test ! -r /bin/vax -o ! -r /bin/pdp11
then
echo 'Link /bin/vax to /bin/true or /bin/false,'
echo 'and /bin/pdp11 to /bin/true or /bin/false.'
echo 'Then try again'
exit 1
fi
if [ -r $places ]
then
. $places
else
SRC=${SRC-/usr/src}
LSRC=${LSRC-/usr/lsrc}
BIN=${BIN-/bin}
UBIN=${UBIN-/usr/bin}
LBIN=${LBIN-/usr/lbin}
fi
LDFILE=${LDFILE-${SRC}/ldflags}
cd ${SRC}/cmd
arguments=$*
pflag=
ldflags=
for A in $*
do
case $A in
-y) yflag=-y
;;
-f) fflag=FFLAG=-f
;;
-s) sflag=-s
yaccrm=YACCRM=:
iflag=IFLAG=
;;
-p) pflag=-p
command="sed -e 's/-p //'"
arguments=`echo $arguments | eval $command`
command=
;;
esac
done
for A in $arguments
do(
if [ x$A = x-s -o x$A = x-y -o x$A = x-f ]
then
continue
fi
if [ $asource ]
then source=$asource
elif [ -f ${LSRC}/cmd/$A -o -d ${LSRC}/cmd/$A ]
then source=$LSRC
else source=$SRC
fi
cd ${source}/cmd
NAME= TEST=./
B=`echo $A ^ sed -e 's/.*\///' `
echo ======== $B
i=$B
if [ -d $B ]
then echo "******** directory $B"
else B=`echo $i | sed -e 's/\(.*\)\..*/\1/'`
if [ -f $B.mk -o -f $LSRC/cmd/$B.mk ]
then i=$B.mk
elif [ -f $B.rc -o -f $LSRC/cmd/$B.rc ]
then i=$B.rc
elif [ -f $B.c -o -f $LSRC/cmd/$B.c ]
then i=$B.c
elif [ -f $B.y -o -f $LSRC/cmd/$B.y ]
then i=$B.y
elif [ -f $B.l -o -f $LSRC/cmd/$B.l ]
then i=$B.l
elif [ -f $B.s -o -f $LSRC/cmd/$B.s ]
then i=$B.s
elif [ -f $B.sh -o -f $LSRC/cmd/$B.sh ]
then i=$B.sh
elif [ -f $B.ex -o -f $LSRC/cmd/$B.ex ]
then i=$B.ex
elif [ -f $B.o -o -f $LSRC/cmd/$B.o ]
then rm -f $B.o
fi
fi
if [ $source = $SRC -a -f ${LSRC}/cmd/$i ]
then source=$LSRC
cd ${source}/cmd
fi
case $i in
*.mk)
command="sed -e 's/$B //'"
if [ -r ${LDFILE} ]
then ldflags=`eval grep "'^$B '" $LDFILE`
fi
ldflags=`echo $ldflags | eval $command`
if [ x$sflag = x-s ]
then
command="sed -e 's/-i//'"
ldflags=`echo $ldflags | eval $command`
else
command="sed -e 's/-f//'"
ldflags=`echo $ldflags | eval $command`
if [ `expr x$ldflags : '.*-i'` != 0 ]
then
command="sed -e 's/-n//'"
ldflags=`echo $ldflags | eval $command`
fi
fi
COMP="make -b -f $B.mk $iflag $fflag install"
if [ "x$ldflags" != x ]
then COMP="$COMP LDFLAGS='$ldflags'"
fi
COMP="$COMP && make -b -f $B.mk $iflag $yaccrm clobber"
echo $COMP
eval $COMP
;;
*.rc) sh -x ${i}
;;
*.y) if [ x$sflag != x-s -o x$yflag = x-y ]
then
echo yacc $i
if yacc $i
then echo mv y.tab.c ${B}.c
mv y.tab.c ${B}.c
lib=-ly places=$places LDFILE=$LDFILE ${SRC}/:mkcmd $sflag $yflag ${B}.c
else echo "yacc failed"
fi
if [ x$sflag != x-s ]
then
rm -f ${B}.c
else
mv ${B}.c ${B}.x
fi
else
mv ${B}.x ${B}.c
lib=-ly places=$places LDFILE=$LDFILE ${SRC}/:mkcmd $sflag $yflag ${B}.c
mv ${B}.c ${B}.x
fi
;;
*.l) if [ x$sflag != x-s -o x$yflag = x-y ]
then
echo lex $i
if lex $i
then echo mv lex.yy.c ${B}.c
mv lex.yy.c ${B}.c
lib=-ll places=$places LDFILE=$LDFILE ${SRC}/:mkcmd $sflag $yflag ${B}.c
else echo "lex failed"
fi
if [ x$sflag != x-s ]
then
rm -f ${B}.c
else
mv ${B}.c ${B}.x
fi
else
mv ${B}.x ${B}.c
lib=-ll places=$places LDFILE=$LDFILE ${SRC}/:mkcmd $sflag $yflag ${B}.c
mv ${B}.c ${B}.x
fi
;;
*.x)
:
;;
*.c)
command="sed -e 's/$B //'"
if [ -r ${LDFILE} ]
then ldflags=`eval grep "'^$B '" $LDFILE`
fi
ldflags=`echo $ldflags | eval $command`
if [ x$fflag = x ]
then
command="sed -e 's/-f//'"
ldflags=`echo $ldflags | eval $command`
fi
if [ x$sflag = x-s ]
then
command="sed -e 's/-i//'"
ldflags=`echo $ldflags | eval $command`
else
if [ `expr "x$ldflags" : '.*-i'` != 0 ]
then
command="sed -e 's/-n//'"
ldflags=`echo $ldflags | eval $command`
fi
fi
COMP="cc -O $ldflags -s $i -o $TEST$B $lib"
echo $COMP
if eval $COMP
then
NAME=$B
else echo $B: cc failed
rm -f $B
fi
lib=
;;
*.s) echo "as -o $TEST$B.o /usr/include/sys.s $i && ld -s -o $TEST$B $TEST$B.o"
if as -o $TEST$B.o /usr/include/sys.s $i && ld -s -o $TEST$B $TEST$B.o
then NAME=$B
else echo $B: as failed
fi
rm -f $TEST$B.o
;;
*.ex) echo "$i is merely a sample."
echo "You should use it as a prototype for your own current situation"
continue
;;
*.sh) echo cp $i $B
if cp $i $B
then NAME=$B
else echo $B: cp failed
fi
;;
*.o) rm -f $i
continue
;;
*) NAME= TEST=
command="sed -e 's/$i //'"
if [ -r ${LDFILE} ]
then ldflags=`eval grep "'^$i '" $LDFILE`
fi;
ldflags=`echo $ldflags | eval $command`
if [ x$sflag = x-s ]
then
command="sed -e 's/-i//'"
ldflags=`echo $ldflags | eval $command`
else
command="sed -e 's/-f//'"
ldflags=`echo $ldflags | eval $command`
if [ `expr x$ldflags : '.*-i'` != 0 ]
then
command="sed -e 's/-n//'"
ldflags=`echo $ldflags | eval $command`
fi
fi
if [ -d $i ]
then echo cd $i
cd $i
if [ -f ${i}.mk ]
then
COMP="make -b -f ${i}.mk ARGS=\"${ARGS}\" $iflag $fflag install"
if [ "x$ldflags" != x ]
then COMP="$COMP LDFLAGS='$ldflags'"
fi
echo $COMP
if eval $COMP
then make -b -f ${i}.mk $iflag $fflag $yaccrm clobber
else echo MAKE ERROR
fi
elif [ -f ${i}.rc ]
then sh -x ${i}.rc
else echo XXXXXXXX Do Not Know How to MAKE $B
fi
$CLEAN
else echo "XXXXXXXX Cannot make $B"
fi
esac
: Install binary just made in appropriate bin
case $NAME in
"") :
;;
*)
cd $TEST
if [ $source = $LSRC ]
then echo /etc/install -n ${LBIN} $NAME
/etc/install -n ${LBIN} $NAME
else echo /etc/install -n ${UBIN} $NAME
/etc/install -n ${UBIN} $NAME
fi
rm -f $NAME
;;
esac
);done