#! /bin/sh # Fix multilib issue for header files. # Copyright (C) 2015 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. progname=$(basename "$0") opt_arch=$(uname -i) # See rhbz#1242873 for more info. test "$opt_arch" = ppc64p7 && opt_arch=ppc64 opt_buildroot=$(pwd) opt_verbose=: opt_additional_suffix= # 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 () { 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 --additional-suffix we usually move 'test.h' to 'test_\$ARCH.h'. However this file could already exist. With this option the multilib file will be named 'test_\$ARCH\$SUFFIX.h' --verbose print some useful information --help show this help EOF $_h_exit && exit "$1" } verbose () { $opt_verbose && echo "INFO: $progname: $*" } die () { echo >&2 " # $*" print_help 1 } error () { error_occurred=: echo >&2 " ! $*" } error_occurred=false while test $# -gt 0 do _opt=$1 ; shift case $_opt in --buildroot|--arch|--additional-suffix|--file) _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 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_additional_suffix}_$opt_arch$suffix" test -f "$original_file" || die "can't find '$original_file'" case $opt_arch in # we only apply this to known Red Hat multilib arches, per bug #177564 i386|x86_64|ppc|ppc64|s390|s390x|sparc|sparc64) ;; *) verbose "we don't need multilib haeder hack for '$opt_arch' architecture (no-op)" exit 0 ;; esac 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 :