# **********************************************************************
#
# Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
#
# This copy of Ice is licensed to you under the terms described in the
# ICE_LICENSE file included in this distribution.
#
# **********************************************************************

#
# This file is included by Make.rules when uname is SunOS.
#

#
# The default compiler on Solaris is CC. 
# If you want to build with another compiler, you can edit this line, or
# comment it out and define CXX=<desired-compiler> in your environment.
# If CXX is not defined anywhere, the default (from gmake) is g++. 
#
CXX   = CC

# This variable is used to determine the machine type.
# For SUN UltraSPARC machines: sun4u
# For x86/x64 machines:        i86pc
#
MACHINE_TYPE                := $(shell uname -m)


ifeq ($(CXX),CC)
    #
    # Sun CC
    #

    #
    # Which version of CC are we using?
    #
    CCVERSION		    = $(filter 5.%, $(shell CC -V 2>&1))

    ifeq ($(MACHINE_TYPE),sun4u)
        ifeq ($(LP64),yes)
            CXXARCHFLAGS    = -xarch=v9
        else
            CXXARCHFLAGS    = -xarch=v8plus
        endif
    endif

    ifeq ($(MACHINE_TYPE),i86pc)
        ifeq ($(LP64),yes)
            CXXARCHFLAGS    = -xarch=amd64
        endif
    endif

    ifeq ($(CCVERSION),5.3)
        FLEX_NOLINE	    = yes
        BISON_NOLINE	    = yes
        TEMPLATE_REPOSITORY = SunWS_cache
    else
        ifeq ($(CCVERSION),5.4)
            CXXWARNFLAGS	= +w
            TEMPLATE_REPOSITORY	= SunWS_cache
        else
            #
            # Assumes >= 5.5
            #
            # -erroff=hidef is a (bad) work-around for
            # for Sun CC 5.5 bug #4852754
            #
            # wvarhidenmem,wvarhidemem: various name hiding
            #
            CXXWARNFLAGS    = +w -erroff=hidef,wvarhidenmem,wvarhidemem
            CXXSCOPEFLAGS   = -xldscope=hidden
        endif
    endif

    #
    # -features=tmplife is needed to destroy temporary objects immediately
    # (as specified by ISO C++) instead of at the end of the current block.
    # This is very useful to avoid deadlocks when using Freeze Map 
    # iterators.
    #

    CXXFLAGS		    = -mt +p -features=tmplife $(CXXSCOPEFLAGS) $(CXXWARNFLAGS) $(CXXARCHFLAGS)

    ifeq ($(STATICLIBS),)
	CXXFLAGS	    += -KPIC
    endif

    ifeq ($(OPTIMIZE),yes)
        CXXFLAGS	    += -O -DNDEBUG
    else
        CXXFLAGS	    += -g
    endif

    #
    # C++ run-time libraries, necessary for linking some shared libraries.
    #
    CXXLIBS		    = -lCstd -lCrun

    mkshlib		    = $(CXX) -G $(LDFLAGS) -o $(1) -h $(2) $(3) $(4)

    mklib		    = $(CXX) -xar -o $(1) $(2)

    ifeq ($(ADD_LIBDIR_TO_RPATH),yes)
         LDPLATFORMFLAGS    = -R $(install_libdir) -z text
    else
         LDPLATFORMFLAGS    = -z text
    endif
    
endif

ifeq ($(CXX),gcc)
    CXX			    = g++
endif

ifeq ($(CXX),g++)

    ifeq ($(LP64),yes)
        CXXARCHFLAGS	    = -m64
    endif

    CXXFLAGS		    = $(CXXARCHFLAGS) -ftemplate-depth-128 -Wall -D_REENTRANT

    ifeq ($(STATICLIBS),)
	CXXFLAGS	    += -fPIC
    endif

    ifeq ($(OPTIMIZE),yes)
        CXXFLAGS	    += -O2 -DNDEBUG
    else
        CXXFLAGS	    += -g
    endif
    
    mkshlib		    = $(CXX) -shared $(LDFLAGS) -o $(1) -h $(2) $(3) $(4)

    mklib		    = ar cr $(1) $(2)
endif

rpathlink                   = -L$(1)

BASELIBS		    = -lIceUtil -lpthread
LIBS			    = $(BZIP2_RPATH_LINK) -lIce $(BASELIBS)

ICEUTIL_OS_LIBS		    = -lpthread -lrt
ICE_OS_LIBS		    = -ldl -lsocket

ifeq ($(MACHINE_TYPE),sun4u)
   lp64suffix		    = /sparcv9
endif
ifeq ($(MACHINE_TYPE),i86pc)
    lp64suffix		    = /amd64
endif

ifeq ($(LP64),yes)
    export LD_LIBRARY_PATH_64	:= $(libdir):$(LD_LIBRARY_PATH_64)
else
    export LD_LIBRARY_PATH	:= $(libdir):$(LD_LIBRARY_PATH)
endif
