Files
FastCarPlay/Makefile
T
2026-03-27 23:57:45 +02:00

70 lines
1.9 KiB
Makefile

# Compiler
CXX := g++
SRC_DIR := ./src
OUT_DIR := ./out
RES_DIR := $(SRC_DIR)/resource
GEN_DIR := $(SRC_DIR)/autogen
BUILD_DIR := $(OUT_DIR)/$(BUILD_TYPE)
# File lists
SRCS := $(shell find $(SRC_DIR) -type f -name '*.cpp')
OBJS=$(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.o,$(SRCS))
RES := $(shell find $(RES_DIR) -type f ! -name '*.h' ! -name '.*' -name '*.*')
RES_SRC := $(patsubst $(RES_DIR)/%,$(GEN_DIR)/%.cpp,$(RES))
# Targets
TARGET_NAME := app
# Build types
.PHONY: all debug release clean build
all: debug
LDOPTIONS := -lSDL2 -lSDL2_ttf -lavformat -lavcodec -lavutil -lswscale -lusb-1.0 -lssl -lcrypto
LDFLAGS :=
CXXCOMMON := -Wall -std=c++17 -Isrc
debug: BUILD_TYPE := debug
debug: CXXFLAGS := -g -O0 -DPROTOCOL_DEBUG -fsanitize=address -fno-omit-frame-pointer
debug: LDFLAGS += -fsanitize=address -fno-omit-frame-pointer
debug: TARGET := $(TARGET_NAME)-debug
debug: prepare
ifeq ($(shell uname -s), Darwin)
# macOS / clang
PLATFORM_LDFLAGS :=
else
# Linux / GCC (Pi or other)
PLATFORM_LDFLAGS := -Wl,--gc-sections -Wl,--as-needed
endif
release: BUILD_TYPE := release
release: CXXFLAGS := -O2 -ffast-math -march=native -fno-plt -fno-rtti -flto -fdata-sections -ffunction-sections -ffunction-sections -fomit-frame-pointer -fvisibility=hidden -pipe -DNDEBUG
release: LDFLAGS += -O2 -ffast-math -march=native -flto -Wl,-O1 $(PLATFORM_LDFLAGS)
release: TARGET := $(TARGET_NAME)
release: prepare
prepare: $(RES_SRC)
$(MAKE) BUILD_TYPE=$(BUILD_TYPE) TARGET=$(OUT_DIR)/$(TARGET) CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" build
build: $(TARGET)
$(GEN_DIR)/%.cpp: $(RES_DIR)/%
@mkdir -p $(GEN_DIR)
xxd -i -n $(basename $(notdir $<)) $< > $@
$(TARGET): $(OBJS)
@mkdir -p $(OUT_DIR)
$(CXX) $(LDFLAGS) $(OBJS) -o $(TARGET) $(LDOPTIONS)
@echo "Build complete: $(TARGET)"
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(dir $@)
$(CXX) $(CXXCOMMON) $(CXXFLAGS) -c $< -o $@
clean:
@rm -rf $(OUT_DIR)
@rm -rf $(GEN_DIR)
@echo "Clean complete"