Page 1 of 1

getopt_long for IRIX

Posted: Wed Jul 04, 2012 9:01 pm
by BSDero
Hi guys!!

I was playing with my SGI and needed an Irix implementation of getopt_long(), so I got source code from NetBSD and OpenBSD and created a SGI version of it.

I tested an example program of getopt_long() I found in google and all seems works flawlessly :), except by a one line change. However the behavior is same than gnu's getopt_long().

I got a tar with sources, header, Makefile and test program, it builds with MipsPro in Irix 6.5. If anybody interested, I would like to share this.

Re: getopt_long for IRIX

Posted: Wed Jul 04, 2012 10:17 pm
by PymbleSoftware
BSDero wrote:Hi guys!!

I was playing with my SGI and needed an Irix implementation of getopt_long(), so I got source code from NetBSD and OpenBSD and created a SGI version of it.

I tested an example program of getopt_long() I found in google and all seems works flawlessly :), except by a one line change. However the behavior is same than gnu's getopt_long().

I got a tar with sources, header, Makefile and test program, it builds with MipsPro in Irix 6.5. If anybody interested, I would like to share this.


From memory there is/was something about this on the MIPS Pro nekochan wiki page.. if not I intended to put something on there at the same time I wrote the section on work arounds or porting or something like that..

EDIT
oh, wait nup.. that was the senenv/putenv thing .. I did have a solution for getopt_long() which I intended to put in a section after ..
http://www.nekochan.net/wiki/MIPS_Pro#s ... ng_in_IRIX

I think I did this when porting hercules IBM mainframe emulator to IRIX.. years ago..

R.

Re: getopt_long for IRIX

Posted: Thu Jul 05, 2012 11:49 am
by canavan
An Implementation of getopt_long is part of gnulib http://www.gnu.org/software/gnulib/MODULES.html#module=getopt-posix. I usually just copy the source files into a suitable directory and add them to the list of .c-Files in the Makefile.

Re: getopt_long for IRIX

Posted: Thu Jul 05, 2012 1:44 pm
by PymbleSoftware
Updated to the wiki to point back here.... http://www.nekochan.net/wiki/MIPSpro#ge ... ng_in_IRIX

R.

Re: getopt_long for IRIX

Posted: Wed Jul 11, 2012 8:08 am
by BSDero
In those GCC-isms related issues I've found *bsd source code easier to port and maintain witrhout all that flags and thinks like that. Source code is way easier to port, clear and maintain.

Re: getopt_long for IRIX

Posted: Tue Sep 12, 2017 12:17 pm
by necron2600
For anyone who has trouble with getopt_long and IRIX..
I know we have a Wiki on this that says "google around for the example code to implement this" .. which was not very helpful for me.
Granted, once I figured it out, it now seems easy but it took some time for me to get to that point. I want this thread to help anyone else with this problem.

Attached is a tarball with ya_getopt .. Yet-Another getopt implementation.. compiles on IRIX and I tested it already (however not very extensively! so hopefully nothing breaks from this).

Tarball contains:
tar tpf ../getopt_long-in-irix.tar

Code: Select all

getopt_long-in-irix/ya_getopt.c
getopt_long-in-irix/ya_getopt.h
getopt_long-in-irix/libya_getopt.so
getopt_long-in-irix/README


the .c and .h are from ya_getopt. libya_getopt.so is a compiled shared library on IRIX 6.5/mips4 with GCC (we all love GCC right? ;)

The README has some rough notes for anyone who may find themselves in a getopt_long() missing situation and may be clueless as to what to do:

Here is the README (its rough notes.. )

Code: Select all

# These are notes for getopt_lang() in IRIX (GCC)

# Yet Another GetOpt implementation (drop-in)
https://github.com/kubo/ya_getopt

# COMPILE shared library (GCC)
# http://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html
gcc -c -Wall -Werror -fpic ya_getopt.c
gcc -shared -o libya_getopt.so ya_getopt.o

# LINK with your code (examples)
gcc -Wall -o test main.c -lya_getopt
# LINK with your code specifying .so library directory location
gcc -L/whereis/ya_getopt/ -Wall -o test main.c -lya_getopt

# Copy ya_getopt.h to your source and edit relevant files:
#include "ya_getopt.h"

# Replace getopt_long() calls in your code to ya_getopt_long()

# Example Makefile changes (and/or Environment variable adjustments)
LDFLAGS = -L/usr/nekoware/lib -L/usr/lib32 -L/whereis/ya_getopt/
LIBS = -lya_getopt

# Note:
Ensure libya_getopt.so is stored somewhere where the binary can access
Such as /usr/local/lib/


It does compile with MIPSpro as well:
cc -c ya_getopt.c
cc -shared -o libya_getopt.so ya_getopt.o

Thanks again to Kubo @ https://github.com/kubo/ya_getopt for his ya_getopt code.

getopt_long-in-irix.tar
(90 KiB) Downloaded 5 times

Re: getopt_long for IRIX

Posted: Fri Sep 15, 2017 11:57 pm
by duck
NetBSD's pkgsrc has a package with netbsd-compatibility functions that include getopt_long. It's called libnbcompat. This works on IRIX, and might provide other useful things if you are feeling porty.

http://pkgsrc.se/pkgtools/libnbcompat
http://cdn.netbsd.org/pub/pkgsrc/curren ... pat/files/

The files in files/ should be enough to compile and you won't need the pkgsrc tree.

Edit: added URL to the files