[pacman-dev] [PATCH] makepkg : switch from getopt to getopts builtin
From f5c5a277e2df14650ae441f32950aa6d4deee50f Mon Sep 17 00:00:00 2001 From: Xavier Chantry <shiningxc@gmail.com> Date: Wed, 28 May 2008 21:57:28 +0200 Subject: [PATCH] makepkg : switch from getopt to getopts builtin
getopt is an external script for parsing and is less portable than getopts which is a bash builtin. The main problem is that it only supports short opts, so long opts had to be dropped. The benefits are a much better portability and a simpler code for the arguments parsing. TODO: better testing, fix man page. Signed-off-by: Xavier Chantry <shiningxc@gmail.com> --- scripts/makepkg.sh.in | 143 +++++++++++++++++++++--------------------------- 1 files changed, 63 insertions(+), 80 deletions(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index cc44c68..f880091 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -27,7 +27,7 @@ # makepkg uses quite a few external programs during its execution. You # need to have at least the following installed for makepkg to function: # awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, find (findutils), -# getopt (util-linux), gettext, grep, gzip, sed +# gettext, grep, gzip, sed # gettext initialization export TEXTDOMAIN='pacman' @@ -1056,31 +1056,31 @@ usage() { printf "$(gettext "Usage: %s [options]")\n" "$0" echo echo "$(gettext "Options:")" - 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")" - 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")" - echo "$(gettext " -g, --geninteg Generate integrity checks for source files")" - echo "$(gettext " -h, --help This help")" - echo "$(gettext " -i, --install Install package after successful build")" - echo "$(gettext " -L, --log Log package build process")" - echo "$(gettext " -m, --nocolor Disable colorized output messages")" - echo "$(gettext " -o, --nobuild Download and extract files only")" + printf "$(gettext " -A Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT" + echo "$(gettext " -c Clean up work files after build")" + echo "$(gettext " -C Clean up source files from the cache")" + echo "$(gettext " -d Skip all dependency checks")" + echo "$(gettext " -e Do not extract source files (use existing src/ dir)")" + echo "$(gettext " -f Overwrite existing package")" + echo "$(gettext " -g Generate integrity checks for source files")" + echo "$(gettext " -h This help")" + echo "$(gettext " -i Install package after successful build")" + echo "$(gettext " -L Log package build process")" + echo "$(gettext " -m Disable colorized output messages")" + echo "$(gettext " -o Download and extract files only")" printf "$(gettext " -p <buildscript> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT" - echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")" + echo "$(gettext " -r Remove installed dependencies after a successful build")" # fix flyspray feature request #2978 - echo "$(gettext " -R, --repackage Repackage contents of pkg/ without building")" - echo "$(gettext " -s, --syncdeps Install missing dependencies with pacman")" - echo "$(gettext " --asroot Allow makepkg to run as root user")" - echo "$(gettext " --holdver Prevent automatic version bumping for development PKGBUILDs")" - echo "$(gettext " --source Do not build package; generate a source-only tarball")" + echo "$(gettext " -R Repackage contents of pkg/ without building")" + echo "$(gettext " -s Install missing dependencies with pacman")" + echo "$(gettext " -O Allow makepkg to run as root user")" + echo "$(gettext " -H Prevent automatic version bumping for development PKGBUILDs")" + echo "$(gettext " -S Do not build package; generate a source-only tarball")" echo echo "$(gettext "These options can be passed to pacman:")" echo - echo "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")" - echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files")" + echo "$(gettext " -n Do not ask for confirmation when resolving dependencies")" + echo "$(gettext " -N Do not show a progress bar when downloading files")" echo printf "$(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT" echo @@ -1130,66 +1130,49 @@ SRCDEST=${_SRCDEST:-$SRCDEST} SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined # Parse Command Line Options. -OPT_SHORT="AbcCdefFghiLmop:rRsSV" -OPT_LONG="ignorearch,asroot,builddeps,clean,cleancache,nodeps,noextract,force,forcever:,geninteg,help,holdver" -OPT_LONG="$OPT_LONG,install,log,nocolor,nobuild,rmdeps,repackage,source,syncdeps,usesudo,version" -# Pacman Options -OPT_LONG="$OPT_LONG,noconfirm,noprogressbar" -OPT_TEMP="$(getopt -o "$OPT_SHORT" -l "$OPT_LONG" -n "$(basename "$0")" -- "$@" || echo 'GETOPT GO BANG!')" -if echo "$OPT_TEMP" | grep -q 'GETOPT GO BANG!'; then - # This is a small hack to stop the script bailing with 'set -e' - echo; usage; exit 1 # E_INVALID_OPTION; -fi -eval set -- "$OPT_TEMP" -unset OPT_SHORT OPT_LONG OPT_TEMP +OPT_SHORT="AcCdefF:ghHiLmnNoOp:rRsSVX" -while true; do - case "$1" in +while getopts "$OPT_SHORT" name; do + case $name in # Pacman Options - --noconfirm) PACMAN_OPTS="$PACMAN_OPTS --noconfirm" ;; - --noprogressbar) PACMAN_OPTS="$PACMAN_OPTS --noprogressbar" ;; + n) PACMAN_OPTS="$PACMAN_OPTS --noconfirm" ;; + N) PACMAN_OPTS="$PACMAN_OPTS --noprogressbar" ;; # Makepkg Options - --asroot) ASROOT=1 ;; - -A|--ignorearch) IGNOREARCH=1 ;; - -c|--clean) CLEANUP=1 ;; - -C|--cleancache) CLEANCACHE=1 ;; - -d|--nodeps) NODEPS=1 ;; - -e|--noextract) NOEXTRACT=1 ;; - -f|--force) FORCE=1 ;; - #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver - --forcever) shift; FORCE_VER=$1;; - -F) INFAKEROOT=1 ;; - -g|--geninteg) GENINTEG=1 ;; - --holdver) HOLDVER=1 ;; - -i|--install) INSTALL=1 ;; - -L|--log) LOGGING=1 ;; - -m|--nocolor) USE_COLOR='n' ;; - -o|--nobuild) NOBUILD=1 ;; - -p) shift; BUILDSCRIPT=$1 ;; - -r|--rmdeps) RMDEPS=1 ;; - -R|--repackage) REPKG=1 ;; - --source) SOURCEONLY=1 ;; - -s|--syncdeps) DEP_BIN=1 ;; - - # BEGIN DEPRECATED - -S|--usesudo) - warning "$(gettext "Sudo is used by default now. The --usesudo option is deprecated!")" ;; - # END DEPRECATED - - -h|--help) usage; exit 0 ;; # E_OK - -V|--version) version; exit 0 ;; # E_OK - - --) OPT_IND=0; shift; break;; - *) usage; exit 1 ;; # E_INVALID_OPTION + A) IGNOREARCH=1 ;; + c) CLEANUP=1 ;; + C) CLEANCACHE=1 ;; + d) NODEPS=1 ;; + e) NOEXTRACT=1 ;; + f) FORCE=1 ;; + # hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver + F) FORCE_VER="$OPTARG";; + g) GENINTEG=1 ;; + H) HOLDVER=1 ;; + i) INSTALL=1 ;; + L) LOGGING=1 ;; + m) USE_COLOR='n' ;; + o) NOBUILD=1 ;; + O) ASROOT=1 ;; + p) BUILDSCRIPT="$OPTARG" ;; + r) RMDEPS=1 ;; + R) REPKG=1 ;; + s) DEP_BIN=1 ;; + S) SOURCEONLY=1 ;; + # hidden opt to indicate fakeroot call + X) INFAKEROOT=1 ;; + + h) usage; exit 0 ;; # E_OK + V) version; exit 0 ;; # E_OK + + ?) usage; exit 1 ;; # E_INVALID_OPTION esac - shift done if [ "$HOLDVER" = "1" -a "$FORCE_VER" != "" ]; then - # The extra '--' is here to prevent gettext from thinking --holdver is + # The extra '--' is here to prevent gettext from thinking -H is # an option - error "$(gettext "\\0--holdver and --forcever cannot both be specified" )" + error "$(gettext "\\0-H and -F cannot both be specified" )" exit 1 fi @@ -1233,12 +1216,12 @@ if [ "$INFAKEROOT" = "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.")" + plain "$(gettext "wish to run as root, please use the -O option.")" exit 1 # $E_USER_ABORT elif [ $EUID -gt 0 -a "$ASROOT" = "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.")" + # Warn those who try to use the -O option when they are not root + error "$(gettext "The -O option is meant for the root user only.")" + plain "$(gettext "Please rerun makepkg without the -O flag.")" exit 1 # $E_USER_ABORT elif [ "$(check_buildenv fakeroot)" = "y" -a $EUID -gt 0 ]; then if [ ! $(type -p fakeroot) ]; then @@ -1254,7 +1237,7 @@ if [ "$INFAKEROOT" = "0" ]; then fi else if [ "$FAKEROOTKEY" = "" ]; then - error "$(gettext "Do not use the '-F' option. This option is only for use by makepkg.")" + error "$(gettext "Do not use the '-X' option. This option is only for use by makepkg.")" exit 1 # TODO: error code fi fi @@ -1333,7 +1316,7 @@ if [ "$install" -a ! -f "$install" ]; then fi # We need to run devel_update regardless of whether we are in the fakeroot -# build process so that if the user runs makepkg --forcever manually, we +# build process so that if the user runs makepkg -F (forcever) manually, we # 1) output the correct pkgver, and 2) use the correct filename when # checking if the package file already exists - fixes FS #9194 devel_check @@ -1469,9 +1452,9 @@ else msg "$(gettext "Entering fakeroot environment...")" if [ "$newpkgver" != "" ]; then - fakeroot -- $0 --forcever $newpkgver -F $ARGLIST || exit $? + fakeroot -- $0 -F $newpkgver -X $ARGLIST || exit $? else - fakeroot -- $0 -F $ARGLIST || exit $? + fakeroot -- $0 -X $ARGLIST || exit $? fi fi -- 1.5.5.1
On Mon 2008-06-02 11:54, Xavier wrote:
From f5c5a277e2df14650ae441f32950aa6d4deee50f Mon Sep 17 00:00:00 2001 From: Xavier Chantry <shiningxc@gmail.com> Date: Wed, 28 May 2008 21:57:28 +0200 Subject: [PATCH] makepkg : switch from getopt to getopts builtin
getopt is an external script for parsing and is less portable than getopts which is a bash builtin. The main problem is that it only supports short opts, so long opts had to be dropped. The benefits are a much better portability and a simpler code for the arguments parsing.
Maybe dropping all long options is not a great idea: makepkg has a lot of options and find an alphanumeric character for each is not that easy/intuitive; Furthermore getopt is ported virtually everywhere: Mac OS X, FreeBSD, OpenBSD, NetBSD etc. and stuff like asciidoc depends upon it. Bear in mind I don't have a strong opinion about that, I was just playing devil's advocate :) -- Alessio (molok) Bolognino Please send personal email to themolok@gmail.com Public Key http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xFE0270FB GPG Key ID = 1024D / FE0270FB 2007-04-11 Key Fingerprint = 9AF8 9011 F271 450D 59CF 2D7D 96C9 8F2A FE02 70FB
Alessio Bolognino wrote:
On Mon 2008-06-02 11:54, Xavier wrote:
From f5c5a277e2df14650ae441f32950aa6d4deee50f Mon Sep 17 00:00:00 2001 From: Xavier Chantry <shiningxc@gmail.com> Date: Wed, 28 May 2008 21:57:28 +0200 Subject: [PATCH] makepkg : switch from getopt to getopts builtin
getopt is an external script for parsing and is less portable than getopts which is a bash builtin. The main problem is that it only supports short opts, so long opts had to be dropped. The benefits are a much better portability and a simpler code for the arguments parsing.
Maybe dropping all long options is not a great idea: makepkg has a lot of options and find an alphanumeric character for each is not that easy/intuitive; Furthermore getopt is ported virtually everywhere: Mac OS X, FreeBSD, OpenBSD, NetBSD etc. and stuff like asciidoc depends upon it.
Wasn't the whole point of this that getopt didn't work properly/as expected on BSD?
Bear in mind I don't have a strong opinion about that, I was just playing devil's advocate :)
Well, I am not a fan! Has anybody looked into parsing options manually? I seem to recall Xavier point out a bash implementation that could be used. makepkg does not have anything too complex (options take one arg max) so it should be fairly easy. I'd much prefer a parse_options function to be added than to lose all the long options. However, if that proves too complex a solution, I will graciously accept defeat... Allan
On Mon, Jun 2, 2008 at 11:15 AM, Allan McRae <mcrae_allan@hotmail.com> wrote:
Alessio Bolognino wrote:
On Mon 2008-06-02 11:54, Xavier wrote:
From f5c5a277e2df14650ae441f32950aa6d4deee50f Mon Sep 17 00:00:00 2001 From: Xavier Chantry <shiningxc@gmail.com> Date: Wed, 28 May 2008 21:57:28 +0200 Subject: [PATCH] makepkg : switch from getopt to getopts builtin
getopt is an external script for parsing and is less portable than getopts which is a bash builtin. The main problem is that it only supports short opts, so long opts had to be dropped. The benefits are a much better portability and a simpler code for the arguments parsing.
Maybe dropping all long options is not a great idea: makepkg has a lot of options and find an alphanumeric character for each is not that easy/intuitive; Furthermore getopt is ported virtually everywhere: Mac OS X, FreeBSD, OpenBSD, NetBSD etc. and stuff like asciidoc depends upon it.
Wasn't the whole point of this that getopt didn't work properly/as expected on BSD?
Bear in mind I don't have a strong opinion about that, I was just playing devil's advocate :)
Well, I am not a fan! Has anybody looked into parsing options manually? I seem to recall Xavier point out a bash implementation that could be used. makepkg does not have anything too complex (options take one arg max) so it should be fairly easy. I'd much prefer a parse_options function to be added than to lose all the long options. However, if that proves too complex a solution, I will graciously accept defeat...
I won't graciously accept it! :) I'd much rather keep longopts, so I think a parse_options() function that uses getopts in combo with some manual longopt parsing is our best bet. -Dan
On Mon, Jun 2, 2008 at 6:29 PM, Dan McGee <dpmcgee@gmail.com> wrote:
I won't graciously accept it! :)
I'd much rather keep longopts, so I think a parse_options() function that uses getopts in combo with some manual longopt parsing is our best bet.
Ok so let's just revert to the old way: http://www.archlinux.org/pipermail/pacman-dev/2008-May/011858.html You can see the loop was approximately twice longer because longopts and shortopts are handled separately, but it might be the best compromise.
2008/6/3 Xavier <shiningxc@gmail.com>:
On Mon, Jun 2, 2008 at 6:29 PM, Dan McGee <dpmcgee@gmail.com> wrote:
I won't graciously accept it! :)
I'd much rather keep longopts, so I think a parse_options() function that uses getopts in combo with some manual longopt parsing is our best bet.
Ok so let's just revert to the old way: http://www.archlinux.org/pipermail/pacman-dev/2008-May/011858.html
You can see the loop was approximately twice longer because longopts and shortopts are handled separately, but it might be the best compromise.
Sounds reasonable. -- Roman Kyrylych (Роман Кирилич)
On Mon, Jun 2, 2008 at 5:11 PM, Alessio Bolognino <themolok.ml@gmail.com> wrote:
Maybe dropping all long options is not a great idea: makepkg has a lot of options and find an alphanumeric character for each is not that easy/intuitive; Furthermore getopt is ported virtually everywhere: Mac OS X, FreeBSD, OpenBSD, NetBSD etc. and stuff like asciidoc depends upon it.
The reason of that patch is that the different getopt implementations are not compatible : http://www.archlinux.org/pipermail/pacman-dev/2008-May/011857.html The arguments parsing currently does not work on osx / bsd.
On Tue 2008-06-03 10:45, Xavier wrote:
On Mon, Jun 2, 2008 at 5:11 PM, Alessio Bolognino <themolok.ml@gmail.com> wrote:
Maybe dropping all long options is not a great idea: makepkg has a lot of options and find an alphanumeric character for each is not that easy/intuitive; Furthermore getopt is ported virtually everywhere: Mac OS X, FreeBSD, OpenBSD, NetBSD etc. and stuff like asciidoc depends upon it.
The reason of that patch is that the different getopt implementations are not compatible : http://www.archlinux.org/pipermail/pacman-dev/2008-May/011857.html The arguments parsing currently does not work on osx / bsd.
Actually FreeBSD and NetBSD have in their port tree "getopt", which is this one: http://software.frodo.looijaard.name/getopt/ as you can see, is the same getopt in util-linux; in OpenBSD's tree is called gnugetopt, but it's still the same software. In Mac OS X it can be installed with macports, and it's called "getopt". -- Alessio (molok) Bolognino Please send personal email to themolok@gmail.com Public Key http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xFE0270FB GPG Key ID = 1024D / FE0270FB 2007-04-11 Key Fingerprint = 9AF8 9011 F271 450D 59CF 2D7D 96C9 8F2A FE02 70FB
On Tue, Jun 3, 2008 at 4:32 PM, Alessio Bolognino <themolok.ml@gmail.com> wrote:
Actually FreeBSD and NetBSD have in their port tree "getopt", which is this one: http://software.frodo.looijaard.name/getopt/ as you can see, is the same getopt in util-linux; in OpenBSD's tree is called gnugetopt, but it's still the same software. In Mac OS X it can be installed with macports, and it's called "getopt".
Now I am confused. Do they all include a getopt in their base system, for example as /bin/getopt , and then external getopt which install as /usr/bin/getopt or something? The binary name is getopt on all except on openbsd where it is gnugetopt? Or were you just talking about the package / port name? In any cases, this is very interesting, are you able to check it to be sure it works? Or anyone else?
On Tue, Jun 3, 2008 at 9:57 AM, Xavier <shiningxc@gmail.com> wrote:
On Tue, Jun 3, 2008 at 4:32 PM, Alessio Bolognino <themolok.ml@gmail.com> wrote:
Actually FreeBSD and NetBSD have in their port tree "getopt", which is this one: http://software.frodo.looijaard.name/getopt/ as you can see, is the same getopt in util-linux; in OpenBSD's tree is called gnugetopt, but it's still the same software. In Mac OS X it can be installed with macports, and it's called "getopt".
Now I am confused. Do they all include a getopt in their base system, for example as /bin/getopt , and then external getopt which install as /usr/bin/getopt or something? The binary name is getopt on all except on openbsd where it is gnugetopt? Or were you just talking about the package / port name?
In any cases, this is very interesting, are you able to check it to be sure it works? Or anyone else?
Yeah, I'm confused as well, wow. I didn't know it was this complex of a situation. I would love to see the following: 1. Where does getopt definitely work and definitely not work "out of the box"? 2. Where is (GNU) getopt available if it is installed? At first I was convinced we shouldn't use it, but now not so much. -Dan
On Tue 2008-06-03 10:22, Dan McGee wrote:
On Tue, Jun 3, 2008 at 9:57 AM, Xavier <shiningxc@gmail.com> wrote:
On Tue, Jun 3, 2008 at 4:32 PM, Alessio Bolognino <themolok.ml@gmail.com> wrote:
Actually FreeBSD and NetBSD have in their port tree "getopt", which is this one: http://software.frodo.looijaard.name/getopt/ as you can see, is the same getopt in util-linux; in OpenBSD's tree is called gnugetopt, but it's still the same software. In Mac OS X it can be installed with macports, and it's called "getopt".
Now I am confused. Do they all include a getopt in their base system, for example as /bin/getopt , and then external getopt which install as /usr/bin/getopt or something? The binary name is getopt on all except on openbsd where it is gnugetopt? Or were you just talking about the package / port name?
In any cases, this is very interesting, are you able to check it to be sure it works? Or anyone else?
Yeah, I'm confused as well, wow. I didn't know it was this complex of a situation.
I would love to see the following: 1. Where does getopt definitely work and definitely not work "out of the box"?
By default GNU getopt is not installed on BSDs.
2. Where is (GNU) getopt available if it is installed?
In Mac OS X is /opt/local/bin/getopt , in OpenBSD is /usr/local/bin/gnugetopt , in FreeBSD probably is /usr/local/bin/getopt , in NetBSD is $somewhere/getopt
At first I was convinced we shouldn't use it, but now not so much.
I don't know if this is acceptable, but we could use a function in makepkg to find the *right* getopt, something like: ------------8<-------------------8<-------------------8<--------------- getopt="" for x in `echo $PATH | sed s@:@\ @g`; do for y in getopt gnugetopt; do if [[ -x $x/$y ]]; then $x/$y --version 2>&1 | grep getopt &>/dev/null if [[ $? == 0 ]] && [[ -z $getopt ]]; then getopt=$x/$y fi fi done done echo $getopt ----------->8------------------->8------------------->8---------------- (It works because GNU getopt prints "getopt (enhanced) 1.1.4" and BSD getopt prints "--") Yeah, it's ugly. -- Alessio (molok) Bolognino Please send personal email to themolok@gmail.com Public Key http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xFE0270FB GPG Key ID = 1024D / FE0270FB 2007-04-11 Key Fingerprint = 9AF8 9011 F271 450D 59CF 2D7D 96C9 8F2A FE02 70FB
On Tue, Jun 3, 2008 at 12:31 PM, Alessio Bolognino <themolok.ml@gmail.com> wrote:
On Tue 2008-06-03 10:22, Dan McGee wrote:
On Tue, Jun 3, 2008 at 9:57 AM, Xavier <shiningxc@gmail.com> wrote:
On Tue, Jun 3, 2008 at 4:32 PM, Alessio Bolognino <themolok.ml@gmail.com> wrote:
Actually FreeBSD and NetBSD have in their port tree "getopt", which is this one: http://software.frodo.looijaard.name/getopt/ as you can see, is the same getopt in util-linux; in OpenBSD's tree is called gnugetopt, but it's still the same software. In Mac OS X it can be installed with macports, and it's called "getopt".
Now I am confused. Do they all include a getopt in their base system, for example as /bin/getopt , and then external getopt which install as /usr/bin/getopt or something? The binary name is getopt on all except on openbsd where it is gnugetopt? Or were you just talking about the package / port name?
In any cases, this is very interesting, are you able to check it to be sure it works? Or anyone else?
Yeah, I'm confused as well, wow. I didn't know it was this complex of a situation.
I would love to see the following: 1. Where does getopt definitely work and definitely not work "out of the box"?
By default GNU getopt is not installed on BSDs.
2. Where is (GNU) getopt available if it is installed?
In Mac OS X is /opt/local/bin/getopt , in OpenBSD is /usr/local/bin/gnugetopt , in FreeBSD probably is /usr/local/bin/getopt , in NetBSD is $somewhere/getopt
At first I was convinced we shouldn't use it, but now not so much.
I don't know if this is acceptable, but we could use a function in makepkg to find the *right* getopt, something like:
------------8<-------------------8<-------------------8<--------------- getopt="" for x in `echo $PATH | sed s@:@\ @g`; do for y in getopt gnugetopt; do if [[ -x $x/$y ]]; then $x/$y --version 2>&1 | grep getopt &>/dev/null if [[ $? == 0 ]] && [[ -z $getopt ]]; then getopt=$x/$y fi fi done done echo $getopt ----------->8------------------->8------------------->8----------------
(It works because GNU getopt prints "getopt (enhanced) 1.1.4" and BSD getopt prints "--")
Yeah, it's ugly.
getopt -T looks like the winner for deciding whether we have a valid getopt version installed. That doesn't solve the parsing issues though. -Dan
Dan McGee wrote:
getopt -T looks like the winner for deciding whether we have a valid getopt version installed. That doesn't solve the parsing issues though.
I am confused. which parsing issues?
Ping. Was there any decision made about this? If the getopts on the different platforms are compatible, there wouldn't be any parsing issues, would there?
On Wed, Jul 9, 2008 at 11:02 AM, Sebastian Nowicki <sebnow@gmail.com> wrote:
Ping.
Was there any decision made about this? If the getopts on the different platforms are compatible, there wouldn't be any parsing issues, would there?
I don't think so, that was the whole purpose of checking for gnu getopt. I don't even know which parsing issues Dan was talking about, parsing issues when using getopt for parsing arguments, or parsing issues inside the "gnu getopt detection" of Alessio or something else.
I just installed GNU getopt manually (not using macports) to /usr/ local on Mac OS X Leopard, and it seems to work fine. The only "problem" is that you have to modify PATH so that /usr/local is before /usr/bin so that the right one gets used. The "gnu getopt finder" code that Alessio would solve the problem (if it works properly). I haven't been able to test it on BSD yet.
participants (6)
-
Alessio Bolognino
-
Allan McRae
-
Dan McGee
-
Roman Kyrylych
-
Sebastian Nowicki
-
Xavier