-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathstd2kern
executable file
·294 lines (267 loc) · 5.84 KB
/
std2kern
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
#!/bin/sh
KERNELDIR=/lib/modules/$(uname -r)/build
PREPARSER="./preparser"
UNIQUE=false
VERBOSE=false
NOTEST=true
DODIFF=false
DIFFREV=false
ALLOW_ANY_DIR=true
docp() {
SRCNAME=$1;
if $VERBOSE; then
echo -n "$SRCNAME... "
fi
# special cases
TMPNAME=/tmp/`basename $1`.$$
# Makefiles
BASENAME=`basename $2`;
if [ "$BASENAME" = "Makefile" ]; then
if [ $VERSION -gt 3 -o \( $VERSION -eq 2 -a $PATCHLEVEL -gt 3 \) ]; then
sed -e "s/drivers\/isdn\/Rules\.make/Rules\.make/" < $SRCNAME > $TMPNAME
if $VERBOSE ; then
echo -n "processing... modified..."
fi
SRCNAME=$TMPNAME
fi
fi
# Rules.make
if [ "$BASENAME" = "Rules.make" ]; then
if ! [ $VERSION -gt 3 -o \( $VERSION -eq 2 -a $PATCHLEVEL -gt 3 \) ]; then
if $VERBOSE; then
echo "skipped"
fi
return
fi
fi
# *.[hc] : preparse if selected
if $UNIQUE ; then
if echo $SRCNAME | egrep -q '.[hc]$'; then
# only copy isdn_compat.h if we don't have a
# delete #include <linux/isdn_compat.h> in the ctrlfile
if [ "$1" = "include/linux/isdn_compat.h" ]; then
if grep -q isdn_compat.h $CTRLNAME; then
if $VERBOSE; then
echo "skipped"
fi
return
fi;
fi
if $VERBOSE; then
echo -n "processing... "
fi
$PREPARSER -c $CTRLNAME $SRCNAME $TMPNAME
RETVAL=$?
if [ $RETVAL -ne 2 -a $RETVAL -ne 0 ] ; then
echo "Problem with preparser retval $RETVAL"
exit 1
fi
if [ $RETVAL -eq 2 ] ; then
if $VERBOSE; then
echo -n "modified... "
fi
SRCNAME=$TMPNAME
fi
fi
fi
if $DODIFF; then
if $VERBOSE; then
echo
fi
if $DIFFREV; then
diff -u $2 $SRCNAME
else
diff -u $SRCNAME $2
fi
else
# do the actual copy, if necessary
if ! cmp -s $SRCNAME $2 ; then
if $VERBOSE; then
echo "copying"
else
echo "$1... copying"
fi
if $NOTEST ; then
mkdir -p `dirname $2`
rm -f $2 # unlink first
cp $SRCNAME $2
fi
else
if $VERBOSE; then
echo "up to date"
fi
fi
fi
if [ -f $TMPNAME ]; then
rm -f $TMPNAME
fi
}
#
# Print usage and exit
#
usage() {
cat<<EOM
std2kern is used for updating your kernel-tree from within
this directory.
std2kern [-h] [-k DIR] [-v] [-u] [-c FILE] [files ...]
Options:
-h This Text.
-k DIR Kerneltree is in DIR instead of /usr/src/linux
-v More mesages about processing
-u preprocessing with $PREPARSER
-d don't copy but do a unified diff instead
-r reverse directions of diff
-c FILE Use FILE as control file for $PREPARSER (only with -u)
-t Test, don't really copy files
Without any files given, within the whole tree, the "right"
files are copied. When any files are given in the commandline,
only those are copied.
EOM
exit
}
#
# Check, if argument is a linux kernel dir
#
checkkernel() {
if [ -f $1/Makefile ] ; then
if [ "`grep ^vmlinux: $1/Makefile | grep vmlinux`" != "" ] ; then
return 0
fi
fi
echo "The given argument does not look like a kernel dir"
if ! $ALLOW_ANY_DIR; then
exit 1
fi
}
#
# Determine a control file name
#
calc_ctrl_file() {
if [ -z "$CTRLNAME" ] ; then
CTRLNAME=v$VERSION.$PATCHLEVEL.$SUBLEVEL.ctrl
if [ -f $CTRLNAME ] ; then
return 0
fi
CTRLNAME=v$VERSION.$PATCHLEVEL.ctrl
if [ -f $CTRLNAME ] ; then
return 0
fi
CTRLNAME=default.ctrl
fi
if [ -f $CTRLNAME ] ; then
return 0
fi
echo "No control file found"
exit 1
}
#
# Determine a version depend file name
#
calc_version_file() {
VERSION_NAME=$1.v$VERSION.$PATCHLEVEL.$SUBLEVEL
if [ -f $VERSION_NAME ] ; then
return 0
fi
VERSION_NAME=$1.v$VERSION.$PATCHLEVEL
if [ -f $VERSION_NAME ] ; then
return 0
fi
VERSION_NAME=""
return 1
}
while getopts :p:dhk:uc:vtidr a ; do
case $a in
\?) case $OPTARG in
k) echo "-k requires Kernel directory parameter"
;;
*) echo "Unknown option: -$OPTARG"
echo "Try std2kern -h"
;;
esac
exit 1
;;
k) checkkernel $OPTARG
KERNELDIR=$OPTARG
;;
c) CTRLNAME=$OPTARG
;;
u) UNIQUE=true
;;
v) VERBOSE=true
;;
t) NOTEST=false
;;
i) ALLOW_ANY_DIR=true;
;;
d) DODIFF=true;
;;
r) DIFFREV=true;
;;
p) PREFIX=$OPTARG;
;;
h) usage
;;
esac
done
shift `expr $OPTIND - 1`
echo
echo "BE AWARE!!"
echo
echo "You are just attempting to overwrite your Kernel mISDN Sources"
echo "you probably prefer to use make install."
echo
echo "KERNELDIR=$KERNELDIR"
ls -ld $KERNELDIR
echo
echo "If you still want to patch this Kernel just answer yes:"
read i
if [ ! $i == "yes" ] ; then
echo "OK exiting"
exit 1
fi
if [ -z "$VERSION" -o -z "$PATCHLEVEL" ] ; then
if ! [ -f $KERNELDIR/Makefile ] ; then
echo "VERSION/PATCHLEVEL not set and no Makefile to read from"
exit 1
fi
eval `sed -n 's/^\([A-Z]*\) = \([0-9]*\)$/\1=\2/p' $KERNELDIR/Makefile`
fi
echo "Current kernel version is $VERSION.$PATCHLEVEL.$SUBLEVEL"
if $UNIQUE ; then
calc_ctrl_file
echo "Controlfile $CTRLNAME"
fi
if [ $# != 0 ]; then
for i in $* ; do
docp $i $KERNELDIR/$i
done
else
for i in `find drivers -type f -name '*.[hc]'`; do
docp $i $KERNELDIR/$i
done
for i in `find include -type f -name '*.h'`; do
docp $i $KERNELDIR/$i
done
for i in drivers/isdn/hardware/Makefile \
drivers/isdn/hardware/Kconfig \
drivers/isdn/hardware/mISDN/Makefile \
drivers/isdn/hardware/mISDN/Kconfig \
drivers/isdn/mISDN/Makefile \
drivers/isdn/mISDN/Kconfig \
drivers/isdn/mISDN/octvqe/Makefile \
drivers/isdn/Kconfig \
drivers/isdn/Makefile; do
calc_version_file $i
if [ -n "$VERSION_NAME" ] ; then
docp $VERSION_NAME $KERNELDIR/$i
else
if [ -f $i ] ; then
echo "use version independ $i for version v$VERSION.$PATCHLEVEL.$SUBLEVEL"
docp $i $KERNELDIR/$i
else
echo "no $i for version v$VERSION.$PATCHLEVEL.$SUBLEVEL found -- skipped"
fi
fi
done
fi
exit 0