generated from wessel/boilerplate-c
68 lines
2.6 KiB
Makefile
68 lines
2.6 KiB
Makefile
# C++ compiler to use
|
|
CC := g++
|
|
|
|
# Directory mappings
|
|
SRC_DIR := src
|
|
LIB_DIR := lib
|
|
OBJ_DIR := obj
|
|
OUT_DIR := out
|
|
INC_DIR := include
|
|
TST_DIR := test
|
|
|
|
# Map all object and source files (C++)
|
|
SRC_FILES := $(wildcard $(SRC_DIR)/*.cpp) $(wildcard $(SRC_DIR)/**/*.cpp) $(wildcard $(LIB_DIR)/*.cpp) $(wildcard $(LIB_DIR)/**/*.cpp)
|
|
OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(filter $(SRC_DIR)/%.cpp,$(SRC_FILES))) \
|
|
$(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(filter $(SRC_DIR)/**/*.cpp,$(SRC_FILES))) \
|
|
$(patsubst $(LIB_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(filter $(LIB_DIR)/%.cpp,$(SRC_FILES))) \
|
|
$(patsubst $(LIB_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(filter $(LIB_DIR)/**/*.cpp,$(SRC_FILES)))
|
|
|
|
TST_FILES := $(wildcard $(TST_DIR)/*.cpp) $(wildcard $(TST_DIR)/**/*.cpp) $(wildcard $(LIB_DIR)/*.cpp) $(wildcard $(LIB_DIR)/**/*.cpp)
|
|
OBJ_TST_FILES := $(patsubst $(TST_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(filter $(TST_DIR)/%.cpp,$(TST_FILES))) \
|
|
$(patsubst $(TST_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(filter $(TST_DIR)/**/*.cpp,$(TST_FILES))) \
|
|
$(patsubst $(LIB_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(filter $(LIB_DIR)/%.cpp,$(TST_FILES))) \
|
|
$(patsubst $(LIB_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(filter $(LIB_DIR)/**/*.cpp,$(TST_FILES)))
|
|
|
|
# All optional libs and Cflags to append to the final command
|
|
LIBS :=
|
|
CFLAGS := -I$(INC_DIR)
|
|
DEBUGFLAGS :=
|
|
BUILDFLAGS :=
|
|
WARNFLAGS := -Wall -Wextra -Wconversion
|
|
|
|
# Special and default commands
|
|
.PHONY: clean help
|
|
.DEFAULT_GOAL := help
|
|
|
|
# Macro for creating object files (C++)
|
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
|
|
$(CC) -c -o $@ $< $(CFLAGS)
|
|
|
|
$(OBJ_DIR)/%.o: $(TST_DIR)/%.cpp
|
|
$(CC) -c -o $@ $< $(CFLAGS)
|
|
|
|
## All make commands ##
|
|
help: ## Lists all commands
|
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
|
|
|
clean: ## Clean up all object files and executables
|
|
rm -f $(OBJ_DIR)/*.o $(OUT_DIR)/*
|
|
|
|
dev: $(OBJ_FILES) ## Build, run and debug the project
|
|
$(CC) -o $(OUT_DIR)/$@ $^ $(CFLAGS) $(LIBS) $(DEBUGFLAGS) && ./out/dev
|
|
|
|
run: $(OBJ_FILES) ## Build and run the project
|
|
$(CC) -o $(OUT_DIR)/$@ $^ $(CFLAGS) $(LIBS) $(WARNFLAGS) && ./out/run
|
|
|
|
prod: $(OBJ_FILES) ## Build the project
|
|
$(CC) -o $(OUT_DIR)/$@ $^ $(CFLAGS) $(LIBS) $(BUILDFLAGS) $(WARNFLAGS)
|
|
|
|
test: $(OBJ_TST_FILES) ## Build tests and run them
|
|
$(CC) -o $(OUT_DIR)/$@ $^ $(CFLAGS) $(LIBS) && ./out/test \
|
|
--port 6060 --timeout 500
|
|
|
|
valgrind: $(OBJ_FILES) ## Build the project and run with Valgrind
|
|
$(CC) -o $(OUT_DIR)/$@ $^ $(CFLAGS) $(LIBS) && valgrind ./out/valgrind
|
|
|
|
strace: $(OBJ_FILES) ## Build the project and run with strace
|
|
$(CC) -o $(OUT_DIR)/$@ $^ $(CFLAGS) $(LIBS) && strace ./out/strace
|