]> git.proxmox.com Git - mirror_zfs.git/blob - copy-builtin
Fix ZVOL_DIR
[mirror_zfs.git] / copy-builtin
1 #!/usr/bin/env 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
16 # When integrated in to a monolithic kernel the spl module must appear
17 # first. This ensures its module initialization function is run before
18 # any of the other module initialization functions which depend on it.
19 MODULES+="spl"
20
21 for MODULE_DIR in module/* module/os/linux/*
22 do
23 [ -d "$MODULE_DIR" ] || continue
24 [ "spl" = "${MODULE_DIR##*/}" ] && continue
25 [ "os" = "${MODULE_DIR#*/}" ] && continue
26 MODULES+=("${MODULE_DIR#*/}")
27 done
28
29 if ! [ -e 'zfs_config.h' ]
30 then
31 echo >&2
32 echo " $0: you did not run configure, or you're not in the ZFS source directory." >&2
33 echo " $0: run configure with --with-linux=$KERNEL_DIR and --enable-linux-builtin." >&2
34 echo >&2
35 exit 1
36 fi
37
38 make clean || true
39 scripts/make_gitrev.sh || true
40
41 rm -rf "$KERNEL_DIR/include/zfs" "$KERNEL_DIR/fs/zfs"
42 cp --recursive include "$KERNEL_DIR/include/zfs"
43 cp --recursive module "$KERNEL_DIR/fs/zfs"
44 cp zfs_config.h "$KERNEL_DIR/include/zfs/"
45
46 for MODULE in "${MODULES[@]}"
47 do
48 sed -i.bak '/obj =/d' "$KERNEL_DIR/fs/zfs/$MODULE/Makefile"
49 sed -i.bak '/src =/d' "$KERNEL_DIR/fs/zfs/$MODULE/Makefile"
50 done
51
52 cat > "$KERNEL_DIR/fs/zfs/Kconfig" <<"EOF"
53 config ZFS
54 tristate "ZFS filesystem support"
55 depends on EFI_PARTITION
56 select ZLIB_INFLATE
57 select ZLIB_DEFLATE
58 help
59 This is the ZFS filesystem from the ZFS On Linux project.
60
61 See https://zfsonlinux.org/
62
63 To compile this file system support as a module, choose M here.
64
65 If unsure, say N.
66 EOF
67
68 {
69 cat <<-"EOF"
70 ZFS_MODULE_CFLAGS = -I$(srctree)/include/zfs
71 ZFS_MODULE_CFLAGS += -I$(srctree)/include/zfs/os/linux/spl
72 ZFS_MODULE_CFLAGS += -I$(srctree)/include/zfs/os/linux/zfs
73 ZFS_MODULE_CFLAGS += -I$(srctree)/include/zfs/os/linux/kernel
74 ZFS_MODULE_CFLAGS += -include $(srctree)/include/zfs/zfs_config.h
75 ZFS_MODULE_CFLAGS += -std=gnu99 -Wno-declaration-after-statement
76 ZFS_MODULE_CPPFLAGS = -D_KERNEL
77 ZFS_MODULE_CPPFLAGS += -UDEBUG -DNDEBUG
78 export ZFS_MODULE_CFLAGS ZFS_MODULE_CPPFLAGS
79
80 obj-$(CONFIG_ZFS) :=
81 EOF
82
83 for MODULE in "${MODULES[@]}"
84 do
85 echo 'obj-$(CONFIG_ZFS) += ' "$MODULE/"
86 done
87 } > "$KERNEL_DIR/fs/zfs/Kbuild"
88
89 add_after()
90 {
91 local FILE="$1"
92 local MARKER="$2"
93 local NEW="$3"
94 local LINE
95
96 while IFS='' read -r LINE
97 do
98 echo "$LINE"
99
100 if [ -n "$MARKER" -a "$LINE" = "$MARKER" ]
101 then
102 echo "$NEW"
103 MARKER=''
104 if IFS='' read -r LINE
105 then
106 [ "$LINE" != "$NEW" ] && echo "$LINE"
107 fi
108 fi
109 done < "$FILE" > "$FILE.new"
110
111 mv "$FILE.new" "$FILE"
112 }
113
114 add_after "$KERNEL_DIR/fs/Kconfig" 'if BLOCK' 'source "fs/zfs/Kconfig"'
115 add_after "$KERNEL_DIR/fs/Makefile" 'endif' 'obj-$(CONFIG_ZFS) += zfs/'
116
117 echo >&2
118 echo " $0: done." >&2
119 echo " $0: now you can build the kernel with ZFS support." >&2
120 echo " $0: make sure you enable ZFS support (CONFIG_ZFS) before building." >&2
121 echo >&2