# CONFIG.Common.UnixCommon
#
# $Revision-Id$
#
#  Contains definitions common to all Unix target archs
#
#  This file is maintained by the build community.
#  Sites may override definitions in CONFIG_SITE.Common.UnixCommon
#  or CONFIG_SITE.<host>.UnixCommon
#-------------------------------------------------------

# Unix valid build types
VALID_BUILDS = Host Ioc

#-------------------------------------------------------
# Unix prefix and suffix definitions
EXE =
OBJ = .o
#Library prefix and suffixes
LIB_PREFIX = lib
LIB_SUFFIX = .a
SHRLIB_SUFFIX = .so$(addprefix .,$(SHRLIB_VERSION))
LOADABLE_SHRLIB_SUFFIX = .so$(addprefix .,$(LOADABLE_SHRLIB_VERSION))
LOADABLE_SHRLIB_PREFIX = lib

#-------------------------------------------------------
#	names of libraries to build 
# <lib> ->  lib<lib>.a
LIBNAME = $(BUILD_LIBRARY:%=$(LIB_PREFIX)%$(LIB_SUFFIX))
# <lib> ->  lib<lib>.so.<version>
SHRLIBNAME_YES = $(BUILD_LIBRARY:%=$(SHRLIB_PREFIX)%$(SHRLIB_SUFFIX))
LOADABLE_SHRLIBNAME = $(LOADABLE_BUILD_LIBRARY:%=$(LOADABLE_SHRLIB_PREFIX)%$(LOADABLE_SHRLIB_SUFFIX))

#-------------------------------------------------------
# shrlib: SHRLIB_DEPLIBS, SHRLIB_LDLIBS and SHRLIBDIR_LDFLAGS definitions

# SHRLIB_LIBS deprecated
LIB_LIBS += $(SHRLIB_LIBS)

SHRLIB_DEPLIBS=$(foreach lib, $(LIB_LIBS) $(USR_LIBS), \
	$(firstword $(wildcard $(addsuffix /$(LIB_PREFIX)$(lib).*, \
    $($(lib)_DIR) $(SHRLIB_SEARCH_DIRS))) \
	$(addsuffix /$(LIB_PREFIX)$(lib)$(LIB_SUFFIX), \
    $(firstword $($(lib)_DIR) $(INSTALL_LIB)))))

SHRLIB_LDLIBS = $(addprefix -l, $($*_LDLIBS) $(LIB_LIBS) $(USR_LIBS))\
 $(STATIC_LDLIBS) \
 $(addprefix -l, $($*_SYS_LIBS) $(LIB_SYS_LIBS) $(USR_SYS_LIBS)) \
 $(LDLIBS)

SHRLIB_DEPLIB_DIRS = $(foreach word,$(sort $(dir $($*_DEPLIBS) $(SHRLIB_DEPLIBS))), \
   $(shell $(PERL) $(TOOLS)/fullPathName.pl $(word)))

SHRLIBDIR_LDFLAGS += $(SHRLIB_DEPLIB_DIRS:%=-L%)

#-------------------------------------------------------
# Prod: PROD_DEPLIBS, PROD_LDLIBS and PRODDIR_LDFLAGS definitions

PROD_DEPLIBS=$(foreach lib,$(PROD_LIBS) $(USR_LIBS), \
	$(firstword $(wildcard $(addsuffix /$(LIB_PREFIX)$(lib).*, \
    $($(lib)_DIR) $(SHRLIB_SEARCH_DIRS))) \
	$(addsuffix /$(LIB_PREFIX)$(lib)$(LIB_SUFFIX), \
    $(firstword $($(lib)_DIR) $(INSTALL_LIB)))))

PROD_LDLIBS = $(addprefix -l, $($*_LDLIBS) $(PROD_LIBS) $(USR_LIBS)) \
 $(STATIC_LDLIBS) \
 $(addprefix -l, $($*_SYS_LIBS) $(PROD_SYS_LIBS) $(USR_SYS_LIBS))

LDLIBS_STATIC_YES = LDLIBS
LDLIBS_SHARED_NO = LDLIBS
PROD_LDLIBS += $($(firstword $(LDLIBS_STATIC_$(STATIC_BUILD)) \
               $(LDLIBS_SHARED_$(SHARED_LIBRARIES))))

PROD_DEPLIB_DIRS = $(foreach word,$(sort $(dir $($*_DEPLIBS) $(PROD_DEPLIBS))), \
  $(shell $(PERL) $(TOOLS)/fullPathName.pl $(word)))

PRODDIR_LDFLAGS += $(PROD_DEPLIB_DIRS:%=-L%)

#--------------------------------------------------
# Link definitions
LINK.cpp = $(CCC) -o $@ $(STATIC_LDFLAGS) $(PRODDIR_LDFLAGS) $(LDFLAGS)
LINK.cpp += $(PROD_LDFLAGS) $(PROD_LD_OBJS) $(PROD_LD_RESS) $(PROD_LDLIBS)
LINK.shrlib = $(CCC) -o $@ $(TARGET_LIB_LDFLAGS) $(SHRLIBDIR_LDFLAGS) $(LDFLAGS)
LINK.shrlib += $(LIB_LDFLAGS) $(LIBRARY_LD_OBJS) $(LIBRARY_LD_RESS) $(SHRLIB_LDLIBS)

#--------------------------------------------------
# Operating system definitions
OP_SYS_CPPFLAGS += -DUNIX 
OP_SYS_LDLIBS += -lm

#--------------------------------------------------
# Allow site overrides
-include $(CONFIG)/os/CONFIG_SITE.Common.UnixCommon
-include $(CONFIG)/os/CONFIG_SITE.$(EPICS_HOST_ARCH).UnixCommon
