c++ 一个经典的makefile实例 g++ (8.1是目标文件)

all:

CC = g++

BLD_DIR = ./build

InitMake := $(shell [ -d $(BLD_DIR) ] || mkdir -p $(BLD_DIR))

EXES = 8.1
SRCS = $(wildcard *.cpp)
OBJS = $(SRCS:%.cpp=$(BLD_DIR)/%.o)
DEPS = $(SRCS:%.cpp=$(BLD_DIR)/%.d)

CFLAGS +=
LDFLAGS +=

8.1: $(BLD_DIR)/8.1.o
        $(CC) -o $@ $^ $(LDFLAGS)

all: $(EXES)

$(OBJS): $(BLD_DIR)/%.o: %.cpp
        $(CC) $(CFLAGS) -o $@ -c $<

.PHONY: all clean

clean:
        $(RM) -rf $(BLD_DIR) 8.1

你可能感兴趣的:(linux)