xref: /freebsd/sys/contrib/openzfs/copy-builtin (revision 5def4c47d4bd90b209b9b4a4ba9faec15846d8fd)
1#!/bin/sh
2
3set -ef
4
5usage()
6{
7	echo "usage: $0 <kernel source tree>" >&2
8	exit 1
9}
10
11[ "$#" -eq 1 ] || usage
12KERNEL_DIR="$1"
13
14if ! [ -e 'zfs_config.h' ]
15then
16	echo "$0: you did not run configure, or you're not in the ZFS source directory."
17	echo "$0: run configure with --with-linux=$KERNEL_DIR and --enable-linux-builtin."
18
19	exit 1
20fi >&2
21
22make clean ||:
23make gitrev
24
25rm -rf "$KERNEL_DIR/include/zfs" "$KERNEL_DIR/fs/zfs"
26cp -R include "$KERNEL_DIR/include/zfs"
27cp -R module "$KERNEL_DIR/fs/zfs"
28cp zfs_config.h "$KERNEL_DIR/include/zfs/"
29
30cat > "$KERNEL_DIR/fs/zfs/Kconfig" <<EOF
31config ZFS
32	tristate "ZFS filesystem support"
33	depends on EFI_PARTITION
34	select ZLIB_INFLATE
35	select ZLIB_DEFLATE
36	help
37	  This is the ZFS filesystem from the OpenZFS project.
38
39	  See https://github.com/openzfs/zfs
40
41	  To compile this file system support as a module, choose M here.
42
43	  If unsure, say N.
44EOF
45
46add_after()
47{
48	FILE="$1"
49	MARKER="$2"
50	NEW="$3"
51
52	while IFS='' read -r LINE
53	do
54		printf "%s\n" "$LINE"
55
56		if [ -n "$MARKER" ] && [ "$LINE" = "$MARKER" ]
57		then
58			printf "%s\n" "$NEW"
59			MARKER=''
60			if IFS='' read -r LINE
61			then
62				[ "$LINE" != "$NEW" ] && printf "%s\n" "$LINE"
63			fi
64		fi
65	done < "$FILE" > "$FILE.new"
66
67	mv "$FILE.new" "$FILE"
68}
69
70add_after "$KERNEL_DIR/fs/Kconfig" 'if BLOCK' 'source "fs/zfs/Kconfig"'
71add_after "$KERNEL_DIR/fs/Makefile" 'endif' 'obj-$(CONFIG_ZFS) += zfs/'
72
73echo "$0: done. now you can build the kernel with ZFS support." >&2
74echo "$0: make sure you enable ZFS support (CONFIG_ZFS) before building." >&2
75