-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
53 lines (40 loc) · 1.21 KB
/
Makefile
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
CC = clang
RM = rm -rf
INCLUDE = include
CFLAGS = -Wall -Wpedantic -Wextra -std=c11 -O3 -I$(INCLUDE)
BINARY = brain
OBJSDIR = objs
SRCSDIR = src
BINDIR = bin
INSTDIR = /usr/local/stow/$(BINARY)
SRCS := $(wildcard src/*.c)
OBJS := $(patsubst %.c, $(OBJSDIR)/%.o, $(notdir $(SRCS)))
DEPS := $(patsubst %.c, %.d, $(SRCS))
ifdef DEBUG
CFLAGS += -ggdb -fsanitize=address,undefined
endif
$(BINARY): | $(BINDIR) $(OBJSDIR) $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(BINDIR)/$(BINARY)
$(BINDIR):
@echo Creating $(abspath $(BINDIR))
mkdir -p $(BINDIR)
$(OBJSDIR):
@echo $(DEPS) - $(SRCS) - $(OBJS) - $(basename $(SRCS))
@echo Creating $(abspath $(OBJSDIR))
mkdir -p $(OBJSDIR)
$(OBJSDIR)/%.o: $(SRCSDIR)/%.c $(OBJSDIR)/%.d $(INCLUDE)/brain/%.h
$(CC) $(CFLAGS) -o $@ -c $<
$(OBJSDIR)/%.d: $(SRCSDIR)/%.c
$(CC) $(CFLAGS) -MM -MT '$(patsubst %.c, %(OBJSDIR)/%.o, $(notdir $<))' $< -MF $@
.PHONY : clean stow unstow
clean :
$(RM) $(BINDIR) $(OBJSDIR)
stow:
@echo Creating $(INSTDIR)
mkdir -p $(INSTDIR)
cp -r $(BINDIR) $(INSTDIR)
stow --dir=/usr/local/stow --target=/usr/local --stow $(BINARY)
@echo Installation finished
unstow:
stow --dir=/usr/local/stow --target=/usr/local --delete $(BINARY)
@echo Successfully uninstalled