1 ################################################################################
3 # rubygem.cygclass - functions for building RubyGems packages
5 # Part of cygport - Cygwin packaging application
6 # Copyright (C) 2006-2020 Cygport authors
7 # Provided by the Cygwin project <https://cygwin.com/>
9 # cygport is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # cygport is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with cygport. If not, see <https://www.gnu.org/licenses/>.
22 ################################################################################
24 #****h* Cygclasses/rubygem.cygclass
28 # RubyGems is a Ruby extension hosting service, much like CPAN is for Perl.
29 # Packages are distributed in the .gem format and have a unique installation
30 # scheme which allows for multiple versions of any package to be installed.
31 # Since Ruby 1.9, RubyGems is fully integrated into Ruby, and has become the
32 # preferred way to distribute Ruby extensions.
34 # This cygclass provides a framework for building RubyGems packages for Cygwin.
41 check_prog_req gem rubygems
43 #****o* rubygem.cygclass/RUBYGEM_NAME
45 # The original package name of the package as listed on RubyGems. The default
46 # value is NAME without the leading "ruby-", which covers most RubyGems packages.
47 # ORIG_PN is also supported for backwards compatibility.
49 : ${RUBYGEM_NAME=${ORIG_PN:-${NAME#ruby-}}}
51 #****o* rubygem.cygclass/CATEGORY (rubygem)
55 #****o* rubygem.cygclass/SUMMARY (rubygem)
57 SUMMARY="Ruby ${NAME#ruby-} module"
59 #****o* rubygem.cygclass/HOMEPAGE (rubygem)
61 # Default homepage of the Ruby module on RubyGems.
63 HOMEPAGE="https://rubygems.org/gems/${RUBYGEM_NAME}"
65 #****o* rubygem.cygclass/SRC_URI (rubygem)
67 # Default download location of the Ruby module on RubyGems.
69 SRC_URI="https://rubygems.org/downloads/${RUBYGEM_NAME}-${VERSION}.gem"
71 SRC_DIR="${RUBYGEM_NAME}-${VERSION}"
73 #****d* rubygem.cygclass/RUBYGEM_DIR
75 # The RubyGems system root directory, namely /usr/share/gems.
77 RUBYGEM_DIR=$(${RUBY} -e 'print Gem.default_dirs[:system][:gem_dir]')
79 #****d* rubygem.cygclass/RUBYGEM_INSTDIR
81 # The directory containing the original runtime content of this particular Gem.
83 RUBYGEM_INSTDIR=${RUBYGEM_DIR}/gems/${RUBYGEM_NAME}-${VERSION}
85 # this file is removed, no need for it in the binary package
86 RUBYGEM_CACHE=${RUBYGEM_DIR}/cache/${RUBYGEM_NAME}-${VERSION}.gem
88 #****d* rubygem.cygclass/RUBYGEM_SPEC
90 # The RubyGems specification file for this particular Gem.
92 RUBYGEM_SPEC=${RUBYGEM_DIR}/specifications/${RUBYGEM_NAME}-${VERSION}.gemspec
94 #****d* rubygem.cygclass/RUBYGEM_DOCDIR
96 # The directory containing the generated documentation of this particular Gem.
98 RUBYGEM_DOCDIR=${RUBYGEM_DIR}/doc/${RUBYGEM_NAME}-${VERSION}
100 #****d* rubygem.cygclass/RUBYGEM_EXTDIR
102 # The directory containing any native compiled extensions of this particular Gem.
104 RUBYGEM_EXTDIR=$(${RUBY} -e 'print Gem.default_dirs[:system][:ext_dir]')/ruby/${RUBY_VERSION%.*}/${RUBYGEM_NAME}-${VERSION}
107 #****C* rubygem.cygclass/rubygem_compile
111 # Rebuilds the source gem (including any patches made to files in $S) and
112 # prepares it for installation.
115 gem build ${RUBYGEM_NAME}.gemspec || error "gem build failed"
118 #****I* rubygem.cygclass/rubygem_install
120 # rubygem_install [CONFIGURE_FLAGS]
122 # Installs the gem contents into $D. Any arguments are passed to extconf.rb
123 # as configure flags.
125 # RUBYGEM_CONFIGURE_ARGS
128 #****v* rubygem.cygclass/RUBYGEM_CONFIGURE_ARGS
130 # Configure flags to be passed to extconf.rb when compiling Gems with
133 CONFIGURE_ARGS="--with-cflags='${CFLAGS} -fdebug-prefix-map=${D}${RUBYGEM_INSTDIR}=/usr/src/debug/${NAME}-${VERSION}-${RELEASE}' $RUBYGEM_CONFIGURE_ARGS $@" \
134 gem install -V --local --ignore-dependencies --document=rdoc,ri \
135 --build-root ${D} --install-dir ${RUBYGEM_DIR} --bindir $(__host_prefix)/bin \
136 ${RUBYGEM_NAME}-${VERSION}.gem || error "gem install failed"
138 # used later to clean up RUBYGEM_INSTDIR
139 gem spec ${RUBYGEM_NAME}-${VERSION}.gem files --yaml \
140 | sed -e 's|^[- ]*|./|g' > ${B}/${RUBYGEM_NAME}-${VERSION}.gem.lst
142 # no need for a copy of the source gem in the binary package
143 rm -f ${D}${RUBYGEM_CACHE}
145 pushd ${D}${RUBYGEM_INSTDIR}
147 # Ruby-GNOME2 components
148 if [ -f ext/${RUBYGEM_NAME}/libruby-${RUBYGEM_NAME/-/_}.a ]
150 dolib ext/${RUBYGEM_NAME}/libruby-${RUBYGEM_NAME/-/_}.a
152 if [ -f ext/${RUBYGEM_NAME}/ruby-${RUBYGEM_NAME/_/-}.pc ]
154 dopkgconfig ext/${RUBYGEM_NAME}/ruby-${RUBYGEM_NAME/_/-}.pc
157 # clean up built files
158 find -type f | grep -Fxvf ${B}/${RUBYGEM_NAME}-${VERSION}.gem.lst | xargs rm -f
159 # these are not needed once installed
160 rm -fr Rakefile *.gemspec depend extconf.rb install.rb setup.rb doc/ ext/ src/ test/
162 popd # ${D}${RUBYGEM_INSTDIR}
164 if [ -d ${D}${RUBYGEM_EXTDIR} ]
166 pushd ${D}${RUBYGEM_EXTDIR}
168 # more Ruby-GNOME2 components
169 for h in $(find -name '*.h')
171 dodir ${RUBY_HEADERDIR}
172 mv ${h} ${D}${RUBY_HEADERDIR}/
175 # these are not needed, but gem.build_complete must remain
176 rm -f gem_make.out mkmf.log
178 popd # ${D}${RUBYGEM_EXTDIR}
182 #****o* rubygem.cygclass/src_compile (rubygem)
190 #****o* rubygem.cygclass/src_install (rubygem)
198 # docs are already installed into RUBYGEM_INSTDIR
199 _CYGPORT_RESTRICT_postinst_doc_=1
201 readonly -f rubygem_compile rubygem_install