]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/bash | |
2 | ||
3 | set -e | |
4 | ||
5 | usage() | |
6 | { | |
7 | echo "usage: $0 <kernel source tree>" >&2 | |
8 | exit 1 | |
9 | } | |
10 | ||
11 | [ "$#" -eq 1 ] || usage | |
12 | KERNEL_DIR="$(readlink --canonicalize-existing "$1")" | |
13 | ||
14 | MODULES=() | |
15 | MODULES+="spl" | |
16 | for MODULE_DIR in module/* | |
17 | do | |
18 | [ -d "$MODULE_DIR" ] || continue | |
19 | [ "spl" = "${MODULE_DIR##*/}" ] && continue | |
20 | MODULES+=("${MODULE_DIR##*/}") | |
21 | done | |
22 | ||
23 | if ! [ -e 'zfs_config.h' ] | |
24 | then | |
25 | echo >&2 | |
26 | echo " $0: you did not run configure, or you're not in the ZFS source directory." >&2 | |
27 | echo " $0: run configure with --with-linux=$KERNEL_DIR and --enable-linux-builtin." >&2 | |
28 | echo >&2 | |
29 | exit 1 | |
30 | fi | |
31 | ||
32 | make clean || true | |
33 | scripts/make_gitrev.sh || true | |
34 | ||
35 | rm -rf "$KERNEL_DIR/include/zfs" "$KERNEL_DIR/fs/zfs" | |
36 | cp --recursive include "$KERNEL_DIR/include/zfs" | |
37 | cp --recursive module "$KERNEL_DIR/fs/zfs" | |
38 | cp zfs_config.h "$KERNEL_DIR/include/zfs/" | |
39 | ||
40 | for MODULE in "${MODULES[@]}" | |
41 | do | |
42 | sed -i.bak '/obj =/d' "$KERNEL_DIR/fs/zfs/$MODULE/Makefile" | |
43 | sed -i.bak '/src =/d' "$KERNEL_DIR/fs/zfs/$MODULE/Makefile" | |
44 | done | |
45 | ||
46 | cat > "$KERNEL_DIR/fs/zfs/Kconfig" <<"EOF" | |
47 | config ZFS | |
48 | tristate "ZFS filesystem support" | |
49 | depends on EFI_PARTITION | |
50 | select ZLIB_INFLATE | |
51 | select ZLIB_DEFLATE | |
52 | help | |
53 | This is the ZFS filesystem from the ZFS On Linux project. | |
54 | ||
55 | See http://zfsonlinux.org/ | |
56 | ||
57 | To compile this file system support as a module, choose M here. | |
58 | ||
59 | If unsure, say N. | |
60 | EOF | |
61 | ||
62 | { | |
63 | cat <<-"EOF" | |
64 | ZFS_MODULE_CFLAGS = -I$(srctree)/include/zfs | |
65 | ZFS_MODULE_CFLAGS += -I$(srctree)/include/zfs/spl | |
66 | ZFS_MODULE_CFLAGS += -include $(srctree)/include/zfs/zfs_config.h | |
67 | ZFS_MODULE_CFLAGS += -std=gnu99 -Wno-declaration-after-statement | |
68 | ZFS_MODULE_CPPFLAGS = -D_KERNEL | |
69 | ZFS_MODULE_CPPFLAGS += -UDEBUG -DNDEBUG | |
70 | export ZFS_MODULE_CFLAGS ZFS_MODULE_CPPFLAGS | |
71 | ||
72 | obj-$(CONFIG_ZFS) := | |
73 | EOF | |
74 | ||
75 | for MODULE in "${MODULES[@]}" | |
76 | do | |
77 | echo 'obj-$(CONFIG_ZFS) += ' "$MODULE/" | |
78 | done | |
79 | } > "$KERNEL_DIR/fs/zfs/Kbuild" | |
80 | ||
81 | add_after() | |
82 | { | |
83 | local FILE="$1" | |
84 | local MARKER="$2" | |
85 | local NEW="$3" | |
86 | local LINE | |
87 | ||
88 | while IFS='' read -r LINE | |
89 | do | |
90 | echo "$LINE" | |
91 | ||
92 | if [ -n "$MARKER" -a "$LINE" = "$MARKER" ] | |
93 | then | |
94 | echo "$NEW" | |
95 | MARKER='' | |
96 | if IFS='' read -r LINE | |
97 | then | |
98 | [ "$LINE" != "$NEW" ] && echo "$LINE" | |
99 | fi | |
100 | fi | |
101 | done < "$FILE" > "$FILE.new" | |
102 | ||
103 | mv "$FILE.new" "$FILE" | |
104 | } | |
105 | ||
106 | add_after "$KERNEL_DIR/fs/Kconfig" 'if BLOCK' 'source "fs/zfs/Kconfig"' | |
107 | add_after "$KERNEL_DIR/fs/Makefile" 'endif' 'obj-$(CONFIG_ZFS) += zfs/' | |
108 | ||
109 | echo >&2 | |
110 | echo " $0: done." >&2 | |
111 | echo " $0: now you can build the kernel with ZFS support." >&2 | |
112 | echo " $0: make sure you enable ZFS support (CONFIG_ZFS) before building." >&2 | |
113 | echo >&2 |