-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path:mkcmd
313 lines (306 loc) · 9.56 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
# Copyright (c) 1984 AT&T
# All Rights Reserved
# THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
# The copyright notice above does not evidence any
# actual or intended publication of such source code.
#ident "@(#)mk::mkcmd 1.28"
#
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
else
AS=as export AS
CC=cc export CC
LD=ld export LD
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"
(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=
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:-$noshlibs}
rootlibs=${ROOTLIBS:-$noshlibs}
fi
ldflags=
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
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 CMD="$MAKE -b -f $B.mk ARGS=\"${ARGS}\" SYMLINK='$symlink' SHLIBS='$shlibs' NOSHLIBS='$noshlibs' PERFLIBS='$perflibs' ROOTLIBS='$rootlibs' IFLAG=\"$iflag\" FFLAG=\"$fflag\" install"
if [ "$ldflags" ]
then CMD="$CMD LDFLAGS='$ldflags'"
fi
echo "$CMD"
if eval $CMD
then ret=0
else ret=1
fi
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)
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