Index: Portfile
===================================================================
--- Portfile	(revision 120816)
+++ Portfile	(working copy)
@@ -8,8 +8,8 @@
 set my_name     icu4c
 # Don't forget to increase the revision number of the dependents (e.g. boost)
 # whenever the library version number changes. Thanks.
-version         51.2
-revision        1
+# port echo depends:icu finds dependencies
+version         53.1
 categories      devel textproc
 platforms       darwin freebsd
 license         MIT
@@ -28,60 +28,92 @@
 distname        ${my_name}-[join [split ${version} .] _]
 extract.suffix  .tgz
 distfiles       ${distname}-src${extract.suffix}
-patchfiles      patch-configure.diff \
-                patch-config-mh-darwin.diff \
-                inline.patch
 
 checksums       ${distname}-src.tgz \
-                rmd160  ef1256bb87b3dcec1cf40b32b11c5c3f1bd48af6 \
-                sha256  deb027a05f1b3bec03298b96fb93b28c84e9683c22e6f94effa67fdc7bd704cc
+                rmd160  9bd1b4bdc2010545c76a927dcf46049686beeab9 \
+                sha256  6fa74fb5aac070c23eaba1711a7178fe582c59867484c5ec07c49002787a9a28
 
 worksrcdir      ${name}/source
 set docdir      ${prefix}/share/doc/${name}
 
+# icu appends -O2 to the cflags and cxxflags
+configure.optflags-delete -Os
+
+# ICU has three mechanisms to aid other projects in building properly
+#     1) .pc files for pkg-config
+#     2) shell script icu-config that can output compiler flags
+#     3) Makefile include files Makefile.inc and pkgdata.inc
+# For a time, all three assumed other projects would want to be
+#     built as ICU had been built, regardless of whether it was appropriate.
+# For the most part, the extraneous flags have been removed.
+#     1) They have been removed completely from the .pc files.
+#        pkg-config is the recommended way of building against ICU.
+#     2) icu-config does not print them out, but they are still contained in the script itself.
+#     3) They still exist in the Makefile include files.
+#
+# for descriptions of the problem, see
+#     r101578
+#     #40069
+#     https://bugs.gentoo.org/show_bug.cgi?id=202059
+#
+# for upstream reports and discussion, see
+#    http://bugs.icu-project.org/trac/ticket/10308
+#    http://bugs.icu-project.org/trac/ticket/6102
 if {[variant_isset universal]} {
-    patchfiles-append   patch-universal.diff
-
-    # weirdly, icu needs a separate source dir built for the build
-    # machine in order to cross-compile
-    pre-configure {
-        global merger_configure_args
-        set cross 0
-        set 32bit 0
-        set crosspath ${worksrcpath}-cross
-        if {${os.major} < 9 || [sysctl hw.cpu64bit_capable] == 0} {
-            set 32bit 1
-        }
-        foreach a $universal_archs_to_use {
-            if {($32bit && ($a eq "x86_64" || $a eq "ppc64")) 
-                || (${os.arch} eq "powerpc" && ($a eq "x86_64" || $a eq "i386"))
-                || (${os.arch} eq "i386" && ($a eq "ppc" || $a eq "ppc64"))} {
-                set cross 1
-                set merger_configure_args($a) --with-cross-build=${crosspath}
+    merger-post-destroot {
+        set rebuilton ""
+        foreach arch ${universal_archs_to_use} {
+            set dir ${destroot}-${arch}
+            
+            # SIZEOF_VOID_P is no longer used in icu-config, so remove it to facilitate merging of the shell script
+            reinplace {s| -DSIZEOF_VOID_P=[48]||g} ${dir}${prefix}/bin/icu-config
+            
+            # icu-config contains the exact time it was built, which makes merging difficult
+            # ensure that all versions of icu-config have the same build timestamp
+            if { ${rebuilton} eq "" } {
+                set rebuilton [exec /usr/bin/tail -n 1 ${dir}${prefix}/bin/icu-config]
+            } else {
+                reinplace "s|^# Rebuilt on .*|${rebuilton}|" ${dir}${prefix}/bin/icu-config
             }
+            
+            # Removing architecture specific information from the Makefile include files is necessary to merge them correctly.
+            # It is concivable that this could cause problems for certain projects.
+            # The developers of ICU suggest using pkg-config over both icu-config and the Makefile includes.
+            reinplace {s| -DSIZEOF_VOID_P=[48]||g} ${dir}${prefix}/lib/icu/${version}/Makefile.inc
+            reinplace -E {s:-arch +[^ ]+::g} ${dir}${prefix}/lib/icu/${version}/pkgdata.inc
         }
-        if {$cross} {
-            copy ${worksrcpath} ${crosspath}
-            set configure_dir_save  ${configure.dir}
-            configure.dir ${crosspath}
-            portconfigure::configure_main
-            configure.dir $configure_dir_save
-            system -W ${crosspath} "${build.cmd}[portbuild::build_getjobsarg]"
-        }
     }
+} else {
+    post-destroot {
+        # stay consistent with the universal build (see comments above)
+        reinplace {s| -DSIZEOF_VOID_P=[48]||g} ${destroot}${prefix}/bin/icu-config
+        reinplace {s| -DSIZEOF_VOID_P=[48]||g} ${destroot}${prefix}/lib/icu/${version}/Makefile.inc
+        reinplace -E {s:-arch +[^ ]+::g} ${destroot}${prefix}/lib/icu/${version}/pkgdata.inc
+    }
 }
 
-post-patch {
-    reinplace "s|__PREFIX__|${prefix}|g" ${worksrcpath}/config/mh-darwin
+post-destroot {
+    # The ICU build mechanism passes rpath to the linker, but this should not be necessary if the shared libraries were built correctly.
+    reinplace {s|^default_ENABLE_RPATH="YES"$|default_ENABLE_RPATH="NO"|g} ${destroot}${prefix}/bin/icu-config
+    reinplace -E {s| -Wl,-rpath,.+/lib||g} ${destroot}${prefix}/lib/icu/${version}/pkgdata.inc
 }
 
 set platform [switch ${os.platform} {darwin {format MacOSX} freebsd {format FreeBSD}}]
 configure.cmd   ./runConfigureICU ${platform}
 
+# enable-rpath forces ICU to build the shared library correctly (with directory name in -install_name)
 configure.args  --enable-static \
-                --disable-samples
+                --disable-samples \
+                --enable-rpath
 
 configure.universal_args-delete --disable-dependency-tracking
+if {[variant_isset universal]} {
+    # ICU detects cross compiling by trying to run binaries.
+    # r73849 and #29904 indicate that cross compiling is a problem.
+    # Of the solutions tried (r79660, r73865, and r73849), simply disallowing cross compiling is by far the simplest.
+    # Note that #29904 should not show up again because universal now better recognizes 32/64-bit cross compiling (r79658)
+    set merger_must_run_binaries "yes"
+}
 
 # Fix bug #11981 that prevents ICU from building when upgrading.
 # The default configure flags causes utilisation of outdated ICU
@@ -89,85 +121,18 @@
 configure.cppflags
 configure.ldflags
 
-post-configure {
-    if {[variant_isset universal]} {
-        # Ticket #23773
-        foreach a ${universal_archs_to_use} {
-            reinplace "s|__ARCH__|${a}|g" ${worksrcpath}-${a}/Makefile
-        }
-    }
-}
-
 build.type      gnu
 
 use_parallel_build  yes
 
-post-build {
-    if {[variant_isset universal]} {
-        set dirs {}
-        foreach arch ${universal_archs_to_use} {
-            lappend dirs ${worksrcpath}-${arch}
-        }
-    } else {
-        set dirs ${worksrcpath}
-    }
-    foreach dir ${dirs} {
-        foreach f {Makefile.inc icu-config icu-i18n.pc icu-io.pc icu-le.pc icu-lx.pc icu-uc.pc icu.pc pkgdata.inc} {
-            reinplace -E {s|-arch [a-z0-9_]+||g} ${dir}/config/${f}
-        }
-    }
-}
-
 test.run        yes
 test.target     check
 
 post-destroot {
     xinstall -d ${destroot}${docdir}
     eval xinstall -m 0644 [glob ${worksrcpath}/../*.{css,html,txt}] ${destroot}${docdir}
-
-    if {[variant_isset universal]} {
-        # Ticket #23773
-        foreach a ${universal_archs_to_use} {
-            reinplace "s|/Makefile.inc|/Makefile-${a}.inc|g" ${destroot}${prefix}/bin/icu-config-${a}
-        }
-        ln -s current/Makefile.inc ${destroot}${prefix}/lib/icu/Makefile.inc
-    }
 }
 
-post-activate {
-    if {[variant_isset universal]} {
-        # Ticket #23773
-        set a ${configure.build_arch}
-        if {$a == "ppc64"} {
-            if {![file exists ${prefix}/bin/icu-config-${a}]} {
-                set a "ppc"
-            }
-        } elseif {$a == "x86_64"} {
-            if {![file exists ${prefix}/bin/icu-config-${a}]} {
-                set a "i386"
-                if {![file exists ${prefix}/bin/icu-config-${a}]} {
-                    set a "ppc"
-                }
-            }
-        } elseif {$a == "i386"} {
-            if {![file exists ${prefix}/bin/icu-config-${a}]} {
-                set a "ppc"
-            }
-        }
-        foreach {p q} [list "${prefix}/bin/icu-config-${a}" "${prefix}/bin/icu-config" \
-                            "${prefix}/lib/icu/${version}/Makefile-${a}.inc" "${prefix}/lib/icu/${version}/Makefile.inc" \
-                            "${prefix}/lib/pkgconfig/icu-i18n-${a}.pc" "${prefix}/lib/pkgconfig/icu-i18n.pc" \
-                            "${prefix}/lib/pkgconfig/icu-io-${a}.pc" "${prefix}/lib/pkgconfig/icu-io.pc" \
-                            "${prefix}/lib/pkgconfig/icu-le-${a}.pc" "${prefix}/lib/pkgconfig/icu-le.pc" \
-                            "${prefix}/lib/pkgconfig/icu-lx-${a}.pc" "${prefix}/lib/pkgconfig/icu-lx.pc" \
-                            "${prefix}/lib/pkgconfig/icu-uc-${a}.pc" "${prefix}/lib/pkgconfig/icu-uc.pc"] {
-            if {[file exists ${p}]} {
-                ln -s ${p} ${q}
-            }
-        }
-    }
-}
-
 # icu @51.2_0 and earlier also installed the following files directly, bypassing destroot:
 #   ${prefix}/lib/icu/${version}/pkgdata.inc
 # These files can be removed from the below deactivation block after August 2014.
@@ -192,8 +157,8 @@
     extract.only        ${distname}-src${extract.suffix}
     distfiles-append    ${distname}-docs.zip
     checksums-append    ${distname}-docs.zip \
-                        rmd160  87f332c1c2e4c5322cd110f93e8ccb288d0303a9 \
-                        sha256  c488b3ddbb99a4a368cfc74e725d6a9e491ae6ac0169caba2197c15ffb85b7c5
+                        rmd160  60ce19f8633c18d670ad2f0b8d7920cd6ed0a314 \
+                        sha256  2c700534d52b98615b4baffcf0502f37540604e67817625f05d6e2fbf98d0c0b
 
     post-extract {
         xinstall -m 0755 -d ${worksrcpath}/doc
Index: files/inline.patch
===================================================================
--- files/inline.patch	(revision 120816)
+++ files/inline.patch	(working copy)
@@ -1,11 +0,0 @@
---- common/umutex.h.orig	2012-06-01 07:52:44.000000000 -0700
-+++ common/umutex.h	2013-01-18 23:34:55.000000000 -0800
-@@ -29,7 +29,7 @@
- #if U_PLATFORM_IS_DARWIN_BASED
- #if defined(__STRICT_ANSI__)
- #define UPRV_REMAP_INLINE
--#define inline
-+#define inline __inline__
- #endif
- #include <libkern/OSAtomic.h>
- #define USE_MAC_OS_ATOMIC_INCREMENT 1
Index: files/patch-config-mh-darwin.diff
===================================================================
--- files/patch-config-mh-darwin.diff	(revision 120816)
+++ files/patch-config-mh-darwin.diff	(working copy)
@@ -1,11 +0,0 @@
---- config/mh-darwin.orig	2011-10-14 04:38:41.000000000 -0700
-+++ config/mh-darwin	2011-10-14 05:32:55.000000000 -0700
-@@ -28,7 +28,7 @@
- ifeq ($(ENABLE_RPATH),YES)
- LD_SONAME = -Wl,-compatibility_version -Wl,$(SO_TARGET_VERSION_MAJOR) -Wl,-current_version -Wl,$(SO_TARGET_VERSION) -install_name $(libdir)/$(notdir $(MIDDLE_SO_TARGET))
- else
--LD_SONAME = -Wl,-compatibility_version -Wl,$(SO_TARGET_VERSION_MAJOR) -Wl,-current_version -Wl,$(SO_TARGET_VERSION) -install_name $(notdir $(MIDDLE_SO_TARGET))
-+LD_SONAME = -Wl,-compatibility_version -Wl,$(SO_TARGET_VERSION_MAJOR) -Wl,-current_version -Wl,$(SO_TARGET_VERSION) -install_name __PREFIX__/lib/$(notdir $(MIDDLE_SO_TARGET))
- endif
- 
- ## Compiler switch to embed a runtime search path
Index: files/patch-configure.diff
===================================================================
--- files/patch-configure.diff	(revision 120816)
+++ files/patch-configure.diff	(working copy)
@@ -1,73 +0,0 @@
---- configure.org	2013-05-30 14:16:18.000000000 +0200
-+++ configure	2013-05-30 14:17:11.000000000 +0200
-@@ -4066,7 +4066,7 @@
-         then
-             # Do not use -ansi. It limits us to C90, and it breaks some platforms.
-             # We use -std=c99 to disable the gnu99 defaults and its associated warnings
--            CFLAGS="$CFLAGS -Wall -std=c99 -pedantic -Wshadow -Wpointer-arith -Wmissing-prototypes -Wwrite-strings"
-+            CFLAGS="$CFLAGS -std=c99 -pedantic -Wshadow -Wpointer-arith -Wmissing-prototypes -Wwrite-strings"
-         else
-             case "${host}" in
-             *-*-cygwin)
-@@ -4078,7 +4078,7 @@
-         fi
-         if test "$GXX" = yes
-         then
--            CXXFLAGS="$CXXFLAGS -W -Wall -pedantic -Wpointer-arith -Wwrite-strings -Wno-long-long"
-+            CXXFLAGS="$CXXFLAGS -W -pedantic -Wpointer-arith -Wwrite-strings -Wno-long-long"
-         else
-             case "${host}" in
-             *-*-cygwin)
-@@ -6006,40 +6006,6 @@
-   $as_echo_n "(cached) " >&6
- else
-   ac_cv_c_bigendian=unknown
--    # See if we're dealing with a universal compiler.
--    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
--/* end confdefs.h.  */
--#ifndef __APPLE_CC__
--	       not a universal capable compiler
--	     #endif
--	     typedef int dummy;
--
--_ACEOF
--if ac_fn_c_try_compile "$LINENO"; then :
--
--	# Check for potential -arch flags.  It is not universal unless
--	# there are at least two -arch flags with different values.
--	ac_arch=
--	ac_prev=
--	for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do
--	 if test -n "$ac_prev"; then
--	   case $ac_word in
--	     i?86 | x86_64 | ppc | ppc64)
--	       if test -z "$ac_arch" || test "$ac_arch" = "$ac_word"; then
--		 ac_arch=$ac_word
--	       else
--		 ac_cv_c_bigendian=universal
--		 break
--	       fi
--	       ;;
--	   esac
--	   ac_prev=
--	 elif test "x$ac_word" = "x-arch"; then
--	   ac_prev=arch
--	 fi
--       done
--fi
--rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-     if test $ac_cv_c_bigendian = unknown; then
-       # See if sys/param.h defines the BYTE_ORDER macro.
-       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-@@ -6214,11 +6180,6 @@
- ;; #(
-    no)
-       ;; #(
--   universal)
--
--$as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h
--
--     ;; #(
-    *)
-      as_fn_error $? "unknown endianness
-  presetting ac_cv_c_bigendian=no (or yes) will help" "$LINENO" 5 ;;
Index: files/patch-universal.diff
===================================================================
--- files/patch-universal.diff	(revision 120816)
+++ files/patch-universal.diff	(working copy)
@@ -1,24 +0,0 @@
---- Makefile.in.orig	2013-05-23 15:06:32.000000000 -0500
-+++ Makefile.in	2013-08-15 01:22:22.000000000 -0500
-@@ -169,15 +169,18 @@
- 	$(INSTALL_SCRIPT) $(top_srcdir)/install-sh $(DESTDIR)$(pkgdatadir)/install-sh
- 	@$(MKINSTALLDIRS) $(DESTDIR)$(libdir)/pkgconfig
- 	$(INSTALL_DATA) $(ALL_PKGCONFIG_FILES) $(DESTDIR)$(libdir)/pkgconfig/
-+	@for f in $(ALL_PKGCONFIG_SUFFIX); do \
-+	  mv "$(DESTDIR)$(libdir)/pkgconfig/icu-$${f}.pc" "$(DESTDIR)$(libdir)/pkgconfig/icu-$${f}-__ARCH__.pc"; \
-+	done;
- 	$(INSTALL_DATA) $(top_srcdir)/../license.html $(DESTDIR)$(pkgdatadir)/license.html
--	$(INSTALL_SCRIPT) $(top_builddir)/config/icu-config $(DESTDIR)$(bindir)/icu-config
--	$(INSTALL_DATA) $(top_builddir)/config/Makefile.inc $(DESTDIR)$(pkglibdir)/Makefile.inc
-+	$(INSTALL_SCRIPT) $(top_builddir)/config/icu-config $(DESTDIR)$(bindir)/icu-config-__ARCH__
-+	$(INSTALL_DATA) $(top_builddir)/config/Makefile.inc $(DESTDIR)$(pkglibdir)/Makefile-__ARCH__.inc
- 	$(INSTALL_DATA) $(top_builddir)/config/pkgdata.inc $(DESTDIR)$(pkglibdir)/pkgdata.inc
- #	@echo icuinfo.xml is built after make check.
- #	-$(INSTALL_DATA) $(top_builddir)/config/icuinfo.xml $(DESTDIR)$(pkglibdir)/icuinfo.xml
- 	cd $(DESTDIR)$(pkglibdir)/..; \
- 	    $(RM) current && ln -s $(VERSION) current; \
--	    $(RM) Makefile.inc && ln -s current/Makefile.inc Makefile.inc; \
-+#	    $(RM) Makefile.inc && ln -s current/Makefile.inc Makefile.inc; \
- 	    $(RM) pkgdata.inc && ln -s current/pkgdata.inc pkgdata.inc
- 
- ifeq ($(DOXYGEN),)
