Files
fsync/Makefile
2026-05-18 14:05:06 -04:00

58 lines
1.4 KiB
Makefile

CC ?= gcc
CFLAGS ?= -Wall -Wextra -O2 -fPIC
LDFLAGS ?= -lhiredis -lcrypto -lrabbitmq -lcjson
SRC_DIR := src
BUILD_DIR := build
TARGET := fsync-monitor
SOURCES := $(wildcard $(SRC_DIR)/*.c)
OBJECTS := $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SOURCES))
HEADERS := $(wildcard $(SRC_DIR)/*.h)
.PHONY: all build clean run install help
all: build
help:
@echo "Fsync - File System Monitor with RabbitMQ"
@echo ""
@echo "Available targets:"
@echo " make build - Build the fsync monitor"
@echo " make run - Run the monitor (requires root)"
@echo " make clean - Clean build artifacts"
@echo " make install - Install to /usr/local/bin"
@echo " make help - Show this help message"
build: $(BUILD_DIR) $(BUILD_DIR)/$(TARGET)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c $(HEADERS)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/$(TARGET): $(OBJECTS)
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@
@echo "Built: $@"
run: build
@if [ "$$(id -u)" != "0" ]; then \
echo "Error: fsync-monitor requires root privileges"; \
exit 1; \
fi
./$(BUILD_DIR)/$(TARGET) $(ARGS)
install: build
@if [ "$$(id -u)" != "0" ]; then \
echo "Error: Installation requires root privileges"; \
exit 1; \
fi
install -m 755 $(BUILD_DIR)/$(TARGET) /usr/local/bin/
@echo "Installed to /usr/local/bin/$(TARGET)"
clean:
rm -rf $(BUILD_DIR)
@echo "Cleaned build artifacts"
.SILENT: help