-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
48 lines (39 loc) · 1.07 KB
/
Makefile
File metadata and controls
48 lines (39 loc) · 1.07 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
# credit to github/WladimirBec for makefile structure
DESTDIR ?=
PREFIX ?= /usr
BLDD := $(abspath ./bld)
CC ?= clang
CFLAGS := -Wall -Wextra -Werror \
-D_POSIX_C_SOURCE=200809L \
-std=c23 \
$(if $(filter 1,$(DEBUG)),-O0 -g,-O3 -flto -pipe)
LDFLAGS := $(if $(filter 1,$(DEBUG)),,-static)
SRCS := main.c util.c zbm.c
OBJS := $(patsubst %.c,$(BLDD)/%.o,$(SRCS))
TARGET := zkpurge
$(BLDD)/$(TARGET): $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
$(BLDD):
@ mkdir -p $@
$(OBJS): $(BLDD)/%.o: %.c | $(BLDD)
$(CC) $(CFLAGS) -c $< -o $@
install: $(BLDD)/$(TARGET)
install -Dm755 $< $(DESTDIR)$(PREFIX)/bin/$(TARGET)
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/$(TARGET)
clean:
rm -fr $(BLDD)
rm -f compile_commands.json
compdb:
@ ( \
echo "["; \
for src in $(SRCS); do \
echo " {"; \
echo " \"directory\": \"$(BLDD)\","; \
echo " \"file\": \"../$$src\","; \
echo " \"command\": \"$(CC) $(CFLAGS) -c $$src -o $(BLDD)/$${src%.c}.o\""; \
echo " },"; \
done; \
echo "]"; \
) > ./compile_commands.json
.PHONY: install uninstall clean compdb