Commit d8ec3733 authored by Charlie Jacobsen's avatar Charlie Jacobsen

reorganize: Kernel build working (out of source build).

I haven't tried running anything yet. Still need to update the
build for the test apps.
parent 5aa522b7
Pipeline #407 skipped
......@@ -97,10 +97,16 @@ AS_IF([test "x$PLATFORM" = "xkernel"],
# Build libcap as kernel module, in addition to static lib.a
AC_ARG_ENABLE([kernel_module],
[AS_HELP_STRING([--disable-kernel-module],
[Disable kernel module build (default=no)])])
[Disable kernel module build (default=no)])],
[],
[enable_kernel_module="yes"])
AM_CONDITIONAL(ENABLE_KERNEL_MODULE,
[test "x$enable_kernel_module" = "xyes"])
AM_COND_IF([ENABLE_KERNEL_MODULE],
[AC_MSG_NOTICE([Building kernel module.])],
[AC_MSG_NOTICE([Not building kernel module.])])
],
[
......@@ -111,10 +117,16 @@ AS_IF([test "x$PLATFORM" = "xkernel"],
])
AC_ARG_ENABLE([test_build],
[AS_HELP_STRING([--disable-test-build],
[Disable building test applications (default=no)])])
[AS_HELP_STRING([--enable-test-build],
[Enable building test applications (default=no)])],
[],
[enable_test_build="no"])
AM_CONDITIONAL(ENABLE_TEST_BUILD,
[test "x$enable_test_build" = "xyes"])
AM_COND_IF([ENABLE_TEST_BUILD],
[AC_MSG_NOTICE([Building tests.])],
[AC_MSG_NOTICE([Not building tests.])])
# --------------------------------------------------
# Checks for programs.
......@@ -269,8 +281,9 @@ AC_CONFIG_FILES(
src/platform/Makefile
src/platform/kernel/Makefile
src/platform/kernel/src/Makefile
src/platform/kernel/module/Kbuild:src/platform/kernel/module/Kbuild.in
src/platform/Kbuild:src/platform/kernel/Kbuild.in
src/platform/kernel/module/Makefile
src/platform/kernel/module/Kbuild
src/platform/kernel/Kbuild
src/platform/kernel/include/Makefile
src/platform/user/Makefile
......
......@@ -31,9 +31,9 @@ extern int cap_debug_level;
#define CAP_DEBUG_WARN 2
#define CAP_DEBUG_MSG 3
#define CAP_DEBUG(lvl, msg, ...) do { \
#define CAP_DEBUG(lvl,msg,...) do { \
if (lvl <= cap_debug_level) \
__cap_debug(msg,## __VA_ARGS__); \
__cap_debug(msg,##__VA_ARGS__); \
} while(0)
#define CAP_BUG() do { __cap_bug(); } while(0)
......
# Build libcap as static library. Unfortunately, the name of the
# library is hard-coded in the kernel build system to be lib.a. (We
# have an extra build step that cp's lib.a -> libcap.a.)
# Kernel source files
# (none for static lib)
# Note: Kernel expects the files to be relative paths (it always prepends
# the current directory).
# Build libcap as static library
lib-y += libcap.a
libcap-objs += \
# This single line of magic makes it so we can do an out of src tree
# build. It has to do with how and where this Kbuild file is included
# in the kernel build system.
src = @abs_top_srcdir@/src/platform/kernel
# Sources that make up library
lib-y += \
$(COMMON_SRCS:.c=.o)
# Pass along include directories from the Automake file
ccflags-y += $(AM_CPPFLAGS)
......@@ -16,36 +16,79 @@ AM_CPPFLAGS = \
$(GLIB_INCLUDES)
COMMON_SRCS = \
../common/cap.c \
../common/cptr_cache.c
../../common/cap.c \
../../common/cptr_cache.c
export AM_CPPFLAGS COMMON_SRCS
LIBCAP_KBUILD=$(PWD)
LIBCAP_KERNEL_MODULE_KBUILD=$(PWD)/platform/kernel/module
LIBCAP_KERNEL_MODULE_KBUILD=$(PWD)/module
# Automake if's aren't as powerful as GNU Make's (partly since Automake
# doesn't know the config selections when it does its job)
all_cmd = $(MAKE) -C $(KDIR) M=$(LIBCAP_KBUILD) \
CPPFLAGS="$(AM_CPPFLAGS) $(CPPFLAGS)" modules
install_cmd = $(MAKE) -C $(KDIR) M=$(LIBCAP_KBUILD) modules_install
clean_cmd = $(MAKE) -C $(KDIR) M=$(LIBCAP_KBUILD) clean
if ENABLE_KERNEL_MODULE
all_cmd += ; $(MAKE) -C $(KDIR) M=$(LIBCAP_KERNEL_MODULE_KBUILD) \
CPPFLAGS="$(AM_CPPFLAGS) $(CPPFLAGS)" modules
install_cmd += ; $(MAKE) -C $(KDIR) M=$(LIBCAP_KERNEL_MODULE_KBUILD) \
modules_install
clean_cmd += ; $(MAKE) -C $(KDIR) M=$(LIBCAP_KERNEL_MODULE_KBUILD) clean
MAYBE_ALL_MODULE = all-module
MAYBE_CLEAN_MODULE = clean-module
MAYBE_MODULES_INSTALL = do-modules-install
endif
all:
$(all_cmd)
# Sequence the build, so we build the lib first
all: all-lib-cp $(MAYBE_ALL_MODULE)
all-module: all-lib-cp
$(MAKE) -C $(KDIR) M=$(LIBCAP_KERNEL_MODULE_KBUILD) modules
all-lib-cp: all-lib
cp lib.a libcap.a
all-lib:
$(MAKE) -C $(KDIR) M=$(LIBCAP_KBUILD)
# Don't do regular install; user probably doesn't want kernel stuff in
# user-level directories.
install-exec-hook:
@echo "----------------------------------------"; \
echo " NOTE"; \
echo ""; \
echo "Skipping copy of libcap.a and libcap.ko."; \
echo "You can find them in (libcap build dir)/src/platform/kernel."; \
echo "To install the kernel module, do 'make modules_install'"; \
echo "in the root of the libcap build tree."; \
echo ""; \
echo "----------------------------------------"
uninstall-hook:
@echo "----------------------------------------"; \
echo " NOTE"; \
echo ""; \
echo "Skipping uninstall of libcap.a and libcap.ko."; \
echo "If you installed the libcap.ko kernel module via"; \
echo "modules_install (in the root of the libcap build tree)"; \
echo "then there really isn't an easy way (that I know of) to"; \
echo "remove the kernel module. It was installed somewhere in"; \
echo ' /lib/modules/`uname -r`/build'; \
echo "(or something similar)."; \
echo "You will have to manually remove it."; \
echo ""; \
echo "----------------------------------------"
do-modules-install:
$(MAKE) -C $(KDIR) M=$(LIBCAP_KERNEL_MODULE_KBUILD) \
modules_install
modules_install: $(MAYBE_MODULES_INSTALL)
clean: clean-lib $(MAYBE_CLEAN_MODULE)
clean-module:
$(MAKE) -C $(KDIR) M=$(LIBCAP_KERNEL_MODULE_KBUILD) clean
install:
$(install_cmd)
clean-lib:
$(MAKE) -C $(KDIR) M=$(LIBCAP_KBUILD) clean
rm -f libcap.a
clean:
$(clean_cmd)
.PHONY: all-module all-lib all-lib-cp do-modules-install modules_install \
clean-module clean-lib
......@@ -19,7 +19,7 @@
#define __cap_msg(format,...) \
printk(KERN_NOTICE "cap: %s:%d: "format,__FUNCTION__,__LINE__,##__VA_ARGS__)
#define __cap_debug(format,...) \
printk(KERN_DEBUG,"cap: %s:%d: "format,__FUNCTION__,__LINE__,##__VA_ARGS__)
printk(KERN_DEBUG "cap: %s:%d: "format,__FUNCTION__,__LINE__,##__VA_ARGS__)
#define __cap_bug() BUG()
......
# Build kernel module that includes libcap.a.
top_srcdir = @top_srcdir@
LIBCAP_PATH = $(top_srcdir)/src/libcap.a
# Note: Kernel expects the files to be relative paths (it always prepends
# the current directory).
obj-m = cap_module.o
# This single line of magic makes it so we can do an out of src tree
# build. It has to do with how and where this Kbuild file is included
# in the kernel build system.
src = @abs_top_srcdir@/src/platform/kernel/module
cap_module-objs += main.o
cap_module-objs += $(LIBCAP_PATH)
\ No newline at end of file
# The module (will be named libcap.ko)
obj-m = libcap.o
# Sources that make up module
libcap-objs += main.o
# Link with libcap.a
libcap-objs += ../libcap.a
# Pass along include directories from the Automake file
ccflags-y += $(AM_CPPFLAGS)
# Empty for now. We trigger the build in the prior directory,
# because the library needs to be built before the kernel module (so
# we can link it).
......@@ -17,7 +17,7 @@ static int __init cap_init_module(void)
static void __exit cap_fini_module(void)
{
cap_exit();
cap_fini();
return;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment