Skip to content

Commit

Permalink
Meta: Add install-ports CMake target
Browse files Browse the repository at this point in the history
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
  • Loading branch information
petelliott authored and awesomekling committed Apr 12, 2021
1 parent 9c3948e commit 938924f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions Meta/install-ports-tree.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion Meta/lint-ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
PORT_TABLE_FILE,
'build_all.sh',
'build_installed.sh',
'README.md'
'README.md',
'.hosted_defs.sh'
}


Expand Down
10 changes: 10 additions & 0 deletions Ports/.hosted_defs.sh
Original file line number Diff line number Diff line change
@@ -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"
24 changes: 13 additions & 11 deletions Ports/.port_include.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 938924f

Please sign in to comment.