--- makepkg 2009-01-21 04:20:05.000000000 +0100 +++ makepkg-split 2009-01-21 14:22:40.000000000 +0100 @@ -42,8 +42,11 @@ startdir="$PWD" srcdir="$startdir/src" pkgdir="$startdir/pkg" +# add support for separate debug packages +dbgdir="$startdir/dbg" -packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge') +# add support for separate debug packages +packaging_options=('strip' 'splitdbg' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge') other_options=('ccache' 'distcc' 'makeflags' 'force') splitpkg_overrides=('pkgdesc' 'license' 'groups' 'depends' 'optdepends' 'provides' \ 'conflicts' 'replaces' 'backup' 'options' 'install') @@ -828,6 +831,60 @@ done fi + # add support for splitting debug files + if [ "$(check_option splitdbg)" = "y" ] || [ "$SPLIT_DBG" = "1" ]; then + msg2 "$(gettext "Moving debugging symbols from binaries and libraries into separate file...")" + local binary + if [ -z "${STRIP_DIRS[*]}" ]; then + # fall back to default value + STRIP_DIRS=(bin lib sbin usr/{bin,lib,sbin,local/{bin,lib,sbin}} + opt/*/{bin,lib,sbin}) + fi + find ${STRIP_DIRS[@]} -type f 2>/dev/null | while read binary ; do + case "$(file -biz "$binary")" in + *application/x-sharedlib*) # Libraries (.so) + /usr/bin/objcopy --only-keep-debug "$binary" "$binary.debug" + /usr/bin/strip --strip-debug "$binary" + debug_basebinary=`echo "$binary" | awk -F '/' '{print $NF}'` + debug_symbolfile=`echo "$binary.debug" | awk -F '/' '{print $NF}'` + debug_basedir=`dirname "$binary.debug"` + pushd $debug_basedir &>/dev/null + /usr/bin/objcopy --add-gnu-debuglink="$debug_symbolfile" "$debug_basebinary" + popd &>/dev/null + if [ ! -d "${dbgdir}/usr/lib/debug/${debug_basedir}" ]; then + mkdir -p "${dbgdir}/usr/lib/debug/${debug_basedir}" + fi + mv "$binary.debug" "${dbgdir}/usr/lib/debug/${debug_basedir}/$debug_symbolfile";; + *application/x-archive*) # Libraries (.a) + /usr/bin/objcopy --only-keep-debug "$binary" "$binary.debug" + /usr/bin/strip --strip-debug "$binary" + debug_basebinary=`echo "$binary" | awk -F '/' '{print $NF}'` + debug_symbolfile=`echo "$binary.debug" | awk -F '/' '{print $NF}'` + debug_basedir=`dirname "$binary.debug"` + pushd $debug_basedir &>/dev/null + /usr/bin/objcopy --add-gnu-debuglink="$debug_symbolfile" "$debug_basebinary" + popd &>/dev/null + if [ ! -d "${dbgdir}/usr/lib/debug/${debug_basedir}" ]; then + mkdir -p "${dbgdir}/usr/lib/debug/${debug_basedir}" + fi + mv "$binary.debug" "${dbgdir}/usr/lib/debug/${debug_basedir}/$debug_symbolfile";; + *application/x-executable*) # Binaries + /usr/bin/objcopy --only-keep-debug "$binary" "$binary.debug" + /usr/bin/strip "$binary" + debug_basebinary=`echo "$binary" | awk -F '/' '{print $NF}'` + debug_symbolfile=`echo "$binary.debug" | awk -F '/' '{print $NF}'` + debug_basedir=`dirname "$binary.debug"` + pushd $debug_basedir &>/dev/null + /usr/bin/objcopy --add-gnu-debuglink="$debug_symbolfile" "$debug_basebinary" + popd &>/dev/null + if [ ! -d "${dbgdir}/usr/lib/debug/${debug_basedir}" ]; then + mkdir -p "${dbgdir}/usr/lib/debug/${debug_basedir}" + fi + mv "$binary.debug" "${dbgdir}/usr/lib/debug/${debug_basedir}/$debug_symbolfile";; + esac + done + fi + if [ "$(check_option strip)" = "y" -a -n "${STRIP_DIRS[*]}" ]; then msg2 "$(gettext "Stripping debugging symbols from binaries and libraries...")" local binary @@ -982,6 +1039,100 @@ shopt -u nullglob } +create_debug_package() { + if [ -z "$1" ]; then + nameofpkg="$pkgname" + else + nameofpkg="$1" + fi + + if [ ! -d "$dbgdir" ]; then + error "$(gettext "Missing pkg/ directory.")" + plain "$(gettext "Aborting...")" + exit 1 # $E_MISSING_PKGDIR + fi + + cd "$dbgdir" + msg "$(gettext "Creating package with debug symbols...")" + + local builddate=$(date -u "+%s") + if [ -n "$PACKAGER" ]; then + local packager="$PACKAGER" + else + local packager="Unknown Packager" + fi + local size=$(du -sk | awk '{print $1 * 1024}') + + # write the .PKGINFO file + msg2 "$(gettext "Generating .PKGINFO file...")" + echo "# Generated by makepkg $myver" >.PKGINFO + if [ "$INFAKEROOT" -eq 1 ]; then + echo "# using $(fakeroot -v)" >>.PKGINFO + fi + echo "# $(LC_ALL=C date -u)" >>.PKGINFO + echo "pkgname = $nameofpkg-debug" >>.PKGINFO + echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO + echo "pkgdesc = $pkgdesc (Debug Symbols)" >>.PKGINFO + echo "url = $url" >>.PKGINFO + echo "builddate = $builddate" >>.PKGINFO + echo "packager = $packager" >>.PKGINFO + echo "size = $size" >>.PKGINFO + if [ -n "$CARCH" ]; then + echo "arch = $CARCH" >>.PKGINFO + fi + if [ "$(check_option force)" = "y" ]; then + echo "force = true" >> .PKGINFO + fi + + local it + for it in "${license[@]}"; do + echo "license = $it" >>.PKGINFO + done + + for it in "${packaging_options[@]}"; do + local ret="$(check_option $it)" + if [ "$ret" != "?" ]; then + if [ "$ret" = "y" ]; then + echo "makepkgopt = $it" >>.PKGINFO + else + echo "makepkgopt = !$it" >>.PKGINFO + fi + fi + done + + # TODO maybe remove this at some point + # warn if license array is not present or empty + if [ -z "$license" ]; then + warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT" + plain "$(gettext "Example for GPL'ed software: license=('GPL').")" + fi + + local comp_files=".PKGINFO" + + # tar it up + msg2 "$(gettext "Compressing package...")" + + local TAR_OPT + case "$PKGEXT" in + *tar.gz) TAR_OPT="z" ;; + *tar.bz2) TAR_OPT="j" ;; + *) warning "$(gettext "'%s' is not a valid archive extension.")" \ + "$PKGEXT" ;; + esac + + local pkg_file="$PKGDEST/${nameofpkg}-debug-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" + + # when fileglobbing, we want * in an empty directory to expand to + # the null string rather than itself + shopt -s nullglob + + if ! bsdtar -c${TAR_OPT}f "$pkg_file" $comp_files *; then + error "$(gettext "Failed to create package file.")" + exit 1 # TODO: error code + fi + shopt -u nullglob +} + create_xdelta() { if [ "$(check_buildenv xdelta)" != "y" ]; then return @@ -1370,11 +1521,13 @@ ARGLIST=$@ # Parse Command Line Options. -OPT_SHORT="AbcCdefFghiLmop:rRsV" +# add support for separate debug packages +OPT_SHORT="AbcCdefFghiLmop:rRstV" OPT_LONG="allsource,asroot,ignorearch,builddeps,clean,cleancache,nodeps" OPT_LONG="$OPT_LONG,noextract,force,forcever:,geninteg,help,holdver" OPT_LONG="$OPT_LONG,install,log,nocolor,nobuild,rmdeps,repackage,source" -OPT_LONG="$OPT_LONG,syncdeps,version,config:" +# add support for separate debug packages +OPT_LONG="$OPT_LONG,syncdeps,splitdbg,version,config:" # Pacman Options OPT_LONG="$OPT_LONG,noconfirm,noprogressbar" OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@" || echo 'PARSE_OPTIONS FAILED')" @@ -1415,6 +1568,8 @@ -R|--repackage) REPKG=1 ;; --source) SOURCEONLY=1 ;; -s|--syncdeps) DEP_BIN=1 ;; + # add support for separate debug packages + -t|--splitdbg) SPLIT_DBG=1 ;; -h|--help) usage; exit 0 ;; # E_OK -V|--version) version; exit 0 ;; # E_OK @@ -1667,20 +1822,51 @@ if [ "$PKGFUNC" -eq 0 ]; then if [ "$REPKG" -eq 0 ]; then run_build + if [ "$(check_option splitdbg)" = "y" ] || [ "$SPLIT_DBG" = "1" ]; then + tidy_install + fi fi else run_package tidy_install fi - create_package + + # add support for separate debug packages + if [ "$(check_option splitdbg)" = "y" ] || [ "$SPLIT_DBG" = "1" ]; then + create_package + # second check, if there are any files + check_dbg_files=`find $dbgdir/ -name "*.debug"` + if [ -z "$check_dbg_files" ]; then + msg2 "$(gettext "No .debug files found, skipping creation of the debug pkg...")" + else + create_debug_package + fi + else + create_package + fi else for pkg in ${pkgname[@]}; do - pkgdir="$pkgdir/$pkg" + pkgdir="$pkgdir/pkg_${pkg}" mkdir -p "$pkgdir" + dbgdir="$startdir/dbg/dbg_${pkg}" + [ ! -d "$dbgdir" ] && mkdir -p "$dbgdir" backup_package_variables run_package $pkg tidy_install - create_package $pkg + + # add support for separate debug packages + if [ "$(check_option splitdbg)" = "y" ] || [ "$SPLIT_DBG" = "1" ]; then + create_package $pkg + # second check, if there are any files + check_dbg_files=`find $dbgdir/ -name "*.debug"` + if [ -z "$check_dbg_files" ]; then + msg2 "$(gettext "No .debug files found, skipping creation of the debug pkg...")" + else + create_debug_package $pkg + fi + else + create_package $pkg + fi restore_package_variables pkgdir="${pkgdir%/*}" done @@ -1769,6 +1955,8 @@ rm -rf "$pkgdir" fi mkdir -p "$pkgdir" + # add support for separate debug packages + mkdir -p "$dbgdir" cd "$startdir" # if we are root or if fakeroot is not enabled, then we don't use it @@ -1784,15 +1972,45 @@ elif [ "$REPKG" -eq 0 ]; then tidy_install fi - create_package + + # add support for separate debug packages + if [ "$(check_option splitdbg)" = "y" ] || [ "$SPLIT_DBG" = "1" ]; then + create_package + # second check, if there are any files + check_dbg_files=`find $dbgdir/ -name "*.debug"` + if [ -z "$check_dbg_files" ]; then + msg2 "$(gettext "No .debug files found, skipping creation of the debug pkg...")" + else + create_debug_package + fi + else + create_package + fi + else for pkg in ${pkgname[@]}; do - pkgdir="$pkgdir/$pkg" + pkgdir="$pkgdir/pkg_${pkg}" mkdir -p "$pkgdir" + dbgdir="$startdir/dbg/dbg_${pkg}" + [ ! -d "$dbgdir" ] && mkdir -p "$dbgdir" backup_package_variables run_package $pkg tidy_install - create_package $pkg + + # add support for separate debug packages + if [ "$(check_option splitdbg)" = "y" ] || [ "$SPLIT_DBG" = "1" ]; then + create_package $pkg + # second check, if there are any files + check_dbg_files=`find $dbgdir/ -name "*.debug"` + if [ -z "$check_dbg_files" ]; then + msg2 "$(gettext "No .debug files found, skipping creation of the debug pkg...")" + else + create_debug_package $pkg + fi + else + create_package $pkg + fi + restore_package_variables pkgdir="${pkgdir%/*}" done