[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
There is a template named, ‘getopt.tpl’ that is distributed with
AutoOpts. Using that template instead of ‘options.tpl’ will produce
completely independent source code that will parse command line options. It
will utilize either the standard getopt(3C)
or the GNU
getopt_long(3GNU)
function to drive the parsing. Which is used is
selected by the presence or absence of the long-opts
program attribute.
It will save you from being dependent upon the libopts
library and
it produces code ready for internationalization. However, it also carries
with it some limitations on the use of AutoOpts features and some requirements
on the build environment.
PLEASE NOTE: in processing the option definitions to produce
the usage text, it is necessary to compile some generated code in a
temporary directory. That means that all the include directories
needed to compile the code must be full path names and not relative
directory names. “.” is a relative directory name. To specify
“-I.” in the CFLAGS
environment variable, you must expand it.
For example, use:
CFLAGS=-I`pwd` |
7.15.1 getopt feature limitations | ||
7.15.2 getopt build requirements |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This list of limitations is relative to the full list of AutoOpts supported features, See section AutoOpts Features.
rc
or ini
files).
Consequently, the resulting code does not support ‘--load-opts’ or
‘--save-opts’ options automatically.
libopts
library. You are constrained to options that
take string
arguments, though you may handle the option
argument with a callback procedure.
settable
because the emitted code
depends upon the SET_OPT_XXX
macros having been defined.
Specify this as a global (program) attribute.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
You must supply some compile and link options via environment variables.
In case the option definition file lives in a different directory.
Any special flags required to compile. The flags from
autoopts-config cflags
will be included automatically. Since
the creation of the option parsing code includes creating a program
that prints out help text, if it is necessary to include files from
various directories to compile that program, you will need to specify
those directories with ‘-Idirpath’ text in the CFLAGS
.
Some experimentation may be necessary in that case.
NOTE: the ‘-Idirpath’ text is only needed if your option
callback functions include code that require additional #include
directives.
Any special flags required to link. The flags from
autoopts-config ldflags
will be included automatically. This
is required only if additional link flags for the help text emission
program might be needed.
This is needed only if
cannot be found in cc
$PATH
(or it is not the one you want).
To use this, set the exported environment variables and specify getopt
as the default template in your option definitions file
(see section The Identification Definition). You will have four new files. Assuming your
definitions were in a file named ‘myprog-opts.def’ and your program name
was specified as ‘progname’, the resulting files would be created:
‘myprog-opts.h’, ‘myprog-opts.c’, ‘getopt-progname.h’ and
‘getopt-progname.c’. You must compile and link both ‘.c’ files into
your program. If there are link failures, then you are using AutoOpts
features that require the ‘libopts’ library. You must remove these
features, See section getopt feature limitations.
These generated files depend upon configure defines to work correctly.
Therefore, you must specify a config-header
attribute
(see section Programming Details) and ensure it has #defines
for
either HAVE_STDINT_H
or HAVE_INTTYPES_H
; either
HAVE_SYS_LIMITS_H
or HAVE_LIMITS_H
; and
HAVE_SYSEXITS_H
, if the ‘sysexits.h’ header is available.
The required header files for these defines are, respectively,
the ‘/usr/include’ files named:
The following header files must also exist on the build platform:
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] |
This document was generated by Bruce Korb on August 21, 2015 using texi2html 1.82.