From 888e4b1d8a9c7fa32d624774326d602deb9a754c Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Wed, 10 Jul 2019 22:54:27 +0200 Subject: Added Makefile to build all software modules The modules can be built inside the 'vanilla' kernel source tree or 'out-of-tree'. Furthermore, the losetup utility can be built. --- Makefile | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9ac1860 --- /dev/null +++ b/Makefile @@ -0,0 +1,83 @@ +#------------------------------------------------------------------------------ +# Makefile - builds the entire project with all subprojects +#------------------------------------------------------------------------------ +# author: Manuel Bentele +# date : 10.07.2019 +#------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ +# Global configuration (file paths and config) +#------------------------------------------------------------------------------ +KERNEL_SRC_DIR := $(shell pwd)/implementation/loop +KERNEL_HDR_DIR := /lib/modules/$(shell uname -r)/build +LOSETUP_SRC_DIR := $(shell pwd)/implementation/losetup +KERNEL_MOD_CONFIG := $(shell pwd)/config/kernel-qcow2_x86-64_module.config +LOCAL_MOD_CONFIG += CONFIG_BLK_DEV_LOOP=m +LOCAL_MOD_CONFIG += CONFIG_BLK_DEV_LOOP_FILE_FMT_RAW=m +LOCAL_MOD_CONFIG += CONFIG_BLK_DEV_LOOP_FILE_FMT_QCOW=m + +BUILD ?= vanilla +KERNEL_DIR ?= $(KERNEL_SRC_DIR) +CONFIG ?= KCONFIG_CONFIG=$(KERNEL_MOD_CONFIG) +TARGET_PATH_PREFX ?= drivers/block/loop/ + +ifeq ($(BUILD),out-of-tree) +PATCH = patch +KERNEL_DIR = $(KERNEL_HDR_DIR) +CONFIG = $(LOCAL_MOD_CONFIG) M=$(KERNEL_SRC_DIR)/drivers/block/loop +TARGET_PATH_PREFX = +endif + +#------------------------------------------------------------------------------ +# Target definitions +#------------------------------------------------------------------------------ +all: modules losetup +clean: clean_modules clean_losetup +modules: loop.ko loop_file_fmt_raw.ko loop_file_fmt_qcow.ko + +clean_modules: + $(call print_heading,"Clean all kernel modules") + @$(MAKE) --no-print-directory -C $(KERNEL_DIR) $(CONFIG) clean + +patch: + $(call print_heading, "Patch kernel headers") + @sudo cp -f $(KERNEL_SRC_DIR)/include/uapi/linux/loop.h \ + $(KERNEL_HDR_DIR)/include/uapi/linux/loop.h + @sudo cp -f $(KERNEL_SRC_DIR)/drivers/block/Kconfig \ + $(KERNEL_HDR_DIR)/drivers/block/Kconfig + @sudo mkdir -p $(KERNEL_HDR_DIR)/drivers/block/loop + @sudo cp -f $(KERNEL_SRC_DIR)/drivers/block/loop/loop_main.h \ + $(KERNEL_HDR_DIR)/drivers/block/loop/loop_main.h + @sudo cp -f $(KERNEL_SRC_DIR)/drivers/block/loop/loop_file_fmt.h \ + $(KERNEL_HDR_DIR)/drivers/block/loop/loop_file_fmt.h + @sudo cp -f $(KERNEL_SRC_DIR)/drivers/block/loop/Kconfig \ + $(KERNEL_HDR_DIR)/drivers/block/loop/Kconfig + +loop.ko: +loop_file_fmt_raw.ko: +loop_file_fmt_qcow.ko: + +%.ko: $(PATCH) + $(call print_heading,"Build $@ kernel module") + @$(MAKE) --no-print-directory -C $(KERNEL_DIR) $(CONFIG) \ + $(TARGET_PATH_PREFX)$@ + +losetup: + $(call print_heading,"Build $@ utility") + @cd $(LOSETUP_SRC_DIR) && \ + ./tools/config-gen all && \ + $(MAKE) --no-print-directory losetup + +clean_losetup: + $(call print_heading,"Clean $@ utility") + @cd $(LOSETUP_SRC_DIR) && \ + $(MAKE) --no-print-directory clean + +#------------------------------------------------------------------------------ +# Function definitions +#------------------------------------------------------------------------------ +define print_heading + @echo "#--------------------------------------------------------------" + @echo "# [BUILD: $(BUILD)] $(1)" + @echo "#--------------------------------------------------------------" +endef -- cgit v1.2.3-55-g7522