sortix-mirror/build-aux/build-ports.sh

171 lines
5.5 KiB
Bash
Raw Normal View History

#!/bin/sh -e
2013-10-30 11:09:57 +00:00
make_dir_path_absolute() {
(cd "$1" && pwd)
}
has_command() {
which "$1" > /dev/null
}
# Detect if the environment isn't set up properly.
if [ -z "$HOST" ]; then
2013-10-30 11:09:57 +00:00
echo "$0: error: You need to set \$HOST" >&2
exit 1
elif [ -z "$SYSROOT" ]; then
echo "$0: error: You need to set \$SYSROOT" >&2
exit 1
elif [ -z "$SORTIX_PORTS_DIR" ]; then
echo "$0: error: You need to set \$SORTIX_PORTS_DIR" >&2
exit 1
elif [ -z "$SORTIX_REPOSITORY_DIR" ]; then
echo "$0: error: You need to set \$SORTIX_REPOSITORY_DIR" >&2
exit 1
elif ! [ -d "$SORTIX_PORTS_DIR" ]; then
echo "Warning: No ports directory found, third party software will not be built"
exit 0
elif ! has_command tix-collection ||
! has_command tix-build ||
! has_command tix-install; then
echo "$0: error: You need to have installed Tix locally to compile ports." >&2
exit 1
fi
# Add the platform triplet to the binary repository path.
SORTIX_REPOSITORY_DIR="$SORTIX_REPOSITORY_DIR/$HOST"
mkdir -p "$SORTIX_REPOSITORY_DIR"
# Make paths absolute for later use.
SYSROOT=$(make_dir_path_absolute "$SYSROOT")
SORTIX_PORTS_DIR=$(make_dir_path_absolute "$SORTIX_PORTS_DIR")
SORTIX_REPOSITORY_DIR=$(make_dir_path_absolute "$SORTIX_REPOSITORY_DIR")
# Decide the optimization options with which the ports will be built.
2016-03-07 17:43:33 +00:00
if [ -z "${OPTLEVEL+x}" ]; then OPTLEVEL="-Os -s"; fi
2013-10-30 11:09:57 +00:00
if [ -z "${PORTS_OPTLEVEL+x}" ]; then PORTS_OPTLEVEL="$OPTLEVEL"; fi
if [ -z "${PORTS_CFLAGS+x}" ]; then PORTS_CFLAGS="$PORTS_OPTLEVEL"; fi
if [ -z "${PORTS_CXXFLAGS+x}" ]; then PORTS_CXXFLAGS="$PORTS_OPTLEVEL"; fi
if [ -z "${CFLAGS+x}" ]; then CFLAGS="$PORTS_CFLAGS"; fi
if [ -z "${CXXFLAGS+x}" ]; then CXXFLAGS="$PORTS_CXXFLAGS"; fi
CFLAGS="$CFLAGS -Werror=format -Wno-error=format-contains-nul -Werror=implicit-function-declaration"
2015-01-27 20:45:43 +00:00
CXXFLAGS="$CXXFLAGS -Werror=format -Wno-error=format-contains-nul"
2013-10-30 11:09:57 +00:00
export CFLAGS
export CXXFLAGS
# Create the system root if absent.
mkdir -p "$SYSROOT"
# Create the binary package repository.
mkdir -p "$SORTIX_REPOSITORY_DIR"
# Initialize Tix package management in the system root if absent.
[ -e "$SYSROOT/tix/collection.conf" ] ||
2016-04-10 13:19:12 +00:00
tix-collection "$SYSROOT" create --platform=$HOST --prefix= --generation=2
2013-10-30 11:09:57 +00:00
# Detect all packages.
get_all_packages() {
for PACKAGE in $(ls "$SORTIX_PORTS_DIR"); do
! [ -f "$SORTIX_PORTS_DIR/$PACKAGE/tixbuildinfo" ] ||
echo $PACKAGE
done
}
# Detect which packages are available if not specified.
if [ -z "${PACKAGES+x}" ]; then
PACKAGES=$(get_all_packages | sort -R)
fi
# Simply stop if there is no packages available.
if [ -z "$PACKAGES" ]; then
exit 0
fi
# Detect the build-time dependencies for a package.
get_package_dependencies_raw() {(
PACKAGE_DIR=$(echo $1 | grep -Eo '^[^\.]*')
! [ -f "$SORTIX_PORTS_DIR/$PACKAGE_DIR/tixbuildinfo" ] ||
Add split packages and cross-bootstrapping support to tix-build(8). pkg.use-bootstrap can now be set to true to add a bootstrap phase to cross-builds. I.e. the package is built for the native platform and installed to a temporary location, which is in the PATH during the actual cross-compilation. This feature is useful for some misbehaving ports that can cross-compile, but require the exact same version of the software installed locally. The bootstrap build is controlled with the bootstrap.foo variables rather than the normal pkg.foo variables. pkg.source-package can now be set to the name of another package, whose source code is built using the current tixbuildinfo. This feature allows providing multiple packages using the same source code package. By default, the source code of the source package is assumed to be in ../${pkg.source-package}, but this can be overridden with the option --source-directory. pkg.alias-of can now be set to the name of another package to specify that this package is an alias of the other package, creating an empty binary package depending on the real package. pkg.subdir support has been fixed in the clean and post-install phases. pkg-config support has been improved and PKG_CONFIG is now set to $HOST-pkg-config and PKG_CONFIG_FOR_BUILD is set to pkg-config. tix-build has been refactored as needed and generally cleaned up. Error handling, such as on allocations, have been added in a lot of cases. The support for FOO_FOR_BUILD variables have been unified and simplified. Appending to PATH now correctly handles the empty PATH.
2016-12-26 12:59:51 +00:00
grep -E "^(pkg\.build-libraries|pkg\.alias-of)=.*" "$SORTIX_PORTS_DIR/$PACKAGE_DIR/tixbuildinfo" | \
sed 's/^[^=]*=//'
2013-10-30 11:09:57 +00:00
)}
# Detect the build-time dependencies for a package with missing optional
# dependencies removed.
get_package_dependencies() {(
PRINTED_ANY=false
for DEPENDENCY in $(get_package_dependencies_raw $1); do
if [ "$DEPENDENCY" != "${DEPENDENCY%\?}" ]; then
DEPENDENCY="${DEPENDENCY%\?}"
FOUND=false
for PACKAGE in $PACKAGES; do
if [ "$PACKAGE" = "$DEPENDENCY" ]; then
FOUND=true
break
fi
done
if ! $FOUND; then
continue
fi
fi
if $PRINTED_ANY; then printf ' '; fi
printf "%s" "$DEPENDENCY"
2013-10-30 11:09:57 +00:00
PRINTED_ANY=true
done
if $PRINTED_ANY; then echo; fi
)}
# Decide the order the packages are built in according to their dependencies.
DEPENDENCY_MAKEFILE=$(mktemp)
(for PACKAGE in $PACKAGES; do
echo "$PACKAGE: $(get_package_dependencies $PACKAGE)"
echo " @echo $PACKAGE"
done;
printf ".PHONY:"
2013-10-30 11:09:57 +00:00
for PACKAGE in $PACKAGES; do
printf " $PACKAGE"
2013-10-30 11:09:57 +00:00
done;
echo) > "$DEPENDENCY_MAKEFILE"
BUILD_LIST=$(unset MAKE;
unset MFLAGS;
unset MAKEFLAGS;
make -Bs -f "$DEPENDENCY_MAKEFILE" $PACKAGES)
rm -f "$DEPENDENCY_MAKEFILE"
PACKAGES="$BUILD_LIST"
2015-02-08 21:17:47 +00:00
# TODO: This adds another decompression and compression to the build time, this
# should be done as a tix post installation step. Also this might miss
# programs in unusual locations, so need a thorough search and strip.
strip_tix() {
DIR=$(mktemp -d)
tar -C "$DIR" -xf "$1"
$HOST-strip -d "$DIR/data/bin/"* 2>/dev/null || true
$HOST-strip -d "$DIR/data/lib/"* 2>/dev/null || true
$HOST-strip -d "$DIR/data/libexec"* 2>/dev/null || true
$HOST-strip -d "$DIR/data/libexec/git-core/"* 2>/dev/null || true
$HOST-strip -d "$DIR/data/sbin/"* 2>/dev/null || true
(cd "$DIR" && tar --numeric-owner --owner=0 --group=0 -cJf port.tar.tix.xz tix data)
2015-02-08 21:17:47 +00:00
cp "$DIR/port.tar.tix.xz" "$1"
rm -rf "$DIR"
}
2013-10-30 11:09:57 +00:00
# Build all the packages (if needed) and otherwise install them.
for PACKAGE in $PACKAGES; do
2015-02-08 21:17:47 +00:00
if ! [ -f "$SORTIX_REPOSITORY_DIR/$PACKAGE.tix.tar.xz" ]; then
Add split packages and cross-bootstrapping support to tix-build(8). pkg.use-bootstrap can now be set to true to add a bootstrap phase to cross-builds. I.e. the package is built for the native platform and installed to a temporary location, which is in the PATH during the actual cross-compilation. This feature is useful for some misbehaving ports that can cross-compile, but require the exact same version of the software installed locally. The bootstrap build is controlled with the bootstrap.foo variables rather than the normal pkg.foo variables. pkg.source-package can now be set to the name of another package, whose source code is built using the current tixbuildinfo. This feature allows providing multiple packages using the same source code package. By default, the source code of the source package is assumed to be in ../${pkg.source-package}, but this can be overridden with the option --source-directory. pkg.alias-of can now be set to the name of another package to specify that this package is an alias of the other package, creating an empty binary package depending on the real package. pkg.subdir support has been fixed in the clean and post-install phases. pkg-config support has been improved and PKG_CONFIG is now set to $HOST-pkg-config and PKG_CONFIG_FOR_BUILD is set to pkg-config. tix-build has been refactored as needed and generally cleaned up. Error handling, such as on allocations, have been added in a lot of cases. The support for FOO_FOR_BUILD variables have been unified and simplified. Appending to PATH now correctly handles the empty PATH.
2016-12-26 12:59:51 +00:00
SOURCE_PACKAGE=$(grep -E "^pkg.source-package=" "$SORTIX_PORTS_DIR/$PACKAGE/tixbuildinfo" | \
sed 's/^[^=]*=//')
2015-02-08 21:17:47 +00:00
tix-build \
--sysroot="$SYSROOT" \
--host=$HOST \
--prefix= \
--destination="$SORTIX_REPOSITORY_DIR" \
--generation=2 \
Add split packages and cross-bootstrapping support to tix-build(8). pkg.use-bootstrap can now be set to true to add a bootstrap phase to cross-builds. I.e. the package is built for the native platform and installed to a temporary location, which is in the PATH during the actual cross-compilation. This feature is useful for some misbehaving ports that can cross-compile, but require the exact same version of the software installed locally. The bootstrap build is controlled with the bootstrap.foo variables rather than the normal pkg.foo variables. pkg.source-package can now be set to the name of another package, whose source code is built using the current tixbuildinfo. This feature allows providing multiple packages using the same source code package. By default, the source code of the source package is assumed to be in ../${pkg.source-package}, but this can be overridden with the option --source-directory. pkg.alias-of can now be set to the name of another package to specify that this package is an alias of the other package, creating an empty binary package depending on the real package. pkg.subdir support has been fixed in the clean and post-install phases. pkg-config support has been improved and PKG_CONFIG is now set to $HOST-pkg-config and PKG_CONFIG_FOR_BUILD is set to pkg-config. tix-build has been refactored as needed and generally cleaned up. Error handling, such as on allocations, have been added in a lot of cases. The support for FOO_FOR_BUILD variables have been unified and simplified. Appending to PATH now correctly handles the empty PATH.
2016-12-26 12:59:51 +00:00
${SOURCE_PACKAGE:+--source-package "$SORTIX_PORTS_DIR/$SOURCE_PACKAGE"} \
2015-02-08 21:17:47 +00:00
"$SORTIX_PORTS_DIR/$PACKAGE"
strip_tix "$SORTIX_REPOSITORY_DIR/$PACKAGE.tix.tar.xz"
fi
2013-10-30 11:09:57 +00:00
tix-install \
--collection="$SYSROOT" \
--reinstall \
"$SORTIX_REPOSITORY_DIR/$PACKAGE.tix.tar.xz"
done