2 # This helper is for templates using gemspec files from upstream or Rubygems.
6 : ${gemspec:=${pkgname#ruby-}.gemspec}
8 # Fix packages that keep Gem.gemspec as the name instead of the proper
10 if [ -f Gem.gemspec
]; then
14 if [ -f .gemspec
]; then
18 # Hardcode name and version just in case they try something funny like
19 # requiring RELEASE to be on the environment to not append -rc0 to version
20 # Some even forget to update the version in the gemspec after releasing
21 sed -ri "s|(\.name .*)=.*|\1 = \"${pkgname#ruby-}\"|g" $gemspec
22 sed -ri "s|(\.version .*)=.*|\1 = \"${version}\"|g" $gemspec
24 # Replace use of `git ls-files` with find, use printf so we can print without starting
26 sed -i 's|`git ls-files`|`find . -type f -printf "%P\\n"`|g' $gemspec
28 # Sadly ruby isn't capable of handling nullbytes in a command so we have to use
29 # -print0, then try using sed to remove the suffix
31 # `find . -type f -print0 | sed -e "s@\\./@@g"`
32 sed -i 's|`git ls-files -z`|`find . -type f -print0 \| sed -e "s@\\\\./@@g"`|g' $gemspec
34 if [ "$CROSS_BUILD" ]; then
36 local _TARGET_PLATFORM
38 _TARGET_PLATFORM
="$(ruby -r \
39 $(find ${XBPS_CROSS_BASE}/usr/lib/ruby -iname rbconfig.rb) \
40 -e 'puts RbConfig::CONFIG["arch
"]' 2>/dev/null)"
42 # Patch all instances of extconf that use create_makefile
43 for f
in $
(find .
-type f
-name 'extconf.rb'); do
44 if [ ! -f ${f}.orig
]; then
45 # Create a .extconf file that forces the Makefile to use our environment
46 # this allows us to cross-compile like it is done with meson cross-files
48 \$CPPFLAGS = ENV['CPPFLAGS'] if ENV['CPPFLAGS']
49 RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
50 RbConfig::MAKEFILE_CONFIG['CXX'] = ENV['CXX'] if ENV['CXX']
51 RbConfig::MAKEFILE_CONFIG['LD'] = ENV['LD'] if ENV['LD']
52 RbConfig::MAKEFILE_CONFIG['CFLAGS'] = ENV['CFLAGS'] if ENV['CFLAGS']
53 RbConfig::MAKEFILE_CONFIG['CPPFLAGS'] = ENV['CPPFLAGS'] if ENV['CPPFLAGS']
54 RbConfig::MAKEFILE_CONFIG['CXXFLAGS'] = ENV['CXXFLAGS'] if ENV['CXXFLAGS']
57 # Use sed and enable verbose mode
59 system("sed -i 's|^V =.*|V = 1|' Makefile")
60 system("sed -i 's|^CFLAGS.*|CFLAGS = \$(CCDLFLAGS) ${VOID_TARGET_CFLAGS} \$(ARCH_FLAG)|' Makefile")
61 system("sed -i 's|^topdir.*|topdir = ${XBPS_CROSS_BASE}/usr/include/ruby-\$(ruby_version)|' Makefile")
62 system("sed -i 's|^hdrdir.*|hdrdir = ${XBPS_CROSS_BASE}/usr/include/ruby-\$(ruby_version)|' Makefile")
63 system("sed -i 's|^arch_hdrdir.*|arch_hdrdir = ${XBPS_CROSS_BASE}/usr/include/ruby-\$(ruby_version)/\$(arch)|' Makefile")
64 system("sed -i 's|^arch =.*|arch = ${_TARGET_PLATFORM}|' Makefile")
65 system("sed -i 's|^dldflags =.*|dldflags = ${LDFLAGS}|' Makefile")
68 # Create a backup which we will restore later
71 # Patch extconf.rb for cross compile
72 cat append append2
> $f
77 # If we are downloading a gem file then create a spec out of it
78 for f
in $distfiles; do
79 if [ "${f##*.}" = "gem" ]; then
81 "${XBPS_SRCDISTDIR}/${pkgname}-${version}/${f##*/}" \
86 sed 's|~>|>=|g' -i $gemspec
88 $gem_cmd build
--verbose ${gemspec}
90 if [ "$CROSS_BUILD" ]; then
91 # Restore previous extconf.rb which we ship.
92 find .
-type f
-name 'extconf.rb.orig' |
while read -r f
; do
101 local _GEMDIR _INSTDIR
103 _GEMDIR
=$
($gem_cmd env gemdir
)
104 _INSTDIR
=${DESTDIR}/${_GEMDIR}/gems/${pkgname#ruby-}-${version}
106 # Ruby is very eager to add CFLAGS everywhere there is a compilation
107 # but we do both cross compilation of the modules and host compilation
108 # for checks, so unset CFLAGS and keep it in a separate value.
109 # We will manually pass CFLAGS as VOID_TAGET_CFLAGS to cross-compilation
110 # And ruby will use rbconfig.rb to get the proper CFLAGS for host compilation
111 VOID_TARGET_CFLAGS
="$CFLAGS"
112 export VOID_TARGET_CFLAGS
117 --install-dir ${DESTDIR}/${_GEMDIR} \
118 --bindir ${DESTDIR}/usr
/bin \
119 --ignore-dependencies \
122 "${pkgname#ruby-}-${version}.gem" \
126 rm -rf ${DESTDIR}/${_GEMDIR}/cache
128 # Remove ext directory, they are only source code and configuration
129 # The actual extensions are in a arch path guarded
130 rm -rf ${_INSTDIR}/ext
132 # Remove duplicated library that is available in a arch guarded
134 rm -rf ${_INSTDIR}/lib
/*.so
136 # Remove installed tests and benchmarks
137 rm -rf ${_INSTDIR}/{test,tests
,autotest
,benchmark
,benchmarks
,script,examples
,demo
}
139 # Remove files shipped on the root of the gem, most of the time they are useless
140 find ${_INSTDIR} -maxdepth 1 -type f
-delete
142 # Remove unnecessary files
143 find ${DESTDIR}/${_GEMDIR}/extensions \
( -name mkmf.log
-o -name gem_make.out \
) -delete
145 # Place manpages in usr/share/man/man[0-9]
146 if [ -d ${_INSTDIR}/man
]; then
147 find ${_INSTDIR}/man
-type f
-name '*.[0-8n]' |
while read -r m
; do
152 rm -rf "${_INSTDIR}/man"
154 # Place executables in /usr/bin
155 if [ -d "${_INSTDIR}/bin" ]; then
156 for f
in "${_INSTDIR}"/bin
/*; do
161 rm -rf ${_INSTDIR}/bin
163 # Place conf files in their places
164 if [ -d ${_INSTDIR}/etc
]; then
165 find ${_INSTDIR}/etc
-type f |
while read -r c
; do
167 mv ${c} "${DESTDIR}/${c##*${_INSTDIR}/etc/}/"
171 rm -rf ${_INSTDIR}/etc
173 if [ "$CROSS_BUILD" ]; then
175 local _TARGET_PLATFORM _TARGET_EXT_DIR
177 # Get arch of the target and host platform by reading the rbconfig.rb
179 _TARGET_PLATFORM="$
(ruby
-r \
180 $
(find ${XBPS_CROSS_BASE}/usr
/lib
/ruby
-iname rbconfig.rb
) \
181 -e 'puts RbConfig::CONFIG["arch"]' 2>/dev
/null
)"
183 # Path to the extensions on a package, ruby installs against the platform
184 # of the host, so we have to move them to the correct place
185 _TARGET_EXT_DIR="${DESTDIR}/${_GEMDIR}/extensions/${_TARGET_PLATFORM}"
187 find ${DESTDIR}/${_GEMDIR}/extensions -maxdepth 1 -type d \
188 -exec mv '{}' ${_TARGET_EXT_DIR} \;