repo/extra/libelf/build

52 lines
1.8 KiB
Plaintext
Raw Normal View History

2019-06-21 15:09:56 +00:00
#!/bin/sh -e
2020-05-26 11:17:16 +00:00
#
2020-05-26 15:17:04 +00:00
# Word splitting (for CFLAGS, CC, etc) is sadly required.
2020-05-26 11:17:16 +00:00
# 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 15:17:04 +00:00
export CFLAGS="-fPIC -O2 $CFLAGS"
2020-05-26 15:01:54 +00:00
export LDFLAGS="-shared $LDFLAGS"
2019-06-21 15:09:56 +00:00
2020-05-26 11:17:16 +00:00
# Patch unneeded in next release.
patch -p1 < libelf-linux.patch
2019-07-06 14:04:12 +00:00
2020-05-26 11:17:16 +00:00
# Generate needed header file.
common/native-elf-format > common/native-elf-format.h
2019-06-21 15:09:56 +00:00
2020-05-26 11:17:16 +00: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
2020-05-26 15:23:35 +00:00
${CC:-cc} -I./libelf -I./common $CFLAGS $CPPFLAGS -c \
2020-05-26 15:01:54 +00:00
-o "${file%%.c}.o" "$file"
2020-05-26 11:17:16 +00:00
done
mkdir -p "$1/usr/lib"
# Create shared library.
2020-05-26 15:23:35 +00:00
${CC:-cc} $LDFLAGS $CFLAGS -I./libelf -I./common libelf/*.o \
2020-05-26 15:01:54 +00:00
-o "$1/usr/lib/libelf.so.1"
2020-05-26 11:17:16 +00:00
# Create static library.
2020-05-26 15:01:54 +00:00
${AR:-ar} -rc "$1/usr/lib/libelf.a" libelf/*.o
2020-05-26 11:17:16 +00:00
# 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"