#!/usr/bin/make -f
export SHELL := /bin/bash
.SHELLFLAGS := -c
export DH_VERBOSE = 1
export DH_OPTIONS = -v

#pie is enabled on Ubuntu16 by default and causes problems building shared libs
DEB_BUILD_MAINT_OPTIONS := hardening=-pie,+bindnow
DEB_BUILD_MAINT_OPTIONS += optimize=-lto
export DEB_BUILD_MAINT_OPTIONS

include /usr/share/dpkg/architecture.mk
include /usr/share/dpkg/pkg-info.mk
include /usr/share/dpkg/buildtools.mk

export SHELL = /bin/bash
export HOME=$(CURDIR)/build
export BUILD_DIR=$(shell pwd)

vafilt					= $(subst $(2)=,,$(filter $(2)=%,$(1)))
ARCHS					:= amd64 arm64 i386
DPKG_VARS				:= $(shell dpkg-architecture)
DEB_BUILD_ARCH			?= $(call vafilt,$(DPKG_VARS),DEB_BUILD_ARCH)
DEB_BUILD_GNU_TYPE		?= $(call vafilt,$(DPKG_VARS),DEB_BUILD_GNU_TYPE)
DEB_BUILD_MULTIARCH		?= $(call vafilt,$(DPKG_VARS),DEB_BUILD_MULTIARCH)
DEB_HOST_ARCH			?= $(call vafilt,$(DPKG_VARS),DEB_HOST_ARCH)
DEB_HOST_ARCH_ENDIAN	?= $(call vafilt,$(DPKG_VARS),DEB_HOST_ARCH_ENDIAN)
DEB_HOST_ARCH_OS		?= $(call vafilt,$(DPKG_VARS),DEB_HOST_ARCH_OS)
DEB_HOST_GNU_TYPE		?= $(call vafilt,$(DPKG_VARS),DEB_HOST_GNU_TYPE)
DEB_HOST_MULTIARCH		?= $(call vafilt,$(DPKG_VARS),DEB_HOST_MULTIARCH)

_sourcedir 		:= debian/source
_exec_prefix	:= /opt/alt/ruby26
_bindir 		:= /opt/alt/ruby26/bin
_libdir 		:= /opt/alt/ruby26/lib

_localstatedir 	:= /var
_includedir 	:= /opt/alt/ruby26/include
_datadir		:= /opt/alt/ruby26/share
_mandir 		:= $(_datadir)/man
_docdir 		:= ${_datadir}/doc
_metainfodir	:= /usr/share/metainfo
uname_m 		:= $(shell uname -m)
buildroot 		:= $(CURDIR)/debian/tmp


ruby_sitedir		:= site_ruby
ruby_vendordir	:= vendor_ruby
ruby_version		:= 2.6.10
srcname			:= alt-ruby26
ruby_api_version     := 2.6.0

ruby_libdir 		:= $(_libdir)/ruby/$(ruby_api_version)
ruby_libarchdir		:= $(_libdir)/ruby/$(ruby_api_version)/$(DEB_HOST_GNU_CPU)-$(DEB_HOST_ARCH_OS)
ruby_sitelibdir		:= $(_datadir)/ruby/$(ruby_sitedir)
ruby_sitearchdir	:= $(_libdir)/ruby/$(ruby_sitedir)
ruby_vendorlibdir	:= $(ruby_libdir)/$(ruby_vendordir)
ruby_vendorarchdir := $(ruby_libarchdir)/$(ruby_vendordir)
rubygems_dir 		:= $(_datadir)/rubygems

gem_dir			:= $(_libdir)/ruby/gems/$(ruby_api_version)

tapset_root 	:= $(_datadir)/systemtap
tapset_dir 	:= $(tapset_root)/tapset
tapset_libdir	:= $(shell echo $(_libdir) | sed 's/64//')

DPKG_CFLAGS := $(shell dpkg-buildflags --get CFLAGS)
DPKG_CFLAGS += -fno-semantic-interposition
DPKG_LDFLAGS := $(shell dpkg-buildflags --get LDFLAGS)

export CFLAGS := $(DPKG_CFLAGS) -g -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
export CXXFLAGS := $(DPKG_CFLAGS) -g -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I$(_includedir)
export LDFLAGS := $(DPKG_LDFLAGS) -L$(_libdir) -Wl,-rpath=$(_libdir)

NJOBS := -j$(shell getconf _NPROCESSORS_ONLN)

LANG=C
export LANG
DEB_CONFIGURE_NORMAL_ARGS =
DEB_CONFIGURE_EXTRA_FLAGS = \
--prefix=/opt/alt/ruby26 \
--exec-prefix=$(_exec_prefix) \
--bindir=$(_bindir) \
--datadir=$(_datadir) \
--includedir=$(_includedir) \
--libdir=$(_libdir) \
--mandir=$(_mandir) \
--with-ruby-pc='$(srcname).pc' \
--with-compress-debug-sections=no \
--enable-shared \
--enable-rpath \
--with-openssl-dir=/opt/alt/openssl \

OPENSSL_PREFIX := /opt/alt/openssl
OPENSSL_LIB := $(OPENSSL_PREFIX)/lib/$(DEB_HOST_MULTIARCH)
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$(OPENSSL_LIB)/pkgconfig
export LDFLAGS += -Wl,-rpath=$(OPENSSL_LIB)
export LDFLAGS += -L$(OPENSSL_LIB)

CFLAGS += -fPIC
CPPFLAGS += -fPIC
CXXFLAGS += $(CPPFLAGS)
DH_FLAGS += --max-parallel=1

DEB_DESTDIR = $(CURDIR)/debian/tmp
DEB_MAKE_CLEAN_TARGET = clean
DEB_MAKE_BUILD_TARGET = build

export CPPFLAGS
export CXXFLAGS
export CFLAGS
export LDFLAGS

# these ignores need replacing in files (see below)
MSPECOPTS := -P 'Dir.chdir defaults to _HOME with no arguments'
MSPECOPTS += -P 'Dir.chdir defaults to the home directory when given a block but no argument'
MSPECOPTS += -P 'Dir.exist_ doesn_t expand paths'
MSPECOPTS += -P 'Dir.exists_ doesn_t expand paths'
MSPECOPTS += -P 'File.lchmod returns false from \\\#respond_to\?'
MSPECOPTS += -P 'File.lchmod raises a NotImplementedError when called'

MSPECOPTS += -P 'File.expand_path expands ENV_USER to the user_s home directory'
MSPECOPTS += -P 'File.expand_path expands ENV_USER_a to a in the user_s home directory'
MSPECOPTS += -P 'File.utime allows Time instances in the far future to set mtime and atime'
MSPECOPTS += -P 'UDPSocket_recvfrom_nonblock using IPv4 using a bound socket with data available the returned address Array uses the correct address family'
MSPECOPTS += -P 'UDPSocket_recvfrom_nonblock using IPv4 using a bound socket with data available the returned address Array uses the port of the client'
MSPECOPTS += -P 'UDPSocket_recvfrom_nonblock using IPv4 using a bound socket with data available the returned address Array uses the hostname of the client'
MSPECOPTS += -P 'UDPSocket_recvfrom_nonblock using IPv4 using a bound socket with data available the returned address Array uses the IP address of the client'
MSPECOPTS += -P 'UDPSocket_recvfrom_nonblock using IPv6 using a bound socket with data available returns an Array containing the data and an Array'
MSPECOPTS += -P 'UDPSocket_recvfrom_nonblock using IPv6 using a bound socket with data available the returned Array contains the data at index 0'
MSPECOPTS += -P 'UDPSocket_recvfrom_nonblock using IPv6 using a bound socket with data available the returned Array contains an Array at index 1'
MSPECOPTS += -P 'UDPSocket_recvfrom_nonblock using IPv6 using a bound socket with data available the returned address Array uses the correct address family'
MSPECOPTS += -P 'UDPSocket_recvfrom_nonblock using IPv6 using a bound socket with data available the returned address Array uses the port of the client'
MSPECOPTS += -P 'UDPSocket_recvfrom_nonblock using IPv6 using a bound socket with data available the returned address Array uses the hostname of the client'
MSPECOPTS += -P 'UDPSocket_recvfrom_nonblock using IPv6 using a bound socket with data available the returned address Array uses the IP address of the client'

MSPECOPTS += -P 'File.ftype returns _socket_ when the file is a socket'
MSPECOPTS += -P 'File::Stat\\\#ftype returns _socket_ when the file is a socket'
MSPECOPTS += -P 'Socket\\\#connect_address using an unbound UNIX socket raises SocketError'
MSPECOPTS += -P 'Socket\\\#connect_address using a bound UNIX socket returns an Addrinfo'
MSPECOPTS += -P 'Socket\\\#connect_address using a bound UNIX socket uses the correct socket path'
MSPECOPTS += -P 'Socket\\\#connect_address using a bound UNIX socket uses AF_UNIX as the address family'
MSPECOPTS += -P 'Socket\\\#connect_address using a bound UNIX socket uses PF_UNIX as the protocol family'
MSPECOPTS += -P 'Socket\\\#connect_address using a bound UNIX socket uses SOCK_STREAM as the socket type'
MSPECOPTS += -P 'Socket\\\#connect_address using a bound UNIX socket uses 0 as the protocol'
MSPECOPTS += -P 'BasicSocket\\\#getpeereid using a UNIXSocket returns an Array with the user and group ID'
MSPECOPTS += -P 'BasicSocket\\\#setsockopt using a UNIX socket sets a boolean option'
MSPECOPTS += -P 'Socket.unix_server_socket when no block is given returns a Socket'
MSPECOPTS += -P 'Socket.unix_server_socket when a block is given yields a Socket'
MSPECOPTS += -P 'Socket.unix_server_socket when a block is given closes the Socket when the block returns'
MSPECOPTS += -P 'Socket.unix when no block is given returns a Socket'
MSPECOPTS += -P 'Socket.unix when a block is given yields a Socket'
MSPECOPTS += -P 'Socket.unix when a block is given closes the Socket when the block returns'
MSPECOPTS += -P 'UNIXServer\\\#accept_nonblock without a client raises IO::WaitReadable'
MSPECOPTS += -P 'UNIXServer\\\#accept_nonblock with a client without any data returns a UNIXSocket'
MSPECOPTS += -P 'UNIXServer\\\#accept_nonblock with a client with data available returns a UNIXSocket'
MSPECOPTS += -P 'UNIXServer\\\#accept_nonblock with a client with data available the returned UNIXSocket can read the data written'
MSPECOPTS += -P 'UNIXServer\\\#accept without a client blocks the calling thread'
MSPECOPTS += -P 'UNIXServer\\\#accept with a client without any data returns a UNIXSocket'
MSPECOPTS += -P 'UNIXServer\\\#accept with a client with data available returns a UNIXSocket'
MSPECOPTS += -P 'UNIXServer\\\#accept with a client with data available the returned UNIXSocket can read the data written'
MSPECOPTS += -P 'UNIXServer\\\#initialize returns a new UNIXServer'
MSPECOPTS += -P 'UNIXServer\\\#initialize sets the socket to binmode'
MSPECOPTS += -P 'UNIXServer\\\#initialize raises Errno::EADDRINUSE when the socket is already in use'
MSPECOPTS += -P 'UNIXServer\\\#listen returns 0'
MSPECOPTS += -P 'UNIXServer\\\#sysaccept without a client blocks the calling thread'
MSPECOPTS += -P 'UNIXServer\\\#sysaccept with a client without any data returns an Integer'
MSPECOPTS += -P 'UNIXServer\\\#sysaccept with a client with data available returns an Integer'
MSPECOPTS += -P 'UNIXSocket\\\#initialize using an existing socket path returns a new UNIXSocket'
MSPECOPTS += -P 'UNIXSocket\\\#initialize using an existing socket path sets the socket path to an empty String'
MSPECOPTS += -P 'UNIXSocket\\\#initialize using an existing socket path sets the socket to binmode'
MSPECOPTS += -P 'UNIXSocket\\\#local_address returns an Addrinfo'
MSPECOPTS += -P 'UNIXSocket\\\#local_address the returned Addrinfo uses AF_UNIX as the address family'
MSPECOPTS += -P 'UNIXSocket\\\#local_address the returned Addrinfo uses PF_UNIX as the protocol family'
MSPECOPTS += -P 'UNIXSocket\\\#local_address the returned Addrinfo uses SOCK_STREAM as the socket type'
MSPECOPTS += -P 'UNIXSocket\\\#local_address the returned Addrinfo uses an empty socket path'
MSPECOPTS += -P 'UNIXSocket\\\#local_address the returned Addrinfo uses 0 as the protocol'
MSPECOPTS += -P 'UNIXSocket\\\#recvfrom using a UNIX socket constructed using UNIXSocket.for_fd returns an Array containing the data and address information'
MSPECOPTS += -P 'UNIXSocket\\\#recvfrom using a UNIX socket constructed using UNIXSocket.for_fd returns an Array containing the data and address information'
MSPECOPTS += -P 'UNIXSocket\\\#remote_address returns an Addrinfo'
MSPECOPTS += -P 'UNIXSocket\\\#remote_address the returned Addrinfo uses AF_UNIX as the address family'
MSPECOPTS += -P 'UNIXSocket\\\#remote_address the returned Addrinfo uses PF_UNIX as the protocol family'
MSPECOPTS += -P 'UNIXSocket\\\#remote_address the returned Addrinfo uses SOCK_STREAM as the socket type'
MSPECOPTS += -P 'UNIXSocket\\\#remote_address the returned Addrinfo uses the correct socket path'
MSPECOPTS += -P 'UNIXSocket\\\#remote_address the returned Addrinfo uses 0 as the protocol'
MSPECOPTS += -P 'Socket\\\#bind using IPv4 using a packed socket address raises Errno::EACCES when the user is not allowed to bind to the port'
MSPECOPTS += -P 'Socket\\\#bind using IPv6 using a packed socket address raises Errno::EACCES when the user is not allowed to bind to the port'

# Skip timezone-related tests
MSPECOPTS += -P 'Time\\\#dst\? dst\? returns whether time is during daylight saving time'
MSPECOPTS += -P 'Time\\\#getlocal returns a new time with the correct utc_offset according to the set timezone'
MSPECOPTS += -P 'Time\\\#gmt_offset returns the correct offset for Hawaii around daylight savings time change'
MSPECOPTS += -P 'Time\\\#gmt_offset returns the correct offset for New Zealand around daylight savings time change'
MSPECOPTS += -P 'Time\\\#gmtoff returns the correct offset for Hawaii around daylight savings time change'
MSPECOPTS += -P 'Time\\\#gmtoff returns the correct offset for New Zealand around daylight savings time change'
MSPECOPTS += -P 'Time\\\#isdst dst\? returns whether time is during daylight saving time'
MSPECOPTS += -P 'Time.local creates the correct time just before dst change'
MSPECOPTS += -P 'Time.local creates the correct time just after dst change'
MSPECOPTS += -P 'Time.local timezone changes correctly adjusts the timezone change to _CEST_ on _Europe/Amsterdam_'
MSPECOPTS += -P 'Time\\\#localtime changes the timezone according to the set one'
MSPECOPTS += -P 'Time.mktime creates the correct time just before dst change'
MSPECOPTS += -P 'Time.mktime creates the correct time just after dst change'
MSPECOPTS += -P 'Time.mktime timezone changes correctly adjusts the timezone change to _CEST_ on _Europe/Amsterdam_'
MSPECOPTS += -P 'Time.new timezone changes correctly adjusts the timezone change to _CEST_ on _Europe/Amsterdam_'
MSPECOPTS += -P 'Time\\\#to_a returns a 10 element array representing the deconstructed time'
MSPECOPTS += -P 'Time\\\#utc_offset returns the correct offset for Hawaii around daylight savings time change'
MSPECOPTS += -P 'Time\\\#utc_offset returns the correct offset for New Zealand around daylight savings time change'
MSPECOPTS += -P 'Time\\\#zone returns the time zone used for time'
MSPECOPTS += -P 'Time\\\#zone returns the correct timezone for a local time'
MSPECOPTS += -P 'CApiTimeSpecs rb_time_num_new creates a Time in the local zone with only a timestamp'
 
%:
	dh $@ $(DH_FLAGS)

override_dh_auto_configure:
	# Remove bundled libraries to be sure they are not used.
	rm -rf ext/psych/yaml
	rm -rf ext/fiddle/libffi*

	./configure $(DEB_CONFIGURE_EXTRA_FLAGS)

override_dh_auto_build:
	make $(NJOBS) COPY="cp -p" Q=

override_dh_auto_test:

	# Check RubyGems version.
	[ "`make --no-print-directory runruby TESTRUN_SCRIPT='bin/gem -v' | tail -1`" == '3.0.3.1' ]

	# Check Rubygems bundled dependencies versions.

	# Molinillo.
	[ "`make --no-print-directory runruby TESTRUN_SCRIPT=\"-e \\\" \
	  module Gem; module Resolver; end; end; \
	  require 'rubygems/resolver/molinillo/lib/molinillo/gem_metadata'; \
	  puts Gem::Resolver::Molinillo::VERSION\\\"\" | tail -1`" \
	  == '0.5.7' ]

	# skip some tests
	echo "exclude :test_expand_path_for_existent_username, \"For mock environments\"" > test/excludes/TestFileExhaustive.rb
	echo "exclude :test_getch_timeout, \"For mock environments\"" > test/excludes/TestIoConsole.rb
	echo "exclude :test_world_writable, \"For mock environments\"" > test/excludes/TestTmpdir.rb
	echo "exclude :test_addrinfo_timeout, \"For mock environments\"" > test/excludes/TestSocketAddrinfo.rb
	echo "exclude :test_respond_to_lchmod, \"For mock environments\"" > test/excludes/TestNotImplement.rb
	echo "exclude :test_execopts_uid, \"For mock environments\"" > test/excludes/TestProcess.rb

	# Do some replacements in test names (couldn't find a way to properly escape single quote, dollar sign and question mark)
	sed -i 's/defaults to $$HOME with no arguments/defaults to _HOME with no arguments/' spec/ruby/core/dir/chdir_spec.rb
	sed -i "s/doesn't expand paths/doesn_t expand paths/" spec/ruby/core/dir/shared/exist.rb
	sed -i 's/describe "Dir.exist?"/describe "Dir.exist_"/' spec/ruby/core/dir/exist_spec.rb
	sed -i 's/describe "Dir.exists?"/describe "Dir.exists_"/' spec/ruby/core/dir/exists_spec.rb
	sed -i 's/UDPSocket#recvfrom_nonblock/UDPSocket_recvfrom_nonblock/' spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb
	sed -i "s/expands \~ENV\['USER'\]/expands ENV_USER/g" spec/ruby/core/file/expand_path_spec.rb
	sed -i "s@ENV_USER/a@ENV_USER_a@g" spec/ruby/core/file/expand_path_spec.rb
	sed -i "s/user's home directory/user_s home directory/g" spec/ruby/core/file/expand_path_spec.rb
	sed -i "s/returns 'socket' when the file is a socket/returns _socket_ when the file is a socket/" spec/ruby/core/file/ftype_spec.rb
	sed -i "s/returns 'socket' when the file is a socket/returns _socket_ when the file is a socket/" spec/ruby/core/file/stat/ftype_spec.rb
	sed -i "s@timezone change to 'CEST' on 'Europe/Amsterdam'@timezone change to _CEST_ on _Europe/Amsterdam_@" spec/ruby/core/time/shared/local.rb

	# Delete chroot tests, they break the build in buildsystem
	rm spec/ruby/core/dir/shared/chroot.rb
	rm spec/ruby/core/dir/chroot_spec.rb
	# Disable SSL-related tests which depend on expired test certificates and don't work with openssl
	rm test/net/ftp/test_ftp.rb
	rm test/net/imap/test_imap.rb
	rm test/net/http/test_https.rb
	# Disable net/http and net/smtp tests: they spawn a server via
	# tcp_server_sockets_port0 and flake with Errno::EADDRINUSE on busy build
	# nodes where several ruby builds run concurrently (mirrors alt-ruby31).
	rm test/net/http/test_http.rb
	rm test/net/smtp/test_smtp.rb

	# Do not test tzdata (no need to test system tzdata itself)
	rm test/ruby/test_time_tz.rb

	make check V=1 TESTS="-v $(DISABLE_TESTS)" MSPECOPT="-fs $(MSPECOPTS)"

override_dh_auto_install:
	make install DESTDIR=$(buildroot)

	# Version is empty if --with-ruby-version is specified.
	# http://bugs.ruby-lang.org/issues/7807
	sed -i 's/Version: ${ruby_version}/Version: $(ruby_version)/' $(buildroot)$(_libdir)/pkgconfig/$(srcname).pc

	# fix rpath for socket.so
	chrpath --replace $(_libdir) $(buildroot)$(ruby_libarchdir)/digest/bubblebabble.so
	chrpath --replace $(_libdir) $(buildroot)$(ruby_libarchdir)/io/nonblock.so
	chrpath --replace $(_libdir) $(buildroot)$(ruby_libarchdir)/io/wait.so
	chrpath --replace $(_libdir) $(buildroot)$(ruby_libarchdir)/json/ext/generator.so
	chrpath --replace $(_libdir) $(buildroot)$(ruby_libarchdir)/json/ext/parser.so

	# .so in /enc directory contain RPATH, but it's empty. when using additional custom RPATH (e.g. for alt-openssl) it transforms
	# to RPATH with : in the end. should reset it to empty, these .so do not need any additional RPATHs anyway
	#chrpath --replace '' $(buildroot)$(ruby_libarchdir)/enc/*.so 
	#chrpath --replace '' $(buildroot)$(ruby_libarchdir)/enc/trans/*.so 

	mkdir -p $(buildroot)/opt/alt/ruby26/etc/
	echo "[ruby2.6]" > $(buildroot)/opt/alt/ruby26/etc/locked_extensions.ini

	# Kill bundled certificates, as they should be part of ca-certificates.
	for cert in \
	  rubygems.org/GlobalSignRootCA.pem \
	  rubygems.org/GlobalSignRootCA_R3.pem ; \
	do \
	  rm $(buildroot)$(rubygems_dir)/rubygems/ssl_certs/$cert; \
	  rm -d $(dirname $(buildroot)$(rubygems_dir)/rubygems/ssl_certs/$cert) || : ; \
	done
	# Ensure there is not forgotten any certificate.
	test ! "$(ls -A $(buildroot)$(rubygems_dir)/rubygems/ssl_certs/ 2>/dev/null)"

	# Fix shebang
	find $(buildroot) -type f -exec sed -i '1s|#!/usr/bin/env ruby|#!$(_bindir)/ruby|g' {} +

# ======================= Packaging ===================================

	dh_installdocs -p alt-ruby26 \
		BSDL COPYING COPYING.ja GPL LEGAL

	dh_movefiles -palt-ruby26 \
		.$(_bindir)/erb \
		.$(_bindir)/ruby \
		.$(_mandir)/man1/erb* \
		.$(_mandir)/man1/ruby* \
		./opt/alt/ruby26/etc/locked_extensions.ini \

	dh_installdocs -p alt-ruby26-devel \
		BSDL COPYING COPYING.ja GPL LEGAL

	dh_movefiles -p alt-ruby26-devel \
		.$(_includedir)/* \
		.$(_libdir)/libruby.so \
		.$(_libdir)/pkgconfig/$(srcname).pc \

	dh_installdocs -p alt-ruby26-libs \
		COPYING COPYING.ja GPL LEGAL README.md NEWS

	dh_installdirs -p alt-ruby26-libs \
		.$(ruby_vendorlibdir) \
		.$(ruby_vendorarchdir) \
		.$(ruby_libdir) \
		.$(ruby_libarchdir) \
		.$(ruby_libarchdir)/cgi \
		.$(ruby_libarchdir)/digest \
		.$(ruby_libarchdir)/enc \
		.$(ruby_libarchdir)/enc/trans \
		.$(ruby_libarchdir)/io \
		.$(ruby_libarchdir)/rbconfig \
		.$(ruby_libarchdir)/racc \

	dh_movefiles -p alt-ruby26-libs \
		.$(ruby_libdir)/abbrev.rb \
		.$(ruby_libdir)/base64.rb \
		.$(ruby_libdir)/benchmark* \
		.$(ruby_libdir)/bundler* \
		.$(ruby_libdir)/cgi* \
		.$(ruby_libdir)/cmath.rb \
		.$(ruby_libdir)/coverage.rb \
		.$(ruby_libdir)/csv* \
		.$(ruby_libdir)/date.rb \
		.$(ruby_libdir)/debug.rb \
		.$(ruby_libdir)/delegate* \
		.$(ruby_libdir)/digest* \
		.$(ruby_libdir)/drb* \
		.$(ruby_libdir)/e2mmap.rb \
		.$(ruby_libdir)/e2mmap \
		.$(ruby_libdir)/English.rb \
		.$(ruby_libdir)/erb.rb \
		.$(ruby_libdir)/error_highlight* \
		.$(ruby_libdir)/expect.rb \
		.$(ruby_libdir)/fiddle* \
		.$(ruby_libdir)/fileutils.rb \
		.$(ruby_libdir)/fileutils \
		.$(ruby_libdir)/find.rb \
		.$(ruby_libdir)/forwardable* \
		.$(ruby_libdir)/getoptlong* \
		.$(ruby_libdir)/ipaddr.rb \
		.$(ruby_libdir)/kconv.rb \
		.$(ruby_libdir)/logger* \
		.$(ruby_libdir)/matrix* \
		.$(ruby_libdir)/mkmf.rb \
		.$(ruby_libdir)/monitor.rb \
		.$(ruby_libdir)/mutex_m.rb \
		.$(ruby_libdir)/net \
		.$(ruby_libdir)/observer* \
		.$(ruby_libdir)/open-uri.rb \
		.$(ruby_libdir)/open3* \
		.$(ruby_libdir)/optionparser.rb \
		.$(ruby_libdir)/optparse* \
		.$(ruby_libdir)/ostruct* \
		.$(ruby_libdir)/pathname.rb \
		.$(ruby_libdir)/pp.rb \
		.$(ruby_libdir)/prettyprint.rb \
		.$(ruby_libdir)/prime.rb \
		.$(ruby_libdir)/profile.rb \
		.$(ruby_libdir)/profiler.rb \
		.$(ruby_libdir)/pstore* \
		.$(ruby_libdir)/reline* \
		.$(ruby_libdir)/resolv.rb \
		.$(ruby_libdir)/resolv-replace.rb \
		.$(ruby_libdir)/rexml \
		.$(ruby_libdir)/rinda \
		.$(ruby_libdir)/ripper* \
		.$(ruby_libdir)/rss* \
		.$(ruby_libdir)/scanf.rb \
		.$(ruby_libdir)/securerandom.rb \
		.$(ruby_libdir)/set.rb \
		.$(ruby_libdir)/shell.rb \
		.$(ruby_libdir)/shell \
		.$(ruby_libdir)/shellwords.rb \
		.$(ruby_libdir)/singleton* \
		.$(ruby_libdir)/socket.rb \
		.$(ruby_libdir)/sync.rb \
		.$(ruby_libdir)/syslog \
		.$(ruby_libdir)/tempfile.rb \
		.$(ruby_libdir)/thwait.rb \
		.$(ruby_libdir)/thwait \
		.$(ruby_libdir)/timeout* \
		.$(ruby_libdir)/time.rb \
		.$(ruby_libdir)/tmpdir.rb \
		.$(ruby_libdir)/tracer* \
		.$(ruby_libdir)/tsort.rb \
		.$(ruby_libdir)/unicode_normalize \
		.$(ruby_libdir)/un.rb \
		.$(ruby_libdir)/uri* \
		.$(ruby_libdir)/weakref* \
		.$(ruby_libdir)/webrick.rb \
		.$(ruby_libdir)/webrick \
		.$(ruby_libdir)/yaml* \
		.$(_libdir)/libruby.so.* \
		.$(ruby_libarchdir)/cgi/escape.so \
		.$(ruby_libarchdir)/continuation.so \
		.$(ruby_libarchdir)/coverage.so \
		.$(ruby_libarchdir)/date_core.so \
		.$(ruby_libarchdir)/dbm.so \
		.$(ruby_libarchdir)/digest.so \
		.$(ruby_libarchdir)/digest/bubblebabble.so \
		.$(ruby_libarchdir)/digest/md5.so \
		.$(ruby_libarchdir)/digest/rmd160.so \
		.$(ruby_libarchdir)/digest/sha1.so \
		.$(ruby_libarchdir)/digest/sha2.so \
		.$(ruby_libarchdir)/enc/big5.so \
		.$(ruby_libarchdir)/enc/cp949.so \
		.$(ruby_libarchdir)/enc/emacs_mule.so \
		.$(ruby_libarchdir)/enc/encdb.so \
		.$(ruby_libarchdir)/enc/euc_jp.so \
		.$(ruby_libarchdir)/enc/euc_kr.so \
		.$(ruby_libarchdir)/enc/euc_tw.so \
		.$(ruby_libarchdir)/enc/gb18030.so \
		.$(ruby_libarchdir)/enc/gb2312.so \
		.$(ruby_libarchdir)/enc/gbk.so \
		.$(ruby_libarchdir)/enc/iso_8859_1.so \
		.$(ruby_libarchdir)/enc/iso_8859_10.so \
		.$(ruby_libarchdir)/enc/iso_8859_11.so \
		.$(ruby_libarchdir)/enc/iso_8859_13.so \
		.$(ruby_libarchdir)/enc/iso_8859_14.so \
		.$(ruby_libarchdir)/enc/iso_8859_15.so \
		.$(ruby_libarchdir)/enc/iso_8859_16.so \
		.$(ruby_libarchdir)/enc/iso_8859_2.so \
		.$(ruby_libarchdir)/enc/iso_8859_3.so \
		.$(ruby_libarchdir)/enc/iso_8859_4.so \
		.$(ruby_libarchdir)/enc/iso_8859_5.so \
		.$(ruby_libarchdir)/enc/iso_8859_6.so \
		.$(ruby_libarchdir)/enc/iso_8859_7.so \
		.$(ruby_libarchdir)/enc/iso_8859_8.so \
		.$(ruby_libarchdir)/enc/iso_8859_9.so \
		.$(ruby_libarchdir)/enc/koi8_r.so \
		.$(ruby_libarchdir)/enc/koi8_u.so \
		.$(ruby_libarchdir)/enc/shift_jis.so \
		.$(ruby_libarchdir)/enc/trans/big5.so \
		.$(ruby_libarchdir)/enc/trans/chinese.so \
		.$(ruby_libarchdir)/enc/trans/ebcdic.so \
		.$(ruby_libarchdir)/enc/trans/emoji.so \
		.$(ruby_libarchdir)/enc/trans/emoji_iso2022_kddi.so \
		.$(ruby_libarchdir)/enc/trans/emoji_sjis_docomo.so \
		.$(ruby_libarchdir)/enc/trans/emoji_sjis_kddi.so \
		.$(ruby_libarchdir)/enc/trans/emoji_sjis_softbank.so \
		.$(ruby_libarchdir)/enc/trans/escape.so \
		.$(ruby_libarchdir)/enc/trans/gb18030.so \
		.$(ruby_libarchdir)/enc/trans/gbk.so \
		.$(ruby_libarchdir)/enc/trans/iso2022.so \
		.$(ruby_libarchdir)/enc/trans/japanese.so \
		.$(ruby_libarchdir)/enc/trans/japanese_euc.so \
		.$(ruby_libarchdir)/enc/trans/japanese_sjis.so \
		.$(ruby_libarchdir)/enc/trans/korean.so \
		.$(ruby_libarchdir)/enc/trans/single_byte.so \
		.$(ruby_libarchdir)/enc/trans/transdb.so \
		.$(ruby_libarchdir)/enc/trans/utf8_mac.so \
		.$(ruby_libarchdir)/enc/trans/utf_16_32.so \
		.$(ruby_libarchdir)/enc/utf_16be.so \
		.$(ruby_libarchdir)/enc/utf_16le.so \
		.$(ruby_libarchdir)/enc/utf_32be.so \
		.$(ruby_libarchdir)/enc/utf_32le.so \
		.$(ruby_libarchdir)/enc/windows_1250.so \
		.$(ruby_libarchdir)/enc/windows_1251.so \
		.$(ruby_libarchdir)/enc/windows_1252.so \
		.$(ruby_libarchdir)/enc/windows_1253.so \
		.$(ruby_libarchdir)/enc/windows_1254.so \
		.$(ruby_libarchdir)/enc/windows_1257.so \
		.$(ruby_libarchdir)/enc/windows_31j.so \
		.$(ruby_libarchdir)/etc.so \
		.$(ruby_libarchdir)/fcntl.so \
		.$(ruby_libarchdir)/fiber.so \
		.$(ruby_libarchdir)/fiddle.so \
		.$(ruby_libarchdir)/gdbm.so \
		.$(ruby_libarchdir)/io/nonblock.so \
		.$(ruby_libarchdir)/io/wait.so \
		.$(ruby_libarchdir)/nkf.so \
		.$(ruby_libarchdir)/objspace.so \
		.$(ruby_libarchdir)/pathname.so \
		.$(ruby_libarchdir)/pty.so \
		.$(ruby_libarchdir)/rbconfig.rb \
		.$(ruby_libarchdir)/rbconfig/sizeof.so \
		.$(ruby_libarchdir)/readline.so \
		.$(ruby_libarchdir)/ripper.so \
		.$(ruby_libarchdir)/sdbm.so \
		.$(ruby_libarchdir)/socket.so \
		.$(ruby_libarchdir)/stringio.so \
		.$(ruby_libarchdir)/strscan.so \
		.$(ruby_libarchdir)/syslog.so \
		.$(ruby_libarchdir)/zlib.so \
		.$(ruby_libdir)/racc* \
		.$(ruby_libarchdir)/racc/cparse.so \
		.$(_bindir)/bundle \
		.$(_bindir)/bundler \
		.$(gem_dir)/gems/bundler-* \
		.$(gem_dir)/specifications/bundler-*.gemspec \
		.$(_mandir)/man1/bundle*.1* \
		.$(_mandir)/man5/gemfile.5* \
		.$(_bindir)/irb \
		.$(ruby_libdir)/irb* \
		.$(gem_dir)/gems/irb-* \
		.$(gem_dir)/specifications/irb-*.gemspec \
		.$(_mandir)/man1/irb.1* \



	dh_installdirs -p alt-ruby26-rubygems \
		.$(rubygems_dir) \
		.$(gem_dir) \
		.$(gem_dir)/build_info  \
		.$(gem_dir)/cache \
		.$(gem_dir)/doc \
		.$(gem_dir)/extensions \
		.$(gem_dir)/gems \
		.$(gem_dir)/plugins \
		.$(gem_dir)/specifications \
		.$(gem_dir)/specifications/default \
		.$(_exec_prefix)/lib/gems \
		.$(_exec_prefix)/lib/gems/ruby \
		.$(_exec_prefix)/lib64/gems \
		.$(_exec_prefix)/lib64/gems/ruby \

	dh_movefiles -p alt-ruby26-rubygems \
		.$(_bindir)/gem \
		.$(ruby_libdir)/rubygems \
		.$(ruby_libdir)/rubygems.rb \
		.$(gem_dir)/specifications/default/bundler-*.gemspec \
		.$(gem_dir)/specifications/default/cgi-*.gemspec \
		.$(gem_dir)/specifications/default/cmath-1.0.0.gemspec \
		.$(gem_dir)/specifications/default/csv-3.0.9.gemspec \
		.$(gem_dir)/specifications/default/date-*.gemspec \
		.$(gem_dir)/specifications/default/dbm-1.0.0.gemspec \
		.$(gem_dir)/specifications/default/etc-1.0.1.gemspec \
		.$(gem_dir)/specifications/default/e2mmap-0.1.0.gemspec \
		.$(gem_dir)/specifications/default/fcntl-1.0.0.gemspec \
		.$(gem_dir)/specifications/default/fiddle-1.0.0.gemspec \
		.$(gem_dir)/specifications/default/fileutils-1.1.0.gemspec \
		.$(gem_dir)/specifications/default/forwardable-1.2.0.gemspec \
		.$(gem_dir)/specifications/default/gdbm-2.0.0.gemspec \
		.$(gem_dir)/specifications/default/ipaddr-1.2.2.gemspec \
		.$(gem_dir)/specifications/default/irb-1.0.0.gemspec \
		.$(gem_dir)/specifications/default/logger-1.3.0.gemspec \
		.$(gem_dir)/specifications/default/matrix-0.1.0.gemspec \
		.$(gem_dir)/specifications/default/mutex_m-0.1.0.gemspec \
		.$(gem_dir)/specifications/default/ostruct-0.1.0.gemspec \
		.$(gem_dir)/specifications/default/prime-0.1.0.gemspec \
		.$(gem_dir)/specifications/default/racc-*.gemspec \
		.$(gem_dir)/specifications/default/rexml-3.1.9.1.gemspec \
		.$(gem_dir)/specifications/default/rss-0.2.7.gemspec \
		.$(gem_dir)/specifications/default/sdbm-1.0.0.gemspec \
		.$(gem_dir)/specifications/default/scanf-1.0.0.gemspec \
		.$(gem_dir)/specifications/default/shell-0.7.gemspec \
		.$(gem_dir)/specifications/default/stringio-0.0.2.gemspec \
		.$(gem_dir)/specifications/default/strscan-1.0.0.gemspec \
		.$(gem_dir)/specifications/default/sync-0.5.0.gemspec \
		.$(gem_dir)/specifications/default/tracer-0.1.0.gemspec \
		.$(gem_dir)/specifications/default/thwait-0.1.0.gemspec \
		.$(gem_dir)/specifications/default/webrick-1.4.4.gemspec \
		.$(gem_dir)/specifications/default/zlib-1.0.0.gemspec \

	dh_movefiles -p alt-ruby26-rubygem-rdoc \
		.$(_bindir)/rdoc \
		.$(_bindir)/ri \
		.$(ruby_libdir)/rdoc* \
		.$(gem_dir)/gems/rdoc-6.1.2.1 \
		.$(gem_dir)/specifications/default/rdoc-6.1.2.1.gemspec \
		.$(_mandir)/man1/ri* \

	dh_installdocs -p alt-ruby26-doc \
		README.md  ChangeLog

	dh_movefiles -p alt-ruby26-doc \
		.$(_datadir)/ri \

	dh_movefiles -p alt-ruby26-rubygem-bigdecimal \
		.$(ruby_libdir)/bigdecimal \
		.$(ruby_libdir)/bigdecimal.rb \
		.$(ruby_libarchdir)/bigdecimal.so \
		.$(ruby_libarchdir)/bigdecimal/util.so \
		.$(gem_dir)/specifications/default/bigdecimal-1.4.1.gemspec \

	dh_movefiles -p alt-ruby26-rubygem-io-console \
		.$(ruby_libdir)/io \
		.$(ruby_libarchdir)/io/console.so \
		.$(gem_dir)/specifications/default/io-console-0.4.7.gemspec \

	dh_movefiles -p alt-ruby26-rubygem-json \
		.$(ruby_libdir)/json \
		.$(ruby_libdir)/json.rb \
		.$(ruby_libarchdir)/json \
		.$(gem_dir)/specifications/default/json-2.1.0.gemspec \

	dh_movefiles -p alt-ruby26-rubygem-psych \
		.$(ruby_libdir)/psych \
		.$(ruby_libdir)/psych.rb \
		.$(ruby_libarchdir)/psych.so \
		.$(gem_dir)/specifications/default/psych-3.1.0.gemspec \

	dh_movefiles -p alt-ruby26-rubygem-minitest \
		.$(gem_dir)/gems/minitest-5.11.3 \
		.$(gem_dir)/cache/minitest-5.11.3.gem \
		.$(gem_dir)/specifications/minitest-5.11.3.gemspec \

	dh_movefiles -p alt-ruby26-rubygem-net-telnet \
		.$(gem_dir)/gems/net-telnet-0.2.0 \
		.$(gem_dir)/cache/net-telnet-0.2.0.gem \
		.$(gem_dir)/specifications/net-telnet-0.2.0.gemspec \

	dh_movefiles -p alt-ruby26-rubygem-power-assert \
		.$(gem_dir)/gems/power_assert-1.1.3 \
		.$(gem_dir)/cache/power_assert-1.1.3.gem \
		.$(gem_dir)/specifications/power_assert-1.1.3.gemspec \

	dh_movefiles -p alt-ruby26-rubygem-rake \
		.$(_bindir)/rake \
		.$(gem_dir)/gems/rake-12.3.3 \
		.$(gem_dir)/cache/rake-12.3.3.gem \
		.$(gem_dir)/specifications/rake-12.3.3.gemspec \
		.$(_mandir)/man1/rake.1* \

	dh_movefiles -p alt-ruby26-rubygem-test-unit \
		.$(gem_dir)/gems/test-unit-3.2.9 \
		.$(gem_dir)/cache/test-unit-3.2.9.gem \
		.$(gem_dir)/specifications/test-unit-3.2.9.gemspec \

	dh_movefiles -p alt-ruby26-rubygem-xmlrpc \
		.$(gem_dir)/gems/xmlrpc-0.3.0/LICENSE.txt \
		.$(gem_dir)/gems/xmlrpc-0.3.0/Gemfile \
		.$(gem_dir)/gems/xmlrpc-0.3.0/Rakefile \
		.$(gem_dir)/gems/xmlrpc-0.3.0/README.md \
		.$(gem_dir)/gems/xmlrpc-0.3.0/bin \
		.$(gem_dir)/gems/xmlrpc-0.3.0/lib \
		.$(gem_dir)/gems/xmlrpc-0.3.0/xmlrpc.gemspec \
		.$(gem_dir)/cache/xmlrpc-0.3.0.gem \
		.$(gem_dir)/specifications/xmlrpc-0.3.0.gemspec \

	find $(buildroot)$(gem_dir)/gems/xmlrpc-0.3.0 -type f -name ".*" -delete

	dh_movefiles -p alt-ruby26-rubygem-openssl \
		.$(ruby_libarchdir)/openssl.so \
		.$(ruby_libdir)/openssl \
		.$(ruby_libdir)/openssl.rb \
		.$(gem_dir)/specifications/default/openssl-2.1.2.gemspec \

	dh_movefiles -p alt-ruby26-rubygem-did-you-mean \
		.$(gem_dir)/cache/did_you_mean-1.3.0.gem \
		.$(ruby_libdir)/did_you_mean* \
		.$(gem_dir)/specifications/did_you_mean-1.3.0.gemspec \
		.$(gem_dir)/gems/did_you_mean-1.3.0 \

override_dh_strip:
	# dh_strip doesn't strips debuginfo from debug/*.so files, which is bad for us
	# so we should copy dh_strip script and modify it
	# new Ubuntu: return if $fn=~m{debug/.*\.so};
	# old Ubuntu: return if $fn=~m/debug\/.*\.so/;
	cp $(shell which dh_strip) .
	sed -i '/debug\/.*\\.so/d' dh_strip
	sed -i '/debug\\\/.*\\.so/d' dh_strip
	./dh_strip

override_dh_missing:
	dh_missing --fail-missing

override_dh_auto_clean:
