Fixup fromcvs/togit conversion
[minix-pkgsrc.git] / lang / ruby / gem.mk
blob54b94f7ce06e41bc46845fd450914d11a4ff58b2
1 # $NetBSD: gem.mk,v 1.19 2013/04/02 15:22:39 taca Exp $
3 # This Makefile fragment is intended to be included by packages that build
4 # and install Ruby gems.
6 # Package-settable variables:
8 # RUBYGEMS_REQD
9 # Minimum version of required rubygems. Ruby base packages contain:
11 # ruby18-base: none
12 # ruby193-base: 1.8.11
13 # ruby200-base: 2.0.0
15 # If newer version of rubygems is resuiqred, set RUBYGEMS_REQD to
16 # minimum version.
18 # Default: not defined
20 # OVERRIDE_GEMSPEC
21 # Fix version of depending gem or modify files in gemspec.
23 # (1) Specify as gem and dependency pattern as usual pkgsrc's one.
25 # Example:
26 # When gemspec contains "json~>1.4.7" as runtime dependency
27 # (i.e. json>=1.4.7<1.5) and if you want to relax it to
28 # "json>=1.4.6" then use:
30 # OVERRIDE_GEMSPEC+= json>=1.4.6
32 # If you want to change depending gem to "json_pure>=1.4.6"
33 # then use:
35 # OVERRIDE_GEMSPEC+= json:json_pure>=1.4.6
37 # You can also remove dependency:
39 # OVERRIDE_GEMSPEC+= json:
41 # (2) Modify instance of gemspec.
43 # Example:
44 # Rename gem's name to "foo" (setting instance @name):
46 # OVERRIDE_GEMSPEC+= :name=foo
48 # Example:
49 # Remove files (a.rb and b.rb) from 'files':
51 # OVERRIDE_GEMSPEC+= :files a.rb= b.rb=
53 # Example:
54 # Add a file (exec.rb) to 'executables':
56 # OVERRIDE_GEMSPEC+= :executables exec.rb
58 # Example:
59 # Rename a file (from 'ruby' to 'ruby193') in 'files':
61 # OVERRIDE_GEMSPEC+= :files ruby=ruby193
63 # Note: Because of limited parser, argumetns for (1) must preceed to (2).
65 # Default: (empty)
67 # GEM_PATH
68 # Set GEM_PATH; search path for rubygems
70 # Default: ${PREFIX}/${GEM_HOME}
72 # BUILD_TARGET
73 # The Rakefile target that creates a local gem if using the
74 # ``rake'' GEM_BUILD method.
76 # Default: gem
78 # GEM_BUILD
79 # The method used to build the local gem.
81 # Possible: gemspec, rake
82 # Default: gemspec
84 # GEM_CLEANBUILD
85 # A list of shell globs representing files to remove from the
86 # gem installed in the installation root. The file is removed
87 # if the path matches the glob and is not in ${WRKSRC}. The
88 # default is "ext/*"
90 # Example:
92 # GEM_CLEANBUILD= *.o *.${RUBY_DLEXT} mkmf.log
94 # GEM_NAME
95 # The name of the gem to install. The default value is ${DISTNAME}.
97 # GEM_SPECFILE
98 # The path to the gemspec file to use when building a gem using
99 # the ``gemspec'' GEM_BUILD method. It defaults to
100 # ${WRKDIR}/${DISTNAME}.gemspec.
102 # RUBYGEM_OPTIONS
103 # Optional parameter to pass to gem on install stage.
106 # Variables defined in this file:
108 # GEM_DOCDIR
109 # The relative path from PREFIX to the directory in the local gem
110 # repository that holds the documentation for the installed gem.
112 # GEM_LIBDIR
113 # The relative path from PREFIX to the directory in the local gem
114 # repository that holds the contents of the installed gem.
116 # RUBYGEM
117 # The path to the rubygems ``gem'' script.
119 .if !defined(_RUBYGEM_MK)
120 _RUBYGEM_MK= # defined
122 # replace interpeter bin default
123 REPLACE_RUBY_DIRS?= bin
124 REPLACE_RUBY_PAT?= *
126 # Default to using rake to build the local gem from the unpacked files.
127 GEM_BUILD?= gemspec
129 OVERRIDE_GEMSPEC?= # default is empty
131 RUBYGEM_LANG?= en_US.UTF-8
132 RUBYGEM_ENV?= LANG=${RUBYGEM_LANG} LC_CTYPE=${RUBYGEM_LANG}
134 .if !empty(OVERRIDE_GEMSPEC)
135 UPDATE_GEMSPEC= ../../lang/ruby/files/update-gemspec.rb
136 .endif
138 .if ${GEM_BUILD} == "rake"
139 USE_RAKE?= YES
140 .endif
142 # print-PLIST support
143 PRINT_PLIST_AWK+= /${GEM_NAME}\.(gem|gemspec)$$/ \
144 { gsub(/${GEM_NAME}\.gem/, "$${GEM_NAME}.gem"); }
145 PRINT_PLIST_AWK+= /${GEM_NAME:S/./[.]/g}[.](gem|gemspec)$$/ \
146 { gsub(/${PKGVERSION_NOREV:S|/|\\/|g}[.]gem/, "$${PKGVERSION}.gem"); }
147 PRINT_PLIST_AWK+= /^${GEM_LIBDIR:S|/|\\/|g}/ \
148 { gsub(/${GEM_LIBDIR:S|/|\\/|g}/, "$${GEM_LIBDIR}"); print; next; }
149 PRINT_PLIST_AWK+= /^${GEM_DOCDIR:S|/|\\/|g}/ \
150 { next; }
151 PRINT_PLIST_AWK+= /^${GEM_HOME:S|/|\\/|g}/ \
152 { gsub(/${GEM_HOME:S|/|\\/|g}/, "$${GEM_HOME}"); \
153 print; next; }
154 PRINT_PLIST_AWK+= /^${RUBY_GEM_BASE:S|/|\\/|g}/ \
155 { gsub(/${RUBY_GEM_BASE:S|/|\\/|g}/, "$${RUBY_GEM_BASE}"); \
156 print; next; }
158 # Include this early in case some of its target are needed
159 .include "../../lang/ruby/modules.mk"
161 # Build and run-time dependencies for Ruby prior to 1.9.
163 # We need rubygems>=1.1.0 to actually build the package, but the
164 # resulting installed gem can run with older versions of rubygems.
166 # If we're using rake to build the local gem, then include it as a
167 # build tool.
170 .if ${RUBY_VER} == "18"
171 BUILD_DEPENDS+= ${RUBY_PKGPREFIX}-rubygems>=1.1.0:../../misc/rubygems
172 DEPENDS+= ${RUBY_PKGPREFIX}-rubygems>=1.0.1:../../misc/rubygems
173 .else # !ruby18
174 . if defined(RUBYGEMS_REQD)
176 RUBY193_RUBYGEMS_VERS= 1.8.11
177 RUBY200_RUBYGEMS_VERS= 2.0.0
179 _RUBYGEMS_REQD_MAJOR= ${RUBYGEMS_REQD:C/\.[0-9\.]+$//}
180 _RUBYGEMS_REQD_MINORS= ${RUBYGEMS_REQD:C/^([0-9]+)\.*//}
182 . if ${RUBY_VER} == "193"
183 _RUBYGEMS_MAJOR= ${RUBY193_RUBYGEMS_VERS:C/\.[0-9\.]+$//}
184 _RUBYGEMS_MINORS= ${RUBY193_RUBYGEMS_VERS:C/^([0-9]+)\.*//}
185 . elif ${RUBY_VER} == "200"
186 _RUBYGEMS_MAJOR= ${RUBY200_RUBYGEMS_VERS:C/\.[0-9\.]+$//}
187 _RUBYGEMS_MINORS= ${RUBY200_RUBYGEMS_VERS:C/^([0-9]+)\.*//}
188 . else
189 PKG_FAIL_REASON+= "Unknown Ruby version specified: ${RUBY_VER}."
190 . endif
192 _RUBYGEMS_REQD= NO
194 . if ${_RUBYGEMS_REQD_MAJOR} > ${_RUBYGEMS_MAJOR}
195 _RUBYGEMS_REQD= YES
196 . elif ${_RUBYGEMS_REQD_MAJOR} == ${_RUBYGEMS_MAJOR}
197 . if !empty(_RUBYGEMS_MINORS) && ${_RUBYGEMS_REQD_MINORS} > ${_RUBYGEMS_MINORS}
198 _RUBYGEMS_REQD= YES
199 . endif
200 . endif
202 . if empty(_RUBYGEMS_REQD:M[nN][oO])
203 DEPENDS+= ${RUBY_PKGPREFIX}-rubygems>=${RUBYGEMS_REQD}:../../misc/rubygems
204 . endif
205 . endif
206 .endif # !ruby18
208 CATEGORIES+= ruby
209 MASTER_SITES?= ${MASTER_SITE_RUBYGEMS}
211 EXTRACT_SUFX?= .gem
212 DISTFILES?= ${DISTNAME}${EXTRACT_SUFX}
214 # If any of the DISTFILES are gems, then skip the normal do-extract actions
215 # and extract them ourselves in gem-extract.
217 .if !empty(DISTFILES:M*.gem)
218 EXTRACT_ONLY?= # empty
219 .endif
221 # Specify GEM_PATH
222 GEM_PATH?= ${PREFIX}/${GEM_HOME}
224 # Base directory for Gems
225 MAKE_ENV+= GEM_PATH=${GEM_PATH}
227 # Directory for the Gem to install
228 GEM_NAME?= ${DISTNAME}
229 GEM_LIBDIR= ${GEM_HOME}/gems/${GEM_NAME}
230 GEM_DOCDIR= ${GEM_HOME}/doc/${GEM_NAME}
231 GEM_CACHEDIR= ${GEM_HOME}/cache
233 # Installed gems have wrapper scripts that call the right interpreter,
234 # regardless of the #! line at the head of a script, so we can skip
235 # the interpreter path check for gems. ANd it is also true for files'
236 # permission.
238 CHECK_INTERPRETER_SKIP+= ${GEM_LIBDIR}/*
239 CHECK_PERMS_SKIP+= ${GEM_LIBDIR}/*
241 # RUBYGEM holds the path to RubyGems' gem command
242 EVAL_PREFIX+= RUBYGEM_PREFIX=${RUBYGEM_NAME}
243 RUBYGEM= ${RUBYGEM_PREFIX}/bin/${RUBYGEM_NAME}
245 # PLIST support
246 PLIST_SUBST+= GEM_NAME=${GEM_NAME}
247 PLIST_SUBST+= GEM_LIBDIR=${GEM_LIBDIR}
248 PLIST_SUBST+= GEM_DOCDIR=${GEM_DOCDIR}
251 ### gem-extract
253 ### The gem-extract target extracts a standard gem file. It is an
254 ### automatic dependency for the post-extract target so it doesn't
255 ### disturb the usual do-extract actions.
257 GEM_SPECFILE?= ${WRKDIR}/${DISTNAME}.gemspec
259 .PHONY: gem-extract
260 post-extract: gem-extract
261 .if !target(gem-extract)
262 gem-extract: fake-home
263 . for _gem_ in ${DISTFILES:M*.gem}
264 ${RUN} cd ${WRKDIR} && ${SETENV} ${MAKE_ENV} ${RUBYGEM_ENV} \
265 ${RUBYGEM} unpack ${_DISTDIR:Q}${_gem_:Q}
266 ${RUN} cd ${WRKDIR} && \
267 ${SETENV} ${MAKE_ENV} TZ=UTC ${RUBYGEM_ENV} \
268 ${RUBYGEM} spec --ruby ${_DISTDIR:Q}${_gem_:Q} > ${_gem_}spec
269 . endfor
270 .endif
273 ### gem-build
275 ### The gem-build target builds a new local gem from the extracted gem's
276 ### contents. The new gem as created as ${WRKSRC}/${GEM_NAME}.gem.
277 ### The local gem is then installed into a special build root under
278 ### ${WRKDIR} (${RUBYGEM_INSTALL_ROOT}), possibly compiling any extensions.
280 GEM_CLEANBUILD?= ext/*
282 .if !empty(GEM_CLEANBUILD:M/*) || !empty(GEM_CLEANBUILD:M*../*)
283 PKG_FAIL_REASON= "GEM_CLEANBUILD must be relative to "${PREFIX}/${GEM_LIBDIR:Q}"."
284 .endif
286 .PHONY: gem-build
287 do-build: _gem-pre-build gem-build
289 _gem-pre-build:
290 .if !empty(OVERRIDE_GEMSPEC)
291 @${STEP_MSG} Override gemspec dependency
292 @${RUBY} ${.CURDIR}/${UPDATE_GEMSPEC} ${WRKDIR}/${GEM_NAME}.gemspec \
293 ${OVERRIDE_GEMSPEC:Q}
294 .endif
295 @${STEP_MSG} "Removing backup files of patch before build"
296 @find ${WRKSRC} -name \*.orig -exec rm {} \;
298 gem-build: _gem-${GEM_BUILD}-build
300 .PHONY: _gem-gemspec-build
301 _gem-gemspec-build:
302 ${RUN} cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} ${RUBYGEM_ENV} \
303 ${RUBYGEM} build ${GEM_SPECFILE}
304 ${RUN} ${TEST} -f ${WRKSRC}/${GEM_NAME}.gem || \
305 ${FAIL_MSG} "Build of ${GEM_NAME}.gem failed."
307 BUILD_TARGET?= gem
309 .PHONY: _gem-rake-build
310 _gem-rake-build:
311 ${RUN} cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} ${RAKE} ${BUILD_TARGET}
312 ${RUN} cd ${WRKSRC} && rm -f ${GEM_NAME}.gem
313 ${RUN} cd ${WRKSRC} && find . -name ${GEM_NAME}.gem -print | \
314 while read file; do \
315 ln -fs "$$file" ${GEM_NAME}.gem; \
316 exit 0; \
317 done
319 RUBYGEM_INSTALL_ROOT= ${WRKDIR}/.inst
320 _RUBYGEM_OPTIONS= --no-update-sources # don't cache the gem index
321 _RUBYGEM_OPTIONS+= --install-dir ${PREFIX}/${GEM_HOME}
322 _RUBYGEM_OPTIONS+= ${RUBYGEM_INSTALL_ROOT_OPTION}
323 _RUBYGEM_OPTIONS+= --ignore-dependencies
324 _RUBYGEM_OPTIONS+= --local ${WRKSRC}/${GEM_NAME}.gem
325 .if !empty(RUBY_BUILD_RI:M[nN][oO])
326 _RUBYGEM_OPTIONS+= --no-ri
327 .endif
328 .if !empty(RUBY_BUILD_RDOC:M[nN][oO])
329 _RUBYGEM_OPTIONS+= --no-rdoc
330 .endif
331 .if !empty(CONFIGURE_ARGS)
332 _RUBYGEM_OPTIONS+= -- --build-args ${CONFIGURE_ARGS}
333 .endif
335 RUBYGEM_INSTALL_ROOT_OPTION= --install-root ${RUBYGEM_INSTALL_ROOT}
337 .PHONY: _gem-build-install-root
338 _gem-build-install-root:
339 @${STEP_MSG} "Installing gem into installation root"
340 ${RUN} ${SETENV} ${MAKE_ENV} ${RUBYGEM_ENV} \
341 ${RUBYGEM} install --backtrace ${RUBYGEM_OPTIONS} ${_RUBYGEM_OPTIONS}
343 # The ``gem'' command doesn't exit with a non-zero result even if the
344 # install of the gem failed, so we do the check and return the proper exit
345 # code ourselves.
347 .PHONY: _gem-build-install-root-check
348 _gem-build-install-root-check:
349 ${RUN} ${TEST} -f ${RUBYGEM_INSTALL_ROOT}${PREFIX}/${GEM_CACHEDIR}/${GEM_NAME}.gem || \
350 ${FAIL_MSG} "Installing ${GEM_NAME}.gem into installation root failed."
352 .if !empty(GEM_CLEANBUILD)
353 .PHONY: _gem-build-cleanbuild
354 _gem-build-cleanbuild:
355 @${STEP_MSG} "Cleaning intermediate gem build files"
356 ${RUN} cd ${RUBYGEM_INSTALL_ROOT}${PREFIX}/${GEM_LIBDIR} && \
357 find . -print | sort -r | \
358 while read file; do \
359 case $$file in \
360 ${GEM_CLEANBUILD:@.p.@./${.p.}) ;;@} \
361 *) continue ;; \
362 esac; \
363 [ ! -e ${WRKSRC:Q}"/$$file" ] || continue; \
364 if [ -d "$$file" ]; then \
365 ${ECHO} "rmdir "${GEM_NAME}"/$$file"; \
366 rmdir $$file; \
367 else \
368 ${ECHO} "rm "${GEM_NAME}"/$$file"; \
369 rm -f $$file; \
370 fi; \
371 done
372 .endif
375 ### gem-install
377 ### The gem-install target installs the gem in ${_RUBY_INSTALL_ROOT} into
378 ### the actual gem repository.
380 GENERATE_PLIST+= ${RUBYGEM_GENERATE_PLIST}
381 RUBYGEM_GENERATE_PLIST= \
382 ${ECHO} "@comment The following lines are automatically generated." && \
383 ( cd ${RUBYGEM_INSTALL_ROOT}${PREFIX} && test -d ${GEM_DOCDIR} && \
384 ${FIND} ${GEM_DOCDIR} \! -type d -print | ${SORT} ) || true;
386 _GEM_INSTALL_TARGETS= _gem-build-install-root
387 _GEM_INSTALL_TARGETS+= _gem-build-install-root-check
388 .if !empty(GEM_CLEANBUILD)
389 _GEM_INSTALL_TARGETS+= _gem-build-cleanbuild
390 .endif
391 _GEM_INSTALL_TARGETS+= _gem-install
393 .ORDER: ${_GEM_INSTALL_TARGETS}
395 USE_TOOLS+= pax
397 do-install: ${_GEM_INSTALL_TARGETS}
399 .PHONY: _gem-install
400 _gem-install:
401 @${STEP_MSG} "gem install"
402 ${RUN} cd ${RUBYGEM_INSTALL_ROOT}${PREFIX} && \
403 pax -rwpe . ${DESTDIR}${PREFIX}
405 .endif