#*************************************************************************
# 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 = tclOS
SHARED_LIBRARIES = YES

ifeq ($(STATIC_BUILD),YES)
LDLIBS_READLINE =
POSIX_LDLIBS =
OP_SYS_LDLIBS =
STATIC_LDLIBS_YES =
GNU_LDLIBS_YES =
endif

LIBSRCS = tclOS.c tclOSCmd.c


ifdef WIN32
USR_LIBS += mdblib tclstub86
else
USR_LIBS = 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

ACLHEADER = $(notdir $(wildcard /usr/include/sys/acl.h))
ifeq ($(ACLHEADER) , acl.h) 
ifeq ($(OS_CLASS),solaris)
USR_CFLAGS += -DACL_FOUND
OP_SYS_LDLIBS += -lsec
endif
ifeq ($(OS_CLASS),Linux)
USR_CFLAGS += -DACL_FOUND
OP_SYS_LDLIBS += -lacl
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 = tclOS.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)

include $(TOP)/configure/RULES
