Linux 5.0 compat: Disable vector instructions on 5.0+ kernels
[zfs.git] / copy-builtin
blob1dcfcb961ee8025d08e0d842affb2f05da1f9edd
1 #!/bin/bash
3 set -e
5 usage()
7 echo "usage: $0 <kernel source tree>" >&2
8 exit 1
11 [ "$#" -eq 1 ] || usage
12 KERNEL_DIR="$(readlink --canonicalize-existing "$1")"
14 MODULES=()
15 MODULES+="spl"
16 for MODULE_DIR in module/*
18 [ -d "$MODULE_DIR" ] || continue
19 [ "spl" = "${MODULE_DIR##*/}" ] && continue
20 MODULES+=("${MODULE_DIR##*/}")
21 done
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
32 make clean || true
33 scripts/make_gitrev.sh || true
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/"
40 for MODULE in "${MODULES[@]}"
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
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.
55 See http://zfsonlinux.org/
57 To compile this file system support as a module, choose M here.
59 If unsure, say N.
60 EOF
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
72 obj-$(CONFIG_ZFS) :=
73 EOF
75 for MODULE in "${MODULES[@]}"
77 echo 'obj-$(CONFIG_ZFS) += ' "$MODULE/"
78 done
79 } > "$KERNEL_DIR/fs/zfs/Kbuild"
81 add_after()
83 local FILE="$1"
84 local MARKER="$2"
85 local NEW="$3"
86 local LINE
88 while IFS='' read -r LINE
90 echo "$LINE"
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"
101 done < "$FILE" > "$FILE.new"
103 mv "$FILE.new" "$FILE"
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/'
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