aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile70
1 files changed, 70 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..346f1f4
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,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 /