-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlkhh-module-make
More file actions
executable file
·135 lines (114 loc) · 3.41 KB
/
lkhh-module-make
File metadata and controls
executable file
·135 lines (114 loc) · 3.41 KB
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
#! /bin/bash
_rootdir=${_rootdir:-"$(dirname "$(readlink -f "$0")")"}
_ver="0.0.1-dev"
#_author="Wei Peng <me@1pengw.com>"
source "${_rootdir}/_shared_prologue"
#
# parameters
#
declare -i instance=${instance:-1}
declare target=${target:-modules}
declare -i jobs=${jobs:-$((2+$(nproc)))}
declare moduleroot=${moduleroot:-"$(readlink -f $PWD)"}
declare -i install=${install:-0}
declare -i nbd=${nbd:-1}
#
# getopt processing
#
function my_getopt_cont () {
local n_shift=1 # number of shifts in the outer loop; shift by 1 by default
case "$1" in
-i|--instance)
shift
instance=$1
n_shift=2
;;
-t|--target)
shift
target=$1
n_shift=2
;;
-j|--jobs)
shift
jobs=$1
n_shift=2
;;
-m|--moduleroot)
shift
moduleroot=$1
n_shift=2
;;
-I|--install)
install=1
n_shift=1
;;
-n|--nbd)
shift
nbd=$1
n_shift=2
;;
esac
return $n_shift
}
my_getopt "i:t:j:m:In:" "instance:,target:,jobs:,moduleroot:,install,nbd:" "my_getopt_cont" "Make and optionally install modules into kernel instance." "$(
cat <<END
[-i|--instance=<instance>] [-t|--target=<target>] [-j|--jobs=<jobs>]
[-m|--moduleroot=<moduleroot>] [-I|--install]
[-n|--nbd=<nbd>]
END
)" "$(
cat <<END
-i --instance Maximal number of kernel instances to prepare (default: $instance).
-t --target Makefile target to make (default: $target).
-j --jobs Number of parallel make jobs (default: $jobs).
-m --moduleroot Root directory of the module, where "Makefile" is found (default: $moduleroot).
-I --install Install the module (default: $install).
-n --nbd Network Block Device (NBD) that has loop-mounted the OS image (default: $nbd).
END
)" "$@"
ret=$?
eval set -- "$_getopt"
shift $ret
# sanity check
vecho 0 <<END
$(
dumpparam <<END1
$(
for name in instance target jobs moduleroot; do
echo "$name=$(echo $(eval "echo \$$name"))"
done
)
END1
)
END
build_dir="$LKHH_ARENA/build/$instance"
[[ -d "$build_dir" ]] || die 1 <<END
ERROR: $build_dir does not exist; consider "lkhh-init -i $instance" first.
END
target_dir="$LKHH_ARENA/target/$instance"
[[ -d "$target_dir" ]] || die 1 <<END
ERROR: $target_dir does not exist; consider "lkhh-init -i $instance" first.
END
moduleroot="$(readlink -f "$moduleroot")"
[[ -d "$moduleroot" ]] || die 1 <<END
ERROR: $moduleroot does not exist.
END
vecho 0 <<END
make -C "$build_dir" -j "$jobs" "O=$build_dir" "M=$moduleroot" "$@" "$target"
END
make -C "$build_dir" -j "$jobs" "O=$build_dir" "M=$moduleroot" "$@" "$target"
# If install is requested.
if (( install > 0 )); then
vecho 0 <<END
make -C "$build_dir" -j "$jobs" "O=$build_dir" "M=$moduleroot" "INSTALL_MOD_PATH=$target_dir" "$@" modules_install
END
make -C "$build_dir" -j "$jobs" "O=$build_dir" "M=$moduleroot" "INSTALL_MOD_PATH=$target_dir" "$@" modules_install
mnt="$LKHH_IMAGE/mnt/$nbd"
if [[ -d "$mnt" ]] && mountpoint "$mnt" >/dev/null; then
target_dir="$mnt/usr"
vecho 0 <<END
sudo make -C "$build_dir" -j "$jobs" "O=$build_dir" "M=$moduleroot" "INSTALL_MOD_PATH=$target_dir" "$@" modules_install
END
sudo make -C "$build_dir" -j "$jobs" "O=$build_dir" "M=$moduleroot" "INSTALL_MOD_PATH=$target_dir" "$@" modules_install
fi
fi