# Maintainer: PktSurf <smlinux@pktsurf.in>
app=musl
version=1.2.3
build=2sml
homepage="http://www.musl-libc.org/"
download="https://musl.libc.org/releases/musl-$version.tar.gz"
desc="Simple, fast and POSIX-compliant C library"
requires="musl"
preservestaticlibs=1

prepbuilddir() {
  mkandenterbuilddir
  rm -rf $app-$version

  tar xf $srcdir/$app-$version.tar.?z*
  cd $app-$version
  fixbuilddirpermissions
}

build() {
  ./configure \
    --prefix="" 

  make
  make install DESTDIR=$pkg

  # Some additional stuff from alpine 
  mkdir -p $pkg/bin 
  gcc -o $pkg/bin/getconf $srcdir/getconf.c 
  gcc -o $pkg/bin/getent $srcdir/getent.c
  gcc -o $pkg/bin/iconv $srcdir/iconv.c 

  ( 
    cd $pkg/lib
    # Remove the symlink, it'll break upgrades and make the system useless
    rm ld-musl-$arch.so.1 
    # Copy the libc.so as the $arch-specific file
    cp libc.so ld-musl-$arch.so.1
  )

  cp COPYRIGHT $pkgdocs/

  cp $srcdir/{cdefs.h,queue.h,stab.h,tree.h} $pkg/include/sys/

  [ "$arch" = "aarch64" ] && install -Dm 644 $srcdir/asm.hwcap.h $pkg/include/asm/hwcap.h

  mkfinalpkg
}

sha512sums="
0d47c3a8c34301b81b346dfd90eedc8d7a68b9dd7cdde41f0003f985a55aec30d7eca974be233ae31814e9c608e989807008a56fff986d88ffe8a09f3b869ee5  musl-1.2.3.tar.lz
0d80f37b34a35e3d14b012257c50862dfeb9d2c81139ea2dfa101d981d093b009b9fa450ba27a708ac59377a48626971dfc58e20a3799084a65777a0c32cbc7d  getconf.c
378d70e65bcc65bb4e1415354cecfa54b0c1146dfb24474b69e418cdbf7ad730472cd09f6f103e1c99ba6c324c9560bccdf287f5889bbc3ef0bdf0e08da47413  getent.c
9d42d66fb1facce2b85dad919be5be819ee290bd26ca2db00982b2f8e055a0196290a008711cbe2b18ec9eee8d2270e3b3a4692c5a1b807013baa5c2b70a2bbf  iconv.c
3af049adb95230efab7e71964e9cb4a5a4d6b4a10adec43e1540fc2a10dbc77ed96511bc862c2f13deb6d599298d3ec2610ad0107898f6105ba4705f973737db  asm.hwcap.h
8c3fddd73b696a38e633953715c79c47703739be27ee085fc6c960a57b6746ca05bf6406f7e6126cc1a13204254fd5830afb566624e1f298f4d6b58216013c28  cdefs.h
19cec4d39310285eb49ad1beae86884080e0152f9477757513050211b31f95ee7283a64ae95939683df09231cfb021ace816b26981ad05f4fff0a39519f935fe  queue.h
cd57bec6b2462b08b54dcfc6ba37e1d5289fcdd9463f22ea091679aa8006e24d89c9d57637c0e7a5bfbf02d06e93aa4cb3c0d066400aa1b698a8ae66a9cb7b8e  stab.h
07cb70f2f0ddb31e23dd913c6f561fc9885667c5803fdf3a559676c99d08834b4104589bacb5d17b4a0b379c68c81a1cf3173832b3da33a7b936fa7b93706844  tree.h
"
