February 2, 2012

The Linux Kernel Makefile.in

OpenSS7, one of my favorite projects, succeed to make fully blown LKM compilation.

After some experiments fail miserable...
My KISS style LKM inside Atoconf based on faking Makefile.in




OpenSS7 macro to find kernel

# =========================================================================
# _LINUX_KERNEL
# -------------------------------------------------------------------------
# The linux kernel build directory is the build kernel tree root against which
# kernel modules will be compiled.
# -------------------------------------------------------------------------
AC_DEFUN([_LINUX_KERNEL], [dnl
AC_CACHE_CHECK([for kernel build directory], [linux_cv_kernel_build], [dnl
AC_MSG_RESULT([searching...])
AC_ARG_WITH([kernel-build],
AS_HELP_STRING([--with-kernel-build=DIR],
[specify the base kernel build directory in which configured
kernel source resides.]),
[with_kernel_build="$withval"],
[with_kernel_build=])
if test :"${with_kernel_build:-no}" != :no
then
linux_cv_kernel_build="$with_kernel_build"
fi
if test :"${linux_cv_kernel_build:-no}" = :no -o ! -d "$linux_cv_kernel_build"
then
if test :"${linux_cv_kernel_build:-no}" = :no
then
AC_MSG_ERROR([
***
*** This package does not support headless kernel build. Install the
*** appropriate built kernel-source and kernel-headers package for the
*** target kernel and then configure again.
***
*** The following directories do no exist in the build environment:
*** "$with_kernel_build"
***
*** ])
fi
fi
AC_MSG_CHECKING([for kernel build directory]) ])
kbuilddir="$linux_cv_kernel_build"
AC_SUBST([kbuilddir])dnl
])# LINUX_KERNEL





acinclude.in per module macro

# =============================================================================
# _MODEM_SETUP_MODULES
# -----------------------------------------------------------------------------
AC_DEFUN([_MODEM_SETUP_MODULES], [dnl
AC_ARG_ENABLE([module-lte-sched],
AS_HELP_STRING([--enable-module-lte-sched],
[enable module lte_sched for linkage with MODEM.
@<:@default=module@:>@]),
[enable_module_lte_sched="$enableval"],
[if test :${modem_big_compile:-yes} = :yes ; then enable_module_lte_sched='yes' ; else enable_module_lte_sched='module' ; fi])
AM_CONDITIONAL([CONFIG_MODEM_LTE_SCHED], [test :${modem_cv_module_lte_sched:-module} = :yes])
# -----------------------------------------------------------------------------

AC_CACHE_CHECK([for MODEM module lte_sched], [modem_cv_module_lte_sched], [dnl
modem_cv_module_lte_sched="${enable_module_lte_sched:-module}"
if test :$modem_cv_module_lte_sched = :module -a :${linux_cv_k_linkage:-loadable} = :linkable ; then
modem_cv_module_lte_sched='yes'
fi])
# -----------------------------------------------------------------------------
case ${modem_cv_module_lte_sched:-module} in
(yes)
AC_DEFINE_UNQUOTED([CONFIG_MODEM_LTE_SCHED], [1], [When defined,] AC_PACKAGE_TITLE [
will include the lte_sched module for linkage with MODEM. When undefined,]
AC_PACKAGE_TITLE [will not include the lte_sched module for linkage with MODEM.])
;;
(module)
AC_DEFINE_UNQUOTED([CONFIG_MODEM_LTE_SCHED_MODULE], [1], [When defined,]
AC_PACKAGE_TITLE [will include the lte_sched module as a standalone loadable kernel module. When
undefined,] AC_PACKAGE_TITLE [will not include the lte_sched module as a standalone loadable kernel
module.])
;;
esac
# -----------------------------------------------------------------------------
AM_CONDITIONAL([CONFIG_MODEM_LTE_SCHED], [test :${modem_cv_module_lte_sched:-module} = :yes])
AM_CONDITIONAL([CONFIG_MODEM_LTE_SCHED_MODULE], [test :${modem_cv_module_lte_sched:-module} = :module])
])# _MODEM_SETUP_MODULES






Fake Makefile.in


target_alias = @target_alias@
target_cpu = @target_cpu@
prefix = @prefix@

KERNEL_ROOT=@kbuilddir@
TARGETDIR=$(prefix)/firmware

ifneq ($(KERNELRELEASE),)
ifdef V
KBUILD_VERBOSE = $(V)
endif

EXTRA_CFLAGS += -I$(src)
EXTRA_CFLAGS +=

@CONFIG_LTE_SCHED_MODULE_TRUE@lte_sched.c: lte_sched.h
@CONFIG_LTE_SCHED_MODULE_TRUE@obj-m += lte_sched.o

#sched_csap-y := sched_csap.o

else

all: modules

modules:
echo "Making $@ in `pwd`"
ARCH=$(target_cpu) CROSS_COMPILE="$(target_alias)-" \
$(MAKE) V=1 -C $(KERNEL_ROOT) M=`pwd` modules

clean:
echo "Making $@ in `pwd`"
ARCH=$(target_cpu) CROSS_COMPILE="$(target_alias)-" \
$(MAKE) V=0 -C $(KERNEL_ROOT) M=`pwd` clean

install:
echo "Making $@ in `pwd`"
ARCH=$(target_cpu) CROSS_COMPILE="$(target_alias)-" \
$(MAKE) V=1 -C $(KERNEL_ROOT) M=`pwd` INSTALL_MOD_PATH=$(TARGETDIR) modules_install
endif