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