Define _XOPEN_SOURCE for Cygwin/Newlib (Issue 315)

pull/354/merge
Jeffrey Walton 2017-03-10 01:53:51 -05:00
parent 86a45fd1ca
commit a0bb490056
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
3 changed files with 19 additions and 15 deletions

View File

@ -8,6 +8,7 @@ RANLIB ?= ranlib
CP ?= cp CP ?= cp
MV ?= mv MV ?= mv
RM ?= rm -f
EGREP ?= egrep EGREP ?= egrep
CHMOD ?= chmod CHMOD ?= chmod
MKDIR ?= mkdir MKDIR ?= mkdir
@ -151,6 +152,13 @@ endif # -mtune
endif # -march endif # -march
# END MARCH_CXXFLAGS # END MARCH_CXXFLAGS
# Cygwin needs _XOPEN_SOURCE for signals
ifeq ($(IS_CYGWIN),1)
ifeq ($(findstring -D_XOPEN_SOURCE,$(CXXFLAGS)),)
CXXFLAGS += -D_XOPEN_SOURCE=700
endif
endif
# Aligned access required for -O3 and above due to vectorization # Aligned access required for -O3 and above due to vectorization
UNALIGNED_ACCESS := $(shell $(EGREP) -c "^[[:space:]]*//[[:space:]]*\#[[:space:]]*define[[:space:]]*CRYPTOPP_NO_UNALIGNED_DATA_ACCESS" config.h) UNALIGNED_ACCESS := $(shell $(EGREP) -c "^[[:space:]]*//[[:space:]]*\#[[:space:]]*define[[:space:]]*CRYPTOPP_NO_UNALIGNED_DATA_ACCESS" config.h)
ifneq ($(UNALIGNED_ACCESS),0) ifneq ($(UNALIGNED_ACCESS),0)
@ -487,7 +495,7 @@ lean: static dynamic cryptest.exe
# May want to export CXXFLAGS="-g3 -O1" # May want to export CXXFLAGS="-g3 -O1"
.PHONY: coverage .PHONY: coverage
coverage: libcryptopp.a cryptest.exe coverage: libcryptopp.a cryptest.exe
@-$(RM) -rf ./TestCoverage/ @-$(RM) -r ./TestCoverage/
lcov --base-directory . --directory . --zerocounters -q lcov --base-directory . --directory . --zerocounters -q
./cryptest.exe v ./cryptest.exe v
./cryptest.exe tv all ./cryptest.exe tv all
@ -528,10 +536,10 @@ docs html:
.PHONY: clean .PHONY: clean
clean: clean:
-$(RM) adhoc.cpp.o adhoc.cpp.proto.o $(LIBOBJS) $(TESTOBJS) $(DLLOBJS) $(LIBIMPORTOBJS) $(TESTIMPORTOBJS) $(DLLTESTOBJS) -$(RM) adhoc.cpp.o adhoc.cpp.proto.o $(LIBOBJS) rdrand-*.o $(TESTOBJS) $(DLLOBJS) $(LIBIMPORTOBJS) $(TESTIMPORTOBJS) $(DLLTESTOBJS)
@-$(RM) libcryptopp.a libcryptopp.dylib cryptopp.dll libcryptopp.dll.a libcryptopp.import.a @-$(RM) libcryptopp.a libcryptopp.dylib cryptopp.dll libcryptopp.dll.a libcryptopp.import.a
@-$(RM) libcryptopp.so libcryptopp.so$(SOLIB_COMPAT_SUFFIX) libcryptopp.so$(SOLIB_VERSION_SUFFIX) @-$(RM) libcryptopp.so libcryptopp.so$(SOLIB_COMPAT_SUFFIX) libcryptopp.so$(SOLIB_VERSION_SUFFIX)
@-$(RM) cryptest.exe dlltest.exe cryptest.import.exe cryptest.info ct rdrand-???.o @-$(RM) cryptest.exe dlltest.exe cryptest.import.exe cryptest.info ct
@-$(RM) *.gcno *.gcda *.stackdump core-* @-$(RM) *.gcno *.gcda *.stackdump core-*
@-$(RM) /tmp/adhoc.exe @-$(RM) /tmp/adhoc.exe
@-$(RM) -r /tmp/cryptopp_test/ @-$(RM) -r /tmp/cryptopp_test/
@ -544,6 +552,7 @@ distclean: clean
-$(RM) adhoc.cpp adhoc.cpp.copied GNUmakefile.deps benchmarks.html cryptest.txt cryptest-*.txt -$(RM) adhoc.cpp adhoc.cpp.copied GNUmakefile.deps benchmarks.html cryptest.txt cryptest-*.txt
@-$(RM) CMakeCache.txt Makefile CTestTestfile.cmake cmake_install.cmake cryptopp-config-version.cmake @-$(RM) CMakeCache.txt Makefile CTestTestfile.cmake cmake_install.cmake cryptopp-config-version.cmake
@-$(RM) cryptopp.tgz *.o *.bc *.ii *.s *~ @-$(RM) cryptopp.tgz *.o *.bc *.ii *.s *~
@-$(RM) -r $(SRCS:.cpp=.obj) *.suo *.sdf *.pdb Win32/ x64/ ipch/
@-$(RM) -r CMakeFiles/ @-$(RM) -r CMakeFiles/
@-$(RM) -r $(DOCUMENT_DIRECTORY)/ @-$(RM) -r $(DOCUMENT_DIRECTORY)/
@-$(RM) -r TestCoverage/ @-$(RM) -r TestCoverage/
@ -557,7 +566,7 @@ install:
-$(CHMOD) 0755 $(DESTDIR)$(INCLUDEDIR)/cryptopp -$(CHMOD) 0755 $(DESTDIR)$(INCLUDEDIR)/cryptopp
-$(CHMOD) 0644 $(DESTDIR)$(INCLUDEDIR)/cryptopp/*.h -$(CHMOD) 0644 $(DESTDIR)$(INCLUDEDIR)/cryptopp/*.h
ifneq ($(wildcard libcryptopp.a),) ifneq ($(wildcard libcryptopp.a),)
$(MKDIR) -p $(DESTDIR)$(LIBDIR) @-$(MKDIR) -p $(DESTDIR)$(LIBDIR)
$(CP) libcryptopp.a $(DESTDIR)$(LIBDIR) $(CP) libcryptopp.a $(DESTDIR)$(LIBDIR)
-$(CHMOD) 0644 $(DESTDIR)$(LIBDIR)/libcryptopp.a -$(CHMOD) 0644 $(DESTDIR)$(LIBDIR)/libcryptopp.a
endif endif
@ -575,13 +584,13 @@ ifneq ($(wildcard cryptest.exe),)
-$(CHMOD) 0644 $(DESTDIR)$(DATADIR)/cryptopp/TestVectors/*.txt -$(CHMOD) 0644 $(DESTDIR)$(DATADIR)/cryptopp/TestVectors/*.txt
endif endif
ifneq ($(wildcard libcryptopp.dylib),) ifneq ($(wildcard libcryptopp.dylib),)
$(MKDIR) -p $(DESTDIR)$(LIBDIR) @-$(MKDIR) -p $(DESTDIR)$(LIBDIR)
$(CP) libcryptopp.dylib $(DESTDIR)$(LIBDIR) $(CP) libcryptopp.dylib $(DESTDIR)$(LIBDIR)
-install_name_tool -id $(DESTDIR)$(LIBDIR)/libcryptopp.dylib $(DESTDIR)$(LIBDIR)/libcryptopp.dylib -install_name_tool -id $(DESTDIR)$(LIBDIR)/libcryptopp.dylib $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
-$(CHMOD) 0755 $(DESTDIR)$(LIBDIR)/libcryptopp.dylib -$(CHMOD) 0755 $(DESTDIR)$(LIBDIR)/libcryptopp.dylib
endif endif
ifneq ($(wildcard libcryptopp.so$(SOLIB_VERSION_SUFFIX)),) ifneq ($(wildcard libcryptopp.so$(SOLIB_VERSION_SUFFIX)),)
$(MKDIR) -p $(DESTDIR)$(LIBDIR) @-$(MKDIR) -p $(DESTDIR)$(LIBDIR)
$(CP) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR) $(CP) libcryptopp.so$(SOLIB_VERSION_SUFFIX) $(DESTDIR)$(LIBDIR)
@-$(CHMOD) 0755 $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_VERSION_SUFFIX) @-$(CHMOD) 0755 $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_VERSION_SUFFIX)
ifeq ($(HAS_SOLIB_VERSION),1) ifeq ($(HAS_SOLIB_VERSION),1)

View File

@ -668,9 +668,8 @@ NAMESPACE_END
# define THREADS_AVAILABLE # define THREADS_AVAILABLE
#endif #endif
// Newlib on Cygwin is a problem. __NEWLIB__ is not defined yet; use __CYGWIN__ as a proxy // Cygwin/Newlib requires _XOPEN_SOURCE=700
// Also see https://github.com/weidai11/cryptopp/issues/315 #if defined(CRYPTOPP_UNIX_AVAILABLE)
#if defined(CRYPTOPP_UNIX_AVAILABLE) && !defined(__CYGWIN__)
# define UNIX_SIGNALS_AVAILABLE 1 # define UNIX_SIGNALS_AVAILABLE 1
#endif #endif

View File

@ -33,7 +33,7 @@ extern "C" {
//! external "C++" linkage. //! external "C++" linkage.
//! \sa SignalHandler, SignalHandlerFn //! \sa SignalHandler, SignalHandlerFn
extern "C" { extern "C" {
inline void NullSignalHandler(int unused) {CRYPTOPP_UNUSED(unused);} inline void NullSignalHandler(int unused) {CRYPTOPP_UNUSED(unused);}
}; };
//! Signal handler for Linux and Unix compatibles //! Signal handler for Linux and Unix compatibles
@ -82,13 +82,9 @@ struct SignalHandler
// Don't step on another's handler if Overwrite=false // Don't step on another's handler if Overwrite=false
if (m_old.sa_handler != 0 && !O) break; if (m_old.sa_handler != 0 && !O) break;
#if defined __CYGWIN__ // Cygwin/Newlib requires -D_XOPEN_SOURCE=700
// http://github.com/weidai11/cryptopp/issues/315
memset(&new_handler, 0x00, sizeof(new_handler));
#else
ret = sigemptyset (&new_handler.sa_mask); ret = sigemptyset (&new_handler.sa_mask);
if (ret != 0) break; // Failed if (ret != 0) break; // Failed
#endif
new_handler.sa_handler = (pfn ? pfn : &NullSignalHandler); new_handler.sa_handler = (pfn ? pfn : &NullSignalHandler);
new_handler.sa_flags = (pfn ? flags : 0); new_handler.sa_flags = (pfn ? flags : 0);