--- /opt/local/var/macports/sources/svn.macports.org/trunk/dports/devel/tao/Portfile	2012-05-28 12:43:07.000000000 -0700
+++ Portfile	2012-05-30 10:16:02.000000000 -0700
@@ -1,5 +1,5 @@
 # -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
-# $Id: Portfile 93517 2012-05-25 14:24:34Z pixilla@macports.org $
+# $Id: Portfile 93489 2012-05-24 05:19:35Z ryandesign@macports.org $
 
 # MacPorts specification for the TAO CORBA package.
 # Includes ACE even though the ace port is available
@@ -10,15 +10,10 @@
 
 PortSystem          1.0
 
-# Disable the full universal support since TAO already does most of this
-# and the extra stuff in muniversal (including making two build trees
-# and using libtool to merge libraries) does not work for this case.
-# PortGroup           muniversal 1.0
-
 name                tao
 set name_package    ACE+TAO
 version             6.1.2
-revision            1
+revision            2
 distname            ${name_package}-${version}
 categories          devel
 platforms           darwin
@@ -40,10 +35,7 @@
                     ftp://download.dre.vanderbilt.edu/previous_versions
 
 universal_variant   yes
-
-variant ssl description {Enable SSL} {
-        depends_lib port:openssl
-}
+default_variants    +server
 
 use_bzip2           yes
 
@@ -70,6 +62,7 @@
         set os.name ${value}
     }
 }
+
 set libenv          DYLD_LIBRARY_PATH=${worksrcpath}/lib
 set aceenv          ACE_ROOT=${worksrcpath}
 set taoenv          TAO_ROOT=${worksrcpath}/TAO
@@ -92,38 +85,70 @@
     reinplace "s|@MACOSX@|${os.name}|g" \
         ${worksrcpath}/ace/config.h \
         ${worksrcpath}/include/makeinclude/platform_macros.GNU
-    # disable the assignment for compilers in lion and use our environment instead
+    # Disable the assignment for compilers in lion and use our environment instead
+    ui_info "patching platform_macosx_lion.GNU"
     reinplace "s|^\\(CXX:=.*\\)|# \\1|g" \
         ${worksrcpath}/include/makeinclude/platform_macosx_lion.GNU
     reinplace "s|^\\(CC:=.*\\)|# \\1|g" \
         ${worksrcpath}/include/makeinclude/platform_macosx_lion.GNU
+}
 
-    if {[variant_exists universal] && [variant_isset universal]} {
-        ui_debug "Enabling a universal build"
+depends_lib-append  path:bin/perl:perl5 \
+                    port:tcl \
+                    port:zlib
+
+proc setuniversalflags {fname cxxflags ldflags} {
+    set apat "-arch \[ \]*\[a-z\]\[_a-z0-9\]*"
+    if {[file exists ${fname}]} {
+        reinplace "s|^\\(\[ \]*FLAGS_C_CC\[ \]*+=\[ \]*\\)${apat}\\(\[ \]*${apat}\\)*|\\1${cxxflags}|g" \
+            ${fname}
+        reinplace "s|^\\(\[ \]*LDFLAGS\[ \]*+=\[ \]*\\)${apat}\\(\[ \]*${apat}\\)*|\\1${ldflags}|g" \
+            ${fname}
+    } else {
+        ui_warn "File ${fname} not found for patching"
+    }
+}
+
+variant universal {
+    post-patch {
+        ui_info "patching platform_macros.GNU"
         reinplace "s|buildbits=64|buildbits=universal|g" \
             ${worksrcpath}/include/makeinclude/platform_macros.GNU
-        # do not set universal=1 which tries i386 and PPC but fails
-        reinplace "s|universal=0|universal=0|g" \
-            ${worksrcpath}/include/makeinclude/platform_macros.GNU
+        setuniversalflags ${worksrcpath}/include/makeinclude/platform_macosx_${os.name}.GNU \
+            ${configure.universal_cxxflags} ${configure.universal_ldflags}
     }
+}
+
+variant ssl description {Enable SSL} {
+    depends_lib-append port:openssl
 
-    if {[variant_exists ssl] && [variant_isset ssl]} {
-        ui_debug "Enabling SSL"
+    post-patch {
         reinplace "s|ssl=0|ssl=1|g" \
             ${worksrcpath}/include/makeinclude/platform_macros.GNU
     }
-
-    reinplace "s|@PREFIX@|${prefix}|g" \
-        ${worksrcpath}/org.macports.${taodaemon}.plist
-    reinplace "s|@USER@|${taouser}|g" \
-        ${worksrcpath}/org.macports.${taodaemon}.plist
-    reinplace "s|@DAEMON@|${taodaemon}|g" \
-        ${worksrcpath}/org.macports.${taodaemon}.plist
 }
 
-depends_lib         path:bin/perl:perl5 \
-                    port:tcl \
-                    port:zlib
+variant server description {Enable CosNaming server} {
+    post-patch {
+        ui_info "patching org.macports.${taodaemon}.plist"
+        reinplace "s|@PREFIX@|${prefix}|g" \
+            ${worksrcpath}/org.macports.${taodaemon}.plist
+        reinplace "s|@USER@|${taouser}|g" \
+            ${worksrcpath}/org.macports.${taodaemon}.plist
+        reinplace "s|@DAEMON@|${taodaemon}|g" \
+            ${worksrcpath}/org.macports.${taodaemon}.plist
+    }
+
+    pre-install {
+        delete ${destroot}${prefix}/etc/LaunchDaemons/org.macports.${taodaemon}/org.macports.${taodaemon}.plist
+        delete ${destroot}${prefix}/etc/LaunchDaemons/org.macports.${taodaemon}/${taodaemon}.wrapper
+        copy ${worksrcpath}/org.macports.${taodaemon}.plist \
+            ${destroot}${prefix}/etc/LaunchDaemons/org.macports.${taodaemon}/org.macports.${taodaemon}.plist
+    }
+
+    startupitem.create  yes
+    startupitem.name    ${taodaemon}
+}
 
 use_configure       no
 
@@ -153,14 +178,6 @@
     # Files required to build CosEvent classes but not installed
     copy ${worksrcpath}/TAO/orbsvcs/orbsvcs/ESF ${destroot}/${prefix}/include/orbsvcs/ESF
 }
-pre-install {
-    delete ${destroot}${prefix}/etc/LaunchDaemons/org.macports.${taodaemon}/org.macports.${taodaemon}.plist
-    delete ${destroot}${prefix}/etc/LaunchDaemons/org.macports.${taodaemon}/${taodaemon}.wrapper
-    copy ${worksrcpath}/org.macports.${taodaemon}.plist \
-        ${destroot}${prefix}/etc/LaunchDaemons/org.macports.${taodaemon}/org.macports.${taodaemon}.plist
-}
-startupitem.create  yes
-startupitem.name    ${taodaemon}
 
 livecheck.type      regex
 livecheck.url       ${master_sites}
