Sync Mk with ports
[dports.git] / Mk / Uses / pgsql.mk
1 # $FreeBSD$
2 #
3 # Provide support for PostgreSQL (pgsql)
4 #
5 # Feature:      pgsql
6 # Usage:        USES=           pgsql[:version]
7 #
8 #               Maintainer can set version required.  Minimum and maximum
9 #               versions can be specified; e.g. 9.0-, 9.2+
10 #
11 #               WANT_PGSQL=     server[:fetch] pltcl plperl
12 #
13 #               Add PostgreSQL component dependency, using
14 #               WANT_PGSQL=     component[:target].
15 #               For the full list use make -V _USE_PGSQL_DEP
16 #               If no version is given (by the maintainer via the port or
17 #               by the user via defined variable), try to find the
18 #               currently installed version.  Fall back to default if
19 #               necessary.
20 #
21 # MAINTAINER: pgsql@FreeBSD.org
22
23 .if !defined(_INCLUDE_USES_PGSQL_MK)
24
25 _INCLUDE_USES_PGSQL_MK= yes
26
27 # Variables set by pgsql.mk:
28 #
29 # PGSQL_VER
30 #       Detected PostgreSQL version.  Do *not* use this
31 #       to add dependencies; use WANT_PGSQL as explained above
32 #
33
34 # When adding a version, please keep the comment in
35 # Mk/bsd.default-versions.mk in sync.
36 VALID_PGSQL_VER=        9.1 9.2 9.3 9.4 9.5
37
38 # Override non-default LIBVERS like this:
39 #PGSQL99_LIBVER=6
40
41 PGSQL_LIBVER=   5
42 .for v in ${VALID_PGSQL_VER:S,.,,}
43 PGSQL$v_LIBVER?=        ${PGSQL_LIBVER}
44 .endfor
45
46 .for v in ${PGSQL_DEFAULT}
47 .  if ! ${VALID_PGSQL_VER:M$v}
48 IGNORE=         Invalid PGSQL default version ${PGSQL_DEFAULT}; valid versions are ${VALID_PGSQL_VER}
49 .  endif
50 .endfor
51
52 .  for w in WITH DEFAULT
53 .    ifdef $w_PGSQL_VER
54 WARNING+=       "$w_PGSQL_VER is defined, consider using DEFAULT_VERSIONS=pgsql=${$w_PGSQL_VER:C,^.,&.,} instead"
55 PGSQL_DEFAULT?= ${$w_PGSQL_VER:C,^.,&.,}
56 .    endif
57 .  endfor
58
59 .  ifdef DEFAULT_PGSQL_VER && WITH_PGSQL_VER
60 IGNORE=         will not allow setting both DEFAULT_PGSQL_VER and WITH_PGSQL_VER.  Use DEFAULT_VERSIONS=pgsql=9.0 instead
61 .  endif
62
63 # Setting/finding PostgreSQL version we want.
64 PG_CONFIG?=     ${LOCALBASE}/bin/pg_config
65 .  if exists(${PG_CONFIG})
66 _PGSQL_VER!=    ${PG_CONFIG} --version | ${SED} -n 's/PostgreSQL[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\)[^0-9].*/\1/p'
67 .  endif
68
69 # Handle the + and - version stuff
70 .  if !empty(pgsql_ARGS)
71 .    if ${pgsql_ARGS:M*+}
72 .      for version in ${VALID_PGSQL_VER}
73 .        if ${pgsql_ARGS:S/+//} <= ${version}
74 _WANT_PGSQL_VER+=${version}
75 .        endif
76 .      endfor
77 .    elif ${pgsql_ARGS:M*-}
78 .      for version in ${VALID_PGSQL_VER}
79 .        if ${pgsql_ARGS:S/-//} >= ${version}
80 _WANT_PGSQL_VER+=${version}
81 .        endif
82 .      endfor
83 .    endif
84 _WANT_PGSQL_VER?=       ${pgsql_ARGS}
85 .  endif
86
87 # Try to match default version, otherwise just take the first version
88 # that matches. Prefer the installed version if it matches
89 .  if !empty(_WANT_PGSQL_VER)
90 .    for version in ${_WANT_PGSQL_VER}
91 .      if ${PGSQL_DEFAULT} == ${version}
92 PGSQL_VER=      ${version}
93 .      endif
94 PGSQL_VER?=     ${version}
95 .    endfor
96 .    if defined(_PGSQL_VER)
97 .      for v in ${_PGSQL_VER}
98 .        if ${_WANT_PGSQL_VER:M$v} == ${_PGSQL_VER}
99 PGSQL_VER=      ${_PGSQL_VER}
100 .        endif
101 .      endfor
102 .    endif
103 .    if defined(_PGSQL_VER) && ${_PGSQL_VER} != ${PGSQL_VER}
104 IGNORE?=        cannot install: the port wants postgresql-client version ${_WANT_PGSQL_VER} and you have version ${_PGSQL_VER} installed
105 .    endif
106 .  endif
107
108 # OK, so the port is ambivalent, we'll just take what's on the system.
109 PGSQL_VER?=     ${_PGSQL_VER}
110
111 # After all that, we still have found nothing!
112 .  if empty(PGSQL_VER)
113 PGSQL_VER=      ${PGSQL_DEFAULT}
114 .  endif
115
116 # We don't want to be :S,.,, the whole time when doing port version checks
117 PGSQL_VER_NODOT=        ${PGSQL_VER:S,.,,}
118
119 # And now we are checking if we can use it
120 .   if defined(PGSQL${PGSQL_VER_NODOT}_LIBVER)
121 # Compat.  Please DO NOT use IGNORE_WITH_PGSQL!
122 .    if defined(IGNORE_WITH_PGSQL)
123 DEV_WARNING+=   "Do not set IGNORE_WITH_PGSQL, use the version argument to USES=pgsql"
124 .       for ver in ${IGNORE_WITH_PGSQL}
125 .               if (${PGSQL_VER} == ${ver})
126 IGNORE?=                cannot install: does not work with postgresql${PGSQL_VER_NODOT}-client (PostgreSQL ${IGNORE_WITH_PGSQL} not supported)
127 .               endif
128 .       endfor
129 .    endif # IGNORE_WITH_PGSQL
130
131 .if !defined(WANT_PGSQL) || ${WANT_PGSQL:Mlib}
132 LIB_DEPENDS+=   libpq.so.${PGSQL${PGSQL_VER_NODOT}_LIBVER}:databases/postgresql${PGSQL_VER_NODOT}-client
133 .endif
134
135 _USE_PGSQL_DEP=         client contrib docs pgtcl pltcl plperl server
136 _USE_PGSQL_DEP_client=  psql
137 _USE_PGSQL_DEP_contrib= vacuumlo
138 _USE_PGSQL_DEP_docs=    postgresql${PGSQL_VER_NODOT}-docs>0
139 _USE_PGSQL_DEP_pgtcl=   ${LOCALBASE}/lib/pgtcl/pkgIndex.tcl
140 _USE_PGSQL_DEP_plperl=  postgresql${PGSQL_VER_NODOT}-plperl>0
141 _USE_PGSQL_DEP_pltcl=   postgresql${PGSQL_VER_NODOT}-pltcl>0
142 _USE_PGSQL_DEP_server=  postgres
143 .    if defined(WANT_PGSQL)
144 .      for depend in ${_USE_PGSQL_DEP}
145 .        if ${WANT_PGSQL:M${depend}}
146 BUILD_DEPENDS+= ${_USE_PGSQL_DEP_${depend}}:databases/postgresql${PGSQL_VER_NODOT}-${depend}
147 RUN_DEPENDS+=   ${_USE_PGSQL_DEP_${depend}}:databases/postgresql${PGSQL_VER_NODOT}-${depend}
148 .        elif ${WANT_PGSQL:M${depend}\:*}
149 BUILD_DEPENDS+= ${NONEXISTENT}:databases/postgresql${PGSQL_VER_NODOT}-${depend}:${WANT_PGSQL:M${depend}\:*:C,^[^:]*\:,,}
150 .        endif
151 .      endfor
152 .    endif
153
154 .  else
155 IGNORE?=                cannot install: unknown PostgreSQL version: ${PGSQL_VER}
156 .  endif # Check for correct version
157 CPPFLAGS+=              -I${LOCALBASE}/include
158 LDFLAGS+=               -L${LOCALBASE}/lib
159
160 .endif # !defined(_INCLUDE_USES_PGSQL_MK)