summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle K <kylek389@gmail.com>2011-07-01 19:37:08 -0500
committerKamil Kaminski <kamilkss@gmail.com>2011-07-01 19:37:08 -0500
commit9129b7ff505f7b296462dcd9e027c892a9c75c52 (patch)
tree1e63277bd3925c43bd17a8441d5e8fdc45ffb0ef
parent34609d64dd1298b77351267ff9763b53de8eecf9 (diff)
downloadGLPyramid-9129b7ff505f7b296462dcd9e027c892a9c75c52.tar.gz
GLPyramid-9129b7ff505f7b296462dcd9e027c892a9c75c52.tar.bz2
GLPyramid-9129b7ff505f7b296462dcd9e027c892a9c75c52.zip
Makefile: touch up the makefiles
The mingw32 for sdl gets fancy templates and automatic dependency generation.
-rw-r--r--glut/Makefile24
-rw-r--r--glut/mingw3224
-rw-r--r--sdl/GL_notes.txt2
-rw-r--r--sdl/Makefile27
-rw-r--r--sdl/glframe.c4
-rw-r--r--sdl/mingw3245
6 files changed, 60 insertions, 66 deletions
diff --git a/glut/Makefile b/glut/Makefile
index fabc6e0..6378bff 100644
--- a/glut/Makefile
+++ b/glut/Makefile
@@ -1,24 +1,30 @@
PROG = pyramid
OBJS = $(PROG).o math3d.o
CC = gcc
+CFLAGS = -Wall -std=c99
DBGFLAGS = -g -O0
+LDFLAGS = -lm
ifdef DEBUG
- CFLAGS = $(DBGFLAGS) -Wall -std=c99
+ CFLAGS += $(DBGFLAGS)
else
- CFLAGS = -Wall -std=c99 -O2 -march=native -mtune=native
+ CFLAGS += -O2 -march=native -mtune=native
+endif
+ifdef MINGW
+ LDFLAGS += -lglew32 -lopengl32 -lglu32 -lfreeglut
+else
+ LDFLAGS += -lGLEW -lGL -lGLU -lglut
endif
-LDFLAGS = -lGLEW -lGL -lGLU -lm -lglut
$(PROG): $(OBJS)
- $(CC) $(LDFLAGS) $(OBJS) -o $(PROG)
+ $(CC) -o $@ $(OBJS) $(LDFLAGS)
-$(PROG).o: $(PROG).c math3d.h
- $(CC) -c $(CFLAGS) $(PROG).c
+$(PROG).o: %.o: %.c math3d.h
+ $(CC) -c $(CFLAGS) $<
-math3d.o: math3d.c math3d.h
- $(CC) -c $(CFLAGS) math3d.c
+math3d.o: %.o: %.c %.h
+ $(CC) -c $(CFLAGS) $<
.PHONY: clean
clean:
- rm -f *.o ./$(PROG)
+ rm -f *.o ./$(PROG) ./$(PROG).exe
diff --git a/glut/mingw32 b/glut/mingw32
deleted file mode 100644
index c6bbc65..0000000
--- a/glut/mingw32
+++ /dev/null
@@ -1,24 +0,0 @@
-PROG = pyramid
-OBJS = $(PROG).o math3d.o
-CC = gcc
-DBGFLAGS = -g -O0
-ifdef DEBUG
- CFLAGS = $(DBGFLAGS) -Wall -std=c99
-else
- CFLAGS = -Wall -std=c99 -O2 -march=native -mtune=native
-endif
-LDFLAGS = -lglew32 -lopengl32 -lglu32 -lm -lfreeglut
-
-$(PROG): $(OBJS)
- $(CC) -o $(PROG) $(OBJS) $(LDFLAGS)
-
-$(PROG).o: $(PROG).c math3d.h
- $(CC) -c $(CFLAGS) $(PROG).c
-
-math3d.o: math3d.c math3d.h
- $(CC) -c $(CFLAGS) math3d.c
-
-.PHONY: clean
-
-clean:
- rm -f *.o ./$(PROG).exe
diff --git a/sdl/GL_notes.txt b/sdl/GL_notes.txt
index b155d88..0a19bbb 100644
--- a/sdl/GL_notes.txt
+++ b/sdl/GL_notes.txt
@@ -66,7 +66,7 @@ Shadow Mapping
Shaders
- VP: to mimick fixed functionality, multiply incoming vertex by MVP (modelview/projection matrices)
- if no transfomration took place, just transfer the vertex data into next stage, clipping AFAIK
+ if no transformation took place, just transfer the vertex data into next stage, clipping AFAIK
Vertex Shader--you can write code for tasks such as:
- Vertex position transformation using the modelview and projection matrices
diff --git a/sdl/Makefile b/sdl/Makefile
index c0683c9..580179b 100644
--- a/sdl/Makefile
+++ b/sdl/Makefile
@@ -1,11 +1,12 @@
PROG = pyramid
OBJS = $(PROG).o math3d.o gltools.o glframe.o shader.o
CC = gcc
+CFLAGS = -Wall -std=c99
DBGFLAGS = -g -O0
ifdef DEBUG
- CFLAGS = $(DBGFLAGS) -Wall -std=c99
+ CFLAGS += $(DBGFLAGS)
else
- CFLAGS = -Wall -std=c99 -O2 -march=native -mtune=native
+ CFLAGS += -O2 -march=native -mtune=native
endif
LDFLAGS = -lGLEW -lGL -lGLU -lm -lglut
SDL_CFLAGS := $(shell sdl-config --cflags)
@@ -14,22 +15,22 @@ 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 $(PROG)
+ $(CC) $(LDFLAGS) $(SDL_LDFLAGS) $(SDL_image_LDFLAGS) $(OBJS) -o $@
-$(PROG).o: $(PROG).c math3d.h gltools.h glframe.h
- $(CC) -c $(CFLAGS) $(SDL_CFLAGS) $(SDL_image_CFLAGS) $(PROG).c
+$(PROG).o: %.o: %.c math3d.h gltools.h glframe.h
+ $(CC) -c $(CFLAGS) $(SDL_CFLAGS) $(SDL_image_CFLAGS) $<
-math3d.o: math3d.c math3d.h
- $(CC) -c $(CFLAGS) math3d.c
+math3d.o: %.o: %.c %.h
+ $(CC) -c $(CFLAGS) $<
-gltools.o: gltools.c gltools.h math3d.h
- $(CC) -c $(CFLAGS) gltools.c
+gltools.o: %.o: %.c %.h math3d.h
+ $(CC) -c $(CFLAGS) $<
-glframe.o: glframe.c glframe.h math3d.h
- $(CC) -c $(CFLAGS) glframe.c
+glframe.o: %.o: %.c %.h math3d.h
+ $(CC) -c $(CFLAGS) $<
-shader.o: shader.c shader.h math3d.h
- $(CC) -c $(CFLAGS) shader.c
+shader.o: %.o: %.c %.h math3d.h
+ $(CC) -c $(CFLAGS) $<
.PHONY: clean
diff --git a/sdl/glframe.c b/sdl/glframe.c
index c61f651..e9cb7c5 100644
--- a/sdl/glframe.c
+++ b/sdl/glframe.c
@@ -69,7 +69,7 @@ void glframe_apply_camera_transform(GLFrame *frame)
glframe_get_camera_orientation(frame, m);
glMultMatrixf(m);
- /* if Rotation only, then do not do the translation */
+ /* if rotation only, then do not do the translation */
if (!rot_only)
glTranslatef(-frame->v_location[0], -frame->v_location[1], -frame->v_location[2]);
@@ -84,7 +84,7 @@ void glframe_apply_camera_transform(GLFrame *frame)
void glframe_move_forward(GLFrame *frame, float delta)
{
- // Move along direction of front direction
+ /* move along direction of front direction */
frame->v_location[0] += frame->v_forward[0] * delta;
frame->v_location[1] += frame->v_forward[1] * delta;
frame->v_location[2] += frame->v_forward[2] * delta;
diff --git a/sdl/mingw32 b/sdl/mingw32
index 94a935b..951fdf7 100644
--- a/sdl/mingw32
+++ b/sdl/mingw32
@@ -1,33 +1,44 @@
-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 -MD
DBGFLAGS = -g -O0
ifdef DEBUG
- CFLAGS = $(DBGFLAGS) -Wall -std=c99
+ CFLAGS += $(DBGFLAGS)
else
- CFLAGS = -Wall -std=c99 -O2 -march=native -mtune=native
+ CFLAGS += -O2 -march=native -mtune=native
endif
LDFLAGS = -lglew32 -lopengl32 -lglu32 -lm -lfreeglut -lmingw32 -lsdlmain -lsdl -lsdl_image -mwindows
-$(PROG): $(OBJS)
- $(CC) -o $(PROG) $(OBJS) $(LDFLAGS)
+OBJ_DIR = obj
+DEPS_DIR = obj
+BIN_DIR = .
-$(PROG).o: $(PROG).c math3d.h gltools.h glframe.h
- $(CC) -c $(CFLAGS) $(PROG).c
+C_FILES = $(filter %.c, $(SRC))
+DEP_FILES = $(addprefix $(DEPS_DIR)\, $(addsuffix .d, $(notdir $(subst .c,,$(SRC)))))
+OBJ_FILES = $(addprefix $(OBJ_DIR)\, $(addsuffix .o, $(notdir $(subst .c,,$(SRC)))))
-math3d.o: math3d.c math3d.h
- $(CC) -c $(CFLAGS) math3d.c
+INCL = -I/include
-gltools.o: gltools.c gltools.h math3d.h
- $(CC) -c $(CFLAGS) gltools.c
+define C_template
+$(1): $(2)
+ @mkdir -p $$(OBJ_DIR)
+ @mkdir -p $$(DEPS_DIR)
+ $$(CC) -c $$(CFLAGS) $$(INCL) $$< -o $$@
+endef
-glframe.o: glframe.c glframe.h math3d.h
- $(CC) -c $(CFLAGS) glframe.c
+all: $(BIN)
-shader.o: shader.c shader.h math3d.h
- $(CC) -c $(CFLAGS) shader.c
+$(foreach cfile, $(C_FILES), $(eval $(call C_template, $(OBJ_DIR)\$(notdir $(subst .c,,$(cfile))).o, $(cfile))))
+
+$(BIN): $(OBJ_FILES)
+ @mkdir -p $(BIN_DIR)
+ $(CC) -o $(BIN_DIR)/$@ $(OBJ_FILES) $(LDFLAGS)
.PHONY: clean
clean:
- rm -f *.o ./$(PROG).exe
+ rm -rf $(OBJ_DIR)
+ rm -f $(BIN_DIR)/$(BIN)
+
+-include $(DEP_FILES)