summaryrefslogtreecommitdiff
path: root/installplatform
blob: 6ea14bb33961dcd72c2e1deacb6e74f3ea0f558e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh

DESTDIR="${DESTDIR:-/}"
pkglibdir="${pkglibdir:-/usr/lib/rpm}"

RPMRC="${1:-rpmrc}"
MACROS="${2:-macros}"
PLATFORM="${3:-platform}"

if grep /share/ $PLATFORM > /dev/null 2>&1 ; then
    DEFAULTDOCDIR='%{_usr}/share/doc'
else
    DEFAULTDOCDIR='%{_usr}/doc'
fi

TEMPRC="/tmp/rpmrc.$$"
cat << E_O_F > $TEMPRC
include:	$RPMRC
macrofiles:	$MACROS
E_O_F

RPM="./rpm --rcfile $TEMPRC"

arch="`$RPM --eval '%{_arch}'`"
VENDOR="`$RPM --eval '%{_vendor}'`"
OS="`$RPM --eval '%{_os}'`"
target_platform="`$RPM --eval '%{_target_platform}'`"
target="`$RPM --eval '%{_target}'`"

rm -f ${DESTDIR}/${pkglibdir}/noarch-${VENDOR}-${OS}
ln -s ${arch}-${VENDOR}-${OS} ${DESTDIR}/${pkglibdir}/noarch-${VENDOR}-${OS}
rm -f ${DESTDIR}/${pkglibdir}/noarch-${OS}
ln -s ${arch}-${VENDOR}-${OS} ${DESTDIR}/${pkglibdir}/noarch-${OS}

case "$arch" in
  i[3456]86) SUBSTS='s_i386_i386_ s_i386_i486_ s_i386_i586_ s_i386_i686_' ;;
  sparc*) SUBSTS='s_sparc\(64\|v9\)_sparc_ s_sparc64_sparcv9_;s_sparc\([^v]\|$\)_sparcv9\1_ s_sparcv9_sparc64_;s_sparc\([^6]\|$\)_sparc64\1_' ;;
  *) SUBSTS=y___ ;;
esac
base_arch=`echo $arch | sed -e 's_i?86_i386_;s_sparc.*_sparc_'`

for SUBST in $SUBSTS ; do
  ARCH=`echo $arch | sed -e $SUBST`
  TARGET_PLATFORM=`echo $target_platform | sed -e $SUBST`
  TARGET=`echo $target | sed -e $SUBST`
  LIB=lib

  PPD="${DESTDIR}/${pkglibdir}/${ARCH}-${VENDOR}-${OS}"

  [ -d $PPD ] || mkdir $PPD

#  RPMRC_OPTFLAGS="`$RPM --target $TARGET --eval '%{optflags}'`"
  RPMRC_OPTFLAGS="`sed -n 's/^optflags: '$ARCH' //p' $RPMRC`"
  RPMRC_OPTFLAGS="`echo $RPMRC_OPTFLAGS | sed -e 's, ,\ ,g'`"

  ARCH_INSTALL_POST='%{nil}'
  MULTILIBNO=
  case "${ARCH}-${OS}" in
    sparc-linux) MULTILIBNO=1 ;;
    sparcv9-linux) MULTILIBNO=1 ;;
    sparc64-linux) ARCH_INSTALL_POST=${pkglibdir}/brp-sparc64-linux; LIB=lib64; MULTILIBNO=2 ;;
  esac

  if [ -n "$MULTILIBNO" ]; then
    MULTILIBSED='-e /^@MULTILIB/d -e s,@MULTILIBNO@,'$MULTILIBNO,
  else
    MULTILIBSED='-e /^@MULTILIBSTART@/,/^@MULTILIBEND@/d'
  fi

  cat $PLATFORM | \
    sed -e "s,@RPMRC_OPTFLAGS@,$RPMRC_OPTFLAGS," \
	-e "s,@RPMRC_ARCH@,$base_arch," \
	-e "s,@LIB@,$LIB," \
	-e "s,@ARCH_INSTALL_POST@,$ARCH_INSTALL_POST," \
	-e "s,@DEFAULTDOCDIR@,$DEFAULTDOCDIR," \
	-e 's,\${,%{_,' \
	$MULTILIBSED \
  > ${PPD}/macros

  #
  # Better try to create these too until the smoke clears. Yuck.
  [ "${ARCH}-${VENDOR}-${OS}" = "${TARGET}" ] || {
    rm -f ${DESTDIR}/${pkglibdir}/${TARGET}
    ln -s ${ARCH}-${VENDOR}-${OS} ${DESTDIR}/${pkglibdir}/${TARGET}
  }
  [ "${ARCH}-${VENDOR}-${OS}" = "${TARGET_PLATFORM}" ] || {
    rm -f ${DESTDIR}/${pkglibdir}/${TARGET_PLATFORM}
    ln -s ${ARCH}-${VENDOR}-${OS} ${DESTDIR}/${pkglibdir}/${TARGET_PLATFORM}
  }

done

rm $TEMPRC