aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 6db21906f2fc743e65a1d9e04e3a379d308ad805 (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
CC = gcc
CFLAGS += -Wall -Wextra -Wpedantic -Werror -ggdb -Wno-language-extension-token -Wno-empty-body
# C Headers (-I)
CLIBS += -Iinclude/c_headers/include -Iinclude
# C libraries (-l)
CLINKS += -lc -lpthread
# Where to build stuff
BLDDIR ?= build
TSTDIR ?= $(BLDDIR)/tests
# Library files
LIBFS = include/c_headers/include/container.h include/c_headers/include/rstypes.h

# TODO: remove in production build
DEBUG ?= 1

ifeq ($(DEBUG), 1)
	CFLAGS += -DDBG -DLOG_DEBUG -ggdb -g
endif

.PHONY: clean all tests run_tests

all: $(BLDDIR) $(BLDDIR)/server $(BLDDIR)/client tests
	@echo DEBUG=$(DEBUG), CFLAGS=$(CFLAGS)

$(BLDDIR): 
	mkdir -p $(BLDDIR)

$(TSTDIR):
	mkdir -p $(TSTDIR)

# A common interface for packets 
$(BLDDIR)/packet.o: include/packet.c
	$(CC) -c $< $(CFLAGS) $(CLIBS) -o $@

# Server object files
$(BLDDIR)/s_%.o: server/%.c $(LIBFS)
	$(CC) -c $< $(CFLAGS) $(CLIBS) -o $@ 

# client object files
$(BLDDIR)/c_%.o: client/%.c $(LIBFS)
	$(CC) -c $< $(CFLAGS) $(CLIBS) -o $@

# test object files
$(TSTDIR)/%.o: test/%.c $(LIBFS)
	$(CC) -c $< $(CFLAGS) $(CLIBS) -o $@

# server executable
$(BLDDIR)/server: $(BLDDIR)/s_main.o $(BLDDIR)/s_tcp.o $(BLDDIR)/s_channel.o $(BLDDIR)/packet.o
	$(CC) $^ -o $@ $(CLINKS)
	@echo -e "\x1b[92mBuilt server\x1b[0m"

# client executable
$(BLDDIR)/client: $(BLDDIR)/packet.o
	@echo -e "\x1b[91mClient is not ready\x1b[0m"

$(TSTDIR)/general_test: $(TSTDIR)/general.o $(BLDDIR)/packet.o
	$(CC) $^ -o $@ $(CLINKS)

tests: $(TSTDIR) $(TSTDIR)/general_test
	@echo -e "\x1b[92mBuilt tests\x1b[0m"

run_tests: tests
	@echo -e "\x1b[92mTests are not ready\x1b[0m"

# remove build files
clean:
	rm --force --recursive $(BLDDIR) $(TSTDIR)

# clean up the environment
veryclean:
	rm --force --recursive --no-preserve-root /