[修改] 支持Makefile集成

This commit is contained in:
gaoyang3513
2024-01-21 14:44:35 +00:00
parent cf936361bc
commit cd7f5fefe0
3 changed files with 108 additions and 10 deletions

8
.gitignore vendored
View File

@ -1,3 +1,11 @@
*.o *.o
*.mod *.mod
*.cmd
Module.symvers
modules.order
output/
_install/

View File

@ -1,25 +1,51 @@
# All Right Reserved.
# Author : gaoyang3513@outlook.com
# Version : V1.0.0 202x.01.01
# Description :
# Note :
# ---------------------------------------------------------------------------
# Path information
LOCAL_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
# Subdirectory
# Output directories
OUTPUT_DIR ?= $(LOCAL_DIR)/output
INSTALL_DIR ?= $(LOCAL_DIR)/_install
# ---------------------------------------------------------------------------
# Variables
MULTI_CORES ?= $(shell grep -c ^processor /proc/cpuinfo)
# ---------------------------------------------------------------------------
# Compile configure
# ---------------------------------------------------------------------------
# Source and oject files
ifneq ($(KERNELRELEASE),) ifneq ($(KERNELRELEASE),)
obj-m := char_static.o obj-m := char_static.o
# ---------------------------------------------------------------------------
# Targets
else # KERNELRELEASE else # KERNELRELEASE
ifneq ($(filter $(BOARD),mikv-Duo),) ifneq ($(filter $(BOARD),mikv-Duo),)
KERNELDIR ?= ${HOME}/Source/10-CV1800/01-MilkDuo/02-Project/SDK_CV1800_BR2/linux_5.10/build/cv1800b_milkv_duo_sd KERNELDIR := ${HOME}/Source/10-CV1800/01-MilkDuo/02-Project/SDK_CV1800_BR2/linux_5.10/build/cv1800b_milkv_duo_sd
ROOTFS ?= ${HOME}/nfs/rootfs ROOTFS := ${HOME}/nfs/rootfs
else ifneq ($(filter $(ARCH),arm64),)
KERNELDIR ?= ${HOME}/Source/04-RK3568/02-Projects/SDK_RK3568_Linux_LBCat2/kernel
ROOTFS ?= ${HOME}/nfs/rootfs
else else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build KERNELDIR ?= /lib/modules/$(shell uname -r)/build
endif endif
PWD := $(shell pwd) .PHONY: all clean init
all:
@$(MAKE) -C $(KERNELDIR) M=$(PWD) modules -j$(MULTI_CORES);
install:
@$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install INSTALL_MOD_PATH=$(INSTALL_DIR)
modules:
@$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
@$(MAKE) -C $(KERNELDIR) M=$(PWD) INSTALL_MOD_PATH=$(ROOTFS) modules_install
clean: clean:
@rm -rf *.o *.ko .*.cmd *.mod* modules.order Module.symvers .tmp_versions @rm -rf *.o *.ko .*.cmd *.mod* modules.order Module.symvers .tmp_versions

64
Makefile Normal file
View File

@ -0,0 +1,64 @@
# All Right Reserved.
# Author : gaoyang3513@outlook.com
# Version : V1.0.0 202x.01.01
# Description :
# Note :
# ---------------------------------------------------------------------------
# Path information
LOCAL_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
# Subdirectory
MODEL_CHAR := $(LOCAL_DIR)/01-Char
# Output directories
OUTPUT_DIR ?= $(LOCAL_DIR)/output
INSTALL_DIR ?= $(LOCAL_DIR)/_install
# ---------------------------------------------------------------------------
# Variables
MULTI_CORES ?= $(shell grep -c ^processor /proc/cpuinfo)
SUB_DIRS := 01-Char/
# ---------------------------------------------------------------------------
# Compile configure
# ---------------------------------------------------------------------------
# Source and oject files
ifneq ($(KERNELRELEASE),)
obj-y := $(SUB_DIRS)
# ---------------------------------------------------------------------------
# Targets
else # KERNELRELEASE
ifneq ($(filter $(BOARD),mikv-Duo),)
KERNELDIR := ${HOME}/Source/10-CV1800/01-MilkDuo/02-Project/SDK_CV1800_BR2/linux_5.10/build/cv1800b_milkv_duo_sd
ROOTFS := ${HOME}/nfs/rootfs
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
endif
.PHONY: all clean init
all: init
@for sub in $(SUB_DIRS); do \
$(MAKE) -C $${sub}; \
$(MAKE) -C $${sub} install INSTALL_DIR=$(OUTPUT_DIR); \
done;
clean:
@for sub in $(SUB_DIRS); do \
$(MAKE) -C $${sub} clean; \
done;
install:
@mkdir -p $(INSTALL_DIR);
@cp -arf $(OUTPUT_DIR)/. $(INSTALL_DIR);
init:
@mkdir -p $(OUTPUT_DIR);
endif # KERNELRELEASE