aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 346f1f47fc1fe8bb6030c19fd34023e7dbc80c26 (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
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

# This variable's value is NOT checked, only it's existence is checked. 
# If you define it as `DEBUG = Off`, it will still build in debug mode
DEBUG = On

ifdef $(DEBUG)
	CFLAGS += -DDBG -ggdb -g
endif

.PHONY: clean all tests run_tests

all: $(BLDDIR) $(BLDDIR)/server $(BLDDIR)/client tests

$(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
	$(CC) -c $< $(CFLAGS) $(CLIBS) -o $@ 

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

# test object files
$(TSTDIR)/%.o: test/%.c
	$(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 /