Skip to content

Commit c167aad

Browse files
dechampsbehlendorf
authored andcommitted
Add script for builtin module building.
This commit introduces a "copy-builtin" script designed to prepare a kernel source tree for building SPL as a builtin module. The script makes a full copy of all needed files, thus making the kernel source tree fully independent of the spl source package. To achieve that, some compilation flags (-include, -I) have been moved to module/Makefile. This Makefile is only used when compiling external modules; when compiling builtin modules, a Kbuild file generated by the configure-builtin script is used instead. This makes sure Makefiles inside the kernel source tree does not contain references to the spl source package. Signed-off-by: Brian Behlendorf <[email protected]> Issue openzfs/zfs#851
1 parent 723aa3b commit c167aad

File tree

5 files changed

+137
-9
lines changed

5 files changed

+137
-9
lines changed

README.markdown

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,11 @@ To build packages for your distribution:
1111
$ ./configure
1212
$ make pkg
1313

14+
To copy the kernel code inside your kernel source tree for builtin
15+
compilation:
16+
17+
$ ./configure --enable-linux-builtin --with-linux=/usr/src/linux-...
18+
$ ./copy-builtin /usr/src/linux-...
19+
1420
Full documentation for building, configuring, and using the SPL can
1521
be found at: <http://zfsonlinux.org>

copy-builtin

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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/*
16+
do
17+
[ -d "$MODULE_DIR" ] || continue
18+
MODULES+=("${MODULE_DIR##*/}")
19+
done
20+
21+
if ! [ -e 'spl_config.h' ]
22+
then
23+
echo >&2
24+
echo " $0: you did not run configure, or you're not in the SPL source directory." >&2
25+
echo " $0: run configure with --with-linux=$KERNEL_DIR and --enable-linux-builtin." >&2
26+
echo >&2
27+
exit 1
28+
fi
29+
30+
make clean || true
31+
32+
rm -rf "$KERNEL_DIR/include/spl" "$KERNEL_DIR/spl"
33+
cp --recursive include "$KERNEL_DIR/include/spl"
34+
cp --recursive module "$KERNEL_DIR/spl"
35+
cp spl_config.h "$KERNEL_DIR/"
36+
37+
adjust_obj_paths()
38+
{
39+
local FILE="$1"
40+
local LINE OBJPATH
41+
42+
while IFS='' read -r LINE
43+
do
44+
OBJPATH="${LINE#\$(MODULE)-objs += }"
45+
if [ "$OBJPATH" = "$LINE" ]
46+
then
47+
echo "$LINE"
48+
else
49+
echo "\$(MODULE)-objs += ${OBJPATH##*/}"
50+
fi
51+
done < "$FILE" > "$FILE.new"
52+
mv "$FILE.new" "$FILE"
53+
}
54+
55+
for MODULE in "${MODULES[@]}"
56+
do
57+
adjust_obj_paths "$KERNEL_DIR/spl/$MODULE/Makefile"
58+
done
59+
60+
cat > "$KERNEL_DIR/spl/Kconfig" <<"EOF"
61+
config SPL
62+
tristate "Solaris Porting Layer (SPL)"
63+
help
64+
This is the SPL library from the ZFS On Linux project.
65+
66+
See http://zfsonlinux.org/
67+
68+
To compile this library as a module, choose M here.
69+
70+
If unsure, say N.
71+
EOF
72+
73+
{
74+
cat <<-"EOF"
75+
SPL_MODULE_CFLAGS = -I$(srctree)/include/spl
76+
SPL_MODULE_CFLAGS += -include $(srctree)/spl_config.h
77+
export SPL_MODULE_CFLAGS
78+
79+
obj-$(CONFIG_SPL) :=
80+
EOF
81+
82+
for MODULE in "${MODULES[@]}"
83+
do
84+
echo 'obj-$(CONFIG_SPL) += ' "$MODULE/"
85+
done
86+
} > "$KERNEL_DIR/spl/Kbuild"
87+
88+
add_after()
89+
{
90+
local FILE="$1"
91+
local MARKER="$2"
92+
local NEW="$3"
93+
local LINE
94+
95+
while IFS='' read -r LINE
96+
do
97+
echo "$LINE"
98+
99+
if [ -n "$MARKER" -a "$LINE" = "$MARKER" ]
100+
then
101+
echo "$NEW"
102+
MARKER=''
103+
if IFS='' read -r LINE
104+
then
105+
[ "$LINE" != "$NEW" ] && echo "$LINE"
106+
fi
107+
fi
108+
done < "$FILE" > "$FILE.new"
109+
110+
mv "$FILE.new" "$FILE"
111+
}
112+
113+
add_after "$KERNEL_DIR/Kconfig" 'source "arch/$SRCARCH/Kconfig"' 'source "spl/Kconfig"'
114+
# We must take care to build SPL before ZFS, else module initialization order will be wrong
115+
sed -i 's#kernel/ mm/ fs/#kernel/ mm/ spl/ fs/#' "$KERNEL_DIR/Makefile"
116+
117+
echo >&2
118+
echo " $0: done." >&2
119+
echo " $0: now you can build the kernel with SPL support." >&2
120+
echo " $0: make sure you enable SPL support (CONFIG_SPL) before building." >&2
121+
echo >&2
122+

module/Makefile.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ subdir-m += splat
33

44
INSTALL=/usr/bin/install
55

6+
SPL_MODULE_CFLAGS = -I@abs_top_srcdir@/include
7+
SPL_MODULE_CFLAGS += -include @abs_top_builddir@/spl_config.h
8+
export SPL_MODULE_CFLAGS
9+
610
modules:
7-
$(MAKE) -C @LINUX_OBJ@ SUBDIRS=`pwd` @KERNELMAKE_PARAMS@ $@
11+
$(MAKE) -C @LINUX_OBJ@ SUBDIRS=`pwd` @KERNELMAKE_PARAMS@ CONFIG_SPL=m $@
812

913
clean:
1014
@# Only cleanup the kernel build directories when CONFIG_KERNEL

module/spl/Makefile.in

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# Makefile.in for spl kernel module
22

33
MODULE := spl
4-
EXTRA_CFLAGS = @KERNELCPPFLAGS@
5-
EXTRA_CFLAGS += -I@abs_top_srcdir@/include
6-
EXTRA_CFLAGS += -include @abs_top_builddir@/spl_config.h
4+
EXTRA_CFLAGS = $(SPL_MODULE_CFLAGS) @KERNELCPPFLAGS@
75

86
# Solaris porting layer module
9-
obj-m := $(MODULE).o
7+
obj-$(CONFIG_SPL) := $(MODULE).o
108

119
$(MODULE)-objs += @top_srcdir@/module/spl/spl-debug.o
1210
$(MODULE)-objs += @top_srcdir@/module/spl/spl-proc.o

module/splat/Makefile.in

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# Makefile.in for splat kernel module
22

33
MODULE := splat
4-
EXTRA_CFLAGS = @KERNELCPPFLAGS@
5-
EXTRA_CFLAGS += -I@abs_top_srcdir@/include
6-
EXTRA_CFLAGS += -include @abs_top_builddir@/spl_config.h
4+
EXTRA_CFLAGS = $(SPL_MODULE_CFLAGS) @KERNELCPPFLAGS@
75

86
# Solaris Porting LAyer Tests
9-
obj-m := $(MODULE).o
7+
obj-$(CONFIG_SPL) := $(MODULE).o
108

119
$(MODULE)-objs += @top_srcdir@/module/splat/splat-ctl.o
1210
$(MODULE)-objs += @top_srcdir@/module/splat/splat-kmem.o

0 commit comments

Comments
 (0)