repo/extra/libelf/build

49 lines
1.7 KiB
Plaintext
Raw Normal View History

2019-06-21 09:09:56 -06:00
#!/bin/sh -e
2020-05-26 05:17:16 -06:00
#
# Word splitting (for CFLAGS, CC, etc) is sadly required.
# shellcheck disable=2086
#
# This package used to provide the old 'libelf' library. This had a sane
# build system and caused us no trouble. There are two issues with the
# old library, 1. It's been unmaintained for years. 2. The Linux kernel
# will (soon) no longer be compatible with it.
#
# elfutils is not an option (as an alternative) as it heavily depends on
# glibc. To package it for a musl based system 8 or so patches are needed
# as well as various libc "extensions" from glibc (fts, obstack, argp).
#
# elftoolchain requires BSD make to build. Rather than package BSD make,
# let's just do the equivalent ourselves in shell. This is fairly simple
# as all we're building is 'libelf' and not the entire toolchain.
2020-05-26 05:20:02 -06:00
export CFLAGS="-shared -fPIC -O2 $CFLAGS"
2019-06-21 09:09:56 -06:00
2020-05-26 05:17:16 -06:00
# Patch unneeded in next release.
patch -p1 < libelf-linux.patch
2019-07-06 08:04:12 -06:00
2020-05-26 05:17:16 -06:00
# Generate needed header file.
common/native-elf-format > common/native-elf-format.h
2019-06-21 09:09:56 -06:00
2020-05-26 05:17:16 -06:00
# Generate needed .c files using m4.
for file in libelf/*.m4; do
${M4:-m4} -DSRCDIR=libelf "$file" > "${file%%.m4}.c"
done
# Create all objects (.o).
for file in libelf/*.c; do
${CC:-cc} -I./common $CFLAGS -c -o "${file%%.c}.o" "$file"
done
mkdir -p "$1/usr/lib"
# Create shared library.
${CC:-cc} $CFLAGS -I./common libelf/*.o -o "$1/usr/lib/libelf.so.1"
# Create static library.
${AR:-ar} rc "$1/usr/lib/libelf.a" libelf/*.o
# Install remaining headers/files.
ln -sf libelf.so.1 "$1/usr/lib/libelf.so"
install -Dm644 libelf/libelf.h "$1/usr/include/libelf.h"
install -Dm644 libelf/gelf.h "$1/usr/include/gelf.h"
install -Dm644 common/elfdefinitions.h "$1/usr/include/elfdefinitions.h"