内核模块模板
#*******************************************************************************
# xxx Co., Ltd. All Right Reserved.
# Author :
# Version : V1.0.0 2020.10.21
# Description :
# Note : gaoyang3513@163.com Modified 2020.10.21
#*******************************************************************************
#*******************************************************************************
# Path information
#*******************************************************************************
LOCAL_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
KERNEL_DIR ?= /home/gaoyang3513/Source/06-SG20x/02-Projects/SDK_SG200x_V2/linux_5.10/build/sg2000_milkv_duos_glibc_arm64_sd
#KERNEL_DIR ?= $(HOME)/Source/06-SG20x/02-Projects/SDK_SG200x_V2/linux_5.10/build/sg2000_milkv_duos_glibc_arm64_sd/
# ParDirectory
LIBS_DIR :=
INCLUDE_DIR :=
# Subdirectory
# Output
OUTPUT_DIR := $(LOCAL_DIR)/output
INSTALL_DIR ?= $(LOCAL_DIR)/__install
#*******************************************************************************
# Variables
#*******************************************************************************
MULTI_CORES ?= $(shell grep -c ^processor /proc/cpuinfo)
MOD_NAME := test_panic
#*******************************************************************************
# Compile configure
#*******************************************************************************
ARCH ?= arm64
CROSS_COMPILE ?= ${HOME}/Source/06-SG20x/02-Projects/SDK_SG200x_V2/host-tools/gcc/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
AR := $(CROSS_COMPILE)ar
STRIP := $(CROSS_COMPILE)strip
OBJDUMP := $(CROSS_COMPILE)objdump
export ARCH CROSS_COMPILE
#*******************************************************************************
# Targets
#*******************************************************************************
.PHONY: all install clean
ifeq ($(KERNELRELEASE),)
all: init
@$(MAKE) modules -C $(KERNEL_DIR) M=$(LOCAL_DIR) -j$(MULTI_CORES)
# @$(MAKE) modules_install -C $(KERNEL_DIR) M=$(LOCAL_DIR) INSTALL_MOD_PATH=$(KERNEL_DIR)/_install_modules INSTALL_MOD_DIR=private
@$(OBJDUMP) -hdS test_ps.o > test_ps.dmp
clean:
# File
@for n in *.o *.ko *.mod.c *.mod *.cmd *.symvers *.order; do \
find $(LOCAL_DIR) -type f -name $$n -exec rm {} \;;\
done
# Directory
@if [ -d $(LOCAL_DIR)/output ]; then rm -rf $(LOCAL_DIR)/output; fi;
@if [ -d $(LOCAL_DIR)/__install ]; then rm -rf $(LOCAL_DIR)/__install; fi;
@if [ -d $(LOCAL_DIR)/.tmp_versions ]; then rm -rf $(LOCAL_DIR)/.tmp_versions; fi;
install:
@mkdir -p $(INSTALL_DIR)/lib/modules/private
@install -m 644 -D $(MOD_NAME).ko $(INSTALL_DIR)/lib/modules/private;
init:
@mkdir -p $(OUTPUT_DIR)
else
obj-m := $(MOD_NAME).o
$(MOD_NAME)-objs := test_ps.o
INC_DIRS :=
ccflags-y +=
EXTRA_CFLAGS += -Wno-error=date-time # Fix compile error on gcc 4.9 and later
EXTRA_CFLAGS += -Wno-date-time -g
endif # ifeq ($(KERNELRELEASE),)
#*******************************************************************************
# xxx Co., Ltd. All Right Reserved.
# Author :
# Version : V1.0.0 2020.10.21
# Description :
# Note : gaoyang3513@163.com Modified 2020.10.21
#*******************************************************************************
#*******************************************************************************
# Path information
#*******************************************************************************
LOCAL_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
KERNEL_DIR ?= /home/gaoyang3513/Source/06-SG20x/02-Projects/SDK_SG200x_V2/linux_5.10/build/sg2000_milkv_duos_glibc_arm64_sd
#KERNEL_DIR ?= $(HOME)/Source/06-SG20x/02-Projects/SDK_SG200x_V2/linux_5.10/build/sg2000_milkv_duos_glibc_arm64_sd/
# ParDirectory
LIBS_DIR :=
INCLUDE_DIR :=
# Subdirectory
SUB_DIRS := $(LOCAL_DIR)/01-Panic
# Output
OUTPUT_DIR := $(LOCAL_DIR)/output
INSTALL_DIR ?= $(LOCAL_DIR)/__install
#*******************************************************************************
# Variables
#*******************************************************************************
MULTI_CORES ?= $(shell grep -c ^processor /proc/cpuinfo)
MOD_NAME := test_panic
#*******************************************************************************
# Compile configure
#*******************************************************************************
ARCH ?= arm64
CROSS_COMPILE ?= ${HOME}/Source/06-SG20x/02-Projects/SDK_SG200x_V2/host-tools/gcc/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
AR := $(CROSS_COMPILE)ar
STRIP := $(CROSS_COMPILE)strip
export ARCH CROSS_COMPILE
#*******************************************************************************
# Targets
#*******************************************************************************
.PHONY: init all clean install menuconfig
ifeq ($(KERNELRELEASE),)
all: init
@for sub in $(SUB_DIRS); do \
$(MAKE) -C $$sub || exit "$$?"; \
$(MAKE) install INSTALL_DIR=$(OUTPUT_DIR) -C $$sub || exit "$$?"; \
done;
clean:
@for sub in $(SUB_DIRS); do \
$(MAKE) clean -C $$sub || exit "$$?"; \
done;
# Directory
@if [ -d $(LOCAL_DIR)/output ]; then rm -rf $(LOCAL_DIR)/output; fi;
@if [ -d $(LOCAL_DIR)/__install ]; then rm -rf $(LOCAL_DIR)/__install; fi;
install:
@mkdir -p $(INSTALL_DIR)
@cp -arf $(OUTPUT_DIR)/. $(INSTALL_DIR)
init:
@mkdir -p $(OUTPUT_DIR);
else
# called from kernel build system: just declare what our modules are
obj-y += $(SUB_DIRS)
INC_DIRS :=
subdir-ccflags-y += $(addprefix -I, $(INC_DIRS))
endif # ifeq ($(KERNELRELEASE),)