ports: Basic ports system + nasm port
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-07-24 17:07:49 +02:00
parent 033aff4f6c
commit 9a00b29304
Signed by: apio
GPG Key ID: B8A7D06E42258954
5 changed files with 195 additions and 0 deletions

3
.gitignore vendored
View File

@ -7,3 +7,6 @@ initrd/bin/**
base/usr/**
.fakeroot
kernel/config.cmake
ports/out/
ports/local/
ports/temp/

19
ports/nasm/PACKAGE Normal file
View File

@ -0,0 +1,19 @@
# Basic information
name="nasm"
version="2.16.01"
# Download options
format="tar"
url="https://www.nasm.us/pub/nasm/releasebuilds/$version/nasm-$version.tar.gz"
output="nasm-$version.tar.gz"
sha256sum="d833bf0f5716e89dbcd345b7f545f25fe348c6e2ef16dbc293e1027bcd22d881"
# Build instructions
use_default_configure=true
default_build_make=true
default_install_make=true
do_patch()
{
mkdir -p $srcdir/asm/include
}

49
tools/install-package.sh Executable file
View File

@ -0,0 +1,49 @@
#!/usr/bin/env bash
set -e
source $(dirname $0)/env.sh
cd $LUNA_ROOT
PORT_NAME=$1
if ! [ -f ports/$PORT_NAME/PACKAGE ]
then
echo "Package $PORT_NAME does not exist. Make sure there is a valid PACKAGE file in the appropriate directory!"
exit 1
fi
source ports/$PORT_NAME/PACKAGE
if [ -f ports/local/$name-$version.tar.gz ]; then
echo "Package $PORT_NAME is already installed and up to date!"
exit 1
fi
if ! [ -f ports/out/$name-$version.tar.gz ]; then
tools/make-package.sh $PORT_NAME
fi
PORT_FILES=$LUNA_BASE/usr/share/pkgdb/$PORT_NAME.files
if [ -f $PORT_FILES ]
then
echo "Package $PORT_NAME is installed, but is an outdated version. Updating."
tools/uninstall-package.sh $PORT_NAME
fi
cp ports/out/$name-$version.tar.gz ports/local/
mkdir -p $LUNA_BASE/usr/share/pkgdb/
cd $LUNA_BASE
find -type f > /tmp/before.list
tar -C $LUNA_BASE -xf $LUNA_ROOT/ports/local/$name-$version.tar.gz
find -type f > /tmp/after.list
awk 'FNR==NR {a[$0]++; next} !($0 in a)' /tmp/before.list /tmp/after.list > $LUNA_BASE/usr/share/pkgdb/$name.files
echo "Package $name version $version successfully installed!"

105
tools/make-package.sh Executable file
View File

@ -0,0 +1,105 @@
#!/usr/bin/env bash
set -e
source $(dirname $0)/env.sh
cd $LUNA_ROOT
PORT_NAME=$1
if ! [ -f ports/$PORT_NAME/PACKAGE ]
then
echo "Package $PORT_NAME does not exist. Make sure there is a valid PACKAGE file in the appropriate directory!"
exit 1
fi
export WORKDIR=$LUNA_ROOT/ports/temp/
show_error()
{
echo $1
exit 1
}
source ports/$PORT_NAME/PACKAGE
[ -z ${name+x} ] && show_error "error: The port's PACKAGE file does not have a 'name' key."
[ -z ${version+x} ] && show_error "error: The port's PACKAGE file does not have a 'version' key."
[ -z ${format+x} ] && show_error "error: The port's PACKAGE file does not have a 'format' key."
[ -z ${url+x} ] && show_error "error: The port's PACKAGE file does not have a 'url' key."
export portdir=$LUNA_ROOT/ports/$name/
export srcdir=${srcdir:-$WORKDIR/$name-$version}
export builddir=$WORKDIR/build-$name
export installdir=$WORKDIR/pkgroot-$name
mkdir -p $WORKDIR
cd $WORKDIR
# Download package sources
case $format in
tar)
[ -z ${output+x} ] && show_error "error: The 'tar' download format needs an 'output' key."
[ -z ${sha256sum+x} ] && show_error "error: The 'tar' download format needs a 'sha256sum' key."
echo "Downloading tarball for $name..."
wget $url --quiet
echo "$sha256sum $output" | sha256sum -c
tar xf $output
rm $output
;;
git)
echo "Cloning repository for $name..."
git clone $url $srcdir
if ! [ -z ${tag+x} ]; then
cd $srcdir
git checkout $tag
cd -
fi
;;
*)
show_error "error: Unrecognized 'format' key in PACKAGE file: '$format'"
;;
esac
mkdir -p $builddir
cd $builddir
declare -F do_patch &>/dev/null && do_patch
echo "Configuring $name..."
if [ "$use_default_configure" = "true" ]; then
$srcdir/configure --host=$LUNA_ARCH-luna --prefix=/usr
else
declare -F do_configure &>/dev/null || show_error "error: If not using the default configure line, the PACKAGE file must provide a 'do_configure' function."
do_configure
fi
echo "Building $name..."
export MAKEJOBS=$(nproc)
if [ "$default_build_make" = "true" ]; then
make -j$MAKEJOBS
else
declare -F do_build &>/dev/null || show_error "error: If not using a default build preset, the PACKAGE file must provide a 'do_build' function."
do_build
fi
echo "Installing $name..."
export DESTDIR=$installdir
if [ "$default_install_make" = "true" ]; then
make install
else
declare -F do_install &>/dev/null || show_error "error: If not using a default install preset, the PACKAGE file must provide a 'do_install' function."
do_install
fi
cd $installdir
tar czf $LUNA_ROOT/ports/out/$name-$version.tar.gz *
cd $LUNA_ROOT
rm -rf $WORKDIR

19
tools/uninstall-package.sh Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -e
source $(dirname $0)/env.sh
cd $LUNA_BASE
PORT_NAME=$1
PORT_FILES=$LUNA_BASE/usr/share/pkgdb/$PORT_NAME.files
if ! [ -f $PORT_FILES ]
then
echo "Package $PORT_NAME has not been installed."
exit 1
fi
rm -v $(cat $LUNA_BASE/usr/share/pkgdb/$PORT_NAME.files)
rm -v $LUNA_BASE/usr/share/pkgdb/$PORT_NAME.files
rm -v $LUNA_ROOT/ports/local/$PORT_NAME-*.tar.gz