From 938924f36de1f335903608c28c4ba5284d5dd883 Mon Sep 17 00:00:00 2001 From: Peter Elliott Date: Fri, 2 Apr 2021 21:53:41 -0600 Subject: [PATCH] Meta: Add install-ports CMake target install-ports copys the necessary files from Ports/ to /usr/Ports. Also refactor the compiler and destiation variables from .port_include.sh into .hosted_defs.sh. .hosted_defs.sh does not exists when ports are built in serenity --- CMakeLists.txt | 5 +++++ Meta/install-ports-tree.sh | 10 ++++++++++ Meta/lint-ports.py | 3 ++- Ports/.hosted_defs.sh | 10 ++++++++++ Ports/.port_include.sh | 24 +++++++++++++----------- 5 files changed, 40 insertions(+), 12 deletions(-) create mode 100755 Meta/install-ports-tree.sh create mode 100644 Ports/.hosted_defs.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 847e26df418..cebc9eb83a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,11 @@ add_custom_target(check-style USES_TERMINAL ) +add_custom_target(install-ports + COMMAND ${CMAKE_COMMAND} -E env "SERENITY_ROOT=${CMAKE_SOURCE_DIR}" "SERENITY_ARCH=${SERENITY_ARCH}" ${CMAKE_SOURCE_DIR}/Meta/install-ports-tree.sh + USES_TERMINAL +) + set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/Meta/install-ports-tree.sh b/Meta/install-ports-tree.sh new file mode 100755 index 00000000000..ceac2058fa8 --- /dev/null +++ b/Meta/install-ports-tree.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +SERENITY_PORTS_DIR="${SERENITY_ROOT}/Build/${SERENITY_ARCH}/Root/usr/Ports" + +for file in $(git ls-files "${SERENITY_ROOT}/Ports"); do + if [ "$(basename "$file")" != ".hosted_defs.sh" ]; then + target=${SERENITY_PORTS_DIR}/$(realpath --relative-to="${SERENITY_ROOT}/Ports" "$file") + mkdir -p "$(dirname "$target")" && cp "$file" "$target" + fi +done diff --git a/Meta/lint-ports.py b/Meta/lint-ports.py index 41e8ffe7843..a25fc109aa2 100755 --- a/Meta/lint-ports.py +++ b/Meta/lint-ports.py @@ -14,7 +14,8 @@ IGNORE_FILES = { PORT_TABLE_FILE, 'build_all.sh', 'build_installed.sh', - 'README.md' + 'README.md', + '.hosted_defs.sh' } diff --git a/Ports/.hosted_defs.sh b/Ports/.hosted_defs.sh new file mode 100644 index 00000000000..fa44d64b97c --- /dev/null +++ b/Ports/.hosted_defs.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +export SERENITY_ROOT="$(realpath "${SCRIPT}/../")" +export SERENITY_BUILD_DIR="${SERENITY_ROOT}/Build/${SERENITY_ARCH}" +export CC="${SERENITY_ARCH}-pc-serenity-gcc" +export CXX="${SERENITY_ARCH}-pc-serenity-g++" +export AR="${SERENITY_ARCH}-pc-serenity-ar" +export RANLIB="${SERENITY_ARCH}-pc-serenity-ranlib" +export PATH="${SERENITY_ROOT}/Toolchain/Local/${SERENITY_ARCH}/bin:${PATH}" +export DESTDIR="${SERENITY_BUILD_DIR}/Root" diff --git a/Ports/.port_include.sh b/Ports/.port_include.sh index a70af4d9aa6..63bee0766d3 100755 --- a/Ports/.port_include.sh +++ b/Ports/.port_include.sh @@ -2,16 +2,17 @@ set -eu SCRIPT="$(dirname "${0}")" -export SERENITY_ROOT="$(realpath "${SCRIPT}/../")" export SERENITY_ARCH="${SERENITY_ARCH:-i686}" -export SERENITY_BUILD_DIR="${SERENITY_ROOT}/Build/${SERENITY_ARCH}" -export CC="${SERENITY_ARCH}-pc-serenity-gcc" -export CXX="${SERENITY_ARCH}-pc-serenity-g++" -export AR="${SERENITY_ARCH}-pc-serenity-ar" -export RANLIB="${SERENITY_ARCH}-pc-serenity-ranlib" -export PATH="${SERENITY_ROOT}/Toolchain/Local/${SERENITY_ARCH}/bin:${PATH}" -packagesdb="${SERENITY_BUILD_DIR}/packages.db" +maybe_source() { + if [ -f "$1" ]; then + . "$1" + fi +} +DESTDIR="/" +maybe_source "${SCRIPT}/.hosted_defs.sh" + +packagesdb="${DESTDIR}/usr/Ports/packages.db" MD5SUM=md5sum @@ -164,7 +165,7 @@ func_defined build || build() { run make $makeopts } func_defined install || install() { - run make DESTDIR="${SERENITY_BUILD_DIR}/Root" $installopts install + run make DESTDIR=$DESTDIR $installopts install } func_defined post_install || post_install() { echo @@ -194,6 +195,7 @@ func_defined clean_all || clean_all() { addtodb() { if [ ! -f "$packagesdb" ]; then echo "Note: $packagesdb does not exist. Creating." + mkdir -p "${DESTDIR}/usr/Ports/" touch "$packagesdb" fi if ! grep -E "^(auto|manual) $port $version" "$packagesdb" > /dev/null; then @@ -226,10 +228,10 @@ uninstall() { for f in `cat plist`; do case $f in */) - run rmdir "${SERENITY_BUILD_DIR}/Root/$f" || true + run rmdir "${DESTDIR}/$f" || true ;; *) - run rm -rf "${SERENITY_BUILD_DIR}/Root/$f" + run rm -rf "${DESTDIR}/$f" ;; esac done