# CSCI-4972/6963 Advanced Computer Graphics, Spring 2007
# Simple Makefile for Homework 4
# for g++ on unix or cygwin platforms

SHELL = /bin/bash

# ===============================================================

default:
	@echo "Please specify a target (unix, cygwin_x, cygwin, or cygwin_noa)"

# Linux or FreeBSD
unix: CC                = g++ -g -O3 -Wall -pedantic
unix: INCLUDE_PATH      = -I/usr/X11R6/include -L/usr/local/include
unix: LIB_PATH          = -L/usr/X11R6/lib -L/usr/local/lib
unix: LIBS              = -lm -lGL -lGLU -lglut
unix: all

# Cygwin with X (probably software emulation)
cygwin_x: CC            = g++ -g -O3 -Wall -pedantic
cygwin_x: INCLUDE_PATH  = -I/usr/X11R6/include
cygwin_x: LIB_PATH      = -L/usr/X11R6/lib
cygwin_x: LIBS          = -lm -lGL -lGLU -lglut
cygwin_x: all

# Cygwin with native Windows libraries
cygwin: CC              = g++ -g -O3 -Wall -pedantic # -DNDEBUG
cygwin: INCLUDE_PATH    = -I/usr/include/w32api 
cygwin: LIB_PATH        = -L/usr/lib/w32api
cygwin: LIBS            = -lm -lopengl32 -lglu32 -lglut32 
cygwin: all

# Cygwin with native Windows libraries, using .lib files from vstudio and glut download
cygwin_noa: VCLIB_PATH      = /c/PROGRA~1/VSNET.2K3/Vc7/PlatformSDK/Lib
cygwin_noa: GLUTLIB_PATH    = /c/GLUT
cygwin_noa: CC              = g++ -g -O3 -Wall -pedantic
cygwin_noa: INCLUDE_PATH    = -I/usr/include/w32api 
cygwin_noa: LIB_PATH        = -L/usr/lib/w32api
cygwin_noa: LIBS            = -lm ${VCLIB_PATH}/OPENGL32.LIB ${VCLIB_PATH}/GLU32.LIB \
                              ${GLUTLIB_PATH}/glut32.lib
cygwin_noa: all

# ===============================================================

SRCS	= main.cpp matrix.cpp camera.cpp glCanvas.cpp mesh.cpp edge.cpp radiosity.cpp face.cpp raytree.cpp raytracer.cpp sphere.cpp material.cpp
OBJS	= $(SRCS:.cpp=.o)
EXE	= render

# ===============================================================
# targets

.PHONY: all check-gcc depend clean

check-gcc:
	@(ver=`$(CC) --version | head -1 | awk '{print $$3}'`; \
	if [ $${ver:0:3} != 3.4 ]; then echo \
	"WARNING: this compiler ($$ver) may not be compatible with "\
	"g++ version 3.4.x, which will be used during grading."; fi)

all: check-gcc depend $(EXE) 

depend:
	$(CC) $(INCLUDE_PATH) -E -M $(SRCS) > Makefile.depend

clean: 
	rm -f *~ *bak *.ob  *.o $(EXE) Makefile.depend

# ===============================================================
# compilation rules

$(EXE): $(OBJS)
	$(CC) $(INCLUDE_PATH) -o $@ $(OBJS) $(LIB_PATH) $(LIBS) 

.cpp.o:
	$(CC) $(INCLUDE_PATH) $< -c -o $@

# ===============================================================

-include Makefile.depend
