distribution/packages/sysutils/busybox/package.mk

244 lines
7.8 KiB
Makefile
Raw Normal View History

2022-02-05 14:23:32 +00:00
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2009-2016 Stephan Raue (stephan@openelec.tv)
# Copyright (C) 2018 Team LibreELEC (https://libreelec.tv)
# Copyright (C) 2018-present Team CoreELEC (https://coreelec.org)
PKG_NAME="busybox"
PKG_VERSION="1.32.1"
PKG_SHA256="9d57c4bd33974140fd4111260468af22856f12f5b5ef7c70c8d9b75c712a0dee"
PKG_LICENSE="GPL"
PKG_SITE="http://www.busybox.net"
2022-05-30 23:13:55 +00:00
PKG_URL="http://busybox.net/downloads/${PKG_NAME}-${PKG_VERSION}.tar.bz2"
2022-02-05 14:23:32 +00:00
PKG_DEPENDS_HOST="gcc:host"
PKG_DEPENDS_TARGET="toolchain busybox:host hdparm hd-idle dosfstools e2fsprogs zip unzip usbutils parted procps-ng gptfdisk libtirpc"
2022-05-31 20:29:04 +00:00
PKG_DEPENDS_INIT="toolchain libtirpc plymouth-lite:init"
2022-02-05 14:23:32 +00:00
PKG_LONGDESC="BusyBox combines tiny versions of many common UNIX utilities into a single small executable."
# busybox fails to build with GOLD support enabled with binutils-2.25
PKG_BUILD_FLAGS="-parallel -gold"
2022-05-30 23:13:55 +00:00
PKG_NEED_UNPACK="${PROJECT_DIR}/${PROJECT}/initramfs"
2022-02-05 14:23:32 +00:00
# nano text editor
2022-05-30 23:13:55 +00:00
if [ "${NANO_EDITOR}" = "yes" ]; then
PKG_DEPENDS_TARGET="${PKG_DEPENDS_TARGET} nano"
2022-02-05 14:23:32 +00:00
fi
# nfs support
2022-05-30 23:13:55 +00:00
if [ "${NFS_SUPPORT}" = yes ]; then
PKG_DEPENDS_TARGET="${PKG_DEPENDS_TARGET} rpcbind"
2022-02-05 14:23:32 +00:00
fi
2022-05-30 23:13:55 +00:00
if [ "${TARGET_ARCH}" = "x86_64" ]; then
2022-02-05 14:23:32 +00:00
PKG_DEPENDS_TARGET+=" pciutils"
fi
pre_build_target() {
2022-05-30 23:13:55 +00:00
PKG_MAKE_OPTS_TARGET="ARCH=${TARGET_ARCH} \
HOSTCC=${HOST_CC} \
CROSS_COMPILE=${TARGET_PREFIX} \
2022-02-05 14:23:32 +00:00
KBUILD_VERBOSE=1 \
install"
2022-05-30 23:13:55 +00:00
mkdir -p ${PKG_BUILD}/.${TARGET_NAME}
cp -RP ${PKG_BUILD}/* ${PKG_BUILD}/.${TARGET_NAME}
2022-02-05 14:23:32 +00:00
}
pre_build_host() {
2022-05-30 23:13:55 +00:00
PKG_MAKE_OPTS_HOST="ARCH=${TARGET_ARCH} CROSS_COMPILE= KBUILD_VERBOSE=1 install"
2022-02-05 14:23:32 +00:00
2022-05-30 23:13:55 +00:00
mkdir -p ${PKG_BUILD}/.${HOST_NAME}
cp -RP ${PKG_BUILD}/* ${PKG_BUILD}/.${HOST_NAME}
2022-02-05 14:23:32 +00:00
}
pre_build_init() {
2022-05-30 23:13:55 +00:00
PKG_MAKE_OPTS_INIT="ARCH=${TARGET_ARCH} \
2022-02-05 14:23:32 +00:00
HOSTCC=$HOST_CC \
2022-05-30 23:13:55 +00:00
CROSS_COMPILE=${TARGET_PREFIX} \
2022-02-05 14:23:32 +00:00
KBUILD_VERBOSE=1 \
install"
2022-05-30 23:13:55 +00:00
mkdir -p ${PKG_BUILD}/.${TARGET_NAME}-init
cp -RP ${PKG_BUILD}/* ${PKG_BUILD}/.${TARGET_NAME}-init
2022-02-05 14:23:32 +00:00
}
configure_host() {
2022-05-30 23:13:55 +00:00
cd ${PKG_BUILD}/.${HOST_NAME}
cp ${PKG_DIR}/config/busybox-host.conf .config
2022-02-05 14:23:32 +00:00
# set install dir
2022-05-30 23:13:55 +00:00
sed -i -e "s|^CONFIG_PREFIX=.*$|CONFIG_PREFIX=\"${PKG_BUILD}/.install_host\"|" .config
2022-02-05 14:23:32 +00:00
make oldconfig
}
configure_target() {
2022-05-30 23:13:55 +00:00
cd ${PKG_BUILD}/.${TARGET_NAME}
2022-02-05 14:23:32 +00:00
find_file_path config/busybox-target.conf
cp $FOUND_PATH .config
# set install dir
sed -i -e "s|^CONFIG_PREFIX=.*$|CONFIG_PREFIX=\"${INSTALL}/usr\"|" .config
2022-02-05 14:23:32 +00:00
if [ ! "$CRON_SUPPORT" = "yes" ] ; then
sed -i -e "s|^CONFIG_CROND=.*$|# CONFIG_CROND is not set|" .config
sed -i -e "s|^CONFIG_FEATURE_CROND_D=.*$|# CONFIG_FEATURE_CROND_D is not set|" .config
sed -i -e "s|^CONFIG_CRONTAB=.*$|# CONFIG_CRONTAB is not set|" .config
sed -i -e "s|^CONFIG_FEATURE_CROND_SPECIAL_TIMES=.*$|# CONFIG_FEATURE_CROND_SPECIAL_TIMES is not set|" .config
fi
if [ ! "$SAMBA_SUPPORT" = yes ]; then
sed -i -e "s|^CONFIG_FEATURE_MOUNT_CIFS=.*$|# CONFIG_FEATURE_MOUNT_CIFS is not set|" .config
fi
# optimize for size
2022-05-30 23:13:55 +00:00
CFLAGS=`echo ${CFLAGS} | sed -e "s|-Ofast|-Os|"`
CFLAGS=`echo ${CFLAGS} | sed -e "s|-O.|-Os|"`
CFLAGS="${CFLAGS} -I${SYSROOT_PREFIX}/usr/include/tirpc"
2022-02-05 14:23:32 +00:00
2022-05-30 23:13:55 +00:00
LDFLAGS="${LDFLAGS} -fwhole-program"
2022-02-05 14:23:32 +00:00
make oldconfig
}
configure_init() {
2022-05-30 23:13:55 +00:00
cd ${PKG_BUILD}/.${TARGET_NAME}-init
find_file_path config/busybox-init.conf
cp $FOUND_PATH .config
2022-02-05 14:23:32 +00:00
2022-05-30 23:13:55 +00:00
# set install dir
sed -i -e "s|^CONFIG_PREFIX=.*$|CONFIG_PREFIX=\"${INSTALL}/usr\"|" .config
2022-02-05 14:23:32 +00:00
2022-05-30 23:13:55 +00:00
# optimize for size
CFLAGS=`echo ${CFLAGS} | sed -e "s|-Ofast|-Os|"`
CFLAGS=`echo ${CFLAGS} | sed -e "s|-O.|-Os|"`
CFLAGS="${CFLAGS} -I${SYSROOT_PREFIX}/usr/include/tirpc"
2022-02-05 14:23:32 +00:00
2022-05-30 23:13:55 +00:00
LDFLAGS="${LDFLAGS} -fwhole-program"
2022-02-05 14:23:32 +00:00
2022-05-30 23:13:55 +00:00
make oldconfig
2022-02-05 14:23:32 +00:00
}
makeinstall_host() {
2022-05-30 23:13:55 +00:00
mkdir -p ${TOOLCHAIN}/bin
cp -R ${PKG_BUILD}/.install_host/bin/* ${TOOLCHAIN}/bin
2022-02-05 14:23:32 +00:00
}
makeinstall_target() {
mkdir -p ${INSTALL}/usr/bin
2022-05-30 23:13:55 +00:00
[ ${TARGET_ARCH} = x86_64 ] && cp ${PKG_DIR}/scripts/getedid ${INSTALL}/usr/bin
cp ${PKG_DIR}/scripts/dtfile ${INSTALL}/usr/bin
cp ${PKG_DIR}/scripts/dtname ${INSTALL}/usr/bin
cp ${PKG_DIR}/scripts/lsb_release ${INSTALL}/usr/bin/
cp ${PKG_DIR}/scripts/pastebinit ${INSTALL}/usr/bin/
ln -sf pastebinit ${INSTALL}/usr/bin/paste
mkdir -p ${INSTALL}/usr/lib/coreelec
cp ${PKG_DIR}/scripts/functions ${INSTALL}/usr/lib/coreelec
cp ${PKG_DIR}/scripts/fs-resize ${INSTALL}/usr/lib/coreelec
2022-03-29 10:43:27 +00:00
sed -e "s/@DISTRONAME@/${DISTRONAME}/g" \
-i ${INSTALL}/usr/lib/coreelec/fs-resize
2022-02-05 14:23:32 +00:00
if listcontains "${FIRMWARE}" "rpi-eeprom"; then
cp ${PKG_DIR}/scripts/rpi-flash-firmware ${INSTALL}/usr/lib/libreelec
2022-02-05 14:23:32 +00:00
fi
mkdir -p ${INSTALL}/etc
cp ${PKG_DIR}/config/profile ${INSTALL}/etc
cp ${PKG_DIR}/config/inputrc ${INSTALL}/etc
cp ${PKG_DIR}/config/httpd.conf ${INSTALL}/etc
cp ${PKG_DIR}/config/suspend-modules.conf ${INSTALL}/etc
2022-02-05 14:23:32 +00:00
# /etc/fstab is needed by...
touch ${INSTALL}/etc/fstab
2022-02-05 14:23:32 +00:00
# /etc/machine-id, needed by systemd and dbus
ln -sf /storage/.cache/systemd-machine-id ${INSTALL}/etc/machine-id
2022-02-05 14:23:32 +00:00
# /etc/mtab is needed by udisks etc...
ln -sf /proc/self/mounts ${INSTALL}/etc/mtab
2022-02-05 14:23:32 +00:00
# create /etc/hostname
ln -sf /proc/sys/kernel/hostname ${INSTALL}/etc/hostname
2022-02-05 14:23:32 +00:00
2022-05-12 00:47:42 +00:00
# create folder for named tables support
2022-05-30 23:13:55 +00:00
ln -sf /storage/.config/iproute2 ${INSTALL}/etc/iproute2
2022-05-12 00:47:42 +00:00
2022-02-05 14:23:32 +00:00
# add webroot
mkdir -p ${INSTALL}/usr/www
echo "It works" > ${INSTALL}/usr/www/index.html
2022-02-05 14:23:32 +00:00
mkdir -p ${INSTALL}/usr/www/error
echo "404" > ${INSTALL}/usr/www/error/404.html
2022-02-05 14:23:32 +00:00
}
post_install() {
### This resolves a conflict with the bash package.
if [ "$(readlink ${INSTALL}/usr/bin/sh)" = "busybox" ]
then
rm -f ${INSTALL}/usr/bin/sh
ln -s bash ${INSTALL}/usr/bin/sh
fi
2022-05-30 23:13:55 +00:00
ROOT_PWD="`${TOOLCHAIN}/bin/cryptpw -m sha512 ${ROOT_PASSWORD}`"
2022-02-05 14:23:32 +00:00
echo "chmod 4755 ${INSTALL}/usr/bin/busybox" >> $FAKEROOT_SCRIPT
echo "chmod 000 ${INSTALL}/usr/cache/shadow" >> $FAKEROOT_SCRIPT
2022-02-05 14:23:32 +00:00
2022-05-30 23:13:55 +00:00
add_user root "${ROOT}_PWD" 0 0 "Root User" "/storage" "/bin/sh"
2022-02-05 14:23:32 +00:00
add_group root 0
add_group users 100
add_user nobody x 65534 65534 "Nobody" "/" "/bin/sh"
add_group nogroup 65534
enable_service shell.service
enable_service show-version.service
enable_service var.mount
listcontains "${FIRMWARE}" "rpi-eeprom" && enable_service rpi-flash-firmware.service
# cron support
if [ "$CRON_SUPPORT" = "yes" ] ; then
mkdir -p ${INSTALL}/usr/lib/systemd/system
cp ${PKG_DIR}/system.d.opt/cron.service ${INSTALL}/usr/lib/systemd/system
2022-02-05 14:23:32 +00:00
enable_service cron.service
mkdir -p ${INSTALL}/usr/share/services
cp -P ${PKG_DIR}/default.d/*.conf ${INSTALL}/usr/share/services
cp ${PKG_DIR}/system.d.opt/cron-defaults.service ${INSTALL}/usr/lib/systemd/system
2022-02-05 14:23:32 +00:00
enable_service cron-defaults.service
fi
}
makeinstall_init() {
mkdir -p ${INSTALL}/bin
ln -sf busybox ${INSTALL}/usr/bin/sh
ln -sf busybox ${INSTALL}/usr/bin/bc
chmod 4755 ${INSTALL}/usr/bin/busybox
2022-02-05 14:23:32 +00:00
mkdir -p ${INSTALL}/etc
touch ${INSTALL}/etc/fstab
ln -sf /proc/self/mounts ${INSTALL}/etc/mtab
2022-02-05 14:23:32 +00:00
if find_file_path initramfs/platform_init; then
cp ${FOUND_PATH} ${INSTALL}
sed -e "s/@BOOT_LABEL@/${DISTRO_BOOTLABEL}/g" \
-e "s/@DISK_LABEL@/${DISTRO_DISKLABEL}/g" \
-i ${INSTALL}/platform_init
chmod 755 ${INSTALL}/platform_init
2022-02-05 14:23:32 +00:00
fi
cp ${PKG_DIR}/scripts/functions ${INSTALL}
cp ${PKG_DIR}/scripts/init ${INSTALL}
2022-02-05 14:23:32 +00:00
if [ -e "${PROJECT_DIR}/${PROJECT}/devices/${DEVICE}/device.init" ]
then
cp ${PROJECT_DIR}/${PROJECT}/devices/${DEVICE}/device.init ${INSTALL}
else
touch ${INSTALL}/device.init
fi
chmod 755 ${INSTALL}/device.init
2022-02-05 14:23:32 +00:00
sed -e "s/@DISTRONAME@/${DISTRONAME}/g" \
2022-03-29 10:43:27 +00:00
-e "s/@DEVICENAME@/${DEVICE}/g" \
-e "s/@KERNEL_NAME@/${KERNEL_NAME}/g" \
-i ${INSTALL}/init
chmod 755 ${INSTALL}/init
2022-02-05 14:23:32 +00:00
}