Move key size fixups from rpmdbAdd & Remove to td2key()
[platform/upstream/rpm.git] / installplatform
1 #!/usr/bin/env bash
2
3 DESTDIR="${DESTDIR:-/}"
4 pkglibdir="${pkglibdir:-/usr/lib/rpm}"
5 platformdir="${pkglibdir}/platform"
6
7 RPMRC="${1:-rpmrc}"
8 MACROS="${2:-macros}"
9 PLATFORM="${3:-platform}"
10
11 if grep /share/ $PLATFORM > /dev/null 2>&1 ; then
12     DEFAULTDOCDIR='%{_usr}/share/doc'
13 else
14     DEFAULTDOCDIR='%{_usr}/doc'
15 fi
16
17 TEMPRC="/tmp/rpmrc.$$"
18 cat << E_O_F > $TEMPRC
19 include:        $RPMRC
20 E_O_F
21
22 RPM="./rpm --rcfile=$TEMPRC --macros=$MACROS"
23
24 canonarch_sed='s_i.86_i386_;s_pentium[34]_i386_;s_athlon_i386_;s_sparc[^-]*_sparc_;s_alpha[^-]*_alpha_;s_arm[^-]*_arm_;s_\(powerpc\|ppc\)[^-]*_ppc_;s,\(ia32e\|amd64\),x86_64,;s_sh4a_sh4_'
25 arch="`$RPM --eval '%{_arch}'|sed -e "$canonarch_sed"`"
26 VENDOR="`$RPM --eval '%{_vendor}'`"
27 OS="`$RPM --eval '%{_os}'`"
28 RPMRC_GNU="`$RPM --eval '%{_gnu}'`"
29 target_platform="`$RPM --eval '%{?_gnu:%undefine _gnu}%{_target_platform}'|sed -e "$canonarch_sed"`"
30 target="`$RPM --eval '%{_target}'|sed -e "$canonarch_sed"`"
31
32 case "$arch" in
33   i[3456]86|pentium[34]|athlon|geode) SUBSTS='s_i386_i386_ s_i386_i486_ s_i386_i586_ s_i386_i686_ s_i386_pentium3_ s_i386_pentium4_ s_i386_athlon_ s_i386_geode_' ;;
34   alpha*) SUBSTS='s_alpha_alpha_ s_alpha_alphaev5_ s_alpha_alphaev56_ s_alpha_alphapca56_ s_alpha_alphaev6_ s_alpha_alphaev67_' ;;
35   arm*) SUBSTS='s_arm_armv3l_ s_arm_armv4l_ s_arm_armv4tl_ s_arm_armv5tel_ s_arm_armv5tejl_ s_arm_armv6l_' ;;
36   sh4*) SUBSTS='s_sh4_sh4_ s_sh4_sh4a_' ;;
37   sparc*) SUBSTS='s_sparc\(64\|64v\|v9v\|v9\)_sparc_ s_sparc64_sparcv9_;s_sparc\([^v]\|$\)_sparcv9\1_ s_sparcv9_sparc64_;s_sparc\([^6]\|$\)_sparc64\1_' ;;
38   powerpc*|ppc*) SUBSTS='s_ppc64_ppc_ s_ppc\([^6ip]\|$\)_ppc64\1_ s_ppc\([^6ip]\|$\)_ppciseries_ s_ppc\([^6ip]\|$\)_ppcpseries_ s_ppc\([^6ip]\|$\)_ppc64iseries_ s_ppc\([^6ip]\|$\)_ppc64pseries_' ;;
39   s390*) SUBSTS='s_s390x_s390_ s_s390\([^x]\|$\)_s390x\1_' ;;
40   x86_64|amd64|ia32e) SUBSTS='s,x86_64,x86_64, s,x86_64,ia32e, s,x86_64,amd64, s,x86_64,i386, s,x86_64,i486, s,x86_64,i586, s,x86_64,i686, s,x86_64,pentium3, s,x86_64,pentium4, s,x86_64,athlon, s,x86_64,geode,' ;;
41   *) SUBSTS=y___ ;;
42 esac
43
44 for SUBST in $SUBSTS ; do
45   ARCH=`echo $arch | sed -e $SUBST`
46   TARGET_PLATFORM=`echo $target_platform | sed -e $SUBST`
47   TARGET=`echo $target | sed -e $SUBST`
48   LIB=lib
49
50   PPD="${DESTDIR}/${platformdir}/${ARCH}-${OS}"
51
52   [ -d $PPD ] || mkdir -p $PPD
53
54   RPMRC_OPTFLAGS="`sed -n 's/^optflags: '$ARCH' //p' $RPMRC`"
55   RPMRC_OPTFLAGS="`echo $RPMRC_OPTFLAGS | sed -e 's, ,\ ,g'`"
56   case $RPMRC_OPTFLAGS in
57   *-g*) ;;
58   *) RPMRC_OPTFLAGS="$RPMRC_OPTFLAGS -g" ;;
59   esac
60
61   ARCH_INSTALL_POST='%{nil}'
62   MULTILIBNO=
63   case "${ARCH}-${OS}" in
64     sparc-linux) MULTILIBNO=1 ;;
65     sparcv8-linux) MULTILIBNO=1 ;;
66     sparcv9-linux) MULTILIBNO=1 ;;
67     sparcv9v-linux) MULTILIBNO=1 ;;
68     sparc64-linux) ARCH_INSTALL_POST=${pkglibdir}/brp-sparc64-linux; LIB=lib64; MULTILIBNO=2 ;;
69     sparc64v-linux) ARCH_INSTALL_PORT=${pkglibdir}/brp-sparc64-linux; LIB=lib64; MULTILIBNO=2 ;;
70     s390-linux) MULTILIBNO=1 ;;
71     s390x-linux) LIB=lib64; MULTILIBNO=2 ;;
72     ppc-linux) MULTILIBNO=1 ;;
73     ppc64-linux) LIB=lib64; MULTILIBNO=2 ;;
74     i?86-linux|pentium?-linux|athlon-linux|geode-linux) MULTILIBNO=1 ;;
75     x86_64-linux|amd64-linux|ia32e-linux) LIB=lib64; MULTILIBNO=2 ;;
76   esac
77
78   # XXX FIXME: incomplete and quite likely wrong too in places,
79   # consult various arch folks for correct names etc.
80   ISANAME=
81   ISABITS=
82   case "${ARCH}" in
83     sparc|sparcv8|sparcv9*) 
84         ISANAME=sparc
85         ISABITS=32
86         ;;
87     sparc64|sparc64v) 
88         ISANAME=sparc
89         ISABITS=64
90         ;;
91     s390)
92         ISANAME=s390
93         ISABITS=32
94         ;;
95     s390x)
96         ISANAME=s390
97         ISABITS=64
98         ;;
99     ppc)
100         ISANAME=ppc
101         ISABITS=32
102         ;;
103     ppc64)
104         ISANAME=ppc
105         ISABITS=64
106         ;;
107     i?86|pentium?|athlon|geode)
108         ISANAME=x86
109         ISABITS=32
110         ;;
111     x86_64|amd64|ia32e)
112         ISANAME=x86
113         ISABITS=64
114         ;;
115   esac
116
117   if [ -n "$MULTILIBNO" ]; then
118     MULTILIBSED='-e /^@MULTILIB/d -e s,@MULTILIBNO@,'$MULTILIBNO,
119   else
120     MULTILIBSED='-e /^@MULTILIBSTART@/,/^@MULTILIBEND@/d'
121   fi
122
123   case $VENDOR in
124   yellowdog)
125     VENDORSED='-e s,^@yellowdog@,,'
126     ;;
127   pld)
128     VENDORSED='-e s,^@pld@,,'
129     RPMRC_OPTFLAGS="`echo $RPMRC_OPTFLAGS | sed -e "s/ -g/ /"`"
130     ;;
131   mandrake)
132     VENDORSED='-e s,^@mandrake@,,'
133     RPMRC_OPTFLAGS="`echo $RPMRC_OPTFLAGS | sed -e s/i386/i686/`"
134     ;;
135   conectiva)
136     VENDORSED='-e s,^@conectiva@,,'
137     ;;
138   redhat)
139     VENDORSED='-e s,^@redhat@,,'
140     ;;
141   apple)
142     VENDORSED='-e s,^@apple@,,'
143     ;;
144   esac
145
146   CANONARCH="`echo $ARCH|sed -e "$canonarch_sed"`"
147
148   cat $PLATFORM \
149   | sed -e "s,@RPMRC_OPTFLAGS@,$RPMRC_OPTFLAGS," \
150         -e "s,$arch,$CANONARCH," \
151         -e "s,@RPMRC_GNU@,$RPMRC_GNU," \
152         -e "s,@LIB@,$LIB," \
153         -e "s,@ARCH_INSTALL_POST@,$ARCH_INSTALL_POST," \
154         -e "s,@DEFAULTDOCDIR@,$DEFAULTDOCDIR," \
155         -e '/\${\w*:-/!s,\${,%{_,' \
156         -e "s,@ISANAME@,$ISANAME," \
157         -e "s,@ISABITS@,$ISABITS," \
158         $MULTILIBSED \
159         $VENDORSED \
160   | grep -v '^@' \
161   > ${PPD}/macros
162
163 done
164
165 { cd ${DESTDIR}/${platformdir}
166   [ -L noarch-${OS} ] && rm -f noarch-${OS} 2>/dev/null
167   mkdir -p noarch-${OS}
168   sed -e "/^%_arch/s,${arch},noarch," ${arch}-${OS}/macros | grep -v '^%optflags' | grep -v "^%__isa" > noarch-${OS}/macros
169 #  [ -d ${VENDOR} ] || mkdir ${VENDOR}
170 #  for i in brp-* find-lang.sh find-provides find-requires perl.prov perl.req
171 #  do
172 #    sed -e "s,/usr/lib/rpm,/usr/lib/rpm/${VENDOR},g" < $i > ${VENDOR}/$i
173 #    chmod +x ${VENDOR}/$i
174 #  done
175 ##  chmod -x ${VENDOR}/perl.req
176 #  echo "macrofiles:     /usr/lib/rpm/macros:/usr/lib/rpm/${VENDOR}/macros:/etc/rpm/macros.specspo:/etc/rpm/macros.cdb" > ${VENDOR}/rpmrc
177 #  sed -e "s,/usr/lib/rpm,/usr/lib/rpm/${VENDOR},g" < ${arch}-${OS}/macros | grep -v '^%(_arch|optflags)' > ${VENDOR}/macros
178 }
179
180 rm $TEMPRC