Makefile学习

makefile中常用的函数:

http://linux.chinaunix.net/techdoc/develop/2009/07/09/1122854.shtml

SRC = $(wildcard *.c)  // 取目录下的.c文件
OBJS = $(patsubst %.c,%.o,$(SRC))      //将.c文件替换成.h文件

SRC = $(shell find . -iname "*.c")    //用shell命令得到.c文件
OBJS := $(addsuffix .o, $(basename $(notdir $(SRC)))) 

notdir: 取不是目录的文件

basename:去掉后缀

addsuffix :增加后缀

编译生成target

$(TARGET): $(OBJS)
    $(CC) -o $@ $(OBJECTS) $(CFLAGS) $(LDFLAGS)

%.o : %.c

  @$(CC) $(CFLAGS) $< -o $@

clean:
    rm -rf *.o $(TARGET)

all: clean $(TARGET)  多目标

CFLAGS:

-fno-builtin

-ffunction-sections

原文地址:https://www.cnblogs.com/chencesc/p/5849730.html