diff --git a/configure.ac b/configure.ac index f4b29b15290b1817dcde7f403ebc9f8b2bb79cfb..3fd33a19907f967be632a2306a22844c3d12ac66 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/include/libcap.h b/src/include/libcap.h index 8cfbc38c61ef6ac76e5b293ac9a2b3c30a05fee7..77df1c3fb5d4fc78051adab4b3661bcc6151df08 100644 --- a/src/include/libcap.h +++ b/src/include/libcap.h @@ -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) diff --git a/src/platform/kernel/Kbuild.in b/src/platform/kernel/Kbuild.in index 94e69ee2583e577cbe04d6536752a7509751ed68..02bca3ea3f07b566c02aa27e2eae370cfa1ee857 100644 --- a/src/platform/kernel/Kbuild.in +++ b/src/platform/kernel/Kbuild.in @@ -1,8 +1,18 @@ +# 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) diff --git a/src/platform/kernel/Makefile.am b/src/platform/kernel/Makefile.am index 9a670dd27352ed316b978bdae50b4969148657b0..85d57423340ab2c18267685f8d4fbf4e5e9c3f56 100644 --- a/src/platform/kernel/Makefile.am +++ b/src/platform/kernel/Makefile.am @@ -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 diff --git a/src/platform/kernel/include/libcap_platform.h b/src/platform/kernel/include/libcap_platform.h index 012774403bfb4a881c831c7c6263dae54653b28b..b2492fe9eb62d9d78d82c3cc76dc9716c4ea0048 100644 --- a/src/platform/kernel/include/libcap_platform.h +++ b/src/platform/kernel/include/libcap_platform.h @@ -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() diff --git a/src/platform/kernel/module/Kbuild.in b/src/platform/kernel/module/Kbuild.in index c0b8e64ad1cbc63af14dac19b470c312e3b62b11..c3bc784eb7aca4b8362e1940ac8abbc05a6777c3 100644 --- a/src/platform/kernel/module/Kbuild.in +++ b/src/platform/kernel/module/Kbuild.in @@ -1,8 +1,21 @@ +# 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) diff --git a/src/platform/kernel/module/Makefile.am b/src/platform/kernel/module/Makefile.am new file mode 100644 index 0000000000000000000000000000000000000000..2a2f85691620f47f59168c058f66056ecbb0c184 --- /dev/null +++ b/src/platform/kernel/module/Makefile.am @@ -0,0 +1,4 @@ + +# 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). diff --git a/src/platform/kernel/module/main.c b/src/platform/kernel/module/main.c index d7f94344f00cd42967a67b71dab75fc99390f12f..1269a3b76797d10b7cac07a6a47a2086442faaca 100644 --- a/src/platform/kernel/module/main.c +++ b/src/platform/kernel/module/main.c @@ -17,7 +17,7 @@ static int __init cap_init_module(void) static void __exit cap_fini_module(void) { - cap_exit(); + cap_fini(); return; }