X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=Makefile;h=96c3aca017841681d83132c3a49771eb9c4707d2;hb=169b8dda5f4c4373300b5be5edc113a376799737;hp=176bd688eea9ba5e10acc06eb4d4dce5413383ba;hpb=cbaece42c0073aef0c915966483c5d138315e126;p=plomrogue diff --git a/Makefile b/Makefile index 176bd68..96c3aca 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,42 @@ -roguelike: - cc -Wall -g -o windows.o -c windows.c - cc -Wall -g -o draw_wins.o -c draw_wins.c - cc -Wall -g -o keybindings.o -c keybindings.c - cc -Wall -g -o readwrite.o -c readwrite.c - cc -Wall -g -o roguelike.o -c roguelike.c - cc -Wall -g -o roguelike windows.o draw_wins.o keybindings.o readwrite.o roguelike.o -lncurses - -clean: - rm *.o; rm roguelike +CC=gcc +CFLAGS=-std=c11 -pedantic-errors -Wall -Werror -Wextra -Wformat-security -g +TARGET_SERVER=roguelike-server +TARGET_CLIENT=roguelike-client +SRCDIR=src +BUILDDIR=build +SERVERDIR=server +CLIENTDIR=client +COMMONDIR=common + +# Build object file lists by building object paths from all source file paths. +SOURCES_SERVER=$(shell find $(SRCDIR)/$(SERVERDIR)/ -type f -name \*.c) +SOURCES_CLIENT=$(shell find $(SRCDIR)/$(CLIENTDIR)/ -type f -name \*.c) +SOURCES_COMMON=$(shell find $(SRCDIR)/$(COMMONDIR)/ -type f -name \*.c) +OBJECTS_SERVER=$(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES_SERVER:.c=.o)) +OBJECTS_CLIENT=$(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES_CLIENT:.c=.o)) +OBJECTS_COMMON=$(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES_COMMON:.c=.o)) + +# "make" without further specifications builds both server and client. +default : $(TARGET_SERVER) $(TARGET_CLIENT) + +# "make roguelike-server" builds only the server. +$(TARGET_SERVER) : $(OBJECTS_SERVER) $(OBJECTS_COMMON) + $(CC) $(CFLAGS) -o $(TARGET_SERVER) $(OBJECTS_SERVER) $(OBJECTS_COMMON) + +# "make roguelike-client" builds only the ncurses client. +$(TARGET_CLIENT) : $(OBJECTS_CLIENT) $(OBJECTS_COMMON) + $(CC) $(CFLAGS) -o $(TARGET_CLIENT) $(OBJECTS_CLIENT) $(OBJECTS_COMMON)\ + -lncurses + +# Build respective object file to any source file. Create build dirs as needed. +$(BUILDDIR)/%.o : $(SRCDIR)/%.c + mkdir -p $(@D) + $(CC) $(CFLAGS) -c $< -o $@ + +# "make clean" to try to delete all files that could possibly have been built. +# Declare target "phony", i.e. this is not about building a file. +.PHONY : clean +clean : + rm -rf $(BUILDDIR) + rm -f $(TARGET_SERVER) + rm -f $(TARGET_CLIENT)