#*********************************************************************
#
# File:          Makefile
#
# Project:       Database for Device Servers with sun-rpc
#
# Description:   Makefile for the database server (dbm_server)
#		 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`

ifdef vwx86
RM = del
else
RM = rm -rf
endif # vwx86

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
LIB_HOME =  $(DS_HOME)/lib/linux/x86
INSTALL_HOME =  $(DS_HOME)/system/bin/linux/x86
endif # linux


#---------------------------------------------------------------------
#		The C compiler (external variable)
ifdef _UCC
#               The C Compiler for OS9

#               ... and his Flags
#                       Includes
INCLDIRS=       -I ../include \
                -I ../../cmds_err/include \
                -I ../../../../classes/main/include \
                -I ../../../xdr/include \
		-I ../../admin/include \
                -I $(DS_HOME)/include \
                -I $(DS_HOME)/include/private \
                -I /usr/local/os9/dd/DEFS

#                       Compiler Flags
CFLAGS =        -mode=c89 -g -D EBUG -to osk -tp 020 -x il -e as=. $(INCLDIRS)
ICODE_CFLAGS =  -mode=c89 -to osk -tp 020 -e il $(INCLDIRS)
NAME =          -o $@
endif

ifdef unix
#               ... and his Flags
#                       Includes
INCLDIRS=      	-I../include \
		-I../../../dserver/system/api/apilib/include \
		-I$(DS_HOME)/include \
		-I$(DS_HOME)/include/private \
		-I$(DS_HOME)/include++

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

NAME    =       -o
endif # unix

#                       Optimizer or ANSI standart?
ifdef __hpux10
CFLAGS  =       -DNDBM +W302 $(INCLDIRS) -c
LFLAGS = 	-Wl,+s -L$(LIB_HOME) -ldsxdr -ldsapi -ldsxdr -ldbapi -lgdbm
endif
ifdef _solaris
CFLAGS  =       -D_solaris -DNDBM $(INCLDIRS) -c
LFLAGS = 	-L$(LIB_HOME) -ldsxdr -ldsapi -ldsxdr -ldbapi -lsocket \
		-L/usr/ucblib -lnsl -lstdc++ -lgdbm 
endif
ifdef linux
CFLAGS  =      	-DNDBM $(INCLDIRS) -c 
LFLAGS = 	-L$(LIB_HOME) -ldsxdr -ldsapi -ldsxdr -ldbapi -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 =		NdbmClass.cpp \
		dbm_devbro.cpp \
		dbm_resbro.cpp \
		main_svc.cpp \
		dbm_miscbro.cpp \
		dbm_clo_op.cpp \
	 	dbm_getdev.cpp \
	 	dbm_impexp.cpp \
		dbm_serv.cpp \
		dbm_tools.cpp \
	 	cmd_query.cpp \
	 	dbm_xdr.cpp \
		dbm_psdev.cpp \
		dbm_update.cpp

#               object files
OBJS =		NdbmClass.o \
		dbm_devbro.o \
		dbm_resbro.o \
		main_svc.o \
		dbm_miscbro.o \
		dbm_clo_op.o \
	 	dbm_getdev.o \
	 	dbm_impexp.o \
		dbm_serv.o \
		dbm_tools.o \
	 	cmd_query.o \
	 	dbm_xdr.o \
		dbm_psdev.o \
		dbm_update.o

#--------------------------------------------------------------------
# What has to be made
#
SERVER =       dbm_server


#--------------------------------------------------------------------
# implicit rule how to make .o from .cpp
.SUFFIXES: .o .cpp
.cpp.o:
	$(CXX) $(CFLAGS) $< -o $*.o
#---------------------------------------------------------------------
# Build library

ifdef unix
all:	$(SERVER)

$(SERVER) : $(OBJS)
	$(CXX) $(OBJS) -o $(SERVER) $(LFLAGS) 
endif # unix


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

clean :
		$(RM) $(OBJS)

clobber:	clean
		$(RM) $(SERVER) 


lock:
		$(RCSLOCK) $(SRC)

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

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

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

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