-
Notifications
You must be signed in to change notification settings - Fork 160
/
Makefile
99 lines (78 loc) · 2.83 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
# Setting GIT_DIR keeps git from ascending to parent directories
# and gives a nicer error message
VERSION ?= $(shell GIT_DIR=$(shell pwd)/.git git describe --tags --dirty)
ifeq ($(VERSION),)
VERSION := "(unknown version)"
$(warning Could not get version from git, setting to $(VERSION))
endif
CFLAGS += -Wall -Wextra -Wformat-security -Wconversion -DVERSION=\"$(VERSION)\" -g -fstack-protector-all -std=gnu99
DESTDIR ?=
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
MANDIR ?= $(PREFIX)/share/man
MAN1DIR ?= $(MANDIR)/man1
# Systemd hardcodes its unit path list
SYSCONFDIR ?= /etc
SYSTEMDUNITDIR ?= /etc/systemd/system
PANDOC := $(shell command -v pandoc 2> /dev/null)
.PHONY: all clean install uninstall format test
all: earlyoom earlyoom.1 earlyoom.service
earlyoom: $(wildcard *.c *.h) Makefile
$(CC) $(LDFLAGS) $(CPPFLAGS) $(CFLAGS) -o $@ $(wildcard *.c)
.PHONY: earlyoom.profile
earlyoom.profile:
$(CC) $(LDFLAGS) $(CPPFLAGS) $(CFLAGS) -DPROFILE_FIND_LARGEST_PROCESS -o earlyoom.profile $(wildcard *.c)
earlyoom.1: MANPAGE.md
ifdef PANDOC
pandoc MANPAGE.md -s -t man > earlyoom.1
else
@echo "pandoc is not installed, skipping earlyoom.1 manpage generation"
endif
clean:
rm -f earlyoom earlyoom.profile earlyoom.service earlyoom.initscript earlyoom.1 earlyoom.1.gz gmon.out*
install: earlyoom.service install-bin install-default install-man
install -d $(DESTDIR)$(SYSTEMDUNITDIR)
install -m 644 $< $(DESTDIR)$(SYSTEMDUNITDIR)
-chcon -t systemd_unit_file_t $(DESTDIR)$(SYSTEMDUNITDIR)/$<
-systemctl enable earlyoom
install-initscript: earlyoom.initscript install-bin install-default
install -d $(DESTDIR)$(SYSCONFDIR)/init.d/
install -m 755 $< $(DESTDIR)$(SYSCONFDIR)/init.d/earlyoom
-update-rc.d earlyoom start 18 2 3 4 5 . stop 20 0 1 6 .
earlyoom.%: earlyoom.%.in
sed "s|:TARGET:|$(BINDIR)|g;s|:SYSCONFDIR:|$(SYSCONFDIR)|g" $< > $@
install-default: earlyoom.default install-man
install -d $(DESTDIR)$(SYSCONFDIR)/default/
install -m 644 $< $(DESTDIR)$(SYSCONFDIR)/default/earlyoom
install-bin: earlyoom
install -d $(DESTDIR)$(BINDIR)/
install -m 755 $< $(DESTDIR)$(BINDIR)/
install-man: earlyoom.1.gz
ifdef PANDOC
install -d $(DESTDIR)$(MAN1DIR)/
install -m 644 $< $(DESTDIR)$(MAN1DIR)/
endif
earlyoom.1.gz: earlyoom.1
ifdef PANDOC
gzip -f -k -n $<
endif
uninstall: uninstall-bin uninstall-man
systemctl disable earlyoom
rm -f $(DESTDIR)$(SYSTEMDUNITDIR)/earlyoom.service
uninstall-man:
rm -f $(DESTDIR)$(MAN1DIR)/earlyoom.1.gz
uninstall-initscript: uninstall-bin
rm -f $(DESTDIR)$(SYSCONFDIR)/init.d/earlyoom
update-rc.d earlyoom remove
uninstall-bin:
rm -f $(DESTDIR)$(BINDIR)/earlyoom
# Depends on earlyoom compilation to make sure the syntax is ok.
format: earlyoom
clang-format --style=file -i *.h *.c
go fmt .
test: earlyoom
cppcheck -q . || echo "skipping optional cppcheck"
go test -v
.PHONY: bench
bench:
go test -run=NONE -bench=.