2015-11-19 05:30:30 +00:00
|
|
|
#! /bin/sh
|
|
|
|
|
2015-11-27 11:44:44 +00:00
|
|
|
# Fix multilib issue for header files.
|
2016-06-22 09:07:22 +00:00
|
|
|
# Copyright (C) 2015-2016 Red Hat, Inc.
|
2015-11-27 11:44:44 +00:00
|
|
|
# Written by Pavel Raiskup <praiskup@redhat.com>
|
2015-11-19 05:30:30 +00:00
|
|
|
#
|
2015-11-27 11:44:44 +00:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
2015-11-19 05:30:30 +00:00
|
|
|
#
|
2015-11-27 11:44:44 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2015-11-19 05:30:30 +00:00
|
|
|
#
|
2015-11-27 11:44:44 +00:00
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2015-11-27 12:00:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Replace the multilib-unclean file with multilib-clean stub, while the
|
2015-11-27 11:44:44 +00:00
|
|
|
# original file is moved to unique architecture-specific location.
|
2015-11-19 05:30:30 +00:00
|
|
|
|
2016-06-22 09:07:22 +00:00
|
|
|
@LIB@
|
2015-11-19 05:30:30 +00:00
|
|
|
|
|
|
|
opt_buildroot=$(pwd)
|
2016-06-13 21:38:43 +00:00
|
|
|
opt_field_separator=-
|
2015-11-19 05:30:30 +00:00
|
|
|
|
|
|
|
# TODO: we could pretty easily implement other then 'cpp-header' stubs, if the
|
|
|
|
# target file type allows some kind of "transparent" file inclusion. For
|
2015-11-19 10:00:26 +00:00
|
|
|
# example shell scripts might use '. "${destdir}/${filename}_x86_64.sh'.
|
2015-11-27 11:44:44 +00:00
|
|
|
# The solution is taken from Fedora PostgreSQL RPM package.
|
2015-11-19 05:30:30 +00:00
|
|
|
print_stub ()
|
|
|
|
{
|
2016-06-22 06:22:06 +00:00
|
|
|
# The '#else' branch here is not needed! We never install this header on
|
|
|
|
# systems where this set of '#ifdef's is not enough (adding suggested e.g.
|
|
|
|
# in rhbz#1242873).
|
|
|
|
|
2017-01-25 16:33:54 +00:00
|
|
|
# TODO: Shorten the #ifdef hell. There's no need to have e.g. ifdef for
|
|
|
|
# x86_64 in ppc64's wrapper.
|
|
|
|
|
2016-06-13 21:38:43 +00:00
|
|
|
replacement=$filename$opt_field_separator
|
2015-11-19 05:30:30 +00:00
|
|
|
cat <<EOF
|
|
|
|
/*
|
|
|
|
* Kluge to support multilib installation of both 32- and 64-bit RPMS:
|
|
|
|
* we need to arrange that header files that appear in both RPMs are
|
|
|
|
* identical. Hence, this file is architecture-independent and calls
|
|
|
|
* in an arch-dependent file that will appear in just one RPM.
|
|
|
|
*
|
|
|
|
* To avoid breaking arches not explicitly supported by Red Hat, we
|
|
|
|
* use this indirection file *only* on known multilib arches.
|
|
|
|
*
|
2017-01-25 16:25:20 +00:00
|
|
|
* We pay attention to include _only_ the original multilib-unclean
|
|
|
|
* header file. Including any other system-header file could cause
|
|
|
|
* unpredictable include-ordering issues (rhbz#1412274, comment #16).
|
|
|
|
*
|
2015-11-19 05:30:30 +00:00
|
|
|
* Note: this may well fail if user tries to use gcc's -I- option.
|
|
|
|
* But that option is deprecated anyway.
|
|
|
|
*/
|
|
|
|
#if defined(__x86_64__)
|
2016-06-13 21:38:43 +00:00
|
|
|
#include "${replacement}x86_64.h"
|
2015-11-19 05:30:30 +00:00
|
|
|
#elif defined(__i386__)
|
2016-06-13 21:38:43 +00:00
|
|
|
#include "${replacement}i386.h"
|
2015-11-19 05:30:30 +00:00
|
|
|
#elif defined(__ppc64__) || defined(__powerpc64__)
|
2016-06-13 21:38:43 +00:00
|
|
|
#include "${replacement}ppc64.h"
|
2015-11-19 05:30:30 +00:00
|
|
|
#elif defined(__ppc__) || defined(__powerpc__)
|
2016-06-13 21:38:43 +00:00
|
|
|
#include "${replacement}ppc.h"
|
2015-11-19 05:30:30 +00:00
|
|
|
#elif defined(__s390x__)
|
2016-06-13 21:38:43 +00:00
|
|
|
#include "${replacement}s390x.h"
|
2015-11-19 05:30:30 +00:00
|
|
|
#elif defined(__s390__)
|
2016-06-13 21:38:43 +00:00
|
|
|
#include "${replacement}s390.h"
|
2015-11-19 05:30:30 +00:00
|
|
|
#elif defined(__sparc__) && defined(__arch64__)
|
2016-06-13 21:38:43 +00:00
|
|
|
#include "${replacement}sparc64.h"
|
2015-11-19 05:30:30 +00:00
|
|
|
#elif defined(__sparc__)
|
2016-06-13 21:38:43 +00:00
|
|
|
#include "${replacement}sparc.h"
|
2015-11-19 05:30:30 +00:00
|
|
|
#endif
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
print_help ()
|
|
|
|
{
|
|
|
|
_h_exit=false
|
|
|
|
test -n "$1" && _h_exit=:
|
|
|
|
|
|
|
|
cat <<EOF
|
|
|
|
Usage: $progname [OPTIONS]
|
|
|
|
|
|
|
|
Replace the multilib-unclean header file with multilib-clean stub, while the
|
|
|
|
original file is moved to unique architecture-specific location. This should be
|
|
|
|
absolutely safe operation (effects of '#include <HEADER.h>' are unchanged.
|
|
|
|
|
|
|
|
To allow us to do incompatible changes in this script, packagers should use this
|
2015-11-19 10:00:26 +00:00
|
|
|
script only through available RPM macros.
|
2015-11-19 05:30:30 +00:00
|
|
|
|
|
|
|
--buildroot prefix (directory where we play with installed files, usually
|
|
|
|
after 'make install DESTDIR=buildroot')
|
2015-11-19 10:00:26 +00:00
|
|
|
--file for example /some/path/test.h
|
2016-06-13 21:38:43 +00:00
|
|
|
--field-separator by default we move filename.h to filename<SEP><ARCH>.h; this
|
2016-06-13 21:45:10 +00:00
|
|
|
option allows you to override the <SEP> part
|
2015-11-19 05:30:30 +00:00
|
|
|
--verbose print some useful information
|
2016-06-22 09:07:22 +00:00
|
|
|
--arch override arch detection (mostly for testing purposes)
|
2015-11-19 05:30:30 +00:00
|
|
|
--help show this help
|
|
|
|
EOF
|
|
|
|
|
|
|
|
$_h_exit && exit "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
while test $# -gt 0
|
|
|
|
do
|
|
|
|
_opt=$1 ; shift
|
|
|
|
case $_opt in
|
2016-06-13 21:38:43 +00:00
|
|
|
--buildroot|--arch|--file|--field-separator)
|
2015-11-19 10:00:26 +00:00
|
|
|
_raw_opt=$(echo "$_opt" | sed -e 's/^--//' -e 's/-/_/g')
|
|
|
|
eval "opt_$_raw_opt=\$1"
|
|
|
|
shift || die "$_opt requires argument"
|
2015-11-19 05:30:30 +00:00
|
|
|
;;
|
|
|
|
--help)
|
|
|
|
print_help 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
error "unexpected '$_opt' program argument"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
$error_occurred && print_help 1
|
2016-06-22 09:07:22 +00:00
|
|
|
fix_arch opt_arch
|
2015-11-19 05:30:30 +00:00
|
|
|
|
2015-11-19 10:00:26 +00:00
|
|
|
for i in arch buildroot file
|
2015-11-19 05:30:30 +00:00
|
|
|
do
|
|
|
|
eval "test -z \"\$opt_$i\"" && error "--$i needs to be set"
|
|
|
|
done
|
|
|
|
$error_occurred && print_help 1
|
|
|
|
|
2015-11-19 10:00:26 +00:00
|
|
|
# --> /buildroot/usr/include/test.h
|
|
|
|
original_file="$opt_buildroot$opt_file"
|
|
|
|
|
|
|
|
# --> /buildroot/usr/include
|
|
|
|
destdir=$(dirname "$original_file")
|
|
|
|
|
|
|
|
# --> test.h
|
|
|
|
orig_basename=$(basename "$original_file")
|
|
|
|
|
|
|
|
# --> test
|
|
|
|
filename=${orig_basename%%.[a-zA-Z0-9_]}
|
|
|
|
|
|
|
|
# --> .h
|
|
|
|
suffix=${orig_basename##${filename}}
|
|
|
|
|
|
|
|
# --> ../test_x86_64.h (on x86_64)
|
2016-06-13 21:38:43 +00:00
|
|
|
multilib_file="$destdir/$filename$opt_field_separator$opt_arch$suffix"
|
2015-11-19 05:30:30 +00:00
|
|
|
|
|
|
|
test -f "$original_file" || die "can't find '$original_file'"
|
|
|
|
|
2016-06-22 09:07:22 +00:00
|
|
|
is_multilib "$opt_arch" || {
|
|
|
|
verbose "we don't need multilib haeder hack for '$opt_arch' architecture (no-op)"
|
|
|
|
exit 0
|
|
|
|
}
|
2015-11-19 05:30:30 +00:00
|
|
|
|
|
|
|
verbose "moving: '$original_file' to '$multilib_file'"
|
|
|
|
|
|
|
|
mv "$original_file" "$multilib_file" || exit 1
|
|
|
|
if print_stub > "$original_file" && chmod 644 "$original_file"; then
|
|
|
|
:
|
|
|
|
else
|
|
|
|
die "can't write into '$original_file'"
|
|
|
|
fi
|
|
|
|
|
|
|
|
:
|