Index: databases/mariadb/files/patch-Makefile.in.diff
===================================================================
--- databases/mariadb/files/patch-Makefile.in.diff	(revision 94531)
+++ databases/mariadb/files/patch-Makefile.in.diff	(working copy)
@@ -1,11 +0,0 @@
---- Makefile.in.orig	2011-03-02 07:25:33.000000000 +0100
-+++ Makefile.in	2011-03-13 20:32:33.000000000 +0100
-@@ -482,7 +482,7 @@
- 			@sql_union_dirs@ storage \
- 			@sql_server@ @man_dirs@ tests \
- 			netware @libmysqld_dirs@ \
--			mysql-test support-files sql-bench @tools_dirs@ \
-+			support-files @tools_dirs@ \
- 			win
- 
- DIST_SUBDIRS = . include Docs zlib \
Index: databases/mariadb/files/patch-storage-maria-CMakeLists.txt.diff
===================================================================
--- databases/mariadb/files/patch-storage-maria-CMakeLists.txt.diff	(revision 0)
+++ databases/mariadb/files/patch-storage-maria-CMakeLists.txt.diff	(working copy)
@@ -0,0 +1,11 @@
+--- a/storage/maria/CMakeLists.txt	2012-06-09 10:56:52.000000000 -0700
++++ b/storage/maria/CMakeLists.txt	2012-06-10 14:30:33.000000000 -0700
+@@ -92,4 +92,7 @@
+ CMAKE_DEPENDENT_OPTION(USE_ARIA_FOR_TMP_TABLES "Use Aria for temporary tables" ON
+                        "WITH_ARIA_STORAGE_ENGINE" OFF)
+ 
+-ADD_SUBDIRECTORY(unittest)
++IF(WITH_MARIA_STORAGE_ENGINE)
++  ENABLE_TESTING()
++  ADD_SUBDIRECTORY(unittest)
++ENDIF()
Index: databases/mariadb/files/my.cnf
===================================================================
--- databases/mariadb/files/my.cnf	(revision 0)
+++ databases/mariadb/files/my.cnf	(working copy)
@@ -0,0 +1,2 @@
+# Use default MacPorts settings
+!include @PREFIX@/etc/@NAME@/macports-default.cnf
Index: databases/mariadb/files/patch-storage-perfschema-CMakeLists.txt.diff
===================================================================
--- databases/mariadb/files/patch-storage-perfschema-CMakeLists.txt.diff	(revision 0)
+++ databases/mariadb/files/patch-storage-perfschema-CMakeLists.txt.diff	(working copy)
@@ -0,0 +1,11 @@
+--- a/storage/perfschema/CMakeLists.txt	2012-06-09 10:56:53.000000000 -0700
++++ b/storage/perfschema/CMakeLists.txt	2012-06-10 14:23:06.000000000 -0700
+@@ -74,6 +74,7 @@
+ )
+ 
+ MYSQL_ADD_PLUGIN(perfschema ${PERFSCHEMA_SOURCES} STORAGE_ENGINE DEFAULT STATIC_ONLY)
+-IF(WITH_PERFSCHEMA_STORAGE_ENGINE)
++IF(WITH_PERFSCHEMA_STORAGE_ENGINE AND WITH_UNIT_TESTS)
++  ENABLE_TESTING()
+   ADD_SUBDIRECTORY(unittest)
+ ENDIF()
Index: databases/mariadb/files/mariadb
===================================================================
--- databases/mariadb/files/mariadb	(revision 0)
+++ databases/mariadb/files/mariadb	(working copy)
@@ -0,0 +1,423 @@
+-
+-
+-
+-
+-
+lib/mariadb/bin/innochecksum
+lib/mariadb/bin/msql2mysql
+lib/mariadb/bin/my_print_defaults
+lib/mariadb/bin/myisam_ftdump
+lib/mariadb/bin/myisamchk
+lib/mariadb/bin/myisamlog
+lib/mariadb/bin/myisampack
+lib/mariadb/bin/mysql
+lib/mariadb/bin/mysql_client_test
+-
+lib/mariadb/bin/mysql_config
+lib/mariadb/bin/mysql_convert_table_format
+lib/mariadb/bin/mysql_find_rows
+lib/mariadb/bin/mysql_fix_extensions
+-
+lib/mariadb/bin/mysql_install_db
+lib/mariadb/bin/mysql_plugin
+lib/mariadb/bin/mysql_secure_installation
+lib/mariadb/bin/mysql_setpermission
+lib/mariadb/bin/mysql_tzinfo_to_sql
+lib/mariadb/bin/mysql_upgrade
+lib/mariadb/bin/mysql_waitpid
+lib/mariadb/bin/mysql_zap
+lib/mariadb/bin/mysqlaccess
+-
+lib/mariadb/bin/mysqladmin
+lib/mariadb/bin/mysqlbinlog
+lib/mariadb/bin/mysqlbug
+lib/mariadb/bin/mysqlcheck
+lib/mariadb/bin/mysqld
+lib/mariadb/bin/mysqld_multi
+lib/mariadb/bin/mysqld_safe
+lib/mariadb/bin/mysqldump
+lib/mariadb/bin/mysqldumpslow
+lib/mariadb/bin/mysqlhotcopy
+lib/mariadb/bin/mysqlimport
+-
+lib/mariadb/bin/mysqlshow
+lib/mariadb/bin/mysqlslap
+lib/mariadb/bin/mysqltest
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+lib/mariadb/bin/perror
+lib/mariadb/bin/replace
+lib/mariadb/bin/resolve_stack_dump
+lib/mariadb/bin/resolveip
+-
+-
+share/man/mariadb/man1/innochecksum.1.gz
+share/man/mariadb/man1/msql2mysql.1.gz
+share/man/mariadb/man1/my_print_defaults.1.gz
+share/man/mariadb/man1/myisam_ftdump.1.gz
+share/man/mariadb/man1/myisamchk.1.gz
+share/man/mariadb/man1/myisamlog.1.gz
+share/man/mariadb/man1/myisampack.1.gz
+share/man/mariadb/man1/mysql-stress-test.pl.1.gz
+share/man/mariadb/man1/mysql-test-run.pl.1.gz
+share/man/mariadb/man1/mysql.1.gz
+share/man/mariadb/man1/mysql.server.1.gz
+share/man/mariadb/man1/mysql_client_test.1.gz
+share/man/mariadb/man1/mysql_client_test_embedded.1.gz
+share/man/mariadb/man1/mysql_config.1.gz
+share/man/mariadb/man1/mysql_convert_table_format.1.gz
+share/man/mariadb/man1/mysql_find_rows.1.gz
+share/man/mariadb/man1/mysql_fix_extensions.1.gz
+share/man/mariadb/man1/mysql_fix_privilege_tables.1.gz
+share/man/mariadb/man1/mysql_install_db.1.gz
+-
+share/man/mariadb/man1/mysql_secure_installation.1.gz
+share/man/mariadb/man1/mysql_setpermission.1.gz
+share/man/mariadb/man1/mysql_tzinfo_to_sql.1.gz
+share/man/mariadb/man1/mysql_upgrade.1.gz
+share/man/mariadb/man1/mysql_waitpid.1.gz
+share/man/mariadb/man1/mysql_zap.1.gz
+share/man/mariadb/man1/mysqlaccess.1.gz
+share/man/mariadb/man1/mysqladmin.1.gz
+share/man/mariadb/man1/mysqlbinlog.1.gz
+-
+share/man/mariadb/man1/mysqlcheck.1.gz
+share/man/mariadb/man1/mysqld_multi.1.gz
+share/man/mariadb/man1/mysqld_safe.1.gz
+share/man/mariadb/man1/mysqldump.1.gz
+share/man/mariadb/man1/mysqldumpslow.1.gz
+share/man/mariadb/man1/mysqlhotcopy.1.gz
+share/man/mariadb/man1/mysqlimport.1.gz
+share/man/mariadb/man1/mysqlman.1.gz
+share/man/mariadb/man1/mysqlshow.1.gz
+share/man/mariadb/man1/mysqlslap.1.gz
+share/man/mariadb/man1/mysqltest.1.gz
+share/man/mariadb/man1/mysqltest_embedded.1.gz
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+share/man/mariadb/man1/perror.1.gz
+share/man/mariadb/man1/replace.1.gz
+share/man/mariadb/man1/resolve_stack_dump.1.gz
+share/man/mariadb/man1/resolveip.1.gz
+share/man/mariadb/man8/mysqld.8.gz
+share/man/mariadb/man8/mysqlmanager.8.gz
+-
+-
+-
+-
+-
+-
+-
+-
+lib/mariadb/bin/innochecksum
+lib/mariadb/bin/msql2mysql
+lib/mariadb/bin/my_print_defaults
+lib/mariadb/bin/myisam_ftdump
+lib/mariadb/bin/myisamchk
+lib/mariadb/bin/myisamlog
+lib/mariadb/bin/myisampack
+lib/mariadb/bin/mysql
+lib/mariadb/bin/mysql_client_test
+-
+lib/mariadb/bin/mysql_config
+lib/mariadb/bin/mysql_convert_table_format
+lib/mariadb/bin/mysql_find_rows
+lib/mariadb/bin/mysql_fix_extensions
+-
+lib/mariadb/bin/mysql_install_db
+lib/mariadb/bin/mysql_plugin
+lib/mariadb/bin/mysql_secure_installation
+lib/mariadb/bin/mysql_setpermission
+lib/mariadb/bin/mysql_tzinfo_to_sql
+lib/mariadb/bin/mysql_upgrade
+lib/mariadb/bin/mysql_waitpid
+lib/mariadb/bin/mysql_zap
+lib/mariadb/bin/mysqlaccess
+-
+lib/mariadb/bin/mysqladmin
+lib/mariadb/bin/mysqlbinlog
+lib/mariadb/bin/mysqlbug
+lib/mariadb/bin/mysqlcheck
+lib/mariadb/bin/mysqld
+lib/mariadb/bin/mysqld_multi
+lib/mariadb/bin/mysqld_safe
+lib/mariadb/bin/mysqldump
+lib/mariadb/bin/mysqldumpslow
+lib/mariadb/bin/mysqlhotcopy
+lib/mariadb/bin/mysqlimport
+-
+lib/mariadb/bin/mysqlshow
+lib/mariadb/bin/mysqlslap
+lib/mariadb/bin/mysqltest
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+lib/mariadb/bin/perror
+lib/mariadb/bin/replace
+lib/mariadb/bin/resolve_stack_dump
+lib/mariadb/bin/resolveip
+-
+-
+share/man/mariadb/man1/innochecksum.1.gz
+share/man/mariadb/man1/msql2mysql.1.gz
+share/man/mariadb/man1/my_print_defaults.1.gz
+share/man/mariadb/man1/myisam_ftdump.1.gz
+share/man/mariadb/man1/myisamchk.1.gz
+share/man/mariadb/man1/myisamlog.1.gz
+share/man/mariadb/man1/myisampack.1.gz
+share/man/mariadb/man1/mysql-stress-test.pl.1.gz
+share/man/mariadb/man1/mysql-test-run.pl.1.gz
+share/man/mariadb/man1/mysql.1.gz
+share/man/mariadb/man1/mysql.server.1.gz
+share/man/mariadb/man1/mysql_client_test.1.gz
+share/man/mariadb/man1/mysql_client_test_embedded.1.gz
+share/man/mariadb/man1/mysql_config.1.gz
+share/man/mariadb/man1/mysql_convert_table_format.1.gz
+share/man/mariadb/man1/mysql_find_rows.1.gz
+share/man/mariadb/man1/mysql_fix_extensions.1.gz
+share/man/mariadb/man1/mysql_fix_privilege_tables.1.gz
+share/man/mariadb/man1/mysql_install_db.1.gz
+-
+share/man/mariadb/man1/mysql_secure_installation.1.gz
+share/man/mariadb/man1/mysql_setpermission.1.gz
+share/man/mariadb/man1/mysql_tzinfo_to_sql.1.gz
+share/man/mariadb/man1/mysql_upgrade.1.gz
+share/man/mariadb/man1/mysql_waitpid.1.gz
+share/man/mariadb/man1/mysql_zap.1.gz
+share/man/mariadb/man1/mysqlaccess.1.gz
+share/man/mariadb/man1/mysqladmin.1.gz
+share/man/mariadb/man1/mysqlbinlog.1.gz
+-
+share/man/mariadb/man1/mysqlcheck.1.gz
+share/man/mariadb/man1/mysqld_multi.1.gz
+share/man/mariadb/man1/mysqld_safe.1.gz
+share/man/mariadb/man1/mysqldump.1.gz
+share/man/mariadb/man1/mysqldumpslow.1.gz
+share/man/mariadb/man1/mysqlhotcopy.1.gz
+share/man/mariadb/man1/mysqlimport.1.gz
+share/man/mariadb/man1/mysqlman.1.gz
+share/man/mariadb/man1/mysqlshow.1.gz
+share/man/mariadb/man1/mysqlslap.1.gz
+share/man/mariadb/man1/mysqltest.1.gz
+share/man/mariadb/man1/mysqltest_embedded.1.gz
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+share/man/mariadb/man1/perror.1.gz
+share/man/mariadb/man1/replace.1.gz
+share/man/mariadb/man1/resolve_stack_dump.1.gz
+share/man/mariadb/man1/resolveip.1.gz
+share/man/mariadb/man8/mysqld.8.gz
+share/man/mariadb/man8/mysqlmanager.8.gz
+-
+-
+-
+-
+-
+-
+-
+-
+lib/mariadb/bin/innochecksum
+lib/mariadb/bin/msql2mysql
+lib/mariadb/bin/my_print_defaults
+lib/mariadb/bin/myisam_ftdump
+lib/mariadb/bin/myisamchk
+lib/mariadb/bin/myisamlog
+lib/mariadb/bin/myisampack
+lib/mariadb/bin/mysql
+lib/mariadb/bin/mysql_client_test
+-
+lib/mariadb/bin/mysql_config
+lib/mariadb/bin/mysql_convert_table_format
+lib/mariadb/bin/mysql_find_rows
+lib/mariadb/bin/mysql_fix_extensions
+-
+lib/mariadb/bin/mysql_install_db
+lib/mariadb/bin/mysql_plugin
+lib/mariadb/bin/mysql_secure_installation
+lib/mariadb/bin/mysql_setpermission
+lib/mariadb/bin/mysql_tzinfo_to_sql
+lib/mariadb/bin/mysql_upgrade
+lib/mariadb/bin/mysql_waitpid
+lib/mariadb/bin/mysql_zap
+lib/mariadb/bin/mysqlaccess
+-
+lib/mariadb/bin/mysqladmin
+lib/mariadb/bin/mysqlbinlog
+lib/mariadb/bin/mysqlbug
+lib/mariadb/bin/mysqlcheck
+lib/mariadb/bin/mysqld
+lib/mariadb/bin/mysqld_multi
+lib/mariadb/bin/mysqld_safe
+lib/mariadb/bin/mysqldump
+lib/mariadb/bin/mysqldumpslow
+lib/mariadb/bin/mysqlhotcopy
+lib/mariadb/bin/mysqlimport
+-
+lib/mariadb/bin/mysqlshow
+lib/mariadb/bin/mysqlslap
+lib/mariadb/bin/mysqltest
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+lib/mariadb/bin/perror
+lib/mariadb/bin/replace
+lib/mariadb/bin/resolve_stack_dump
+lib/mariadb/bin/resolveip
+-
+-
+share/man/mariadb/man1/innochecksum.1.gz
+share/man/mariadb/man1/msql2mysql.1.gz
+share/man/mariadb/man1/my_print_defaults.1.gz
+share/man/mariadb/man1/myisam_ftdump.1.gz
+share/man/mariadb/man1/myisamchk.1.gz
+share/man/mariadb/man1/myisamlog.1.gz
+share/man/mariadb/man1/myisampack.1.gz
+share/man/mariadb/man1/mysql-stress-test.pl.1.gz
+share/man/mariadb/man1/mysql-test-run.pl.1.gz
+share/man/mariadb/man1/mysql.1.gz
+share/man/mariadb/man1/mysql.server.1.gz
+share/man/mariadb/man1/mysql_client_test.1.gz
+share/man/mariadb/man1/mysql_client_test_embedded.1.gz
+share/man/mariadb/man1/mysql_config.1.gz
+share/man/mariadb/man1/mysql_convert_table_format.1.gz
+share/man/mariadb/man1/mysql_find_rows.1.gz
+share/man/mariadb/man1/mysql_fix_extensions.1.gz
+share/man/mariadb/man1/mysql_fix_privilege_tables.1.gz
+share/man/mariadb/man1/mysql_install_db.1.gz
+-
+share/man/mariadb/man1/mysql_secure_installation.1.gz
+share/man/mariadb/man1/mysql_setpermission.1.gz
+share/man/mariadb/man1/mysql_tzinfo_to_sql.1.gz
+share/man/mariadb/man1/mysql_upgrade.1.gz
+share/man/mariadb/man1/mysql_waitpid.1.gz
+share/man/mariadb/man1/mysql_zap.1.gz
+share/man/mariadb/man1/mysqlaccess.1.gz
+share/man/mariadb/man1/mysqladmin.1.gz
+share/man/mariadb/man1/mysqlbinlog.1.gz
+-
+share/man/mariadb/man1/mysqlcheck.1.gz
+share/man/mariadb/man1/mysqld_multi.1.gz
+share/man/mariadb/man1/mysqld_safe.1.gz
+share/man/mariadb/man1/mysqldump.1.gz
+share/man/mariadb/man1/mysqldumpslow.1.gz
+share/man/mariadb/man1/mysqlhotcopy.1.gz
+share/man/mariadb/man1/mysqlimport.1.gz
+share/man/mariadb/man1/mysqlman.1.gz
+share/man/mariadb/man1/mysqlshow.1.gz
+share/man/mariadb/man1/mysqlslap.1.gz
+share/man/mariadb/man1/mysqltest.1.gz
+share/man/mariadb/man1/mysqltest_embedded.1.gz
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+-
+share/man/mariadb/man1/perror.1.gz
+share/man/mariadb/man1/replace.1.gz
+share/man/mariadb/man1/resolve_stack_dump.1.gz
+share/man/mariadb/man1/resolveip.1.gz
+share/man/mariadb/man8/mysqld.8.gz
+share/man/mariadb/man8/mysqlmanager.8.gz
+-
+-
+-
Index: databases/mariadb/files/macports-default.cnf
===================================================================
--- databases/mariadb/files/macports-default.cnf	(revision 0)
+++ databases/mariadb/files/macports-default.cnf	(working copy)
@@ -0,0 +1,11 @@
+# WARNING! ANY CHANGES TO THIS FILE WILL BE LOST ON UNINSTALL/UPGRADES!
+# Make your changes to @PREFIX@/etc/@NAME@/my.cnf
+# YOU HAVE BEEN WARNED!
+
+# MacPorts default options
+[mysqld]
+# skip-networking so multple mysql server ports can be loaded
+# without each competing for port 3306.
+# One can always put the servers on different ports and
+# remove or comment this option.
+skip-networking
Index: databases/mariadb/files/patch-cmake-install_layout.cmake.diff
===================================================================
--- databases/mariadb/files/patch-cmake-install_layout.cmake.diff	(revision 0)
+++ databases/mariadb/files/patch-cmake-install_layout.cmake.diff	(working copy)
@@ -0,0 +1,52 @@
+--- a/cmake/install_layout.cmake	2012-06-09 10:56:48.000000000 -0700
++++ b/cmake/install_layout.cmake	2012-06-09 18:27:32.000000000 -0700
+@@ -71,7 +71,7 @@
+ ENDIF()
+ 
+ SET(INSTALL_LAYOUT "${INSTALL_LAYOUT}"
+-CACHE STRING "Installation directory layout. Options are: STANDALONE (as in zip or tar.gz installer) RPM DEB SVR4")
++CACHE STRING "Installation directory layout. Options are: STANDALONE (as in zip or tar.gz installer) RPM DEB SVR4 MACPORTS")
+ 
+ IF(UNIX)
+   IF(INSTALL_LAYOUT MATCHES "RPM")
+@@ -89,7 +89,7 @@
+     SET(CMAKE_INSTALL_PREFIX ${default_prefix}
+       CACHE PATH "install prefix" FORCE)
+   ENDIF()
+-  SET(VALID_INSTALL_LAYOUTS "RPM" "STANDALONE" "DEB" "SVR4")
++  SET(VALID_INSTALL_LAYOUTS "RPM" "STANDALONE" "DEB" "SVR4" "MACPORTS")
+   LIST(FIND VALID_INSTALL_LAYOUTS "${INSTALL_LAYOUT}" ind)
+   IF(ind EQUAL -1)
+     MESSAGE(FATAL_ERROR "Invalid INSTALL_LAYOUT parameter:${INSTALL_LAYOUT}."
+@@ -219,6 +219,31 @@
+ SET(INSTALL_PLUGINTESTDIR_SVR4          ${plugin_tests})
+ 
+ SET(INSTALL_UNIX_ADDRDIR_SVR            "/tmp/mysql.sock")
++#
++# MACPORTS layout
++#
++SET(INSTALL_BINDIR_MACPORTS             "lib/@NAME@/bin")
++SET(INSTALL_SBINDIR_MACPORTS            "lib/@NAME@/bin")
++SET(INSTALL_SCRIPTDIR_MACPORTS          "lib/@NAME@/bin")
++#
++SET(INSTALL_LIBDIR_MACPORTS             "lib/@NAME@/mysql")
++SET(INSTALL_PLUGINDIR_MACPORTS          "lib/@NAME@/plugin")
++#
++SET(INSTALL_INCLUDEDIR_MACPORTS         "include/@NAME@/mysql")
++#
++SET(INSTALL_DOCDIR_MACPORTS             "share/docs/@NAME@")
++SET(INSTALL_DOCREADMEDIR_MACPORTS       "share/docs/@NAME@")
++SET(INSTALL_MANDIR_MACPORTS             "share/man/@NAME@")
++SET(INSTALL_INFODIR_MACPORTS            "share/docs/@NAME@")
++#
++SET(INSTALL_SHAREDIR_MACPORTS           "share/@NAME@")
++SET(INSTALL_MYSQLSHAREDIR_MACPORTS      "share/@NAME@")
++SET(INSTALL_MYSQLTESTDIR_MACPORTS       "share/@NAME@/mysql-test")
++SET(INSTALL_SQLBENCHDIR_MACPORTS        "share/@NAME@")
++SET(INSTALL_SUPPORTFILESDIR_MACPORTS    "share/@NAME@/support-files")
++#
++SET(INSTALL_MYSQLDATADIR_MACPORTS       "var/db/@NAME@")
++SET(INSTALL_PLUGINTESTDIR_MACPORTS      ${plugin_tests})
+ 
+ # Clear cached variables if install layout was changed
+ IF(OLD_INSTALL_LAYOUT)
Index: databases/mariadb/Portfile
===================================================================
--- databases/mariadb/Portfile	(revision 94531)
+++ databases/mariadb/Portfile	(working copy)
@@ -1,130 +1,241 @@
 # -*- 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$
 
-PortSystem              1.0
+PortSystem          1.0
 
-name                    mariadb
-conflicts               mysql5-devel mysql5 mysql4
-version                 5.2.9
-categories              databases
-platforms               darwin
-license                 GPL-2
-maintainers             jogwtr@googlemail.com
+name                mariadb
+set name_mysql      ${name}
+version             5.5.24
+# Please set revision_client and revision_server to 0 if you bump version.
+set revision_client 0
+set revision_server 0
+categories          databases
+platforms           darwin
+license             GPL-2
+maintainers         googlemail.com:jogwtr
 
-description \
-    A database server that offers drop-in replacement functionality for MySQL
-long_description \
-    MariaDB is a database server that offers drop-in replacement functionality for \
-    MySQL1. MariaDB is built by some of the original authors of MySQL, with \
-    assistance from the broader community of Free and open source software \
-    developers. In addition to the core functionality of MySQL, MariaDB offers a \
-    rich set of feature enhancements including alternate storage engines, server \
-    optimizations, and patches.
+if {$subport == $name} {
 
-homepage                http://mariadb.org/
-master_sites \
-    http://mirrors.supportex.net/mariadb/${distname}/kvm-tarbake-jaunty-x86/ \
-    http://www.percona.com/downloads/MariaDB/${distname}/kvm-tarbake-jaunty-x86/ \
-    http://ftp.osuosl.org/pub/mariadb/${distname}/kvm-tarbake-jaunty-x86/ \
-    http://mirrors.supportex.net/mariadb/${distname}/kvm-tarbake-jaunty-x86/ \
-    http://technocation.org/mirror/mariadb/${distname}/kvm-tarbake-jaunty-x86/ \
-    http://mirror.aarnet.edu.au/pub/MariaDB/${distname}/kvm-tarbake-jaunty-x86/ \
-    http://ftp-stud.hs-esslingen.de/pub/Mirrors/mariadb/${distname}/kvm-tarbake-jaunty-x86/ \
-    http://gd.tuwien.ac.at/db/mariadb/${distname}/kvm-tarbake-jaunty-x86/ \
-    http://mirrors.fe.up.pt/pub/mariadb/${distname}/kvm-tarbake-jaunty-x86/
-distname                mariadb-${version}
+    PortGroup           archcheck 1.0
+    PortGroup           cmake 1.0
+    PortGroup           select 1.0
 
-checksums               md5     eb79ea79d3199c37f15d88fbd97e2216 \
-                        sha1    da87cdc4d3f76cbbe059684175461e18972f323b \
-                        rmd160  23f89e13ec9b9f731f42ba65f40ea07ad21a4471
+    set branch          [join [lrange [split ${version} .] 0 1] .]
 
-depends_lib             port:zlib \
-                        port:openssl
+    revision            ${revision_client}
+    license             GPL-2
+    description         Multithreaded SQL database server
+    long_description    MySQL is an open-source, multi-threaded SQL database with a command \
+                        syntax very similar to mSQL.
 
-set major_version       [strsed ${version} {s/\..*$//}]
-set mariadb             mysql5
-set libdir              ${prefix}/lib/${mariadb}
-set bindir              ${libdir}/bin
-set dbdir               ${prefix}/var/db/${mariadb}
-set sysconfdir          ${prefix}/etc/${mariadb}
+    homepage            http://mariadb.org/
+    master_sites \
+        http://ftp.osuosl.org/pub/mariadb/mariadb-${version}/kvm-tarbake-jaunty-x86/ \
+        http://mirror2.hs-esslingen.de/mariadb/mariadb-${version}/kvm-tarbake-jaunty-x86/ \
+        http://mirror3.layerjet.com/mariadb/mariadb-${version}/kvm-tarbake-jaunty-x86/ \
+        http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/mariadb-${version}/kvm-tarbake-jaunty-x86/ \
+        http://mirrors.supportex.net/mariadb/mariadb-${version}/kvm-tarbake-jaunty-x86/ \
+        http://mirror.switch.ch/mirror/mariadb/mariadb-${version}/kvm-tarbake-jaunty-x86/ \
+        http://mirrors.fe.up.pt/pub/mariadb/mariadb-${version}/kvm-tarbake-jaunty-x86/ \
+        http://gd.tuwien.ac.at/db/mariadb/mariadb-${version}/kvm-tarbake-jaunty-x86/ \
+        http://mirror.aarnet.edu.au/pub/MariaDB/mariadb-${version}/kvm-tarbake-jaunty-x86/ \
+        http://ftp.heanet.ie/mirrors/mariadb/mariadb-${version}/kvm-tarbake-jaunty-x86/
 
-if {"darwin" == ${os.platform} && ${os.major} > 8} {
-    set mariadbuser       _mysql
-} else {
-    set mariadbuser       mysql
-}
+    use_parallel_build  yes
 
-patchfiles                patch-Makefile.in.diff
+    patch.pre_args      -p1
+    patchfiles          patch-cmake-install_layout.cmake.diff \
+                        patch-storage-maria-CMakeLists.txt.diff \
+                        patch-storage-perfschema-CMakeLists.txt.diff
 
-configure.args \
-    --mandir=${prefix}/share/man \
-    --infodir=${prefix}/share/info \
-    --localstatedir=${dbdir} \
-    --libdir=${libdir} \
-    --bindir=${bindir} \
-    --includedir=${prefix}/include/${mariadb} \
-    --datadir=${prefix}/share/${mariadb} \
-    --sysconfdir=${sysconfdir} \
-    --with-zlib-dir=bundled \
-    --with-ssl=${prefix} \
-    --with-extra-charsets=complex \
-    --with-unix-socket-path=${prefix}/var/run/${mariadb}/mysqld.sock \
-    --with-mysqld-user=${mariadbuser} \
-    --without-docs \
-    --with-plugins=max \
-    --enable-thread-safe-client \
-    --enable-assembler \
-    --enable-thread-safe-client \
-    --with-big-tables \
-    --with-plugin-aria \
-    --with-aria-tmp-tables \
-    --without-plugin-innodb_plugin \
-    --with-libevent \
-    --enable-local-infile
+    checksums           rmd160  237dd9e77c110c11d078362cb7c84c3dcefbf785 \
+                        sha256  ced8d6b851ad0047d6654520c784f1bcfc3afa986f154ddb798041d1ebf9118b
 
-# Add readline support.
-# "--without-readline" has the peculiar meaning "do not use the bundled copy
-# of readline but use the system's (i.e. MacPorts') copy of readline"
-depends_lib-append      port:readline
-configure.args-append   --without-readline
+    depends_lib-append  port:zlib \
+                        port:cmake
+    depends_run-append  port:mysql_select
 
-# Build libmysqld embedded server.
-configure.cflags-append -fPIC
-configure.cxxflags-append -fPIC
-configure.args-append --with-embedded-server --with-pic
+    select.group        mysql
+    select.file         ${filespath}/${name_mysql}
 
-post-build {
-    set dirs ${worksrcpath}
-    foreach dir ${dirs} {
-        reinplace -E {s|-arch [a-z0-9_]+||g} \
-            ${dir}/scripts/mysql_config \
-            ${dir}/scripts/mysqlbug
+    archcheck.files     lib/libz.dylib
+
+    post-extract {
+        file mkdir ${worksrcpath}/build_macports/macports
+        copy ${filespath}/macports-default.cnf \
+            ${filespath}/my.cnf \
+            ${worksrcpath}/build_macports/macports/
     }
-}
 
-pre-destroot {
-    xinstall -m 755 -d ${destroot}${sysconfdir}
-    destroot.keepdirs-append ${destroot}${sysconfdir}
-}
+    post-patch {
+        reinplace "s|@NAME@|${name_mysql}|g" \
+            ${worksrcpath}/cmake/install_layout.cmake
+        reinplace "s|@NAME@|${name_mysql}|g" \
+            ${worksrcpath}/build_macports/macports/macports-default.cnf \
+            ${worksrcpath}/build_macports/macports/my.cnf
+        reinplace "s|@PREFIX@|${prefix}|g" \
+            ${worksrcpath}/build_macports/macports/macports-default.cnf \
+            ${worksrcpath}/build_macports/macports/my.cnf
+    }
 
-post-destroot {
-    # Fix paths in manpages and sample configuration files
-    foreach manpage [glob -type f ${destroot}${prefix}/share/man/man\[1-9\]/*] {
-        reinplace "s|/etc/my.cnf|${sysconfdir}/my.cnf|g" ${manpage}
+    configure.cmd       cmake ..
+    configure.dir       ${worksrcpath}/build_macports
+    build.dir           ${worksrcpath}/build_macports
+
+    configure.args-delete \
+                        -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib
+    configure.args-append \
+                        -DCMAKE_INSTALL_NAME_DIR:STRING=${prefix}/lib/${name_mysql}/mysql \
+                        -DINSTALL_LAYOUT:STRING=MACPORTS \
+                        -DSYSCONFDIR:PATH=${prefix}/etc/${name_mysql} \
+                        -DMYSQL_UNIX_ADDR:PATH=${prefix}/var/run/${name_mysql}/mysqld.sock \
+                        -DMYSQL_DATADIR:PATH=${prefix}/var/db/${name_mysql} \
+                        -DDEFAULT_CHARSET:STRING=utf8 \
+                        -DDEFAULT_COLLATION:STRING=utf8_general_ci \
+                        -DWITH_EMBEDDED_SERVER:BOOL=OFF \
+                        -DWITH_ZLIB:STRING=system \
+                        -DWITH_UNIT_TESTS:BOOL=ON \
+                        -DENABLE_GCOV:BOOL=OFF \
+                        -DENABLE_DTRACE:BOOL=OFF \
+                        -DWITH_READLINE:BOOL=ON \
+                        -DWITH_LIBEDIT:BOOL=OFF \
+                        -DWITH_LIBWRAP:BOOL=ON \
+                        -DWITH_SSL:STRING=no
+
+    # OQGraph storage engine does not currently compile
+    configure.args-append \
+                        -DWITHOUT_OQGRAPH:BOOL=YES
+
+    post-build {
+        set dirs ${worksrcpath}/build_macports
+        foreach dir ${dirs} {
+            reinplace -E {s|-arch [a-z0-9_]+||g} \
+                ${dir}/scripts/mysql_config \
+                ${dir}/scripts/mysqlbug
+        }
     }
-    foreach samp_conffile [glob -type f ${destroot}${prefix}/share/${mariadb}/mysql/my-*.cnf] {
-        reinplace "s|/etc/my.cnf|${sysconfdir}/my.cnf|g" ${samp_conffile}
+
+    post-destroot {
+        # proc portdestroot::destroot_finish fails to find and compress our man pages
+        # so borrow the compress command and run on our files now.
+        set manpath "${destroot}${prefix}/share/man"
+        set gzip [findBinary gzip ${portutil::autoconf::gzip_path}]
+        foreach manpage [glob -type f ${destroot}${prefix}/share/man/${name_mysql}/man\[1-9\]/*] {
+            # Fix paths in manpages
+            reinplace "s|/etc/|${prefix}/etc/${name_mysql}/|g" ${manpage}
+            # Compress all manpages with gzip
+            system "$gzip -9vf ${manpage}"
+        }
+        foreach samp_conffile [glob -type f ${destroot}${prefix}/share/${name_mysql}/support-files/my-*.cnf] {
+            # Fix paths in sample configuration files
+            reinplace "s|/etc/my.cnf|${prefix}/etc/${name_mysql}/my.cnf|g" ${samp_conffile}
+        }
+        xinstall -m 755 -o root -d \
+            ${destroot}${prefix}/etc/${name_mysql}
+        copy ${worksrcpath}/build_macports/macports/macports-default.cnf \
+            ${destroot}${prefix}/etc/${name_mysql}/
+        xinstall -m 755 -o root -d \
+            ${destroot}${prefix}/share/${name_mysql}/support-files/macports
+        copy ${worksrcpath}/build_macports/macports/my.cnf \
+            ${destroot}${prefix}/share/${name_mysql}/support-files/macports/
     }
+
+    post-install {
+        if {![file exists ${prefix}/etc/LaunchDaemons/org.macports.${name_mysql}/org.macports.${name_mysql}-server.plist]} {
+            ui_msg "The ${name_mysql} client has been installed."
+            ui_msg "To install the ${name_mysql} server, install the ${name_mysql}-server port."
+        }
+    }
+
+    pre-activate {
+        if { [file exists ${prefix}/etc/${name_mysql}/macports-default.cnf]
+            && ![catch {set vers [lindex [registry_active ${name_mysql}-server] 0]}]
+            && [vercmp [lindex $vers 1] 5.5.24] < 0 } {
+        
+            set deactivate_proc registry_deactivate_composite
+            if {[info commands registry_deactivate_composite] == {}} {
+                set deactivate_proc registry_deactivate
+            }
+            $deactivate_proc ${name_mysql}-server "" [list ports_nodepcheck 1]
+        }
+    }
+
+    post-activate {
+        if {![file exists ${prefix}/etc/${name_mysql}/my.cnf]} {
+            copy ${destroot}${prefix}/share/${name_mysql}/support-files/macports/my.cnf \
+                ${prefix}/etc/${name_mysql}/
+        }
+    }
+
+    variant openssl description {Enable OpenSSL support} {
+
+        depends_lib-append      port:openssl
+        configure.args-delete   -DWITH_SSL:STRING=no
+        configure.args-append   -DWITH_SSL:STRING=system
+        archcheck.files-append  lib/libssl.dylib
+    }
+
+    variant system_readline description {Use system readline instead of bundled readline} {
     
-    # Symlink mysql binaries into bin directory, with ${major_version} appended to the name
-    foreach f [glob -tails -directory ${destroot}${bindir} my*] {
-        ln -sf ${bindir}/${f} ${destroot}${prefix}/bin/${f}${major_version}
+        # Add readline support.
+        # "-DWITH_READLINE:BOOL=OFF" has the peculiar meaning "do not use the bundled copy
+        # of readline but use the system's (i.e. MacPorts') copy of readline"
+        depends_lib-append      port:readline
+        configure.args-delete   -DWITH_READLINE:BOOL=ON
+        configure.args-append   -DWITH_READLINE:BOOL=OFF
+        archcheck.files-append  lib/libreadline.dylib
     }
+
+    livecheck.type      regex
+    livecheck.url       http://downloads.mariadb.org/MariaDB/+releases/
+    livecheck.regex     "<a href=\"/MariaDB/(\[^/\]+)/\">"
 }
 
-post-install {
-    if {![file exists ${prefix}/etc/LaunchDaemons/org.macports.${mariadb}/org.macports.${mariadb}.plist]} {
-        ui_msg "The MariaDB client has been installed."
-        ui_msg "If you also want a MariaDB server, install the mariadb-server port."
+subport ${name_mysql}-server {
+
+    revision            ${revision_server}
+    license             BSD
+    description         Run ${name_mysql} as server
+    long_description    ${description}
+
+    supported_archs     noarch
+    distfiles
+
+    depends_run         port:${name_mysql}
+
+    if {"darwin" == ${os.platform} && ${os.major} > 8} {
+        set mysqluser       _mysql
+    } else {
+        set mysqluser       mysql
     }
+    add_users ${mysqluser} group=${mysqluser} realname=MySQL\ Server
+
+    startupitem.create      yes
+    startupitem.executable  ${prefix}/lib/${name_mysql}/bin/mysqld --user=${mysqluser}
+
+    use_configure       no
+
+    build {}
+
+    destroot {
+        xinstall -m 755 -o root -d \
+            ${destroot}${prefix}/var/run
+        xinstall -m 755 -o ${mysqluser} -g ${mysqluser} -d \
+            ${destroot}${prefix}/etc/${name_mysql} \
+            ${destroot}${prefix}/var/db/${name_mysql} \
+            ${destroot}${prefix}/var/log/${name_mysql} \
+            ${destroot}${prefix}/var/run/${name_mysql}
+        destroot.keepdirs-append  \
+            ${destroot}${prefix}/var/db/${name_mysql} \
+            ${destroot}${prefix}/var/log/${name_mysql} \
+            ${destroot}${prefix}/var/run/${name_mysql}
+    }
+
+    notes "
+If this is a new install you might want to run:
+
+\$ sudo -u ${mysqluser} ${prefix}/lib/${name_mysql}/bin/mysql_install_db
+"
+
+    livecheck.type          none
 }
