vmrcli/makefile

54 lines
1.1 KiB
Makefile
Raw Normal View History

2025-01-28 22:27:20 +00:00
# Program name
2024-06-25 04:34:28 +01:00
program = vmrcli
2025-01-28 22:27:20 +00:00
# Compiler
2024-06-25 04:34:28 +01:00
CC = gcc
2025-01-28 22:27:20 +00:00
# Directories
2024-06-25 04:34:28 +01:00
SRC_DIR := src
OBJ_DIR := obj
BIN_DIR := bin
2025-01-28 22:27:20 +00:00
# Executable and source/object files
2024-06-25 04:34:28 +01:00
EXE := $(BIN_DIR)/$(program).exe
SRC := $(wildcard $(SRC_DIR)/*.c)
OBJ := $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
2025-01-28 22:27:20 +00:00
# Conditional compilation flags for logging
LOG_USE_COLOR ?= yes
ifeq ($(LOG_USE_COLOR), yes)
CPPFLAGS := -Iinclude -MMD -MP -DLOG_USE_COLOR
else
CPPFLAGS := -Iinclude -MMD -MP
endif
2025-01-28 22:27:20 +00:00
# Compiler and linker flags
CFLAGS = -O -Wall -W -pedantic -ansi -std=c2x
2024-06-25 04:34:28 +01:00
LDFLAGS := -Llib
LDLIBS := -lm
2025-01-28 22:27:20 +00:00
# Phony targets
2024-06-25 04:34:28 +01:00
.PHONY: all clean
2025-01-28 22:27:20 +00:00
# Default target
2024-06-25 04:34:28 +01:00
all: $(EXE)
2025-01-28 22:27:20 +00:00
# Link the executable
2024-06-25 04:34:28 +01:00
$(EXE): $(OBJ) | $(BIN_DIR)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
2025-01-28 22:27:20 +00:00
# Compile source files to object files
2024-06-25 04:34:28 +01:00
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
2025-01-28 22:27:20 +00:00
# Create necessary directories
2024-06-25 04:34:28 +01:00
$(BIN_DIR) $(OBJ_DIR):
2024-06-25 16:45:46 +01:00
pwsh -Command New-Item -Path $@ -ItemType Directory
2024-06-25 04:34:28 +01:00
2025-01-28 22:27:20 +00:00
# Clean up generated files
2024-06-25 04:34:28 +01:00
clean:
2025-02-17 15:25:01 +00:00
pwsh -Command Remove-Item -Recurse $(BIN_DIR), $(OBJ_DIR) -force
2024-06-25 04:34:28 +01:00
2025-01-28 22:27:20 +00:00
# Include dependency files
2024-06-25 04:34:28 +01:00
-include $(OBJ:.o=.d)