### this file is sourced not run
PKGBUILD=1
PKGARCH=x86_64

# source: james
# release tarball
PKGVER=1.2.4
TARBALL=musl-$PKGVER.tar.gz
MD5SUM=ba95cb2c0ba278f081f96380be555fce
SRC_URL=http://musl.libc.org/releases/$TARBALL
BUNDLE=

# git-master tarball
#PKGVER=1.2.3.2023.04 # release is one year behind at this point
#MD5SUM=6337d5cb096fdb421aae0e5d7ddb05af
#hash=7d756e1c04de6eb3f2b3d3e1141a218bb329fcfb
#hash7=${hash#???????}; hash7=${hash%$hash7}
#TARBALL=musl-$PKGVER-$hash7.tar.gz
#SRC_URL=https://git.musl-libc.org/cgit/musl/snapshot/musl-$hash.tar.gz

SLACKDESC="musl-libc: musl-libc $PKGVER (musl C library)  
musl-libc:  
musl-libc: Musl is a small yet versatile and complete C library. Designed 
musl-libc: mainly for static linking.  
musl-libc: 
musl-libc: This contains the 64-bit version of the static libraries,
musl-libc: as well as gcc wrapper, for building 64-bit static binaries.
musl-libc: 
musl-libc: Compiler is called musl-gcc.
musl-libc: 
musl-libc: http://musl.libc.org/
"

### default pkg_download
### default pkg_prepare
### default pkg_package
### build
pkg_build() {
	cd /tmp/musl*
	export CFLAGS="$CFLAGS -fPIC" # make sure everything is relocatable
	./configure --prefix=/usr/musl --exec-prefix=/usr --disable-shared --syslibdir=/$LIBDIR &&
	#cat config.mak && read &&
	make $MAKEFLAGS && make install &&
	pkg_build_slackdesc &&
	
	# bug
	sed -i -e 's/gcc -m64/gcc/' /usr/bin/musl-gcc &&

	# make sure it works
	cat > /tmp/test.c << EOF &&
#include <stdio.h>
int main() {
	printf("It works!\n");
	return 0;
}
EOF
	musl-gcc -s -o /tmp/test /tmp/test.c &&
	file /tmp/test &&
	/tmp/test
}
