summaryrefslogtreecommitdiff
path: root/core/glibc/PKGBUILD
blob: a6d490f3687dfdeb311388a77f69788be2132ee6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# $Id: PKGBUILD 141374 2011-10-30 06:48:27Z allan $
# Maintainer: Allan McRae <allan@archlinux.org>

# toolchain build order: linux-api-headers->glibc->binutils->gcc->binutils->glibc
# NOTE: valgrind requires rebuilt with each major glibc version

pkgname=glibc
pkgver=2.14.1
pkgrel=1
_glibcdate=20111025
pkgdesc="GNU C Library"
arch=('i686' 'x86_64' 'mips64el')
url="http://www.gnu.org/software/libc"
license=('GPL' 'LGPL')
groups=('base')
depends=('linux-api-headers>=3.0' 'tzdata')
makedepends=('gcc>=4.6')
backup=(etc/gai.conf
        etc/locale.gen
        etc/nscd.conf)
options=('!strip')
install=glibc.install
source=(ftp://ftp.archlinux.org/other/glibc/${pkgname}-${pkgver}_${_glibcdate}.tar.xz
        http://repo.parabolagnulinux.org/other/glibc-ports-${pkgver}_${_glibcdate}.tar.xz
        glibc-2.10-dont-build-timezone.patch
        glibc-2.10-bz4781.patch
        glibc-__i686.patch
        glibc-2.12.1-static-shared-getpagesize.patch
        glibc-2.12.2-ignore-origin-of-privileged-program.patch
        glibc-2.13-futex.patch
        glibc-2.14-libdl-crash.patch
        glibc-2.14-revert-4768ae77.patch
        glibc-2.14-reexport-rpc-interface.patch
        glibc-2.14-reinstall-nis-rpc-headers.patch
        nscd
        locale.gen.txt
        locale-gen)


mksource() {
  git clone git://sourceware.org/git/glibc.git
  pushd glibc
  git checkout -b glibc-2.14-arch origin/release/2.14/master
  popd
  tar -cvJf glibc-${pkgver}_${_glibcdate}.tar.xz glibc/*
  mksource-ports
}

mksource-ports() {
  git clone git://sourceware.org/git/glibc-ports.git
  pushd glibc-ports
  git checkout -b glibc-2.14-arch origin/release/2.14/master
  popd
  tar -cvJf glibc-ports-${pkgver}_${_glibcdate}.tar.xz glibc-ports/*
}

build() {
  cd ${srcdir}/glibc

  # timezone data is in separate package (tzdata)
  patch -Np1 -i ${srcdir}/glibc-2.10-dont-build-timezone.patch

  # http://sources.redhat.com/bugzilla/show_bug.cgi?id=4781
  patch -Np1 -i ${srcdir}/glibc-2.10-bz4781.patch

  # http://sources.redhat.com/bugzilla/show_bug.cgi?id=411
  # http://sourceware.org/ml/libc-alpha/2009-07/msg00072.html
  patch -Np1 -i ${srcdir}/glibc-__i686.patch

  # http://sourceware.org/bugzilla/show_bug.cgi?id=11929
  # using Fedora "fix" as patch in that bug report causes breakages...
  patch -Np1 -i ${srcdir}/glibc-2.12.1-static-shared-getpagesize.patch

  # http://www.exploit-db.com/exploits/15274/
  # http://sourceware.org/git/?p=glibc.git;a=patch;h=d14e6b09 (only fedora branch...)
  patch -Np1 -i ${srcdir}/glibc-2.12.2-ignore-origin-of-privileged-program.patch

  # http://sourceware.org/bugzilla/show_bug.cgi?id=12403
  patch -Np1 -i ${srcdir}/glibc-2.13-futex.patch

  # http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=675155e9 (only fedora branch...)
  # http://sourceware.org/ml/libc-alpha/2011-06/msg00006.html
  patch -Np1 -i ${srcdir}/glibc-2.14-libdl-crash.patch

  # Revert commit causing issues with crappy DNS servers...
  # Will be removed when workaround becomes annoying to maintain - USE A BETTER DNS SERVER!
  # Note that both these patches do not fix the issue completely:
  # http://sourceware.org/bugzilla/show_bug.cgi?id=13013
  # http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=032c0ee3 (only fedora branch...)
  patch -Np1 -i ${srcdir}/glibc-2.14-revert-4768ae77.patch

  # re-export RPC interface until libtirpc is ready as a replacement
  # http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=acee4873 (only fedora branch...)
  patch -Np1 -i ${srcdir}/glibc-2.14-reexport-rpc-interface.patch
  # http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=bdd816a3 (only fedora branch...)
  patch -Np1 -i ${srcdir}/glibc-2.14-reinstall-nis-rpc-headers.patch

  ln -s ../glibc-ports ports

  install -dm755 ${pkgdir}/etc
  touch ${pkgdir}/etc/ld.so.conf

  cd ${srcdir}
  mkdir glibc-build
  cd glibc-build

  if [[ ${CARCH} = "i686" ]]; then
    # Hack to fix NPTL issues with Xen, only required on 32bit platforms
    export CFLAGS="${CFLAGS} -mno-tls-direct-seg-refs"
  elif [[ ${CARCH} = "mips64el" ]]; then
    # mips64el is only supported out of tree.
    extra_addons=",ports"
  fi

  if [[ ${CARCH} != "mips64el" ]]; then
      echo "slibdir=/lib" >> configparms
      libdir=/usr/lib
  else
      echo "slibdir=/lib32" >> configparms
      libdir=/usr/lib32
  fi

  # remove hardening options from CFLAGS for building libraries
  CFLAGS=${CFLAGS/-fstack-protector/}
  CFLAGS=${CFLAGS/-D_FORTIFY_SOURCE=2/}

  ${srcdir}/glibc/configure --prefix=/usr \
      --libdir=$libdir --libexecdir=$libdir \
      --with-headers=/usr/include \
      --enable-add-ons=nptl,libidn$extra_addons \
      --enable-kernel=2.6.27 \
      --with-tls --with-__thread \
      --enable-bind-now --without-gd \
      --without-cvs --disable-profile \
      --enable-multi-arch

  # build libraries with hardening disabled
  echo "build-programs=no" >> configparms
  make
  
  # re-enable hardening for programs
  sed -i "s#=no#=yes#" configparms
  echo "CC += -fstack-protector -D_FORTIFY_SOURCE=2" >> configparms
  echo "CXX += -fstack-protector -D_FORTIFY_SOURCE=2" >> configparms
  make

  # remove harding in preparation to run test-suite
  sed -i '2,4d' configparms
}

check() {
  cd ${srcdir}/glibc-build

  # some errors are expected - manually check log files
  make -k check || true
}

package() {
  cd ${srcdir}/glibc-build
  make install_root=${pkgdir} install

  if [[ ${CARCH} != "mips64el" ]]; then
      libdir=usr/lib
      slibdir=lib
  else
      libdir=usr/lib32
      slibdir=lib32
  fi

  rm -f ${pkgdir}/etc/ld.so.{cache,conf}

  install -dm755 ${pkgdir}/etc/rc.d
  install -dm755 ${pkgdir}/usr/sbin
  install -dm755 ${pkgdir}/${libdir}/locale
  install -m644 ${srcdir}/glibc/nscd/nscd.conf ${pkgdir}/etc/nscd.conf
  install -m755 ${srcdir}/nscd ${pkgdir}/etc/rc.d/nscd
  install -m755 ${srcdir}/locale-gen ${pkgdir}/usr/sbin
  install -m644 ${srcdir}/glibc/posix/gai.conf ${pkgdir}/etc/gai.conf

  sed -i -e 's/^\tserver-user/#\tserver-user/' ${pkgdir}/etc/nscd.conf

  # create /etc/locale.gen
  install -m644 ${srcdir}/locale.gen.txt ${pkgdir}/etc/locale.gen
  sed -i "s|/| |g" ${srcdir}/glibc/localedata/SUPPORTED
  sed -i 's|\\| |g' ${srcdir}/glibc/localedata/SUPPORTED
  sed -i "s|SUPPORTED-LOCALES=||" ${srcdir}/glibc/localedata/SUPPORTED
  cat ${srcdir}/glibc/localedata/SUPPORTED >> ${pkgdir}/etc/locale.gen
  sed -i "s|^|#|g" ${pkgdir}/etc/locale.gen

  if [[ ${CARCH} = "x86_64" ]]; then
    # fix for the linker
    sed -i '/RTLDLIST/s%lib64%lib%' ${pkgdir}/usr/bin/ldd
    # Comply with multilib binaries, they look for the linker in /lib64
    mkdir ${pkgdir}/lib64
    cd ${pkgdir}/lib64
    ln -v -s ../lib/ld* .
  elif [[ ${CARCH} = "mips64el" ]]; then
    # Previously our binaries used /lib/ld.so.1 as the interpreter, we
    # don't want the upgrade to fail due to this.
    mkdir ${pkgdir}/lib
    cd ${pkgdir}/lib
    ln -s ../lib32/ld* .
  fi
  
  # manually strip files as stripping libpthread-*.so and libthread_db.so
  # with the default $STRIP_SHARED breaks gdb and stripping ld-*.so breaks
  # valgrind on x86_64

  cd $pkgdir
  strip $STRIP_BINARIES sbin/{ldconfig,sln} \
                        usr/bin/{gencat,getconf,getent,iconv,locale} \
                        usr/bin/{localedef,pcprofiledump,rpcgen,sprof} \
                        $libdir/getconf/* \
                        usr/sbin/{iconvconfig,nscd}
  [[ $CARCH = "i686" ]] && strip $STRIP_BINARIES usr/bin/lddlibc4

  strip $STRIP_STATIC $libdir/*.a \
                      $slibdir/{{ld,libpthread}-${pkgver},libthread_db-1.0}.so

  strip $STRIP_SHARED $slibdir/{libanl,libBrokenLocale,libc,libcidn,libcrypt}-${pkgver}.so \
                      $slibdir/libnss_{compat,dns,files,hesiod,nis,nisplus}-${pkgver}.so \
                      $slibdir/{libdl,libm,libnsl,libresolv,librt,libutil}-${pkgver}.so \
                      $slibdir/{libmemusage,libpcprofile,libSegFault}.so \
                      $libdir/{pt_chown,{audit,gconv}/*.so}
}