#*********************************************************************
#
# File          :   Makefile
#
# Project       :   ASCII based interface to device server API
#
# Description   :   Makefile to build libtcapi.so
#
# Author        :   A.Gotz
#
# Original	:   October 1999
#
#
# Copyleft (c) 1999 by European Synchrotron Radiation Facility,
#                      Grenoble, France
#
#**********************************************************************
#

#---------------------------------------------------------------------
#	This Makefile works with the GNU make (sometimes called gmake)
#	It makes use of the GNU make conditional statements to support
#	multiple platforms. To use this makefile for a particular platform
#	call GNU make with the appropriate symbol for that platform
#	defined e.g. "gmake linux=1 all". The following symbols
#	are used to identify the following platforms :
#
#	linux		=	Linux
#	hpux10.2	=	HPUX 10.20 9000 series  
#	solaris		=	Solaris 
#	
DS_HOME	= $(DSHOME)
TCVERS=$(shell ident tc_str.c | grep Header | awk -f ./version.awk)

ifdef linux
LIB_HOME     =  $(DS_HOME)/lib/linux/x86
INSTALL_HOME =  $(DS_HOME)/lib/linux/x86
endif


#---------------------------------------------------------------------
# All include file and standard library pathes
#


INCLDIRS =  	-I ../include \
		-I ../../ascapi/include \
		-I $(DS_HOME)/include

#---------------------------------------------------------------------
# All necessary compiler flags
#
#                	Libraries

NAME =       	-o 

ifdef linux
CC      =       gcc
endif

ifdef linux
CFLAGS  =       -Dlinux -DEBUG -c $(INCLDIRS)
CFLAGS_SL  =    $(CFLAGS) -fPIC
LFLAGS = 	-G
endif

#
#---------------------------------------------------------------------
# All Files needed for the library to build
#
#               all include files
INCL     =	tc_api.h \
		tc_str.h

#               source files
SRC	 =	tc_str.c Makefile

#               object files for archive library
OBJS	=	tc_str.o

#               object files for shared library
OBJS_SL =	tc_str.so.o



#--------------------------------------------------------------------
# What has to be made
#
#		Names of the libraries shared and archive

LIBNAME =       libtcapi.a
ifdef linux
LIBNAME_SL =    libtcapi
SL_EXT =	so
endif

#---------------------------------------------------------------------
# build libraries
#

	
all:		$(LIBNAME) $(LIBNAME_SL).$(SL_EXT)



# define a rule for making shared library objects (suffice .sl.o)
.SUFFIXES: .so.o .c
.c.so.o:
	$(CC) $(CFLAGS_SL) $< -o $*.so.o


$(LIBNAME): $(OBJS)
		ar rv $(LIBNAME) $(OBJS)

$(LIBNAME_SL).$(SL_EXT): $(OBJS_SL)
		echo "making TCAPI shared library VERSION $(TCVERS) ..."
		$(CC) -shared -Wl,-soname,$(LIBNAME_SL).$(SL_EXT) \
		-o $(LIBNAME_SL).$(TCVERS).$(SL_EXT) $(OBJS_SL)
		rm -rf $(LIBNAME_SL).$(SL_EXT)
		ln -s $(LIBNAME_SL).$(TCVERS).$(SL_EXT) $(LIBNAME_SL).$(SL_EXT)


install:	$(LIBNAME_SL).$(SL_EXT)
		echo "installing TCAPI shared library VERSION $(TCVERS) ..."
		cp $(LIBNAME_SL).$(TCVERS).$(SL_EXT) $(INSTALL_HOME)
		rm -rf $(INSTALL_HOME)/$(LIBNAME_SL).$(SL_EXT)
		cd $(INSTALL_HOME); \
		ln -s $(LIBNAME_SL).$(TCVERS).$(SL_EXT) $(LIBNAME_SL).$(SL_EXT)


clean:	
		-rm -f $(OBJS) 
		-rm -f $(OBJS_SL) 


clobber:	clean
		-rm -f $(LIBNAME_SL).$(TCVERS).$(SL_EXT)
		-rm -f $(LIBNAME_SL).$(SL_EXT)
		-rm -f $(LIBNAME)
