Makefile编写

SRCS = $(wildcard *.c)
SRC= $(SRCS)
TARGET =app
BUILD_DIR=build
OBJS := $(patsubst %.c,$(BUILD_DIR)/%.o,$(SRC))
PPS  :=$(OBJS:%.o=%.i)
CFLAGS +=-g
CFLAGS += -I./


.PHONY:  all echo prease
all:clean  prease $(OBJS)  $(PPS) 
        @echo ""
        @echo "buil target"
        gcc $(OBJS) $(CFLAGS) -o  $(TARGET)


$(OBJS):$(BUILD_DIR)/%.o:%.c
        gcc -c $< -o $@ 

$(PPS):$(BUILD_DIR)/%.i:%.c
        @gcc -E $< -o $@
        @echo "gcc -E $< -o $@"

clean:
        echo "cread build dir"
        rm -rf $(BUILD_DIR)
        -rm -rf $(TARGET) *.o

prease:
        -@mkdir -p  $(BUILD_DIR)

echo:
        @echo "target=$(TARGET)"
        @echo "OBJS = $(OBJS)"
        @echo "SRC = $(SRC)"

你可能感兴趣的:(GCC编译)