#----------------------------------------------------------------------------------
#
#      Makefile for EZWGL, the EZ Widget and Graphics Library.
#
#----------------------------------------------------------------------------------

# place to install the EZWGL library
LIBDIR = /usr/local/lib
#LIBDIR = /usr/lib

# place to install the header file EZ.h
INCLDIR = /usr/local/include
#INCLDIR = /usr/include

# place to instal the man pages
MANDIR=/usr/local/man/man3

#----------------------------------------------------------------------------------
AR = ar
RANLIB = ranlib
RM = /bin/rm -f
#----------------------------------------------------------------------------------
# Compiler, you need gcc.
#
CC= gcc 
#
# The following option turns on a simple memeory allocation 
# debuger. It merely records all the bytes allocated by EZWGL
# and reports to you every 20 seconds the total bytes allocated.
# on exit, it reports to you all the possible memory leaks.
#
DEBUG_FLAG = -DMEM_DEBUG 
#
# Optimization flag.
#
OPTIMIZATION_FLAG = -O2  -fexpensive-optimizations -funroll-loops
#
# If your X window environment does not have the MIT shared memory
# extension, comment out the next line.
#
XSHM_FLAG= -DXSHM 
#
#
MISC_FLAG= $(XSHM_FLAG) -DEZ_ADD_INPUT 
#
#  Jpeg support depend on (libjpeg release 6a of 7-Feb-96) 
#  from The Independent JPEG Group. 
#  If you don't want the JPEG support, simply comment out
#  the next two lines.
#
JPEG_FLAG = -DJPEG -I../jpeg 
JPEG_LIB = ../jpeg/libjpeg.a 
#
# A few high frequency gl routines have macro substitutes. The macro version
# is about, on average, 5-10% faster. However, they generate about 25% larger
# executables. If your system does not have a hardware sqrt
# instruction, you may want to uncomment the #-DLOW_PRECISION_SQRT
# in the following line. It uses a low precision sqrt function
# for lighting calculations.
#
GL_FLAG = -DUSE_GL_MACROS  #-DLOW_PRECISION_SQRT
#
#------------------------------------------------------------------
CFLAGS =  $(OPTIMIZATION_FLAG) 
FLAGS = $(DEBUG_FLAG) $(GL_FLAG) $(MISC_FLAG) $(JPEG_FLAG)
COMPILER = $(CC)  $(CFLAGS) 

#------------------------------------------------------------------

all:  shared

shared:
	cd lib;       make shared CC="$(COMPILER) $(FLAGS) -fpic"
	cd examples;  make all  CC="$(COMPILER)" LIBDIR="$(LIBDIR)" JPEG_LIB="$(JPEG_LIB)"
	cd test;      make all  CC="$(COMPILER)" LIBDIR="$(LIBDIR)" JPEG_LIB="$(JPEG_LIB)"

static:
	cd lib;       make static  CC="$(COMPILER) $(FLAGS)" AR="$(AR)" RANLIB="$(RANLIB)"
	cd examples;  make all  CC="$(COMPILER)" LIBDIR="$(LIBDIR)" JPEG_LIB="$(JPEG_LIB)"
	cd test;      make all  CC="$(COMPILER)" LIBDIR="$(LIBDIR)" JPEG_LIB="$(JPEG_LIB)"

install-shared:
	cd lib;      make install-shared CC="$(COMPILER)  $(FLAGS) -fpic" LIBDIR="$(LIBDIR)"
	cd include;  make install CC="$(COMPILER)" INCLDIR="$(INCLDIR)"


install-static:
	cd lib;      make install-static CC="$(COMPILER)  $(FLAGS)" AR=$(AR) LIBDIR="$(LIBDIR)"  RANLIB="$(RANLIB)"
	cd include;  make install CC="$(COMPILER)" INCLDIR="$(INCLDIR)"

install-man:
	(cd doc/man3;  tar cf - . | (cd $(MANDIR); tar xf - ) )

clean:
	cd lib;      make clean RM="$(RM)"
	cd examples; make clean RM="$(RM)"
	cd test;     make clean RM="$(RM)"

#------------------------------------------------------------------
