summaryrefslogtreecommitdiffstats
path: root/sdl/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'sdl/Makefile')
-rw-r--r--sdl/Makefile35
1 files changed, 23 insertions, 12 deletions
diff --git a/sdl/Makefile b/sdl/Makefile
index 580179b..1d881e9 100644
--- a/sdl/Makefile
+++ b/sdl/Makefile
@@ -1,5 +1,5 @@
-PROG = pyramid
-OBJS = $(PROG).o math3d.o gltools.o glframe.o shader.o
+BIN = pyramid
+SRC = pyramid.c math3d.c gltools.c glframe.c shader.c
CC = gcc
CFLAGS = -Wall -std=c99
DBGFLAGS = -g -O0
@@ -14,25 +14,36 @@ SDL_LDFLAGS := $(shell sdl-config --libs)
SDL_image_CFLAGS := $(shell pkg-config --cflags SDL_image)
SDL_image_LDFLAGS := $(shell pkg-config --libs SDL_image)
-$(PROG): $(OBJS)
- $(CC) $(LDFLAGS) $(SDL_LDFLAGS) $(SDL_image_LDFLAGS) $(OBJS) -o $@
+OBJ_DIR = obj
+OBJ_REL = $(addsuffix .o, $(subst .c,,$(SRC)))
+OBJ_ABS = $(addprefix $(OBJ_DIR)/, $(addsuffix .o, $(subst .c,,$(SRC))))
-$(PROG).o: %.o: %.c math3d.h gltools.h glframe.h
- $(CC) -c $(CFLAGS) $(SDL_CFLAGS) $(SDL_image_CFLAGS) $<
+$(BIN): $(OBJ_DIR) $(OBJ_REL)
+ $(CC) $(LDFLAGS) $(SDL_LDFLAGS) $(SDL_image_LDFLAGS) $(OBJ_ABS) -o $@
+
+pyramid.o: %.o: %.c math3d.h gltools.h glframe.h
+ $(CC) -c $(CFLAGS) $(SDL_CFLAGS) $(SDL_image_CFLAGS) $< -o $(OBJ_DIR)/$@
math3d.o: %.o: %.c %.h
- $(CC) -c $(CFLAGS) $<
+ $(CC) -c $(CFLAGS) $< -o $(OBJ_DIR)/$@
gltools.o: %.o: %.c %.h math3d.h
- $(CC) -c $(CFLAGS) $<
+ $(CC) -c $(CFLAGS) $< -o $(OBJ_DIR)/$@
glframe.o: %.o: %.c %.h math3d.h
- $(CC) -c $(CFLAGS) $<
+ $(CC) -c $(CFLAGS) $< -o $(OBJ_DIR)/$@
shader.o: %.o: %.c %.h math3d.h
- $(CC) -c $(CFLAGS) $<
+ $(CC) -c $(CFLAGS) $< -o $(OBJ_DIR)/$@
+
+$(OBJ_DIR):
+ mkdir -p $(OBJ_DIR)
-.PHONY: clean
+.PHONY: clean info
clean:
- rm -f *.o ./$(PROG)
+ rm -rf $(OBJ_DIR)
+ rm -f $(BIN)
+
+info:
+ @echo $(OBJ_REL)