-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
55 lines (42 loc) · 1016 Bytes
/
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
54
55
CC:=g++
SRCEXT:=cpp
CFLAGS:=-std=c++17 -O3
LDFLAGS:=-lpng
BIN:=desktop-dmenu
SRC:=.
OBJ:=obj
MAKEFILE:=Makefile
CLANGDINFO:=compile_commands.json
DEPDIR:=$(OBJ)/deps
SRCS:=$(wildcard $(SRC)/*.$(SRCEXT))
DEPFLAGS=-MT $@ -MMD -MP -MF $(DEPDIR)/$*.d
make:: $(CLANGDINFO) $(BIN)
run:: $(CLANGDINFO) $(BIN)
./$(BIN)
clean::
rm -r $(OBJ) || true
rm -r $(DEPDIR) || true
rm $(BIN) || true
rm $(CLANGDINFO) || true
install:: $(BIN)
cp $(BIN) /usr/local/bin/$(BIN)
# Rules for compilation
OBJS:=$(SRCS:$(SRC)/%.$(SRCEXT)=$(OBJ)/%.o)
$(BIN): $(OBJS) | $(OBJ)
$(CC) $(CFLAGS) $(OBJS) -o $@ $(LDFLAGS)
$(OBJ)/%.o: $(SRC)/%.$(SRCEXT) $(DEPDIR)/%.d | $(OBJ) $(DEPDIR)
$(CC) $(DEPFLAGS) $(CFLAGS) -c -o $@ $<
# Directories
$(OBJ):
mkdir -p $@
$(DEPDIR):
mkdir -p $@
# Dependencies (include files)
DEPFILES:=$(SRCS:$(SRC)/%.$(SRCEXT)=$(DEPDIR)/%.d)
$(DEPFILES):
include $(wildcard $(DEPFILES))
# Create compile commands using bear
makebin:: $(BIN)
$(CLANGDINFO): $(MAKEFILE)
make clean
bear -- make makebin