SHELL	= /bin/sh

.SUFFIXES : .cxx .o
.SUFFIXES : .c .o

CC		= g++
LINKCC		= g++
RM		= rm -rf
TOUCH		= touch
AR		= ar
AROPS		= cru
LODER		= $(AR) $(AROPS)
LOCAL		= /usr/local
OPTOPT		= -O
GRAMOPT		= -pedantic
WARNOPT		= -Wall -Wextra -Wshadow -Wpointer-arith -Wconversion \
			-Wredundant-decls -Woverloaded-virtual
EXTOPT		=
OPS		= $(OPTOPT) $(GRAMOPT) $(WARNOPT) $(EXTOPT)
BCCBASE		= C:/borland/bcc55
BCCINC		= -I$(BCCBASE)/Include
BCCLIB		= -L$(BCCBASE)/Lib -L$(BCCBASE)/Lib/PSDK
DXSDKPATH	= C:/DXSDK_Mar2008
POSTLINK	= :
#

SAMPLESRCS = box.cxx ball.cxx gui.cxx car.cxx viewer.cxx texture.cxx \
		resize.cxx particle.cxx textimage.cxx genmat.cxx pick.cxx

SAMPLE	= $(SAMPLESRCS:.cxx=)
SAMPLEEXE = $(SAMPLESRCS:cxx=exe)
SAMPLEAPPS = $(SAMPLESRCS:cxx=app)

ALLSRCS = $(SAMPLESRCS)

###################

FKLIB		= -lFK2_fltkWin -lFK2_base -lFK2_fltkErr
FKLIB_G		= -lFK2_fltkWin_g -lFK2_base_g -lFK2_fltkErr_g
FKLIB_CUDA	= -lFK2_fltkWin_c -lFK2_base_c -lFK2_fltkErr_c
FKLINK		= $(FKLIB)
LINK		= $(FKLINK) $(SYSLIBS)
TARGET		= target
OUTPUT		= -o $*

all:
	@echo "	FreeBSD:		make fb"
	@echo "	FreeBSD Debug:		make fb-g"
	@echo "	Cygwin-gcc:		make cw-gcc"
	@echo "	MingW:			make ming"
	@echo "	MingW Debug:		make ming-g"
	@echo "	MingW D3D:		make ming-d3d"
	@echo "	Borland C++:		make bcc"
	@echo "	MacOS X:		make mac"
	@echo "	MacOS X Debug:		make mac-g"
	@echo "	MacOS X CUDA:		make mac-c"

fb:
	$(MAKE) $(TARGET) \
	"SYSOPS = -D_FREEBSD_ -DNO_GLU_LIBRARY" \
	"INCLDIRS = -I. -I.. -I../../include -I$(LOCAL)/include" \
	"LFLAGS = -L../lib -L../../lib -L$(LOCAL)/lib" \
	"SYSLIBS = -limdkcv \
			-lfltk_images -lfltk_forms -lfltk_gl -lfltk_jpeg \
			-lfltk -lpng -lz \
			-lfreetype -lGL \
			-lXft -lfontconfig -lXinerama -lpthread \
			-lXext -lX11 -lm" \
	"RANLIB = ranlib"

fb-g:
	$(MAKE) $(TARGET) \
	"OPTOPT = -g" \
	"SYSOPS = -D_FREEBSD_ -DNO_GLU_LIBRARY" \
	"INCLDIRS = -I. -I.. -I../../include -I$(LOCAL)/include" \
	"LFLAGS = -L../lib -L../../lib -L$(LOCAL)/lib" \
	"SYSLIBS = -limdkcv \
			-lfltk_images -lfltk_forms -lfltk_gl -lfltk_jpeg \
			-lfltk -lpng -lz \
			-lfreetype -lGL \
			-lXft -lfontconfig -lXinerama -lpthread \
			-lXext -lX11 -lm" \
	"RANLIB = ranlib" \
	"FKLINK = $(FKLIB_G)"

cw-gcc:
	$(MAKE) $(TARGET) \
	"CC = g++" \
	"SYSOPS = -DWIN32 -D_CYGWIN_GCC_ \
		-mwindows -e _mainCRTStartup -mno-cygwin" \
	"INCLDIRS = -I.. -I../../FK_Cyg/include" \
	"LFLAGS = -L../lib -L../../FK_Cyg/lib" \
	"SYSLIBS = -lfltk_gl -lfltk_jpeg -lfltk_png -lfltk_images \
		-lfltk_forms -lfltk \
		-lfreetype -limdkcv \
		-lwinmm -lole32 -luuid -lglu32 -lopengl32 \
		-limm32 -lgdi32 -lcomctl32 -lwsock32 -lsupc++ -lz" \
	"RANLIB = ranlib"

ming:
	$(MAKE) $(TARGET) \
	"CC = g++" \
	"SYSOPS = -DWIN32 -D_MINGW_ \
		-mwindows -e _mainCRTStartup -mno-cygwin" \
	"INCLDIRS = -I.. -I../../FK_Ming/include -I../../include" \
	"LFLAGS = -L../lib -L../../lib -L../../FK_Ming/lib" \
	"SYSLIBS = -lfltk_gl -lfltk_jpeg -lfltk_png -lfltk_images \
		-lfltk_forms -lfltk -lfltk_z \
		-lfreetype -limdkcv \
		-lwinmm -lole32 -luuid -lglu32 -lopengl32 \
		-limm32 -lgdi32 -lcomctl32 -lwsock32 -lsupc++" \
	"RANLIB = ranlib"

ming-g:
	$(MAKE) $(TARGET) \
	"CC = g++" \
	"OPTOPT = -g" \
	"SYSOPS = -DWIN32 -D_MINGW_ \
		-mwindows -e _mainCRTStartup -mno-cygwin" \
	"INCLDIRS = -I.. -I../../FK_Ming/include -I../../include" \
	"LFLAGS = -L../lib -L../../lib -L../../FK_Ming/lib" \
	"SYSLIBS = -lfltk_gl -lfltk_jpeg -lfltk_png -lfltk_images \
		-lfltk_forms -lfltk -lfltk_z \
		-lfreetype -limdkcv \
		-lwinmm -lole32 -luuid -lglu32 -lopengl32 \
		-limm32 -lgdi32 -lcomctl32 -lwsock32 -lsupc++" \
	"RANLIB = ranlib" \
	"FKLINK = $(FKLIB_G)"

ming-d3d:
	$(MAKE) $(TARGET) \
	"CC = g++" \
	"GRAMOPT = " \
	"SYSOPS = -DWIN32 -D_MINGW_ -DFK_D3D \
		-mwindows -e _mainCRTStartup -mno-cygwin" \
	"INCLDIRS = -I.. -I../../FK_Ming/include \
		-I../../include -I$(DXSDKPATH)/Include" \
	"LFLAGS = -L../lib -L../../lib -L../../FK_Ming/lib \
		-L$(DXSDKPATH)/Lib/x86" \
	"SYSLIBS = -lfltk_gl -lfltk_jpeg -lfltk_png -lfltk_images \
		-lfltk_forms -lfltk -lfltk_z \
		-lfreetype -limdkcv \
		-ld3dx9 -ld3d9 \
		-lwinmm -lole32 -luuid -lglu32 -lopengl32 \
		-limm32 -lgdi32 -lcomctl32 -lwsock32 -lsupc++" \
	"RANLIB = ranlib"

bcc:
	$(MAKE) $(TARGET) \
	"CC = bcc32" \
	"SHELL = " \
	"OPTOPT = -O2 -Hc -Vx -Ve -6" \
	"GRAMOPT = -P" \
	"WARNOPT = -q -w-8004 -w-8057" \
	"SYSOPS = -DWIN32 -DBORLAND" \
	"INCLDIRS = -I.. -I../../FK_BCC/include $(BCCINC)" \
	"DEPENDDIRS = " \
	"LFLAGS = -L../lib -L../../FK_BCC/lib $(BCCLIB)" \
	"FKLIB = fk2_fltkWin.lib fk2_base.lib fk2_fltkErr.lib" \
	"SYSLIBS = fltk.lib freetype.lib imdkcv.lib" \
	"OUTPUT = "

mac:
	$(MAKE) $(TARGET) \
	"CC = c++" \
	"OPTOPT = -O -pipe" \
	"SYSOPS = -D_MACOSX_ -arch i386" \
	"INCLDIRS = -I. -I.. -I../../include -I$(LOCAL)/include" \
	"LFLAGS = -L../lib -L../../lib -L$(LOCAL)/lib" \
	"SYSLIBS = -limdkcv -lfltk_gl -lfltk_jpeg \
		-lfltk -lpng -lfreetype -lz \
		-framework AGL -framework OpenGL \
		-framework Carbon -framework Cocoa \
		-framework ApplicationServices \
		-framework Foundation \
		-framework AudioToolBox" \
	"RANLIB = ranlib" \
	"SAMPLE = $(SAMPLEAPPS)" \
	"POSTLINK = ../FK/appmake.pl"

mac-g:
	$(MAKE) $(TARGET) \
	"CC = c++" \
	"OPTOPT = -g" \
	"SYSOPS = -D_MACOSX_ -arch i386" \
	"INCLDIRS = -I. -I.. -I../../include -I$(LOCAL)/include" \
	"LFLAGS = -L../lib -L../../lib -L$(LOCAL)/lib" \
	"SYSLIBS = -limdkcv -lfltk_gl -lfltk_jpeg \
		-lfltk -lpng -lfreetype -lz \
		-framework AGL -framework OpenGL \
		-framework Carbon -framework Cocoa \
		-framework ApplicationServices \
		-framework Foundation \
		-framework AudioToolBox" \
	"RANLIB = ranlib" \
	"FKLINK = $(FKLIB_G)" \
	"SAMPLE = $(SAMPLEAPPS)" \
	"POSTLINK = ../FK/appmake.pl"

mac-c:
	$(MAKE) $(TARGET) \
	"CC = nvcc" \
	"OPTOPT = -O1" \
	"GRAMOPT = --host-compilation c++" \
	"WARNOPT = " \
	"SYSOPS = -D_MACOSX_" \
	"INCLDIRS = -I. -I.. -I../../include -I/usr/local/include \
		-I/usr/local/cuda/include \
		-I/Developer/GPU\ Computing/C/common/inc" \
	"DEPENDDIRS = " \
	"LFLAGS = -arch i386 -fPIC -L../lib -L../../lib -L$(LOCAL)/lib \
		-L/usr/local/cuda/lib \
		-L/Developer/GPU\ Computing/C/lib" \
 	"SYSLIBS = -limdkcv -lfltk_gl_c -lfltk_forms_c \
		-lfltk_images_c -lfltk_jpeg_c -lfltk_png_c \
		-lfltk_c -lfreetype -lz \
		-lcutil -lcublas -lcuda -lcudart \
		-framework AGL -framework OpenGL \
		-framework Carbon -framework ApplicationServices \
		-framework Foundation \
		-framework AudioToolBox" \
	"RANLIB = ranlib" \
	"SAMPLE = $(SAMPLEAPPS)" \
	"FKLINK = $(FKLIB_CUDA)" \
	"POSTLINK = ../FK/appmake.pl"

CFLAGS = $(OPS) $(SYSOPS) $(INCLDIRS)

target : $(SAMPLE)

clean:
	$(RM) $(SAMPLE) $(SAMPLEEXE) Makefile.bak \
		$(SAMPLESRCS:cxx=obj) $(SAMPLESRCS:cxx=tds) \
		$(SAMPLESRCS:cxx=o) $(SAMPLEAPPS) \
		*.out core *.core *~ #*# 
###
%.app : %.cxx
	$(CC) -c $(CFLAGS) $< -o $*.o
	$(LINKCC) $(SYSOPS) $(LFLAGS) $*.o $(LINK) -o $*
	$(POSTLINK) $*

.cxx :
	$(CC) $(CFLAGS) $(LFLAGS) $< $(OUTPUT) $(LINK)

####################
