Use openjdk 7 over openjdk 6
[dports.git] / Mk / bsd.ruby.mk
1 #
2 # bsd.ruby.mk - Utility definitions for Ruby related ports.
3 #
4 # Created by: Akinori MUSHA <knu@FreeBSD.org>
5 #
6 # $FreeBSD$
7 #
8
9 .if !defined(Ruby_Include)
10
11 Ruby_Include=                   bsd.ruby.mk
12 Ruby_Include_MAINTAINER=        ruby@FreeBSD.org
13
14 #
15 # [variables that a user may define]
16 #
17 # RUBY_VER              - (See below)
18 # RUBY_DEFAULT_VER      - Set to (e.g.) "1.9" if you want to refer to "ruby19"
19 #                         just as "ruby".
20 # RUBY_ARCH             - (See below)
21 # RUBY_RD_HTML          - Define if you want HTML files generated from RD files.
22 #
23 #
24 # [variables that each port can define]
25 #
26 # RUBY                  - Set to full path of ruby.  If you set this, the values
27 #                         of the following variables are automatically obtained
28 #                         from the ruby executable: RUBY_VER, RUBY_VERSION,
29 #                         RUBY_NAME, RUBY_ARCH, RUBY_LIBDIR, RUBY_ARCHLIBDIR,
30 #                         RUBY_SITELIBDIR, and RUBY_SITEARCHLIBDIR.
31 # RUBY_VER              - Set to the alternative short version of ruby in the
32 #                         form of `x.y' (see below for current value).
33 # USE_RUBY              - Says that the port uses ruby for building and running.
34 # RUBY_NO_BUILD_DEPENDS - Says that the port should not build-depend on ruby.
35 # RUBY_NO_RUN_DEPENDS   - Says that the port should not run-depend on ruby.
36 # USE_LIBRUBY           - Says that the port uses libruby.
37 # USE_RUBY_EXTCONF      - Says that the port uses extconf.rb to configure.
38 #                         Implies USE_RUBY.
39 # RUBY_EXTCONF          - Set to the alternative name of extconf.rb
40 #                         (default: extconf.rb).
41 # RUBY_EXTCONF_SUBDIRS  - Set to list of subdirectories, if multiple modules
42 #                         are included.
43 # USE_RUBY_SETUP        - Says that the port uses setup.rb to configure and
44 #                         build.
45 # RUBY_SETUP            - Set to the alternative name of setup.rb
46 #                         (default: setup.rb).
47 # USE_RUBY_RDTOOL       - Says that the port uses rdtool to generate documents.
48 # USE_RUBY_RDOC         - Says that the port uses rdoc to generate documents.
49 # USE_RUBY_FEATURES     - Says that the port requires some of the following
50 #                         features for building and/or running (default: none):
51 #                         iconv
52 # RUBY_REQUIRE          - Set to a Ruby expression to evaluate before building
53 #                         the port.  The constant "Ruby" is set to the integer
54 #                         version number of ruby, and the result of the
55 #                         expression will be set to RUBY_PROVIDED, which is
56 #                         left undefined if the result is nil, false or a
57 #                         zero-length string.  Implies USE_RUBY.
58 # RUBY_SHEBANG_FILES    - Specify the files which shebang lines you want to fix.
59 # RUBY_RD_FILES         - Specify the RD files which you want to generate HTML
60 #                         documents from. If this is defined and not empty,
61 #                         USE_RUBY_RDTOOL is implied and RUBY_RD_HTML_FILES is
62 #                         defined.
63 # USE_RUBYGEMS          - Says that the port uses rubygems packaging system.
64 # RUBYGEM_AUTOPLIST     - Generate packing list for rubygems based port
65 #                         automatically.
66 #
67 #
68 # [variables that each port should not (re)define]
69 #
70 # RUBY_PKGNAMEPREFIX    - Common PKGNAMEPREFIX for ruby ports
71 #                         (default: ruby${RUBY_SUFFIX}-)
72 # RUBY_RELVERSION       - Full version of ruby without preview/beta suffix in
73 #                         the form of `x.y.z' (see below for current value).
74 # RUBY_RELVERSION_CODE  - Integer version of RUBY_RELVERSION in the form of
75 #                         `xyz'.
76 # RUBY_VERSION          - Composite version of RUBY_RELVERSION and
77 #                         RUBY_PATCHLEVEL in the form of `x.y.z.p'.
78 #                         (default: ${RUBY_RELVERSION}.${RUBY_PATCHLEVEL})
79 # RUBY_VERSION_CODE     - Composite integer version of RUBY_VERSION in the form
80 #                         of `xyzp'.
81 # RUBY_PORTVERSION      - PORTVERSION for the standard ruby ports (ruby,
82 #                         ruby-gdbm, etc.).
83 # RUBY_PORTREVISION     - PORTREVISION for the standard ruby ports.
84 # RUBY_PORTEPOCH        - PORTEPOCH for the standard ruby ports.
85 # RUBY_DISTNAME         - DISTNAME for the standard ruby ports, i.e. the
86 #                         basename of the ruby distribution tarball.
87 # RUBY_DISTVERSION      - The version number part of RUBY_DISTNAME.
88 # RUBY_PATCHFILES       - PATCHFILES for the standard ruby ports, i.e. the
89 #                         basename of the ruby distribution tarball.
90 # RUBY_WRKSRC           - WRKSRC for the ruby port.
91 # MASTER_SITE_SUBDIR_RUBY       - MASTER_SITE_SUBDIR for the ruby distfiles.
92 #
93 # RUBY_SHLIBVER         - Major version of libruby (see below for current
94 #                         value).
95 # RUBY_ARCH             - Set to target architecture name.
96 #                         (e.g. i386-freebsd7)
97 # RUBY_SUFFIX           - Suffix for ruby binaries and directories
98 #                         (${RUBY_VER:S/.//}).
99 # RUBY_WITHOUT_SUFFIX   - Always ${LOCALBASE}/bin/ruby.
100 # RUBY_WITH_SUFFIX      - Always ${RUBY_WITHOUT_SUFFIX}${RUBY_SUFFIX}.
101 # RUBY_NAME             - Ruby's name with trailing suffix.
102 #
103 # RUBY_MODNAME          - Set to the module name (default: ${PORTNAME}).
104 #
105 # RUBY_RD2              - Full path of rd2 executable.
106 # RUBY_RDOC             - Full path of rdoc executable.
107 #
108 # RUBY_BASE_PORT        - Port path of base ruby without PORTSDIR, without
109 #                         suffix except version.
110 # RUBY_PORT             - Port path of ruby without PORTSDIR.
111 # RUBY_RDTOOL_PORT      - Port path of rdtool without PORTSDIR.
112 # RUBY_RDOC_PORT        - Port path of rdoc without PORTSDIR.
113 # RUBY_ICONV_PORT       - Port path of ruby-iconv without PORTSDIR.
114 #
115 # DEPEND_LIBRUBY        - LIB_DEPENDS entry for libruby.
116 # DEPEND_RUBY           - BUILD_DEPENDS/RUN_DEPENDS entry for ruby.
117 # DEPEND_RUBY_RDTOOL    - BUILD_DEPENDS entry for rdtool.
118 # DEPEND_RUBY_RDOC      - BUILD_DEPENDS entry for rdoc.
119 # DEPEND_RUBY_ICONV     - BUILD_DEPENDS/RUN_DEPENDS entry for ruby-iconv.
120 #
121 # RUBY_LIBDIR           - Installation path for architecture independent
122 #                         libraries.
123 # RUBY_ARCHLIBDIR       - Installation path for architecture dependent
124 #                         libraries.
125 # RUBY_SITELIBDIR       - Installation path for site architecture independent
126 #                         libraries.
127 # RUBY_SITEARCHLIBDIR   - Installation path for site architecture dependent
128 #                         libraries.
129 # RUBY_DOCDIR           - Installation path for documents.
130 # RUBY_EXAMPLESDIR      - Installation path for examples.
131 # RUBY_RIDIR            - Installation path for site architecture independent ri
132 #                         documents.
133 # RUBY_SITERIDIR        - Installation path for site architecture dependent ri
134 #                         documents.
135 # RUBY_MODDOCDIR        - Installation path for the module's documents.
136 # RUBY_MODEXAMPLESDIR   - Installation path for the module's examples.
137 # RUBY_ELISPDIR         - Installation path for emacs lisp files.
138 #
139
140 .include "${PORTSDIR}/Mk/bsd.default-versions.mk"
141
142 .if defined(RUBY_DEFAULT_VER)
143 WARNING+=       "RUBY_DEFAULT_VER is defined, consider using DEFAULT_VERSIONS=ruby=${RUBY_DEFAULT_VER} instead"
144 .endif
145
146 RUBY_DEFAULT_VER?=      ${RUBY_DEFAULT}
147
148 RUBY_VER?=              ${RUBY_DEFAULT_VER}
149
150 .if defined(RUBY)
151 .if !exists(${RUBY})
152 IGNORE= cannot install: you set the variable RUBY to "${RUBY}", but it does not seem to exist.  Please specify an already installed ruby executable.
153 .endif
154
155 _RUBY_TEST!=            ${RUBY} -e 'begin; require "rbconfig"; puts "ok" ; rescue LoadError; puts "error"; end'
156 .if !empty(_RUBY_TEST) && ${_RUBY_TEST} != "ok"
157 IGNORE= cannot install: you set the variable RUBY to "${RUBY}", but it failed to include rbconfig.  Please specify a properly installed ruby executable.
158 .endif
159
160 _RUBY_CONFIG=           ${RUBY} -r rbconfig -e 'C = RbConfig::CONFIG' -e
161
162 RUBY_VERSION!=          ${_RUBY_CONFIG} 'puts C["ruby_version"]'
163 RUBY_SUFFIX?=           # empty
164
165 RUBY_ARCH!=             ${_RUBY_CONFIG} 'puts C["target"]'
166 RUBY_NAME!=             ${_RUBY_CONFIG} 'puts C["ruby_install_name"]'
167
168 _RUBY_SYSLIBDIR!=       ${_RUBY_CONFIG} 'puts C["libdir"]'
169 _RUBY_SITEDIR!=         ${_RUBY_CONFIG} 'puts C["sitedir"]'
170 _RUBY_VENDORDIR!=       ${_RUBY_CONFIG} 'puts C["vendordir"]'
171 .else
172 RUBY?=                  ${LOCALBASE}/bin/${RUBY_NAME}
173
174 .if defined(RUBY_VER)
175 . if ${RUBY_VER} == 1.9
176 #
177 # Ruby 1.9
178 #
179 RUBY_RELVERSION=        1.9.3
180 RUBY_PORTREVISION=      2
181 RUBY_PORTEPOCH=         1
182 RUBY_PATCHLEVEL=        484
183
184 #
185 # PLIST_SUB helpers
186 #
187 RUBY19=                 ""
188 RUBY20=                 "@comment "
189 RUBY21=                 "@comment "
190
191 . elif ${RUBY_VER} == 2.0
192 #
193 # Ruby 2.0
194 #
195 RUBY_RELVERSION=        2.0.0
196 RUBY_PORTREVISION=      5
197 RUBY_PORTEPOCH=         1
198 RUBY_PATCHLEVEL=        353
199
200 #
201 # PLIST_SUB helpers
202 #
203 RUBY19=                 "@comment "
204 RUBY20=                 ""
205 RUBY21=                 "@comment "
206
207 . elif ${RUBY_VER} == 2.1
208 #
209 # Ruby 2.1
210 #
211 RUBY_RELVERSION=        2.1.1
212 RUBY_PORTREVISION=      1
213 RUBY_PORTEPOCH=         1
214 RUBY_PATCHLEVEL=        0
215
216 #
217 # PLIST_SUB helpers
218 #
219 RUBY19=                 "@comment "
220 RUBY20=                 "@comment "
221 RUBY21=                 ""
222
223 . else
224 #
225 # Other versions
226 #
227 IGNORE= Only ruby 1.9, 2.0 and 2.1 are supported
228 . endif
229 .endif # defined(RUBY_VER)
230
231 .if ${RUBY_PATCHLEVEL} == 0
232 RUBY_VERSION?=          ${RUBY_RELVERSION}
233 RUBY_DISTVERSION?=      ${RUBY_RELVERSION}
234 .else
235 RUBY_VERSION?=          ${RUBY_RELVERSION}.${RUBY_PATCHLEVEL}
236 RUBY_DISTVERSION?=      ${RUBY_RELVERSION}-p${RUBY_PATCHLEVEL}
237 .endif
238
239 RUBY_WRKSRC=            ${WRKDIR}/ruby-${RUBY_DISTVERSION}
240
241 RUBY_CONFIGURE_ARGS+=   --with-rubyhdrdir="${PREFIX}/include/ruby-${RUBY_VER}/" \
242                         --with-rubylibprefix="${PREFIX}/lib/ruby" \
243                         --docdir="${RUBY_DOCDIR}" \
244                         --with-soname=ruby${RUBY_SUFFIX}
245
246 CONFIGURE_TARGET?=      ${ARCH}-portbld-${OPSYS:tl}${OSREL:C/\..*//}
247
248 RUBY_ARCH?=             ${ARCH}-${OPSYS:tl}${OSREL:C/\..*//}
249 RUBY_NAME?=             ruby${RUBY_SUFFIX}
250
251 _RUBY_SYSLIBDIR?=       ${PREFIX}/lib
252 _RUBY_SITEDIR?=         ${_RUBY_SYSLIBDIR}/ruby/site_ruby
253 _RUBY_VENDORDIR?=       ${_RUBY_SYSLIBDIR}/ruby/vendor_ruby
254 .endif
255 #      defined(RUBY)
256
257 .if defined(LANG) && !empty(LANG)
258 GEM_ENV+=               LANG=${LANG}
259 .else
260 GEM_ENV+=               LANG=en_US.UTF-8
261 .endif
262
263 .if defined(LC_ALL) && !empty(LC_ALL)
264 GEM_ENV+=               LC_ALL=${LC_ALL}
265 .else
266 GEM_ENV+=               LC_ALL=en_US.UTF-8
267 .endif
268
269 .if defined(LC_CTYPE) && !empty(LC_CTYPE)
270 GEM_ENV+=               LC_CTYPE=${LC_CTYPE}
271 .else
272 GEM_ENV+=               LC_CTYPE=UTF-8
273 .endif
274
275 RUBY_DEFAULT_SUFFIX?=   ${RUBY_DEFAULT_VER:S/.//}
276
277 RUBY_DISTVERSION?=      ${RUBY_VERSION}
278 RUBY_PORTVERSION?=      ${RUBY_VERSION}
279 MASTER_SITE_SUBDIR_RUBY?=       ${RUBY_VER}
280 RUBY_DISTNAME?=         ruby-${RUBY_DISTVERSION}
281
282 RUBY_WRKSRC?=           ${WRKDIR}/${RUBY_DISTNAME}
283
284 RUBY_RELVERSION_CODE?=  ${RUBY_RELVERSION:S/.//g}
285 RUBY_VERSION_CODE?=     ${RUBY_VERSION:S/.//g}
286 RUBY_VER=               ${RUBY_VERSION:C/([[:digit:]]+\.[[:digit:]]+).*/\1/}
287 RUBY_SUFFIX=            ${RUBY_VER:S/.//}
288
289 RUBY_WITHOUT_SUFFIX?=   ${LOCALBASE}/bin/ruby
290 RUBY_WITH_SUFFIX?=      ${RUBY_WITHOUT_SUFFIX}${RUBY_SUFFIX}
291
292 RUBY_PKGNAMEPREFIX?=    ruby${RUBY_SUFFIX}-
293 RUBY_SHLIBVER?=         ${RUBY_VER:S/.//}
294
295 RUBY_CONFIGURE_ARGS+=   --program-prefix=""
296
297 DEPENDS_ARGS+=          RUBY_VER="${RUBY_VER}"
298
299 RUBY_CONFIGURE_ARGS+=   --program-suffix="${RUBY_SUFFIX}"
300
301 RUBY_MODNAME?=          ${PORTNAME}
302
303 # Commands
304 RUBY_RD2?=              ${LOCALBASE}/bin/rd2
305 RUBY_RDOC?=             ${LOCALBASE}/bin/rdoc${RUBY_VER:S/.//}
306
307 # Ports
308 RUBY_BASE_PORT?=        lang/ruby${RUBY_VER:S/.//}
309 RUBY_PORT?=             ${RUBY_BASE_PORT}
310 RUBY_RDTOOL_PORT?=      textproc/ruby-rdtool
311 RUBY_RDOC_PORT?=        textproc/ruby-rdoc
312 RUBY_ICONV_PORT?=       converters/ruby-iconv
313
314 # Depends
315 DEPEND_LIBRUBY?=        ${RUBY_NAME}.${RUBY_SHLIBVER}:${PORTSDIR}/${RUBY_PORT}
316 DEPEND_RUBY?=           ${RUBY}:${PORTSDIR}/${RUBY_PORT}
317 DEPEND_RUBY_RDTOOL?=    ${RUBY_RD2}:${PORTSDIR}/${RUBY_RDTOOL_PORT}
318 DEPEND_RUBY_ICONV=      ${RUBY_ARCHLIBDIR}/iconv.so:${PORTSDIR}/${RUBY_ICONV_PORT}
319
320 # Directories
321 RUBY_LIBDIR?=           ${_RUBY_SYSLIBDIR}/ruby/${RUBY_VER}
322 RUBY_ARCHLIBDIR?=       ${RUBY_LIBDIR}/${RUBY_ARCH}
323 RUBY_SITELIBDIR?=       ${_RUBY_SITEDIR}/${RUBY_VER}
324 RUBY_SITEARCHLIBDIR?=   ${RUBY_SITELIBDIR}/${RUBY_ARCH}
325 RUBY_VENDORLIBDIR?=     ${_RUBY_VENDORDIR}/${RUBY_VER}
326 RUBY_VENDORARCHLIBDIR?= ${RUBY_VENDORLIBDIR}/${RUBY_ARCH}
327 RUBY_DOCDIR?=           ${PREFIX}/share/doc/${RUBY_NAME}
328 RUBY_EXAMPLESDIR?=      ${PREFIX}/share/examples/${RUBY_NAME}
329 RUBY_RIDIR?=            ${PREFIX}/share/ri/${RUBY_VER}/system
330 RUBY_SITERIDIR?=        ${PREFIX}/share/ri/${RUBY_VER}/site
331 RUBY_MODDOCDIR?=        ${RUBY_DOCDIR}/${RUBY_MODNAME}
332 RUBY_MODEXAMPLESDIR?=   ${RUBY_EXAMPLESDIR}/${RUBY_MODNAME}
333 RUBY_ELISPDIR?=         ${PREFIX}/lib/ruby/elisp
334
335 # PLIST
336 PLIST_RUBY_DIRS=        RUBY_LIBDIR="${RUBY_LIBDIR}" \
337                         RUBY_ARCHLIBDIR="${RUBY_ARCHLIBDIR}" \
338                         RUBY_SITELIBDIR="${RUBY_SITELIBDIR}" \
339                         RUBY_SITEARCHLIBDIR="${RUBY_SITEARCHLIBDIR}" \
340                         RUBY_VENDORLIBDIR="${RUBY_VENDORLIBDIR}" \
341                         RUBY_VENDORARCHLIBDIR="${RUBY_VENDORARCHLIBDIR}" \
342                         RUBY_MODDOCDIR="${RUBY_MODDOCDIR}" \
343                         RUBY_MODEXAMPLESDIR="${RUBY_MODEXAMPLESDIR}" \
344                         RUBY_DOCDIR="${RUBY_DOCDIR}" \
345                         RUBY_EXAMPLESDIR="${RUBY_EXAMPLESDIR}" \
346                         RUBY_RIDIR="${RUBY_RIDIR}" \
347                         RUBY_SITERIDIR="${RUBY_SITERIDIR}" \
348                         RUBY_ELISPDIR="${RUBY_ELISPDIR}"
349
350 PLIST_SUB+=             ${PLIST_RUBY_DIRS:C,DIR="(${LOCALBASE}|${PREFIX})/,DIR=",} \
351                         RUBY_VERSION="${RUBY_VERSION}" \
352                         RUBY_VER="${RUBY_VER}" \
353                         RUBY_SHLIBVER="${RUBY_SHLIBVER}" \
354                         RUBY_ARCH="${RUBY_ARCH}" \
355                         RUBY_SUFFIX="${RUBY_SUFFIX}" \
356                         RUBY_NAME="${RUBY_NAME}" \
357                         RUBY_DEFAULT_SUFFIX="${RUBY_DEFAULT_SUFFIX}" \
358                         RUBY19=${RUBY19} \
359                         RUBY20=${RUBY20} \
360                         RUBY21=${RUBY21}
361
362 .if defined(USE_RUBY_RDOC)
363 MAKE_ENV+=      RUBY_RDOC=${RUBY_RDOC}
364 .endif
365
366 # require check
367 .if defined(RUBY_REQUIRE)
368 USE_RUBY=               yes
369
370 .if exists(${RUBY})
371 RUBY_PROVIDED!=         ${RUBY} -e '\
372         Ruby = ${RUBY_RELVERSION_CODE}; \
373         value = begin; ${RUBY_REQUIRE}; end and puts value'
374 .else
375 RUBY_PROVIDED=          "should be"     # the latest version is going to be installed
376 .endif
377
378 .if empty(RUBY_PROVIDED)
379 .undef RUBY_PROVIDED
380 .endif
381 .endif
382
383 # fix shebang lines
384 .if defined(RUBY_SHEBANG_FILES) && !empty(RUBY_SHEBANG_FILES)
385 USE_RUBY=               yes
386
387 post-patch:     ruby-shebang-patch
388
389 ruby-shebang-patch:
390         @cd ${WRKSRC}; for f in ${RUBY_SHEBANG_FILES}; do \
391         ${ECHO_MSG} "===>  Fixing the #! line of $$f"; \
392         TMPFILE=`mktemp -t rubyshebang`; \
393         cp $$f $$TMPFILE; \
394         ${AWK} 'BEGIN {flag = 0;}                                                               \
395                 {                                                                               \
396                         if (flag == 0) {                                                        \
397                                 if ($$0 ~ /^#!/) {                                              \
398                                         sub(/#!(.*\/)?(env[[:space:]]+)?ruby/, "#!${RUBY}", $$0);\
399                                         print $$0;                                              \
400                                 }                                                               \
401                                 else {                                                          \
402                                         print "#!${RUBY}";                                      \
403                                         print $$0;                                              \
404                                 }                                                               \
405                                 flag = 1;                                                       \
406                         } else {                                                                \
407                                 print $$0;                                                      \
408                         }                                                                       \
409                 }' $$TMPFILE > $$f; \
410         rm -f $$TMPFILE; \
411         done
412 .endif
413
414 .if ${PORT_OPTIONS:MDEBUG}
415 RUBY_FLAGS+=    -d
416 .endif
417
418 #
419 # RubyGems support
420 #
421 .if defined(USE_RUBYGEMS)
422
423 BUILD_DEPENDS+= ${RUBYGEMBIN}:${PORTSDIR}/devel/ruby-gems
424 RUN_DEPENDS+=   ${RUBYGEMBIN}:${PORTSDIR}/devel/ruby-gems
425
426 PKGNAMEPREFIX?= rubygem-
427 EXTRACT_SUFX=   .gem
428 EXTRACT_ONLY=
429 DIST_SUBDIR=    rubygem
430
431 EXTRACT_DEPENDS+=       ${RUBYGEMBIN}:${PORTSDIR}/devel/ruby-gems
432 GEMS_BASE_DIR=  lib/ruby/gems/${RUBY_VER}
433 GEMS_DIR=       ${GEMS_BASE_DIR}/gems
434 DOC_DIR=        ${GEMS_BASE_DIR}/doc
435 CACHE_DIR=      ${GEMS_BASE_DIR}/cache
436 SPEC_DIR=       ${GEMS_BASE_DIR}/specifications
437 GEM_NAME?=      ${PORTNAME}-${PORTVERSION}
438 GEM_LIB_DIR?=   ${GEMS_DIR}/${GEM_NAME}
439 GEM_DOC_DIR?=   ${DOC_DIR}/${GEM_NAME}
440 GEM_SPEC?=      ${SPEC_DIR}/${GEM_NAME}.gemspec
441 GEM_CACHE?=     ${CACHE_DIR}/${GEM_NAME}.gem
442
443 PLIST_SUB+=     PORTVERSION="${PORTVERSION}" \
444                 REV="${RUBY_GEM}" \
445                 GEMS_BASE_DIR="lib/ruby/gems/${RUBY_VER}" \
446                 GEMS_DIR="${GEMS_DIR}" \
447                 DOC_DIR="${DOC_DIR}" \
448                 CACHE_DIR="${CACHE_DIR}" \
449                 SPEC_DIR="${SPEC_DIR}" \
450                 PORT="${PORTNAME}-${PORTVERSION}" \
451                 GEM_NAME="${GEM_NAME}" \
452                 GEM_LIB_DIR="${GEM_LIB_DIR}" \
453                 GEM_DOC_DIR="${GEM_DOC_DIR}" \
454                 GEM_SPEC="${GEM_SPEC}" \
455                 GEM_CACHE="${GEM_CACHE}" \
456                 EXTRACT_SUFX="${EXTRACT_SUFX}"
457
458 RUBYGEMBIN=     ${LOCALBASE}/bin/gem${RUBY_VER:S/.//}
459
460 . if defined(DISTFILES)
461 GEMFILES=       ${DISTFILES:C/:[^:]+$//}
462 . else
463 GEMFILES=       ${DISTNAME}${EXTRACT_SUFX}
464 . endif
465
466 RUBYGEM_ARGS=-l --no-update-sources --no-ri --install-dir ${STAGEDIR}${PREFIX}/lib/ruby/gems/${RUBY_VER} --ignore-dependencies --bindir=${STAGEDIR}${PREFIX}/bin
467 GEM_ENV+=       RB_USER_INSTALL=yes
468 .if defined(NOPORTDOCS)
469 RUBYGEM_ARGS+=  --no-rdoc
470 .endif
471
472 do-extract:
473         @${SETENV} ${GEM_ENV} ${RUBYGEMBIN} unpack --target=${WRKDIR} ${DISTDIR}/${DIST_SUBDIR}/${GEMFILES}
474         @${TAR} -xOzf ${DISTDIR}/${DIST_SUBDIR}/${GEMFILES} metadata.gz | ${GZCAT} > ${BUILD_WRKSRC}/${GEMFILES}spec
475
476 do-build:
477         @(cd ${BUILD_WRKSRC}; if ! ${SETENV} ${GEM_ENV} ${RUBYGEMBIN} build --force ${GEMFILES}spec ; then \
478                 if [ -n "${BUILD_FAIL_MESSAGE}" ] ; then \
479                         ${ECHO_MSG} "===> Compilation failed unexpectedly."; \
480                         (${ECHO_CMD} "${BUILD_FAIL_MESSAGE}") | ${FMT} 75 79 ; \
481                         fi; \
482                 ${FALSE}; \
483                 fi)
484
485 do-install:
486         @(cd ${BUILD_WRKSRC}; ${SETENV} ${GEM_ENV} ${RUBYGEMBIN} install ${RUBYGEM_ARGS} ${GEMFILES} -- --build-args ${CONFIGURE_ARGS})
487
488 . if defined(RUBYGEM_AUTOPLIST)
489 .  if !target(post-install-script)
490 post-install-script:
491         @${ECHO} ${GEM_CACHE} >> ${TMPPLIST}
492         @${ECHO} ${GEM_SPEC} >> ${TMPPLIST}
493 .if !defined(NOPORTDOCS)
494         @${FIND} -ds ${STAGEDIR}${PREFIX}/${GEM_DOC_DIR} -type f -print | ${SED} -E -e \
495                 's,^${STAGEDIR}${PREFIX}/?,,' >> ${TMPPLIST}
496         @${FIND} -ds ${STAGEDIR}${PREFIX}/${GEM_DOC_DIR} -type d -print | ${SED} -E -e \
497                 's,^${STAGEDIR}${PREFIX}/?,@dirrm ,' >> ${TMPPLIST}
498 .endif
499         @${FIND} -ds ${STAGEDIR}${PREFIX}/${GEM_LIB_DIR} -type f -print | ${SED} -E -e \
500                 's,^${STAGEDIR}${PREFIX}/?,,' >> ${TMPPLIST}
501         @${FIND} -ds ${STAGEDIR}${PREFIX}/${GEM_LIB_DIR} -type d -print | ${SED} -E -e \
502                 's,^${STAGEDIR}${PREFIX}/?,@dirrm ,' >> ${TMPPLIST}
503         @${ECHO_CMD} "@unexec rmdir %D/${GEMS_DIR} 2>/dev/null || true" >> ${TMPPLIST}
504 .if !defined(NOPORTDOCS)
505         @${ECHO_CMD} "@unexec rmdir %D/${DOC_DIR} 2>/dev/null || true" >> ${TMPPLIST}
506 .endif
507         @${ECHO_CMD} "@unexec rmdir %D/${CACHE_DIR} 2>/dev/null || true" >> ${TMPPLIST}
508         @${ECHO_CMD} "@unexec rmdir %D/${SPEC_DIR} 2>/dev/null || true" >> ${TMPPLIST}
509         @${ECHO_CMD} "@unexec rmdir %D/${GEMS_BASE_DIR} 2>/dev/null || true" >> ${TMPPLIST}
510         @${ECHO_CMD} "@unexec rmdir %D/lib/ruby/gems 2>/dev/null || true" >> ${TMPPLIST}
511         @${ECHO_CMD} "@unexec rmdir %D/lib/ruby 2>/dev/null || true" >> ${TMPPLIST}
512 .  endif
513 . endif
514
515 .endif # USE_RUBYGEMS
516
517 #
518 # extconf.rb support
519 #
520 .if defined(USE_RUBY_EXTCONF)
521 USE_RUBY=               yes
522
523 RUBY_EXTCONF?=          extconf.rb
524 CONFIGURE_ARGS+=        --with-opt-dir="${LOCALBASE}"
525
526 do-configure:   ruby-extconf-configure
527
528 ruby-extconf-configure:
529 .if defined(RUBY_EXTCONF_SUBDIRS)
530 .for d in ${RUBY_EXTCONF_SUBDIRS}
531         @${ECHO_MSG} "===>  Running ${RUBY_EXTCONF} in ${d} to configure"
532         @cd ${CONFIGURE_WRKSRC}/${d}; \
533         ${SETENV} ${CONFIGURE_ENV} ${RUBY} ${RUBY_FLAGS} ${RUBY_EXTCONF} ${CONFIGURE_ARGS}
534 .endfor
535 .else
536         @${ECHO_MSG} "===>  Running ${RUBY_EXTCONF} to configure"
537         @cd ${CONFIGURE_WRKSRC}; \
538         ${SETENV} ${CONFIGURE_ENV} ${RUBY} ${RUBY_FLAGS} ${RUBY_EXTCONF} ${CONFIGURE_ARGS}
539 .endif
540 .endif
541
542 #
543 # setup.rb support
544 #
545 .if defined(USE_RUBY_SETUP)
546 RUBY_SETUP?=            setup.rb
547
548 do-configure:   ruby-setup-configure
549
550 ruby-setup-configure:
551         @${ECHO_MSG} "===>  Running ${RUBY_SETUP} to configure"
552         @cd ${BUILD_WRKSRC}; \
553         ${SETENV} ${CONFIGURE_ENV} ${RUBY} ${RUBY_FLAGS} ${RUBY_SETUP} config ${CONFIGURE_ARGS}
554
555 do-build:       ruby-setup-build
556
557 ruby-setup-build:
558         @${ECHO_MSG} "===>  Running ${RUBY_SETUP} to build"
559         @cd ${BUILD_WRKSRC}; \
560         ${SETENV} ${MAKE_ENV} ${RUBY} ${RUBY_FLAGS} ${RUBY_SETUP} setup
561
562 do-install:     ruby-setup-install
563
564 ruby-setup-install:
565         @${ECHO_MSG} "===>  Running ${RUBY_SETUP} to install"
566         @cd ${INSTALL_WRKSRC}; \
567         ${SETENV} ${MAKE_ENV} ${RUBY} ${RUBY_FLAGS} ${RUBY_SETUP} install --prefix=${STAGEDIR}
568 .endif
569
570 .if defined(USE_LIBRUBY)
571 LIB_DEPENDS+=           ${DEPEND_LIBRUBY}
572 .endif
573
574 .if defined(USE_RUBY)
575 .if !defined(RUBY_NO_BUILD_DEPENDS)
576 EXTRACT_DEPENDS+=       ${DEPEND_RUBY}
577 PATCH_DEPENDS+=         ${DEPEND_RUBY}
578 BUILD_DEPENDS+=         ${DEPEND_RUBY}
579 .endif
580 .if !defined(RUBY_NO_RUN_DEPENDS)
581 RUN_DEPENDS+=           ${DEPEND_RUBY}
582 .endif
583 .endif
584
585 .if defined(USE_RUBY_FEATURES)
586
587 _use=   ${USE_RUBY_FEATURES:Miconv}
588 .if !empty(_use)
589 .if (${RUBY_VER} == 1.9)
590 BUILD_DEPENDS+=         ${DEPEND_RUBY_ICONV}
591 RUN_DEPENDS+=           ${DEPEND_RUBY_ICONV}
592 .endif
593 .endif
594
595 .undef _use
596 .endif
597
598 .if defined(USE_RAKE)
599 BUILD_DEPENDS+=         ${LOCALBASE}/bin/rake:${PORTSDIR}/devel/rubygem-rake
600 RAKE_BIN=       ${LOCALBASE}/bin/rake
601 .endif
602
603 # documents
604
605 RUBY_NO_RD_HTML=        yes
606
607 .if defined(RUBY_RD_HTML)
608 .undef RUBY_NO_RD_HTML
609 .endif
610
611 .if defined(NOPORTDOCS)
612 RUBY_NO_RD_HTML=        yes
613 .endif
614
615 .if defined(RUBY_RD_FILES) && !defined(RUBY_NO_RD_HTML)
616 USE_RUBY_RDTOOL=        yes
617
618 RUBY_RD_HTML_FILES=     ${RUBY_RD_FILES:S/.rb$//:S/.rd././:S/.rd$//:S/$/.html/}
619
620 PLIST_SUB+=             RUBY_RD_HTML_FILES=""
621
622 pre-install:    ruby-rd-build
623
624 ruby-rd-build:
625 .if !empty(RUBY_RD_FILES)
626         @${ECHO_MSG} "===>  Generating HTML documents from RD documents"
627         @cd ${WRKSRC}; for rd in ${RUBY_RD_FILES}; do \
628                 html=$$(echo $$rd | ${SED} 's/\.rb$$//;s/\.rd\././;s/\.rd$$//').html; \
629                 ${ECHO_MSG} "${RUBY_RD2} $$rd > $$html"; \
630                 ${RUBY_RD2} $$rd > $$html; \
631         done
632 .else
633         @${DO_NADA}
634 .endif
635
636 .else
637 RUBY_RD_HTML_FILES=     # empty
638
639 PLIST_SUB+=             RUBY_RD_HTML_FILES="@comment "
640 .endif
641
642 .if !defined(NOPORTDOCS) && defined(USE_RUBY_RDTOOL)
643 BUILD_DEPENDS+=         ${DEPEND_RUBY_RDTOOL}
644 .endif
645
646 .endif