2021-01-29 01:31:56 +00:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
# SPDX-FileCopyrightText: 2021 Andrius Štikonas <andrius@stikonas.eu>
|
2021-02-18 07:29:58 +00:00
|
|
|
# SPDX-FileCopyrightText: 2021 fosslinux <fosslinux@aussies.space>
|
2021-03-17 17:27:19 +00:00
|
|
|
# SPDX-FileCopyrightText: 2021 Paul Dersey <pdersey@gmail.com>
|
2021-05-18 12:37:34 +01:00
|
|
|
# SPDX-FileCopyrightText: 2021 Melg Eight <public.melg8@gmail.com>
|
2021-02-18 07:29:58 +00:00
|
|
|
#
|
2021-01-29 01:31:56 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
# Common build steps
|
|
|
|
# Build function provides a few common stages with default implementation
|
|
|
|
# that can be overridden on per package basis in the build script.
|
2021-02-18 07:29:58 +00:00
|
|
|
# build takes three arguments:
|
2021-01-29 01:31:56 +00:00
|
|
|
# 1) name-version of the package
|
|
|
|
# 2) optionally specify build script. Default is name-version.sh
|
2021-02-18 07:29:58 +00:00
|
|
|
# 3) optionally specify name of checksum file. Default is checksums
|
2021-04-04 23:41:42 +01:00
|
|
|
# 4) directory of patches. Default is patches
|
2021-04-13 13:34:11 +01:00
|
|
|
# 5) directory to cd into. Default is ${pkg}
|
2021-01-29 01:31:56 +00:00
|
|
|
build () {
|
|
|
|
pkg=$1
|
|
|
|
script_name=${2:-${pkg}.sh}
|
2021-02-18 07:29:58 +00:00
|
|
|
checksum_f=${3:-checksums}
|
2021-04-13 13:34:11 +01:00
|
|
|
dirname=${5:-${pkg}}
|
2021-01-29 01:31:56 +00:00
|
|
|
|
2021-06-24 00:32:19 +01:00
|
|
|
cd "${SOURCES}/${pkg}" || (echo "Cannot cd into ${pkg}!"; kill $$)
|
2021-01-28 18:53:44 +00:00
|
|
|
echo "${pkg}: beginning build using script ${script_name}"
|
2021-01-29 01:31:56 +00:00
|
|
|
base_dir="${PWD}"
|
2021-03-03 00:05:33 +00:00
|
|
|
patch_dir="${base_dir}/${4:-patches}"
|
2021-01-29 01:31:56 +00:00
|
|
|
mk_dir="${base_dir}/mk"
|
2021-01-28 18:53:44 +00:00
|
|
|
files_dir="${base_dir}/files"
|
2021-01-29 01:31:56 +00:00
|
|
|
|
|
|
|
mkdir -p "build"
|
|
|
|
cd "build"
|
|
|
|
|
|
|
|
build_script="${base_dir}/${script_name}"
|
|
|
|
if test -e "${build_script}"; then
|
|
|
|
# shellcheck source=/dev/null
|
|
|
|
. "${build_script}"
|
|
|
|
fi
|
2021-02-03 21:30:02 +00:00
|
|
|
|
|
|
|
echo "${pkg}: unpacking source."
|
2021-05-03 23:48:06 +01:00
|
|
|
build_stage=src_unpack
|
|
|
|
call $build_stage
|
2021-02-03 21:30:02 +00:00
|
|
|
|
2021-04-13 13:34:11 +01:00
|
|
|
cd "${dirname}" || (echo "Cannot cd into build/${dirname}!"; kill $$)
|
2021-01-29 01:31:56 +00:00
|
|
|
|
|
|
|
echo "${pkg}: preparing source."
|
2021-05-03 23:48:06 +01:00
|
|
|
build_stage=src_prepare
|
|
|
|
call $build_stage
|
2021-01-29 01:31:56 +00:00
|
|
|
|
|
|
|
echo "${pkg}: configuring source."
|
2021-05-03 23:48:06 +01:00
|
|
|
build_stage=src_configure
|
|
|
|
call $build_stage
|
2021-01-29 01:31:56 +00:00
|
|
|
|
|
|
|
echo "${pkg}: compiling source."
|
2021-05-03 23:48:06 +01:00
|
|
|
build_stage=src_compile
|
|
|
|
call $build_stage
|
2021-01-29 01:31:56 +00:00
|
|
|
|
|
|
|
echo "${pkg}: installing."
|
2021-05-03 23:48:06 +01:00
|
|
|
build_stage=src_install
|
|
|
|
call $build_stage
|
2021-01-29 01:31:56 +00:00
|
|
|
|
2021-06-24 00:32:19 +01:00
|
|
|
cd "${SOURCES}/${pkg}"
|
2021-01-29 01:31:56 +00:00
|
|
|
|
2021-02-18 07:29:58 +00:00
|
|
|
echo "${pkg}: checksumming installed files."
|
2021-02-28 22:07:55 +00:00
|
|
|
test -e "${checksum_f}" && sha256sum -c "${checksum_f}"
|
2021-02-18 07:29:58 +00:00
|
|
|
|
2021-06-10 11:24:50 +01:00
|
|
|
echo "${pkg}: cleaning up."
|
|
|
|
rm -rf "build"
|
|
|
|
|
2021-01-29 01:31:56 +00:00
|
|
|
echo "${pkg}: build successful"
|
2021-06-24 00:32:19 +01:00
|
|
|
cd "${SOURCES}"
|
2021-02-03 22:09:21 +00:00
|
|
|
|
|
|
|
unset -f src_unpack src_prepare src_configure src_compile src_install
|
2021-01-29 01:31:56 +00:00
|
|
|
}
|
|
|
|
|
2021-04-04 23:41:42 +01:00
|
|
|
# Default unpacking function that unpacks all source tarballs.
|
2021-01-29 01:31:56 +00:00
|
|
|
default_src_unpack() {
|
|
|
|
src_dir="${base_dir}/src"
|
|
|
|
|
2021-05-08 12:32:40 +01:00
|
|
|
# Check for new tar
|
|
|
|
if test -e "${PREFIX}/libexec/rmt"; then
|
|
|
|
for i in "${src_dir}"/*; do
|
|
|
|
tar --no-same-owner -xf "${i}"
|
|
|
|
done
|
|
|
|
else
|
|
|
|
for i in "${src_dir}"/*.tar.gz; do
|
|
|
|
[ -e "${i}" ] || continue
|
|
|
|
tar -xzf "${i}"
|
|
|
|
done
|
|
|
|
for i in "${src_dir}"/*.tar.bz2; do
|
|
|
|
[ -e "${i}" ] || continue
|
|
|
|
tar -xf "${i}" --use-compress-program=bzip2
|
|
|
|
done
|
|
|
|
for i in "${src_dir}"/*.tar.xz; do
|
|
|
|
[ -e "${i}" ] || continue
|
|
|
|
tar -xf "${i}" --use-compress-program=xz
|
|
|
|
done
|
|
|
|
for i in "${src_dir}"/*.tar; do
|
|
|
|
[ -e "${i}" ] || continue
|
|
|
|
tar -xf "${i}"
|
|
|
|
done
|
|
|
|
fi
|
2021-01-29 01:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Default function to prepare source code.
|
|
|
|
# It applies all patches from patch_dir (at the moment only -p0 patches are supported).
|
2021-01-28 18:53:44 +00:00
|
|
|
# Then it copies our custom makefile and any other custom files from files directory.
|
2021-01-29 01:31:56 +00:00
|
|
|
default_src_prepare() {
|
|
|
|
if test -d "${patch_dir}"; then
|
|
|
|
for p in "${patch_dir}"/*.patch; do
|
2021-03-02 22:02:07 +00:00
|
|
|
echo "Applying patch: ${p}"
|
2021-01-29 01:31:56 +00:00
|
|
|
patch -Np0 < "${p}"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
makefile="${mk_dir}/main.mk"
|
|
|
|
if test -e "${makefile}"; then
|
|
|
|
cp "${makefile}" Makefile
|
|
|
|
fi
|
2021-01-28 18:53:44 +00:00
|
|
|
|
|
|
|
if test -d "${files_dir}"; then
|
|
|
|
cp "${files_dir}"/* "${PWD}/"
|
|
|
|
fi
|
2021-01-29 01:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Default function for configuring source.
|
|
|
|
default_src_configure() {
|
|
|
|
:
|
|
|
|
}
|
|
|
|
|
|
|
|
# Default function for compiling source. It simply runs make without any parameters.
|
|
|
|
default_src_compile() {
|
2021-04-02 12:24:40 +01:00
|
|
|
make -f Makefile PREFIX="${PREFIX}"
|
2021-01-29 01:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Default installing function. PREFIX should be set by run.sh script.
|
|
|
|
# Note that upstream makefiles might ignore PREFIX and have to be configured in configure stage.
|
|
|
|
default_src_install() {
|
2021-04-02 12:24:40 +01:00
|
|
|
make -f Makefile install PREFIX="${PREFIX}" DESTDIR="${DESTDIR}"
|
2021-01-29 01:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Check if bash function exists
|
|
|
|
fn_exists() {
|
|
|
|
test "$(type -t "$1")" == 'function'
|
|
|
|
}
|
|
|
|
|
|
|
|
# Call package specific function or default implementation.
|
|
|
|
call() {
|
|
|
|
if fn_exists "$1"; then
|
|
|
|
$1
|
|
|
|
else
|
|
|
|
default_"${1}"
|
|
|
|
fi
|
|
|
|
}
|
2021-05-03 23:48:06 +01:00
|
|
|
|
|
|
|
# Call default build stage function
|
|
|
|
default() {
|
|
|
|
"default_${build_stage}"
|
|
|
|
}
|
2021-05-18 12:37:34 +01:00
|
|
|
|
2021-06-24 00:32:19 +01:00
|
|
|
# Set modified dates of all files to be 0 unix time.
|
2021-05-18 12:37:34 +01:00
|
|
|
# Should be called at the end of bootstrapping process.
|
|
|
|
# This function needs `touch` that supports --no-dereference
|
|
|
|
# (at least coreutils 8.1).
|
|
|
|
canonicalise_all_files_timestamp() {
|
|
|
|
find / -exec touch --no-dereference -t 197001010000.00 {} +
|
|
|
|
}
|
2021-08-05 13:16:19 +01:00
|
|
|
|
|
|
|
populate_device_nodes() {
|
|
|
|
# http://www.linuxfromscratch.org/lfs/view/6.1/chapter06/devices.html
|
|
|
|
mkdir -p "${1}/dev"
|
|
|
|
test -c "${1}/dev/null" || mknod -m 666 "${1}/dev/null" c 1 3
|
|
|
|
test -c "${1}/dev/zero" || mknod -m 666 "${1}/dev/zero" c 1 5
|
|
|
|
test -c "${1}/dev/ptmx" || mknod -m 666 "${1}/dev/ptmx" c 5 2
|
|
|
|
test -c "${1}/dev/tty" || mknod -m 666 "${1}/dev/tty" c 5 0
|
|
|
|
test -c "${1}/dev/random" || mknod -m 444 "${1}/dev/random" c 1 8
|
|
|
|
test -c "${1}/dev/urandom" || mknod -m 444 "${1}/dev/urandom" c 1 9
|
|
|
|
test -c "${1}/dev/console" || mknod -m 666 "${1}/dev/console" c 5 1
|
|
|
|
}
|