1 # -*- tab-width: 4; -*-
7 .if defined(_POSTMKINCLUDED) && !defined(Database_Post_Include)
9 Database_Post_Include= bsd.database.mk
10 Database_Include_MAINTAINER= ports@FreeBSD.org
12 # This file contains some routines to interact with different databases, such
13 # as MySQL, PostgreSQL, and Berkley DB. To include this file, define macro
14 # USE_[DATABASE], for example USE_MYSQL. Defining macro like
15 # USE_[DATABASE]_VER or WANT_[DATABASE]_VER will include this file as well.
18 # USE_MYSQL - Add MySQL (client/server/embedded) dependency (default:
20 # If no version is given (by the maintainer via the port or
21 # by the user via defined variable), try to find the
22 # currently installed version. Fall back to default if
23 # necessary (MySQL-5.5 = 55).
25 # - MySQL default version. Can be overridden within a port.
28 # - Maintainer can set an arbitrary version of MySQL to always
29 # build this port with (overrides WITH_MYSQL_VER).
31 # - This variable can be defined if the ports does not support
32 # one or more versions of MySQL.
34 # - User defined variable to set MySQL version.
36 # - Detected MySQL version.
38 # USE_PGSQL - Add PostgreSQL client dependency. Components can be depended
39 # on using USE_PGSQL= component[:target]. For the full list
40 # use make -V _USE_PGSQL_DEP
41 # If no version is given (by the maintainer via the port or
42 # by the user via defined variable), try to find the
43 # currently installed version. Fall back to default if
44 # necessary (PostgreSQL-9.0 = 90).
46 # - PostgreSQL default version, currently 92.
48 # - Maintainer can set an arbitrary version of PostgreSQL to
49 # always build this port with (overrides WITH_PGSQL_VER).
50 # Minimum and maximum versions can be set (e.g. 90+)
52 # - User defined variable to set PostgreSQL version.
54 # - Detected PostgreSQL version.
56 # USE_BDB - Add Berkeley DB library dependency.
57 # If no version is given (by the maintainer via the port or
58 # by the user via defined variable), try to find the
59 # currently installed version. Fall back to default if
62 # - This variable can be defined when the port does not
63 # support one or more versions of Berkeley DB.
65 # - Maintainer can set a version of Berkeley DB to always
66 # build this port with (overrides WITH_BDB_VER).
68 # - User defined global variable to set Berkeley DB version.
69 # <UNIQUENAME>_WITH_BDB_VER
70 # - User defined port specific variable to set Berkeley DB
73 # - Use the highest installed version of Berkeley DB.
75 # - This variable is automatically set to the name of the
76 # Berkeley DB library (default: db48).
78 # - This variable is automatically set to the name of the
79 # Berkeley DB C++ library (default: db48_cxx).
81 # - This variable is automatically set to the location of
82 # the Berkeley DB include directory (default:
83 # ${LOCALBASE}/include/db48).
85 # - This variable is automatically set to the location of
86 # the Berkeley DB library directory.
88 # - Detected Berkeley DB version.
90 # USE_SQLITE - Add dependency on SQLite library. Valid values are:
91 # 3 and 2. If version is not specified directly then
92 # SQLite-3 is used (if USE_SQLITE= yes).
94 # - Detected SQLite version.
96 # USE_FIREBIRD - Add dependency on Firebird library. Valid values are:
97 # 2 and 1. If no version is given by the maintainer (if
98 # USE_FIREBIRD= yes) and the user did not define
99 # WITH_FIREBIRD_VER variable, fall back to default "2".
101 # - User defined variable to set Firebird version.
103 # - Detected Firebird version.
105 .include "${PORTSDIR}/Mk/bsd.default-versions.mk"
107 .if defined(DEFAULT_MYSQL_VER)
108 WARNING+= "DEFAULT_MYSQL_VER is defined, consider using DEFAULT_VERSIONS=mysql=${DEFAULT_MYSQL_VER} instead"
111 .if defined(DEFAULT_PGSQL_VER)
112 WARNING+= "DEFAULT_PGSQL_VER is defined, consider using DEFAULT_VERSIONS=pgsql=${DEFAULT_PGSQL_VER} instead"
115 .if defined(USE_MYSQL)
116 DEFAULT_MYSQL_VER?= ${MYSQL_DEFAULT:S/.//}
117 # MySQL client version currently supported.
126 # Setting/finding MySQL version we want.
127 .if exists(${LOCALBASE}/bin/mysql)
128 _MYSQL!= ${LOCALBASE}/bin/mysql --version | ${SED} -e 's/.*Distrib \([0-9]\)\.\([0-9]*\).*/\1\2/'
129 _PERCONA!= ${LOCALBASE}/bin/mysql --version | ${GREP} Percona | wc -l
130 _MARIADB!= ${LOCALBASE}/bin/mysql --version | ${GREP} MariaDB | wc -l
133 _MYSQL_VER= ${_MYSQL}p
134 .elif ${_MARIADB} == 1
135 _MYSQL_VER= ${_MYSQL}m
137 _MYSQL_VER= ${_MYSQL}
141 .if defined(WANT_MYSQL_VER)
142 .if defined(WITH_MYSQL_VER) && ${WITH_MYSQL_VER} != ${WANT_MYSQL_VER}
143 IGNORE= cannot install: the port wants mysql${WANT_MYSQL_VER}-client and you try to install mysql${WITH_MYSQL_VER}-client
145 MYSQL_VER= ${WANT_MYSQL_VER}
146 .elif defined(WITH_MYSQL_VER)
147 MYSQL_VER= ${WITH_MYSQL_VER}
149 .if defined(_MYSQL_VER)
150 MYSQL_VER= ${_MYSQL_VER}
152 MYSQL_VER= ${DEFAULT_MYSQL_VER}
154 .endif # WANT_MYSQL_VER
156 .if defined(_MYSQL_VER)
157 .if ${_MYSQL_VER} != ${MYSQL_VER}
158 IGNORE= cannot install: MySQL versions mismatch: mysql${_MYSQL_VER}-client is installed and wanted version is mysql${MYSQL_VER}-client
162 .if (${MYSQL_VER} == "53m")
163 _MYSQL_CLIENT= databases/mariadb-client
164 _MYSQL_SERVER= databases/mariadb-server
165 .elif (${MYSQL_VER} == "55m")
166 _MYSQL_CLIENT= databases/mariadb55-client
167 _MYSQL_SERVER= databases/mariadb55-server
168 .elif (${MYSQL_VER} == "55p")
169 _MYSQL_CLIENT= databases/percona55-client
170 _MYSQL_SERVER= databases/percona55-server
171 .elif (${MYSQL_VER} == "56p")
172 _MYSQL_CLIENT= databases/percona56-client
173 _MYSQL_SERVER= databases/percona56-server
175 _MYSQL_CLIENT= databases/mysql${MYSQL_VER}-client
176 _MYSQL_SERVER= databases/mysql${MYSQL_VER}-server
179 # And now we are checking if we can use it
180 .if defined(MYSQL${MYSQL_VER}_LIBVER)
181 .if defined(IGNORE_WITH_MYSQL)
182 . for VER in ${IGNORE_WITH_MYSQL}
183 . if (${MYSQL_VER} == "${VER}")
184 IGNORE= cannot install: does not work with MySQL version ${MYSQL_VER} (MySQL ${IGNORE_WITH_MYSQL} not supported)
187 .endif # IGNORE_WITH_MYSQL
188 .if (${USE_MYSQL} == "server" || ${USE_MYSQL} == "embedded")
189 RUN_DEPENDS+= ${LOCALBASE}/libexec/mysqld:${PORTSDIR}/${_MYSQL_SERVER}
190 .if (${USE_MYSQL} == "embedded")
191 BUILD_DEPENDS+= ${LOCALBASE}/lib/mysql/libmysqld.a:${PORTSDIR}/${_MYSQL_SERVER}
194 LIB_DEPENDS+= libmysqlclient.so.${MYSQL${MYSQL_VER}_LIBVER}:${PORTSDIR}/${_MYSQL_CLIENT}
197 IGNORE= cannot install: unknown MySQL version: ${MYSQL_VER}
198 .endif # Check for correct libs
201 .if defined(USE_PGSQL)
202 VALID_PGSQL_VER= 84 90 91 92 93 94
203 DEFAULT_PGSQL_VER?= ${PGSQL_DEFAULT:S/.//}
212 # Setting/finding PostgreSQL version we want.
213 . if exists(${LOCALBASE}/bin/pg_config)
214 _PGSQL_VER!= ${LOCALBASE}/bin/pg_config --version | ${SED} -n 's/PostgreSQL[^0-9]*\([0-9][0-9]*\)\.\([0-9][0-9]*\)[^0-9].*/\1\2/p'
215 WITH_PGSQL_VER?= ${_PGSQL_VER}
216 . if ${WITH_PGSQL_VER} != ${_PGSQL_VER}
217 IGNORE?= cannot install: you have set WITH_PGSQL_VER=${WITH_PGSQL_VER} in make.conf, but you have postgresql${_PGSQL_VER}-client installed
221 . if defined(WANT_PGSQL_VER)
222 . if ${WANT_PGSQL_VER:M*+}
223 . for version in ${VALID_PGSQL_VER}
224 . if ${WANT_PGSQL_VER:S/+//} <= ${version}
225 _WANT_PGSQL_VER+=${version}
228 . elif ${WANT_PGSQL_VER:M*-}
229 . for version in ${VALID_PGSQL_VER}
230 . if ${WANT_PGSQL_VER:S/-//} >= ${version}
231 _WANT_PGSQL_VER+=${version}
235 _WANT_PGSQL_VER?= ${WANT_PGSQL_VER}
238 . if !empty(_WANT_PGSQL_VER)
239 . for version in ${_WANT_PGSQL_VER}
240 . if defined(WITH_PGSQL_VER)
241 . if ${WITH_PGSQL_VER} == ${version}
242 PGSQL_VER= ${WITH_PGSQL_VER}
244 . elif ${DEFAULT_PGSQL_VER} == ${version}
245 PGSQL_VER= ${version}
247 PGSQL_VER?= ${version}
249 . if defined(WITH_PGSQL_VER) && ${WITH_PGSQL_VER} != ${PGSQL_VER}
250 IGNORE?= cannot install: the port wants postgresql-client version ${WANT_PGSQL_VER} and you have version ${WITH_PGSQL_VER} installed or set in make.conf
254 .if !empty(WITH_PGSQL_VER)
255 PGSQL_VER?= ${WITH_PGSQL_VER}
257 PGSQL_VER?= ${DEFAULT_PGSQL_VER}
260 # And now we are checking if we can use it
261 .if defined(PGSQL${PGSQL_VER}_LIBVER)
262 .if defined(IGNORE_WITH_PGSQL)
263 . for ver in ${IGNORE_WITH_PGSQL}
264 . if (${PGSQL_VER} == ${ver})
265 IGNORE?= cannot install: does not work with postgresql${PGSQL_VER}-client (PostgresSQL ${IGNORE_WITH_PGSQL} not supported)
268 .endif # IGNORE_WITH_PGSQL
270 LIB_DEPENDS+= libpq.so.${PGSQL${PGSQL_VER}_LIBVER}:${PORTSDIR}/databases/postgresql${PGSQL_VER}-client
272 _USE_PGSQL_DEP= contrib docs pgtcl pltcl plperl server
273 _USE_PGSQL_DEP_contrib= pgbench
274 _USE_PGSQL_DEP_docs= postgresql${PGSQL_VER}-docs>0
275 _USE_PGSQL_DEP_pgtcl= ${LOCALBASE}/lib/pgtcl/pkgIndex.tcl
276 _USE_PGSQL_DEP_plperl= postgresql${PGSQL_VER}-plperl>0
277 _USE_PGSQL_DEP_pltcl= postgresql${PGSQL_VER}-pltcl>0
278 _USE_PGSQL_DEP_server= postgres
279 . for depend in ${_USE_PGSQL_DEP}
280 . if ${USE_PGSQL:M${depend}}
281 BUILD_DEPENDS+= ${_USE_PGSQL_DEP_${depend}}:${PORTSDIR}/databases/postgresql${PGSQL_VER}-${depend}
282 RUN_DEPENDS+= ${_USE_PGSQL_DEP_${depend}}:${PORTSDIR}/databases/postgresql${PGSQL_VER}-${depend}
283 . elif ${USE_PGSQL:M${depend}\:*}
284 BUILD_DEPENDS+= ${NONEXISTENT}:${PORTSDIR}/databases/postgresql${PGSQL_VER}-${depend}:${USE_PGSQL:M${depend}\:*:C,^[^:]*\:,,}
289 IGNORE?= cannot install: unknown PostgreSQL version: ${PGSQL_VER}
290 .endif # Check for correct version
291 CPPFLAGS+= -I${LOCALBASE}/include
292 LDFLAGS+= -L${LOCALBASE}/lib
297 _DB_PORTS= 40 41 42 43 44 46 47 48 5 6 40+ 41+ 42+ 43+ 44+ 46+ 47+ 48+ 5+ 6+
298 # Dependence lines for different db versions
299 db40_DEPENDS= libdb4.so:${PORTSDIR}/databases/db4
300 db41_DEPENDS= libdb41.so:${PORTSDIR}/databases/db41
301 db42_DEPENDS= libdb-4.2.so:${PORTSDIR}/databases/db42
302 db43_DEPENDS= libdb-4.3.so:${PORTSDIR}/databases/db43
303 db44_DEPENDS= libdb-4.4.so:${PORTSDIR}/databases/db44
304 db46_DEPENDS= libdb-4.6.so:${PORTSDIR}/databases/db46
305 db47_DEPENDS= libdb-4.7.so:${PORTSDIR}/databases/db47
306 db48_DEPENDS= libdb-4.8.so:${PORTSDIR}/databases/db48
307 db5_DEPENDS= libdb-5.3.so:${PORTSDIR}/databases/db5
308 db6_DEPENDS= libdb-6.0.so:${PORTSDIR}/databases/db6
309 # Detect db versions by finding some files
310 db40_FIND= ${LOCALBASE}/include/db4/db.h
311 db41_FIND= ${LOCALBASE}/include/db41/db.h
312 db42_FIND= ${LOCALBASE}/include/db42/db.h
313 db43_FIND= ${LOCALBASE}/include/db43/db.h
314 db44_FIND= ${LOCALBASE}/include/db44/db.h
315 db46_FIND= ${LOCALBASE}/include/db46/db.h
316 db47_FIND= ${LOCALBASE}/include/db47/db.h
317 db48_FIND= ${LOCALBASE}/include/db48/db.h
318 db5_FIND= ${LOCALBASE}/include/db5/db.h
319 db6_FIND= ${LOCALBASE}/include/db6/db.h
321 # For specifying [40, 41, ..]+
322 _DB_40P= 40 ${_DB_41P}
323 _DB_41P= 41 ${_DB_42P}
324 _DB_42P= 42 ${_DB_43P}
325 _DB_43P= 43 ${_DB_44P}
326 _DB_44P= 44 ${_DB_46P}
327 _DB_46P= 46 ${_DB_47P}
328 _DB_47P= 47 ${_DB_48P}
329 _DB_48P= 48 ${_DB_5P}
333 # Override the global WITH_BDB_VER with the
334 # port specific <UNIQUENAME>_WITH_BDB_VER
335 .if defined(${UNIQUENAME:tu:S,-,_,}_WITH_BDB_VER)
336 WITH_BDB_VER= ${${UNIQUENAME:tu:S,-,_,}_WITH_BDB_VER}
339 .if defined(WITH_BDB_VER)
340 . if ${WITH_BDB_VER} == 4
342 . elif ${WITH_BDB_VER} != 1
343 USE_BDB= ${WITH_BDB_VER}
346 _WANT_BDB_VER= ${USE_BDB}
348 # Assume the default bdb version as 48
349 .if ${USE_BDB:tl} == "yes"
357 # Override the user defined WITH_BDB_VER with the WANT_BDB_VER
358 .if defined(WANT_BDB_VER)
359 .for bdb in ${_DB_PORTS}
360 .if ${WANT_BDB_VER} == "${bdb}" && ${_BDB_VER} == "no"
361 _BDB_VER= ${WANT_BDB_VER}
364 USE_BDB= ${WANT_BDB_VER}
366 .for bdb in ${_DB_PORTS}
367 .if ${_WANT_BDB_VER} == "${bdb}" && ${_BDB_VER} == "no"
368 _MATCHED_DB_VER:= ${bdb:S/+//}
369 . if ${_MATCHED_DB_VER} == "${bdb}"
370 # USE_BDB is exactly specified
373 # USE_BDB is specified as VER+
374 . for dbx in ${_DB_${_MATCHED_DB_VER}P}
375 . if exists(${db${dbx}_FIND})
377 # Skip versions we are incompatible with
378 . if defined(INVALID_BDB_VER)
380 . for BRKDB in ${INVALID_BDB_VER}
381 . if ${_CHK_BDB} == "${BRKDB}"
387 . if defined(WITH_BDB_HIGHEST)
388 # Use the highest version of Berkeley DB found
390 . elif ${_BDB_VER} == no
391 # Use the first Berkeley DB found
397 . if ${_BDB_VER} == "no"
398 # No existing db4 version is detected in system, use the default
406 # USE_BDB is specified incorrectly, so mark this as IGNORE
407 .if ${_BDB_VER} == "no"
408 IGNORE= cannot install: unknown Berkeley DB version: ${USE_BDB}
410 # Now check if we can use it
411 . if defined(INVALID_BDB_VER)
412 . for VER in ${INVALID_BDB_VER}
413 _CHK_PLUS:= ${VER:S/+//}
414 # INVALID_BDB_VER is specified as VER+
415 . if ${_CHK_PLUS} != "${VER}"
416 . if ${_BDB_VER} == "${_CHK_PLUS}"
419 . for VER_P in ${_DB_${_CHK_PLUS}P}
420 . if ${_BDB_VER} == "${VER_P}"
425 . elif ${_BDB_VER} == "${VER}"
430 . if ${_BDB_IGNORE} == "yes"
431 IGNORE= cannot install: does not work with Berkeley DB version ${_BDB_VER} (${INVALID_BDB_VER} not supported)
433 # Now add the dependency on Berkeley DB ${_BDB_VER) version
434 # This is for ports that want to link Berkeley DB statically, such
435 # as devel/subversion, if the corresponding option is active:
436 .if defined(BDB_BUILD_DEPENDS)
437 BUILD_DEPENDS+= ${db${_BDB_VER}_FIND}:${db${_BDB_VER}_DEPENDS:C/^libdb.*://}
439 LIB_DEPENDS+= ${db${_BDB_VER}_DEPENDS}
441 . if ${_BDB_VER} == 40
443 BDB_LIB_CXX_NAME= db4_cxx
444 BDB_INCLUDE_DIR= ${LOCALBASE}/include/db4
445 . elif ${_BDB_VER} == 42
447 BDB_LIB_CXX_NAME= db_cxx-4.2
448 BDB_LIB_DIR= ${LOCALBASE}/lib/db42
449 . elif ${_BDB_VER} == 43
451 BDB_LIB_CXX_NAME= db_cxx-4.3
452 BDB_LIB_DIR= ${LOCALBASE}/lib/db43
453 . elif ${_BDB_VER} == 44
455 BDB_LIB_CXX_NAME= db_cxx-4.4
456 BDB_LIB_DIR= ${LOCALBASE}/lib/db44
457 . elif ${_BDB_VER} == 46
459 BDB_LIB_CXX_NAME= db_cxx-4.6
460 BDB_LIB_DIR= ${LOCALBASE}/lib/db46
461 . elif ${_BDB_VER} == 47
463 BDB_LIB_CXX_NAME= db_cxx-4.7
464 BDB_LIB_DIR= ${LOCALBASE}/lib/db47
465 . elif ${_BDB_VER} == 48
467 BDB_LIB_CXX_NAME= db_cxx-4.8
468 BDB_LIB_DIR= ${LOCALBASE}/lib/db48
469 . elif ${_BDB_VER} == 5
471 BDB_LIB_CXX_NAME= db_cxx-5.3
472 BDB_LIB_DIR= ${LOCALBASE}/lib/db5
473 . elif ${_BDB_VER} == 6
475 BDB_LIB_CXX_NAME= db_cxx-6.0
476 BDB_LIB_DIR= ${LOCALBASE}/lib/db6
478 BDB_LIB_NAME?= db${_BDB_VER}
479 BDB_LIB_CXX_NAME?= db${_BDB_VER}_cxx
480 BDB_INCLUDE_DIR?= ${LOCALBASE}/include/db${_BDB_VER}
481 BDB_LIB_DIR?= ${LOCALBASE}/lib
486 # Obsolete variables - ports can define these to want users about
487 # variables that may be in /etc/make.conf but that are no longer
489 .if defined(OBSOLETE_BDB_VAR)
490 . for var in ${OBSOLETE_BDB_VAR}
495 . if defined(BAD_VAR)
496 _IGNORE_MSG= Obsolete variable(s) ${BAD_VAR} use WITH_BDB_VER or ${UNIQUENAME:tu:S,-,_,}_WITH_BDB_VER to select Berkeley DB version
498 IGNORE+= ${_IGNORE_MSG}
500 IGNORE= ${_IGNORE_MSG}
507 # Handling SQLite dependency
508 .if defined(USE_SQLITE)
510 .if ${USE_SQLITE:tl} == "yes"
513 _SQLITE_VER= ${USE_SQLITE}
516 # USE_SQLITE is specified incorrectly, so mark this as IGNORE
517 .if ${_SQLITE_VER} == "3"
518 LIB_DEPENDS+= libsqlite3.so:${PORTSDIR}/databases/sqlite${_SQLITE_VER}
519 SQLITE_VER= ${_SQLITE_VER}
520 .elif ${_SQLITE_VER} == "2"
521 LIB_DEPENDS+= libsqlite.so:${PORTSDIR}/databases/sqlite${_SQLITE_VER}
522 SQLITE_VER= ${_SQLITE_VER}
524 IGNORE= cannot install: unknown SQLite version: ${_SQLITE_VER}
527 .endif # defined(USE_SQLITE)
529 .if defined(USE_FIREBIRD)
531 .if defined(WITH_FIREBIRD_VER)
532 USE_FIREBIRD= ${WITH_FIREBIRD_VER}
535 .if ${USE_FIREBIRD:tl} == "yes"
536 FIREBIRD_VER= ${FIREBIRD_DEFAULT:S/.//}
538 FIREBIRD_VER= ${USE_FIREBIRD}
541 .if ${FIREBIRD_VER} == "21"
542 LIB_DEPENDS+= libfbclient.so:${PORTSDIR}/databases/firebird21-client
543 .elif ${FIREBIRD_VER} == "25"
544 LIB_DEPENDS+= libfbclient.so:${PORTSDIR}/databases/firebird25-client
546 IGNORE= cannot install: unknown Firebird version: ${FIREBIRD_VER}
549 .endif # defined(USE_FIREBIRD)
551 .endif # defined(_POSTMKINCLUDED) && !defined(Database_Post_Include)