1# Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED. 2# 3# This program is free software; you can redistribute it and/or 4# modify it under the terms of the GNU General Public License 5# as published by the Free Software Foundation; either version 2 6# of the License, or (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program; if not, write to the Free Software 15# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 17#******************************************************************************* 18#The rule of make Linux kernel module 19#******************************************************************************* 20 21$(TARGET)-objs = $(SRCS:%.c=%.o) 22$(MOD_NAME)-objs = $(SRCS_O:%.c=%.o) 23 24ifneq ($(KERNELRELEASE),) 25 obj-m += $(TARGET).o 26 obj-m += $(MOD_NAME).o 27endif 28 29EXTRA_CFLAGS += $(MKP_CFLAGS) 30KBUILD_EXTRA_SYMBOLS += $(HI_KBUILD_EXTRA_SYMBOLS) 31 32#******************************************************************************* 33#The file need tobe clean, when make clean 34CLEAN_FILE := $(SRCS:%.c=%.o) 35CLEAN_FILE += $(SRCS:%.c=%.o.cmd) 36CLEAN_FILE += $(join $(dir $(SRCS)), $(patsubst %.c, .%.o.cmd, $(notdir $(SRCS)))) 37CLEAN_FILE += $(TARGET).mod.c \ 38 $(TARGET).ko.cmd \ 39 $(TARGET).ko \ 40 $(TARGET).o \ 41 $(TARGET).mod.o \ 42 .$(TARGET).ko.cmd \ 43 .$(TARGET).o.cmd \ 44 .$(TARGET).mod.o.cmd 45CLEAN_FILE += $(MOD_NAME).mod.c \ 46 *.ko \ 47 *.o \ 48 *.mod \ 49 .*.cmd \ 50CLEAN_FILE += ./*/*.o ./*/.*.cmd 51 52#******************************************************************************* 53.PHONY: default clean 54default: 55 @echo -e "\e[0;32;1m--Compiling '$(TARGET)'... Configs as follow:\e[0;36;1m" 56 @echo "---- USER_CROSS=$(CROSS) KERNEL_CROSS=$(CROSS_COMPILE)" 57 @echo ---- HIARCH=$(HIARCH), ARCH=$(ARCH), HICHIP=$(HICHIP), CVER=$(CVER), DBG=$(HIDBG), HI_FPGA=$(HI_FPGA) 58 @echo ---- CPU_TYPE=$(CPU_TYPE) 59 @echo ---- MPP_CFLAGS=$(MPP_CFLAGS) 60 @echo ---- MKP_CFLAGS=$(MKP_CFLAGS) 61 @echo ---- SDK_PATH=$(SDK_PATH) , PARAM_FILE=$(PARAM_FILE) 62 @echo ---- KERNEL_ROOT=$(KERNEL_ROOT) 63 @echo ---- ARCH_ROOT=$(ARCH_ROOT), ARCH_HAL=$(ARCH_HAL) 64 @echo ---- HIGDB=$(HIGDB) 65 @echo ---- COMPILER_TRIPLE=$(COMPILER_TRIPLE) 66 @@echo -e "\e[0m" 67 #@$(MAKE) -C $(KERNEL_ROOT) M=$(PWD) $(COMPILER_TRIPLE) V=10 modules -j 24 68 @$(MAKE) -C $(KERNEL_ROOT) M=$(PWD) $(COMPILER_TRIPLE) $(COMPILER_TRIPLE) V=10 modules -j 24 69ifeq ($(HIGDB), n) 70ifeq ($(OHOS_LITE), y) 71 @$(CROSS_COMPILE)strip --strip-unneeded $(TARGET).ko 72 @$(CROSS_COMPILE)strip --strip-unneeded $(MOD_NAME).o 73else 74 @$(CROSS_PATH)/$(CROSS_COMPILE)strip --strip-unneeded $(TARGET).ko 75 @$(CROSS_PATH)/$(CROSS_COMPILE)strip --strip-unneeded $(MOD_NAME).o 76endif 77endif 78 @mkdir -p $(REL_KO) && cp -rf $(TARGET).ko $(REL_KO) && chmod 777 $(REL_KO)/load* 79# @mkdir -p $(REL_INC) && $(call maco_cp_file,$(INC_FILE),$(REL_INC)) 80ifeq ($(CONFIG_DRIVER_SPACE_TYPE),kernel_space) 81 @mkdir -p $(REL_OBJ) && cp -rf $(MOD_NAME).o $(REL_OBJ) 82 @mkdir -p $(REL_INI) && cp -rf $(INIT_FILE) $(REL_INI) 83endif 84 85clean: 86 @rm -f $(CLEAN_FILE) 87 @rm -f $(REL_KO)/$(TARGET).ko 88ifeq ($(CONFIG_DRIVER_SPACE_TYPE),kernel_space) 89 @rm -f $(REL_OBJ)/$(MOD_NAME).o 90 @rm -f $(REL_INI)/$(shell basename $(INIT_FILE)) 91endif 92 @rm .tmp_versions -rf 93 @rm Module.symvers -f 94 @rm modules.order -f 95