test.cpp/Makefile

67 lines
1.2 KiB
Makefile
Raw Normal View History

2019-10-27 12:04:07 +00:00
CROSS_COMPILE ?=
TARGET_FILE ?= test
C_FLAGS += -Wall -Werror -DGNU -D__GNU__ -D__GCC__
C_FLAGS += -Os
C_FLAGS += -ffunction-sections
C_FLAGS += -fdata-sections
C_FLAGS += -std=c18
C_FLAGS += -pedantic
C_FLAGS += -pedantic-errors
C_FLAGS += -ggdb3
C_FLAGS += -Iinclude
CXXFLAGS += -Os
CXXFLAGS += -ggdb3
CXXFLAGS += -std=c++17
CXXFLAGS += -pedantic
CXXFLAGS += -pedantic-errors
CXXFLAGS += -ffunction-sections -fdata-sections
CXXFLAGS += -fno-implicit-inline-templates
LD_LIBS := -lc -lgcc
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)
-include $($(subst .o,.d,$(OBJS))
endif