2023-07-24 15:07:49 +00:00
#!/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."
2023-08-08 17:46:04 +00:00
if ! [ -z ${ dependencies +x } ] ; then
2023-08-11 16:25:07 +00:00
echo " Installing dependencies of $name : ( ${ dependencies [@] } ) "
2023-08-08 17:46:04 +00:00
for dep in ${ dependencies [@] } ; do
tools/install-package.sh $dep
done
fi
2023-07-24 15:07:49 +00:00
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."
2023-08-11 16:25:07 +00:00
if ! [ -f $output ] ; then
echo " Downloading tarball for $name ... "
wget $url --quiet
else
echo " Using cached tarball for $name . "
fi
2023-07-24 15:07:49 +00:00
echo " $sha256sum $output " | sha256sum -c
tar xf $output
; ;
git)
2023-08-19 17:54:37 +00:00
if ! [ -d $srcdir ] ; then
2023-08-11 16:25:07 +00:00
echo " Cloning repository for $name ... "
git clone $url $srcdir
else
echo " Using local repository for $name . "
fi
2023-07-24 15:07:49 +00:00
if ! [ -z ${ tag +x } ] ; then
cd $srcdir
git checkout $tag
cd -
fi
; ;
*)
show_error " error: Unrecognized 'format' key in PACKAGE file: ' $format ' "
; ;
esac
2023-08-11 16:25:07 +00:00
if ! [ " $set_cc_variables " = "no" ] ; then
2023-07-24 17:14:22 +00:00
export CC = x86_64-luna-gcc
export CXX = x86_64-luna-g++
2023-08-19 17:54:37 +00:00
export AR = x86_64-luna-ar
2023-08-08 18:28:11 +00:00
export PKG_CONFIG = luna-pkg-config
2023-07-24 17:14:22 +00:00
export CC_FOR_BUILD = gcc
export CXX_FOR_BUILD = g++
2023-08-19 17:54:37 +00:00
export AR_FOR_BUILD = ar
2023-08-08 18:28:11 +00:00
export PKG_CONFIG_FOR_BUILD = pkg-config
2023-08-11 16:25:07 +00:00
fi
2023-07-24 17:14:22 +00:00
2023-07-24 15:07:49 +00:00
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
2023-07-24 16:50:51 +00:00
elif [ " $use_cmake_configure " = "true" ] ; then
cmake -S $srcdir -B . -DCMAKE_C_COMPILER= $LUNA_ARCH -luna-gcc -DCMAKE_CXX_COMPILER= $LUNA_ARCH -luna-g++ -G "Unix Makefiles"
2023-07-24 15:07:49 +00:00
else
2023-07-24 16:50:51 +00:00
declare -F do_configure & >/dev/null || show_error "error: If not using a default configure line, the PACKAGE file must provide a 'do_configure' function."
2023-07-24 15:07:49 +00:00
do_configure
fi
echo " Building $name ... "
export MAKEJOBS = $( nproc)
if [ " $default_build_make " = "true" ] ; then
make -j$MAKEJOBS
2023-07-24 16:50:51 +00:00
elif [ " $default_build_cmake " = "true" ] ; then
cmake --build .
2023-07-24 15:07:49 +00:00
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 ... "
2023-07-24 16:50:51 +00:00
mkdir -p $installdir
2023-07-24 15:07:49 +00:00
export DESTDIR = $installdir
if [ " $default_install_make " = "true" ] ; then
make install
2023-07-24 16:50:51 +00:00
elif [ " $default_install_cmake " = "true" ] ; then
cmake --install $builddir --prefix /usr
2023-07-24 15:07:49 +00:00
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
2023-08-08 17:46:04 +00:00
rm -f $installdir /usr/lib/*.la # remove all libtool .la files, as they use host stuff which we don't want at all
set +e
$LUNA_ARCH -luna-strip $installdir /usr/bin/* # strip all binaries
set -e
2023-07-24 15:07:49 +00:00
cd $installdir
tar czf $LUNA_ROOT /ports/out/$name -$version .tar.gz *
cd $LUNA_ROOT
rm -rf $WORKDIR