#
# Prototype file for the glibc-solibs package
#

# Package specific information for glibc-solibs
PROGNAME="GNU C Library, Runtime Support"
DESC="\
glibc-solibs (shared GNU C libraries)                                  \n\
                                                                       \n\
This package contains the shared libraries, binaries, and support      \n\
files required to run most Linux applications linked with glibc."

# package name
SUBPKGNAME=glibc-solibs-$VERSION-s390-$BUILD
TAG=ADD

subinstall() {
   ### install glibc to the fake tree
   cd $TMP/glibc-$VERSION/build-glibc-$VERSION
   make install install_root=/package-glibc

   ### remove the stuff we don't want
   ( cd /package-glibc
     mv usr/bin usr/bin.rm     
     mv sbin sbin.rm
     mkdir -p usr/bin sbin
     mv usr/bin.rm/ldd usr/bin/
     mv sbin.rm/ldconfig sbin/

     rm -rf etc \
            install \
            sbin.rm

     for d in bin.rm doc include info lib man sbin share
     do
        rm -rf usr/$d
     done

     rm lib/ld.so.1

   # Add a symlink that doesn't seem to get created by ldconfig
     cd lib/
     rm -rf ld-linux.so.2 ; ln -sf ld-$VERSION.so ld-linux.so.2
   )
}

subspecial() {
   cd $SUBPKG/
   ### move everything out of /package-glibc
   mv package-glibc/* ./
   rmdir package-glibc/

   ### strip libraries
   find . -type f -exec strip {} \;

   chown -R root.bin sbin/ usr/bin
   chmod 4755 usr/libexec/pt_chown

   ### move the libraries to an incoming location and fix the doinst script
   cd lib
   mkdir incoming
   mv *.so *.so.* incoming
   mv incoming/libSegFault* ./

   ### make our new doinst.sh script
   cd $SUBCTL
   cat <<"EOF" >> doinst.sh.incoming
#!/bin/sh
# Copyright (C) 2002  Slackware Linux, Inc.
#
# 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.
#
# Swap glibc on the fly.
#
# If we're on a running system we have to handle this _very_ carefully.  :-)
# The tricks involved here get trickier every time...

if [ -x /sbin/ldconfig -a -d /lib/incoming ]; then # swap on the fly
  # First create copies of the incoming libraries:
  ( cd lib/incoming
    for file in * ; do
      if [ ! -r ../${file}.incoming ]; then
        cp -a $file ../${file}.incoming
      fi
    done
  )
  # Then switch to them all at once:
  /sbin/ldconfig -l /lib/*.incoming 2> /dev/null
  # Finally, rename them and clean up:
  ( cd lib
    for file in *.incoming ; do
      rm -f `basename $file .incoming`
      cp -a $file `basename $file .incoming`
      /sbin/ldconfig -l `basename $file .incoming`
      rm -f $file
    done
  )
else # no ldconfig?  Good, it's safe to just jam it on home (and make links below):
  ( cd lib/incoming
    for file in * ; do
      cp -a $file ..
    done
  )
fi

# Now, get rid of the temporary directory:
rm -rf lib/incoming

# Create the library symlinks
if [ -x sbin/ldconfig ]; then
  ( cd lib ; ../sbin/ldconfig . )
else # In case there's no ldconfig, make the links manually:
EOF

   cat doinst.sh.incoming doinst.sh > new.sh
   rm -rf doinst.sh
   rm -rf doinst.sh.incoming
   mv new.sh doinst.sh

   cat $CWD/slack-desc.glibc-solibs > slack-desc

   ### Remove instances of /package-glibc from the doinst.sh script
   sed -e 's%package-glibc/%%g' doinst.sh > doinst.sh.incoming
   rm -f doinst.sh
   mv doinst.sh.incoming doinst.sh

   ### we need to close this last if block
   echo "fi" >> doinst.sh

   ### we don't want this left around
   cd $TMP
   rm -rf /package-glibc
}

