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