From b5f2f44fcc7666a8ed355067653cc47bea4877da Mon Sep 17 00:00:00 2001 From: Barry Kane Date: Tue, 11 Apr 2023 11:33:36 +0100 Subject: [PATCH] Improved makefile. - Makefile now doesn't hardcode gcc. (Whether SilverMUD is compiler agnostic remains to be seen.) - The first target is now all, which compiles a "release" build. - General cleanup, removal of duplicate variables, and commenting. --- Makefile | 54 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index f35ca9a..a656190 100644 --- a/Makefile +++ b/Makefile @@ -1,30 +1,38 @@ -CC = gcc -clientsrc = $(wildcard src/*.c) \ - src/client/SilverMUDClient.c -clientobj = $(clientsrc:.c=.o) -serversrc = $(wildcard src/*.c) \ - src/server/SilverMUDServer.c -serverobj = $(serversrc:.c=.o) +# Compiler and linker flags needed to link to the needed libraries: CFLAGS = `pkg-config --cflags guile-3.0` -CLIENTLDFLAGS= -lpthread -lncurses -lgnutls `pkg-config --libs guile-3.0` -SERVERLDFLAGS= -lpthread -lncurses -lgnutls `pkg-config --libs guile-3.0` -SilverMUDClient: $(clientobj) - gcc -o $@ $^ $(CLIENTLDFLAGS) +LDFLAGS= -lpthread -lncurses -lgnutls `pkg-config --libs guile-3.0` -SilverMUDServer: $(serverobj) - gcc -o $@ $^ $(SERVERLDFLAGS) +# Files needed to compile the client: +clientsrc = $(wildcard src/*.c) src/client/SilverMUDClient.c +clientobj = $(clientsrc:.c=.o) -SilverMUDClientDebug: $(clientobj) - gcc -pg $^ $(CLIENTLDFLAGS) -o $@ - -SilverMUDServerDebug: $(serverobj) - gcc -pg $^ $(SERVERLDFLAGS) -o $@ - -.PHONY: clean -clean: - rm -f $(clientobj) $(serverobj) SilverMUDClient SilverMUDServer SilverMUDClientDebug SilverMUDServerDebug +# Files needed to compile the server: +serversrc = $(wildcard src/*.c) src/server/SilverMUDServer.c +serverobj = $(serversrc:.c=.o) +# Default target: Compile the client and server with aggressive optimizations and a big stack of warnings: all: clean SilverMUDClient SilverMUDServer -all: CFLAGS += -Wall -Wextra -Ofast +all: CFLAGS += -Wall -Wextra -Ofast + +# Debug target: Compile the client and server with profiling, debug information, debug optimization, and the +# preprocessor flag "debug" set. debug: CFLAGS += -Wall -Wextra -pg -ggdb -Og -D debug debug: clean SilverMUDClientDebug SilverMUDServerDebug + +SilverMUDClient: $(clientobj) + cc $^ $(LDFLAGS) -o $@ + +SilverMUDServer: $(serverobj) + cc $^ $(LDFLAGS) -o $@ + +SilverMUDClientDebug: $(clientobj) + cc -pg $^ $(LDFLAGS) -o $@ + +SilverMUDServerDebug: $(serverobj) + cc -pg $^ $(LDFLAGS) -o $@ + +# Start from a clean slate: +.PHONY: clean +clean: + rm -f $(clientobj) $(serverobj) SilverMUDClient SilverMUDServer SilverMUDClientDebug SilverMUDServerDebug gmon.out +