Sync Mk with ports
[dports.git] / Mk / bsd.wx.mk
1 # bsd.wx.mk - Support for wxWidgets based ports.
2 #
3 # Created by: Alejandro Pulver <alepulver@FreeBSD.org>
4 #
5 # The following variables can be defined in a port that uses the wxWidgets
6 # library, contributed libraries, WxPython and/or more wxWidgets related
7 # components (with run and/or build dependencies). It can be used after and/or
8 # before bsd.port.pre.mk, but Python components will only work if Python
9 # variables (e.g. USE_PYTHON) are defined before it (this is a bsd.python.mk
10 # limitation), at least it is manually included.
11 #
12 # USE_WX        - Set to the list of wxWidgets versions that can be used by
13 #                 the port. The syntax allows the following elements:
14 #                 - Single version (e.g. "3.0").
15 #                 - Range of versions (e.g. "2.8-3.0"). Must be ascending.
16 #                 - Partial range: single version and upper (e.g. "2.8+").
17 #                 - Partial range: single version and lower (e.g. "-2.8").
18 #                 Multiple elements can be specified separated by spaces.
19 # USE_WX_NOT    - Set to the list of wxWidgets versions that can't be used by
20 #                 the port. In other words, it removes some versions from
21 #                 USE_WX. If the latter is not defined, it will have the value
22 #                 of all the possible versions. The syntax is like USE_WX.
23 # WX_COMPS      - Set to the list of wxWidgets components the port uses.
24 #                 Several components can be specified separated by spaces. By
25 #                 default it will have the value of "wx". Suffixes in the form
26 #                 ":xxx" may be added to the components to determine the
27 #                 dependency type.
28 #                 The available components are:
29 #                 wx            - The wxWidgets library.
30 #                 contrib       - The wxWidgets contributed libraries.
31 #                 python        - The wxWidgets API for Python.
32 #                 The available dependency types are:
33 #                 build         - Requires component for building.
34 #                 lib           - Requires component for building and running.
35 #                 run           - Requires component for running.
36 #                 If no suffix is present then "run" will be used for "python"
37 #                 and "lib" for others.
38 # WX_CONF_ARGS  - Set to "absolute" or "relative" if the port needs configure
39 #                 arguments in addition to the WX_CONFIG environment variable.
40 #                 It determines the type of parameters that have to be passed
41 #                 to the configure script. In the first case it adds
42 #                 "--with-wx-config=${WX_CONFIG}" (absolute path of
43 #                 WX_CONFIG), and in second one "--with-wx=${LOCALBASE}" plus
44 #                 "--with-wx-config=${WX_CONFIG:T} (prefix and name).
45 # WX_PREMK      - Define to determine version and define WX_CONFIG/WX_VERSION
46 #                 after <bsd.port.pre.mk> (in case the port needs to manually
47 #                 run the script).
48 # WANT_WX       - Set to "yes" or a valid single version (no ranges, etc).
49 #                 In both cases it will detect the installed wxWidgets
50 #                 components and add them to the variable HAVE_WX. If a
51 #                 version is selected, HAVE_WX will contain a list of
52 #                 components in the other case it will contain a list of
53 #                 "component-version" pairs (e.g. wx-2.8, contrib-2.8, etc).
54 #                 It has to be used before bsd.port.pre.mk.
55 # WANT_WX_VER   - Set to the preferred wxWidgets version for the port. It must
56 #                 be present in USE_WX or missing in USE_WX_NOT. This is
57 #                 overridden by the user variable WITH_WX_VER if set. It can
58 #                 contain multiple versions in order of preference (last ones
59 #                 are tried first).
60 #
61 # The following variables are intended for the user and can be defined in
62 # make.conf.
63 # WITH_WX_VER   - Define to the list of preferred versions in reverse order.
64 #
65 # The following variables are defined by this file, to be read from the port.
66 # WX_CONFIG     - The path to the wx-config program (with different name).
67 # WXRC_CMD      - The path to the wxrc program (with different name).
68 # WX_VERSION    - The wxWidgets version that is going to be used.
69 # HAVE_WX       - The list of wxWidgets components installed, if WANT_WX was
70 #                 defined. The components will have version suffix if it was
71 #                 set to "yes".
72 #
73 # Examples:
74 # - A port that needs wxWidgets 2.8 and contributed libraries
75 #       USE_WX=         2.8
76 #       WX_COMPS=       wx contrib
77 # - A port that needs WxPython 2.8 for running.
78 #       USE_PYTHON=     yes
79 #       USE_WX=         2.8
80 #       WX_COMPS=       python:run
81 # - A port that needs WxPython 2.8 or 3.0 for building.
82 #       USE_PYTHON=     yes
83 #       USE_WX=         2.8 3.0
84 #       WX_COMPS=       python:build
85 # - A port that needs wxWidgets version 2.8 or higher and contributed
86 #       libraries.
87 #       USE_WX=         2.8+
88 #       WX_COMPS=       wx contrib
89 # - A port that needs wxWidgets of any version other than 2.8.
90 #       USE_WX_NOT=     2.8
91 #
92
93 WX_Include_MAINTAINER=  ports@FreeBSD.org
94
95 #
96 # Global definitions.
97 #
98
99 .if !defined(_WX_Definitions_Done)
100 _WX_Definitions_Done=   yes
101
102 #
103 # Common variables:
104 # _WX_COMPS_ALL         - List of valid components.
105 # _WX_DEP_TYPES_ALL     - List of valid dependency types.
106 # _WX_VERS_ALL          - List of supported versions.
107 # _WX_VERS_UC_ALL       - List of Unicode capable versions.
108 # _WX_VERS_LISTS        - Reverse lists preference order.
109 #
110
111 _WX_COMPS_ALL=          wx contrib python
112 _WX_DEP_TYPES_ALL=      build lib run
113 _WX_VERS_ALL=           2.8 3.0 3.1
114 _WX_VERS_UC_ALL=        2.8 3.0 3.1
115 _WX_VERS_SKIP=          3.0 3.1
116 _WX_VERS_LISTS=         WANT_WX_VER WITH_WX_VER _WX_VER_INSTALLED
117
118 #
119 # Variables used to determine what is needed:
120 # _WX_PORT_comp_ver     - Port directory.
121 # _WX_LIB_comp_ver      - Name of the shared library (optional).
122 # _WX_SHVER_comp_ver    - Shared library version (optional).
123 # _WX_FILE_comp_ver     - File installed by that component.
124 # _WX_DEPTYPE_comp_ver  - Default dependency type (optional).
125 #
126
127 # wxgtk 2.8
128 _WX_PORT_wx_2.8=        x11-toolkits/wxgtk28
129 _WX_LIB_wx_2.8=         wx_base${_WX_UC}-2.8
130
131 _WX_PORT_contrib_2.8=   x11-toolkits/wxgtk28-contrib
132 _WX_LIB_contrib_2.8=    wx_gtk2${_WX_UC}_fl-2.8
133
134 # wxgtk 3.0
135 _WX_PORT_wx_3.0=        x11-toolkits/wxgtk30
136 _WX_LIB_wx_3.0=         wx_baseu-3.0
137
138 _WX_PORT_python_3.0=    x11-toolkits/py-wxPython40@${PY_FLAVOR}
139 _WX_FILE_python_3.0=    ${PYTHON_SITELIBDIR}/wx/__init__.py
140
141 # wxgtk 3.1
142 _WX_PORT_wx_3.1=        x11-toolkits/wxgtk31
143 _WX_LIB_wx_3.1=         wx_baseu-3.1
144
145 # Set _WX_SHVER_comp_ver to 0 and _WX_FILE_comp_ver for libs appropriately.
146 # Set _WX_DEPTYPE_comp_ver for "python" to "run", and others to "lib".
147
148 .       for comp in ${_WX_COMPS_ALL}
149 _WX_COMP=               ${comp}
150 .               for ver in ${_WX_VERS_ALL}
151 .                       if defined(_WX_LIB_${comp}_${ver})
152 _WX_SHVER_${comp}_${ver}=       0
153 _WX_FILE_${comp}_${ver}=        ${LOCALBASE}/lib/lib${_WX_LIB_${comp}_${ver}}.so.${_WX_SHVER_${comp}_${ver}}
154 .                       endif
155 .                       if ${_WX_COMP} == "python"
156 _WX_DEPTYPE_${comp}_${ver}=     run
157 .                       else
158 _WX_DEPTYPE_${comp}_${ver}=     lib
159 .                       endif
160 .               endfor
161 .       endfor
162 .endif          # !_WX_Defined_Done
163
164 #
165 # Check if we are going to determine the version.
166 #
167
168 .if !defined(_WX_Version_Done) && (defined(_POSTMKINCLUDED) || \
169     (defined(WX_PREMK) && defined(BEFOREPORTMK) && \
170     (defined(USE_WX) || defined(USE_WX_NOT))))
171 _WX_Need_Version=       yes
172 .endif
173
174 #
175 # Check for present components.
176 #
177
178 # Requested by the user.
179
180 .if defined(WANT_WX) && defined(BEFOREPORTMK)
181 _WANT_WX=               ${WANT_WX}
182 .endif
183
184 # Used for autodetection of installed versions.
185
186 .if defined(_WX_Need_Version)
187 _WANT_WX=               yes
188 .endif
189
190 .if defined(_WANT_WX)
191
192 # These variables are reprocessed later so they won't affect other parts.
193
194 _WX_VER_FINAL=          ${_WX_VERS_UC_ALL}
195 _WX_UC=                 u
196 _WX_PYSUFX=             -unicode
197
198 # Fill _HAVE_WX with the installed components.
199
200 .       undef _HAVE_WX
201 .       for __WANT_WX in ${_WANT_WX}
202 # Check if _WANT_WX contains more than one word.
203 .               if defined(_HAVE_WX)
204 IGNORE?=                selected multiple values for WANT_WX: ${_WANT_WX}
205 .               endif
206 _HAVE_WX=               #
207 # Check for all versions.
208 .               if ${_WANT_WX:tl} == "yes"
209 .                       for comp in ${_WX_COMPS_ALL}
210 .                               for ver in ${_WX_VER_FINAL}
211 _WX_COMP=               _WX_FILE_${comp}_${ver}
212 .                                       if defined(${_WX_COMP}) && exists(${${_WX_COMP}})
213 _HAVE_WX+=              ${comp}-${ver}
214 .                                       endif
215 .                               endfor
216 .                       endfor
217 # Check for a specific version.
218 .               elif ${_WX_VERS_ALL:M${__WANT_WX}}
219 .                       for comp in ${_WX_COMPS_ALL}
220 .                               if exists(${_WX_FILE_${comp}_${__WANT_WX}})
221 _HAVE_WX+=              ${comp}
222 .                               endif
223 .                       endfor
224 .               else
225 IGNORE?=                selected an invalid value for WANT_WX: ${__WANT_WX}
226 .               endif
227 .       endfor
228 .endif          # _WANT_WX
229
230 # Requested by the user.
231
232 .if defined(WANT_WX) && defined(BEFOREPORTMK)
233 HAVE_WX:=               ${_HAVE_WX}
234 .endif
235
236 # Used for autodetection of installed versions.
237
238 .if defined(_WX_Need_Version)
239 _WX_VER_INSTALLED:=     ${_HAVE_WX:Mwx-*:S/wx-//}
240 .endif
241
242 #
243 # Select wxWidgets version.
244 #
245
246 .if defined(_WX_Need_Version)
247 _WX_Version_Done=       yes
248
249 #
250 # Basic component parsing (ignores dependency types).
251 #
252 # The variables used are:
253 # _WX_COMP              - Component part.
254 # _WX_COMPS_FINAL       - Final list of components.
255 #
256
257 # Detect duplicated components.
258
259 _WX_COMPS_FINAL=        #
260 .for comp in ${WX_COMPS}
261 _WX_COMP=               ${comp:C/:([[:alpha:]]+)$//}
262 .       for __WX_COMP in ${_WX_COMP}
263 .               if ${_WX_COMPS_ALL:M${__WX_COMP}} == ""
264 IGNORE?=                selected an invalid wxWidgets component: ${__WX_COMP}
265 .               endif
266 .       endfor
267 .       for newcomp in ${_WX_COMP}
268 .               if ${_WX_COMPS_FINAL:M${newcomp}} == "" && !defined(IGNORE)
269 _WX_COMPS_FINAL+=       ${newcomp}
270 .               endif
271 .       endfor
272 .endfor
273
274 # Set defaults (if one isn't present).
275
276 USE_WX?=                ${_WX_VERS_ALL}
277 USE_WX_NOT?=            #
278
279 #
280 # Make lists of valid and invalid versions.
281 #
282 # The following variables are used:
283 # _WX_VER_CHECK         - If the version is a single one, express in a range.
284 # _WX_VER_MIN           - Lower version of the range.
285 # _WX_VER_MAX           - Higher version of the range.
286 # _WX_VER_LIST          - List of requested versions.
287 # _WX_VER_NOT_LIST      - List of disallowed versions.
288 # _WX_VER_MERGED        - List of requested version without disallowed ones.
289 #
290
291 .for list in VER VER_NOT
292 _WX_${list}_LIST=       #
293 .       for ver in ${USE_WX${list:C/VER//}}
294 _WX_VER_CHECK:=         ${ver:C/^([[:digit:]]+(\.[[:digit:]]+)*)$/\1-\1/}
295 _WX_VER_MIN:=           ${_WX_VER_CHECK:C/([[:digit:]]+(\.[[:digit:]]+)*)[-+].*/\1/}
296 _WX_VER_MAX:=           ${_WX_VER_CHECK:C/.*-([[:digit:]]+(\.[[:digit:]]+)*)/\1/}
297 # Minimum version not specified.
298 .               if ${_WX_VER_MIN} == ${_WX_VER_CHECK}
299 .                       undef _WX_VER_MIN
300 .                       for v in ${_WX_VERS_ALL}
301 .                               if ${_WX_VER_CHECK:C/[-+]//} == ${v} || ${_WX_VERS_SKIP:M${v}} == ""
302 _WX_VER_MIN?=           ${v}
303 .                               endif
304 .                       endfor
305 .               endif
306 # Maximum version not specified.
307 .               if ${_WX_VER_MAX} == ${_WX_VER_CHECK}
308 .                       for v in ${_WX_VERS_ALL}
309 .                               if ${_WX_VER_CHECK:C/[-+]//} == ${v} || ${_WX_VERS_SKIP:M${v}} == ""
310 _WX_VER_MAX=            ${v}
311 .                               endif
312 .                       endfor
313 .               endif
314 # Expand versions and add valid ones to each list.
315 .               for v in ${_WX_VERS_ALL}
316 .                       if ${_WX_VER_MIN} <= ${v} && ${_WX_VER_MAX} >= ${v} && \
317                            ${_WX_${list}_LIST:M${v}} == ""
318 _WX_${list}_LIST+=      ${v}
319 .                       endif
320 .               endfor
321 .       endfor
322 .endfor
323
324 # Merge the lists into a single list of valid versions.
325
326 _WX_VER_MERGED=         #
327 .for ver in ${_WX_VER_LIST}
328 .       if ${_WX_VER_NOT_LIST:M${ver}} == ""
329 _WX_VER_MERGED+=        ${ver}
330 .       endif
331 .endfor
332
333 # Check for a null version.
334
335 .if empty(_WX_VER_MERGED)
336 IGNORE?=                selected a null or invalid wxWidgets version
337 .endif
338
339 # Avoid versions which have unavailable components.
340
341 .for ver in ${_WX_VER_MERGED}
342 .       for comp in ${_WX_COMPS_FINAL}
343 .               if !defined(_WX_PORT_${comp}_${ver})
344 _WX_WRONG_COMPS+=       ${comp}
345 _WX_WRONG_VERS+=        ${ver}
346 _WX_VER_MERGED:=        ${_WX_VER_MERGED:N${ver}}
347 .               endif
348 .       endfor
349 .endfor
350
351 .if empty(_WX_VER_MERGED)
352 IGNORE?=                selected wxWidgets versions (${_WX_WRONG_VERS}) which do not have the selected components (${_WX_WRONG_COMPS})
353 .endif
354
355 #
356 # Unicode support.
357 #
358
359 # Create a list of capable versions.
360
361 _WX_VER_UC=             #
362 .for ver in ${_WX_VER_MERGED}
363 .       if ${_WX_VERS_UC_ALL:M${ver}} != ""
364 _WX_VER_UC+=            ${ver}
365 .       endif
366 .endfor
367
368 # Set Unicode variables.
369
370 _WX_VER_FINAL=          ${_WX_VER_UC}
371 _WX_UC=                 u
372 _WX_PYSUFX=             -unicode
373
374 # Remove unusable installed versions.
375
376 .for ver in ${_WX_VER_INSTALLED}
377 .       if ${_WX_VER_FINAL:M${ver}} == ""
378 _WX_VER_INSTALLED:=     ${_WX_VER_INSTALLED:N${ver}}
379 .       endif
380 .endfor
381
382 #
383 # Choose final version.
384 #
385
386 #
387 # Check for the following (in order):
388 # 1) WITH_WX_VER        - User preference.
389 # 2) WANT_WX_VER        - Port preference.
390 # 3) _WX_VER_INSTALLED  - Installed versions.
391 # 4) _WX_VER_FINAL      - Available versions.
392
393
394 .for list in _WX_VER_FINAL ${_WX_VERS_LISTS}
395 .       if defined(${list})
396 .               for ver in ${${list}}
397 .                       if ${_WX_VER_FINAL:M${ver}} != ""
398 _WX_VER=                ${ver}
399 .                       endif
400 .               endfor
401 .       endif
402 .endfor
403
404 #
405 # Set variables.
406 #
407
408 .if ${_WX_VER:R} == 3
409 _GTKVER=        3
410 .else
411 _GTKVER=        2
412 .endif
413
414 WX_CONFIG?=             ${LOCALBASE}/bin/wxgtk${_GTKVER}${_WX_UC}-${_WX_VER}-config
415 WXRC_CMD?=              ${LOCALBASE}/bin/wxrc-gtk${_GTKVER}${_WX_UC}-${_WX_VER}
416 WX_VERSION?=            ${_WX_VER}
417
418 .endif          # _WX_Need_Version
419
420 #
421 # Process components list and add dependencies, variables, etc.
422 #
423
424 .if defined(_POSTMKINCLUDED)
425
426 #
427 # Component parsing.
428 #
429 # The variables used are:
430 # _WX_COMP              - Component part.
431 # _WX_DEP_TYPE          - Dependency type part.
432 # _WX_COMP_NEW          - Component + dependency type.
433 # _WX_COMPS_FINAL       - Final list of components with dependency types.
434 #
435
436 # Default components.
437
438 WX_COMPS?=              wx
439
440 # Detect invalid and duplicated components.
441
442 _WX_COMPS_FINAL=        #
443 .for comp in ${WX_COMPS}
444 _WX_COMP=               ${comp:C/:([[:alpha:]]+)$//}
445 .       if ${_WX_COMP} == ${comp}
446 _WX_DEP_TYPE=           ${_WX_DEPTYPE_${comp}_${_WX_VER}}
447 .       else
448 _WX_DEP_TYPE=           ${comp:C/.+:([[:alpha:]]+)$/\1/}
449 .       endif
450 _WX_COMP_NEW=           ${_WX_COMP}_${_WX_DEP_TYPE}
451 .       for __WX_COMP in ${_WX_COMP}
452 .               if ${_WX_COMPS_ALL:M${__WX_COMP}} == ""
453 IGNORE?=                selected an invalid wxWidgets component: ${__WX_COMP}
454 .               endif
455 .       endfor
456 .       for __WX_DEP_TYPE in ${_WX_DEP_TYPE}
457 .               if ${_WX_DEP_TYPES_ALL:M${__WX_DEP_TYPE}} == ""
458 IGNORE?=                selected an invalid wxWidgets dependency type: ${__WX_DEP_TYPE}
459 .               endif
460 .       endfor
461 .       if !defined(_WX_PORT_${_WX_COMP}_${_WX_VER})
462 IGNORE?=                selected a wxWidgets component (${_WX_COMP}) which is not available for the selected version (${_WX_VER})
463 .       endif
464 .       for newcomp in ${_WX_COMP_NEW}
465 .               if ${_WX_COMPS_FINAL:M${newcomp}} == "" && !defined(IGNORE)
466 _WX_COMPS_FINAL+=       ${newcomp}
467 .               endif
468 .       endfor
469 .endfor
470
471 # Add dependencies.
472 #
473 # The variable used are:
474 # _WX_COMP              - Component part.
475 # _WX_DEP_TYPE          - Dependency type part.
476
477 .for comp in ${_WX_COMPS_FINAL}
478 _WX_COMP=               ${comp:C/_([[:alpha:]]+)$//}
479 _WX_DEP_TYPE=           ${comp:C/.+_([[:alpha:]]+)$/\1/}
480 # XXX Need a .for loop here so the variable is expanded before the assignment.
481 .       for comp_part in ${_WX_COMP}
482 .               if ${_WX_DEP_TYPE} == "lib"
483 .                       if defined(_WX_LIB_${_WX_COMP}_${_WX_VER})
484 LIB_DEPENDS+=           lib${_WX_LIB_${comp_part}_${_WX_VER}}.so:${_WX_PORT_${comp_part}_${_WX_VER}}
485 .                       else
486 BUILD_DEPENDS+=         ${_WX_FILE_${comp_part}_${_WX_VER}}:${_WX_PORT_${comp_part}_${_WX_VER}}
487 RUN_DEPENDS+=           ${_WX_FILE_${comp_part}_${_WX_VER}}:${_WX_PORT_${comp_part}_${_WX_VER}}
488 .                       endif
489 .               else
490 ${_WX_DEP_TYPE:tu}_DEPENDS+=    ${_WX_FILE_${comp_part}_${_WX_VER}}:${_WX_PORT_${comp_part}_${_WX_VER}}
491 .               endif
492 .       endfor
493 .endfor
494
495 #
496 # Set build related variables.
497 #
498
499 MAKE_ENV+=              WX_CONFIG=${WX_CONFIG}
500 CONFIGURE_ENV+=         WX_CONFIG=${WX_CONFIG}
501
502 .if defined(WX_CONF_ARGS)
503 .       if ${WX_CONF_ARGS:tl} == "absolute"
504 CONFIGURE_ARGS+=        --with-wx-config=${WX_CONFIG}
505 .       elif ${WX_CONF_ARGS:tl} == "relative"
506 CONFIGURE_ARGS+=        --with-wx=${LOCALBASE} \
507                         --with-wx-config=${WX_CONFIG:T}
508 .       else
509 IGNORE?=                selected an invalid wxWidgets configure argument type: ${WX_CONF_ARGS}
510 .       endif
511 .endif
512
513 .endif          # _POSTMKINCLUDED