Sync Mk with ports
[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: Mk/bsd.ruby.mk 335012 2013-11-27 13:21:30Z swills $
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"; rescue LoadError; puts "error"; end'
156 .if !empty(_RUBY_TEST)
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 = Config::CONFIG' -e
161
162 RUBY_VERSION!=          ${_RUBY_CONFIG} 'puts 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=      0
181 RUBY_PORTEPOCH=         1
182 RUBY_PATCHLEVEL=        484
183
184 RUBY_VERSION?=          ${RUBY_RELVERSION}.${RUBY_PATCHLEVEL}
185 RUBY_DISTVERSION?=      ${RUBY_RELVERSION}-p${RUBY_PATCHLEVEL}
186
187 RUBY_WRKSRC=            ${WRKDIR}/ruby-${RUBY_DISTVERSION}
188
189 GEM_ENV+=               LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
190
191 RUBY_CONFIGURE_ARGS+=   --with-rubyhdrdir="${PREFIX}/include/ruby-1.9/" \
192                         --with-rubylibprefix="${PREFIX}/lib/ruby" \
193                         --docdir="${RUBY_DOCDIR}" \
194                         --with-soname=ruby19
195
196 #
197 # PLIST_SUB helpers
198 #
199 RUBY19=                 ""
200 RUBY20=                 "@comment "
201
202 . elif ${RUBY_VER} == 2.0
203 #
204 # Ruby 2.0
205 #
206 RUBY_RELVERSION=        2.0.0
207 RUBY_PORTREVISION=      1
208 RUBY_PORTEPOCH=         1
209 RUBY_PATCHLEVEL=        353
210
211 RUBY_VERSION?=          ${RUBY_RELVERSION}.${RUBY_PATCHLEVEL}
212 RUBY_DISTVERSION?=      ${RUBY_RELVERSION}-p${RUBY_PATCHLEVEL}
213
214 RUBY_WRKSRC=            ${WRKDIR}/ruby-${RUBY_DISTVERSION}
215
216 GEM_ENV?=               LC_CTYPE=UTF-8
217
218 RUBY_CONFIGURE_ARGS+=   --with-rubyhdrdir="${PREFIX}/include/ruby-2.0/" \
219                         --with-rubylibprefix="${PREFIX}/lib/ruby" \
220                         --docdir="${RUBY_DOCDIR}" \
221                         --with-soname=ruby20
222
223 #
224 # PLIST_SUB helpers
225 #
226 RUBY19=                 "@comment "
227 RUBY20=                 ""
228
229
230 . else
231 #
232 # Other versions
233 #
234 IGNORE= Only ruby 1.9 and 2.0 are supported
235 . endif
236 .endif # defined(RUBY_VER)
237
238 CONFIGURE_TARGET?=      ${ARCH}-dports-${OPSYS:tl}${OSREL:C/\..*//}
239
240 RUBY_ARCH?=             ${ARCH}-${OPSYS:tl}${OSREL:C/\..*//}
241 RUBY_NAME?=             ruby${RUBY_SUFFIX}
242
243 _RUBY_SYSLIBDIR?=       ${PREFIX}/lib
244 _RUBY_SITEDIR?=         ${_RUBY_SYSLIBDIR}/ruby/site_ruby
245 _RUBY_VENDORDIR?=       ${_RUBY_SYSLIBDIR}/ruby/vendor_ruby
246 .endif
247 #      defined(RUBY)
248
249 RUBY_DEFAULT_SUFFIX?=   ${RUBY_DEFAULT_VER:S/.//}
250
251 RUBY_DISTVERSION?=      ${RUBY_VERSION}
252 RUBY_PORTVERSION?=      ${RUBY_VERSION}
253 MASTER_SITE_SUBDIR_RUBY?=       ${RUBY_VER}
254 RUBY_DISTNAME?=         ruby-${RUBY_DISTVERSION}
255
256 RUBY_WRKSRC?=           ${WRKDIR}/${RUBY_DISTNAME}
257
258 RUBY_RELVERSION_CODE?=  ${RUBY_RELVERSION:S/.//g}
259 RUBY_VERSION_CODE?=     ${RUBY_VERSION:S/.//g}
260 RUBY_VER=               ${RUBY_VERSION:C/([[:digit:]]+\.[[:digit:]]+).*/\1/}
261 RUBY_SUFFIX=            ${RUBY_VER:S/.//}
262
263 RUBY_WITHOUT_SUFFIX?=   ${LOCALBASE}/bin/ruby
264 RUBY_WITH_SUFFIX?=      ${RUBY_WITHOUT_SUFFIX}${RUBY_SUFFIX}
265
266 RUBY_PKGNAMEPREFIX?=    ruby${RUBY_SUFFIX}-
267 RUBY_SHLIBVER?=         ${RUBY_VER:S/.//}
268
269 RUBY_CONFIGURE_ARGS+=   --program-prefix=""
270
271 DEPENDS_ARGS+=          RUBY_VER="${RUBY_VER}"
272
273 RUBY_CONFIGURE_ARGS+=   --program-suffix="${RUBY_SUFFIX}"
274
275 RUBY_MODNAME?=          ${PORTNAME}
276
277 # Commands
278 RUBY_RD2?=              ${LOCALBASE}/bin/rd2
279 RUBY_RDOC?=             ${LOCALBASE}/bin/rdoc${RUBY_VER:S/.//}
280
281 # Ports
282 RUBY_BASE_PORT?=        lang/ruby${RUBY_VER:S/.//}
283 RUBY_PORT?=             ${RUBY_BASE_PORT}
284 RUBY_RDTOOL_PORT?=      textproc/ruby-rdtool
285 RUBY_RDOC_PORT?=        textproc/ruby-rdoc
286 RUBY_ICONV_PORT?=       converters/ruby-iconv
287
288 # Depends
289 DEPEND_LIBRUBY?=        ${RUBY_NAME}.${RUBY_SHLIBVER}:${PORTSDIR}/${RUBY_PORT}
290 DEPEND_RUBY?=           ${RUBY}:${PORTSDIR}/${RUBY_PORT}
291 DEPEND_RUBY_RDTOOL?=    ${RUBY_RD2}:${PORTSDIR}/${RUBY_RDTOOL_PORT}
292 DEPEND_RUBY_ICONV=      ${RUBY_ARCHLIBDIR}/iconv.so:${PORTSDIR}/${RUBY_ICONV_PORT}
293
294 # Directories
295 RUBY_LIBDIR?=           ${_RUBY_SYSLIBDIR}/ruby/${RUBY_VER}
296 RUBY_ARCHLIBDIR?=       ${RUBY_LIBDIR}/${RUBY_ARCH}
297 RUBY_SITELIBDIR?=       ${_RUBY_SITEDIR}/${RUBY_VER}
298 RUBY_SITEARCHLIBDIR?=   ${RUBY_SITELIBDIR}/${RUBY_ARCH}
299 RUBY_VENDORLIBDIR?=     ${_RUBY_VENDORDIR}/${RUBY_VER}
300 RUBY_VENDORARCHLIBDIR?= ${RUBY_VENDORLIBDIR}/${RUBY_ARCH}
301 RUBY_DOCDIR?=           ${PREFIX}/share/doc/${RUBY_NAME}
302 RUBY_EXAMPLESDIR?=      ${PREFIX}/share/examples/${RUBY_NAME}
303 RUBY_RIDIR?=            ${PREFIX}/share/ri/${RUBY_VER}/system
304 RUBY_SITERIDIR?=        ${PREFIX}/share/ri/${RUBY_VER}/site
305 RUBY_MODDOCDIR?=        ${RUBY_DOCDIR}/${RUBY_MODNAME}
306 RUBY_MODEXAMPLESDIR?=   ${RUBY_EXAMPLESDIR}/${RUBY_MODNAME}
307 RUBY_ELISPDIR?=         ${PREFIX}/lib/ruby/elisp
308
309 # PLIST
310 PLIST_RUBY_DIRS=        RUBY_LIBDIR="${RUBY_LIBDIR}" \
311                         RUBY_ARCHLIBDIR="${RUBY_ARCHLIBDIR}" \
312                         RUBY_SITELIBDIR="${RUBY_SITELIBDIR}" \
313                         RUBY_SITEARCHLIBDIR="${RUBY_SITEARCHLIBDIR}" \
314                         RUBY_VENDORLIBDIR="${RUBY_VENDORLIBDIR}" \
315                         RUBY_VENDORARCHLIBDIR="${RUBY_VENDORARCHLIBDIR}" \
316                         RUBY_MODDOCDIR="${RUBY_MODDOCDIR}" \
317                         RUBY_MODEXAMPLESDIR="${RUBY_MODEXAMPLESDIR}" \
318                         RUBY_DOCDIR="${RUBY_DOCDIR}" \
319                         RUBY_EXAMPLESDIR="${RUBY_EXAMPLESDIR}" \
320                         RUBY_RIDIR="${RUBY_RIDIR}" \
321                         RUBY_SITERIDIR="${RUBY_SITERIDIR}" \
322                         RUBY_ELISPDIR="${RUBY_ELISPDIR}"
323
324 PLIST_SUB+=             ${PLIST_RUBY_DIRS:C,DIR="(${LOCALBASE}|${PREFIX})/,DIR=",} \
325                         RUBY_VERSION="${RUBY_VERSION}" \
326                         RUBY_VER="${RUBY_VER}" \
327                         RUBY_SHLIBVER="${RUBY_SHLIBVER}" \
328                         RUBY_ARCH="${RUBY_ARCH}" \
329                         RUBY_SUFFIX="${RUBY_SUFFIX}" \
330                         RUBY_NAME="${RUBY_NAME}" \
331                         RUBY_DEFAULT_SUFFIX="${RUBY_DEFAULT_SUFFIX}" \
332                         RUBY19=${RUBY19} \
333                         RUBY20=${RUBY20} \
334
335 .if defined(USE_RUBY_RDOC)
336 MAKE_ENV+=      RUBY_RDOC=${RUBY_RDOC}
337 .endif
338
339 # require check
340 .if defined(RUBY_REQUIRE)
341 USE_RUBY=               yes
342
343 .if exists(${RUBY})
344 RUBY_PROVIDED!=         ${RUBY} -e '\
345         Ruby = ${RUBY_RELVERSION_CODE}; \
346         value = begin; ${RUBY_REQUIRE}; end and puts value'
347 .else
348 RUBY_PROVIDED=          "should be"     # the latest version is going to be installed
349 .endif
350
351 .if empty(RUBY_PROVIDED)
352 .undef RUBY_PROVIDED
353 .endif
354 .endif
355
356 # fix shebang lines
357 .if defined(RUBY_SHEBANG_FILES) && !empty(RUBY_SHEBANG_FILES)
358 USE_RUBY=               yes
359
360 post-patch:     ruby-shebang-patch
361
362 ruby-shebang-patch:
363         @cd ${WRKSRC}; for f in ${RUBY_SHEBANG_FILES}; do \
364         ${ECHO_MSG} "===>  Fixing the #! line of $$f"; \
365         TMPFILE=`mktemp -t rubyshebang`; \
366         cp $$f $$TMPFILE; \
367         ${AWK} 'BEGIN {flag = 0;}                                                               \
368                 {                                                                               \
369                         if (flag == 0) {                                                        \
370                                 if ($$0 ~ /^#!/) {                                              \
371                                         sub(/#!(.*\/)?(env[[:space:]]+)?ruby/, "#!${RUBY}", $$0);\
372                                         print $$0;                                              \
373                                 }                                                               \
374                                 else {                                                          \
375                                         print "#!${RUBY}";                                      \
376                                         print $$0;                                              \
377                                 }                                                               \
378                                 flag = 1;                                                       \
379                         } else {                                                                \
380                                 print $$0;                                                      \
381                         }                                                                       \
382                 }' $$TMPFILE > $$f; \
383         rm -f $$TMPFILE; \
384         done
385 .endif
386
387 .if ${PORT_OPTIONS:MDEBUG}
388 RUBY_FLAGS+=    -d
389 .endif
390
391 #
392 # RubyGems support
393 #
394 .if defined(USE_RUBYGEMS)
395
396 BUILD_DEPENDS+= ${RUBYGEMBIN}:${PORTSDIR}/devel/ruby-gems
397 RUN_DEPENDS+=   ${RUBYGEMBIN}:${PORTSDIR}/devel/ruby-gems
398
399 PKGNAMEPREFIX?= rubygem-
400 EXTRACT_SUFX=   .gem
401 EXTRACT_ONLY=
402 DIST_SUBDIR=    rubygem
403
404 EXTRACT_DEPENDS+=       ${RUBYGEMBIN}:${PORTSDIR}/devel/ruby-gems
405 GEMS_BASE_DIR=  lib/ruby/gems/${RUBY_VER}
406 GEMS_DIR=       ${GEMS_BASE_DIR}/gems
407 DOC_DIR=        ${GEMS_BASE_DIR}/doc
408 CACHE_DIR=      ${GEMS_BASE_DIR}/cache
409 SPEC_DIR=       ${GEMS_BASE_DIR}/specifications
410 GEM_NAME?=      ${PORTNAME}-${PORTVERSION}
411 GEM_LIB_DIR?=   ${GEMS_DIR}/${GEM_NAME}
412 GEM_DOC_DIR?=   ${DOC_DIR}/${GEM_NAME}
413 GEM_SPEC?=      ${SPEC_DIR}/${GEM_NAME}.gemspec
414 GEM_CACHE?=     ${CACHE_DIR}/${GEM_NAME}.gem
415
416 PLIST_SUB+=     PORTVERSION="${PORTVERSION}" \
417                 REV="${RUBY_GEM}" \
418                 GEMS_BASE_DIR="lib/ruby/gems/${RUBY_VER}" \
419                 GEMS_DIR="${GEMS_DIR}" \
420                 DOC_DIR="${DOC_DIR}" \
421                 CACHE_DIR="${CACHE_DIR}" \
422                 SPEC_DIR="${SPEC_DIR}" \
423                 PORT="${PORTNAME}-${PORTVERSION}" \
424                 GEM_NAME="${GEM_NAME}" \
425                 GEM_LIB_DIR="${GEM_LIB_DIR}" \
426                 GEM_DOC_DIR="${GEM_DOC_DIR}" \
427                 GEM_SPEC="${GEM_SPEC}" \
428                 GEM_CACHE="${GEM_CACHE}" \
429                 EXTRACT_SUFX="${EXTRACT_SUFX}"
430
431 RUBYGEMBIN=     ${LOCALBASE}/bin/gem${RUBY_VER:S/.//}
432
433 . if defined(DISTFILES)
434 GEMFILES=       ${DISTFILES:C/:[^:]+$//}
435 . else
436 GEMFILES=       ${DISTNAME}${EXTRACT_SUFX}
437 . endif
438
439 .if defined(NO_STAGE)
440 RUBYGEM_ARGS=-l --no-update-sources --no-ri --install-dir ${PREFIX}/lib/ruby/gems/${RUBY_VER}
441 .else
442 RUBYGEM_ARGS=-l --no-update-sources --no-ri --install-dir ${STAGEDIR}${PREFIX}/lib/ruby/gems/${RUBY_VER} --ignore-dependencies --bindir=${STAGEDIR}${PREFIX}/bin
443 .endif
444 .if defined(NOPORTDOCS)
445 RUBYGEM_ARGS+=  --no-rdoc
446 .endif
447
448 do-extract:
449         @${SETENV} ${GEM_ENV} ${RUBYGEMBIN} unpack --target=${WRKDIR} ${DISTDIR}/${DIST_SUBDIR}/${GEMFILES}
450         @${TAR} -xOzf ${DISTDIR}/${DIST_SUBDIR}/${GEMFILES} metadata.gz | ${GZCAT} > ${BUILD_WRKSRC}/${GEMFILES}spec
451
452 do-build:
453         @(cd ${BUILD_WRKSRC}; if ! ${SETENV} ${GEM_ENV} ${RUBYGEMBIN} build --force ${GEMFILES}spec ; then \
454                 if [ -n "${BUILD_FAIL_MESSAGE}" ] ; then \
455                         ${ECHO_MSG} "===> Compilation failed unexpectedly."; \
456                         (${ECHO_CMD} "${BUILD_FAIL_MESSAGE}") | ${FMT} 75 79 ; \
457                         fi; \
458                 ${FALSE}; \
459                 fi)
460
461 do-install:
462         @(cd ${BUILD_WRKSRC}; ${SETENV} ${GEM_ENV} ${RUBYGEMBIN} install ${RUBYGEM_ARGS} ${GEMFILES} -- --build-args ${CONFIGURE_ARGS})
463
464 . if defined(RUBYGEM_AUTOPLIST)
465 .  if !target(post-install-script)
466 post-install-script:
467         @${ECHO} ${GEM_CACHE} >> ${TMPPLIST}
468         @${ECHO} ${GEM_SPEC} >> ${TMPPLIST}
469 .if !defined(NOPORTDOCS)
470         @${FIND} -ds ${STAGEDIR}${PREFIX}/${GEM_DOC_DIR} -type f -print | ${SED} -E -e \
471                 's,^${STAGEDIR}${PREFIX}/?,,' >> ${TMPPLIST}
472         @${FIND} -ds ${STAGEDIR}${PREFIX}/${GEM_DOC_DIR} -type d -print | ${SED} -E -e \
473                 's,^${STAGEDIR}${PREFIX}/?,@dirrm ,' >> ${TMPPLIST}
474 .endif
475         @${FIND} -ds ${STAGEDIR}${PREFIX}/${GEM_LIB_DIR} -type f -print | ${SED} -E -e \
476                 's,^${STAGEDIR}${PREFIX}/?,,' >> ${TMPPLIST}
477         @${FIND} -ds ${STAGEDIR}${PREFIX}/${GEM_LIB_DIR} -type d -print | ${SED} -E -e \
478                 's,^${STAGEDIR}${PREFIX}/?,@dirrm ,' >> ${TMPPLIST}
479         @${ECHO_CMD} "@unexec rmdir %D/${GEMS_DIR} 2>/dev/null || true" >> ${TMPPLIST}
480 .if !defined(NOPORTDOCS)
481         @${ECHO_CMD} "@unexec rmdir %D/${DOC_DIR} 2>/dev/null || true" >> ${TMPPLIST}
482 .endif
483         @${ECHO_CMD} "@unexec rmdir %D/${CACHE_DIR} 2>/dev/null || true" >> ${TMPPLIST}
484         @${ECHO_CMD} "@unexec rmdir %D/${SPEC_DIR} 2>/dev/null || true" >> ${TMPPLIST}
485         @${ECHO_CMD} "@unexec rmdir %D/${GEMS_BASE_DIR} 2>/dev/null || true" >> ${TMPPLIST}
486         @${ECHO_CMD} "@unexec rmdir %D/lib/ruby/gems 2>/dev/null || true" >> ${TMPPLIST}
487         @${ECHO_CMD} "@unexec rmdir %D/lib/ruby 2>/dev/null || true" >> ${TMPPLIST}
488 .  endif
489 . endif
490
491 .endif # USE_RUBYGEMS
492
493 #
494 # extconf.rb support
495 #
496 .if defined(USE_RUBY_EXTCONF)
497 USE_RUBY=               yes
498
499 RUBY_EXTCONF?=          extconf.rb
500 CONFIGURE_ARGS+=        --with-opt-dir="${LOCALBASE}"
501
502 do-configure:   ruby-extconf-configure
503
504 ruby-extconf-configure:
505 .if defined(RUBY_EXTCONF_SUBDIRS)
506 .for d in ${RUBY_EXTCONF_SUBDIRS}
507         @${ECHO_MSG} "===>  Running ${RUBY_EXTCONF} in ${d} to configure"
508         @cd ${CONFIGURE_WRKSRC}/${d}; \
509         ${SETENV} ${CONFIGURE_ENV} ${RUBY} ${RUBY_FLAGS} ${RUBY_EXTCONF} ${CONFIGURE_ARGS}
510 .endfor
511 .else
512         @${ECHO_MSG} "===>  Running ${RUBY_EXTCONF} to configure"
513         @cd ${CONFIGURE_WRKSRC}; \
514         ${SETENV} ${CONFIGURE_ENV} ${RUBY} ${RUBY_FLAGS} ${RUBY_EXTCONF} ${CONFIGURE_ARGS}
515 .endif
516 .endif
517
518 #
519 # setup.rb support
520 #
521 .if defined(USE_RUBY_SETUP)
522 RUBY_SETUP?=            setup.rb
523
524 do-configure:   ruby-setup-configure
525
526 ruby-setup-configure:
527         @${ECHO_MSG} "===>  Running ${RUBY_SETUP} to configure"
528         @cd ${BUILD_WRKSRC}; \
529         ${SETENV} ${CONFIGURE_ENV} ${RUBY} ${RUBY_FLAGS} ${RUBY_SETUP} config ${CONFIGURE_ARGS}
530
531 do-build:       ruby-setup-build
532
533 ruby-setup-build:
534         @${ECHO_MSG} "===>  Running ${RUBY_SETUP} to build"
535         @cd ${BUILD_WRKSRC}; \
536         ${SETENV} ${MAKE_ENV} ${RUBY} ${RUBY_FLAGS} ${RUBY_SETUP} setup
537
538 do-install:     ruby-setup-install
539
540 ruby-setup-install:
541         @${ECHO_MSG} "===>  Running ${RUBY_SETUP} to install"
542         @cd ${INSTALL_WRKSRC}; \
543         ${SETENV} ${MAKE_ENV} ${RUBY} ${RUBY_FLAGS} ${RUBY_SETUP} install
544 .endif
545
546 .if defined(USE_LIBRUBY)
547 LIB_DEPENDS+=           ${DEPEND_LIBRUBY}
548 .endif
549
550 .if defined(USE_RUBY)
551 .if !defined(RUBY_NO_BUILD_DEPENDS)
552 EXTRACT_DEPENDS+=       ${DEPEND_RUBY}
553 PATCH_DEPENDS+=         ${DEPEND_RUBY}
554 BUILD_DEPENDS+=         ${DEPEND_RUBY}
555 .endif
556 .if !defined(RUBY_NO_RUN_DEPENDS)
557 RUN_DEPENDS+=           ${DEPEND_RUBY}
558 .endif
559 .endif
560
561 .if defined(USE_RUBY_FEATURES)
562
563 _use=   ${USE_RUBY_FEATURES:Miconv}
564 .if !empty(_use)
565 .if (${RUBY_VER} == 1.9)
566 BUILD_DEPENDS+=         ${DEPEND_RUBY_ICONV}
567 RUN_DEPENDS+=           ${DEPEND_RUBY_ICONV}
568 .endif
569 .endif
570
571 .undef _use
572 .endif
573
574 .if defined(USE_RAKE)
575 BUILD_DEPENDS+=         ${LOCALBASE}/bin/rake:${PORTSDIR}/devel/rubygem-rake
576 RAKE_BIN=       ${LOCALBASE}/bin/rake
577 .endif
578
579 # documents
580
581 RUBY_NO_RD_HTML=        yes
582
583 .if defined(RUBY_RD_HTML)
584 .undef RUBY_NO_RD_HTML
585 .endif
586
587 .if defined(NOPORTDOCS)
588 RUBY_NO_RD_HTML=        yes
589 .endif
590
591 .if defined(RUBY_RD_FILES) && !defined(RUBY_NO_RD_HTML)
592 USE_RUBY_RDTOOL=        yes
593
594 RUBY_RD_HTML_FILES=     ${RUBY_RD_FILES:S/.rb$//:S/.rd././:S/.rd$//:S/$/.html/}
595
596 PLIST_SUB+=             RUBY_RD_HTML_FILES=""
597
598 pre-install:    ruby-rd-build
599
600 ruby-rd-build:
601 .if !empty(RUBY_RD_FILES)
602         @${ECHO_MSG} "===>  Generating HTML documents from RD documents"
603         @cd ${WRKSRC}; for rd in ${RUBY_RD_FILES}; do \
604                 html=$$(echo $$rd | ${SED} 's/\.rb$$//;s/\.rd\././;s/\.rd$$//').html; \
605                 ${ECHO_MSG} "${RUBY_RD2} $$rd > $$html"; \
606                 ${RUBY_RD2} $$rd > $$html; \
607         done
608 .else
609         @${DO_NADA}
610 .endif
611
612 .else
613 RUBY_RD_HTML_FILES=     # empty
614
615 PLIST_SUB+=             RUBY_RD_HTML_FILES="@comment "
616 .endif
617
618 .if !defined(NOPORTDOCS) && defined(USE_RUBY_RDTOOL)
619 BUILD_DEPENDS+=         ${DEPEND_RUBY_RDTOOL}
620 .endif
621
622 .endif