Refine rubygem handling
[dports.git] / Mk / bsd.tcl.mk
1 # -*- tab-width: 4; -*-
2 # ex: ts=4
3 #
4 # $FreeBSD: Mk/bsd.tcl.mk 318663 2013-05-21 08:59:02Z gahr $
5 #
6
7 .if !defined(_POSTMKINCLUDED) && !defined(Tcl_Pre_Include)
8
9 Tcl_Pre_Include=                bsd.tcl.mk
10 Tcl_Include_MAINTAINER=         mm@FreeBSD.org
11
12 # USE_TCL               - Add library dependency on Tcl. If no version is given by the maintainer
13 #                         via the port or by the user via defined variable try to find the highest
14 #                         stable installed version.
15 #                         Available values: yes 86+ 85+ 84+ 85 84
16 #                         NOTE: - default value 86 is used in case of USE_TCL=yes
17 #
18 # USE_TCL_BUILD         - Add buildtime dependency on Tcl (tclsh).
19 #                         Available values: see USE_TCL
20 #                         NOTE: - has no effect if USE_TCL is defined
21 #
22 # USE_TCL_RUN           - Add runtime dependency on Tcl (tclsh).
23 #                         Available values: see USE_TCL
24 #                         NOTE: - has no effect if USE_TCL is defined
25 #                               - value is implied by USE_TCL_BUILD (if defined)
26 #
27 # USE_TCL_WRAPPER       - Depend on the tclsh wrapper to run. Ports that do not explicitly require
28 #                         a specific tclsh version may use this.
29 #                         The tclsh wrapper script installs into ${LOCALBASE}/bin/tclsh
30 #                         NOTE: - USE_TCL_WRAPPER and USE_TCL can be used together
31 #                               - ports using the wrapper should support default Tcl (8.6)
32 ##
33 # INVALID_TCL_VER       - This variable contains a list of Tcl versions not supported by the port.
34 #                         This setting is effective only when USE_TCL is set to a range (e.g. 85+)
35 # WITH_TCL_VER          - User defined global variable to set Tcl version
36 #                         This variable is effective only if USE_TCL is set to a range (e.g. 85+)
37 #                         and WITH_TCL_VER points inside that range.
38 #                         NOTE: INVALID_TCL_VER takes precedence
39 # <UNIQUENAME>_WITH_TCL_VER     - User defined port specific variable to set Tcl version
40 ##
41 # TCL_VER               - Detected by bsd.tcl.mk. Contains the version number of Tcl to be used.
42 #
43 ##
44 # USE_TK                - Add library dependency on Tk. If no version is given by the maintainer
45 #                         via the port or by the user via defined variable try to find the highest
46 #                         stable installed version.
47 #                         Avaliable values: yes 86+ 85+ 84+ 85 84
48 #                         NOTE: - overrides USE_TCL
49 #                               - default value 86 is used in case of USE_TK=yes
50 #
51 # USE_TK_BUILD          - Add buildtime dependency on Tk (wish).
52 #                         Available values: see USE_TK
53 #                         NOTE: - has no effect if USE_TK is defined
54 #
55 # USE_TK_RUN            - Add runtime dependency on Tk (wish).
56 #                         Available values: see USE_TK
57 #                         NOTE: - has no effect if USE_TK is defined
58 #                               - value is implied by USE_TK_BUILD (if defined)
59 #
60 # USE_TK_WRAPPER        - Depend on the wish wrapper to run. Ports that do not explicitly require
61 #                         a specific wish version may use this.
62 #                         The wish wrapper script installs into ${LOCALBASE}/bin/wish
63 #                         NOTE: - USE_TK_WRAPPER and USE_TK can be used together.
64 #                               - ports using the wrapper should support default Tk (8.6)
65 ##
66 # INVALID_TK_VER        - This variable contains a list of Tk versions not supported by the port
67 #                         This setting is effective only when USE_TK is set to a range (e.g. 85+)
68 # WITH_TK_VER           - User defined global variable to set Tk version.
69 #                         This variable is effective only if USE_TK is set to a range (e.g. 85+)
70 #                         and WITH_TK_VER points inside that range.
71 #                         NOTE: overrides WITH_TCL_VER.
72 # <UNIQUENAME>_WITH_TK_VER      - User defined port specific variable to set Tk version
73 #                         NOTE: overrides <UNIQUENAME>_WITH_TCL_VER.
74 ##
75 # TCL_LIBDIR            - Path where tcl libraries can be found
76 #
77 # TCL_INCLUDEDIR        - Path where tcl C headers can be found
78 ##
79 # TK_LIBDIR             - Path where tk libraries can be found
80 #
81 # TK_INCLUDEDIR         - Path where tk C headers can be found
82 ##
83 # TCLSH                 - Path to tclsh executable respecting Tcl version
84 #                         or to the tclsh wrapper if USE_TCL_WRAPPER is set
85 #
86 # WISH                  - Path to wish executable respecting Tk version
87 #                         or to the wish wrapper if USE_TK_WRAPPER is set
88 #
89 ##
90 # PATCH_TCL_SCRIPTS     - List of tcl scripts that need to be patched to replace
91 #                         tclsh calls with tclsh${TK_VER} calls. Also note that
92 #                         post-patch target is used.
93 #
94 # PATCH_TK_SCRIPTS      - List of tcl scripts that need to be patched to replace
95 #                         wish calls with wish${TK_VER} calls. Also note that
96 #                         post-patch target is used.
97
98 # Set RUN_DEPENDS for wrappers
99 . if defined(USE_TCL_WRAPPER)
100 RUN_DEPENDS+=           tclsh:${PORTSDIR}/lang/tcl-wrapper
101 . endif
102 . if defined(USE_TK_WRAPPER)
103 RUN_DEPENDS+=           wish:${PORTSDIR}/x11-toolkits/tk-wrapper
104 . endif
105
106 # Process USE_TCL_BUILD and USE_TCL_RUN
107 .if !defined(USE_TCL)
108 . if defined(USE_TCL_RUN)
109 USE_TCL:=       ${USE_TCL_RUN}
110 _TCL_RUN_DEPENDS=       yes
111 . endif
112 . if defined(USE_TCL_BUILD)
113 USE_TCL:=       ${USE_TCL_BUILD}
114 _TCL_BUILD_DEPENDS=     yes
115 . endif
116 .endif
117
118 # Process USE_TK_BUILD and USE_TK_RUN
119 .if !defined(USE_TK)
120 . if defined(USE_TK_RUN)
121 USE_TK:=        ${USE_TK_RUN}
122 _TK_RUN_DEPENDS=        yes
123 . endif
124 . if defined(USE_TK_BUILD)
125 USE_TK:=        ${USE_TK_BUILD}
126 _TK_BUILD_DEPENDS=      yes
127 . endif
128 .endif
129
130 # Override the global WITH_TCL_VER or WITH_TK_VER with the
131 # port specific <UNIQUENAME>_WITH_TCL_VER or <UNIQUENAME>_WITH_TK_VER
132 . if defined(${UNIQUENAME:tu:S,-,_,}_WITH_TCL_VER)
133 WITH_TCL_VER:=  ${${UNIQUENAME:tu:S,-,_,}_WITH_TCL_VER}
134 . endif
135 . if defined(${UNIQUENAME:tu:S,-,_,}_WITH_TK_VER)
136 WITH_TK_VER:=   ${${UNIQUENAME:tu:S,-,_,}_WITH_TK_VER}
137 . endif
138
139 # If USE_TK, WITH_TK_VER, INVALID_TK_VER is defined,
140 # set USE_TCL, WITH_TCL_VER, INVALID_TCL_VER to identical values
141 # we require the same version of Tcl for Tk
142 . if defined(USE_TK)
143 .  if !defined(USE_TCL)
144 _TK_ONLY=       yes
145 .  endif
146 USE_TCL:=       ${USE_TK}
147 . endif
148 . if defined(WITH_TK_VER)
149 WITH_TCL_VER:=  ${WITH_TK_VER}
150 . endif
151 . if defined(INVALID_TK_VER)
152 INVALID_TCL_VER:=       ${INVALID_TK_VER}
153 . endif
154
155 #
156 # Tcl part
157 #
158 . if defined(USE_TCL)
159
160 _TCL_DEFAULT_VERSION=           86
161 _TCL_VERSIONS=                  86 85 84
162 _TCL_RANGE_VERSIONS=            86+ 85+ 84+
163
164 # For specifying [85, 84, ..]+
165 _TCL_84P=       84 85 86
166 _TCL_85P=       85 86
167 _TCL_86P=       86
168
169 # Set the default Tcl version and check if USE_TCL=yes was given
170 .  if ${USE_TCL} == "yes"
171 USE_TCL=        ${_TCL_DEFAULT_VERSION}
172 .  endif
173
174 _TCL_VER=       no
175
176 # Check if we have user-defined WITH_TCL_VER and if it matches
177 # the range specified in port's USE_TCL or USE_TK
178 .  if defined(WITH_TCL_VER)
179 .   for ver in ${_TCL_RANGE_VERSIONS}
180 .    if ${USE_TCL} == "${ver}" && ${_TCL_VER} == "no"
181 _MATCHED_TCL_VER:=      ${USE_TCL:S/+//}
182 .     for tcl in ${_TCL_${_MATCHED_TCL_VER}P}
183 .      if ${WITH_TCL_VER} == ${tcl}
184 #  Check if user supplied WITH_TCL is in the INVALID_TCL_VER list
185 _BRKTCL=        no
186 .       for iver in ${INVALID_TCL_VER}
187 .        if ${WITH_TCL_VER} == ${iver}
188 _BRKTCL=        yes
189 .        endif
190 .       endfor
191 #  If WITH_TCL is not in the INVALID_TCL_VER list, use it
192 #  otherwise take default from port
193 .       if ${_BRKTCL} == "no"
194 _TCL_VER=       ${WITH_TCL_VER}
195 USE_TCL=        ${_TCL_VER}
196 .       endif
197 .      endif
198 .     endfor
199 .    endif
200 .   endfor
201 .  endif
202
203 # Check for highest installed Tcl (if e.g. 84+ is specified)
204 # The default version of Tcl counts as the highest
205 .  if ${_TCL_VER} == "no"
206 .   for ver in ${_TCL_RANGE_VERSIONS}
207 .    if ${USE_TCL} == "${ver}" && ${_TCL_VER} == "no"
208 _MATCHED_TCL_VER:=      ${USE_TCL:S/+//}
209 .     for tcl in ${_TCL_${_MATCHED_TCL_VER}P}
210 #  Skip versions we are incompatible with
211 _BRKTCL=        no
212 .      for iver in ${INVALID_TCL_VER}
213 _INVALID_VER=   ${iver}
214 .       if ${_INVALID_VER} == ${tcl}
215 _BRKTCL=        yes
216 .       endif
217 .      endfor
218 .      if ${_BRKTCL} == "no"
219 #  We have matched a supported version
220 _TCL_VER_MATCH=${tcl}
221 #  Check if the default version is supported
222 .       if ${_TCL_VER_MATCH} == ${_TCL_DEFAULT_VERSION}
223 _TCL_SUPPORT_DEFAULT=   yes
224 .       endif
225 #  Look for installed versions
226 .       if exists(${LOCALBASE}/include/tcl${tcl:S/8/8./}/tcl.h)
227 _TCL_INST_VER=${tcl}
228 #  Check if the default version is installed
229 .        if ${_TCL_INST_VER} == ${_TCL_DEFAULT_VERSION}
230 _TCL_HAVE_DEFAULT=      yes
231 .        endif
232 .       endif
233 .      endif
234 .     endfor
235 .    endif
236 .   endfor
237 .   if defined(_MATCHED_TCL_VER)
238 .    if defined(_TCL_INST_VER)
239 #  Default version is installed
240 .     if defined(_TCL_HAVE_DEFAULT)
241 USE_TCL=        ${_TCL_DEFAULT_VERSION}
242 .     else
243 #  Default version is not installed, but another supported version is installed
244 USE_TCL=        ${_TCL_INST_VER}
245 .     endif
246 #  No supported version is installed, we want to install the default version
247 .    elif defined(_TCL_SUPPORT_DEFAULT)
248 USE_TCL=        ${_TCL_DEFAULT_VERSION}
249 .    elif defined(_TCL_VER_MATCH)
250 #  Default version is not wanted, select next best match
251 USE_TCL=        ${_TCL_VER_MATCH}
252 .    else
253 #  INVALID_[TCL|TK]_VER removes all choices from the USE_[TCL|TK] range
254 IGNORE=         selection of a Tcl/Tk version is not possible. Please check USE_[TCL|TK] and INVALID_[TCL|TK]_VER
255 .    endif
256 .   endif
257 .  endif
258
259 TCL_VER:=       ${USE_TCL:S/8/8./}
260
261 # Check if a correct Tcl/Tk version was specified
262 _FOUND=         no
263 .  for ver in ${_TCL_VERSIONS}
264 .   if ${USE_TCL} == "${ver}" && ${_FOUND} == "no"
265 _FOUND=         yes
266 .   endif
267 .  endfor
268
269 .  if ${_FOUND} == "yes"
270
271 TCL_INCLUDEDIR=         ${LOCALBASE}/include/tcl${TCL_VER}
272 TCL_LIBDIR=             ${LOCALBASE}/lib/tcl${TCL_VER}
273 TCLSH=                  ${LOCALBASE}/bin/tclsh${TCL_VER}
274
275 # Add dependencies
276 .   if !defined(_TK_ONLY)
277 .    if !defined(_TCL_RUN_DEPENDS) && !defined(_TCL_BUILD_DEPENDS)
278 LIB_DEPENDS+=   tcl${USE_TCL}:${PORTSDIR}/lang/tcl${USE_TCL}
279 .    else
280 .     if defined(_TCL_BUILD_DEPENDS)
281 BUILD_DEPENDS+= tclsh${TCL_VER}:${PORTSDIR}/lang/tcl${USE_TCL}
282 .     endif
283 .     if defined(_TCL_RUN_DEPENDS)
284 RUN_DEPENDS+=   tclsh${TCL_VER}:${PORTSDIR}/lang/tcl${USE_TCL}
285 .     endif
286 .    endif
287 .   endif
288
289 .  elif !defined(IGNORE)
290 IGNORE=         unknown Tcl/Tk version specified: ${USE_TCL}
291 .  endif
292
293 #
294 # Tk part
295 #
296 .  if defined(USE_TK)
297
298 # We now read the version numbers from the Tcl part
299 USE_TK:=        ${USE_TCL}
300 TK_VER:=        ${USE_TCL:S/8/8./}
301
302 .   if !defined(_TK_RUN_DEPENDS) && !defined(_TK_BUILD_DEPENDS)
303 LIB_DEPENDS+=   tk${USE_TK}:${PORTSDIR}/x11-toolkits/tk${USE_TK}
304 .   else
305 .    if defined(_TK_BUILD_DEPENDS)
306 BUILD_DEPENDS+= wish${TK_VER}:${PORTSDIR}/x11-toolkits/tk${USE_TK}
307 .    endif
308 .    if defined(_TK_RUN_DEPENDS)
309 RUN_DEPENDS+=   wish${TK_VER}:${PORTSDIR}/x11-toolkits/tk${USE_TK}
310 .    endif
311 .   endif
312
313 TK_INCLUDEDIR=          ${LOCALBASE}/include/tk${TK_VER}
314 TK_LIBDIR=              ${LOCALBASE}/lib/tk${TK_VER}
315 WISH=                   ${LOCALBASE}/bin/wish${TK_VER}
316
317 .  endif # defined(USE_TK)
318 . endif # defined(USE_TCL)
319
320 # (Re)set WISH and TCLSH to the wrapper, if defined
321 . if defined(USE_TCL_WRAPPER)
322 TCLSH=                  ${LOCALBASE}/bin/tclsh
323 . endif
324 . if defined(USE_TK_WRAPPER)
325 WISH=                   ${LOCALBASE}/bin/wish
326 . endif
327
328 .endif # !defined(_POSTMKINCLUDED) && !defined(Tcl_Pre_Include)
329
330 .if defined(_POSTMKINCLUDED) && !defined(Tcl_Post_Include)
331
332 Tcl_Post_Include=       bsd.tcl.mk
333
334 . if defined(PATCH_TCL_SCRIPTS) || defined (PATCH_TK_SCRIPTS)
335 .  if !target(post-patch)
336 post-patch:
337 .   if defined(PATCH_TCL_SCRIPTS) && defined(TCLSH)
338 .    for tcl_script in ${PATCH_TCL_SCRIPTS}
339         @${REINPLACE_CMD} -e 's,tclsh,${TCLSH},' ${WRKSRC}/${tcl_script}
340 .    endfor
341 .   endif
342 .   if defined(PATCH_TK_SCRIPTS) && defined(WISH)
343 .    for tk_script in ${PATCH_TK_SCRIPTS}
344         @${REINPLACE_CMD} -e 's,wish,${WISH},' ${WRKSRC}/${tk_script}
345 .    endfor
346 .   endif
347 .  endif # !target(post-patch)
348 . endif # defined(PATCH_TCL_SCRIPTS) || defined (PATCH_TK_SCRIPTS)
349 .endif # defined(_POSTMKINCLUDED) && !defined(Tcl_Post_Include)