aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: a7ebec0bfc1ff63a0fddce6937faa80f886b468b (plain) (blame)
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
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.  This file is offered as-is,
# without any warranty.


# The package path prefix, if you want to install to another root, set DESTDIR to that root.
PREFIX ?= /usr
# The binary path excluding prefix.
BIN ?= /bin
# The library binary path excluding prefix.
LIBEXEC ?= /libexec
# The resource path excluding prefix.
DATA ?= /share
# The binary path including prefix.
BINDIR ?= $(PREFIX)$(BIN)
# The library binary path including prefix.
LIBEXECDIR ?= $(PREFIX)$(LIBEXEC)
# The resource path including prefix.
DATADIR ?= $(PREFIX)$(DATA)
# The license base path including prefix.
LICENSEDIR ?= $(DATADIR)/licenses


# The name of the package as it should be installed.
PKGNAME ?= orphan-reaper

# The name of the command as it should be installed.
COMMAND ?= orphan-reaper


# Flags to compile with.
USER_FLAGS = $(CFLAGS) $(LDFLAGS) $(CPPFLAGS)
WARN = -Wall -Wextra -pedantic
OPTIMISE = -O3
DEFS = -D'LIBEXECDIR="$(LIBEXECDIR)"'
C_FLAGS = $(OPTIMISE) $(WARN) $(DEFS) $(USER_FLAGS)



# Build rules.

.PHONY: all
all: bin/orphan-reaper bin/reapd


bin/%: src/%.c
	mkdir -p bin
	$(CC) $(C_FLAGS) -o $@ $<


# Install rules.

.PHONY: install
install: install-base

.PHONY: install
install-all: install-base

.PHONY: install-base
install-base: install-cmd install-copyright


.PHONY: install-cmd
install-cmd: bin/orphan-reaper bin/reapd
	install -dm755 -- "$(DESTDIR)$(BINDIR)"
	install -dm755 -- "$(DESTDIR)$(LIBEXECDIR)"
	install -m755 bin/orphan-reaper -- "$(DESTDIR)$(BINDIR)/$(COMMAND)"
	install -m755 bin/reapd -- "$(DESTDIR)$(LIBEXECDIR)/reapd"


.PHONY: install-copyright
install-copyright: install-copying install-license

.PHONY: install-copying
install-copying:
	install -dm755 -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)"
	install -m644 COPYING -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)/COPYING"

.PHONY: install-license
install-license:
	install -dm755 -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)"
	install -m644 LICENSE -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)/LICENSE"



# Uninstall rules.

.PHONY: uninstall
uninstall:
	-rm -- "$(DESTDIR)$(BINDIR)/$(COMMAND)"
	-rm -- "$(DESTDIR)$(LIBEXECDIR)/reapd"
	-rm -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)/COPYING"
	-rm -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)/LICENSE"


# Clean rules.

.PHONY: clean
clean:
	-rm -rf obj bin