################################################################################
#
#  Makefile for libtpcrec
#
#  Environment variables:
#	OS = 'operating system'
#	INCLUDE = 'include path'
#	LDFLAGS = 'library path'
#	PET_BIN = 'where to install binaries'
#	PET_LIB = 'where to install libraries'
#	PET_ARCHIVE = 'where to archive sources'
#	PET_WW_ARCHIVE = 'where to put www content'
#
#  Main targets:
#	compile: compile library and executable
#	install: install library and executable
#	html: create the html documentation
#	clean & clobber: clean the directory
#
#  Date:
#  2005-05-19 Jarkko Johansson
#  2005-11-07 Calle Laakkonen
#  2005-11-29 Jarkko Johansson
#
################################################################################
# ------------- General settings:----------------------------------------------#
LIBRARY		= libtpcrec
SOURCES 	= ellipse.c prmat.c radon.c libtpcrecv.c
OBJECTS 	= ${SOURCES:.c=.o}
LIBARCHIVE	= ${LIBRARY}.a
DOXYGEN		= doxygen
CC		= gcc
CFLAGS 		= -s -Wall -O2 ${INCLUDE}
LIBS 		= -L. -ltpcrec
ZIP		= zip
PRVERS		= progvers
ADDDATE		= adddate
PDOC2HTML	= pdoc2htm

# ------------- OS/terminal dependent settings:--------------------------------#
ifeq ($(OS),Windows_NT)
EXT		= .exe
endif

LIBEXEC 	= ${LIBRARY}${EXT}

# ------------- Compilation: --------------------------------------------------#
compile: ${LIBARCHIVE} ${LIBEXEC}

# Compile library
${LIBARCHIVE}: ${OBJECTS}
	${AR} -rvs ${LIBARCHIVE} ${OBJECTS}

# Compile executable
${LIBEXEC}: ${LIBARCHIVE} ${LIBRARY}.c
	${CC} ${LIBRARY}.c -o ${LIBRARY}.exe  ${CFLAGS} ${LIBS}

# ------------- Version information: ------------------------------------------#
libversion: ${LIBRARY}.version

${LIBRARY}.version: ${SOURCES}
	${PRVERS} ${LIBEXEC} ${LIBRARY}.version

# ------------- Installation: -------------------------------------------------#
install: libversion libinstall execinstall

libinstall: ${LIBARCHIVE}
	${ADDDATE} -i=${LIBRARY}.version -o=${PET_LIB} -nodate ${LIBARCHIVE}

execinstall: ${LIBEXEC}
	${ADDDATE} -i=${LIBRARY}.version -o=${PET_BIN} -nodate -copy ${LIBEXEC}

# ------------- Html creation rules -------------------------------------------#
html: ${LIBEXEC}
	./${LIBEXEC} -R > Readme
	./${LIBEXEC} -H > History
	${DOXYGEN}

# ------------- Cleanup: ------------------------------------------------------#
clean:
	rm -f ${LIBRARY}${EXT} ${OBJECTS} ${LIBRARY}.a

clobber: clean
	rm -f *~ *.exe

