
#*********************************************************************
#
# File:          Makefile
#
# Project:       Device Servers with sun-rpc
#
# Description:   Makefile for DC-library libdcapi.a 
#		 Please use the conditional Makefile commands !
#
# Author(s):     Andy Gotz
#
# Original:	 August 2000
#
#
# Copyright (c) 2000 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)

# retrieve version number for present release (4.x) from dev_api.c
# this will be used to name the shared library (assumes ident is
# supported for Solaris, if this is not the case then force the
# version number or pass it as a symbol)
DCVERS=$(shell ident dcrd_cli.c | grep Header | awk -f ./version.awk)

ifdef OSK
INSTALL_HOME = 	$(DS_HOME)/lib/os9
endif
ifdef _UCC
INSTALL_HOME =  $(DS_HOME)/lib/os9/ucc
endif
ifdef __hp9000s700
INSTALL_HOME =  $(DS_HOME)/lib/s700
INSTALL_HOME_SL =  $(DS_HOME)/lib/s700
endif
ifdef __hpux10
INSTALL_HOME =  $(DS_HOME)/lib/hpux10.2
INSTALL_HOME_SL =  $(DS_HOME)/lib/hpux10.2
endif
ifdef sun
INSTALL_HOME = 	$(DS_HOME)/lib/sun4
endif
ifdef _solaris
INSTALL_HOME = 	$(DS_HOME)/lib/solaris
INSTALL_HOME_SL = 	$(DS_HOME)/lib/solaris
endif
ifdef linux
ifdef 68k
INSTALL_HOME =  $(DS_HOME)/lib/linux/68k
INSTALL_HOME_SL =  $(DS_HOME)/lib/linux/68k
else # 68k
INSTALL_HOME =  $(DS_HOME)/lib/linux/x86
INSTALL_HOME_SL =  $(DS_HOME)/lib/linux/x86
endif # 68k
endif # linux
ifdef vw68k
INSTALL_HOME =  $(DS_HOME)/lib/vxworks/68k
endif # vw68k
ifdef vwx86
INSTALL_HOME =  $(DS_HOME)\lib\vxworks\x86
endif # vwx86

#---------------------------------------------------------------------
ifdef OSK
#               The C Compiler for OS9

#               ... and his Flags
#                       Includes
INCLDIRS=       -v=../include \
		-v=$(DS_HOME)/include \
		-v=$(DS_HOME)/include/private

#                       Libraries
#               There's no link phase - ergo no libraries to include

#               	Compiler Flags
CFLAGS  =       -g -DBUG -K=2F -r=. $(INCLDIRS) $(EXTRACFLAGS)
endif

ifdef _UCC
#               The C Compiler for OS9

#               ... and his Flags
#                       Includes
INCLDIRS=       -I ../include \
                -I $(DS_HOME)/include \
		-I $(DS_HOME)/include/private

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


ifdef unix

#               ... and his Flags
#                       Includes
INCLDIRS=       -I../include \
		-I$(DS_HOME)/include \
		-I$(DS_HOME)/include/private

ifdef vw68k
INCLDIRS = 	-I../include \
		-I$(DS_HOME)/include \
		-I$(DS_HOME)/include/private \
		-I/usr/local/tornado/target/h \
		-I/usr/local/tornado/target/h/rpc \
		-I/usr/local/tornado/target/src/config
endif # vw68k
ifdef vwx86
INCLDIRS = 	-I..\include \
		-I$(DS_HOME)\include \
		-I$(DS_HOME)\include\private \
		-IC:\TORNADO\target\h \
		-IC:\TORNADO\target\rpc \
		-IC:\TORNADO\target\src\config
endif # vxworks

#                       Libraries
#               There's no link phase - ergo no libraries to include
NAME    =       -o
endif # unix


#                       Optimizer or ANSI standart ?
ifdef __hpux
CFLAGS  =       -Aa -g -DBUG -Dunix -D_HPUX_SOURCE -c $(INCLDIRS) \
		$(EXTRACFLAGS)
CFLAGS_SL  =    $(CFLAGS) +z
endif # __hpux
ifdef sun
CFLAGS  =       -Aa -g -DBUG -Dunix -c $(INCLDIRS) $(EXTRACFLAGS)
endif # sun
ifdef _solaris
ifdef NATIVE
CFLAGS  =       -Xa -g -Dsolaris -DBUG -c $(INCLDIRS) $(EXTRACFLAGS)
CFLAGS_SL  =    $(CFLAGS) -KPIC
else
CFLAGS  =       -g -Dsolaris -DBUG -c $(INCLDIRS) $(EXTRACFLAGS)
CFLAGS_SL  =    $(CFLAGS) -fPIC
endif # NATIVE
endif # _solaris
ifdef linux
CFLAGS  =      	$(INCLDIRS) -Dlinux -Dunix -D_BSD_SOURCE -ansi -DEBUG -g -c \
		$(EXTRACFLAGS)
CFLAGS_SL  =   	$(INCLDIRS) -Dlinux -Dunix -D_BSD_SOURCE -ansi -DEBUG -fPIC -c \
		$(EXTRACFLAGS)
endif # linux
ifdef lynx
CFLAGS  =      -Dlynx -Dunix -ansi -X -DBUG -g -c $(INCLDIRS) $(EXTRACFLAGS)
endif # lynx
ifdef vw68k
CFLAGS  =       -Dvxworks -Dunix -DCPU=MC68040 -ansi -m68040 \
		-fno-builtin -nostdinc -DEBUG $(INCLDIRS) $(EXTRACFLAGS)
endif # vw68k
ifdef vwx86
CFLAGS  =      	-Dvxworks -Dunix -DCPU=I80386 -ansi -mno-486 -fno-builtin \
		-nostdinc -fno-defer-pop -DBUG -g $(INCLDIRS)  $(EXTRACFLAGS)
endif # vwx86


#---------------------------------------------------------------------
# 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)"


#---------------------------------------------------------------------
# All files needed for the library
#
#		include files
INCL 	=	dc.h \
		dc_xdr.h \
		dcrd_xdr.h \
		dcwr_xdr.h

#		source files
SRC  	=	dc_sdev.c \
		dchist_cli.c \
		dcrd_xdr.c \
		dcrd_cli.c \
		dcrd_clnt.c \
		dcwr_xdr.c \
		dcwr_cli.c \
                dcwr_clnt.c \
                utils_cli.c

#		object files
OBJS  	=	dc_sdev.o \
		dchist_cli.o \
		dcrd_xdr.o \
		dcrd_cli.o \
                dcrd_clnt.o \
		dcwr_xdr.o \
                dcwr_cli.o \
                dcwr_clnt.o \
                utils_cli.o

OBJS_SL	=	dc_sdev.sl.o \
		dchist_cli.sl.o \
		dcrd_xdr.sl.o \
		dcrd_cli.sl.o \
                dcrd_clnt.sl.o \
		dcwr_xdr.sl.o \
                dcwr_cli.sl.o \
                dcwr_clnt.sl.o \
                utils_cli.sl.o

ICODE_OBJS =	dc_sdev.ic \
		dchist_cli.ic \
		dcrd_xdr.ic \
		dcrd_cli.ic \
                dcrd_clnt.ic \
		dcwr_xdr.ic \
                dcwr_cli.ic \
                dcwr_clnt.ic \
                utils_cli.ic

ifdef OSK
OBJS =		dc_sdev.r \
		dchist_cli.r \
		dcrd_xdr.r \
		dcrd_cli.r \
                dcrd_clnt.r \
		dcwr_xdr.r \
                dcwr_cli.r \
                dcwr_clnt.r \
                utils_cli.r
endif

#--------------------------------------------------------------------
# What has to be made
#
LIBNAME	   =	libdcapi.a
ifdef __hp9000s700
LIBNAME_SL =	libdcapi
SL_EXT =	sl
endif # __hp9000s700
ifdef _solaris
LIBNAME_SL =	libdcapi
SL_EXT =	so
endif # _solaris
ifdef linux
LIBNAME_SL =    libdcapi
SL_EXT =	so
endif # linux
ifdef _UCC
ICODE_LIBNAME 	 =	libdcapi.il
endif # _UCC
ifdef OSK
LIBNAME    =	os9-dcapilib.l
endif # OSK

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

all:	$(OBJS) $(LIBNAME) $(LIBNAME_ALL)

all_sl:	$(LIBNAME_SL).$(SL_EXT)

#
# DO NOT recompile everything everytime
#
#$(OBJS):	
#		$(CC) $(CFLAGS) $(SRC)


ifdef OSK
#               Making an OS-9 library is concatenating the members
#		Small kernel
$(LIBNAME):     $(OBJS)
		rm -rf $(LIBNAME)
		cat $(OBJS) > $(LIBNAME)      
endif # OSK

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


ifdef _UCC
.SUFFIXES: .ic .c
.c.ic:

#$(ICODE_OBJS):
#		$(CC) $(ICODE_CFLAGS) -P $? $(NAME)

		$(CC) $(ICODE_CFLAGS) $(NAME) -efe $<


#               Make OS-9 library
#		Small kernel
$(LIBNAME):     $(OBJS) $(ICODE_OBJS)
		rm -rf $(LIBNAME)
		libgen $(OBJS) -co=$(LIBNAME)
	
		rm -rf $(ICODE_LIBNAME)
		$(CC) $(ICODE_CFLAGS) $(ICODE_OBJS) -Wi,-m -f $(ICODE_LIBNAME)
endif # _UCC

ifdef unix
#		Make HPUX library
#		Small kernel
$(LIBNAME):	$(OBJS)
		ar rv $(LIBNAME) $(OBJS)

ifdef sun
		ranlib $(LIBNAME)
endif # sun

#
# shared libraries
#
ifndef vxworks
$(LIBNAME_SL).$(SL_EXT):	$(OBJS_SL)
ifdef _solaris
		ld -G -o $(LIBNAME_SL).$(SL_EXT).$(DCVERS) $(OBJS_SL)
endif # _solaris
ifdef __hp9000s700
		ld -b -o $(LIBNAME_SL).$(SL_EXT).$(DCVERS) $(OBJS_SL) 
endif # __hp9000s700
ifdef linux
		$(CC) -shared -Wl,-soname,$(LIBNAME_SL).$(SL_EXT).$(DCVERS) \
		-o $(LIBNAME_SL).$(SL_EXT).$(DCVERS) $(OBJS_SL) 
endif # linux
		rm -rf $(LIBNAME_SL).$(SL_EXT)
		ln -s $(LIBNAME_SL).$(SL_EXT).$(DCVERS) $(LIBNAME_SL).$(SL_EXT)
endif # !vxworks
endif #unix



install :	$(LIBNAME) 
ifndef vxworks
#		intall the library
		cp $(LIBNAME) $(INSTALL_HOME)
else
		cp libdcapi.o $(INSTALL_HOME)
endif # !vxworks 
ifdef _UCC
		cp $(ICODE_LIBNAME) $(INSTALL_HOME)
endif # _UCC
#		install the include files
#
# vxworks group does not have the permissions to copy include files
# 
ifndef vxworks
		for i in $(INCL);\
		do \
		( rm -f $(DSHOME)/include/$$i; \
		  cp ../include/$$i $(DSHOME)/include;\
		  chmod 664 $(DSHOME)/include/$$i; ) \
		done
endif # vxworks

install_sl :	
#
# shared libraries are installed as links; a new copy
# is created for each new DCVERS version
#
		cp $(LIBNAME_SL).$(SL_EXT).$(DCVERS) $(INSTALL_HOME_SL)
		rm -rf $(INSTALL_HOME_SL)/$(LIBNAME_SL).$(SL_EXT)
		cd $(INSTALL_HOME_SL); ln -s $(LIBNAME_SL).$(SL_EXT).$(DCVERS) $(LIBNAME_SL).$(SL_EXT)


clean :		
		rm -rf $(OBJS)	
		rm -rf $(OBJS_SL)	
		rm -rf $(ICODE_OBJS)
		rm -rf *.i


clobber:	clean
		rm -rf	$(LIBNAME) 
ifdef $(LIBNAME_SL)
		rm -rf  $(LIBNAME_SL).$(SL_EXT)
		rm -rf  $(LIBNAME_SL).$(SL_EXT).$(DCVERS)
endif # $(LIBNAME_SL)
ifdef _UCC
		rm -rf	$(ICODE_LIBNAME) 
endif # _UCC


lock:
	$(RCSLOCK) $(SRC)
	cd ../include; $(RCSLOCK) $(INCL); cd ../src

co:
	$(RCSCO) $(SRC)
	cd ../include; $(RCSCO) $(INCL); cd ../src

ci:
	$(RCSCI) $(SRC)
	cd ../include; $(RCSCI) $(INCL); cd ../src
#
