I previously mentioned ax_check_mysql.m4 in one of my posts, an m4 macro written for autoconf. So here’s a bit more information about it, and some examples on how to use it.
So ax_check_mysql is essentially an m4 macro for autoconf that was written with MySQL plugin developers in mind. When one runs the macro, a detected MySQL installation will give you the following information:
- The path to the directory containing the MySQL executables
- The path to the directory containing MySQL includes (if they exist)
- The path to the directory where MySQL plugins go
- The version of MySQL
- Whether MySQL is 32 or 64 bit
In the situation where an installation can not be detected or an incomplete one is found, arguments can also be entered manually with:
(where the root directory of the MySQL installation is passed (such as /usr/local/mysql or some other custom directory) and
--with-mysql-command, --with-mysql-plugin, --with-mysql-include
Which would just passing all the directories directly.
One can include the macro in the same fashion as any other macro in the configure.ac file:
AC_INIT(ax_check_mysql_example,version-1.0) m4_include([m4_ax_check_mysql.m4]) AX_CHECK_MYSQL([no],[yes],[5.0],[no]) AC_MSG_NOTICE($MYSQL) AC_MSG_NOTICE($MYSQL_COMMANDS)
Now if I run this script on a computer with MySQL installed, you should something along the lines of:
$ autoconf && ./configure checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking how to run the C preprocessor... gcc -E checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes Testing if MySQL was installed to common source/binary directory checking for mysql... no Testing if MySQL was installed to common package manager directory checking for mysql... yes checking /usr/include/mysql/mysql_version.h/mysql_version.h usability... no checking /usr/include/mysql/mysql_version.h/mysql_version.h presence... no checking for /usr/include/mysql/mysql_version.h/mysql_version.h... no checking /usr/include/mysql_version.h/mysql_version.h usability... no checking /usr/include/mysql_version.h/mysql_version.h presence... no checking for /usr/include/mysql_version.h/mysql_version.h... no checking if /usr/lib/mysql/plugin/ exists...... yes checking for mysql... /usr/bin/ configure: WARNING: A package install was detected, but the include dire ctory could not be found! MySQL development library may not be installed . If development library is installed please use --with-mysql-include -- with-mysql-plugin --with-mysql-command to manually assign directory loca tions checking MySQL Architecture... 32 checking MySQL Version... 5.1.41 checking if MySQL install supports Plugins... yes checking if MySQL version is equal or greater than 5.0... yes configure: yes configure: /usr/bin/
Note that the last two lines of output were echoing the MYSQL and MYSQL_COMMAND variables respectively, and that I do not have the development library installed. A full list of variables available are listed in the documentation.
One can pass four arguments when running the macro:
MYSQL-PLUGIN-NEEDED: if the MySQL version doesn’t support plugins (< 5.1), this will cause failure.
MYSQL-REQUIRED: say if MySQL is required or not.
MINIMUM-VERSION: minimum version required for MySQL (i.e. 5.0 or 5.5)
INCLUDES-REQUIRED: whether the MySQL includes are required (will fail if includes are not found)
For example, If I wanted MySQL 5.5 or higher, I could enter:
AC_INIT(ax_check_mysql_example,version-1.0) m4_include([m4_ax_check_mysql.m4]) AX_CHECK_MYSQL([no],[yes],[5.5],[no])
And as my MySQL installation is 5.1.41, ./configure will fail:
checking MySQL Architecture... 32 checking MySQL Version... 5.1.41 checking if MySQL install supports Plugins... yes checking if MySQL version is equal or greater than 5.5... no configure: error: installed MySQL version is not above 5.5. Please upgrade your version of MySQL
Entering nothing in the version field will allow any version.
Warnings will be outputted instead of errors if components aren’t required (such as includes or MySQL itself).
And there’s a brief example! Feel free to comment or contact me (firstname.lastname@example.org) if there are any questions/ comments.
The script is maintained by myself on github: