Added xbps-src and its associated code again.

It's better to keep it outside of XBPS.

--HG--
extra : convert_revision : 34f9c316585b972158d6ee55492c02c9bc5d3fcd
This commit is contained in:
Juan RP 2009-10-18 11:17:26 +02:00
parent 7fbc4b9545
commit 745192ef37
26 changed files with 3867 additions and 0 deletions

17
Makefile Normal file
View file

@ -0,0 +1,17 @@
# Toplevel Makefile
#
.PHONY: all
all:
$(MAKE) -C xbps-src
.PHONY: install
install:
$(MAKE) -C xbps-src install
.PHONY: uninstall
uninstall:
$(MAKE) -C xbps-src uninstall
.PHONY: clean
clean:
$(MAKE) -C xbps-src clean

115
README Normal file
View file

@ -0,0 +1,115 @@
------------------------------------------------------------------------------
REQUIREMENTS
------------------------------------------------------------------------------
The following software is required in the host system to build XBPS
binary packages:
* GNU GCC C++
* GNU Make
* GNU Bison
* fakeroot
* wget OR curl OR fetch (statically linked or no additional deps)
* perl
* sudo
Please note that wget/curl or any program used to fetch distfiles,
must be statically linked or if shared, it should be only linked to libc.
This is required to not depend in external libs while building packages
in the chroot.
Run "make install clean" at the top level directory, xbps-src and
its shell utilities will be installed into /usr/local by default (can be
changed by setting PREFIX and DESTDIR).
------------------------------------------------------------------------------
HOW TO BUILD/HANDLE PACKAGES FROM SOURCE
------------------------------------------------------------------------------
Before using xbps-src, some required utilities need to be built and installed
into $(PREFIX); by default they are installed into /usr/local.
You can do this by issuing "make" and "make install" as root in the top
level directory.
If configuration file is not specified from the command line with the
-c flag, it will first try to use the default location at
/usr/local/etc/xbps-src.conf (or the installation prefix that was specified
to the make(1) command), and as last resort in the etc directory of the
current directory.
To avoid problems with libtool and configure scripts finding stuff that is
available in the host system, almost all packages must be built inside of a
chroot. So the first thing would be to create the binary packages with:
$ xbps-src install xbps-base-chroot
This will build all required packages via fakeroot in masterdir, therefore you
can run it as normal user. Next commands will require super-user privileges
and all package handling will be done within the chroot. I believe it's the
most easier and faster way to handle clean dependencies; another reason would
be that xbps packages are meant to be used in a system and not just for
ordinary users. So once all packages are built, you can create and enter
to the chroot with:
$ sudo xbps-src chroot
Press Control + D to exit from the chroot. The following targets will require
to be done in the chroot:
build, configure, install, install-destdir, remove, stow and unstow.
Now let's explain some more about the targets that you can use. To start
installing packages you should use the install target:
$ sudo xbps-src install glib
If the package is properly installed, it will be "stowned" automatically.
``stowned'' means that this package is available in the master directory,
on which xpbs has copied all files from DESTDIR/<pkgname>.
To remove a currently installed (and stowned) package, you can use:
$ sudo xbps-src remove glib
Please note that when you remove it, the package will also be removed
from XBPS_DESTDIR and previously "unstowned".
To stow an already installed package (from XBPS_DESTDIR/<pkgname>):
$ sudo xbps-src stow glib
and to unstow an already installed (stowned) package:
$ sudo xbps-src unstow glib
You can also print some stuff about any template build file, e.g:
$ xbps-src info glib
To list installed (stowned) packages, use this:
$ xbps-src list
To only extract the distfiles, without configuring/building/installing:
$ xbps-src extract foo
To not remove the build directory after successful installation:
$ sudo xbps-src -C install blah
To only fetch the distfile:
$ xbps-src fetch blah
To only install the package, _without_ stowning it into the master directory:
$ sudo xbps-src install-destdir blob
To list files installed by a package, note that package must be installed
into destination directory first:
$ xbps-src listfiles blob
------------------------------------------------------------------------------
Juan Romero Pardines <xtraeme@gmail.com>

36
xbps-src/Makefile Normal file
View file

@ -0,0 +1,36 @@
include vars.mk
BIN = xbps-src
SUBDIRS = etc shutils
.PHONY: all
all:
sed -e "s|@@XBPS_INSTALL_PREFIX@@|$(PREFIX)|g" \
-e "s|@@XBPS_INSTALL_ETCDIR@@|$(ETCDIR)|g" \
-e "s|@@XBPS_INSTALL_SHAREDIR@@|$(SHAREDIR)|g" \
$(BIN).sh.in > $(BIN)
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir; \
done
.PHONY: clean
clean:
-rm -f $(BIN)
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir clean; \
done
.PHONY: install
install: all
install -d $(SBINDIR)
install -m 755 $(BIN) $(SBINDIR)
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir install; \
done
.PHONY: uninstall
uninstall:
-rm -f $(SBINDIR)/$(BIN)
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir uninstall; \
done

25
xbps-src/etc/Makefile Normal file
View file

@ -0,0 +1,25 @@
include ../vars.mk
CONF_FILE = xbps-src.conf
.PHONY: all
all:
sed -e "s|@@XBPS_INSTALL_PREFIX@@|$(PREFIX)|g" \
$(CONF_FILE).in > $(CONF_FILE)
.PHONY: clean
clean:
-rm -f $(CONF_FILE)
.PHONY: install
install:
if [ ! -d $(DESTDIR)$(ETCDIR) ]; then \
install -d $(DESTDIR)$(ETCDIR); \
fi
if [ ! -f $(DESTDIR)$(ETCDIR)/$(CONF_FILE) ]; then \
install -m 644 $(CONF_FILE) $(DESTDIR)$(ETCDIR); \
fi
.PHONY: uninstall
uninstall:

View file

@ -0,0 +1,64 @@
#
# Configuration file for xbps-src.
#
#
# Directory where XBPS has been installed. By default /usr/local.
#
XBPS_INSTALLDIR=@@XBPS_INSTALL_PREFIX@@
#
# Global directory where the xbps distribution files are stored.
# Templates, patches and helper files should all be in that directory.
#
XBPS_DISTRIBUTIONDIR=$HOME/xbps
#
# Master directory: this is where all symlinks will be
# created pointing at packages installed in XBPS_DESTDIR.
#
XBPS_MASTERDIR=$XBPS_DISTRIBUTIONDIR/masterdir
#
# Destination directory: this is where all package files will be
# installed.
#
XBPS_DESTDIR=$XBPS_DISTRIBUTIONDIR/destdir
#
# Binary packages directory: this is where the binary packages will
# be created to.
#
XBPS_PACKAGESDIR=$XBPS_DISTRIBUTIONDIR/packages
#
# Directory where source files will be extracted to.
#
XBPS_BUILDDIR=$XBPS_DISTRIBUTIONDIR/builddir
#
# Directory where source distribution files are stored.
#
XBPS_SRCDISTDIR=$XBPS_DISTRIBUTIONDIR/srcdistdir
#
# Compilation flags for cc and c++.
#
XBPS_CFLAGS="-O2 -pipe"
XBPS_CXXFLAGS="$XBPS_CFLAGS"
#
# Number of jobs when running GNU or BSD make style packages.
#
#XBPS_MAKEJOBS=4
#
# Fetch command to download files.
#
XBPS_FETCH_CMD=wget
#
# Cross compilation stuff.
#
#XBPS_CROSS_TARGET=i686-pc-linux-gnu
#XBPS_CROSS_DIR=/storage/mktoolchain/$XBPS_CROSS_TARGET

21
xbps-src/shutils/Makefile Normal file
View file

@ -0,0 +1,21 @@
include ../vars.mk
.PHONY: all
all:
.PHONY: clean
clean:
.PHONY: install
install:
if [ ! -d $(DESTDIR)$(SHAREDIR) ]; then \
install -d $(DESTDIR)$(SHAREDIR); \
fi
for f in *.sh; do \
install -m 755 $$f $(DESTDIR)$(SHAREDIR); \
done
.PHONY: uninstall
uninstall:
-rm -rf $(DESTDIR)$(SHAREDIR)

View file

@ -0,0 +1,86 @@
#-
# Copyright (c) 2008-2009 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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.
#-
#
# Runs the "build" phase for a pkg. This builds the binaries and other
# related stuff.
#
build_src_phase()
{
local pkg="$pkgname-$version" pkgparam="$1" f
[ -z $pkgparam ] && [ -z $pkgname -o -z $version ] && return 1
#
# Skip this phase for: meta-template, only-install, custom-install
# and python-module style builds.
#
[ "$build_style" = "meta-template" -o \
"$build_style" = "only-install" -o \
"$build_style" = "custom-install" -o \
"$build_style" = "python-module" ] && return 0
[ ! -d $wrksrc ] && msg_error "unexistent build directory [$wrksrc]"
cd $wrksrc || exit 1
[ -n "$revision" ] && pkg="${pkg}_${revision}"
# cross compilation vars.
if [ -n "$cross_compiler" ]; then
. $XBPS_SHUTILSDIR/cross-compilation.sh
cross_compile_setvars
fi
[ -z "$make_cmd" ] && make_cmd=/usr/bin/make
# Run pre_build func.
run_func pre_build || msg_error "pre_build stage failed!"
[ -n "$XBPS_MAKEJOBS" -a -z "$disable_parallel_build" ] && \
makejobs="-j$XBPS_MAKEJOBS"
. $XBPS_SHUTILSDIR/buildvars_funcs.sh
set_build_vars
msg_normal "Running build phase for $pkg."
#
# Build package via make.
#
${make_cmd} ${makejobs} ${make_build_args} ${make_build_target}
[ $? -ne 0 ] && msg_error "building $pkg (build phase)."
# Run post_build func.
run_func post_build || msg_error "post_build stage failed!"
unset makejobs
# unset cross compiler vars.
[ -n "$cross_compiler" ] && cross_compile_unsetvars
unset_build_vars
touch -f $XBPS_BUILD_DONE
}

View file

@ -0,0 +1,194 @@
#-
# Copyright (c) 2008-2009 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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.
#-
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
#
# Recursive function that installs all direct and indirect
# dependencies of a package.
#
install_pkg_deps()
{
local curpkg="$1"
local curpkgname=$(xbps-pkgdb getpkgname $1)
local saved_prevpkg=$(xbps-pkgdb getpkgname $2)
local j jver jname reqver
[ -z "$curpkg" ] && return 1
if [ -n "$prev_pkg" ]; then
curpkg=$prev_pkg
curpkgname=$(xbps-pkgdb getpkgname ${curpkg})
fi
msg_normal "Installing $saved_prevpkg dependency: $curpkgname."
run_template $curpkgname
check_build_depends_pkg
if [ $? -eq 0 ]; then
msg_normal "Dependency $curpkgname requires:"
for j in ${build_depends}; do
jname=$(xbps-pkgdb getpkgname ${j})
jver=$($XBPS_REGPKGDB_CMD version ${jname})
reqver=$(xbps-pkgdb getpkgversion ${j})
check_installed_pkg $j
if [ $? -eq 0 ]; then
echo " $jname >= $reqver: found $jname-$jver."
else
echo " $jname >= $reqver: not found."
fi
done
fi
for j in ${build_depends}; do
#
# Check if dep already installed.
#
check_installed_pkg $j
[ $? -eq 0 ] && continue
[ -n "$prev_pkg" ] && unset prev_pkg
#
# Iterate again, this will check if there are more
# required deps for current pkg.
#
install_pkg_deps $j $curpkg
prev_pkg="$j"
done
install_pkg $curpkgname
[ -n "$prev_pkg" ] && unset prev_pkg
}
#
# Installs all dependencies required by a package.
#
install_dependencies_pkg()
{
local pkg="$1"
local lpkgname=$(xbps-pkgdb getpkgname ${pkg})
local i ipkgname iversion reqvers notinstalled_deps lver
[ -z "$pkg" ] && return 1
doing_deps=true
if [ -n "$revision" ]; then
lver="${version}_${revision}"
else
lver="${version}"
fi
msg_normal "Required build dependencies for $pkgname-$lver... "
for i in ${build_depends}; do
ipkgname=$(xbps-pkgdb getpkgname ${i})
iversion=$($XBPS_REGPKGDB_CMD version $ipkgname)
reqvers=$(xbps-pkgdb getpkgversion ${i})
check_installed_pkg $i
if [ $? -eq 0 ]; then
echo " $ipkgname >= $reqvers: found $ipkgname-$iversion."
continue
else
echo " $ipkgname >= $reqvers: not found."
notinstalled_deps="$notinstalled_deps $i"
fi
done
[ -z "$notinstalled_deps" ] && return 0
for i in ${notinstalled_deps}; do
check_installed_pkg $i
[ $? -eq 0 ] && continue
ipkgname=$(xbps-pkgdb getpkgname ${i})
run_template $ipkgname
check_build_depends_pkg
if [ $? -eq 1 ]; then
msg_normal "Installing $lpkgname dependency: $ipkgname."
install_pkg $ipkgname
else
install_pkg_deps $i $pkg
fi
done
}
install_builddeps_required_pkg()
{
local pkg="$1"
local pkgname=$(xbps-pkgdb getpkgname ${pkg})
local dep depname
[ -z "$pkg" ] && return 1
run_template $pkgname
for dep in ${build_depends}; do
check_installed_pkg $dep
if [ $? -ne 0 ]; then
msg_normal "Installing $pkgname dependency: $dep."
depname=$(xbps-pkgdb getpkgname ${dep})
install_pkg $depname
fi
done
}
#
# Checks the registered pkgs db file and returns 0 if a pkg that satisfies
# the minimal required version is there, or 1 otherwise.
#
check_installed_pkg()
{
local pkg="$1"
local pkgname reqver iver
[ -z "$pkg" ] && return 2
pkgname=$(xbps-pkgdb getpkgname $pkg)
reqver=$(xbps-pkgdb getpkgversion $pkg)
run_template $pkgname
iver="$($XBPS_REGPKGDB_CMD version $pkgname)"
if [ -n "$iver" ]; then
xbps-cmpver $pkgname-$iver $pkgname-$reqver
[ $? -eq 0 -o $? -eq 1 ] && return 0
fi
return 1
}
#
# Checks the build depends db file and returns 0 if pkg has dependencies,
# otherwise returns 1.
#
check_build_depends_pkg()
{
[ -z "$pkgname" ] && return 2
if [ -n "$build_depends" ]; then
return 0
else
return 1
fi
}

View file

@ -0,0 +1,58 @@
#-
# Copyright (c) 2008 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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.
#-
#
# Functions to set some env vars required to build the packages
# required by the xbps-base-chroot package.
#
set_build_vars()
{
if [ -z "$in_chroot" ]; then
SAVE_LDLIBPATH=$LD_LIBRARY_PATH
LD_LIBRARY_PATH="$XBPS_MASTERDIR/usr/lib"
PKG_CONFIG="$XBPS_MASTERDIR/usr/bin/pkg-config"
PKG_CONFIG_LIBDIR="$XBPS_MASTERDIR/usr/lib/pkgconfig"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
export PKG_CONFIG_LIBDIR="$PKG_CONFIG_LIBDIR"
export PKG_CONFIG="$PKG_CONFIG"
fi
LDFLAGS="-L$XBPS_MASTERDIR/usr/lib"
CFLAGS="$CFLAGS $XBPS_CFLAGS"
CXXFLAGS="$CXXFLAGS $XBPS_CXXFLAGS"
CPPFLAGS="-I$XBPS_MASTERDIR/usr/include $CPPFLAGS"
export CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS"
export CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS"
}
unset_build_vars()
{
if [ -z "$in_chroot" ]; then
unset PKG_CONFIG LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$SAVE_LDLIBPATH
fi
unset LDFLAGS CFLAGS CXXFLAGS CPPFLAGS
}

300
xbps-src/shutils/chroot.sh Normal file
View file

@ -0,0 +1,300 @@
#-
# Copyright (c) 2008-2009 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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.
#-
#
# Script to install packages into a sandbox in masterdir.
# Actually this needs the xbps-base-chroot package installed.
#
# Umount stuff if SIGINT or SIGQUIT was caught
trap umount_chroot_fs INT QUIT
prepare_chroot()
{
local f=
# Create some required files.
touch $XBPS_MASTERDIR/etc/mtab
for f in run/utmp log/btmp log/lastlog log/wtmp; do
touch -f $XBPS_MASTERDIR/var/$f
done
for f in run/utmp log/lastlog; do
chmod 644 $XBPS_MASTERDIR/var/$f
done
cat > $XBPS_MASTERDIR/etc/passwd <<_EOF
root:x:0:0:root:/root:/bin/bash
nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
_EOF
# Default group list as specified by LFS.
cat > $XBPS_MASTERDIR/etc/group <<_EOF
root:x:0:
bin:x:1:
sys:x:2:
kmem:x:3:
tty:x:4:
tape:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
uucp:x:10:
audio:x:11:
video:x:12:
utmp:x:13:
usb:x:14:
cdrom:x:15:
mail:x:34:
nogroup:x:99:
users:x:1000:
_EOF
# Default file as in Ubuntu.
cat > $XBPS_MASTERDIR/etc/hosts <<_EOF
127.0.0.1 xbps localhost.localdomain localhost
127.0.1.1 xbps
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
_EOF
# Use OpenDNS servers.
cat > $XBPS_MASTERDIR/etc/resolv.conf <<_EOF
nameserver 208.67.222.222
nameserver 208.67.220.220
_EOF
touch $XBPS_MASTERDIR/.xbps_perms_done
}
rebuild_ldso_cache()
{
echo -n "==> Rebuilding chroot's dynamic linker cache..."
chroot $XBPS_MASTERDIR /sbin/ldconfig -c /etc/ld.so.conf
chroot $XBPS_MASTERDIR /sbin/ldconfig -C /etc/ld.so.cache
echo " done."
}
install_xbps_utils()
{
local needed fetch_cmd
local xbps_prefix=$XBPS_MASTERDIR/usr/local
for f in bin cmpver digest pkgdb; do
if [ ! -x $xbps_prefix/sbin/xbps-${f} ]; then
needed=yes
fi
done
if [ -n "$needed" ]; then
cd ${XBPS_MASTERDIR}/bin && ln -s dash sh
echo "=> Installing the required XBPS utils."
chroot $XBPS_MASTERDIR sh -c \
"echo /usr/local/lib > /etc/ld.so.conf"
fetch_cmd="$(which $XBPS_FETCH_CMD 2>/dev/null)"
if [ -z "$fetch_cmd" ]; then
echo "Unexistent XBPS_FETCH_CMD specified!"
exit 1
fi
cp -f $fetch_cmd $xbps_prefix/sbin
for f in bin cmpver digest pkgdb repo; do
cp -f $XBPS_INSTALLDIR/sbin/xbps-$f.static \
$xbps_prefix/sbin/xbps-$f
done
cp -f $XBPS_INSTALLDIR/sbin/xbps-src $xbps_prefix/sbin
if [ -z $XBPS_INSTALLDIR ]; then
installdir=/usr/share/xbps
else
installdir=$XBPS_INSTALLDIR/share/xbps
fi
cp -a $installdir $xbps_prefix/share
rebuild_ldso_cache
fi
}
xbps_chroot_handler()
{
local action="$1"
local pkg="$2"
local only_destdir="$3"
[ -z "$action" -o -z "$pkg" ] && return 1
[ "$action" != "configure" -a "$action" != "build" -a \
"$action" != "install" -a "$action" != "chroot" ] && return 1
mount_chroot_fs
install_xbps_utils
if [ ! -f $XBPS_MASTERDIR/.xbps_perms_done ]; then
echo -n "==> Preparing chroot on $XBPS_MASTERDIR... "
prepare_chroot
echo "done."
fi
if [ "$action" = "chroot" ]; then
env in_chroot=yes LANG=C chroot $XBPS_MASTERDIR /bin/bash
else
[ -n "$only_destdir" ] && \
local lenv="install_destdir_target=yes"
env in_chroot=yes LANG=C ${lenv} chroot $XBPS_MASTERDIR \
xbps-src $action $pkg
fi
msg_normal "Exiting from the chroot on $XBPS_MASTERDIR."
umount_chroot_fs
}
mount_chroot_fs()
{
local cnt=
REQFS="sys proc dev xbps xbps_builddir xbps_destdir \
xbps_packagesdir xbps_srcdistdir"
if [ -d "$XBPS_CROSS_DIR" ]; then
local cross=yes
REQFS="$REQFS xbps_crossdir"
fi
for f in ${REQFS}; do
if [ ! -f $XBPS_MASTERDIR/.${f}_mount_bind_done ]; then
echo -n "=> Mounting $f in chroot... "
local blah=
case $f in
xbps) blah=$XBPS_DISTRIBUTIONDIR;;
xbps_builddir) blah=$XBPS_BUILDDIR;;
xbps_destdir) blah=$XBPS_DESTDIR;;
xbps_srcdistdir) blah=$XBPS_SRCDISTDIR;;
xbps_packagesdir) blah=$XBPS_PACKAGESDIR;;
xbps_crossdir)
[ -n $cross ] && blah=$XBPS_CROSS_DIR
;;
*) blah=/$f;;
esac
[ ! -d $blah ] && echo "failed." && continue
mount --bind $blah $XBPS_MASTERDIR/$f
if [ $? -eq 0 ]; then
echo 1 > $XBPS_MASTERDIR/.${f}_mount_bind_done
echo "done."
else
echo "failed."
fi
else
cnt=$(cat $XBPS_MASTERDIR/.${f}_mount_bind_done)
cnt=$(($cnt + 1))
echo $cnt > $XBPS_MASTERDIR/.${f}_mount_bind_done
fi
done
unset f
}
umount_chroot_fs()
{
local fs=
local dir=
local cnt=
for fs in ${REQFS}; do
[ ! -f $XBPS_MASTERDIR/.${fs}_mount_bind_done ] && continue
cnt=$(cat $XBPS_MASTERDIR/.${fs}_mount_bind_done)
if [ $cnt -gt 1 ]; then
cnt=$(($cnt - 1))
echo $cnt > $XBPS_MASTERDIR/.${fs}_mount_bind_done
else
echo -n "=> Unmounting $fs from chroot... "
umount -f $XBPS_MASTERDIR/$fs
if [ $? -eq 0 ]; then
rm -f $XBPS_MASTERDIR/.${fs}_mount_bind_done
echo "done."
else
echo "failed."
fi
fi
unset fs
done
for dir in ${EXTDIRS}; do
[ -f $XBPS_MASTERDIR/.${dir}_mount_bind_done ] && continue
[ -d $XBPS_MASTERDIR/$dir ] && rmdir $XBPS_MASTERDIR/$dir
done
}
[ -n "$base_chroot" ] && return 0
. $XBPS_SHUTILSDIR/builddep_funcs.sh
check_installed_pkg xbps-base-chroot-0.1
if [ $? -ne 0 ]; then
echo "The '$pkgname' package requires to be installed in a chroot."
echo "Please install the 'xbps-base-chroot' package and try again."
exit 1
fi
if [ "$(id -u)" -ne 0 ]; then
if [ -n "$origin_tmpl" ]; then
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
reset_tmpl_vars
run_file $XBPS_TEMPLATESDIR/$origin_tmpl/template
fi
echo "The '$pkgname' package requires to be installed in a chroot."
echo "You cannot do this as normal user, try again being root."
exit 1
fi
msg_normal "Entering into the chroot on $XBPS_MASTERDIR."
EXTDIRS="xbps xbps_builddir xbps_destdir xbps_packagesdir \
xbps_srcdistdir xbps_crossdir"
REQDIRS="bin sbin tmp var sys proc dev usr/local/etc ${EXTDIRS}"
for f in ${REQDIRS}; do
[ ! -d $XBPS_MASTERDIR/$f ] && mkdir -p $XBPS_MASTERDIR/$f
done
unset f REQDIRS
XBPSSRC_CF=$XBPS_MASTERDIR/usr/local/etc/xbps-src.conf
echo "XBPS_DISTRIBUTIONDIR=/xbps" > $XBPSSRC_CF
echo "XBPS_MASTERDIR=/" >> $XBPSSRC_CF
echo "XBPS_DESTDIR=/xbps_destdir" >> $XBPSSRC_CF
echo "XBPS_PACKAGESDIR=/xbps_packagesdir" >> $XBPSSRC_CF
echo "XBPS_BUILDDIR=/xbps_builddir" >> $XBPSSRC_CF
echo "XBPS_SRCDISTDIR=/xbps_srcdistdir" >> $XBPSSRC_CF
echo "XBPS_CFLAGS=\"$XBPS_CFLAGS\"" >> $XBPSSRC_CF
echo "XBPS_CXXFLAGS=\"\$XBPS_CFLAGS\"" >> $XBPSSRC_CF
echo "XBPS_FETCH_CMD=$XBPS_FETCH_CMD" >> $XBPSSRC_CF
if [ -n "$XBPS_MAKEJOBS" ]; then
echo "XBPS_MAKEJOBS=$XBPS_MAKEJOBS" >> $XBPSSRC_CF
fi
if [ -n "$XBPS_CROSS_TARGET" -a -d "$XBPS_CROSS_DIR" ]; then
echo "XBPS_CROSS_TARGET=$XBPS_CROSS_TARGET" >> $XBPSSRC_CF
echo "XBPS_CROSS_DIR=/xbps_crossdir" >> $XBPSSRC_CF
fi

View file

@ -0,0 +1,102 @@
#-
# Copyright (c) 2008-2009 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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.
#-
#
# Common functions for xbps.
#
run_func()
{
func="$1"
[ -z "$func" ] && return 1
type -t $func | grep -q 'function'
if [ $? -eq 0 ]; then
$func
return $?
fi
}
run_rootcmd()
{
local lenv=
local usesudo="$1"
[ -n "$in_chroot" ] && unset fakeroot_cmd
lenv="XBPS_DESTDIR=$XBPS_DESTDIR"
lenv="XBPS_DISTRIBUTIONDIR=$XBPS_DISTRIBUTIONDIR $lenv"
shift
if [ "$usesudo" = "yes" -a -z "$in_chroot" ]; then
sudo env ${lenv} $@
else
env ${lenv} ${fakeroot_cmd} $@
fi
}
msg_error()
{
[ -z "$1" ] && return 1
# error messages in bold/red
printf "\033[1m\033[31m"
if [ -n "$in_chroot" ]; then
echo "[chroot] => ERROR: $1"
else
echo "=> ERROR: $1"
fi
printf "\033[m"
exit 1
}
msg_warn()
{
[ -z "$1" ] && return 1
# warn messages in bold/yellow
printf "\033[1m\033[33m"
if [ -n "$in_chroot" ]; then
echo "[chroot] => WARNING: $1"
else
echo "=> WARNING: $1"
fi
printf "\033[m"
}
msg_normal()
{
[ -z "$1" ] && return 1
# normal messages in bold
printf "\033[1m"
if [ -n "$in_chroot" ]; then
echo "[chroot] => $1"
else
echo "=> $1"
fi
printf "\033[m"
}

View file

@ -0,0 +1,132 @@
#-
# Copyright (c) 2008-2009 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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.
#-
#
# Runs the "configure" phase for a pkg. This setups the Makefiles or any
# other stuff required to be able to build binaries or such.
#
configure_src_phase()
{
local f lver pkg="$1"
[ -z $pkg ] && [ -z $pkgname ] && return 1
[ ! -d $wrksrc ] && msg_error "unexistent build directory [$wrksrc]."
# Apply patches if requested by template file
if [ ! -f $XBPS_APPLYPATCHES_DONE ]; then
. $XBPS_SHUTILSDIR/patch_funcs.sh
apply_tmpl_patches
fi
#
# Skip this phase for: meta-template, only-install, custom-install,
# gnu_makefile and python-module style builds.
#
[ "$build_style" = "meta-template" -o \
"$build_style" = "only-install" -o \
"$build_style" = "custom-install" -o \
"$build_style" = "gnu_makefile" -o \
"$build_style" = "python-module" ] && return 0
if [ -n "$revision" ]; then
lver="${version}_${revision}"
else
lver="${version}"
fi
# cross compilation vars.
if [ -n "$cross_compiler" ]; then
. $XBPS_SHUTILSDIR/cross-compilation.sh
cross_compile_setvars
fi
# Run pre_configure func.
run_func pre_configure || msg_error "pre_configure stage failed!"
# Export configure_env vars.
for f in ${configure_env}; do
export "$f"
done
msg_normal "Running configure phase for $pkgname-$lver."
[ -z "$configure_script" ] && configure_script="./configure"
cd $wrksrc || exit 1
. $XBPS_SHUTILSDIR/buildvars_funcs.sh
set_build_vars
case "$build_style" in
gnu_configure|gnu-configure)
#
# Packages using GNU autoconf
#
${configure_script} --prefix=/usr --sysconfdir=/etc \
--infodir=/usr/share/info --mandir=/usr/share/man \
${configure_args}
;;
configure)
#
# Packages using custom configure scripts.
#
${configure_script} ${configure_args}
;;
perl-module|perl_module)
#
# Packages that are perl modules and use Makefile.PL files.
# They are all handled by the helper perl-module.sh.
#
. $XBPS_HELPERSDIR/perl-module.sh
perl_module_build $pkgname
;;
*)
#
# Unknown build_style type won't work :-)
#
msg_error "unknown build_style [$build_style]"
exit 1
;;
esac
if [ "$build_style" != "perl_module" -a "$?" -ne 0 ]; then
msg_error "building $pkg (configure phase)."
fi
# Run post_configure func.
run_func post_configure || msg_error "post_configure stage failed!"
# unset configure_env vars.
for f in ${configure_env}; do
unset eval ${f%=*}
done
# unset cross compiler vars.
[ -n "$cross_compiler" ] && cross_compile_unsetvars
unset_build_vars
touch -f $XBPS_CONFIGURE_DONE
}

View file

@ -0,0 +1,70 @@
#-
# Copyright (c) 2008 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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 helper sets some required vars to be able to cross build
# packages on xbps. The target is specified in the configuration file
# and will be read any time the cross compilation flag is used.
#
[ -z "$XBPS_CROSS_TARGET" -o ! -d $XBPS_CROSS_DIR/bin ] && return 1
# Check if all required bins are there.
for bin in gcc g++ cpp ar as ranlib ld strip; do
if [ ! -x $XBPS_CROSS_DIR/bin/$XBPS_CROSS_TARGET-${bin} ]; then
msg_error "cross-compilation: cannot find ${bin}, aborting."
fi
done
SAVE_PATH="$PATH"
if [ "$xbps_machine" = "x86_64" ]; then
XBPS_CROSS_HOST="x86_64-unknown-linux-gnu"
else
XBPS_CROSS_HOST="$xbps_machine-pc-linux-gnu"
fi
cross_compile_setvars()
{
export GCC=$XBPS_CROSS_TARGET-gcc
export CC=$XBPS_CROSS_TARGET-gcc
export CXX=$XBPS_CROSS_TARGET-g++
export CPP=$XBPS_CROSS_TARGET-cpp
export AR=$XBPS_CROSS_TARGET-ar
export AS=$XBPS_CROSS_TARGET-as
export RANLIB=$XBPS_CROSS_TARGET-ranlib
export LD=$XBPS_CROSS_TARGET-ld
export STRIP=$XBPS_CROSS_TARGET-strip
export PATH="$XBPS_CROSS_DIR/bin:$PATH"
}
cross_compile_unsetvars()
{
unset GCC CC CXX CPP AR AS RANLIB LD STRIP PATH
export PATH="$SAVE_PATH"
}
if [ "$build_style" = "gnu_configure" ]; then
configure_args="--build=$XBPS_CROSS_HOST --host=$XBPS_CROSS_TARGET"
configure_args="$configure_args --target=$XBPS_CROSS_TARGET"
fi

View file

@ -0,0 +1,176 @@
#-
# Copyright (c) 2008 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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.
#-
#
# Extracts contents of distfiles specified in a template into
# the $wrksrc directory.
#
extract_distfiles()
{
local count=0 pkg="$1"
local curfile cursufx lwrksrc ltar_cmd f lver
[ -f $XBPS_EXTRACT_DONE ] && return 0
[ -z "$in_chroot" -a ! -w $XBPS_BUILDDIR ] && \
msg_error "can't extract distfile(s) (permission denied)"
#
# If we are being called via the target, just extract and return.
#
[ -n "$pkg" -a -z "$pkgname" ] && return 1
#
# There's nothing of interest if we are a meta template.
#
[ "$build_style" = "meta-template" ] && return 0
if [ -n "$revision" ]; then
lver="${version}_${revision}"
else
lver="${version}"
fi
#
# If noextract is set, do a "fake extraction".
#
if [ -z "$distfiles" -o -n "$noextract" ]; then
mkdir $wrksrc
touch -f $XBPS_EXTRACT_DONE
return 0
fi
for f in ${distfiles}; do
count=$(($count + 1))
done
if [ "$count" -gt 1 ]; then
if [ -z "$wrksrc" ]; then
msg_error "\$wrksrc must be defined with multiple distfiles."
exit 1
fi
mkdir $wrksrc
fi
msg_normal "Extracting $pkgname-$lver distfile(s)."
if [ -n "$tar_override_cmd" ]; then
ltar_cmd="$tar_override_cmd"
else
ltar_cmd="tar"
fi
for f in ${distfiles}; do
curfile=$(basename $f)
if $(echo $f|grep -q '.tar.lzma'); then
cursufx=".tar.lzma"
elif $(echo $f|grep -q '.tar.bz2'); then
cursufx=".tar.bz2"
elif $(echo $f|grep -q '.tbz'); then
cursufx=".tbz"
elif $(echo $f|grep -q '.tar.gz'); then
cursufx=".tar.gz"
elif $(echo $f|grep -q '.tgz'); then
cursufx=".tgz"
elif $(echo $f|grep -q '.gz'); then
cursufx=".gz"
elif $(echo $f|grep -q '.bz2'); then
cursufx=".bz2"
elif $(echo $f|grep -q '.tar'); then
cursufx=".tar"
elif $(echo $f|grep -q '.zip'); then
cursufx=".zip"
else
msg_error "unknown distfile suffix for $curfile."
fi
if [ $count -gt 1 ]; then
lwrksrc="$wrksrc"
else
lwrksrc="$XBPS_BUILDDIR"
fi
case ${cursufx} in
.tar.lzma)
if [ -x $XBPS_MASTERDIR/usr/bin/lzma ]; then
cp -f $XBPS_SRCDISTDIR/$curfile $lwrksrc
cd $lwrksrc && \
$XBPS_MASTERDIR/usr/bin/lzma \
-d $curfile && \
$ltar_cmd xf ${curfile%.lzma} \
-C $lwrksrc && \
rm -f ${curfile%.lzma}
if [ $? -ne 0 ]; then
msg_error "extracting $curfile into $lwrksrc."
fi
else
msg_error "cannot find lzma bin for extraction."
fi
;;
.tar.bz2|.tbz)
$ltar_cmd xfj $XBPS_SRCDISTDIR/$curfile -C $lwrksrc
if [ $? -ne 0 ]; then
msg_error "extracting $curfile into $lwrksrc."
fi
;;
.tar.gz|.tgz)
$ltar_cmd xfz $XBPS_SRCDISTDIR/$curfile -C $lwrksrc
if [ $? -ne 0 ]; then
msg_error "extracting $curfile into $lwrksrc."
fi
;;
.gz|.bz2)
cp -f $XBPS_SRCDISTDIR/$curfile $lwrksrc
if [ "$cursufx" = ".gz" ]; then
cd $lwrksrc && gunzip $curfile
else
cd $lwrksrc && bunzip2 $curfile
fi
;;
.tar)
$ltar_cmd xf $XBPS_SRCDISTDIR/$curfile -C $lwrksrc
if [ $? -ne 0 ]; then
msg_error "extracting $curfile into $lwrksrc."
fi
;;
.zip)
if [ -x $XBPS_MASTERDIR/usr/bin/unzip ]; then
$XBPS_MASTERDIR/usr/bin/unzip \
-q -x $XBPS_SRCDISTDIR/$curfile -d $lwrksrc
if [ $? -ne 0 ]; then
msg_error "extracting $curfile into $lwrksrc."
fi
else
msg_error "cannot find unzip bin for extraction"
fi
;;
*)
msg_error "cannot guess $curfile extract suffix. ($cursufx)"
;;
esac
done
touch -f $XBPS_EXTRACT_DONE
}

View file

@ -0,0 +1,167 @@
#-
# Copyright (c) 2008 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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.
#-
#
# Verifies that file's checksum downloaded matches what it's specified
# in template file.
#
verify_sha256_cksum()
{
local file="$1"
local origsum="$2"
[ -z "$file" -o -z "$cksum" ] && return 1
filesum=$(xbps-digest $XBPS_SRCDISTDIR/$file)
if [ "$origsum" != "$filesum" ]; then
msg_error "SHA256 checksum doesn't match for $file."
fi
msg_normal "SHA256 checksum OK for $file."
}
fetch_update_cksum()
{
local tmpl="$XBPS_TEMPLATESDIR/$pkgname/template"
local upcmd=$(basename $XBPS_SRCDISTDIR/$1)
sed -i -e "s|checksum.*|checksum=$(xbps-digest ${upcmd})|" $tmpl
return $?
}
#
# Downloads the distfiles and verifies checksum for all them.
#
fetch_distfiles()
{
local pkg="$1"
local upcksum="$2"
local dfiles=
local localurl=
local dfcount=0
local ckcount=0
local f=
[ -z $pkgname ] && exit 1
#
# There's nothing of interest if we are a meta template.
#
[ "$build_style" = "meta-template" ] && return 0
#
# If nofetch is set in a build template, skip this phase
# entirely and run the do_fetch() function.
#
if [ -n "$nofetch" ]; then
cd ${XBPS_BUILDDIR} && run_func do_fetch
return $?
fi
cd $XBPS_SRCDISTDIR || return 1
for f in ${distfiles}; do
curfile=$(basename $f)
if [ -f "$XBPS_SRCDISTDIR/$curfile" ]; then
if [ -n "$upcksum" ]; then
fetch_update_cksum $curfile
run_template $pkgname
fi
for i in ${checksum}; do
if [ $dfcount -eq $ckcount -a -n $i ]; then
cksum=$i
found=yes
break
fi
ckcount=$(($ckcount + 1))
done
if [ -z $found ]; then
msg_error "cannot find checksum for $curfile."
fi
verify_sha256_cksum $curfile $cksum
if [ $? -eq 0 ]; then
unset cksum found
ckcount=0
dfcount=$(($dfcount + 1))
continue
fi
fi
msg_normal "Fetching distfile: $curfile."
if [ -n "$distfiles" ]; then
localurl="$f"
else
localurl="$url/$curfile"
fi
$XBPS_FETCH_CMD $localurl
if [ $? -ne 0 ]; then
unset localurl
if [ ! -f $XBPS_SRCDISTDIR/$curfile ]; then
msg_error "couldn't fetch $curfile."
else
msg_error "there was an error fetching $curfile."
fi
else
unset localurl
if [ -n "$upcksum" ]; then
fetch_update_cksum $curfile
run_template $pkgname
fi
#
# XXX duplicate code.
#
for i in ${checksum}; do
if [ $dfcount -eq $ckcount -a -n $i ]; then
cksum=$i
found=yes
break
fi
ckcount=$(($ckcount + 1))
done
if [ -z $found ]; then
msg_error "cannot find checksum for $curfile."
fi
verify_sha256_cksum $curfile $cksum
if [ $? -eq 0 ]; then
unset cksum found
ckcount=0
fi
fi
dfcount=$(($dfcount + 1))
done
unset cksum found
}

View file

@ -0,0 +1,192 @@
#-
# Copyright (c) 2008-2009 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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.
#-
#
# Runs the "install" phase for a pkg. This consists in installing package
# into the destination directory.
#
strip_files()
{
if [ ! -x /usr/bin/strip ]; then
return 0
fi
[ -n "$nostrip" ] && return 0
msg_normal "Finding binaries/libraries to strip..."
for f in $(find ${DESTDIR} -type f); do
case "$(file -biz $f)" in
application/x-executable*)
/usr/bin/strip $f && \
echo "===> Stripped executable: $(basename $f)";;
application/x-sharedlib*|application/x-archive*)
/usr/bin/strip -S $f && \
echo "===> Stripped library: $(basename $f)";;
esac
done
}
install_src_phase()
{
local pkg="$1"
local f i subpkg lver spkgrev
[ -z $pkg ] && [ -z $pkgname ] && return 1
if [ -n "$revision" ]; then
lver="${version}_${revision}"
else
lver="${version}"
fi
#
# There's nothing we can do if we are a meta template.
# Just creating the dir is enough to write the package metadata.
#
if [ "$build_style" = "meta-template" ]; then
mkdir -p $XBPS_DESTDIR/$pkgname-$version
return 0
fi
cd $wrksrc || msg_error "can't change cwd to wrksrc!"
# Run pre_install func.
run_func pre_install || msg_error "pre_install stage failed!"
msg_normal "Running install phase for $pkgname-$lver."
# cross compilation vars.
if [ -n "$cross_compiler" ]; then
. $XBPS_SHUTILSDIR/cross-compilation.sh
cross_compile_setvars
fi
# Type of installation: custom, make or python.
case "$build_style" in
custom-install)
run_func do_install || msg_error "do_install stage failed!"
;;
python-module)
. $XBPS_HELPERSDIR/python-module.sh
run_func do_install || msg_error "python module install failed!"
;;
*)
make_install $lver
;;
esac
# Run post_install func.
run_func post_install || msg_error "post_install stage failed!"
# Remove libtool archives by default.
if [ -z "$keep_libtool_archives" ]; then
find ${DESTDIR} -type f -name \*.la -delete
fi
# Always remove perllocal.pod and .packlist files.
if [ "$pkgname" != "perl" ]; then
find ${DESTDIR} -type f -name perllocal.pod -delete
find ${DESTDIR} -type f -name .packlist -delete
fi
# Remove empty directories by default.
if [ -z "$keep_empty_dirs" ]; then
find ${DESTDIR} -depth -type d -empty -delete
fi
# Strip bins/libs.
strip_files
# unset cross compiler vars.
[ -n "$cross_compiler" ] && cross_compile_unsetvars
msg_normal "Installed $pkgname-$lver into $XBPS_DESTDIR."
if [ "$build_style" != "custom-install" -a -z "$distfiles" ]; then
touch -f $XBPS_INSTALL_DONE
fi
#
# Build subpackages if found.
#
for subpkg in ${subpackages}; do
if [ "${pkg}" != "${sourcepkg}" ] && \
[ "${pkg}" != "${sourcepkg}-${subpkg}" ]; then
continue
fi
if [ -n "$revision" ]; then
spkgrev="${sourcepkg}-${subpkg}-${version}_${revision}"
else
spkgrev="${sourcepkg}-${subpkg}-${version}"
fi
check_installed_pkg ${spkgrev}
[ $? -eq 0 ] && continue
msg_normal "Preparing $sourcepkg subpackage: $sourcepkg-$subpkg"
if [ ! -f $XBPS_TEMPLATESDIR/$pkgname/$subpkg.template ]; then
msg_error "Cannot find subpackage template!"
fi
. $XBPS_TEMPLATESDIR/$pkgname/$subpkg.template
pkgname=${sourcepkg}-${subpkg}
set_tmpl_common_vars
run_func do_install || \
msg_error "$pkgname do_install stage failed!"
run_template ${sourcepkg}
[ "$pkg" = "${sourcepkg}-${subpkg}" ] && break
done
[ -n "$subpackages" ] && setup_tmpl ${sourcepkg}
#
# Remove $wrksrc if -C not specified.
#
if [ -d "$wrksrc" -a -z "$dontrm_builddir" ]; then
rm -rf $wrksrc && \
msg_normal "Removed $pkgname-$lver build directory."
fi
}
#
# Installs a package via 'make install ...'.
#
make_install()
{
local lver="$1"
if [ -z "$make_install_target" ]; then
make_install_target="DESTDIR=${DESTDIR} install"
fi
[ -z "$make_cmd" ] && make_cmd=/usr/bin/make
. $XBPS_SHUTILSDIR/buildvars_funcs.sh
set_build_vars
#
# Install package via make.
#
run_rootcmd no ${make_cmd} ${make_install_target} \
${make_install_args} || msg_error "installing $pkgname-$lver"
# Unset build vars.
unset_build_vars
}

View file

@ -0,0 +1,124 @@
#-
# Copyright (c) 2008-2009 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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.
#-
xbps_make_binpkg()
{
local pkg="$1"
local subpkg
for subpkg in ${subpackages}; do
if [ "$pkg" = "$pkgname-$subpkg" ]; then
unset revision
. $XBPS_TEMPLATESDIR/$pkgname/$subpkg.template
pkgname=${sourcepkg}-${subpkg}
set_tmpl_common_vars
xbps_make_binpkg_real
return $?
fi
run_template ${sourcepkg}
done
set_tmpl_common_vars
xbps_make_binpkg_real
return $?
}
#
# This function builds a binary package from an installed xbps
# package in destdir.
#
xbps_make_binpkg_real()
{
local binpkg pkgdir arch use_sudo lver
local tar_flags="cfp"
if [ ! -d ${DESTDIR} ]; then
echo "$pkgname: unexistent destdir... skipping!"
return 0
fi
cd ${DESTDIR}
if [ -n "$noarch" ]; then
arch=noarch
else
arch=$xbps_machine
fi
if [ -n "$base_chroot" ]; then
use_sudo=no
else
use_sudo=yes
fi
if [ -n "$revision" ]; then
lver="${version}_${revision}"
else
lver="${version}"
fi
binpkg=$pkgname-$lver.$arch.xbps
pkgdir=$XBPS_PACKAGESDIR/$arch
#
# Make sure that INSTALL is the first file on the archive,
# this is to ensure that it's run before any other file is
# unpacked.
#
if [ -x ./INSTALL ]; then
run_rootcmd $use_sudo tar $tar_flags \
$XBPS_BUILDDIR/$binpkg ./INSTALL
[ $? -ne 0 ] && msg_error "Failed to add INSTALL script."
fi
if [ -x ./REMOVE ]; then
if [ -x ./INSTALL ]; then
tar_flags="rfp"
fi
run_rootcmd $use_sudo tar $tar_flags \
$XBPS_BUILDDIR/$binpkg ./REMOVE
[ $? -ne 0 ] && msg_error "Failed to add REMOVE script."
fi
if [ -x ./INSTALL -o -x ./REMOVE ]; then
tar_flags="rfp"
elif [ ! -x ./INSTALL -o ! -x ./REMOVE ]; then
tar_flags="cfp"
fi
run_rootcmd $use_sudo tar $tar_flags $XBPS_BUILDDIR/$binpkg \
./files.plist ./props.plist
[ $? -ne 0 ] && msg_error "Failed to add metadata files."
run_rootcmd $use_sudo tar rfp $XBPS_BUILDDIR/$binpkg . \
--exclude "./INSTALL" --exclude "./REMOVE" \
--exclude "./files.plist" --exclude "./props.plist" \
--exclude "./var/db/xbps/metadata/*/flist" && \
bzip2 -9 $XBPS_BUILDDIR/$binpkg && \
mv $XBPS_BUILDDIR/$binpkg.bz2 $XBPS_BUILDDIR/$binpkg
if [ $? -eq 0 ]; then
[ ! -d $pkgdir ] && mkdir -p $pkgdir
mv -f $XBPS_BUILDDIR/$binpkg $pkgdir
echo "=> Built package: $binpkg"
fi
return $?
}

View file

@ -0,0 +1,368 @@
#-
# Copyright (c) 2008-2009 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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.
#-
write_metadata_flist_header()
{
[ ! -f "$1" ] && return 1
cat > $1 <<_EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
_EOF
}
xbps_write_metadata_pkg()
{
local pkg="$1"
local subpkg spkgrev
for subpkg in ${subpackages}; do
if [ "${pkg}" != "${sourcepkg}" ] && \
[ "${pkg}" != "${sourcepkg}-${subpkg}" ]; then
continue
fi
if [ -n "${revision}" ]; then
spkgrev="${sourcepkg}-${subpkg}-${version}_${revision}"
else
spkgrev="${sourcepkg}-${subpkg}-${version}"
fi
check_installed_pkg ${spkgrev}
[ $? -eq 0 ] && continue
if [ ! -f $XBPS_TEMPLATESDIR/$sourcepkg/$subpkg.template ]; then
msg_error "Cannot find subpackage template!"
fi
unset run_depends conf_files noarch triggers replaces \
revision openrc_services essential keep_empty_dirs
. $XBPS_TEMPLATESDIR/${sourcepkg}/${subpkg}.template
pkgname=${sourcepkg}-${subpkg}
set_tmpl_common_vars
xbps_write_metadata_pkg_real
run_template ${sourcepkg}
[ "${pkg}" = "${sourcepkg}-${subpkg}" ] && break
done
[ -n "${subpackages}" ] && [ "$pkg" != "${sourcepkg}" ] && return $?
if [ "$build_style" = "meta-template" -a -z "${run_depends}" ]; then
for spkg in ${subpackages}; do
if [ -n "${revision}" ]; then
spkgrev="$sourcepkg-$spkg-${version}_$revision"
else
spkgrev="${sourcepkg}-${spkg}-${version}"
fi
run_depends="${run_depends} ${spkgrev}"
done
fi
set_tmpl_common_vars
xbps_write_metadata_pkg_real
}
#
# This function writes the metadata files into package's destdir,
# these will be used for binary packages.
#
xbps_write_metadata_pkg_real()
{
local metadir=${DESTDIR}/var/db/xbps/metadata/$pkgname
local f i j found arch dirat lnkat newlnk lver TMPFLIST TMPFPLIST
local fpattern="s|${DESTDIR}||g;s|^\./$||g;/^$/d"
if [ ! -d "${DESTDIR}" ]; then
echo "ERROR: $pkgname not installed into destdir."
exit 1
fi
if [ -n "$noarch" ]; then
arch=noarch
else
arch=$xbps_machine
fi
if [ -n "$revision" ]; then
lver="${version}_${revision}"
else
lver="${version}"
fi
# Write the files.plist file.
TMPFLIST=$(mktemp -t flist.XXXXXXXXXX) || exit 1
TMPFPLIST=$(mktemp -t fplist.XXXXXXXXXX) || exit 1
#
# Find out if this package contains info files and compress
# all them with gzip.
#
if [ -f ${DESTDIR}/usr/share/info/dir ]; then
# Always remove this file if curpkg is not texinfo.
if [ "$pkgname" != "texinfo" ]; then
rm -f ${DESTDIR}/usr/share/info/dir
fi
# Add info-files trigger.
triggers="info-files $triggers"
for f in $(find -L ${DESTDIR}/usr/share/info -type f); do
j=$(echo $f|sed -e "$fpattern")
[ "$j" = "" ] && continue
[ "$j" = "/usr/share/info/dir" ] && continue
# Ignore compressed files.
if $(echo $j|grep -q '.*.gz$'); then
continue
fi
# Ignore non info files.
if ! $(echo $j|grep -q '.*.info$') && \
! $(echo $j|grep -q '.*.info-[0-9]*$'); then
continue
fi
if [ -h ${DESTDIR}/$j ]; then
dirat=$(dirname $j)
lnkat=$(readlink ${DESTDIR}/$j)
newlnk=$(basename $j)
rm -f ${DESTDIR}/$j
cd ${DESTDIR}/$dirat
ln -s ${lnkat}.gz ${newlnk}.gz
continue
fi
echo "===> Compressing info file: $j..."
gzip -q9 ${DESTDIR}/$j
done
fi
#
# Find out if this package contains manual pages and
# compress all them with gzip.
#
if [ -d "${DESTDIR}/usr/share/man" ]; then
for f in $(find -L ${DESTDIR}/usr/share/man -type f); do
j=$(echo $f|sed -e "$fpattern")
[ "$j" = "" ] && continue
if $(echo $j|grep -q '.*.gz$'); then
continue
fi
if [ -h ${DESTDIR}/$j ]; then
dirat=$(dirname $j)
lnkat=$(readlink ${DESTDIR}/$j)
newlnk=$(basename $j)
rm -f ${DESTDIR}/$j
cd ${DESTDIR}/$dirat
ln -s ${lnkat}.gz ${newlnk}.gz
continue
fi
echo "===> Compressing manpage: $j..."
gzip -q9 ${DESTDIR}/$j
done
fi
cd ${DESTDIR}
msg_normal "Writing package metadata for $pkgname-$lver..."
write_metadata_flist_header $TMPFPLIST
# Pass 1: add links.
echo "<key>links</key>" >> $TMPFPLIST
echo "<array>" >> $TMPFPLIST
for f in $(find ${DESTDIR} -type l); do
j=$(echo $f|sed -e "$fpattern")
[ "$j" = "" ] && continue
echo "$j" >> $TMPFLIST
echo "<dict>" >> $TMPFPLIST
echo "<key>file</key>" >> $TMPFPLIST
echo "<string>$j</string>" >> $TMPFPLIST
echo "</dict>" >> $TMPFPLIST
done
echo "</array>" >> $TMPFPLIST
# Pass 2: add regular files.
echo "<key>files</key>" >> $TMPFPLIST
echo "<array>" >> $TMPFPLIST
for f in $(find ${DESTDIR} -type f); do
j=$(echo $f|sed -e "$fpattern")
[ "$j" = "" ] && continue
echo "$j" >> $TMPFLIST
# Skip configuration files.
for i in ${conf_files}; do
[ "$j" = "$i" ] && found=1 && break
done
[ -n "$found" ] && unset found && continue
echo "<dict>" >> $TMPFPLIST
echo "<key>file</key>" >> $TMPFPLIST
echo "<string>$j</string>" >> $TMPFPLIST
echo "<key>sha256</key>" >> $TMPFPLIST
echo "<string>$(xbps-digest $f)</string>" >> $TMPFPLIST
echo "</dict>" >> $TMPFPLIST
done
echo "</array>" >> $TMPFPLIST
# Pass 3: add directories.
echo "<key>dirs</key>" >> $TMPFPLIST
echo "<array>" >> $TMPFPLIST
for f in $(find ${DESTDIR} -type d|sort -ur); do
j=$(echo $f|sed -e "$fpattern")
[ "$j" = "" ] && continue
echo "$j" >> $TMPFLIST
echo "<dict>" >> $TMPFPLIST
echo "<key>file</key>" >> $TMPFPLIST
echo "<string>$j</string>" >> $TMPFPLIST
echo "</dict>" >> $TMPFPLIST
done
echo "</array>" >> $TMPFPLIST
# Add configuration files into its own array.
if [ -n "${conf_files}" ]; then
echo "<key>conf_files</key>" >> $TMPFPLIST
echo "<array>" >> $TMPFPLIST
for f in ${conf_files}; do
i=${DESTDIR}/${f}
[ ! -f ${i} ] && continue
echo "<dict>" >> $TMPFPLIST
echo "<key>file</key>" >> $TMPFPLIST
echo "<string>$f</string>" >> $TMPFPLIST
echo "<key>sha256</key>" >> $TMPFPLIST
echo "<string>$(xbps-digest ${i})</string>" >> $TMPFPLIST
echo "</dict>" >> $TMPFPLIST
done
echo "</array>" >> $TMPFPLIST
fi
echo "</dict>" >> $TMPFPLIST
echo "</plist>" >> $TMPFPLIST
sed -i -e /^$/d $TMPFLIST
# Write the props.plist file.
local TMPFPROPS=$(mktemp -t fprops.XXXXXXXXXX) || exit 1
cat > $TMPFPROPS <<_EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>pkgname</key>
<string>$pkgname</string>
<key>version</key>
<string>$lver</string>
<key>architecture</key>
<string>$arch</string>
<key>installed_size</key>
<integer>$(du -sb ${DESTDIR}|awk '{print $1}')</integer>
<key>maintainer</key>
<string>$(echo $maintainer|sed -e 's|<|[|g;s|>|]|g')</string>
<key>short_desc</key>
<string>$short_desc</string>
<key>long_desc</key>
<string>$long_desc</string>
_EOF
#
# If package sets $openrc_services, add the openrc-service
# trigger and OpenRC run dependency.
#
if [ -n "$openrc_services" ]; then
triggers="$triggers openrc-service"
Add_dependency run OpenRC
fi
# Is this an essential pkg?
if [ -n "$essential" ]; then
echo "<key>essential</key>" >> $TMPFPROPS
echo "<true/>" >> $TMPFPROPS
fi
# Dependencies
if [ -n "$run_depends" ]; then
echo "<key>run_depends</key>" >> $TMPFPROPS
echo "<array>" >> $TMPFPROPS
for f in ${run_depends}; do
echo "<string>$f</string>" >> $TMPFPROPS
done
echo "</array>" >> $TMPFPROPS
fi
# Configuration files
if [ -n "$conf_files" ]; then
echo "<key>conf_files</key>" >> $TMPFPROPS
echo "<array>" >> $TMPFPROPS
for f in ${conf_files}; do
echo "<string>$f</string>" >> $TMPFPROPS
done
echo "</array>" >> $TMPFPROPS
fi
# Replace package(s).
if [ -n "$replaces" ]; then
echo "<key>replaces</key>" >> $TMPFPROPS
echo "<array>" >> $TMPFPROPS
for f in ${replaces}; do
echo "<string>$f</string>" >> $TMPFPROPS
done
echo "</array>" >> $TMPFPROPS
fi
# Terminate the property list file.
echo "</dict>" >> $TMPFPROPS
echo "</plist>" >> $TMPFPROPS
if [ ! -d $metadir ]; then
mkdir -p $metadir >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR: you don't have enough perms for this."
rm -f $TMPFLIST $TMPFPROPS
exit 1
fi
fi
# Write metadata files and cleanup.
if [ -s $TMPFLIST ]; then
mv -f $TMPFLIST $metadir/flist
else
rm -f $TMPFLIST
fi
mv -f $TMPFPLIST ${DESTDIR}/files.plist
mv -f $TMPFPROPS ${DESTDIR}/props.plist
$XBPS_REGPKGDB_CMD sanitize-plist ${DESTDIR}/files.plist
$XBPS_REGPKGDB_CMD sanitize-plist ${DESTDIR}/props.plist
chmod 644 ${DESTDIR}/files.plist ${DESTDIR}/props.plist
[ -f $metadir/flist ] && chmod 644 $metadir/flist
#
# Update desktop-file-utils database if package contains
# any desktop file in /usr/share/applications.
#
if [ -d ${DESTDIR}/usr/share/applications ]; then
if find . -type f -name \*.desktop 2>&1 >/dev/null; then
triggers="$triggers update-desktopdb"
fi
fi
#
# Create the INSTALL/REMOVE scripts if package uses them
# or uses any available trigger.
#
. ${XBPS_SHUTILSDIR}/metadata_scripts.sh
xbps_write_metadata_scripts_pkg install
xbps_write_metadata_scripts_pkg remove
}

View file

@ -0,0 +1,227 @@
#-
# Copyright (c) 2009 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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.
#-
xbps_write_metadata_scripts_pkg()
{
local action="$1"
local tmpf=$(mktemp -t xbps-install.XXXXXXXXXX) || exit 1
local fpattern="s|${DESTDIR}||g;s|^\./$||g;/^$/d"
local targets found info_files
case "$action" in
install) ;;
remove) ;;
*) return 1;;
esac
cd ${DESTDIR}
cat >> $tmpf <<_EOF
#!/bin/sh -e
#
# Generic INSTALL/REMOVE script. Arguments passed to this script:
#
# \$1 = ACTION [pre/post]
# \$2 = PKGNAME
# \$3 = VERSION
# \$4 = UPDATE [yes/no]
#
# Note that paths must be relative to CWD, to avoid calling
# host commands if /bin/sh (dash) is not installed and it's
# not possible to chroot(3).
#
export PATH="./bin:./sbin:./usr/bin:./usr/sbin"
TRIGGERSDIR="./var/db/xbps/triggers"
ACTION="\$1"
PKGNAME="\$2"
VERSION="\$3"
UPDATE="\$4"
#
# The following code will run the triggers.
#
_EOF
#
# Handle GNU Info files.
#
if [ -d "${DESTDIR}/usr/share/info" ]; then
unset info_files
for f in $(find ${DESTDIR}/usr/share/info -type f); do
j=$(echo $f|sed -e "$fpattern")
[ "$j" = "" ] && continue
[ "$j" = "/usr/share/info/dir" ] && continue
if [ -z "$info_files" ]; then
info_files="$j"
else
info_files="$info_files $j"
fi
done
if [ -n "${info_files}" ]; then
for f in ${triggers}; do
[ "$f" = "info-files" ] && found=1
done
[ -z "$found" ] && triggers="$triggers info-files"
unset found
echo "export info_files=\"${info_files}\"" >> $tmpf
echo >> $tmpf
fi
fi
#
# Handle OpenRC services.
#
if [ -n "${openrc_services}" ]; then
echo "export openrc_services=\"${openrc_services}\"" >> $tmpf
echo >> $tmpf
fi
#
# (Un)Register a shell in /etc/shells.
#
if [ -n "${register_shell}" ]; then
for f in ${triggers}; do
[ "$f" = "register-shell" ] && found=1
done
[ -z "$found" ] && triggers="$triggers register-shell"
unset found
echo "export register_shell=\"${register_shell}\"" >> $tmpf
echo >> $tmpf
fi
#
# Handle SGML/XML catalog entries via xmlcatmgr.
#
if [ -n "${sgml_catalogs}" ]; then
for catalog in ${sgml_catalogs}; do
sgml_entries="${sgml_entries} CATALOG ${catalog} --"
done
fi
if [ -n "${sgml_entries}" ]; then
echo "export sgml_entries=\"${sgml_entries}\"" >> $tmpf
echo >> $tmpf
fi
if [ -n "${xml_catalogs}" ]; then
for catalog in ${xml_catalogs}; do
xml_entries="${xml_entries} nextCatalog ${catalog} --"
done
fi
if [ -n "${xml_entries}" ]; then
echo "export xml_entries=\"${xml_entries}\"" >> $tmpf
echo >> $tmpf
fi
#
# Handle X11 font updates via mkfontdir/mkfontscale.
#
if [ -n "${font_dirs}" ]; then
echo "export font_dirs=\"${font_dirs}\"" >> $tmpf
echo >> $tmpf
fi
#
# Handle GTK+ Icon cache directories.
#
if [ -n "${gtk_iconcache_dirs}" ]; then
echo "export gtk_iconcache_dirs=\"${gtk_iconcache_dirs}\"" \
>> $tmpf
echo >> $tmpf
fi
if [ -n "$triggers" ]; then
found=1
echo "case \"\${ACTION}\" in" >> $tmpf
echo "pre)" >> $tmpf
for f in ${triggers}; do
if [ ! -f $XBPS_TRIGGERSDIR/$f ]; then
rm -f $tmpf
msg_error "$pkgname: unknown trigger $f, aborting!"
fi
done
for f in ${triggers}; do
targets=$($XBPS_TRIGGERSDIR/$f targets)
for j in ${targets}; do
if ! $(echo $j|grep -q pre-${action}); then
continue
fi
printf "\t\${TRIGGERSDIR}/$f run $j \${PKGNAME} \${VERSION} \${UPDATE}\n" >> $tmpf
printf "\t[ \$? -ne 0 ] && exit \$?\n" >> $tmpf
done
done
printf "\t;;\n" >> $tmpf
echo "post)" >> $tmpf
for f in ${triggers}; do
targets=$($XBPS_TRIGGERSDIR/$f targets)
for j in ${targets}; do
if ! $(echo $j|grep -q post-${action}); then
continue
fi
printf "\t\${TRIGGERSDIR}/$f run $j \${PKGNAME} \${VERSION} \${UPDATE}\n" >> $tmpf
printf "\t[ \$? -ne 0 ] && exit \$?\n" >> $tmpf
done
done
printf "\t;;\n" >> $tmpf
echo "esac" >> $tmpf
echo >> $tmpf
fi
case "$action" in
install)
if [ -n "${sourcepkg}" -a "${sourcepkg}" != "${pkgname}" ]; then
install_file=${XBPS_TEMPLATESDIR}/${pkgname}/${pkgname}.INSTALL
else
install_file=${XBPS_TEMPLATESDIR}/${pkgname}/INSTALL
fi
if [ -f ${install_file} ]; then
found=1
cat ${install_file} >> $tmpf
fi
echo "exit 0" >> $tmpf
if [ -z "$found" ]; then
rm -f $tmpf
return 0
fi
mv $tmpf ${DESTDIR}/INSTALL && chmod 755 ${DESTDIR}/INSTALL
;;
remove)
if [ -n "${sourcepkg}" -a "${sourcepkg}" != "${pkgname}" ]; then
remove_file=${XBPS_TEMPLATESDIR}/${pkgname}/${pkgname}.REMOVE
else
remove_file=${XBPS_TEMPLATESDIR}/${pkgname}/REMOVE
fi
if [ -f ${remove_file} ]; then
found=1
cat ${remove_file} >> $tmpf
fi
echo "exit 0" >> $tmpf
if [ -z "$found" ]; then
rm -f $tmpf
return 0
fi
mv $tmpf ${DESTDIR}/REMOVE && chmod 755 ${DESTDIR}/REMOVE
;;
esac
}

439
xbps-src/shutils/mktoolchain.sh Executable file
View file

@ -0,0 +1,439 @@
#!/bin/sh
#
#-
# Copyright (c) 2008 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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.
#-
#
# Script to be able to build a full cross toolchain for Linux/x86.
# This has been made thanks to various sources recollected from wikipedia
# and other cross compiling related pages.
# Setup some defaults
: ${GNU_URL_BASE:=http://ftp.gnu.org/gnu}
: ${KERNEL_URL_BASE:=http://www.kernel.org/pub/linux/kernel/v2.6}
: ${GCC_VER:=4.3.2}
: ${BINUTILS_VER:=2.19}
: ${GLIBC_VER:=2.7}
: ${KERNEL_VER:=2.6.27.3}
: ${CROSSDIR:=$HOME/mktoolchain}
: ${BUILDDIR:=$CROSSDIR/build}
: ${SOURCEDISTDIR:=$BUILDDIR/sources}
: ${FETCH_CMD:=wget}
usage()
{
echo "usage: $0 [-b dir] [-c dir] [-s dir] <target triplet>"
echo
echo "Optional flags:"
echo " -b Directory to be used for temporary building."
echo " -c Directory to be used for final cross tools."
echo " -s Directory where the sources are available."
exit 1
}
check_path()
{
local orig="$1"
case "$orig" in
/) ;;
/*) orig="${orig%/}" ;;
*) orig="$PWD/${orig%/}" ;;
esac
SANITIZED_DESTDIR=$orig
}
fetch_sources()
{
local pkg=
cd $SOURCEDISTDIR || exit 1
pkg=linux
if [ ! -f $pkg-$KERNEL_VER.tar.bz2 ]; then
echo "Fetching $pkg kernel-$KERNEL_VER sources..."
$FETCH_CMD $KERNEL_URL_BASE/$pkg-$KERNEL_VER.tar.bz2 || exit 1
fi
pkg=gcc
if [ ! -f $pkg-$GCC_VER.tar.bz2 ]; then
echo "Fetching $pkg-$GCC_VER..."
$FETCH_CMD $GNU_URL_BASE/$pkg/$pkg-$GCC_VER/$pkg-$GCC_VER.tar.bz2 || exit 1
fi
pkg=binutils
if [ ! -f $pkg-$BINUTILS_VER.tar.bz2 ]; then
echo "Fetching $pkg-$BINUTILS_VER..."
$FETCH_CMD $GNU_URL_BASE/$pkg/$pkg-$BINUTILS_VER.tar.bz2 \
|| exit 1
fi
pkg=glibc
if [ ! -f $pkg-$GLIBC_VER.tar.bz2 ]; then
echo "Fetching $pkg-$GLIBC_VER..."
$FETCH_CMD $GNU_URL_BASE/$pkg/$pkg-$GLIBC_VER.tar.bz2 || exit 1
fi
}
kernel_headers()
{
local pkg="linux-$KERNEL_VER"
cd $BUILDDIR || exit 1
tar xfj $SOURCEDISTDIR/$pkg.tar.bz2 -C $BUILDDIR || exit 1
cd $pkg || exit 1
make ARCH=$KERNEL_ARCH headers_check || exit 1
make ARCH=$KERNEL_ARCH headers_install \
INSTALL_HDR_PATH=$SYSROOT/usr || exit 1
cd $SYSROOT/usr/include && ln -s asm asm-$KERNEL_ARCH
cd $BUILDDIR && rm -rf $pkg || exit 1
touch -f $BUILDDIR/.kernel_headers_done
}
binutils()
{
local pkg="binutils-$BINUTILS_VER"
cd $BUILDDIR || exit 1
if [ ! -d $pkg ]; then
tar xfj $SOURCEDISTDIR/$pkg.tar.bz2 -C $BUILDDIR || exit 1
fi
cd $pkg || exit 1
[ ! -d build ] && mkdir build || exit 1
cd build || exit 1
../configure --prefix=$CROSSDIR \
--target=$CROSS_TARGET \
--with-sysroot=$SYSROOT \
--with-build-sysroot=$SYSROOT \
--disable-nls --enable-shared \
--disable-multilib || exit 1
make configure-host && make && make install || exit 1
# Remove unneeded stuff
for f in info man share; do
[ -d $CROSSDIR/$f ] && rm -rf $CROSSDIR/$f
done
cd $BUILDDIR && rm -rf $pkg || exit 1
touch -f $BUILDDIR/.binutils_done
}
glibc_patches()
{
# Apply some required patches for i[56]86-pc-linux-gnu and
# common targets.
$FETCH_CMD http://www.freesa.org/toolchain/patches/glibc-2.7-fixup_for_gcc43-1.patch
$FETCH_CMD http://www.freesa.org/toolchain/patches/glibc-2.7-i586_chk-1.patch
$FETCH_CMD http://www.freesa.org/toolchain/patches/glibc-2.7-libgcc_eh-1.patch
$FETCH_CMD http://svn.exactcode.de/t2/trunk/package/base/glibc/x86-fnstsw.patch
patch -Np1 -i glibc-2.7-fixup_for_gcc43-1.patch || exit 1
patch -Np1 -i glibc-2.7-i586_chk-1.patch || exit 1
patch -Np1 -i glibc-2.7-libgcc_eh-1.patch || exit 1
patch -Np1 -i x86-fnstsw.patch || exit 1
touch -f $BUILDDIR/glibc-$GLIBC_VER/.patches_done
}
gcc()
{
local stage="$1"
local pkg="gcc-$GCC_VER"
local configure_args=
local make_args=
local make_install_args=
local touch_f=
cd $BUILDDIR || exit 1
if [ ! -d $pkg ]; then
tar xfj $SOURCEDISTDIR/$pkg.tar.bz2 -C $BUILDDIR || exit 1
fi
[ ! -d $pkg/build ] && mkdir $pkg/build
cd $pkg/build || exit 1
case $stage in
full)
# gcc with support for C and C++.
touch_f=".gcc_full_done"
make_args="AS_FOR_TARGET=$CROSS_TARGET-as"
make_args="$make_args LD_FOR_TARGET=$CROSS_TARGET-ld"
make_install_args="install"
configure_args="--enable-shared --enable-threads=posix"
configure_args="$configure_args --enable-languages=c,c++"
configure_args="$configure_args --enable-__cxa_atexit"
configure_args="$configure_args --enable-tls"
;;
libgcc)
# Enough to be able to build full glibc.
make all-target-libgcc && make install-target-libgcc || exit 1
rm -rf $SYSROOT/lib/crt* || exit 1
touch -f $BUILDDIR/.gcc_libgcc_done
cd $BUILDDIR/$pkg && rm -rf build
return 0
;;
bootstrap)
# gcc bootstrap
touch_f=".gcc_bootstrap_done"
make_args="all-gcc"
make_install_args="install-gcc"
configure_args="--disable-shared --disable-libmudflap"
configure_args="$configure_args --disable-threads"
configure_args="$configure_args --disable-libssp"
configure_args="$configure_args --enable-languages=c"
;;
*) ;;
esac
../configure --prefix=$CROSSDIR \
--build=$CROSS_HOST --host=$CROSS_HOST \
--target=$CROSS_TARGET \
--with-sysroot=$SYSROOT \
--with-build-sysroot=$SYSROOT \
--disable-multilib \
${configure_args} || exit 1
env LDFLAGS_FOR_TARGET="--sysroot=$SYSROOT" \
CPPFLAGS_FOR_TARGET="--sysroot=$SYSROOT" \
make ${make_args} && make ${make_install_args} || exit 1
# Remove unneeded stuff
for f in info share man; do
[ -d $CROSSDIR/$f ] && rm -rf $CROSSDIR/$f
done
# Do not remove builddir if bootstrap, we want all objs for
# the libgcc pass.
if [ "$stage" != "bootstrap" ]; then
cd $BUILDDIR/$pkg && rm -rf build || exit 1
fi
touch -f $BUILDDIR/$touch_f
}
glibc()
{
local stage="$1"
local pkg="glibc-$GLIBC_VER"
local touch_f=
local cross_binutils="$CROSSDIR/$CROSS_TARGET/bin"
local configure_args=
local CC=
local BUILD_CC=
local RANLIB=
local AR=
cd $BUILDDIR || exit 1
if [ ! -d $pkg ]; then
tar xfj $SOURCEDISTDIR/$pkg.tar.bz2 -C $BUILDDIR || exit 1
fi
cd $pkg || exit 1
[ ! -f .patches_done ] && glibc_patches
[ ! -d build ] && mkdir build
cd build || exit 1
# NPTL support.
echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" >> config.cache
if [ "$KERNEL_ARCH" = "i386" ]; then
echo "CFLAGS+=-march=${CROSS_TARGET%%-*} -mtune=generic" \
> configparms
fi
case $stage in
startup|full)
BUILD_CC=$CROSS_TARGET-gcc
CC=$CROSS_TARGET-gcc
AR=$CROSS_TARGET-ar
RANLIB=$CROSS_TARGET-ranlib
configure_args="${configure_args} --with-binutils=$CROSSDIR/bin"
configure_args="${configure_args} --cache-file=config.cache"
;;
headers)
CC=gcc
configure_args="${configure_args} --with-binutils=$cross_binutils"
configure_args="${configure_args} --disable-sanity-checks"
;;
*) ;;
esac
CC=${CC} BUILD_CC=${BUILD_CC} AR=${AR} RANLIB=${RANLIB} \
../configure --prefix=/usr \
--host=$CROSS_TARGET --build=$CROSS_HOST \
--enable-kernel=2.6.25 --with-tls \
--with-__thread --without-selinux \
--without-gd --without-cvs --disable-profile \
--enable-add-ons \
--with-headers=$SYSROOT/usr/include \
${configure_args} || exit 1
case $stage in
startup)
touch_f=".glibc_startup_done"
make -r -C ../csu objdir=$PWD $PWD/csu/crt1.o || exit 1
make -r -C ../csu objdir=$PWD $PWD/csu/crti.o || exit 1
make -r -C ../csu objdir=$PWD $PWD/csu/crtn.o || exit 1
mkdir -p $SYSROOT/lib || exit 1
cp -f csu/crt1.o csu/crti.o csu/crtn.o $SYSROOT/lib || exit 1
;;
headers)
touch_f=".glibc_headers_done"
make cross-compiling=yes \
install_root=$SYSROOT install-headers || exit 1
cp -v bits/stdio_lim.h $SYSROOT/usr/include/bits || exit 1
touch $SYSROOT/usr/include/gnu/stubs.h || exit 1
cp -v ../nptl/sysdeps/pthread/pthread.h \
$SYSROOT/usr/include || exit 1
if [ "$KERNEL_ARCH" = "i386" ]; then
local bitsdir="nptl/sysdeps/unix/sysv/linux/i386/bits"
cp -v ../$bitsdir/pthreadtypes.h \
$SYSROOT/usr/include/bits || exit 1
fi
;;
full)
touch_f=".glibc_full_done"
make && make install_root=$SYSROOT install || exit 1
;;
esac
if [ "$stage" != "headers" ]; then
cd $BUILDDIR/$pkg && rm -rf build || exit 1
fi
touch -f $BUILDDIR/$touch_f
}
while getopts "b:c:s:" opt; do
case $opt in
b) BUILDDIR=$OPTARG
check_path $BUILDDIR
BUILDDIR=$SANITIZED_DESTDIR
;;
c) CROSSDIR=$OPTARG
check_path $CROSSDIR
CROSSDIR=$SANITIZED_DESTDIR
;;
s) SOURCEDISTDIR=$OPTARG
check_path $SOURCEDISTDIR
SOURCEDISTDIR=$SANITIZED_DESTDIR
;;
--) shift; break;;
esac
done
shift $(($OPTIND - 1))
[ $# -ne 1 ] && usage
if [ -z "$1" ]; then
echo "ERROR: missing target triplet."
exit 1
else
CROSS_TARGET=$1
case $CROSS_TARGET in
i686-pc-linux-gnu)
KERNEL_ARCH=i386
CROSS_HOST="$(uname -m)-unknown-linux-gnu"
;;
x86-64-unknown-linux-gnu)
KERNEL_ARCH=x86_64
CROSS_HOST="$(uname -m)-pc-linux-gnu"
;;
*)
echo "ERROR: unknown target triplet $CROSS_TARGET."
exit 1
;;
esac
fi
CROSSDIR=$CROSSDIR/$CROSS_TARGET
SYSROOT=$CROSSDIR/sysroot
[ ! -d $SYSROOT/usr ] && mkdir -p $SYSROOT/usr
[ ! -d $BUILDDIR ] && mkdir -p $BUILDDIR
[ ! -d $SOURCEDISTDIR ] && mkdir -p $SOURCEDISTDIR
unset CFLAGS CXXFLAGS CC CXX AR AS RANLIB LD_STRIP
unset LD_LIBRARY_PATH LD_RUN_PATH
export PATH="$CROSSDIR/bin:/bin:/usr/bin"
fetch_sources
if [ ! -f $BUILDDIR/.kernel_headers_done ]; then
echo "Installing kernel headers..."
kernel_headers
fi
if [ ! -f $BUILDDIR/.binutils_done ]; then
echo "Installing binutils..."
binutils
fi
if [ ! -f $BUILDDIR/.glibc_headers_done ]; then
echo "Installing glibc headers..."
glibc headers
fi
if [ ! -f $BUILDDIR/.gcc_bootstrap_done ]; then
echo "Installing gcc (bootstrap)..."
gcc bootstrap
fi
if [ ! -f $BUILDDIR/.glibc_startup_done ]; then
echo "Installing glibc (startup)..."
glibc startup
fi
if [ ! -f $BUILDDIR/.gcc_libgcc_done ]; then
echo "Installing gcc (libgcc)..."
gcc libgcc
fi
if [ ! -f $BUILDDIR/.glibc_full_done ]; then
echo "Installing glibc (full)..."
glibc full
fi
if [ ! -f $BUILDDIR/.gcc_full_done ]; then
echo "Installing gcc (full)..."
gcc full
fi
[ -d $BUILDDIR ] && rm -rf $BUILDDIR
echo "Finished. Toolchain for $CROSS_TARGET at $CROSSDIR."
exit 0

View file

@ -0,0 +1,82 @@
#-
# Copyright (c) 2008-2009 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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.
#-
#
# Applies to the build directory all patches found in PATCHESDIR
# (templates/$pkgname/patches).
#
apply_tmpl_patches()
{
local patch_files args patch i
[ ! -d $PATCHESDIR ] && return 0
for f in $(echo $PATCHESDIR/*); do
if $(echo $f|grep -q '.args'); then
continue
fi
patch_files="$patch_files $f"
done
for i in ${patch_files}; do
args="-Np0"
patch=$(basename $i)
if [ -f $PATCHESDIR/$patch.args ]; then
args=$(cat $PATCHESDIR/$patch.args)
fi
cp -f $i $wrksrc
# Try to guess if its a compressed patch.
if $(echo $i|grep -q '.diff.gz'); then
gunzip $wrksrc/$patch
patch=${patch%%.gz}
elif $(echo $i|grep -q '.patch.gz'); then
gunzip $wrksrc/$patch
patch=${patch%%.gz}
elif $(echo $i|grep -q '.diff.bz2'); then
bunzip2 $wrksrc/$patch
patch=${patch%%.bz2}
elif $(echo $i|grep -q '.patch.bz2'); then
bunzip2 $wrksrc/$patch
patch=${patch%%.bz2}
elif $(echo $i|grep -q '.diff'); then
:
elif $(echo $i|grep -q '.patch'); then
:
else
msg_warn "unknown patch type: $i."
continue
fi
cd $wrksrc && patch -s ${args} < $patch 2>/dev/null
if [ $? -eq 0 ]; then
msg_normal "Patch applied: $patch."
else
msg_error "couldn't apply patch: $patch."
fi
done
touch -f $XBPS_APPLYPATCHES_DONE
}

View file

@ -0,0 +1,172 @@
#-
# Copyright (c) 2008-2009 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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.
#-
. ${XBPS_SHUTILSDIR}/tmpl_funcs.sh
#
# Installs a pkg by reading its build template file.
#
install_pkg()
{
local pkg=
local curpkgn="$1"
local cdestdir=
local cur_tmpl="$XBPS_TEMPLATESDIR/$curpkgn/template"
if [ -z $cur_tmpl -o ! -f $cur_tmpl ]; then
msg_error "cannot find $cur_tmpl template build file."
fi
#
# If we are being invoked through the chroot, re-read config file
# to get correct stuff.
#
if [ -n "$in_chroot" ]; then
check_config_vars
set_defvars
fi
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
reset_tmpl_vars
. $cur_tmpl
pkg="$curpkgn-$version"
#
# If we are the originator package save the path this template in
# other var for future use.
#
[ -z "$origin_tmpl" ] && origin_tmpl=$pkgname
if [ -z "$base_chroot" -a -z "$in_chroot" ]; then
. $XBPS_SHUTILSDIR/chroot.sh
[ -n "$install_destdir_target" ] && cdestdir=yes
xbps_chroot_handler install $curpkgn $cdestdir
return $?
fi
#
# We are going to install a new package.
#
setup_tmpl $curpkgn
#
# Install dependencies required by this package.
#
if [ -z "$doing_deps" ]; then
. $XBPS_SHUTILSDIR/builddep_funcs.sh
install_dependencies_pkg $pkg
#
# At this point all required deps are installed, and
# only remaining is the origin template; install it.
#
unset doing_deps
reset_tmpl_vars
setup_tmpl $curpkgn
fi
#
# Fetch, extract, build and install into the destination directory.
#
. $XBPS_SHUTILSDIR/fetch_funcs.sh
fetch_distfiles
if [ ! -f "$XBPS_EXTRACT_DONE" ]; then
. $XBPS_SHUTILSDIR/extract_funcs.sh
extract_distfiles
fi
if [ ! -f "$XBPS_CONFIGURE_DONE" ]; then
. $XBPS_SHUTILSDIR/configure_funcs.sh
configure_src_phase
fi
if [ ! -f "$XBPS_BUILD_DONE" ]; then
. $XBPS_SHUTILSDIR/build_funcs.sh
build_src_phase
fi
. $XBPS_SHUTILSDIR/install_funcs.sh
install_src_phase $curpkgn
# Always write metadata to package's destdir.
. $XBPS_SHUTILSDIR/metadata.sh
xbps_write_metadata_pkg $curpkgn
#
# Do not stow package if it wasn't requested.
#
if [ -z "$install_destdir_target" ]; then
. $XBPS_SHUTILSDIR/stow_funcs.sh
stow_pkg $curpkgn
fi
}
#
# Lists files installed by a package.
#
list_pkg_files()
{
local pkg="$1"
local ver=
[ -z $pkg ] && msg_error "unexistent package, aborting."
ver=$($XBPS_REGPKGDB_CMD version $pkg)
[ -z "$ver" ] && msg_error "$pkg is not installed."
cat $XBPS_PKGMETADIR/$pkg/flist
}
#
# Removes a currently installed package (unstow + removed from destdir).
#
remove_pkg()
{
local pkg="$1" subpkg ver
[ -z $pkg ] && msg_error "unexistent package, aborting."
if [ ! -f "$XBPS_TEMPLATESDIR/$pkg/template" ]; then
msg_error "cannot find template build file."
fi
. $XBPS_TEMPLATESDIR/$pkg/template
for f in ${subpackages}; do
if [ "$pkg" = "${pkgname}-${f}" ]; then
pkgname=${pkg}
break;
fi
done
ver=$($XBPS_REGPKGDB_CMD version $pkg)
[ -z "$ver" ] && msg_error "$pkg is not installed."
. $XBPS_SHUTILSDIR/stow_funcs.sh
unstow_pkg $pkg
if [ $? -eq 0 -a -d $XBPS_DESTDIR/$pkg-${ver%_${revision}} ]; then
rm -rf $XBPS_DESTDIR/$pkg-${ver%_${revision}}
fi
return $?
}

View file

@ -0,0 +1,170 @@
#-
# Copyright (c) 2008-2009 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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.
#-
. ${XBPS_SHUTILSDIR}/builddep_funcs.sh
stow_pkg()
{
local pkg="$1"
local subpkg spkgrev
for subpkg in ${subpackages}; do
if [ "${pkg}" != "${sourcepkg}" ] && \
[ "${pkg}" != "${sourcepkg}-${subpkg}" ]; then
continue
fi
if [ -n "$revision" ]; then
spkgrev="${sourcepkg}-${subpkg}-${version}_${revision}"
else
spkgrev="${sourcepkg}-${subpkg}-${version}"
fi
check_installed_pkg ${spkgrev}
[ $? -eq 0 ] && continue
if [ ! -f $XBPS_TEMPLATESDIR/${sourcepkg}/${subpkg}.template ]; then
msg_error "Cannot find subpackage template!"
fi
unset revision
. $XBPS_TEMPLATESDIR/${sourcepkg}/${subpkg}.template
pkgname=${sourcepkg}-${subpkg}
set_tmpl_common_vars
stow_pkg_real ${pkgname}
run_template ${sourcepkg}
if [ "${pkg}" = "${sourcepkg}-${subpkg}" ]; then
#
# If it's a subpackage, just remove sourcepkg from
# destdir and return, we are done.
#
rm -rf $XBPS_DESTDIR/${spkgrev}
return $?
fi
done
stow_pkg_real ${pkg} ${automatic}
return $?
}
#
# Stow a package, i.e copy files from destdir into masterdir
# and register pkg into the package database.
#
stow_pkg_real()
{
local pkg="$1"
local i lver regpkgdb_flags
[ -z "$pkg" ] && return 2
if [ $(id -u) -ne 0 ] && [ ! -w $XBPS_MASTERDIR ]; then
msg_error "cannot stow $pkg! (permission denied)"
fi
if [ "$build_style" = "meta-template" ]; then
[ ! -d ${DESTDIR} ] && mkdir -p ${DESTDIR}
fi
[ -n "$stow_flag" ] && run_template $pkg
cd ${DESTDIR} || exit 1
# Copy files into masterdir.
for i in $(echo *); do
if [ "$i" = "INSTALL" -o "$i" = "REMOVE" -o \
"$i" = "files.plist" -o "$i" = "props.plist" ]; then
continue
fi
cp -a ${i} $XBPS_MASTERDIR
done
#
# Register pkg in plist file.
#
if [ -n "$revision" ]; then
lver="${version}_${revision}"
else
lver="${version}"
fi
$XBPS_REGPKGDB_CMD register $pkg $lver "$short_desc" || exit 1
return $?
}
#
# Unstow a package, i.e remove its files from masterdir and
# unregister pkg from package database.
#
unstow_pkg()
{
local f ver pkg="$1"
[ -z $pkg ] && msg_error "template wasn't specified?"
if [ $(id -u) -ne 0 ] && \
[ ! -w $XBPS_MASTERDIR ]; then
msg_error "cannot unstow $pkg! (permission denied)"
fi
run_template $pkg
ver=$($XBPS_REGPKGDB_CMD version $pkg)
if [ -z "$ver" ]; then
msg_error "$pkg is not installed."
fi
cd $XBPS_PKGMETADIR/$pkg || exit 1
if [ "$build_style" = "meta-template" ]; then
# If it's a metapkg, do nothing.
:
elif [ ! -f flist ]; then
msg_error "$pkg is incomplete, missing flist."
elif [ ! -w flist ]; then
msg_error "$pkg cannot be removed (permission denied)."
elif [ -s flist ]; then
# Remove installed files.
for f in $(cat flist); do
if [ -f $XBPS_MASTERDIR/$f -o -h $XBPS_MASTERDIR/$f ]; then
rm $XBPS_MASTERDIR/$f >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Removing file: $f"
fi
fi
done
for f in $(cat flist); do
if [ -d $XBPS_MASTERDIR/$f ]; then
rmdir $XBPS_MASTERDIR/$f >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Removing directory: $f"
fi
fi
done
fi
# Remove metadata dir.
rm -rf $XBPS_PKGMETADIR/$pkg
# Unregister pkg from plist file.
$XBPS_REGPKGDB_CMD unregister $pkg $ver
return $?
}

View file

@ -0,0 +1,233 @@
#-
# Copyright (c) 2008-2009 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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.
#-
#
# Shows info about a template.
#
info_tmpl()
{
local i=
for f in $(echo $XBPS_COMMONVARSDIR/*.sh); do
[ -r ${f} ] && . ${f}
done
echo "pkgname: $pkgname"
echo "version: $version"
[ -n "$revision" ] && echo "revision: $revision"
for i in "${distfiles}"; do
[ -n "$i" ] && echo "distfile: $i"
done
[ -n "$checksum" ] && echo "checksum: $checksum"
echo "maintainer: $maintainer"
echo "build_style: $build_style"
echo "short_desc: $short_desc"
echo "$long_desc"
echo
. $XBPS_SHUTILSDIR/builddep_funcs.sh
run_template $pkgname
check_build_depends_pkg
if [ $? -eq 0 ]; then
echo "This package requires the following dependencies to be built:"
for i in ${build_depends}; do
echo " $i"
done
fi
}
#
# Resets all vars used by a template.
#
reset_tmpl_vars()
{
local v=
local TMPL_VARS="pkgname distfiles configure_args configure_env \
make_build_args make_install_args build_style \
short_desc maintainer long_desc checksum wrksrc \
make_cmd base_chroot register_shell keep_empty_dirs \
make_build_target configure_script noextract nofetch \
pre_configure pre_build pre_install build_depends \
post_configure post_build post_install nostrip \
make_install_target version revision essential \
sgml_catalogs xml_catalogs xml_entries sgml_entries \
disable_parallel_build run_depends cross_compiler \
only_for_archs conf_files keep_libtool_archives \
noarch subpackages sourcepkg gtk_iconcache_dirs \
abi_depends api_depends triggers openrc_services \
replaces XBPS_EXTRACT_DONE XBPS_CONFIGURE_DONE \
XBPS_BUILD_DONE XBPS_INSTALL_DONE FILESDIR DESTDIR \
SRCPKGDESTDIR PATCHESDIR"
for v in ${TMPL_VARS}; do
eval unset "$v"
done
. $XBPS_SHUTILSDIR/buildvars_funcs.sh
unset_build_vars
}
#
# Reads a template file and setups required variables for operations.
#
setup_tmpl()
{
local pkg="$1"
[ -z "$pkg" ] && msg_error "missing package name after target."
for f in $(echo $XBPS_COMMONVARSDIR/*.sh); do
[ -r ${f} ] && . ${f}
done
if [ -f "$XBPS_TEMPLATESDIR/$pkg/template" ]; then
if [ "$pkgname" != "$pkg" ]; then
reset_tmpl_vars
. $XBPS_TEMPLATESDIR/$pkg/template
fi
prepare_tmpl
else
msg_error "cannot find '$pkg' template build file."
fi
}
Add_dependency()
{
local type="$1"
local pkgname="$2"
local minver="$3"
case "$type" in
build|full|run) ;;
*) msg_error "Unknown dependency type for $pkgname." ;;
esac
if [ -f $XBPS_TEMPLATESDIR/$pkgname/$pkgname.depends ]; then
. $XBPS_TEMPLATESDIR/$pkgname/$pkgname.depends
elif [ -f $XBPS_TEMPLATESDIR/$pkgname/depends ]; then
. $XBPS_TEMPLATESDIR/$pkgname/depends
fi
if [ "$type" = "full" -o "$type" = "build" ]; then
if [ -z "$minver" -a -z "$api_depends" ]; then
build_depends="${build_depends} $pkgname-0"
elif [ -z "$minver" -a -n "$api_depends" ]; then
build_depends="${build_depends} $pkgname-$api_depends"
else
build_depends="${build_depends} $pkgname-$minver"
fi
fi
if [ "$type" = "full" -o "$type" = "run" ]; then
if [ -z "$minver" -a -z "$abi_depends" ]; then
run_depends="${run_depends} $pkgname-0"
elif [ -z "$minver" -a -n "$abi_depends" ]; then
run_depends="${run_depends} $pkgname-$abi_depends"
else
run_depends="${run_depends} $pkgname-$minver"
fi
fi
unset abi_depends api_depends
}
#
# Checks some vars used in templates and sets some of them required.
#
prepare_tmpl()
{
local REQ_VARS i found
#
# There's nothing of interest if we are a meta template.
#
if [ "$build_style" = "meta-template" ]; then
set_tmpl_common_vars
return 0
fi
REQ_VARS="pkgname version build_style short_desc long_desc"
# Check if required vars weren't set.
for i in ${REQ_VARS}; do
eval val="\$$i"
if [ -z "$val" -o -z "$i" ]; then
msg_error "\"$i\" not set on $pkgname template."
fi
done
for i in ${only_for_archs}; do
[ "$i" = "$xbps_machine" ] && found=si && break
done
if [ -n "${only_for_archs}" -a -z "$found" ]; then
msg_error "this package is only for: ${only_for_archs}."
fi
unset XBPS_EXTRACT_DONE XBPS_APPLYPATCHES_DONE
unset XBPS_CONFIGURE_DONE XBPS_BUILD_DONE XBPS_INSTALL_DONE
[ -z "$wrksrc" ] && wrksrc="$pkgname-$version"
wrksrc="$XBPS_BUILDDIR/$wrksrc"
XBPS_EXTRACT_DONE="$wrksrc/.xbps_extract_done"
XBPS_APPLYPATCHES_DONE="$wrksrc/.xbps_applypatches_done"
XBPS_CONFIGURE_DONE="$wrksrc/.xbps_configure_done"
XBPS_BUILD_DONE="$wrksrc/.xbps_build_done"
XBPS_INSTALL_DONE="$wrksrc/.xbps_install_done"
set_tmpl_common_vars
if [ -z "$in_chroot" ]; then
export PATH="$XBPS_MASTERDIR/bin:$XBPS_MASTERDIR/sbin"
export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
export PATH="$PATH:$XBPS_MASTERDIR/usr/sbin"
export PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin"
export PATH="$PATH:/usr/local/sbin"
fi
}
set_tmpl_common_vars()
{
[ -z "$pkgname" ] && return 1
FILESDIR=${XBPS_TEMPLATESDIR}/${pkgname}/files
PATCHESDIR=${XBPS_TEMPLATESDIR}/${pkgname}/patches
DESTDIR=${XBPS_DESTDIR}/${pkgname}-${version}
if [ -z "${sourcepkg}" ]; then
sourcepkg=${pkgname}
fi
SRCPKGDESTDIR=${XBPS_DESTDIR}/${sourcepkg}-${version}
}
run_template()
{
local pkg="$1"
if [ "$pkgname" != "$pkg" ]; then
reset_tmpl_vars
. $XBPS_TEMPLATESDIR/$pkg/template
set_tmpl_common_vars
fi
}

9
xbps-src/vars.mk Normal file
View file

@ -0,0 +1,9 @@
# Common variables.
PREFIX ?= /usr/local
SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
#
# The following two vars shouldn't be specified with DESTDIR!
#
SHAREDIR ?= $(PREFIX)/share/xbps-src/shutils
ETCDIR ?= $(PREFIX)/etc

288
xbps-src/xbps-src.sh.in Normal file
View file

@ -0,0 +1,288 @@
#!/bin/sh
#
# Copyright (c) 2008-2009 Juan Romero Pardines.
# 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 ``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 THE AUTHOR 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.
#-
trap "echo && exit 1" INT QUIT
: ${XBPS_CONFIG_FILE:=@@XBPS_INSTALL_ETCDIR@@/xbps-src.conf}
: ${progname:=$(basename $0)}
: ${fakeroot_cmd:=fakeroot}
: ${xbps_machine:=$(uname -m)}
usage()
{
cat << _EOF
$progname: [-C] [-c <config_file>] [-u] <target> <pkg>
Targets:
build <pkg> Build a package (fetch + extract + configure + build).
build-pkg [<pkg>|all] Build a binary package from <pkg>.
Package must be installed into destdir. If the <all>
keyword is used instead of <pkg>, all packages
currently installed will be used.
chroot Enter to the chroot in masterdir.
configure <pkg> Configure a package (fetch + extract + configure).
extract <pkg> Extract distribution file(s) into build directory.
fetch <pkg> Download distribution file(s).
info <pkg> Show information about <pkg>.
install-destdir <pkg> build + install into destdir.
install <pkg> install-destdir + stow.
list List installed packages in masterdir.
listfiles <pkg> List installed files from <pkg>.
remove <pkg> Remove package completely (destdir + masterdir).
stow <pkg> Copy <pkg> files from destdir into masterdir and
register package in database.
unstow <pkg> Remove <pkg> files from masterdir and unregister
package from database.
Options:
-C Do not remove build directory after successful installation.
-c Path to global configuration file:
if not specified @@XBPS_INSTALL_ETCDIR@@/xbps-src.conf is used.
-u Update the checksum in template file if used in 'fetch' target.
_EOF
exit 1
}
check_path()
{
eval local orig="$1"
case "$orig" in
/) ;;
/*) orig="${orig%/}" ;;
*) orig="$(pwd)/${orig%/}" ;;
esac
path_fixed="$orig"
}
run_file()
{
local file="$1"
check_path "$file"
. $path_fixed
}
set_defvars()
{
local DDIRS i
: ${XBPS_TEMPLATESDIR:=$XBPS_DISTRIBUTIONDIR/templates}
: ${XBPS_TRIGGERSDIR:=$XBPS_DISTRIBUTIONDIR/triggers}
: ${XBPS_HELPERSDIR:=$XBPS_DISTRIBUTIONDIR/helpers}
: ${XBPS_COMMONVARSDIR:=$XBPS_DISTRIBUTIONDIR/common}
: ${XBPS_DBDIR:=$XBPS_MASTERDIR/var/db/xbps}
: ${XBPS_META_PATH:=$XBPS_DBDIR/}
: ${XBPS_PKGMETADIR:=$XBPS_DBDIR/metadata}
: ${XBPS_SHUTILSDIR:=@@XBPS_INSTALL_SHAREDIR@@}
DDIRS="XBPS_TEMPLATESDIR XBPS_TRIGGERSDIR XBPS_HELPERSDIR"
DDIRS="$DDIRS XBPS_COMMONVARSDIR XBPS_SHUTILSDIR"
for i in ${DDIRS}; do
eval val="\$$i"
[ ! -d "$val" ] && msg_error "cannot find $i, aborting."
done
XBPS_REGPKGDB_CMD="xbps-pkgdb -r $XBPS_MASTERDIR"
XBPS_BIN_CMD="xbps-bin -r $XBPS_MASTERDIR"
}
#
# Checks that all required variables specified in the configuration
# file are properly working.
#
check_config_vars()
{
local cffound f
if [ -z "$config_file_specified" ]; then
config_file_paths="$XBPS_CONFIG_FILE ./etc/xbps-src.conf"
for f in $config_file_paths; do
[ -f $f ] && XBPS_CONFIG_FILE=$f && \
cffound=yes && break
done
[ -z "$cffound" ] && msg_error "cannot find a config file"
fi
run_file ${XBPS_CONFIG_FILE}
XBPS_CONFIG_FILE=$path_fixed
if [ ! -f "$XBPS_CONFIG_FILE" ]; then
msg_error "cannot find configuration file: $XBPS_CONFIG_FILE"
fi
local XBPS_VARS="XBPS_MASTERDIR XBPS_DESTDIR XBPS_BUILDDIR \
XBPS_SRCDISTDIR"
for f in ${XBPS_VARS}; do
eval val="\$$f"
[ -z "$val" ] && msg_error "'$f' not set in configuration file"
if [ ! -d "$val" ]; then
mkdir "$val"
[ $? -ne 0 ] && msg_error "couldn't create '$f' directory"
fi
done
export PATH="$PATH:@@XBPS_INSTALL_PREFIX@@/sbin"
}
#
# main()
#
while getopts "Cc:u" opt; do
case $opt in
C) dontrm_builddir=yes;;
c) config_file_specified=yes; XBPS_CONFIG_FILE="$OPTARG";;
u) update_checksum=yes;;
--) shift; break;;
esac
done
shift $(($OPTIND - 1))
[ $# -eq 0 -o $# -gt 2 ] && usage
target="$1"
if [ -z "$target" ]; then
echo "=> ERROR: missing target."
usage
fi
#
# Check configuration vars before anyting else, and set defaults vars.
#
check_config_vars
set_defvars
. $XBPS_SHUTILSDIR/common_funcs.sh
# Main switch
case "$target" in
build|configure)
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
setup_tmpl $2
if [ -z "$base_chroot" -a -z "$in_chroot" ]; then
. $XBPS_SHUTILSDIR/chroot.sh
if [ "$target" = "build" ]; then
xbps_chroot_handler build $2
else
xbps_chroot_handler configure $2
fi
else
. $XBPS_SHUTILSDIR/fetch_funcs.sh
fetch_distfiles $2
if [ ! -f "$XBPS_EXTRACT_DONE" ]; then
. $XBPS_SHUTILSDIR/extract_funcs.sh
extract_distfiles $2
fi
if [ "$target" = "configure" ]; then
. $XBPS_SHUTILSDIR/configure_funcs.sh
configure_src_phase $2
else
if [ ! -f "$XBPS_CONFIGURE_DONE" ]; then
. $XBPS_SHUTILSDIR/configure_funcs.sh
configure_src_phase $2
fi
. $XBPS_SHUTILSDIR/build_funcs.sh
build_src_phase $2
fi
fi
;;
build-pkg)
. $XBPS_SHUTILSDIR/make-binpkg.sh
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
if [ "$2" = "all" ]; then
for f in $($XBPS_BIN_CMD list|awk '{print $1}'); do
pkg=$(xbps-pkgdb getpkgname $f)
setup_tmpl ${pkg}
xbps_make_binpkg ${pkg}
reset_tmpl_vars
done
else
setup_tmpl $2
xbps_make_binpkg $2
fi
;;
chroot)
. $XBPS_SHUTILSDIR/chroot.sh
xbps_chroot_handler chroot dummy
;;
extract|fetch|info)
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
setup_tmpl $2
if [ "$target" = "info" ]; then
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
info_tmpl $2
exit $?
fi
if [ "$target" = "fetch" ]; then
. $XBPS_SHUTILSDIR/fetch_funcs.sh
fetch_distfiles $2 $update_checksum
exit $?
fi
. $XBPS_SHUTILSDIR/extract_funcs.sh
extract_distfiles $2
;;
install|install-destdir)
[ -z "$2" ] && msg_error "missing package name after target."
[ "$target" = "install-destdir" ] && install_destdir_target=yes
. $XBPS_SHUTILSDIR/pkgtarget_funcs.sh
install_pkg $2
;;
list|listfiles)
if [ "$target" = "list" ]; then
$XBPS_BIN_CMD list
exit $?
fi
. $XBPS_SHUTILSDIR/pkgtarget_funcs.sh
list_pkg_files $2
;;
remove)
[ -z "$2" ] && msg_error "missing package name after target."
. $XBPS_SHUTILSDIR/pkgtarget_funcs.sh
remove_pkg $2
;;
stow)
stow_flag=yes
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
setup_tmpl $2
. $XBPS_SHUTILSDIR/stow_funcs.sh
stow_pkg $2
;;
unstow)
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
setup_tmpl $2
. $XBPS_SHUTILSDIR/stow_funcs.sh
unstow_pkg $2
;;
*)
echo "=> ERROR: invalid target: $target."
usage
esac
# Agur
exit $?