-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
71 lines (55 loc) · 1.75 KB
/
Copy pathMakefile
File metadata and controls
71 lines (55 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Compiler and flags
CC = gcc
CFLAGS = -Wall -Wextra -O2
LDFLAGS =
# Target executable
TARGET = fawatch
# Source files
SRCS = main.c
OBJS = $(SRCS:.c=.o)
# Installation paths
PREFIX ?= /usr/local
BINDIR = $(PREFIX)/bin
SCRIPTS = fasync.sh
# Systemd paths
SYSTEMDDIR = /etc/systemd/system
SERVICE_FILE = fasync@.service
# Configuration paths
CONFIGDIR = /etc/default
CONFIG_EXAMPLE = fasync-example
# Default target
all: $(TARGET)
# Link object file into executable
$(TARGET): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $^
# Compile source file into object file
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
# Install: copy binaries, scripts, systemd template and config example from repo
install: all
# Install executable and script
install -m 755 -d $(BINDIR)
install -m 755 $(TARGET) $(BINDIR)
install -m 755 $(SCRIPTS) $(BINDIR)
# Install systemd service template from repository
install -m 755 -d $(SYSTEMDDIR)
install -m 644 $(SERVICE_FILE) $(SYSTEMDDIR)/$(SERVICE_FILE)
# Install configuration example if not already present
install -m 755 -d $(CONFIGDIR)
@if [ ! -f $(CONFIGDIR)/$(CONFIG_EXAMPLE) ]; then \
install -m 644 $(CONFIG_EXAMPLE) $(CONFIGDIR)/$(CONFIG_EXAMPLE); \
echo "Installed configuration example to $(CONFIGDIR)/$(CONFIG_EXAMPLE)"; \
fi
# Reload systemd configuration if systemctl is available
if command -v systemctl >/dev/null 2>&1; then systemctl daemon-reload; fi
# Uninstall: remove all installed files and reload systemd
uninstall:
cd $(BINDIR) && rm -f $(TARGET) $(SCRIPTS)
rm -f $(SYSTEMDDIR)/$(SERVICE_FILE)
rm -f $(CONFIGDIR)/$(CONFIG_EXAMPLE)
if command -v systemctl >/dev/null 2>&1; then systemctl daemon-reload; fi
# Clean build artifacts
clean:
rm -f $(OBJS) $(TARGET)
# Phony targets (not files)
.PHONY: all clean install uninstall