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