Illumos 5911 - ZFS "hangs" while deleting file
[zfs.git] / copy-builtin
blobfbe20dda5fb273e22cc79799954e2bd95edf4467
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 for MODULE_DIR in module/*
17 [ -d "$MODULE_DIR" ] || continue
18 MODULES+=("${MODULE_DIR##*/}")
19 done
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
30 make clean || true
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/"
37 adjust_obj_paths()
39 local FILE="$1"
40 local LINE OBJPATH
42 while IFS='' read -r LINE
44 OBJPATH="${LINE#\$(MODULE)-objs += }"
45 if [ "$OBJPATH" = "$LINE" ]
46 then
47 echo "$LINE"
48 else
49 echo "\$(MODULE)-objs += ${OBJPATH##*/}"
51 done < "$FILE" > "$FILE.new"
52 mv "$FILE.new" "$FILE"
55 for MODULE in "${MODULES[@]}"
57 adjust_obj_paths "$KERNEL_DIR/fs/zfs/$MODULE/Makefile"
58 done
60 cat > "$KERNEL_DIR/fs/zfs/Kconfig" <<"EOF"
61 config ZFS
62 tristate "ZFS filesystem support"
63 depends on SPL
64 depends on EFI_PARTITION
65 select ZLIB_INFLATE
66 select ZLIB_DEFLATE
67 help
68 This is the ZFS filesystem from the ZFS On Linux project.
70 See http://zfsonlinux.org/
72 To compile this file system support as a module, choose M here.
74 If unsure, say N.
75 EOF
78 cat <<-"EOF"
79 ZFS_MODULE_CFLAGS = -I$(srctree)/include/zfs -I$(srctree)/include/spl
80 ZFS_MODULE_CFLAGS += -include $(srctree)/spl_config.h -include $(srctree)/zfs_config.h
81 export ZFS_MODULE_CFLAGS
83 obj-$(CONFIG_ZFS) :=
84 EOF
86 for MODULE in "${MODULES[@]}"
88 echo 'obj-$(CONFIG_ZFS) += ' "$MODULE/"
89 done
90 } > "$KERNEL_DIR/fs/zfs/Kbuild"
92 add_after()
94 local FILE="$1"
95 local MARKER="$2"
96 local NEW="$3"
97 local LINE
99 while IFS='' read -r LINE
101 echo "$LINE"
103 if [ -n "$MARKER" -a "$LINE" = "$MARKER" ]
104 then
105 echo "$NEW"
106 MARKER=''
107 if IFS='' read -r LINE
108 then
109 [ "$LINE" != "$NEW" ] && echo "$LINE"
112 done < "$FILE" > "$FILE.new"
114 mv "$FILE.new" "$FILE"
117 add_after "$KERNEL_DIR/fs/Kconfig" 'if BLOCK' 'source "fs/zfs/Kconfig"'
118 add_after "$KERNEL_DIR/fs/Makefile" 'endif' 'obj-$(CONFIG_ZFS) += zfs/'
120 echo >&2
121 echo " $0: done." >&2
122 echo " $0: now you can build the kernel with ZFS support." >&2
123 echo " $0: make sure you enable ZFS support (CONFIG_ZFS) before building." >&2
124 echo >&2