summaryrefslogtreecommitdiff
path: root/Makefile
blob: f08e26ea0bd1bd524df4ff65fa4269db8882e53c (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
SOURCES = client.c gitversion.c log.c mach.c main.c util.c
OBJECTS = $(SOURCES:.c=.o)
SCRIPTS = scripts/tokssh scripts/toxish
EXECUTABLES = tuntox tuntox_nostatic
DEB_VERSION = 0.0.9-1
DEB_ARCH = amd64
DEBS = ../tuntox_$(DEB_VERSION)_$(DEB_ARCH).deb ../tuntox-dbgsym_$(DEB_VERSION)_$(DEB_ARCH).deb
INCLUDES = client.h gitversion.h log.h mach.h main.h tox_bootstrap.h utarray.h uthash.h util.h utlist.h utstring.h
DEPS = toxcore
CC = gcc
CFLAGS = -g -W -Wall -O2 -fcompare-debug-second
CFLAGS += $(shell pkg-config --cflags $(DEPS))
LDFLAGS = -g -pthread -lm -static -lrt
LDFLAGS += $(shell pkg-config --static --libs $(DEPS))
DSO_LDFLAGS = -g -pthread -lm -lrt
DSO_LDFLAGS += $(shell pkg-config --libs $(DEPS))
PYTHON = /usr/bin/env python3
INSTALL = install -C
INSTALL_MKDIR = $(INSTALL) -d -m 755

prefix = /usr
bindir = $(prefix)/bin
etcdir = /etc

# Targets
.PHONY: all clean
all: $(EXECUTABLES)

gitversion != printf %s $$(git rev-parse HEAD) && (git diff --quiet || printf %s -dirty)
gitversion_on_disk != 2>/dev/null read _ _ v < gitversion.h && echo $$v || true
ifneq ("$(gitversion)", $(gitversion_on_disk))
.PHONY: gitversion.h
endif

gitversion.h:
	@echo "  GEN   $@"
	@echo '#define GITVERSION "$(gitversion)"' > $@

tox_bootstrap.h:
	$(PYTHON) generate_tox_bootstrap.py

%.o: %.c $(INCLUDES) gitversion.h tox_bootstrap.h
	@echo "  CC    $@"
	@$(CC) -c $(CFLAGS) $< -o $@

tuntox: $(OBJECTS) $(INCLUDES)
	$(CC) -o $@ $(OBJECTS) -lpthread $(LDFLAGS)

tuntox_nostatic: $(OBJECTS) $(INCLUDES)
	$(CC) -o $@ $(OBJECTS) -lpthread $(DSO_LDFLAGS)

cscope.out:
	@echo "  GEN   $@"
	@cscope -bv ./*.[ch] &> /dev/null

clean:
	rm -f $(OBJECTS) $(EXECUTABLES) cscope.out gitversion.h

ifneq ($(shell id -u),0)
install:
	sudo MAKEFLAGS=$(MAKEFLAGS) -- $(MAKE) install
else
install: tuntox_nostatic
	install -d -m755 $(DESTDIR)$(bindir) $(DESTDIR)$(etcdir)
	install -d -m700 $(DESTDIR)$(etcdir)/tuntox
	install -D -T tuntox_nostatic $(DESTDIR)$(bindir)/tuntox
	install -D -t $(DESTDIR)$(bindir) $(SCRIPTS)
	install -m0644 -D -t $(DESTDIR)$(etcdir)/systemd/system scripts/tuntox.service
ifeq ($(SKIP_SYSTEMCTL),)
	systemctl daemon-reload
	systemctl restart tuntox
	systemctl status tuntox
endif
endif

.PHONY: install-debs debs
install-debs: $(DEBS)
	$(shell [ "$$(id -u)" = 0 ] || echo sudo) dpkg -i $(DEBS)
$(DEBS) debs:
	fakeroot -- sh -c 'SKIP_SYSTEMCTL=y ./debian/rules binary'