61 lines
1.4 KiB
Makefile
61 lines
1.4 KiB
Makefile
# makefile inspired by:
|
|
# https://www.lucavall.in/blog/crafting-clean-maintainable-understandable-makefile-for-c-project
|
|
# https://archive.ph/2zHEM
|
|
|
|
debug ?= 0
|
|
NAME := yab-ssg
|
|
SRC_DIR := src
|
|
BUILD_DIR := build
|
|
INCLUDE_DIR := include
|
|
LIB_DIR := lib
|
|
BIN_DIR := bin
|
|
TESTS_DIR := tests
|
|
|
|
OBJS := $(patsubst %.c,%.o, $(wildcard $(SRC_DIR)/*.c) $(wildcard $(LIB_DIR)/**/*.c))
|
|
|
|
CC := clang
|
|
CFLAGS := -std=c99 -Wall -Wextra -Wpedantic
|
|
|
|
ifeq ($(debug), 1)
|
|
CFLAGS := $(CFLAGS) -g -O0
|
|
else
|
|
CFLAGS := $(CFLAGS) -Oz
|
|
endif
|
|
|
|
$(NAME): dir $(OBJS)
|
|
$(CC) $(CFLAGS) $(LDFLAGS) -o $(BIN_DIR)/$@ $(patsubst %, build/%, $(OBJS))
|
|
|
|
$(OBJS): dir
|
|
@mkdir -p $(BUILD_DIR)/$(@D)
|
|
@$(CC) $(CFLAGS) -o $(BUILD_DIR)/$@ -c $*.c
|
|
|
|
# Compiles and runs
|
|
run: dir $(OBJS) $(NAME)
|
|
@$(BIN_DIR)/$(NAME)
|
|
|
|
# Runs CUnit tests
|
|
# test: dir
|
|
# @$(CC) $(CFLAGS) -lcunit -o $(BIN_DIR)/$(NAME)_test $(TESTS_DIR)/*.c
|
|
# @$(BIN_DIR)/$(NAME)_test
|
|
|
|
# Runs tests
|
|
test: dir
|
|
@$(CC) $(CFLAGS) -o $(BIN_DIR)/$(NAME)_test $(TESTS_DIR)/*.c
|
|
@$(BIN_DIR)/$(NAME)_test
|
|
|
|
# Run valgrind memory checker on executable
|
|
check: $(NAME)
|
|
@sudo valgrind -s --leak-check=full --show-leak-kinds=all $(BIN_DIR)/$< --help
|
|
@sudo valgrind -s --leak-check=full --show-leak-kinds=all $(BIN_DIR)/$< --version
|
|
@sudo valgrind -s --leak-check=full --show-leak-kinds=all $(BIN_DIR)/$< -v
|
|
|
|
# Setup build and bin directories
|
|
dir:
|
|
@mkdir -p $(BUILD_DIR) $(BIN_DIR)
|
|
|
|
# Clean build and bin directories
|
|
clean:
|
|
@rm -rf $(BUILD_DIR) $(BIN_DIR)
|
|
|
|
.PHONY: check dir clean
|