hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 327856d5288ca5b9af70abdde437c784f56ff950 (plain)
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
CC := clang
STD := c17

DEBUG ?= 1
SANITIZE ?= 1

CFLAGS := -std=$(STD)          \
          -Wall                \
          -Wextra              \
          -Wshadow             \
          -Wpedantic           \
          -Wconversion         \
          -Wstrict-prototypes  \
          -Wsign-conversion    \
          -Wmissing-prototypes

ifeq ($(DEBUG),1)
CFLAGS += -g -fno-omit-frame-pointer
else
CFLAGS += -O2
endif

ifeq ($(SANITIZE),1)
CFLAGS += -fsanitize=address,undefined
LDFLAGS += -fsanitize=address,undefined
endif

TARGET := mkproj
SRC := mkproj.c

PREFIX ?= /usr/local
bindir := $(DESTDIR)$(PREFIX)/bin
mandir := $(DESTDIR)$(PREFIX)/share/man/man1

all: $(TARGET)

$(TARGET): $(SRC)
	$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)

check:
	bear -- make clean all
	cppcheck --enable=warning,style,performance,portability \
		 --project=compile_commands.json                \
		 --error-exitcode=1

clean:
	rm -rf $(TARGET) $(TARGET).dSYM

install: mkproj.1
	$(MAKE) DEBUG=0 SANITIZE=0 clean all
	install -d $(bindir)
	install -m 755 $(TARGET) $(bindir)/$(TARGET)
	install -d $(mandir)
	install -m 644 mkproj.1 $(mandir)/mkproj.1

uninstall:
	rm -f $(bindir)/$(TARGET)
	rm -f $(mandir)/mkproj.1

.PHONY: all check clean install uninstall