-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
89 lines (74 loc) · 2.53 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
BIN = syshud
LIB = libsyshud.so
PKGS = gtkmm-4.0 gtk4-layer-shell-0
SRCS = $(wildcard src/*.cpp)
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
LIBDIR ?= $(PREFIX)/lib
DATADIR ?= $(PREFIX)/share
SRCS := $(filter-out src/wireplumber.cpp,$(SRCS))
SRCS := $(filter-out src/pulse.cpp,$(SRCS))
SRCS := $(filter-out src/backlight.cpp,$(SRCS))
SRCS := $(filter-out src/keytoggles.cpp,$(SRCS))
# TODO: Add support for both pulse and wp (Auto detect)
ifneq (, $(shell grep -E '^#define AUDIO_PULSEAUDIO' src/config.hpp))
SRCS += src/pulse.cpp
PKGS += libpulse
endif
ifneq (, $(shell grep -E '^#define AUDIO_WIREPLUMBER' src/config.hpp))
SRCS += src/wireplumber.cpp
PKGS += wireplumber-0.5
endif
ifneq (, $(shell grep -E '^#define FEATURE_BACKLIGHT' src/config.hpp))
SRCS += src/backlight.cpp
endif
ifneq (, $(shell grep -E '^#define FEATURE_KEYBOARD' src/config.hpp))
SRCS += src/keytoggles.cpp
PKGS += libevdev
endif
OBJS = $(SRCS:.cpp=.o)
CXXFLAGS += -Oz -s -Wall -flto -fno-exceptions -fPIC
LDFLAGS += -Wl,--as-needed,-z,now,-z,pack-relative-relocs
CXXFLAGS += $(shell pkg-config --cflags $(PKGS))
LDFLAGS += $(shell pkg-config --libs $(PKGS))
JOB_COUNT := $(BIN) $(LIB) $(OBJS) src/git_info.hpp
JOBS_DONE := $(shell ls -l $(JOB_COUNT) 2> /dev/null | wc -l)
define progress
$(eval JOBS_DONE := $(shell echo $$(($(JOBS_DONE) + 1))))
@printf "[$(JOBS_DONE)/$(shell echo $(JOB_COUNT) | wc -w)] %s %s\n" $(1) $(2)
endef
all: $(BIN) $(LIB)
install: $(all)
@echo "Installing..."
@install -D -t $(DESTDIR)$(BINDIR) $(BIN)
@install -D -t $(DESTDIR)$(LIBDIR) $(LIB)
@install -D -t $(DESTDIR)$(DATADIR)/sys64/hud config.conf style.css
clean:
@echo "Cleaning up"
@rm $(BIN) $(LIB) $(OBJS) src/git_info.hpp
$(BIN): src/git_info.hpp src/main.o src/config_parser.o
$(call progress, Linking $@)
@$(CXX) -o $(BIN) \
src/main.o \
src/config_parser.o \
$(CXXFLAGS) \
-Wl,--no-as-needed \
$(shell pkg-config --libs gtkmm-4.0 gtk4-layer-shell-0)
$(LIB): $(OBJS)
$(call progress, Linking $@)
@$(CXX) -o $(LIB) \
$(filter-out src/main.o src/config_parser.o, $(OBJS)) \
$(CXXFLAGS) \
$(LDFLAGS) \
-shared
%.o: %.cpp
$(call progress, Compiling $@)
@$(CXX) -c $< -o $@ \
$(CXXFLAGS)
src/git_info.hpp:
$(call progress, Creating $@)
@commit_hash=$$(git rev-parse HEAD); \
commit_date=$$(git show -s --format=%cd --date=short $$commit_hash); \
commit_message=$$(git show -s --format="%s" $$commit_hash | sed 's/"/\\\"/g'); \
echo "#define GIT_COMMIT_MESSAGE \"$$commit_message\"" > src/git_info.hpp; \
echo "#define GIT_COMMIT_DATE \"$$commit_date\"" >> src/git_info.hpp