musl: build without gnu make

This commit is contained in:
Ella-0 2021-10-11 17:30:08 +01:00
parent 1b869812b8
commit 64ec36b51a
7 changed files with 271 additions and 12 deletions

View file

@ -0,0 +1,28 @@
alltypes_h = custom_target(
'alltypes.h',
output : 'alltypes.h',
input : [
meson.project_source_root() + '/tools/mkalltypes.sed',
meson.project_source_root() + '/arch/'+arch+'/bits/alltypes.h.in',
meson.project_source_root() + '/include/alltypes.h.in'
],
command : ['sed', '-f', '@INPUT0@', '@INPUT1@', '@INPUT2@'],
capture : true
)
syscall_h_in = custom_target(
'syscall.in',
output : 'syscall.in',
input : meson.project_source_root() + '/arch/'+arch+'/bits/syscall.h.in',
command : ['sed', '-n', '-e', 's/__NR_/SYS_/p', '@INPUT@'],
capture : true
)
syscall_h = custom_target(
'syscall.h',
output : 'syscall.h',
input : [ meson.project_source_root() + '/arch/'+arch+'/bits/syscall.h.in', syscall_h_in ],
command : ['cat', '@INPUT0@', '@INPUT1@'],
capture : true
)

View file

@ -8,35 +8,47 @@ ext="dev"
fetch() {
curl "https://musl.libc.org/releases/$pkgname-$pkgver.tar.gz" -o $pkgname-$pkgver.tar.gz
tar -xf $pkgname-$pkgver.tar.gz
cd $pkgname-$pkgver
cp ../../meson.build .
cp ../../glob.sh .
cp ../../globbits.sh .
cp ../../version_h.sh .
cp ../../crt.meson.build crt/meson.build
mkdir bits
cp ../../bits.meson.build bits/meson.build
mkdir build
}
build() {
cd $pkgname-$pkgver
./configure \
--prefix=/usr \
--build=$(uname -m)-unknown-linux-musl \
--host=$(uname -m)-unknown-linux-musl \
--enable-wrapper=no
gmake
cd build
meson .. -Dprefix=/usr
samu
}
package() {
cd $pkgname-$pkgver
gmake install DESTDIR=$pkgdir
rm -r $pkgdir/usr/include
cd build
DESTDIR=$pkgdir samu install
cd ..
rm -rf $pkgdir/usr/include
install -d $pkgdir/usr/bin
install -d $pkgdir/lib
rm $pkgdir/lib/ld-musl-$(uname -m).so.1
mv $pkgdir/usr/lib/libc.so $pkgdir/lib/ld-musl-$(uname -m).so.1
ln -sr $pkgdir/lib/ld-musl-$(uname -m).so.1 $pkgdir/usr/lib/libc.so
ln -sr $pkgdir/lib/ld-musl-$(uname -m).so.1 $pkgdir/usr/bin/ldd
}
package_dev() {
cd $pkgname-$pkgver
gmake install DESTDIR=$pkgdir
cd build
DESTDIR=$pkgdir samu install
rm $pkgdir/usr/lib/*.so
rm -rf $pkgdir/lib
}

View file

@ -0,0 +1,45 @@
Scrt1 = custom_target('Scrt1.o',
output : 'Scrt1.o',
input : 'Scrt1.c',
command : [ cc.cmd_array(), inc_dir_flags, c_args, '-DCRT', '-c', '-o', '@OUTPUT@', '@INPUT@' ],
depends : [ alltypes_h, syscall_h, version_h ],
install : true,
install_dir: 'lib'
)
rcrt1 = custom_target('rcrt1.o',
output : 'rcrt1.o',
input : 'rcrt1.c',
command : [ cc.cmd_array(), inc_dir_flags, c_args, '-DCRT', '-c', '-o', '@OUTPUT@', '@INPUT@' ],
depends : [ alltypes_h, syscall_h, version_h ],
install : true,
install_dir: 'lib'
)
crt1 = custom_target('crt1.o',
output : 'crt1.o',
input : 'crt1.c',
command : [ cc.cmd_array(), inc_dir_flags, c_args, '-DCRT', '-c', '-o', '@OUTPUT@', '@INPUT@' ],
depends : [ alltypes_h, syscall_h, version_h ],
install : true,
install_dir: 'lib'
)
crti = custom_target('crti.o',
output : 'crti.o',
input : target_machine.cpu_family() + '/crti.s',
command : [ cc.cmd_array(), inc_dir_flags, c_args, '-DCRT', '-c', '-o', '@OUTPUT@', '@INPUT@' ],
depends : [ alltypes_h, syscall_h, version_h ],
install : true,
install_dir: 'lib'
)
crtn = custom_target('crtn.o',
output : 'crtn.o',
input : target_machine.cpu_family() + '/crtn.s',
command : [ cc.cmd_array(), inc_dir_flags, c_args, '-DCRT', '-c', '-o', '@OUTPUT@', '@INPUT@' ],
depends : [ alltypes_h, syscall_h, version_h ],
install : true,
install_dir: 'lib'
)

23
linux/musl/glob.sh Executable file
View file

@ -0,0 +1,23 @@
#!/bin/sh
ARCH=$1
MALLOC_IMPL=mallocng
ARCH_FILES=src/*/x86_64/*.[csS]
HAVE=$(echo $ARCH_FILES | tr ' ' '\n' | sed 's|'$ARCH/'||g' | cut -d'.' -f 1)
echo $ARCH_FILES | tr ' ' '\n'
FILES=$(echo src/*/*.[csS] | tr ' ' '\n')
for have in $HAVE; do
FILES=$(echo $FILES | tr ' ' '\n' | grep -v $have'.[csS]')
done
echo $FILES | tr ' ' '\n'
echo src/malloc/$MALLOC_IMPL/*.[csS] | tr ' ' '\n'
#find src/*/ -maxdepth 1 -name '*.[csS]'
#find src/*/$ARCH -maxdepth 1 -name '*.[csS]'

13
linux/musl/globbits.sh Executable file
View file

@ -0,0 +1,13 @@
#!/bin/sh
ARCH=$1
ARCH_INC=arch/$ARCH/bits/*.h
echo $ARCH_INC | tr ' ' '\n'
HAVE=$(echo $ARCH_INC | tr ' ' '\n' | sed 's|'$ARCH'|generic|g')
INCLUDES=arch/generic/bits/*.h
for inc in $HAVE; do
INCLUDES=$(echo $INCLUDES | tr ' ' '\n' | grep -v $inc)
done
echo $INCLUDES | tr ' ' '\n'

136
linux/musl/meson.build Normal file
View file

@ -0,0 +1,136 @@
project('musl', 'c', version : '1.2.2', license : 'MIT')
cc = meson.get_compiler('c')
cmd = cc.cmd_array()
cmd += '--print-libgcc-file-name'
libgcc = run_command(cmd)
libgcc = libgcc.stdout().strip()
message('libgcc: ', libgcc)
globbed_sources = run_command(meson.project_source_root() + '/glob.sh', target_machine.cpu_family())
newline= '''
'''
globbed_sources = globbed_sources.stdout().strip().split(newline)
globbed_headers = run_command(meson.project_source_root() + '/globbits.sh', target_machine.cpu_family())
newline= '''
'''
globbed_headers = globbed_headers.stdout().strip().split(newline)
install_headers(globbed_headers, subdir: 'bits')
install_headers(
run_command('find', meson.project_source_root() + '/include/', '-name', '*.h').stdout().strip().split(newline)
)
install_headers(
run_command('find', meson.project_source_root() + '/include/net', '-name', '*.h').stdout().strip().split(newline),
subdir: 'net'
)
install_headers(
run_command('find', meson.project_source_root() + '/include/netpacket', '-name', '*.h').stdout().strip().split(newline),
subdir: 'netpacket'
)
install_headers(
run_command('find', meson.project_source_root() + '/include/sys', '-name', '*.h').stdout().strip().split(newline),
subdir: 'sys'
)
install_headers(
run_command('find', meson.project_source_root() + '/include/scsi', '-name', '*.h').stdout().strip().split(newline),
subdir: 'scsi'
)
install_headers(
run_command('find', meson.project_source_root() + '/include/arpa', '-name', '*.h').stdout().strip().split(newline),
subdir: 'arpa'
)
install_headers(
run_command('find', meson.project_source_root() + '/include/netinet', '-name', '*.h').stdout().strip().split(newline),
subdir: 'netinet'
)
message(globbed_headers)
c_args = [
'-pipe',
'-fomit-frame-pointer',
'-fno-unwind-tables',
'-fno-asynchronous-unwind-tables',
'-ffunction-sections',
'-fdata-sections',
'-std=c99', '-ffreestanding', '-nostdinc',
'-D_XOPEN_SOURCE=700',
'-fno-stack-protector',
'-fPIC'
]
ld_args = [
'-nostdlib',
'-Wl,--dynamic-list='+meson.project_source_root()+'/dynamic.list',
'-Wl,-e,_dlstart',
libgcc
]
arch = target_machine.cpu()
inc_dir_flags = [
'-I'+meson.project_source_root()+'/arch/' + arch,
'-I'+meson.project_source_root()+'/arch/generic',
'-I'+meson.project_source_root()+'/src/internal',
'-I'+meson.project_source_root()+'/src/include',
'-I'+meson.project_source_root()+'/include',
'-I'+meson.project_build_root()
]
inc_dirs = include_directories(
'arch/' + arch,
'arch/generic',
'src/internal',
'src/include',
'include'
)
subdir('bits/')
ldso_sources = [
'ldso/dlstart.c',
'ldso/dynlink.c',
]
version_h = custom_target(
'version.h',
output : 'version.h',
command : [ meson.project_source_root()+'/version_h.sh' ],
capture : true
)
shared_library('c',
ldso_sources,
globbed_sources,
alltypes_h,
syscall_h,
version_h,
c_args: c_args, link_args: ld_args,
include_directories: inc_dirs,
install: true
)
static_library('c',
ldso_sources,
globbed_sources,
alltypes_h,
syscall_h,
version_h,
c_args: c_args, link_args: ld_args,
include_directories: inc_dirs,
install: true
)
static_library('crypt', install: true)
static_library('dl', install: true)
static_library('m', install: true)
static_library('rt', install: true)
static_library('pthread', install: true)
static_library('util', install: true)
static_library('xnet', install: true)
subdir('crt')

2
linux/musl/version_h.sh Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
printf '#define VERSION "%s"\n' $(sh ./tools/version.sh)