# GNUmakefile

include Makefile

# ─── Adições ────────────────────────────────────────────────────
CXX_SOURCES := $(wildcard Src/*.cpp)
CXX_OBJECTS := $(addprefix $(BUILD_DIR)/,$(notdir $(CXX_SOURCES:.cpp=.o)))

C_INCLUDES += \
-ILib/YMF262/Inc \
-ISrc

CXX      = arm-none-eabi-g++
CXXFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) \
           -Wall -fdata-sections -ffunction-sections \
           -g -gdwarf-2 -std=c++17 -fno-exceptions -fno-rtti

vpath %.cpp Src

# Regra de compilação C++
$(BUILD_DIR)/%.o: %.cpp GNUmakefile | $(BUILD_DIR)
	$(CXX) -c $(CXXFLAGS) -MMD -MP -MF"$(@:%.o=%.d)" $< -o $@

# Sobrescreve a regra de link injetando CXX_OBJECTS
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) $(CXX_OBJECTS) Makefile
	$(CC) $(OBJECTS) $(CXX_OBJECTS) $(LDFLAGS) -o $@
	$(SZ) $@

# ─── Doxygen ────────────────────────────────────────────────────
docs/latex/refman.tex: $(wildcard Lib/YMF262/Inc/*.h) $(wildcard Lib/YMF262/Src/*.c) Doxyfile
	doxygen Doxyfile

docs/latex/refman.pdf: docs/latex/refman.tex
	$(MAKE) -C docs/latex

doxygen: docs/latex/refman.tex
doxygen-pdf: docs/latex/refman.pdf

.PHONY: doxygen doxygen-pdf