RFC: Macro for building modules
sparky at pld-linux.org
sparky at pld-linux.org
Tue Nov 7 18:22:19 CET 2006
Right now we are copying code for building kernel 2.6 modules to each
spec which provides them. It is a little hard to maintain and to add
some functionality. I have created macro for building modules based on
that code, a little expanded (with cross-compilation support). Now in
spec file thete will only have to be some thing like:
%if %{with kernel}
cd module/place
%build_kernel_modules module_name1 module_name2
cd ../..
%endif
If some additional options for make modules are required they may be
passed like: -1 option1 -2 option2 -3 option3; up to 9 options are
supported.
Exemple when some additional option in make modules is required:
%build_kernel_modules -1 T=$TMPDIR mol
There may be 2 options passed to make prepare scripts: -p o1 -P o2.
Module patching is supported via shell script called pld-module.patch.
Exemple with additional patching:
%if %{with kernel}
cp -f pwc-if.c pwc-if.c.orig
cat > pld-module.patch <<'EOF'
set -e -x
if grep -q "CONFIG_PREEMPT_RT" o/.config; then
sed 's/SPIN_LOCK_UNLOCKED/SPIN_LOCK_UNLOCKED(pdev->ptrlock)/' \
pwc-if.c.orig > pwc-if.c
else
cat pwc-if.c.orig > pwc-if.c
fi
EOF
%build_kernel_modules pwc
%endif
Now, take a look at the code and propose your additions! Number and use
of backshashes is scary, but it has to be this way as %define is expanded
before anything.
--
____ Sparky{PI] -- Przemyslaw _ ___ _ _ ........... LANG...Pl..Ca..Es..En
/____) ___ ___ _ _ || Iskra | | _ \| | | : WWW........ppcrcd.pld-linux.org
\____\| -_)'___| ||^'||//\\// < | _/| | | : JID......sparky<at>jabberes.org
(____/|| (_-_|_|| ||\\ || |_ |_| |_| _| : Mail....sparky<at>pld-linux.org
-------------- next part --------------
%build_kernel_modules(1:2:3:4:5:6:7:8:9:p:P:) \
%{!?1:%{error:build_kernel_modules: Required module name missing}} \
\
%define Opts \\\\\\\
%if "%{_target_base_arch}" != "%{_arch}" \\\
%if "%{_arch}" == "x86_64" && "%{_target_base_arch}" == "i386" \\\
CC="%{__cc}" CPP="%{__cpp}" ARCH=%{_target_base_arch} \\\
%else \\\
ARCH=%{_target_base_arch} CROSS_COMPILE=%{_target_cpu}-pld-linux- \\\
%endif \\\
%else \\\
CC="%{__cc}" CPP="%{__cpp}" \\\
%endif \
%define MakeOpts HOSTCC="%{__cc}" %{?with_verbose:V=1} %{Opts} \
\
for cfg in %{?with_dist_kernel:%{?with_smp:smp} up}%{!?with_dist_kernel:nondist}; do \
if [ ! -r "%{_kernelsrcdir}/config-$cfg" ]; then \
exit 1 \
fi \
install -d o/include/linux \
ln -sf %{_kernelsrcdir}/config-$cfg o/.config \
ln -sf %{_kernelsrcdir}/Module.symvers-$cfg o/Module.symvers \
ln -sf %{_kernelsrcdir}/include/linux/autoconf-$cfg.h o/include/linux/autoconf.h \
\
[ ! -e pld-module.patch ] || %__spec_build_shell pld-module.patch \
\
%if %{with dist_kernel} \
%{__make} -j1 -C %{_kernelsrcdir} prepare scripts \\\
O=$PWD/o %{-p*} %{-P*} \\\
%{MakeOpts} \
%else \
install -d o/include/config \
touch o/include/config/MARKER \
ln -sf %{_kernelsrcdir}/scripts o/scripts \
%endif \
\
%{__make} -C %{_kernelsrcdir} modules \\\
M=$PWD O=$PWD/o \\\
%{-1*} %{-2*} %{-3*} %{-4*} %{-5*} %{-6*} %{-7*} %{-8*} %{-9*} \\\
%{MakeOpts} \
\
for MODULE in %{*}; do \
mv ${MODULE}{,-$cfg}.ko \
done \
done \
%{nil}
More information about the pld-devel-en
mailing list