set -e
set -x
cd $glibcroot


# %define rpc_thread 0
# %{?do_rpc_thread:%define rpc_thread 1}

# %define rpc_single 0
# %{?do_rpc_single:%define rpc_single 1}

# # We have to put something here. -pipe seems to be a safe choice.
# %define mips_isa_flags "-pipe"
# %{?mips_isa:%define mips_isa_flags %{mips_isa}}

# %if %{_arch} != %{_build_arch}
# %define cross_compile 1
# %else
# %define cross_compile 0
# %endif
# %{?do_cross_compile:%define cross_compile 1}

# %define build_data_files 1
# %define include_data_files 1

# %if %{cross_compile}
# %define build_data_files 0
# %define include_data_files 0

# # We compile some data files natively for cross compile only if the
# # build machine is compitable with the target.
# %if %{_build_arch} == i386

# %ifarch mipsel %{ix86}
# %define include_data_files 1

# %ifarch mipsel
# %define build_data_files 1
# %endif
# %endif
# %endif
# %endif

# %ifarch %{ix86}
# %define GLIBC_2_2_COMPATIABLE 1
# %else
# %define GLIBC_2_2_COMPATIABLE 0
# %endif
# %define GLIBC_LINK_TIME_COMPATIABLE 0

# %define glibcrelease 19.4
# %define auxarches i586 i686 athlon sparcv9 alphaev6
# %{?no_auxarches:%define auxarches none}
# Summary: The GNU libc libraries.
# Name: glibc
# Version: 2.2.4
# Release: %{glibcrelease}
# Copyright: LGPL
# Group: System Environment/Libraries
# Source: %{name}-%{version}.tar.bz2
Patch1000=glibc-2.2-pthread.patch
Patch2000=glibc-2.2-symver.patch
Patch3000=glibc-2.2-mmap64.patch
Patch4000=glibc-2.2-prelink.patch
Patch4001=glibc-2.2-linker.patch
Patch5000=glibc-2.2-rpc-single.patch
Patch6000=glibc-2.2-rpc-thread.patch
Patch7000=glibc-2.2-prof-dso.patch
Patch10000=glibc-cross.patch
Patch10001=glibc-redhat-cross.patch
# In the source tarball the file diff-CYGNUS-to-REDHAT.patch contains all
# diffs applied by Red Hat to the current CVS version of glibc

#%ifarch ia64 sparc64 s390x mips mipsel
#Conflicts: kernel < 2.4.0
#%define enablekernel 2.4.0
#%define enablemask [01].*|2.[0-3]*
# %else
# %define enablekernel 2.2.5
# %ifarch i686
# %define enablekernel2 2.4.1
# %define enablemask [01].*|2.[0-3]*|2.4.0*
# %else
# %define enablemask [01].*|2.[0-1]*|2.2.[0-4]|2.2.[0-4][^0-9]*
# %endif
# %endif
# %define __find_provides %{_builddir}/%{name}-%{version}/find_provides.sh

Patch=glibc-kernel-2.4.patch

#%prep
#%setup -q
# If we are building enablekernel 2.x.y glibc on older kernel,
# we have to make sure no binaries compiled against that glibc
# are ever run
#case `uname -r` in
#%enablemask)

# Well, who knows where we're building

#%patch -p1
patch <$patchdir/$Patch -p1
#;; esac

#%ifarch armv4l sparc64 ia64 s390 s390x mips mipsel
rm -rf glibc-compat
#%endif

# Waiting for explanation...
rm -f sysdeps/powerpc/memset.S

#%ifarch %{ix86}
# It seems that only ia32 needs the pthread symbol versioning patch.
#%patch1000 -p0 -b .pthread
#%endif
patch <$patchdir/$Patch2000 -p0 -z .symver

patch <$patchdir/$Patch3000 -p0 -z .mmap64
patch <$patchdir/$Patch4000 -p1 -E -z .prelink
patch <$patchdir/$Patch4001 -p1 -z .linker
#%if %{rpc_single}
#patch <$patchdir/$Patch5000 -p1 -z .single
#%endif
#%if %{rpc_thread}
#patch <$patchdir/$Patch6000 -p0 -z .thread
#%endif
patch <$patchdir/$Patch7000 -p1 -z .prof-dso
#%if %{cross_compile}
# We assume the build machine is running the same version of glibc.

# Well, or one that's close enough
patch <$patchdir/$Patch10000 -p1 -z .cross
patch <$patchdir/$Patch10001 -p1 -z .redhat-cross
#%endif
#autoconf

find . -type f -size 0 -o -name "*.orig" -exec rm -f {} \;
