当前位置:网站首页>Generic kernel and userspace Makefiles

Generic kernel and userspace Makefiles

2022-08-11 06:16:00 , as you like

User space Makefile, save as a Makefile

TARGET:=mainSOURCE_FILES:=$(wildcard *.c)INCLUDE_FILES:=$(wildcard *.h)INCLUDE_FILES+=$(wildcard *.h)OBJ:=$(patsubst %.c, %.o, $(SOURCE_FILES))C_FLAGS:= -g -Wall -O2 \-fsanitize=addressLINK_MODULES:=-pthreadLDFLAGS := -L../out/lib/#LINK_MODULES += -lmodulename$(TARGET):$(OBJ)gcc $(C_FLAGS) $(LINK_MODULES) $(LDFLAGS) -o $(TARGET) $(OBJ)%.o:%.c $(INCLUDE_FILES)gcc $(C_FLAGS) -c -o [email protected] $<.PHONY:cleanclean:rm -f $(TARGET) $(OBJ)

The Makefile of the Kernel space, save it as a Makefile

CONFIG_MODULE_SIG=nobj-m := icdev.oCURRENT_PATH:=$(shell pwd)#the current kernel version numberLINUX_KERNEL:=$(shell uname -r)#the absolute pathLINUX_KERNEL_PATH:=/usr/src/linux-headers-$(LINUX_KERNEL)#complie objectall:make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules #######cleanclean:make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean ######

Generic C++ Makefile with directory settings

########## Makefile COMMON #########c or c++EXTENSION =c#gcc or g++CC = gcc#exe nameTARGET = mpls_dump#source-file-direction space add-more-as: src src1 src2SUBDIR=file util.#.o file directionOBJ_DIR = out# (including .h file direction)#CPPFLAGS += -I ./incCPPFLAGS=-I.# link flagsLDFLAGS += -pthread# C flagsCFLAGS += -g -Wall -O2 \-fsanitize=address \-DHAVE_CONFIG_H#not change lines belowALL_SOURCES=$(foreach dir,$(SUBDIR), $(wildcard $(dir)/*.$(EXTENSION)))SOURCE_TO_OBJECT = ./$(OBJ_DIR)/$(subst .$(EXTENSION),.o,$(notdir $(1)))ALL_OBJECTS=$(foreach src,$(ALL_SOURCES),$(call SOURCE_TO_OBJECT,$(src)))define CREATE_OBJECT_TARGET$(call SOURCE_TO_OBJECT,$(1)) : $(1)if [ ! -d $(OBJ_DIR) ]; then mkdir -p $(OBJ_DIR); fi;\$(CC) -c $(CFLAGS) $(CPPFLAGS) -o [email protected] $$^endef$(TARGET):$(ALL_OBJECTS)$(CC) $(CFLAGS) $(LDFLAGS) -o [email protected] $^mv $(TARGET) $(OBJ_DIR)$(foreach src,$(ALL_SOURCES),$(eval $(call CREATE_OBJECT_TARGET,$(src))))all: $(TARGET).PHONY:cleanclean:rm -rf $(OBJ_DIR) $(TARGET)


原网站

版权声明
本文为[, as you like]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/223/202208110514299683.html