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:
9 # Minimum version of required rubygems. Ruby base packages contain:
12 # ruby193-base: 1.8.11
15 # If newer version of rubygems is resuiqred, set RUBYGEMS_REQD to
18 # Default: not defined
21 # Fix version of depending gem or modify files in gemspec.
23 # (1) Specify as gem and dependency pattern as usual pkgsrc's one.
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"
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.
44 # Rename gem's name to "foo" (setting instance @name):
46 # OVERRIDE_GEMSPEC+= :name=foo
49 # Remove files (a.rb and b.rb) from 'files':
51 # OVERRIDE_GEMSPEC+= :files a.rb= b.rb=
54 # Add a file (exec.rb) to 'executables':
56 # OVERRIDE_GEMSPEC+= :executables exec.rb
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).
68 # Set GEM_PATH; search path for rubygems
70 # Default: ${PREFIX}/${GEM_HOME}
73 # The Rakefile target that creates a local gem if using the
74 # ``rake'' GEM_BUILD method.
79 # The method used to build the local gem.
81 # Possible: gemspec, rake
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
92 # GEM_CLEANBUILD= *.o *.${RUBY_DLEXT} mkmf.log
95 # The name of the gem to install. The default value is ${DISTNAME}.
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.
103 # Optional parameter to pass to gem on install stage.
106 # Variables defined in this file:
109 # The relative path from PREFIX to the directory in the local gem
110 # repository that holds the documentation for the installed gem.
113 # The relative path from PREFIX to the directory in the local gem
114 # repository that holds the contents of the installed gem.
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
126 # Default to using rake to build the local gem from the unpacked files.
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
138 .if
${GEM_BUILD} == "rake"
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
}/ \
151 PRINT_PLIST_AWK
+= /^
${GEM_HOME
:S|
/|
\\/|g
}/ \
152 { gsub
(/${GEM_HOME
:S|
/|
\\/|g
}/, "$${GEM_HOME}"); \
154 PRINT_PLIST_AWK
+= /^
${RUBY_GEM_BASE
:S|
/|
\\/|g
}/ \
155 { gsub
(/${RUBY_GEM_BASE
:S|
/|
\\/|g
}/, "$${RUBY_GEM_BASE}"); \
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
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
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]+)\.
*//}
189 PKG_FAIL_REASON
+= "Unknown Ruby version specified: ${RUBY_VER}."
194 . if
${_RUBYGEMS_REQD_MAJOR} > ${_RUBYGEMS_MAJOR}
196 . elif
${_RUBYGEMS_REQD_MAJOR} == ${_RUBYGEMS_MAJOR}
197 . if
!empty
(_RUBYGEMS_MINORS
) && ${_RUBYGEMS_REQD_MINORS} > ${_RUBYGEMS_MINORS}
202 . if empty
(_RUBYGEMS_REQD
:M
[nN
][oO
])
203 DEPENDS
+= ${RUBY_PKGPREFIX}-rubygems
>=${RUBYGEMS_REQD}:..
/..
/misc
/rubygems
209 MASTER_SITES?
= ${MASTER_SITE_RUBYGEMS}
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
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'
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}
246 PLIST_SUBST
+= GEM_NAME
=${GEM_NAME}
247 PLIST_SUBST
+= GEM_LIBDIR
=${GEM_LIBDIR}
248 PLIST_SUBST
+= GEM_DOCDIR
=${GEM_DOCDIR}
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
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
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
}"."
287 do-build
: _gem-pre-build gem-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
}
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
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."
309 .PHONY
: _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
; \
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
328 .if
!empty
(RUBY_BUILD_RDOC
:M
[nN
][oO
])
329 _RUBYGEM_OPTIONS
+= --no-rdoc
331 .if
!empty
(CONFIGURE_ARGS
)
332 _RUBYGEM_OPTIONS
+= -- --build-args
${CONFIGURE_ARGS}
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
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 \
360 ${GEM_CLEANBUILD
:@.p.@.
/${.p.
}) ;;@
} \
363 [ ! -e
${WRKSRC
:Q
}"/$$file" ] || continue
; \
364 if
[ -d
"$$file" ]; then \
365 ${ECHO} "rmdir "${GEM_NAME}"/$$file"; \
368 ${ECHO} "rm "${GEM_NAME}"/$$file"; \
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
391 _GEM_INSTALL_TARGETS
+= _gem-install
393 .ORDER
: ${_GEM_INSTALL_TARGETS}
397 do-install
: ${_GEM_INSTALL_TARGETS}
401 @
${STEP_MSG} "gem install"
402 ${RUN} cd
${RUBYGEM_INSTALL_ROOT}${PREFIX} && \
403 pax
-rwpe .
${DESTDIR}${PREFIX}