I have my own C project on github. I want to add long-option support by using GNU getopt_long()
(which has it's own git repository). I believe there are 4 ways I can do this:
getopt_long()
source files of getopt.c
, getopt1.c
, and gnugetopt.h
.The advantage of 1 and 2 is that I track getopt_long()
. The advantages of 3 and 4 are that if the git repository of getopt_long()
moves, it wont break my repository and it's much simpler to do.
Is there a recommended "GNU way" to do this?
After a bit more Googl'ing, I found the official GNU answer.
Briefly, there are two recommended approaches:
Using the gnulib-tool
command, one imports getopt
to compile it as a subset of the GNU library by making a few tweaks to one's configure.ac
and Makefile.am
files.
getopt_long
sources (the "old" way)Import the getopt_long
sources of getopt.c
, getopt1.c
, and gnugetopt.h
and use the adl_func_getopt_long.m4
macro to test for the existence of getopt_long
on the platform and compile the imported sources only if necessary.