home · contact · privacy
MAJOR re-write. Split plomrogue into a server and a client. Re-wrote large parts
[plomrogue] / Makefile
1 CC=gcc
2 CFLAGS=-Wall -g
3 TARGET_SERVER=roguelike-server
4 TARGET_CLIENT=roguelike-client
5 SRCDIR=src
6 BUILDDIR=build
7 SERVERDIR=server
8 CLIENTDIR=client
9 COMMONDIR=common
10
11 # Build object file lists by building object paths from all source file paths.
12 SOURCES_SERVER=$(shell find $(SRCDIR)/$(SERVERDIR)/ -type f -name \*.c)
13 SOURCES_CLIENT=$(shell find $(SRCDIR)/$(CLIENTDIR)/ -type f -name \*.c)
14 SOURCES_COMMON=$(shell find $(SRCDIR)/$(COMMONDIR)/ -type f -name \*.c)
15 OBJECTS_SERVER=$(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES_SERVER:.c=.o))
16 OBJECTS_CLIENT=$(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES_CLIENT:.c=.o))
17 OBJECTS_COMMON=$(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES_COMMON:.c=.o))
18
19 # "make" without further specifications builds both server and client.
20 default : $(TARGET_SERVER) $(TARGET_CLIENT)
21
22 # "make roguelike-server" builds only the server.
23 $(TARGET_SERVER) : $(OBJECTS_SERVER) $(OBJECTS_COMMON)
24         $(CC) $(CFLAGS) -o $(TARGET_SERVER) $(OBJECTS_SERVER) $(OBJECTS_COMMON)
25
26 # "make roguelike-client" builds only the ncurses client.
27 $(TARGET_CLIENT) : $(OBJECTS_CLIENT) $(OBJECTS_COMMON)
28         $(CC) $(CFLAGS) -o $(TARGET_CLIENT) $(OBJECTS_CLIENT) $(OBJECTS_COMMON)\
29          -lncurses
30
31 # Build respective object file to any source file. Create build dirs as needed.
32 $(BUILDDIR)/%.o : $(SRCDIR)/%.c
33         mkdir -p $(@D)
34         $(CC) $(CFLAGS) -c $< -o $@
35
36 # "make clean" to tries to delete all files that could possibly have been built.
37 # Declare target "phony", i.e. this is not about building a file.
38 .PHONY : clean
39 clean :
40         rm -rf $(BUILDDIR)
41         rm -f $(TARGET_SERVER)
42         rm -f $(TARGET_CLIENT)