#*********************************************************************
#
# File:          Makefile
#
# Project:       Device Servers in C++
#
# Description:   GNU Makefile for the Serial class implemented in C++
#
# Author(s):     Manuel Perez, Andy Gotz
#
# Original:	 February 1999
#
# 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`


CXX	=	g++
CC	=	gcc

#               ... and his Flags
#
#                Includes
#

INCLDIRS=       -I. \
		-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

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 __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 __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

#---------------------------------------------------------------------
# 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  = 	$(SERVER_NAME).h

SERVER =  $(SERVER_NAME)ds

CLIENT = SerialLine_menu

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

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

all:	$(SERVER) $(CLIENT)

$(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) : 	SerialLine_menu.o
	$(CC) SerialLine_menu.o $(LFLAGS) $(LIBS) -o $(CLIENT)

SerialLine_menu.o : SerialLine_menu.c
	$(CC) $(CXXFLAGS) SerialLine_menu.c

#---------------------------------------------------------------------
# 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 $(SERVER_NAME).h $(DSHOME)/include++
	chmod 664 $(DSHOME)/include++/$(SERVER_NAME).h
	cp $(LIBNAME) $(INSTALL_HOME)

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

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