home · contact · privacy
56a158c56c346e524046b30dbd3c89ca4ed2ded4
[plomrogue] / Makefile
1 TARGET=roguelike
2 SRCDIR=src
3 BUILDDIR=build
4 CC=gcc
5 CFLAGS=-Wall -g
6
7 # Use all .c files below SRCDIR for sources. Build object file paths by
8 # replacing SRCDIR with BUILDDIR and .c endings with .o endings.
9 SOURCES=$(shell find $(SRCDIR)/ -type f -name \*.c)
10 OBJECTS=$(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.c=.o))
11
12 # Linking TARGET demands generation of all OBJECTS files. To build them,
13 # rely on this rule: Each file of path BUILDDIR/[name].o is compiled
14 # from a file of path SRCDIR/[name].c. Build BUILDDIR as needed.
15 $(TARGET): $(OBJECTS)
16         $(CC) $(CFLAGS) -o roguelike $(OBJECTS) -lncurses
17 $(BUILDDIR)/%.o: $(SRCDIR)/%.c
18         mkdir -p $(BUILDDIR); $(CC) $(CFLAGS) -c $< -o $@
19
20 # Use "clean" to delete build and target files. Tell make that "clean"
21 # is a "phony" target, i.e. this is not about building a file.
22 .PHONY: clean
23 clean:
24         rm $(OBJECTS)
25         rmdir $(BUILDDIR)
26         rm $(TARGET)