X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=Makefile;h=56a158c56c346e524046b30dbd3c89ca4ed2ded4;hb=c7cdbe6260e5cd6a8efe2c73a02c9635b67ec4b7;hp=7a60ae07bc66d3517a0028a96311d038598cd0ae;hpb=a3c0f0cc2892e7efdaa4c85c844aa4b1ad1e077f;p=plomrogue diff --git a/Makefile b/Makefile index 7a60ae0..56a158c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,26 @@ -roguelike: - cc -g -o windows.o -c windows.c - cc -g -o roguelike.o -c roguelike.c - cc -g -o roguelike windows.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)