makepkg: add -D flag to change directory before building

This is similar to -C in git/make/nina. Sadly -C is already taken for
us.

This is useful for scripts where you for loop over packages, as well as
when I'm testing makepkg builds and I'm too lazy to cd.
This commit is contained in:
morganamilo 2023-01-29 14:04:34 +00:00 committed by Allan McRae
parent 36d70a93e2
commit 0dfe5c96ae
2 changed files with 13 additions and 3 deletions

View file

@ -146,6 +146,9 @@ Options
*-C, \--cleanbuild*:: *-C, \--cleanbuild*::
Remove the $srcdir before building the package. Remove the $srcdir before building the package.
*-D* <dir>, *\--dir* <dir> ::
Change to directory <dir> before reading the PKGBUILD or doing anything else.
*\--allsource*:: *\--allsource*::
Do not actually build the package, but build a source-only tarball that Do not actually build the package, but build a source-only tarball that
includes all sources, including those that are normally downloaded via includes all sources, including those that are normally downloaded via

View file

@ -43,7 +43,6 @@ unset GREP_OPTIONS
declare -r makepkg_version='@PACKAGE_VERSION@' declare -r makepkg_version='@PACKAGE_VERSION@'
declare -r confdir='@sysconfdir@' declare -r confdir='@sysconfdir@'
declare -r BUILDSCRIPT='@BUILDSCRIPT@' declare -r BUILDSCRIPT='@BUILDSCRIPT@'
declare -r startdir="$(pwd -P)"
LIBRARY=${LIBRARY:-'@libmakepkgdir@'} LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
@ -51,6 +50,7 @@ LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
ASDEPS=0 ASDEPS=0
BUILDFUNC=0 BUILDFUNC=0
BUILDPKG=1 BUILDPKG=1
CHDIR=''
CHECKFUNC=0 CHECKFUNC=0
CLEANBUILD=0 CLEANBUILD=0
CLEANUP=0 CLEANUP=0
@ -939,8 +939,8 @@ fi
ARGLIST=("$@") ARGLIST=("$@")
# Parse Command Line Options. # Parse Command Line Options.
OPT_SHORT="AcCdefFghiLmop:rRsSV" OPT_SHORT="AcCdD:efFghiLmop:rRsSV"
OPT_LONG=('allsource' 'check' 'clean' 'cleanbuild' 'config:' 'force' 'geninteg' OPT_LONG=('allsource' 'check' 'clean' 'cleanbuild' 'config:' 'dir:' 'force' 'geninteg'
'help' 'holdver' 'ignorearch' 'install' 'key:' 'log' 'noarchive' 'nobuild' 'help' 'holdver' 'ignorearch' 'install' 'key:' 'log' 'noarchive' 'nobuild'
'nocolor' 'nocheck' 'nodeps' 'noextract' 'noprepare' 'nosign' 'packagelist' 'nocolor' 'nocheck' 'nodeps' 'noextract' 'noprepare' 'nosign' 'packagelist'
'printsrcinfo' 'repackage' 'rmdeps' 'sign' 'skipchecksums' 'skipinteg' 'printsrcinfo' 'repackage' 'rmdeps' 'sign' 'skipchecksums' 'skipinteg'
@ -971,6 +971,7 @@ while true; do
--check) RUN_CHECK='y' ;; --check) RUN_CHECK='y' ;;
--config) shift; MAKEPKG_CONF=$1 ;; --config) shift; MAKEPKG_CONF=$1 ;;
-d|--nodeps) NODEPS=1 ;; -d|--nodeps) NODEPS=1 ;;
-D|--dir) shift; CHDIR=$1 ;;
-e|--noextract) NOEXTRACT=1 ;; -e|--noextract) NOEXTRACT=1 ;;
-f|--force) FORCE=1 ;; -f|--force) FORCE=1 ;;
-F) INFAKEROOT=1 ;; -F) INFAKEROOT=1 ;;
@ -1017,6 +1018,12 @@ while [[ $1 ]]; do
shift shift
done done
if [[ -n $CHDIR ]]; then
cd_safe "$CHDIR"
fi
declare -r startdir="$(pwd -P)"
# setup signal traps # setup signal traps
trap 'clean_up' 0 trap 'clean_up' 0
for signal in TERM HUP QUIT; do for signal in TERM HUP QUIT; do