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