-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
156 lines (109 loc) · 4.22 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# ============================================================================ #
#
#
#
# ---------------------------------------------------------------------------- #
MAKEFILE_DIR ?= $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
# ---------------------------------------------------------------------------- #
.PHONY: all clean FORCE check install bin tests
.DEFAULT_GOAL = bin
all: bin
# ---------------------------------------------------------------------------- #
CXX ?= c++
RM ?= rm -f
CAT ?= cat
PKG_CONFIG ?= pkg-config
NIX ?= nix
UNAME ?= uname
MKDIR ?= mkdir
MKDIR_P ?= $(MKDIR) -p
CP ?= cp
TR ?= tr
SED ?= sed
TEST ?= test
BATS ?= bats
# ---------------------------------------------------------------------------- #
PREFIX ?= $(MAKEFILE_DIR)/out
BINDIR ?= $(PREFIX)/bin
# ---------------------------------------------------------------------------- #
SRCS = $(wildcard *.cc)
BINS = parser-util
# ---------------------------------------------------------------------------- #
nljson_CFLAGS ?= $(shell $(PKG_CONFIG) --cflags nlohmann_json)
nljson_CFLAGS := $(nljson_CFLAGS)
boost_CFLAGS ?= \
-I$(shell $(NIX) build --no-link --print-out-paths 'nixpkgs#boost')/include
boost_CFLAGS := $(boost_CFLAGS)
nix_INCDIR ?= $(shell $(PKG_CONFIG) --variable=includedir nix-cmd)
nix_INCDIR := $(nix_INCDIR)
ifndef nix_CFLAGS
nix_CFLAGS = $(boost_CFLAGS)
nix_CFLAGS += $(shell $(PKG_CONFIG) --cflags nix-main nix-cmd nix-expr)
nix_CFLAGS += -isystem $(shell $(PKG_CONFIG) --variable=includedir nix-cmd)
nix_CFLAGS += -include $(nix_INCDIR)/nix/config.h
endif
nix_CFLAGS := $(nix_CFLAGS)
ifndef nix_LDFLAGS
nix_LDFLAGS = \
$(shell $(PKG_CONFIG) --libs nix-main nix-cmd nix-expr nix-store)
nix_LDFLAGS += -lnixfetchers
endif
nix_LDFLAGS := $(nix_LDFLAGS)
# ---------------------------------------------------------------------------- #
CXXFLAGS ?=
CXXFLAGS += $(EXTRA_CFLAGS) $(EXTRA_CXXFLAGS)
CXXFLAGS += $(nix_CFLAGS) $(nljson_CFLAGS)
LDFLAGS ?=
LDFLAGS += $(EXTRA_LDFLAGS)
LDFLAGS += $(nix_LDFLAGS)
ifneq ($(DEBUG),)
CXXFLAGS += -ggdb3 -pg
LDFLAGS += -ggdb3 -pg
endif
# ---------------------------------------------------------------------------- #
clean: FORCE
-$(RM) $(addprefix bin/,$(BINS))
-$(RM) *.o */*.o
-$(RM) result
-$(RM) -r $(PREFIX)
-$(RM) gmon.out *.log
# ---------------------------------------------------------------------------- #
%.o: %.cc
$(CXX) $(CXXFLAGS) -c "$<" -o "$@"
bin/parser-util: $(SRCS:.cc=.o)
$(MKDIR_P) $(@D)
$(CXX) $(CXXFLAGS) $(LDFLAGS) "$<" -o "$@"
bin: $(addprefix bin/,$(BINS))
# ---------------------------------------------------------------------------- #
.PHONY: install-dirs install-bin
install: install-dirs install-bin
install-dirs: FORCE
$(MKDIR_P) $(BINDIR)
$(BINDIR)/%: bin/% | install-dirs
$(CP) -- "$<" "$@"
install-bin: $(addprefix $(BINDIR)/,$(BINS))
# ---------------------------------------------------------------------------- #
check: bin/parser-util FORCE
@if ! $(BATS) --help >/dev/null 2>&1; then \
echo 'check: Cannot run bats executable. Did you install it?' >&2; \
exit 1; \
fi; \
export PARSER_UTIL='$(MAKEFILE_DIR)/bin/parser-util'; \
$(BATS) '$(MAKEFILE_DIR)/tests';
# ---------------------------------------------------------------------------- #
.PHONY: ccls
ccls: .ccls
.ccls: FORCE
echo 'clang' > "$@";
{ \
if [[ -n "$(NIX_CC)" ]]; then \
$(CAT) "$(NIX_CC)/nix-support/libc-cflags"; \
$(CAT) "$(NIX_CC)/nix-support/libcxx-cxxflags"; \
fi; \
echo $(CXXFLAGS); \
}|$(TR) ' ' '\n'|$(SED) 's/-std=/%cpp -std=/' >> "$@";
# ---------------------------------------------------------------------------- #
#
#
#
# ============================================================================ #