-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
80 lines (62 loc) · 2 KB
/
Makefile
File metadata and controls
80 lines (62 loc) · 2 KB
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
# Installation settings, max be overwritten
PREFIX ?= /usr/local
CONFIG_DIR ?= /etc
COMMAND_PIPE ?= /run/throttle
# Compiler and linker flags
CXXFLAGS += -Wall -Wextra -std=c++11
OPTFLAGS ?= -O3
LFLAGS = -Wall $(LIBOPTIONS)
# Files and libraries
SOURCES := main.cpp throttle.cpp conf.cpp
CPPS := $(patsubst %,src/%,$(SOURCES))
OBJS := $(patsubst %.cpp, %.o, $(CPPS))
DEBUG_OBJS := $(patsubst %.cpp, %-debug.o, $(CPPS))
LIBS :=
LIBOPTIONS := $(patsubst %, -l%, $(LIBS))
# Derive systemd directories from prefix.
ifeq ($(PREFIX),/usr)
SYSTEMD := /usr/lib/systemd/system
TMPFILES := /usr/lib/tmpfiles.d
else
SYSTEMD := /etc/systemd/system
TMPFILES := /etc/tmpfiles.d
endif
DEBUG_CORES := 2
# Compiling
throttle: $(OBJS) throttle.conf
$(CXX) $(LFLAGS) -o throttle $(OBJS)
$(OBJS): %.o: %.cpp src/throttle.hpp
$(CXX) -c -DNDEBUG $(OPTFLAGS) $(CXXFLAGS) -o $@ $<
# Configuration
throttle.conf:
./config >throttle.conf
# Debug
debug: debug/throttle debug/throttle.conf debug/pipe
debug/:
mkdir -p debug
debug/throttle: $(DEBUG_OBJS)
$(CXX) -g $(LFLAGS) -o $@ $(DEBUG_OBJS)
$(DEBUG_OBJS): %-debug.o: %.cpp src/throttle.hpp | debug/
$(CXX) -c -g $(CXXFLAGS) -o $@ $<
debug/throttle.conf: | debug/
(cd debug; ../config $(DEBUG_CORES) >throttle.conf)
debug/pipe: | debug/
[ -p debug/pipe ] || mkfifo debug/pipe
# Installation
install: throttle
@install --verbose --strip --owner=root throttle $(PREFIX)/sbin
@install --verbose --mode=644 --owner=root throttle.conf $(CONFIG_DIR)
@sed "{s|PREFIX|$(PREFIX)|g; s|CONFIG_FILE|$(CONFIG_DIR)/throttle.conf|g; s|PIPE|$(COMMAND_PIPE)|g}" \
throttle.service >$(SYSTEMD)/throttle.service
@echo "p $(COMMAND_PIPE) 660 root users - -" >$(TMPFILES)/throttle.conf
uninstall:
-rm $(PREFIX)/sbin/throttle
-rm $(CONFIG_DIR)/throttle.conf
-rm $(SYSTEMD)/throttle.service
-rm $(TMPFILES)/throttle.conf
# Cleaning up
clean:
-rm src/*.o throttle debug/throttle
-rm debug/cpu*freq debug/temp_input debug/pipe
-rm throttle.conf debug/throttle.conf
.PHONY: debug install uninstall clean