### this file is sourced not run
PKGVER=2.19
PKGBUILD=1
PKGARCH=i686

TARBALL=glibc-2.19.tar.xz
MD5SUM=e26b8cc666b162f999404b03970f14e4
SRC_URL=http://distro.ibiblio.org/fatdog/source/710/clfs-packages-3.0.0.tar
BUNDLE=clfs-packages-3.0.0.tar

SLACKREQ=
SLACKDESC="glibc32: glibc32 $PKGVER (Core system library)  
glibc32:  
glibc32: The Glibc package contains the main C library. This library provides 
glibc32: the basic routines for allocating memory, searching directories, 
glibc32: opening and closing files, reading and writing files, string handling, 
glibc32: pattern matching, arithmetic, and so on.  
glibc32: 
glibc32: This is the 32-bit version of glibc. You only need this if you plan to
glibc32: run or build 32-bit programs.
glibc32: 
glibc32:
"

### override download for LFS sources
# $1-src-dir $2-tarball 
pkg_download() {
	echo downloading $BUNDLE for $TARBALL
	wget -P $1 $SRC_URL
	tar -xf $1/$BUNDLE --strip-components=1 -C $1 
	rm $1/$BUNDLE
}

### default pkg_prepare

### package - only collect the libraries
pkg_package() {
	rm -rf sbin usr/bin usr/sbin usr/share/i18n usr/share/locale usr/share/info
}

### build
pkg_build() {
	cd /tmp/glibc*
	echo applying patches... &&
	
	# Debian 2.19-18+deb8u3 patches for mainly to address CVE-2015-7547 
	for p in \
		glibc-2.19-git-updates.patch \
		glibc-2.19-resolv-failure.patch \
		glibc-2.19-CVE-2015-7547.patch;
	do
		patch -Np1 -i ../pkg/$p || return 1
	done &&	
	
	# apply patches (LFS-7.1 for glibc-2.14.1, also applicable for LFS 7.4)
	#DL=/lib/ld-linux-armhf.so.3
	#sed -i "s|libs -o|libs -L/usr/lib -Wl,-dynamic-linker=$DL -o|" \
	#	scripts/test-installation.pl &&

	# CLFS 3.0.0 adjust linker patch
	LINKER=$(readelf -l /tools/bin/bash | sed -n 's@.*interpret.*/tools\(.*\)]$@\1@p') &&
	sed -i "s|libs -o|libs -L/usr/lib -Wl,-dynamic-linker=${LINKER} -o|" \
	  scripts/test-installation.pl &&
	unset LINKER &&	
	sed -i 's/\\$$(pwd)/`pwd`/' timezone/Makefile 		
	
	# build dir
	mkdir -v ../glibc-build
	cd ../glibc-build
	
	# extra CFLAGS for default native environment
	#echo 'CFLAGS += -mfloat-abi=hard -mfpu=vfpv3-d16 -march=armv7-a -mcpu=cortex-a8 -mtune=cortex-a8 -pipe -O3' > /tmp/glibc-build/configparms
	
	CC="gcc ${BUILD32}" CXX="g++ ${BUILD32}" \
		../glibc-2.19/configure --prefix=/usr \
		--disable-profile --enable-kernel=2.6.32 \
		--libexecdir=/usr/lib/glibc --host=${CLFS_TARGET32} \
		--enable-obsolete-rpc &&
		
	#sh &&
	make $MAKEFLAGS &&
	#sh &&
	touch /etc/ld.so.conf && # temporary blank ld.so
	make install &&
	rm -v /usr/include/rpcsvc/*.x &&
	#sh &&
	rm -f /etc/ld.so.conf &&

	pkg_build_slackdesc
} 
