#*************************************************************************
# 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.
# EPICS BASE Versions 3.13.7
# and higher are distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution. 
#*************************************************************************

#
#  Contains definitions common to all Unix archs
#
#  This file is maintained by the EPICS community.
#  Sites may override these definitions in CONFIG_SITE.Host.UnixCommon
 

#-------------------------------------------------------
#	adjust names of libraries to build
#
# <lib> ->  lib<lib>.a
LIBNAME = $(LIBRARY:%=lib%.a)

#-------------------------------------------------------
# Shared library definitions

# CONFIG.Host.<arch> files may override
SHRLIB_SUFFIX = .so

SHRLIBNAME = lib$(LIBRARY)$(SHRLIB_SUFFIX)$(SHRLIB_VERSION:%=.%)

SYS_DLL_LIBS += $(SYS_DLL_LIBS_$(OS_CLASS))
DLL_LIBS = $(patsubst $(LIBRARY),, $(PROD_LIBS) $(USR_LIBS)) $(SYS_DLL_LIBS)

INSTALL_SHRLIB = $(INSTALL_LIB)

LINK.shrlib= $(SHRLIB_LINKER) -o $@ $(CFLAGS) $(CPPFLAGS) $(SHRLIB_LDFLAGS) $(DLL_LDFLAGS) $(LDFLAGS)

#-------------------------------------------------------
# Unix command definitions

CPP = cpp
RANLIB = ranlib

# GNU compilers
GCC = gcc
G++ = g++

#-------------------------------------------------------
# Unix suffix definitions
EXE =
OBJ = .o

#--------------------------------------------------
# Dependancy definitions
COND_PROD_DEPLIBS = $(foreach prod,$(PROD), $(foreach lib, $($(basename $(prod))_LIBS),$(firstword $(wildcard $($(lib)_DIR)/lib$(lib).* $(EPICS_BASE_LIB)/lib$(lib).*))))
PRODNAME_DEPLIBS = $(foreach lib,$(PRODNAME_LIBS),$(firstword $(wildcard $($(lib)_DIR)/lib$(lib).* $(EPICS_BASE_LIB)/lib$(lib).*)))
PROD_DEPLIBS = $(foreach lib,$(PROD_LIBS),$(firstword $(wildcard $($(lib)_DIR)/lib$(lib).* $(EPICS_BASE_LIB)/lib$(lib).*)))
USR_DEPLIBS = $(foreach lib,$(USR_LIBS),$(firstword $(wildcard $($(lib)_DIR)/lib$(lib).* $(EPICS_BASE_LIB)/lib$(lib).*)))
DLL_DEPLIBS = $(foreach lib,$(DLL_LIBS),$(firstword $(wildcard $($(lib)_DIR)/lib$(lib).* $(EPICS_BASE_LIB)/lib$(lib).*)))
#--------------------------------------------------
# Determine ld flags
USR_DIRS = $(dir $(PRODNAME_DEPLIBS)) $(dir $(PROD_DEPLIBS))\
 $(dir $(USR_DEPLIBS))
USR_LDFLAGS += $(sort $(USR_DIRS:%=-L%))
DLL_DIRS = $(dir $(DLL_DEPLIBS))
DLL_LDFLAGS = $(sort $(DLL_DIRS:%=-L%))

# Determine ld libs
USR_LDLIBS = $(PRODNAME_LIBS:%=-l%) $(PROD_LIBS:%=-l%) $(USR_LIBS:%=-l%)\
 $(SYS_PROD_LIBS:%=-l%)
DLL_LDLIBS = $(DLL_LIBS:%=-l%)

#--------------------------------------------------
# Operating system definitions
OP_SYS_INCLUDES =
OP_SYS_CFLAGS = -DUNIX

OP_SYS_LDFLAGS =
OP_SYS_LDLIBS = -lm

#--------------------------------------------------
# Link definitions
LINK.c = $(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
LINK.cc = $(CXX) -o $@ $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)

#--------------------------------------------------
# Allow site overrides
-include $(EPICS_BASE)/config/CONFIG_SITE.Host.UnixCommon
