summaryrefslogtreecommitdiff
path: root/Makefile
blob: b17dec36ec81cdb71b08fd341b4a98d75d6d27e7 (plain)
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
# Copyright (C) 2016  Luke Shumaker
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# The source is C99 written for GNU libc
CFLAGS   += -std=c99
CPPFLAGS += -std=c99
CPPFLAGS += -D_GNU_SOURCE

# Be hyper-strict
CFLAGS   += -Wall -Werror -Wextra -pedantic
CPPFLAGS += -Wall -Werror -Wextra -pedantic

# Debugging
CFLAGS   += -g -fvar-tracking-assignments
CPPFLAGS += -g -fvar-tracking-assignments

# Enable the stack protector
CFLAGS += -fstack-protector

# Enable FORTIFY_SOURCE
CFLAGS   += -O2
CPPFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2

# The main Makefile segment
all: build
.PHONY: all

include config.mk

progs = freenect-server multipart-replace-http-server
units = freenect-server-http.service freenect-server-http.socket freenect-server.service freenect-server@.socket

build: $(addprefix src/,$(progs)) $(addprefix systemd/,$(units))
.PHONY: build

install: $(addprefix $(DESTDIR)$(bindir)/,$(progs)) $(addprefix $(DESTDIR)$(systemddir)/,$(units))
.PHONY: install

# Automatically figure out C header dependencies
CPPFLAGS += -MD -MF $(@D)/$(@F:%.o=.%.mk) -MP
-include src/.*.mk

# Dependencies that don't get figured out automatically
src/freenect-server: src/util.o -lfreenect -lusb-1.0 -ljpeg
src/multipart-replace-http-server: src/util.o src/wg.o src/multipart-replace.o -lpthread
systemd/freenect-server-http.service: .var.user .var.group .var.bindir
systemd/freenect-server-http.socket: .var.httpstream
systemd/freenect-server.service: .var.user .var.group .var.bindir
systemd/freenect-server@.socket: .var.user .var.group

# Rules to make things
COPYING.GPL3:
	wget http://www.gnu.org/licenses/gpl-3.0.txt -O $@

systemd/%: systemd/%.in
	sed $(foreach v,$(patsubst .var.%,%,$(filter .var.%,$^)), -e 's|@$v@|$($v)|' ) < $< > $@
$(DESTDIR)$(bindir)/%: src/%
	install -Dm755 $< $@
$(DESTDIR)$(systemddir)/%: systemd/%
	install -Dm644 $< $@
.var.%: FORCE
	@printf '%s' '$($*)' | ./write-ifchanged $@

# Undo
clean:
	rm -f -- src/*.o src/.*.mk
	rm -f -- $(addprefix src/,$(progs)) $(addprefix systemd/,$(units))
.PHONY: clean

uninstall:
	rm -f -- $(addprefix $(DESTDIR)$(bindir)/,$(progs)) $(addprefix $(DESTDIR)$(systemddir)/,$(units))
	rmdir -p -- $(dir $(addprefix $(DESTDIR)$(bindir)/,$(progs)) $(addprefix $(DESTDIR)$(systemddir)/,$(units))) 2>/dev/null || true
.PHONY: uninstall

# Noise that I put in every Makefile
.PHONY: FORCE
.DELETE_ON_ERROR:
.SECONDARY: