[pacman-dev] [PATCH] makepkg : switch from getopt to getopts builtin

Alessio Bolognino themolok.ml at gmail.com
Tue Jun 3 13:31:04 EDT 2008


On Tue 2008-06-03 10:22, Dan McGee wrote:
> On Tue, Jun 3, 2008 at 9:57 AM, Xavier <shiningxc at gmail.com> wrote:
> > On Tue, Jun 3, 2008 at 4:32 PM, Alessio Bolognino <themolok.ml at 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 at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 194 bytes
Desc: not available
URL: <http://archlinux.org/pipermail/pacman-dev/attachments/20080603/a244e48e/attachment.pgp>


More information about the pacman-dev mailing list