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+= mysqlclient.${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
203 DEFAULT_PGSQL_VER?= ${PGSQL_DEFAULT:S/.//}
211 # Setting/finding PostgreSQL version we want.
212 . if exists(${LOCALBASE}/bin/pg_config)
213 _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'
214 WITH_PGSQL_VER?= ${_PGSQL_VER}
215 . if ${WITH_PGSQL_VER} != ${_PGSQL_VER}
216 IGNORE?= cannot install: you have set WITH_PGSQL_VER=${WITH_PGSQL_VER} in make.conf, but you have postgresql${_PGSQL_VER}-client installed
220 . if defined(WANT_PGSQL_VER)
221 . if ${WANT_PGSQL_VER:M*+}
222 . for version in ${VALID_PGSQL_VER}
223 . if ${WANT_PGSQL_VER:S/+//} <= ${version}
224 _WANT_PGSQL_VER+=${version}
227 . elif ${WANT_PGSQL_VER:M*-}
228 . for version in ${VALID_PGSQL_VER}
229 . if ${WANT_PGSQL_VER:S/-//} >= ${version}
230 _WANT_PGSQL_VER+=${version}
234 _WANT_PGSQL_VER?= ${WANT_PGSQL_VER}
237 . if !empty(_WANT_PGSQL_VER)
238 . for version in ${_WANT_PGSQL_VER}
239 . if defined(WITH_PGSQL_VER)
240 . if ${WITH_PGSQL_VER} == ${version}
241 PGSQL_VER= ${WITH_PGSQL_VER}
243 . elif ${DEFAULT_PGSQL_VER} == ${version}
244 PGSQL_VER= ${version}
246 PGSQL_VER?= ${version}
248 . if defined(WITH_PGSQL_VER) && ${WITH_PGSQL_VER} != ${PGSQL_VER}
249 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
253 .if !empty(WITH_PGSQL_VER)
254 PGSQL_VER?= ${WITH_PGSQL_VER}
256 PGSQL_VER?= ${DEFAULT_PGSQL_VER}
259 # And now we are checking if we can use it
260 .if defined(PGSQL${PGSQL_VER}_LIBVER)
261 .if defined(IGNORE_WITH_PGSQL)
262 . for ver in ${IGNORE_WITH_PGSQL}
263 . if (${PGSQL_VER} == ${ver})
264 IGNORE?= cannot install: does not work with postgresql${PGSQL_VER}-client (PostgresSQL ${IGNORE_WITH_PGSQL} not supported)
267 .endif # IGNORE_WITH_PGSQL
269 LIB_DEPENDS+= pq.${PGSQL${PGSQL_VER}_LIBVER}:${PORTSDIR}/databases/postgresql${PGSQL_VER}-client
271 _USE_PGSQL_DEP= contrib docs pgtcl pltcl plperl server
272 _USE_PGSQL_DEP_contrib= pgbench
273 _USE_PGSQL_DEP_docs= postgresql${PGSQL_VER}-docs>0
274 _USE_PGSQL_DEP_pgtcl= ${LOCALBASE}/lib/pgtcl/pkgIndex.tcl
275 _USE_PGSQL_DEP_plperl= postgresql${PGSQL_VER}-plperl>0
276 _USE_PGSQL_DEP_pltcl= postgresql${PGSQL_VER}-pltcl>0
277 _USE_PGSQL_DEP_server= postgres
278 . for depend in ${_USE_PGSQL_DEP}
279 . if ${USE_PGSQL:M${depend}}
280 BUILD_DEPENDS+= ${_USE_PGSQL_DEP_${depend}}:${PORTSDIR}/databases/postgresql${PGSQL_VER}-${depend}
281 RUN_DEPENDS+= ${_USE_PGSQL_DEP_${depend}}:${PORTSDIR}/databases/postgresql${PGSQL_VER}-${depend}
282 . elif ${USE_PGSQL:M${depend}\:*}
283 BUILD_DEPENDS+= ${NONEXISTENT}:${PORTSDIR}/databases/postgresql${PGSQL_VER}-${depend}:${USE_PGSQL:M${depend}\:*:C,^[^:]*\:,,}
288 IGNORE?= cannot install: unknown PostgreSQL version: ${PGSQL_VER}
289 .endif # Check for correct version
290 CPPFLAGS+= -I${LOCALBASE}/include
291 LDFLAGS+= -L${LOCALBASE}/lib
296 _DB_PORTS= 40 41 42 43 44 46 47 48 5 6 40+ 41+ 42+ 43+ 44+ 46+ 47+ 48+ 5+ 6+
297 # Dependence lines for different db versions
298 db40_DEPENDS= libdb4.so:${PORTSDIR}/databases/db4
299 db41_DEPENDS= libdb41.so:${PORTSDIR}/databases/db41
300 db42_DEPENDS= libdb-4.2.so:${PORTSDIR}/databases/db42
301 db43_DEPENDS= libdb-4.3.so:${PORTSDIR}/databases/db43
302 db44_DEPENDS= libdb-4.4.so:${PORTSDIR}/databases/db44
303 db46_DEPENDS= libdb-4.6.so:${PORTSDIR}/databases/db46
304 db47_DEPENDS= libdb-4.7.so:${PORTSDIR}/databases/db47
305 db48_DEPENDS= libdb-4.8.so:${PORTSDIR}/databases/db48
306 db5_DEPENDS= libdb-5.3.so:${PORTSDIR}/databases/db5
307 db6_DEPENDS= libdb-6.0.so:${PORTSDIR}/databases/db6
308 # Detect db versions by finding some files
309 db40_FIND= ${LOCALBASE}/include/db4/db.h
310 db41_FIND= ${LOCALBASE}/include/db41/db.h
311 db42_FIND= ${LOCALBASE}/include/db42/db.h
312 db43_FIND= ${LOCALBASE}/include/db43/db.h
313 db44_FIND= ${LOCALBASE}/include/db44/db.h
314 db46_FIND= ${LOCALBASE}/include/db46/db.h
315 db47_FIND= ${LOCALBASE}/include/db47/db.h
316 db48_FIND= ${LOCALBASE}/include/db48/db.h
317 db5_FIND= ${LOCALBASE}/include/db5/db.h
318 db6_FIND= ${LOCALBASE}/include/db6/db.h
320 # For specifying [40, 41, ..]+
321 _DB_40P= 40 ${_DB_41P}
322 _DB_41P= 41 ${_DB_42P}
323 _DB_42P= 42 ${_DB_43P}
324 _DB_43P= 43 ${_DB_44P}
325 _DB_44P= 44 ${_DB_46P}
326 _DB_46P= 46 ${_DB_47P}
327 _DB_47P= 47 ${_DB_48P}
328 _DB_48P= 48 ${_DB_5P}
332 # Override the global WITH_BDB_VER with the
333 # port specific <UNIQUENAME>_WITH_BDB_VER
334 .if defined(${UNIQUENAME:tu:S,-,_,}_WITH_BDB_VER)
335 WITH_BDB_VER= ${${UNIQUENAME:tu:S,-,_,}_WITH_BDB_VER}
338 .if defined(WITH_BDB_VER)
339 . if ${WITH_BDB_VER} == 4
341 . elif ${WITH_BDB_VER} != 1
342 USE_BDB= ${WITH_BDB_VER}
345 _WANT_BDB_VER= ${USE_BDB}
347 # Assume the default bdb version as 48
348 .if ${USE_BDB:tl} == "yes"
356 # Override the user defined WITH_BDB_VER with the WANT_BDB_VER
357 .if defined(WANT_BDB_VER)
358 .for bdb in ${_DB_PORTS}
359 .if ${WANT_BDB_VER} == "${bdb}" && ${_BDB_VER} == "no"
360 _BDB_VER= ${WANT_BDB_VER}
363 USE_BDB= ${WANT_BDB_VER}
365 .for bdb in ${_DB_PORTS}
366 .if ${_WANT_BDB_VER} == "${bdb}" && ${_BDB_VER} == "no"
367 _MATCHED_DB_VER:= ${bdb:S/+//}
368 . if ${_MATCHED_DB_VER} == "${bdb}"
369 # USE_BDB is exactly specified
372 # USE_BDB is specified as VER+
373 . for dbx in ${_DB_${_MATCHED_DB_VER}P}
374 . if exists(${db${dbx}_FIND})
376 # Skip versions we are incompatible with
377 . if defined(INVALID_BDB_VER)
379 . for BRKDB in ${INVALID_BDB_VER}
380 . if ${_CHK_BDB} == "${BRKDB}"
386 . if defined(WITH_BDB_HIGHEST)
387 # Use the highest version of Berkeley DB found
389 . elif ${_BDB_VER} == no
390 # Use the first Berkeley DB found
396 . if ${_BDB_VER} == "no"
397 # No existing db4 version is detected in system, use the default
405 # USE_BDB is specified incorrectly, so mark this as IGNORE
406 .if ${_BDB_VER} == "no"
407 IGNORE= cannot install: unknown Berkeley DB version: ${USE_BDB}
409 # Now check if we can use it
410 . if defined(INVALID_BDB_VER)
411 . for VER in ${INVALID_BDB_VER}
412 _CHK_PLUS:= ${VER:S/+//}
413 # INVALID_BDB_VER is specified as VER+
414 . if ${_CHK_PLUS} != "${VER}"
415 . if ${_BDB_VER} == "${_CHK_PLUS}"
418 . for VER_P in ${_DB_${_CHK_PLUS}P}
419 . if ${_BDB_VER} == "${VER_P}"
424 . elif ${_BDB_VER} == "${VER}"
429 . if ${_BDB_IGNORE} == "yes"
430 IGNORE= cannot install: does not work with Berkeley DB version ${_BDB_VER} (${INVALID_BDB_VER} not supported)
432 # Now add the dependency on Berkeley DB ${_BDB_VER) version
433 # This is for ports that want to link Berkeley DB statically, such
434 # as devel/subversion, if the corresponding option is active:
435 .if defined(BDB_BUILD_DEPENDS)
436 BUILD_DEPENDS+= ${db${_BDB_VER}_FIND}:${db${_BDB_VER}_DEPENDS:C/^libdb.*://}
438 LIB_DEPENDS+= ${db${_BDB_VER}_DEPENDS}
440 . if ${_BDB_VER} == 40
442 BDB_LIB_CXX_NAME= db4_cxx
443 BDB_INCLUDE_DIR= ${LOCALBASE}/include/db4
444 . elif ${_BDB_VER} == 42
446 BDB_LIB_CXX_NAME= db_cxx-4.2
447 BDB_LIB_DIR= ${LOCALBASE}/lib/db42
448 . elif ${_BDB_VER} == 43
450 BDB_LIB_CXX_NAME= db_cxx-4.3
451 BDB_LIB_DIR= ${LOCALBASE}/lib/db43
452 . elif ${_BDB_VER} == 44
454 BDB_LIB_CXX_NAME= db_cxx-4.4
455 BDB_LIB_DIR= ${LOCALBASE}/lib/db44
456 . elif ${_BDB_VER} == 46
458 BDB_LIB_CXX_NAME= db_cxx-4.6
459 BDB_LIB_DIR= ${LOCALBASE}/lib/db46
460 . elif ${_BDB_VER} == 47
462 BDB_LIB_CXX_NAME= db_cxx-4.7
463 BDB_LIB_DIR= ${LOCALBASE}/lib/db47
464 . elif ${_BDB_VER} == 48
466 BDB_LIB_CXX_NAME= db_cxx-4.8
467 BDB_LIB_DIR= ${LOCALBASE}/lib/db48
468 . elif ${_BDB_VER} == 5
470 BDB_LIB_CXX_NAME= db_cxx-5.3
471 BDB_LIB_DIR= ${LOCALBASE}/lib/db5
472 . elif ${_BDB_VER} == 6
474 BDB_LIB_CXX_NAME= db_cxx-6.0
475 BDB_LIB_DIR= ${LOCALBASE}/lib/db6
477 BDB_LIB_NAME?= db${_BDB_VER}
478 BDB_LIB_CXX_NAME?= db${_BDB_VER}_cxx
479 BDB_INCLUDE_DIR?= ${LOCALBASE}/include/db${_BDB_VER}
480 BDB_LIB_DIR?= ${LOCALBASE}/lib
485 # Obsolete variables - ports can define these to want users about
486 # variables that may be in /etc/make.conf but that are no longer
488 .if defined(OBSOLETE_BDB_VAR)
489 . for var in ${OBSOLETE_BDB_VAR}
494 . if defined(BAD_VAR)
495 _IGNORE_MSG= Obsolete variable(s) ${BAD_VAR} use WITH_BDB_VER or ${UNIQUENAME:tu:S,-,_,}_WITH_BDB_VER to select Berkeley DB version
497 IGNORE+= ${_IGNORE_MSG}
499 IGNORE= ${_IGNORE_MSG}
506 # Handling SQLite dependency
507 .if defined(USE_SQLITE)
509 .if ${USE_SQLITE:tl} == "yes"
512 _SQLITE_VER= ${USE_SQLITE}
515 # USE_SQLITE is specified incorrectly, so mark this as IGNORE
516 .if ${_SQLITE_VER} == "3"
517 LIB_DEPENDS+= libsqlite3.so:${PORTSDIR}/databases/sqlite${_SQLITE_VER}
518 SQLITE_VER= ${_SQLITE_VER}
519 .elif ${_SQLITE_VER} == "2"
520 LIB_DEPENDS+= libsqlite.so:${PORTSDIR}/databases/sqlite${_SQLITE_VER}
521 SQLITE_VER= ${_SQLITE_VER}
523 IGNORE= cannot install: unknown SQLite version: ${_SQLITE_VER}
526 .endif # defined(USE_SQLITE)
528 .if defined(USE_FIREBIRD)
530 .if defined(WITH_FIREBIRD_VER)
531 USE_FIREBIRD= ${WITH_FIREBIRD_VER}
534 .if ${USE_FIREBIRD:tl} == "yes"
537 FIREBIRD_VER= ${USE_FIREBIRD}
540 .if ${FIREBIRD_VER} == "2"
541 LIB_DEPENDS+= fbclient.2:${PORTSDIR}/databases/firebird20-client
542 .elif ${FIREBIRD_VER} == "20"
543 LIB_DEPENDS+= fbclient.2:${PORTSDIR}/databases/firebird20-client
544 .elif ${FIREBIRD_VER} == "21"
545 LIB_DEPENDS+= fbclient.2:${PORTSDIR}/databases/firebird21-client
546 .elif ${FIREBIRD_VER} == "25"
547 LIB_DEPENDS+= fbclient.2:${PORTSDIR}/databases/firebird25-client
549 IGNORE= cannot install: unknown Firebird version: ${FIREBIRD_VER}
552 .endif # defined(USE_FIREBIRD)
554 .endif # defined(_POSTMKINCLUDED) && !defined(Database_Post_Include)