This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
lsts_glued/mkpackage.bash

356 lines
9.1 KiB
Bash
Raw Normal View History

2013-07-13 17:19:22 +01:00
#! /bin/bash
2013-08-19 14:31:11 +01:00
###########################################################################
# GLUED: GNU/Linux Uniform Environment Distribution #
2014-02-02 04:04:03 +00:00
# Copyright (C) 2007-2014 Universidade do Porto - Faculdade de Engenharia #
2013-08-19 14:31:11 +01:00
# Laboratório de Sistemas e Tecnologia Subaquática (LSTS) #
###########################################################################
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or (at #
# your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
# General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA #
# 02110-1301 USA. #
###########################################################################
2014-02-02 04:04:03 +00:00
# Author: Ricardo Martins #
###########################################################################
2013-07-13 17:19:22 +01:00
source "functions.bash"
download_tool()
{
wget -c "$1" -O "$2"
if [ $? -eq 0 ]; then
return 0
fi
curl -C - "$1" -o "$2"
if [ $? -eq 0 ]; then
return 0
fi
return 1
}
md5sum_tool()
{
sum="$(md5sum < "$cfg_dir_downloads/$file" 2> /dev/null | cut -f1 -d' ')"
if [ -n "$sum" ]; then
echo "$sum"
fi
sum="$(md5 < "$cfg_dir_downloads/$file" 2> /dev/null)"
if [ -n "$sum" ]; then
echo "$sum"
fi
}
download()
{
n=0; while [ -n "${url[$n]}" ]; do
u="${url[$n]}"
s="${md5[$n]}"
file=$(basename "$u")
if [ -f "$cfg_dir_downloads/$file" ]; then
md5=$(md5sum_tool "$cfg_dir_downloads/$file")
if [ "$s" = "$md5" ]; then
let n++
continue
fi
fi
download_tool "$u" "$cfg_dir_downloads/$file"
if [ $? -ne 0 ]; then
echo "ERROR: download failed"
exit 1
fi
md5="$(md5sum_tool "$cfg_dir_downloads/$file")"
if [ "$s" != "$md5" ]; then
echo "ERROR: MD5 checksum mismatch: $s vs $md5"
return 1
fi
let n++
done
n=0; while [ -n "${svn[$n]}" ]; do
u="$(echo ${svn[$n]} | cut -f1 -d'#')"
r="$(echo ${svn[$n]} | cut -f2 -d'#')"
dir=$(basename $u)
svn export -r "$r" "$u" "$cfg_dir_downloads/$dir"
let n++
done
n=0; while [ -n "${git[$n]}" ]; do
u="$(echo ${git[$n]} | cut -f1 -d'#')"
b="$(echo ${git[$n]} | cut -f2 -d'#')"
dir=$(basename $u)
des="${cfg_dir_builds}/$PKG/$dir-git"
if [[ "$u" == git* ]]; then
git clone --verbose --branch "$b" "$u" "$des"
else
git clone --verbose "$u" "$des"
fi
let n++
done
2013-07-13 17:19:22 +01:00
return 0
}
post_unpack()
{
echo "using dummy 'post_unpack' hook."
}
unpack()
{
n=0; while [ -n "${url[$n]}" ]; do
u="${url[$n]}"
s="${md5[$n]}"
file=$(basename "$u")
case $file in
*tar*|*tgz|*tbz*)
tar -C "$cfg_dir_builds/$PKG" -x -f "$cfg_dir_downloads/$file" || exit 1
;;
*zip)
unzip "$cfg_dir_downloads/$file" -d "$cfg_dir_builds/$PKG" || exit 1
;;
*)
echo "File $file can't be handled."
;;
esac
let n++
done
dir_gnu_cfg="$cfg_dir_toolchain/share/gnu-config"
if [ "$cfg_dir_cfg/config.sub" ]; then
find "$cfg_dir_builds/$PKG" -name config.sub -exec install -v -m 0755 "$dir_gnu_cfg/config.sub" '{}' \;
fi
if [ "$cfg_dir_cfg/config.guess" ]; then
find "$cfg_dir_builds/$PKG" -name config.guess -exec install -v -m 0755 "$dir_gnu_cfg/config.guess" '{}' \;
fi
2013-07-13 17:19:22 +01:00
return 0
}
refresh()
{
echo "Using dummy 'refresh' rule."
}
configure()
{
echo "Using dummy 'configure' rule."
}
build()
{
echo "Using dummy 'build' rule."
}
host_install()
{
echo "Using dummy 'host_install' rule."
}
target_install()
{
echo "Using dummy 'target_install' rule."
}
postconfigure()
{
echo "Using dummy 'postconfigure' rule."
}
perform_clean()
{
2014-02-02 09:43:32 +00:00
rm -rf "$cfg_dir_builds/$PKG/$pkg_var"
2013-07-13 17:19:22 +01:00
}
perform_all()
{
start="$(date +%s)"
2014-02-02 09:43:32 +00:00
nfo1 "$PKG / $pkg_var"
2013-07-13 17:19:22 +01:00
2014-02-02 09:43:32 +00:00
export pkg_build_dir="$cfg_dir_builds/$PKG/$pkg_var"
2013-07-13 17:19:22 +01:00
for rule in download unpack post_unpack refresh configure build host_install target_install postconfigure; do
case $rule in
download | unpack | post_unpack)
marker="$cfg_dir_builds/$PKG/.$rule"
;;
*)
2014-02-02 09:43:32 +00:00
marker="$cfg_dir_builds/$PKG/$pkg_var/.$rule"
2013-07-13 17:19:22 +01:00
;;
esac
2014-02-02 09:43:32 +00:00
mkdir -p "$cfg_dir_builds/$PKG/$pkg_var" && cd "$cfg_dir_builds/$PKG/$pkg_var"
2013-07-13 17:19:22 +01:00
if [ -z "$build_dir" ]; then
build_dir="$PKG-$version"
fi
if [ -n "$build_dir" ]; then
mkdir -p "$cfg_dir_builds/$PKG/$build_dir" && cd "$cfg_dir_builds/$PKG/$build_dir"
fi
if [ -n "$build_always" ] || [ "$rule" = 'refresh' ]; then
nfo2 "$rule"
2014-02-02 09:43:32 +00:00
$rule > "$cfg_dir_builds/$PKG/$pkg_var/$rule.log" 2>&1
2013-07-13 17:19:22 +01:00
else
if ! [ -f "$marker" ]; then
nfo2 "$rule"
2014-02-02 09:43:32 +00:00
$rule > "$cfg_dir_builds/$PKG/$pkg_var/$rule.log" 2>&1
2013-07-13 17:19:22 +01:00
if [ $? -eq 0 ]; then
touch "$marker"
else
2014-02-02 09:43:32 +00:00
err "failed to execute rule $rule of $PKG / $pkg_var"
tail "$cfg_dir_builds/$PKG/$pkg_var/$rule.log"
2013-07-13 17:19:22 +01:00
exit 1
fi
fi
fi
done
elapsed=$[ $(date +%s)-$start ]
ok "completed in ${elapsed}s"
2014-02-02 09:43:32 +00:00
touch "$cfg_dir_builds/$PKG/$pkg_var/.complete"
2013-07-13 17:19:22 +01:00
}
# Check shell.
if [ -z "$BASH_VERSION" ]; then
echo "ERROR: you must use bash to run this script."
exit 1
fi
# Check command line arguments.
if [ $# -lt 2 ]; then
echo "Usage: $0 <config> <package> [all|clean|download|unpack|configure|build|install]"
exit 1
fi
# Read system configuration file.
if ! [ -f "$1" ]; then
echo "ERROR: invalid configuration file '$1'"
exit 1
fi
# Read system configuration file.
source "$1"
# Unset variables that may be a problem to this script.
unset LD_LIBRARY_PATH
unset CFLAGS
unset LDFLAGS
unset CXXFLAGS
export PKG_CONFIG_PATH="$cfg_dir_toolchain_sysroot/usr/lib/pkgconfig"
export LD_LIBRARY_PATH="$cfg_dir_toolchain/lib"
# Sanitize PATH.
paths="$(echo $PATH | sed 's%/\{1,\}%/%g')"
clean_path=""
while [ -n "$paths" ]; do
path=$(echo "$paths" | cut -f1 -d:)
paths=$(echo "$paths" | cut -f2- -d:)
if [ "$path" = "$paths" ]; then
paths=""
fi
if [ "$path" = "" ] || [ "$path" = "." ] || [ "$path" = "./" ]; then
continue
fi
if [ "$path" = "$cfg_dir_toolchain/$cfg_target_canonical/bin" ]; then
continue
fi
if [ "$path" = "$cfg_sys_family/toolchain/$cfg_target_canonical/bin" ]; then
continue
fi
clean_path="$clean_path:$path"
done
export PATH="$cfg_dir_toolchain/bin$clean_path"
pkg="$(echo $2 | cut -f1 -d'/')"
pkg_var="$(echo $2 | cut -f2 -d'/')"
if [ "$pkg_var" = "$pkg" ]; then
pkg_var='default'
fi
export PKG="$pkg"
2014-02-02 09:43:32 +00:00
export pkg_var="$pkg_var"
export pkg_common="$cfg_dir_packages/$PKG/common.bash"
2013-07-13 17:19:22 +01:00
if ! [ -d "$cfg_dir_packages/$PKG" ]; then
echo "ERROR: package '$PKG' does not exist."
exit 1
fi
2014-02-02 09:43:32 +00:00
if ! [ -f "$cfg_dir_packages/$PKG/$pkg_var.bash" ]; then
echo "ERROR: variant '$pkg_var' of package '$PKG' does not exist."
2013-07-13 17:19:22 +01:00
exit 1
fi
if [ -z "$3" ]; then
rule="all"
else
rule="$3"
fi
mkdir -p "$cfg_dir_downloads" "$cfg_dir_rootfs" "$cfg_dir_toolchain" "$cfg_dir_builds/$PKG"
export cfg_package_spec_dir="$cfg_dir_base/packages/$PKG"
2014-02-02 09:43:32 +00:00
. "$cfg_dir_packages/$PKG/$pkg_var.bash"
2013-07-13 17:19:22 +01:00
# Postconfiguration:
if [ -e "$cfg_dir_postconfiguration/$PKG/$cfg_sys_name.bash" ]; then
# echo "ERROR: postconfiguration exists '$PKG'."
# echo "$cfg_dir_postconfiguration/$PKG/$cfg_sys_name.bash"
# exit 1
. "$cfg_dir_postconfiguration/$PKG/$cfg_sys_name.bash"
fi
# Handle dependencies.
n=0; while [ -n "${requires[$n]}" ]; do
req="${requires[$n]}"
let n++
if [ -z "$req" ]; then
break
fi
if [ -f "$cfg_dir_builds/$req/.complete" ]; then
continue
fi
"$0" "$1" "$req"
if [ $? -ne 0 ]; then
2014-02-02 09:43:32 +00:00
err "failed to build dependency for package $PKG / $pkg_var"
2013-07-13 17:19:22 +01:00
exit 1
fi
done
perform_"$rule"