- remove src/common/getopt.h since it collide with /usr/include/getopt.h

- replace @GETOPTSRC@ by $(top_srcdir)/src/common/my_getopt.c in
  Makefile.am files

- change the detection of getopt_long in configure.in since GETOPTSRC is
  not used anymore. my_getopt.c is now always compiled and used but
  provides getopt_long() only if HAVE_GETOPT_H is NOT defined (ie. if
  getopt_long() is not provided by the system)

- src/common/my_getopt.c: the code is within #ifndef HAVE_GETOPT_H

- move the useful lines of src/common/getopt.h in src/common/my_getopt.h


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2989 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
ludovic.rousseau 2006-07-12 07:43:38 +00:00
parent 1eb33bc946
commit 2495268d98
8 changed files with 55 additions and 96 deletions

View File

@ -96,7 +96,10 @@ dnl Checks for library functions.
AC_FUNC_ERROR_AT_LINE
AC_FUNC_STAT
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([getpass gettimeofday memset mkdir strdup strerror setutent vsyslog setlocale])
AC_CHECK_FUNCS([getpass gettimeofday memset mkdir strdup strerror setutent vsyslog setlocale getopt_long])
# if the system does not provide strlcpy() we provide our own version
AC_CHECK_FUNCS(strlcpy)
AC_CHECK_HEADERS([zlib.h],[LIBS="$LIBS -lz"])
@ -120,12 +123,6 @@ if test x$ac_cv_func_socket_in_lsocket = xyes; then
AC_CHECK_LIB(resolv, res_query, [LIBS="$LIBS -lresolv" ac_cv_func_res_query_in_lresolv=yes])
fi
AC_SUBST(GETOPTSRC)
AC_CHECK_FUNC(getopt_long, AC_DEFINE(HAVE_GETOPT_LONG, 1, [Define if you have the `getopt_long' function.]),
[GETOPTSRC="$GETOPTSRC \$(top_srcdir)/src/common/my_getopt.c"
CPPFLAGS="-I\$(top_srcdir)/src/common $CPPFLAGS"
AC_DEFINE(HAVE_GETOPT_H, 1, [Define if you have the <getopt.h> header file.])])
AC_CHECK_HEADERS([readline/readline.h])
AC_SUBST(LIBREADLINE)
saved_LIBS="$LIBS"

View File

@ -3,5 +3,5 @@
MAINTAINERCLEANFILES = Makefile.in
EXTRA_DIST = Makefile.mak getpass.c \
ChangeLog LICENSE README.my_getopt getopt.3 getopt.h getopt.txt \
ChangeLog LICENSE README.my_getopt getopt.3 getopt.txt \
main.c my_getopt.c my_getopt.h

View File

@ -1,56 +0,0 @@
/*
* getopt.h - cpp wrapper for my_getopt to make it look like getopt.
* Copyright 1997, 2000, 2001, 2002, Benjamin Sittler
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef MY_WRAPPER_GETOPT_H_INCLUDED
#define MY_WRAPPER_GETOPT_H_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
#include "my_getopt.h"
#undef getopt
#define getopt my_getopt
#undef getopt_long
#define getopt_long my_getopt_long
#undef getopt_long_only
#define getopt_long_only my_getopt_long_only
#undef _getopt_internal
#define _getopt_internal _my_getopt_internal
#undef opterr
#define opterr my_opterr
#undef optind
#define optind my_optind
#undef optopt
#define optopt my_optopt
#undef optarg
#define optarg my_optarg
#ifdef __cplusplus
}
#endif
#endif /* MY_WRAPPER_GETOPT_H_INCLUDED */

View File

@ -23,6 +23,12 @@
* DEALINGS IN THE SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef HAVE_GETOPT_H
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
@ -269,3 +275,6 @@ int my_getopt_long_only(int argc, char * argv[], const char *shortopts,
{
return _my_getopt_internal(argc, argv, shortopts, longopts, longind, 1);
}
#endif

View File

@ -26,10 +26,27 @@
#ifndef MY_GETOPT_H_INCLUDED
#define MY_GETOPT_H_INCLUDED
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#else
#ifdef __cplusplus
extern "C" {
#endif
#define getopt my_getopt
#define getopt_long my_getopt_long
#define getopt_long_only my_getopt_long_only
#define _getopt_internal _my_getopt_internal
#define opterr my_opterr
#define optind my_optind
#define optopt my_optopt
#define optarg my_optarg
/* UNIX-style short-argument parser */
extern int my_getopt(int argc, char * argv[], const char *opts);
@ -66,4 +83,6 @@ extern int _my_getopt_internal(int argc, char * argv[], const char *shortopts,
}
#endif
#endif /* HAVE_GETOPT_H */
#endif /* MY_GETOPT_H_INCLUDED */

View File

@ -7,19 +7,15 @@ SUBDIRS = . regression
EXTRA_DIST = Makefile.mak
AM_LDFLAGS = @LIBOPENSC@ $(LTLIBLTDL)
AM_CFLAGS = -I$(top_srcdir)/src/common
noinst_PROGRAMS = base64 lottery p15dump pintest prngtest
SRC = sc-test.c
SRC = sc-test.c $(top_srcdir)/src/common/my_getopt.c
INC = sc-test.h
base64_SOURCES = base64.c $(SRC) $(INC)
base64_LDADD = @GETOPTSRC@
lottery_SOURCES = lottery.c $(SRC) $(INC)
lottery_LDADD = @GETOPTSRC@
p15dump_SOURCES = p15dump.c print.c $(SRC) $(INC)
p15dump_LDADD = @GETOPTSRC@
pintest_SOURCES = pintest.c print.c $(SRC) $(INC)
pintest_LDADD = @GETOPTSRC@
prngtest_SOURCES = prngtest.c $(SRC) $(INC)
prngtest_LDADD = @GETOPTSRC@

View File

@ -10,9 +10,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include "my_getopt.h"
#include <opensc/opensc.h>
#include "sc-test.h"

View File

@ -4,7 +4,7 @@ MAINTAINERCLEANFILES = Makefile.in
EXTRA_DIST = Makefile.mak
AM_CFLAGS = $(OPENSSL_CFLAGS)
AM_CFLAGS = $(OPENSSL_CFLAGS) -I$(top_srcdir)/src/common
AM_LDFLAGS = @LIBOPENSC@
if HAVE_OPENSSL
@ -16,27 +16,23 @@ bin_PROGRAMS = opensc-tool opensc-explorer pkcs15-tool pkcs15-crypt \
pkcs11-tool cardos-info eidenv \
$(PROGRAMS_OPENSSL)
opensc_tool_SOURCES = opensc-tool.c util.c
opensc_tool_LDADD = @GETOPTSRC@
piv_tool_SOURCES = piv-tool.c util.c
piv_tool_LDADD = @GETOPTSRC@
opensc_explorer_SOURCES = opensc-explorer.c util.c
opensc_explorer_LDADD = @GETOPTSRC@ $(LIBREADLINE)
pkcs15_tool_SOURCES = pkcs15-tool.c util.c
pkcs15_tool_LDADD = @GETOPTSRC@ $(OPENSSL_LIBS)
pkcs11_tool_SOURCES = pkcs11-tool.c util.c
pkcs11_tool_LDADD = @GETOPTSRC@ ../pkcs11/libpkcs11.la $(OPENSSL_LIBS) $(LTLIBLTDL)
pkcs15_crypt_SOURCES = pkcs15-crypt.c util.c
pkcs15_crypt_LDADD = @GETOPTSRC@ $(OPENSSL_LIBS)
cryptoflex_tool_SOURCES = cryptoflex-tool.c util.c
cryptoflex_tool_LDADD = @GETOPTSRC@ $(OPENSSL_LIBS)
pkcs15_init_SOURCES = pkcs15-init.c util.c
pkcs15_init_LDADD = @GETOPTSRC@ $(OPENSSL_LIBS) ../pkcs15init/libpkcs15init.la
cardos_info_SOURCES = cardos-info.c util.c
cardos_info_LDADD = @GETOPTSRC@
eidenv_SOURCES = eidenv.c
eidenv_LDADD = @GETOPTSRC@
netkey_tool_SOURCES = netkey-tool.c
netkey_tool_LDADD = @GETOPTSRC@ $(OPENSSL_LIBS)
opensc_tool_SOURCES = opensc-tool.c util.c $(top_srcdir)/src/common/my_getopt.c
piv_tool_SOURCES = piv-tool.c util.c $(top_srcdir)/src/common/my_getopt.c
opensc_explorer_SOURCES = opensc-explorer.c util.c $(top_srcdir)/src/common/my_getopt.c
opensc_explorer_LDADD = $(LIBREADLINE)
pkcs15_tool_SOURCES = pkcs15-tool.c util.c $(top_srcdir)/src/common/my_getopt.c
pkcs15_tool_LDADD = $(OPENSSL_LIBS)
pkcs11_tool_SOURCES = pkcs11-tool.c util.c $(top_srcdir)/src/common/my_getopt.c
pkcs11_tool_LDADD = ../pkcs11/libpkcs11.la $(OPENSSL_LIBS) $(LTLIBLTDL)
pkcs15_crypt_SOURCES = pkcs15-crypt.c util.c $(top_srcdir)/src/common/my_getopt.c
pkcs15_crypt_LDADD = $(OPENSSL_LIBS)
cryptoflex_tool_SOURCES = cryptoflex-tool.c util.c $(top_srcdir)/src/common/my_getopt.c
cryptoflex_tool_LDADD = $(OPENSSL_LIBS)
pkcs15_init_SOURCES = pkcs15-init.c util.c $(top_srcdir)/src/common/my_getopt.c
pkcs15_init_LDADD = $(OPENSSL_LIBS) ../pkcs15init/libpkcs15init.la
cardos_info_SOURCES = cardos-info.c util.c $(top_srcdir)/src/common/my_getopt.c
eidenv_SOURCES = eidenv.c $(top_srcdir)/src/common/my_getopt.c
netkey_tool_SOURCES = netkey-tool.c $(top_srcdir)/src/common/my_getopt.c
netkey_tool_LDADD = $(OPENSSL_LIBS)
noinst_HEADERS = util.h