#*************************************************************************
# Copyright (c) 2002 The University of Chicago, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# This file is distributed subject to a Software License Agreement found
# in the file LICENSE that is included with this distribution. 
#*************************************************************************

TOP=../../../..
include $(TOP)/configure/CONFIG

LIBRARY = tclRPN
SHARED_LIBRARIES = YES

LIBSRCS = tclRPN.c tclRPNCmd.c


SYS_GSLLIB = gsl gslcblas
ifeq ($(OS_CLASS),Linux)
  GSL = $(words $(wildcard $(EPICS_EXTENSIONS)/src/SDDS/gsl))
  ifeq ($(GSL), 1)
    GSLLIB = gsl gslcblas
    SYS_GSLLIB = 
  endif
endif

ifdef WIN32
USR_LIBS += rpnlib $(GSLLIB) mdbmth mdblib gsl tclstub86
else
USR_LIBS = rpnlib $(GSLLIB) mdbmth mdblib

ifeq ($(EPICS_HOST_ARCH),linux-x86_64)
OAGTCL = $(notdir $(wildcard /usr/local/oag/ActiveTcl/linux-x86_64.ActiveTcl8.6.13/include/tcl.h))
ifeq ($(OAGTCL) , tcl.h) 
TCL_INC = /usr/local/oag/ActiveTcl/linux-x86_64.ActiveTcl8.6.13/include
TCL_LIB = /usr/local/oag/ActiveTcl/linux-x86_64.ActiveTcl8.6.13/lib
endif

OAGTCL = $(notdir $(wildcard /lustre/3rdPartySoftware/ActiveTcl/linux-x86_64.ActiveTcl8.6.13.custom/include/tcl.h))
ifeq ($(OAGTCL) , tcl.h) 
TCL_INC = /lustre/3rdPartySoftware/ActiveTcl/linux-x86_64.ActiveTcl8.6.13.custom/include
TCL_LIB = /lustre/3rdPartySoftware/ActiveTcl/linux-x86_64.ActiveTcl8.6.13.custom/lib
endif
endif

ifeq ($(EPICS_HOST_ARCH),darwin-x86)
OAGTCL = $(notdir $(wildcard /Library/Frameworks/Tcl.framework/Headers/tcl.h))
ifeq ($(OAGTCL) , tcl.h) 
TCL_INC = /Library/Frameworks/Tcl.framework/Headers
TCL_LIB = /Library/Frameworks/Tcl.framework
TK_INC = /Library/Frameworks/Tk.framework/Headers
TK_LIB = /Library/Frameworks/Tk.framework
endif
endif

ifeq ($(EPICS_HOST_ARCH),darwin-aarch64)
OAGTCL = $(notdir $(wildcard /opt/local/include/tcl.h))
ifeq ($(OAGTCL) , tcl.h) 
TCL_INC = /opt/local/include
TCL_LIB = /opt/local/lib
TK_INC = /opt/local/include
TK_LIB = /opt/local/lib
endif
endif

TCLVERSION = $(notdir $(firstword $(wildcard $(TCL_LIB)/libtclstub8.6.a $(TCL_LIB)/libtclstub8.5.a $(TCL_LIB)/libtclstub8.4.a $(TCL_LIB)/libtclstub8.3.a $(TCL_LIB)/libtclstub.a)))
ifeq ($(TCLVERSION),libtclstub8.6.a)
USR_LIBS += tclstub8.6
endif
ifeq ($(TCLVERSION),libtclstub8.5.a)
USR_LIBS += tclstub8.5
endif
ifeq ($(TCLVERSION),libtclstub8.4.a)
USR_LIBS += tclstub8.4
endif
ifeq ($(TCLVERSION),libtclstub8.3.a)
USR_LIBS += tclstub8.3
endif
ifeq ($(TCLVERSION),libtclstub.a)
USR_LIBS += tclstub
endif

endif

USR_CFLAGS += -DUSE_TCL_STUBS -I$(EPICS_EXTENSIONS)/src/SDDS/lzma
ifneq ($(TCL_INC) , /usr/include) 
USR_CFLAGS += -I$(TCL_INC)
endif
USR_CFLAGS += -I$(EPICS_EXTENSIONS_INCLUDE)

USR_CFLAGS_solaris = -D__EXTENSIONS__
INC = tclRPN.h 

tclstub8.6_DIR = $(TCL_LIB)
tclstub86_DIR = $(TCL_LIB)
tclstub8.5_DIR = $(TCL_LIB)
tclstub85_DIR = $(TCL_LIB)
tclstub8.4_DIR = $(TCL_LIB)
tclstub84_DIR = $(TCL_LIB)
tclstub8.3_DIR = $(TCL_LIB)
tclstub_DIR = $(TCL_LIB)

tclRPN_SYS_LIBS += $(SYS_GSLLIB)

include $(TOP)/configure/RULES
