diff --git a/configure.in b/configure.in index 9d2c0ab5..5ddda124 100644 --- a/configure.in +++ b/configure.in @@ -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 header file.])]) - AC_CHECK_HEADERS([readline/readline.h]) AC_SUBST(LIBREADLINE) saved_LIBS="$LIBS" diff --git a/src/common/Makefile.am b/src/common/Makefile.am index d0aa9a9f..24771bec 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -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 diff --git a/src/common/getopt.h b/src/common/getopt.h deleted file mode 100644 index 5f08ccb4..00000000 --- a/src/common/getopt.h +++ /dev/null @@ -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 */ diff --git a/src/common/my_getopt.c b/src/common/my_getopt.c index 512b0ae2..d8019553 100644 --- a/src/common/my_getopt.c +++ b/src/common/my_getopt.c @@ -23,6 +23,12 @@ * DEALINGS IN THE SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifndef HAVE_GETOPT_H + #include #include #include @@ -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 + diff --git a/src/common/my_getopt.h b/src/common/my_getopt.h index 34fcfe70..4678b544 100644 --- a/src/common/my_getopt.h +++ b/src/common/my_getopt.h @@ -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 +#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 */ diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index b88f36e8..9f168f80 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -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@ diff --git a/src/tests/sc-test.c b/src/tests/sc-test.c index a336f8b0..88462e56 100644 --- a/src/tests/sc-test.c +++ b/src/tests/sc-test.c @@ -10,9 +10,7 @@ #include #include #include -#ifdef HAVE_GETOPT_H -#include -#endif +#include "my_getopt.h" #include #include "sc-test.h" diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am index b9ee1391..d8e66ee8 100644 --- a/src/tools/Makefile.am +++ b/src/tools/Makefile.am @@ -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