index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
-rw-r--r-- | scripts/makepkg.sh.in | 557 |
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index d05d2403..d2cf52e2 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -38,11 +38,16 @@ export COMMAND_MODE='legacy' myver='@PACKAGE_VERSION@' confdir='@sysconfdir@' +BUILDSCRIPT='@BUILDSCRIPT@' startdir="$PWD" srcdir="$startdir/src" pkgdir="$startdir/pkg" -known_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'ccache' 'distcc' 'makeflags' 'force') -readonly -a known_options + +packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge') +other_options=('ccache' 'distcc' 'makeflags' 'force') +splitpkg_overrides=('pkgdesc' 'license' 'groups' 'depends' 'optdepends' 'provides' \ + 'conflicts' 'replaces' 'backup' 'options' 'install') +readonly -a packaging_options other_options splitpkg_overrides # Options ASROOT=0 @@ -62,6 +67,8 @@ LOGGING=0 SOURCEONLY=0 IGNOREARCH=0 HOLDVER=0 +PKGFUNC=0 +SPLITPKG=0 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call # when dealing with svn/cvs/etc PKGBUILDs. @@ -122,7 +129,7 @@ error() { # the fakeroot call, the error message will be printed by the main call. ## trap_exit() { - if [ "$INFAKEROOT" = "0" ]; then + if [ "$INFAKEROOT" -eq 0 ]; then echo error "$@" fi @@ -136,16 +143,16 @@ trap_exit() { clean_up() { local EXIT_CODE=$? - if [ "$INFAKEROOT" = "1" ]; then + if [ "$INFAKEROOT" -eq 1 ]; then # Don't clean up when leaving fakeroot, we're not done yet. return fi - if [ $EXIT_CODE -eq 0 -a "$CLEANUP" = "1" ]; then + if [ $EXIT_CODE -eq 0 -a "$CLEANUP" -eq 1 ]; then # If it's a clean exit and -c/--clean has been passed... msg "$(gettext "Cleaning up...")" rm -rf "$pkgdir" "$srcdir" - if [ "$pkgname" != "" ]; then + if [ -n "$pkgname" ]; then # Can't do this unless the BUILDSCRIPT has been sourced. rm -f "${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log*" fi @@ -270,7 +277,7 @@ get_downloadclient() { local i for i in "${DLAGENTS[@]}"; do local handler=$(echo $i | sed 's|::.*||') - if [ "$proto" == "$handler" ]; then + if [ "$proto" = "$handler" ]; then agent=$(echo $i | sed 's|^.*::||') break fi @@ -278,7 +285,7 @@ get_downloadclient() { # if we didn't find an agent, return an error if [ -z "$agent" ]; then - error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$confdir/makepkg.conf" + error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$MAKEPKG_CONF" plain "$(gettext "Aborting...")" exit 1 # $E_CONFIG_ERROR fi @@ -346,16 +353,16 @@ handledeps() { local deplist="$*" - if [ "$DEP_BIN" = "0" ]; then + if [ "$DEP_BIN" -eq 0 ]; then return $R_DEPS_MISSING fi - if [ "$DEP_BIN" = "1" ]; then + if [ "$DEP_BIN" -eq 1 ]; then # install missing deps from binary packages (using pacman -S) msg "$(gettext "Installing missing dependencies...")" local ret=0 - if [ "$ASROOT" = 0 ]; then + if [ "$ASROOT" -eq 0 ]; then sudo pacman $PACMAN_OPTS -S --asdeps $deplist || ret=$? else pacman $PACMAN_OPTS -S --asdeps $deplist || ret=$? @@ -382,7 +389,7 @@ resolve_deps() { local R_DEPS_MISSING=1 local deplist="$(check_deps $*)" - if [ "$deplist" = "" ]; then + if [ -z "$deplist" ]; then return $R_DEPS_SATISFIED fi @@ -390,8 +397,8 @@ resolve_deps() { pkgdeps="$pkgdeps $deplist" # check deps again to make sure they were resolved deplist="$(check_deps $*)" - [ "$deplist" = "" ] && return $R_DEPS_SATISFIED - elif [ "$DEP_BIN" = "1" ]; then + [ -z "$deplist" ] && return $R_DEPS_SATISFIED + elif [ "$DEP_BIN" -eq 1 ]; then error "$(gettext "Failed to install all missing dependencies.")" fi @@ -407,8 +414,8 @@ resolve_deps() { # fix flyspray bug #5923 remove_deps() { # $pkgdeps is a GLOBAL variable, set by resolve_deps() - [ "$RMDEPS" = "0" ] && return - [ "$pkgdeps" = "" ] && return + [ "$RMDEPS" -eq 0 ] && return + [ -z "$pkgdeps" ] && return local dep depstrip deplist deplist="" @@ -419,7 +426,7 @@ remove_deps() { msg "Removing installed dependencies..." local ret=0 - if [ "$ASROOT" = "0" ]; then + if [ "$ASROOT" -eq 0 ]; then sudo pacman $PACMAN_OPTS -Rns $deplist || ret=$? else pacman $PACMAN_OPTS -Rns $deplist || ret=$? @@ -488,6 +495,11 @@ generate_checksums() { msg "$(gettext "Generating checksums for source files...")" plain "" + if [ ! $(type -p openssl) ]; then + error "$(gettext "Cannot find openssl.")" + exit 1 # $E_MISSING_PROGRAM + fi + local integ for integ in ${INTEGRITY_CHECK[@]}; do integ="$(echo $integ | tr '[:upper:]' '[:lower:]')" @@ -498,11 +510,6 @@ generate_checksums() { exit 1;; # $E_CONFIG_ERROR esac - if [ ! $(type -p openssl) ]; then - error "$(gettext "Cannot find openssl.")" - exit 1 # $E_MISSING_PROGRAM - fi - local ct=0 local numsrc=${#source[@]} echo -n "${integ}sums=(" @@ -540,24 +547,18 @@ generate_checksums() { } check_checksums() { - local integ - for integ in ${INTEGRITY_CHECK[@]}; do - integ="$(echo $integ | tr '[:upper:]' '[:lower:]')" - case "$integ" in - md5|sha1|sha256|sha384|sha512) : ;; - *) - error "$(gettext "Invalid integrity algorithm '%s' specified")" "$integ" - exit 1;; # $E_CONFIG_ERROR - esac - - if [ ! $(type -p openssl) ]; then - error "$(gettext "Cannot find openssl.")" - exit 1 # $E_MISSING_PROGRAM - fi + if [ ! $(type -p openssl) ]; then + error "$(gettext "Cannot find openssl.")" + exit 1 # $E_MISSING_PROGRAM + fi + local correlation=0 + local integ required + for integ in md5 sha1 sha256 sha384 sha512; do local integrity_sums=($(eval echo "\${${integ}sums[@]}")) if [ ${#integrity_sums[@]} -eq ${#source[@]} ]; then msg "$(gettext "Validating source files with %s...")" "${integ}sums" + correlation=1 local errors=0 local idx=0 local file @@ -591,10 +592,16 @@ check_checksums() { error "$(gettext "One or more files did not pass the validity check!")" exit 1 # TODO: error code fi - else - warning "$(gettext "Integrity checks (%s) are missing or incomplete.")" "$integ" + elif [ ${#integrity_sums[@]} -gt 0 ]; then + error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ" + exit 1 # TODO: error code fi done + + if [ $correlation -eq 0 ]; then + error "$(gettext "Integrity checks are missing.")" + exit 1 # TODO: error code + fi } extract_sources() { @@ -674,13 +681,13 @@ run_build() { cd "$srcdir" # ensure all necessary build variables are exported - export CFLAGS CXXFLAGS MAKEFLAGS CHOST + export CFLAGS CXXFLAGS MAKEFLAGS LDFLAGS CHOST # save our shell options so build() can't override what we need local shellopts=$(shopt -p) local ret=0 - if [ "$LOGGING" = "1" ]; then - BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log" + if [ "$LOGGING" -eq 1 ]; then + BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}-build.log" if [ -f "$BUILDLOG" ]; then local i=1 while true; do @@ -708,21 +715,88 @@ run_build() { fi } +run_package() { + if [ -z "$1" ]; then + pkgfunc="package" + nameofpkg="$pkgname" + else + pkgfunc="package_$1" + nameofpkg="$1" + fi + + # clear user-specified makeflags if requested + if [ "$(check_option makeflags)" = "n" ]; then + MAKEFLAGS="" + fi + + msg "$(gettext "Starting %s()...")" "$pkgfunc" + cd "$srcdir" + + # ensure all necessary build variables are exported + export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST + + local ret=0 + if [ "$LOGGING" -eq 1 ]; then + BUILDLOG="${startdir}/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}-package.log" + if [ -f "$BUILDLOG" ]; then + local i=1 + while true; do + if [ -f "$BUILDLOG.$i" ]; then + i=$(($i +1)) + else + break + fi + done + mv "$BUILDLOG" "$BUILDLOG.$i" + fi + + # ensure overridden package variables suvrive tee with split packages + logpipe=$(mktemp -u "$startdir/logpipe.XXXXXXXX") + mknod "$logpipe" p + exec 3>&1 + tee "$BUILDLOG" < "$logpipe" & + exec 1>"$logpipe" 2>"$logpipe" + $pkgfunc 2>&1 || ret=$? + sync + exec 1>&3 2>&3 3>&- + rm "$logpipe" + else + $pkgfunc 2>&1 || ret=$? + fi + + if [ $ret -gt 0 ]; then + error "$(gettext "Packaging Failed.")" + plain "$(gettext "Aborting...")" + remove_deps + exit 2 # $E_BUILD_FAILED + fi +} + tidy_install() { cd "$pkgdir" msg "$(gettext "Tidying install...")" - if [ "$(check_option docs)" = "n" ]; then - msg2 "$(gettext "Removing info/doc files...")" - #fix flyspray bug #5021 + if [ "$(check_option docs)" = "n" -a -n "${DOC_DIRS[*]}" ]; then + msg2 "$(gettext "Removing doc files...")" rm -rf ${DOC_DIRS[@]} fi - if [ "$(check_option zipman)" = "y" ]; then - msg2 "$(gettext "Compressing man pages...")" - local manpage mandirs ext file link hardlinks hl - mandirs="usr/man usr/share/man usr/local/man usr/local/share/man opt/*/man" - find ${mandirs} -type f 2>/dev/null | + if [ "$(check_option purge)" = "y" -a -n "${PURGE_TARGETS[*]}" ]; then + msg2 "$(gettext "Purging other files...")" + local pt + for pt in "${PURGE_TARGETS[@]}"; do + if [ "${pt}" = "${pt//\/}" ]; then + find . -type f -name "${pt}" -exec rm -f -- '{}' \; + else + rm -f ${pt} + fi + done + fi + + if [ "$(check_option zipman)" = "y" -a -n "${MAN_DIRS[*]}" ]; then + msg2 "$(gettext "Compressing man and info pages...")" + local manpage ext file link hardlinks hl + find ${MAN_DIRS[@]} -type f 2>/dev/null | while read manpage ; do # check file still exists (potentially compressed with hard link) if [ -f ${manpage} ]; then @@ -730,7 +804,7 @@ tidy_install() { file="${manpage##*/}" if [ "$ext" != "gz" -a "$ext" != "bz2" ]; then # update symlinks to this manpage - find ${mandirs} -lname "$file" 2>/dev/null | + find ${MAN_DIRS[@]} -lname "$file" 2>/dev/null | while read link ; do rm -f "$link" ln -sf "${file}.gz" "${link}.gz" @@ -738,7 +812,7 @@ tidy_install() { # find hard links and remove them # the '|| true' part keeps the script from bailing if find returned an # error, such as when one of the man directories doesn't exist - hardlinks="$(find ${mandirs} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true + hardlinks="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true for hl in ${hardlinks}; do rm -f "${hl}"; done @@ -754,15 +828,9 @@ tidy_install() { done fi - - if [ "$(check_option strip)" = "y" ]; then + if [ "$(check_option strip)" = "y" -a -n "${STRIP_DIRS[*]}" ]; then msg2 "$(gettext "Stripping debugging symbols from binaries and libraries...")" 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) @@ -787,6 +855,12 @@ tidy_install() { } create_package() { + if [ -z "$1" ]; then + nameofpkg="$pkgname" + else + nameofpkg="$1" + fi + if [ ! -d "$pkgdir" ]; then error "$(gettext "Missing pkg/ directory.")" plain "$(gettext "Aborting...")" @@ -797,7 +871,7 @@ create_package() { msg "$(gettext "Creating package...")" local builddate=$(date -u "+%s") - if [ "$PACKAGER" != "" ]; then + if [ -n "$PACKAGER" ]; then local packager="$PACKAGER" else local packager="Unknown Packager" @@ -807,18 +881,18 @@ create_package() { # write the .PKGINFO file msg2 "$(gettext "Generating .PKGINFO file...")" echo "# Generated by makepkg $myver" >.PKGINFO - if [ "$INFAKEROOT" = "1" ]; then + if [ "$INFAKEROOT" -eq 1 ]; then echo "# using $(fakeroot -v)" >>.PKGINFO fi echo "# $(LC_ALL=C date -u)" >>.PKGINFO - echo "pkgname = $pkgname" >>.PKGINFO + echo "pkgname = $nameofpkg" >>.PKGINFO echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO echo "pkgdesc = $pkgdesc" >>.PKGINFO echo "url = $url" >>.PKGINFO echo "builddate = $builddate" >>.PKGINFO echo "packager = $packager" >>.PKGINFO echo "size = $size" >>.PKGINFO - if [ "$CARCH" != "" ]; then + if [ -n "$CARCH" ]; then echo "arch = $CARCH" >>.PKGINFO fi if [ "$(check_option force)" = "y" ]; then @@ -850,10 +924,20 @@ create_package() { for it in "${backup[@]}"; do echo "backup = $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 [ "$license" = "" ]; then + 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 @@ -861,7 +945,7 @@ create_package() { local comp_files=".PKGINFO" # check for an install script - if [ "$install" != "" ]; then + if [ -n "$install" ]; then msg2 "$(gettext "Adding install script...")" cp "$startdir/$install" .INSTALL comp_files="$comp_files .INSTALL" @@ -877,86 +961,30 @@ create_package() { # tar it up msg2 "$(gettext "Compressing package...")" - local pkg_file="$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" + 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}-${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 -czf "$pkg_file" $comp_files *; then + 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 - elif [ ! "$(type -p xdelta)" ]; then - error "$(gettext "Cannot find the xdelta binary! Is xdelta installed?")" - return - fi - - local pkg_file=$1 - local cache_dir="/var/cache/pacman/pkg" # TODO: autoconf me - local pkginfo="$(mktemp "$startdir"/xdelta-pkginfo.XXXXXXXXX)" - - local old_file old_version - for old_file in $(ls {"$cache_dir","$PKGDEST"}/${pkgname}-*-*{,-$CARCH}$PKGEXT 2>/dev/null); do - bsdtar -xOf "$old_file" .PKGINFO > "$pkginfo" || continue - if [ "$(cat "$pkginfo" | grep '^pkgname = ')" != "pkgname = $pkgname" ]; then - continue # Package name does not match. - elif [ "$(cat "$pkginfo" | grep '^arch = ')" != "arch = $CARCH" ] ; then - continue # Not same arch. - fi - - old_version="$(cat "$pkginfo" | grep '^pkgver = ' | sed 's/^pkgver = //')" - - # old_version may include the target package, only use the old versions - local vercmp=$(vercmp "$old_version" "$latest_version") - if [ "$old_version" != "$pkgver-$pkgrel" -a $vercmp -gt 0 ]; then - local latest_version=$old_version - local base_file=$old_file - fi - done - - rm -f "$pkginfo" - - if [ "$base_file" != "" ]; then - msg "$(gettext "Making delta from version %s...")" "$latest_version" - local delta_file="$PKGDEST/$pkgname-${latest_version}_to_$pkgver-$pkgrel-$CARCH.delta" - local ret=0 - - # xdelta will decompress base_file & pkg_file into TMP_DIR (or /tmp if - # TMP_DIR is unset) then perform the delta on the resulting tars - xdelta delta "$base_file" "$pkg_file" "$delta_file" || ret=$? - - if [ $ret -eq 0 -o $ret -eq 1 ]; then - # Generate the final gz using xdelta for compression. xdelta will be our - # common denominator compression utility between the packager and the - # users. makepkg and pacman must use the same compression algorithm or - # the delta generated package may not match, producing md5 checksum - # errors. - msg2 "$(gettext "Recreating package tarball from delta to match md5 signatures")" - msg2 "$(gettext "NOTE: the delta should ONLY be distributed with this tarball")" - ret=0 - xdelta patch "$delta_file" "$base_file" "$pkg_file" || ret=$? - if [ $ret -ne 0 ]; then - error "$(gettext "Could not generate the package from the delta.")" - exit 1 - fi - else - warning "$(gettext "Delta was not able to be created.")" - fi - else - warning "$(gettext "No previous version found, skipping xdelta.")" - fi -} - create_srcpackage() { cd "$startdir" - if [ "$SOURCEONLY" = "2" ]; then + if [ "$SOURCEONLY" -eq 2 ]; then # get back to our src directory so we can begin with sources mkdir -p "$srcdir" cd "$srcdir" @@ -972,7 +1000,7 @@ create_srcpackage() { msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT" ln -s "${startdir}/${BUILDSCRIPT}" "${srclinks}/${pkgname}/" - if [ "$install" != "" ]; then + if [ -n "$install" ]; then if [ -f $install ]; then msg2 "$(gettext "Adding install script...")" ln -s "${startdir}/$install" "${srclinks}/${pkgname}/" @@ -992,18 +1020,26 @@ create_srcpackage() { if [ -f "$netfile" ]; then msg2 "$(gettext "Adding %s...")" "$netfile" ln -s "${startdir}/$netfile" "${srclinks}/${pkgname}" - elif [ "$SOURCEONLY" = "2" -a -f "$SRCDEST/$file" ]; then + elif [ "$SOURCEONLY" -eq 2 -a -f "$SRCDEST/$file" ]; then msg2 "$(gettext "Adding %s...")" "$file" ln -s "$SRCDEST/$file" "${srclinks}/${pkgname}/" fi done + local TAR_OPT + case "$SRCEXT" in + *tar.gz) TAR_OPT="z" ;; + *tar.bz2) TAR_OPT="j" ;; + *) warning "$(gettext "'%s' is not a valid archive extension.")" \ + "$SRCEXT" ;; + esac + local pkg_file="$PKGDEST/${pkgname}-${pkgver}-${pkgrel}${SRCEXT}" # tar it up msg2 "$(gettext "Compressing source package...")" cd "${srclinks}" - if ! bsdtar -czLf "$pkg_file" ${pkgname}; then + if ! bsdtar -c${TAR_OPT}Lf "$pkg_file" ${pkgname}; then error "$(gettext "Failed to create source package file.")" exit 1 # TODO: error code fi @@ -1012,9 +1048,9 @@ create_srcpackage() { } install_package() { - [ "$INSTALL" = "0" ] && return + [ "$INSTALL" -eq 0 ] && return msg "$(gettext "Installing package ${pkgname} with pacman -U...")" - if [ "$ASROOT" = "0" ]; then + if [ "$ASROOT" -eq 0 ]; then sudo pacman $PACMAN_OPTS -U $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} || exit $? else pacman $PACMAN_OPTS -U $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} || exit $? @@ -1024,10 +1060,14 @@ install_package() { devel_check() { newpkgver="" # Only update pkgver if --holdver is not set - if [ "$HOLDVER" = "1" ]; then + if [ "$HOLDVER" -eq 1 ]; then + return + fi + # Cannot update pkgver/pkgrel if reading PKGBUILD from pipe + if [ ! -f "./$BUILDSCRIPT" ]; then return fi - if [ "$FORCE_VER" = "" ]; then + if [ -z "$FORCE_VER" ]; then # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so. # This will only be used on the first call to makepkg; subsequent # calls to makepkg via fakeroot will explicitly pass the version @@ -1070,7 +1110,7 @@ devel_check() { cd ../../ fi - if [ "$newpkgver" != "" ]; then + if [ -n "$newpkgver" ]; then msg2 "$(gettext "Version found: %s")" "$newpkgver" fi @@ -1090,15 +1130,35 @@ devel_update() { # ... # _foo=pkgver # - if [ "$newpkgver" != "" ]; then + if [ -n "$newpkgver" ]; then if [ "$newpkgver" != "$pkgver" ]; then - sed -i "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "./$BUILDSCRIPT" - sed -i "s/^pkgrel=[^ ]*/pkgrel=1/" "./$BUILDSCRIPT" - source "$BUILDSCRIPT" + if [ -f "./$BUILDSCRIPT" ]; then + sed -i "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "./$BUILDSCRIPT" + sed -i "s/^pkgrel=[^ ]*/pkgrel=1/" "./$BUILDSCRIPT" + source "$BUILDSCRIPT" + fi fi fi } +backup_package_variables() { + for var in ${splitpkg_overrides[@]}; do + indirect="${var}_backup" + eval "${indirect}=\"${!var}\"" + done +} + +restore_package_variables() { + for var in ${splitpkg_overrides[@]}; do + indirect="${var}_backup" + if [ -n "${!indirect}" ]; then + eval "${var}=\"${!indirect}\"" + else + unset ${var} + fi + done +} + # getopt like parser parse_options() { local short_options=$1; shift; @@ -1195,6 +1255,7 @@ usage() { printf "$(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT" echo "$(gettext " -c, --clean Clean up work files after build")" echo "$(gettext " -C, --cleancache Clean up source files from the cache")" + printf "$(gettext " --config <config> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf" echo "$(gettext " -d, --nodeps Skip all dependency checks")" echo "$(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")" echo "$(gettext " -f, --force Overwrite existing package")" @@ -1242,36 +1303,12 @@ fi ARGLIST=$@ -#preserve environment variables -_PKGDEST=${PKGDEST} -_SRCDEST=${SRCDEST} - -# Source makepkg.conf; fail if it is not found -if [ -r "$confdir/makepkg.conf" ]; then - source "$confdir/makepkg.conf" -else - error "$(gettext "%s not found.")" "$confdir/makepkg.conf" - plain "$(gettext "Aborting...")" - exit 1 # $E_CONFIG_ERROR -fi - -# Source user-specific makepkg.conf overrides -if [ -r ~/.makepkg.conf ]; then - source ~/.makepkg.conf -fi - -# override settings with an environment variable for batch processing -PKGDEST=${_PKGDEST:-$PKGDEST} -PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined -SRCDEST=${_SRCDEST:-$SRCDEST} -SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined - # Parse Command Line Options. OPT_SHORT="AbcCdefFghiLmop:rRsV" 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" +OPT_LONG="$OPT_LONG,syncdeps,version,config:" # Pacman Options OPT_LONG="$OPT_LONG,noconfirm,noprogressbar" OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@" || echo 'PARSE_OPTIONS FAILED')" @@ -1294,6 +1331,7 @@ while true; do -A|--ignorearch) IGNOREARCH=1 ;; -c|--clean) CLEANUP=1 ;; -C|--cleancache) CLEANCACHE=1 ;; + --config) shift; MAKEPKG_CONF=$1 ;; -d|--nodeps) NODEPS=1 ;; -e|--noextract) NOEXTRACT=1 ;; -f|--force) FORCE=1 ;; @@ -1321,13 +1359,41 @@ while true; do shift done -if [ "$HOLDVER" = "1" -a "$FORCE_VER" != "" ]; then +#preserve environment variables +_PKGDEST=${PKGDEST} +_SRCDEST=${SRCDEST} + +# default config is makepkg.conf +MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf} + +# Source the config file; fail if it is not found +if [ -r "$MAKEPKG_CONF" ]; then + source "$MAKEPKG_CONF" +else + error "$(gettext "%s not found.")" "$MAKEPKG_CONF" + plain "$(gettext "Aborting...")" + exit 1 # $E_CONFIG_ERROR +fi + +# Source user-specific makepkg.conf overrides +if [ -r ~/.makepkg.conf ]; then + source ~/.makepkg.conf +fi + +# override settings with an environment variable for batch processing +PKGDEST=${_PKGDEST:-$PKGDEST} +PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined +SRCDEST=${_SRCDEST:-$SRCDEST} +SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined + + +if [ "$HOLDVER" -eq 1 -a -n "$FORCE_VER" ]; then # The '\\0' is here to prevent gettext from thinking --holdver is an option error "$(gettext "\\0--holdver and --forcever cannot both be specified" )" exit 1 fi -if [ "$CLEANCACHE" = "1" ]; then +if [ "$CLEANCACHE" -eq 1 ]; then #fix flyspray feature request #5223 if [ -n "$SRCDEST" -a "$SRCDEST" != "$startdir" ]; then msg "$(gettext "Cleaning up ALL files from %s.")" "$SRCDEST" @@ -1352,25 +1418,25 @@ if [ "$CLEANCACHE" = "1" ]; then fi else # $SRCDEST is $startdir, two possibilities - error "$(gettext "Source destination must be defined in makepkg.conf.")" + error "$(gettext "Source destination must be defined in %s.")" "$MAKEPKG_CONF" plain "$(gettext "In addition, please run makepkg -C outside of your cache directory.")" exit 1 fi fi if [ -z "$BUILDSCRIPT" ]; then - error "$(gettext "BUILDSCRIPT is undefined! Ensure you have updated %s.")" "$confdir/makepkg.conf" + error "$(gettext "BUILDSCRIPT is undefined! Ensure you have updated %s.")" "$MAKEPKG_CONF" exit 1 fi -if [ "$INFAKEROOT" = "0" ]; then - if [ $EUID -eq 0 -a "$ASROOT" = "0" ]; then +if [ "$INFAKEROOT" -eq 0 ]; then + if [ $EUID -eq 0 -a "$ASROOT" -eq 0 ]; then # Warn those who like to live dangerously. error "$(gettext "Running makepkg as root is a BAD idea and can cause")" plain "$(gettext "permanent, catastrophic damage to your system. If you")" plain "$(gettext "wish to run as root, please use the --asroot option.")" exit 1 # $E_USER_ABORT - elif [ $EUID -gt 0 -a "$ASROOT" = "1" ]; then + elif [ $EUID -gt 0 -a "$ASROOT" -eq 1 ]; then # Warn those who try to use the --asroot option when they are not root error "$(gettext "The --asroot option is meant for the root user only.")" plain "$(gettext "Please rerun makepkg without the --asroot flag.")" @@ -1378,25 +1444,25 @@ if [ "$INFAKEROOT" = "0" ]; then elif [ "$(check_buildenv fakeroot)" = "y" -a $EUID -gt 0 ]; then if [ ! $(type -p fakeroot) ]; then error "$(gettext "Fakeroot must be installed if using the 'fakeroot' option")" - plain "$(gettext "in the BUILDENV array in %s.")" "$confdir/makepkg.conf" + plain "$(gettext "in the BUILDENV array in %s.")" "$MAKEPKG_CONF" exit 1 fi elif [ $EUID -gt 0 ]; then warning "$(gettext "Running makepkg as an unprivileged user will result in non-root")" plain "$(gettext "ownership of the packaged files. Try using the fakeroot environment by")" - plain "$(gettext "placing 'fakeroot' in the BUILDENV array in makepkg.conf.")" + plain "$(gettext "placing 'fakeroot' in the BUILDENV array in %s.")" "$MAKEPKG_CONF" sleep 1 fi else - if [ "$FAKEROOTKEY" = "" ]; then + if [ -z "$FAKEROOTKEY" ]; then error "$(gettext "Do not use the '-F' option. This option is only for use by makepkg.")" exit 1 # TODO: error code fi fi # check for sudo if we will need it during makepkg execution -if [ "$ASROOT" = "0" -a \( "$DEP_BIN" = "1" \ - -o "$RMDEPS" = "1" -o "$INSTALL" = "1" \) ]; then +if [ "$ASROOT" -eq 0 \ + -a \( "$DEP_BIN" -eq 1 -o "$RMDEPS" -eq 1 -o "$INSTALL" -eq 1 \) ]; then if [ ! "$(type -p sudo)" ]; then error "$(gettext "Cannot find the sudo binary! Is sudo installed?")" plain "$(gettext "Missing dependencies cannot be installed or removed as a normal user")" @@ -1410,13 +1476,24 @@ unset replaces depends conflicts backup source install build makedepends unset optdepends options noextract if [ ! -f "$BUILDSCRIPT" ]; then - error "$(gettext "%s does not exist.")" "$BUILDSCRIPT" - exit 1 + if [ -t 0 ]; then + error "$(gettext "%s does not exist.")" "$BUILDSCRIPT" + exit 1 + else + # PKGBUILD passed through a pipe + BUILDSCRIPT=/dev/stdin + fi +else + crlftest=$(file $BUILDSCRIPT | grep -F 'CRLF' || true) + if [ -n "$crlftest" ]; then + error "$(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDSCRIPT" + exit 1 + fi fi source "$BUILDSCRIPT" -if [ "$GENINTEG" = "1" ]; then +if [ "$GENINTEG" -eq 1 ]; then mkdir -p "$srcdir" cd "$srcdir" download_sources @@ -1424,6 +1501,14 @@ if [ "$GENINTEG" = "1" ]; then exit 0 # $E_OK fi +if [ "$(type -t package)" = "function" ]; then + PKGFUNC=1 +fi + +if [ "${#pkgname[@]}" -gt "1" ]; then + SPLITPKG=1 +fi + # check for no-no's in the build script if [ -z "$pkgname" ]; then error "$(gettext "%s is not allowed to be empty.")" "pkgname" @@ -1451,15 +1536,11 @@ if [ "$arch" = 'any' ]; then fi if ! in_array $CARCH ${arch[@]}; then - if [ "$IGNOREARCH" = "0" ]; then + if [ "$IGNOREARCH" -eq 0 ]; then error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgname" "$CARCH" plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT" plain "$(gettext "such as arch=('%s').")" "$CARCH" exit 1 - else - warning "$(gettext "%s is not available for the '%s' architecture.")" "$pkgname" "$CARCH" - plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT" - plain "$(gettext "such as arch=('%s').")" "$CARCH" fi fi @@ -1480,7 +1561,7 @@ valid_options=1 for opt in ${options[@]}; do known=0 # check if option matches a known option or its inverse - for kopt in ${known_options[@]}; do + for kopt in ${packaging_options[@]} ${other_options[@]}; do if [ "${opt}" = "${kopt}" -o "${opt}" = "!${kopt}" ]; then known=1 fi @@ -1503,8 +1584,8 @@ devel_check devel_update if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" \ - -a "$FORCE" = "0" -a "$SOURCEONLY" = "0" -a "$NOBUILD" = "0" ]; then - if [ "$INSTALL" = "1" ]; then + -a "$FORCE" -eq 0 -a "$SOURCEONLY" -eq 0 -a "$NOBUILD" -eq 0 ]; then + if [ "$INSTALL" -eq 1 ]; then warning "$(gettext "A package has already been built, installing existing package...")" install_package exit $? @@ -1515,31 +1596,40 @@ if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" \ fi # Run the bare minimum in fakeroot -# fix flyspray bug 6208 -- using makepkg with fakeroot gives an error -if [ "$INFAKEROOT" = "1" ]; then - if [ "$REPKG" = "1" ]; then - warning "$(gettext "Skipping build.")" +if [ "$INFAKEROOT" -eq 1 ]; then + if [ "$SPLITPKG" -eq 0 ]; then + if [ "$PKGFUNC" -eq 0 ]; then + if [ "$REPKG" -eq 0 ]; then + run_build + fi + else + run_package + tidy_install + fi + create_package else - run_build - tidy_install + for pkg in ${pkgname[@]}; do + pkgdir="$pkgdir/$pkg" + mkdir -p "$pkgdir" + backup_package_variables + run_package $pkg + tidy_install + create_package $pkg + restore_package_variables + pkgdir="${pkgdir%/*}" + done fi - create_package - msg "$(gettext "Leaving fakeroot environment.")" exit 0 # $E_OK fi msg "$(gettext "Making package: %s")" "$pkgname $pkgver-$pkgrel $CARCH ($(date))" -if [ $EUID -eq 0 ]; then - warning "$(gettext "Running makepkg as root...")" -fi - # if we are creating a source-only package, go no further -if [ "$SOURCEONLY" != "0" ]; then +if [ "$SOURCEONLY" -ne 0 ]; then if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}${SRCEXT}" \ - -a "$FORCE" = "0" ]; then + -a "$FORCE" -eq 0 ]; then error "$(gettext "A package has already been built. (use -f to overwrite)")" exit 1 fi @@ -1549,11 +1639,11 @@ if [ "$SOURCEONLY" != "0" ]; then fi # fix flyspray bug #5973 -if [ "$NODEPS" = "1" -o "$NOBUILD" = "1" -o "$REPKG" = "1" ]; then - if [ "$NODEPS" = "1" ]; then +if [ "$NODEPS" -eq 1 -o "$NOBUILD" -eq 1 -o "$REPKG" -eq 1 ]; then + # no warning message needed for nobuild, repkg + if [ "$NODEPS" -eq 1 ]; then warning "$(gettext "Skipping dependency checks.")" fi - # skip printing a warning message for the others: nobuild, repkg elif [ $(type -p pacman) ]; then unset pkgdeps # Set by resolve_deps() and used by remove_deps() deperr=0 @@ -1579,16 +1669,19 @@ umask 0022 mkdir -p "$srcdir" cd "$srcdir" -if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then +if [ "$NOEXTRACT" -eq 1 ]; then warning "$(gettext "Skipping source retrieval -- using existing src/ tree")" warning "$(gettext "Skipping source integrity checks -- using existing src/ tree")" warning "$(gettext "Skipping source extraction -- using existing src/ tree")" - if [ "$NOEXTRACT" = "1" -a "$(ls "$srcdir" 2>/dev/null)" = "" ]; then + if [ "$NOEXTRACT" -eq 1 -a -z "$(ls "$srcdir" 2>/dev/null)" ]; then error "$(gettext "The source directory is empty, there is nothing to build!")" plain "$(gettext "Aborting...")" exit 1 - elif [ "$REPKG" = "1" -a \( ! -d "$pkgdir" -o "$(ls "$pkgdir" 2>/dev/null)" = "" \) ]; then + fi +elif [ "$REPKG" -eq 1 ]; then + if [ "$PKGFUNC" -eq 0 -a "$SPLITPKG" -eq 0 \ + -a \( ! -d "$pkgdir" -o -z "$(ls "$pkgdir" 2>/dev/null)" \) ]; then error "$(gettext "The package directory is empty, there is nothing to repackage!")" plain "$(gettext "Aborting...")" exit 1 @@ -1599,40 +1692,60 @@ else extract_sources fi -if [ "$NOBUILD" = "1" ]; then +if [ "$NOBUILD" -eq 1 ]; then msg "$(gettext "Sources are ready.")" exit 0 #E_OK else # check for existing pkg directory; don't remove if we are repackaging - if [ -d "$pkgdir" -a "$REPKG" = "0" ]; then + if [ -d "$pkgdir" \ + -a \( "$REPKG" -eq 0 -o "$PKGFUNC" -eq 1 -o "$SPLITPKG" -eq 1 \) ]; then msg "$(gettext "Removing existing pkg/ directory...")" rm -rf "$pkgdir" fi mkdir -p "$pkgdir" cd "$startdir" + # if we are root or if fakeroot is not enabled, then we don't use it if [ "$(check_buildenv fakeroot)" != "y" -o $EUID -eq 0 ]; then - # if we are root or if fakeroot is not enabled, then we don't use it - if [ "$REPKG" = "1" ]; then - warning "$(gettext "Skipping build.")" + if [ "$REPKG" -eq 0 ]; then + devel_update + run_build + fi + if [ "$SPLITPKG" -eq 0 ]; then + if [ "$PKGFUNC" -eq 1 ]; then + run_package + tidy_install + elif [ "$REPKG" -eq 0 ]; then + tidy_install + fi + create_package else + for pkg in ${pkgname[@]}; do + pkgdir="$pkgdir/$pkg" + mkdir -p "$pkgdir" + backup_package_variables + run_package $pkg + tidy_install + create_package $pkg + restore_package_variables + pkgdir="${pkgdir%/*}" + done + fi + else + if [ "$REPKG" -eq 0 -a \( "$PKGFUNC" -eq 1 -o "$SPLITPKG" -eq 1 \) ]; then devel_update run_build - tidy_install + cd "$startdir" fi - create_package - else msg "$(gettext "Entering fakeroot environment...")" - if [ "$newpkgver" != "" ]; then + if [ -n "$newpkgver" ]; then fakeroot -- $0 --forcever $newpkgver -F $ARGLIST || exit $? else fakeroot -- $0 -F $ARGLIST || exit $? fi fi - - create_xdelta "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" fi msg "$(gettext "Finished making: %s")" "$pkgname $pkgver-$pkgrel $CARCH ($(date))" |