59 lines
1.1 KiB
Makefile
59 lines
1.1 KiB
Makefile
CROSS_COMPILE ?=
|
|
|
|
TARGET_FILE ?= bootloader
|
|
|
|
CXXFLAGS += -O0
|
|
CXXFLAGS += -ggdb3
|
|
CXXFLAGS += -std=c++17
|
|
CXXFLAGS += -pedantic
|
|
CXXFLAGS += -pedantic-errors
|
|
CXXFLAGS += -ffunction-sections -fdata-sections
|
|
CXXFLAGS += -fno-implicit-inline-templates
|
|
CXXFLAGS += -Isrc
|
|
CXXFLAGS += -std=c++20
|
|
|
|
|
|
LD_LIBS := -lc -lgcc -lpthread
|
|
|
|
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
|