summaryrefslogtreecommitdiff
path: root/lang/ruby/ruby.port.mk
diff options
context:
space:
mode:
Diffstat (limited to 'lang/ruby/ruby.port.mk')
-rw-r--r--lang/ruby/ruby.port.mk280
1 files changed, 280 insertions, 0 deletions
diff --git a/lang/ruby/ruby.port.mk b/lang/ruby/ruby.port.mk
new file mode 100644
index 0000000..cf2d743
--- /dev/null
+++ b/lang/ruby/ruby.port.mk
@@ -0,0 +1,280 @@
1# ruby module
2
3# Variables defined in this file that prefixed with _ are designed for
4# internal use, not currently used in the ports tree outside this file,
5# and are purposely not documented.
6
7CATEGORIES+= lang/ruby
8
9# Whether the ruby module should automatically add FLAVORs.
10# If left blank, does so only for gem ports.
11.if ${CONFIGURE_STYLE:L:Mgem}
12MODRUBY_HANDLE_FLAVORS ?= Yes
13.else
14MODRUBY_HANDLE_FLAVORS ?= No
15.endif
16
17# This allows you to build packages for multiple ruby versions and
18# implementations using the same port directory for gem
19# ports. It does this by adding FLAVORS automatically, unless FLAVORS are
20# already defined or the port defines MODRUBY_REV to tie the port to a specific
21# ruby version.
22.if !defined(MODRUBY_REV)
23. if ${MODRUBY_HANDLE_FLAVORS:L:Myes}
24
25# If ruby.pork.mk should handle FLAVORs, define a separate FLAVOR
26# for each ruby version.
27. if !defined(FLAVORS)
28FLAVORS= ruby31 ruby32 ruby33
29. endif
30
31# Instead of adding flavors to the end of the package name, we use
32# different package stems (rubyXY-*) for different ruby versions.
33# In most cases, PKGNAME in the port should be set to the same as
34# DISTNAME, and this will insert the correct package prefix.
35FULLPKGNAME?= ${MODRUBY_PKG_PREFIX}-${PKGNAME}
36
37# If the port installs binary files or man pages and can work on multiple
38# versions of ruby, those files should have the appropriate suffix so that
39# they do not conflict. GEM_BIN_SUFFIX should be added after such a filename
40# in the PLIST so that the gem will correctly package on all supported
41# versions of ruby.
42SUBST_VARS+= GEM_BIN_SUFFIX GEM_MAN_SUFFIX
43
44FLAVOR?=
45# Without a FLAVOR, assume the use of ruby 3.2.
46. if empty(FLAVOR)
47FLAVOR = ruby32
48. endif
49
50# Check for conflicting FLAVORs and set MODRUBY_REV appropriately based
51# on the FLAVOR.
52. for i in ruby31 ruby32 ruby33
53. if ${FLAVOR:M$i}
54MODRUBY_REV = ${i:C/ruby([0-9])/\1./}
55. if ${FLAVOR:N$i:Mruby31} || \
56 ${FLAVOR:N$i:Mruby32} || \
57 ${FLAVOR:N$i:Mruby33}
58ERRORS += "Fatal: Conflicting flavors used: ${FLAVOR}"
59. endif
60. endif
61. endfor
62. endif
63.endif
64
65# The default ruby version to use for non-gem ports. Defaults to ruby
66# 3.2 for consistency with the default ruby32 FLAVOR for gem ports.
67MODRUBY_REV?= 3.2
68
69# Use the FLAVOR as the prefix for the package, to avoid conflicts.
70MODRUBY_PKG_PREFIX = ${MODRUBY_FLAVOR}
71
72GEM_BIN_SUFFIX = ${MODRUBY_BINREV}
73GEM_MAN_SUFFIX = ${GEM_BIN_SUFFIX}
74MODRUBY_ARCH= ${MACHINE_ARCH:S/amd64/x86_64/}-openbsd
75MODRUBY_BINREV = ${MODRUBY_LIBREV:S/.//}
76MODRUBY_BIN_RSPEC = ${LOCALBASE}/bin/rspec${MODRUBY_BINREV}
77MODRUBY_FLAVOR = ruby${MODRUBY_BINREV}
78MODRUBY_LIBREV = ${MODRUBY_REV}
79MODRUBY_BUILD_DEPENDS= ${MODRUBY_RUN_DEPENDS}
80MODRUBY_LIB_DEPENDS= ${MODRUBY_RUN_DEPENDS}
81MODRUBY_RUN_DEPENDS= lang/ruby/${MODRUBY_REV}
82MODRUBY_SITEARCHDIR = ${MODRUBY_SITEDIR}/${MODRUBY_ARCH}
83MODRUBY_SITEDIR = lib/ruby/site_ruby/${MODRUBY_LIBREV}
84MODRUBY_RELEXAMPLEDIR= share/examples/${MODRUBY_PKG_PREFIX}
85MODRUBY_WANTLIB= ruby${MODRUBY_BINREV}
86RAKE= ${LOCALBASE}/bin/rake${MODRUBY_BINREV}
87RUBY= ${LOCALBASE}/bin/ruby${MODRUBY_BINREV}
88
89_MODRUBY_RSPEC3_DEPENDS = devel/ruby-rspec/3/rspec,${MODRUBY_FLAVOR}>=3.0
90
91.if defined(MODRUBY_TEST)
92. if !${MODRUBY_TEST:L:Mrspec3} && !${MODRUBY_TEST:L:Mtestrb} && \
93 !${MODRUBY_TEST:L:Mrake} && !${MODRUBY_TEST:L:Mruby}
94ERRORS += "Fatal: Unsupported MODRUBY_TEST value: ${MODRUBY_TEST}"
95. endif
96.else
97. if ${CONFIGURE_STYLE:L:Mgem}
98. if !target(do-test)
99# Disable regress for gem ports, since they won't use make check for test.
100NO_TEST = Yes
101. endif
102. endif
103MODRUBY_TEST?=
104.endif
105
106# Assume that we want to automatically add ruby to BUILD_DEPENDS
107# and RUN_DEPENDS unless the port specifically requests not to.
108MODRUBY_BUILDDEP?= Yes
109MODRUBY_RUNDEP?= Yes
110
111.if ${NO_BUILD:L} == no && ${MODRUBY_BUILDDEP:L} == yes
112BUILD_DEPENDS+= ${MODRUBY_BUILD_DEPENDS}
113.endif
114.if ${MODRUBY_RUNDEP:L} == yes
115RUN_DEPENDS+= ${MODRUBY_RUN_DEPENDS}
116.endif
117
118.if ${MODRUBY_TEST:L:Mrspec3}
119TEST_DEPENDS+= ${_MODRUBY_RSPEC3_DEPENDS}
120.endif
121
122MODRUBY_RUBY_ADJ = perl -pi \
123 -e '$$. == 1 && s|^.*env ruby.*$$|\#!${RUBY}|;' \
124 -e '$$. == 1 && s|^.*bin/ruby.*$$|\#!${RUBY}|;' \
125 -e 'close ARGV if eof;'
126MODRUBY_ADJ_FILES?=
127.if !empty(MODRUBY_ADJ_FILES)
128MODRUBY_pre-configure +=for pat in ${MODRUBY_ADJ_FILES:QL}; do \
129 find ${WRKSRC} -type f -name "$$pat" \
130 -exec ${MODRUBY_RUBY_ADJ} {} + ; \
131 done
132.endif
133
134MODRUBY_WANTLIB+= c gmp m pthread
135
136.if ${CONFIGURE_STYLE:L:Mext}
137# Ruby C exensions are specific to an arch and are loaded as
138# shared libraries (not compiled into ruby), so make sure PKG_ARCH=*
139# is not set.
140. if defined(PKG_ARCH) && ${PKG_ARCH} == *
141ERRORS+= "Fatal: Should not have PKG_ARCH=* when compiling extensions"
142. endif
143
144# Add appropriate libraries to WANTLIB depending on ruby version and
145# implementation
146WANTLIB+= ${MODRUBY_WANTLIB}
147LIB_DEPENDS+= ${MODRUBY_LIB_DEPENDS}
148.endif
149
150.if ${CONFIGURE_STYLE:L:Mgem}
151# All gems should be in the same directory on rubygems.org.
152SITES?= ${SITE_RUBYGEMS}
153EXTRACT_SUFX= .gem
154
155. if ${CONFIGURE_STYLE:L:Mext}
156# Use ports-gcc for ruby32 extensions if base does not use clang
157. if ${FLAVOR:Mruby32} || ${FLAVOR:Mruby33}
158COMPILER ?= base-clang ports-gcc
159COMPILER_LANGS ?= c
160. endif
161# Add build complete file to package so rubygems doesn't complain
162# or build extensions at runtime
163GEM_EXTENSIONS_DIR ?= ${GEM_LIB}/extensions/${MODRUBY_ARCH:S/i386/x86/}/${MODRUBY_REV}/${DISTNAME}
164_GEM_EXTENSIONS_FILE ?= ${GEM_EXTENSIONS_DIR}/gem.build_complete
165SUBST_VARS+= GEM_EXTENSIONS_DIR
166PKG_ARGS+= -f ${PORTSDIR}/lang/ruby/rubygems-ext.PLIST
167. else
168# Pure ruby gem ports without C extensions are arch-independent.
169PKG_ARCH= *
170. endif
171
172GEM= ${LOCALBASE}/bin/gem${MODRUBY_BINREV}
173GEM_BIN = bin
174GEM_LIB = lib/ruby/gems/${MODRUBY_LIBREV}
175GEM_BASE_LIB= ${_GEM_BASE}/ruby/${MODRUBY_LIBREV}
176_GEM_BASE= ${WRKDIR}/gem-tmp/.gem
177_GEM_ABS_PATH= ${PREFIX}/${GEM_LIB}
178GEM_BASE_BIN= ${GEM_BASE_LIB}/bin
179
180# We purposely do not install documentation for ruby gems, because
181# the filenames are generated differently on different ruby versions,
182# and most use 1 file per method, which is insane.
183GEM_FLAGS+= --local -N --no-force --verbose --backtrace --user-install
184_GEM_CONTENT= ${WRKDIR}/gem-content
185_GEM_DATAFILE= ${_GEM_CONTENT}/data.tar.gz
186_GEM_PATCHED= ${DISTNAME}${EXTRACT_SUFX}
187_GEM_MAKE= "make V=1"
188
189# Unpack the gem into WRKDIST so it can be patched. Include the gem metadata
190# under WRKDIST so it can be patched easily to remove or change dependencies.
191# Remove any signing of packages, as patching the gem could then break the
192# signatures.
193EXTRACT_CASES += *.gem) \
194 mkdir ${WRKDIST} ${_GEM_CONTENT}; \
195 tar -xf ${FULLDISTDIR}/$$archive -C ${_GEM_CONTENT}; \
196 tar -xzf ${_GEM_DATAFILE} -C ${WRKDIST} && rm -f ${_GEM_DATAFILE}; \
197 gzcat ${_GEM_CONTENT}/metadata.gz > ${WRKDIST}/.metadata; \
198 rm -f ${_GEM_CONTENT}/*.gz.sig ${_GEM_CONTENT}/checksums.yaml.gz;;
199
200# Rebuild the gem manually after possible patching, then install it to a
201# temporary directory (not the final directory under fake).
202_MODRUBY_BUILD_TARGET = \
203 if [ -f ${WRKDIST}/.metadata ]; then \
204 cd ${WRKDIST} && gzip .metadata && \
205 mv -f .metadata.gz ${_GEM_CONTENT}/metadata.gz; \
206 fi; \
207 cd ${WRKDIST} && pax -wz -s '/.*${PATCHORIG:S@.@\.@g}$$//' \
208 -x ustar -o write_opt=nodir . >${_GEM_DATAFILE}; \
209 cd ${_GEM_CONTENT} && tar -cf ${WRKDIR}/${_GEM_PATCHED} *.gz; \
210 mkdir -p ${_GEM_BASE}; \
211 env -i ${MAKE_ENV} HOME=`dirname ${_GEM_BASE}` GEM_HOME=${_GEM_BASE} \
212 make=${_GEM_MAKE} \
213 ${GEM} install ${GEM_FLAGS} ${WRKDIR}/${_GEM_PATCHED} \
214 -- ${CONFIGURE_ARGS}
215
216# Take the temporary gem directory, install the binary stub files to
217# the appropriate directory, and move and fix ownership the gem library
218# files.
219_MODRUBY_INSTALL_TARGET = \
220 if [ -d ${GEM_BASE_BIN} ]; then \
221 ${INSTALL_DATA_DIR} ${PREFIX}/${GEM_BIN}; \
222 for f in ${GEM_BASE_BIN}/*; do \
223 ${INSTALL_SCRIPT} $$f ${PREFIX}/${GEM_BIN}; \
224 done; \
225 rm -r ${GEM_BASE_BIN}; \
226 fi; \
227 ${INSTALL_DATA_DIR} ${_GEM_ABS_PATH}; \
228 cd ${GEM_BASE_LIB} && mv * ${_GEM_ABS_PATH}; \
229 if [ 'X' != "X${_GEM_EXTENSIONS_FILE}" ]; then \
230 mkdir -p ${PREFIX}/${GEM_EXTENSIONS_DIR}; \
231 touch ${PREFIX}/${_GEM_EXTENSIONS_FILE}; \
232 fi
233 chown -R ${SHAREOWN}:${SHAREGRP} ${_GEM_ABS_PATH}
234
235. if !target(do-build)
236do-build:
237 ${_MODRUBY_BUILD_TARGET}
238. endif
239. if !target(do-install)
240do-install:
241 ${_MODRUBY_INSTALL_TARGET}
242. endif
243.endif
244
245# PLIST magic. Set variables so that the same PLIST will work for
246# all ruby versions and implementations.
247SUBST_VARS += MODRUBY_RELEXAMPLEDIR MODRUBY_SITEARCHDIR MODRUBY_SITEDIR \
248 MODRUBY_LIBREV MODRUBY_ARCH GEM_LIB GEM_BIN DISTNAME
249UPDATE_PLIST_ARGS += -s MODRUBY_RELEXAMPLEDIR -s MODRUBY_SITEARCHDIR \
250 -s MODRUBY_SITEDIR -s GEM_LIB -s GEM_BIN
251
252# test stuff
253
254.if !empty(MODRUBY_TEST)
255. if !target(do-test)
256
257. if ${MODRUBY_TEST:L:Mrake}
258_MODRUBY_TEST_BIN ?= ${RAKE}
259. elif ${MODRUBY_TEST:L:Mrspec3}
260_MODRUBY_TEST_BIN ?= ${MODRUBY_BIN_RSPEC}
261. elif ${MODRUBY_TEST:L:Mtestrb}
262_MODRUBY_TEST_BIN ?= ${RUBY} ${PORTSDIR}/lang/ruby/files/testrb.rb
263. elif ${MODRUBY_TEST:L:Mruby}
264_MODRUBY_TEST_BIN ?= ${RUBY}
265. endif
266
267. if ${MODRUBY_TEST:L:Mrspec3}
268MODRUBY_TEST_TARGET ?= spec
269. else
270MODRUBY_TEST_TARGET ?= test
271. endif
272
273MODRUBY_TEST_ENV ?=
274MODRUBY_TEST_ENV += RUBYLIB=.:"$$RUBYLIB"
275do-test:
276 cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} HOME=${WRKBUILD} \
277 ${MODRUBY_TEST_ENV} ${_MODRUBY_TEST_BIN} \
278 ${MODRUBY_TEST_TARGET}
279. endif
280.endif