summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2017-12-01 02:34:09 +0300
committerOxore <oxore@protonmail.com>2017-12-01 02:34:09 +0300
commit8e95c29f1fec9b73859b71fe5e7538a2b17e4d82 (patch)
tree6d6e6d38e38a8b4ef0771d1612ca1ac1359e9f9f
parentae01c7fc02f17105f9e04af493f4dd8986fbcb8b (diff)
Make make to put all object files into "build" directory
-rw-r--r--.gitignore1
-rw-r--r--Makefile46
2 files changed, 34 insertions, 13 deletions
diff --git a/.gitignore b/.gitignore
index d5ccb00..1e78de1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
tetris
*.o
*.swp
+build
diff --git a/Makefile b/Makefile
index 3d62d6e..b8b76ba 100644
--- a/Makefile
+++ b/Makefile
@@ -1,19 +1,39 @@
CC=gcc
-FILES:=$(wildcard src/*.c)
-FILES:=$(FILES:.c=.o)
+CFLAGS+=-Wall
+CFLAGS+=-std=c11
+CFLAGS+=-O0
+CFLAGS+=-I$(INCLUDE)
+LIBS+=-lcsfml-graphics
+LIBS+=-lcsfml-window
+LIBS+=-lcsfml-system
-CFLAGS += -Wall
-CFLAGS += -std=c99
-CFLAGS += -O0
-CFLAGS += -Iinclude
-LIBS += -lcsfml-graphics
-LIBS += -lcsfml-window
-LIBS += -lcsfml-system
+BUILD:=build
+SRC:=src
+INCLUDE:=include
+SOURCES:=$(wildcard $(SRC)/*.c)
+OBJECTS:=$(patsubst $(SRC)/%.c,$(BUILD)/%.o,$(SOURCES))
-all: tetris
+TARGET:=tetris
-tetris: $(FILES)
- $(CC) -o $@ $^ $(CFLAGS) $(LIBS)
+#======================================================================
+
+all: $(TARGET)
+
+$(TARGET): $(OBJECTS)
+ @echo "Compiling: $@"
+ @$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
+ @echo "Build successfull"
+
+$(OBJECTS): | $(BUILD)
+
+$(BUILD):
+ @mkdir -p $(BUILD)
+
+$(BUILD)/%.o: $(SRC)/%.c
+ @echo "Compiling: $@"
+ @$(CC) -c $(CFLAGS) $(LIBS) -o $@ $<
clean:
- rm -f tetris $(FILES)
+ @rm -rfv $(TARGET) $(BUILD)
+
+.PHONY: all clean