2019-09-24 09:56:39 +03:00
#!/bin/bash
set -eu
2019-12-21 00:49:27 +03:00
SCRIPT = ` dirname $0 `
export SERENITY_ROOT = ` realpath $SCRIPT /../`
prefix = $SERENITY_ROOT /Ports
2019-05-28 01:02:29 +03:00
2019-09-24 09:56:39 +03:00
export CC = i686-pc-serenity-gcc
export CXX = i686-pc-serenity-g++
2019-12-21 00:49:27 +03:00
export PATH = $SERENITY_ROOT /Toolchain/Local/bin:$PATH
2019-05-28 01:02:29 +03:00
2019-09-24 09:56:39 +03:00
. " $@ "
shift
: " ${ makeopts : =-j $( nproc) } "
: " ${ installopts : = } "
: " ${ workdir : = $port - $version } "
: " ${ configscript : =configure } "
: " ${ configopts : = } "
: " ${ useconfigure : =false } "
: " ${ depends : = } "
: " ${ patchlevel : =1 } "
2019-05-28 02:25:29 +03:00
2019-09-24 09:56:39 +03:00
run_nocd( ) {
2019-05-28 03:58:36 +03:00
echo " + $@ (nocd) "
( " $@ " )
}
2019-09-24 09:56:39 +03:00
run( ) {
echo " + $@ "
( cd " $workdir " && " $@ " )
2019-05-28 01:02:29 +03:00
}
2019-09-24 09:56:39 +03:00
run_replace_in_file( ) {
2019-11-03 12:05:02 +03:00
run perl -p -i -e " $1 " $2
2019-09-24 09:56:39 +03:00
}
# Checks if a function is defined. In this case, if the function is not defined in the port's script, then we will use our defaults. This way, ports don't need to include these functions every time, but they can override our defaults if needed.
func_defined( ) {
2019-11-03 12:05:02 +03:00
PATH = command -V " $1 " > /dev/null 2>& 1
2019-09-24 09:56:39 +03:00
}
func_defined fetch || fetch( ) {
OLDIFS = $IFS
IFS = $'\n'
for f in $files ; do
IFS = $OLDIFS
2019-11-03 12:05:02 +03:00
read url filename <<< $( echo " $f " )
2019-12-23 15:24:56 +03:00
if [ -f " $filename " ] ; then
echo " $filename already exists "
else
run_nocd curl ${ curlopts :- } " $url " -o " $filename "
fi
2019-09-24 09:56:39 +03:00
case " $filename " in
*.tar*| .tbz*| *.txz| *.tgz)
run_nocd tar xf " $filename "
; ;
*.gz)
run_nocd gunzip " $filename "
; ;
2019-11-13 19:22:24 +03:00
*.zip)
2019-12-06 21:45:57 +03:00
run_nocd bsdtar xf " $filename " || run_nocd unzip -qo " $filename "
2019-11-13 19:22:24 +03:00
; ;
2019-09-24 09:56:39 +03:00
*)
echo " Note: no case for file $filename . "
; ;
esac
2019-12-23 15:24:56 +03:00
done
2019-09-24 09:56:39 +03:00
if [ -d patches ] ; then
for f in patches/*; do
run patch -p" $patchlevel " < " $f "
done
2019-05-28 19:55:49 +03:00
fi
}
2019-09-24 09:56:39 +03:00
func_defined configure || configure( ) {
run ./" $configscript " --host= i686-pc-serenity $configopts
2019-05-28 19:55:49 +03:00
}
2019-09-24 09:56:39 +03:00
func_defined build || build( ) {
2019-11-03 12:05:02 +03:00
run make $makeopts
2019-05-28 11:25:39 +03:00
}
2019-09-24 09:56:39 +03:00
func_defined install || install( ) {
run make DESTDIR = " $SERENITY_ROOT " /Root $installopts install
2019-05-28 02:25:29 +03:00
}
2019-09-24 09:56:39 +03:00
func_defined clean || clean( ) {
2019-11-03 12:05:02 +03:00
rm -rf " $workdir " *.out
2019-05-28 01:02:29 +03:00
}
2019-09-24 09:56:39 +03:00
func_defined clean_dist || clean_dist( ) {
OLDIFS = $IFS
IFS = $'\n'
for f in $files ; do
IFS = $OLDIFS
read url filename hash <<< $( echo " $f " )
rm -f " $filename "
done
2019-05-28 01:02:29 +03:00
}
2019-09-24 09:56:39 +03:00
func_defined clean_all || clean_all( ) {
2019-11-03 12:05:02 +03:00
rm -rf " $workdir " *.out
2019-09-24 09:56:39 +03:00
OLDIFS = $IFS
IFS = $'\n'
for f in $files ; do
IFS = $OLDIFS
read url filename hash <<< $( echo " $f " )
rm -f " $filename "
done
2019-05-28 01:02:29 +03:00
}
2019-09-24 09:56:39 +03:00
addtodb( ) {
if [ ! -f " $prefix " /packages.db ] ; then
echo " Note: $prefix /packages.db does not exist. Creating. "
touch " $prefix " /packages.db
fi
if ! grep -E " ^(auto|manual) $port $version " " $prefix " /packages.db > /dev/null; then
echo " Adding $port $version to database of installed ports! "
if [ " ${ 1 :- } " = "--auto" ] ; then
echo " auto $port $version " >> " $prefix " /packages.db
else
echo " manual $port $version " >> " $prefix " /packages.db
2019-11-03 12:05:02 +03:00
if [ ! -z " ${ dependlist :- } " ] ; then
2019-09-24 09:56:39 +03:00
echo " dependency $port $dependlist " >> " $prefix /packages.db "
fi
fi
else
>& 2 echo " Warning: $port $version already installed. Not adding to database of installed ports! "
fi
2019-05-28 01:02:29 +03:00
}
2019-09-24 09:56:39 +03:00
installdepends( ) {
for depend in $depends ; do
dependlist = " ${ dependlist :- } $depend "
done
for depend in $depends ; do
if ! grep " $depend " " $prefix " /packages.db > /dev/null; then
( cd " ../ $depend " && ./package.sh --auto)
fi
done
2019-05-28 05:02:42 +03:00
}
2019-09-24 09:56:39 +03:00
uninstall( ) {
if grep " ^manual $port " " $prefix " /packages.db > /dev/null; then
if [ -f plist ] ; then
for f in ` cat plist` ; do
case $f in
*/)
2019-09-24 16:34:14 +03:00
run rmdir " $SERENITY_ROOT /Root/ $f " || true
2019-09-24 09:56:39 +03:00
; ;
*)
2019-09-24 16:34:14 +03:00
run rm -rf " $SERENITY_ROOT /Root/ $f "
2019-09-24 09:56:39 +03:00
; ;
esac
done
# Without || true, mv will not be executed if you are uninstalling your only remaining port.
grep -v " ^manual $port " " $prefix " /packages.db > packages.dbtmp || true
mv packages.dbtmp " $prefix " /packages.db
else
>& 2 echo "Error: This port does not have a plist yet. Cannot uninstall."
fi
else
>& 2 echo " Error: $port is not installed. Cannot uninstall. "
fi
}
do_fetch( ) {
installdepends
echo " Fetching $port ! "
2019-05-28 01:02:29 +03:00
fetch
2019-09-24 09:56:39 +03:00
}
do_configure( ) {
if [ " $useconfigure " = "true" ] ; then
echo " Configuring $port ! "
2019-11-13 19:22:24 +03:00
chmod +x " ${ workdir } " /" $configscript "
2019-09-24 09:56:39 +03:00
configure
else
echo "This port does not use a configure script. Skipping configure step."
fi
}
do_build( ) {
echo " Building $port ! "
2019-05-28 01:02:29 +03:00
build
2019-09-24 09:56:39 +03:00
}
do_install( ) {
echo " Installing $port ! "
2019-05-28 01:02:29 +03:00
install
2019-09-24 09:56:39 +03:00
addtodb " ${ 1 :- } "
}
do_clean( ) {
echo " Cleaning workdir and .out files in $port ! "
clean
}
do_clean_dist( ) {
echo " Cleaning dist in $port ! "
clean_dist
}
do_clean_all( ) {
echo " Cleaning all in $port ! "
clean_all
}
do_uninstall( ) {
echo " Uninstalling $port ! "
uninstall
}
do_all( ) {
do_fetch
do_configure
do_build
do_install " ${ 1 :- } "
}
2019-05-28 01:02:29 +03:00
2019-09-24 09:56:39 +03:00
if [ -z " ${ 1 :- } " ] ; then
do_all
2019-05-28 01:02:29 +03:00
else
2019-09-24 09:56:39 +03:00
case " $1 " in
fetch| configure| build| install| clean| clean_dist| clean_all| uninstall)
2019-11-03 12:05:02 +03:00
do_$1
2019-09-24 09:56:39 +03:00
; ;
--auto)
2019-11-03 12:05:02 +03:00
do_all $1
2019-09-24 09:56:39 +03:00
; ;
*)
>& 2 echo " I don't understand $1 ! Supported arguments: fetch, configure, build, install, clean, clean_dist, clean_all, uninstall. "
exit 1
; ;
esac
2019-05-28 01:02:29 +03:00
fi