summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcflip <cflip@cflip.net>2022-09-19 21:39:53 -0600
committercflip <cflip@cflip.net>2022-09-19 21:39:53 -0600
commitb8766fcef6dcc40bd46584015375ea76518c6201 (patch)
tree1ef5433f2c613e5bc063d415805a619bfe641cbe
parent0db641014f9163df475018a618ceb8bdb01250d1 (diff)
Improve Makefile build system
Building each source file as a separate object makes it faster to compile when only changing one source file, and also allows you to compile with multiple threads when building the whole project.
-rw-r--r--.gitignore8
-rw-r--r--Makefile29
2 files changed, 25 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index 58f0b1b..3bfe699 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,6 @@
-# Ignore executable binary
-cfws
+# Ignore IDE and editor project files
+.vscode
-.vscode \ No newline at end of file
+# Ignore build output
+cfws
+*.o
diff --git a/Makefile b/Makefile
index c4da138..573c499 100644
--- a/Makefile
+++ b/Makefile
@@ -1,13 +1,24 @@
+CXX=g++
+LD=g++
+
CFLAGS=-pedantic -Wall --std=c++17
-SRC=src/main.cpp \
- src/CGIScript.cpp \
- src/ClientConnection.cpp \
- src/ServerConnection.cpp \
- src/HttpRequest.cpp \
- src/HttpResponse.cpp
+OBJS=src/main.o \
+ src/CGIScript.o \
+ src/ClientConnection.o \
+ src/ServerConnection.o \
+ src/HttpRequest.o \
+ src/HttpResponse.o
+
+all: cfws
+
+%.o: %.cpp
+ $(CXX) $< -o $@ -c $(CFLAGS)
+
+cfws: $(OBJS)
+ $(LD) $^ -o $@ $(CFLAGS)
-OUT=cfws
+.PHONY: clean
-$(OUT): $(SRC)
- $(CXX) $(CFLAGS) -o $(OUT) $(SRC)
+clean:
+ rm -f $(OBJS) cfws