###############################################################################
#
#  Makefile for Time Activity Curve IO C library (libtpccurveio).
#
#  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'
#
# Required files:
#	Doxyfile
#
# Main targets:
#	compile: compile library and executable
#	install: install library and executable
#       distribution: archiving sources and docs for back-up and distribution
#	clean & clobber: clean the directory
#  Usage:
#	Replace <library> with the name of your library (without version number).
#	Replace <library short name> with the short name without lib.
#	Replace <C files> with a list of your C source files.
#	Modify Doxyfile to be used in html creation.
#
#	Compile with: make -e
#
# Version:
#  2005-22-02 Jarkko Johansson
#  2005-03-03 JJ
#	Set environment variables INCLUDE and LDFLAGS to location of header
#	files and libraries to be linked (linking for the test program).
#
# 2005-04-25 JJ
#	Targets for installation and htlm creation added.
#	Htlm creation with doxygen requires the Doxyfile.
#
# 2005-05-04 JJ
#	Target for archiving added (works only in UNIX/Linux).
#
# 2005-06-17 Kaisa Sederholm
#       Added "remove" into html target
#
# 2005-10-31 Vesa Oikonen
#       Removed version numbers from PRVERS and ADDDATE.
#       Added version numbers to other libraries in INCLUDE.
#
# 2006-01-31 VO
#       Updated libtpcimgio version to 1.1.4.
#
# 2006-06-03 VO
#       Updated libtpcmisc version to 1.1.2.
#
# 2006-07-13 VO
#       Changed according to example library project dated 2006-06-20.
#       Compiler flag -std=gnu99 (default is gnu89).
#
# 2006-07-31 VO
#       Added -lm in LIBS
#
# 2007-02-10 VO
#       Added dftio.c and dftunit.c.
#
# 2007-08-09 VO
#       Added dftres.c.
#
# 2007-08-13 VO
#       Added petunits.c.
#
###############################################################################
# ------------- General settings:----------------------------------------------#
LIBRARY		= libtpccurveio
SOURCES 	= dft.c dftio.c dftunit.c petunits.c mathfunc.c ncifile.c \
                  result.c dftres.c cpt.c idwc.c if.c libtpccurveiov.c
OBJECTS 	= ${SOURCES:.c=.o}
LIBARCHIVE	= ${LIBRARY}.a
DOXYGEN		= doxygen
CC		= gcc
CFLAGS 		= -std=gnu99 -s -Wall -O ${INCLUDE}
LDFLAGS         = -L.
LIBS 		= ${LDFLAGS} -ltpccurveio -ltpcmisc -lm
ZIP		= zip
PRVERS		= progvers -opt=-b
ADDDATE		= adddate
PDOC2HTML	= pdoc2htm -L

# ------------- OS/terminal dependent settings:--------------------------------#
ifeq ($(OS),Windows_NT)
SUF		= 
EXT		= .exe
else
SUF		= ./
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 ${LIBEXEC}  ${CFLAGS} ${LIBS}

ifneq ($(OS),Windows_NT)
	 chmod a+x ${LIBEXEC}
endif

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

${LIBRARY}.version: ${LIBEXEC}
	${PRVERS} ${SUF}${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}

# ------------- Distribution: ----------------------------------------------------------#
distribution: libversion doxyapi libbinarchive libsrcarchive

doxyapi: ${LIBARCHIVE} ${LIBEXEC}
	./${LIBEXEC} -R > Readme
	./${LIBEXEC} -H > History
	make_doxyapi.sh ${LIBRARY}

libbinarchive: ${LIBARCHIVE} ${LIBEXEC}
	make_libbinarchive.sh ${LIBRARY}

libsrcarchive: clobber
	make_libsrcarchive.sh ${LIBRARY}

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

clobber: clean
	rm -f *~



