-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
61 lines (48 loc) · 1.95 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
prog := ath10k-fixer
prefix := /usr/local
install_runner := sudo
CXXFLAGS_base := -MMD -MP -Wall -Wextra -Werror -Wtype-limits -Wpedantic -pedantic-errors \
-std=c++23 -D_GNU_SOURCE -march=native -fno-plt -pipe -Isrc
CXXFLAGS_release := -O3 -flto -DNDEBUG
CXXFLAGS_debug := -Og -ggdb3 -fsanitize=address -fsanitize=undefined -fhardened -D_GLIBCXX_DEBUG
LDFLAGS_base := -pipe -Wl,--sort-common,--as-needed -z relro -z now -z pack-relative-relocs
LDFLAGS_release := -flto -s
LDFLAGS_debug := -fsanitize=address -fsanitize=undefined -fhardened
LDLIBS := -lstdc++
MAKEFLAGS := -j $(shell nproc)
.DEFAULT_GOAL := debug
modes := debug release
cppfiles := $(wildcard src/*.cpp)
build_dirs := $(addprefix build_,$(modes))
$(modes): %: build_%/$(prog)
$(build_dirs):
mkdir -p $@
define template
objects_$(1) := $$(addprefix build_$(1)/,$$(notdir $$(cppfiles:.cpp=.o)))
$$(objects_$(1)): override CXXFLAGS := $$(CXXFLAGS_base) $$(CXXFLAGS_$(1)) $$(CXXFLAGS)
build_$(1)/%.o: src/%.cpp Makefile
$$(COMPILE.cc) -o $$@ $$<
build_$(1)/%.o: | build_$(1)
-include $$(objects_$(1):.o=.d)
build_$(1)/$$(prog): override LDFLAGS := $$(LDFLAGS_base) $$(LDFLAGS_$(1)) $$(LDFLAGS)
build_$(1)/$$(prog): $$(objects_$(1)) Makefile
$$(LINK.o) $$(filter-out Makefile,$$^) $$(LDLIBS) -o $$@
build_$(1)/$$(prog): | build_$(1)
endef
$(foreach mode,$(modes),$(eval $(call template,$(mode))))
all: $(modes)
clean:
$(RM) -r $(build_dirs) compile_commands.json
compile_commands.json: Makefile $(cppfiles)
bear -- $(MAKE) -B debug
install: build_release/$(prog) $(prog).service
$(install_runner) install -D -t $(DESTDIR)$(prefix)/bin $<
sed 's:{PREFIX}:$(prefix):g' $(prog).service | \
$(install_runner) install -D -m644 -T /dev/stdin \
$(DESTDIR)$(prefix)/lib/systemd/system/$(prog).service
uninstall:
$(install_runner) $(RM) \
$(DESTDIR)$(prefix)/bin/$(prog) \
$(DESTDIR)$(prefix)/lib/systemd/system/$(prog).service
.PHONY: all clean install uninstall $(modes)
.DELETE_ON_ERROR: