Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

394 lines
16KB

  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_check_mysql.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_CHECK_MYSQL([MYSQL-PLUGIN-NEEDED],[MYSQL-REQUIRED],[MINIMUM-VERSION],[INCLUDES-REQUIRED])
  8. # AX_SOURCE_MYSQL()
  9. # AX_CHECK_MYSQL_INSTALL([ROOT-DIR],[IF-FOUND],[IF-NOT-FOUND])
  10. #
  11. # DESCRIPTION
  12. #
  13. # Looks for a MySQL installation in typical locations, or can take in a
  14. # flag designating where a MySQL installation is found. Sets the variables
  15. # stated to various attributes of the desired MySQL installation.
  16. #
  17. # In detail, AX_CHECK_MYSQL will automatically look for a MySQL
  18. # installation in the directories that a mysql source or binary install
  19. # typically install to. AX_CHECK_MYSQL will throw an error if it cannot
  20. # find one, and it is required.
  21. #
  22. # AX_CHECK_MYSQL can also check for specific variables passed regarding a
  23. # location of a MySQL installation.
  24. #
  25. # If a MySQL installation is found, AX_CHECK_MYSQL sets variables
  26. # regarding the version of MySQL, its architecture (32 or 64 bit), and
  27. # wether the version supports Plugins.
  28. #
  29. # AX_CHECK_MYSQL_INSTALL will check a designated root directory for a
  30. # command, plugin, and include directory. If a mysql binary is not found
  31. # or not found, the IF-FOUND and IF-NOT-FOUND directive will be executed,
  32. # respectively.
  33. #
  34. # AX_CHECK_MYSQL adds the following flags:
  35. #
  36. # --with-mysql, for the root of a desired MySQL installation
  37. # --with-mysql-plugin, for the path to the plugin directory of the MySQL installation
  38. # --with-mysql-include, for the path to the include directory of the MySQL installation
  39. # --with-mysql-command, for the path to the binary directory of the MySQL installation
  40. # --with-mysql-source, for the path to a directory containing the source of the MySQL installation
  41. #
  42. # AX_CHECK_MYSQL sets:
  43. #
  44. # MYSQL to indicate whether MySQL was found or not
  45. # MYSQL_INCLUDES to the include directory (if one exists)
  46. # MYSQL_PLUGINS to the plugin directory
  47. # MYSQL_COMMANDS to the mysql executable directory
  48. # MYSQL_ARCHITECTURE to whether MySQL is 32 or 64 bit (32 if 32, 64 if 64)
  49. # MYSQL_VERSION to what the MySQL version is (5.1,5.5, etc)
  50. # MYSQL_PLUGIN_OK to whether MySQL version supports plugins (5.1 or greater)
  51. # MYSQL_55 to whether the version of MySQL is 5.5 or greater
  52. # MYSQL_SOURCE to the source directory passed by --with-mysql-source
  53. #
  54. # LICENSE
  55. #
  56. # Copyright (c) 2011 University of Washington
  57. # Copyright (c) 2011 Yusuke Tsutsumi <tsutsumi.yusuke@gmail.com>
  58. # Copyright (c) 2011 Craig Stimmel <cstimmel@uw.edu>
  59. # Copyright (c) 2011 Eric Wu
  60. #
  61. # Copying and distribution of this file, with or without modification, are
  62. # permitted in any medium without royalty provided the copyright notice
  63. # and this notice are preserved. This file is offered as-is, without any
  64. # warranty.
  65. #serial 6
  66. AC_ARG_WITH(mysql,AS_HELP_STRING([--with-mysql],[root of the MySQL installation]))
  67. AC_ARG_WITH(mysql_plugin,AS_HELP_STRING([--with-mysql-plugin],[path to the MySQL installation plugin directory]))
  68. AC_ARG_WITH(mysql_include,AS_HELP_STRING([--with-mysql-include],[path to the MySQL installation include directory]))
  69. AC_ARG_WITH(mysql_command,AS_HELP_STRING([--with-mysql-command],[path to the MySQL executables directory]))
  70. AC_ARG_WITH(mysql_source,AS_HELP_STRING([--with-mysql-source],[path to MySQL source files]))
  71. # Used to look for MySQL installation specifically. Checks if binary exists.
  72. AC_DEFUN([AX_CHECK_MYSQL_COMMANDS],[
  73. # Define variables passed
  74. COMMAND_DIR="$1"
  75. # Check for the binary, and set appropriate variables
  76. unset ac_cv_mysql_bin_test
  77. AC_CHECK_PROG(mysql_bin_test,mysql,$COMMAND_DIR,no,$COMMAND_DIR)
  78. if test "$mysql_bin_test" != "no"; then
  79. AC_SUBST(MYSQL_COMMANDS,$mysql_bin_test)
  80. AC_SUBST(MYSQL,yes)
  81. else
  82. AC_SUBST(MYSQL_COMMANDS,no)
  83. AC_SUBST(MYSQL,no)
  84. fi
  85. ])
  86. # Use to look for the plugins directory
  87. AC_DEFUN([AX_CHECK_MYSQL_PLUGINS],[
  88. # Define variables passed
  89. PLUGIN_DIR="$1"
  90. AC_MSG_CHECKING([if $PLUGIN_DIR exists...])
  91. if [[ -d "$PLUGIN_DIR" ]]; then
  92. AC_SUBST(MYSQL_PLUGIN,yes)
  93. AC_MSG_RESULT([yes])
  94. else
  95. AC_SUBST(MYSQL_PLUGIN,no)
  96. AC_MSG_RESULT([no])
  97. fi
  98. ])
  99. # Use to look if includes are installed (determined by the existence of mysql_version.h)
  100. AC_DEFUN([AX_CHECK_MYSQL_INCLUDES],[
  101. # Define variables passed
  102. INCLUDE_DIR="$1"
  103. AC_CHECK_HEADER($INCLUDE_DIR/mysql_version.h,
  104. AC_SUBST(MYSQL_INCLUDES,$INCLUDE_DIR/),
  105. AC_SUBST(MYSQL_INCLUDES,no))
  106. ])
  107. AC_DEFUN([AX_CHECK_MYSQL_INSTALL],[
  108. #Define variables passed
  109. ROOT_DIR="$1"
  110. # Check for include directory
  111. AX_CHECK_MYSQL_INCLUDES([$ROOT_DIR/include/mysql/mysql_version.h])
  112. if test "$MYSQL_INCLUDES" == "no" ; then
  113. AX_CHECK_MYSQL_INCLUDES([$ROOT_DIR/include/mysql_version.h])
  114. fi
  115. mysql_include_test=$MYSQL_INCLUDES
  116. # Check for plugin directory
  117. AX_CHECK_MYSQL_PLUGINS([$ROOT_DIR/lib/mysql/plugin/])
  118. if test "$MYSQL_PLUGIN" == "no" ; then
  119. unset $MYSQL_PLUGIN
  120. AX_CHECK_MYSQL_PLUGINS([$ROOT_DIR/lib/plugin/])
  121. fi
  122. mysql_plugin_test=$MYSQL_PLUGIN
  123. # Check for binary directory
  124. AX_CHECK_MYSQL_COMMANDS([$ROOT_DIR/bin/])
  125. if test "$MYSQL" != "no"
  126. then
  127. true
  128. $2
  129. else
  130. true
  131. $3
  132. fi
  133. ])
  134. AC_DEFUN([AX_CHECK_MYSQL],[
  135. mysql_test="no"
  136. # Define variables
  137. MYSQL_PLUGIN_NEEDED=`echo $1 | grep -i -o "y"`
  138. MYSQL_REQUIRED=`echo $2 | grep -i -o "y"`
  139. MINIMUM_V="$3"
  140. INCLUDES_REQUIRED=`echo $4 | grep -i -o "y"`
  141. CLASSIFIER="none"
  142. mysql_issue=""
  143. # Checks for common installation locations of MySQL
  144. echo "Testing if MySQL was installed to common source/binary directory"
  145. AC_CHECK_PROG(mysqlsource,mysql,yes,no,/usr/local/mysql/bin,)
  146. echo "Testing if MySQL was installed to common package manager directory"
  147. AC_CHECK_PROG(mysqlpackage,mysql,yes,no,/usr/bin,)
  148. # Checks whether the directories contains what they're supposed to, then produces an error otherwise.
  149. # In addition, will also generate an error if no installations exist, or two installations are detected.
  150. if test "$ac_cv_prog_mysqlsource" == "yes" && test "$ac_cv_prog_mysqlpackage" == "yes"
  151. then
  152. mysql_issue="Multiple MySQL installations found. Please specify the MySQL installation directory with --with-mysql"
  153. else if test "$ac_cv_prog_mysqlsource" == "yes"
  154. then
  155. AX_CHECK_MYSQL_INSTALL(/usr/local/mysql,,)
  156. CLASSIFIER="source"
  157. else if test "$ac_cv_prog_mysqlpackage" == "yes"
  158. then
  159. AX_CHECK_MYSQL_INSTALL(/usr,,)
  160. CLASSIFIER="package"
  161. else
  162. mysql_issue="No default MySQL installs detected. Please specify the MySQL installation directory with --with-mysql"
  163. fi
  164. fi
  165. fi
  166. # Checks if --with-mysql flag was passed. If so, verifies that the directory follows assumed
  167. # structure and include,plugin, and bin directory is found. If there are no issues, this
  168. # will nullify any errors that would have been thrown by the above checking.
  169. if test "$with_mysql" != ""
  170. then
  171. AX_CHECK_MYSQL_INSTALL($with_mysql,,)
  172. CLASSIFIER="root"
  173. mysql_issue=""
  174. fi
  175. # Checks if specific MySQL directory flags were passed (--with-mysql-plugin, --with-mysql-include, --with-mysql-bin)
  176. # If so then checks if these variables are proper directories. If not, returns an error. Requires that all three directories must be defined.
  177. if test "$with_mysql_plugin" != "" || test "$with_mysql_include" != "" || test "$with_mysql_command" != ""
  178. then
  179. mysql_test="yes"
  180. if test "$with_mysql_plugin" == "" || test "$with_mysql_command" == ""
  181. then
  182. mysql_test="no"
  183. if test "$MYSQL_REQUIRED" != ""
  184. then
  185. AC_MSG_ERROR([Argument is missing! When using --with-mysql-plugin --with-mysql-bin please enter arguments for each.])
  186. else
  187. AC_MSG_WARN([Argument is missing! When using --with-mysql-plugin --with-mysql-bin please enter arguments for each.])
  188. fi
  189. else
  190. mysql_issue=""
  191. AX_CHECK_MYSQL_PLUGINS([$with_mysql_plugin])
  192. AX_CHECK_MYSQL_INCLUDES([$with_mysql_include])
  193. AX_CHECK_MYSQL_COMMANDS([$with_mysql_command])
  194. CLASSIFIER="custom"
  195. fi
  196. fi
  197. # If the installation does not exist or satisfy requirements, send an error or warning
  198. mysql_dne_message=""
  199. mysql_include_dne_message=""
  200. if test "$mysql_issue" != ""
  201. then
  202. if test "$MYSQL_REQUIRED" != ""
  203. then
  204. AC_MSG_ERROR([$mysql_issue])
  205. else
  206. AC_MSG_WARN([$mysql_issue])
  207. fi
  208. fi
  209. # Error message for not finding mysql executable
  210. if test "$MYSQL_BIN" == "no"
  211. then
  212. if test "$CLASSIFIER" == "root"
  213. then
  214. mysql_dne_message="Could not find directory containing MySQL includes. Please designate the command\,plugin\,and include directories manually with --with-mysql-command\, --with-mysql-plugin\, and --with-mysql-include"
  215. fi
  216. if test "$CLASSIFIER" == "custom"
  217. then
  218. mysql_dne_message="Could not find mysql executable in designated command directory. Please pass the directory containing the mysql executable with --with-mysql-command"
  219. fi
  220. fi
  221. # Error message for not finding mysql plugin directory
  222. if test "$MYSQL_PLUGINS" == "no"
  223. then
  224. if test "$CLASSIFIER" == "source"
  225. then
  226. AC_MSG_WARN([Could not find plugin directory for detected source installation. Please pass the root directory of the MySQL installation with --with-mysql])
  227. fi
  228. if test "$CLASSIFIER" == "package"
  229. then
  230. AC_MSG_WARN([Could not find plugin directory for detected package installation. Please pass the root directory of the MySQL installation with --with-mysql])
  231. fi
  232. if test "$CLASSIFIER" == "root"
  233. then
  234. AC_MSG_WARN([Could not find directory for MySQL plugins. Please designate the command\,plugin\,and include directories manually with --with-mysql-command\, --with-mysql-plugin\, and --with-mysql-include])
  235. fi
  236. if test "$CLASSIFIER" == "custom"
  237. then
  238. AC_MSG_WARN([Could not find mysql includes in designated plugin directory. Please pass the directory containing the mysql executable with --with-mysql-plugin])
  239. fi
  240. fi
  241. # Error message for not finding mysql include directory
  242. if test "$MYSQL_INCLUDES" == "no"
  243. then
  244. if test "$CLASSIFIER" == "source"
  245. then
  246. mysql_include_dne_message="A source install was detected, but the include directory 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 locations"
  247. fi
  248. if test "$CLASSIFIER" == "package"
  249. then
  250. mysql_include_dne_message="A package install was detected, but the include directory 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 locations"
  251. fi
  252. if test "$CLASSIFIER" == "root"
  253. then
  254. mysql_include_dne_message="Could not find directory containing MySQL includes. The MySQL development library may not be installed. If development library is installed\, please designate the command\,plugin\,and include directories manually with --with-mysql-command\, --with-mysql-plugin\, and --with-mysql-include"
  255. fi
  256. if test "$CLASSIFIER" == "custom"
  257. then
  258. mysql_include_dne_message="Could not find mysql includes in designated include directory. Please pass the directory containing the mysql_version.h include file with --with-mysql-include"
  259. fi
  260. fi
  261. # And execute the error messages
  262. if test "$mysql_dne_message" != ""
  263. then
  264. if test "$MYSQL_REQUIRED" != ""
  265. then
  266. AC_MSG_ERROR([$mysql_dne_message])
  267. else
  268. AC_MSG_WARN([$mysql_dne_message])
  269. fi
  270. fi
  271. if test "$mysql_include_dne_message" != ""
  272. then
  273. if test "$INCLUDES_REQUIRED" != ""
  274. then
  275. AC_MSG_ERROR([$mysql_include_dne_message])
  276. else
  277. AC_MSG_WARN([$mysql_include_dne_message])
  278. fi
  279. fi
  280. if test "$MYSQL" == "yes"
  281. then
  282. # Check MySQL version, wether it's 32 or 64 bit, and modifies the architecture variable accordingly
  283. AC_MSG_CHECKING([MySQL Architecture])
  284. MYSQL_ARCHITECTURE='file '$MYSQL_COMMANDS'/mysql'
  285. MYSQL_ARCHITECTURE=`$MYSQL_ARCHITECTURE | grep -o ".*bit" | sed s/-bit//g | grep -o "[[0-9]][[0-9]]$"`
  286. AC_MSG_RESULT([$MYSQL_ARCHITECTURE])
  287. AC_SUBST(MYSQL_ARCHITECTURE,$MYSQL_ARCHITECTURE)
  288. # Checks MySQL binary version
  289. AC_MSG_CHECKING([MySQL Version])
  290. MYSQL_PREFIX=$MYSQL_COMMANDS'/mysqladmin -v'
  291. MYSQL_V=`$MYSQL_PREFIX | grep -o 'Distrib.*,' | sed s/Distrib\ //g | sed s/,//g`
  292. AC_MSG_RESULT([$MYSQL_V])
  293. # Checks whether MySQL version is greater than 5.1, the version needed for plugins
  294. AC_MSG_CHECKING([if MySQL install supports Plugins])
  295. MYSQL_MAJOR_V=`echo $MYSQL_V | cut -c 1`
  296. MYSQL_MINOR_V=`echo $MYSQL_V | cut -c 3`
  297. MYSQL_REV_V=`echo $MYSQL_V | cut -c 5-6`
  298. MYSQL_PLUGIN_MINOR_V=1
  299. MYSQL_PLUGIN_MAJOR_V=5
  300. if test "$MYSQL_MAJOR_V" -lt "$MYSQL_PLUGIN_MAJOR_V" || (test "$MYSQL_MAJOR_V" -eq "$MYSQL_PLUGIN_MAJOR_V" && test "$MYSQL_MINOR_V" -lt "$MYSQL_PLUGIN_MINOR_V")
  301. then
  302. AC_SUBST(MYSQL_PLUGIN_OK,no)
  303. AC_MSG_RESULT([no])
  304. else
  305. AC_SUBST(MYSQL_PLUGIN_OK,yes)
  306. AC_MSG_RESULT([yes])
  307. fi
  308. if test "$MYSQL_PLUGIN_NEEDED" != ""
  309. then
  310. if test "$MYSQL_PLUGIN_OK" == "no"
  311. then
  312. AC_MSG_ERROR([MySQL version is not able to support plugins! Please upgrade your version of MySQL before installing])
  313. fi
  314. fi
  315. # Checks wether MINIMUM-VERSION was passed, does error checking for the value, and checks for version
  316. if test "$MINIMUM_V" != ""
  317. then
  318. MINIMUM_MAJOR_V=`echo $MINIMUM_V | cut -c 1`
  319. MINIMUM_MINOR_V=`echo $MINIMUM_V | cut -c 3`
  320. MINIMUM_REV_V=`echo $MINIMUM_V | cut -c 5-6`
  321. CHECKER_MAJOR=`echo $MINIMUM_MAJOR_V | grep -o '[[0-9]]'`
  322. CHECKER_MINOR=`echo $MINIMUM_MINOR_V | grep -o '[[0-9]]'`
  323. CHECKER_REV=`echo $MINIMUM_REV_V | grep -o '^[[0-9]]+'`
  324. if test "$CHECKER_MAJOR" != "" && test "$CHECKER_MINOR" != "" && test "$CHECKER_REV" == ""
  325. then
  326. AC_MSG_CHECKING([if MySQL version is equal or greater than $MINIMUM_V])
  327. if test "$MYSQL_MAJOR_V" -lt "$MINIMUM_MAJOR_V" || (test "$MYSQL_MAJOR_V" -eq "$MINIMUM_MAJOR_V" && test "$MYSQL_MINOR_V" -lt "$MINIMUM_MINOR_V") || (test "$MYSQL_MAJOR_V" -eq "$MINIMUM_MAJOR_V" && test "$MYSQL_MINOR_V" -eq "$MINIMUM_MINOR_V" && "$MYSQL_REV_V" -lt "MINIMUM_REV_V")
  328. then
  329. AC_SUBST(MYSQL_PLUGIN_OK,no)
  330. AC_MSG_RESULT([no])
  331. AC_MSG_ERROR([installed MySQL version is not above $MINIMUM_V. Please upgrade your version of MySQL])
  332. else
  333. AC_SUBST(MYSQL_PLUGIN_OK,yes)
  334. AC_MSG_RESULT([yes])
  335. fi
  336. else
  337. AC_MSG_ERROR([MINIMUM-VERSION variable in AX_CHEC_MYSQL is not formatted properly. Please use X.X or X.X.XX])
  338. fi
  339. fi
  340. # Checks whether MySQL version is 5.5 or greater, the production release with major header/include changes from before
  341. if test "$MYSQL_MAJOR_V" -gt 4 && test "$MYSQL_MINOR_V" -gt 4
  342. then
  343. AC_SUBST(MYSQL_55,yes)
  344. else
  345. AC_SUBST(MYSQL_55,no)
  346. fi
  347. fi
  348. ])
  349. AC_DEFUN([AX_SOURCE_MYSQL],[
  350. if test "$with_mysql_source" == ""
  351. then
  352. AC_MSG_ERROR(["Please Designate MySQL source path, using --with-mysql-source=YOUR_PATH"])
  353. else
  354. AC_SUBST(MYSQL_SOURCE,$with_mysql_source)
  355. fi
  356. ])