test.cpp/Makefile

58 lines
1.0 KiB
Makefile
Raw Permalink Normal View History

2019-10-27 12:04:07 +00:00
CROSS_COMPILE ?=
TARGET_FILE ?= test
2019-10-30 10:41:30 +00:00
CXXFLAGS += -O0
2019-10-27 12:04:07 +00:00
CXXFLAGS += -ggdb3
CXXFLAGS += -std=c++17
CXXFLAGS += -pedantic
CXXFLAGS += -pedantic-errors
CXXFLAGS += -ffunction-sections -fdata-sections
CXXFLAGS += -fno-implicit-inline-templates
2021-06-09 05:45:02 +00:00
CXXFLAGS += -Isrc
2019-10-27 12:04:07 +00:00
2019-10-27 12:24:19 +00:00
LD_LIBS := -lc -lgcc -lpthread
2019-10-27 12:04:07 +00:00
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
OBJ_DIR := obj
BIN_DIR := bin
SRC_DIR := src
CC_SRCS = $(wildcard $(SRC_DIR)/*.cc)
CC_OBJS = $(patsubst %.cc,$(OBJ_DIR)/%.o,$(notdir $(CC_SRCS)))
OBJS = $(CC_OBJS)
TARGET = $(BIN_DIR)/$(TARGET_FILE)
.PHONY: all
all: $(TARGET)
$(TARGET): $(OBJS) Makefile
@mkdir -p $(BIN_DIR)
$(CXX) $(LD_FLAGS) $(OBJS) $(LD_LIBS) -o $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cc
@mkdir -p $(dir $@)
@$(call makedep,$<,$@,$(patsubst %.cc,%.d,$(OBJ_DIR)/$(notdir $<)),$(CXXFLAGS))
$(CXX) -c $(CXXFLAGS) -o $@ $<
.PHONY: clean
clean:
rm -rf \
$(OBJS) \
$(patsubst %.o,%.d,$(OBJS)) \
$(TARGET)
define makedep
$(CXX) -MM -MF $3 -MP -MT $2 $4 $1
endef
ifneq ($(MAKECMDGOALS),clean)
2019-10-30 10:41:30 +00:00
-include $(subst .o,.d,$(OBJS))
2019-10-27 12:04:07 +00:00
endif