X-Git-Url: https://plomlompom.com/repos/test.html?a=blobdiff_plain;f=Makefile;h=56a158c56c346e524046b30dbd3c89ca4ed2ded4;hb=fbff7bf7700c79ad484a83353685ecebf2a3541e;hp=3c25ff931f15cd6c730be88506e8cd03f8781249;hpb=fb2c9683f4b3bd48226ea45222185f99812744ff;p=plomrogue
diff --git a/Makefile b/Makefile
index 3c25ff9..56a158c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,14 +1,26 @@
-CC=cc
-CFLAGS=-Wall -g
TARGET=roguelike
-OBJECTS=windows.o draw_wins.o keybindings.o readwrite.o roguelike.o
+SRCDIR=src
+BUILDDIR=build
+CC=gcc
+CFLAGS=-Wall -g
-roguelike: $(OBJECTS)
- $(CC) $(CFLAGS) -o roguelike $(OBJECTS) -lncurses
+# Use all .c files below SRCDIR for sources. Build object file paths by
+# replacing SRCDIR with BUILDDIR and .c endings with .o endings.
+SOURCES=$(shell find $(SRCDIR)/ -type f -name \*.c)
+OBJECTS=$(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.c=.o))
-%.o: %.c
- $(CC) $(CFLAGS) -c $< -o $@
+# Linking TARGET demands generation of all OBJECTS files. To build them,
+# rely on this rule: Each file of path BUILDDIR/[name].o is compiled
+# from a file of path SRCDIR/[name].c. Build BUILDDIR as needed.
+$(TARGET): $(OBJECTS)
+ $(CC) $(CFLAGS) -o roguelike $(OBJECTS) -lncurses
+$(BUILDDIR)/%.o: $(SRCDIR)/%.c
+ mkdir -p $(BUILDDIR); $(CC) $(CFLAGS) -c $< -o $@
+# Use "clean" to delete build and target files. Tell make that "clean"
+# is a "phony" target, i.e. this is not about building a file.
.PHONY: clean
clean:
- rm $(OBJECTS); rm roguelike
+ rm $(OBJECTS)
+ rmdir $(BUILDDIR)
+ rm $(TARGET)