%define ACEVER  6.0.0

Summary:      The ADAPTIVE Communication Environment (ACE)
Name:         ace
Version:      %{ACEVER}

%define exagrid_release exagrid1
Release:      1%{?OPTTAG}%{?dist}.0.%{?exagrid_release}

Group:        Development/Libraries/C and C++
URL:          http://www.cs.wustl.edu/~schmidt/ACE.html
License:      DOC License
#Source0:      http://download.dre.vanderbilt.edu/previous_versions/ACE+TAO+CIAO-src-%{ACEVER}.tar.gz
#source is really from: http://www.riverace.com/ACE-value-kits/ACE60aSRC.tar.gz
Source:       %{name}-%{version}.tar.gz
BuildRoot:    %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

BuildRequires:  redhat-rpm-config
BuildRequires:  openssl-devel
BuildRequires:  gcc-c++
BuildRequires:  libstdc++-devel
BuildRequires:  lsb
BuildRequires:  perl

# ---------------- ace ----------------

%description

The ADAPTIVE Communication Environment (ACE) is a freely available,
open-source object-oriented (OO) framework that implements many core
patterns for concurrent communication software. ACE provides a rich
set of reusable C++ wrapper facades and framework components that
perform common communication software tasks across a range of OS
platforms. The communication software tasks provided by ACE include
event demultiplexing and event handler dispatching, signal handling,
service initialization, interprocess communication, shared memory
management, message routing, dynamic (re)configuration of distributed
services, concurrent execution and synchronization.

# ---------------- ace-devel ----------------

%package -n     ace-devel
Summary:        Header files and development components for ACE
Version:        %{ACEVER}
Group:          Development/Libraries/C and C++
Requires:       ace = %{ACEVER}
Requires:       openssl-devel
Provides:       perl(PerlACE::Run_Test) perl(Process) perl(VmsProcess) perl(Win32::Process)

%description -n ace-devel

This package contains the components needed for developing programs
using ACE.

# ================================================================
# prep
# ================================================================

%prep
%setup -q

# ================================================================
# build
# ================================================================

%build
export ACE_ROOT=$(pwd)
export LD_LIBRARY_PATH=$ACE_ROOT/lib:$LD_LIBRARY_PATH

# Add Exagrid-specific lines to config.h
cat > $ACE_ROOT/ace/config.h << EOF
#define ACE_USE_DEV_POLL_REACTOR_FOR_REACTOR_IMPL  // ExaGrid
#define ACE_HAS_REACTOR_NOTIFICATION_QUEUE  // Ken Sedgwick 2006-04-19
#define ACE_GCC_HAS_TEMPLATE_INSTANTIATION_VISIBILITY_ATTRS 1  // Ken Sedgwick 2007-05-05
#if !defined(ACE_HAS_EVENT_POLL)
#define ACE_HAS_EVENT_POLL 1 // Ken Sedgwick 2009-09-18
#endif
EOF

# If ipv6 support is indicated insert some lines into the config.h file
#
%if %{?_with_ipv6:1}%{!?_with_ipv6:0}
cat >> $ACE_ROOT/ace/config.h << EOF
#define ACE_HAS_IPV6
#define ACE_USES_IPV4_IPV6_MIGRATION
EOF
%endif

# Include platform include
cat >> $ACE_ROOT/ace/config.h << EOF
#include "ace/config-linux.h"
EOF

# platform_macros.GNU
%if 0%{?suse_version}
cat > $ACE_ROOT/include/makeinclude/platform_macros.GNU <<EOF
CCFLAGS += %optflags
CFLAGS += %optflags
EOF
%endif

cat >> $ACE_ROOT/include/makeinclude/platform_macros.GNU <<EOF
ssl = 1
EOF

# 64 bit machines need additional macro.
%ifarch x86_64 ia64 ppc64 s390x
cat >> $ACE_ROOT/include/makeinclude/platform_macros.GNU <<EOF
buildbits = 64
EOF
%endif

cat >> $ACE_ROOT/include/makeinclude/platform_macros.GNU <<EOF
optimize = 1
EOF

cat >> $ACE_ROOT/include/makeinclude/platform_macros.GNU <<EOF
include \$(ACE_ROOT)/include/makeinclude/platform_linux.GNU
EOF

make

# ================================================================
# install
# ================================================================

%define ACEVERSO %{ACEVER}

%install

export ACE_ROOT=$(pwd)
export LD_LIBRARY_PATH=$ACE_ROOT/lib:$LD_LIBRARY_PATH

# install shared libraries
install -d $RPM_BUILD_ROOT%{_libdir}

# ACE libraries
INSTLIBS=`ls ${ACE_ROOT}/lib/libACE*.so.%{ACEVERSO}`
install $INSTLIBS $RPM_BUILD_ROOT%{_libdir}

# Remove ACE XMl libraries we don't use
rm $RPM_BUILD_ROOT%{_libdir}/libACEXML*

# Create un-versioned symbolic links for libraries
(cd $RPM_BUILD_ROOT%{_libdir} && \
 ls *.so.* | awk 'BEGIN{FS="."}{print "ln -sf " $0 " " $1 "." $2;}' | sh)

# Copy header files for devel package
mkdir -p -m 755 $RPM_BUILD_ROOT/usr/include/ace
install -m 644 -t $RPM_BUILD_ROOT/usr/include/ace ace/*.h
cp -r ace/os_include $RPM_BUILD_ROOT/usr/include/ace/

# Copy "in-line header" files for devel package
install -m 644 -t $RPM_BUILD_ROOT/usr/include/ace ace/*.inl

# Copy cpp files needed for templates
install -m 644 -t $RPM_BUILD_ROOT/usr/include/ace ace/*.cpp

# ================================================================
# clean
# ================================================================

%clean
rm -rf %{buildroot}

# ================================================================
# post install
# ================================================================

# ---------------- ace ----------------

%post -n ace
/sbin/ldconfig

# ---------------- ace-devel ----------------

%post -n ace-devel
/sbin/ldconfig

# ================================================================
# post uninstall
# ================================================================

# ---------------- ace ----------------

%postun -n ace
/sbin/ldconfig

# ================================================================
# files
# ================================================================

# ---------------- ace ----------------

%files -n ace
%defattr(-,root,root,-)
%{_libdir}/libACE.so.%{ACEVERSO}
%{_libdir}/libACE_ETCL_Parser.so.%{ACEVERSO}
%{_libdir}/libACE_ETCL.so.%{ACEVERSO}
%{_libdir}/libACE_HTBP.so.%{ACEVERSO}
%{_libdir}/libACE_Monitor_Control.so.%{ACEVERSO}
%{_libdir}/libACE_RMCast.so.%{ACEVERSO}
%{_libdir}/libACE_TMCast.so.%{ACEVERSO}
%{_libdir}/libACE_SSL.so.%{ACEVERSO}
%{_libdir}/libACE_INet.so.%{ACEVERSO}
%{_libdir}/libACE_INet_SSL.so.%{ACEVERSO}

%doc ACE-INSTALL.html
%doc AUTHORS
%doc COPYING
%doc PROBLEM-REPORT-FORM
%doc README
%doc THANKS
%doc VERSION

# ---------------- ace-devel ----------------

%files -n ace-devel
%defattr(-,root,root,-)
%{_libdir}/libACE.so
%{_libdir}/libACE_ETCL_Parser.so
%{_libdir}/libACE_ETCL.so
%{_libdir}/libACE_HTBP.so
%{_libdir}/libACE_Monitor_Control.so
%{_libdir}/libACE_RMCast.so
%{_libdir}/libACE_TMCast.so
%{_libdir}/libACE_SSL.so
%{_libdir}/libACE_INet.so
%{_libdir}/libACE_INet_SSL.so
/usr/include/ace

%doc AUTHORS
%doc COPYING
%doc PROBLEM-REPORT-FORM
%doc README
%doc VERSION
