hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: c424affc4fb8a29717c389ae44bed96f5981732a (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
61
62
63
64
65
66
67
68
69
70
71
72
73
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
bashdir := $(DESTDIR)$(PREFIX)/share/bash-completion/completions
zshdir := $(DESTDIR)$(PREFIX)/share/zsh/site-functions
fishdir := $(DESTDIR)$(PREFIX)/share/fish/vendor_completions.d

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

test: $(TARGET)
	@sh tests.sh

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
	install -d $(bashdir) $(zshdir) $(fishdir)
	./$(TARGET) --completions bash > $(bashdir)/mkproj
	./$(TARGET) --completions zsh  > $(zshdir)/_mkproj
	./$(TARGET) --completions fish > $(fishdir)/mkproj.fish

uninstall:
	rm -f $(bindir)/$(TARGET)
	rm -f $(mandir)/mkproj.1
	rm -f $(bashdir)/mkproj
	rm -f $(zshdir)/_mkproj
	rm -f $(fishdir)/mkproj.fish

.PHONY: all check test clean install uninstall