-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path:mkcmd
426 lines (405 loc) · 12.4 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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
#ident "@(#)mk::mkcmd 1.31"
if i386
then
echo
echo
echo
echo " Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T"
echo " All Rights Reserved"
echo
echo " THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T"
echo " The copyright notice above does not evidence any actual or"
echo " intended publication of such source code."
echo
echo " Copyright (c) 1987, 1988 Microsoft Corporation"
echo " All Rights Reserved"
echo
echo " This Module contains Proprietary Information of Microsoft"
echo " Corporation and should be treated as Confidential."
echo
echo
echo
echo $0 started at `date`
fi
MAKE=${MAKE:-make}
CLOBBER=${CLOBBER:-"ON"}
# If we are in a cross compilation environment then use cross compiler
if [ "$ROOT" != "" ]
then
if u3b2 || u3b15
then
AS=m32as export AS
CC=m32cc export CC
LD=m32ld export LD
fi
if i386
then
AS=i386as export AS
CC=i386cc export CC
LD=i386ld export LD
fi
else
AS=as export AS
CC=cc export CC
LD=ld export LD
fi
if i386
then
if [ ! -d $ROOT/etc ] ; then mkdir $ROOT/etc ; fi
if [ ! -d $ROOT/etc/default ] ; then mkdir $ROOT/etc/default ; fi
if [ ! -d $ROOT/etc/cron.d ] ; then mkdir $ROOT/etc/cron.d ; fi
if [ ! -d $ROOT/usr/bin ] ; then mkdir $ROOT/usr/bin ; fi
if [ ! -d $ROOT/usr/sbin ] ; then mkdir $ROOT/usr/sbin ; fi
if [ ! -d $ROOT/sbin ] ; then mkdir $ROOT/sbin ; fi
if [ ! -d $ROOT/var ] ; then mkdir $ROOT/var ; fi
if [ ! -d $ROOT/var/spool ] ; then mkdir $ROOT/var/spool ; fi
if [ ! -d $ROOT/usr/lbin ]; then mkdir $ROOT/usr/lbin; fi
if [ ! -d $ROOT/usr/ucb ]; then mkdir $ROOT/usr/ucb; fi
if [ ! -d $ROOT/usr/share ]; then mkdir $ROOT/usr/share; fi
if [ ! -d $ROOT/usr/share/lib ]; then mkdir $ROOT/usr/share/lib; fi
if [ ! -d $ROOT/usr/lib/class ]; then mkdir $ROOT/usr/lib/class; fi
if [ ! -d $ROOT/usr/lib/fs ]; then mkdir $ROOT/usr/lib/fs; fi
if [ ! -d $ROOT/etc/fs ]; then mkdir $ROOT/etc/fs; fi
fi
# Insure that only one machine type is valid
# Note: the redirection is needed to handle the possibility
# of a nonexistent file in the $MACH machine list
MACH="vax pdp11 u3b2 u3b u3b15 i386"
(truecnt=0
for mach in $MACH
do
`$mach`
if [ $? -eq 0 ]
then
truecnt=`expr $truecnt + 1`
fi
done
if [ $truecnt -ne 1 ]
then
echo ":mkcmd: **** Only one of the following machine types can"
echo " be true: $MACH"
exit 1
fi ) 2>/dev/null
#
places=${places-$ROOT/etc/places}
if [ -r $places ]
then
. $places
else
SRC=${SRC-$ROOT/usr/src}
LSRC=${LSRC-$ROOT/usr/lsrc}
BIN=${BIN-$ROOT/bin}
UBIN=${UBIN-$ROOT/usr/bin}
LBIN=${LBIN-$ROOT/usr/lbin}
fi
LDFILE=${LDFILE-${SRC}/ldflags}
# Initialize default flag values:
# fflag - controls the FFLAG varible. It is set to either null
# (use hardware floating point) or '-f' (use software
# simulation floating point).
# sflag - shared text, turns off the -i and -n loader options.
# Saves the intermediate .c file from a yacc or lex in
# <filename>.x for later :mkcmd runs.
# ldlibs - shared library flag. It is either "-lnsl_s" (build w/the
# shared libnsl_s.a) or "-lc_s -lnsl_s" (build w/both
# shared libc_s.a and libnsl_s.a). Default is both.
# iflag - seperate I&D space. It is either set to '-i' (when building
# certain commands on a 16-bit machine (e.g. PDP11/70)
# or null (for all other cases).
# symlink -variable to pass symbolic links to makefiles
fflag=
sflag=
iflag=
CCSTYPE=${CCSTYPE:-ELF}; export CCSTYPE
if [ x$CCSTYPE = xCOFF ]
then
shlibs=${SHLIBS:-"-lc_s"}
noshlibs=${NOSHLIBS:-""}
perflibs=${PERFLIBS:-$shlibs}
rootlibs=${ROOTLIBS:-$shlibs}
else
shlibs=${SHLIBS:-""}
noshlibs=${NOSHLIBS:-"-dn"}
perflibs=${PERFLIBS:-$shlibs}
rootlibs=${ROOTLIBS:-$noshlibs}
fi
ldflags=
if [ "$SYMLINK" = "" ]
then
RELEASE=`uname -r | cut -c1-3`
if [ $RELEASE -lt 4.0 ]
then
SYMLINK=":"
fi
fi
symlink=${SYMLINK:-"ln -s"}
for opt in $*
do
case $opt in
-f) fflag="-f"
;;
-s) sflag=-s
yaccrm="YACCRM=:"
iflag=
;;
-*) echo ":mkcmd; **** unknown option '$opt' - ignored"
;;
*) break
;;
esac
shift
done
#
# Process remaining arguments as source that needs to be built.
# The three interesting variables are:
# B - basename of each argument
# BASE - basename of each option with its dot suffix removed
# OBJ - file to be installed if the build is successful
#
cd $SRC/cmd
if i386
then
#
# check out the BUS type.
BTYPE="BUS=AT386"
ATYPE="ARCH=AT386"
VPIX=-DVPIX;
MERGE386=-DMERGE386;
while [ $# -ge 1 ]
do
case "$1" in
BUS*) BTYPE="$1"; shift;;
ARC*) ATYPE="$1"; shift;;
vpix|VPIX) VPIX=-DVPIX; shift;;
novpix|NOVPIX) VPIX=""; shift;;
merge386|MERGE386) MERGE386=-DMERGE386; shift;;
nomerge386|NOMERGE386) MERGE386=""; shift;;
*) break;;
esac
done
DFLGS="$VPIX $MERGE386"; export DFLGS
export BTYPE ATYPE
#
# for now, just always make libcmd.a
#
if [ "$ldflags" ]
then CMD="$CMD LDFLAGS='$ldflags'"
fi
echo "$CMD"
if eval $CMD
then ret=0
else ret=1
fi
if [ $ret -ne 0 ]
then echo "**** Build of libcmd failed ($MAKE)"
fi
cd ..
fi
arguments=$*
for arg in $arguments
do(
# Local version takes precedence over official version
if [ -f $LSRC/cmd/$arg -o -d $LSRC/cmd/$arg ]
then source=$LSRC
else source=$SRC
fi
cd ${source}/cmd
OBJ=
B=`basename $arg`
# Is this an aberrant file with its makefile in the $SRC/cmd directory?
# If so then skip this file since it will handled by the makefile
##(not in subdir) case $B in
##(not in subdir) *.c | *.s)
##(not in subdir) b=`basename $B ".[cs]"`
##(not in subdir) if [ -f $b.mk ]
##(not in subdir) then continue
##(not in subdir) fi
##(not in subdir) ;;
##(not in subdir) esac
echo "\n======== $B"
BASE=$B
# if not a directory then remove suffix and determine the file type
##(not in subdir) if [ ! -d $B ]
##(not in subdir) then BASE=`echo $B | sed -e 's/\(.*\)\..*/\1/'`
##(not in subdir) if [ -f ${BASE}.mk -o -f $LSRC/cmd/${BASE}.mk ]
##(not in subdir) then B=${BASE}.mk
##(not in subdir) elif [ -f ${BASE}.rc -o -f $LSRC/cmd/${BASE}.rc ]
##(not in subdir) then B=${BASE}.rc
##(not in subdir) elif [ -f ${BASE}.c -o -f $LSRC/cmd/${BASE}.c ]
##(not in subdir) then B=${BASE}.c
##(not in subdir) elif [ -f ${BASE}.sh -o -f $LSRC/cmd/${BASE}.sh ]
##(not in subdir) then B=${BASE}.sh
##(not in subdir) elif [ -f ${BASE}.y -o -f $LSRC/cmd/${BASE}.y ]
##(not in subdir) then B=${BASE}.y
##(not in subdir) elif [ -f ${BASE}.l -o -f $LSRC/cmd/${BASE}.l ]
##(not in subdir) then B=${BASE}.l
##(not in subdir) elif [ -f ${BASE}.s -o -f $LSRC/cmd/${BASE}.s ]
##(not in subdir) then B=${BASE}.s
##(not in subdir) elif [ -f ${BASE}.o -o -f $LSRC/cmd/${BASE}.o ]
##(not in subdir) then B=${BASE}.o
##(not in subdir) fi
##(not in subdir) fi
#
if [ "$source" = "$SRC" -a -f $LSRC/cmd/$B ]
then source=$LSRC
cd ${source}/cmd
fi
#
if [ -r $LDFILE ]
then ldflags=`grep "^${BASE} " $LDFILE | sed -e "s/${BASE} //"`
if [ -z "$fflag" ]
then ldflags=`echo $ldflags | sed -e 's/-f//'`
fi
if [ "$sflag" = "-s" ]
then ldflags=`echo $ldflags | sed -e 's/-i//'`
else if [ `expr x$ldflags : '.*-i'` != 0 ]
then ldflags=`echo $ldflags | sed -e 's/-n//'`
fi
fi
else ldflags=""
fi
#
# Now build the command according to its file type
##(not in subdir) case $B in
##(not in subdir)
##(not in subdir) *.mk)
##(not in subdir) CMD="$MAKE -b -f ${BASE}.mk LDLIBS='$ldlibs' IFLAG=\"$iflag\" FFLAG=\"$fflag\" install"
##(not in subdir) if [ "$ldflags" ]
##(not in subdir) then CMD="$CMD LDFLAGS='$ldflags'"
##(not in subdir) fi
##(not in subdir) echo "$CMD"
##(not in subdir) if eval $CMD
##(not in subdir) then ret=0
##(not in subdir) else ret=1
##(not in subdir) fi
##(not in subdir) CMD="$MAKE -b -f ${BASE}.mk LDLIBS='$ldlibs' IFLAG=\"$iflag\" FFLAG=\"$fflag\" $yaccrm clobber"
##(not in subdir) test "$CLOBBER" != "OFF" && ( echo "$CMD" ; eval $CMD )
##(not in subdir) if [ $ret -ne 0 ]
##(not in subdir) then echo "**** Build of ${BASE} failed ($MAKE)"
##(not in subdir) fi
##(not in subdir) ;;
##(not in subdir)
##(not in subdir) *.rc) sh -x $B
##(not in subdir) if [ $? -ne 0 ]
##(not in subdir) then echo "**** Build of $B failed (sh)"
##(not in subdir) fi
##(not in subdir) ;;
##(not in subdir)
##(not in subdir) *.c)
##(not in subdir) CMD="$CC -O $ldflags -s -o ./${BASE} $B $lib"
##(not in subdir) echo "$CMD"
##(not in subdir) if eval $CMD
##(not in subdir) then OBJ=${BASE}
##(not in subdir) else echo "**** Build of ${BASE} failed ($CC)"
##(not in subdir) rm -f ./${BASE}.o ./${BASE}
##(not in subdir) fi
##(not in subdir) lib=
##(not in subdir) ;;
##(not in subdir)
##(not in subdir) *.sh) echo "cp $B ${BASE}"
##(not in subdir) if cp $B ${BASE}
##(not in subdir) then OBJ=${BASE}
##(not in subdir) else echo "**** Build of ${BASE} failed (cp)"
##(not in subdir) fi
##(not in subdir) ;;
##(not in subdir)
##(not in subdir) *.s) CMD="$CC -s -o ./${BASE} $B"
##(not in subdir) echo "$CMD"
##(not in subdir) if eval $CMD
##(not in subdir) then OBJ=${BASE}
##(not in subdir) else echo "**** Build of ${BASE} failed ($CC)"
##(not in subdir) rm -f ./${BASE}.o ./{BASE}
##(not in subdir) fi
##(not in subdir) ;;
##(not in subdir)
##(not in subdir) *.y) if [ "$sflag" != "-s" ]
##(not in subdir) then echo "yacc $B"
##(not in subdir) if yacc $B
##(not in subdir) then echo "mv y.tab.c ${BASE}.c"
##(not in subdir) mv y.tab.c ${BASE}.c
##(not in subdir) lib=-ly places=$places LDFILE=$LDFILE sh $SRC/:mkcmd $sflag $fflag ${BASE}.c
##(not in subdir) else echo "**** Build of ${BASE} failed (yacc)"
##(not in subdir) fi
##(not in subdir) rm -f ${BASE}.c
##(not in subdir) else
##(not in subdir) mv ${BASE}.x ${BASE}.c
##(not in subdir) lib=-ly places=$places LDFILE=$LDFILE sh $SRC/:mkcmd $sflag $fflag ${BASE}.c
##(not in subdir) mv ${BASE}.c ${BASE}.x
##(not in subdir) fi
##(not in subdir) ;;
##(not in subdir)
##(not in subdir) *.l) if [ "$sflag" != "-s" ]
##(not in subdir) then echo "lex $B"
##(not in subdir) if lex $B
##(not in subdir) then echo "mv lex.yy.c ${BASE}.c"
##(not in subdir) mv lex.yy.c ${BASE}.c
##(not in subdir) lib=-ll places=$places LDFILE=$LDFILE sh $SRC/:mkcmd $sflag ${BASE}.c
##(not in subdir) else echo "**** Build of ${BASE} failed (lex)"
##(not in subdir) fi
##(not in subdir) rm -f ${BASE}.c
##(not in subdir) else
##(not in subdir) mv ${BASE}.x ${BASE}.c
##(not in subdir) lib=-ll places=$places LDFILE=$LDFILE sh $SRC/:mkcmd $sflag ${BASE}.c
##(not in subdir) mv ${BASE}.c ${BASE}.x
##(not in subdir) fi
##(not in subdir) ;;
##(not in subdir)
##(not in subdir) *.x) continue
##(not in subdir) ;;
##(not in subdir)
##(not in subdir) *.o) rm -f $B
##(not in subdir) ;;
##(not in subdir)
##(not in subdir) *)
if [ -d $B ]
then echo "cd $B"
cd $B
if [ -f $B.mk ]
then
if i386
then CMD="$MAKE -b -f $B.mk ${BTYPE} ${ATYPE} ARGS=\"${ARGS}\" SYMLINK='$symlink' SHLIBS='$shlibs' NOSHLIBS='$noshlibs' PERFLIBS='$perflibs' ROOTLIBS='$rootlibs' IFLAG=\"$iflag\" FFLAG=\"$fflag\" DFLGS=\"${DFLGS}\" install"
else
CMD="$MAKE -b -f $B.mk ARGS=\"${ARGS}\" SYMLINK='$symlink' SHLIBS='$shlibs' NOSHLIBS='$noshlibs' PERFLIBS='$perflibs' ROOTLIBS='$rootlibs' IFLAG=\"$iflag\" FFLAG=\"$fflag\" install"
fi
if [ "$ldflags" ]
then CMD="$CMD LDFLAGS='$ldflags'"
fi
echo "$CMD"
if eval $CMD
then ret=0
else ret=1
fi
if i386
then
CMD="$MAKE -b -f $B.mk ${BTYPE} ${ATYPE} SYMLINK='$symlink' SHLIBS='$shlibs' NOSHLIBS='$noshlibs' PERFLIBS='$perflibs' ROOTLIBS='$rootlibs' IFLAG=\"$iflag\" FFLAG=\"$fflag\" DFLGS=\"${DFLGS}\" $yaccrm clobber"
echo "$CMD"
eval "$CMD"
else
CMD="$MAKE -b -f $B.mk SYMLINK='$symlink' SHLIBS='$shlibs' NOSHLIBS='$noshlibs' PERFLIBS='$perflibs' ROOTLIBS='$rootlibs' IFLAG=\"$iflag\" FFLAG=\"$fflag\" $yaccrm clobber"
test "$CLOBBER" != "OFF" &&
(echo "$CMD" ; eval $CMD)
fi
if [ $ret -ne 0 ]
then echo "**** Build of ${BASE} failed ($MAKE)"
fi
##(not in subdir) elif [ -f $B.rc ]
##(not in subdir) then sh -x $B.rc
else echo "**** Build of $B failed (no makefile found in directory)"
fi
rm -f *.o
else echo ":mkcmd: *** no directory found for $B under $source"
fi
##(not in subdir) esac
#
# If build was successful install new object in appropriate bin
##(not in subdir) if [ -n "$OBJ" ]
##(not in subdir) then
##(not in subdir) if [ "$source" = "$LSRC" ]
##(not in subdir) then echo "install -n $LBIN $OBJ"
##(not in subdir) install -n $LBIN $OBJ
##(not in subdir) else echo "install -n $UBIN $OBJ"
##(not in subdir) install -n $UBIN $OBJ
##(not in subdir) fi
##(not in subdir) rm -f $OBJ
##(not in subdir) fi
);done