333 lines (309 with data), 10.3 kB
#!/bin/sh
#-
# Copyright (c) 2010, 2011 iXsystems, Inc., All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL Jordan Hubbard OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This file is heavily derived from both Sam Leffler's Avilia config,
# as well as the BSDRP project's config file. Neither of these have
# an explicit copyright/license statement, but are implicitly BSDL.
#
# Where cust_pkg() finds packages to install
NANO_PACKAGE_DIR=${NANO_SRC}/${NANO_TOOLS}/Pkg
NANO_DATADIR=${NANO_OBJ}/_.data
NANO_DATASIZE=40960
NANO_INIT_IMG2=0
unset MAKEOBJDIRPREFIX
# Python version needs to be known when we are picking port vs package. However,
# we've not yet created the make.conf.build file, nor setup things so that the nano
# vars for that are even defined. To cope, export this globally. We may be able
# to remove it from make.conf.build, but it doesn't hurt to have it there and
# may help.
export PYTHON_DEFAULT_VERSION=python2.7
# Defeat the python auto versioning goo that contaminates the build slightly
# with the host's python version rather than the version that's inside the
# port tree we're building. We do this by adding PYTHON_CMD=/bin/true to the
# make package-name invocation.
PKGNAME_HACK=PYTHON_CMD=/bin/true
# this to go into nanobsd.sh
NANO_PORTS=${NANO_PORTS:-/usr/ports}
clean_packages()
{
LOCAL_DIR=${NANO_WORLDDIR}/usr/local
pprint 2 "Clean and create world directory (${LOCAL_DIR})"
if [ -d "$LOCAL_DIR" ]; then
rm -Rf ${LOCAL_DIR} >/dev/null 2>&1
chflags -R noschg ${LOCAL_DIR}/ || :
rm -rf ${LOCAL_DIR}
fi
for f in bin etc lib libdata libexec sbin share; do
mkdir -p ${LOCAL_DIR}/$f
done
find ${LOCAL_DIR}/var/db/pkg/ -mindepth 1 -maxdepth 1 | xargs rm -Rf
}
customize_cmd clean_packages
cust_install_machine_files()
{
echo "cd ${NANO_CFG_BASE}/Files"
cd ${NANO_CFG_BASE}/Files
find . -print | grep -Ev '/(CVS|\.git|\.svn)' | cpio -dumpv ${NANO_WORLDDIR}
}
customize_cmd cust_install_files
customize_cmd cust_install_machine_files
buildenv()
{
cd ${NANO_SRC}
env \
DESTDIR=${NANO_WORLDDIR} \
${NANO_PMAKE} \
buildenv \
__MAKE_CONF=${NANO_MAKE_CONF_BUILD}
}
NANO_MAKEFS="makefs -B big \
-o bsize=4096,fsize=512,density=8192,optimization=space"
export NANO_MAKEFS
if [ "$DEBUG" = 1 ]; then
DEBUG_BUILD="
DEBUG_FLAGS= -g
"
else
DEBUG_INSTALL="
INSTALL_NODEBUG= t
"
fi
# NB: leave c++ enabled so devd can be built
CONF_BUILD="
#WITHOUT_ACPI=true
WITHOUT_ATM=true
WITHOUT_AUDIT=true
WITHOUT_BIND_DNSSEC=true
WITHOUT_BIND_ETC=true
WITHOUT_BIND_LIBS_LWRES=true
WITHOUT_BIND_NAMED=true
WITHOUT_BLUETOOTH=true
WITHOUT_CALENDAR=true
WITHOUT_CTM=true
WITHOUT_CVS=true
WITHOUT_DICT=true
WITHOUT_EXAMPLES=true
WITHOUT_FORTRAN=true
WITHOUT_FREEBSD_UPDATE=yes
WITHOUT_GAMES=true
WITHOUT_GCOV=true
WITHOUT_GPIB=true
WITHOUT_HTML=true
WITHOUT_I4B=true
WITHOUT_IPFILTER=true
WITHOUT_IPX=true
WITHOUT_LIB32=true
WITHOUT_LIBKSE=true
WITHOUT_LOCALES=true
WITHOUT_LPR=true
WITHOUT_MAN=true
WITHOUT_NDIS=true
WITHOUT_NIS=true
WITHOUT_NLS=true
WITHOUT_NS_CACHING=true
WITHOUT_OBJC=true
WITHOUT_PORTSNAP=true
WITHOUT_PPP=true
WITHOUT_PROFILE=true
WITHOUT_RCMDS=true
WITHOUT_SENDMAIL=true
# Knob needs to be fixed on systems that don't have the docs stuff
# preinstalled, e.g. 9.x bsdinstall images.
#WITHOUT_SHAREDOCS=true
WITHOUT_SSP=true
WITHOUT_SYSCONS=true
WITHOUT_SYSINSTALL=true
# Telnet's a useful tool to have on the remote box.
#WITHOUT_TELNET=true
WITHOUT_WIRELESS=true
WITHOUT_WPA_SUPPLICANT_EAPOL=true
PYTHON_DEFAULT_VERSION=python2.7
LOCAL_DIRS=${NANO_LOCAL_DIRS}
${DEBUG_BUILD}
"
CONF_INSTALL="$CONF_BUILD
NOPORTDOCS=t
NO_INSTALL_MANPAGES=t
# devel/apr sucks.
WITH_BDB_VER=46
${DEBUG_INSTALL}
"
# The following would help...
# WITHOUT_TOOLCHAIN=true can't build ports
# WITHOUT_INSTALLLIB=true libgcc.a
#
# from the build
# WITHOUT_INFO=true makeinfo
# WITHOUT_RCS=true
PKG_ONLY_MAKE_CONF="
WITHOUT_TOOLCHAIN=true
WITHOUT_INSTALLLIB=true
WITHOUT_INFO=true
WITHOUT_RCS=true
WITHOUT_SHAREDOCS=true
"
NANO_PACKAGE_ONLY=1
# Ports compiles need to be free of locale tainting.
for v in $(env | egrep '^(LANG|LC).*='); do
unset ${v%=*}
done
CR()
{
local newvers revision branch
newvers="$NANO_SRC/sys/conf/newvers.sh"
revision=$(grep -m 1 REVISION= $newvers | cut -f2 -d '"')
branch=$(grep -m 1 BRANCH= $newvers | cut -f2 -d '"')
# 1. Invoke a subshell so we don't pollute the build environment with
# these variables.
# 2. Use sane defaults to avoid polluting the build environment with
# system specific settings that might have been defined via
# /etc/make.conf (LOCALBASE), etc.
mount -t devfs none $NANO_WORLDDIR/dev
(set -e
env
export UNAME_m=$NANO_ARCH
export UNAME_p=$NANO_ARCH
export UNAME_r="$revision-$branch"
export UNAME_v="$(uname -v | sed -e "s/$(uname -p)/$UNAME_p/" -e "s/$(uname -r)/$UNAME_r/g")"
export OSVERSION=$(awk '/\#define.*__FreeBSD_version/ { print $3 }' "$NANO_SRC/sys/sys/param.h")
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
chroot ${NANO_WORLDDIR} /bin/sh -exc "$*")
umount $NANO_WORLDDIR/dev
}
# install a package from a pre-built binary
do_add_pkg ()
{
# Need to create ${NANO_OBJ}/ports in this add_pkg_${port} function
mkdir -p ${NANO_OBJ}/ports/distfiles
mkdir -p ${NANO_OBJ}/ports/packages
mkdir -p ${NANO_WORLDDIR}/usr/ports/packages/All
mkdir -p ${NANO_WORLDDIR}/usr/ports/distfiles
mount -t nullfs -o noatime ${NANO_OBJ}/ports/packages \
${NANO_WORLDDIR}/usr/ports/packages
mount -t nullfs -o noatime ${NANO_OBJ}/ports/distfiles \
${NANO_WORLDDIR}/usr/ports/distfiles
CR "cd /usr/ports/packages/All;pkg_add -F $1.tbz"
umount ${NANO_WORLDDIR}/usr/ports/distfiles
umount ${NANO_WORLDDIR}/usr/ports/packages
rmdir ${NANO_WORLDDIR}/usr/ports/packages/All
rmdir ${NANO_WORLDDIR}/usr/ports/packages
rmdir ${NANO_WORLDDIR}/usr/ports/distfiles
rmdir ${NANO_WORLDDIR}/usr/ports
}
# Build a port (with the side effect of creating a package)
do_add_port ()
{
local port_path
port_path=$1
shift
# Need to create ${NANO_OBJ}/ports in this add_port_${port} function
mkdir -p ${NANO_OBJ}/ports/distfiles
mkdir -p ${NANO_OBJ}/ports/packages
mkdir -p ${NANO_PORTS}/packages
mkdir -p ${NANO_PORTS}/distfiles
mkdir -p ${NANO_WORLDDIR}/usr/src
mkdir -p ${NANO_WORLDDIR}/usr/ports
mount -t nullfs -o noatime ${NANO_SRC} ${NANO_WORLDDIR}/usr/src
mount -t nullfs -o noatime ${NANO_PORTS} ${NANO_WORLDDIR}/usr/ports
mount -t nullfs -o noatime ${NANO_OBJ}/ports/packages \
${NANO_WORLDDIR}/usr/ports/packages
mount -t nullfs -o noatime ${NANO_OBJ}/ports/distfiles \
${NANO_WORLDDIR}/usr/ports/distfiles
mkdir -p ${NANO_WORLDDIR}/usr/workdir
cp /etc/resolv.conf ${NANO_WORLDDIR}/etc/resolv.conf
# Improvement: Don't know why package-recursive don't works here
CR "env \
TARGET=${NANO_ARCH} \
TARGET_ARCH=${NANO_ARCH} \
make \
__MAKE_CONF=${NANO_MAKE_CONF_BUILD} \
SRC_BASE=/usr/src \
WRKDIRPREFIX=/usr/workdir -C /usr/ports/$port_path \
clean package BATCH=yes -DUSE_PACKAGE_DEPENDS \
$* clean -DFORCE_PACKAGE -DFORCE_PKG_REGISTER"
rm ${NANO_WORLDDIR}/etc/resolv.conf
rm -rf ${NANO_WORLDDIR}/usr/obj
rm -rf ${NANO_WORLDDIR}/usr/workdir
umount ${NANO_WORLDDIR}/usr/ports/packages
umount ${NANO_WORLDDIR}/usr/ports/distfiles
umount ${NANO_WORLDDIR}/usr/ports
umount ${NANO_WORLDDIR}/usr/src
}
# Need to check if this function works with cross-compiling architecture!!!!
# Recursive complex function: Generate one function for each ports
add_port ()
{
local _add_pkg
local port_path=$1
local port=`echo $1 | sed -e 's/\//_/'`
shift
# Check if package already exist
# Need to:
# 1. check ARCH of this package!
# 2. Add a trap
cd ${NANO_PORTS}/${port_path}
# __MAKE_CONF -> ${NANO_MAKE_CONF_BUILD} -- can't plug this in because of a sourcing chicken and egg problem.
set +e
PKG_NAME=`make ${PKGNAME_HACK} PORTSDIR=${NANO_PORTS} __MAKE_CONF=${NANO_OBJ}/make.conf.install OPTIONSFILE=/nonexistent package-name $*`
if [ $? -ne 0 ]; then
echo "failed to determine the package name for $port_path"
exit 1
fi
set -e
_add_pkg=false
if $do_world && $do_clean; then
# HACK: make do_build.sh -ff work properly instead of having
# do_add_pkg fall flat on its face when it tries to add the
# missing package.
:
elif [ -f ${NANO_OBJ}/ports/packages/All/${PKG_NAME}.tbz ]; then
# Pkg file found: Generate add_pkg_NAME function
_add_pkg=true
fi
if $_add_pkg; then
eval "
add_pkg_${port} () {
do_add_pkg ${PKG_NAME}
}
customize_cmd add_pkg_${port}
"
else
echo "Package is not yet built: $port"
eval "
add_port_${port} () {
do_add_port ${port_path} $*
}
customize_cmd add_port_${port}
"
NANO_PACKAGE_ONLY=0
fi
}
__a=`mount | grep ${NANO_OBJ}/ | awk '{print length($3), $3;}' | sort -rn | awk '{$1=""; print;}'`
if [ -n "$__a" ]; then
echo "unmounting $__a"
umount $__a
fi
NANO_BOOTLOADER="boot/boot0"