从网上抄了一个makfile用于自己的工程
1. 我的工程目录如下
2.修改后的makfile修改如下
MAKEFLAGS := -j $(shell nproc)
SRC_EXT := c
OBJ_EXT := o
CC := gcc
SRC_DIR := ./
WORKING_DIR := ./build
BUILD_DIR := $(WORKING_DIR)/obj
BIN_DIR := $(WORKING_DIR)/bin
WARNINGS := -Wall -Wextra \
-Wshadow -Wundef -Wmaybe-uninitialized -Wmissing-prototypes -Wno-discarded-qualifiers \
-Wno-unused-function -Wno-error=strict-prototypes -Wpointer-arith -fno-strict-aliasing -Wno-error=cpp -Wuninitialized \
-Wno-unused-parameter -Wno-missing-field-initializers -Wno-format-nonliteral -Wno-cast-qual -Wunreachable-code -Wno-switch-default \
-Wreturn-type -Wmultichar -Wformat-security -Wno-ignored-qualifiers -Wno-error=pedantic -Wno-sign-compare -Wno-error=missing-prototypes -Wdouble-promotion -Wclobbered -Wdeprecated \
-Wempty-body -Wshift-negative-value -Wstack-usage=2048 \
-Wtype-limits -Wsizeof-pointer-memaccess -Wpointer-arith
CFLAGS := -O0 -g $(WARNINGS)
# # Add simulator define to allow modification of source
# DEFINES := -D SIMULATOR=1
# Include simulator inc folder first so lv_conf.h from custom UI can be used instead
INC := -I./led/ -I./ -I./shell/
# LDFLAGS := -lSDL2 -lm
BIN := $(BIN_DIR)/test
COMPILE = $(CC) $(CFLAGS) $(INC) $(DEFINES)
# Automatically include all source files
SRCS := $(shell find $(SRC_DIR) -type f -name '*.c' -not -path '*/\.*')
OBJECTS := $(patsubst $(SRC_DIR)%,$(BUILD_DIR)/%,$(SRCS:.$(SRC_EXT)=.$(OBJ_EXT)))
all: default
# .o文件依赖.c文件, 循环推倒
$(BUILD_DIR)/%.$(OBJ_EXT): $(SRC_DIR)/%.$(SRC_EXT)
@echo 'Building project file: $<'
# 取目标的路径,递归创建目录
@mkdir -p $(dir $@)
# 编译各个文件,生成.o文件
@$(COMPILE) -c -o "$@" "$<"
default: $(OBJECTS)
# 递归创建bin目录
@mkdir -p $(BIN_DIR)
# 链接所有.o文件
$(CC) -o $(BIN) $(OBJECTS) $(LDFLAGS)
clean:
rm -rf $(WORKING_DIR)