X-Git-Url: https://plomlompom.com/repos/test.html?a=blobdiff_plain;f=Makefile;h=c7831bd86e01a79c5abc0a449d2efba192eceff0;hb=eb96a1dfe83cef7f3d1c0c73e03b915caca09db8;hp=3c25ff931f15cd6c730be88506e8cd03f8781249;hpb=fb2c9683f4b3bd48226ea45222185f99812744ff;p=plomrogue
diff --git a/Makefile b/Makefile
index 3c25ff9..c7831bd 100644
--- a/Makefile
+++ b/Makefile
@@ -1,14 +1,42 @@
-CC=cc
+CC=gcc
CFLAGS=-Wall -g
-TARGET=roguelike
-OBJECTS=windows.o draw_wins.o keybindings.o readwrite.o roguelike.o
+TARGET_SERVER=roguelike-server
+TARGET_CLIENT=roguelike-client
+SRCDIR=src
+BUILDDIR=build
+SERVERDIR=server
+CLIENTDIR=client
+COMMONDIR=common
-roguelike: $(OBJECTS)
- $(CC) $(CFLAGS) -o roguelike $(OBJECTS) -lncurses
+# 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))
-%.o: %.c
+# "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 $@
-.PHONY: clean
-clean:
- rm $(OBJECTS); rm roguelike
+# "make clean" to tries 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)