#---------------------------------------------------------------------
# Home Directories
#
#
#       The variables DSHOME is passed to the Makefile
#       as input arguments or via the environment.
#
# external variable DSHOME
DS_HOME   =   	$(DSHOME)

DEV_CLASS =     ../../../../classes/main
DEV_CLASSP =    ../../../../classes++/device
DEV_CMDS  =     ../../cmds_err
LOHOME    =	`pwd`


ifdef _UCC
INSTALL_HOME =  $(DS_HOME)/lib/os9
endif

ifdef __hpux
INSTALL_HOME =  $(DS_HOME)/lib/s700
endif

ifdef __hpux10
INSTALL_HOME =  $(DS_HOME)/lib/hpux10.2
endif

ifdef linux
ifdef x86
INSTALL_HOME =  $(DS_HOME)/lib/linux/x86
endif # x86
ifdef 68k
INSTALL_HOME =  $(DS_HOME)/lib/linux/68k
endif # 68k
endif

ifdef _solaris
INSTALL_HOME =  $(DS_HOME)/lib/solaris
endif

ifdef vw68k
INSTALL_HOME =  $(DS_HOME)/lib/vxworks/68k
endif

ifdef vwx86
INSTALL_HOME =  $(DS_HOME)\lib\vxworks\x86
endif

#               ... and his Flags
#                       Includes
ifdef _UCC
INCLDIRS=       -I../include \
		-I../../../../classes++/device/include \
		-I../../../../classes++/device/oic/include \
                -I../../cmds_err/include \
                -I../../../../classes/main/include \
                -I../../../xdr/include \
                -I$(DS_HOME)/include \
		-I$(DS_HOME)/include++ \
                -I$(DS_HOME)/include/private
else
INCLDIRS=       -I../include \
		-I../../../../classes++/device/include \
		-I../../../../classes++/device/oic/include \
                -I../../cmds_err/include \
                -I../../../../classes/main/include \
                -I../../../xdr/include \
                -I$(DS_HOME)/include \
		-I$(DS_HOME)/include++ \
                -I$(DS_HOME)/include/private \
		-I/usr/include
endif # _UCC

ifdef __hpux
INCLDIRSXX =	-I$(DS_HOME)/include/hpux10
endif

ifdef _UCC
INCLDIRSXX =	-I/usr/local/os9/dd/DEFS
endif

ifdef vw68k
INCLDIRSXX=	-I$(WIND_BASE)/target/h \
		-I$(WIND_BASE)/target/h/rpc \
		-I$(WIND_BASE)/target/src/config
endif # vw68k

ifdef vwx86
INCLDIRSXX=	-IC:\TORNADO\target\h \
		-IC:\TORNADO\target\h\rpc \
		-IC:\TORNADO\target\src\config
endif # vwx86


#                       Compiler Flags
ifdef _UCC
#               The C Compiler for OS9
CXX =            /usr/local/MWOS/UNIX/bin/xcc
CFLAGS =        -mode=c89 -g -qp -D EBUG -to osk -tp 020 -x il -a=warn -e as=. \
		$(INCLDIRS) $(INCLDIRSXX) $(EXTRACFLAGS)
ICODE_CFLAGS =  -mode=c89 -qp -D EBUG -to osk -tp 020 -e il $(INCLDIRS) \
		$(INCLDIRSXX)
NAME =          -o $@
endif

ifdef __hpux
ifdef NATIF
CXX =		aCC
else
CXX =		g++
endif
CFLAGS  =       -g -Dunix $(INCLDIRS) $(INCLDIRSXX) \
		-D__STDC__ -D_HPUX_SOURCE -D__STDC__ -c $(EXTRACFLAGS)
endif

ifdef __hpux10
ifdef NATIF
CFLAGS  =       -g -Dunix +W302,749 $(INCLDIRS) -D_HPUX_SOURCE \
		-D_XOPEN_SOURCE_EXTENDED -c $(EXTRACFLAGS)
CXXFLAGS_SL =	$(CFLAGS) +z
else
CFLAGS  =       -g -Dunix $(INCLDIRS) -c  $(EXTRACFLAGS)
endif
endif # __hpux10

ifdef linux
ifdef x86
CXX =		g++
CFLAGS  =       -g -Dunix $(INCLDIRS) $(INCLDIRSXX) \
		-D__STDC__ -D_GNU_SOURCE -c $(EXTRACFLAGS)
else
CXX =		/usr/bin/m68k-linux-g++
CFLAGS  =       -g -Dunix -Dlinux68k -I/usr/include/m68k-linux \
		$(INCLDIRS) $(INCLDIRSXX) -D__STDC__ -c $(EXTRACFLAGS)
endif # x86
CXXFLAGS =	$(CFLAGS) $(INCLDIRSXX) -D__STDC__ 
CXXFLAGS_SL =	$(CXXFLAGS) -fPIC
endif

ifdef _solaris
ifdef NATIF
CXX =		/opt/SUNWspro/bin/CC
else
CXX =		g++
endif
CFLAGS  =       -g -Dunix -Dsolaris $(INCLDIRS) $(INCLDIRSXX) -c $(EXTRACFLAGS)
CXXFLAGS =	$(CFLAGS) $(INCLDIRSXX)
CXXFLAGS_SL =	$(CXXFLAGS) -fPIC
endif

ifdef vw68k
#CXX =		/users/vw/gnu/hp9700.68k/bin/cc68k
CXX =		/usr/local/tornado/host/parisc-hpux9/bin/g++68k
CFLAGS  =       -g -Dunix $(INCLDIRS) $(INCLDIRSXX) \
		-D__STDC__ -c -Dvxworks -DCPU=MC68040 \
		-ansi -m68040  $(EXTRACFLAGS)
CXXFLAGS =	$(CFLAGS) $(INCLDIRSXX) -D__STDC__ 
endif

ifdef vwx86
CXX =		c:\TORNADO\host\x86-win32\bin\cc386
CFLAGS  =       -g -Dunix $(INCLDIRS) $(INCLDIRSXX) \
		-D__STDC__ -c -Dvxworks -DCPU=I80386 \
		-ansi -mno-486 -fno-builtin -nostdinc \
		-fno-defer-pop $(EXTRACFLAGS)
CXXFLAGS =	$(CFLAGS) $(INCLDIRSXX) -D__STDC__ 
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)"


#---------------------------------------------------------------------
# All files needed for the library
#
#	File list for RCS control
#               all include files
API_INCL   =   	API.h \
		ApiP.h \
		DevSec.h
CLASS_INCL =	DevServerP.h \
		DevServer.h \
		DevSignal.h
CLASSP_INCL =   Device.H \
		OICDevice.H

#               source files
API_SRC   = 	gen_api.c \
	 	dev_api.c \
	 	util_api.c \
		sec_api.c \
		asyn_api.c \
		event_api.c
CLASS_SRC =	gettrans.c \
		startup.c \
		svc_api.c \
		oic.c \
		ds_prog_vers3.c \
		DevServer.c \
		DevServerMain.c \
		DevServerSig.c
CLASSP_SRC =	Device.C \
		OICDevice.C

#
#	source list to make library
#		source files
ifdef vwx86
SRC =           gen_api.cpp \
                dev_api.cpp \
                util_api.cpp \
                sec_api.cpp \
                asyn_api.cpp \
                event_api.cpp \
                dev_errors.cpp \
                dev_states.cpp \
                gettrans.cpp \
		startup.cpp \
                svc_api.cpp \
                oic.cpp \
                ds_prog_vers3.cpp \
                DevServer.cpp \
                DevServerMain.cpp \
                startup.cpp \
                DevServerSig.cpp \
                Device.cpp \
                OICDevice.cpp

#               object files

OBJS =		gen_api.cxx.o \
  		dev_api.cxx.o \
	 	util_api.cxx.o \
		sec_api.cxx.o \
 		asyn_api.cxx.o \
 		event_api.cxx.o \
		dev_errors.cxx.o \
		dev_states.cxx.o \
		oic.cxx.o \
  		gettrans.cxx.o \
  		startup.cxx.o \
		svc_api.cxx.o \
		ds_prog_vers3.cxx.o \
  		DevServer.cxx.o \
  		DevServerMain.cxx.o \
  		DevServerSig.cxx.o \
		Device.cxx.o \
		OICDevice.cxx.o


ifdef vwx86
# 
# cancel implicit rule to make .o from .c
#
%.o : %.c
#
# define a rule to make .cxx.o from .cpp 
#
%.cxx.o : %.cpp ; $(CXX) $(CXXFLAGS) $(NAME) $< 
endif # vwx86

else
SRC =		gen_api.c \
	 	dev_api.c \
	 	util_api.c \
		sec_api.c \
		asyn_api.c \
		event_api.c \
		dev_errors.c \
		dev_states.c \
		$(DEV_CLASS)/src/oic.c \
		$(DEV_CLASS)/src/gettrans.c \
		$(DEV_CLASS)/src/startup.c \
		$(DEV_CLASS)/src/svc_api.c \
		$(DEV_CLASS)/src/ds_prog_vers3.c \
		$(DEV_CLASS)/src/DevServer.c \
		$(DEV_CLASS)/src/DevServerMain.c \
		$(DEV_CLASS)/src/DevServerSig.c \
		$(DEV_CLASSP)/src/Device.C \
		$(DEV_CLASSP)/oic/src/OICDevice.C

#               object files

OBJS =		gen_api.cxx.o \
  		dev_api.cxx.o \
	 	util_api.cxx.o \
		sec_api.cxx.o \
		asyn_api.cxx.o \
		event_api.cxx.o \
		dev_errors.cxx.o \
		dev_states.cxx.o \
		$(DEV_CLASS)/src/oic.cxx.o \
  		$(DEV_CLASS)/src/gettrans.cxx.o \
  		$(DEV_CLASS)/src/startup.cxx.o \
		$(DEV_CLASS)/src/svc_api.cxx.o \
		$(DEV_CLASS)/src/ds_prog_vers3.cxx.o \
  		$(DEV_CLASS)/src/DevServer.cxx.o \
  		$(DEV_CLASS)/src/DevServerMain.cxx.o \
  		$(DEV_CLASS)/src/DevServerSig.cxx.o \
		Device.cxx.o \
		OICDevice.cxx.o

OBJS_SL =	gen_api.cxx.sl.o \
  		dev_api.cxx.o \
	 	util_api.cxx.sl.o \
		sec_api.cxx.sl.o \
 		asyn_api.cxx.sl.o \
 		event_api.cxx.sl.o \
		dev_errors.cxx.sl.o \
		dev_states.cxx.sl.o \
		oic.cxx.sl.o \
  		gettrans.cxx.sl.o \
  		startup.cxx.sl.o \
		svc_api.cxx.sl.o \
		ds_prog_vers3.cxx.sl.o \
  		DevServer.cxx.sl.o \
  		DevServerMain.cxx.sl.o \
  		DevServerSig.cxx.sl.o \
		Device.cxx.sl.o \
		OICDevice.cxx.sl.o

#
# special rule for Device.o because of problems with Ultra C++ 
# compiler not being able to output the file in the source directory
#
Device.cxx.o :	$(DEV_CLASSP)/src/Device.C
		$(CXX) $(CFLAGS) -o Device.cxx.o $(DEV_CLASSP)/src/Device.C

OICDevice.cxx.o :	$(DEV_CLASSP)/oic/src/OICDevice.C
		$(CXX) $(CFLAGS) -o OICDevice.cxx.o $(DEV_CLASSP)/oic/src/OICDevice.C
endif # vwx86


ICODE_OBJS = 	gen_api.ic \
  		dev_api.ic \
	 	util_api.ic \
		sec_api.ic \
		asyn_api.ic \
		event_api.ic \
		dev_errors.ic \
		dev_states.ic \
		$(DEV_CLASS)/src/oic.ic \
		$(DEV_CLASS)/src/gettrans.ic \
		$(DEV_CLASS)/src/startup.ic \
		$(DEV_CLASS)/src/svc_api.ic \
		$(DEV_CLASS)/src/ds_prog_vers3.ic \
		$(DEV_CLASS)/src/DevServer.ic \
		$(DEV_CLASS)/src/DevServerMain.ic \
		$(DEV_CLASS)/src/DevServerSig.ic \
		$(DEV_CLASSP)/src/Device.ic \
		$(DEV_CLASSP)/oic/src/OICDevice.ic


#--------------------------------------------------------------------
# What has to be made
#
ifdef __hpux
ifdef NATIF
LIBNAME =       libdsapi++.a
LIBNAME_SL =    libdsapi++.sl
else
LIBNAME = 	libdsapig++.a
LIBNAME_SL =    libdsapig++.sl
endif
endif

ifdef linux
LIBNAME =       libdsapig++.a
LIBNAME_SL =    libdsapig++.so
endif

ifdef _solaris
ifdef NATIF
LIBNAME = 	libdsapi++.a
LIBNAME_SL =    libdsapi++.so
else
LIBNAME =       libdsapig++.a
LIBNAME_SL =    libdsapig++.so
endif
endif

ifdef vxworks
LIBNAME =       libdsapig++.o
endif
ifdef _UCC
LIBNAME =       libdsapi++.a
ICODE_LIBNAME = libdsapi++.il
endif


#               Names of the include files in the 
#		installation directories
#
INCL_INST  = 	../include/API.h \
		../include/DevSec.h \
		$(DEV_CLASS)/include/DevServer.h \
		$(DEV_CLASS)/include/DevSignal.h \
		$(DEV_CMDS)/include/DevErrors.h \
		$(DEV_CMDS)/include/DevCmds.h \
		$(DEV_CMDS)/include/DevStates.h \
		$(DEV_CMDS)/include/DserverTeams.h \
		$(DEV_CMDS)/include/CntrlDsNumbers.h
INCLP_INST = 	../include/ApiP.h \
		$(DEV_CLASS)/include/DevServerP.h

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

all:	$(OBJS) $(LIBNAME)

all_sl:	$(OBJS_SL) $(LIBNAME_SL)

#
# DO NOT recompile all C files
#
#$(OBJS):        
#		$(CXX) $(CFLAGS) $(SRC)

ifdef _UCC
.SUFFIXES: .cxx.o .C
.C.cxx.o:
		$(CXX) $(CFLAGS) $(NAME) -efe $<
.SUFFIXES: .ic .c
.c.ic:
		$(CXX) $(ICODE_CFLAGS) $(NAME) -efe $<
.SUFFIXES: .ic .C
.C.ic:
		$(CXX) $(ICODE_CFLAGS) $(NAME) -efe $<
#
# DO NOT recompile all icode files
#
#$(ICODE_OBJS):	
#	        $(CXX) $(ICODE_CFLAGS) $(NAME) -efe $<


$(LIBNAME):     $(OBJS) $(ICODE_OBJS)
		libgen $(OBJS) -co=$(LIBNAME)

		$(CXX) $(ICODE_CFLAGS) $(ICODE_OBJS) -Wi,-m -f $(ICODE_LIBNAME)
endif # _UCC

.SUFFIXES: .cxx.o .c
.c.cxx.o:
		$(CXX) $(CXXFLAGS_SL) $(NAME) $< -o $*.cxx.o

.SUFFIXES: .cxx.sl.o .c
.c.cxx.sl.o:
		$(CXX) $(CXXFLAGS_SL) $(NAME) $< -o $*.cxx.sl.o

.SUFFIXES: .cxx.sl.o .cpp
.cpp.cxx.sl.o:
		$(CXX) $(CXXFLAGS_SL) $(NAME) $< -o $*.cxx.sl.o

.SUFFIXES: .cxx.sl.o .C
.C.cxx.sl.o:
		$(CXX) $(CXXFLAGS_SL) $(NAME) $< -o $*.cxx.sl.o

ifdef unix
$(LIBNAME):	$(OBJS)
ifdef vw68k
		ar68k -r $(LIBNAME) $(OBJS)
		ranlib68k $(LIBNAME)
else
ifdef vwx86
#		ar386 -r $(LIBNAME) $(OBJS)
#		ranlib386 $(LIBNAME)
		ld386 -r -o $(LIBNAME) $(OBJS)
else
ifdef 68k
		m68k-linux-ar -r  $(LIBNAME) $(OBJS) 
		m68k-linux-ranlib  $(LIBNAME) 
else
		ar rv $(LIBNAME) $(OBJS)
endif # 68k
endif # vwx86
endif # vw68k

$(LIBNATIF):	$(OBJS)
		ar rv $(LIBNATIF) $(OBJS)
endif # unix

ifdef unix
ifdef __hpux10
$(LIBNAME_SL):	$(OBJS_SL)
		ld -b -o $(LIBNAME_SL) $(OBJS_SL)
endif # __hpux10
ifdef linux
$(LIBNAME_SL):	$(OBJS_SL)
		$(CXX) -shared -Wl,-soname,$(LIBNAME_SL) -o $(LIBNAME_SL) $(OBJS_SL)
endif # linux
ifdef _solaris
$(LIBNAME_SL):	$(OBJS_SL)
		ld -G -o $(LIBNAME_SL) $(OBJS_SL)
endif # _solaris
endif # unix

install_incl:	
		cp $(DEV_CLASSP)/include/Device.H $(DSHOME)/include++
		chmod 664 $(DSHOME)/include++/Device.H
		cp $(DEV_CLASSP)/oic/include/OICDevice.H $(DSHOME)/include++
		chmod 664 $(DSHOME)/include++/OICDevice.H

install :       install_incl
		cp $(LIBNAME) $(INSTALL_HOME)
ifdef _UCC
		cp $(ICODE_LIBNAME) $(INSTALL_HOME)
endif


install_sl :
		cp $(LIBNAME_SL) $(INSTALL_HOME)

clean :
		rm -rf $(OBJS)
		rm -rf $(ICODE_OBJS)
		rm -rf *.o
		rm -rf $(DEV_CLASS)/src/?*.o
		rm -rf *.i
		rm -rf $(DEV_CLASS)/src/?*.i
		rm -rf $(DEV_CLASSP)/src/?*.o
		rm -rf $(DEV_CLASSP)/src/?*.i


clobber:	clean
		rm -rf	$(LIBNAME)
ifdef _UCC
		rm -rf	$(ICODE_LIBNAME)
endif # _UCC

lock:
		$(RCSLOCK) $(API_SRC)
		cd ../include; $(RCSLOCK) $(API_INCL)
		cd $(DEV_CLASS)/src; $(RCSLOCK) $(CLASS_SRC)
		cd $(DEV_CLASS)/include; $(RCSLOCK) $(CLASS_INCL)
		cd $(DEV_CLASSP)/src; $(RCSLOCK) $(CLASSP_SRC)
		cd $(DEV_CLASSP)/include; $(RCSLOCK) $(CLASSP_INCL)
		cd $(LOHOME)

co:
		$(RCSCO) $(API_SRC)
		cd ../include; $(RCSCO) $(API_INCL); cd ../src
		cd $(DEV_CLASS)/src; $(RCSCO) $(CLASS_SRC)
		cd $(DEV_CLASS)/include; $(RCSCO) $(CLASS_INCL)
		cd $(DEV_CLASSP)/src; $(RCSCO) $(CLASSP_SRC)
		cd $(DEV_CLASSP)/include; $(RCSCO) $(CLASSP_INCL)
		cd $(LOHOME)

ci:
		$(RCSCI) $(API_SRC)
		cd ../include; $(RCSCI) $(API_INCL); cd ../src
		cd $(DEV_CLASS)/src; $(RCSCI) $(CLASS_SRC)
		cd $(DEV_CLASS)/include; $(RCSCI) $(CLASS_INCL)
		cd $(DEV_CLASSP)/src; $(RCSCI) $(CLASSP_SRC)
		cd $(DEV_CLASSP)/include; $(RCSCI) $(CLASSP_INCL)
		cd $(LOHOME)
#
#
