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

# source: james
# release tarball
PKGVER=1.2.5
TARBALL=musl-$PKGVER.tar.gz
MD5SUM=ac5cfde7718d0547e224247ccfe59f18
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-libc32: musl-libc32 $PKGVER (musl C library)  
musl-libc32:  
musl-libc32: Musl is a small yet versatile and complete C library. Designed 
musl-libc32: mainly for static linking.  
musl-libc32: 
musl-libc32: This contains the 32-bit version of the static libraries,
musl-libc32: as well as gcc wrapper, for building 32-bit static binaries.
musl-libc32: 
musl-libc32: Compiler is called musl32-gcc
musl-libc32: 
musl-libc32: 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/musl32 --exec-prefix=/usr --disable-shared --syslibdir=/$LIBDIR32 &&
	sed -i -e 's/^ARCH =.*/ARCH = i386/; s/^CFLAGS =/CFLAGS = -m32 /' config.mak &&
	#cat config.mak && return 1
	make $MAKEFLAGS && make install &&
	mv /usr/bin/musl-gcc /usr/bin/musl32-gcc &&
	pkg_build_slackdesc &&
	
	# patch the specs file with ours
	cp /tmp/pkg/musl-gcc.specs /usr/musl32/lib &&

	# bug
	sed -i -e 's/gcc -m32/gcc/' /usr/bin/musl32-gcc &&

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