#
# RcsID = " $Header: Makefile,v 2.1 96/12/17 18:21:02 meyer Exp $ ";
#
#*********************************************************************
#
# File:          Makefile 
#
# Project:       Device Servers with SUN-RPC
#
# Description:   Makefile for SerialLine device server
#
# Original:   	 March 1994
#
# $Log:	Makefile,v $
# Revision 2.1  96/12/17  18:21:02  18:21:02  meyer (J.Meyer)
# changed netdb.l to netdb_small.l for os9.
# 
# Revision 2.0  95/11/10  18:24:13  18:24:13  beteva (A.Beteva)
# corresponds to v2.0 of the server
# 
# Revision 1.2  95/11/10  15:43:25  15:43:25  goetz (Andy Goetz)
# added extra 10K stack, added csl library
# 
# Revision 1.1  
# Initial revision
#
# Copyright (c) 1994 by European Synchrotron Radiation Facility,
#                       Grenoble, France
#
#**********************************************************************

#---------------------------------------------------------------------
#	usage uccmake e=<edition number> VERSION=<version number>
#	      xxxmake VERSION=<version number>
#	make ci LOCKMSG=<message>
#	The variable MWOS is passed via the environment as:
# 	MWOS	 =	/usr/local/MWOS
#	The search path is set as
# 	PATH     =	$PATH:$MWOS/UNIX/bin/hp97k
#
#	For UltraC use the settings for the environment variables:
 	DSHOME 	 = 	/libra/users/d/dserver
 	CDEF 	 =	$(MWOS)/OS9/SRC/DEFS
 	CDEFESRF =	/usr/local/os9/dd/DEFS
 	CLIB 	 =	$(MWOS)/OS9/LIB
 	CLIBESRF =	/usr/local/os9/dd/LIB
#
#
# Home Directories
#

ifdef _UCC
LIB_HOME	= $(DSHOME)/lib/os9/ucc
OBJS_HOME	= $(DSHOME)/lib/os9/ucc/objs
INSTALL_HOME	= $(DSHOME)/bin/os9
endif # _UCC
ifdef lynx
LIB_HOME     =  $(DSHOME)/lib/lynxos
INSTALL_HOME =  $(DSHOME)/bin/lynxos
endif # lynx
ifdef __hp9000s700
LIB_HOME     =  $(DSHOME)/lib/s700
INSTALL_HOME =  $(DSHOME)/bin/s700
DASLIB	     = $(DASHOME)/lib/s700
endif # __hp9000s700
ifdef sun
LIB_HOME     =  $(DSHOME)/lib/sun4
INSTALL_HOME =  $(DSHOME)/bin/sun4
endif # sun
ifdef _solaris
LIB_HOME     =  $(DSHOME)/lib/solaris2
INSTALL_HOME =  $(DSHOME)/bin/solaris2
endif # _solaris


#---------------------------------------------------------------------
# All include file and standard library paths
#
#		make sure to get always the new include files 
#		under ../include
#
ifdef _UCC
INCLDIRS =  	-I ../include \
		-I $(DSHOME)/include \
		-I $(DSHOME)/include/private
#		-I $(CDEFESRF)
endif # _UCC

ifdef unix
INCLDIRS =	-I../include \
		-I$(DSHOME)/include \
		-I$(DSHOME)/include/private
endif # unix

#---------------------------------------------------------------------
# All necessary compiler flags for UNIX and OS9
#

# Debug flags
DEBUG =  -D DS_DBUG=0 -D SL_DBUG -g

ifdef _UCC
#               The C Compiler for OS9
CC =       	/usr/local/MWOS/UNIX/bin/hp97k/xcc

#                	Libraries
LIBDIRS =       -L $(LIB_HOME) \
		-L $(CLIB) \
		-L $(CLIBESRF) 

LFLAGS =   	$(LIBDIRS) \
		-l dsapi \
		-l dsxdr \
		-l dbapi \
		-l rpclib.l \
		-l socklib.l \
		-l netdb_small.l \
		-l unix.l \
		-l sys_clib.l \
		-l os9esrf.l \
		-l csl.l
#		-l dsclass \

ICODE_LFLAGS = 	$(LIBDIRS) \
                -Wi,-l=$(LIB_HOME)/libdsapi.il \
                -Wi,-l=$(LIB_HOME)/libdsxdr.il \
                -Wi,-l=$(LIB_HOME)/libdbapi.il \
		-Wi,-l=$(LIB_HOME)/libdsclass.il \
                -l dsapi \
                -l rpclib.l \
                -l netdb.l \
                -l socklib.l \
                -l sys_clib.l \
		-l csl.l

#               	Compiler Flags
#CFLAGS = -mode=c89 -to osk -tp 020 -Wl,-e=$(e) -i -M ol=10K $(INCLDIRS)
CFLAGS = -mode=c89 -to osk -tp 020ld -Wl,-e=$(e) -i -M ol=10K $(INCLDIRS)
# $(DEBUG)
NAME =       	-o $@
endif # _UCC

ifdef unix
#               The C Compiler for HPUX
CC =       	/bin/cc
ifdef lynx
CC      =       gcc
endif # lynx

#                       Libraries
LIBDIRS =       -L $(LIB_HOME)
LFLAGS = 	$(LIBDIRS) -ldsapi -ldbapi -ldsxdr
# when using CodeCenter
CODELIBS = -L $(DSHOME)/lib/s700 -ldsapi -ldbapi -ldsxdr

NAME =       	-o 
endif # unix

#            		Optimizer and ANSI standart for UNIX
ifdef __hpux
CFLAGS = 	-Aa  -D_HPUX_SOURCE $(INCLDIRS)
#$(DEBUG)
endif # __hpux
ifdef sun
CFLAGS = 	-O $(INCLDIRS) $(DEBUG)
endif # sun
ifdef lynx
CFLAGS  =       -Dlynx -Dunix -ansi -X $(INCLDIRS)
endif # lynx

#--------------------------------------------------------------------
#	 Server and test menu generic names
SERVER	 = 	SerialLine
CLIENT	 = 	SerialLine_menu


#---------------------------------------------------------------------
# RCS options to lock and check out a version.
# Or to check in a new version.
#
#               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)"

#---------------------------------------------------------------------
# Class library
# The object file representing the class has
# to be added to the class library.
#
CLASS_LIB = libdsclass.a
CLASS_OBJS = $(SERVER).o

#
#---------------------------------------------------------------------
# All Files needed for the Server and the client
#
#               all include files
INCL     =	$(SERVER)P.h \
		$(SERVER).h 
#		Dev$(SERVER)Cmds.h \
#		Dev$(SERVER)Errors.h

RES	=	$(SERVER).res \
		$(SERVER)Cmds.res

#               source files
SRC	 =	startup.c \
		$(SERVER).c \
		$(CLIENT).c 

#               object files
SVC_OBJS =	startup.o \
		$(SERVER).o

SVC_ICODE =	startup.i \
		$(SERVER).i

CLN_OBJS =	$(CLIENT).o

#---------------------------------------------------------------------
# What has to be made
#

#		Names of executables 
#		and include files in the installation directories
SVC_INST   = 	$(SERVER)
CLN_INST   = 	$(CLIENT)
INCL_INST  =	$(SERVER).h
# Dev$(SERVER)Cmds.h Dev$(SERVER)Errors.h
INCLP_INST = 	$(SERVER)P.h

#---------------------------------------------------------------------
# build server and client
#

ifdef _UCC
#               Rule for making OS-9 relocatable files
.SUFFIXES: .i .c
.c.i:
	
	
all:		$(SERVER)
#		cp $(SERVER) /usr/local/os9/dd/DSERVER/NEW
#$(CLIENT)

$(SERVER):  	$(SVC_OBJS)
		$(CC) $(CFLAGS) $(NAME) $(SVC_OBJS) $(LFLAGS)

$(CLIENT):  	$(CLN_OBJS)
		$(CC) $(CFLAGS) $(NAME) $(CLN_OBJS) $(LFLAGS)

icode:		$(SVC_ICODE)
		echo Linking LTDC with icode libraries!
		$(CC) $(CFLAGS) -o $(SERVER) $(SVC_ICODE) $(ICODE_LFLAGS)

$(SVC_ICODE):
		$(CC) $(CFLAGS) -P $? -o $@
endif # _UCC


ifdef unix
all:		$(CLIENT) 

$(CLIENT):  	$(CLN_OBJS) 
		$(CC) $(CFLAGS) $(NAME) $@ $(CLN_OBJS) $(LFLAGS)
endif # unix


# 		Add object file representing the class
#		to the class library.
#
$(CLASS_LIB):	$(CLASS_OBJS) 
ifdef _UCC
#		For os9 all object files are kept are
#		kept in a special directory, because
#		the library has to be built by a cat
#		of all object files.
#
		cp $(CLASS_OBJS) $(OBJS_HOME)
		libgen -c $(OBJS_HOME)/?*.o -o=$(OBJS_HOME)/$(CLASS_LIB)
		cp $(OBJS_HOME)/$(CLASS_LIB) $(LIB_HOME)
		rm -rf $(OBJS_HOME)/$(CLASS_LIB)
endif # _UCC
ifdef unix
		ar rv $(LIB_HOME)/$(CLASS_LIB) $(CLASS_OBJS)
endif # unix


#
# 		install executables		
#
ifdef _UCC
install:	$(SERVER) $(CLIENT) $(CLASS_LIB)
		cp $(SERVER) $(INSTALL_HOME)/$(SVC_INST)
		cp $(CLIENT) $(INSTALL_HOME)/$(CLN_INST)
endif # _UCC
ifdef unix
install:	$(CLIENT)
		cp $(CLIENT) $(INSTALL_HOME)/$(CLN_INST)
endif # unix
#
#		install include files
#
		rm -f $(DSHOME)/include/$(INCL_INST)
		cp ../include/$(INCL_INST) $(DSHOME)/include
		chmod 664 $(DSHOME)/include/$(INCL_INST)
		rm -f $(DSHOME)/include/private/$(INCLP_INST)
		cp ../include/$(INCLP_INST) $(DSHOME)/include/private
		chmod 664 $(DSHOME)/include/private/$(INCLP_INST)


clean:	
		-rm -f $(SVC_OBJS) 
		-rm -f $(CLN_OBJS) 
		-rm -f $(SVC_ICODE)
		-rm -f *.ic
#
# what does this do - looks dangerous !
#
#		-rm -f *~ 


clobber:	clean
		-rm -f $(SERVER)
		-rm -f $(SERVER).stb
		-rm -f $(SERVER).dbg
		-rm -f $(CLIENT) 


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

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

ci:
		$(RCSCI) $(SRC)
		cd ../include; $(RCSCI) $(INCL); cd ../src
		cd ../res; $(RCSCI) $(RES); cd ../src
#
#
# when using CodeCenter
code-c:
	#load $(SRC) $(CFLAGS) $(INCLDIRS) $(CODELIBS)
