ruby.port.mk 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. # $OpenBSD: ruby.port.mk,v 1.90 2017/01/06 16:03:54 jeremy Exp $
  2. # ruby module
  3. CATEGORIES+= lang/ruby
  4. # Whether the ruby module should automatically add FLAVORs.
  5. # If left blank, does so only for gem and extconf ports.
  6. .if ${CONFIGURE_STYLE:L:Mgem} || ${CONFIGURE_STYLE:L:Mextconf}
  7. MODRUBY_HANDLE_FLAVORS ?= Yes
  8. .else
  9. MODRUBY_HANDLE_FLAVORS ?= No
  10. .endif
  11. # This allows you to build packages for multiple ruby versions and
  12. # implementations using the same port directory for gem and extconf based
  13. # ports. It does this by adding FLAVORS automatically, unless FLAVORS are
  14. # already defined or the port defines MODRUBY_REV to tie the port to a specific
  15. # ruby version. For example, JDBC gem ports want to set FLAVOR=jruby, since
  16. # they don't work on other ruby implementations.
  17. .if !defined(MODRUBY_REV)
  18. . if ${MODRUBY_HANDLE_FLAVORS:L:Myes}
  19. # If ruby.pork.mk should handle FLAVORs, define a separate FLAVOR
  20. # for each ruby interpreter
  21. . if !defined(FLAVORS)
  22. FLAVORS= ruby18 ruby21 ruby22 ruby23 ruby24
  23. . if !${CONFIGURE_STYLE:L:Mext} && !${CONFIGURE_STYLE:L:Mextconf}
  24. FLAVORS+= jruby
  25. . endif
  26. . endif
  27. # Instead of adding flavors to the end of the package name, we use
  28. # different package stems for different ruby versions and implementations.
  29. # ruby 1.8 uses the historical ruby-* package stem, newer ruby versions
  30. # use rubyXY-* and jruby uses jruby-*. In most cases,
  31. # PKGNAME in the port should be set to the same as DISTNAME, and this
  32. # will insert the correct package prefix.
  33. FULLPKGNAME?= ${MODRUBY_PKG_PREFIX}-${PKGNAME}
  34. # If the port installs binary files or man pages and can work on multiple
  35. # versions of ruby, those files should have the appropriate suffix so that
  36. # they do not conflict. GEM_BIN_SUFFIX should be added after such a filename
  37. # in the PLIST so that the gem will correctly package on all supported
  38. # versions of ruby.
  39. SUBST_VARS+= GEM_BIN_SUFFIX GEM_MAN_SUFFIX
  40. FLAVOR?=
  41. # Without a FLAVOR, assume the use of ruby 2.3.
  42. . if empty(FLAVOR)
  43. FLAVOR = ruby23
  44. . endif
  45. # Check for conflicting FLAVORs and set MODRUBY_REV appropriately based
  46. # on the FLAVOR.
  47. . for i in ruby18 ruby21 ruby22 ruby23 ruby24 jruby
  48. . if ${FLAVOR:M$i}
  49. MODRUBY_REV = ${i:C/ruby([0-9])/\1./}
  50. . if ${FLAVOR:N$i:Mruby18} || \
  51. ${FLAVOR:N$i:Mruby21} || \
  52. ${FLAVOR:N$i:Mruby22} || \
  53. ${FLAVOR:N$i:Mruby23} || \
  54. ${FLAVOR:N$i:Mruby24} || \
  55. ${FLAVOR:N$i:Mjruby}
  56. ERRORS += "Fatal: Conflicting flavors used: ${FLAVOR}"
  57. . endif
  58. . endif
  59. . endfor
  60. . if ${FLAVOR:Mruby18}
  61. # Handle updates from older ruby 1.8 ports that didn't use the ruby18
  62. # FLAVOR by adding a @pkgpath entry to the PLIST.
  63. SUBST_VARS+= PKGPATH
  64. PKG_ARGS+= -f ${PORTSDIR}/lang/ruby/ruby18.PLIST
  65. . endif
  66. . endif
  67. .endif
  68. # The default ruby version to use for non-gem/extconf ports. Defaults to ruby
  69. # 2.3 for consistency with the default ruby23 FLAVOR for gem/extconf ports.
  70. MODRUBY_REV?= 2.3
  71. # Because the jruby FLAVORs use same binary names but in
  72. # different directories, GEM_MAN_SUFFIX is used for the man pages to avoid
  73. # conflicts since all man files go in the same directory.
  74. GEM_MAN_SUFFIX = ${GEM_BIN_SUFFIX}
  75. # Use the FLAVOR as the prefix for the package, to avoid conflicts.
  76. MODRUBY_PKG_PREFIX = ${MODRUBY_FLAVOR}
  77. # Set MODRUBY_* variables as well as the path for the ruby interpreter and
  78. # related commands used by MODRUBY_TEST and manually in some port targets.
  79. .if ${MODRUBY_REV} == jruby
  80. GEM_MAN_SUFFIX = -${MODRUBY_FLAVOR}
  81. MODRUBY_ARCH= ${MACHINE_ARCH:S/amd64/x86_64/}-java
  82. MODRUBY_BIN_RSPEC = ${RUBY} -S rspec
  83. MODRUBY_BIN_TESTRB = ${RUBY} -S testrb
  84. MODRUBY_FLAVOR = jruby
  85. MODRUBY_LIBDIR= ${LOCALBASE}/jruby/lib/ruby
  86. MODRUBY_LIBREV = 2.3.0
  87. MODRUBY_SITEARCHDIR = ${MODRUBY_SITEDIR}/java
  88. MODRUBY_SITEDIR = jruby/lib/ruby/site_ruby/${MODRUBY_LIBREV}
  89. RAKE= ${RUBY} -S rake
  90. RSPEC= ${RUBY} -S spec
  91. RUBY= ${LOCALBASE}/jruby/bin/jruby
  92. . if ${CONFIGURE_STYLE:L:Mext} || ${CONFIGURE_STYLE:L:Mextconf}
  93. ERRORS += "Fatal: Ruby C extensions are unsupported on JRuby"
  94. . else
  95. MODRUBY_RUN_DEPENDS= lang/jruby
  96. . endif
  97. .else # not jruby
  98. . if ${MODRUBY_REV} == 1.8
  99. MODRUBY_PKG_PREFIX = ruby
  100. . endif
  101. GEM_BIN_SUFFIX = ${MODRUBY_BINREV}
  102. MODRUBY_ARCH= ${MACHINE_ARCH:S/amd64/x86_64/}-openbsd
  103. MODRUBY_BINREV = ${MODRUBY_LIBREV:S/.//}
  104. MODRUBY_BIN_RSPEC = ${LOCALBASE}/bin/rspec${MODRUBY_BINREV}
  105. MODRUBY_BIN_TESTRB = ${LOCALBASE}/bin/testrb${MODRUBY_BINREV}
  106. MODRUBY_FLAVOR = ruby${MODRUBY_BINREV}
  107. MODRUBY_LIBDIR= ${LOCALBASE}/lib/ruby
  108. MODRUBY_LIBREV = ${MODRUBY_REV}
  109. MODRUBY_LIB_DEPENDS= ${MODRUBY_RUN_DEPENDS}
  110. MODRUBY_RUN_DEPENDS= lang/ruby/${MODRUBY_REV}
  111. MODRUBY_SITEARCHDIR = ${MODRUBY_SITEDIR}/${MODRUBY_ARCH}
  112. MODRUBY_SITEDIR = lib/ruby/site_ruby/${MODRUBY_LIBREV}
  113. MODRUBY_WANTLIB= ruby${MODRUBY_BINREV}
  114. RAKE= ${LOCALBASE}/bin/rake${MODRUBY_BINREV}
  115. RSPEC= ${LOCALBASE}/bin/spec${MODRUBY_BINREV}
  116. RUBY= ${LOCALBASE}/bin/ruby${MODRUBY_BINREV}
  117. .endif
  118. MODRUBY_RSPEC_DEPENDS = devel/ruby-rspec/1,${MODRUBY_FLAVOR}<2.0
  119. MODRUBY_RSPEC3_DEPENDS = devel/ruby-rspec/3/rspec,${MODRUBY_FLAVOR}>=3.0
  120. .if defined(MODRUBY_TEST)
  121. . if !${MODRUBY_TEST:L:Mrspec} && !${MODRUBY_TEST:L:Mrspec3} && \
  122. !${MODRUBY_TEST:L:Mrake} && !${MODRUBY_TEST:L:Mruby} && \
  123. !${MODRUBY_TEST:L:Mtestrb}
  124. ERRORS += "Fatal: Unsupported MODRUBY_TEST value: ${MODRUBY_TEST}"
  125. . endif
  126. .else
  127. . if ${CONFIGURE_STYLE:L:Mextconf} || ${CONFIGURE_STYLE:L:Mgem} || \
  128. ${CONFIGURE_STYLE:L:Msetup}
  129. . if !target(do-test)
  130. # Disable regress for extconf, gem, and setup based ports, since they
  131. # won't use make check for test.
  132. NO_TEST = Yes
  133. . endif
  134. . endif
  135. MODRUBY_TEST?=
  136. .endif
  137. MODRUBY_BUILD_DEPENDS= ${MODRUBY_RUN_DEPENDS}
  138. # common directories for ruby extensions
  139. # used to create docs and examples install path
  140. MODRUBY_RELDOCDIR= share/doc/${MODRUBY_PKG_PREFIX}
  141. MODRUBY_RELEXAMPLEDIR= share/examples/${MODRUBY_PKG_PREFIX}
  142. MODRUBY_DOCDIR= ${PREFIX}/${MODRUBY_RELDOCDIR}
  143. MODRUBY_EXAMPLEDIR= ${PREFIX}/${MODRUBY_RELEXAMPLEDIR}
  144. SUBST_VARS += ^MODRUBY_RELDOCDIR ^MODRUBY_RELEXAMPLEDIR
  145. # Assume that we want to automatically add ruby to BUILD_DEPENDS
  146. # and RUN_DEPENDS unless the port specifically requests not to.
  147. MODRUBY_BUILDDEP?= Yes
  148. MODRUBY_RUNDEP?= Yes
  149. .if ${NO_BUILD:L} == no && ${MODRUBY_BUILDDEP:L} == yes
  150. BUILD_DEPENDS+= ${MODRUBY_BUILD_DEPENDS}
  151. .endif
  152. .if ${MODRUBY_RUNDEP:L} == yes
  153. RUN_DEPENDS+= ${MODRUBY_RUN_DEPENDS}
  154. .endif
  155. .if ${MODRUBY_TEST:L:Mrake} && ${MODRUBY_REV} == 1.8
  156. TEST_DEPENDS+= devel/ruby-rake
  157. .endif
  158. .if ${MODRUBY_TEST:L:Mrspec}
  159. TEST_DEPENDS+= ${MODRUBY_RSPEC_DEPENDS}
  160. .endif
  161. .if ${MODRUBY_TEST:L:Mrspec3}
  162. TEST_DEPENDS+= ${MODRUBY_RSPEC3_DEPENDS}
  163. .endif
  164. MODRUBY_RUBY_ADJ = perl -pi \
  165. -e '$$. == 1 && s|^.*env ruby.*$$|\#!${RUBY}|;' \
  166. -e '$$. == 1 && s|^.*bin/ruby.*$$|\#!${RUBY}|;' \
  167. -e 'close ARGV if eof;'
  168. MODRUBY_ADJ_FILES?=
  169. .if !empty(MODRUBY_ADJ_FILES)
  170. MODRUBY_ADJ_REPLACE= for pat in ${MODRUBY_ADJ_FILES:QL}; do \
  171. find ${WRKSRC} -type f -name "$$pat" -print0 | \
  172. xargs -0r ${MODRUBY_RUBY_ADJ} ; \
  173. done
  174. MODRUBY_pre-configure += ${MODRUBY_ADJ_REPLACE}
  175. .endif
  176. MODRUBY_WANTLIB+= c m
  177. .if ${MODRUBY_REV} != 1.8
  178. MODRUBY_WANTLIB+= gmp pthread
  179. .endif
  180. .if ${CONFIGURE_STYLE:L:Mext} || ${CONFIGURE_STYLE:L:Mextconf}
  181. # Ruby C exensions are specific to an arch and are loaded as
  182. # shared libraries (not compiled into ruby), so make sure PKG_ARCH=*
  183. # is not set.
  184. . if defined(PKG_ARCH) && ${PKG_ARCH} == *
  185. ERRORS+= "Fatal: Should not have PKG_ARCH=* when compiling extensions"
  186. . endif
  187. # Add appropriate libraries to WANTLIB depending on ruby version and
  188. # implementation
  189. WANTLIB+= ${MODRUBY_WANTLIB}
  190. LIB_DEPENDS+= ${MODRUBY_LIB_DEPENDS}
  191. .endif
  192. .if ${CONFIGURE_STYLE:L:Mextconf}
  193. CONFIGURE_STYLE= simple
  194. CONFIGURE_SCRIPT= ${SETENV} ${MAKE_ENV} ${RUBY} extconf.rb
  195. .elif ${CONFIGURE_STYLE:L:Mgem}
  196. # All gems should be in the same directory on rubygems.org.
  197. MASTER_SITES?= ${MASTER_SITE_RUBYGEMS}
  198. EXTRACT_SUFX= .gem
  199. # Require versions that no longer create the .require_paths files.
  200. . if ${MODRUBY_REV} == 1.8
  201. BUILD_DEPENDS+= devel/ruby-gems>=1.8.23p3
  202. RUN_DEPENDS+= devel/ruby-gems>=1.3.7p0
  203. . elif ${MODRUBY_REV} == jruby
  204. BUILD_DEPENDS+= lang/jruby>=1.6.5
  205. . elif ${MODRUBY_REV} == 2.1
  206. # Require version that fixes extensions directory path
  207. BUILD_DEPENDS+= lang/ruby/2.1>=2.1.0p0
  208. . endif
  209. # Pure ruby gem ports without C extensions are arch-independent.
  210. . if !${CONFIGURE_STYLE:L:Mext}
  211. PKG_ARCH= *
  212. . elif ${MODRUBY_REV} != 1.8
  213. # Add build complete file to package so rubygems doesn't complain
  214. # or build extensions at runtime
  215. GEM_EXTENSIONS_DIR ?= ${GEM_LIB}/extensions/${MODRUBY_ARCH:S/i386/x86/}/${MODRUBY_REV}/${DISTNAME}
  216. GEM_EXTENSIONS_FILE ?= ${GEM_EXTENSIONS_DIR}/gem.build_complete
  217. SUBST_VARS+= GEM_EXTENSIONS_DIR
  218. PKG_ARGS+= -f ${PORTSDIR}/lang/ruby/rubygems-ext.PLIST
  219. . endif
  220. # PLIST magic. Set variables so that the same PLIST will work for
  221. # all ruby versions and implementations.
  222. SUBST_VARS+= ^GEM_LIB ^GEM_BIN DISTNAME
  223. . if ${MODRUBY_REV} == jruby
  224. GEM= ${RUBY} -S gem
  225. GEM_BIN = jruby/bin
  226. GEM_LIB = jruby/lib/ruby/gems/1.8
  227. GEM_BASE_LIB= ${GEM_BASE}/jruby/${MODRUBY_LIBREV}
  228. . else
  229. GEM= ${LOCALBASE}/bin/gem${MODRUBY_BINREV}
  230. GEM_BIN = bin
  231. GEM_LIB = lib/ruby/gems/${MODRUBY_LIBREV}
  232. GEM_BASE_LIB= ${GEM_BASE}/ruby/${MODRUBY_LIBREV}
  233. . endif
  234. GEM_BASE= ${WRKDIR}/gem-tmp/.gem
  235. GEM_ABS_PATH= ${PREFIX}/${GEM_LIB}
  236. GEM_BASE_BIN= ${GEM_BASE_LIB}/bin
  237. # We purposely do not install documentation for ruby gems, because
  238. # the filenames are generated differently on different ruby versions,
  239. # and most use 1 file per method, which is insane.
  240. GEM_FLAGS+= --local --no-rdoc --no-ri --no-force --verbose --backtrace \
  241. --user-install
  242. _GEM_CONTENT= ${WRKDIR}/gem-content
  243. _GEM_DATAFILE= ${_GEM_CONTENT}/data.tar.gz
  244. _GEM_PATCHED= ${DISTNAME}${EXTRACT_SUFX}
  245. _GEM_MAKE= "make V=1"
  246. # Unpack the gem into WRKDIST so it can be patched. Include the gem metadata
  247. # under WRKDIST so it can be patched easily to remove or change dependencies.
  248. # Remove any signing of packages, as patching the gem could then break the
  249. # signatures.
  250. EXTRACT_CASES += *.gem) \
  251. mkdir ${WRKDIST} ${_GEM_CONTENT}; \
  252. cd ${_GEM_CONTENT} && tar -xf ${FULLDISTDIR}/$$archive; \
  253. cd ${WRKDIST} && tar -xzf ${_GEM_DATAFILE} && rm -f ${_GEM_DATAFILE}; \
  254. gzcat ${_GEM_CONTENT}/metadata.gz > ${WRKDIST}/.metadata; \
  255. rm -f ${_GEM_CONTENT}/*.gz.sig ${_GEM_CONTENT}/checksums.yaml.gz;;
  256. # Rebuild the gem manually after possible patching, then install it to a
  257. # temporary directory (not the final directory under fake, since that would
  258. # require root access and building C extensions as root).
  259. MODRUBY_BUILD_TARGET = \
  260. if [ -f ${WRKDIST}/.metadata ]; then \
  261. cd ${WRKDIST} && gzip .metadata && \
  262. mv -f .metadata.gz ${_GEM_CONTENT}/metadata.gz; \
  263. fi; \
  264. cd ${WRKDIST} && pax -wz -s '/.*${PATCHORIG:S@.@\.@g}$$//' \
  265. -x ustar -o write_opt=nodir . >${_GEM_DATAFILE}; \
  266. cd ${_GEM_CONTENT} && tar -cf ${WRKDIR}/${_GEM_PATCHED} *.gz; \
  267. mkdir -p ${GEM_BASE}; \
  268. env -i ${MAKE_ENV} HOME=`dirname ${GEM_BASE}` GEM_HOME=${GEM_BASE} \
  269. make=${_GEM_MAKE} \
  270. ${GEM} install ${GEM_FLAGS} ${WRKDIR}/${_GEM_PATCHED} \
  271. -- ${CONFIGURE_ARGS}
  272. # Take the temporary gem directory, install the binary stub files to
  273. # the appropriate directory, and move and fix ownership the gem library
  274. # files.
  275. MODRUBY_INSTALL_TARGET = \
  276. if [ -d ${GEM_BASE_BIN} ]; then \
  277. ${INSTALL_DATA_DIR} ${PREFIX}/${GEM_BIN}; \
  278. for f in ${GEM_BASE_BIN}/*; do \
  279. ${INSTALL_SCRIPT} $$f ${PREFIX}/${GEM_BIN}; \
  280. done; \
  281. rm -r ${GEM_BASE_BIN}; \
  282. fi; \
  283. ${INSTALL_DATA_DIR} ${GEM_ABS_PATH}; \
  284. cd ${GEM_BASE_LIB} && mv * ${GEM_ABS_PATH}; \
  285. if [ 'X' != "X${GEM_EXTENSIONS_FILE}" ]; then \
  286. mkdir -p ${PREFIX}/${GEM_EXTENSIONS_DIR}; \
  287. touch ${PREFIX}/${GEM_EXTENSIONS_FILE}; \
  288. fi
  289. chown -R ${SHAREOWN}:${SHAREGRP} ${GEM_ABS_PATH}
  290. . if !target(do-build)
  291. do-build:
  292. ${MODRUBY_BUILD_TARGET}
  293. . endif
  294. . if !target(do-install)
  295. do-install:
  296. ${MODRUBY_INSTALL_TARGET}
  297. . endif
  298. .elif ${CONFIGURE_STYLE:L:Msetup}
  299. MODRUBY_configure= \
  300. cd ${WRKSRC}; ${SETENV} ${CONFIGURE_ENV} ${RUBY} setup.rb config \
  301. --prefix=${PREFIX} ${CONFIGURE_ARGS};
  302. MODRUBY_BUILD_TARGET = \
  303. cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} ${RUBY} setup.rb setup
  304. MODRUBY_INSTALL_TARGET = \
  305. cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} ${RUBY} setup.rb install \
  306. --prefix=${DESTDIR}
  307. . if !target(do-build)
  308. do-build:
  309. ${MODRUBY_BUILD_TARGET}
  310. . endif
  311. . if !target(do-install)
  312. do-install:
  313. ${MODRUBY_INSTALL_TARGET}
  314. . endif
  315. .endif
  316. # These are mostly used by the non-gem ports.
  317. SUBST_VARS+= ^MODRUBY_SITEARCHDIR ^MODRUBY_SITEDIR MODRUBY_LIBREV \
  318. MODRUBY_ARCH
  319. # test stuff
  320. .if !empty(MODRUBY_TEST)
  321. . if !target(do-test)
  322. . if ${MODRUBY_TEST:L:Mrake}
  323. MODRUBY_TEST_BIN ?= ${RAKE} --trace
  324. . elif ${MODRUBY_TEST:L:Mrspec}
  325. MODRUBY_TEST_BIN ?= ${RSPEC}
  326. . elif ${MODRUBY_TEST:L:Mrspec3}
  327. MODRUBY_TEST_BIN ?= ${MODRUBY_BIN_RSPEC}
  328. . elif ${MODRUBY_TEST:L:Mtestrb}
  329. . if ${MODRUBY_REV} == "1.8" || ${MODRUBY_REV} == "2.1"
  330. MODRUBY_TEST_BIN ?= ${MODRUBY_BIN_TESTRB}
  331. . else
  332. MODRUBY_TEST_BIN ?= ${RUBY} ${PORTSDIR}/lang/ruby/files/testrb.rb
  333. . endif
  334. . elif ${MODRUBY_TEST:L:Mruby}
  335. MODRUBY_TEST_BIN ?= ${RUBY}
  336. . endif
  337. . if ${MODRUBY_TEST:L:Mrspec} || ${MODRUBY_TEST:L:Mrspec3}
  338. MODRUBY_TEST_TARGET ?= spec
  339. . else
  340. MODRUBY_TEST_TARGET ?= test
  341. . endif
  342. MODRUBY_TEST_ENV ?=
  343. MODRUBY_TEST_ENV += RUBYLIB=.:"$$RUBYLIB"
  344. MODRUBY_TEST_DIR ?= ${WRKSRC}
  345. do-test:
  346. cd ${MODRUBY_TEST_DIR} && ${SETENV} ${MAKE_ENV} HOME=${WRKBUILD} \
  347. ${MODRUBY_TEST_ENV} ${MODRUBY_TEST_BIN} \
  348. ${MODRUBY_TEST_TARGET}
  349. . endif
  350. .endif