#*********************************************************************
#
# File:          Makefile
#
# Project:       Database for Device Servers with sun-rpc
#
# Description:   Makefile for the database tools (db_update etc.)
#		 for TACO device servers
#
#                Please use the conditional GNU Makefile commands !
#			
#		 e.g. gmake unix=1 linux=1 x86=1 all
#
# Author(s):     Andy Gotz
#
# Original:	 October 1998
#
#
# $Revision$
# $Date$
#
# $Author$
#
# $Log$
#
# Copyright (c) 1998 by European Synchrotron Radiation Facility,
#                       Grenoble, France
#
#                       All Rights Reserved
#
#**********************************************************************

#---------------------------------------------------------------------
# Home Directories
#
#
#       The variables DSHOME is passed to the Makefile
#       as input arguments or via the environment.
#
# external variable DSHOME
DS_HOME   =   	$(DSHOME)

LOHOME    =	`pwd`

RM = rm -rf

ifdef __hpux10
LIB_HOME =  $(DS_HOME)/lib/hpux10.2
INSTALL_HOME =  $(DS_HOME)/system/bin/hpux10.2
endif
ifdef _solaris
LIB_HOME =  $(DS_HOME)/lib/solaris
INSTALL_HOME =  $(DS_HOME)/system/bin/solaris
endif
ifdef linux
ifdef x86
LIB_HOME =  $(DS_HOME)/lib/linux/x86
INSTALL_HOME =  $(DS_HOME)/system/bin/linux/x86
endif # x86
ifdef 68k
LIB_HOME =  $(DS_HOME)/lib/linux/68k
INSTALL_HOME =  $(DS_HOME)/system/bin/linux/68k
endif # 68k
endif # linux

#---------------------------------------------------------------------
#		The C++ compiler (external variable)
ifdef unix
#               ... and his Flags
#                       Includes
INCLDIRS=      -I$(DS_HOME)/include \
		-I$(DS_HOME)/include/private

#                       Libraries
#               No link phase - ergo no libraries to include

NAME    =       -o
endif # unix

#                       Optimizer or ANSI standart?
ifdef __hpux10
CFLAGS  =       +W302 -c $(INCLDIRS) -DNDBM
LFLAGS 	= 	-Wl,+s -Wl,+vallcompatwarnings -Wl,-a,archive \
		-L$(LIB_HOME) -ldsapi -ldbapi -ldsxdr -lgdbm
endif
ifdef _solaris
CFLAGS  =       -c $(INCLDIRS) -DNDBM
LFLAGS 	= 	-L$(LIB_HOME) -ldsapi -ldbapi -ldsxdr -lsocket -lgdbm -lnsl -lstdc++
endif
ifdef linux
CFLAGS  =      	$(INCLDIRS) -c  -DNDBM
LFLAGS 	= 	-L$(LIB_HOME) -ldsapi -ldbapi -ldsxdr -lgdbm
endif


#---------------------------------------------------------------------
# RCS options
#
#               RCS lock options
RCSLOCK  =      co -l -r$(VERSION)
#               RCS check out options
RCSCO    =      co -r$(VERSION)
#               RCS check in options
RCSCI    =      ci -u -f -s"Rel" -r$(VERSION) -m"$(LOCKMSG)"
#               RCS unlock options
RCSUNLOCK  =    rcs -u$(VERSION)
#               RCS diff options
RCSDIFF    =    rcsdiff -r$(VERSION)

#---------------------------------------------------------------------
# All files needed for the library
#
#	File list for RCS control
#               all include files
#
#	source list to make library
#		
SRC =		db_fillup.cpp \
	 	db_update.cpp \
	 	db_read.cpp \
	 	db_info.cpp \
	 	db_initcache.cpp \
	 	db_devinfo.cpp \
	 	db_devdel.cpp \
	 	db_servdel.cpp \
	 	db_servinfo.cpp \
	 	db_servunreg.cpp \
	 	db_devres.cpp \
	 	db_resdel.cpp

#               object files
OBJS =		db_fillup.o \
	 	db_update.o \
	 	db_read.o \
	 	db_info.o \
	 	db_initcache.o \
	 	db_devinfo.o \
	 	db_devdel.o \
	 	db_servdel.o \
	 	db_servinfo.o \
	 	db_servunreg.o \
	 	db_devres.o \
	 	db_resdel.o

#--------------------------------------------------------------------
# What has to be made
#
TOOLS =		db_fillup \
	 	db_update \
	 	db_read \
	 	db_info \
	 	db_initcache \
	 	db_devinfo \
	 	db_devdel \
	 	db_servdel \
	 	db_servinfo \
	 	db_servunreg \
	 	db_devres \
	 	db_resdel

#---------------------------------------------------------------------
# Rules

%.o : %.cpp ; $(CXX) $(CFLAGS) $<  

#---------------------------------------------------------------------
# Build library

ifdef unix
all:	$(TOOLS)

db_fillup : db_fillup.o
	$(CXX) db_fillup.o -o db_fillup $(LFLAGS)

db_update : db_update.o
	$(CXX) db_update.o -o db_update $(LFLAGS)

db_read : db_read.o
	$(CXX) db_read.o -o db_read $(LFLAGS)

db_info : db_info.o
	$(CXX) db_info.o -o db_info $(LFLAGS)

db_initcache : db_initcache.o
	$(CXX) db_initcache.o -o db_initcache $(LFLAGS)

db_devinfo : db_devinfo.o
	$(CXX) db_devinfo.o -o db_devinfo $(LFLAGS)

db_devdel : db_devdel.o
	$(CXX) db_devdel.o -o db_devdel $(LFLAGS)

db_servdel : db_servdel.o
	$(CXX) db_servdel.o -o db_servdel $(LFLAGS)

db_servinfo : db_servinfo.o
	$(CXX) db_servinfo.o -o db_servinfo $(LFLAGS)

db_servunreg : db_servunreg.o
	$(CXX) db_servunreg.o -o db_servunreg $(LFLAGS)

db_devres : db_devres.o
	$(CXX) db_devres.o -o db_devres $(LFLAGS)

db_resdel : db_resdel.o
	$(CXX) db_resdel.o -o db_resdel $(LFLAGS)

db_sec_passwd : db_sec_passwd.o
	$(CXX) db_sec_passwd.o -o db_sec_passwd $(LFLAGS)

endif # unix

install :       
#		install library
		cp $(TOOLS) $(INSTALL_HOME)

clean :
		$(RM) $(OBJS)

clobber:	clean
		$(RM) $(TOOLS) 


lock:
		$(RCSLOCK) $(SRC)

co:
		$(RCSCO) $(SRC)
		cd $(LOHOME)

ci:
		$(RCSCI) $(SRC)
		cd $(LOHOME)

unlock:
		$(RCSUNLOCK) $(SRC)
		cd $(LOHOME)

diff:
		$(RCSDIFF) $(SRC)
		cd $(LOHOME)
