diff options
Diffstat (limited to 'lang/ruby/ruby.port.mk')
| -rw-r--r-- | lang/ruby/ruby.port.mk | 280 |
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 | |||
| 7 | CATEGORIES+= 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} | ||
| 12 | MODRUBY_HANDLE_FLAVORS ?= Yes | ||
| 13 | .else | ||
| 14 | MODRUBY_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) | ||
| 28 | FLAVORS= 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. | ||
| 35 | FULLPKGNAME?= ${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. | ||
| 42 | SUBST_VARS+= GEM_BIN_SUFFIX GEM_MAN_SUFFIX | ||
| 43 | |||
| 44 | FLAVOR?= | ||
| 45 | # Without a FLAVOR, assume the use of ruby 3.2. | ||
| 46 | . if empty(FLAVOR) | ||
| 47 | FLAVOR = 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} | ||
| 54 | MODRUBY_REV = ${i:C/ruby([0-9])/\1./} | ||
| 55 | . if ${FLAVOR:N$i:Mruby31} || \ | ||
| 56 | ${FLAVOR:N$i:Mruby32} || \ | ||
| 57 | ${FLAVOR:N$i:Mruby33} | ||
| 58 | ERRORS += "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. | ||
| 67 | MODRUBY_REV?= 3.2 | ||
| 68 | |||
| 69 | # Use the FLAVOR as the prefix for the package, to avoid conflicts. | ||
| 70 | MODRUBY_PKG_PREFIX = ${MODRUBY_FLAVOR} | ||
| 71 | |||
| 72 | GEM_BIN_SUFFIX = ${MODRUBY_BINREV} | ||
| 73 | GEM_MAN_SUFFIX = ${GEM_BIN_SUFFIX} | ||
| 74 | MODRUBY_ARCH= ${MACHINE_ARCH:S/amd64/x86_64/}-openbsd | ||
| 75 | MODRUBY_BINREV = ${MODRUBY_LIBREV:S/.//} | ||
| 76 | MODRUBY_BIN_RSPEC = ${LOCALBASE}/bin/rspec${MODRUBY_BINREV} | ||
| 77 | MODRUBY_FLAVOR = ruby${MODRUBY_BINREV} | ||
| 78 | MODRUBY_LIBREV = ${MODRUBY_REV} | ||
| 79 | MODRUBY_BUILD_DEPENDS= ${MODRUBY_RUN_DEPENDS} | ||
| 80 | MODRUBY_LIB_DEPENDS= ${MODRUBY_RUN_DEPENDS} | ||
| 81 | MODRUBY_RUN_DEPENDS= lang/ruby/${MODRUBY_REV} | ||
| 82 | MODRUBY_SITEARCHDIR = ${MODRUBY_SITEDIR}/${MODRUBY_ARCH} | ||
| 83 | MODRUBY_SITEDIR = lib/ruby/site_ruby/${MODRUBY_LIBREV} | ||
| 84 | MODRUBY_RELEXAMPLEDIR= share/examples/${MODRUBY_PKG_PREFIX} | ||
| 85 | MODRUBY_WANTLIB= ruby${MODRUBY_BINREV} | ||
| 86 | RAKE= ${LOCALBASE}/bin/rake${MODRUBY_BINREV} | ||
| 87 | RUBY= ${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} | ||
| 94 | ERRORS += "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. | ||
| 100 | NO_TEST = Yes | ||
| 101 | . endif | ||
| 102 | . endif | ||
| 103 | MODRUBY_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. | ||
| 108 | MODRUBY_BUILDDEP?= Yes | ||
| 109 | MODRUBY_RUNDEP?= Yes | ||
| 110 | |||
| 111 | .if ${NO_BUILD:L} == no && ${MODRUBY_BUILDDEP:L} == yes | ||
| 112 | BUILD_DEPENDS+= ${MODRUBY_BUILD_DEPENDS} | ||
| 113 | .endif | ||
| 114 | .if ${MODRUBY_RUNDEP:L} == yes | ||
| 115 | RUN_DEPENDS+= ${MODRUBY_RUN_DEPENDS} | ||
| 116 | .endif | ||
| 117 | |||
| 118 | .if ${MODRUBY_TEST:L:Mrspec3} | ||
| 119 | TEST_DEPENDS+= ${_MODRUBY_RSPEC3_DEPENDS} | ||
| 120 | .endif | ||
| 121 | |||
| 122 | MODRUBY_RUBY_ADJ = perl -pi \ | ||
| 123 | -e '$$. == 1 && s|^.*env ruby.*$$|\#!${RUBY}|;' \ | ||
| 124 | -e '$$. == 1 && s|^.*bin/ruby.*$$|\#!${RUBY}|;' \ | ||
| 125 | -e 'close ARGV if eof;' | ||
| 126 | MODRUBY_ADJ_FILES?= | ||
| 127 | .if !empty(MODRUBY_ADJ_FILES) | ||
| 128 | MODRUBY_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 | |||
| 134 | MODRUBY_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} == * | ||
| 141 | ERRORS+= "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 | ||
| 146 | WANTLIB+= ${MODRUBY_WANTLIB} | ||
| 147 | LIB_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. | ||
| 152 | SITES?= ${SITE_RUBYGEMS} | ||
| 153 | EXTRACT_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} | ||
| 158 | COMPILER ?= base-clang ports-gcc | ||
| 159 | COMPILER_LANGS ?= c | ||
| 160 | . endif | ||
| 161 | # Add build complete file to package so rubygems doesn't complain | ||
| 162 | # or build extensions at runtime | ||
| 163 | GEM_EXTENSIONS_DIR ?= ${GEM_LIB}/extensions/${MODRUBY_ARCH:S/i386/x86/}/${MODRUBY_REV}/${DISTNAME} | ||
| 164 | _GEM_EXTENSIONS_FILE ?= ${GEM_EXTENSIONS_DIR}/gem.build_complete | ||
| 165 | SUBST_VARS+= GEM_EXTENSIONS_DIR | ||
| 166 | PKG_ARGS+= -f ${PORTSDIR}/lang/ruby/rubygems-ext.PLIST | ||
| 167 | . else | ||
| 168 | # Pure ruby gem ports without C extensions are arch-independent. | ||
| 169 | PKG_ARCH= * | ||
| 170 | . endif | ||
| 171 | |||
| 172 | GEM= ${LOCALBASE}/bin/gem${MODRUBY_BINREV} | ||
| 173 | GEM_BIN = bin | ||
| 174 | GEM_LIB = lib/ruby/gems/${MODRUBY_LIBREV} | ||
| 175 | GEM_BASE_LIB= ${_GEM_BASE}/ruby/${MODRUBY_LIBREV} | ||
| 176 | _GEM_BASE= ${WRKDIR}/gem-tmp/.gem | ||
| 177 | _GEM_ABS_PATH= ${PREFIX}/${GEM_LIB} | ||
| 178 | GEM_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. | ||
| 183 | GEM_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. | ||
| 193 | EXTRACT_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) | ||
| 236 | do-build: | ||
| 237 | ${_MODRUBY_BUILD_TARGET} | ||
| 238 | . endif | ||
| 239 | . if !target(do-install) | ||
| 240 | do-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. | ||
| 247 | SUBST_VARS += MODRUBY_RELEXAMPLEDIR MODRUBY_SITEARCHDIR MODRUBY_SITEDIR \ | ||
| 248 | MODRUBY_LIBREV MODRUBY_ARCH GEM_LIB GEM_BIN DISTNAME | ||
| 249 | UPDATE_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} | ||
| 268 | MODRUBY_TEST_TARGET ?= spec | ||
| 269 | . else | ||
| 270 | MODRUBY_TEST_TARGET ?= test | ||
| 271 | . endif | ||
| 272 | |||
| 273 | MODRUBY_TEST_ENV ?= | ||
| 274 | MODRUBY_TEST_ENV += RUBYLIB=.:"$$RUBYLIB" | ||
| 275 | do-test: | ||
| 276 | cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} HOME=${WRKBUILD} \ | ||
| 277 | ${MODRUBY_TEST_ENV} ${_MODRUBY_TEST_BIN} \ | ||
| 278 | ${MODRUBY_TEST_TARGET} | ||
| 279 | . endif | ||
| 280 | .endif | ||
