Index: /trunk/dports/php/pear-install-phar/Portfile
===================================================================
--- /trunk/dports/php/pear-install-phar/Portfile	(revision 98223)
+++ /trunk/dports/php/pear-install-phar/Portfile	(revision 98224)
@@ -6,5 +6,5 @@
 name                pear-install-phar
 version             20110901
-revision            3
+revision            4
 categories          php www
 license             BSD PHP-3 LGPL-2.1+
@@ -13,31 +13,24 @@
 homepage            http://pear.php.net
 master_sites        http://pear.php.net
-livecheck.type      moddate
-
-dist_subdir         ${name}-${version}
-distfiles           install-pear-nozlib.phar
-
-checksums           rmd160  1eef5e3a68b5521e2d42e68d031fd79828709923 \
-                    sha256  06757ae34c93d4aad8a3abc63958106ca11bb1a9a5f85e7e013d70077e4aafa1
-
-set buildpath       ${worksrcpath}/build
-set libpath         /lib/php/pear
 
 subport php5-pear {
 
-    set dbpath          /var/db/php5
-    depends_lib         port:php5
+    set php.port        [lindex [split $subport -] 0]
+    set php.db          /var/db/${php.port}
+    depends_lib         port:${php.port}
 }
 
 subport php53-pear {
 
-    set dbpath          /var/db/php53
-    depends_lib         port:php53
+    set php.port        [lindex [split $subport -] 0]
+    set php.db          /var/db/${php.port}
+    depends_lib         port:${php.port}
 }
 
 subport php54-pear {
 
-    set dbpath          /var/db/php54
-    depends_lib         port:php54
+    set php.port        [lindex [split $subport -] 0]
+    set php.db          /var/db/${php.port}
+    depends_lib         port:${php.port}
 }
 
@@ -48,4 +41,15 @@
     description         PEAR installer phar
     long_description    ${description}
+
+    livecheck.type      moddate
+
+    dist_subdir         ${name}-${version}
+    distfiles           install-pear-nozlib.phar
+
+    checksums           rmd160  1eef5e3a68b5521e2d42e68d031fd79828709923 \
+                        sha256  06757ae34c93d4aad8a3abc63958106ca11bb1a9a5f85e7e013d70077e4aafa1
+
+    set buildpath       ${worksrcpath}/build
+    set libpath         /lib/php/pear
 
     extract.mkdir       yes
@@ -64,31 +68,37 @@
 } else {
 
-    description         PEAR build and repository support for php
+    description         Optional port that auto-prepends the PEAR repository for ${php.port}.
     long_description    ${description}
 
     distfiles
 
-    build {
+    worksrcdir          ${php.port}-pear
+    extract.dir         ${worksrcpath}
+    extract.mkdir       yes
+    post-extract {
 
-        xinstall -d ${buildpath}${dbpath}
-        set fp [open ${buildpath}${dbpath}/pear-ini.php w]
-        puts $fp "<?php"
-        puts $fp "# Automatically add the PEAR repository path to PHP's include_path."
-        puts $fp "set_include_path ( get_include_path (  ) . PATH_SEPARATOR . '${prefix}/lib/php/pear' ) ;"
-        close $fp
-    
-        set fp [open ${buildpath}${dbpath}/pear.ini w]
-        puts $fp "; Do not edit this file; it is automatically generated by MacPorts."
-        puts $fp "; Any changes you make will be lost if you upgrade or uninstall ${subport}-pear."
-        puts $fp "; To configure PHP, edit ${prefix}/etc/${subport}/php.ini."
-        puts $fp "auto_prepend_file = '${prefix}${dbpath}/pear/pear-ini.php'"
-        close $fp
+        copy ${filespath}/pear-ini.php ${worksrcpath}/pear-ini.php
+        copy ${filespath}/pear.ini ${worksrcpath}/pear.ini
     }
+
+    post-patch {
+
+        reinplace "s,@PHP.PORT@,${php.port},g" \
+            ${worksrcpath}/pear.ini
+        reinplace "s,@PREFIX@,${prefix},g" \
+            ${worksrcpath}/pear-ini.php \
+            ${worksrcpath}/pear.ini
+    }
+
+    use_configure       no
+    build {}
 
     destroot {
 
-        xinstall -d ${destroot}${prefix}${dbpath}/pear
-        file copy ${buildpath}${dbpath}/pear-ini.php ${destroot}${prefix}${dbpath}/pear/pear-ini.php
-        file copy ${buildpath}${dbpath}/pear.ini ${destroot}${prefix}${dbpath}/pear.ini
+        xinstall -d -m 0755 ${destroot}${prefix}/var/db/${php.port}/pear
+        xinstall -m 0644 ${worksrcpath}/pear-ini.php \
+            ${destroot}${prefix}/var/db/${php.port}/pear/pear-ini.php
+        xinstall -m 0644 ${worksrcpath}/pear.ini \
+            ${destroot}${prefix}/var/db/${php.port}/pear.ini
     }
 }
Index: /trunk/dports/php/pear-install-phar/files/pear-ini.php
===================================================================
--- /trunk/dports/php/pear-install-phar/files/pear-ini.php	(revision 98224)
+++ /trunk/dports/php/pear-install-phar/files/pear-ini.php	(revision 98224)
@@ -0,0 +1,3 @@
+<?php
+# Automatically add the PEAR repository path to PHP's include_path.
+set_include_path ( get_include_path (  ) . PATH_SEPARATOR . '@PREFIX@/lib/php/pear' );
Index: /trunk/dports/php/pear-install-phar/files/pear.ini
===================================================================
--- /trunk/dports/php/pear-install-phar/files/pear.ini	(revision 98224)
+++ /trunk/dports/php/pear-install-phar/files/pear.ini	(revision 98224)
@@ -0,0 +1,4 @@
+; Do not edit this file; it is automatically generated by MacPorts.
+; Any changes you make will be lost if you upgrade or uninstall @PHP.PORT@-pear.
+; To configure PHP, edit @PREFIX@/etc/@PHP.PORT@/php.ini.
+auto_prepend_file = '@PREFIX@/var/db/@PHP.PORT@/pear/pear-ini.php'
