IGNOREPATH=/etc:/tmp:/proc:/dev:/root:/var:/mnt:/home:/usr/src
#
# Need LOTS of disk to build this stuff.
#

STRIPLIB=n
STRIPBIN=y

# Package specific information for glibc
VERSION=2.3.2
PROGNAME="GNU C Library $VERSION"
DESC="\
glibc (GNU C libraries)                                              \n\
                                                                     \n\
This package contains the GNU C libraries and header files.  The GNU \n\
C library was written originally by Roland McGrath, and is currently \n\
maintained by Ulrich Drepper.  Some parts of the library were        \n\
contributed or worked on by other people.                            \n\
                                                                     \n\
You'll need this package to compile programs."

BUILD=1
MAINTAINER="Mark Post <mark.post@eds.com>"
SOURCE=ftp://ftp.gnu.org/gnu/glibc
TAG=ADD
PKGNAME=glibc-$VERSION-s390xcross-$BUILD

compile() {
#  tar -yxvf $CWD/glibc-$VERSION.tar.bz2

   cd $TMP/glibc-$VERSION
if false ; then
   tar -yxvf $CWD/glibc-linuxthreads-$VERSION.tar.bz2

   chown -R root.root .

   # Fix compatibility problems with old binaries/libraries [for now]:
   zcat $CWD/glibc-ctype-compat-v3.patch.gz | patch -p1
   zcat $CWD/glibc-stack_end-compat.patch.gz | patch -p1
   # Fix a problem with Sun Java SDK.  Hopefully soon we'll see a new
   # official Sun Java that's compiled with glibc-2.3.x/gcc-3.2.x, but
   # this works around it for now.
   zcat $CWD/glibc-libc_wait-compat-v2.patch.gz | patch -p1
   # This patch is from glibc CVS to fix problems with TLS.  We'll include
   # it because this will become more important as we move toward Linux 2.5.x.
   zcat $CWD/glibc-dl-reloc-calc-fix.patch.gz | patch -p1
   # Fix obsolete sscanf() parameter syntax for gcc-3.3.x:
   zcat $CWD/glibc.gcc33x.diff.gz | patch -p1
   # Include updated Brazil timezone information:
   zcat $CWD/glibc.daylight_saving_time-2003-br.diff.gz | patch -p1
   # Additional support for UTF-8 locales:
   zcat $CWD/glibc.utf.diff.gz | patch -p1 --verbose

   # Fix a compile problem
   cat $CWD/tls.h.diff | patch -p1

   # Fix a problem that shows up in the gcc java compiler
   cat $CWD/backtrace.c.diff | patch -p1

   # Fix subsequent problems by specifying -fPIC rather than -fpic
   cat $CWD/makeconfig.diff | patch -p1 

   # Fix another java problem, this time for 3.4.0
   # http://sources.redhat.com/ml/libc-hacker/2003-12/msg00025.html
   cat $CWD/backtrace.c.java.diff | patch -p1 --backup --suffix=.orig
   cat $CWD/unwind.h.diff | patch -p1 --backup --suffix=.orig

   # Make build directory:
   mkdir build-glibc-$VERSION
fi
   cd build-glibc-$VERSION

   CFLAGS="-O2 -g" ../configure --prefix=/home/s390/s390x-ibm-linux \
               --enable-add-ons=linuxthreads \
               --without-cvs \
               --build=s390-slackware-linux \
               --host=s390x-slackware-linux \
               --target=s390x-slackware-linux
   make
exit
}

install() {
   cd $TMP/glibc-$VERSION/build-glibc-$VERSION
   make install install_root=/package-glibc
   make localedata/install-locales install_root=/package-glibc

   rm -f /package-glibc/usr/lib/*_p.a

   # The prevailing standard seems to be putting unstripped libraries in
   # /usr/lib/debug/ and stripping the debugging symbols from all the other
   # libraries except the profiling ones:
   strip -g /package-glibc/lib/lib*
   strip -g /package-glibc/usr/lib/l*.so*
   strip -g /package-glibc/usr/lib/lib*.a

   ### Add a copy of the zoneinfo stuff
   ( cd /package-glibc
     tar -zxvpf $CWD/timezone-scripts.tar.gz
   )

   # Don't forget to add the /usr/share/zoneinfo/localtime -> /etc/localtime symlink! :)
   if [ ! -r /package-glibc/usr/share/zoneinfo/localtime ]; then
     ( cd /package-glibc/usr/share/zoneinfo ; ln -sf /etc/localtime . )
   fi

   # Out of the build directory...
   cd ..

   # We'll automatically install the config file for the Name Server Cache Daemon.
   # Perhaps this should also have some commented-out startup code in rc.inet2...
   cat nscd/nscd.conf > /package-glibc/etc/nscd.conf.new

   ### Install the documentation
   mkdir -p /package-glibc/usr/doc/glibc-$VERSION
   cp -a BUGS CONFORMANCE COPYING COPYING.LIB FAQ INSTALL INTERFACE \
      LICENSES NAMESPACE NEWS NOTES PROJECTS README README.libm \
      /package-glibc/usr/doc/glibc-$VERSION

   cd linuxthreads/
   mkdir -p /package-glibc/usr/doc/glibc-$VERSION/linuxthreads/Examples
   cp -a Banner FAQ.html LICENSE README README.Xfree3.2 linuxthreads.texi \
         Examples \
       /package-glibc/usr/doc/glibc-$VERSION/linuxthreads/

   cd man
   mkdir -p /package-glibc/usr/man/man3
   for file in *.man
   do
      cat $file | gzip -9c > \
         /package-glibc/usr/man/man3/`basename $file .man`.3.gz
   done

   gzip -9 /package-glibc/usr/info/*

   ( cd /package-glibc/sbin/
     rm sln ; ln -sf /bin/sln sln
   )

   ( cd /package-glibc/lib/
     rm -f ld.so.1
     rm -f ld-linux.so.2 ; ln -sf ld-$VERSION.so ld-linux.so.2
     # Pat doesn't have this one for some reason...
#    rm -f libnss_files.so ; ln -s libnss_files.so.2 libnss_files.so
   )

#  ( cd /package-glibc/usr/lib/
#    rm -rf libpthread.so ; ln -sf ../../lib/libpthread.so.0 libpthread.so
#  )

   rm -f /package-glibc/etc/ld.so.cache \
         /package-glibc/etc/localtime \
         /package-glibc/usr/share/i18n/locales/zh_TW.orig
}

attributes() {
   chown -R root.bin $PKG/package-glibc/sbin/ \
                     $PKG/package-glibc/usr/bin/ \
                     $PKG/package-glibc/usr/sbin/
}

special() {
   ### first, move everything out of /package-glibc
   cd $PKG
   mv package-glibc/* ./
   rmdir package-glibc/

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

   ### Make our new doinst.sh script
   cd $CTL

   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

# Add the default localtime link in /etc, if none exists:
if [ ! -L etc/localtime ]; then
 ( cd etc ; rm -rf localtime )
 ( cd etc ; ln -sf ../usr/share/zoneinfo/Factory localtime )
fi
# Add the default link in /usr/share/zoneinfo, if none exists:
if [ ! -L usr/share/zoneinfo/localtime ]; then
 ( cd usr/share/zoneinfo ; rm -rf localtime )
 ( cd usr/share/zoneinfo ; ln -sf /etc/localtime localtime )
fi
( cd usr/share/zoneinfo ; rm -rf timeconfig )
( cd usr/share/zoneinfo ; ln -sf /usr/sbin/timeconfig timeconfig )

# Handle nscd.conf config file:
config() {
  NEW="$1"
  OLD="`dirname $NEW`/`basename $NEW .new`"
  # If there's no config file by that name, mv it over:
  if [ ! -r $OLD ]; then
    mv $NEW $OLD
  elif [ "`cat $OLD | md5sum`" = "`cat $NEW | md5sum`" ]; then # toss the redundant copy
    rm $NEW
  fi
  # Otherwise, we leave the .new copy for the admin to consider...
}
config etc/nscd.conf.new

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

EOF

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

#  cat doinst.sh.incoming doinst.sh > doinst.sh.new
   cat doinst.sh.incoming doinst.sh | sed -e '/cd package-glibc\/sbin/ {i \
fi \
\
# Always make these links
;N;}' > doinst.sh.new

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

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

   ### Remove instances of /package-glibc from the doinst.sh script
   sed -e 's%package-glibc/%%g' doinst.sh > doinst.sh.new
   cat doinst.sh.new > doinst.sh
   rm doinst.sh.new
   ### Let's not forget to remove /package-glibc   :)
   rm -vrf /package-glibc
}

subpacks() {
   repack glibc-debug
   repack glibc-i18n
   repack glibc-profile
   repack glibc-solibs 
   repack glibc-zoneinfo
}

