diff --git a/.gitignore b/.gitignore index 1b122cad..457b1ed7 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,7 @@ apps/bin/** tests/**/bin/** base/usr/include/** base/usr/lib/** -**/*.a \ No newline at end of file +**/*.a +ports/**/workdir/** +ports/ports.list +**/*.pkg.tar.xz \ No newline at end of file diff --git a/Makefile b/Makefile index 994d06e0..1127ab60 100644 --- a/Makefile +++ b/Makefile @@ -22,4 +22,5 @@ initrd-clean: install: @$(MAKE) -C kernel install @$(MAKE) -C libs install - @$(MAKE) -C apps install \ No newline at end of file + @$(MAKE) -C apps install + @tools/install-built-ports.sh \ No newline at end of file diff --git a/ports/add-port.sh b/ports/add-port.sh new file mode 100755 index 00000000..2ac3ed62 --- /dev/null +++ b/ports/add-port.sh @@ -0,0 +1,96 @@ +#!/usr/bin/env bash + +set -e + +cd $(dirname $0)/.. + +source tools/env.sh + +cd ports + +export DESTDIR=${DESTDIR:-"$LUNA_ROOT/initrd"} + +export listdir=$PWD + +if [ -z $1 ] +then + echo "Usage: add-port.sh " + exit 1 +fi + +if [ -d $1 ] +then + pkgscript=$1/package.sh +elif [ -f $1 ] +then + pkgscript=$1 +else + echo "Unrecognized argument: $1" + exit 1 +fi + +export portdir=$(realpath $(dirname $pkgscript)) +export workdir=$portdir/workdir +mkdir -p $workdir + +source $pkgscript + +echo "Building $pkgname version $pkgver..." + +cd $workdir + +if ! [ -d $srcdir ] +then + mkdir -p $setupdir + cd $setupdir + + echo "Downloading $pkgname version $pkgver..." + + case $pkgmode in + "web") wget $pkgurl;; + "git") git clone $pkgurl;; + *) echo "Don't know how to download package mode '$pkgmode'"; exit 1;; + esac + + command -v port_unpack >/dev/null + if [ "$?" = "0" ] + then + echo "Unpacking $pkgname version $pkgver..." + port_unpack + fi + + command -v port_patch >/dev/null + if [ "$?" = "0" ] + then + echo "Patching $pkgname version $pkgver..." + port_patch + fi +fi + +cd $workdir + +mkdir -p $builddir +cd $builddir + +command -v port_configure >/dev/null +if [ "$?" = "0" ] +then + echo "Configuring $pkgname version $pkgver..." + port_configure +fi + +echo "Making $pkgname version $pkgver..." +port_build # this one is required + +cd $workdir + +mkdir -p $installdir +cd $installdir + +echo "Installing $pkgname version $pkgver..." +port_install + +echo "$pkgname" >> $listdir/ports.list +cat $listdir/ports.list | sort | uniq | tee $listdir/ports.list >/dev/null # avoid duplicates + +echo "Success! Registered port: $pkgname version $pkgver." diff --git a/ports/bc/bc.patch b/ports/bc/bc.patch new file mode 100644 index 00000000..b5a3bcd5 --- /dev/null +++ b/ports/bc/bc.patch @@ -0,0 +1,69 @@ +diff --color -rN -u bc-vanilla/include/library.h bc-6.0.4/include/library.h +--- a/bc-6.0.4/include/library.h 2022-09-26 19:34:34.000000000 +0200 ++++ b/bc-6.0.4/include/library.h 2022-10-15 14:59:11.413415573 +0200 +@@ -36,7 +36,7 @@ + #ifndef LIBBC_PRIVATE_H + #define LIBBC_PRIVATE_H + +-#ifndef _WIN32 ++#if !defined(_WIN32) && !defined(__luna__) + + #include + +@@ -236,13 +236,17 @@ + BcVm* + bcl_getspecific(void); + +-#ifndef _WIN32 ++#if !defined(_WIN32) && !defined(__luna__) + + typedef pthread_key_t BclTls; + + #else // _WIN32 + ++#ifdef __luna__ ++typedef int BclTls; ++#else + typedef DWORD BclTls; ++#endif + + #endif // _WIN32 + +diff --color -rN -u bc-vanilla/src/vm.c bc-6.0.4/src/vm.c +--- a/bc-6.0.4/src/vm.c 2022-09-26 19:34:35.000000000 +0200 ++++ b/bc-6.0.4/src/vm.c 2022-10-21 17:29:13.511229371 +0200 +@@ -49,7 +49,7 @@ + #include + #include + +-#else // _WIN32 ++#else + + #define WIN32_LEAN_AND_MEAN + #include +@@ -193,7 +193,7 @@ + static void + bc_vm_sigaction(void) + { +-#ifndef _WIN32 ++#if !defined(_WIN32) && !defined(__luna__) + + struct sigaction sa; + +@@ -223,11 +223,15 @@ + if (BC_TTY) sigaction(SIGHUP, &sa, NULL); + #endif // BC_ENABLE_HISTORY + +-#else // _WIN32 ++#else ++ ++#ifndef __luna__ + + signal(SIGTERM, bc_vm_sig); + signal(SIGINT, bc_vm_sig); + ++#endif ++ + #endif // _WIN32 + } + diff --git a/ports/bc/package.sh b/ports/bc/package.sh new file mode 100644 index 00000000..b245bf3d --- /dev/null +++ b/ports/bc/package.sh @@ -0,0 +1,40 @@ +pkgname="bc" +pkgver="6.0.4" +pkgurl="https://github.com/gavinhoward/bc/releases/download/$pkgver/bc-$pkgver.tar.gz" + +pkgmode="web" + +setupdir="$workdir" +builddir="$workdir/build" +installdir="$workdir/build" +srcdir="$workdir/bc-$pkgver" + +port_unpack() +{ + tar xvf bc-$pkgver.tar.gz +} + +port_patch() +{ + patch -u -i $portdir/bc.patch -p 1 -d $workdir +} + +port_configure() +{ + HOSTCC=gcc PREFIX=${PREFIX:-""} $workdir/bc-$pkgver/configure --disable-nls --bc-only --disable-history --disable-man-pages +} + +port_build() +{ + make +} + +port_install() +{ + make install +} + +port_uninstall() +{ + make uninstall +} \ No newline at end of file diff --git a/ports/make-package.sh b/ports/make-package.sh new file mode 100755 index 00000000..2f9d9772 --- /dev/null +++ b/ports/make-package.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -e + +source $(dirname $0)/../tools/env.sh + +source $LUNA_ROOT/ports/$1/package.sh + +mkdir $PWD/pkgroot + +DESTDIR=$PWD/pkgroot $LUNA_ROOT/ports/add-port.sh $pkgname + +cd pkgroot + +tar cJf ../$pkgname-$pkgver.pkg.tar.xz * + +cd .. + +DESTDIR=$PWD/pkgroot $LUNA_ROOT/ports/remove-port.sh $pkgname + +rm -rf $PWD/pkgroot + +echo "Built package $pkgname-$pkgver.pkg.tar.xz" \ No newline at end of file diff --git a/ports/remove-port.sh b/ports/remove-port.sh new file mode 100755 index 00000000..5031852a --- /dev/null +++ b/ports/remove-port.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +set -e + +cd $(dirname $0)/.. + +source tools/env.sh + +cd ports + +export listdir=$PWD + +if [ -z $1 ] +then + echo "Usage: remove-port.sh " + exit 1 +fi + +if [ -d $1 ] +then + pkgscript=$1/package.sh +elif [ -f $1 ] +then + pkgscript=$1 +else + echo "Unrecognized argument: $1" + exit 1 +fi + +export portdir=$(realpath $(dirname $pkgscript)) +export workdir=$portdir/workdir +mkdir -p $workdir + +source $pkgscript + +echo "Removing $pkgname version $pkgver..." + +cd $installdir +port_uninstall + +rm -rf $workdir +cat $listdir/ports.list | sort | uniq | grep -v $pkgname | tee $listdir/ports.list >/dev/null + +echo "Success! Removed port: $pkgname version $pkgver." \ No newline at end of file diff --git a/tools/install-built-ports.sh b/tools/install-built-ports.sh new file mode 100755 index 00000000..0f8a1758 --- /dev/null +++ b/tools/install-built-ports.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -e + +source $(dirname $0)/env.sh + +cd $LUNA_ROOT/ports + +if ! [ -f ./ports.list ] +then + echo "No ports built." +fi + +install_port() +{ + export portdir=$PWD/$1 + export workdir=$portdir/workdir + source $portdir/package.sh + echo "installing port: $pkgname version $pkgver" + mkdir -p $installdir + cd $installdir + port_install +} + +while read package; do + install_port $package +done < ./ports.list