#!/bin/bash
cd /usr/src/glibc-[0-9]*/ ||exit

#Glibc build system is self-contained: will install perfectly even with (still) incorrect specs file and linker

#a failing long double test means: your ld from binutils is probably broken, eg because of too aggressive lib stripping

#the test suite for Glibc in this section is considered critical.

#all old!?:
#patch -p 1 <../glibc-2.3.5-fix_test-1.patch
#patch -p 1 <../glibc-2.3.5-allow-gcc4-string.patch
#patch -p 1 <../glibc-2.3.5-allow-gcc4-symbols.patch
#patch -p 1 <../glibc-2.3.5-gcc4_fix_elf-2.patch
#patch -p 1 <../glibc-2.3.5-gcc41_jis208-1.patch
#patch -p 1 <../glibc-2.4-libgcc_eh-1.patch


cd .. &&
rm -rf _glibc &&
mkdir _glibc &&
cd _glibc &&
#--enable-add-ons: here: enable only nptl
../glibc-[0-9]*/configure --prefix=/usr --libexecdir=/usr/lib/glibc \
  --disable-profile --enable-add-ons --enable-kernel=current \
  --without-cvs &&
make &&
#make check &&
#avoid warning:
touch /etc/ld.so.conf &&
make install &&
#this would install all locales:
# make localedata/install-locales
#this installs only locales needed for gc tests:
mkdir -p /usr/lib/locale &&
localedef -i de_DE -f ISO-8859-1 de_DE &&
localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro &&
localedef -i en_HK -f ISO-8859-1 en_HK
localedef -i en_PH -f ISO-8859-1 en_PH
localedef -i en_US -f ISO-8859-1 en_US
localedef -i es_MX -f ISO-8859-1 es_MX
localedef -i fa_IR -f UTF-8 fa_IR
localedef -i fr_FR -f ISO-8859-1 fr_FR
localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro
localedef -i it_IT -f ISO-8859-1 it_IT
localedef -i ja_JP -f EUC-JP ja_JP
#build and install linuxthreads man pages:
#make -C ../glibc-*/linuxthreads/man &&
#make -C ../glibc-*/linuxthreads/man install

#convert locales to UTF-8 for a multilingual system:
localedef -v -c -i en_US -f UTF-8 en_US.UTF-8
localedef -v -c -i de_DE -f UTF-8 de_DE.UTF-8
localedef -v -c -i ja_JP -f UTF-8 ja_JP.UTF-8



#glibc defaults are not optimal:
if ! test -f /etc/nsswitch.conf; then
cat >/etc/nsswitch.conf <<"EOF"
# Begin /etc/nsswitch.conf

passwd: files
group: files
shadow: files

publickey: files

hosts: files dns
networks: files

protocols: db files
services: db files
ethers: db files
rpc: db files

netgroup: db files

# End /etc/nsswitch.conf
EOF
fi


#find out timezone with: tzselect
#copy instead of symlink to cover /usr on a separate partition
cp --remove-destination /usr/share/zoneinfo/Europe/Berlin /etc/localtime


cat >/etc/ld.so.conf <<"EOF"
# Begin /etc/ld.so.conf

#default is /usr, /usr/lib. Add additional lib dirs (1 per line) here.

# End /etc/ld.so.conf
EOF
