APP=musl
VERSION=1.1.24
BUILD=1sml
HOMEPAGE='http://www.musl-libc.org/'
DOWNLOAD='https://musl.libc.org/releases/musl-1.1.24.tar.gz'
DESC="Simple, fast and POSIX-compliant C library"
REQUIRES="musl"

build() {
  mkandenterbuilddir
  rm -rf $APP-$VERSION

  tar xf $SRCDIR/$APP-$VERSION.tar.?z*
  cd $APP-$VERSION
  fixbuilddirpermissions

  # Thanks sabotage
  cp $SRCDIR/musl-wcsnrtombs.c src/multibyte/wcsnrtombs.c

  ./configure \
    --prefix="" 

  make
  make install DESTDIR=$PKG

  # Some additional stuff from alpine 
  mkdir -p addons && cd addons
  cp $SRCDIR/{getconf.c,getent.c,iconv.c} .

  gcc -o getconf getconf.c ; install -Dm 755 getconf $PKG/bin/getconf
  gcc -o getent getent.c ; install -Dm 755 getent $PKG/bin/getent
  gcc -o iconv iconv.c ; install -Dm 755 iconv $PKG/bin/iconv
  cd ..

  ( 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

  #( 
  #mkdir -p $PKG/bin 
  #cd $PKG/lib ; ln -sf libc.so ld-musl-$ARCH.so.1
  #)

  mkfinalpkg
}

SHA512SUMS="
5a8c719897b4d24ba7c0d7d584fdc57f46bb65bb9c7ca4b1d03d54cf8b5fd15697ccc5536d3e4e2a907624cfb0926877b8e7fa2b2ef961c3ea4458b7b3ca930c  musl-1.1.24.tar.lz
0d80f37b34a35e3d14b012257c50862dfeb9d2c81139ea2dfa101d981d093b009b9fa450ba27a708ac59377a48626971dfc58e20a3799084a65777a0c32cbc7d  getconf.c
378d70e65bcc65bb4e1415354cecfa54b0c1146dfb24474b69e418cdbf7ad730472cd09f6f103e1c99ba6c324c9560bccdf287f5889bbc3ef0bdf0e08da47413  getent.c
9d42d66fb1facce2b85dad919be5be819ee290bd26ca2db00982b2f8e055a0196290a008711cbe2b18ec9eee8d2270e3b3a4692c5a1b807013baa5c2b70a2bbf  iconv.c
fb9ee91cf8fd6330727b67fee8f4f7c4e603839c5cbd8fa9e838bf2f5f68558119d0535de54643d56ddbc2ac5dcd38878818e91da7c6dd15c10422c84270d2ef  musl-wcsnrtombs.c
3af049adb95230efab7e71964e9cb4a5a4d6b4a10adec43e1540fc2a10dbc77ed96511bc862c2f13deb6d599298d3ec2610ad0107898f6105ba4705f973737db  asm.hwcap.h
8c3fddd73b696a38e633953715c79c47703739be27ee085fc6c960a57b6746ca05bf6406f7e6126cc1a13204254fd5830afb566624e1f298f4d6b58216013c28  cdefs.h
19cec4d39310285eb49ad1beae86884080e0152f9477757513050211b31f95ee7283a64ae95939683df09231cfb021ace816b26981ad05f4fff0a39519f935fe  queue.h
cd57bec6b2462b08b54dcfc6ba37e1d5289fcdd9463f22ea091679aa8006e24d89c9d57637c0e7a5bfbf02d06e93aa4cb3c0d066400aa1b698a8ae66a9cb7b8e  stab.h
07cb70f2f0ddb31e23dd913c6f561fc9885667c5803fdf3a559676c99d08834b4104589bacb5d17b4a0b379c68c81a1cf3173832b3da33a7b936fa7b93706844  tree.h
"
