###############################################################################
#
# Copyright (c) 2005 by Turku PET Centre 
#
# Purpose: Makefile for PET ROI C library (libtpcroi).
#
# Environment variables:
#	OS = 'operating system'
#	INCLUDE = 'include path' (optional)
#	LDFLAGS = 'library path' (optional)
#	PET_BIN = 'where to install binaries'
#	PET_LIB = 'where to install libraries'
#	PET_ARCHIVE = 'where to archive sources'
#	PET_WWW_ARCHIVE = 'where to put www content' (used in Doxyfile)
#
# Required files:
#	Doxyfile
#
# Main targets:
#	compile: compile the library and the test program
#	install: install the library and the test program
#	html: create the html documentation with doxygen
#	archive: archive the source code
#	test: run tests on library
#	clean & clobber: clean the directory
#	upgrade: clean compile test install clobber html 
#
# 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.
#
###############################################################################


# Programs to use:
CC 		= gcc
#AR 		= ar
DOXYGEN		= doxygen
ZIP		= zip



# Compilation parameters:
LIBS  		= -L. -ltpcroi
INCLUDE		= -Iinclude -I../libtpcimgio/include -I../libtpcmisc/include
CFLAGS 		= -s -Wall -O2 ${INCLUDE}



# Library related variables:
LIB		= libtpcroi
LIB_CFILES 	= roi.c oldroi.c libtpcroiv.c
LIB_OBJECTS 	= ${LIB_CFILES:.c=.o}
LIB_ARCHIVE	= ${LIB}.a
ifeq ($(OS),Windows_NT)
LIB_EXEC	= ${LIB}.exe
else
LIB_EXEC	= ${LIB}
endif
LIB_EXEC_CFILES	= ${LIB}.c
LIB_EXEC_OBJECTS= ${LIB_EXEC_CFILES:.c=.o}


# Function serial numbers for testing the library functions;
# these should correspond to serial numbers defined in libtpcroi.c:


# Library compilation rules:
compile: ${LIB_ARCHIVE} ${LIB_EXEC}

${LIB_ARCHIVE}: ${LIB_OBJECTS}
	${AR} -rvs ${LIB_ARCHIVE} ${LIB_OBJECTS}

${LIB_EXEC}: ${LIB_OBJECTS} ${LIB_EXEC_OBJECTS}
	${LINK.c} -o ${LIB_EXEC} ${LIB_EXEC_OBJECTS} ${LIBS}

${LIB_VERSION:.c=.o}: ${LIB_CFILES}

# Installation rules:
install: install_lib install_lib_exec

install_lib:
	progvers_0_2_0 ./${LIB_EXEC} ${LIB}.version
	adddate_0_3_2 -i=${LIB}.version -o=${PET_LIB} -nodate -copy ${LIB_ARCHIVE}

install_lib_exec:
	progvers_0_2_0 ./${LIB_EXEC} ${LIB}.version
	adddate_0_3_2 -i=${LIB}.version -o=${PET_BIN} -nodate -copy ${LIB_EXEC}


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


# Archiving rules:
archive:
#	progvers_0_2_0 ./${LIB_EXEC} ${LIB}.version
	cd .. 
	adddate_0_3_2 -i=${LIB}/${LIB}.version -copy -nodate ${LIB}
#	${ZIP} -r ${LIB}.zip ../${LIB}/*
#	progvers_0_2_0 ./${LIB_EXEC} ${LIB}.version
#	adddate_0_3_2 -i=${LIB}.version -o=${PET_ARCHIVE}/lib/${LIB} ${LIB_ARCHIVE}

# Testing rules:

# Cleaning rules:
clean:
	rm -f ${LIB_OBJECTS} ${LIB_EXEC_OBJECTS}

clobber:
	rm -f ${LIB_OBJECTS} ${LIB_EXEC_OBJECTS}
	rm -f ${LIB_ARCHIVE} ${LIB_EXEC} ${LIB}.version
	rm -f *~ ./include/*~ History Readme
	rm -rf ./html


# Upgrade rules; do all:
upgrade: clean compile test install clobber html 
