#! /bin/sh # Fix multilib issue for header files. # Copyright (C) 2015-2016 Red Hat, Inc. # Written by Pavel Raiskup # # 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. # # 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. # # 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. # Replace the multilib-unclean file with multilib-clean stub, while the # original file is moved to unique architecture-specific location. @LIB@ opt_buildroot=$(pwd) opt_field_separator=- # TODO: we could pretty easily implement other then 'cpp-header' stubs, if the # target file type allows some kind of "transparent" file inclusion. For # example shell scripts might use '. "${destdir}/${filename}_x86_64.sh'. # The solution is taken from Fedora PostgreSQL RPM package. print_stub () { # 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). # TODO: Shorten the #ifdef hell. There's no need to have e.g. ifdef for # x86_64 in ppc64's wrapper. replacement=$filename$opt_field_separator cat <' are unchanged. To allow us to do incompatible changes in this script, packagers should use this script only through available RPM macros. --buildroot prefix (directory where we play with installed files, usually after 'make install DESTDIR=buildroot') --file for example /some/path/test.h --field-separator by default we move filename.h to filename.h; this option allows you to override the part --verbose print some useful information --arch override arch detection (mostly for testing purposes) --help show this help EOF $_h_exit && exit "$1" } while test $# -gt 0 do _opt=$1 ; shift case $_opt in --buildroot|--arch|--file|--field-separator) _raw_opt=$(echo "$_opt" | sed -e 's/^--//' -e 's/-/_/g') eval "opt_$_raw_opt=\$1" shift || die "$_opt requires argument" ;; --help) print_help 0 ;; *) error "unexpected '$_opt' program argument" ;; esac done $error_occurred && print_help 1 fix_arch opt_arch for i in arch buildroot file do eval "test -z \"\$opt_$i\"" && error "--$i needs to be set" done $error_occurred && print_help 1 # --> /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) multilib_file="$destdir/$filename$opt_field_separator$opt_arch$suffix" test -f "$original_file" || die "can't find '$original_file'" is_multilib "$opt_arch" || { verbose "we don't need multilib haeder hack for '$opt_arch' architecture (no-op)" exit 0 } 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 :