-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
51 lines (38 loc) · 942 Bytes
/
Copy pathMakefile
File metadata and controls
51 lines (38 loc) · 942 Bytes
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
# Compiler and flags
CC = gcc
CFLAGS = -Wall -Wextra -g
# Directories
OBJDIR = obj/
BINDIR = bin/
SRCDIR = src/
INSTALLDIR = /usr/local/bin/
# Output executable
EXECUTABLE = backlight-ctrl
TARGET = $(BINDIR)$(EXECUTABLE)
# Source and object files
SRCS = $(wildcard $(SRCDIR)*.c)
OBJS = $(patsubst $(SRCDIR)%.c,$(OBJDIR)%.o,$(SRCS))
# Possible targets
all: $(OBJDIR) $(BINDIR) $(TARGET)
install: all
sudo cp $(TARGET) $(INSTALLDIR)
uninstall:
sudo rm $(INSTALLDIR)$(EXECUTABLE)
# Ensure object directory exists
$(OBJDIR):
mkdir -p $(OBJDIR)
# Ensure binary directory exists
$(BINDIR):
mkdir -p $(BINDIR)
# Link object files into the final executable
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) -o $@ $^
# Compile .c source files to .o object files
$(OBJDIR)%.o: $(SRCDIR)%.c
$(CC) $(CFLAGS) -c $< -o $@
# Remove build artifacts
clean:
rm -f $(OBJS) $(TARGET)
rmdir $(OBJDIR)
rmdir $(BINDIR)
.PHONY: all clean install uninstall