X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=Makefile;h=56a158c56c346e524046b30dbd3c89ca4ed2ded4;hb=714bf970109b33005e0ab3e588d818460ccdc304;hp=176bd688eea9ba5e10acc06eb4d4dce5413383ba;hpb=cbaece42c0073aef0c915966483c5d138315e126;p=plomrogue diff --git a/Makefile b/Makefile index 176bd68..56a158c 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,26 @@ -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 +TARGET=roguelike +SRCDIR=src +BUILDDIR=build +CC=gcc +CFLAGS=-Wall -g +# 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)) + +# 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 *.o; rm roguelike + rm $(OBJECTS) + rmdir $(BUILDDIR) + rm $(TARGET)