100 lines
1.9 KiB
Makefile
100 lines
1.9 KiB
Makefile
# Inputs
|
|
|
|
SRC_DIRS := src
|
|
INC_DIRS := inc
|
|
LIBS := glew glfw3 freetype2 sdbus-c++
|
|
|
|
|
|
# Outputs
|
|
|
|
OUT_NAME := timer_overlay
|
|
BUILD_DIR := build
|
|
OFILE_DIR := $(BUILD_DIR)/objects
|
|
PREFIX ?= /usr/bin
|
|
|
|
|
|
# Project sources
|
|
|
|
LIB_INCLUDES := $(foreach lib, $(LIBS), $(shell pkg-config --cflags-only-I $(lib)))
|
|
INCLUDES := $(addprefix -I, $(INC_DIRS)) $(LIB_INCLUDES)
|
|
C_SOURCES := $(foreach dir, $(SRC_DIRS), $(wildcard $(dir)/*.c))
|
|
CXX_SOURCES := $(foreach dir, $(SRC_DIRS), $(wildcard $(dir)/*.cpp))
|
|
|
|
|
|
# Intermediary Outputs
|
|
|
|
OFILES := $(addprefix $(OFILE_DIR)/, $(notdir $(C_SOURCES:.c=.o) $(CXX_SOURCES:.cpp=.o)))
|
|
|
|
|
|
# Compiler flags
|
|
|
|
OPT := -O2
|
|
CPPFLAGS := $(INCLUDES) -MMD
|
|
CFLAGS := $(OPT) -Wall -Wextra -Wpedantic
|
|
CXXFLAGS := -std=c++17 $(OPT) -Wall -Wextra -Wpedantic
|
|
|
|
|
|
# Linker flags
|
|
|
|
LDFLAGS := $(foreach lib, $(LIBS), $(shell pkg-config --libs-only-L $(lib)))
|
|
LDLIBS := $(foreach lib, $(LIBS), $(shell pkg-config --libs-only-l $(lib)))
|
|
|
|
|
|
# Dependency files generated by the compiler
|
|
|
|
DEPENDS := $(OFILES:.o=.d)
|
|
|
|
|
|
# All output directories
|
|
|
|
ALL_DIRS := $(BUILD_DIR) $(OFILE_DIR)
|
|
|
|
|
|
# Use CC as linker if there are no CXX source files
|
|
|
|
ifeq ($(strip $(CXX_SOURCES)),)
|
|
LD := $(CC)
|
|
else
|
|
LD := $(CXX)
|
|
endif
|
|
|
|
|
|
|
|
.PHONY: all run clean install
|
|
|
|
all: $(BUILD_DIR)/$(OUT_NAME)
|
|
|
|
run: $(BUILD_DIR)/$(OUT_NAME)
|
|
$(BUILD_DIR)/$(OUT_NAME)
|
|
|
|
clean:
|
|
$(RM) -r $(ALL_DIRS)
|
|
|
|
install: $(BUILD_DIR)/$(OUT_NAME)
|
|
install -D $(BUILD_DIR)/$(OUT_NAME) $(PREFIX)
|
|
|
|
|
|
# Include generated header file dependencies
|
|
|
|
-include $(DEPENDS)
|
|
|
|
|
|
$(BUILD_DIR)/$(OUT_NAME): $(OFILES) | $(COMPILED_SHADERS) $(TEXTURES) $(MODELS) $(BUILD_DIR)
|
|
$(LD) $^ $(LDFLAGS) $(LDLIBS) -o $@
|
|
|
|
$(OFILE_DIR)/%.o: %.c | $(OFILE_DIR)
|
|
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
|
|
|
$(OFILE_DIR)/%.o: %.cpp | $(OFILE_DIR)
|
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
|
|
|
|
|
|
# Directories
|
|
|
|
$(ALL_DIRS):
|
|
mkdir -p $@
|
|
|
|
|
|
vpath %.c $(SRC_DIRS)
|
|
vpath %.cpp $(SRC_DIRS)
|