#*********************************************************************
#
# File:          Makefile
#
# Project:       Device Servers in C++
#
# Description:   GNU Makefile for the Serial class implemented in C++
#
# Author(s):     Manuel Perez
#
# Original:	 February 1999
#
# $Log: Makefile,v $
# Revision 1.7  1999/06/22 11:49:38  perez
# serialds: full path serialline device descriptor
#
# Revision 1.6  1999/06/22 11:15:28  perez
# serialds: add CLASS resource for debug messages
#
# Revision 1.5  1999/06/21 13:58:16  perez
# First Release
#
# Revision 1.4  1999/04/09 15:30:17  perez
# Ok, with board init in driveur
#
# Revision 1.3  1999/04/06 11:36:47  perez
# Add miniterm and bridge tools
#
# Revision 1.2  1999/03/25 16:18:01  perez
# Works with standard driver (one IRQ per port)
#
# Revision 1.1  1999/03/02 09:53:28  perez
# Suppress Class resources
#
# Revision 1.0  1999/02/23 18:38:55  perez
# Initial Revision
#
#
#
# README :      To use this GNU Makefile call GNU make (gmake)
#               with the appropiate flags defined depending on your system
#               e.g. make unix=1 linux68k=1 or gmake unix=1 __hpux=1.
#               The following flags are used in this Makefile :
#
#                       unix            - for Unix (i.e. HPUX, Solaris, Linux)
#                       __hpux          - for HPUX
#                       _hp9000s700     - for HPUX on HP9000/700
#                       _UCC            - for OS9 Ultra-C++
#                       _solaris        - for Solaris
#                       linuxx86        - for Linux on x86 platform
#                       linux68k        - for Linux on 68k platform
#
#		Here is the syntaxe to generate the device server for a
#		linux x86 box, the load argument download it directly on the
#		test machine:
#			make unix=1 linuxx86=1
#			make unix=1 linuxx86=1 load
#
#		Several tools (sources located under test/ directory) only
#		available for linux x86, the loadxxx argument generates
#		and downloads them directly on the test machine:
#			make test
#			make loadtest
#
#		Downloading system configuration scripts on the test machine:
#			make loadscripts
# 
# Copyright (c) 1997 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 unix
CXX	=	g++
endif # unix

ifdef _UCC
CXX	=	xcc
endif # _UCC

#               ... and his Flags
#
#                Includes
#

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

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

NAME    =       -o


# Debug flags
DEBUG =  -D DS_DBUG=0 -D SL_DEBUG=1 -g


#                       ANSI standard
ifdef __hpux
CFLAGS	=	-g -Dunix -D__STDC__   -DPRINT -D_HPUX_SOURCE -c
endif # __hpux
ifdef _solaris
CFLAGS	=	-g -Dunix -D__STDC__ -c
endif # solaris

ifdef linuxx86
CFLAGS	=	-g -Dunix -D__STDC__  -c $(DEBUG)
endif # linuxx86

ifdef linux68k
CFLAGS	=	-g -Dunix -D__STDC__ -c
endif # linux68k

ifdef _UCC
CFLAGS  =       -mode=c89 -qp -to osk -tp 020 -x il -e as=. -a=warn \
		  -DPRINT $(INCLDIRS)
endif # _UCC

CXXFLAGS =	$(CFLAGS) $(INCLDIRS)

ifdef unix
LIBS	=	-ldsclassg++ -ldsapig++ -ldbapi -ldsxdr -lm
endif # unix

ifdef linuxx86
LIBS	=	-ldsapig++ -ldbapi -ldsxdr -lm
endif # linuxx86

ifdef linux68k
LIBS	=	-ldsapig++ -ldbapi -ldsxdr -lm
endif # linux68k

ifdef _UCC
LIBS =		-l dsclass++ \
		-l dsapi++ \
		-l dbapi \
		-l dsapi++ \
		-l dsxdr \
		-l cplib.l \
                -l dataport \
		-l os9esrfa.l \
		-l rpclib.l \
		-l netdb_small.l \
		-l unix.l \
		-l socklib.l \
		-l sys_clib020.l
endif # _UCC

ifdef __hpux
LFLAGS	=	-L$(DSHOME)/lib/s700
endif # __hpux
ifdef _solaris
LFLAGS	=	-L$(DSHOME)/lib/solaris
endif # _solaris

ifdef linuxx86
LFLAGS	=	-L$(DSHOME)/lib/linux/x86 -static
endif # linuxx86

ifdef linux68k
LFLAGS	=	-L$(DSHOME)/lib/linux/68k
endif # linux68k

ifdef _UCC
LFLAGS  =	-mode=c89 -b -Wl,-a -Wl,-M=20k \
		-L$(DSHOME)/lib/os9 -L/usr/local/os9/dd/LIB
endif # _UCC

ifdef __hp9000s700
INSTALL_HOME =	$(DSHOME)/lib/s700
endif # __hp9000s700
ifdef _solaris
INSTALL_HOME =	$(DSHOME)/lib/solaris
endif # _solaris

ifdef linuxx86
INSTALL_HOME =	$(DSHOME)/lib/linux
endif # linuxx86

ifdef linux68k
INSTALL_HOME =	$(DSHOME)/lib/linux
endif # linux68k

ifdef _UCC
INSTALL_HOME =	$(DSHOME)/lib/os9
endif # _UCC


#---------------------------------------------------------------------
# All files needed for the library
#
#	File list for RCS control
#               all include files
CLASS_INCL =	 $(SERVER_NAME).h

#               source files
SERVER_NAME =	Serial
CLASS_SRC =	$(SERVER_NAME).cpp \
		startup.cpp

#--------------------------------------------------------------------
# What has to be made
#
#               Names of the include files in the 
#		installation directories
#
INCL_INST  = 	../include/$(SERVER_NAME).h

SERVER =  $(SERVER_NAME)ds

CLIENT = template_menu

ifdef unix
LIBNAME	=	libdsclassg++.a
endif # unix
ifdef _UCC
LIBNAME =	libdsclass++.a
endif # _UCC

#---------------------------------------------------------------------
# Build server
#

all:	$(SERVER)

$(SERVER) : 	startup.o  $(SERVER_NAME).o
ifdef unix
	$(CXX) startup.o  $(SERVER_NAME).o $(LFLAGS) $(LIBS) -o $(SERVER)
endif # unix
ifdef _UCC
	$(CXX) $(LFLAGS) $(LIBS) -o $(SERVER) startup.o  $(SERVER_NAME).o
endif # _UCC

startup.o : startup.cpp
	$(CXX) $(CXXFLAGS) startup.cpp

$(SERVER_NAME).o :  $(SERVER_NAME).cpp $(INCL_INST)
	$(CXX) $(CXXFLAGS)  $(SERVER_NAME).cpp

#---------------------------------------------------------------------
# Build client
#

$(CLIENT) : 	template_menu.o
ifdef unix
	$(CXX) template_menu.o $(LFLAGS) $(LIBS) -o $(CLIENT)
endif # unix
ifdef _UCC
	$(CXX) $(LFLAGS) $(LIBS) -o $(CLIENT) template_menu.o 
endif # _UCC

template_menu.o : template_menu.cpp
	$(CXX) $(CXXFLAGS) template_menu.cpp

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

$(LIBNAME):  $(SERVER_NAME).o
	cp $(INSTALL_HOME)/$(LIBNAME) .
ifdef unix
	ar rv $(LIBNAME)  $(SERVER_NAME).o
endif # unix
ifdef _UCC
	libgen  $(SERVER_NAME).o -co=$(LIBNAME)
endif # _UCC

install : $(LIBNAME)
	cp -f ../include/$(SERVER_NAME).h $(DSHOME)/include++
	chmod 664 $(DSHOME)/include++/$(SERVER_NAME).h
	cp $(LIBNAME) $(INSTALL_HOME)

#---------------------------------------------------------------------
# Downloading the server to the target host
#
HOST = tb004
USER = dserver
DIR  = /users/dserver/bin/linuxx86
#
load:	$(SERVER)
	@echo -e "Download the server to \"$(HOST)\"\c"
	@(rcp $(SERVER) $(USER)@$(HOST):$(DIR))
	@echo -e "\007 .....  done."

#---------------------------------------------------------------------
#
out:
	co -l Makefile
	co -l README
	co -l $(CLASS_SRC)
	cd ../include; co -l $(CLASS_INCL); cd ../src

in:
	ci -u -f$(VERSION) -m"$(LOCKMSG)" Makefile
	ci -u -f$(VERSION) -m"$(LOCKMSG)" README
	ci -u -f$(VERSION) -m"$(LOCKMSG)" $(CLASS_SRC)
	cd ../include; ci -u -f$(VERSION) -m"$(LOCKMSG)" $(CLASS_INCL);cd ../src

#---------------------------------------------------------------------
#
clean :
	rm -rf *.o

ifdef _UCC
	rm -rf *.dbg *.stb
endif # _UCC


clobber:	clean
	rm -rf $(SERVER)
	rm -rf $(LIBNAME)


