Upgrade libevent to release-2.1.12-stable

Change-Id: Id26c13a4fc1e140627d8869de2b6e2929f8a2a7b
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 70acb69..676727f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,16 +46,13 @@
 
 project(libevent C)
 
-set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
+list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
 string(REGEX MATCH "SunOS" SOLARIS "${CMAKE_SYSTEM_NAME}")
 
 
 include(CheckTypeSize)
-include(CheckFunctionExistsEx)
 include(CheckFileOffsetBits)
-include(CheckFunctionExists)
-include(CheckIncludeFile)
-include(CheckIncludeFiles)
+include(Macros)
 include(CheckVariableExists)
 include(CheckSymbolExists)
 include(CheckStructHasMember)
@@ -84,10 +81,10 @@
 set(EVENT_PACKAGE_VERSION
     "${EVENT_VERSION_MAJOR}.${EVENT_VERSION_MINOR}.${EVENT_VERSION_PATCH}")
 
-set(EVENT_NUMERIC_VERSION 0x02010b00)
+set(EVENT_NUMERIC_VERSION 0x02010c00)
 # equals to VERSION_INFO in Makefile.am
 set(EVENT_ABI_LIBVERSION_CURRENT   7)
-set(EVENT_ABI_LIBVERSION_REVISION  0)
+set(EVENT_ABI_LIBVERSION_REVISION  1)
 set(EVENT_ABI_LIBVERSION_AGE       0)
 
 # equals to RELEASE in Makefile.am
@@ -158,9 +155,18 @@
 
 # Put the libaries and binaries that get built into directories at the
 # top of the build tree rather than in hard-to-find leaf directories.
-set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
-set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
-set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
+#
+# But only if this variables are not defined yet
+# (i.e. libevent is used via add_subdirectory())
+if (NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
+    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
+endif()
+if (NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY)
+    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
+endif()
+if (NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
+    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
+endif()
 
 if (EVENT__ENABLE_VERBOSE_DEBUG)
     add_definitions(-DUSE_DEBUG=1)
@@ -243,7 +249,6 @@
 
     if (EVENT__MSVC_STATIC_RUNTIME)
         foreach (flag_var
-                 CMAKE_C_FLAGS
                  CMAKE_C_FLAGS_DEBUG
                  CMAKE_C_FLAGS_RELEASE
                  CMAKE_C_FLAGS_MINSIZEREL
@@ -326,11 +331,14 @@
     )
 endif()
 
+if (MINGW OR CYGWIN)
+    set(WIN32 TRUE)
+endif()
+
 # Winsock.
 if(WIN32)
-    set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h ws2tcpip.h)
-    set(CMAKE_REQUIRED_LIBRARIES  ws2_32.lib shell32.lib advapi32.lib)
-    set(CMAKE_REQUIRED_DEFINITIONS -FIwinsock2.h -FIws2tcpip.h)
+    set(CMAKE_REQUIRED_LIBRARIES  ws2_32 shell32 advapi32)
+    set(CMAKE_REQUIRED_DEFINITIONS -FIwinsock2.h -FIws2tcpip.h -D_WIN32_WINNT=0x0600)
 endif()
 if (SOLARIS)
     set(CMAKE_REQUIRED_LIBRARIES socket nsl)
@@ -352,145 +360,161 @@
 
 if (_GNU_SOURCE)
     add_definitions(-D_GNU_SOURCE=1)
+    set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
 endif()
 
-CHECK_INCLUDE_FILE(sys/types.h EVENT__HAVE_SYS_TYPES_H)
-if(EVENT__HAVE_SYS_TYPES_H)
-    list(APPEND CMAKE_EXTRA_INCLUDE_FILES sys/types.h)
+# Check if header files exist
+list(APPEND FILES_TO_CHECK
+    fcntl.h
+    inttypes.h
+    memory.h
+    signal.h
+    stdarg.h
+    stddef.h
+    stdint.h
+    stdlib.h
+    string.h
+    errno.h
+    unistd.h
+    time.h
+    sys/types.h
+    sys/stat.h
+    sys/time.h
+    sys/param.h
+)
+if (WIN32)
+    list(APPEND FILES_TO_CHECK
+        io.h
+        winsock2.h
+        ws2tcpip.h
+        afunix.h
+    )
+else()
+    list(APPEND FILES_TO_CHECK
+        netdb.h
+        dlfcn.h
+        arpa/inet.h
+        poll.h
+        port.h
+        sys/socket.h
+        sys/random.h
+        sys/un.h
+        sys/devpoll.h
+        sys/epoll.h
+        sys/eventfd.h
+        sys/event.h
+        sys/ioctl.h
+        sys/mman.h
+        sys/queue.h
+        sys/select.h
+        sys/sendfile.h
+        sys/uio.h
+        sys/wait.h
+        sys/resource.h
+        sys/timerfd.h
+        netinet/in.h
+        netinet/in6.h
+        netinet/tcp.h
+        ifaddrs.h
+    )
 endif()
 
-CHECK_INCLUDE_FILE(sys/socket.h EVENT__HAVE_SYS_SOCKET_H)
-if(EVENT__HAVE_SYS_SOCKET_H)
-    list(APPEND CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
+if (NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
+    list(APPEND FILES_TO_CHECK sys/sysctl.h)
 endif()
 
-CHECK_INCLUDE_FILE(netinet/in.h EVENT__HAVE_NETINET_IN_H)
-if(EVENT__HAVE_NETINET_IN_H)
-    list(APPEND CMAKE_EXTRA_INCLUDE_FILES netinet/in.h)
+if (APPLE)
+    list(APPEND FILES_TO_CHECK
+        mach/mach_time.h
+        mach/mach.h
+    )
 endif()
 
-CHECK_INCLUDE_FILE(sys/un.h EVENT__HAVE_SYS_UN_H)
-if(EVENT__HAVE_SYS_UN_H)
-    list(APPEND CMAKE_EXTRA_INCLUDE_FILES sys/un.h)
+foreach(FILE ${FILES_TO_CHECK})
+    CHECK_INCLUDE_FILE_CONCAT(${FILE} "EVENT")
+endforeach()
+unset(FILES_TO_CHECK)
+
+# Check if functions exist
+list(APPEND SYMBOLS_TO_CHECK
+    getaddrinfo
+    getnameinfo
+    getprotobynumber
+    getservbyname
+    gethostbyname
+    inet_ntop
+    inet_pton
+    gettimeofday
+    signal
+    strtoll
+    splice
+    strlcpy
+    strsep
+    strtok_r
+    vasprintf
+    timerclear
+    timercmp
+    timerisset
+    timeradd
+    nanosleep
+    putenv
+    umask
+)
+if (NOT EVENT__DISABLE_CLOCK_GETTIME)
+    list(APPEND SYMBOLS_TO_CHECK clock_gettime)
 endif()
 
-if(WIN32)
-    CHECK_INCLUDE_FILE(afunix.h EVENT__HAVE_AFUNIX_H)
-    if(EVENT__HAVE_AFUNIX_H)
-        list(APPEND CMAKE_EXTRA_INCLUDE_FILES afunix.h)
+if (WIN32)
+    list(APPEND SYMBOLS_TO_CHECK
+        _gmtime64_s
+        _gmtime64
+    )
+else()
+    list(APPEND SYMBOLS_TO_CHECK
+        getifaddrs
+        select
+        epoll_create
+        epoll_create1
+        epoll_ctl
+        eventfd
+        poll
+        port_create
+        kqueue
+        fcntl
+        mmap
+        pipe
+        pipe2
+        sendfile
+        sigaction
+        strsignal
+        sysctl
+        accept4
+        arc4random
+        arc4random_buf
+        arc4random_addrandom
+        getrandom
+        getegid
+        geteuid
+        issetugid
+        usleep
+        timerfd_create
+        setenv
+        unsetenv
+        setrlimit
+        gethostbyname_r
+    )
+    if (APPLE)
+        list(APPEND SYMBOLS_TO_CHECK mach_absolute_time)
     endif()
 endif()
-CHECK_TYPE_SIZE("struct sockaddr_un" EVENT__HAVE_STRUCT_SOCKADDR_UN)
 
-CHECK_INCLUDE_FILE(netinet/in6.h EVENT__HAVE_NETINET_IN6_H)
-if(EVENT__HAVE_NETINET_IN6_H)
-    list(APPEND CMAKE_EXTRA_INCLUDE_FILES netinet/in6.h)
-endif()
-
-CHECK_INCLUDE_FILE(unistd.h EVENT__HAVE_UNISTD_H)
-CHECK_INCLUDE_FILE(netdb.h EVENT__HAVE_NETDB_H)
-CHECK_INCLUDE_FILE(dlfcn.h EVENT__HAVE_DLFCN_H)
-CHECK_INCLUDE_FILE(arpa/inet.h EVENT__HAVE_ARPA_INET_H)
-CHECK_INCLUDE_FILE(fcntl.h EVENT__HAVE_FCNTL_H)
-if(EVENT__HAVE_FCNTL_H)
-    list(APPEND CMAKE_EXTRA_INCLUDE_FILES fcntl.h)
-endif()
-CHECK_INCLUDE_FILE(inttypes.h EVENT__HAVE_INTTYPES_H)
-CHECK_INCLUDE_FILE(memory.h EVENT__HAVE_MEMORY_H)
-CHECK_INCLUDE_FILE(poll.h EVENT__HAVE_POLL_H)
-CHECK_INCLUDE_FILE(port.h EVENT__HAVE_PORT_H)
-if(EVENT__HAVE_PORT_H)
-    list(APPEND CMAKE_EXTRA_INCLUDE_FILES port.h)
-endif()
-CHECK_INCLUDE_FILE(signal.h EVENT__HAVE_SIGNAL_H)
-CHECK_INCLUDE_FILE(stdarg.h EVENT__HAVE_STDARG_H)
-CHECK_INCLUDE_FILE(stddef.h EVENT__HAVE_STDDEF_H)
-CHECK_INCLUDE_FILE(stdint.h EVENT__HAVE_STDINT_H)
-CHECK_INCLUDE_FILE(stdlib.h EVENT__HAVE_STDLIB_H)
-CHECK_INCLUDE_FILE(strings.h EVENT__HAVE_STRINGS_H)
-CHECK_INCLUDE_FILE(string.h EVENT__HAVE_STRING_H)
-CHECK_INCLUDE_FILE(sys/devpoll.h EVENT__HAVE_DEVPOLL)
-CHECK_INCLUDE_FILE(sys/epoll.h EVENT__HAVE_SYS_EPOLL_H)
-CHECK_INCLUDE_FILE(sys/eventfd.h EVENT__HAVE_SYS_EVENTFD_H)
-CHECK_INCLUDE_FILE(sys/event.h EVENT__HAVE_SYS_EVENT_H)
-CHECK_INCLUDE_FILE(sys/ioctl.h EVENT__HAVE_SYS_IOCTL_H)
-CHECK_INCLUDE_FILE(sys/mman.h EVENT__HAVE_SYS_MMAN_H)
-CHECK_INCLUDE_FILE(sys/param.h EVENT__HAVE_SYS_PARAM_H)
-CHECK_INCLUDE_FILE(sys/queue.h EVENT__HAVE_SYS_QUEUE_H)
-CHECK_INCLUDE_FILE(sys/select.h EVENT__HAVE_SYS_SELECT_H)
-CHECK_INCLUDE_FILE(sys/sendfile.h EVENT__HAVE_SYS_SENDFILE_H)
-CHECK_INCLUDE_FILE(sys/stat.h EVENT__HAVE_SYS_STAT_H)
-CHECK_INCLUDE_FILE(sys/time.h EVENT__HAVE_SYS_TIME_H)
-if(EVENT__HAVE_SYS_TIME_H)
-    list(APPEND CMAKE_EXTRA_INCLUDE_FILES sys/time.h)
-endif()
-CHECK_INCLUDE_FILE(sys/uio.h EVENT__HAVE_SYS_UIO_H)
-CHECK_INCLUDE_FILES("sys/types.h;ifaddrs.h" EVENT__HAVE_IFADDRS_H)
-CHECK_INCLUDE_FILE(mach/mach_time.h EVENT__HAVE_MACH_MACH_TIME_H)
-CHECK_INCLUDE_FILE(netinet/tcp.h EVENT__HAVE_NETINET_TCP_H)
-CHECK_INCLUDE_FILE(sys/wait.h EVENT__HAVE_SYS_WAIT_H)
-CHECK_INCLUDE_FILE(sys/resource.h EVENT__HAVE_SYS_RESOURCE_H)
-CHECK_INCLUDE_FILE(sys/sysctl.h EVENT__HAVE_SYS_SYSCTL_H)
-CHECK_INCLUDE_FILE(sys/timerfd.h EVENT__HAVE_SYS_TIMERFD_H)
-CHECK_INCLUDE_FILE(errno.h EVENT__HAVE_ERRNO_H)
-
-
-CHECK_FUNCTION_EXISTS_EX(epoll_create EVENT__HAVE_EPOLL)
-CHECK_FUNCTION_EXISTS_EX(epoll_ctl EVENT__HAVE_EPOLL_CTL)
-CHECK_FUNCTION_EXISTS_EX(eventfd EVENT__HAVE_EVENTFD)
-if(NOT EVENT__DISABLE_CLOCK_GETTIME)
-    CHECK_FUNCTION_EXISTS_EX(clock_gettime EVENT__HAVE_CLOCK_GETTIME)
-endif()
-CHECK_FUNCTION_EXISTS_EX(fcntl EVENT__HAVE_FCNTL)
-CHECK_FUNCTION_EXISTS_EX(getaddrinfo EVENT__HAVE_GETADDRINFO)
-CHECK_FUNCTION_EXISTS_EX(getnameinfo EVENT__HAVE_GETNAMEINFO)
-CHECK_FUNCTION_EXISTS_EX(gettimeofday EVENT__HAVE_GETTIMEOFDAY)
-CHECK_FUNCTION_EXISTS_EX(getprotobynumber EVENT__HAVE_GETPROTOBYNUMBER)
-CHECK_FUNCTION_EXISTS_EX(getservbyname EVENT__HAVE_GETSERVBYNAME)
-CHECK_FUNCTION_EXISTS_EX(inet_ntop EVENT__HAVE_INET_NTOP)
-CHECK_FUNCTION_EXISTS_EX(inet_pton EVENT__HAVE_INET_PTON)
-CHECK_FUNCTION_EXISTS_EX(kqueue EVENT__HAVE_KQUEUE)
-CHECK_FUNCTION_EXISTS_EX(mmap EVENT__HAVE_MMAP)
-CHECK_FUNCTION_EXISTS_EX(pipe EVENT__HAVE_PIPE)
-CHECK_FUNCTION_EXISTS_EX(pipe2 EVENT__HAVE_PIPE2)
-CHECK_FUNCTION_EXISTS_EX(poll EVENT__HAVE_POLL)
-CHECK_FUNCTION_EXISTS_EX(port_create EVENT__HAVE_PORT_CREATE)
-CHECK_FUNCTION_EXISTS_EX(sendfile EVENT__HAVE_SENDFILE)
-CHECK_FUNCTION_EXISTS_EX(sigaction EVENT__HAVE_SIGACTION)
-CHECK_FUNCTION_EXISTS_EX(signal EVENT__HAVE_SIGNAL)
-CHECK_FUNCTION_EXISTS_EX(splice EVENT__HAVE_SPLICE)
-CHECK_FUNCTION_EXISTS_EX(strlcpy EVENT__HAVE_STRLCPY)
-CHECK_FUNCTION_EXISTS_EX(strsep EVENT__HAVE_STRSEP)
-CHECK_FUNCTION_EXISTS_EX(strtok_r EVENT__HAVE_STRTOK_R)
-CHECK_FUNCTION_EXISTS_EX(strtoll EVENT__HAVE_STRTOLL)
-CHECK_FUNCTION_EXISTS_EX(vasprintf EVENT__HAVE_VASPRINTF)
-CHECK_FUNCTION_EXISTS_EX(sysctl EVENT__HAVE_SYSCTL)
-CHECK_FUNCTION_EXISTS_EX(accept4 EVENT__HAVE_ACCEPT4)
-CHECK_FUNCTION_EXISTS_EX(arc4random EVENT__HAVE_ARC4RANDOM)
-CHECK_FUNCTION_EXISTS_EX(arc4random_buf EVENT__HAVE_ARC4RANDOM_BUF)
-CHECK_FUNCTION_EXISTS_EX(arc4random_addrandom EVENT__HAVE_ARC4RANDOM_ADDRANDOM)
-CHECK_FUNCTION_EXISTS_EX(epoll_create1 EVENT__HAVE_EPOLL_CREATE1)
-CHECK_FUNCTION_EXISTS_EX(getegid EVENT__HAVE_GETEGID)
-CHECK_FUNCTION_EXISTS_EX(geteuid EVENT__HAVE_GETEUID)
-CHECK_FUNCTION_EXISTS_EX(getifaddrs EVENT__HAVE_GETIFADDRS)
-CHECK_FUNCTION_EXISTS_EX(issetugid EVENT__HAVE_ISSETUGID)
-CHECK_FUNCTION_EXISTS_EX(mach_absolute_time EVENT__HAVE_MACH_ABSOLUTE_TIME)
-CHECK_FUNCTION_EXISTS_EX(nanosleep EVENT__HAVE_NANOSLEEP)
-CHECK_FUNCTION_EXISTS_EX(usleep EVENT__HAVE_USLEEP)
-CHECK_FUNCTION_EXISTS_EX(timeradd EVENT__HAVE_TIMERADD)
-CHECK_FUNCTION_EXISTS_EX(timerclear EVENT__HAVE_TIMERCLEAR)
-CHECK_FUNCTION_EXISTS_EX(timercmp EVENT__HAVE_TIMERCMP)
-CHECK_FUNCTION_EXISTS_EX(timerfd_create EVENT__HAVE_TIMERFD_CREATE)
-CHECK_FUNCTION_EXISTS_EX(timerisset EVENT__HAVE_TIMERISSET)
-CHECK_FUNCTION_EXISTS_EX(putenv EVENT__HAVE_PUTENV)
-CHECK_FUNCTION_EXISTS_EX(setenv EVENT__HAVE_SETENV)
-CHECK_FUNCTION_EXISTS_EX(setrlimit EVENT__HAVE_SETRLIMIT)
-CHECK_FUNCTION_EXISTS_EX(umask EVENT__HAVE_UMASK)
-CHECK_FUNCTION_EXISTS_EX(unsetenv EVENT__HAVE_UNSETENV)
+# Add stdio.h for vasprintf
+set(EVENT_INCLUDES ${EVENT_INCLUDES} stdio.h)
+CHECK_SYMBOLS_EXIST("${SYMBOLS_TO_CHECK}" "${EVENT_INCLUDES}" "EVENT")
+unset(SYMBOLS_TO_CHECK)
+set(EVENT__HAVE_EPOLL ${EVENT__HAVE_EPOLL_CREATE})
 
 # Get the gethostbyname_r prototype.
-CHECK_FUNCTION_EXISTS_EX(gethostbyname_r EVENT__HAVE_GETHOSTBYNAME_R)
-
 if(EVENT__HAVE_GETHOSTBYNAME_R)
     CHECK_PROTOTYPE_DEFINITION(gethostbyname_r
         "int gethostbyname_r(const char *name, struct hostent *hp, struct hostent_data *hdata)"
@@ -515,10 +539,10 @@
     set(EVENT__HAVE_EVENT_PORTS 1)
 endif()
 
-if(NOT WIN32)
-    CHECK_FUNCTION_EXISTS_EX(select EVENT__HAVE_SELECT)
-endif()
+# Only `CHECK_TYPE_SIZE()' will use `CMAKE_EXTRA_INCLUDE_FILES'
+set(CMAKE_EXTRA_INCLUDE_FILES ${EVENT_INCLUDES})
 
+CHECK_TYPE_SIZE("struct sockaddr_un" EVENT__HAVE_STRUCT_SOCKADDR_UN)
 CHECK_TYPE_SIZE("uint8_t" EVENT__HAVE_UINT8_T)
 CHECK_TYPE_SIZE("uint16_t" EVENT__HAVE_UINT16_T)
 CHECK_TYPE_SIZE("uint32_t" EVENT__HAVE_UINT32_T)
@@ -557,8 +581,6 @@
 CHECK_SYMBOL_EXISTS(TAILQ_FOREACH sys/queue.h EVENT__HAVE_TAILQFOREACH)
 CHECK_CONST_EXISTS(CTL_KERN sys/sysctl.h EVENT__HAVE_DECL_CTL_KERN)
 CHECK_CONST_EXISTS(KERN_ARND sys/sysctl.h EVENT__HAVE_DECL_KERN_ARND)
-CHECK_CONST_EXISTS(KERN_RANDOM sys/sysctl.h EVENT__HAVE_DECL_KERN_RANDOM)
-CHECK_CONST_EXISTS(RANDOM_UUID sys/sysctl.h EVENT__HAVE_DECL_RANDOM_UUID)
 CHECK_SYMBOL_EXISTS(F_SETFD fcntl.h EVENT__HAVE_SETFD)
 
 CHECK_TYPE_SIZE(fd_mask EVENT__HAVE_FD_MASK)
@@ -927,19 +949,21 @@
 include(AddEventLibrary)
 add_event_library(event_core SOURCES ${SRC_CORE})
 add_event_library(event_extra
-    LIBRARIES event_core_shared
+    INNER_LIBRARIES event_core
     SOURCES ${SRC_EXTRA})
 
 if (NOT EVENT__DISABLE_OPENSSL)
     add_event_library(event_openssl
-        LIBRARIES event_core_shared ${OPENSSL_LIBRARIES}
+        INNER_LIBRARIES event_core
+        OUTER_INCLUDES ${OPENSSL_INCLUDE_DIR}
+        LIBRARIES ${OPENSSL_LIBRARIES}
         SOURCES ${SRC_OPENSSL})
 endif()
 
-if (CMAKE_USE_PTHREADS_INIT)
+if (EVENT__HAVE_PTHREADS)
     set(SRC_PTHREADS evthread_pthread.c)
     add_event_library(event_pthreads
-        LIBRARIES event_core_shared
+        INNER_LIBRARIES event_core
         SOURCES ${SRC_PTHREADS})
 endif()
 
@@ -950,6 +974,18 @@
 
 set(WIN32_GETOPT)
 if (WIN32)
+    set(_TMPLIBS)
+    if (${EVENT_LIBRARY_STATIC})
+        list(APPEND _TMPLIBS event_core_static event_static)
+    endif()
+    if (${EVENT_LIBRARY_SHARED})
+        list(APPEND _TMPLIBS event_core_shared event_shared)
+    endif()
+    foreach(lib ${_TMPLIBS})
+        target_link_libraries(${lib} iphlpapi)
+    endforeach()
+    unset(_TMPLIBS)
+
     list(APPEND WIN32_GETOPT
          WIN32-Code/getopt.c
          WIN32-Code/getopt_long.c)
@@ -969,6 +1005,9 @@
 
     if (${ssl})
         target_link_libraries(${name} event_openssl)
+        if(WIN32)
+            target_link_libraries(${name} crypt32)
+        endif()
     endif()
 endmacro()
 if (NOT EVENT__DISABLE_SAMPLES)
@@ -1064,7 +1103,7 @@
                 DEPENDS
                     event_rpcgen.py
                     test/regress.rpc
-                COMMAND ${PYTHON_EXECUTABLE} ../event_rpcgen.py regress.rpc
+                COMMAND ${PYTHON_EXECUTABLE} ../event_rpcgen.py --quiet regress.rpc
                 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
 
             list(APPEND SRC_REGRESS
@@ -1091,7 +1130,7 @@
                 if (NOT EVENT__DISABLE_THREAD_SUPPORT)
                     list(APPEND SRC_REGRESS test/regress_thread.c)
                 endif()
-            elseif (CMAKE_USE_PTHREADS_INIT)
+            elseif (EVENT__HAVE_PTHREADS)
                 list(APPEND SRC_REGRESS test/regress_thread.c)
             endif()
 
@@ -1140,6 +1179,7 @@
     # - ellzey
     set(TESTPROGS test-changelist
                   test-eof
+                  test-closed
                   test-fdleak
                   test-init
                   test-time
@@ -1198,7 +1238,7 @@
 
     # Default environment variables turns off all event systems,
     # then we enable each one, one at a time when creating the tests.
-    set(DEFAULT_TEST_ENV_VARS "EVENT_SHOW_METHOD=1;")
+    set(DEFAULT_TEST_ENV_VARS)
     foreach(BACKEND ${BACKENDS})
         set(BACKEND_ENV_VAR "EVENT_NO${BACKEND}=1")
         list(APPEND DEFAULT_TEST_ENV_VARS "${BACKEND_ENV_VAR}")
@@ -1247,13 +1287,13 @@
             set(TEST_NAME regress__${BACKEND_TEST_NAME})
 
             add_test(${TEST_NAME}
-                     ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/regress)
+                     ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/regress --quiet)
 
             set_tests_properties(${TEST_NAME}
                                  PROPERTIES ENVIRONMENT "${ENV_VARS}")
 
             add_test(${TEST_NAME}_debug
-                     ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/regress)
+                     ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/regress --quiet)
 
             set_tests_properties(${TEST_NAME}_debug
                                  PROPERTIES ENVIRONMENT "${ENV_VARS};EVENT_DEBUG_MODE=1")
@@ -1412,18 +1452,24 @@
 # Installation preparation.
 #
 
-if(WIN32 AND NOT CYGWIN)
-  set(DEF_INSTALL_CMAKE_DIR cmake)
-else()
-  set(DEF_INSTALL_CMAKE_DIR lib/cmake/libevent)
-endif()
-
 set(EVENT_INSTALL_CMAKE_DIR
-    "${CMAKE_INSTALL_PREFIX}/${DEF_INSTALL_CMAKE_DIR}"
-    CACHE PATH "Installation directory for CMake files")
+    "${CMAKE_INSTALL_PREFIX}/lib/cmake/libevent")
 
 export(PACKAGE libevent)
 
+function(gen_package_config forinstall)
+    if(${forinstall})
+        set(CONFIG_FOR_INSTALL_TREE 1)
+        set(dir "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}")
+    else()
+        set(CONFIG_FOR_INSTALL_TREE 0)
+        set(dir "${PROJECT_BINARY_DIR}")
+    endif()
+    configure_file(${PROJECT_SOURCE_DIR}/cmake/LibeventConfig.cmake.in
+                "${dir}/LibeventConfig.cmake"
+                @ONLY)
+endfunction()
+
 # Generate the config file for the build-tree.
 set(EVENT__INCLUDE_DIRS
     "${PROJECT_SOURCE_DIR}/include"
@@ -1433,26 +1479,10 @@
     ${EVENT__INCLUDE_DIRS}
     CACHE PATH "Libevent include directories")
 
-configure_file(${PROJECT_SOURCE_DIR}/cmake/LibeventConfigBuildTree.cmake.in
-               ${PROJECT_BINARY_DIR}/LibeventConfig.cmake
-               @ONLY)
+gen_package_config(0)
 
 # Generate the config file for the installation tree.
-# Calculate the relative directory from the Cmake dir.
-file(RELATIVE_PATH
-     REL_INCLUDE_DIR
-     "${EVENT_INSTALL_CMAKE_DIR}"
-     "${CMAKE_INSTALL_PREFIX}/include")
-
-# Note the LIBEVENT_CMAKE_DIR is defined in LibeventConfig.cmake.in,
-# we escape it here so it's evaluated when it is included instead
-# so that the include dirs are given relative to where the
-# config file is located.
-set(EVENT_INSTALL_INCLUDE_DIR "\${LIBEVENT_CMAKE_DIR}/${REL_INCLUDE_DIR}")
-
-configure_file(${PROJECT_SOURCE_DIR}/cmake/LibeventConfig.cmake.in
-               ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibeventConfig.cmake
-               @ONLY)
+gen_package_config(1)
 
 # Generate version info for both build-tree and install-tree.
 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibeventConfigVersion.cmake.in
@@ -1464,6 +1494,11 @@
         DESTINATION "include"
         COMPONENT dev)
 
+# Install public headers
+install(FILES ${HDR_PUBLIC}
+        DESTINATION "include/event2"
+        COMPONENT dev)
+
 # Install the configs.
 install(FILES
         ${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/LibeventConfig.cmake
@@ -1472,9 +1507,19 @@
         COMPONENT dev)
 
 # Install exports for the install-tree.
-install(EXPORT LibeventTargets
-        DESTINATION "${DEF_INSTALL_CMAKE_DIR}"
+macro(install_export type)
+    install(EXPORT LibeventTargets-${type}
+        NAMESPACE ${PROJECT_NAME}::
+        DESTINATION "${EVENT_INSTALL_CMAKE_DIR}"
         COMPONENT dev)
+endmacro()
+
+if (${EVENT_LIBRARY_STATIC})
+    install_export(static)
+endif()
+if (${EVENT_LIBRARY_SHARED})
+    install_export(shared)
+endif()
 
 # Install the scripts.
 install(PROGRAMS
@@ -1483,25 +1528,24 @@
        COMPONENT runtime)
 
 # Create documents with doxygen.
-find_program(DOXYGEN doxygen)
-if (DOXYGEN)
-    add_custom_target(doxygen
-                      COMMAND ${DOXYGEN} Doxyfile
-                      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
-else()
-    message(WARNING "The doxygen target will not support since doxygen command was not found!")
+option(EVENT__DOXYGEN
+    "Enables doxygen documentation" OFF)
+if (EVENT__DOXYGEN)
+    include(UseDoxygen)
+    UseDoxygen()
 endif()
 
 
-# Create the uninstall target.
-# https://gitlab.kitware.com/cmake/community/wikis/FAQ#can-i-do-make-uninstall-with-cmake
-configure_file(${PROJECT_SOURCE_DIR}/cmake/Uninstall.cmake.in
-               ${PROJECT_BINARY_DIR}/Uninstall.cmake
-               @ONLY)
+if (NOT TARGET uninstall)
+	# Create the uninstall target.
+	# https://gitlab.kitware.com/cmake/community/wikis/FAQ#can-i-do-make-uninstall-with-cmake
+	configure_file(${PROJECT_SOURCE_DIR}/cmake/Uninstall.cmake.in
+				   ${PROJECT_BINARY_DIR}/Uninstall.cmake
+				   @ONLY)
 
-add_custom_target(uninstall
-                  COMMAND ${CMAKE_COMMAND} -P ${PROJECT_BINARY_DIR}/Uninstall.cmake)
-
+	add_custom_target(uninstall
+					  COMMAND ${CMAKE_COMMAND} -P ${PROJECT_BINARY_DIR}/Uninstall.cmake)
+endif()
 
 message(STATUS "")
 message(STATUS "        ---( Libevent " ${EVENT_VERSION} " )---")
diff --git a/ChangeLog b/ChangeLog
index e89d5a8..17874b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,84 @@
+Changes in version 2.1.12-stable (05 Jul 2020)
+
+ This release contains mostly bug fixes (I decided not to port some features
+ that can be ported even without ABI breakage, if you cannot find feature that
+ you are interested in, please give us a note!)
+
+ Since 2.1.12 libevent will use github actions as main CI, since
+ it recommends itself better then travis/appveyor (and had been removed from
+ upstream).
+
+ Look carefully at "slightly touches the behaviour" section.
+
+ Below you will find some of changes (this list has been cleaned up from the
+ patches that touches only tests and similar):
+
+ CI:
+  o Backport github actions to 2.1 (be3acd7c Azat Khuzhin)
+  o Merge branch 'event_rpcgen.py-cleanup' (f0ded5f3, 48e04887 Enji Cooper)
+  o Add API/ABI checker (using LVC) (709210d4, 2af1f6cc yuangongji)
+
+ test:
+  o tinytest: support timeout on Windows (794e8f75 yuangongji)
+  o Merge branch 'osx-clock' (e85afbe3 Azat Khuzhin)
+  o test-ratelim: calculate timers bias (for slow CPUs) to avoid false-positive (8ad26d0b Azat Khuzhin)
+
+ fixes:
+  o buffer: do not pass NULL to memcpy() from evbuffer_pullup() (5b063049 Azat Khuzhin)
+  o http: fix undefined-shift in EVUTIL_IS*_ helpers (6b8d02a7 Azat Khuzhin)
+  o Check error code of evhttp_add_header_internal() in evhttp_parse_query_impl() (97e28f09 Azat Khuzhin)
+  o http: fix EVHTTP_CON_AUTOFREE in case of timeout (and some else) (1be25938 Azat Khuzhin)
+  o evdns: Add additional validation for values of dns options (c2972453 ayuseleznev)
+  o There is typo in GetAdaptersAddresses windows library. It should be iphlpapi.dll (891adda9 Aleksandr-Melnikov)
+  o Merge branch 'EV_CLOSED-and-EV_ET-fixes' (db2efdf5 Azat Khuzhin)
+  o Fix memory corruption in EV_CLOSURE_EVENT_FINALIZE with debug enabled (8ccd8f56 Jan Kasiak)
+  o increase segment refcnt only if evbuffer_add_file_segment() succeeds (30662a3c yuangongji)
+  o evdns: fix a crash when evdns_base with waiting requests is freed (6f8e0e97 ayuseleznev)
+  o event_base_once: fix potential null pointer threat (2e9ceb16 chenguolong)
+  o http: do not assume body for CONNECT (1b42270b Azat Khuzhin)
+  o evbuffer_add_file: fix freeing of segment in the error path (5f017bde Azat Khuzhin)
+  o Fix checking return value of the evdns_base_resolv_conf_parse() (fc51bf2c Azat Khuzhin)
+  o Merge branch 'fix-signal-leak' (poll/select now needs reinit) (1c9cc07b Azat Khuzhin)
+
+ improvements:
+  o evutil_time: improve evutil_gettimeofday on Windows (a8219143 Nick Grifka)
+  o Support EV_CLOSED on linux for poll(2) (2530e7c6 Azat Khuzhin)
+  o Parse IPv6 scope IDs. (f602211f Philip Homburg)
+  o evutil_time: Implements usleep() using wait funtion on Windows (d42240d1 yuangongji)
+  o evutil_time: detect and use _gmtime64_s()/_gmtime64() (f4a6152c yuangongji)
+
+ slightly touches the behaviour:
+  o bufferevent: allow setting priority on socket and openssl type (4dd3acdd Nicolas J. Bouliane)
+  o Fix EV_CLOSED detection/reporting (epoll only) (1df324d4 Azat Khuzhin) (XXX)
+  o Revert "Warn if forked from the event loop during event_reinit()" (71f5c0d3 Azat Khuzhin)
+
+ samples:
+  o https-client: load certificates from the system cert store on Windows (e9478640 yuangongji)
+
+ build fixes:
+  o Do not use sysctl.h on linux (it had been deprecated) (d2871a37 Azat Khuzhin)
+  o cmake: avoid problems from use of CMAKE_USE_PTHREADS_INIT (a62ec765 Paul Osborne)
+  o Update list of cmake files for autotools dist archive (2016f017 Azat Khuzhin)
+  o LibeventConfig.cmake: restore CMAKE_FIND_LIBRARY_SUFFIXES and LIBEVENT_STATIC_LINK default (640f9cf6 Mario Emmenlauer)
+  o cmake: fix getaddrinfo checking error (dea51c2e yuangongji)
+  o autoconf: fix getaddrinfo checking errors on mingw (b9bf7fa7 yuangongji)
+  o Do not use shared global structures on CYGWIN (8a9b5655 Azat Khuzhin)
+  o Added uninstall target check to cmakelists (3f1fb1f9 Dimo Markov)
+  o Fix compilation without OPENSSL_API_COMPAT (921bdcdd Azat Khuzhin)
+  o cmake: improve package config file (1c047618, baec84f2 yuangongji)
+  o Link with iphlpapi only on windows (976f7d34 Azat Khuzhin)
+  o autotools: fails build when need but can not find openssl (93174bb5 yuangongji)
+  o Merge branch 'http-connect' (e2424229 Azat Khuzhin)
+  o Fix compat with NetBSD >= 10 (5febb4e1 Kamil Rytarowski)
+  o cmake: fix getrandom() detection (e0e5f3bd Azat Khuzhin)
+  o arc4random: replace sysctl() with getrandom (on linux) (66ec78fd Azat Khuzhin)
+  o Upgrade autoconf (after upgrading minimum required to 2.67) (45da7d9d yuangongji)
+  o eliminate some C4267 warnings in Windows (9e468c77 yuangongji)
+  o autotools: attach doxygen target into all target (5d1e8570 yuangongji)
+  o cmake: attach doxygen target into all target (7a85300a yuangongji)
+  o Change the minimum version of automake to 1.13 and autoconf to 2.67 (fdb8fb66 ygj6)
+  o Add Uninstall.cmake.in into dist archive (877f2355 Azat Khuzhin)
+
 Changes in version 2.1.11-stable (01 Aug 2019)
 
  This release contains one ABI breakage fix (that had been introduced in
diff --git a/Doxyfile b/Doxyfile
index d9d6603..3f094f7 100644
--- a/Doxyfile
+++ b/Doxyfile
@@ -17,11 +17,11 @@
 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded 
 # by quotes) that should identify the project.
 
-PROJECT_NAME           = libevent
+PROJECT_NAME           = $(PROJECT)-$(VERSION)
 
 # Place all output under 'doxygen/'
 
-OUTPUT_DIRECTORY        = doxygen/
+OUTPUT_DIRECTORY        = $(DOCDIR)
 
 # If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen 
 # will interpret the first line (until the first dot) of a JavaDoc-style 
@@ -64,24 +64,24 @@
 # with spaces.
 
 INPUT                  = \
-        include/event2/buffer.h \
-        include/event2/buffer_compat.h \
-        include/event2/bufferevent.h \
-        include/event2/bufferevent_compat.h \
-        include/event2/bufferevent_ssl.h \
-        include/event2/dns.h \
-        include/event2/dns_compat.h \
-        include/event2/event.h \
-        include/event2/event_compat.h \
-        include/event2/http.h \
-        include/event2/http_compat.h \
-        include/event2/listener.h \
-        include/event2/rpc.h \
-        include/event2/rpc_compat.h \
-        include/event2/tag.h \
-        include/event2/tag_compat.h \
-        include/event2/thread.h \
-        include/event2/util.h
+        $(SRCDIR)/include/event2/buffer.h \
+        $(SRCDIR)/include/event2/buffer_compat.h \
+        $(SRCDIR)/include/event2/bufferevent.h \
+        $(SRCDIR)/include/event2/bufferevent_compat.h \
+        $(SRCDIR)/include/event2/bufferevent_ssl.h \
+        $(SRCDIR)/include/event2/dns.h \
+        $(SRCDIR)/include/event2/dns_compat.h \
+        $(SRCDIR)/include/event2/event.h \
+        $(SRCDIR)/include/event2/event_compat.h \
+        $(SRCDIR)/include/event2/http.h \
+        $(SRCDIR)/include/event2/http_compat.h \
+        $(SRCDIR)/include/event2/listener.h \
+        $(SRCDIR)/include/event2/rpc.h \
+        $(SRCDIR)/include/event2/rpc_compat.h \
+        $(SRCDIR)/include/event2/tag.h \
+        $(SRCDIR)/include/event2/tag_compat.h \
+        $(SRCDIR)/include/event2/thread.h \
+        $(SRCDIR)/include/event2/util.h
 
 #---------------------------------------------------------------------------
 # configuration options related to the HTML output
@@ -90,7 +90,7 @@
 # If the GENERATE_HTML tag is set to YES (the default) Doxygen will 
 # generate HTML output.
 
-GENERATE_HTML          = YES
+GENERATE_HTML          = $(GENERATE_HTML)
 
 #---------------------------------------------------------------------------
 # configuration options related to the LaTeX output
@@ -99,7 +99,7 @@
 # If the GENERATE_LATEX tag is set to YES (the default) Doxygen will 
 # generate Latex output.
 
-GENERATE_LATEX         = YES
+GENERATE_LATEX         = $(GENERATE_LATEX)
 
 # The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. 
 # If a relative path is entered the value of OUTPUT_DIRECTORY will be 
@@ -175,7 +175,7 @@
 # If the GENERATE_MAN tag is set to YES (the default) Doxygen will 
 # generate man pages
 
-GENERATE_MAN           = NO
+GENERATE_MAN           = $(GENERATE_MAN)
 
 # The MAN_EXTENSION tag determines the extension that is added to 
 # the generated man pages (default is the subroutine's section .3)
diff --git a/METADATA b/METADATA
index d9738a9..e0b41cc 100644
--- a/METADATA
+++ b/METADATA
@@ -7,13 +7,13 @@
   }
   url {
     type: ARCHIVE
-    value: "https://github.com/libevent/libevent/releases/download/release-2.1.11-stable/libevent-2.1.11-stable.tar.gz"
+    value: "https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz"
   }
-  version: "release-2.1.11-stable"
+  version: "release-2.1.12-stable"
   license_type: RECIPROCAL
   last_upgrade_date {
-    year: 2019
-    month: 8
-    day: 1
+    year: 2020
+    month: 7
+    day: 10
   }
 }
diff --git a/Makefile.am b/Makefile.am
index dd90502..2181500 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,8 +5,8 @@
 # See LICENSE for copying information.
 
 # 'foreign' means that we're not enforcing GNU package rules strictly.
-# '1.11.2' means that we need automake 1.11.2 or later (and we do).
-AUTOMAKE_OPTIONS = foreign 1.11.2 subdir-objects
+# '1.13' means that we need automake 1.13 or later (and we do).
+AUTOMAKE_OPTIONS = foreign 1.13 subdir-objects
 
 ACLOCAL_AMFLAGS = -I m4
 
@@ -38,7 +38,7 @@
 #
 # Once an RC is out, DO NOT MAKE ANY ABI-BREAKING CHANGES IN THAT SERIES
 # UNLESS YOU REALLY REALLY HAVE TO.
-VERSION_INFO = 7:0:0
+VERSION_INFO = 7:1:0
 
 # History:          RELEASE    VERSION_INFO
 #  2.0.1-alpha --     2.0        1:0:0
@@ -75,6 +75,7 @@
 #  2.1.9-beta--       2.1        6:3:0 (No ABI change)
 #  2.1.10-stable--    2.1        6:4:0 (No ABI change, WRONG)
 #  2.1.11-stable--    2.1        7:0:0 (ABI changed)
+#  2.1.12-stable--    2.1        7:1:0 (No ABI change)
 
 # ABI version history for this package effectively restarts every time
 # we change RELEASE.  Version 1.4.x had RELEASE of 1.4.
@@ -113,8 +114,6 @@
 	cmake/CheckConstExists.cmake \
 	cmake/CheckFileOffsetBits.c \
 	cmake/CheckFileOffsetBits.cmake \
-	cmake/CheckFunctionExistsEx.c \
-	cmake/CheckFunctionExistsEx.cmake \
 	cmake/CheckFunctionKeywords.cmake \
 	cmake/CheckPrototypeDefinition.c.in \
 	cmake/CheckPrototypeDefinition.cmake \
@@ -122,10 +121,11 @@
 	cmake/CodeCoverage.cmake \
 	cmake/COPYING-CMAKE-SCRIPTS \
 	cmake/Copyright.txt \
-	cmake/FindGit.cmake \
-	cmake/LibeventConfigBuildTree.cmake.in \
 	cmake/LibeventConfig.cmake.in \
 	cmake/LibeventConfigVersion.cmake.in \
+	cmake/Macros.cmake \
+	cmake/Uninstall.cmake.in \
+	cmake/UseDoxygen.cmake \
 	cmake/VersionViaGit.cmake \
 	event-config.h.cmake \
 	evconfig-private.h.cmake \
@@ -177,6 +177,7 @@
 
 if BUILD_WIN32
 
+SYS_CORE_LIBS = -liphlpapi
 SYS_LIBS = -lws2_32 -lshell32 -ladvapi32
 SYS_SRC = win32select.c buffer_iocp.c event_iocp.c \
 	bufferevent_async.c
@@ -188,6 +189,7 @@
 
 else
 
+SYS_CORE_LIBS =
 SYS_LIBS =
 SYS_SRC =
 SYS_INCLUDES =
@@ -264,11 +266,11 @@
 GENERIC_LDFLAGS = -version-info $(VERSION_INFO) $(RELEASE) $(NO_UNDEFINED) $(AM_LDFLAGS)
 
 libevent_la_SOURCES = $(CORE_SRC) $(EXTRAS_SRC)
-libevent_la_LIBADD = @LTLIBOBJS@ $(SYS_LIBS)
+libevent_la_LIBADD = @LTLIBOBJS@ $(SYS_LIBS) $(SYS_CORE_LIBS)
 libevent_la_LDFLAGS = $(GENERIC_LDFLAGS)
 
 libevent_core_la_SOURCES = $(CORE_SRC)
-libevent_core_la_LIBADD = @LTLIBOBJS@ $(SYS_LIBS)
+libevent_core_la_LIBADD = @LTLIBOBJS@ $(SYS_LIBS) $(SYS_CORE_LIBS)
 libevent_core_la_LDFLAGS = $(GENERIC_LDFLAGS)
 
 if PTHREADS
@@ -336,9 +338,7 @@
 
 verify: check
 
-doxygen: FORCE
-	doxygen $(srcdir)/Doxyfile
-FORCE:
+include doxygen.am
 
 DISTCLEANFILES += *~ libevent.pc libevent_core.pc libevent_extra.pc ./include/event2/event-config.h
 
diff --git a/Makefile.in b/Makefile.in
index 9f4b477..04e0ae3 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
 # @configure_input@
 
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
 
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -38,6 +38,16 @@
 #
 # See LICENSE for copying information.
 
+# Doxygen documentation will not be generated with default configuration,
+# unless '--enable-doxygen-doc' is configured.
+# The following targets are all about doxygen:
+# make                # 'make doxygen' would be auto executed
+# make doxygen        # generating doxygen documentation
+# make doxygen-doc    # same as 'make doxygen'
+# make clean          # clean docs generated by doxygen
+# make install        # install doxygen documentation
+# make uninstall      # uninstall doxygen documentation
+
 
 
 
@@ -125,33 +135,36 @@
 @OPENSSL_TRUE@am__append_5 = include/event2/bufferevent_ssl.h
 @INSTALL_LIBEVENT_FALSE@am__append_6 = $(EVENT2_EXPORT)
 @OPENSSL_TRUE@am__append_7 = sample/le-proxy sample/https-client
-@OPENSSL_TRUE@am__append_8 = \
+@BUILD_WIN32_TRUE@@OPENSSL_TRUE@am__append_8 = -lcrypt32
+@OPENSSL_TRUE@am__append_9 = \
 @OPENSSL_TRUE@	sample/hostcheck.h \
 @OPENSSL_TRUE@	sample/openssl_hostname_validation.h
 
-@BUILD_SAMPLES_TRUE@am__append_9 = $(SAMPLES)
-@BUILD_REGRESS_TRUE@am__append_10 = $(TESTPROGRAMS)
-@BUILD_REGRESS_TRUE@am__append_11 = test/regress
-@BUILD_REGRESS_TRUE@am__append_12 = test/regress.gen.c test/regress.gen.h
-@PTHREADS_TRUE@am__append_13 = libevent_pthreads.la
-@BUILD_WIN32_TRUE@am__append_14 = test/regress_iocp.c
-@OPENSSL_TRUE@am__append_15 = test/regress_ssl.c
-@OPENSSL_TRUE@am__append_16 = $(OPENSSL_INCS)
-@OPENSSL_TRUE@am__append_17 = libevent_openssl.la $(OPENSSL_LIBS) ${OPENSSL_LIBADD}
-@BUILD_WIN32_TRUE@@THREADS_TRUE@am__append_18 = evthread_win32.c
-@STRLCPY_IMPL_TRUE@am__append_19 = strlcpy.c
-@SELECT_BACKEND_TRUE@am__append_20 = select.c
-@POLL_BACKEND_TRUE@am__append_21 = poll.c
-@DEVPOLL_BACKEND_TRUE@am__append_22 = devpoll.c
-@KQUEUE_BACKEND_TRUE@am__append_23 = kqueue.c
-@EPOLL_BACKEND_TRUE@am__append_24 = epoll.c
-@EVPORT_BACKEND_TRUE@am__append_25 = evport.c
-@SIGNAL_SUPPORT_TRUE@am__append_26 = signal.c
-@INSTALL_LIBEVENT_FALSE@am__append_27 = $(EVENT1_HDRS)
+@BUILD_SAMPLES_TRUE@am__append_10 = $(SAMPLES)
+@BUILD_REGRESS_TRUE@am__append_11 = $(TESTPROGRAMS)
+@BUILD_REGRESS_TRUE@am__append_12 = test/regress
+@BUILD_REGRESS_TRUE@am__append_13 = test/regress.gen.c test/regress.gen.h
+@PTHREADS_TRUE@am__append_14 = libevent_pthreads.la
+@BUILD_WIN32_TRUE@am__append_15 = test/regress_iocp.c
+@OPENSSL_TRUE@am__append_16 = test/regress_ssl.c
+@OPENSSL_TRUE@am__append_17 = $(OPENSSL_INCS)
+@OPENSSL_TRUE@am__append_18 = libevent_openssl.la $(OPENSSL_LIBS) ${OPENSSL_LIBADD}
+@BUILD_WIN32_TRUE@@THREADS_TRUE@am__append_19 = evthread_win32.c
+@STRLCPY_IMPL_TRUE@am__append_20 = strlcpy.c
+@SELECT_BACKEND_TRUE@am__append_21 = select.c
+@POLL_BACKEND_TRUE@am__append_22 = poll.c
+@DEVPOLL_BACKEND_TRUE@am__append_23 = devpoll.c
+@KQUEUE_BACKEND_TRUE@am__append_24 = kqueue.c
+@EPOLL_BACKEND_TRUE@am__append_25 = epoll.c
+@EVPORT_BACKEND_TRUE@am__append_26 = evport.c
+@SIGNAL_SUPPORT_TRUE@am__append_27 = signal.c
+@INSTALL_LIBEVENT_FALSE@am__append_28 = $(EVENT1_HDRS)
 subdir = .
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/m4/ac_backport_259_ssizet.m4 \
 	$(top_srcdir)/m4/acx_pthread.m4 \
+	$(top_srcdir)/m4/ax_check_funcs_ex.m4 \
+	$(top_srcdir)/m4/ax_prog_doxygen.m4 \
 	$(top_srcdir)/m4/libevent_openssl.m4 \
 	$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
 	$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
@@ -216,12 +229,13 @@
          $(am__cd) "$$dir" && rm -f $$files; }; \
   }
 am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \
-	"$(DESTDIR)$(pkgconfigdir)" "$(DESTDIR)$(includedir)" \
-	"$(DESTDIR)$(include_event2dir)" \
+	"$(DESTDIR)$(man3dir)" "$(DESTDIR)$(pkgconfigdir)" \
+	"$(DESTDIR)$(includedir)" "$(DESTDIR)$(include_event2dir)" \
 	"$(DESTDIR)$(include_event2dir)"
 LTLIBRARIES = $(lib_LTLIBRARIES) $(noinst_LTLIBRARIES)
 am__DEPENDENCIES_1 =
-libevent_la_DEPENDENCIES = @LTLIBOBJS@ $(am__DEPENDENCIES_1)
+libevent_la_DEPENDENCIES = @LTLIBOBJS@ $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1)
 am__libevent_la_SOURCES_DIST = buffer.c bufferevent.c \
 	bufferevent_filter.c bufferevent_pair.c bufferevent_ratelim.c \
 	bufferevent_sock.c event.c evmap.c evthread.c evutil.c \
@@ -265,7 +279,8 @@
 	$(libevent_la_LDFLAGS) $(LDFLAGS) -o $@
 @INSTALL_LIBEVENT_FALSE@am_libevent_la_rpath =
 @INSTALL_LIBEVENT_TRUE@am_libevent_la_rpath = -rpath $(libdir)
-libevent_core_la_DEPENDENCIES = @LTLIBOBJS@ $(am__DEPENDENCIES_1)
+libevent_core_la_DEPENDENCIES = @LTLIBOBJS@ $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1)
 am__libevent_core_la_SOURCES_DIST = buffer.c bufferevent.c \
 	bufferevent_filter.c bufferevent_pair.c bufferevent_ratelim.c \
 	bufferevent_sock.c event.c evmap.c evthread.c evutil.c \
@@ -343,7 +358,7 @@
 sample_https_client_OBJECTS = $(am_sample_https_client_OBJECTS)
 @OPENSSL_TRUE@sample_https_client_DEPENDENCIES = libevent.la \
 @OPENSSL_TRUE@	libevent_openssl.la $(am__DEPENDENCIES_1) \
-@OPENSSL_TRUE@	$(am__DEPENDENCIES_1)
+@OPENSSL_TRUE@	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
 am__sample_le_proxy_SOURCES_DIST = sample/le-proxy.c
 @OPENSSL_TRUE@am_sample_le_proxy_OBJECTS =  \
 @OPENSSL_TRUE@	sample/le_proxy-le-proxy.$(OBJEXT)
@@ -404,7 +419,7 @@
 	test/regress-tinytest.$(OBJEXT) $(am__objects_13) \
 	$(am__objects_14) $(am__objects_15) $(am__objects_16)
 test_regress_OBJECTS = $(am_test_regress_OBJECTS)
-am__DEPENDENCIES_3 = $(am__append_13)
+am__DEPENDENCIES_3 = $(am__append_14)
 @OPENSSL_TRUE@am__DEPENDENCIES_4 = libevent_openssl.la \
 @OPENSSL_TRUE@	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
 test_regress_DEPENDENCIES = $(am__DEPENDENCIES_1) libevent_core.la \
@@ -455,7 +470,7 @@
 am__v_at_0 = @
 am__v_at_1 = 
 DEFAULT_INCLUDES = -I.@am__isrc@
-depcomp = $(SHELL) $(top_srcdir)/depcomp
+depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp
 am__maybe_remake_depfiles = depfiles
 am__depfiles_remade = $(DEPDIR)/epoll_sub.Plo ./$(DEPDIR)/buffer.Plo \
 	./$(DEPDIR)/buffer_iocp.Plo ./$(DEPDIR)/bufferevent.Plo \
@@ -573,6 +588,9 @@
     n|no|NO) false;; \
     *) (install-info --version) >/dev/null 2>&1;; \
   esac
+man3dir = $(mandir)/man3
+NROFF = nroff
+MANS = $(man3_MANS)
 DATA = $(pkgconfig_DATA)
 am__include_HEADERS_DIST = include/evdns.h include/event.h \
 	include/evhttp.h include/evrpc.h include/evutil.h
@@ -622,8 +640,8 @@
 HEADERS = $(include_HEADERS) $(include_event2_HEADERS) \
 	$(nodist_include_event2_HEADERS) $(nodist_noinst_HEADERS) \
 	$(noinst_HEADERS)
-am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) \
-	$(LISP)config.h.in evconfig-private.h.in
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) \
+	config.h.in evconfig-private.h.in
 # Read a list of newline-separated strings from the standard input,
 # and print each of them once, without duplicates.  Input order is
 # *not* preserved.
@@ -802,7 +820,7 @@
 RECHECK_LOGS = $(TEST_LOGS)
 TEST_SUITE_LOG = test-suite.log
 TEST_EXTENSIONS = @EXEEXT@ .test
-LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver
+LOG_DRIVER = $(SHELL) $(top_srcdir)/build-aux/test-driver
 LOG_COMPILE = $(LOG_COMPILER) $(AM_LOG_FLAGS) $(LOG_FLAGS)
 am__set_b = \
   case '$@' in \
@@ -817,18 +835,26 @@
 am__test_logs1 = $(TESTS:=.log)
 am__test_logs2 = $(am__test_logs1:@EXEEXT@.log=.log)
 TEST_LOGS = $(am__test_logs2:.test.log=.log)
-TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver
+TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/build-aux/test-driver
 TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \
 	$(TEST_LOG_FLAGS)
 am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in \
-	$(srcdir)/evconfig-private.h.in $(srcdir)/include/include.am \
-	$(srcdir)/libevent.pc.in $(srcdir)/libevent_core.pc.in \
-	$(srcdir)/libevent_extra.pc.in \
+	$(srcdir)/doxygen.am $(srcdir)/evconfig-private.h.in \
+	$(srcdir)/include/include.am $(srcdir)/libevent.pc.in \
+	$(srcdir)/libevent_core.pc.in $(srcdir)/libevent_extra.pc.in \
 	$(srcdir)/libevent_openssl.pc.in \
 	$(srcdir)/libevent_pthreads.pc.in $(srcdir)/sample/include.am \
-	$(srcdir)/test/include.am ChangeLog compile config.guess \
-	config.sub depcomp epoll_sub.c install-sh ltmain.sh missing \
-	test-driver
+	$(srcdir)/test/include.am $(top_srcdir)/build-aux/compile \
+	$(top_srcdir)/build-aux/config.guess \
+	$(top_srcdir)/build-aux/config.sub \
+	$(top_srcdir)/build-aux/depcomp \
+	$(top_srcdir)/build-aux/install-sh \
+	$(top_srcdir)/build-aux/ltmain.sh \
+	$(top_srcdir)/build-aux/missing \
+	$(top_srcdir)/build-aux/test-driver ChangeLog \
+	build-aux/compile build-aux/config.guess build-aux/config.sub \
+	build-aux/depcomp build-aux/install-sh build-aux/ltmain.sh \
+	build-aux/missing epoll_sub.c
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 distdir = $(PACKAGE)-$(VERSION)
 top_distdir = $(distdir)
@@ -863,8 +889,32 @@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
 DLLTOOL = @DLLTOOL@
+DOXYGEN_PAPER_SIZE = @DOXYGEN_PAPER_SIZE@
 DSYMUTIL = @DSYMUTIL@
 DUMPBIN = @DUMPBIN@
+DX_CONFIG = @DX_CONFIG@
+DX_DOCDIR = @DX_DOCDIR@
+DX_DOT = @DX_DOT@
+DX_DOXYGEN = @DX_DOXYGEN@
+DX_DVIPS = @DX_DVIPS@
+DX_EGREP = @DX_EGREP@
+DX_ENV = @DX_ENV@
+DX_FLAG_chi = @DX_FLAG_chi@
+DX_FLAG_chm = @DX_FLAG_chm@
+DX_FLAG_doc = @DX_FLAG_doc@
+DX_FLAG_dot = @DX_FLAG_dot@
+DX_FLAG_html = @DX_FLAG_html@
+DX_FLAG_man = @DX_FLAG_man@
+DX_FLAG_pdf = @DX_FLAG_pdf@
+DX_FLAG_ps = @DX_FLAG_ps@
+DX_FLAG_rtf = @DX_FLAG_rtf@
+DX_FLAG_xml = @DX_FLAG_xml@
+DX_HHC = @DX_HHC@
+DX_LATEX = @DX_LATEX@
+DX_MAKEINDEX = @DX_MAKEINDEX@
+DX_PDFLATEX = @DX_PDFLATEX@
+DX_PERL = @DX_PERL@
+DX_PROJECT = @DX_PROJECT@
 ECHO_C = @ECHO_C@
 ECHO_N = @ECHO_N@
 ECHO_T = @ECHO_T@
@@ -913,7 +963,7 @@
 PKG_CONFIG = @PKG_CONFIG@
 PTHREAD_CC = @PTHREAD_CC@
 PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
-PTHREAD_LIBS = @PTHREAD_LIBS@ $(am__append_13)
+PTHREAD_LIBS = @PTHREAD_LIBS@ $(am__append_14)
 RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
@@ -976,8 +1026,8 @@
 top_srcdir = @top_srcdir@
 
 # 'foreign' means that we're not enforcing GNU package rules strictly.
-# '1.11.2' means that we need automake 1.11.2 or later (and we do).
-AUTOMAKE_OPTIONS = foreign 1.11.2 subdir-objects
+# '1.13' means that we need automake 1.13 or later (and we do).
+AUTOMAKE_OPTIONS = foreign 1.13 subdir-objects
 ACLOCAL_AMFLAGS = -I m4
 
 # This is the "Release" of the Libevent ABI.  It takes precedence over
@@ -1008,7 +1058,7 @@
 #
 # Once an RC is out, DO NOT MAKE ANY ABI-BREAKING CHANGES IN THAT SERIES
 # UNLESS YOU REALLY REALLY HAVE TO.
-VERSION_INFO = 7:0:0
+VERSION_INFO = 7:1:0
 
 # History:          RELEASE    VERSION_INFO
 #  2.0.1-alpha --     2.0        1:0:0
@@ -1045,6 +1095,7 @@
 #  2.1.9-beta--       2.1        6:3:0 (No ABI change)
 #  2.1.10-stable--    2.1        6:4:0 (No ABI change, WRONG)
 #  2.1.11-stable--    2.1        7:0:0 (ABI changed)
+#  2.1.12-stable--    2.1        7:1:0 (No ABI change)
 
 # ABI version history for this package effectively restarts every time
 # we change RELEASE.  Version 1.4.x had RELEASE of 1.4.
@@ -1080,8 +1131,6 @@
 	cmake/CheckConstExists.cmake \
 	cmake/CheckFileOffsetBits.c \
 	cmake/CheckFileOffsetBits.cmake \
-	cmake/CheckFunctionExistsEx.c \
-	cmake/CheckFunctionExistsEx.cmake \
 	cmake/CheckFunctionKeywords.cmake \
 	cmake/CheckPrototypeDefinition.c.in \
 	cmake/CheckPrototypeDefinition.cmake \
@@ -1089,10 +1138,11 @@
 	cmake/CodeCoverage.cmake \
 	cmake/COPYING-CMAKE-SCRIPTS \
 	cmake/Copyright.txt \
-	cmake/FindGit.cmake \
-	cmake/LibeventConfigBuildTree.cmake.in \
 	cmake/LibeventConfig.cmake.in \
 	cmake/LibeventConfigVersion.cmake.in \
+	cmake/Macros.cmake \
+	cmake/Uninstall.cmake.in \
+	cmake/UseDoxygen.cmake \
 	cmake/VersionViaGit.cmake \
 	event-config.h.cmake \
 	evconfig-private.h.cmake \
@@ -1112,7 +1162,7 @@
 @INSTALL_LIBEVENT_TRUE@pkgconfig_DATA = $(LIBEVENT_PKGCONFIG)
 @INSTALL_LIBEVENT_FALSE@noinst_LTLIBRARIES = $(LIBEVENT_LIBS_LA)
 EXTRA_SOURCE = 
-noinst_HEADERS = $(am__append_6) $(am__append_8) test/regress.h \
+noinst_HEADERS = $(am__append_6) $(am__append_9) test/regress.h \
 	test/regress_thread.h test/tinytest.h test/tinytest_local.h \
 	test/tinytest_macros.h WIN32-Code/nmake/evconfig-private.h \
 	WIN32-Code/nmake/event2/event-config.h WIN32-Code/getopt.h \
@@ -1125,12 +1175,12 @@
 	kqueue-internal.h log-internal.h minheap-internal.h \
 	mm-internal.h ratelim-internal.h ratelim-internal.h \
 	strlcpy-internal.h time-internal.h util-internal.h \
-	openssl-compat.h $(am__append_27)
+	openssl-compat.h $(am__append_28)
 CLEANFILES = test/rpcgen-attempted
 DISTCLEANFILES = test/regress.gen.c test/regress.gen.h *~ libevent.pc \
 	libevent_core.pc libevent_extra.pc \
 	./include/event2/event-config.h
-BUILT_SOURCES = $(am__append_12) include/event2/event-config.h
+BUILT_SOURCES = $(am__append_13) include/event2/event-config.h
 include_event2dir = $(includedir)/event2
 EVENT2_EXPORT = include/event2/buffer.h include/event2/buffer_compat.h \
 	include/event2/bufferevent.h \
@@ -1160,7 +1210,9 @@
 @OPENSSL_TRUE@	sample/hostcheck.c \
 @OPENSSL_TRUE@	sample/openssl_hostname_validation.c
 
-@OPENSSL_TRUE@sample_https_client_LDADD = libevent.la libevent_openssl.la $(OPENSSL_LIBS) $(OPENSSL_LIBADD)
+@OPENSSL_TRUE@sample_https_client_LDADD = libevent.la \
+@OPENSSL_TRUE@	libevent_openssl.la $(OPENSSL_LIBS) \
+@OPENSSL_TRUE@	$(OPENSSL_LIBADD) $(am__append_8)
 @OPENSSL_TRUE@sample_https_client_CPPFLAGS = $(AM_CPPFLAGS) $(OPENSSL_INCS)
 sample_event_read_fifo_SOURCES = sample/event-read-fifo.c
 sample_event_read_fifo_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la
@@ -1233,15 +1285,15 @@
 	test/regress_minheap.c test/regress_rpc.c \
 	test/regress_testutils.c test/regress_testutils.h \
 	test/regress_util.c test/tinytest.c $(regress_thread_SOURCES) \
-	$(regress_zlib_SOURCES) $(am__append_14) $(am__append_15)
+	$(regress_zlib_SOURCES) $(am__append_15) $(am__append_16)
 @BUILD_WIN32_TRUE@@THREADS_TRUE@regress_thread_SOURCES = test/regress_thread.c
 @PTHREADS_TRUE@regress_thread_SOURCES = test/regress_thread.c
 @ZLIB_REGRESS_TRUE@regress_zlib_SOURCES = test/regress_zlib.c
 test_regress_LDADD = $(LIBEVENT_GC_SECTIONS) libevent_core.la \
 	libevent_extra.la $(PTHREAD_LIBS) $(ZLIB_LIBS) \
-	$(am__append_17)
+	$(am__append_18)
 test_regress_CPPFLAGS = $(AM_CPPFLAGS) $(PTHREAD_CFLAGS) \
-	$(ZLIB_CFLAGS) -Itest $(am__append_16)
+	$(ZLIB_CFLAGS) -Itest $(am__append_17)
 test_regress_LDFLAGS = $(PTHREAD_CFLAGS)
 test_bench_SOURCES = test/bench.c
 test_bench_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la
@@ -1251,18 +1303,20 @@
 test_bench_http_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la
 test_bench_httpclient_SOURCES = test/bench_httpclient.c
 test_bench_httpclient_LDADD = $(LIBEVENT_GC_SECTIONS) libevent_core.la
+@BUILD_WIN32_FALSE@SYS_CORE_LIBS = 
+@BUILD_WIN32_TRUE@SYS_CORE_LIBS = -liphlpapi
 @BUILD_WIN32_FALSE@SYS_LIBS = 
 @BUILD_WIN32_TRUE@SYS_LIBS = -lws2_32 -lshell32 -ladvapi32
-@BUILD_WIN32_FALSE@SYS_SRC = $(am__append_19) $(am__append_20) \
-@BUILD_WIN32_FALSE@	$(am__append_21) $(am__append_22) \
-@BUILD_WIN32_FALSE@	$(am__append_23) $(am__append_24) \
-@BUILD_WIN32_FALSE@	$(am__append_25) $(am__append_26)
+@BUILD_WIN32_FALSE@SYS_SRC = $(am__append_20) $(am__append_21) \
+@BUILD_WIN32_FALSE@	$(am__append_22) $(am__append_23) \
+@BUILD_WIN32_FALSE@	$(am__append_24) $(am__append_25) \
+@BUILD_WIN32_FALSE@	$(am__append_26) $(am__append_27)
 @BUILD_WIN32_TRUE@SYS_SRC = win32select.c buffer_iocp.c event_iocp.c \
-@BUILD_WIN32_TRUE@	bufferevent_async.c $(am__append_18) \
-@BUILD_WIN32_TRUE@	$(am__append_19) $(am__append_20) \
-@BUILD_WIN32_TRUE@	$(am__append_21) $(am__append_22) \
-@BUILD_WIN32_TRUE@	$(am__append_23) $(am__append_24) \
-@BUILD_WIN32_TRUE@	$(am__append_25) $(am__append_26)
+@BUILD_WIN32_TRUE@	bufferevent_async.c $(am__append_19) \
+@BUILD_WIN32_TRUE@	$(am__append_20) $(am__append_21) \
+@BUILD_WIN32_TRUE@	$(am__append_22) $(am__append_23) \
+@BUILD_WIN32_TRUE@	$(am__append_24) $(am__append_25) \
+@BUILD_WIN32_TRUE@	$(am__append_26) $(am__append_27)
 @BUILD_WIN32_FALSE@SYS_INCLUDES = 
 @BUILD_WIN32_TRUE@SYS_INCLUDES = -IWIN32-Code -IWIN32-Code/nmake
 CORE_SRC = \
@@ -1297,10 +1351,10 @@
 AM_LDFLAGS = $(LIBEVENT_LDFLAGS)
 GENERIC_LDFLAGS = -version-info $(VERSION_INFO) $(RELEASE) $(NO_UNDEFINED) $(AM_LDFLAGS)
 libevent_la_SOURCES = $(CORE_SRC) $(EXTRAS_SRC)
-libevent_la_LIBADD = @LTLIBOBJS@ $(SYS_LIBS)
+libevent_la_LIBADD = @LTLIBOBJS@ $(SYS_LIBS) $(SYS_CORE_LIBS)
 libevent_la_LDFLAGS = $(GENERIC_LDFLAGS)
 libevent_core_la_SOURCES = $(CORE_SRC)
-libevent_core_la_LIBADD = @LTLIBOBJS@ $(SYS_LIBS)
+libevent_core_la_LIBADD = @LTLIBOBJS@ $(SYS_LIBS) $(SYS_CORE_LIBS)
 libevent_core_la_LDFLAGS = $(GENERIC_LDFLAGS)
 @PTHREADS_TRUE@libevent_pthreads_la_SOURCES = evthread_pthread.c
 @PTHREADS_TRUE@libevent_pthreads_la_LIBADD = $(MAYBE_CORE)
@@ -1320,6 +1374,13 @@
 	include/evutil.h
 
 @INSTALL_LIBEVENT_TRUE@include_HEADERS = $(EVENT1_HDRS)
+
+# integrate doxygen with automake targets
+@ENABLE_DOXYGEN_TRUE@man3_MANS = @DX_DOCDIR@/man/man3/*
+
+# Docs will be installed. It may be one or more docs supported
+# by doxygen, but does not include 'man'.
+@ENABLE_DOXYGEN_TRUE@docdirs = $(DX_INSTALL_DOCS)
 all: $(BUILT_SOURCES) config.h evconfig-private.h
 	$(MAKE) $(AM_MAKEFLAGS) all-am
 
@@ -1327,7 +1388,7 @@
 .SUFFIXES: .c .lo .log .o .obj .test .test$(EXEEXT) .trs
 am--refresh: Makefile
 	@:
-$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am $(srcdir)/include/include.am $(srcdir)/sample/include.am $(srcdir)/test/include.am $(am__configure_deps)
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am $(srcdir)/include/include.am $(srcdir)/sample/include.am $(srcdir)/test/include.am $(srcdir)/doxygen.am $(am__configure_deps)
 	@for dep in $?; do \
 	  case '$(am__configure_deps)' in \
 	    *$$dep*) \
@@ -1349,7 +1410,7 @@
 	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__maybe_remake_depfiles)'; \
 	    cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__maybe_remake_depfiles);; \
 	esac;
-$(srcdir)/include/include.am $(srcdir)/sample/include.am $(srcdir)/test/include.am $(am__empty):
+$(srcdir)/include/include.am $(srcdir)/sample/include.am $(srcdir)/test/include.am $(srcdir)/doxygen.am $(am__empty):
 
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
 	$(SHELL) ./config.status --recheck
@@ -2143,6 +2204,47 @@
 
 distclean-libtool:
 	-rm -f libtool config.lt
+install-man3: $(man3_MANS)
+	@$(NORMAL_INSTALL)
+	@list1='$(man3_MANS)'; \
+	list2=''; \
+	test -n "$(man3dir)" \
+	  && test -n "`echo $$list1$$list2`" \
+	  || exit 0; \
+	echo " $(MKDIR_P) '$(DESTDIR)$(man3dir)'"; \
+	$(MKDIR_P) "$(DESTDIR)$(man3dir)" || exit 1; \
+	{ for i in $$list1; do echo "$$i"; done;  \
+	if test -n "$$list2"; then \
+	  for i in $$list2; do echo "$$i"; done \
+	    | sed -n '/\.3[a-z]*$$/p'; \
+	fi; \
+	} | while read p; do \
+	  if test -f $$p; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; echo "$$p"; \
+	done | \
+	sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^3][0-9a-z]*$$,3,;x' \
+	      -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \
+	sed 'N;N;s,\n, ,g' | { \
+	list=; while read file base inst; do \
+	  if test "$$base" = "$$inst"; then list="$$list $$file"; else \
+	    echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man3dir)/$$inst'"; \
+	    $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man3dir)/$$inst" || exit $$?; \
+	  fi; \
+	done; \
+	for i in $$list; do echo "$$i"; done | $(am__base_list) | \
+	while read files; do \
+	  test -z "$$files" || { \
+	    echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man3dir)'"; \
+	    $(INSTALL_DATA) $$files "$(DESTDIR)$(man3dir)" || exit $$?; }; \
+	done; }
+
+uninstall-man3:
+	@$(NORMAL_UNINSTALL)
+	@list='$(man3_MANS)'; test -n "$(man3dir)" || exit 0; \
+	files=`{ for i in $$list; do echo "$$i"; done; \
+	} | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^3][0-9a-z]*$$,3,;x' \
+	      -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \
+	dir='$(DESTDIR)$(man3dir)'; $(am__uninstall_files_from_dir)
 install-pkgconfigDATA: $(pkgconfig_DATA)
 	@$(NORMAL_INSTALL)
 	@list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \
@@ -2571,6 +2673,10 @@
 	tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz
 	$(am__post_remove_distdir)
 
+dist-zstd: distdir
+	tardir=$(distdir) && $(am__tar) | zstd -c $${ZSTD_CLEVEL-$${ZSTD_OPT--19}} >$(distdir).tar.zst
+	$(am__post_remove_distdir)
+
 dist-tarZ: distdir
 	@echo WARNING: "Support for distribution archives compressed with" \
 		       "legacy program 'compress' is deprecated." >&2
@@ -2613,6 +2719,8 @@
 	  eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\
 	*.zip*) \
 	  unzip $(distdir).zip ;;\
+	*.tar.zst*) \
+	  zstd -dc $(distdir).tar.zst | $(am__untar) ;;\
 	esac
 	chmod -R a-w $(distdir)
 	chmod u+w $(distdir)
@@ -2683,10 +2791,10 @@
 	$(MAKE) $(AM_MAKEFLAGS) check-TESTS
 check: $(BUILT_SOURCES)
 	$(MAKE) $(AM_MAKEFLAGS) check-am
-all-am: Makefile $(PROGRAMS) $(LTLIBRARIES) $(SCRIPTS) $(DATA) \
+all-am: Makefile $(PROGRAMS) $(LTLIBRARIES) $(SCRIPTS) $(MANS) $(DATA) \
 		$(HEADERS) config.h evconfig-private.h
 installdirs:
-	for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(pkgconfigdir)" "$(DESTDIR)$(includedir)" "$(DESTDIR)$(include_event2dir)" "$(DESTDIR)$(include_event2dir)"; do \
+	for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man3dir)" "$(DESTDIR)$(pkgconfigdir)" "$(DESTDIR)$(includedir)" "$(DESTDIR)$(include_event2dir)" "$(DESTDIR)$(include_event2dir)"; do \
 	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
 	done
 install: $(BUILT_SOURCES)
@@ -2730,9 +2838,12 @@
 	@echo "This command is intended for maintainers to use"
 	@echo "it deletes files that may require special tools to rebuild."
 	-test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
+@ENABLE_DOXYGEN_FALSE@uninstall-local:
+@ENABLE_DOXYGEN_FALSE@install-data-local:
+@ENABLE_DOXYGEN_FALSE@clean-local:
 clean: clean-am
 
-clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
+clean-am: clean-generic clean-libLTLIBRARIES clean-libtool clean-local \
 	clean-noinstLTLIBRARIES clean-noinstPROGRAMS mostlyclean-am
 
 distclean: distclean-am
@@ -2830,7 +2941,8 @@
 
 info-am:
 
-install-data-am: install-includeHEADERS install-include_event2HEADERS \
+install-data-am: install-data-local install-includeHEADERS \
+	install-include_event2HEADERS install-man \
 	install-nodist_include_event2HEADERS install-pkgconfigDATA
 
 install-dvi: install-dvi-am
@@ -2847,7 +2959,7 @@
 
 install-info-am:
 
-install-man:
+install-man: install-man3
 
 install-pdf: install-pdf-am
 
@@ -2957,34 +3069,39 @@
 
 uninstall-am: uninstall-dist_binSCRIPTS uninstall-includeHEADERS \
 	uninstall-include_event2HEADERS uninstall-libLTLIBRARIES \
+	uninstall-local uninstall-man \
 	uninstall-nodist_include_event2HEADERS uninstall-pkgconfigDATA
 
+uninstall-man: uninstall-man3
+
 .MAKE: all check check-am install install-am install-strip
 
 .PHONY: CTAGS GTAGS TAGS all all-am am--depfiles am--refresh check \
 	check-TESTS check-am clean clean-cscope clean-generic \
-	clean-libLTLIBRARIES clean-libtool clean-noinstLTLIBRARIES \
-	clean-noinstPROGRAMS cscope cscopelist-am ctags ctags-am dist \
-	dist-all dist-bzip2 dist-gzip dist-lzip dist-shar dist-tarZ \
-	dist-xz dist-zip distcheck distclean distclean-compile \
+	clean-libLTLIBRARIES clean-libtool clean-local \
+	clean-noinstLTLIBRARIES clean-noinstPROGRAMS cscope \
+	cscopelist-am ctags ctags-am dist dist-all dist-bzip2 \
+	dist-gzip dist-lzip dist-shar dist-tarZ dist-xz dist-zip \
+	dist-zstd distcheck distclean distclean-compile \
 	distclean-generic distclean-hdr distclean-libtool \
 	distclean-tags distcleancheck distdir distuninstallcheck dvi \
 	dvi-am html html-am info info-am install install-am \
-	install-data install-data-am install-dist_binSCRIPTS \
-	install-dvi install-dvi-am install-exec install-exec-am \
-	install-html install-html-am install-includeHEADERS \
-	install-include_event2HEADERS install-info install-info-am \
-	install-libLTLIBRARIES install-man \
-	install-nodist_include_event2HEADERS install-pdf \
-	install-pdf-am install-pkgconfigDATA install-ps install-ps-am \
-	install-strip installcheck installcheck-am installdirs \
-	maintainer-clean maintainer-clean-generic mostlyclean \
-	mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
-	pdf pdf-am ps ps-am recheck tags tags-am uninstall \
-	uninstall-am uninstall-dist_binSCRIPTS \
+	install-data install-data-am install-data-local \
+	install-dist_binSCRIPTS install-dvi install-dvi-am \
+	install-exec install-exec-am install-html install-html-am \
+	install-includeHEADERS install-include_event2HEADERS \
+	install-info install-info-am install-libLTLIBRARIES \
+	install-man install-man3 install-nodist_include_event2HEADERS \
+	install-pdf install-pdf-am install-pkgconfigDATA install-ps \
+	install-ps-am install-strip installcheck installcheck-am \
+	installdirs maintainer-clean maintainer-clean-generic \
+	mostlyclean mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool pdf pdf-am ps ps-am recheck tags tags-am \
+	uninstall uninstall-am uninstall-dist_binSCRIPTS \
 	uninstall-includeHEADERS uninstall-include_event2HEADERS \
-	uninstall-libLTLIBRARIES \
-	uninstall-nodist_include_event2HEADERS uninstall-pkgconfigDATA
+	uninstall-libLTLIBRARIES uninstall-local uninstall-man \
+	uninstall-man3 uninstall-nodist_include_event2HEADERS \
+	uninstall-pkgconfigDATA
 
 .PRECIOUS: Makefile
 
@@ -3033,9 +3150,40 @@
 
 verify: check
 
-doxygen: FORCE
-	doxygen $(srcdir)/Doxyfile
-FORCE:
+# Add all needed rules defined in ax_prog_doxygen.m4
+@ENABLE_DOXYGEN_TRUE@@DX_RULES@
+
+# Use 'make clean' to clean docs generated by doxygen.
+@ENABLE_DOXYGEN_TRUE@clean-local:
+@ENABLE_DOXYGEN_TRUE@	-rm -rf $(DX_CLEANFILES)
+@ENABLE_DOXYGEN_TRUE@$(man3_MANS): doxygen-doc
+
+# Rules for installing docs generated by doxygen into $(htmldir),
+# The typical value of $(htmldir) is '/usr/local/share/doc/$(PACKAGE)'
+@ENABLE_DOXYGEN_TRUE@install-data-local:
+@ENABLE_DOXYGEN_TRUE@	@if ! test -d "$(DESTDIR)$(htmldir)"; then \
+@ENABLE_DOXYGEN_TRUE@	  echo "$(mkinstalldirs) '$(DESTDIR)$(htmldir)'"; \
+@ENABLE_DOXYGEN_TRUE@	  $(mkinstalldirs) '$(DESTDIR)$(htmldir)'; \
+@ENABLE_DOXYGEN_TRUE@	fi
+@ENABLE_DOXYGEN_TRUE@	@for d in $(docdirs); do \
+@ENABLE_DOXYGEN_TRUE@	  echo "cp -pR $$d '$(DESTDIR)$(htmldir)/'"; \
+@ENABLE_DOXYGEN_TRUE@	  cp -pR $$d '$(DESTDIR)$(htmldir)/'; \
+@ENABLE_DOXYGEN_TRUE@	done
+
+# Rules for uninstalling docs generated by doxygen from $(htmldir)
+@ENABLE_DOXYGEN_TRUE@uninstall-local:
+@ENABLE_DOXYGEN_TRUE@	@for d in $(docdirs); do \
+@ENABLE_DOXYGEN_TRUE@	  d=`basename $$d`; \
+@ENABLE_DOXYGEN_TRUE@	  echo "test ! -d '$(DESTDIR)$(htmldir)/'$$d || \
+@ENABLE_DOXYGEN_TRUE@	  { find '$(DESTDIR)$(htmldir)/'$$d -type d ! -perm -200 -exec chmod u+w '{}' ';' && \
+@ENABLE_DOXYGEN_TRUE@	  rm -rf '$(DESTDIR)$(htmldir)/'$$d; }"; \
+@ENABLE_DOXYGEN_TRUE@	  test ! -d '$(DESTDIR)$(htmldir)/'$$d || \
+@ENABLE_DOXYGEN_TRUE@	  { find '$(DESTDIR)$(htmldir)/'$$d -type d ! -perm -200 -exec chmod u+w '{}' ';' && \
+@ENABLE_DOXYGEN_TRUE@	  rm -rf '$(DESTDIR)$(htmldir)/'$$d; }; \
+@ENABLE_DOXYGEN_TRUE@	done
+@ENABLE_DOXYGEN_TRUE@	rmdir "$(DESTDIR)$(htmldir)/" || true
+
+@ENABLE_DOXYGEN_TRUE@doxygen: doxygen-doc
 
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
diff --git a/README.md b/README.md
index 8be37f4..1247e22 100644
--- a/README.md
+++ b/README.md
@@ -464,6 +464,24 @@
  * jeremyerb
  * Fabrice Fontaine
  * wenyg
+ * Aleksandr-Melnikov
+ * ayuseleznev
+ * chenguolong
+ * Dimo Markov
+ * dota17
+ * fanquake
+ * Jan Kasiak
+ * Kamil Rytarowski
+ * Mario Emmenlauer
+ * Michael Davidsaver
+ * mohuang
+ * Nick Grifka
+ * Nicolas J. Bouliane
+ * Paul Osborne
+ * Philip Homburg
+ * Wataru Ashihara
+ * William A Rowe Jr
+ * yangyongsheng
 
 
 If we have forgotten your name, please contact us.
diff --git a/WIN32-Code/nmake/event2/event-config.h b/WIN32-Code/nmake/event2/event-config.h
index 35ec16f..3f3a0d2 100644
--- a/WIN32-Code/nmake/event2/event-config.h
+++ b/WIN32-Code/nmake/event2/event-config.h
@@ -271,7 +271,7 @@
 /* #undef EVENT__HAVE_WORKING_KQUEUE */
 
 /* Numeric representation of the version */
-#define EVENT__NUMERIC_VERSION 0x02010b00
+#define EVENT__NUMERIC_VERSION 0x02010c00
 
 /* Name of package */
 #define EVENT__PACKAGE "libevent"
@@ -332,7 +332,7 @@
 #define EVENT__TIME_WITH_SYS_TIME 1
 
 /* Version number of package */
-#define EVENT__VERSION "2.1.11-stable"
+#define EVENT__VERSION "2.1.12-stable"
 
 /* Define to `__inline__' or `__inline' if that's what the C compiler
    calls it, or to nothing if 'inline' is not supported under any name.  */
diff --git a/aclocal.m4 b/aclocal.m4
index 9678d0b..dbe0113 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1,6 +1,6 @@
-# generated automatically by aclocal 1.16.1 -*- Autoconf -*-
+# generated automatically by aclocal 1.16.2 -*- Autoconf -*-
 
-# Copyright (C) 1996-2018 Free Software Foundation, Inc.
+# Copyright (C) 1996-2020 Free Software Foundation, Inc.
 
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -20,7 +20,7 @@
 If you have problems, you may need to regenerate the build system entirely.
 To do so, use the procedure documented by the package, typically 'autoreconf'.])])
 
-# Copyright (C) 2002-2018 Free Software Foundation, Inc.
+# Copyright (C) 2002-2020 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -35,7 +35,7 @@
 [am__api_version='1.16'
 dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
 dnl require some minimum version.  Point them to the right macro.
-m4_if([$1], [1.16.1], [],
+m4_if([$1], [1.16.2], [],
       [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
 ])
 
@@ -51,14 +51,14 @@
 # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
 # This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
 AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
-[AM_AUTOMAKE_VERSION([1.16.1])dnl
+[AM_AUTOMAKE_VERSION([1.16.2])dnl
 m4_ifndef([AC_AUTOCONF_VERSION],
   [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
 _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
 
 # AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-
 
-# Copyright (C) 2001-2018 Free Software Foundation, Inc.
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -110,7 +110,7 @@
 
 # AM_CONDITIONAL                                            -*- Autoconf -*-
 
-# Copyright (C) 1997-2018 Free Software Foundation, Inc.
+# Copyright (C) 1997-2020 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -141,7 +141,7 @@
 Usually this means the macro was only invoked conditionally.]])
 fi])])
 
-# Copyright (C) 1999-2018 Free Software Foundation, Inc.
+# Copyright (C) 1999-2020 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -332,7 +332,7 @@
 
 # Generate code to set up dependency tracking.              -*- Autoconf -*-
 
-# Copyright (C) 1999-2018 Free Software Foundation, Inc.
+# Copyright (C) 1999-2020 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -371,7 +371,9 @@
   done
   if test $am_rc -ne 0; then
     AC_MSG_FAILURE([Something went wrong bootstrapping makefile fragments
-    for automatic dependency tracking.  Try re-running configure with the
+    for automatic dependency tracking.  If GNU make was not used, consider
+    re-running the configure script with MAKE="gmake" (or whatever is
+    necessary).  You can also try re-running configure with the
     '--disable-dependency-tracking' option to at least be able to build
     the package (albeit without support for automatic dependency tracking).])
   fi
@@ -398,7 +400,7 @@
 
 # Do all the work for Automake.                             -*- Autoconf -*-
 
-# Copyright (C) 1996-2018 Free Software Foundation, Inc.
+# Copyright (C) 1996-2020 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -595,7 +597,7 @@
 done
 echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
 
-# Copyright (C) 2001-2018 Free Software Foundation, Inc.
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -616,7 +618,7 @@
 fi
 AC_SUBST([install_sh])])
 
-# Copyright (C) 2003-2018 Free Software Foundation, Inc.
+# Copyright (C) 2003-2020 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -637,7 +639,7 @@
 
 # Check to see how 'make' treats includes.	            -*- Autoconf -*-
 
-# Copyright (C) 2001-2018 Free Software Foundation, Inc.
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -680,7 +682,7 @@
 
 # Fake the existence of programs that GNU maintainers use.  -*- Autoconf -*-
 
-# Copyright (C) 1997-2018 Free Software Foundation, Inc.
+# Copyright (C) 1997-2020 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -719,7 +721,7 @@
 
 # Helper functions for option handling.                     -*- Autoconf -*-
 
-# Copyright (C) 2001-2018 Free Software Foundation, Inc.
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -748,7 +750,7 @@
 AC_DEFUN([_AM_IF_OPTION],
 [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
 
-# Copyright (C) 1999-2018 Free Software Foundation, Inc.
+# Copyright (C) 1999-2020 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -795,7 +797,7 @@
 # For backward compatibility.
 AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])])
 
-# Copyright (C) 2001-2018 Free Software Foundation, Inc.
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -814,7 +816,7 @@
 
 # Check to make sure that the build environment is sane.    -*- Autoconf -*-
 
-# Copyright (C) 1996-2018 Free Software Foundation, Inc.
+# Copyright (C) 1996-2020 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -895,7 +897,7 @@
 rm -f conftest.file
 ])
 
-# Copyright (C) 2009-2018 Free Software Foundation, Inc.
+# Copyright (C) 2009-2020 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -955,7 +957,7 @@
 _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl
 ])
 
-# Copyright (C) 2001-2018 Free Software Foundation, Inc.
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -983,7 +985,7 @@
 INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
 AC_SUBST([INSTALL_STRIP_PROGRAM])])
 
-# Copyright (C) 2006-2018 Free Software Foundation, Inc.
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -1002,7 +1004,7 @@
 
 # Check how to create a tarball.                            -*- Autoconf -*-
 
-# Copyright (C) 2004-2018 Free Software Foundation, Inc.
+# Copyright (C) 2004-2020 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -1135,6 +1137,8 @@
 
 m4_include([m4/ac_backport_259_ssizet.m4])
 m4_include([m4/acx_pthread.m4])
+m4_include([m4/ax_check_funcs_ex.m4])
+m4_include([m4/ax_prog_doxygen.m4])
 m4_include([m4/libevent_openssl.m4])
 m4_include([m4/libtool.m4])
 m4_include([m4/ltoptions.m4])
diff --git a/arc4random.c b/arc4random.c
index be64452..8729f6b 100644
--- a/arc4random.c
+++ b/arc4random.c
@@ -63,6 +63,9 @@
 #ifdef EVENT__HAVE_SYS_SYSCTL_H
 #include <sys/sysctl.h>
 #endif
+#ifdef EVENT__HAVE_SYS_RANDOM_H
+#include <sys/random.h>
+#endif
 #endif
 #include <limits.h>
 #include <stdlib.h>
@@ -167,17 +170,11 @@
 }
 #endif
 
-#if defined(EVENT__HAVE_SYS_SYSCTL_H) && defined(EVENT__HAVE_SYSCTL)
-#if EVENT__HAVE_DECL_CTL_KERN && EVENT__HAVE_DECL_KERN_RANDOM && EVENT__HAVE_DECL_RANDOM_UUID
-#define TRY_SEED_SYSCTL_LINUX
+#if defined(EVENT__HAVE_GETRANDOM)
+#define TRY_SEED_GETRANDOM
 static int
-arc4_seed_sysctl_linux(void)
+arc4_seed_getrandom(void)
 {
-	/* Based on code by William Ahern, this function tries to use the
-	 * RANDOM_UUID sysctl to get entropy from the kernel.  This can work
-	 * even if /dev/urandom is inaccessible for some reason (e.g., we're
-	 * running in a chroot). */
-	int mib[] = { CTL_KERN, KERN_RANDOM, RANDOM_UUID };
 	unsigned char buf[ADD_ENTROPY];
 	size_t len, n;
 	unsigned i;
@@ -188,7 +185,7 @@
 	for (len = 0; len < sizeof(buf); len += n) {
 		n = sizeof(buf) - len;
 
-		if (0 != sysctl(mib, 3, &buf[len], &n, NULL, 0))
+		if (0 == getrandom(&buf[len], n, 0))
 			return -1;
 	}
 	/* make sure that the buffer actually got set. */
@@ -202,8 +199,9 @@
 	evutil_memclear_(buf, sizeof(buf));
 	return 0;
 }
-#endif
+#endif /* EVENT__HAVE_GETRANDOM */
 
+#if defined(EVENT__HAVE_SYS_SYSCTL_H) && defined(EVENT__HAVE_SYSCTL)
 #if EVENT__HAVE_DECL_CTL_KERN && EVENT__HAVE_DECL_KERN_ARND
 #define TRY_SEED_SYSCTL_BSD
 static int
@@ -342,6 +340,10 @@
 	if (0 == arc4_seed_win32())
 		ok = 1;
 #endif
+#ifdef TRY_SEED_GETRANDOM
+	if (0 == arc4_seed_getrandom())
+		ok = 1;
+#endif
 #ifdef TRY_SEED_URANDOM
 	if (0 == arc4_seed_urandom())
 		ok = 1;
@@ -351,12 +353,6 @@
 	    0 == arc4_seed_proc_sys_kernel_random_uuid())
 		ok = 1;
 #endif
-#ifdef TRY_SEED_SYSCTL_LINUX
-	/* Apparently Linux is deprecating sysctl, and spewing warning
-	 * messages when you try to use it. */
-	if (!ok && 0 == arc4_seed_sysctl_linux())
-		ok = 1;
-#endif
 #ifdef TRY_SEED_SYSCTL_BSD
 	if (0 == arc4_seed_sysctl_bsd())
 		ok = 1;
diff --git a/buffer.c b/buffer.c
index a51b6c5..3524b35 100644
--- a/buffer.c
+++ b/buffer.c
@@ -1421,9 +1421,11 @@
 	for (; chain != NULL && (size_t)size >= chain->off; chain = next) {
 		next = chain->next;
 
-		memcpy(buffer, chain->buffer + chain->misalign, chain->off);
-		size -= chain->off;
-		buffer += chain->off;
+		if (chain->buffer) {
+			memcpy(buffer, chain->buffer + chain->misalign, chain->off);
+			size -= chain->off;
+			buffer += chain->off;
+		}
 		if (chain == last_with_data)
 			removed_last_with_data = 1;
 		if (&chain->next == buf->last_with_datap)
@@ -3209,7 +3211,6 @@
 			}
 		}
 	}
-	++seg->refcnt;
 	EVLOCK_UNLOCK(seg->lock, 0);
 
 	if (buf->freeze_end)
@@ -3273,6 +3274,9 @@
 		chain->off = length;
 	}
 
+	EVLOCK_LOCK(seg->lock, 0);
+	++seg->refcnt;
+	EVLOCK_UNLOCK(seg->lock, 0);
 	extra->segment = seg;
 	buf->n_add_for_cb += length;
 	evbuffer_chain_insert(buf, chain);
diff --git a/bufferevent_sock.c b/bufferevent_sock.c
index f275b02..f40a8d9 100644
--- a/bufferevent_sock.c
+++ b/bufferevent_sock.c
@@ -650,7 +650,7 @@
 	struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
 
 	BEV_LOCK(bufev);
-	if (!BEV_IS_SOCKET(bufev))
+	if (BEV_IS_ASYNC(bufev) || BEV_IS_FILTER(bufev) || BEV_IS_PAIR(bufev))
 		goto done;
 
 	if (event_priority_set(&bufev->ev_read, priority) == -1)
diff --git a/compile b/build-aux/compile
similarity index 98%
rename from compile
rename to build-aux/compile
index 99e5052..23fcba0 100755
--- a/compile
+++ b/build-aux/compile
@@ -3,7 +3,7 @@
 
 scriptversion=2018-03-07.03; # UTC
 
-# Copyright (C) 1999-2018 Free Software Foundation, Inc.
+# Copyright (C) 1999-2020 Free Software Foundation, Inc.
 # Written by Tom Tromey <tromey@cygnus.com>.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -53,7 +53,7 @@
 	  MINGW*)
 	    file_conv=mingw
 	    ;;
-	  CYGWIN*)
+	  CYGWIN* | MSYS*)
 	    file_conv=cygwin
 	    ;;
 	  *)
@@ -67,7 +67,7 @@
 	mingw/*)
 	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
 	  ;;
-	cygwin/*)
+	cygwin/* | msys/*)
 	  file=`cygpath -m "$file" || echo "$file"`
 	  ;;
 	wine/*)
diff --git a/config.guess b/build-aux/config.guess
similarity index 84%
rename from config.guess
rename to build-aux/config.guess
index 256083a..45001cf 100755
--- a/config.guess
+++ b/build-aux/config.guess
@@ -1,8 +1,8 @@
 #! /bin/sh
 # Attempt to guess a canonical system name.
-#   Copyright 1992-2018 Free Software Foundation, Inc.
+#   Copyright 1992-2020 Free Software Foundation, Inc.
 
-timestamp='2018-03-08'
+timestamp='2020-01-01'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -50,7 +50,7 @@
 GNU config.guess ($timestamp)
 
 Originally written by Per Bothner.
-Copyright 1992-2018 Free Software Foundation, Inc.
+Copyright 1992-2020 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -84,8 +84,6 @@
   exit 1
 fi
 
-trap 'exit 1' 1 2 15
-
 # CC_FOR_BUILD -- compiler used by this script. Note that the use of a
 # compiler to aid in system detection is discouraged as it requires
 # temporary files to be created and, as you can see below, it is a
@@ -96,34 +94,40 @@
 
 # Portable tmp directory creation inspired by the Autoconf team.
 
-set_cc_for_build='
-trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
-trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
-: ${TMPDIR=/tmp} ;
- { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
- { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
- { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
- { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
-dummy=$tmp/dummy ;
-tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
-case $CC_FOR_BUILD,$HOST_CC,$CC in
- ,,)    echo "int x;" > "$dummy.c" ;
-	for c in cc gcc c89 c99 ; do
-	  if ($c -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then
-	     CC_FOR_BUILD="$c"; break ;
-	  fi ;
-	done ;
-	if test x"$CC_FOR_BUILD" = x ; then
-	  CC_FOR_BUILD=no_compiler_found ;
-	fi
-	;;
- ,,*)   CC_FOR_BUILD=$CC ;;
- ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
-esac ; set_cc_for_build= ;'
+tmp=
+# shellcheck disable=SC2172
+trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15
+
+set_cc_for_build() {
+    # prevent multiple calls if $tmp is already set
+    test "$tmp" && return 0
+    : "${TMPDIR=/tmp}"
+    # shellcheck disable=SC2039
+    { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
+	{ test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } ||
+	{ tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } ||
+	{ echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; }
+    dummy=$tmp/dummy
+    case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in
+	,,)    echo "int x;" > "$dummy.c"
+	       for driver in cc gcc c89 c99 ; do
+		   if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then
+		       CC_FOR_BUILD="$driver"
+		       break
+		   fi
+	       done
+	       if test x"$CC_FOR_BUILD" = x ; then
+		   CC_FOR_BUILD=no_compiler_found
+	       fi
+	       ;;
+	,,*)   CC_FOR_BUILD=$CC ;;
+	,*,*)  CC_FOR_BUILD=$HOST_CC ;;
+    esac
+}
 
 # This is needed to find uname on a Pyramid OSx when run in the BSD universe.
 # (ghazi@noc.rutgers.edu 1994-08-24)
-if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
+if test -f /.attbin/uname ; then
 	PATH=$PATH:/.attbin ; export PATH
 fi
 
@@ -138,7 +142,7 @@
 	# We could probably try harder.
 	LIBC=gnu
 
-	eval "$set_cc_for_build"
+	set_cc_for_build
 	cat <<-EOF > "$dummy.c"
 	#include <features.h>
 	#if defined(__UCLIBC__)
@@ -199,7 +203,7 @@
 		os=netbsdelf
 		;;
 	    arm*|i386|m68k|ns32k|sh3*|sparc|vax)
-		eval "$set_cc_for_build"
+		set_cc_for_build
 		if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
 			| grep -q __ELF__
 		then
@@ -237,7 +241,7 @@
 	# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
 	# contains redundant information, the shorter form:
 	# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
-	echo "$machine-${os}${release}${abi}"
+	echo "$machine-${os}${release}${abi-}"
 	exit ;;
     *:Bitrig:*:*)
 	UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'`
@@ -260,6 +264,9 @@
     *:SolidBSD:*:*)
 	echo "$UNAME_MACHINE"-unknown-solidbsd"$UNAME_RELEASE"
 	exit ;;
+    *:OS108:*:*)
+	echo "$UNAME_MACHINE"-unknown-os108_"$UNAME_RELEASE"
+	exit ;;
     macppc:MirBSD:*:*)
 	echo powerpc-unknown-mirbsd"$UNAME_RELEASE"
 	exit ;;
@@ -269,12 +276,15 @@
     *:Sortix:*:*)
 	echo "$UNAME_MACHINE"-unknown-sortix
 	exit ;;
+    *:Twizzler:*:*)
+	echo "$UNAME_MACHINE"-unknown-twizzler
+	exit ;;
     *:Redox:*:*)
 	echo "$UNAME_MACHINE"-unknown-redox
 	exit ;;
     mips:OSF1:*.*)
-        echo mips-dec-osf1
-        exit ;;
+	echo mips-dec-osf1
+	exit ;;
     alpha:OSF1:*:*)
 	case $UNAME_RELEASE in
 	*4.0)
@@ -389,7 +399,7 @@
 	echo i386-pc-auroraux"$UNAME_RELEASE"
 	exit ;;
     i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
-	eval "$set_cc_for_build"
+	set_cc_for_build
 	SUN_ARCH=i386
 	# If there is a compiler, see if it is configured for 64-bit objects.
 	# Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
@@ -482,7 +492,7 @@
 	echo clipper-intergraph-clix"$UNAME_RELEASE"
 	exit ;;
     mips:*:*:UMIPS | mips:*:*:RISCos)
-	eval "$set_cc_for_build"
+	set_cc_for_build
 	sed 's/^	//' << EOF > "$dummy.c"
 #ifdef __cplusplus
 #include <stdio.h>  /* for printf() prototype */
@@ -579,7 +589,7 @@
 	exit ;;
     *:AIX:2:3)
 	if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
-		eval "$set_cc_for_build"
+		set_cc_for_build
 		sed 's/^		//' << EOF > "$dummy.c"
 		#include <sys/systemcfg.h>
 
@@ -660,7 +670,7 @@
 		    esac
 		fi
 		if [ "$HP_ARCH" = "" ]; then
-		    eval "$set_cc_for_build"
+		    set_cc_for_build
 		    sed 's/^		//' << EOF > "$dummy.c"
 
 		#define _HPUX_SOURCE
@@ -700,7 +710,7 @@
 	esac
 	if [ "$HP_ARCH" = hppa2.0w ]
 	then
-	    eval "$set_cc_for_build"
+	    set_cc_for_build
 
 	    # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
 	    # 32-bit code.  hppa64-hp-hpux* has the same kernel and a compiler
@@ -726,7 +736,7 @@
 	echo ia64-hp-hpux"$HPUX_REV"
 	exit ;;
     3050*:HI-UX:*:*)
-	eval "$set_cc_for_build"
+	set_cc_for_build
 	sed 's/^	//' << EOF > "$dummy.c"
 	#include <unistd.h>
 	int
@@ -840,6 +850,17 @@
     *:BSD/OS:*:*)
 	echo "$UNAME_MACHINE"-unknown-bsdi"$UNAME_RELEASE"
 	exit ;;
+    arm:FreeBSD:*:*)
+	UNAME_PROCESSOR=`uname -p`
+	set_cc_for_build
+	if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
+	    | grep -q __ARM_PCS_VFP
+	then
+	    echo "${UNAME_PROCESSOR}"-unknown-freebsd"`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`"-gnueabi
+	else
+	    echo "${UNAME_PROCESSOR}"-unknown-freebsd"`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`"-gnueabihf
+	fi
+	exit ;;
     *:FreeBSD:*:*)
 	UNAME_PROCESSOR=`/usr/bin/uname -p`
 	case "$UNAME_PROCESSOR" in
@@ -881,7 +902,7 @@
 	echo "$UNAME_MACHINE"-pc-uwin
 	exit ;;
     amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
-	echo x86_64-unknown-cygwin
+	echo x86_64-pc-cygwin
 	exit ;;
     prep*:SunOS:5.*:*)
 	echo powerpcle-unknown-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`"
@@ -894,8 +915,8 @@
 	# other systems with GNU libc and userland
 	echo "$UNAME_MACHINE-unknown-`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"``echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`-$LIBC"
 	exit ;;
-    i*86:Minix:*:*)
-	echo "$UNAME_MACHINE"-pc-minix
+    *:Minix:*:*)
+	echo "$UNAME_MACHINE"-unknown-minix
 	exit ;;
     aarch64:Linux:*:*)
 	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
@@ -905,7 +926,7 @@
 	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
 	exit ;;
     alpha:Linux:*:*)
-	case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
+	case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null` in
 	  EV5)   UNAME_MACHINE=alphaev5 ;;
 	  EV56)  UNAME_MACHINE=alphaev56 ;;
 	  PCA56) UNAME_MACHINE=alphapca56 ;;
@@ -922,7 +943,7 @@
 	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
 	exit ;;
     arm*:Linux:*:*)
-	eval "$set_cc_for_build"
+	set_cc_for_build
 	if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
 	    | grep -q __ARM_EABI__
 	then
@@ -971,23 +992,51 @@
 	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
 	exit ;;
     mips:Linux:*:* | mips64:Linux:*:*)
-	eval "$set_cc_for_build"
+	set_cc_for_build
+	IS_GLIBC=0
+	test x"${LIBC}" = xgnu && IS_GLIBC=1
 	sed 's/^	//' << EOF > "$dummy.c"
 	#undef CPU
-	#undef ${UNAME_MACHINE}
-	#undef ${UNAME_MACHINE}el
+	#undef mips
+	#undef mipsel
+	#undef mips64
+	#undef mips64el
+	#if ${IS_GLIBC} && defined(_ABI64)
+	LIBCABI=gnuabi64
+	#else
+	#if ${IS_GLIBC} && defined(_ABIN32)
+	LIBCABI=gnuabin32
+	#else
+	LIBCABI=${LIBC}
+	#endif
+	#endif
+
+	#if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6
+	CPU=mipsisa64r6
+	#else
+	#if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6
+	CPU=mipsisa32r6
+	#else
+	#if defined(__mips64)
+	CPU=mips64
+	#else
+	CPU=mips
+	#endif
+	#endif
+	#endif
+
 	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
-	CPU=${UNAME_MACHINE}el
+	MIPS_ENDIAN=el
 	#else
 	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
-	CPU=${UNAME_MACHINE}
+	MIPS_ENDIAN=
 	#else
-	CPU=
+	MIPS_ENDIAN=
 	#endif
 	#endif
 EOF
-	eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU'`"
-	test "x$CPU" != x && { echo "$CPU-unknown-linux-$LIBC"; exit; }
+	eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI'`"
+	test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; }
 	;;
     mips64el:Linux:*:*)
 	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
@@ -1100,7 +1149,7 @@
 	    *Pentium)	     UNAME_MACHINE=i586 ;;
 	    *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
 	esac
-	echo "$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}{$UNAME_VERSION}"
+	echo "$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}"
 	exit ;;
     i*86:*:3.2:*)
 	if test -f /usr/options/cb.name; then
@@ -1284,38 +1333,39 @@
 	echo "$UNAME_MACHINE"-apple-rhapsody"$UNAME_RELEASE"
 	exit ;;
     *:Darwin:*:*)
-	UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
-	eval "$set_cc_for_build"
-	if test "$UNAME_PROCESSOR" = unknown ; then
-	    UNAME_PROCESSOR=powerpc
+	UNAME_PROCESSOR=`uname -p`
+	case $UNAME_PROCESSOR in
+	    unknown) UNAME_PROCESSOR=powerpc ;;
+	esac
+	if command -v xcode-select > /dev/null 2> /dev/null && \
+		! xcode-select --print-path > /dev/null 2> /dev/null ; then
+	    # Avoid executing cc if there is no toolchain installed as
+	    # cc will be a stub that puts up a graphical alert
+	    # prompting the user to install developer tools.
+	    CC_FOR_BUILD=no_compiler_found
+	else
+	    set_cc_for_build
 	fi
-	if test "`echo "$UNAME_RELEASE" | sed -e 's/\..*//'`" -le 10 ; then
-	    if [ "$CC_FOR_BUILD" != no_compiler_found ]; then
-		if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
-		       (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
-		       grep IS_64BIT_ARCH >/dev/null
-		then
-		    case $UNAME_PROCESSOR in
-			i386) UNAME_PROCESSOR=x86_64 ;;
-			powerpc) UNAME_PROCESSOR=powerpc64 ;;
-		    esac
-		fi
-		# On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc
-		if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \
-		       (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
-		       grep IS_PPC >/dev/null
-		then
-		    UNAME_PROCESSOR=powerpc
-		fi
+	if [ "$CC_FOR_BUILD" != no_compiler_found ]; then
+	    if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
+		   (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
+		   grep IS_64BIT_ARCH >/dev/null
+	    then
+		case $UNAME_PROCESSOR in
+		    i386) UNAME_PROCESSOR=x86_64 ;;
+		    powerpc) UNAME_PROCESSOR=powerpc64 ;;
+		esac
+	    fi
+	    # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc
+	    if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \
+		   (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
+		   grep IS_PPC >/dev/null
+	    then
+		UNAME_PROCESSOR=powerpc
 	    fi
 	elif test "$UNAME_PROCESSOR" = i386 ; then
-	    # Avoid executing cc on OS X 10.9, as it ships with a stub
-	    # that puts up a graphical alert prompting to install
-	    # developer tools.  Any system running Mac OS X 10.7 or
-	    # later (Darwin 11 and later) is required to have a 64-bit
-	    # processor. This is not true of the ARM version of Darwin
-	    # that Apple uses in portable devices.
-	    UNAME_PROCESSOR=x86_64
+	    # uname -m returns i386 or x86_64
+	    UNAME_PROCESSOR=$UNAME_MACHINE
 	fi
 	echo "$UNAME_PROCESSOR"-apple-darwin"$UNAME_RELEASE"
 	exit ;;
@@ -1358,6 +1408,7 @@
 	# "uname -m" is not consistent, so use $cputype instead. 386
 	# is converted to i386 for consistency with other x86
 	# operating systems.
+	# shellcheck disable=SC2154
 	if test "$cputype" = 386; then
 	    UNAME_MACHINE=i386
 	else
@@ -1414,8 +1465,148 @@
     amd64:Isilon\ OneFS:*:*)
 	echo x86_64-unknown-onefs
 	exit ;;
+    *:Unleashed:*:*)
+	echo "$UNAME_MACHINE"-unknown-unleashed"$UNAME_RELEASE"
+	exit ;;
 esac
 
+# No uname command or uname output not recognized.
+set_cc_for_build
+cat > "$dummy.c" <<EOF
+#ifdef _SEQUENT_
+#include <sys/types.h>
+#include <sys/utsname.h>
+#endif
+#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__)
+#if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__)
+#include <signal.h>
+#if defined(_SIZE_T_) || defined(SIGLOST)
+#include <sys/utsname.h>
+#endif
+#endif
+#endif
+main ()
+{
+#if defined (sony)
+#if defined (MIPSEB)
+  /* BFD wants "bsd" instead of "newsos".  Perhaps BFD should be changed,
+     I don't know....  */
+  printf ("mips-sony-bsd\n"); exit (0);
+#else
+#include <sys/param.h>
+  printf ("m68k-sony-newsos%s\n",
+#ifdef NEWSOS4
+  "4"
+#else
+  ""
+#endif
+  ); exit (0);
+#endif
+#endif
+
+#if defined (NeXT)
+#if !defined (__ARCHITECTURE__)
+#define __ARCHITECTURE__ "m68k"
+#endif
+  int version;
+  version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
+  if (version < 4)
+    printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
+  else
+    printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);
+  exit (0);
+#endif
+
+#if defined (MULTIMAX) || defined (n16)
+#if defined (UMAXV)
+  printf ("ns32k-encore-sysv\n"); exit (0);
+#else
+#if defined (CMU)
+  printf ("ns32k-encore-mach\n"); exit (0);
+#else
+  printf ("ns32k-encore-bsd\n"); exit (0);
+#endif
+#endif
+#endif
+
+#if defined (__386BSD__)
+  printf ("i386-pc-bsd\n"); exit (0);
+#endif
+
+#if defined (sequent)
+#if defined (i386)
+  printf ("i386-sequent-dynix\n"); exit (0);
+#endif
+#if defined (ns32000)
+  printf ("ns32k-sequent-dynix\n"); exit (0);
+#endif
+#endif
+
+#if defined (_SEQUENT_)
+  struct utsname un;
+
+  uname(&un);
+  if (strncmp(un.version, "V2", 2) == 0) {
+    printf ("i386-sequent-ptx2\n"); exit (0);
+  }
+  if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
+    printf ("i386-sequent-ptx1\n"); exit (0);
+  }
+  printf ("i386-sequent-ptx\n"); exit (0);
+#endif
+
+#if defined (vax)
+#if !defined (ultrix)
+#include <sys/param.h>
+#if defined (BSD)
+#if BSD == 43
+  printf ("vax-dec-bsd4.3\n"); exit (0);
+#else
+#if BSD == 199006
+  printf ("vax-dec-bsd4.3reno\n"); exit (0);
+#else
+  printf ("vax-dec-bsd\n"); exit (0);
+#endif
+#endif
+#else
+  printf ("vax-dec-bsd\n"); exit (0);
+#endif
+#else
+#if defined(_SIZE_T_) || defined(SIGLOST)
+  struct utsname un;
+  uname (&un);
+  printf ("vax-dec-ultrix%s\n", un.release); exit (0);
+#else
+  printf ("vax-dec-ultrix\n"); exit (0);
+#endif
+#endif
+#endif
+#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__)
+#if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__)
+#if defined(_SIZE_T_) || defined(SIGLOST)
+  struct utsname *un;
+  uname (&un);
+  printf ("mips-dec-ultrix%s\n", un.release); exit (0);
+#else
+  printf ("mips-dec-ultrix\n"); exit (0);
+#endif
+#endif
+#endif
+
+#if defined (alliant) && defined (i860)
+  printf ("i860-alliant-bsd\n"); exit (0);
+#endif
+
+  exit (1);
+}
+EOF
+
+$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=`$dummy` &&
+	{ echo "$SYSTEM_NAME"; exit; }
+
+# Apollos put the system type in the environment.
+test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; }
+
 echo "$0: unable to guess system type" >&2
 
 case "$UNAME_MACHINE:$UNAME_SYSTEM" in
diff --git a/build-aux/config.sub b/build-aux/config.sub
new file mode 100755
index 0000000..f02d43a
--- /dev/null
+++ b/build-aux/config.sub
@@ -0,0 +1,1793 @@
+#! /bin/sh
+# Configuration validation subroutine script.
+#   Copyright 1992-2020 Free Software Foundation, Inc.
+
+timestamp='2020-01-01'
+
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see <https://www.gnu.org/licenses/>.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that
+# program.  This Exception is an additional permission under section 7
+# of the GNU General Public License, version 3 ("GPLv3").
+
+
+# Please send patches to <config-patches@gnu.org>.
+#
+# Configuration subroutine to validate and canonicalize a configuration type.
+# Supply the specified configuration type as an argument.
+# If it is invalid, we print an error message on stderr and exit with code 1.
+# Otherwise, we print the canonical config type on stdout and succeed.
+
+# You can get the latest version of this script from:
+# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
+
+# This file is supposed to be the same for all GNU packages
+# and recognize all the CPU types, system types and aliases
+# that are meaningful with *any* GNU software.
+# Each package is responsible for reporting which valid configurations
+# it does not support.  The user should be able to distinguish
+# a failure to support a valid configuration from a meaningless
+# configuration.
+
+# The goal of this file is to map all the various variations of a given
+# machine specification into a single specification in the form:
+#	CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
+# or in some cases, the newer four-part form:
+#	CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
+# It is wrong to echo any other type of specification.
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS
+
+Canonicalize a configuration name.
+
+Options:
+  -h, --help         print this help, then exit
+  -t, --time-stamp   print date of last modification, then exit
+  -v, --version      print version number, then exit
+
+Report bugs and patches to <config-patches@gnu.org>."
+
+version="\
+GNU config.sub ($timestamp)
+
+Copyright 1992-2020 Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+  case $1 in
+    --time-stamp | --time* | -t )
+       echo "$timestamp" ; exit ;;
+    --version | -v )
+       echo "$version" ; exit ;;
+    --help | --h* | -h )
+       echo "$usage"; exit ;;
+    -- )     # Stop option processing
+       shift; break ;;
+    - )	# Use stdin as input.
+       break ;;
+    -* )
+       echo "$me: invalid option $1$help" >&2
+       exit 1 ;;
+
+    *local*)
+       # First pass through any local machine types.
+       echo "$1"
+       exit ;;
+
+    * )
+       break ;;
+  esac
+done
+
+case $# in
+ 0) echo "$me: missing argument$help" >&2
+    exit 1;;
+ 1) ;;
+ *) echo "$me: too many arguments$help" >&2
+    exit 1;;
+esac
+
+# Split fields of configuration type
+# shellcheck disable=SC2162
+IFS="-" read field1 field2 field3 field4 <<EOF
+$1
+EOF
+
+# Separate into logical components for further validation
+case $1 in
+	*-*-*-*-*)
+		echo Invalid configuration \`"$1"\': more than four components >&2
+		exit 1
+		;;
+	*-*-*-*)
+		basic_machine=$field1-$field2
+		os=$field3-$field4
+		;;
+	*-*-*)
+		# Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two
+		# parts
+		maybe_os=$field2-$field3
+		case $maybe_os in
+			nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc \
+			| linux-newlib* | linux-musl* | linux-uclibc* | uclinux-uclibc* \
+			| uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \
+			| netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \
+			| storm-chaos* | os2-emx* | rtmk-nova*)
+				basic_machine=$field1
+				os=$maybe_os
+				;;
+			android-linux)
+				basic_machine=$field1-unknown
+				os=linux-android
+				;;
+			*)
+				basic_machine=$field1-$field2
+				os=$field3
+				;;
+		esac
+		;;
+	*-*)
+		# A lone config we happen to match not fitting any pattern
+		case $field1-$field2 in
+			decstation-3100)
+				basic_machine=mips-dec
+				os=
+				;;
+			*-*)
+				# Second component is usually, but not always the OS
+				case $field2 in
+					# Prevent following clause from handling this valid os
+					sun*os*)
+						basic_machine=$field1
+						os=$field2
+						;;
+					# Manufacturers
+					dec* | mips* | sequent* | encore* | pc533* | sgi* | sony* \
+					| att* | 7300* | 3300* | delta* | motorola* | sun[234]* \
+					| unicom* | ibm* | next | hp | isi* | apollo | altos* \
+					| convergent* | ncr* | news | 32* | 3600* | 3100* \
+					| hitachi* | c[123]* | convex* | sun | crds | omron* | dg \
+					| ultra | tti* | harris | dolphin | highlevel | gould \
+					| cbm | ns | masscomp | apple | axis | knuth | cray \
+					| microblaze* | sim | cisco \
+					| oki | wec | wrs | winbond)
+						basic_machine=$field1-$field2
+						os=
+						;;
+					*)
+						basic_machine=$field1
+						os=$field2
+						;;
+				esac
+			;;
+		esac
+		;;
+	*)
+		# Convert single-component short-hands not valid as part of
+		# multi-component configurations.
+		case $field1 in
+			386bsd)
+				basic_machine=i386-pc
+				os=bsd
+				;;
+			a29khif)
+				basic_machine=a29k-amd
+				os=udi
+				;;
+			adobe68k)
+				basic_machine=m68010-adobe
+				os=scout
+				;;
+			alliant)
+				basic_machine=fx80-alliant
+				os=
+				;;
+			altos | altos3068)
+				basic_machine=m68k-altos
+				os=
+				;;
+			am29k)
+				basic_machine=a29k-none
+				os=bsd
+				;;
+			amdahl)
+				basic_machine=580-amdahl
+				os=sysv
+				;;
+			amiga)
+				basic_machine=m68k-unknown
+				os=
+				;;
+			amigaos | amigados)
+				basic_machine=m68k-unknown
+				os=amigaos
+				;;
+			amigaunix | amix)
+				basic_machine=m68k-unknown
+				os=sysv4
+				;;
+			apollo68)
+				basic_machine=m68k-apollo
+				os=sysv
+				;;
+			apollo68bsd)
+				basic_machine=m68k-apollo
+				os=bsd
+				;;
+			aros)
+				basic_machine=i386-pc
+				os=aros
+				;;
+			aux)
+				basic_machine=m68k-apple
+				os=aux
+				;;
+			balance)
+				basic_machine=ns32k-sequent
+				os=dynix
+				;;
+			blackfin)
+				basic_machine=bfin-unknown
+				os=linux
+				;;
+			cegcc)
+				basic_machine=arm-unknown
+				os=cegcc
+				;;
+			convex-c1)
+				basic_machine=c1-convex
+				os=bsd
+				;;
+			convex-c2)
+				basic_machine=c2-convex
+				os=bsd
+				;;
+			convex-c32)
+				basic_machine=c32-convex
+				os=bsd
+				;;
+			convex-c34)
+				basic_machine=c34-convex
+				os=bsd
+				;;
+			convex-c38)
+				basic_machine=c38-convex
+				os=bsd
+				;;
+			cray)
+				basic_machine=j90-cray
+				os=unicos
+				;;
+			crds | unos)
+				basic_machine=m68k-crds
+				os=
+				;;
+			da30)
+				basic_machine=m68k-da30
+				os=
+				;;
+			decstation | pmax | pmin | dec3100 | decstatn)
+				basic_machine=mips-dec
+				os=
+				;;
+			delta88)
+				basic_machine=m88k-motorola
+				os=sysv3
+				;;
+			dicos)
+				basic_machine=i686-pc
+				os=dicos
+				;;
+			djgpp)
+				basic_machine=i586-pc
+				os=msdosdjgpp
+				;;
+			ebmon29k)
+				basic_machine=a29k-amd
+				os=ebmon
+				;;
+			es1800 | OSE68k | ose68k | ose | OSE)
+				basic_machine=m68k-ericsson
+				os=ose
+				;;
+			gmicro)
+				basic_machine=tron-gmicro
+				os=sysv
+				;;
+			go32)
+				basic_machine=i386-pc
+				os=go32
+				;;
+			h8300hms)
+				basic_machine=h8300-hitachi
+				os=hms
+				;;
+			h8300xray)
+				basic_machine=h8300-hitachi
+				os=xray
+				;;
+			h8500hms)
+				basic_machine=h8500-hitachi
+				os=hms
+				;;
+			harris)
+				basic_machine=m88k-harris
+				os=sysv3
+				;;
+			hp300 | hp300hpux)
+				basic_machine=m68k-hp
+				os=hpux
+				;;
+			hp300bsd)
+				basic_machine=m68k-hp
+				os=bsd
+				;;
+			hppaosf)
+				basic_machine=hppa1.1-hp
+				os=osf
+				;;
+			hppro)
+				basic_machine=hppa1.1-hp
+				os=proelf
+				;;
+			i386mach)
+				basic_machine=i386-mach
+				os=mach
+				;;
+			isi68 | isi)
+				basic_machine=m68k-isi
+				os=sysv
+				;;
+			m68knommu)
+				basic_machine=m68k-unknown
+				os=linux
+				;;
+			magnum | m3230)
+				basic_machine=mips-mips
+				os=sysv
+				;;
+			merlin)
+				basic_machine=ns32k-utek
+				os=sysv
+				;;
+			mingw64)
+				basic_machine=x86_64-pc
+				os=mingw64
+				;;
+			mingw32)
+				basic_machine=i686-pc
+				os=mingw32
+				;;
+			mingw32ce)
+				basic_machine=arm-unknown
+				os=mingw32ce
+				;;
+			monitor)
+				basic_machine=m68k-rom68k
+				os=coff
+				;;
+			morphos)
+				basic_machine=powerpc-unknown
+				os=morphos
+				;;
+			moxiebox)
+				basic_machine=moxie-unknown
+				os=moxiebox
+				;;
+			msdos)
+				basic_machine=i386-pc
+				os=msdos
+				;;
+			msys)
+				basic_machine=i686-pc
+				os=msys
+				;;
+			mvs)
+				basic_machine=i370-ibm
+				os=mvs
+				;;
+			nacl)
+				basic_machine=le32-unknown
+				os=nacl
+				;;
+			ncr3000)
+				basic_machine=i486-ncr
+				os=sysv4
+				;;
+			netbsd386)
+				basic_machine=i386-pc
+				os=netbsd
+				;;
+			netwinder)
+				basic_machine=armv4l-rebel
+				os=linux
+				;;
+			news | news700 | news800 | news900)
+				basic_machine=m68k-sony
+				os=newsos
+				;;
+			news1000)
+				basic_machine=m68030-sony
+				os=newsos
+				;;
+			necv70)
+				basic_machine=v70-nec
+				os=sysv
+				;;
+			nh3000)
+				basic_machine=m68k-harris
+				os=cxux
+				;;
+			nh[45]000)
+				basic_machine=m88k-harris
+				os=cxux
+				;;
+			nindy960)
+				basic_machine=i960-intel
+				os=nindy
+				;;
+			mon960)
+				basic_machine=i960-intel
+				os=mon960
+				;;
+			nonstopux)
+				basic_machine=mips-compaq
+				os=nonstopux
+				;;
+			os400)
+				basic_machine=powerpc-ibm
+				os=os400
+				;;
+			OSE68000 | ose68000)
+				basic_machine=m68000-ericsson
+				os=ose
+				;;
+			os68k)
+				basic_machine=m68k-none
+				os=os68k
+				;;
+			paragon)
+				basic_machine=i860-intel
+				os=osf
+				;;
+			parisc)
+				basic_machine=hppa-unknown
+				os=linux
+				;;
+			pw32)
+				basic_machine=i586-unknown
+				os=pw32
+				;;
+			rdos | rdos64)
+				basic_machine=x86_64-pc
+				os=rdos
+				;;
+			rdos32)
+				basic_machine=i386-pc
+				os=rdos
+				;;
+			rom68k)
+				basic_machine=m68k-rom68k
+				os=coff
+				;;
+			sa29200)
+				basic_machine=a29k-amd
+				os=udi
+				;;
+			sei)
+				basic_machine=mips-sei
+				os=seiux
+				;;
+			sequent)
+				basic_machine=i386-sequent
+				os=
+				;;
+			sps7)
+				basic_machine=m68k-bull
+				os=sysv2
+				;;
+			st2000)
+				basic_machine=m68k-tandem
+				os=
+				;;
+			stratus)
+				basic_machine=i860-stratus
+				os=sysv4
+				;;
+			sun2)
+				basic_machine=m68000-sun
+				os=
+				;;
+			sun2os3)
+				basic_machine=m68000-sun
+				os=sunos3
+				;;
+			sun2os4)
+				basic_machine=m68000-sun
+				os=sunos4
+				;;
+			sun3)
+				basic_machine=m68k-sun
+				os=
+				;;
+			sun3os3)
+				basic_machine=m68k-sun
+				os=sunos3
+				;;
+			sun3os4)
+				basic_machine=m68k-sun
+				os=sunos4
+				;;
+			sun4)
+				basic_machine=sparc-sun
+				os=
+				;;
+			sun4os3)
+				basic_machine=sparc-sun
+				os=sunos3
+				;;
+			sun4os4)
+				basic_machine=sparc-sun
+				os=sunos4
+				;;
+			sun4sol2)
+				basic_machine=sparc-sun
+				os=solaris2
+				;;
+			sun386 | sun386i | roadrunner)
+				basic_machine=i386-sun
+				os=
+				;;
+			sv1)
+				basic_machine=sv1-cray
+				os=unicos
+				;;
+			symmetry)
+				basic_machine=i386-sequent
+				os=dynix
+				;;
+			t3e)
+				basic_machine=alphaev5-cray
+				os=unicos
+				;;
+			t90)
+				basic_machine=t90-cray
+				os=unicos
+				;;
+			toad1)
+				basic_machine=pdp10-xkl
+				os=tops20
+				;;
+			tpf)
+				basic_machine=s390x-ibm
+				os=tpf
+				;;
+			udi29k)
+				basic_machine=a29k-amd
+				os=udi
+				;;
+			ultra3)
+				basic_machine=a29k-nyu
+				os=sym1
+				;;
+			v810 | necv810)
+				basic_machine=v810-nec
+				os=none
+				;;
+			vaxv)
+				basic_machine=vax-dec
+				os=sysv
+				;;
+			vms)
+				basic_machine=vax-dec
+				os=vms
+				;;
+			vsta)
+				basic_machine=i386-pc
+				os=vsta
+				;;
+			vxworks960)
+				basic_machine=i960-wrs
+				os=vxworks
+				;;
+			vxworks68)
+				basic_machine=m68k-wrs
+				os=vxworks
+				;;
+			vxworks29k)
+				basic_machine=a29k-wrs
+				os=vxworks
+				;;
+			xbox)
+				basic_machine=i686-pc
+				os=mingw32
+				;;
+			ymp)
+				basic_machine=ymp-cray
+				os=unicos
+				;;
+			*)
+				basic_machine=$1
+				os=
+				;;
+		esac
+		;;
+esac
+
+# Decode 1-component or ad-hoc basic machines
+case $basic_machine in
+	# Here we handle the default manufacturer of certain CPU types.  It is in
+	# some cases the only manufacturer, in others, it is the most popular.
+	w89k)
+		cpu=hppa1.1
+		vendor=winbond
+		;;
+	op50n)
+		cpu=hppa1.1
+		vendor=oki
+		;;
+	op60c)
+		cpu=hppa1.1
+		vendor=oki
+		;;
+	ibm*)
+		cpu=i370
+		vendor=ibm
+		;;
+	orion105)
+		cpu=clipper
+		vendor=highlevel
+		;;
+	mac | mpw | mac-mpw)
+		cpu=m68k
+		vendor=apple
+		;;
+	pmac | pmac-mpw)
+		cpu=powerpc
+		vendor=apple
+		;;
+
+	# Recognize the various machine names and aliases which stand
+	# for a CPU type and a company and sometimes even an OS.
+	3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
+		cpu=m68000
+		vendor=att
+		;;
+	3b*)
+		cpu=we32k
+		vendor=att
+		;;
+	bluegene*)
+		cpu=powerpc
+		vendor=ibm
+		os=cnk
+		;;
+	decsystem10* | dec10*)
+		cpu=pdp10
+		vendor=dec
+		os=tops10
+		;;
+	decsystem20* | dec20*)
+		cpu=pdp10
+		vendor=dec
+		os=tops20
+		;;
+	delta | 3300 | motorola-3300 | motorola-delta \
+	      | 3300-motorola | delta-motorola)
+		cpu=m68k
+		vendor=motorola
+		;;
+	dpx2*)
+		cpu=m68k
+		vendor=bull
+		os=sysv3
+		;;
+	encore | umax | mmax)
+		cpu=ns32k
+		vendor=encore
+		;;
+	elxsi)
+		cpu=elxsi
+		vendor=elxsi
+		os=${os:-bsd}
+		;;
+	fx2800)
+		cpu=i860
+		vendor=alliant
+		;;
+	genix)
+		cpu=ns32k
+		vendor=ns
+		;;
+	h3050r* | hiux*)
+		cpu=hppa1.1
+		vendor=hitachi
+		os=hiuxwe2
+		;;
+	hp3k9[0-9][0-9] | hp9[0-9][0-9])
+		cpu=hppa1.0
+		vendor=hp
+		;;
+	hp9k2[0-9][0-9] | hp9k31[0-9])
+		cpu=m68000
+		vendor=hp
+		;;
+	hp9k3[2-9][0-9])
+		cpu=m68k
+		vendor=hp
+		;;
+	hp9k6[0-9][0-9] | hp6[0-9][0-9])
+		cpu=hppa1.0
+		vendor=hp
+		;;
+	hp9k7[0-79][0-9] | hp7[0-79][0-9])
+		cpu=hppa1.1
+		vendor=hp
+		;;
+	hp9k78[0-9] | hp78[0-9])
+		# FIXME: really hppa2.0-hp
+		cpu=hppa1.1
+		vendor=hp
+		;;
+	hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
+		# FIXME: really hppa2.0-hp
+		cpu=hppa1.1
+		vendor=hp
+		;;
+	hp9k8[0-9][13679] | hp8[0-9][13679])
+		cpu=hppa1.1
+		vendor=hp
+		;;
+	hp9k8[0-9][0-9] | hp8[0-9][0-9])
+		cpu=hppa1.0
+		vendor=hp
+		;;
+	i*86v32)
+		cpu=`echo "$1" | sed -e 's/86.*/86/'`
+		vendor=pc
+		os=sysv32
+		;;
+	i*86v4*)
+		cpu=`echo "$1" | sed -e 's/86.*/86/'`
+		vendor=pc
+		os=sysv4
+		;;
+	i*86v)
+		cpu=`echo "$1" | sed -e 's/86.*/86/'`
+		vendor=pc
+		os=sysv
+		;;
+	i*86sol2)
+		cpu=`echo "$1" | sed -e 's/86.*/86/'`
+		vendor=pc
+		os=solaris2
+		;;
+	j90 | j90-cray)
+		cpu=j90
+		vendor=cray
+		os=${os:-unicos}
+		;;
+	iris | iris4d)
+		cpu=mips
+		vendor=sgi
+		case $os in
+		    irix*)
+			;;
+		    *)
+			os=irix4
+			;;
+		esac
+		;;
+	miniframe)
+		cpu=m68000
+		vendor=convergent
+		;;
+	*mint | mint[0-9]* | *MiNT | *MiNT[0-9]*)
+		cpu=m68k
+		vendor=atari
+		os=mint
+		;;
+	news-3600 | risc-news)
+		cpu=mips
+		vendor=sony
+		os=newsos
+		;;
+	next | m*-next)
+		cpu=m68k
+		vendor=next
+		case $os in
+		    openstep*)
+		        ;;
+		    nextstep*)
+			;;
+		    ns2*)
+		      os=nextstep2
+			;;
+		    *)
+		      os=nextstep3
+			;;
+		esac
+		;;
+	np1)
+		cpu=np1
+		vendor=gould
+		;;
+	op50n-* | op60c-*)
+		cpu=hppa1.1
+		vendor=oki
+		os=proelf
+		;;
+	pa-hitachi)
+		cpu=hppa1.1
+		vendor=hitachi
+		os=hiuxwe2
+		;;
+	pbd)
+		cpu=sparc
+		vendor=tti
+		;;
+	pbb)
+		cpu=m68k
+		vendor=tti
+		;;
+	pc532)
+		cpu=ns32k
+		vendor=pc532
+		;;
+	pn)
+		cpu=pn
+		vendor=gould
+		;;
+	power)
+		cpu=power
+		vendor=ibm
+		;;
+	ps2)
+		cpu=i386
+		vendor=ibm
+		;;
+	rm[46]00)
+		cpu=mips
+		vendor=siemens
+		;;
+	rtpc | rtpc-*)
+		cpu=romp
+		vendor=ibm
+		;;
+	sde)
+		cpu=mipsisa32
+		vendor=sde
+		os=${os:-elf}
+		;;
+	simso-wrs)
+		cpu=sparclite
+		vendor=wrs
+		os=vxworks
+		;;
+	tower | tower-32)
+		cpu=m68k
+		vendor=ncr
+		;;
+	vpp*|vx|vx-*)
+		cpu=f301
+		vendor=fujitsu
+		;;
+	w65)
+		cpu=w65
+		vendor=wdc
+		;;
+	w89k-*)
+		cpu=hppa1.1
+		vendor=winbond
+		os=proelf
+		;;
+	none)
+		cpu=none
+		vendor=none
+		;;
+	leon|leon[3-9])
+		cpu=sparc
+		vendor=$basic_machine
+		;;
+	leon-*|leon[3-9]-*)
+		cpu=sparc
+		vendor=`echo "$basic_machine" | sed 's/-.*//'`
+		;;
+
+	*-*)
+		# shellcheck disable=SC2162
+		IFS="-" read cpu vendor <<EOF
+$basic_machine
+EOF
+		;;
+	# We use `pc' rather than `unknown'
+	# because (1) that's what they normally are, and
+	# (2) the word "unknown" tends to confuse beginning users.
+	i*86 | x86_64)
+		cpu=$basic_machine
+		vendor=pc
+		;;
+	# These rules are duplicated from below for sake of the special case above;
+	# i.e. things that normalized to x86 arches should also default to "pc"
+	pc98)
+		cpu=i386
+		vendor=pc
+		;;
+	x64 | amd64)
+		cpu=x86_64
+		vendor=pc
+		;;
+	# Recognize the basic CPU types without company name.
+	*)
+		cpu=$basic_machine
+		vendor=unknown
+		;;
+esac
+
+unset -v basic_machine
+
+# Decode basic machines in the full and proper CPU-Company form.
+case $cpu-$vendor in
+	# Here we handle the default manufacturer of certain CPU types in canonical form. It is in
+	# some cases the only manufacturer, in others, it is the most popular.
+	craynv-unknown)
+		vendor=cray
+		os=${os:-unicosmp}
+		;;
+	c90-unknown | c90-cray)
+		vendor=cray
+		os=${os:-unicos}
+		;;
+	fx80-unknown)
+		vendor=alliant
+		;;
+	romp-unknown)
+		vendor=ibm
+		;;
+	mmix-unknown)
+		vendor=knuth
+		;;
+	microblaze-unknown | microblazeel-unknown)
+		vendor=xilinx
+		;;
+	rs6000-unknown)
+		vendor=ibm
+		;;
+	vax-unknown)
+		vendor=dec
+		;;
+	pdp11-unknown)
+		vendor=dec
+		;;
+	we32k-unknown)
+		vendor=att
+		;;
+	cydra-unknown)
+		vendor=cydrome
+		;;
+	i370-ibm*)
+		vendor=ibm
+		;;
+	orion-unknown)
+		vendor=highlevel
+		;;
+	xps-unknown | xps100-unknown)
+		cpu=xps100
+		vendor=honeywell
+		;;
+
+	# Here we normalize CPU types with a missing or matching vendor
+	dpx20-unknown | dpx20-bull)
+		cpu=rs6000
+		vendor=bull
+		os=${os:-bosx}
+		;;
+
+	# Here we normalize CPU types irrespective of the vendor
+	amd64-*)
+		cpu=x86_64
+		;;
+	blackfin-*)
+		cpu=bfin
+		os=linux
+		;;
+	c54x-*)
+		cpu=tic54x
+		;;
+	c55x-*)
+		cpu=tic55x
+		;;
+	c6x-*)
+		cpu=tic6x
+		;;
+	e500v[12]-*)
+		cpu=powerpc
+		os=$os"spe"
+		;;
+	mips3*-*)
+		cpu=mips64
+		;;
+	ms1-*)
+		cpu=mt
+		;;
+	m68knommu-*)
+		cpu=m68k
+		os=linux
+		;;
+	m9s12z-* | m68hcs12z-* | hcs12z-* | s12z-*)
+		cpu=s12z
+		;;
+	openrisc-*)
+		cpu=or32
+		;;
+	parisc-*)
+		cpu=hppa
+		os=linux
+		;;
+	pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
+		cpu=i586
+		;;
+	pentiumpro-* | p6-* | 6x86-* | athlon-* | athalon_*-*)
+		cpu=i686
+		;;
+	pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
+		cpu=i686
+		;;
+	pentium4-*)
+		cpu=i786
+		;;
+	pc98-*)
+		cpu=i386
+		;;
+	ppc-* | ppcbe-*)
+		cpu=powerpc
+		;;
+	ppcle-* | powerpclittle-*)
+		cpu=powerpcle
+		;;
+	ppc64-*)
+		cpu=powerpc64
+		;;
+	ppc64le-* | powerpc64little-*)
+		cpu=powerpc64le
+		;;
+	sb1-*)
+		cpu=mipsisa64sb1
+		;;
+	sb1el-*)
+		cpu=mipsisa64sb1el
+		;;
+	sh5e[lb]-*)
+		cpu=`echo "$cpu" | sed 's/^\(sh.\)e\(.\)$/\1\2e/'`
+		;;
+	spur-*)
+		cpu=spur
+		;;
+	strongarm-* | thumb-*)
+		cpu=arm
+		;;
+	tx39-*)
+		cpu=mipstx39
+		;;
+	tx39el-*)
+		cpu=mipstx39el
+		;;
+	x64-*)
+		cpu=x86_64
+		;;
+	xscale-* | xscalee[bl]-*)
+		cpu=`echo "$cpu" | sed 's/^xscale/arm/'`
+		;;
+
+	# Recognize the canonical CPU Types that limit and/or modify the
+	# company names they are paired with.
+	cr16-*)
+		os=${os:-elf}
+		;;
+	crisv32-* | etraxfs*-*)
+		cpu=crisv32
+		vendor=axis
+		;;
+	cris-* | etrax*-*)
+		cpu=cris
+		vendor=axis
+		;;
+	crx-*)
+		os=${os:-elf}
+		;;
+	neo-tandem)
+		cpu=neo
+		vendor=tandem
+		;;
+	nse-tandem)
+		cpu=nse
+		vendor=tandem
+		;;
+	nsr-tandem)
+		cpu=nsr
+		vendor=tandem
+		;;
+	nsv-tandem)
+		cpu=nsv
+		vendor=tandem
+		;;
+	nsx-tandem)
+		cpu=nsx
+		vendor=tandem
+		;;
+	s390-*)
+		cpu=s390
+		vendor=ibm
+		;;
+	s390x-*)
+		cpu=s390x
+		vendor=ibm
+		;;
+	tile*-*)
+		os=${os:-linux-gnu}
+		;;
+
+	*)
+		# Recognize the canonical CPU types that are allowed with any
+		# company name.
+		case $cpu in
+			1750a | 580 \
+			| a29k \
+			| aarch64 | aarch64_be \
+			| abacus \
+			| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] \
+			| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] \
+			| alphapca5[67] | alpha64pca5[67] \
+			| am33_2.0 \
+			| amdgcn \
+			| arc | arceb \
+			| arm  | arm[lb]e | arme[lb] | armv* \
+			| avr | avr32 \
+			| asmjs \
+			| ba \
+			| be32 | be64 \
+			| bfin | bpf | bs2000 \
+			| c[123]* | c30 | [cjt]90 | c4x \
+			| c8051 | clipper | craynv | csky | cydra \
+			| d10v | d30v | dlx | dsp16xx \
+			| e2k | elxsi | epiphany \
+			| f30[01] | f700 | fido | fr30 | frv | ft32 | fx80 \
+			| h8300 | h8500 \
+			| hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
+			| hexagon \
+			| i370 | i*86 | i860 | i960 | ia16 | ia64 \
+			| ip2k | iq2000 \
+			| k1om \
+			| le32 | le64 \
+			| lm32 \
+			| m32c | m32r | m32rle \
+			| m5200 | m68000 | m680[012346]0 | m68360 | m683?2 | m68k \
+			| m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x \
+			| m88110 | m88k | maxq | mb | mcore | mep | metag \
+			| microblaze | microblazeel \
+			| mips | mipsbe | mipseb | mipsel | mipsle \
+			| mips16 \
+			| mips64 | mips64eb | mips64el \
+			| mips64octeon | mips64octeonel \
+			| mips64orion | mips64orionel \
+			| mips64r5900 | mips64r5900el \
+			| mips64vr | mips64vrel \
+			| mips64vr4100 | mips64vr4100el \
+			| mips64vr4300 | mips64vr4300el \
+			| mips64vr5000 | mips64vr5000el \
+			| mips64vr5900 | mips64vr5900el \
+			| mipsisa32 | mipsisa32el \
+			| mipsisa32r2 | mipsisa32r2el \
+			| mipsisa32r6 | mipsisa32r6el \
+			| mipsisa64 | mipsisa64el \
+			| mipsisa64r2 | mipsisa64r2el \
+			| mipsisa64r6 | mipsisa64r6el \
+			| mipsisa64sb1 | mipsisa64sb1el \
+			| mipsisa64sr71k | mipsisa64sr71kel \
+			| mipsr5900 | mipsr5900el \
+			| mipstx39 | mipstx39el \
+			| mmix \
+			| mn10200 | mn10300 \
+			| moxie \
+			| mt \
+			| msp430 \
+			| nds32 | nds32le | nds32be \
+			| nfp \
+			| nios | nios2 | nios2eb | nios2el \
+			| none | np1 | ns16k | ns32k | nvptx \
+			| open8 \
+			| or1k* \
+			| or32 \
+			| orion \
+			| picochip \
+			| pdp10 | pdp11 | pj | pjl | pn | power \
+			| powerpc | powerpc64 | powerpc64le | powerpcle | powerpcspe \
+			| pru \
+			| pyramid \
+			| riscv | riscv32 | riscv64 \
+			| rl78 | romp | rs6000 | rx \
+			| score \
+			| sh | shl \
+			| sh[1234] | sh[24]a | sh[24]ae[lb] | sh[23]e | she[lb] | sh[lb]e \
+			| sh[1234]e[lb] |  sh[12345][lb]e | sh[23]ele | sh64 | sh64le \
+			| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet \
+			| sparclite \
+			| sparcv8 | sparcv9 | sparcv9b | sparcv9v | sv1 | sx* \
+			| spu \
+			| tahoe \
+			| tic30 | tic4x | tic54x | tic55x | tic6x | tic80 \
+			| tron \
+			| ubicom32 \
+			| v70 | v850 | v850e | v850e1 | v850es | v850e2 | v850e2v3 \
+			| vax \
+			| visium \
+			| w65 \
+			| wasm32 | wasm64 \
+			| we32k \
+			| x86 | x86_64 | xc16x | xgate | xps100 \
+			| xstormy16 | xtensa* \
+			| ymp \
+			| z8k | z80)
+				;;
+
+			*)
+				echo Invalid configuration \`"$1"\': machine \`"$cpu-$vendor"\' not recognized 1>&2
+				exit 1
+				;;
+		esac
+		;;
+esac
+
+# Here we canonicalize certain aliases for manufacturers.
+case $vendor in
+	digital*)
+		vendor=dec
+		;;
+	commodore*)
+		vendor=cbm
+		;;
+	*)
+		;;
+esac
+
+# Decode manufacturer-specific aliases for certain operating systems.
+
+if [ x$os != x ]
+then
+case $os in
+	# First match some system type aliases that might get confused
+	# with valid system types.
+	# solaris* is a basic system type, with this one exception.
+	auroraux)
+		os=auroraux
+		;;
+	bluegene*)
+		os=cnk
+		;;
+	solaris1 | solaris1.*)
+		os=`echo $os | sed -e 's|solaris1|sunos4|'`
+		;;
+	solaris)
+		os=solaris2
+		;;
+	unixware*)
+		os=sysv4.2uw
+		;;
+	gnu/linux*)
+		os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
+		;;
+	# es1800 is here to avoid being matched by es* (a different OS)
+	es1800*)
+		os=ose
+		;;
+	# Some version numbers need modification
+	chorusos*)
+		os=chorusos
+		;;
+	isc)
+		os=isc2.2
+		;;
+	sco6)
+		os=sco5v6
+		;;
+	sco5)
+		os=sco3.2v5
+		;;
+	sco4)
+		os=sco3.2v4
+		;;
+	sco3.2.[4-9]*)
+		os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
+		;;
+	sco3.2v[4-9]* | sco5v6*)
+		# Don't forget version if it is 3.2v4 or newer.
+		;;
+	scout)
+		# Don't match below
+		;;
+	sco*)
+		os=sco3.2v2
+		;;
+	psos*)
+		os=psos
+		;;
+	# Now accept the basic system types.
+	# The portable systems comes first.
+	# Each alternative MUST end in a * to match a version number.
+	# sysv* is not here because it comes later, after sysvr4.
+	gnu* | bsd* | mach* | minix* | genix* | ultrix* | irix* \
+	     | *vms* | esix* | aix* | cnk* | sunos | sunos[34]*\
+	     | hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \
+	     | sym* | kopensolaris* | plan9* \
+	     | amigaos* | amigados* | msdos* | newsos* | unicos* | aof* \
+	     | aos* | aros* | cloudabi* | sortix* | twizzler* \
+	     | nindy* | vxsim* | vxworks* | ebmon* | hms* | mvs* \
+	     | clix* | riscos* | uniplus* | iris* | isc* | rtu* | xenix* \
+	     | knetbsd* | mirbsd* | netbsd* \
+	     | bitrig* | openbsd* | solidbsd* | libertybsd* | os108* \
+	     | ekkobsd* | kfreebsd* | freebsd* | riscix* | lynxos* \
+	     | bosx* | nextstep* | cxux* | aout* | elf* | oabi* \
+	     | ptx* | coff* | ecoff* | winnt* | domain* | vsta* \
+	     | udi* | eabi* | lites* | ieee* | go32* | aux* | hcos* \
+	     | chorusrdb* | cegcc* | glidix* \
+	     | cygwin* | msys* | pe* | moss* | proelf* | rtems* \
+	     | midipix* | mingw32* | mingw64* | linux-gnu* | linux-android* \
+	     | linux-newlib* | linux-musl* | linux-uclibc* \
+	     | uxpv* | beos* | mpeix* | udk* | moxiebox* \
+	     | interix* | uwin* | mks* | rhapsody* | darwin* \
+	     | openstep* | oskit* | conix* | pw32* | nonstopux* \
+	     | storm-chaos* | tops10* | tenex* | tops20* | its* \
+	     | os2* | vos* | palmos* | uclinux* | nucleus* \
+	     | morphos* | superux* | rtmk* | windiss* \
+	     | powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \
+	     | skyos* | haiku* | rdos* | toppers* | drops* | es* \
+	     | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
+	     | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
+	     | nsk* | powerunix)
+	# Remember, each alternative MUST END IN *, to match a version number.
+		;;
+	qnx*)
+		case $cpu in
+		    x86 | i*86)
+			;;
+		    *)
+			os=nto-$os
+			;;
+		esac
+		;;
+	hiux*)
+		os=hiuxwe2
+		;;
+	nto-qnx*)
+		;;
+	nto*)
+		os=`echo $os | sed -e 's|nto|nto-qnx|'`
+		;;
+	sim | xray | os68k* | v88r* \
+	    | windows* | osx | abug | netware* | os9* \
+	    | macos* | mpw* | magic* | mmixware* | mon960* | lnews*)
+		;;
+	linux-dietlibc)
+		os=linux-dietlibc
+		;;
+	linux*)
+		os=`echo $os | sed -e 's|linux|linux-gnu|'`
+		;;
+	lynx*178)
+		os=lynxos178
+		;;
+	lynx*5)
+		os=lynxos5
+		;;
+	lynx*)
+		os=lynxos
+		;;
+	mac*)
+		os=`echo "$os" | sed -e 's|mac|macos|'`
+		;;
+	opened*)
+		os=openedition
+		;;
+	os400*)
+		os=os400
+		;;
+	sunos5*)
+		os=`echo "$os" | sed -e 's|sunos5|solaris2|'`
+		;;
+	sunos6*)
+		os=`echo "$os" | sed -e 's|sunos6|solaris3|'`
+		;;
+	wince*)
+		os=wince
+		;;
+	utek*)
+		os=bsd
+		;;
+	dynix*)
+		os=bsd
+		;;
+	acis*)
+		os=aos
+		;;
+	atheos*)
+		os=atheos
+		;;
+	syllable*)
+		os=syllable
+		;;
+	386bsd)
+		os=bsd
+		;;
+	ctix* | uts*)
+		os=sysv
+		;;
+	nova*)
+		os=rtmk-nova
+		;;
+	ns2)
+		os=nextstep2
+		;;
+	# Preserve the version number of sinix5.
+	sinix5.*)
+		os=`echo $os | sed -e 's|sinix|sysv|'`
+		;;
+	sinix*)
+		os=sysv4
+		;;
+	tpf*)
+		os=tpf
+		;;
+	triton*)
+		os=sysv3
+		;;
+	oss*)
+		os=sysv3
+		;;
+	svr4*)
+		os=sysv4
+		;;
+	svr3)
+		os=sysv3
+		;;
+	sysvr4)
+		os=sysv4
+		;;
+	# This must come after sysvr4.
+	sysv*)
+		;;
+	ose*)
+		os=ose
+		;;
+	*mint | mint[0-9]* | *MiNT | MiNT[0-9]*)
+		os=mint
+		;;
+	zvmoe)
+		os=zvmoe
+		;;
+	dicos*)
+		os=dicos
+		;;
+	pikeos*)
+		# Until real need of OS specific support for
+		# particular features comes up, bare metal
+		# configurations are quite functional.
+		case $cpu in
+		    arm*)
+			os=eabi
+			;;
+		    *)
+			os=elf
+			;;
+		esac
+		;;
+	nacl*)
+		;;
+	ios)
+		;;
+	none)
+		;;
+	*-eabi)
+		;;
+	*)
+		echo Invalid configuration \`"$1"\': system \`"$os"\' not recognized 1>&2
+		exit 1
+		;;
+esac
+else
+
+# Here we handle the default operating systems that come with various machines.
+# The value should be what the vendor currently ships out the door with their
+# machine or put another way, the most popular os provided with the machine.
+
+# Note that if you're going to try to match "-MANUFACTURER" here (say,
+# "-sun"), then you have to tell the case statement up towards the top
+# that MANUFACTURER isn't an operating system.  Otherwise, code above
+# will signal an error saying that MANUFACTURER isn't an operating
+# system, and we'll never get to this point.
+
+case $cpu-$vendor in
+	score-*)
+		os=elf
+		;;
+	spu-*)
+		os=elf
+		;;
+	*-acorn)
+		os=riscix1.2
+		;;
+	arm*-rebel)
+		os=linux
+		;;
+	arm*-semi)
+		os=aout
+		;;
+	c4x-* | tic4x-*)
+		os=coff
+		;;
+	c8051-*)
+		os=elf
+		;;
+	clipper-intergraph)
+		os=clix
+		;;
+	hexagon-*)
+		os=elf
+		;;
+	tic54x-*)
+		os=coff
+		;;
+	tic55x-*)
+		os=coff
+		;;
+	tic6x-*)
+		os=coff
+		;;
+	# This must come before the *-dec entry.
+	pdp10-*)
+		os=tops20
+		;;
+	pdp11-*)
+		os=none
+		;;
+	*-dec | vax-*)
+		os=ultrix4.2
+		;;
+	m68*-apollo)
+		os=domain
+		;;
+	i386-sun)
+		os=sunos4.0.2
+		;;
+	m68000-sun)
+		os=sunos3
+		;;
+	m68*-cisco)
+		os=aout
+		;;
+	mep-*)
+		os=elf
+		;;
+	mips*-cisco)
+		os=elf
+		;;
+	mips*-*)
+		os=elf
+		;;
+	or32-*)
+		os=coff
+		;;
+	*-tti)	# must be before sparc entry or we get the wrong os.
+		os=sysv3
+		;;
+	sparc-* | *-sun)
+		os=sunos4.1.1
+		;;
+	pru-*)
+		os=elf
+		;;
+	*-be)
+		os=beos
+		;;
+	*-ibm)
+		os=aix
+		;;
+	*-knuth)
+		os=mmixware
+		;;
+	*-wec)
+		os=proelf
+		;;
+	*-winbond)
+		os=proelf
+		;;
+	*-oki)
+		os=proelf
+		;;
+	*-hp)
+		os=hpux
+		;;
+	*-hitachi)
+		os=hiux
+		;;
+	i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
+		os=sysv
+		;;
+	*-cbm)
+		os=amigaos
+		;;
+	*-dg)
+		os=dgux
+		;;
+	*-dolphin)
+		os=sysv3
+		;;
+	m68k-ccur)
+		os=rtu
+		;;
+	m88k-omron*)
+		os=luna
+		;;
+	*-next)
+		os=nextstep
+		;;
+	*-sequent)
+		os=ptx
+		;;
+	*-crds)
+		os=unos
+		;;
+	*-ns)
+		os=genix
+		;;
+	i370-*)
+		os=mvs
+		;;
+	*-gould)
+		os=sysv
+		;;
+	*-highlevel)
+		os=bsd
+		;;
+	*-encore)
+		os=bsd
+		;;
+	*-sgi)
+		os=irix
+		;;
+	*-siemens)
+		os=sysv4
+		;;
+	*-masscomp)
+		os=rtu
+		;;
+	f30[01]-fujitsu | f700-fujitsu)
+		os=uxpv
+		;;
+	*-rom68k)
+		os=coff
+		;;
+	*-*bug)
+		os=coff
+		;;
+	*-apple)
+		os=macos
+		;;
+	*-atari*)
+		os=mint
+		;;
+	*-wrs)
+		os=vxworks
+		;;
+	*)
+		os=none
+		;;
+esac
+fi
+
+# Here we handle the case where we know the os, and the CPU type, but not the
+# manufacturer.  We pick the logical manufacturer.
+case $vendor in
+	unknown)
+		case $os in
+			riscix*)
+				vendor=acorn
+				;;
+			sunos*)
+				vendor=sun
+				;;
+			cnk*|-aix*)
+				vendor=ibm
+				;;
+			beos*)
+				vendor=be
+				;;
+			hpux*)
+				vendor=hp
+				;;
+			mpeix*)
+				vendor=hp
+				;;
+			hiux*)
+				vendor=hitachi
+				;;
+			unos*)
+				vendor=crds
+				;;
+			dgux*)
+				vendor=dg
+				;;
+			luna*)
+				vendor=omron
+				;;
+			genix*)
+				vendor=ns
+				;;
+			clix*)
+				vendor=intergraph
+				;;
+			mvs* | opened*)
+				vendor=ibm
+				;;
+			os400*)
+				vendor=ibm
+				;;
+			ptx*)
+				vendor=sequent
+				;;
+			tpf*)
+				vendor=ibm
+				;;
+			vxsim* | vxworks* | windiss*)
+				vendor=wrs
+				;;
+			aux*)
+				vendor=apple
+				;;
+			hms*)
+				vendor=hitachi
+				;;
+			mpw* | macos*)
+				vendor=apple
+				;;
+			*mint | mint[0-9]* | *MiNT | MiNT[0-9]*)
+				vendor=atari
+				;;
+			vos*)
+				vendor=stratus
+				;;
+		esac
+		;;
+esac
+
+echo "$cpu-$vendor-$os"
+exit
+
+# Local variables:
+# eval: (add-hook 'before-save-hook 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:
diff --git a/depcomp b/build-aux/depcomp
similarity index 99%
rename from depcomp
rename to build-aux/depcomp
index 65cbf70..6b39162 100755
--- a/depcomp
+++ b/build-aux/depcomp
@@ -3,7 +3,7 @@
 
 scriptversion=2018-03-07.03; # UTC
 
-# Copyright (C) 1999-2018 Free Software Foundation, Inc.
+# Copyright (C) 1999-2020 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
diff --git a/install-sh b/build-aux/install-sh
similarity index 97%
rename from install-sh
rename to build-aux/install-sh
index 8175c64..20d8b2e 100755
--- a/install-sh
+++ b/build-aux/install-sh
@@ -451,7 +451,18 @@
     trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
 
     # Copy the file name to the temp name.
-    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
+    (umask $cp_umask &&
+     { test -z "$stripcmd" || {
+	 # Create $dsttmp read-write so that cp doesn't create it read-only,
+	 # which would cause strip to fail.
+	 if test -z "$doit"; then
+	   : >"$dsttmp" # No need to fork-exec 'touch'.
+	 else
+	   $doit touch "$dsttmp"
+	 fi
+       }
+     } &&
+     $doit_exec $cpprog "$src" "$dsttmp") &&
 
     # and set any options; do chmod last to preserve setuid bits.
     #
diff --git a/ltmain.sh b/build-aux/ltmain.sh
similarity index 99%
rename from ltmain.sh
rename to build-aux/ltmain.sh
index d3ab94d..48cea9b 100644
--- a/ltmain.sh
+++ b/build-aux/ltmain.sh
@@ -2,7 +2,7 @@
 ## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
 ##               by inline-source v2018-07-24.06
 
-# libtool (GNU libtool) 2.4.6.42-b88ce
+# libtool (GNU libtool) 2.4.6.42-b88ce-dirty
 # Provide generalized library-building support services.
 # Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
 
@@ -31,7 +31,7 @@
 
 PROGRAM=libtool
 PACKAGE=libtool
-VERSION=2.4.6.42-b88ce
+VERSION=2.4.6.42-b88ce-dirty
 package_revision=2.4.6.42
 
 
@@ -2176,7 +2176,7 @@
 # End:
 
 # Set a version string.
-scriptversion='(GNU libtool) 2.4.6.42-b88ce'
+scriptversion='(GNU libtool) 2.4.6.42-b88ce-dirty'
 
 
 # func_echo ARG...
@@ -2267,7 +2267,7 @@
        compiler:       $LTCC
        compiler flags: $LTCFLAGS
        linker:         $LD (gnu? $with_gnu_ld)
-       version:        $progname (GNU libtool) 2.4.6.42-b88ce
+       version:        $progname (GNU libtool) 2.4.6.42-b88ce-dirty
        automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
        autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
 
diff --git a/missing b/build-aux/missing
similarity index 98%
rename from missing
rename to build-aux/missing
index 625aeb1..8d0eaad 100755
--- a/missing
+++ b/build-aux/missing
@@ -3,7 +3,7 @@
 
 scriptversion=2018-03-07.03; # UTC
 
-# Copyright (C) 1996-2018 Free Software Foundation, Inc.
+# Copyright (C) 1996-2020 Free Software Foundation, Inc.
 # Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
 
 # This program is free software; you can redistribute it and/or modify
diff --git a/test-driver b/build-aux/test-driver
similarity index 98%
rename from test-driver
rename to build-aux/test-driver
index b8521a4..89dba1e 100755
--- a/test-driver
+++ b/build-aux/test-driver
@@ -3,7 +3,7 @@
 
 scriptversion=2018-03-07.03; # UTC
 
-# Copyright (C) 2011-2018 Free Software Foundation, Inc.
+# Copyright (C) 2011-2020 Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
diff --git a/cmake/AddEventLibrary.cmake b/cmake/AddEventLibrary.cmake
index 352c86b..04f5837 100644
--- a/cmake/AddEventLibrary.cmake
+++ b/cmake/AddEventLibrary.cmake
@@ -35,6 +35,45 @@
     )
 endmacro()
 
+# LIB_NAME maybe event_core, event_extra, event_openssl, event_pthreads or event.
+# Targets whose LIB_NAME is not 'event' should be exported and installed.
+macro(export_install_target TYPE LIB_NAME OUTER_INCLUDES)
+    if("${LIB_NAME}" STREQUAL "event")
+        install(TARGETS "${LIB_NAME}_${TYPE}"
+            LIBRARY DESTINATION "lib" COMPONENT lib
+            ARCHIVE DESTINATION "lib" COMPONENT lib
+            RUNTIME DESTINATION "lib" COMPONENT lib
+            COMPONENT dev
+        )
+    else()
+        string(REPLACE "event_" "" PURE_NAME ${LIB_NAME})
+        string(TOUPPER ${TYPE} UPPER_TYPE)
+        list(APPEND LIBEVENT_${UPPER_TYPE}_LIBRARIES "${PURE_NAME}")
+        set(OUTER_INCS)
+        if (NOT "${OUTER_INCLUDES}" STREQUAL "NONE")
+            set(OUTER_INCS ${OUTER_INCLUDES})
+        endif()
+        target_include_directories("${LIB_NAME}_${TYPE}"
+            PUBLIC  "$<INSTALL_INTERFACE:include>"
+                    "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
+                    "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>"
+                    ${OUTER_INCS}
+        )
+        set_target_properties("${LIB_NAME}_${TYPE}" PROPERTIES EXPORT_NAME ${PURE_NAME})
+        export(TARGETS "${LIB_NAME}_${TYPE}"
+            NAMESPACE ${PROJECT_NAME}::
+            FILE "${PROJECT_BINARY_DIR}/LibeventTargets-${TYPE}.cmake"
+            APPEND
+        )
+        install(TARGETS "${LIB_NAME}_${TYPE}"
+            EXPORT LibeventTargets-${TYPE}
+            LIBRARY DESTINATION "lib" COMPONENT lib
+            ARCHIVE DESTINATION "lib" COMPONENT lib
+            RUNTIME DESTINATION "lib" COMPONENT lib
+            COMPONENT dev
+        )
+    endif()
+endmacro()
 
 # Global variables that it uses:
 # - EVENT_ABI_LIBVERSION
@@ -44,8 +83,6 @@
 # - EVENT_PACKAGE_RELEASE
 # - CMAKE_THREAD_LIBS_INIT LIB_PLATFORM
 # - OPENSSL_LIBRARIES
-# - HDR_PUBLIC
-# - EVENT_INSTALL_INCLUDE_DIR
 # - EVENT_SHARED_FLAGS
 # - EVENT_LIBRARY_STATIC
 # - EVENT_LIBRARY_SHARED
@@ -57,11 +94,13 @@
     cmake_parse_arguments(LIB
         "" # Options
         "VERSION" # One val
-        "SOURCES;LIBRARIES" # Multi val
+        "SOURCES;LIBRARIES;INNER_LIBRARIES;OUTER_INCLUDES" # Multi val
         ${ARGN}
     )
 
-    set(ADD_EVENT_LIBRARY_TARGETS)
+    if ("${LIB_OUTER_INCLUDES}" STREQUAL "")
+        set(LIB_OUTER_INCLUDES NONE)
+    endif()
     set(ADD_EVENT_LIBRARY_INTERFACE)
 
     if (${EVENT_LIBRARY_STATIC})
@@ -69,12 +108,17 @@
         set_target_properties("${LIB_NAME}_static" PROPERTIES
             OUTPUT_NAME "${LIB_NAME}"
             CLEAN_DIRECT_OUTPUT 1)
-        set_target_properties(
-            "${LIB_NAME}_static" PROPERTIES
-            PUBLIC_HEADER "${HDR_PUBLIC}")
 
-        list(APPEND LIBEVENT_STATIC_LIBRARIES "${LIB_NAME}_static")
-        list(APPEND ADD_EVENT_LIBRARY_TARGETS "${LIB_NAME}_static")
+        if(LIB_INNER_LIBRARIES)
+            set(INNER_LIBRARIES "${LIB_INNER_LIBRARIES}_static")
+        endif()
+        target_link_libraries("${LIB_NAME}_static"
+            ${CMAKE_THREAD_LIBS_INIT}
+            ${LIB_PLATFORM}
+            ${INNER_LIBRARIES}
+            ${LIB_LIBRARIES})
+
+        export_install_target(static "${LIB_NAME}" "${LIB_OUTER_INCLUDES}")
 
         set(ADD_EVENT_LIBRARY_INTERFACE "${LIB_NAME}_static")
     endif()
@@ -82,9 +126,13 @@
     if (${EVENT_LIBRARY_SHARED})
         add_library("${LIB_NAME}_shared" SHARED ${LIB_SOURCES})
 
+        if(LIB_INNER_LIBRARIES)
+            set(INNER_LIBRARIES "${LIB_INNER_LIBRARIES}_shared")
+        endif()
         target_link_libraries("${LIB_NAME}_shared"
             ${CMAKE_THREAD_LIBS_INIT}
             ${LIB_PLATFORM}
+            ${INNER_LIBRARIES}
             ${LIB_LIBRARIES})
 
         if (EVENT_SHARED_FLAGS)
@@ -110,14 +158,10 @@
                 "${LIB_NAME}_shared" PROPERTIES
                 OUTPUT_NAME "${LIB_NAME}-${EVENT_PACKAGE_RELEASE}"
                 VERSION "${CURRENT_MINUS_AGE}.${EVENT_ABI_LIBVERSION_AGE}.${EVENT_ABI_LIBVERSION_REVISION}"
-                SOVERSION "${CURRENT_MINUS_AGE}")
+                SOVERSION "${CURRENT_MINUS_AGE}"
+                INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
         endif()
 
-        set_target_properties(
-            "${LIB_NAME}_shared" PROPERTIES
-            PUBLIC_HEADER "${HDR_PUBLIC}"
-            CLEAN_DIRECT_OUTPUT 1)
-
         if (NOT WIN32)
             set(LIB_LINK_NAME
                 "${CMAKE_SHARED_LIBRARY_PREFIX}${LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}")
@@ -127,33 +171,19 @@
                 COMMAND ${CMAKE_COMMAND} -E create_symlink
                     "$<TARGET_FILE_NAME:${LIB_NAME}_shared>"
                     "${LIB_LINK_NAME}"
-                WORKING_DIRECTORY "lib")
+                WORKING_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
         endif()
 
-        list(APPEND LIBEVENT_SHARED_LIBRARIES "${LIB_NAME}_shared")
-        list(APPEND ADD_EVENT_LIBRARY_TARGETS "${LIB_NAME}_shared")
+        export_install_target(shared "${LIB_NAME}" "${LIB_OUTER_INCLUDES}")
 
         set(ADD_EVENT_LIBRARY_INTERFACE "${LIB_NAME}_shared")
-    endif()
 
-    export(TARGETS ${ADD_EVENT_LIBRARY_TARGETS}
-       FILE "${PROJECT_BINARY_DIR}/LibeventTargets.cmake"
-       APPEND
-    )
-
-    install(TARGETS ${ADD_EVENT_LIBRARY_TARGETS}
-        EXPORT LibeventTargets
-        LIBRARY DESTINATION "lib" COMPONENT lib
-        ARCHIVE DESTINATION "lib" COMPONENT lib
-        RUNTIME DESTINATION "lib" COMPONENT lib
-        PUBLIC_HEADER DESTINATION "include/event2"
-        COMPONENT dev
-    )
-    if (NOT WIN32 AND ${EVENT_LIBRARY_SHARED})
-        install(FILES
-            "$<TARGET_FILE_DIR:${LIB_NAME}_shared>/${LIB_LINK_NAME}"
-            DESTINATION "lib"
-            COMPONENT lib)
+        if (NOT WIN32)
+            install(FILES
+                "$<TARGET_FILE_DIR:${LIB_NAME}_shared>/${LIB_LINK_NAME}"
+                DESTINATION "lib"
+                COMPONENT lib)
+        endif()
     endif()
 
     add_library(${LIB_NAME} INTERFACE)
diff --git a/cmake/CheckFunctionExistsEx.c b/cmake/CheckFunctionExistsEx.c
deleted file mode 100644
index 224e340..0000000
--- a/cmake/CheckFunctionExistsEx.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifdef CHECK_FUNCTION_EXISTS
-
-#ifdef __cplusplus
-extern "C"
-#endif
-  char
-  CHECK_FUNCTION_EXISTS(void);
-#ifdef __CLASSIC_C__
-int main()
-{
-  int ac;
-  char* av[];
-#else
-int main(int ac, char* av[])
-{
-#endif
-  CHECK_FUNCTION_EXISTS();
-  if (ac > 1000) {
-    return *av[0];
-  }
-  return 0;
-}
-
-#else /* CHECK_FUNCTION_EXISTS */
-
-#error "CHECK_FUNCTION_EXISTS has to specify the function"
-
-#endif /* CHECK_FUNCTION_EXISTS */
diff --git a/cmake/CheckFunctionExistsEx.cmake b/cmake/CheckFunctionExistsEx.cmake
deleted file mode 100644
index 78bc2ec..0000000
--- a/cmake/CheckFunctionExistsEx.cmake
+++ /dev/null
@@ -1,69 +0,0 @@
-# - Check if a C function can be linked
-# CHECK_FUNCTION_EXISTS(<function> <variable>)
-#
-# Check that the <function> is provided by libraries on the system and
-# store the result in a <variable>.  This does not verify that any
-# system header file declares the function, only that it can be found
-# at link time (considure using CheckSymbolExists).
-#
-# The following variables may be set before calling this macro to
-# modify the way the check is run:
-#
-#  CMAKE_REQUIRED_FLAGS = string of compile command line flags
-#  CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
-#  CMAKE_REQUIRED_INCLUDES = list of include directories
-#  CMAKE_REQUIRED_LIBRARIES = list of libraries to link
-
-#=============================================================================
-# Copyright 2002-2011 Kitware, Inc.
-#
-# Distributed under the OSI-approved BSD License (the "License");
-# see accompanying file Copyright.txt for details.
-#
-# This software is distributed WITHOUT ANY WARRANTY; without even the
-# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-# See the License for more information.
-#=============================================================================
-# (To distribute this file outside of CMake, substitute the full
-#  License text for the above reference.)
-
-MACRO(CHECK_FUNCTION_EXISTS_EX FUNCTION VARIABLE)
-  IF(${VARIABLE} MATCHES "^${VARIABLE}$")
-    SET(MACRO_CHECK_FUNCTION_DEFINITIONS 
-      "-DCHECK_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}")
-    MESSAGE(STATUS "Looking for ${FUNCTION}")
-    IF(CMAKE_REQUIRED_LIBRARIES)
-      SET(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES
-        "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
-    ELSE(CMAKE_REQUIRED_LIBRARIES)
-      SET(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES)
-    ENDIF(CMAKE_REQUIRED_LIBRARIES)
-    IF(CMAKE_REQUIRED_INCLUDES)
-      SET(CHECK_FUNCTION_EXISTS_ADD_INCLUDES
-        "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
-    ELSE(CMAKE_REQUIRED_INCLUDES)
-      SET(CHECK_FUNCTION_EXISTS_ADD_INCLUDES)
-    ENDIF(CMAKE_REQUIRED_INCLUDES)
-    TRY_COMPILE(${VARIABLE}
-      ${CMAKE_BINARY_DIR}
-	  ${PROJECT_SOURCE_DIR}/cmake/CheckFunctionExistsEx.c
-      COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
-      CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
-      "${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}"
-      "${CHECK_FUNCTION_EXISTS_ADD_INCLUDES}"
-      OUTPUT_VARIABLE OUTPUT)
-    IF(${VARIABLE})
-      SET(${VARIABLE} 1 CACHE INTERNAL "Have function ${FUNCTION}")
-      MESSAGE(STATUS "Looking for ${FUNCTION} - found")
-      FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 
-        "Determining if the function ${FUNCTION} exists passed with the following output:\n"
-        "${OUTPUT}\n\n")
-    ELSE(${VARIABLE})
-      MESSAGE(STATUS "Looking for ${FUNCTION} - not found")
-      SET(${VARIABLE} "" CACHE INTERNAL "Have function ${FUNCTION}")
-      FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 
-        "Determining if the function ${FUNCTION} exists failed with the following output:\n"
-        "${OUTPUT}\n\n")
-    ENDIF(${VARIABLE})
-  ENDIF()
-ENDMACRO(CHECK_FUNCTION_EXISTS_EX)
diff --git a/cmake/FindGit.cmake b/cmake/FindGit.cmake
deleted file mode 100644
index 2abbfe4..0000000
--- a/cmake/FindGit.cmake
+++ /dev/null
@@ -1,45 +0,0 @@
-# The module defines the following variables:
-#   GIT_EXECUTABLE - path to git command line client
-#   GIT_FOUND - true if the command line client was found
-# Example usage:
-#   find_package(Git)
-#   if(GIT_FOUND)
-#     message("git found: ${GIT_EXECUTABLE}")
-#   endif()
-
-#=============================================================================
-# Copyright 2010 Kitware, Inc.
-#
-# Distributed under the OSI-approved BSD License (the "License");
-# see accompanying file Copyright.txt for details.
-#
-# This software is distributed WITHOUT ANY WARRANTY; without even the
-# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-# See the License for more information.
-#=============================================================================
-# (To distributed this file outside of CMake, substitute the full
-#  License text for the above reference.)
-
-# Look for 'git' or 'eg' (easy git)
-set(git_names git eg)
-
-# Prefer .cmd variants on Windows unless running in a Makefile
-# in the MSYS shell.
-if(WIN32)
-  if(NOT CMAKE_GENERATOR MATCHES "MSYS")
-    set(git_names git.cmd git eg.cmd eg)
-  endif()
-endif()
-
-find_program(GIT_EXECUTABLE
-  NAMES ${git_names}
-  DOC "git command line client")
-
-mark_as_advanced(GIT_EXECUTABLE)
-
-# Handle the QUIETLY and REQUIRED arguments and set GIT_FOUND to TRUE if
-# all listed variables are TRUE
-
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(Git DEFAULT_MSG GIT_EXECUTABLE)
-
diff --git a/cmake/LibeventConfig.cmake.in b/cmake/LibeventConfig.cmake.in
index 5422336..7b808c3 100644
--- a/cmake/LibeventConfig.cmake.in
+++ b/cmake/LibeventConfig.cmake.in
@@ -1,18 +1,183 @@
 # - Config file for the Libevent package
 # It defines the following variables
-#  LIBEVENT_INCLUDE_DIRS     - include directories
+#  LIBEVENT_FOUND            - true if libevent and all required components found on the system
+#  LIBEVENT_xxx_FOUND        - true if component xxx(see available components) found on the system
+#  LIBEVENT_VERSION          - libevent version in format Major.Minor.Patch
+#  LIBEVENT_INCLUDE_DIRS     - directories where libevent header is located.
+#  LIBEVENT_INCLUDE_DIR      - same as DIRS
+#  LIBEVENT_LIBRARIES        - libevent library to link against.
+#  LIBEVENT_LIBRARY          - same as LIBRARIES
+#
+# These variables are deprecated, don't use them.
 #  LIBEVENT_STATIC_LIBRARIES - libraries to link against (archive/static)
 #  LIBEVENT_SHARED_LIBRARIES - libraries to link against (shared)
+#
+# When you try to locate the libevent libraries, you should specify which components you want to use.
+# The following table lists all available components. If none is given, all imported targets will used.
+#  core        - the core functons of libevent
+#  extra       - extra functions, contains http, dns and rpc
+#  pthreads    - multiple threads for libevent, not exists on Windows
+#  openssl     - openssl support for libevent
+#
+# By default, the shared libraries of libevent will be found. To find the static ones instead,
+# you must set the LIBEVENT_STATIC_LINK variable to TRUE before calling find_package(Libevent ...).
+# If no component provided, all components will be used.
+# example:
+#  set(LIBEVENT_STATIC_LINK TRUE)
+#  find_package(Libevent 2.2 REQUIRED COMPONENTS core)
+#  include_directories(${LIBEVENT_INCLUDE_DIRS})  # Can be omitted
+#  target_link_libraries(myapp ${LIBEVENT_LIBRARIES})
+#    or target_link_libraries(myapp libevent::core)
+#
+# find_package() can handle dependencies automatically. For example, given the 'openssl' component,
+# all dependencies (libevent_core, libssl, libcrypto and openssl include directories) will be found.
 
-# Get the path of the current file.
-get_filename_component(LIBEVENT_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
+set(CONFIG_FOR_INSTALL_TREE @CONFIG_FOR_INSTALL_TREE@)
 
-# Set the include directories.
-set(LIBEVENT_INCLUDE_DIRS "@EVENT_INSTALL_INCLUDE_DIR@")
-
-# Include the project Targets file, this contains definitions for IMPORTED targets.
-include(${LIBEVENT_CMAKE_DIR}/LibeventTargets.cmake)
+set(LIBEVENT_VERSION @EVENT_PACKAGE_VERSION@)
 
 # IMPORTED targets from LibeventTargets.cmake
 set(LIBEVENT_STATIC_LIBRARIES "@LIBEVENT_STATIC_LIBRARIES@")
 set(LIBEVENT_SHARED_LIBRARIES "@LIBEVENT_SHARED_LIBRARIES@")
+
+# Default to the same type as libevent was built:
+if(NOT DEFINED LIBEVENT_STATIC_LINK)
+    set(LIBEVENT_STATIC_LINK NOT @EVENT_LIBRARY_SHARED@)
+endif()
+
+set(CMAKE_FIND_LIBRARY_SUFFIXES_SAVE "${CMAKE_FIND_LIBRARY_SUFFIXES}")
+if(${LIBEVENT_STATIC_LINK})
+    set(_LIB_TYPE static)
+    set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
+    set(_AVAILABLE_LIBS "${LIBEVENT_STATIC_LIBRARIES}")
+else()
+    set(_LIB_TYPE shared)
+    set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
+    set(_AVAILABLE_LIBS "${LIBEVENT_SHARED_LIBRARIES}")
+endif()
+
+# Get the path of the current file.
+get_filename_component(LIBEVENT_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
+get_filename_component(_INSTALL_PREFIX "${LIBEVENT_CMAKE_DIR}/../../.." ABSOLUTE)
+
+macro(message_if_needed _flag _msg)
+    if (NOT ${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
+        message(${_flag} "${_msg}")
+    endif()
+endmacro()
+
+macro(no_component_msg _comp)
+    if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED_${_comp})
+        set(pthreadlib)
+        if(NOT WIN32)
+            set(pthreadlib ", pthreads")
+        endif()
+        message(FATAL_ERROR "Your libevent library does not contain a ${_comp} component!\n"
+                "The valid components are core, extra${pthreadlib} and openssl.")
+    else()
+        message_if_needed(WARNING "Your libevent library does not contain a ${_comp} component!")
+    endif()
+endmacro()
+
+set(_EVENT_COMPONENTS)
+if(${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
+    list(REMOVE_DUPLICATES ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
+    foreach(_comp ${${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS})
+        list(FIND _AVAILABLE_LIBS ${_comp} _INDEX)
+        if(_INDEX GREATER -1)
+            list(APPEND _EVENT_COMPONENTS ${_comp})
+        else()
+            no_component_msg(${_comp})
+        endif()
+    endforeach()
+else()
+    set(_EVENT_COMPONENTS ${_AVAILABLE_LIBS})
+endif()
+
+set(_POSSIBLE_PKG_NAMES)
+list(APPEND _POSSIBLE_PKG_NAMES ${CMAKE_FIND_PACKAGE_NAME} LIBEVENT Libevent libevent)
+list(REMOVE_DUPLICATES _POSSIBLE_PKG_NAMES)
+
+macro(set_case_insensitive_found _comp)
+    foreach(name ${_POSSIBLE_PKG_NAMES})
+        if("${_comp}" STREQUAL "")
+            set(${name}_FOUND TRUE)
+            set(${name}_NOTFOUND FALSE)
+        else()
+            set(${name}_${_comp}_FOUND TRUE)
+            set(${name}_${_comp}_NOTFOUND FALSE)
+        endif()
+    endforeach()
+endmacro()
+
+if(CONFIG_FOR_INSTALL_TREE)
+    ## Config for install tree ----------------------------------------
+    # Find includes
+    unset(_event_h CACHE)
+    find_path(_event_h
+              NAMES event2/event.h
+              PATHS "${_INSTALL_PREFIX}/include"
+              NO_DEFAULT_PATH)
+    if(_event_h)
+        set(LIBEVENT_INCLUDE_DIRS "${_event_h}")
+        message_if_needed(STATUS "Found libevent include directory: ${_event_h}")
+    else()
+        message_if_needed(WARNING "Your libevent library does not contain header files!")
+    endif()
+
+    # Find libraries
+    macro(find_event_lib _comp)
+        unset(_event_lib CACHE)
+        find_library(_event_lib
+                    NAMES "event_${_comp}"
+                    PATHS "${_INSTALL_PREFIX}/lib"
+                    NO_DEFAULT_PATH)
+        if(_event_lib)
+            list(APPEND LIBEVENT_LIBRARIES "libevent::${_comp}")
+            set_case_insensitive_found(${_comp})
+            message_if_needed(STATUS "Found libevent component: ${_event_lib}")
+        else()
+            no_component_msg(${_comp})
+        endif()
+    endmacro()
+
+    foreach(comp ${_EVENT_COMPONENTS})
+        find_event_lib(${comp})
+    endforeach()
+else()
+    ## Config for build tree ----------------------------------------
+    set(LIBEVENT_INCLUDE_DIRS "@EVENT__INCLUDE_DIRS@")
+    foreach(_comp ${_EVENT_COMPONENTS})
+        list(APPEND LIBEVENT_LIBRARIES "libevent::${_comp}")
+        set_case_insensitive_found(${_comp})
+    endforeach()
+endif()
+
+set(LIBEVENT_INCLUDE_DIR ${LIBEVENT_INCLUDE_DIRS})
+if(LIBEVENT_LIBRARIES)
+    set(LIBEVENT_LIBRARY ${LIBEVENT_LIBRARIES})
+    if(CONFIG_FOR_INSTALL_TREE)
+        message_if_needed(STATUS "Found libevent ${LIBEVENT_VERSION} in ${_INSTALL_PREFIX}")
+    else()
+        message_if_needed(STATUS "Found libevent ${LIBEVENT_VERSION} in ${LIBEVENT_CMAKE_DIR}")
+    endif()
+
+    # Avoid including targets more than one times
+    if(NOT TARGET event_core_${_LIB_TYPE})
+        # Include the project Targets file, this contains definitions for IMPORTED targets.
+        include(${LIBEVENT_CMAKE_DIR}/LibeventTargets-${_LIB_TYPE}.cmake)
+    endif()
+else()
+    if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
+        message(FATAL_ERROR "Can not find any libraries for libevent.")
+    else()
+        message_if_needed(WARNING "Can not find any libraries for libevent.")
+    endif()
+endif()
+
+set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES_SAVE}")
+unset(_LIB_TYPE)
+unset(_AVAILABLE_LIBS)
+unset(_EVENT_COMPONENTS)
+unset(_POSSIBLE_PKG_NAMES)
+unset(_INSTALL_PREFIX)
diff --git a/cmake/LibeventConfigBuildTree.cmake.in b/cmake/LibeventConfigBuildTree.cmake.in
deleted file mode 100644
index 02edef3..0000000
--- a/cmake/LibeventConfigBuildTree.cmake.in
+++ /dev/null
@@ -1,17 +0,0 @@
-# - Config file for the Libevent package
-# It defines the following variables
-#  LIBEVENT_INCLUDE_DIRS - include directories for FooBar
-#  LIBEVENT_LIBRARIES    - libraries to link against
-
-# Get the path of the current file.
-get_filename_component(LIBEVENT_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
-
-# Set the include directories.
-set(LIBEVENT_INCLUDE_DIRS "@EVENT__INCLUDE_DIRS@")
-
-# Include the project Targets file, this contains definitions for IMPORTED targets.
-include(${LIBEVENT_CMAKE_DIR}/LibeventTargets.cmake)
-
-# IMPORTED targets from LibeventTargets.cmake
-set(LIBEVENT_LIBRARIES event event_core event_extra)
-
diff --git a/cmake/Macros.cmake b/cmake/Macros.cmake
new file mode 100644
index 0000000..e480bbf
--- /dev/null
+++ b/cmake/Macros.cmake
@@ -0,0 +1,36 @@
+include(CheckSymbolExists)
+include(CheckIncludeFiles)
+
+# Check if each symbol in the symbol list exists,
+# and define PREFIX__HAVE_SYMNAME to 1 if yes.
+#
+# SYMLIST: list of symbols to check
+# HEADERS: header files to be included in check code
+# PREFIX: the prefix of definition
+macro(CHECK_SYMBOLS_EXIST SYMLIST HEADERS PREFIX)
+  foreach(SYMNAME ${SYMLIST})
+    string(TOUPPER "${SYMNAME}" SYMNAME_UPPER)
+    if ("${PREFIX}" STREQUAL "")
+      set(HAVE_SYM_DEF "HAVE_${SYMNAME_UPPER}")
+    else()
+      set(HAVE_SYM_DEF "${PREFIX}__HAVE_${SYMNAME_UPPER}")
+    endif()
+    CHECK_SYMBOL_EXISTS(${SYMNAME} "${HEADERS}" ${HAVE_SYM_DEF})
+  endforeach()
+endmacro()
+
+# Check if file exists, define PREFIX__HAVE_FILE to 1 if yes,
+# and collect file to EVENT_INCLUDES
+macro(CHECK_INCLUDE_FILE_CONCAT FILE PREFIX)
+  string(REGEX REPLACE "[./]" "_" FILE_UL ${FILE})
+  string(TOUPPER "${FILE_UL}" FILE_UL_UPPER)
+  if ("${PREFIX}" STREQUAL "")
+    set(HAVE_FILE_DEF "HAVE_${FILE_UL_UPPER}")
+  else()
+    set(HAVE_FILE_DEF "${PREFIX}__HAVE_${FILE_UL_UPPER}")
+  endif()
+  CHECK_INCLUDE_FILES("${EVENT_INCLUDES};${FILE}" ${HAVE_FILE_DEF})
+  if(${HAVE_FILE_DEF})
+    set(EVENT_INCLUDES ${EVENT_INCLUDES} ${FILE})
+  endif()
+endmacro()
diff --git a/cmake/Uninstall.cmake.in b/cmake/Uninstall.cmake.in
new file mode 100644
index 0000000..c6dc09e
--- /dev/null
+++ b/cmake/Uninstall.cmake.in
@@ -0,0 +1,23 @@
+# https://gitlab.kitware.com/cmake/community/wikis/FAQ#can-i-do-make-uninstall-with-cmake
+
+if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
+  message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
+endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
+
+file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
+string(REGEX REPLACE "\n" ";" files "${files}")
+foreach(file ${files})
+  message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
+  if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+    exec_program(
+      "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
+      OUTPUT_VARIABLE rm_out
+      RETURN_VALUE rm_retval
+      )
+    if(NOT "${rm_retval}" STREQUAL 0)
+      message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
+    endif(NOT "${rm_retval}" STREQUAL 0)
+  else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+    message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
+  endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+endforeach(file)
diff --git a/cmake/UseDoxygen.cmake b/cmake/UseDoxygen.cmake
new file mode 100644
index 0000000..3b60d5a
--- /dev/null
+++ b/cmake/UseDoxygen.cmake
@@ -0,0 +1,111 @@
+# Use FindDoxygen.cmake to generate documentation.
+
+option(DOXYGEN_GENERATE_HTML  "Generate HTML"      ON)
+option(DOXYGEN_GENERATE_MAN   "Generate man pages" OFF)
+option(DOXYGEN_MAN_LINKS      "Generate man links" ON)
+option(DOXYGEN_GENERATE_LATEX "Generate LaTeX"     OFF)
+
+# If the case-insensitive value of the cmake option is one of
+# "off, no, false" or 0, it is equal to false, otherwise true.
+# And the values of the doxygen config does not exactly match it.
+# So we need to convert the cmake option to a doxygen config.
+macro(_convert_to_dx_cfg CMK_OPTION)
+  if (${CMK_OPTION})
+    set(${CMK_OPTION} YES)
+  else()
+    set(${CMK_OPTION} NO)
+  endif()
+endmacro()
+
+macro(UseDoxygen)
+  if (${CMAKE_VERSION} VERSION_LESS "3.9")
+    # Old versions of cmake have poor support for Doxygen generation.
+    message(FATAL_ERROR "Doxygen generation only enabled for cmake 3.9 and higher")
+  else()
+    find_package(Doxygen)
+    if (DOXYGEN_FOUND)
+      set(DOXYGEN_PROJECT_NAME ${PROJECT_NAME})
+      set(DOXYGEN_PROJECT_NUMBER ${EVENT_PACKAGE_VERSION})
+      set(DOXYGEN_PROJECT_BRIEF "Event notification library")
+      set(DOXYGEN_OUTPUT_DIRECTORY doxygen)
+      set(DOXYGEN_STRIP_FROM_PATH include)
+      set(DOXYGEN_JAVADOC_AUTOBRIEF YES)
+      set(DOXYGEN_OPTIMIZE_OUTPUT_FOR_C YES)
+      set(DOXYGEN_SORT_BRIEF_DOCS YES)
+      set(DOXYGEN_RECURSIVE NO)
+
+      _convert_to_dx_cfg(DOXYGEN_GENERATE_HTML)
+      _convert_to_dx_cfg(DOXYGEN_GENERATE_MAN)
+      _convert_to_dx_cfg(DOXYGEN_MAN_LINKS)
+      _convert_to_dx_cfg(DOXYGEN_GENERATE_LATEX)
+
+      set(DOXYGEN_LATEX_CMD_NAME latex)
+      set(DOXYGEN_PAPER_TYPE a4wide)
+      set(DOXYGEN_PDF_HYPERLINKS NO)
+
+      set(DOXYGEN_GENERATE_RTF NO)
+      set(DOXYGEN_GENERATE_XML NO)
+      set(DOXYGEN_GENERATE_CHI NO)
+
+      set(DOXYGEN_PREDEFINED TAILQ_ENTRY
+        RB_ENTRY
+        EVENT_DEFINED_TQENTRY_
+        EVENT_IN_DOXYGEN_
+      )
+
+      set(DOX_INPUT include/event2/buffer.h
+        include/event2/buffer_compat.h
+        include/event2/bufferevent.h
+        include/event2/bufferevent_compat.h
+        include/event2/bufferevent_ssl.h
+        include/event2/dns.h
+        include/event2/dns_compat.h
+        include/event2/event.h
+        include/event2/event_compat.h
+        include/event2/http.h
+        include/event2/http_compat.h
+        include/event2/listener.h
+        include/event2/rpc.h
+        include/event2/rpc_compat.h
+        include/event2/tag.h
+        include/event2/tag_compat.h
+        include/event2/thread.h
+        include/event2/util.h
+      )
+      # Add 'doxygen' target
+      doxygen_add_docs(doxygen
+        ${DOX_INPUT}
+        ALL
+        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+        COMMENT "Generating doxygen documentation for ${PROJECT_NAME}..."
+      )
+
+      # Use 'make clean' to remove the generated directory
+      set_property(DIRECTORY
+        PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
+        "${PROJECT_BINARY_DIR}/${DOXYGEN_OUTPUT_DIRECTORY}"
+      )
+
+      # Install html into <prefix>/share/doc/<project>
+      if ("${DOXYGEN_GENERATE_HTML}" STREQUAL "YES")
+        install(DIRECTORY
+          ${PROJECT_BINARY_DIR}/${DOXYGEN_OUTPUT_DIRECTORY}/html
+          DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc/${PROJECT_NAME}
+          COMPONENT doc
+        )
+      endif()
+
+      # Install manual into <prefix>/share/man/man3
+      if ("${DOXYGEN_GENERATE_MAN}" STREQUAL "YES")
+        install(DIRECTORY
+          ${PROJECT_BINARY_DIR}/${DOXYGEN_OUTPUT_DIRECTORY}/man/man3
+          DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man
+          COMPONENT doc
+        )
+      endif()
+
+    else(DOXYGEN_FOUND)
+      message(FATAL_ERROR "Doxygen command not found, set EVENT__DOXYGEN to disable")
+    endif (DOXYGEN_FOUND)
+  endif()
+endmacro()
diff --git a/cmake/VersionViaGit.cmake b/cmake/VersionViaGit.cmake
index 504980a..24eb6af 100644
--- a/cmake/VersionViaGit.cmake
+++ b/cmake/VersionViaGit.cmake
@@ -23,7 +23,7 @@
 	# set our defaults.
 	set(EVENT_GIT___VERSION_MAJOR 2)
 	set(EVENT_GIT___VERSION_MINOR 1)
-	set(EVENT_GIT___VERSION_PATCH 11)
+	set(EVENT_GIT___VERSION_PATCH 12)
 	set(EVENT_GIT___VERSION_STAGE "stable")
 
 	find_package(Git)
@@ -31,7 +31,7 @@
 	if (GIT_FOUND)
 		execute_process(
 			COMMAND
-				${GIT_EXECUTABLE} describe --abbrev=0
+				${GIT_EXECUTABLE} describe --abbrev=0 --always
 			WORKING_DIRECTORY
 				${PROJECT_SOURCE_DIR}
 			RESULT_VARIABLE
@@ -42,7 +42,9 @@
 		)
 
 		string(REGEX REPLACE "[\\._-]" ";" VERSION_LIST "${GITVERSION}")
-		list(LENGTH VERSION_LIST VERSION_LIST_LENGTH)
+		if(VERSION_LIST)
+			list(LENGTH VERSION_LIST VERSION_LIST_LENGTH)
+		endif()
 
 		if ((GITRET EQUAL 0) AND (VERSION_LIST_LENGTH EQUAL 5))
 			list(GET VERSION_LIST 1 _MAJOR)
diff --git a/config.h.in b/config.h.in
index 122aecf..9e38327 100644
--- a/config.h.in
+++ b/config.h.in
@@ -12,6 +12,9 @@
 /* Define to 1 if you have the `accept4' function. */
 #undef HAVE_ACCEPT4
 
+/* Define to 1 if you have the <afunix.h> header file. */
+#undef HAVE_AFUNIX_H
+
 /* Define to 1 if you have the `arc4random' function. */
 #undef HAVE_ARC4RANDOM
 
@@ -35,14 +38,6 @@
    don't. */
 #undef HAVE_DECL_KERN_ARND
 
-/* Define to 1 if you have the declaration of `KERN_RANDOM', and to 0 if you
-   don't. */
-#undef HAVE_DECL_KERN_RANDOM
-
-/* Define to 1 if you have the declaration of `RANDOM_UUID', and to 0 if you
-   don't. */
-#undef HAVE_DECL_RANDOM_UUID
-
 /* Define if /dev/poll is available */
 #undef HAVE_DEVPOLL
 
@@ -106,6 +101,9 @@
 /* Define to 1 if you have the `getprotobynumber' function. */
 #undef HAVE_GETPROTOBYNUMBER
 
+/* Define to 1 if you have the `getrandom' function. */
+#undef HAVE_GETRANDOM
+
 /* Define to 1 if you have the `getservbyname' function. */
 #undef HAVE_GETSERVBYNAME
 
@@ -130,12 +128,18 @@
 /* Define to 1 if you have the `kqueue' function. */
 #undef HAVE_KQUEUE
 
+/* Define to 1 if you have the `ws2_32' library (-lws2_32). */
+#undef HAVE_LIBWS2_32
+
 /* Define if the system has zlib */
 #undef HAVE_LIBZ
 
 /* Define to 1 if you have the `mach_absolute_time' function. */
 #undef HAVE_MACH_ABSOLUTE_TIME
 
+/* Define to 1 if you have the <mach/mach.h> header file. */
+#undef HAVE_MACH_MACH_H
+
 /* Define to 1 if you have the <mach/mach_time.h> header file. */
 #undef HAVE_MACH_MACH_TIME_H
 
@@ -313,6 +317,9 @@
 /* Define to 1 if you have the <sys/queue.h> header file. */
 #undef HAVE_SYS_QUEUE_H
 
+/* Define to 1 if you have the <sys/random.h> header file. */
+#undef HAVE_SYS_RANDOM_H
+
 /* Define to 1 if you have the <sys/resource.h> header file. */
 #undef HAVE_SYS_RESOURCE_H
 
@@ -403,6 +410,12 @@
 /* Define to 1 if you have the <zlib.h> header file. */
 #undef HAVE_ZLIB_H
 
+/* Define to 1 if you have the `_gmtime64' function. */
+#undef HAVE__GMTIME64
+
+/* Define to 1 if you have the `_gmtime64_s' function. */
+#undef HAVE__GMTIME64_S
+
 /* Define to 1 if compiler have __FUNCTION__ */
 #undef HAVE___FUNCTION__
 
diff --git a/config.sub b/config.sub
deleted file mode 100755
index 9ccf09a..0000000
--- a/config.sub
+++ /dev/null
@@ -1,1801 +0,0 @@
-#! /bin/sh
-# Configuration validation subroutine script.
-#   Copyright 1992-2018 Free Software Foundation, Inc.
-
-timestamp='2018-03-08'
-
-# This file is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <https://www.gnu.org/licenses/>.
-#
-# As a special exception to the GNU General Public License, if you
-# distribute this file as part of a program that contains a
-# configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that
-# program.  This Exception is an additional permission under section 7
-# of the GNU General Public License, version 3 ("GPLv3").
-
-
-# Please send patches to <config-patches@gnu.org>.
-#
-# Configuration subroutine to validate and canonicalize a configuration type.
-# Supply the specified configuration type as an argument.
-# If it is invalid, we print an error message on stderr and exit with code 1.
-# Otherwise, we print the canonical config type on stdout and succeed.
-
-# You can get the latest version of this script from:
-# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
-
-# This file is supposed to be the same for all GNU packages
-# and recognize all the CPU types, system types and aliases
-# that are meaningful with *any* GNU software.
-# Each package is responsible for reporting which valid configurations
-# it does not support.  The user should be able to distinguish
-# a failure to support a valid configuration from a meaningless
-# configuration.
-
-# The goal of this file is to map all the various variations of a given
-# machine specification into a single specification in the form:
-#	CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
-# or in some cases, the newer four-part form:
-#	CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
-# It is wrong to echo any other type of specification.
-
-me=`echo "$0" | sed -e 's,.*/,,'`
-
-usage="\
-Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS
-
-Canonicalize a configuration name.
-
-Options:
-  -h, --help         print this help, then exit
-  -t, --time-stamp   print date of last modification, then exit
-  -v, --version      print version number, then exit
-
-Report bugs and patches to <config-patches@gnu.org>."
-
-version="\
-GNU config.sub ($timestamp)
-
-Copyright 1992-2018 Free Software Foundation, Inc.
-
-This is free software; see the source for copying conditions.  There is NO
-warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
-
-help="
-Try \`$me --help' for more information."
-
-# Parse command line
-while test $# -gt 0 ; do
-  case $1 in
-    --time-stamp | --time* | -t )
-       echo "$timestamp" ; exit ;;
-    --version | -v )
-       echo "$version" ; exit ;;
-    --help | --h* | -h )
-       echo "$usage"; exit ;;
-    -- )     # Stop option processing
-       shift; break ;;
-    - )	# Use stdin as input.
-       break ;;
-    -* )
-       echo "$me: invalid option $1$help"
-       exit 1 ;;
-
-    *local*)
-       # First pass through any local machine types.
-       echo "$1"
-       exit ;;
-
-    * )
-       break ;;
-  esac
-done
-
-case $# in
- 0) echo "$me: missing argument$help" >&2
-    exit 1;;
- 1) ;;
- *) echo "$me: too many arguments$help" >&2
-    exit 1;;
-esac
-
-# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
-# Here we must recognize all the valid KERNEL-OS combinations.
-maybe_os=`echo "$1" | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
-case $maybe_os in
-  nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
-  linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
-  knetbsd*-gnu* | netbsd*-gnu* | netbsd*-eabi* | \
-  kopensolaris*-gnu* | cloudabi*-eabi* | \
-  storm-chaos* | os2-emx* | rtmk-nova*)
-    os=-$maybe_os
-    basic_machine=`echo "$1" | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
-    ;;
-  android-linux)
-    os=-linux-android
-    basic_machine=`echo "$1" | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown
-    ;;
-  *)
-    basic_machine=`echo "$1" | sed 's/-[^-]*$//'`
-    if [ "$basic_machine" != "$1" ]
-    then os=`echo "$1" | sed 's/.*-/-/'`
-    else os=; fi
-    ;;
-esac
-
-### Let's recognize common machines as not being operating systems so
-### that things like config.sub decstation-3100 work.  We also
-### recognize some manufacturers as not being operating systems, so we
-### can provide default operating systems below.
-case $os in
-	-sun*os*)
-		# Prevent following clause from handling this invalid input.
-		;;
-	-dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
-	-att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
-	-unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
-	-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
-	-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
-	-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
-	-apple | -axis | -knuth | -cray | -microblaze*)
-		os=
-		basic_machine=$1
-		;;
-	-bluegene*)
-		os=-cnk
-		;;
-	-sim | -cisco | -oki | -wec | -winbond)
-		os=
-		basic_machine=$1
-		;;
-	-scout)
-		;;
-	-wrs)
-		os=-vxworks
-		basic_machine=$1
-		;;
-	-chorusos*)
-		os=-chorusos
-		basic_machine=$1
-		;;
-	-chorusrdb)
-		os=-chorusrdb
-		basic_machine=$1
-		;;
-	-hiux*)
-		os=-hiuxwe2
-		;;
-	-sco6)
-		os=-sco5v6
-		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
-		;;
-	-sco5)
-		os=-sco3.2v5
-		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
-		;;
-	-sco4)
-		os=-sco3.2v4
-		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
-		;;
-	-sco3.2.[4-9]*)
-		os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
-		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
-		;;
-	-sco3.2v[4-9]*)
-		# Don't forget version if it is 3.2v4 or newer.
-		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
-		;;
-	-sco5v6*)
-		# Don't forget version if it is 3.2v4 or newer.
-		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
-		;;
-	-sco*)
-		os=-sco3.2v2
-		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
-		;;
-	-udk*)
-		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
-		;;
-	-isc)
-		os=-isc2.2
-		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
-		;;
-	-clix*)
-		basic_machine=clipper-intergraph
-		;;
-	-isc*)
-		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
-		;;
-	-lynx*178)
-		os=-lynxos178
-		;;
-	-lynx*5)
-		os=-lynxos5
-		;;
-	-lynx*)
-		os=-lynxos
-		;;
-	-ptx*)
-		basic_machine=`echo "$1" | sed -e 's/86-.*/86-sequent/'`
-		;;
-	-psos*)
-		os=-psos
-		;;
-	-mint | -mint[0-9]*)
-		basic_machine=m68k-atari
-		os=-mint
-		;;
-esac
-
-# Decode aliases for certain CPU-COMPANY combinations.
-case $basic_machine in
-	# Recognize the basic CPU types without company name.
-	# Some are omitted here because they have special meanings below.
-	1750a | 580 \
-	| a29k \
-	| aarch64 | aarch64_be \
-	| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
-	| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
-	| am33_2.0 \
-	| arc | arceb \
-	| arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \
-	| avr | avr32 \
-	| ba \
-	| be32 | be64 \
-	| bfin \
-	| c4x | c8051 | clipper \
-	| d10v | d30v | dlx | dsp16xx \
-	| e2k | epiphany \
-	| fido | fr30 | frv | ft32 \
-	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
-	| hexagon \
-	| i370 | i860 | i960 | ia16 | ia64 \
-	| ip2k | iq2000 \
-	| k1om \
-	| le32 | le64 \
-	| lm32 \
-	| m32c | m32r | m32rle | m68000 | m68k | m88k \
-	| maxq | mb | microblaze | microblazeel | mcore | mep | metag \
-	| mips | mipsbe | mipseb | mipsel | mipsle \
-	| mips16 \
-	| mips64 | mips64el \
-	| mips64octeon | mips64octeonel \
-	| mips64orion | mips64orionel \
-	| mips64r5900 | mips64r5900el \
-	| mips64vr | mips64vrel \
-	| mips64vr4100 | mips64vr4100el \
-	| mips64vr4300 | mips64vr4300el \
-	| mips64vr5000 | mips64vr5000el \
-	| mips64vr5900 | mips64vr5900el \
-	| mipsisa32 | mipsisa32el \
-	| mipsisa32r2 | mipsisa32r2el \
-	| mipsisa32r6 | mipsisa32r6el \
-	| mipsisa64 | mipsisa64el \
-	| mipsisa64r2 | mipsisa64r2el \
-	| mipsisa64r6 | mipsisa64r6el \
-	| mipsisa64sb1 | mipsisa64sb1el \
-	| mipsisa64sr71k | mipsisa64sr71kel \
-	| mipsr5900 | mipsr5900el \
-	| mipstx39 | mipstx39el \
-	| mn10200 | mn10300 \
-	| moxie \
-	| mt \
-	| msp430 \
-	| nds32 | nds32le | nds32be \
-	| nios | nios2 | nios2eb | nios2el \
-	| ns16k | ns32k \
-	| open8 | or1k | or1knd | or32 \
-	| pdp10 | pj | pjl \
-	| powerpc | powerpc64 | powerpc64le | powerpcle \
-	| pru \
-	| pyramid \
-	| riscv32 | riscv64 \
-	| rl78 | rx \
-	| score \
-	| sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[234]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
-	| sh64 | sh64le \
-	| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
-	| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
-	| spu \
-	| tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \
-	| ubicom32 \
-	| v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
-	| visium \
-	| wasm32 \
-	| x86 | xc16x | xstormy16 | xtensa \
-	| z8k | z80)
-		basic_machine=$basic_machine-unknown
-		;;
-	c54x)
-		basic_machine=tic54x-unknown
-		;;
-	c55x)
-		basic_machine=tic55x-unknown
-		;;
-	c6x)
-		basic_machine=tic6x-unknown
-		;;
-	leon|leon[3-9])
-		basic_machine=sparc-$basic_machine
-		;;
-	m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip)
-		basic_machine=$basic_machine-unknown
-		os=-none
-		;;
-	m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65)
-		;;
-	ms1)
-		basic_machine=mt-unknown
-		;;
-
-	strongarm | thumb | xscale)
-		basic_machine=arm-unknown
-		;;
-	xgate)
-		basic_machine=$basic_machine-unknown
-		os=-none
-		;;
-	xscaleeb)
-		basic_machine=armeb-unknown
-		;;
-
-	xscaleel)
-		basic_machine=armel-unknown
-		;;
-
-	# We use `pc' rather than `unknown'
-	# because (1) that's what they normally are, and
-	# (2) the word "unknown" tends to confuse beginning users.
-	i*86 | x86_64)
-	  basic_machine=$basic_machine-pc
-	  ;;
-	# Object if more than one company name word.
-	*-*-*)
-		echo Invalid configuration \`"$1"\': machine \`"$basic_machine"\' not recognized 1>&2
-		exit 1
-		;;
-	# Recognize the basic CPU types with company name.
-	580-* \
-	| a29k-* \
-	| aarch64-* | aarch64_be-* \
-	| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
-	| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
-	| alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \
-	| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
-	| avr-* | avr32-* \
-	| ba-* \
-	| be32-* | be64-* \
-	| bfin-* | bs2000-* \
-	| c[123]* | c30-* | [cjt]90-* | c4x-* \
-	| c8051-* | clipper-* | craynv-* | cydra-* \
-	| d10v-* | d30v-* | dlx-* \
-	| e2k-* | elxsi-* \
-	| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
-	| h8300-* | h8500-* \
-	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
-	| hexagon-* \
-	| i*86-* | i860-* | i960-* | ia16-* | ia64-* \
-	| ip2k-* | iq2000-* \
-	| k1om-* \
-	| le32-* | le64-* \
-	| lm32-* \
-	| m32c-* | m32r-* | m32rle-* \
-	| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
-	| m88110-* | m88k-* | maxq-* | mcore-* | metag-* \
-	| microblaze-* | microblazeel-* \
-	| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
-	| mips16-* \
-	| mips64-* | mips64el-* \
-	| mips64octeon-* | mips64octeonel-* \
-	| mips64orion-* | mips64orionel-* \
-	| mips64r5900-* | mips64r5900el-* \
-	| mips64vr-* | mips64vrel-* \
-	| mips64vr4100-* | mips64vr4100el-* \
-	| mips64vr4300-* | mips64vr4300el-* \
-	| mips64vr5000-* | mips64vr5000el-* \
-	| mips64vr5900-* | mips64vr5900el-* \
-	| mipsisa32-* | mipsisa32el-* \
-	| mipsisa32r2-* | mipsisa32r2el-* \
-	| mipsisa32r6-* | mipsisa32r6el-* \
-	| mipsisa64-* | mipsisa64el-* \
-	| mipsisa64r2-* | mipsisa64r2el-* \
-	| mipsisa64r6-* | mipsisa64r6el-* \
-	| mipsisa64sb1-* | mipsisa64sb1el-* \
-	| mipsisa64sr71k-* | mipsisa64sr71kel-* \
-	| mipsr5900-* | mipsr5900el-* \
-	| mipstx39-* | mipstx39el-* \
-	| mmix-* \
-	| mt-* \
-	| msp430-* \
-	| nds32-* | nds32le-* | nds32be-* \
-	| nios-* | nios2-* | nios2eb-* | nios2el-* \
-	| none-* | np1-* | ns16k-* | ns32k-* \
-	| open8-* \
-	| or1k*-* \
-	| orion-* \
-	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
-	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
-	| pru-* \
-	| pyramid-* \
-	| riscv32-* | riscv64-* \
-	| rl78-* | romp-* | rs6000-* | rx-* \
-	| sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
-	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
-	| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
-	| sparclite-* \
-	| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx*-* \
-	| tahoe-* \
-	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
-	| tile*-* \
-	| tron-* \
-	| ubicom32-* \
-	| v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
-	| vax-* \
-	| visium-* \
-	| wasm32-* \
-	| we32k-* \
-	| x86-* | x86_64-* | xc16x-* | xps100-* \
-	| xstormy16-* | xtensa*-* \
-	| ymp-* \
-	| z8k-* | z80-*)
-		;;
-	# Recognize the basic CPU types without company name, with glob match.
-	xtensa*)
-		basic_machine=$basic_machine-unknown
-		;;
-	# Recognize the various machine names and aliases which stand
-	# for a CPU type and a company and sometimes even an OS.
-	386bsd)
-		basic_machine=i386-pc
-		os=-bsd
-		;;
-	3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
-		basic_machine=m68000-att
-		;;
-	3b*)
-		basic_machine=we32k-att
-		;;
-	a29khif)
-		basic_machine=a29k-amd
-		os=-udi
-		;;
-	abacus)
-		basic_machine=abacus-unknown
-		;;
-	adobe68k)
-		basic_machine=m68010-adobe
-		os=-scout
-		;;
-	alliant | fx80)
-		basic_machine=fx80-alliant
-		;;
-	altos | altos3068)
-		basic_machine=m68k-altos
-		;;
-	am29k)
-		basic_machine=a29k-none
-		os=-bsd
-		;;
-	amd64)
-		basic_machine=x86_64-pc
-		;;
-	amd64-*)
-		basic_machine=x86_64-`echo "$basic_machine" | sed 's/^[^-]*-//'`
-		;;
-	amdahl)
-		basic_machine=580-amdahl
-		os=-sysv
-		;;
-	amiga | amiga-*)
-		basic_machine=m68k-unknown
-		;;
-	amigaos | amigados)
-		basic_machine=m68k-unknown
-		os=-amigaos
-		;;
-	amigaunix | amix)
-		basic_machine=m68k-unknown
-		os=-sysv4
-		;;
-	apollo68)
-		basic_machine=m68k-apollo
-		os=-sysv
-		;;
-	apollo68bsd)
-		basic_machine=m68k-apollo
-		os=-bsd
-		;;
-	aros)
-		basic_machine=i386-pc
-		os=-aros
-		;;
-	asmjs)
-		basic_machine=asmjs-unknown
-		;;
-	aux)
-		basic_machine=m68k-apple
-		os=-aux
-		;;
-	balance)
-		basic_machine=ns32k-sequent
-		os=-dynix
-		;;
-	blackfin)
-		basic_machine=bfin-unknown
-		os=-linux
-		;;
-	blackfin-*)
-		basic_machine=bfin-`echo "$basic_machine" | sed 's/^[^-]*-//'`
-		os=-linux
-		;;
-	bluegene*)
-		basic_machine=powerpc-ibm
-		os=-cnk
-		;;
-	c54x-*)
-		basic_machine=tic54x-`echo "$basic_machine" | sed 's/^[^-]*-//'`
-		;;
-	c55x-*)
-		basic_machine=tic55x-`echo "$basic_machine" | sed 's/^[^-]*-//'`
-		;;
-	c6x-*)
-		basic_machine=tic6x-`echo "$basic_machine" | sed 's/^[^-]*-//'`
-		;;
-	c90)
-		basic_machine=c90-cray
-		os=-unicos
-		;;
-	cegcc)
-		basic_machine=arm-unknown
-		os=-cegcc
-		;;
-	convex-c1)
-		basic_machine=c1-convex
-		os=-bsd
-		;;
-	convex-c2)
-		basic_machine=c2-convex
-		os=-bsd
-		;;
-	convex-c32)
-		basic_machine=c32-convex
-		os=-bsd
-		;;
-	convex-c34)
-		basic_machine=c34-convex
-		os=-bsd
-		;;
-	convex-c38)
-		basic_machine=c38-convex
-		os=-bsd
-		;;
-	cray | j90)
-		basic_machine=j90-cray
-		os=-unicos
-		;;
-	craynv)
-		basic_machine=craynv-cray
-		os=-unicosmp
-		;;
-	cr16 | cr16-*)
-		basic_machine=cr16-unknown
-		os=-elf
-		;;
-	crds | unos)
-		basic_machine=m68k-crds
-		;;
-	crisv32 | crisv32-* | etraxfs*)
-		basic_machine=crisv32-axis
-		;;
-	cris | cris-* | etrax*)
-		basic_machine=cris-axis
-		;;
-	crx)
-		basic_machine=crx-unknown
-		os=-elf
-		;;
-	da30 | da30-*)
-		basic_machine=m68k-da30
-		;;
-	decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
-		basic_machine=mips-dec
-		;;
-	decsystem10* | dec10*)
-		basic_machine=pdp10-dec
-		os=-tops10
-		;;
-	decsystem20* | dec20*)
-		basic_machine=pdp10-dec
-		os=-tops20
-		;;
-	delta | 3300 | motorola-3300 | motorola-delta \
-	      | 3300-motorola | delta-motorola)
-		basic_machine=m68k-motorola
-		;;
-	delta88)
-		basic_machine=m88k-motorola
-		os=-sysv3
-		;;
-	dicos)
-		basic_machine=i686-pc
-		os=-dicos
-		;;
-	djgpp)
-		basic_machine=i586-pc
-		os=-msdosdjgpp
-		;;
-	dpx20 | dpx20-*)
-		basic_machine=rs6000-bull
-		os=-bosx
-		;;
-	dpx2*)
-		basic_machine=m68k-bull
-		os=-sysv3
-		;;
-	e500v[12])
-		basic_machine=powerpc-unknown
-		os=$os"spe"
-		;;
-	e500v[12]-*)
-		basic_machine=powerpc-`echo "$basic_machine" | sed 's/^[^-]*-//'`
-		os=$os"spe"
-		;;
-	ebmon29k)
-		basic_machine=a29k-amd
-		os=-ebmon
-		;;
-	elxsi)
-		basic_machine=elxsi-elxsi
-		os=-bsd
-		;;
-	encore | umax | mmax)
-		basic_machine=ns32k-encore
-		;;
-	es1800 | OSE68k | ose68k | ose | OSE)
-		basic_machine=m68k-ericsson
-		os=-ose
-		;;
-	fx2800)
-		basic_machine=i860-alliant
-		;;
-	genix)
-		basic_machine=ns32k-ns
-		;;
-	gmicro)
-		basic_machine=tron-gmicro
-		os=-sysv
-		;;
-	go32)
-		basic_machine=i386-pc
-		os=-go32
-		;;
-	h3050r* | hiux*)
-		basic_machine=hppa1.1-hitachi
-		os=-hiuxwe2
-		;;
-	h8300hms)
-		basic_machine=h8300-hitachi
-		os=-hms
-		;;
-	h8300xray)
-		basic_machine=h8300-hitachi
-		os=-xray
-		;;
-	h8500hms)
-		basic_machine=h8500-hitachi
-		os=-hms
-		;;
-	harris)
-		basic_machine=m88k-harris
-		os=-sysv3
-		;;
-	hp300-*)
-		basic_machine=m68k-hp
-		;;
-	hp300bsd)
-		basic_machine=m68k-hp
-		os=-bsd
-		;;
-	hp300hpux)
-		basic_machine=m68k-hp
-		os=-hpux
-		;;
-	hp3k9[0-9][0-9] | hp9[0-9][0-9])
-		basic_machine=hppa1.0-hp
-		;;
-	hp9k2[0-9][0-9] | hp9k31[0-9])
-		basic_machine=m68000-hp
-		;;
-	hp9k3[2-9][0-9])
-		basic_machine=m68k-hp
-		;;
-	hp9k6[0-9][0-9] | hp6[0-9][0-9])
-		basic_machine=hppa1.0-hp
-		;;
-	hp9k7[0-79][0-9] | hp7[0-79][0-9])
-		basic_machine=hppa1.1-hp
-		;;
-	hp9k78[0-9] | hp78[0-9])
-		# FIXME: really hppa2.0-hp
-		basic_machine=hppa1.1-hp
-		;;
-	hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
-		# FIXME: really hppa2.0-hp
-		basic_machine=hppa1.1-hp
-		;;
-	hp9k8[0-9][13679] | hp8[0-9][13679])
-		basic_machine=hppa1.1-hp
-		;;
-	hp9k8[0-9][0-9] | hp8[0-9][0-9])
-		basic_machine=hppa1.0-hp
-		;;
-	hppaosf)
-		basic_machine=hppa1.1-hp
-		os=-osf
-		;;
-	hppro)
-		basic_machine=hppa1.1-hp
-		os=-proelf
-		;;
-	i370-ibm* | ibm*)
-		basic_machine=i370-ibm
-		;;
-	i*86v32)
-		basic_machine=`echo "$1" | sed -e 's/86.*/86-pc/'`
-		os=-sysv32
-		;;
-	i*86v4*)
-		basic_machine=`echo "$1" | sed -e 's/86.*/86-pc/'`
-		os=-sysv4
-		;;
-	i*86v)
-		basic_machine=`echo "$1" | sed -e 's/86.*/86-pc/'`
-		os=-sysv
-		;;
-	i*86sol2)
-		basic_machine=`echo "$1" | sed -e 's/86.*/86-pc/'`
-		os=-solaris2
-		;;
-	i386mach)
-		basic_machine=i386-mach
-		os=-mach
-		;;
-	vsta)
-		basic_machine=i386-unknown
-		os=-vsta
-		;;
-	iris | iris4d)
-		basic_machine=mips-sgi
-		case $os in
-		    -irix*)
-			;;
-		    *)
-			os=-irix4
-			;;
-		esac
-		;;
-	isi68 | isi)
-		basic_machine=m68k-isi
-		os=-sysv
-		;;
-	leon-*|leon[3-9]-*)
-		basic_machine=sparc-`echo "$basic_machine" | sed 's/-.*//'`
-		;;
-	m68knommu)
-		basic_machine=m68k-unknown
-		os=-linux
-		;;
-	m68knommu-*)
-		basic_machine=m68k-`echo "$basic_machine" | sed 's/^[^-]*-//'`
-		os=-linux
-		;;
-	magnum | m3230)
-		basic_machine=mips-mips
-		os=-sysv
-		;;
-	merlin)
-		basic_machine=ns32k-utek
-		os=-sysv
-		;;
-	microblaze*)
-		basic_machine=microblaze-xilinx
-		;;
-	mingw64)
-		basic_machine=x86_64-pc
-		os=-mingw64
-		;;
-	mingw32)
-		basic_machine=i686-pc
-		os=-mingw32
-		;;
-	mingw32ce)
-		basic_machine=arm-unknown
-		os=-mingw32ce
-		;;
-	miniframe)
-		basic_machine=m68000-convergent
-		;;
-	*mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
-		basic_machine=m68k-atari
-		os=-mint
-		;;
-	mips3*-*)
-		basic_machine=`echo "$basic_machine" | sed -e 's/mips3/mips64/'`
-		;;
-	mips3*)
-		basic_machine=`echo "$basic_machine" | sed -e 's/mips3/mips64/'`-unknown
-		;;
-	monitor)
-		basic_machine=m68k-rom68k
-		os=-coff
-		;;
-	morphos)
-		basic_machine=powerpc-unknown
-		os=-morphos
-		;;
-	moxiebox)
-		basic_machine=moxie-unknown
-		os=-moxiebox
-		;;
-	msdos)
-		basic_machine=i386-pc
-		os=-msdos
-		;;
-	ms1-*)
-		basic_machine=`echo "$basic_machine" | sed -e 's/ms1-/mt-/'`
-		;;
-	msys)
-		basic_machine=i686-pc
-		os=-msys
-		;;
-	mvs)
-		basic_machine=i370-ibm
-		os=-mvs
-		;;
-	nacl)
-		basic_machine=le32-unknown
-		os=-nacl
-		;;
-	ncr3000)
-		basic_machine=i486-ncr
-		os=-sysv4
-		;;
-	netbsd386)
-		basic_machine=i386-unknown
-		os=-netbsd
-		;;
-	netwinder)
-		basic_machine=armv4l-rebel
-		os=-linux
-		;;
-	news | news700 | news800 | news900)
-		basic_machine=m68k-sony
-		os=-newsos
-		;;
-	news1000)
-		basic_machine=m68030-sony
-		os=-newsos
-		;;
-	news-3600 | risc-news)
-		basic_machine=mips-sony
-		os=-newsos
-		;;
-	necv70)
-		basic_machine=v70-nec
-		os=-sysv
-		;;
-	next | m*-next)
-		basic_machine=m68k-next
-		case $os in
-		    -nextstep* )
-			;;
-		    -ns2*)
-		      os=-nextstep2
-			;;
-		    *)
-		      os=-nextstep3
-			;;
-		esac
-		;;
-	nh3000)
-		basic_machine=m68k-harris
-		os=-cxux
-		;;
-	nh[45]000)
-		basic_machine=m88k-harris
-		os=-cxux
-		;;
-	nindy960)
-		basic_machine=i960-intel
-		os=-nindy
-		;;
-	mon960)
-		basic_machine=i960-intel
-		os=-mon960
-		;;
-	nonstopux)
-		basic_machine=mips-compaq
-		os=-nonstopux
-		;;
-	np1)
-		basic_machine=np1-gould
-		;;
-	neo-tandem)
-		basic_machine=neo-tandem
-		;;
-	nse-tandem)
-		basic_machine=nse-tandem
-		;;
-	nsr-tandem)
-		basic_machine=nsr-tandem
-		;;
-	nsv-tandem)
-		basic_machine=nsv-tandem
-		;;
-	nsx-tandem)
-		basic_machine=nsx-tandem
-		;;
-	op50n-* | op60c-*)
-		basic_machine=hppa1.1-oki
-		os=-proelf
-		;;
-	openrisc | openrisc-*)
-		basic_machine=or32-unknown
-		;;
-	os400)
-		basic_machine=powerpc-ibm
-		os=-os400
-		;;
-	OSE68000 | ose68000)
-		basic_machine=m68000-ericsson
-		os=-ose
-		;;
-	os68k)
-		basic_machine=m68k-none
-		os=-os68k
-		;;
-	pa-hitachi)
-		basic_machine=hppa1.1-hitachi
-		os=-hiuxwe2
-		;;
-	paragon)
-		basic_machine=i860-intel
-		os=-osf
-		;;
-	parisc)
-		basic_machine=hppa-unknown
-		os=-linux
-		;;
-	parisc-*)
-		basic_machine=hppa-`echo "$basic_machine" | sed 's/^[^-]*-//'`
-		os=-linux
-		;;
-	pbd)
-		basic_machine=sparc-tti
-		;;
-	pbb)
-		basic_machine=m68k-tti
-		;;
-	pc532 | pc532-*)
-		basic_machine=ns32k-pc532
-		;;
-	pc98)
-		basic_machine=i386-pc
-		;;
-	pc98-*)
-		basic_machine=i386-`echo "$basic_machine" | sed 's/^[^-]*-//'`
-		;;
-	pentium | p5 | k5 | k6 | nexgen | viac3)
-		basic_machine=i586-pc
-		;;
-	pentiumpro | p6 | 6x86 | athlon | athlon_*)
-		basic_machine=i686-pc
-		;;
-	pentiumii | pentium2 | pentiumiii | pentium3)
-		basic_machine=i686-pc
-		;;
-	pentium4)
-		basic_machine=i786-pc
-		;;
-	pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
-		basic_machine=i586-`echo "$basic_machine" | sed 's/^[^-]*-//'`
-		;;
-	pentiumpro-* | p6-* | 6x86-* | athlon-*)
-		basic_machine=i686-`echo "$basic_machine" | sed 's/^[^-]*-//'`
-		;;
-	pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
-		basic_machine=i686-`echo "$basic_machine" | sed 's/^[^-]*-//'`
-		;;
-	pentium4-*)
-		basic_machine=i786-`echo "$basic_machine" | sed 's/^[^-]*-//'`
-		;;
-	pn)
-		basic_machine=pn-gould
-		;;
-	power)	basic_machine=power-ibm
-		;;
-	ppc | ppcbe)	basic_machine=powerpc-unknown
-		;;
-	ppc-* | ppcbe-*)
-		basic_machine=powerpc-`echo "$basic_machine" | sed 's/^[^-]*-//'`
-		;;
-	ppcle | powerpclittle)
-		basic_machine=powerpcle-unknown
-		;;
-	ppcle-* | powerpclittle-*)
-		basic_machine=powerpcle-`echo "$basic_machine" | sed 's/^[^-]*-//'`
-		;;
-	ppc64)	basic_machine=powerpc64-unknown
-		;;
-	ppc64-*) basic_machine=powerpc64-`echo "$basic_machine" | sed 's/^[^-]*-//'`
-		;;
-	ppc64le | powerpc64little)
-		basic_machine=powerpc64le-unknown
-		;;
-	ppc64le-* | powerpc64little-*)
-		basic_machine=powerpc64le-`echo "$basic_machine" | sed 's/^[^-]*-//'`
-		;;
-	ps2)
-		basic_machine=i386-ibm
-		;;
-	pw32)
-		basic_machine=i586-unknown
-		os=-pw32
-		;;
-	rdos | rdos64)
-		basic_machine=x86_64-pc
-		os=-rdos
-		;;
-	rdos32)
-		basic_machine=i386-pc
-		os=-rdos
-		;;
-	rom68k)
-		basic_machine=m68k-rom68k
-		os=-coff
-		;;
-	rm[46]00)
-		basic_machine=mips-siemens
-		;;
-	rtpc | rtpc-*)
-		basic_machine=romp-ibm
-		;;
-	s390 | s390-*)
-		basic_machine=s390-ibm
-		;;
-	s390x | s390x-*)
-		basic_machine=s390x-ibm
-		;;
-	sa29200)
-		basic_machine=a29k-amd
-		os=-udi
-		;;
-	sb1)
-		basic_machine=mipsisa64sb1-unknown
-		;;
-	sb1el)
-		basic_machine=mipsisa64sb1el-unknown
-		;;
-	sde)
-		basic_machine=mipsisa32-sde
-		os=-elf
-		;;
-	sei)
-		basic_machine=mips-sei
-		os=-seiux
-		;;
-	sequent)
-		basic_machine=i386-sequent
-		;;
-	sh5el)
-		basic_machine=sh5le-unknown
-		;;
-	simso-wrs)
-		basic_machine=sparclite-wrs
-		os=-vxworks
-		;;
-	sps7)
-		basic_machine=m68k-bull
-		os=-sysv2
-		;;
-	spur)
-		basic_machine=spur-unknown
-		;;
-	st2000)
-		basic_machine=m68k-tandem
-		;;
-	stratus)
-		basic_machine=i860-stratus
-		os=-sysv4
-		;;
-	strongarm-* | thumb-*)
-		basic_machine=arm-`echo "$basic_machine" | sed 's/^[^-]*-//'`
-		;;
-	sun2)
-		basic_machine=m68000-sun
-		;;
-	sun2os3)
-		basic_machine=m68000-sun
-		os=-sunos3
-		;;
-	sun2os4)
-		basic_machine=m68000-sun
-		os=-sunos4
-		;;
-	sun3os3)
-		basic_machine=m68k-sun
-		os=-sunos3
-		;;
-	sun3os4)
-		basic_machine=m68k-sun
-		os=-sunos4
-		;;
-	sun4os3)
-		basic_machine=sparc-sun
-		os=-sunos3
-		;;
-	sun4os4)
-		basic_machine=sparc-sun
-		os=-sunos4
-		;;
-	sun4sol2)
-		basic_machine=sparc-sun
-		os=-solaris2
-		;;
-	sun3 | sun3-*)
-		basic_machine=m68k-sun
-		;;
-	sun4)
-		basic_machine=sparc-sun
-		;;
-	sun386 | sun386i | roadrunner)
-		basic_machine=i386-sun
-		;;
-	sv1)
-		basic_machine=sv1-cray
-		os=-unicos
-		;;
-	symmetry)
-		basic_machine=i386-sequent
-		os=-dynix
-		;;
-	t3e)
-		basic_machine=alphaev5-cray
-		os=-unicos
-		;;
-	t90)
-		basic_machine=t90-cray
-		os=-unicos
-		;;
-	tile*)
-		basic_machine=$basic_machine-unknown
-		os=-linux-gnu
-		;;
-	tx39)
-		basic_machine=mipstx39-unknown
-		;;
-	tx39el)
-		basic_machine=mipstx39el-unknown
-		;;
-	toad1)
-		basic_machine=pdp10-xkl
-		os=-tops20
-		;;
-	tower | tower-32)
-		basic_machine=m68k-ncr
-		;;
-	tpf)
-		basic_machine=s390x-ibm
-		os=-tpf
-		;;
-	udi29k)
-		basic_machine=a29k-amd
-		os=-udi
-		;;
-	ultra3)
-		basic_machine=a29k-nyu
-		os=-sym1
-		;;
-	v810 | necv810)
-		basic_machine=v810-nec
-		os=-none
-		;;
-	vaxv)
-		basic_machine=vax-dec
-		os=-sysv
-		;;
-	vms)
-		basic_machine=vax-dec
-		os=-vms
-		;;
-	vpp*|vx|vx-*)
-		basic_machine=f301-fujitsu
-		;;
-	vxworks960)
-		basic_machine=i960-wrs
-		os=-vxworks
-		;;
-	vxworks68)
-		basic_machine=m68k-wrs
-		os=-vxworks
-		;;
-	vxworks29k)
-		basic_machine=a29k-wrs
-		os=-vxworks
-		;;
-	w65*)
-		basic_machine=w65-wdc
-		os=-none
-		;;
-	w89k-*)
-		basic_machine=hppa1.1-winbond
-		os=-proelf
-		;;
-	x64)
-		basic_machine=x86_64-pc
-		;;
-	xbox)
-		basic_machine=i686-pc
-		os=-mingw32
-		;;
-	xps | xps100)
-		basic_machine=xps100-honeywell
-		;;
-	xscale-* | xscalee[bl]-*)
-		basic_machine=`echo "$basic_machine" | sed 's/^xscale/arm/'`
-		;;
-	ymp)
-		basic_machine=ymp-cray
-		os=-unicos
-		;;
-	none)
-		basic_machine=none-none
-		os=-none
-		;;
-
-# Here we handle the default manufacturer of certain CPU types.  It is in
-# some cases the only manufacturer, in others, it is the most popular.
-	w89k)
-		basic_machine=hppa1.1-winbond
-		;;
-	op50n)
-		basic_machine=hppa1.1-oki
-		;;
-	op60c)
-		basic_machine=hppa1.1-oki
-		;;
-	romp)
-		basic_machine=romp-ibm
-		;;
-	mmix)
-		basic_machine=mmix-knuth
-		;;
-	rs6000)
-		basic_machine=rs6000-ibm
-		;;
-	vax)
-		basic_machine=vax-dec
-		;;
-	pdp11)
-		basic_machine=pdp11-dec
-		;;
-	we32k)
-		basic_machine=we32k-att
-		;;
-	sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)
-		basic_machine=sh-unknown
-		;;
-	cydra)
-		basic_machine=cydra-cydrome
-		;;
-	orion)
-		basic_machine=orion-highlevel
-		;;
-	orion105)
-		basic_machine=clipper-highlevel
-		;;
-	mac | mpw | mac-mpw)
-		basic_machine=m68k-apple
-		;;
-	pmac | pmac-mpw)
-		basic_machine=powerpc-apple
-		;;
-	*-unknown)
-		# Make sure to match an already-canonicalized machine name.
-		;;
-	*)
-		echo Invalid configuration \`"$1"\': machine \`"$basic_machine"\' not recognized 1>&2
-		exit 1
-		;;
-esac
-
-# Here we canonicalize certain aliases for manufacturers.
-case $basic_machine in
-	*-digital*)
-		basic_machine=`echo "$basic_machine" | sed 's/digital.*/dec/'`
-		;;
-	*-commodore*)
-		basic_machine=`echo "$basic_machine" | sed 's/commodore.*/cbm/'`
-		;;
-	*)
-		;;
-esac
-
-# Decode manufacturer-specific aliases for certain operating systems.
-
-if [ x"$os" != x"" ]
-then
-case $os in
-	# First match some system type aliases that might get confused
-	# with valid system types.
-	# -solaris* is a basic system type, with this one exception.
-	-auroraux)
-		os=-auroraux
-		;;
-	-solaris1 | -solaris1.*)
-		os=`echo $os | sed -e 's|solaris1|sunos4|'`
-		;;
-	-solaris)
-		os=-solaris2
-		;;
-	-unixware*)
-		os=-sysv4.2uw
-		;;
-	-gnu/linux*)
-		os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
-		;;
-	# es1800 is here to avoid being matched by es* (a different OS)
-	-es1800*)
-		os=-ose
-		;;
-	# Now accept the basic system types.
-	# The portable systems comes first.
-	# Each alternative MUST end in a * to match a version number.
-	# -sysv* is not here because it comes later, after sysvr4.
-	-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
-	      | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
-	      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
-	      | -sym* | -kopensolaris* | -plan9* \
-	      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
-	      | -aos* | -aros* | -cloudabi* | -sortix* \
-	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
-	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
-	      | -hiux* | -knetbsd* | -mirbsd* | -netbsd* \
-	      | -bitrig* | -openbsd* | -solidbsd* | -libertybsd* \
-	      | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
-	      | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
-	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
-	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* | -hcos* \
-	      | -chorusos* | -chorusrdb* | -cegcc* | -glidix* \
-	      | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
-	      | -midipix* | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
-	      | -linux-newlib* | -linux-musl* | -linux-uclibc* \
-	      | -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \
-	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* \
-	      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
-	      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
-	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
-	      | -morphos* | -superux* | -rtmk* | -windiss* \
-	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
-	      | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* \
-	      | -onefs* | -tirtos* | -phoenix* | -fuchsia* | -redox* | -bme* \
-	      | -midnightbsd*)
-	# Remember, each alternative MUST END IN *, to match a version number.
-		;;
-	-qnx*)
-		case $basic_machine in
-		    x86-* | i*86-*)
-			;;
-		    *)
-			os=-nto$os
-			;;
-		esac
-		;;
-	-nto-qnx*)
-		;;
-	-nto*)
-		os=`echo $os | sed -e 's|nto|nto-qnx|'`
-		;;
-	-sim | -xray | -os68k* | -v88r* \
-	      | -windows* | -osx | -abug | -netware* | -os9* \
-	      | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
-		;;
-	-mac*)
-		os=`echo "$os" | sed -e 's|mac|macos|'`
-		;;
-	-linux-dietlibc)
-		os=-linux-dietlibc
-		;;
-	-linux*)
-		os=`echo $os | sed -e 's|linux|linux-gnu|'`
-		;;
-	-sunos5*)
-		os=`echo "$os" | sed -e 's|sunos5|solaris2|'`
-		;;
-	-sunos6*)
-		os=`echo "$os" | sed -e 's|sunos6|solaris3|'`
-		;;
-	-opened*)
-		os=-openedition
-		;;
-	-os400*)
-		os=-os400
-		;;
-	-wince*)
-		os=-wince
-		;;
-	-utek*)
-		os=-bsd
-		;;
-	-dynix*)
-		os=-bsd
-		;;
-	-acis*)
-		os=-aos
-		;;
-	-atheos*)
-		os=-atheos
-		;;
-	-syllable*)
-		os=-syllable
-		;;
-	-386bsd)
-		os=-bsd
-		;;
-	-ctix* | -uts*)
-		os=-sysv
-		;;
-	-nova*)
-		os=-rtmk-nova
-		;;
-	-ns2)
-		os=-nextstep2
-		;;
-	-nsk*)
-		os=-nsk
-		;;
-	# Preserve the version number of sinix5.
-	-sinix5.*)
-		os=`echo $os | sed -e 's|sinix|sysv|'`
-		;;
-	-sinix*)
-		os=-sysv4
-		;;
-	-tpf*)
-		os=-tpf
-		;;
-	-triton*)
-		os=-sysv3
-		;;
-	-oss*)
-		os=-sysv3
-		;;
-	-svr4*)
-		os=-sysv4
-		;;
-	-svr3)
-		os=-sysv3
-		;;
-	-sysvr4)
-		os=-sysv4
-		;;
-	# This must come after -sysvr4.
-	-sysv*)
-		;;
-	-ose*)
-		os=-ose
-		;;
-	-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
-		os=-mint
-		;;
-	-zvmoe)
-		os=-zvmoe
-		;;
-	-dicos*)
-		os=-dicos
-		;;
-	-pikeos*)
-		# Until real need of OS specific support for
-		# particular features comes up, bare metal
-		# configurations are quite functional.
-		case $basic_machine in
-		    arm*)
-			os=-eabi
-			;;
-		    *)
-			os=-elf
-			;;
-		esac
-		;;
-	-nacl*)
-		;;
-	-ios)
-		;;
-	-none)
-		;;
-	*)
-		# Get rid of the `-' at the beginning of $os.
-		os=`echo $os | sed 's/[^-]*-//'`
-		echo Invalid configuration \`"$1"\': system \`"$os"\' not recognized 1>&2
-		exit 1
-		;;
-esac
-else
-
-# Here we handle the default operating systems that come with various machines.
-# The value should be what the vendor currently ships out the door with their
-# machine or put another way, the most popular os provided with the machine.
-
-# Note that if you're going to try to match "-MANUFACTURER" here (say,
-# "-sun"), then you have to tell the case statement up towards the top
-# that MANUFACTURER isn't an operating system.  Otherwise, code above
-# will signal an error saying that MANUFACTURER isn't an operating
-# system, and we'll never get to this point.
-
-case $basic_machine in
-	score-*)
-		os=-elf
-		;;
-	spu-*)
-		os=-elf
-		;;
-	*-acorn)
-		os=-riscix1.2
-		;;
-	arm*-rebel)
-		os=-linux
-		;;
-	arm*-semi)
-		os=-aout
-		;;
-	c4x-* | tic4x-*)
-		os=-coff
-		;;
-	c8051-*)
-		os=-elf
-		;;
-	hexagon-*)
-		os=-elf
-		;;
-	tic54x-*)
-		os=-coff
-		;;
-	tic55x-*)
-		os=-coff
-		;;
-	tic6x-*)
-		os=-coff
-		;;
-	# This must come before the *-dec entry.
-	pdp10-*)
-		os=-tops20
-		;;
-	pdp11-*)
-		os=-none
-		;;
-	*-dec | vax-*)
-		os=-ultrix4.2
-		;;
-	m68*-apollo)
-		os=-domain
-		;;
-	i386-sun)
-		os=-sunos4.0.2
-		;;
-	m68000-sun)
-		os=-sunos3
-		;;
-	m68*-cisco)
-		os=-aout
-		;;
-	mep-*)
-		os=-elf
-		;;
-	mips*-cisco)
-		os=-elf
-		;;
-	mips*-*)
-		os=-elf
-		;;
-	or32-*)
-		os=-coff
-		;;
-	*-tti)	# must be before sparc entry or we get the wrong os.
-		os=-sysv3
-		;;
-	sparc-* | *-sun)
-		os=-sunos4.1.1
-		;;
-	pru-*)
-		os=-elf
-		;;
-	*-be)
-		os=-beos
-		;;
-	*-ibm)
-		os=-aix
-		;;
-	*-knuth)
-		os=-mmixware
-		;;
-	*-wec)
-		os=-proelf
-		;;
-	*-winbond)
-		os=-proelf
-		;;
-	*-oki)
-		os=-proelf
-		;;
-	*-hp)
-		os=-hpux
-		;;
-	*-hitachi)
-		os=-hiux
-		;;
-	i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
-		os=-sysv
-		;;
-	*-cbm)
-		os=-amigaos
-		;;
-	*-dg)
-		os=-dgux
-		;;
-	*-dolphin)
-		os=-sysv3
-		;;
-	m68k-ccur)
-		os=-rtu
-		;;
-	m88k-omron*)
-		os=-luna
-		;;
-	*-next)
-		os=-nextstep
-		;;
-	*-sequent)
-		os=-ptx
-		;;
-	*-crds)
-		os=-unos
-		;;
-	*-ns)
-		os=-genix
-		;;
-	i370-*)
-		os=-mvs
-		;;
-	*-gould)
-		os=-sysv
-		;;
-	*-highlevel)
-		os=-bsd
-		;;
-	*-encore)
-		os=-bsd
-		;;
-	*-sgi)
-		os=-irix
-		;;
-	*-siemens)
-		os=-sysv4
-		;;
-	*-masscomp)
-		os=-rtu
-		;;
-	f30[01]-fujitsu | f700-fujitsu)
-		os=-uxpv
-		;;
-	*-rom68k)
-		os=-coff
-		;;
-	*-*bug)
-		os=-coff
-		;;
-	*-apple)
-		os=-macos
-		;;
-	*-atari*)
-		os=-mint
-		;;
-	*)
-		os=-none
-		;;
-esac
-fi
-
-# Here we handle the case where we know the os, and the CPU type, but not the
-# manufacturer.  We pick the logical manufacturer.
-vendor=unknown
-case $basic_machine in
-	*-unknown)
-		case $os in
-			-riscix*)
-				vendor=acorn
-				;;
-			-sunos*)
-				vendor=sun
-				;;
-			-cnk*|-aix*)
-				vendor=ibm
-				;;
-			-beos*)
-				vendor=be
-				;;
-			-hpux*)
-				vendor=hp
-				;;
-			-mpeix*)
-				vendor=hp
-				;;
-			-hiux*)
-				vendor=hitachi
-				;;
-			-unos*)
-				vendor=crds
-				;;
-			-dgux*)
-				vendor=dg
-				;;
-			-luna*)
-				vendor=omron
-				;;
-			-genix*)
-				vendor=ns
-				;;
-			-mvs* | -opened*)
-				vendor=ibm
-				;;
-			-os400*)
-				vendor=ibm
-				;;
-			-ptx*)
-				vendor=sequent
-				;;
-			-tpf*)
-				vendor=ibm
-				;;
-			-vxsim* | -vxworks* | -windiss*)
-				vendor=wrs
-				;;
-			-aux*)
-				vendor=apple
-				;;
-			-hms*)
-				vendor=hitachi
-				;;
-			-mpw* | -macos*)
-				vendor=apple
-				;;
-			-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
-				vendor=atari
-				;;
-			-vos*)
-				vendor=stratus
-				;;
-		esac
-		basic_machine=`echo "$basic_machine" | sed "s/unknown/$vendor/"`
-		;;
-esac
-
-echo "$basic_machine$os"
-exit
-
-# Local variables:
-# eval: (add-hook 'before-save-hook 'time-stamp)
-# time-stamp-start: "timestamp='"
-# time-stamp-format: "%:y-%02m-%02d"
-# time-stamp-end: "'"
-# End:
diff --git a/configure b/configure
index d5e286a..f43e2f2 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for libevent 2.1.11-stable.
+# Generated by GNU Autoconf 2.69 for libevent 2.1.12-stable.
 #
 #
 # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
@@ -587,12 +587,13 @@
 # Identity of this package.
 PACKAGE_NAME='libevent'
 PACKAGE_TARNAME='libevent'
-PACKAGE_VERSION='2.1.11-stable'
-PACKAGE_STRING='libevent 2.1.11-stable'
+PACKAGE_VERSION='2.1.12-stable'
+PACKAGE_STRING='libevent 2.1.12-stable'
 PACKAGE_BUGREPORT=''
 PACKAGE_URL=''
 
 ac_unique_file="event.c"
+ac_default_prefix=/usr/local
 # Factoring default headers for most tests.
 ac_includes_default="\
 #include <stdio.h>
@@ -632,6 +633,49 @@
 ac_subst_vars='am__EXEEXT_FALSE
 am__EXEEXT_TRUE
 LTLIBOBJS
+ENABLE_DOXYGEN_MAN_FALSE
+ENABLE_DOXYGEN_MAN_TRUE
+ENABLE_DOXYGEN_FALSE
+ENABLE_DOXYGEN_TRUE
+DX_RULES
+PAPER_SIZE
+DOXYGEN_PAPER_SIZE
+GENERATE_LATEX
+DX_PDFLATEX
+DX_FLAG_pdf
+DX_EGREP
+DX_DVIPS
+DX_MAKEINDEX
+DX_LATEX
+DX_FLAG_ps
+DX_FLAG_html
+GENERATE_CHI
+DX_FLAG_chi
+GENERATE_HTMLHELP
+GENERATE_HTML
+HHC_PATH
+DX_HHC
+DX_FLAG_chm
+GENERATE_XML
+DX_FLAG_xml
+GENERATE_RTF
+DX_FLAG_rtf
+GENERATE_MAN
+DX_FLAG_man
+DOT_PATH
+HAVE_DOT
+DX_DOT
+DX_FLAG_dot
+PERL_PATH
+DX_PERL
+DX_DOXYGEN
+DX_FLAG_doc
+PROJECT
+SRCDIR
+DX_ENV
+DX_DOCDIR
+DX_CONFIG
+DX_PROJECT
 INSTALL_LIBEVENT_FALSE
 INSTALL_LIBEVENT_TRUE
 LIBEVENT_GC_SECTIONS
@@ -823,6 +867,16 @@
 with_sysroot
 enable_libtool_lock
 enable_largefile
+enable_doxygen_doc
+enable_doxygen_dot
+enable_doxygen_man
+enable_doxygen_rtf
+enable_doxygen_xml
+enable_doxygen_chm
+enable_doxygen_chi
+enable_doxygen_html
+enable_doxygen_ps
+enable_doxygen_pdf
 '
       ac_precious_vars='build_alias
 host_alias
@@ -833,7 +887,8 @@
 LIBS
 CPPFLAGS
 CPP
-LT_SYS_LIBRARY_PATH'
+LT_SYS_LIBRARY_PATH
+DOXYGEN_PAPER_SIZE'
 
 
 # Initialize some variables set by options.
@@ -1374,7 +1429,7 @@
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures libevent 2.1.11-stable to adapt to many kinds of systems.
+\`configure' configures libevent 2.1.12-stable to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1444,7 +1499,7 @@
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of libevent 2.1.11-stable:";;
+     short | recursive ) echo "Configuration of libevent 2.1.12-stable:";;
    esac
   cat <<\_ACEOF
 
@@ -1484,6 +1539,17 @@
                           optimize for fast installation [default=yes]
   --disable-libtool-lock  avoid locking (might break parallel builds)
   --disable-largefile     omit support for large files
+  --enable-doxygen-doc    generate any doxygen documentation
+  --enable-doxygen-dot    generate graphics for doxygen documentation
+  --enable-doxygen-man    generate doxygen manual pages
+  --enable-doxygen-rtf    generate doxygen RTF documentation
+  --enable-doxygen-xml    generate doxygen XML documentation
+  --enable-doxygen-chm    generate doxygen compressed HTML help documentation
+  --enable-doxygen-chi    generate doxygen separate compressed HTML help index
+                          file
+  --disable-doxygen-html  don't generate doxygen plain HTML documentation
+  --enable-doxygen-ps     generate doxygen PostScript documentation
+  --enable-doxygen-pdf    generate doxygen PDF documentation
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
@@ -1508,6 +1574,8 @@
   CPP         C preprocessor
   LT_SYS_LIBRARY_PATH
               User-defined run-time library search path.
+  DOXYGEN_PAPER_SIZE
+              a4wide (default), a4, letter, legal or executive
 
 Use these variables to override the choices made by `configure' or to help
 it to find libraries and programs with nonstandard names/locations.
@@ -1575,7 +1643,7 @@
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-libevent configure 2.1.11-stable
+libevent configure 2.1.12-stable
 generated by GNU Autoconf 2.69
 
 Copyright (C) 2012 Free Software Foundation, Inc.
@@ -2280,7 +2348,7 @@
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by libevent $as_me 2.1.11-stable, which was
+It was created by libevent $as_me 2.1.12-stable, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   $ $0 $@
@@ -2632,10 +2700,8 @@
 
 
 
-am__api_version='1.16'
-
 ac_aux_dir=
-for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
+for ac_dir in build-aux "$srcdir"/build-aux; do
   if test -f "$ac_dir/install-sh"; then
     ac_aux_dir=$ac_dir
     ac_install_sh="$ac_aux_dir/install-sh -c"
@@ -2651,7 +2717,7 @@
   fi
 done
 if test -z "$ac_aux_dir"; then
-  as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5
+  as_fn_error $? "cannot find install-sh, install.sh, or shtool in build-aux \"$srcdir\"/build-aux" "$LINENO" 5
 fi
 
 # These three variables are undocumented and unsupported,
@@ -2663,6 +2729,8 @@
 ac_configure="$SHELL $ac_aux_dir/configure"  # Please don't use this var.
 
 
+am__api_version='1.16'
+
 # Find a good install program.  We prefer a C program (faster),
 # so one script is as good as another.  But avoid the broken or
 # incompatible versions:
@@ -3147,7 +3215,7 @@
 
 # Define the identity of the package.
  PACKAGE='libevent'
- VERSION='2.1.11-stable'
+ VERSION='2.1.12-stable'
 
 
 cat >>confdefs.h <<_ACEOF
@@ -3282,12 +3350,9 @@
 ac_config_headers="$ac_config_headers config.h evconfig-private.h:evconfig-private.h.in"
 
 
-$as_echo "#define NUMERIC_VERSION 0x02010b00" >>confdefs.h
+$as_echo "#define NUMERIC_VERSION 0x02010c00" >>confdefs.h
 
 
-if test "$prefix" = "NONE"; then
-   prefix="/usr/local"
-fi
 
 
 DEPDIR="${am__leading_dot}deps"
@@ -4789,7 +4854,6 @@
 
 
 
-
 # Make sure we can run config.sub.
 $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
   as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5
@@ -4884,8 +4948,6 @@
 
 # AC_PROG_MKDIR_P - $(MKDIR_P) should be defined by AM_INIT_AUTOMAKE
 
-# AC_PROG_SED is only available in Autoconf >= 2.59b; workaround for older
-# versions
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5
 $as_echo_n "checking for a sed that does not truncate output... " >&6; }
 if ${ac_cv_path_SED+:} false; then :
@@ -5130,6 +5192,7 @@
 
 
 
+
 case `pwd` in
   *\ * | *\	*)
     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5
@@ -5138,7 +5201,7 @@
 
 
 
-macro_version='2.4.6.42-b88ce'
+macro_version='2.4.6.42-b88ce-dirty'
 macro_revision='2.4.6.42'
 
 
@@ -13075,6 +13138,7 @@
 die horribly
 #endif
 
+
   ;
   return 0;
 }
@@ -13085,6 +13149,7 @@
 else
   bwin32=false; { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
+
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
@@ -13101,6 +13166,7 @@
 die horribly
 #endif
 
+
   ;
   return 0;
 }
@@ -13111,6 +13177,7 @@
 else
   midipix=false; { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
+
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
@@ -13127,6 +13194,7 @@
 die horribly
 #endif
 
+
   ;
   return 0;
 }
@@ -13137,6 +13205,7 @@
 else
   cygwin=false; { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
+
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
@@ -13677,6 +13746,11 @@
      yes)
 $as_echo "#define HAVE_OPENSSL 1" >>confdefs.h
  ;;
+     *) as_fn_error $? "openssl is a must but can not be found. You should add the \
+directory containing \`openssl.pc' to the \`PKG_CONFIG_PATH' environment variable, \
+or set \`CFLAGS' and \`LDFLAGS' directly for openssl, or use \`--disable-openssl' \
+to disable support for openssl encryption" "$LINENO" 5
+	;;
     esac
     ;;
 esac
@@ -13697,6 +13771,7 @@
   fcntl.h \
   ifaddrs.h \
   mach/mach_time.h \
+  mach/mach.h \
   netdb.h \
   netinet/in.h \
   netinet/in6.h \
@@ -13723,7 +13798,9 @@
   sys/timerfd.h \
   sys/uio.h \
   sys/wait.h \
+  sys/random.h \
   errno.h \
+  afunix.h \
 
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
@@ -13738,12 +13815,15 @@
 done
 
 
-for ac_header in sys/sysctl.h
+case "${host_os}" in
+    linux*) ;;
+    *)
+        for ac_header in sys/sysctl.h
 do :
   ac_fn_c_check_header_compile "$LINENO" "sys/sysctl.h" "ac_cv_header_sys_sysctl_h" "
-#ifdef HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#endif
+        #ifdef HAVE_SYS_PARAM_H
+        #include <sys/param.h>
+        #endif
 
 "
 if test "x$ac_cv_header_sys_sysctl_h" = xyes; then :
@@ -13755,6 +13835,8 @@
 
 done
 
+esac
+
 if test "x$ac_cv_header_sys_queue_h" = "xyes"; then
 	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for TAILQ_FOREACH in sys/queue.h" >&5
 $as_echo_n "checking for TAILQ_FOREACH in sys/queue.h... " >&6; }
@@ -13909,32 +13991,6 @@
 cat >>confdefs.h <<_ACEOF
 #define HAVE_DECL_CTL_KERN $ac_have_decl
 _ACEOF
-ac_fn_c_check_decl "$LINENO" "KERN_RANDOM" "ac_cv_have_decl_KERN_RANDOM" "#include <sys/types.h>
-	     #include <sys/sysctl.h>
-
-"
-if test "x$ac_cv_have_decl_KERN_RANDOM" = xyes; then :
-  ac_have_decl=1
-else
-  ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_KERN_RANDOM $ac_have_decl
-_ACEOF
-ac_fn_c_check_decl "$LINENO" "RANDOM_UUID" "ac_cv_have_decl_RANDOM_UUID" "#include <sys/types.h>
-	     #include <sys/sysctl.h>
-
-"
-if test "x$ac_cv_have_decl_RANDOM_UUID" = xyes; then :
-  ac_have_decl=1
-else
-  ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_RANDOM_UUID $ac_have_decl
-_ACEOF
 ac_fn_c_check_decl "$LINENO" "KERN_ARND" "ac_cv_have_decl_KERN_ARND" "#include <sys/types.h>
 	     #include <sys/sysctl.h>
 
@@ -13985,61 +14041,45 @@
 
 
 if test x$bwin32 = xtrue; then
-   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing getservbyname" >&5
-$as_echo_n "checking for library containing getservbyname... " >&6; }
-if ${ac_cv_search_getservbyname+:} false; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -lws2_32" >&5
+$as_echo_n "checking for main in -lws2_32... " >&6; }
+if ${ac_cv_lib_ws2_32_main+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  ac_func_search_save_LIBS=$LIBS
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lws2_32  $LIBS"
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char getservbyname ();
+
 int
 main ()
 {
-return getservbyname ();
+return main ();
   ;
   return 0;
 }
 _ACEOF
-for ac_lib in '' ws2_32; do
-  if test -z "$ac_lib"; then
-    ac_res="none required"
-  else
-    ac_res=-l$ac_lib
-    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
-  fi
-  if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_search_getservbyname=$ac_res
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_ws2_32_main=yes
+else
+  ac_cv_lib_ws2_32_main=no
 fi
 rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext
-  if ${ac_cv_search_getservbyname+:} false; then :
-  break
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
 fi
-done
-if ${ac_cv_search_getservbyname+:} false; then :
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ws2_32_main" >&5
+$as_echo "$ac_cv_lib_ws2_32_main" >&6; }
+if test "x$ac_cv_lib_ws2_32_main" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBWS2_32 1
+_ACEOF
 
-else
-  ac_cv_search_getservbyname=no
-fi
-rm conftest.$ac_ext
-LIBS=$ac_func_search_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_getservbyname" >&5
-$as_echo "$ac_cv_search_getservbyname" >&6; }
-ac_res=$ac_cv_search_getservbyname
-if test "$ac_res" != no; then :
-  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+  LIBS="-lws2_32 $LIBS"
 
 fi
+ac_cv_lib_ws2_32=ac_cv_lib_ws2_32_main
 
 fi
 
@@ -14213,11 +14253,7 @@
   getegid \
   geteuid \
   getifaddrs \
-  getnameinfo \
-  getprotobynumber \
   gettimeofday \
-  inet_ntop \
-  inet_pton \
   issetugid \
   mach_absolute_time \
   mmap \
@@ -14241,7 +14277,7 @@
   unsetenv \
   usleep \
   vasprintf \
-  getservbyname \
+  getrandom \
 
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
@@ -14254,6 +14290,34 @@
 fi
 done
 
+
+if test x$bwin32 = xtrue; then :
+  for ac_func in _gmtime64_s
+do :
+  ac_fn_c_check_func "$LINENO" "_gmtime64_s" "ac_cv_func__gmtime64_s"
+if test "x$ac_cv_func__gmtime64_s" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE__GMTIME64_S 1
+_ACEOF
+
+else
+  for ac_func in _gmtime64
+do :
+  ac_fn_c_check_func "$LINENO" "_gmtime64" "ac_cv_func__gmtime64"
+if test "x$ac_cv_func__gmtime64" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE__GMTIME64 1
+_ACEOF
+
+fi
+done
+
+fi
+done
+
+
+fi
+
  if test x"$ac_cv_func_strlcpy" = xno; then
   STRLCPY_IMPL_TRUE=
   STRLCPY_IMPL_FALSE='#'
@@ -14263,6 +14327,145 @@
 fi
 
 
+
+
+if test x$bwin32 = xtrue; then :
+  	if test "x#ifdef _WIN32
+    #include <winsock2.h>
+    #include <ws2tcpip.h>
+    #endif" = "x"; then :
+  as_fn_error $? "header not privided" "$LINENO" 5
+fi
+				if test "x#ifdef _WIN32
+    #include <winsock2.h>
+    #include <ws2tcpip.h>
+    #endif" = "x"; then :
+  as_fn_error $? "header not privided" "$LINENO" 5
+fi
+
+	ac_fn_c_check_decl "$LINENO" "getnameinfo" "ac_cv_have_decl_decl" "		#ifdef _WIN32
+    #include <winsock2.h>
+    #include <ws2tcpip.h>
+    #endif
+"
+if test "x$ac_cv_have_decl_decl" = xyes; then :
+
+$as_echo "#define HAVE_GETNAMEINFO 1" >>confdefs.h
+
+fi
+
+					if test "x#ifdef _WIN32
+    #include <winsock2.h>
+    #include <ws2tcpip.h>
+    #endif" = "x"; then :
+  as_fn_error $? "header not privided" "$LINENO" 5
+fi
+
+	ac_fn_c_check_decl "$LINENO" "getprotobynumber" "ac_cv_have_decl_decl" "		#ifdef _WIN32
+    #include <winsock2.h>
+    #include <ws2tcpip.h>
+    #endif
+"
+if test "x$ac_cv_have_decl_decl" = xyes; then :
+
+$as_echo "#define HAVE_GETPROTOBYNUMBER 1" >>confdefs.h
+
+fi
+
+					if test "x#ifdef _WIN32
+    #include <winsock2.h>
+    #include <ws2tcpip.h>
+    #endif" = "x"; then :
+  as_fn_error $? "header not privided" "$LINENO" 5
+fi
+
+	ac_fn_c_check_decl "$LINENO" "getservbyname" "ac_cv_have_decl_decl" "		#ifdef _WIN32
+    #include <winsock2.h>
+    #include <ws2tcpip.h>
+    #endif
+"
+if test "x$ac_cv_have_decl_decl" = xyes; then :
+
+$as_echo "#define HAVE_GETSERVBYNAME 1" >>confdefs.h
+
+fi
+
+					if test "x#ifdef _WIN32
+    #include <winsock2.h>
+    #include <ws2tcpip.h>
+    #endif" = "x"; then :
+  as_fn_error $? "header not privided" "$LINENO" 5
+fi
+
+	ac_fn_c_check_decl "$LINENO" "inet_ntop" "ac_cv_have_decl_decl" "		#ifdef _WIN32
+    #include <winsock2.h>
+    #include <ws2tcpip.h>
+    #endif
+"
+if test "x$ac_cv_have_decl_decl" = xyes; then :
+
+$as_echo "#define HAVE_INET_NTOP 1" >>confdefs.h
+
+fi
+
+					if test "x#ifdef _WIN32
+    #include <winsock2.h>
+    #include <ws2tcpip.h>
+    #endif" = "x"; then :
+  as_fn_error $? "header not privided" "$LINENO" 5
+fi
+
+	ac_fn_c_check_decl "$LINENO" "inet_pton" "ac_cv_have_decl_decl" "		#ifdef _WIN32
+    #include <winsock2.h>
+    #include <ws2tcpip.h>
+    #endif
+"
+if test "x$ac_cv_have_decl_decl" = xyes; then :
+
+$as_echo "#define HAVE_INET_PTON 1" >>confdefs.h
+
+fi
+
+					if test "x#ifdef _WIN32
+    #include <winsock2.h>
+    #include <ws2tcpip.h>
+    #endif" = "x"; then :
+  as_fn_error $? "header not privided" "$LINENO" 5
+fi
+
+	ac_fn_c_check_decl "$LINENO" "getaddrinfo" "ac_cv_have_decl_decl" "		#ifdef _WIN32
+    #include <winsock2.h>
+    #include <ws2tcpip.h>
+    #endif
+"
+if test "x$ac_cv_have_decl_decl" = xyes; then :
+
+$as_echo "#define HAVE_GETADDRINFO 1" >>confdefs.h
+
+fi
+
+
+
+else
+  for ac_func in getnameinfo getprotobynumber getservbyname inet_ntop inet_pton
+do :
+  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
+fi
+
+
+
+if test x$bwin32 = xfalse; then :
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getaddrinfo" >&5
 $as_echo_n "checking for getaddrinfo... " >&6; }
 if ${libevent_cv_getaddrinfo+:} false; then :
@@ -14424,6 +14627,7 @@
 
 fi
 
+fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for F_SETFD in fcntl.h" >&5
 $as_echo_n "checking for F_SETFD in fcntl.h... " >&6; }
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -14535,9 +14739,11 @@
 		if test "$cross_compiling" = yes; then :
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
+
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
+
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
 #endif
@@ -14552,8 +14758,9 @@
 #include <fcntl.h>
 
 int
-main(int argc, char **argv)
+main ()
 {
+
 	int kq;
 	int n;
 	int fd[2];
@@ -14562,15 +14769,15 @@
 	char buf[80000];
 
 	if (pipe(fd) == -1)
-		exit(1);
+  		return 1;
 	if (fcntl(fd[1], F_SETFL, O_NONBLOCK) == -1)
-		exit(1);
+		return 1;
 
 	while ((n = write(fd[1], buf, sizeof(buf))) == sizeof(buf))
 		;
 
-        if ((kq = kqueue()) == -1)
-		exit(1);
+	if ((kq = kqueue()) == -1)
+		return 1;
 
 	memset(&ev, 0, sizeof(ev));
 	ev.ident = fd[1];
@@ -14578,7 +14785,7 @@
 	ev.flags = EV_ADD | EV_ENABLE;
 	n = kevent(kq, &ev, 1, NULL, 0, NULL);
 	if (n == -1)
-		exit(1);
+		return 1;
 
 	read(fd[0], buf, sizeof(buf));
 
@@ -14586,9 +14793,13 @@
 	ts.tv_nsec = 0;
 	n = kevent(kq, NULL, 0, &ev, 1, &ts);
 	if (n == -1 || n == 0)
-		exit(1);
+		return 1;
 
-	exit(0);
+	return 0;
+
+
+  ;
+  return 0;
 }
 _ACEOF
 if ac_fn_c_try_run "$LINENO"; then :
@@ -14597,7 +14808,7 @@
 
 $as_echo "#define HAVE_WORKING_KQUEUE 1" >>confdefs.h
 
-    havekqueue=yes
+      havekqueue=yes
 
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
@@ -14644,9 +14855,11 @@
 		if test "$cross_compiling" = yes; then :
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
+
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
+
 #include <stdint.h>
 #include <sys/param.h>
 #include <sys/types.h>
@@ -14661,12 +14874,17 @@
 }
 
 int
-main(int argc, char **argv)
+main ()
 {
+
 	int epfd;
 
 	epfd = epoll_create(256);
-	exit (epfd == -1 ? 1 : 0);
+	return (epfd == -1 ? 1 : 0);
+
+
+  ;
+  return 0;
 }
 _ACEOF
 if ac_fn_c_try_run "$LINENO"; then :
@@ -14675,9 +14893,9 @@
 
 $as_echo "#define HAVE_EPOLL 1" >>confdefs.h
 
-    needsignal=yes
-    have_epoll=yes
-    case " $LIBOBJS " in
+      needsignal=yes
+      have_epoll=yes
+      case " $LIBOBJS " in
   *" epoll_sub.$ac_objext "* ) ;;
   *) LIBOBJS="$LIBOBJS epoll_sub.$ac_objext"
  ;;
@@ -15567,6 +15785,9 @@
 #ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif
+#ifdef _WIN32
+#include <winsock2.h>
+#endif
 
 "
 if test "x$ac_cv_type_struct_linger" = xyes; then :
@@ -15590,10 +15811,12 @@
  #else
  #include <sys/socket.h>
  #endif
+
 int
 main ()
 {
 socklen_t x;
+
   ;
   return 0;
 }
@@ -15621,6 +15844,7 @@
 main ()
 {
  const char *cp = __func__;
+
   ;
   return 0;
 }
@@ -15647,6 +15871,7 @@
 main ()
 {
  const char *cp = __FUNCTION__;
+
   ;
   return 0;
 }
@@ -16196,7 +16421,7 @@
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
   # -W is the same as -Wextra
-  CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wmissing-declarations -Wredundant-decls -Wnested-externs -Wbad-function-cast"
+  CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wmissing-declarations -Wnested-externs -Wbad-function-cast"
   if test x$enable_gcc_warnings = xyes; then
     CFLAGS="$CFLAGS -Werror"
   fi
@@ -16330,6 +16555,2046 @@
 fi
 
 
+# Doxygen support
+
+
+
+
+
+
+
+
+
+
+# Files:
+DX_PROJECT=libevent
+
+DX_CONFIG='${top_srcdir}/Doxyfile'
+
+DX_DOCDIR='doxygen'
+
+
+# Environment variables used inside doxygen.cfg:
+DX_ENV="$DX_ENV SRCDIR='$srcdir'"
+SRCDIR=$srcdir
+
+DX_ENV="$DX_ENV PROJECT='$DX_PROJECT'"
+PROJECT=$DX_PROJECT
+
+DX_ENV="$DX_ENV VERSION='$PACKAGE_VERSION'"
+
+
+# Doxygen itself:
+
+
+
+    # Check whether --enable-doxygen-doc was given.
+if test "${enable_doxygen_doc+set}" = set; then :
+  enableval=$enable_doxygen_doc;
+case "$enableval" in
+#(
+y|Y|yes|Yes|YES)
+    DX_FLAG_doc=1
+
+
+;; #(
+n|N|no|No|NO)
+    DX_FLAG_doc=0
+
+;; #(
+*)
+    as_fn_error $? "invalid value '$enableval' given to doxygen-doc" "$LINENO" 5
+;;
+esac
+
+else
+
+DX_FLAG_doc=0
+
+
+
+fi
+
+if test "$DX_FLAG_doc" = 1; then
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}doxygen", so it can be a program name with args.
+set dummy ${ac_tool_prefix}doxygen; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_DX_DOXYGEN+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $DX_DOXYGEN in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_DX_DOXYGEN="$DX_DOXYGEN" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_DX_DOXYGEN="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+DX_DOXYGEN=$ac_cv_path_DX_DOXYGEN
+if test -n "$DX_DOXYGEN"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_DOXYGEN" >&5
+$as_echo "$DX_DOXYGEN" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_path_DX_DOXYGEN"; then
+  ac_pt_DX_DOXYGEN=$DX_DOXYGEN
+  # Extract the first word of "doxygen", so it can be a program name with args.
+set dummy doxygen; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_ac_pt_DX_DOXYGEN+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $ac_pt_DX_DOXYGEN in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_ac_pt_DX_DOXYGEN="$ac_pt_DX_DOXYGEN" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_ac_pt_DX_DOXYGEN="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+ac_pt_DX_DOXYGEN=$ac_cv_path_ac_pt_DX_DOXYGEN
+if test -n "$ac_pt_DX_DOXYGEN"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_DOXYGEN" >&5
+$as_echo "$ac_pt_DX_DOXYGEN" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_pt_DX_DOXYGEN" = x; then
+    DX_DOXYGEN=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DX_DOXYGEN=$ac_pt_DX_DOXYGEN
+  fi
+else
+  DX_DOXYGEN="$ac_cv_path_DX_DOXYGEN"
+fi
+
+if test "$DX_FLAG_doc$DX_DOXYGEN" = 1; then
+    if test "xdoxygen" = "xdoxygen"; then
+        as_fn_error $? "doxygen not found - will not generate any doxygen documentation" "$LINENO" 5
+    else
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: doxygen not found - will not generate any doxygen documentation" >&5
+$as_echo "$as_me: WARNING: doxygen not found - will not generate any doxygen documentation" >&2;}
+    fi
+    DX_FLAG_doc=0
+
+fi
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}perl", so it can be a program name with args.
+set dummy ${ac_tool_prefix}perl; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_DX_PERL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $DX_PERL in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_DX_PERL="$DX_PERL" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_DX_PERL="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+DX_PERL=$ac_cv_path_DX_PERL
+if test -n "$DX_PERL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_PERL" >&5
+$as_echo "$DX_PERL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_path_DX_PERL"; then
+  ac_pt_DX_PERL=$DX_PERL
+  # Extract the first word of "perl", so it can be a program name with args.
+set dummy perl; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_ac_pt_DX_PERL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $ac_pt_DX_PERL in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_ac_pt_DX_PERL="$ac_pt_DX_PERL" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_ac_pt_DX_PERL="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+ac_pt_DX_PERL=$ac_cv_path_ac_pt_DX_PERL
+if test -n "$ac_pt_DX_PERL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_PERL" >&5
+$as_echo "$ac_pt_DX_PERL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_pt_DX_PERL" = x; then
+    DX_PERL=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DX_PERL=$ac_pt_DX_PERL
+  fi
+else
+  DX_PERL="$ac_cv_path_DX_PERL"
+fi
+
+if test "$DX_FLAG_doc$DX_PERL" = 1; then
+    if test "xperl" = "xdoxygen"; then
+        as_fn_error $? "perl not found - will not generate any doxygen documentation" "$LINENO" 5
+    else
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: perl not found - will not generate any doxygen documentation" >&5
+$as_echo "$as_me: WARNING: perl not found - will not generate any doxygen documentation" >&2;}
+    fi
+    DX_FLAG_doc=0
+
+fi
+
+    :
+fi
+if test "$DX_FLAG_doc" = 1; then
+    DX_ENV="$DX_ENV PERL_PATH='$DX_PERL'"
+PERL_PATH=$DX_PERL
+
+    :
+else
+
+    :
+fi
+
+
+# Dot for graphics:
+
+
+
+    # Check whether --enable-doxygen-dot was given.
+if test "${enable_doxygen_dot+set}" = set; then :
+  enableval=$enable_doxygen_dot;
+case "$enableval" in
+#(
+y|Y|yes|Yes|YES)
+    DX_FLAG_dot=1
+
+
+test "$DX_FLAG_doc" = "1" \
+|| as_fn_error $? "doxygen-dot requires doxygen-doc" "$LINENO" 5
+
+;; #(
+n|N|no|No|NO)
+    DX_FLAG_dot=0
+
+;; #(
+*)
+    as_fn_error $? "invalid value '$enableval' given to doxygen-dot" "$LINENO" 5
+;;
+esac
+
+else
+
+DX_FLAG_dot=0
+
+
+test "$DX_FLAG_doc" = "1" || DX_FLAG_dot=0
+
+
+
+fi
+
+if test "$DX_FLAG_dot" = 1; then
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}dot", so it can be a program name with args.
+set dummy ${ac_tool_prefix}dot; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_DX_DOT+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $DX_DOT in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_DX_DOT="$DX_DOT" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_DX_DOT="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+DX_DOT=$ac_cv_path_DX_DOT
+if test -n "$DX_DOT"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_DOT" >&5
+$as_echo "$DX_DOT" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_path_DX_DOT"; then
+  ac_pt_DX_DOT=$DX_DOT
+  # Extract the first word of "dot", so it can be a program name with args.
+set dummy dot; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_ac_pt_DX_DOT+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $ac_pt_DX_DOT in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_ac_pt_DX_DOT="$ac_pt_DX_DOT" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_ac_pt_DX_DOT="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+ac_pt_DX_DOT=$ac_cv_path_ac_pt_DX_DOT
+if test -n "$ac_pt_DX_DOT"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_DOT" >&5
+$as_echo "$ac_pt_DX_DOT" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_pt_DX_DOT" = x; then
+    DX_DOT=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DX_DOT=$ac_pt_DX_DOT
+  fi
+else
+  DX_DOT="$ac_cv_path_DX_DOT"
+fi
+
+if test "$DX_FLAG_dot$DX_DOT" = 1; then
+    if test "xdot" = "xdoxygen"; then
+        as_fn_error $? "dot not found - will not generate graphics for doxygen documentation" "$LINENO" 5
+    else
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: dot not found - will not generate graphics for doxygen documentation" >&5
+$as_echo "$as_me: WARNING: dot not found - will not generate graphics for doxygen documentation" >&2;}
+    fi
+    DX_FLAG_dot=0
+
+fi
+
+    :
+fi
+if test "$DX_FLAG_dot" = 1; then
+    DX_ENV="$DX_ENV HAVE_DOT='YES'"
+HAVE_DOT=YES
+
+             DX_ENV="$DX_ENV DOT_PATH='`expr ".$DX_DOT" : '\(\.\)[^/]*$' \| "x$DX_DOT" : 'x\(.*\)/[^/]*$'`'"
+DOT_PATH=`expr ".$DX_DOT" : '\(\.\)[^/]*$' \| "x$DX_DOT" : 'x\(.*\)/[^/]*$'`
+
+    :
+else
+    DX_ENV="$DX_ENV HAVE_DOT='NO'"
+HAVE_DOT=NO
+
+    :
+fi
+
+
+# Man pages generation:
+
+
+
+    # Check whether --enable-doxygen-man was given.
+if test "${enable_doxygen_man+set}" = set; then :
+  enableval=$enable_doxygen_man;
+case "$enableval" in
+#(
+y|Y|yes|Yes|YES)
+    DX_FLAG_man=1
+
+
+test "$DX_FLAG_doc" = "1" \
+|| as_fn_error $? "doxygen-man requires doxygen-doc" "$LINENO" 5
+
+;; #(
+n|N|no|No|NO)
+    DX_FLAG_man=0
+
+;; #(
+*)
+    as_fn_error $? "invalid value '$enableval' given to doxygen-man" "$LINENO" 5
+;;
+esac
+
+else
+
+DX_FLAG_man=0
+
+
+test "$DX_FLAG_doc" = "1" || DX_FLAG_man=0
+
+
+
+fi
+
+if test "$DX_FLAG_man" = 1; then
+
+    :
+fi
+if test "$DX_FLAG_man" = 1; then
+    DX_ENV="$DX_ENV GENERATE_MAN='YES'"
+GENERATE_MAN=YES
+
+    :
+else
+    DX_ENV="$DX_ENV GENERATE_MAN='NO'"
+GENERATE_MAN=NO
+
+    :
+fi
+
+
+# RTF file generation:
+
+
+
+    # Check whether --enable-doxygen-rtf was given.
+if test "${enable_doxygen_rtf+set}" = set; then :
+  enableval=$enable_doxygen_rtf;
+case "$enableval" in
+#(
+y|Y|yes|Yes|YES)
+    DX_FLAG_rtf=1
+
+
+test "$DX_FLAG_doc" = "1" \
+|| as_fn_error $? "doxygen-rtf requires doxygen-doc" "$LINENO" 5
+
+;; #(
+n|N|no|No|NO)
+    DX_FLAG_rtf=0
+
+;; #(
+*)
+    as_fn_error $? "invalid value '$enableval' given to doxygen-rtf" "$LINENO" 5
+;;
+esac
+
+else
+
+DX_FLAG_rtf=0
+
+
+test "$DX_FLAG_doc" = "1" || DX_FLAG_rtf=0
+
+
+
+fi
+
+if test "$DX_FLAG_rtf" = 1; then
+
+    :
+fi
+if test "$DX_FLAG_rtf" = 1; then
+    DX_ENV="$DX_ENV GENERATE_RTF='YES'"
+GENERATE_RTF=YES
+
+    :
+else
+    DX_ENV="$DX_ENV GENERATE_RTF='NO'"
+GENERATE_RTF=NO
+
+    :
+fi
+
+
+# XML file generation:
+
+
+
+    # Check whether --enable-doxygen-xml was given.
+if test "${enable_doxygen_xml+set}" = set; then :
+  enableval=$enable_doxygen_xml;
+case "$enableval" in
+#(
+y|Y|yes|Yes|YES)
+    DX_FLAG_xml=1
+
+
+test "$DX_FLAG_doc" = "1" \
+|| as_fn_error $? "doxygen-xml requires doxygen-doc" "$LINENO" 5
+
+;; #(
+n|N|no|No|NO)
+    DX_FLAG_xml=0
+
+;; #(
+*)
+    as_fn_error $? "invalid value '$enableval' given to doxygen-xml" "$LINENO" 5
+;;
+esac
+
+else
+
+DX_FLAG_xml=0
+
+
+test "$DX_FLAG_doc" = "1" || DX_FLAG_xml=0
+
+
+
+fi
+
+if test "$DX_FLAG_xml" = 1; then
+
+    :
+fi
+if test "$DX_FLAG_xml" = 1; then
+    DX_ENV="$DX_ENV GENERATE_XML='YES'"
+GENERATE_XML=YES
+
+    :
+else
+    DX_ENV="$DX_ENV GENERATE_XML='NO'"
+GENERATE_XML=NO
+
+    :
+fi
+
+
+# (Compressed) HTML help generation:
+
+
+
+    # Check whether --enable-doxygen-chm was given.
+if test "${enable_doxygen_chm+set}" = set; then :
+  enableval=$enable_doxygen_chm;
+case "$enableval" in
+#(
+y|Y|yes|Yes|YES)
+    DX_FLAG_chm=1
+
+
+test "$DX_FLAG_doc" = "1" \
+|| as_fn_error $? "doxygen-chm requires doxygen-doc" "$LINENO" 5
+
+;; #(
+n|N|no|No|NO)
+    DX_FLAG_chm=0
+
+;; #(
+*)
+    as_fn_error $? "invalid value '$enableval' given to doxygen-chm" "$LINENO" 5
+;;
+esac
+
+else
+
+DX_FLAG_chm=0
+
+
+test "$DX_FLAG_doc" = "1" || DX_FLAG_chm=0
+
+
+
+fi
+
+if test "$DX_FLAG_chm" = 1; then
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}hhc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}hhc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_DX_HHC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $DX_HHC in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_DX_HHC="$DX_HHC" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_DX_HHC="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+DX_HHC=$ac_cv_path_DX_HHC
+if test -n "$DX_HHC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_HHC" >&5
+$as_echo "$DX_HHC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_path_DX_HHC"; then
+  ac_pt_DX_HHC=$DX_HHC
+  # Extract the first word of "hhc", so it can be a program name with args.
+set dummy hhc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_ac_pt_DX_HHC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $ac_pt_DX_HHC in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_ac_pt_DX_HHC="$ac_pt_DX_HHC" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_ac_pt_DX_HHC="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+ac_pt_DX_HHC=$ac_cv_path_ac_pt_DX_HHC
+if test -n "$ac_pt_DX_HHC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_HHC" >&5
+$as_echo "$ac_pt_DX_HHC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_pt_DX_HHC" = x; then
+    DX_HHC=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DX_HHC=$ac_pt_DX_HHC
+  fi
+else
+  DX_HHC="$ac_cv_path_DX_HHC"
+fi
+
+if test "$DX_FLAG_chm$DX_HHC" = 1; then
+    if test "xhhc" = "xdoxygen"; then
+        as_fn_error $? "hhc not found - will not generate doxygen compressed HTML help documentation" "$LINENO" 5
+    else
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: hhc not found - will not generate doxygen compressed HTML help documentation" >&5
+$as_echo "$as_me: WARNING: hhc not found - will not generate doxygen compressed HTML help documentation" >&2;}
+    fi
+    DX_FLAG_chm=0
+
+fi
+
+    :
+fi
+if test "$DX_FLAG_chm" = 1; then
+    DX_ENV="$DX_ENV HHC_PATH='$DX_HHC'"
+HHC_PATH=$DX_HHC
+
+             DX_ENV="$DX_ENV GENERATE_HTML='YES'"
+GENERATE_HTML=YES
+
+             DX_ENV="$DX_ENV GENERATE_HTMLHELP='YES'"
+GENERATE_HTMLHELP=YES
+
+    :
+else
+    DX_ENV="$DX_ENV GENERATE_HTMLHELP='NO'"
+GENERATE_HTMLHELP=NO
+
+    :
+fi
+
+
+# Separate CHI file generation.
+
+
+
+    # Check whether --enable-doxygen-chi was given.
+if test "${enable_doxygen_chi+set}" = set; then :
+  enableval=$enable_doxygen_chi;
+case "$enableval" in
+#(
+y|Y|yes|Yes|YES)
+    DX_FLAG_chi=1
+
+
+test "$DX_FLAG_chm" = "1" \
+|| as_fn_error $? "doxygen-chi requires doxygen-chm" "$LINENO" 5
+
+;; #(
+n|N|no|No|NO)
+    DX_FLAG_chi=0
+
+;; #(
+*)
+    as_fn_error $? "invalid value '$enableval' given to doxygen-chi" "$LINENO" 5
+;;
+esac
+
+else
+
+DX_FLAG_chi=0
+
+
+test "$DX_FLAG_chm" = "1" || DX_FLAG_chi=0
+
+
+
+fi
+
+if test "$DX_FLAG_chi" = 1; then
+
+    :
+fi
+if test "$DX_FLAG_chi" = 1; then
+    DX_ENV="$DX_ENV GENERATE_CHI='YES'"
+GENERATE_CHI=YES
+
+    :
+else
+    DX_ENV="$DX_ENV GENERATE_CHI='NO'"
+GENERATE_CHI=NO
+
+    :
+fi
+
+
+# Plain HTML pages generation:
+
+
+
+    # Check whether --enable-doxygen-html was given.
+if test "${enable_doxygen_html+set}" = set; then :
+  enableval=$enable_doxygen_html;
+case "$enableval" in
+#(
+y|Y|yes|Yes|YES)
+    DX_FLAG_html=1
+
+
+test "$DX_FLAG_doc" = "1" \
+|| as_fn_error $? "doxygen-html requires doxygen-doc" "$LINENO" 5
+
+test "$DX_FLAG_chm" = "0" \
+|| as_fn_error $? "doxygen-html contradicts doxygen-chm" "$LINENO" 5
+
+;; #(
+n|N|no|No|NO)
+    DX_FLAG_html=0
+
+;; #(
+*)
+    as_fn_error $? "invalid value '$enableval' given to doxygen-html" "$LINENO" 5
+;;
+esac
+
+else
+
+DX_FLAG_html=1
+
+
+test "$DX_FLAG_doc" = "1" || DX_FLAG_html=0
+
+
+test "$DX_FLAG_chm" = "0" || DX_FLAG_html=0
+
+
+
+fi
+
+if test "$DX_FLAG_html" = 1; then
+
+    :
+fi
+if test "$DX_FLAG_html" = 1; then
+    DX_ENV="$DX_ENV GENERATE_HTML='YES'"
+GENERATE_HTML=YES
+
+    :
+else
+    test "$DX_FLAG_chm" = 1 || DX_ENV="$DX_ENV GENERATE_HTML='NO'"
+GENERATE_HTML=NO
+
+    :
+fi
+
+
+# PostScript file generation:
+
+
+
+    # Check whether --enable-doxygen-ps was given.
+if test "${enable_doxygen_ps+set}" = set; then :
+  enableval=$enable_doxygen_ps;
+case "$enableval" in
+#(
+y|Y|yes|Yes|YES)
+    DX_FLAG_ps=1
+
+
+test "$DX_FLAG_doc" = "1" \
+|| as_fn_error $? "doxygen-ps requires doxygen-doc" "$LINENO" 5
+
+;; #(
+n|N|no|No|NO)
+    DX_FLAG_ps=0
+
+;; #(
+*)
+    as_fn_error $? "invalid value '$enableval' given to doxygen-ps" "$LINENO" 5
+;;
+esac
+
+else
+
+DX_FLAG_ps=0
+
+
+test "$DX_FLAG_doc" = "1" || DX_FLAG_ps=0
+
+
+
+fi
+
+if test "$DX_FLAG_ps" = 1; then
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}latex", so it can be a program name with args.
+set dummy ${ac_tool_prefix}latex; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_DX_LATEX+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $DX_LATEX in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_DX_LATEX="$DX_LATEX" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_DX_LATEX="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+DX_LATEX=$ac_cv_path_DX_LATEX
+if test -n "$DX_LATEX"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_LATEX" >&5
+$as_echo "$DX_LATEX" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_path_DX_LATEX"; then
+  ac_pt_DX_LATEX=$DX_LATEX
+  # Extract the first word of "latex", so it can be a program name with args.
+set dummy latex; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_ac_pt_DX_LATEX+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $ac_pt_DX_LATEX in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_ac_pt_DX_LATEX="$ac_pt_DX_LATEX" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_ac_pt_DX_LATEX="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+ac_pt_DX_LATEX=$ac_cv_path_ac_pt_DX_LATEX
+if test -n "$ac_pt_DX_LATEX"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_LATEX" >&5
+$as_echo "$ac_pt_DX_LATEX" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_pt_DX_LATEX" = x; then
+    DX_LATEX=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DX_LATEX=$ac_pt_DX_LATEX
+  fi
+else
+  DX_LATEX="$ac_cv_path_DX_LATEX"
+fi
+
+if test "$DX_FLAG_ps$DX_LATEX" = 1; then
+    if test "xlatex" = "xdoxygen"; then
+        as_fn_error $? "latex not found - will not generate doxygen PostScript documentation" "$LINENO" 5
+    else
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: latex not found - will not generate doxygen PostScript documentation" >&5
+$as_echo "$as_me: WARNING: latex not found - will not generate doxygen PostScript documentation" >&2;}
+    fi
+    DX_FLAG_ps=0
+
+fi
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}makeindex", so it can be a program name with args.
+set dummy ${ac_tool_prefix}makeindex; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_DX_MAKEINDEX+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $DX_MAKEINDEX in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_DX_MAKEINDEX="$DX_MAKEINDEX" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_DX_MAKEINDEX="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+DX_MAKEINDEX=$ac_cv_path_DX_MAKEINDEX
+if test -n "$DX_MAKEINDEX"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_MAKEINDEX" >&5
+$as_echo "$DX_MAKEINDEX" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_path_DX_MAKEINDEX"; then
+  ac_pt_DX_MAKEINDEX=$DX_MAKEINDEX
+  # Extract the first word of "makeindex", so it can be a program name with args.
+set dummy makeindex; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_ac_pt_DX_MAKEINDEX+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $ac_pt_DX_MAKEINDEX in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_ac_pt_DX_MAKEINDEX="$ac_pt_DX_MAKEINDEX" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_ac_pt_DX_MAKEINDEX="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+ac_pt_DX_MAKEINDEX=$ac_cv_path_ac_pt_DX_MAKEINDEX
+if test -n "$ac_pt_DX_MAKEINDEX"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_MAKEINDEX" >&5
+$as_echo "$ac_pt_DX_MAKEINDEX" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_pt_DX_MAKEINDEX" = x; then
+    DX_MAKEINDEX=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DX_MAKEINDEX=$ac_pt_DX_MAKEINDEX
+  fi
+else
+  DX_MAKEINDEX="$ac_cv_path_DX_MAKEINDEX"
+fi
+
+if test "$DX_FLAG_ps$DX_MAKEINDEX" = 1; then
+    if test "xmakeindex" = "xdoxygen"; then
+        as_fn_error $? "makeindex not found - will not generate doxygen PostScript documentation" "$LINENO" 5
+    else
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: makeindex not found - will not generate doxygen PostScript documentation" >&5
+$as_echo "$as_me: WARNING: makeindex not found - will not generate doxygen PostScript documentation" >&2;}
+    fi
+    DX_FLAG_ps=0
+
+fi
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}dvips", so it can be a program name with args.
+set dummy ${ac_tool_prefix}dvips; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_DX_DVIPS+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $DX_DVIPS in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_DX_DVIPS="$DX_DVIPS" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_DX_DVIPS="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+DX_DVIPS=$ac_cv_path_DX_DVIPS
+if test -n "$DX_DVIPS"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_DVIPS" >&5
+$as_echo "$DX_DVIPS" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_path_DX_DVIPS"; then
+  ac_pt_DX_DVIPS=$DX_DVIPS
+  # Extract the first word of "dvips", so it can be a program name with args.
+set dummy dvips; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_ac_pt_DX_DVIPS+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $ac_pt_DX_DVIPS in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_ac_pt_DX_DVIPS="$ac_pt_DX_DVIPS" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_ac_pt_DX_DVIPS="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+ac_pt_DX_DVIPS=$ac_cv_path_ac_pt_DX_DVIPS
+if test -n "$ac_pt_DX_DVIPS"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_DVIPS" >&5
+$as_echo "$ac_pt_DX_DVIPS" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_pt_DX_DVIPS" = x; then
+    DX_DVIPS=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DX_DVIPS=$ac_pt_DX_DVIPS
+  fi
+else
+  DX_DVIPS="$ac_cv_path_DX_DVIPS"
+fi
+
+if test "$DX_FLAG_ps$DX_DVIPS" = 1; then
+    if test "xdvips" = "xdoxygen"; then
+        as_fn_error $? "dvips not found - will not generate doxygen PostScript documentation" "$LINENO" 5
+    else
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: dvips not found - will not generate doxygen PostScript documentation" >&5
+$as_echo "$as_me: WARNING: dvips not found - will not generate doxygen PostScript documentation" >&2;}
+    fi
+    DX_FLAG_ps=0
+
+fi
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}egrep", so it can be a program name with args.
+set dummy ${ac_tool_prefix}egrep; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_DX_EGREP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $DX_EGREP in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_DX_EGREP="$DX_EGREP" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_DX_EGREP="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+DX_EGREP=$ac_cv_path_DX_EGREP
+if test -n "$DX_EGREP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_EGREP" >&5
+$as_echo "$DX_EGREP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_path_DX_EGREP"; then
+  ac_pt_DX_EGREP=$DX_EGREP
+  # Extract the first word of "egrep", so it can be a program name with args.
+set dummy egrep; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_ac_pt_DX_EGREP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $ac_pt_DX_EGREP in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_ac_pt_DX_EGREP="$ac_pt_DX_EGREP" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_ac_pt_DX_EGREP="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+ac_pt_DX_EGREP=$ac_cv_path_ac_pt_DX_EGREP
+if test -n "$ac_pt_DX_EGREP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_EGREP" >&5
+$as_echo "$ac_pt_DX_EGREP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_pt_DX_EGREP" = x; then
+    DX_EGREP=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DX_EGREP=$ac_pt_DX_EGREP
+  fi
+else
+  DX_EGREP="$ac_cv_path_DX_EGREP"
+fi
+
+if test "$DX_FLAG_ps$DX_EGREP" = 1; then
+    if test "xegrep" = "xdoxygen"; then
+        as_fn_error $? "egrep not found - will not generate doxygen PostScript documentation" "$LINENO" 5
+    else
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: egrep not found - will not generate doxygen PostScript documentation" >&5
+$as_echo "$as_me: WARNING: egrep not found - will not generate doxygen PostScript documentation" >&2;}
+    fi
+    DX_FLAG_ps=0
+
+fi
+
+    :
+fi
+if test "$DX_FLAG_ps" = 1; then
+
+    :
+else
+
+    :
+fi
+
+
+# PDF file generation:
+
+
+
+    # Check whether --enable-doxygen-pdf was given.
+if test "${enable_doxygen_pdf+set}" = set; then :
+  enableval=$enable_doxygen_pdf;
+case "$enableval" in
+#(
+y|Y|yes|Yes|YES)
+    DX_FLAG_pdf=1
+
+
+test "$DX_FLAG_doc" = "1" \
+|| as_fn_error $? "doxygen-pdf requires doxygen-doc" "$LINENO" 5
+
+;; #(
+n|N|no|No|NO)
+    DX_FLAG_pdf=0
+
+;; #(
+*)
+    as_fn_error $? "invalid value '$enableval' given to doxygen-pdf" "$LINENO" 5
+;;
+esac
+
+else
+
+DX_FLAG_pdf=0
+
+
+test "$DX_FLAG_doc" = "1" || DX_FLAG_pdf=0
+
+
+
+fi
+
+if test "$DX_FLAG_pdf" = 1; then
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}pdflatex", so it can be a program name with args.
+set dummy ${ac_tool_prefix}pdflatex; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_DX_PDFLATEX+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $DX_PDFLATEX in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_DX_PDFLATEX="$DX_PDFLATEX" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_DX_PDFLATEX="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+DX_PDFLATEX=$ac_cv_path_DX_PDFLATEX
+if test -n "$DX_PDFLATEX"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_PDFLATEX" >&5
+$as_echo "$DX_PDFLATEX" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_path_DX_PDFLATEX"; then
+  ac_pt_DX_PDFLATEX=$DX_PDFLATEX
+  # Extract the first word of "pdflatex", so it can be a program name with args.
+set dummy pdflatex; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_ac_pt_DX_PDFLATEX+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $ac_pt_DX_PDFLATEX in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_ac_pt_DX_PDFLATEX="$ac_pt_DX_PDFLATEX" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_ac_pt_DX_PDFLATEX="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+ac_pt_DX_PDFLATEX=$ac_cv_path_ac_pt_DX_PDFLATEX
+if test -n "$ac_pt_DX_PDFLATEX"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_PDFLATEX" >&5
+$as_echo "$ac_pt_DX_PDFLATEX" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_pt_DX_PDFLATEX" = x; then
+    DX_PDFLATEX=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DX_PDFLATEX=$ac_pt_DX_PDFLATEX
+  fi
+else
+  DX_PDFLATEX="$ac_cv_path_DX_PDFLATEX"
+fi
+
+if test "$DX_FLAG_pdf$DX_PDFLATEX" = 1; then
+    if test "xpdflatex" = "xdoxygen"; then
+        as_fn_error $? "pdflatex not found - will not generate doxygen PDF documentation" "$LINENO" 5
+    else
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: pdflatex not found - will not generate doxygen PDF documentation" >&5
+$as_echo "$as_me: WARNING: pdflatex not found - will not generate doxygen PDF documentation" >&2;}
+    fi
+    DX_FLAG_pdf=0
+
+fi
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}makeindex", so it can be a program name with args.
+set dummy ${ac_tool_prefix}makeindex; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_DX_MAKEINDEX+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $DX_MAKEINDEX in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_DX_MAKEINDEX="$DX_MAKEINDEX" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_DX_MAKEINDEX="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+DX_MAKEINDEX=$ac_cv_path_DX_MAKEINDEX
+if test -n "$DX_MAKEINDEX"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_MAKEINDEX" >&5
+$as_echo "$DX_MAKEINDEX" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_path_DX_MAKEINDEX"; then
+  ac_pt_DX_MAKEINDEX=$DX_MAKEINDEX
+  # Extract the first word of "makeindex", so it can be a program name with args.
+set dummy makeindex; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_ac_pt_DX_MAKEINDEX+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $ac_pt_DX_MAKEINDEX in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_ac_pt_DX_MAKEINDEX="$ac_pt_DX_MAKEINDEX" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_ac_pt_DX_MAKEINDEX="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+ac_pt_DX_MAKEINDEX=$ac_cv_path_ac_pt_DX_MAKEINDEX
+if test -n "$ac_pt_DX_MAKEINDEX"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_MAKEINDEX" >&5
+$as_echo "$ac_pt_DX_MAKEINDEX" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_pt_DX_MAKEINDEX" = x; then
+    DX_MAKEINDEX=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DX_MAKEINDEX=$ac_pt_DX_MAKEINDEX
+  fi
+else
+  DX_MAKEINDEX="$ac_cv_path_DX_MAKEINDEX"
+fi
+
+if test "$DX_FLAG_pdf$DX_MAKEINDEX" = 1; then
+    if test "xmakeindex" = "xdoxygen"; then
+        as_fn_error $? "makeindex not found - will not generate doxygen PDF documentation" "$LINENO" 5
+    else
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: makeindex not found - will not generate doxygen PDF documentation" >&5
+$as_echo "$as_me: WARNING: makeindex not found - will not generate doxygen PDF documentation" >&2;}
+    fi
+    DX_FLAG_pdf=0
+
+fi
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}egrep", so it can be a program name with args.
+set dummy ${ac_tool_prefix}egrep; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_DX_EGREP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $DX_EGREP in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_DX_EGREP="$DX_EGREP" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_DX_EGREP="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+DX_EGREP=$ac_cv_path_DX_EGREP
+if test -n "$DX_EGREP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_EGREP" >&5
+$as_echo "$DX_EGREP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_path_DX_EGREP"; then
+  ac_pt_DX_EGREP=$DX_EGREP
+  # Extract the first word of "egrep", so it can be a program name with args.
+set dummy egrep; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_ac_pt_DX_EGREP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $ac_pt_DX_EGREP in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_ac_pt_DX_EGREP="$ac_pt_DX_EGREP" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_ac_pt_DX_EGREP="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+ac_pt_DX_EGREP=$ac_cv_path_ac_pt_DX_EGREP
+if test -n "$ac_pt_DX_EGREP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_EGREP" >&5
+$as_echo "$ac_pt_DX_EGREP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_pt_DX_EGREP" = x; then
+    DX_EGREP=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DX_EGREP=$ac_pt_DX_EGREP
+  fi
+else
+  DX_EGREP="$ac_cv_path_DX_EGREP"
+fi
+
+if test "$DX_FLAG_pdf$DX_EGREP" = 1; then
+    if test "xegrep" = "xdoxygen"; then
+        as_fn_error $? "egrep not found - will not generate doxygen PDF documentation" "$LINENO" 5
+    else
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: egrep not found - will not generate doxygen PDF documentation" >&5
+$as_echo "$as_me: WARNING: egrep not found - will not generate doxygen PDF documentation" >&2;}
+    fi
+    DX_FLAG_pdf=0
+
+fi
+
+    :
+fi
+if test "$DX_FLAG_pdf" = 1; then
+
+    :
+else
+
+    :
+fi
+
+
+# LaTeX generation for PS and/or PDF:
+if test "$DX_FLAG_ps" = 1 || test "$DX_FLAG_pdf" = 1; then
+    DX_ENV="$DX_ENV GENERATE_LATEX='YES'"
+GENERATE_LATEX=YES
+
+else
+    DX_ENV="$DX_ENV GENERATE_LATEX='NO'"
+GENERATE_LATEX=NO
+
+fi
+
+# Paper size for PS and/or PDF:
+
+case "$DOXYGEN_PAPER_SIZE" in
+#(
+"")
+    DOXYGEN_PAPER_SIZE=""
+
+;; #(
+a4wide|a4|letter|legal|executive)
+    DX_ENV="$DX_ENV PAPER_SIZE='$DOXYGEN_PAPER_SIZE'"
+PAPER_SIZE=$DOXYGEN_PAPER_SIZE
+
+;; #(
+*)
+    as_fn_error $? "unknown DOXYGEN_PAPER_SIZE='$DOXYGEN_PAPER_SIZE'" "$LINENO" 5
+;;
+esac
+
+# Rules:
+if test $DX_FLAG_html -eq 1; then :
+  DX_SNIPPET_html="## ------------------------------- ##
+## Rules specific for HTML output. ##
+## ------------------------------- ##
+
+DX_CLEAN_HTML = \$(DX_DOCDIR)/html\\
+                \$(DX_DOCDIR)/html
+
+"
+else
+  DX_SNIPPET_html=""
+fi
+if test $DX_FLAG_chi -eq 1; then :
+  DX_SNIPPET_chi="
+DX_CLEAN_CHI = \$(DX_DOCDIR)/\$(PACKAGE).chi\\
+               \$(DX_DOCDIR)/\$(PACKAGE).chi"
+else
+  DX_SNIPPET_chi=""
+fi
+if test $DX_FLAG_chm -eq 1; then :
+  DX_SNIPPET_chm="## ------------------------------ ##
+## Rules specific for CHM output. ##
+## ------------------------------ ##
+
+DX_CLEAN_CHM = \$(DX_DOCDIR)/chm\\
+               \$(DX_DOCDIR)/chm\
+${DX_SNIPPET_chi}
+
+"
+else
+  DX_SNIPPET_chm=""
+fi
+if test $DX_FLAG_man -eq 1; then :
+  DX_SNIPPET_man="## ------------------------------ ##
+## Rules specific for MAN output. ##
+## ------------------------------ ##
+
+DX_CLEAN_MAN = \$(DX_DOCDIR)/man\\
+               \$(DX_DOCDIR)/man
+
+"
+else
+  DX_SNIPPET_man=""
+fi
+if test $DX_FLAG_rtf -eq 1; then :
+  DX_SNIPPET_rtf="## ------------------------------ ##
+## Rules specific for RTF output. ##
+## ------------------------------ ##
+
+DX_CLEAN_RTF = \$(DX_DOCDIR)/rtf\\
+               \$(DX_DOCDIR)/rtf
+
+"
+else
+  DX_SNIPPET_rtf=""
+fi
+if test $DX_FLAG_xml -eq 1; then :
+  DX_SNIPPET_xml="## ------------------------------ ##
+## Rules specific for XML output. ##
+## ------------------------------ ##
+
+DX_CLEAN_XML = \$(DX_DOCDIR)/xml\\
+               \$(DX_DOCDIR)/xml
+
+"
+else
+  DX_SNIPPET_xml=""
+fi
+if test $DX_FLAG_ps -eq 1; then :
+  DX_SNIPPET_ps="## ----------------------------- ##
+## Rules specific for PS output. ##
+## ----------------------------- ##
+
+DX_CLEAN_PS = \$(DX_DOCDIR)/\$(PACKAGE).ps\\
+              \$(DX_DOCDIR)/\$(PACKAGE).ps
+
+DX_PS_GOAL = doxygen-ps
+
+doxygen-ps: \$(DX_CLEAN_PS)
+
+\$(DX_DOCDIR)/\$(PACKAGE).ps: \$(DX_DOCDIR)/\$(PACKAGE).tag
+	\$(DX_V_LATEX)cd \$(DX_DOCDIR)/latex; \\
+	rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \\
+	\$(DX_LATEX) refman.tex; \\
+	\$(DX_MAKEINDEX) refman.idx; \\
+	\$(DX_LATEX) refman.tex; \\
+	countdown=5; \\
+	while \$(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \\
+	                  refman.log > /dev/null 2>&1 \\
+	   && test \$\$countdown -gt 0; do \\
+	    \$(DX_LATEX) refman.tex; \\
+            countdown=\`expr \$\$countdown - 1\`; \\
+	done; \\
+	\$(DX_DVIPS) -o ../\$(PACKAGE).ps refman.dvi
+
+"
+else
+  DX_SNIPPET_ps=""
+fi
+if test $DX_FLAG_pdf -eq 1; then :
+  DX_SNIPPET_pdf="## ------------------------------ ##
+## Rules specific for PDF output. ##
+## ------------------------------ ##
+
+DX_CLEAN_PDF = \$(DX_DOCDIR)/\$(PACKAGE).pdf\\
+               \$(DX_DOCDIR)/\$(PACKAGE).pdf
+
+DX_PDF_GOAL = doxygen-pdf
+
+doxygen-pdf: \$(DX_CLEAN_PDF)
+
+\$(DX_DOCDIR)/\$(PACKAGE).pdf: \$(DX_DOCDIR)/\$(PACKAGE).tag
+	\$(DX_V_LATEX)cd \$(DX_DOCDIR)/latex; \\
+	rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \\
+	\$(DX_PDFLATEX) refman.tex; \\
+	\$(DX_MAKEINDEX) refman.idx; \\
+	\$(DX_PDFLATEX) refman.tex; \\
+	countdown=5; \\
+	while \$(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \\
+	                  refman.log > /dev/null 2>&1 \\
+	   && test \$\$countdown -gt 0; do \\
+	    \$(DX_PDFLATEX) refman.tex; \\
+	    countdown=\`expr \$\$countdown - 1\`; \\
+	done; \\
+	mv refman.pdf ../\$(PACKAGE).pdf
+
+"
+else
+  DX_SNIPPET_pdf=""
+fi
+if test $DX_FLAG_ps -eq 1 -o $DX_FLAG_pdf -eq 1; then :
+  DX_SNIPPET_latex="## ------------------------------------------------- ##
+## Rules specific for LaTeX (shared for PS and PDF). ##
+## ------------------------------------------------- ##
+
+DX_V_LATEX = \$(_DX_v_LATEX_\$(V))
+_DX_v_LATEX_ = \$(_DX_v_LATEX_\$(AM_DEFAULT_VERBOSITY))
+_DX_v_LATEX_0 = @echo \"  LATEX \" \$@;
+
+DX_CLEAN_LATEX = \$(DX_DOCDIR)/latex\\
+                 \$(DX_DOCDIR)/latex
+
+"
+else
+  DX_SNIPPET_latex=""
+fi
+
+if test $DX_FLAG_doc -eq 1; then :
+  DX_SNIPPET_doc="## --------------------------------- ##
+## Format-independent Doxygen rules. ##
+## --------------------------------- ##
+
+${DX_SNIPPET_html}\
+${DX_SNIPPET_chm}\
+${DX_SNIPPET_man}\
+${DX_SNIPPET_rtf}\
+${DX_SNIPPET_xml}\
+${DX_SNIPPET_ps}\
+${DX_SNIPPET_pdf}\
+${DX_SNIPPET_latex}\
+DX_V_DXGEN = \$(_DX_v_DXGEN_\$(V))
+_DX_v_DXGEN_ = \$(_DX_v_DXGEN_\$(AM_DEFAULT_VERBOSITY))
+_DX_v_DXGEN_0 = @echo \"  DXGEN \" \$<;
+
+.PHONY: doxygen-run doxygen-doc \$(DX_PS_GOAL) \$(DX_PDF_GOAL)
+
+.INTERMEDIATE: doxygen-run \$(DX_PS_GOAL) \$(DX_PDF_GOAL)
+
+doxygen-run: \$(DX_DOCDIR)/\$(PACKAGE).tag
+
+doxygen-doc: doxygen-run \$(DX_PS_GOAL) \$(DX_PDF_GOAL)
+
+\$(DX_DOCDIR)/\$(PACKAGE).tag: \$(DX_CONFIG) \$(pkginclude_HEADERS)
+	\$(A""M_V_at)rm -rf \$(DX_DOCDIR)
+	\$(DX_V_DXGEN)\$(DX_ENV) DOCDIR=\$(DX_DOCDIR) \$(DX_DOXYGEN) \$(DX_CONFIG)
+	\$(A""M_V_at)echo Timestamp >\$@
+
+DX_CLEANFILES = \\
+	\$(DX_DOCDIR)/doxygen_sqlite3.db \\
+	\$(DX_DOCDIR)/\$(PACKAGE).tag \\
+	-r \\
+	\$(DX_CLEAN_HTML) \\
+	\$(DX_CLEAN_CHM) \\
+	\$(DX_CLEAN_CHI) \\
+	\$(DX_CLEAN_MAN) \\
+	\$(DX_CLEAN_RTF) \\
+	\$(DX_CLEAN_XML) \\
+	\$(DX_CLEAN_PS) \\
+	\$(DX_CLEAN_PDF) \\
+	\$(DX_CLEAN_LATEX)
+DX_INSTALL_DOCS = \\
+	\$(DX_CLEAN_HTML) \\
+	\$(DX_CLEAN_CHM) \\
+	\$(DX_CLEAN_CHI) \\
+	\$(DX_CLEAN_RTF) \\
+	\$(DX_CLEAN_XML) \\
+	\$(DX_CLEAN_PS) \\
+	\$(DX_CLEAN_PDF) \\
+	\$(DX_CLEAN_LATEX)
+    "
+else
+  DX_SNIPPET_doc=""
+fi
+DX_RULES="${DX_SNIPPET_doc}"
+
+
+#For debugging:
+#echo DX_FLAG_doc=$DX_FLAG_doc
+#echo DX_FLAG_dot=$DX_FLAG_dot
+#echo DX_FLAG_man=$DX_FLAG_man
+#echo DX_FLAG_html=$DX_FLAG_html
+#echo DX_FLAG_chm=$DX_FLAG_chm
+#echo DX_FLAG_chi=$DX_FLAG_chi
+#echo DX_FLAG_rtf=$DX_FLAG_rtf
+#echo DX_FLAG_xml=$DX_FLAG_xml
+#echo DX_FLAG_pdf=$DX_FLAG_pdf
+#echo DX_FLAG_ps=$DX_FLAG_ps
+#echo DX_ENV=$DX_ENV
+
+
+ if test "$DX_FLAG_doc" = "1"; then
+  ENABLE_DOXYGEN_TRUE=
+  ENABLE_DOXYGEN_FALSE='#'
+else
+  ENABLE_DOXYGEN_TRUE='#'
+  ENABLE_DOXYGEN_FALSE=
+fi
+
+ if test "$DX_FLAG_man" = "1"; then
+  ENABLE_DOXYGEN_MAN_TRUE=
+  ENABLE_DOXYGEN_MAN_FALSE='#'
+else
+  ENABLE_DOXYGEN_MAN_TRUE='#'
+  ENABLE_DOXYGEN_MAN_FALSE=
+fi
+
+
 ac_config_files="$ac_config_files libevent.pc libevent_openssl.pc libevent_pthreads.pc libevent_core.pc libevent_extra.pc"
 
 ac_config_files="$ac_config_files Makefile"
@@ -16547,6 +18812,14 @@
   as_fn_error $? "conditional \"INSTALL_LIBEVENT\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${ENABLE_DOXYGEN_TRUE}" && test -z "${ENABLE_DOXYGEN_FALSE}"; then
+  as_fn_error $? "conditional \"ENABLE_DOXYGEN\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${ENABLE_DOXYGEN_MAN_TRUE}" && test -z "${ENABLE_DOXYGEN_MAN_FALSE}"; then
+  as_fn_error $? "conditional \"ENABLE_DOXYGEN_MAN\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 
 : "${CONFIG_STATUS=./config.status}"
 ac_write_fail=0
@@ -16944,7 +19217,7 @@
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by libevent $as_me 2.1.11-stable, which was
+This file was extended by libevent $as_me 2.1.12-stable, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -17010,7 +19283,7 @@
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-libevent config.status 2.1.11-stable
+libevent config.status 2.1.12-stable
 configured by $0, generated by GNU Autoconf 2.69,
   with options \\"\$ac_cs_config\\"
 
@@ -18109,7 +20382,9 @@
     { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
 as_fn_error $? "Something went wrong bootstrapping makefile fragments
-    for automatic dependency tracking.  Try re-running configure with the
+    for automatic dependency tracking.  If GNU make was not used, consider
+    re-running the configure script with MAKE=\"gmake\" (or whatever is
+    necessary).  You can also try re-running configure with the
     '--disable-dependency-tracking' option to at least be able to build
     the package (albeit without support for automatic dependency tracking).
 See \`config.log' for more details" "$LINENO" 5; }
@@ -18136,7 +20411,6 @@
     cat <<_LT_EOF >> "$cfgfile"
 #! $SHELL
 # Generated automatically by $as_me ($PACKAGE) $VERSION
-# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
 # NOTE: Changes made to this file will be lost: look at ltmain.sh.
 
 # Provide generalized library-building support services.
diff --git a/configure.ac b/configure.ac
index 298d3ab..d00e063 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5,30 +5,23 @@
 dnl
 dnl Original version Dug Song <dugsong@monkey.org>
 
-AC_INIT(libevent,2.1.11-stable)
-AC_PREREQ(2.62)
+AC_INIT(libevent,2.1.12-stable)
+AC_PREREQ(2.67)
 AC_CONFIG_SRCDIR(event.c)
 
 AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_AUX_DIR([build-aux])
 AM_INIT_AUTOMAKE
 dnl AM_SILENT_RULES req. automake 1.11.  [no] defaults V=1
-m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
+AM_SILENT_RULES([yes])
 AC_CONFIG_HEADERS(config.h  evconfig-private.h:evconfig-private.h.in)
-AC_DEFINE(NUMERIC_VERSION, 0x02010b00, [Numeric representation of the version])
+AC_DEFINE(NUMERIC_VERSION, 0x02010c00, [Numeric representation of the version])
 
 dnl Initialize prefix.
-if test "$prefix" = "NONE"; then
-   prefix="/usr/local"
-fi
+AC_PREFIX_DEFAULT([/usr/local])
 
 dnl Try and get a full POSIX environment on obscure systems
-ifdef([AC_USE_SYSTEM_EXTENSIONS], [
 AC_USE_SYSTEM_EXTENSIONS
-], [
-AC_AIX
-AC_GNU_SOURCE
-AC_MINIX
-])
 
 AC_CANONICAL_BUILD
 AC_CANONICAL_HOST
@@ -48,11 +41,7 @@
 AC_PROG_LN_S
 # AC_PROG_MKDIR_P - $(MKDIR_P) should be defined by AM_INIT_AUTOMAKE
 
-# AC_PROG_SED is only available in Autoconf >= 2.59b; workaround for older
-# versions
-ifdef([AC_PROG_SED], [AC_PROG_SED], [
-AC_CHECK_PROGS(SED, [gsed sed])
-])
+AC_PROG_SED
 
 AC_PROG_GCC_TRADITIONAL
 
@@ -126,7 +115,8 @@
   [], [enable_clock_gettime=yes])
 
 
-AC_PROG_LIBTOOL
+LT_PREREQ([2.4.2])
+LT_INIT
 
 dnl   Uncomment "AC_DISABLE_SHARED" to make shared libraries not get
 dnl   built by default.  You can also turn shared libs on and off from
@@ -150,40 +140,46 @@
 dnl - check if the macro _WIN32 is defined on this compiler.
 dnl - (this is how we check for a windows compiler)
 AC_MSG_CHECKING(for WIN32)
-AC_TRY_COMPILE(,
-	[
+AC_COMPILE_IFELSE(
+  [AC_LANG_PROGRAM([],
+    [
 #ifndef _WIN32
 die horribly
 #endif
-	],
-	bwin32=true; AC_MSG_RESULT(yes),
-	bwin32=false; AC_MSG_RESULT(no),
+    ]
+  )],
+	[bwin32=true; AC_MSG_RESULT(yes)],
+	[bwin32=false; AC_MSG_RESULT(no)]
 )
 
 dnl - check if the macro __midipix__ is defined on this compiler.
 dnl - (this is how we check for a midipix version of GCC)
 AC_MSG_CHECKING(for MIDIPIX)
-AC_TRY_COMPILE(,
-	[
+AC_COMPILE_IFELSE(
+  [AC_LANG_PROGRAM([],
+    [
 #ifndef __midipix__
 die horribly
 #endif
-	],
-	midipix=true; AC_MSG_RESULT(yes),
-	midipix=false; AC_MSG_RESULT(no),
+    ]
+  )],
+	[midipix=true; AC_MSG_RESULT(yes)],
+	[midipix=false; AC_MSG_RESULT(no)]
 )
 
 dnl - check if the macro __CYGWIN__ is defined on this compiler.
 dnl - (this is how we check for a cygwin version of GCC)
 AC_MSG_CHECKING(for CYGWIN)
-AC_TRY_COMPILE(,
-	[
+AC_COMPILE_IFELSE(
+  [AC_LANG_PROGRAM([],
+    [
 #ifndef __CYGWIN__
 die horribly
 #endif
-	],
-	cygwin=true; AC_MSG_RESULT(yes),
-	cygwin=false; AC_MSG_RESULT(no),
+    ]
+  )],
+	[cygwin=true; AC_MSG_RESULT(yes)],
+	[cygwin=false; AC_MSG_RESULT(no)]
 )
 
 AC_CHECK_HEADERS([zlib.h])
@@ -226,6 +222,7 @@
   fcntl.h \
   ifaddrs.h \
   mach/mach_time.h \
+  mach/mach.h \
   netdb.h \
   netinet/in.h \
   netinet/in6.h \
@@ -252,14 +249,21 @@
   sys/timerfd.h \
   sys/uio.h \
   sys/wait.h \
+  sys/random.h \
   errno.h \
+  afunix.h \
 ])
 
-AC_CHECK_HEADERS(sys/sysctl.h, [], [], [
-#ifdef HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#endif
-])
+case "${host_os}" in
+    linux*) ;;
+    *)
+        AC_CHECK_HEADERS(sys/sysctl.h, [], [], [
+        #ifdef HAVE_SYS_PARAM_H
+        #include <sys/param.h>
+        #endif
+        ])
+esac
+
 if test "x$ac_cv_header_sys_queue_h" = "xyes"; then
 	AC_MSG_CHECKING(for TAILQ_FOREACH in sys/queue.h)
 	AC_EGREP_CPP(yes,
@@ -332,7 +336,7 @@
 fi
 
 if test "x$ac_cv_header_sys_sysctl_h" = "xyes"; then
-	AC_CHECK_DECLS([CTL_KERN, KERN_RANDOM, RANDOM_UUID, KERN_ARND], [], [],
+	AC_CHECK_DECLS([CTL_KERN, KERN_ARND], [], [],
 	   [[#include <sys/types.h>
 	     #include <sys/sysctl.h>]]
 	)
@@ -344,7 +348,7 @@
 AM_CONDITIONAL(BUILD_WITH_NO_UNDEFINED, test x$bwin32 = xtrue || test x$cygwin = xtrue || test x$midipix = xtrue)
 
 if test x$bwin32 = xtrue; then
-   AC_SEARCH_LIBS([getservbyname],[ws2_32])
+  AC_HAVE_LIBRARY([ws2_32])
 fi
 
 dnl Checks for typedefs, structures, and compiler characteristics.
@@ -364,11 +368,7 @@
   getegid \
   geteuid \
   getifaddrs \
-  getnameinfo \
-  getprotobynumber \
   gettimeofday \
-  inet_ntop \
-  inet_pton \
   issetugid \
   mach_absolute_time \
   mmap \
@@ -392,10 +392,36 @@
   unsetenv \
   usleep \
   vasprintf \
-  getservbyname \
+  getrandom \
 ])
+
+AS_IF([test x$bwin32 = xtrue],
+  AC_CHECK_FUNCS(_gmtime64_s, , [AC_CHECK_FUNCS(_gmtime64)])
+)
+
 AM_CONDITIONAL(STRLCPY_IMPL, [test x"$ac_cv_func_strlcpy" = xno])
 
+m4_define([funcstochk],
+  [getnameinfo
+  getprotobynumber
+  getservbyname
+  inet_ntop
+  inet_pton]
+)
+
+AS_IF([test x$bwin32 = xtrue],
+  [AX_CHECK_DECLS_EX([funcstochk getaddrinfo],
+    [#ifdef _WIN32
+    #include <winsock2.h>
+    #include <ws2tcpip.h>
+    #endif])],
+  [AC_CHECK_FUNCS(m4_normalize(funcstochk))]
+)
+
+m4_undefine([funcstochk])
+
+dnl check getaddrinfo and gethostbyname_r for non-windows
+AS_IF([test x$bwin32 = xfalse], [
 AC_CACHE_CHECK(
     [for getaddrinfo],
     [libevent_cv_getaddrinfo],
@@ -441,27 +467,27 @@
      [Define this if gethostbyname_r takes 6 arguments])
     AC_MSG_RESULT(6)
   ], [
-    AC_TRY_COMPILE([
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
 #include <netdb.h>
     ], [
       char *cp1, *cp2;
       struct hostent *h1;
       int i1, i2;
       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
-    ], [
+    ])], [
       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
         [Define this if gethostbyname_r takes 5 arguments])
       AC_MSG_RESULT(5)
-   ], [
-      AC_TRY_COMPILE([
+    ], [
+      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
 #include <netdb.h>
      ], [
        char *cp1;
        struct hostent *h1;
        struct hostent_data hd;
        (void) gethostbyname_r(cp1,h1,&hd);
-     ], [
+     ])], [
        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
          [Define this if gethostbyname_r takes 3 arguments])
@@ -475,6 +501,7 @@
 ])
 
 fi
+]) dnl end of checking getaddrinfo and gethostbyname_r
 
 AC_MSG_CHECKING(for F_SETFD in fcntl.h)
 AC_EGREP_CPP(yes,
@@ -517,7 +544,8 @@
 	AC_CHECK_FUNCS(kqueue, [havekqueue=yes], )
 	if test "x$havekqueue" = "xyes" ; then
 		AC_MSG_CHECKING(for working kqueue)
-		AC_TRY_RUN(
+		AC_RUN_IFELSE(
+      [AC_LANG_PROGRAM([
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
 #endif
@@ -530,50 +558,50 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
-
-int
-main(int argc, char **argv)
-{
+        ], [[
 	int kq;
 	int n;
-	int fd[[2]];
+	int fd[2];
 	struct kevent ev;
 	struct timespec ts;
-	char buf[[80000]];
+	char buf[80000];
 
 	if (pipe(fd) == -1)
-		exit(1);
-	if (fcntl(fd[[1]], F_SETFL, O_NONBLOCK) == -1)
-		exit(1);
+  		return 1;
+	if (fcntl(fd[1], F_SETFL, O_NONBLOCK) == -1)
+		return 1;
 
-	while ((n = write(fd[[1]], buf, sizeof(buf))) == sizeof(buf))
+	while ((n = write(fd[1], buf, sizeof(buf))) == sizeof(buf))
 		;
 
-        if ((kq = kqueue()) == -1)
-		exit(1);
+	if ((kq = kqueue()) == -1)
+		return 1;
 
 	memset(&ev, 0, sizeof(ev));
-	ev.ident = fd[[1]];
+	ev.ident = fd[1];
 	ev.filter = EVFILT_WRITE;
 	ev.flags = EV_ADD | EV_ENABLE;
 	n = kevent(kq, &ev, 1, NULL, 0, NULL);
 	if (n == -1)
-		exit(1);
+		return 1;
 
-	read(fd[[0]], buf, sizeof(buf));
+	read(fd[0], buf, sizeof(buf));
 
 	ts.tv_sec = 0;
 	ts.tv_nsec = 0;
 	n = kevent(kq, NULL, 0, &ev, 1, &ts);
 	if (n == -1 || n == 0)
-		exit(1);
+		return 1;
 
-	exit(0);
-}, [AC_MSG_RESULT(yes)
-    AC_DEFINE(HAVE_WORKING_KQUEUE, 1,
-		[Define if kqueue works correctly with pipes])
-    havekqueue=yes
-    ], AC_MSG_RESULT(no), AC_MSG_RESULT(no))
+	return 0;
+        ]]
+      )],
+      [AC_MSG_RESULT(yes)
+      AC_DEFINE(HAVE_WORKING_KQUEUE, 1,
+        [Define if kqueue works correctly with pipes])
+      havekqueue=yes
+      ], [AC_MSG_RESULT(no)], [AC_MSG_RESULT(no)]
+    )
 	fi
 fi
 AM_CONDITIONAL(KQUEUE_BACKEND, [test "x$havekqueue" = "xyes"])
@@ -589,7 +617,8 @@
 if test "x$ac_cv_header_sys_epoll_h" = "xyes"; then
 	if test "x$haveepoll" = "xno" ; then
 		AC_MSG_CHECKING(for epoll system call)
-		AC_TRY_RUN(
+		AC_RUN_IFELSE(
+      [AC_LANG_PROGRAM([[
 #include <stdint.h>
 #include <sys/param.h>
 #include <sys/types.h>
@@ -602,21 +631,21 @@
 {
 	return (syscall(__NR_epoll_create, size));
 }
-
-int
-main(int argc, char **argv)
-{
+        ]],[[
 	int epfd;
 
 	epfd = epoll_create(256);
-	exit (epfd == -1 ? 1 : 0);
-}, [AC_MSG_RESULT(yes)
-    AC_DEFINE(HAVE_EPOLL, 1,
-	[Define if your system supports the epoll system calls])
-    needsignal=yes
-    have_epoll=yes
-    AC_LIBOBJ(epoll_sub)
-    ], AC_MSG_RESULT(no), AC_MSG_RESULT(no))
+	return (epfd == -1 ? 1 : 0);
+        ]]
+      )], 
+      [AC_MSG_RESULT(yes)
+      AC_DEFINE(HAVE_EPOLL, 1,
+	      [Define if your system supports the epoll system calls])
+      needsignal=yes
+      have_epoll=yes
+      AC_LIBOBJ(epoll_sub)
+      ], [AC_MSG_RESULT(no)], [AC_MSG_RESULT(no)]
+    )
 	fi
 fi
 AM_CONDITIONAL(EPOLL_BACKEND, [test "x$haveepoll" = "xyes"])
@@ -726,39 +755,48 @@
 #ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif
+#ifdef _WIN32
+#include <winsock2.h>
+#endif
 ])
 
 AC_MSG_CHECKING([for socklen_t])
-AC_TRY_COMPILE([
+AC_COMPILE_IFELSE(
+  [AC_LANG_PROGRAM([
  #include <sys/types.h>
  #ifdef _WIN32
  #include <ws2tcpip.h>
  #else
  #include <sys/socket.h>
- #endif],
-  [socklen_t x;],
-  AC_MSG_RESULT([yes]),
+ #endif
+    ],[socklen_t x;]
+  )],
+	[AC_MSG_RESULT([yes])],
   [AC_MSG_RESULT([no])
   AC_DEFINE(socklen_t, unsigned int,
-	[Define to unsigned int if you dont have it])]
+	  [Define to unsigned int if you dont have it])]
 )
 
 # __func__/__FUNCTION__ is not a macros in general
 AC_MSG_CHECKING([whether our compiler supports __func__])
-AC_TRY_COMPILE([],
-  [ const char *cp = __func__; ],
-  [ AC_DEFINE(HAVE___func__, 1, [Define to 1 if compiler have __func__])
+AC_COMPILE_IFELSE(
+  [AC_LANG_PROGRAM([],
+    [ const char *cp = __func__; ]
+  )],
+	[ AC_DEFINE(HAVE___func__, 1, [Define to 1 if compiler have __func__])
     AC_MSG_RESULT([yes])
   ],
-  AC_MSG_RESULT([no])
+  [AC_MSG_RESULT([no])]
 )
 AC_MSG_CHECKING([whether our compiler supports __FUNCTION__])
-AC_TRY_COMPILE([],
-  [ const char *cp = __FUNCTION__; ],
-  [ AC_DEFINE(HAVE___FUNCTION__, 1, [Define to 1 if compiler have __FUNCTION__])
+AC_COMPILE_IFELSE(
+  [AC_LANG_PROGRAM([],
+    [ const char *cp = __FUNCTION__; ]
+  )],
+	[ AC_DEFINE(HAVE___FUNCTION__, 1, [Define to 1 if compiler have __FUNCTION__])
     AC_MSG_RESULT([yes])
   ],
-  AC_MSG_RESULT([no])
+  [AC_MSG_RESULT([no])]
 )
 
 # check if we can compile with pthreads
@@ -828,7 +866,7 @@
 #endif])], have_clang=yes, have_clang=no)
 
   # -W is the same as -Wextra
-  CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wmissing-declarations -Wredundant-decls -Wnested-externs -Wbad-function-cast"
+  CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wmissing-declarations -Wnested-externs -Wbad-function-cast"
   if test x$enable_gcc_warnings = xyes; then
     CFLAGS="$CFLAGS -Werror"
   fi
@@ -951,5 +989,19 @@
 
 AM_CONDITIONAL([INSTALL_LIBEVENT], [test "$enable_libevent_install" = "yes"])
 
+# Doxygen support
+DX_HTML_FEATURE(ON)
+DX_MAN_FEATURE(OFF)
+DX_RTF_FEATURE(OFF)
+DX_XML_FEATURE(OFF)
+DX_PDF_FEATURE(OFF)
+DX_PS_FEATURE(OFF)
+DX_CHM_FEATURE(OFF)
+DX_CHI_FEATURE(OFF)
+DX_INIT_DOXYGEN([libevent], [${top_srcdir}/Doxyfile], [doxygen])
+
+AM_CONDITIONAL([ENABLE_DOXYGEN], [test "$DX_FLAG_doc" = "1"])
+AM_CONDITIONAL([ENABLE_DOXYGEN_MAN], [test "$DX_FLAG_man" = "1"])
+
 AC_CONFIG_FILES( [libevent.pc libevent_openssl.pc libevent_pthreads.pc libevent_core.pc libevent_extra.pc] )
 AC_OUTPUT(Makefile)
diff --git a/doxygen.am b/doxygen.am
new file mode 100644
index 0000000..916d7c4
--- /dev/null
+++ b/doxygen.am
@@ -0,0 +1,55 @@
+# Doxygen documentation will not be generated with default configuration,
+# unless '--enable-doxygen-doc' is configured.
+# The following targets are all about doxygen:
+# make                # 'make doxygen' would be auto executed
+# make doxygen        # generating doxygen documentation
+# make doxygen-doc    # same as 'make doxygen'
+# make clean          # clean docs generated by doxygen
+# make install        # install doxygen documentation
+# make uninstall      # uninstall doxygen documentation
+
+if ENABLE_DOXYGEN
+
+# Add all needed rules defined in ax_prog_doxygen.m4
+@DX_RULES@
+
+# Use 'make clean' to clean docs generated by doxygen.
+clean-local:
+	-rm -rf $(DX_CLEANFILES)
+
+# integrate doxygen with automake targets
+man3_MANS = @DX_DOCDIR@/man/man3/*
+$(man3_MANS): doxygen-doc
+
+# Docs will be installed. It may be one or more docs supported
+# by doxygen, but does not include 'man'.
+docdirs = $(DX_INSTALL_DOCS)
+
+# Rules for installing docs generated by doxygen into $(htmldir),
+# The typical value of $(htmldir) is '/usr/local/share/doc/$(PACKAGE)'
+install-data-local:
+	@if ! test -d "$(DESTDIR)$(htmldir)"; then \
+	  echo "$(mkinstalldirs) '$(DESTDIR)$(htmldir)'"; \
+	  $(mkinstalldirs) '$(DESTDIR)$(htmldir)'; \
+	fi
+	@for d in $(docdirs); do \
+	  echo "cp -pR $$d '$(DESTDIR)$(htmldir)/'"; \
+	  cp -pR $$d '$(DESTDIR)$(htmldir)/'; \
+	done
+
+# Rules for uninstalling docs generated by doxygen from $(htmldir)
+uninstall-local:
+	@for d in $(docdirs); do \
+	  d=`basename $$d`; \
+	  echo "test ! -d '$(DESTDIR)$(htmldir)/'$$d || \
+	  { find '$(DESTDIR)$(htmldir)/'$$d -type d ! -perm -200 -exec chmod u+w '{}' ';' && \
+	  rm -rf '$(DESTDIR)$(htmldir)/'$$d; }"; \
+	  test ! -d '$(DESTDIR)$(htmldir)/'$$d || \
+	  { find '$(DESTDIR)$(htmldir)/'$$d -type d ! -perm -200 -exec chmod u+w '{}' ';' && \
+	  rm -rf '$(DESTDIR)$(htmldir)/'$$d; }; \
+	done
+	rmdir "$(DESTDIR)$(htmldir)/" || true
+
+doxygen: doxygen-doc
+
+endif ENABLE_DOXYGEN
diff --git a/epoll.c b/epoll.c
index a0df0d2..bdec2e4 100644
--- a/epoll.c
+++ b/epoll.c
@@ -281,7 +281,7 @@
 		return 0;
 	}
 
-	if ((ch->read_change|ch->write_change) & EV_CHANGE_ET)
+	if ((ch->read_change|ch->write_change|ch->close_change) & EV_CHANGE_ET)
 		events |= EPOLLET;
 
 	memset(&epev, 0, sizeof(epev));
@@ -486,7 +486,9 @@
 			continue;
 #endif
 
-		if (what & (EPOLLHUP|EPOLLERR)) {
+		if (what & EPOLLERR) {
+			ev = EV_READ | EV_WRITE;
+		} else if ((what & EPOLLHUP) && !(what & EPOLLRDHUP)) {
 			ev = EV_READ | EV_WRITE;
 		} else {
 			if (what & EPOLLIN)
diff --git a/evdns.c b/evdns.c
index de3848a..a5b31a3 100644
--- a/evdns.c
+++ b/evdns.c
@@ -3531,6 +3531,7 @@
 		base->global_max_retransmits = retries;
 	} else if (str_matches_option(option, "randomize-case:")) {
 		int randcase = strtoint(val);
+		if (randcase == -1) return -1;
 		if (!(flags & DNS_OPTION_MISC)) return 0;
 		base->global_randomize_case = randcase;
 	} else if (str_matches_option(option, "bind-to:")) {
@@ -3554,11 +3555,13 @@
 		    sizeof(tv));
 	} else if (str_matches_option(option, "so-rcvbuf:")) {
 		int buf = strtoint(val);
+		if (buf == -1) return -1;
 		if (!(flags & DNS_OPTION_MISC)) return 0;
 		log(EVDNS_LOG_DEBUG, "Setting SO_RCVBUF to %s", val);
 		base->so_rcvbuf = buf;
 	} else if (str_matches_option(option, "so-sndbuf:")) {
 		int buf = strtoint(val);
+		if (buf == -1) return -1;
 		if (!(flags & DNS_OPTION_MISC)) return 0;
 		log(EVDNS_LOG_DEBUG, "Setting SO_SNDBUF to %s", val);
 		base->so_sndbuf = buf;
@@ -4032,7 +4035,7 @@
 #else
 		r = evdns_base_resolv_conf_parse(base, opts, "/etc/resolv.conf");
 #endif
-		if (r == -1) {
+		if (r) {
 			evdns_base_free_and_unlock(base, 0);
 			return NULL;
 		}
@@ -4106,6 +4109,11 @@
 
 	/* TODO(nickm) we might need to refcount here. */
 
+	while (base->req_waiting_head) {
+		if (fail_requests)
+			reply_schedule_callback(base->req_waiting_head, 0, DNS_ERR_SHUTDOWN, NULL);
+		request_finished(base->req_waiting_head, &base->req_waiting_head, 1);
+	}
 	for (i = 0; i < base->n_req_heads; ++i) {
 		while (base->req_heads[i]) {
 			if (fail_requests)
@@ -4113,11 +4121,6 @@
 			request_finished(base->req_heads[i], &REQ_HEAD(base, base->req_heads[i]->trans_id), 1);
 		}
 	}
-	while (base->req_waiting_head) {
-		if (fail_requests)
-			reply_schedule_callback(base->req_waiting_head, 0, DNS_ERR_SHUTDOWN, NULL);
-		request_finished(base->req_waiting_head, &base->req_waiting_head, 1);
-	}
 	base->global_requests_inflight = base->global_requests_waiting = 0;
 
 	for (server = base->server_head; server; server = server_next) {
diff --git a/event-config.h.cmake b/event-config.h.cmake
index 498ab1e..fccf0cf 100644
--- a/event-config.h.cmake
+++ b/event-config.h.cmake
@@ -75,11 +75,8 @@
 /* Define to 1 if you have the declaration of `KERN_ARND'. */
 #define EVENT__HAVE_DECL_KERN_ARND @EVENT__HAVE_DECL_KERN_ARND@
 
-/* Define to 1 if you have the declaration of `KERN_RANDOM'. */
-#define EVENT__HAVE_DECL_KERN_RANDOM @EVENT__HAVE_DECL_KERN_RANDOM@
-
-/* Define to 1 if you have the declaration of `RANDOM_UUID'. */
-#define EVENT__HAVE_DECL_RANDOM_UUID @EVENT__HAVE_DECL_RANDOM_UUID@
+/* Define to 1 if you have `getrandom' function. */
+#cmakedefine EVENT__HAVE_GETRANDOM 1
 
 /* Define if /dev/poll is available */
 #cmakedefine EVENT__HAVE_DEVPOLL 1
@@ -181,6 +178,9 @@
 /* Define to 1 if you have the <mach/mach_time.h> header file. */
 #cmakedefine EVENT__HAVE_MACH_MACH_TIME_H 1
 
+/* Define to 1 if you have the <mach/mach.h> header file. */
+#cmakedefine EVENT__HAVE_MACH_MACH_H 1
+
 /* Define to 1 if you have the <memory.h> header file. */
 #cmakedefine EVENT__HAVE_MEMORY_H 1
 
@@ -274,9 +274,6 @@
 /* Define to 1 if you have the <stdlib.h> header file. */
 #cmakedefine EVENT__HAVE_STDLIB_H 1
 
-/* Define to 1 if you have the <strings.h> header file. */
-#cmakedefine EVENT__HAVE_STRINGS_H 1
-
 /* Define to 1 if you have the <string.h> header file. */
 #cmakedefine EVENT__HAVE_STRING_H 1
 
@@ -292,6 +289,12 @@
 /* Define to 1 if you have the `strtoll' function. */
 #cmakedefine EVENT__HAVE_STRTOLL 1
 
+/* Define to 1 if you have the `_gmtime64_s' function. */
+#cmakedefine EVENT__HAVE__GMTIME64_S 1
+
+/* Define to 1 if you have the `_gmtime64' function. */
+#cmakedefine EVENT__HAVE__GMTIME64 1
+
 /* Define to 1 if the system has the type `struct addrinfo'. */
 #cmakedefine EVENT__HAVE_STRUCT_ADDRINFO 1
 
@@ -367,6 +370,9 @@
 /* Define to 1 if you have the <sys/stat.h> header file. */
 #cmakedefine EVENT__HAVE_SYS_STAT_H 1
 
+/* Define to 1 if you have the <sys/random.h> header file. */
+#cmakedefine EVENT__HAVE_SYS_RANDOM_H 1
+
 /* Define to 1 if you have the <sys/sysctl.h> header file. */
 #cmakedefine EVENT__HAVE_SYS_SYSCTL_H 1
 
diff --git a/event-internal.h b/event-internal.h
index 92941b7..9e5ff42 100644
--- a/event-internal.h
+++ b/event-internal.h
@@ -418,7 +418,7 @@
  * if it is running in another thread and it doesn't have EV_FINALIZE set.
  */
 #define EVENT_DEL_AUTOBLOCK 2
-/** Argument for event_del_nolock_. Tells event_del to procede even if the
+/** Argument for event_del_nolock_. Tells event_del to proceed even if the
  * event is set up for finalization rather for regular use.*/
 #define EVENT_DEL_EVEN_IF_FINALIZING 3
 int event_del_nolock_(struct event *ev, int blocking);
diff --git a/event.c b/event.c
index b2ad341..7a42b73 100644
--- a/event.c
+++ b/event.c
@@ -987,12 +987,6 @@
 
 	EVBASE_ACQUIRE_LOCK(base, th_base_lock);
 
-	if (base->running_loop) {
-		event_warnx("%s: forked from the event_loop.", __func__);
-		res = -1;
-		goto done;
-	}
-
 	evsel = base->evsel;
 
 	/* check if this event mechanism requires reinit on the backend */
@@ -1712,8 +1706,8 @@
 			evcb_evfinalize = ev->ev_evcallback.evcb_cb_union.evcb_evfinalize;
 			EVUTIL_ASSERT((evcb->evcb_flags & EVLIST_FINALIZING));
 			EVBASE_RELEASE_LOCK(base, th_base_lock);
-			evcb_evfinalize(ev, ev->ev_arg);
 			event_debug_note_teardown_(ev);
+			evcb_evfinalize(ev, ev->ev_arg);
 			if (evcb_closure == EV_CLOSURE_EVENT_FINALIZE_FREE)
 				mm_free(ev);
 		}
@@ -2062,6 +2056,9 @@
 	int res = 0;
 	int activate = 0;
 
+	if (!base)
+		return (-1);
+
 	/* We cannot support signals that just fire once, or persistent
 	 * events. */
 	if (events & (EV_SIGNAL|EV_PERSIST))
diff --git a/event_rpcgen.py b/event_rpcgen.py
index 0911ca2..0bae3b0 100755
--- a/event_rpcgen.py
+++ b/event_rpcgen.py
@@ -6,65 +6,79 @@
 #
 # Generates marshaling code based on libevent.
 
-# TODO:
-# 1) use optparse to allow the strategy shell to parse options, and
-#    to allow the instantiated factory (for the specific output language)
-#    to parse remaining options
-# 2) move the globals into a class that manages execution (including the
-#    progress outputs that space stderr at the moment)
-# 3) emit other languages
+# pylint: disable=too-many-lines
+# pylint: disable=too-many-branches
+# pylint: disable=too-many-public-methods
+# pylint: disable=too-many-statements
+# pylint: disable=global-statement
 
-import sys
+# TODO:
+# 1) propagate the arguments/options parsed by argparse down to the
+#    instantiated factory objects.
+# 2) move the globals into a class that manages execution, including the
+#    progress outputs that go to stderr at the moment.
+# 3) emit other languages.
+
+import argparse
 import re
+import sys
 
 _NAME = "event_rpcgen.py"
 _VERSION = "0.1"
 
 # Globals
-line_count = 0
+LINE_COUNT = 0
 
-white = re.compile(r'\s+')
-cppcomment = re.compile(r'\/\/.*$')
-nonident = re.compile(r'[^a-zA-Z0-9_]')
-structref = re.compile(r'^struct\[([a-zA-Z_][a-zA-Z0-9_]*)\]$')
-structdef = re.compile(r'^struct +[a-zA-Z_][a-zA-Z0-9_]* *{$')
+CPPCOMMENT_RE = re.compile(r"\/\/.*$")
+NONIDENT_RE = re.compile(r"\W")
+PREPROCESSOR_DEF_RE = re.compile(r"^#define")
+STRUCT_REF_RE = re.compile(r"^struct\[(?P<name>[a-zA-Z_][a-zA-Z0-9_]*)\]$")
+STRUCT_DEF_RE = re.compile(r"^struct +[a-zA-Z_][a-zA-Z0-9_]* *{$")
+WHITESPACE_RE = re.compile(r"\s+")
 
-headerdirect = []
-cppdirect = []
+HEADER_DIRECT = []
+CPP_DIRECT = []
 
-QUIETLY = 0
+QUIETLY = False
+
 
 def declare(s):
     if not QUIETLY:
         print(s)
 
+
 def TranslateList(mylist, mydict):
     return [x % mydict for x in mylist]
 
-# Exception class for parse errors
+
 class RpcGenError(Exception):
-        def __init__(self, why):
-                self.why = why
-        def __str__(self):
-                return str(self.why)
+    """An Exception class for parse errors."""
+
+    def __init__(self, why): # pylint: disable=super-init-not-called
+        self.why = why
+
+    def __str__(self):
+        return str(self.why)
+
 
 # Holds everything that makes a struct
-class Struct:
+class Struct(object):
     def __init__(self, name):
         self._name = name
         self._entries = []
         self._tags = {}
-        declare('  Created struct: %s' % name)
+        declare("  Created struct: %s" % name)
 
     def AddEntry(self, entry):
         if entry.Tag() in self._tags:
             raise RpcGenError(
                 'Entry "%s" duplicates tag number %d from "%s" '
-                'around line %d' % (entry.Name(), entry.Tag(),
-                                    self._tags[entry.Tag()], line_count))
+                "around line %d"
+                % (entry.Name(), entry.Tag(), self._tags[entry.Tag()], LINE_COUNT)
+            )
         self._entries.append(entry)
         self._tags[entry.Tag()] = entry.Name()
-        declare('    Added entry: %s' % entry.Name())
+        declare("    Added entry: %s" % entry.Name())
 
     def Name(self):
         return self._name
@@ -75,10 +89,12 @@
         name = "%s_%s" % (self._name, entry.Name())
         return name.upper()
 
-    def PrintIndented(self, file, ident, code):
+    @staticmethod
+    def PrintIndented(filep, ident, code):
         """Takes an array, add indentation to each entry and prints it."""
         for entry in code:
-            file.write('%s%s\n' % (ident, entry))
+            filep.write("%s%s\n" % (ident, entry))
+
 
 class StructCCode(Struct):
     """ Knows how to generate C code for a struct """
@@ -86,42 +102,41 @@
     def __init__(self, name):
         Struct.__init__(self, name)
 
-    def PrintTags(self, file):
+    def PrintTags(self, filep):
         """Prints the tag definitions for a structure."""
-        file.write('/* Tag definition for %s */\n' % self._name)
-        file.write('enum %s_ {\n' % self._name.lower())
+        filep.write("/* Tag definition for %s */\n" % self._name)
+        filep.write("enum %s_ {\n" % self._name.lower())
         for entry in self._entries:
-            file.write('  %s=%d,\n' % (self.EntryTagName(entry), entry.Tag()))
-        file.write('  %s_MAX_TAGS\n' % (self._name.upper()))
-        file.write('};\n\n')
+            filep.write("  %s=%d,\n" % (self.EntryTagName(entry), entry.Tag()))
+        filep.write("  %s_MAX_TAGS\n" % (self._name.upper()))
+        filep.write("};\n\n")
 
-    def PrintForwardDeclaration(self, file):
-        file.write('struct %s;\n' % self._name)
+    def PrintForwardDeclaration(self, filep):
+        filep.write("struct %s;\n" % self._name)
 
-    def PrintDeclaration(self, file):
-        file.write('/* Structure declaration for %s */\n' % self._name)
-        file.write('struct %s_access_ {\n' % self._name)
+    def PrintDeclaration(self, filep):
+        filep.write("/* Structure declaration for %s */\n" % self._name)
+        filep.write("struct %s_access_ {\n" % self._name)
         for entry in self._entries:
-            dcl = entry.AssignDeclaration('(*%s_assign)' % entry.Name())
-            dcl.extend(
-                entry.GetDeclaration('(*%s_get)' % entry.Name()))
+            dcl = entry.AssignDeclaration("(*%s_assign)" % entry.Name())
+            dcl.extend(entry.GetDeclaration("(*%s_get)" % entry.Name()))
             if entry.Array():
-                dcl.extend(
-                    entry.AddDeclaration('(*%s_add)' % entry.Name()))
-            self.PrintIndented(file, '  ', dcl)
-        file.write('};\n\n')
+                dcl.extend(entry.AddDeclaration("(*%s_add)" % entry.Name()))
+            self.PrintIndented(filep, "  ", dcl)
+        filep.write("};\n\n")
 
-        file.write('struct %s {\n' % self._name)
-        file.write('  struct %s_access_ *base;\n\n' % self._name)
+        filep.write("struct %s {\n" % self._name)
+        filep.write("  struct %s_access_ *base;\n\n" % self._name)
         for entry in self._entries:
             dcl = entry.Declaration()
-            self.PrintIndented(file, '  ', dcl)
-        file.write('\n')
+            self.PrintIndented(filep, "  ", dcl)
+        filep.write("\n")
         for entry in self._entries:
-            file.write('  ev_uint8_t %s_set;\n' % entry.Name())
-        file.write('};\n\n')
+            filep.write("  ev_uint8_t %s_set;\n" % entry.Name())
+        filep.write("};\n\n")
 
-        file.write("""struct %(name)s *%(name)s_new(void);
+        filep.write(
+            """struct %(name)s *%(name)s_new(void);
 struct %(name)s *%(name)s_new_with_arg(void *);
 void %(name)s_free(struct %(name)s *);
 void %(name)s_clear(struct %(name)s *);
@@ -131,226 +146,291 @@
 void evtag_marshal_%(name)s(struct evbuffer *, ev_uint32_t,
     const struct %(name)s *);
 int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
-    struct %(name)s *);\n""" % { 'name' : self._name })
-
+    struct %(name)s *);\n"""
+            % {"name": self._name}
+        )
 
         # Write a setting function of every variable
         for entry in self._entries:
-            self.PrintIndented(file, '', entry.AssignDeclaration(
-                entry.AssignFuncName()))
-            self.PrintIndented(file, '', entry.GetDeclaration(
-                entry.GetFuncName()))
+            self.PrintIndented(
+                filep, "", entry.AssignDeclaration(entry.AssignFuncName())
+            )
+            self.PrintIndented(filep, "", entry.GetDeclaration(entry.GetFuncName()))
             if entry.Array():
-                self.PrintIndented(file, '', entry.AddDeclaration(
-                    entry.AddFuncName()))
+                self.PrintIndented(filep, "", entry.AddDeclaration(entry.AddFuncName()))
 
-        file.write('/* --- %s done --- */\n\n' % self._name)
+        filep.write("/* --- %s done --- */\n\n" % self._name)
 
-    def PrintCode(self, file):
-        file.write(('/*\n'
-                       ' * Implementation of %s\n'
-                       ' */\n\n') % self._name)
+    def PrintCode(self, filep):
+        filep.write(
+            """/*
+ * Implementation of %s
+ */
+"""
+            % (self._name)
+        )
 
-        file.write('static struct %(name)s_access_ %(name)s_base__ = {\n' % \
-              { 'name' : self._name })
+        filep.write(
+            """
+static struct %(name)s_access_ %(name)s_base__ = {
+"""
+            % {"name": self._name}
+        )
         for entry in self._entries:
-            self.PrintIndented(file, '  ', entry.CodeBase())
-        file.write('};\n\n')
+            self.PrintIndented(filep, "  ", entry.CodeBase())
+        filep.write("};\n\n")
 
         # Creation
-        file.write((
-            'struct %(name)s *\n'
-            '%(name)s_new(void)\n'
-            '{\n'
-            '  return %(name)s_new_with_arg(NULL);\n'
-            '}\n'
-            '\n'
-            'struct %(name)s *\n'
-            '%(name)s_new_with_arg(void *unused)\n'
-            '{\n'
-            '  struct %(name)s *tmp;\n'
-            '  if ((tmp = malloc(sizeof(struct %(name)s))) == NULL) {\n'
-            '    event_warn("%%s: malloc", __func__);\n'
-            '    return (NULL);\n'
-            '  }\n'
-            '  tmp->base = &%(name)s_base__;\n\n') % { 'name' : self._name })
+        filep.write(
+            """struct %(name)s *
+%(name)s_new(void)
+{
+  return %(name)s_new_with_arg(NULL);
+}
+
+struct %(name)s *
+%(name)s_new_with_arg(void *unused)
+{
+  struct %(name)s *tmp;
+  if ((tmp = malloc(sizeof(struct %(name)s))) == NULL) {
+    event_warn("%%s: malloc", __func__);
+    return (NULL);
+  }
+  tmp->base = &%(name)s_base__;
+
+"""
+            % {"name": self._name}
+        )
 
         for entry in self._entries:
-            self.PrintIndented(file, '  ', entry.CodeInitialize('tmp'))
-            file.write('  tmp->%s_set = 0;\n\n' % entry.Name())
+            self.PrintIndented(filep, "  ", entry.CodeInitialize("tmp"))
+            filep.write("  tmp->%s_set = 0;\n\n" % entry.Name())
 
-        file.write((
-            '  return (tmp);\n'
-            '}\n\n'))
+        filep.write(
+            """  return (tmp);
+}
+
+"""
+        )
 
         # Adding
         for entry in self._entries:
             if entry.Array():
-                self.PrintIndented(file, '', entry.CodeAdd())
-            file.write('\n')
+                self.PrintIndented(filep, "", entry.CodeAdd())
+            filep.write("\n")
 
         # Assigning
         for entry in self._entries:
-            self.PrintIndented(file, '', entry.CodeAssign())
-            file.write('\n')
+            self.PrintIndented(filep, "", entry.CodeAssign())
+            filep.write("\n")
 
         # Getting
         for entry in self._entries:
-            self.PrintIndented(file, '', entry.CodeGet())
-            file.write('\n')
+            self.PrintIndented(filep, "", entry.CodeGet())
+            filep.write("\n")
 
         # Clearing
-        file.write(( 'void\n'
-                        '%(name)s_clear(struct %(name)s *tmp)\n'
-                        '{'
-                        '\n') % { 'name' : self._name })
+        filep.write(
+            """void
+%(name)s_clear(struct %(name)s *tmp)
+{
+"""
+            % {"name": self._name}
+        )
         for entry in self._entries:
-            self.PrintIndented(file, '  ', entry.CodeClear('tmp'))
+            self.PrintIndented(filep, "  ", entry.CodeClear("tmp"))
 
-        file.write('}\n\n')
+        filep.write("}\n\n")
 
         # Freeing
-        file.write(( 'void\n'
-                        '%(name)s_free(struct %(name)s *tmp)\n'
-                        '{'
-                        '\n') % { 'name' : self._name })
+        filep.write(
+            """void
+%(name)s_free(struct %(name)s *tmp)
+{
+"""
+            % {"name": self._name}
+        )
 
         for entry in self._entries:
-            self.PrintIndented(file, '  ', entry.CodeFree('tmp'))
+            self.PrintIndented(filep, "  ", entry.CodeFree("tmp"))
 
-        file.write(('  free(tmp);\n'
-                       '}\n\n'))
+        filep.write(
+            """  free(tmp);
+}
+
+"""
+        )
 
         # Marshaling
-        file.write(('void\n'
-                       '%(name)s_marshal(struct evbuffer *evbuf, '
-                       'const struct %(name)s *tmp)'
-                       '{\n') % { 'name' : self._name })
+        filep.write(
+            """void
+%(name)s_marshal(struct evbuffer *evbuf, const struct %(name)s *tmp) {
+"""
+            % {"name": self._name}
+        )
         for entry in self._entries:
-            indent = '  '
+            indent = "  "
             # Optional entries do not have to be set
             if entry.Optional():
-                indent += '  '
-                file.write('  if (tmp->%s_set) {\n' % entry.Name())
+                indent += "  "
+                filep.write("  if (tmp->%s_set) {\n" % entry.Name())
             self.PrintIndented(
-                file, indent,
-                entry.CodeMarshal('evbuf', self.EntryTagName(entry),
-                                  entry.GetVarName('tmp'),
-                                  entry.GetVarLen('tmp')))
+                filep,
+                indent,
+                entry.CodeMarshal(
+                    "evbuf",
+                    self.EntryTagName(entry),
+                    entry.GetVarName("tmp"),
+                    entry.GetVarLen("tmp"),
+                ),
+            )
             if entry.Optional():
-                file.write('  }\n')
+                filep.write("  }\n")
 
-        file.write('}\n\n')
+        filep.write("}\n\n")
 
         # Unmarshaling
-        file.write(('int\n'
-                       '%(name)s_unmarshal(struct %(name)s *tmp, '
-                       ' struct evbuffer *evbuf)\n'
-                       '{\n'
-                       '  ev_uint32_t tag;\n'
-                       '  while (evbuffer_get_length(evbuf) > 0) {\n'
-                       '    if (evtag_peek(evbuf, &tag) == -1)\n'
-                       '      return (-1);\n'
-                       '    switch (tag) {\n'
-                       '\n') % { 'name' : self._name })
+        filep.write(
+            """int
+%(name)s_unmarshal(struct %(name)s *tmp, struct evbuffer *evbuf)
+{
+  ev_uint32_t tag;
+  while (evbuffer_get_length(evbuf) > 0) {
+    if (evtag_peek(evbuf, &tag) == -1)
+      return (-1);
+    switch (tag) {
+
+"""
+            % {"name": self._name}
+        )
         for entry in self._entries:
-            file.write('      case %s:\n' % self.EntryTagName(entry))
+            filep.write("      case %s:\n" % (self.EntryTagName(entry)))
             if not entry.Array():
-                file.write((
-                    '        if (tmp->%s_set)\n'
-                    '          return (-1);'
-                    '\n') % (entry.Name()))
+                filep.write(
+                    """        if (tmp->%s_set)
+          return (-1);
+"""
+                    % (entry.Name())
+                )
 
             self.PrintIndented(
-                file, '        ',
-                entry.CodeUnmarshal('evbuf',
-                                    self.EntryTagName(entry),
-                                    entry.GetVarName('tmp'),
-                                    entry.GetVarLen('tmp')))
+                filep,
+                "        ",
+                entry.CodeUnmarshal(
+                    "evbuf",
+                    self.EntryTagName(entry),
+                    entry.GetVarName("tmp"),
+                    entry.GetVarLen("tmp"),
+                ),
+            )
 
-            file.write(( '        tmp->%s_set = 1;\n' % entry.Name() +
-                            '        break;\n' ))
-        file.write(( '      default:\n'
-                        '        return -1;\n'
-                        '    }\n'
-                        '  }\n\n' ))
+            filep.write(
+                """        tmp->%s_set = 1;
+        break;
+"""
+                % (entry.Name())
+            )
+        filep.write(
+            """      default:
+        return -1;
+    }
+  }
+
+"""
+        )
         # Check if it was decoded completely
-        file.write(( '  if (%(name)s_complete(tmp) == -1)\n'
-                        '    return (-1);'
-                        '\n') % { 'name' : self._name })
-
-        # Successfully decoded
-        file.write(( '  return (0);\n'
-                        '}\n\n'))
+        filep.write(
+            """  if (%(name)s_complete(tmp) == -1)
+    return (-1);
+  return (0);
+}
+"""
+            % {"name": self._name}
+        )
 
         # Checking if a structure has all the required data
-        file.write((
-            'int\n'
-            '%(name)s_complete(struct %(name)s *msg)\n'
-            '{\n' ) % { 'name' : self._name })
+        filep.write(
+            """
+int
+%(name)s_complete(struct %(name)s *msg)
+{
+"""
+            % {"name": self._name}
+        )
         for entry in self._entries:
             if not entry.Optional():
                 code = [
-                    'if (!msg->%(name)s_set)',
-                    '  return (-1);' ]
+                    """if (!msg->%(name)s_set)
+    return (-1);"""
+                ]
                 code = TranslateList(code, entry.GetTranslation())
-                self.PrintIndented(
-                    file, '  ', code)
+                self.PrintIndented(filep, "  ", code)
 
             self.PrintIndented(
-                file, '  ',
-                entry.CodeComplete('msg', entry.GetVarName('msg')))
-        file.write((
-            '  return (0);\n'
-            '}\n\n' ))
+                filep, "  ", entry.CodeComplete("msg", entry.GetVarName("msg"))
+            )
+        filep.write(
+            """  return (0);
+}
+"""
+        )
 
         # Complete message unmarshaling
-        file.write((
-            'int\n'
-            'evtag_unmarshal_%(name)s(struct evbuffer *evbuf, '
-            'ev_uint32_t need_tag, struct %(name)s *msg)\n'
-            '{\n'
-            '  ev_uint32_t tag;\n'
-            '  int res = -1;\n'
-            '\n'
-            '  struct evbuffer *tmp = evbuffer_new();\n'
-            '\n'
-            '  if (evtag_unmarshal(evbuf, &tag, tmp) == -1'
-            ' || tag != need_tag)\n'
-            '    goto error;\n'
-            '\n'
-            '  if (%(name)s_unmarshal(msg, tmp) == -1)\n'
-            '    goto error;\n'
-            '\n'
-            '  res = 0;\n'
-            '\n'
-            ' error:\n'
-            '  evbuffer_free(tmp);\n'
-            '  return (res);\n'
-            '}\n\n' ) % { 'name' : self._name })
+        filep.write(
+            """
+int
+evtag_unmarshal_%(name)s(struct evbuffer *evbuf, ev_uint32_t need_tag,
+  struct %(name)s *msg)
+{
+  ev_uint32_t tag;
+  int res = -1;
+
+  struct evbuffer *tmp = evbuffer_new();
+
+  if (evtag_unmarshal(evbuf, &tag, tmp) == -1 || tag != need_tag)
+    goto error;
+
+  if (%(name)s_unmarshal(msg, tmp) == -1)
+    goto error;
+
+  res = 0;
+
+ error:
+  evbuffer_free(tmp);
+  return (res);
+}
+"""
+            % {"name": self._name}
+        )
 
         # Complete message marshaling
-        file.write((
-            'void\n'
-            'evtag_marshal_%(name)s(struct evbuffer *evbuf, ev_uint32_t tag, '
-            'const struct %(name)s *msg)\n'
-            '{\n'
-            '  struct evbuffer *buf_ = evbuffer_new();\n'
-            '  assert(buf_ != NULL);\n'
-            '  %(name)s_marshal(buf_, msg);\n'
-            '  evtag_marshal_buffer(evbuf, tag, buf_);\n '
-            '  evbuffer_free(buf_);\n'
-            '}\n\n' ) % { 'name' : self._name })
+        filep.write(
+            """
+void
+evtag_marshal_%(name)s(struct evbuffer *evbuf, ev_uint32_t tag,
+    const struct %(name)s *msg)
+{
+  struct evbuffer *buf_ = evbuffer_new();
+  assert(buf_ != NULL);
+  %(name)s_marshal(buf_, msg);
+  evtag_marshal_buffer(evbuf, tag, buf_);
+  evbuffer_free(buf_);
+}
 
-class Entry:
-    def __init__(self, type, name, tag):
-        self._type = type
+"""
+            % {"name": self._name}
+        )
+
+
+class Entry(object):
+    def __init__(self, ent_type, name, tag):
+        self._type = ent_type
         self._name = name
         self._tag = int(tag)
-        self._ctype = type
-        self._optional = 0
-        self._can_be_array = 0
-        self._array = 0
+        self._ctype = ent_type
+        self._optional = False
+        self._can_be_array = False
+        self._array = False
         self._line_count = -1
         self._struct = None
         self._refname = None
@@ -358,8 +438,9 @@
         self._optpointer = True
         self._optaddarg = True
 
-    def GetInitializer(self):
-        assert 0, "Entry does not provide initializer"
+    @staticmethod
+    def GetInitializer():
+        raise NotImplementedError("Entry does not provide an initializer")
 
     def SetStruct(self, struct):
         self._struct = struct
@@ -386,326 +467,351 @@
     def Type(self):
         return self._type
 
-    def MakeArray(self, yes=1):
-        self._array = yes
+    def MakeArray(self):
+        self._array = True
 
     def MakeOptional(self):
-        self._optional = 1
+        self._optional = True
 
     def Verify(self):
         if self.Array() and not self._can_be_array:
             raise RpcGenError(
                 'Entry "%s" cannot be created as an array '
-                'around line %d' % (self._name, self.LineCount()))
+                "around line %d" % (self._name, self.LineCount())
+            )
         if not self._struct:
             raise RpcGenError(
                 'Entry "%s" does not know which struct it belongs to '
-                'around line %d' % (self._name, self.LineCount()))
+                "around line %d" % (self._name, self.LineCount())
+            )
         if self._optional and self._array:
             raise RpcGenError(
                 'Entry "%s" has illegal combination of optional and array '
-                'around line %d' % (self._name, self.LineCount()))
+                "around line %d" % (self._name, self.LineCount())
+            )
 
-    def GetTranslation(self, extradict = {}):
+    def GetTranslation(self, extradict=None):
+        if extradict is None:
+            extradict = {}
         mapping = {
-            "parent_name" : self._struct.Name(),
-            "name" : self._name,
-            "ctype" : self._ctype,
-            "refname" : self._refname,
-            "optpointer" : self._optpointer and "*" or "",
-            "optreference" : self._optpointer and "&" or "",
-            "optaddarg" :
-            self._optaddarg and ", const %s value" % self._ctype or ""
-            }
+            "parent_name": self._struct.Name(),
+            "name": self._name,
+            "ctype": self._ctype,
+            "refname": self._refname,
+            "optpointer": self._optpointer and "*" or "",
+            "optreference": self._optpointer and "&" or "",
+            "optaddarg": self._optaddarg and ", const %s value" % self._ctype or "",
+        }
         for (k, v) in list(extradict.items()):
             mapping[k] = v
 
         return mapping
 
     def GetVarName(self, var):
-        return '%(var)s->%(name)s_data' % self.GetTranslation({ 'var' : var })
+        return "%(var)s->%(name)s_data" % self.GetTranslation({"var": var})
 
-    def GetVarLen(self, var):
-        return 'sizeof(%s)' % self._ctype
+    def GetVarLen(self, _var):
+        return "sizeof(%s)" % self._ctype
 
     def GetFuncName(self):
-        return '%s_%s_get' % (self._struct.Name(), self._name)
+        return "%s_%s_get" % (self._struct.Name(), self._name)
 
     def GetDeclaration(self, funcname):
-        code = [ 'int %s(struct %s *, %s *);' % (
-            funcname, self._struct.Name(), self._ctype ) ]
+        code = [
+            "int %s(struct %s *, %s *);" % (funcname, self._struct.Name(), self._ctype)
+        ]
         return code
 
     def CodeGet(self):
-        code = (
-            'int',
-            '%(parent_name)s_%(name)s_get(struct %(parent_name)s *msg, '
-            '%(ctype)s *value)',
-            '{',
-            '  if (msg->%(name)s_set != 1)',
-            '    return (-1);',
-            '  *value = msg->%(name)s_data;',
-            '  return (0);',
-            '}' )
-        code = '\n'.join(code)
+        code = """int
+%(parent_name)s_%(name)s_get(struct %(parent_name)s *msg, %(ctype)s *value)
+{
+  if (msg->%(name)s_set != 1)
+    return (-1);
+  *value = msg->%(name)s_data;
+  return (0);
+}"""
         code = code % self.GetTranslation()
-        return code.split('\n')
+        return code.split("\n")
 
     def AssignFuncName(self):
-        return '%s_%s_assign' % (self._struct.Name(), self._name)
+        return "%s_%s_assign" % (self._struct.Name(), self._name)
 
     def AddFuncName(self):
-        return '%s_%s_add' % (self._struct.Name(), self._name)
+        return "%s_%s_add" % (self._struct.Name(), self._name)
 
     def AssignDeclaration(self, funcname):
-        code = [ 'int %s(struct %s *, const %s);' % (
-            funcname, self._struct.Name(), self._ctype ) ]
+        code = [
+            "int %s(struct %s *, const %s);"
+            % (funcname, self._struct.Name(), self._ctype)
+        ]
         return code
 
     def CodeAssign(self):
-        code = [ 'int',
-                 '%(parent_name)s_%(name)s_assign(struct %(parent_name)s *msg,'
-                 ' const %(ctype)s value)',
-                 '{',
-                 '  msg->%(name)s_set = 1;',
-                 '  msg->%(name)s_data = value;',
-                 '  return (0);',
-                 '}' ]
-        code = '\n'.join(code)
+        code = [
+            "int",
+            "%(parent_name)s_%(name)s_assign(struct %(parent_name)s *msg,"
+            " const %(ctype)s value)",
+            "{",
+            "  msg->%(name)s_set = 1;",
+            "  msg->%(name)s_data = value;",
+            "  return (0);",
+            "}",
+        ]
+        code = "\n".join(code)
         code = code % self.GetTranslation()
-        return code.split('\n')
+        return code.split("\n")
 
     def CodeClear(self, structname):
-        code = [ '%s->%s_set = 0;' % (structname, self.Name()) ]
+        code = ["%s->%s_set = 0;" % (structname, self.Name())]
 
         return code
 
-    def CodeComplete(self, structname, var_name):
+    @staticmethod
+    def CodeComplete(_structname, _var_name):
         return []
 
-    def CodeFree(self, name):
+    @staticmethod
+    def CodeFree(_name):
         return []
 
     def CodeBase(self):
-        code = [
-            '%(parent_name)s_%(name)s_assign,',
-            '%(parent_name)s_%(name)s_get,'
-            ]
+        code = ["%(parent_name)s_%(name)s_assign,", "%(parent_name)s_%(name)s_get,"]
         if self.Array():
-            code.append('%(parent_name)s_%(name)s_add,')
+            code.append("%(parent_name)s_%(name)s_add,")
 
-        code = '\n'.join(code)
+        code = "\n".join(code)
         code = code % self.GetTranslation()
-        return code.split('\n')
+        return code.split("\n")
+
 
 class EntryBytes(Entry):
-    def __init__(self, type, name, tag, length):
+    def __init__(self, ent_type, name, tag, length):
         # Init base class
-        Entry.__init__(self, type, name, tag)
+        super(EntryBytes, self).__init__(ent_type, name, tag)
 
         self._length = length
-        self._ctype = 'ev_uint8_t'
+        self._ctype = "ev_uint8_t"
 
-    def GetInitializer(self):
+    @staticmethod
+    def GetInitializer():
         return "NULL"
 
-    def GetVarLen(self, var):
-        return '(%s)' % self._length
+    def GetVarLen(self, _var):
+        return "(%s)" % self._length
 
-    def CodeArrayAdd(self, varname, value):
+    @staticmethod
+    def CodeArrayAdd(varname, _value):
         # XXX: copy here
-        return [ '%(varname)s = NULL;' % { 'varname' : varname } ]
+        return ["%(varname)s = NULL;" % {"varname": varname}]
 
     def GetDeclaration(self, funcname):
-        code = [ 'int %s(struct %s *, %s **);' % (
-            funcname, self._struct.Name(), self._ctype ) ]
+        code = [
+            "int %s(struct %s *, %s **);" % (funcname, self._struct.Name(), self._ctype)
+        ]
         return code
 
     def AssignDeclaration(self, funcname):
-        code = [ 'int %s(struct %s *, const %s *);' % (
-            funcname, self._struct.Name(), self._ctype ) ]
+        code = [
+            "int %s(struct %s *, const %s *);"
+            % (funcname, self._struct.Name(), self._ctype)
+        ]
         return code
 
     def Declaration(self):
-        dcl  = ['ev_uint8_t %s_data[%s];' % (self._name, self._length)]
+        dcl = ["ev_uint8_t %s_data[%s];" % (self._name, self._length)]
 
         return dcl
 
     def CodeGet(self):
         name = self._name
-        code = [ 'int',
-                 '%s_%s_get(struct %s *msg, %s **value)' % (
-            self._struct.Name(), name,
-            self._struct.Name(), self._ctype),
-                 '{',
-                 '  if (msg->%s_set != 1)' % name,
-                 '    return (-1);',
-                 '  *value = msg->%s_data;' % name,
-                 '  return (0);',
-                 '}' ]
+        code = [
+            "int",
+            "%s_%s_get(struct %s *msg, %s **value)"
+            % (self._struct.Name(), name, self._struct.Name(), self._ctype),
+            "{",
+            "  if (msg->%s_set != 1)" % name,
+            "    return (-1);",
+            "  *value = msg->%s_data;" % name,
+            "  return (0);",
+            "}",
+        ]
         return code
 
     def CodeAssign(self):
         name = self._name
-        code = [ 'int',
-                 '%s_%s_assign(struct %s *msg, const %s *value)' % (
-            self._struct.Name(), name,
-            self._struct.Name(), self._ctype),
-                 '{',
-                 '  msg->%s_set = 1;' % name,
-                 '  memcpy(msg->%s_data, value, %s);' % (
-            name, self._length),
-                 '  return (0);',
-                 '}' ]
+        code = [
+            "int",
+            "%s_%s_assign(struct %s *msg, const %s *value)"
+            % (self._struct.Name(), name, self._struct.Name(), self._ctype),
+            "{",
+            "  msg->%s_set = 1;" % name,
+            "  memcpy(msg->%s_data, value, %s);" % (name, self._length),
+            "  return (0);",
+            "}",
+        ]
         return code
 
     def CodeUnmarshal(self, buf, tag_name, var_name, var_len):
-        code = [  'if (evtag_unmarshal_fixed(%(buf)s, %(tag)s, '
-                  '%(var)s, %(varlen)s) == -1) {',
-                  '  event_warnx("%%s: failed to unmarshal %(name)s", __func__);',
-                  '  return (-1);',
-                  '}'
-                  ]
-        return TranslateList(code,
-                             self.GetTranslation({
-            'var' : var_name,
-            'varlen' : var_len,
-            'buf' : buf,
-            'tag' : tag_name }))
+        code = [
+            "if (evtag_unmarshal_fixed(%(buf)s, %(tag)s, "
+            "%(var)s, %(varlen)s) == -1) {",
+            '  event_warnx("%%s: failed to unmarshal %(name)s", __func__);',
+            "  return (-1);",
+            "}",
+        ]
+        return TranslateList(
+            code,
+            self.GetTranslation(
+                {"var": var_name, "varlen": var_len, "buf": buf, "tag": tag_name}
+            ),
+        )
 
-    def CodeMarshal(self, buf, tag_name, var_name, var_len):
-        code = ['evtag_marshal(%s, %s, %s, %s);' % (
-            buf, tag_name, var_name, var_len)]
+    @staticmethod
+    def CodeMarshal(buf, tag_name, var_name, var_len):
+        code = ["evtag_marshal(%s, %s, %s, %s);" % (buf, tag_name, var_name, var_len)]
         return code
 
     def CodeClear(self, structname):
-        code = [ '%s->%s_set = 0;' % (structname, self.Name()),
-                 'memset(%s->%s_data, 0, sizeof(%s->%s_data));' % (
-            structname, self._name, structname, self._name)]
+        code = [
+            "%s->%s_set = 0;" % (structname, self.Name()),
+            "memset(%s->%s_data, 0, sizeof(%s->%s_data));"
+            % (structname, self._name, structname, self._name),
+        ]
 
         return code
 
     def CodeInitialize(self, name):
-        code  = ['memset(%s->%s_data, 0, sizeof(%s->%s_data));' % (
-            name, self._name, name, self._name)]
+        code = [
+            "memset(%s->%s_data, 0, sizeof(%s->%s_data));"
+            % (name, self._name, name, self._name)
+        ]
         return code
 
     def Verify(self):
         if not self._length:
             raise RpcGenError(
                 'Entry "%s" needs a length '
-                'around line %d' % (self._name, self.LineCount()))
+                "around line %d" % (self._name, self.LineCount())
+            )
 
-        Entry.Verify(self)
+        super(EntryBytes, self).Verify()
+
 
 class EntryInt(Entry):
-    def __init__(self, type, name, tag, bits=32):
+    def __init__(self, ent_type, name, tag, bits=32):
         # Init base class
-        Entry.__init__(self, type, name, tag)
+        super(EntryInt, self).__init__(ent_type, name, tag)
 
-        self._can_be_array = 1
+        self._can_be_array = True
         if bits == 32:
-            self._ctype = 'ev_uint32_t'
-            self._marshal_type = 'int'
+            self._ctype = "ev_uint32_t"
+            self._marshal_type = "int"
         if bits == 64:
-            self._ctype = 'ev_uint64_t'
-            self._marshal_type = 'int64'
+            self._ctype = "ev_uint64_t"
+            self._marshal_type = "int64"
 
-    def GetInitializer(self):
+    @staticmethod
+    def GetInitializer():
         return "0"
 
-    def CodeArrayFree(self, var):
+    @staticmethod
+    def CodeArrayFree(_var):
         return []
 
-    def CodeArrayAssign(self, varname, srcvar):
-        return [ '%(varname)s = %(srcvar)s;' % { 'varname' : varname,
-                                                'srcvar' : srcvar } ]
+    @staticmethod
+    def CodeArrayAssign(varname, srcvar):
+        return ["%(varname)s = %(srcvar)s;" % {"varname": varname, "srcvar": srcvar}]
 
-    def CodeArrayAdd(self, varname, value):
+    @staticmethod
+    def CodeArrayAdd(varname, value):
         """Returns a new entry of this type."""
-        return [ '%(varname)s = %(value)s;' % { 'varname' : varname,
-                                              'value' : value } ]
+        return ["%(varname)s = %(value)s;" % {"varname": varname, "value": value}]
 
-    def CodeUnmarshal(self, buf, tag_name, var_name, var_len):
+    def CodeUnmarshal(self, buf, tag_name, var_name, _var_len):
         code = [
-            'if (evtag_unmarshal_%(ma)s(%(buf)s, %(tag)s, &%(var)s) == -1) {',
+            "if (evtag_unmarshal_%(ma)s(%(buf)s, %(tag)s, &%(var)s) == -1) {",
             '  event_warnx("%%s: failed to unmarshal %(name)s", __func__);',
-            '  return (-1);',
-            '}' ]
-        code = '\n'.join(code) % self.GetTranslation({
-            'ma'  : self._marshal_type,
-            'buf' : buf,
-            'tag' : tag_name,
-            'var' : var_name })
-        return code.split('\n')
+            "  return (-1);",
+            "}",
+        ]
+        code = "\n".join(code) % self.GetTranslation(
+            {"ma": self._marshal_type, "buf": buf, "tag": tag_name, "var": var_name}
+        )
+        return code.split("\n")
 
-    def CodeMarshal(self, buf, tag_name, var_name, var_len):
+    def CodeMarshal(self, buf, tag_name, var_name, _var_len):
         code = [
-            'evtag_marshal_%s(%s, %s, %s);' % (
-            self._marshal_type, buf, tag_name, var_name)]
+            "evtag_marshal_%s(%s, %s, %s);"
+            % (self._marshal_type, buf, tag_name, var_name)
+        ]
         return code
 
     def Declaration(self):
-        dcl  = ['%s %s_data;' % (self._ctype, self._name)]
+        dcl = ["%s %s_data;" % (self._ctype, self._name)]
 
         return dcl
 
     def CodeInitialize(self, name):
-        code = ['%s->%s_data = 0;' % (name, self._name)]
+        code = ["%s->%s_data = 0;" % (name, self._name)]
         return code
 
+
 class EntryString(Entry):
-    def __init__(self, type, name, tag):
+    def __init__(self, ent_type, name, tag):
         # Init base class
-        Entry.__init__(self, type, name, tag)
+        super(EntryString, self).__init__(ent_type, name, tag)
 
-        self._can_be_array = 1
-        self._ctype = 'char *'
+        self._can_be_array = True
+        self._ctype = "char *"
 
-    def GetInitializer(self):
+    @staticmethod
+    def GetInitializer():
         return "NULL"
 
-    def CodeArrayFree(self, varname):
-        code = [
-            'if (%(var)s != NULL) free(%(var)s);' ]
+    @staticmethod
+    def CodeArrayFree(varname):
+        code = ["if (%(var)s != NULL) free(%(var)s);"]
 
-        return TranslateList(code, { 'var' : varname })
+        return TranslateList(code, {"var": varname})
 
-    def CodeArrayAssign(self, varname, srcvar):
+    @staticmethod
+    def CodeArrayAssign(varname, srcvar):
         code = [
-            'if (%(var)s != NULL)',
-            '  free(%(var)s);',
-            '%(var)s = strdup(%(srcvar)s);',
-            'if (%(var)s == NULL) {',
+            "if (%(var)s != NULL)",
+            "  free(%(var)s);",
+            "%(var)s = strdup(%(srcvar)s);",
+            "if (%(var)s == NULL) {",
             '  event_warnx("%%s: strdup", __func__);',
-            '  return (-1);',
-            '}' ]
+            "  return (-1);",
+            "}",
+        ]
 
-        return TranslateList(code, { 'var' : varname,
-                                     'srcvar' : srcvar })
+        return TranslateList(code, {"var": varname, "srcvar": srcvar})
 
-    def CodeArrayAdd(self, varname, value):
+    @staticmethod
+    def CodeArrayAdd(varname, value):
         code = [
-            'if (%(value)s != NULL) {',
-            '  %(var)s = strdup(%(value)s);',
-            '  if (%(var)s == NULL) {',
-            '    goto error;',
-            '  }',
-            '} else {',
-            '  %(var)s = NULL;',
-            '}' ]
+            "if (%(value)s != NULL) {",
+            "  %(var)s = strdup(%(value)s);",
+            "  if (%(var)s == NULL) {",
+            "    goto error;",
+            "  }",
+            "} else {",
+            "  %(var)s = NULL;",
+            "}",
+        ]
 
-        return TranslateList(code, { 'var' : varname,
-                                     'value' : value })
+        return TranslateList(code, {"var": varname, "value": value})
 
     def GetVarLen(self, var):
-        return 'strlen(%s)' % self.GetVarName(var)
+        return "strlen(%s)" % self.GetVarName(var)
 
-    def CodeMakeInitalize(self, varname):
-        return '%(varname)s = NULL;' % { 'varname' : varname }
+    @staticmethod
+    def CodeMakeInitalize(varname):
+        return "%(varname)s = NULL;" % {"varname": varname}
 
     def CodeAssign(self):
-        name = self._name
         code = """int
 %(parent_name)s_%(name)s_assign(struct %(parent_name)s *msg,
     const %(ctype)s value)
@@ -716,131 +822,137 @@
     return (-1);
   msg->%(name)s_set = 1;
   return (0);
-}""" % self.GetTranslation()
+}""" % (
+            self.GetTranslation()
+        )
 
-        return code.split('\n')
+        return code.split("\n")
 
-    def CodeUnmarshal(self, buf, tag_name, var_name, var_len):
-        code = ['if (evtag_unmarshal_string(%(buf)s, %(tag)s, &%(var)s) == -1) {',
-                '  event_warnx("%%s: failed to unmarshal %(name)s", __func__);',
-                '  return (-1);',
-                '}'
-                ]
-        code = '\n'.join(code) % self.GetTranslation({
-            'buf' : buf,
-            'tag' : tag_name,
-            'var' : var_name })
-        return code.split('\n')
+    def CodeUnmarshal(self, buf, tag_name, var_name, _var_len):
+        code = [
+            "if (evtag_unmarshal_string(%(buf)s, %(tag)s, &%(var)s) == -1) {",
+            '  event_warnx("%%s: failed to unmarshal %(name)s", __func__);',
+            "  return (-1);",
+            "}",
+        ]
+        code = "\n".join(code) % self.GetTranslation(
+            {"buf": buf, "tag": tag_name, "var": var_name}
+        )
+        return code.split("\n")
 
-    def CodeMarshal(self, buf, tag_name, var_name, var_len):
-        code = ['evtag_marshal_string(%s, %s, %s);' % (
-            buf, tag_name, var_name)]
+    @staticmethod
+    def CodeMarshal(buf, tag_name, var_name, _var_len):
+        code = ["evtag_marshal_string(%s, %s, %s);" % (buf, tag_name, var_name)]
         return code
 
     def CodeClear(self, structname):
-        code = [ 'if (%s->%s_set == 1) {' % (structname, self.Name()),
-                 '  free(%s->%s_data);' % (structname, self.Name()),
-                 '  %s->%s_data = NULL;' % (structname, self.Name()),
-                 '  %s->%s_set = 0;' % (structname, self.Name()),
-                 '}'
-                 ]
+        code = [
+            "if (%s->%s_set == 1) {" % (structname, self.Name()),
+            "  free(%s->%s_data);" % (structname, self.Name()),
+            "  %s->%s_data = NULL;" % (structname, self.Name()),
+            "  %s->%s_set = 0;" % (structname, self.Name()),
+            "}",
+        ]
 
         return code
 
     def CodeInitialize(self, name):
-        code  = ['%s->%s_data = NULL;' % (name, self._name)]
+        code = ["%s->%s_data = NULL;" % (name, self._name)]
         return code
 
     def CodeFree(self, name):
-        code  = ['if (%s->%s_data != NULL)' % (name, self._name),
-                 '    free (%s->%s_data);' % (name, self._name)]
+        code = [
+            "if (%s->%s_data != NULL)" % (name, self._name),
+            "    free (%s->%s_data);" % (name, self._name),
+        ]
 
         return code
 
     def Declaration(self):
-        dcl  = ['char *%s_data;' % self._name]
+        dcl = ["char *%s_data;" % self._name]
 
         return dcl
 
+
 class EntryStruct(Entry):
-    def __init__(self, type, name, tag, refname):
+    def __init__(self, ent_type, name, tag, refname):
         # Init base class
-        Entry.__init__(self, type, name, tag)
+        super(EntryStruct, self).__init__(ent_type, name, tag)
 
         self._optpointer = False
-        self._can_be_array = 1
+        self._can_be_array = True
         self._refname = refname
-        self._ctype = 'struct %s*' % refname
+        self._ctype = "struct %s*" % refname
         self._optaddarg = False
 
     def GetInitializer(self):
         return "NULL"
 
-    def GetVarLen(self, var):
-        return '-1'
+    def GetVarLen(self, _var):
+        return "-1"
 
-    def CodeArrayAdd(self, varname, value):
+    def CodeArrayAdd(self, varname, _value):
         code = [
-            '%(varname)s = %(refname)s_new();',
-            'if (%(varname)s == NULL)',
-            '  goto error;' ]
+            "%(varname)s = %(refname)s_new();",
+            "if (%(varname)s == NULL)",
+            "  goto error;",
+        ]
 
-        return TranslateList(code, self.GetTranslation({ 'varname' : varname }))
+        return TranslateList(code, self.GetTranslation({"varname": varname}))
 
     def CodeArrayFree(self, var):
-        code = [ '%(refname)s_free(%(var)s);' % self.GetTranslation(
-            { 'var' : var }) ]
+        code = ["%(refname)s_free(%(var)s);" % self.GetTranslation({"var": var})]
         return code
 
     def CodeArrayAssign(self, var, srcvar):
         code = [
-            'int had_error = 0;',
-            'struct evbuffer *tmp = NULL;',
-            '%(refname)s_clear(%(var)s);',
-            'if ((tmp = evbuffer_new()) == NULL) {',
+            "int had_error = 0;",
+            "struct evbuffer *tmp = NULL;",
+            "%(refname)s_clear(%(var)s);",
+            "if ((tmp = evbuffer_new()) == NULL) {",
             '  event_warn("%%s: evbuffer_new()", __func__);',
-            '  had_error = 1;',
-            '  goto done;',
-            '}',
-            '%(refname)s_marshal(tmp, %(srcvar)s);',
-            'if (%(refname)s_unmarshal(%(var)s, tmp) == -1) {',
+            "  had_error = 1;",
+            "  goto done;",
+            "}",
+            "%(refname)s_marshal(tmp, %(srcvar)s);",
+            "if (%(refname)s_unmarshal(%(var)s, tmp) == -1) {",
             '  event_warnx("%%s: %(refname)s_unmarshal", __func__);',
-            '  had_error = 1;',
-            '  goto done;',
-            '}',
-            'done:'
-            'if (tmp != NULL)',
-            '  evbuffer_free(tmp);',
-            'if (had_error) {',
-            '  %(refname)s_clear(%(var)s);',
-            '  return (-1);',
-            '}' ]
+            "  had_error = 1;",
+            "  goto done;",
+            "}",
+            "done:",
+            "if (tmp != NULL)",
+            "  evbuffer_free(tmp);",
+            "if (had_error) {",
+            "  %(refname)s_clear(%(var)s);",
+            "  return (-1);",
+            "}",
+        ]
 
-        return TranslateList(code, self.GetTranslation({
-            'var' : var,
-            'srcvar' : srcvar}))
+        return TranslateList(code, self.GetTranslation({"var": var, "srcvar": srcvar}))
 
     def CodeGet(self):
         name = self._name
-        code = [ 'int',
-                 '%s_%s_get(struct %s *msg, %s *value)' % (
-            self._struct.Name(), name,
-            self._struct.Name(), self._ctype),
-                 '{',
-                 '  if (msg->%s_set != 1) {' % name,
-                 '    msg->%s_data = %s_new();' % (name, self._refname),
-                 '    if (msg->%s_data == NULL)' % name,
-                 '      return (-1);',
-                 '    msg->%s_set = 1;' % name,
-                 '  }',
-                 '  *value = msg->%s_data;' % name,
-                 '  return (0);',
-                 '}' ]
+        code = [
+            "int",
+            "%s_%s_get(struct %s *msg, %s *value)"
+            % (self._struct.Name(), name, self._struct.Name(), self._ctype),
+            "{",
+            "  if (msg->%s_set != 1) {" % name,
+            "    msg->%s_data = %s_new();" % (name, self._refname),
+            "    if (msg->%s_data == NULL)" % name,
+            "      return (-1);",
+            "    msg->%s_set = 1;" % name,
+            "  }",
+            "  *value = msg->%s_data;" % name,
+            "  return (0);",
+            "}",
+        ]
         return code
 
     def CodeAssign(self):
-        name = self._name
-        code = """int
+        code = (
+            """int
 %(parent_name)s_%(name)s_assign(struct %(parent_name)s *msg,
     const %(ctype)s value)
 {
@@ -875,186 +987,210 @@
      msg->%(name)s_data = NULL;
    }
    return (-1);
-}""" % self.GetTranslation()
-        return code.split('\n')
+}"""
+            % self.GetTranslation()
+        )
+        return code.split("\n")
 
     def CodeComplete(self, structname, var_name):
-        code = [ 'if (%(structname)s->%(name)s_set && '
-                 '%(refname)s_complete(%(var)s) == -1)',
-                 '  return (-1);' ]
+        code = [
+            "if (%(structname)s->%(name)s_set && "
+            "%(refname)s_complete(%(var)s) == -1)",
+            "  return (-1);",
+        ]
 
-        return TranslateList(code, self.GetTranslation({
-            'structname' : structname,
-            'var' : var_name }))
+        return TranslateList(
+            code, self.GetTranslation({"structname": structname, "var": var_name})
+        )
 
-    def CodeUnmarshal(self, buf, tag_name, var_name, var_len):
-        code = ['%(var)s = %(refname)s_new();',
-                'if (%(var)s == NULL)',
-                '  return (-1);',
-                'if (evtag_unmarshal_%(refname)s(%(buf)s, %(tag)s, '
-                '%(var)s) == -1) {',
-                  '  event_warnx("%%s: failed to unmarshal %(name)s", __func__);',
-                '  return (-1);',
-                '}'
-                ]
-        code = '\n'.join(code) % self.GetTranslation({
-            'buf' : buf,
-            'tag' : tag_name,
-            'var' : var_name })
-        return code.split('\n')
+    def CodeUnmarshal(self, buf, tag_name, var_name, _var_len):
+        code = [
+            "%(var)s = %(refname)s_new();",
+            "if (%(var)s == NULL)",
+            "  return (-1);",
+            "if (evtag_unmarshal_%(refname)s(%(buf)s, %(tag)s, ",
+            "    %(var)s) == -1) {",
+            '  event_warnx("%%s: failed to unmarshal %(name)s", __func__);',
+            "  return (-1);",
+            "}",
+        ]
+        code = "\n".join(code) % self.GetTranslation(
+            {"buf": buf, "tag": tag_name, "var": var_name}
+        )
+        return code.split("\n")
 
-    def CodeMarshal(self, buf, tag_name, var_name, var_len):
-        code = ['evtag_marshal_%s(%s, %s, %s);' % (
-            self._refname, buf, tag_name, var_name)]
+    def CodeMarshal(self, buf, tag_name, var_name, _var_len):
+        code = [
+            "evtag_marshal_%s(%s, %s, %s);" % (self._refname, buf, tag_name, var_name)
+        ]
         return code
 
     def CodeClear(self, structname):
-        code = [ 'if (%s->%s_set == 1) {' % (structname, self.Name()),
-                 '  %s_free(%s->%s_data);' % (
-            self._refname, structname, self.Name()),
-                 '  %s->%s_data = NULL;' % (structname, self.Name()),
-                 '  %s->%s_set = 0;' % (structname, self.Name()),
-                 '}'
-                 ]
+        code = [
+            "if (%s->%s_set == 1) {" % (structname, self.Name()),
+            "  %s_free(%s->%s_data);" % (self._refname, structname, self.Name()),
+            "  %s->%s_data = NULL;" % (structname, self.Name()),
+            "  %s->%s_set = 0;" % (structname, self.Name()),
+            "}",
+        ]
 
         return code
 
     def CodeInitialize(self, name):
-        code  = ['%s->%s_data = NULL;' % (name, self._name)]
+        code = ["%s->%s_data = NULL;" % (name, self._name)]
         return code
 
     def CodeFree(self, name):
-        code  = ['if (%s->%s_data != NULL)' % (name, self._name),
-                 '    %s_free(%s->%s_data);' % (
-            self._refname, name, self._name)]
+        code = [
+            "if (%s->%s_data != NULL)" % (name, self._name),
+            "    %s_free(%s->%s_data);" % (self._refname, name, self._name),
+        ]
 
         return code
 
     def Declaration(self):
-        dcl  = ['%s %s_data;' % (self._ctype, self._name)]
+        dcl = ["%s %s_data;" % (self._ctype, self._name)]
 
         return dcl
 
+
 class EntryVarBytes(Entry):
-    def __init__(self, type, name, tag):
+    def __init__(self, ent_type, name, tag):
         # Init base class
-        Entry.__init__(self, type, name, tag)
+        super(EntryVarBytes, self).__init__(ent_type, name, tag)
 
-        self._ctype = 'ev_uint8_t *'
+        self._ctype = "ev_uint8_t *"
 
-    def GetInitializer(self):
+    @staticmethod
+    def GetInitializer():
         return "NULL"
 
     def GetVarLen(self, var):
-        return '%(var)s->%(name)s_length' % self.GetTranslation({ 'var' : var })
+        return "%(var)s->%(name)s_length" % self.GetTranslation({"var": var})
 
-    def CodeArrayAdd(self, varname, value):
+    @staticmethod
+    def CodeArrayAdd(varname, _value):
         # xxx: copy
-        return [ '%(varname)s = NULL;' % { 'varname' : varname } ]
+        return ["%(varname)s = NULL;" % {"varname": varname}]
 
     def GetDeclaration(self, funcname):
-        code = [ 'int %s(struct %s *, %s *, ev_uint32_t *);' % (
-            funcname, self._struct.Name(), self._ctype ) ]
+        code = [
+            "int %s(struct %s *, %s *, ev_uint32_t *);"
+            % (funcname, self._struct.Name(), self._ctype)
+        ]
         return code
 
     def AssignDeclaration(self, funcname):
-        code = [ 'int %s(struct %s *, const %s, ev_uint32_t);' % (
-            funcname, self._struct.Name(), self._ctype ) ]
+        code = [
+            "int %s(struct %s *, const %s, ev_uint32_t);"
+            % (funcname, self._struct.Name(), self._ctype)
+        ]
         return code
 
     def CodeAssign(self):
         name = self._name
-        code = [ 'int',
-                 '%s_%s_assign(struct %s *msg, '
-                 'const %s value, ev_uint32_t len)' % (
-            self._struct.Name(), name,
-            self._struct.Name(), self._ctype),
-                 '{',
-                 '  if (msg->%s_data != NULL)' % name,
-                 '    free (msg->%s_data);' % name,
-                 '  msg->%s_data = malloc(len);' % name,
-                 '  if (msg->%s_data == NULL)' % name,
-                 '    return (-1);',
-                 '  msg->%s_set = 1;' % name,
-                 '  msg->%s_length = len;' % name,
-                 '  memcpy(msg->%s_data, value, len);' % name,
-                 '  return (0);',
-                 '}' ]
+        code = [
+            "int",
+            "%s_%s_assign(struct %s *msg, "
+            "const %s value, ev_uint32_t len)"
+            % (self._struct.Name(), name, self._struct.Name(), self._ctype),
+            "{",
+            "  if (msg->%s_data != NULL)" % name,
+            "    free (msg->%s_data);" % name,
+            "  msg->%s_data = malloc(len);" % name,
+            "  if (msg->%s_data == NULL)" % name,
+            "    return (-1);",
+            "  msg->%s_set = 1;" % name,
+            "  msg->%s_length = len;" % name,
+            "  memcpy(msg->%s_data, value, len);" % name,
+            "  return (0);",
+            "}",
+        ]
         return code
 
     def CodeGet(self):
         name = self._name
-        code = [ 'int',
-                 '%s_%s_get(struct %s *msg, %s *value, ev_uint32_t *plen)' % (
-            self._struct.Name(), name,
-            self._struct.Name(), self._ctype),
-                 '{',
-                 '  if (msg->%s_set != 1)' % name,
-                 '    return (-1);',
-                 '  *value = msg->%s_data;' % name,
-                 '  *plen = msg->%s_length;' % name,
-                 '  return (0);',
-                 '}' ]
+        code = [
+            "int",
+            "%s_%s_get(struct %s *msg, %s *value, ev_uint32_t *plen)"
+            % (self._struct.Name(), name, self._struct.Name(), self._ctype),
+            "{",
+            "  if (msg->%s_set != 1)" % name,
+            "    return (-1);",
+            "  *value = msg->%s_data;" % name,
+            "  *plen = msg->%s_length;" % name,
+            "  return (0);",
+            "}",
+        ]
         return code
 
     def CodeUnmarshal(self, buf, tag_name, var_name, var_len):
-        code = ['if (evtag_payload_length(%(buf)s, &%(varlen)s) == -1)',
-                '  return (-1);',
-                # We do not want DoS opportunities
-                'if (%(varlen)s > evbuffer_get_length(%(buf)s))',
-                '  return (-1);',
-                'if ((%(var)s = malloc(%(varlen)s)) == NULL)',
-                '  return (-1);',
-                'if (evtag_unmarshal_fixed(%(buf)s, %(tag)s, %(var)s, '
-                '%(varlen)s) == -1) {',
-                '  event_warnx("%%s: failed to unmarshal %(name)s", __func__);',
-                '  return (-1);',
-                '}'
-                ]
-        code = '\n'.join(code) % self.GetTranslation({
-            'buf' : buf,
-            'tag' : tag_name,
-            'var' : var_name,
-            'varlen' : var_len })
-        return code.split('\n')
+        code = [
+            "if (evtag_payload_length(%(buf)s, &%(varlen)s) == -1)",
+            "  return (-1);",
+            # We do not want DoS opportunities
+            "if (%(varlen)s > evbuffer_get_length(%(buf)s))",
+            "  return (-1);",
+            "if ((%(var)s = malloc(%(varlen)s)) == NULL)",
+            "  return (-1);",
+            "if (evtag_unmarshal_fixed(%(buf)s, %(tag)s, %(var)s, "
+            "%(varlen)s) == -1) {",
+            '  event_warnx("%%s: failed to unmarshal %(name)s", __func__);',
+            "  return (-1);",
+            "}",
+        ]
+        code = "\n".join(code) % self.GetTranslation(
+            {"buf": buf, "tag": tag_name, "var": var_name, "varlen": var_len}
+        )
+        return code.split("\n")
 
-    def CodeMarshal(self, buf, tag_name, var_name, var_len):
-        code = ['evtag_marshal(%s, %s, %s, %s);' % (
-            buf, tag_name, var_name, var_len)]
+    @staticmethod
+    def CodeMarshal(buf, tag_name, var_name, var_len):
+        code = ["evtag_marshal(%s, %s, %s, %s);" % (buf, tag_name, var_name, var_len)]
         return code
 
     def CodeClear(self, structname):
-        code = [ 'if (%s->%s_set == 1) {' % (structname, self.Name()),
-                 '  free (%s->%s_data);' % (structname, self.Name()),
-                 '  %s->%s_data = NULL;' % (structname, self.Name()),
-                 '  %s->%s_length = 0;' % (structname, self.Name()),
-                 '  %s->%s_set = 0;' % (structname, self.Name()),
-                 '}'
-                 ]
+        code = [
+            "if (%s->%s_set == 1) {" % (structname, self.Name()),
+            "  free (%s->%s_data);" % (structname, self.Name()),
+            "  %s->%s_data = NULL;" % (structname, self.Name()),
+            "  %s->%s_length = 0;" % (structname, self.Name()),
+            "  %s->%s_set = 0;" % (structname, self.Name()),
+            "}",
+        ]
 
         return code
 
     def CodeInitialize(self, name):
-        code  = ['%s->%s_data = NULL;' % (name, self._name),
-                 '%s->%s_length = 0;' % (name, self._name) ]
+        code = [
+            "%s->%s_data = NULL;" % (name, self._name),
+            "%s->%s_length = 0;" % (name, self._name),
+        ]
         return code
 
     def CodeFree(self, name):
-        code  = ['if (%s->%s_data != NULL)' % (name, self._name),
-                 '    free(%s->%s_data);' % (name, self._name)]
+        code = [
+            "if (%s->%s_data != NULL)" % (name, self._name),
+            "    free(%s->%s_data);" % (name, self._name),
+        ]
 
         return code
 
     def Declaration(self):
-        dcl  = ['ev_uint8_t *%s_data;' % self._name,
-                'ev_uint32_t %s_length;' % self._name]
+        dcl = [
+            "ev_uint8_t *%s_data;" % self._name,
+            "ev_uint32_t %s_length;" % self._name,
+        ]
 
         return dcl
 
+
 class EntryArray(Entry):
+    _index = None
+
     def __init__(self, entry):
         # Init base class
-        Entry.__init__(self, entry._type, entry._name, entry._tag)
+        super(EntryArray, self).__init__(entry._type, entry._name, entry._tag)
 
         self._entry = entry
         self._refname = entry._refname
@@ -1065,37 +1201,42 @@
 
         # provide a new function for accessing the variable name
         def GetVarName(var_name):
-            return '%(var)s->%(name)s_data[%(index)s]' % \
-                   self._entry.GetTranslation({'var' : var_name,
-                                               'index' : self._index})
+            return "%(var)s->%(name)s_data[%(index)s]" % self._entry.GetTranslation(
+                {"var": var_name, "index": self._index}
+            )
+
         self._entry.GetVarName = GetVarName
 
     def GetInitializer(self):
         return "NULL"
 
-    def GetVarName(self, var_name):
-        return var_name
+    def GetVarName(self, var):
+        return var
 
-    def GetVarLen(self, var_name):
-        return '-1'
+    def GetVarLen(self, _var_name):
+        return "-1"
 
     def GetDeclaration(self, funcname):
         """Allows direct access to elements of the array."""
         code = [
-            'int %(funcname)s(struct %(parent_name)s *, int, %(ctype)s *);' %
-            self.GetTranslation({ 'funcname' : funcname }) ]
+            "int %(funcname)s(struct %(parent_name)s *, int, %(ctype)s *);"
+            % self.GetTranslation({"funcname": funcname})
+        ]
         return code
 
     def AssignDeclaration(self, funcname):
-        code = [ 'int %s(struct %s *, int, const %s);' % (
-            funcname, self._struct.Name(), self._ctype ) ]
+        code = [
+            "int %s(struct %s *, int, const %s);"
+            % (funcname, self._struct.Name(), self._ctype)
+        ]
         return code
 
     def AddDeclaration(self, funcname):
         code = [
-            '%(ctype)s %(optpointer)s '
-            '%(funcname)s(struct %(parent_name)s *msg%(optaddarg)s);' % \
-            self.GetTranslation({ 'funcname' : funcname }) ]
+            "%(ctype)s %(optpointer)s "
+            "%(funcname)s(struct %(parent_name)s *msg%(optaddarg)s);"
+            % self.GetTranslation({"funcname": funcname})
+        ]
         return code
 
     def CodeGet(self):
@@ -1107,226 +1248,249 @@
     return (-1);
   *value = msg->%(name)s_data[offset];
   return (0);
-}""" % self.GetTranslation()
+}
+""" % (
+            self.GetTranslation()
+        )
 
-        return code.split('\n')
+        return code.splitlines()
 
     def CodeAssign(self):
         code = [
-            'int',
-            '%(parent_name)s_%(name)s_assign(struct %(parent_name)s *msg, int off,',
-            '    const %(ctype)s value)',
-            '{',
-            '  if (!msg->%(name)s_set || off < 0 || off >= msg->%(name)s_length)',
-            '    return (-1);\n',
-            '  {' ]
+            "int",
+            "%(parent_name)s_%(name)s_assign(struct %(parent_name)s *msg, int off,",
+            "  const %(ctype)s value)",
+            "{",
+            "  if (!msg->%(name)s_set || off < 0 || off >= msg->%(name)s_length)",
+            "    return (-1);",
+            "",
+            "  {",
+        ]
         code = TranslateList(code, self.GetTranslation())
 
         codearrayassign = self._entry.CodeArrayAssign(
-            'msg->%(name)s_data[off]' % self.GetTranslation(), 'value')
-        code += ['    ' + x for x in codearrayassign]
+            "msg->%(name)s_data[off]" % self.GetTranslation(), "value"
+        )
+        code += ["    " + x for x in codearrayassign]
 
-        code += TranslateList([
-            '  }',
-            '  return (0);',
-            '}' ], self.GetTranslation())
+        code += TranslateList(["  }", "  return (0);", "}"], self.GetTranslation())
 
         return code
 
     def CodeAdd(self):
         codearrayadd = self._entry.CodeArrayAdd(
-            'msg->%(name)s_data[msg->%(name)s_length - 1]' % self.GetTranslation(),
-            'value')
+            "msg->%(name)s_data[msg->%(name)s_length - 1]" % self.GetTranslation(),
+            "value",
+        )
         code = [
-            'static int',
-            '%(parent_name)s_%(name)s_expand_to_hold_more('
-            'struct %(parent_name)s *msg)',
-            '{',
-            '  int tobe_allocated = msg->%(name)s_num_allocated;',
-            '  %(ctype)s* new_data = NULL;',
-            '  tobe_allocated = !tobe_allocated ? 1 : tobe_allocated << 1;',
-            '  new_data = (%(ctype)s*) realloc(msg->%(name)s_data,',
-            '      tobe_allocated * sizeof(%(ctype)s));',
-            '  if (new_data == NULL)',
-            '    return -1;',
-            '  msg->%(name)s_data = new_data;',
-            '  msg->%(name)s_num_allocated = tobe_allocated;',
-            '  return 0;'
-            '}',
-            '',
-            '%(ctype)s %(optpointer)s',
-            '%(parent_name)s_%(name)s_add('
-            'struct %(parent_name)s *msg%(optaddarg)s)',
-            '{',
-            '  if (++msg->%(name)s_length >= msg->%(name)s_num_allocated) {',
-            '    if (%(parent_name)s_%(name)s_expand_to_hold_more(msg)<0)',
-            '      goto error;',
-            '  }' ]
+            "static int",
+            "%(parent_name)s_%(name)s_expand_to_hold_more("
+            "struct %(parent_name)s *msg)",
+            "{",
+            "  int tobe_allocated = msg->%(name)s_num_allocated;",
+            "  %(ctype)s* new_data = NULL;",
+            "  tobe_allocated = !tobe_allocated ? 1 : tobe_allocated << 1;",
+            "  new_data = (%(ctype)s*) realloc(msg->%(name)s_data,",
+            "      tobe_allocated * sizeof(%(ctype)s));",
+            "  if (new_data == NULL)",
+            "    return -1;",
+            "  msg->%(name)s_data = new_data;",
+            "  msg->%(name)s_num_allocated = tobe_allocated;",
+            "  return 0;",
+            "}",
+            "",
+            "%(ctype)s %(optpointer)s",
+            "%(parent_name)s_%(name)s_add(struct %(parent_name)s *msg%(optaddarg)s)",
+            "{",
+            "  if (++msg->%(name)s_length >= msg->%(name)s_num_allocated) {",
+            "    if (%(parent_name)s_%(name)s_expand_to_hold_more(msg)<0)",
+            "      goto error;",
+            "  }",
+        ]
 
         code = TranslateList(code, self.GetTranslation())
 
-        code += ['  ' + x for x in codearrayadd]
+        code += ["  " + x for x in codearrayadd]
 
-        code += TranslateList([
-            '  msg->%(name)s_set = 1;',
-            '  return %(optreference)s(msg->%(name)s_data['
-            'msg->%(name)s_length - 1]);',
-            'error:',
-            '  --msg->%(name)s_length;',
-            '  return (NULL);',
-            '}' ], self.GetTranslation())
+        code += TranslateList(
+            [
+                "  msg->%(name)s_set = 1;",
+                "  return %(optreference)s(msg->%(name)s_data["
+                "msg->%(name)s_length - 1]);",
+                "error:",
+                "  --msg->%(name)s_length;",
+                "  return (NULL);",
+                "}",
+            ],
+            self.GetTranslation(),
+        )
 
         return code
 
     def CodeComplete(self, structname, var_name):
-        self._index = 'i'
+        self._index = "i"
         tmp = self._entry.CodeComplete(structname, self._entry.GetVarName(var_name))
         # skip the whole loop if there is nothing to check
         if not tmp:
             return []
 
-        translate = self.GetTranslation({ 'structname' : structname })
+        translate = self.GetTranslation({"structname": structname})
         code = [
-            '{',
-            '  int i;',
-            '  for (i = 0; i < %(structname)s->%(name)s_length; ++i) {' ]
+            "{",
+            "  int i;",
+            "  for (i = 0; i < %(structname)s->%(name)s_length; ++i) {",
+        ]
 
         code = TranslateList(code, translate)
 
-        code += ['    ' + x for x in tmp]
+        code += ["    " + x for x in tmp]
 
-        code += [
-            '  }',
-            '}' ]
+        code += ["  }", "}"]
 
         return code
 
-    def CodeUnmarshal(self, buf, tag_name, var_name, var_len):
-        translate = self.GetTranslation({ 'var' : var_name,
-                                          'buf' : buf,
-                                          'tag' : tag_name,
-                                          'init' : self._entry.GetInitializer()})
+    def CodeUnmarshal(self, buf, tag_name, var_name, _var_len):
+        translate = self.GetTranslation(
+            {
+                "var": var_name,
+                "buf": buf,
+                "tag": tag_name,
+                "init": self._entry.GetInitializer(),
+            }
+        )
         code = [
-            'if (%(var)s->%(name)s_length >= %(var)s->%(name)s_num_allocated &&',
-            '    %(parent_name)s_%(name)s_expand_to_hold_more(%(var)s) < 0) {',
+            "if (%(var)s->%(name)s_length >= %(var)s->%(name)s_num_allocated &&",
+            "    %(parent_name)s_%(name)s_expand_to_hold_more(%(var)s) < 0) {",
             '  puts("HEY NOW");',
-            '  return (-1);',
-            '}']
+            "  return (-1);",
+            "}",
+        ]
 
         # the unmarshal code directly returns
         code = TranslateList(code, translate)
 
-        self._index = '%(var)s->%(name)s_length' % translate
-        code += self._entry.CodeUnmarshal(buf, tag_name,
-                                        self._entry.GetVarName(var_name),
-                                        self._entry.GetVarLen(var_name))
+        self._index = "%(var)s->%(name)s_length" % translate
+        code += self._entry.CodeUnmarshal(
+            buf,
+            tag_name,
+            self._entry.GetVarName(var_name),
+            self._entry.GetVarLen(var_name),
+        )
 
-        code += [ '++%(var)s->%(name)s_length;' % translate ]
+        code += ["++%(var)s->%(name)s_length;" % translate]
 
         return code
 
-    def CodeMarshal(self, buf, tag_name, var_name, var_len):
-        code = ['{',
-                '  int i;',
-                '  for (i = 0; i < %(var)s->%(name)s_length; ++i) {' ]
+    def CodeMarshal(self, buf, tag_name, var_name, _var_len):
+        code = ["{", "  int i;", "  for (i = 0; i < %(var)s->%(name)s_length; ++i) {"]
 
-        self._index = 'i'
-        code += self._entry.CodeMarshal(buf, tag_name,
-                                        self._entry.GetVarName(var_name),
-                                        self._entry.GetVarLen(var_name))
-        code += ['  }',
-                 '}'
-                 ]
+        self._index = "i"
+        code += self._entry.CodeMarshal(
+            buf,
+            tag_name,
+            self._entry.GetVarName(var_name),
+            self._entry.GetVarLen(var_name),
+        )
+        code += ["  }", "}"]
 
-        code = "\n".join(code) % self.GetTranslation({ 'var' : var_name })
+        code = "\n".join(code) % self.GetTranslation({"var": var_name})
 
-        return code.split('\n')
+        return code.split("\n")
 
     def CodeClear(self, structname):
-        translate = self.GetTranslation({ 'structname' : structname })
+        translate = self.GetTranslation({"structname": structname})
         codearrayfree = self._entry.CodeArrayFree(
-            '%(structname)s->%(name)s_data[i]' % self.GetTranslation(
-            { 'structname' : structname } ))
+            "%(structname)s->%(name)s_data[i]"
+            % self.GetTranslation({"structname": structname})
+        )
 
-        code = [ 'if (%(structname)s->%(name)s_set == 1) {' ]
+        code = ["if (%(structname)s->%(name)s_set == 1) {"]
 
         if codearrayfree:
             code += [
-                '  int i;',
-                '  for (i = 0; i < %(structname)s->%(name)s_length; ++i) {' ]
+                "  int i;",
+                "  for (i = 0; i < %(structname)s->%(name)s_length; ++i) {",
+            ]
 
         code = TranslateList(code, translate)
 
         if codearrayfree:
-            code += ['    ' + x for x in codearrayfree]
-            code += [
-                '  }' ]
+            code += ["    " + x for x in codearrayfree]
+            code += ["  }"]
 
-        code += TranslateList([
-                 '  free(%(structname)s->%(name)s_data);',
-                 '  %(structname)s->%(name)s_data = NULL;',
-                 '  %(structname)s->%(name)s_set = 0;',
-                 '  %(structname)s->%(name)s_length = 0;',
-                 '  %(structname)s->%(name)s_num_allocated = 0;',
-                 '}'
-                 ], translate)
+        code += TranslateList(
+            [
+                "  free(%(structname)s->%(name)s_data);",
+                "  %(structname)s->%(name)s_data = NULL;",
+                "  %(structname)s->%(name)s_set = 0;",
+                "  %(structname)s->%(name)s_length = 0;",
+                "  %(structname)s->%(name)s_num_allocated = 0;",
+                "}",
+            ],
+            translate,
+        )
 
         return code
 
     def CodeInitialize(self, name):
-        code  = ['%s->%s_data = NULL;' % (name, self._name),
-                 '%s->%s_length = 0;' % (name, self._name),
-                 '%s->%s_num_allocated = 0;' % (name, self._name)]
+        code = [
+            "%s->%s_data = NULL;" % (name, self._name),
+            "%s->%s_length = 0;" % (name, self._name),
+            "%s->%s_num_allocated = 0;" % (name, self._name),
+        ]
         return code
 
     def CodeFree(self, structname):
-        code = self.CodeClear(structname);
+        code = self.CodeClear(structname)
 
-        code += TranslateList([
-            'free(%(structname)s->%(name)s_data);' ],
-                              self.GetTranslation({'structname' : structname }))
+        code += TranslateList(
+            ["free(%(structname)s->%(name)s_data);"],
+            self.GetTranslation({"structname": structname}),
+        )
 
         return code
 
     def Declaration(self):
-        dcl  = ['%s *%s_data;' % (self._ctype, self._name),
-                'int %s_length;' % self._name,
-                'int %s_num_allocated;' % self._name ]
+        dcl = [
+            "%s *%s_data;" % (self._ctype, self._name),
+            "int %s_length;" % self._name,
+            "int %s_num_allocated;" % self._name,
+        ]
 
         return dcl
 
-def NormalizeLine(line):
-    global white
-    global cppcomment
 
-    line = cppcomment.sub('', line)
+def NormalizeLine(line):
+
+    line = CPPCOMMENT_RE.sub("", line)
     line = line.strip()
-    line = white.sub(' ', line)
+    line = WHITESPACE_RE.sub(" ", line)
 
     return line
 
+
+ENTRY_NAME_RE = re.compile(r"(?P<name>[^\[\]]+)(\[(?P<fixed_length>.*)\])?")
+ENTRY_TAG_NUMBER_RE = re.compile(r"(0x)?\d+", re.I)
+
+
 def ProcessOneEntry(factory, newstruct, entry):
-    optional = 0
-    array = 0
-    entry_type = ''
-    name = ''
-    tag = ''
+    optional = False
+    array = False
+    entry_type = ""
+    name = ""
+    tag = ""
     tag_set = None
-    separator = ''
-    fixed_length = ''
+    separator = ""
+    fixed_length = ""
 
-    tokens = entry.split(' ')
-    while tokens:
-        token = tokens[0]
-        tokens = tokens[1:]
-
+    for token in entry.split(" "):
         if not entry_type:
-            if not optional and token == 'optional':
-                optional = 1
+            if not optional and token == "optional":
+                optional = True
                 continue
 
-            if not array and token == 'array':
-                array = 1
+            if not array and token == "array":
+                array = True
                 continue
 
         if not entry_type:
@@ -1334,53 +1498,52 @@
             continue
 
         if not name:
-            res = re.match(r'^([^\[\]]+)(\[.*\])?$', token)
+            res = ENTRY_NAME_RE.match(token)
             if not res:
-                 raise RpcGenError(
-                     'Cannot parse name: \"%s\" '
-                     'around line %d' % (entry, line_count))
-            name = res.group(1)
-            fixed_length = res.group(2)
-            if fixed_length:
-                fixed_length = fixed_length[1:-1]
+                raise RpcGenError(
+                    r"""Cannot parse name: "%s" around line %d""" % (entry, LINE_COUNT)
+                )
+            name = res.group("name")
+            fixed_length = res.group("fixed_length")
             continue
 
         if not separator:
             separator = token
-            if separator != '=':
-                 raise RpcGenError('Expected "=" after name \"%s\" got %s'
-                                   % (name, token))
+            if separator != "=":
+                raise RpcGenError(
+                    r'''Expected "=" after name "%s" got "%s"''' % (name, token)
+                )
             continue
 
         if not tag_set:
             tag_set = 1
-            if not re.match(r'^(0x)?[0-9]+$', token):
-                raise RpcGenError('Expected tag number: \"%s\"' % entry)
+            if not ENTRY_TAG_NUMBER_RE.match(token):
+                raise RpcGenError(r'''Expected tag number: "%s"''' % (entry))
             tag = int(token, 0)
             continue
 
-        raise RpcGenError('Cannot parse \"%s\"' % entry)
+        raise RpcGenError(r'''Cannot parse "%s"''' % (entry))
 
     if not tag_set:
-        raise RpcGenError('Need tag number: \"%s\"' % entry)
+        raise RpcGenError(r'''Need tag number: "%s"''' % (entry))
 
     # Create the right entry
-    if entry_type == 'bytes':
+    if entry_type == "bytes":
         if fixed_length:
             newentry = factory.EntryBytes(entry_type, name, tag, fixed_length)
         else:
             newentry = factory.EntryVarBytes(entry_type, name, tag)
-    elif entry_type == 'int' and not fixed_length:
+    elif entry_type == "int" and not fixed_length:
         newentry = factory.EntryInt(entry_type, name, tag)
-    elif entry_type == 'int64' and not fixed_length:
+    elif entry_type == "int64" and not fixed_length:
         newentry = factory.EntryInt(entry_type, name, tag, bits=64)
-    elif entry_type == 'string' and not fixed_length:
+    elif entry_type == "string" and not fixed_length:
         newentry = factory.EntryString(entry_type, name, tag)
     else:
-        res = structref.match(entry_type)
+        res = STRUCT_REF_RE.match(entry_type)
         if res:
             # References another struct defined in our file
-            newentry = factory.EntryStruct(entry_type, name, tag, res.group(1))
+            newentry = factory.EntryStruct(entry_type, name, tag, res.group("name"))
         else:
             raise RpcGenError('Bad type: "%s" in "%s"' % (entry_type, entry))
 
@@ -1392,32 +1555,30 @@
         newentry.MakeArray()
 
     newentry.SetStruct(newstruct)
-    newentry.SetLineCount(line_count)
+    newentry.SetLineCount(LINE_COUNT)
     newentry.Verify()
 
     if array:
         # We need to encapsulate this entry into a struct
-        newname = newentry.Name()+ '_array'
-
-        # Now borgify the new entry.
         newentry = factory.EntryArray(newentry)
         newentry.SetStruct(newstruct)
-        newentry.SetLineCount(line_count)
+        newentry.SetLineCount(LINE_COUNT)
         newentry.MakeArray()
 
     newstruct.AddEntry(newentry)
 
     return structs
 
+
 def ProcessStruct(factory, data):
-    tokens = data.split(' ')
+    tokens = data.split(" ")
 
     # First three tokens are: 'struct' 'name' '{'
     newstruct = factory.Struct(tokens[1])
 
-    inside = ' '.join(tokens[3:-1])
+    inside = " ".join(tokens[3:-1])
 
-    tokens = inside.split(';')
+    tokens = inside.split(";")
 
     structs = []
 
@@ -1432,36 +1593,52 @@
     structs.append(newstruct)
     return structs
 
-def GetNextStruct(file):
-    global line_count
-    global cppdirect
 
-    got_struct = 0
+C_COMMENT_START = "/*"
+C_COMMENT_END = "*/"
 
-    processed_lines = []
+C_COMMENT_START_RE = re.compile(re.escape(C_COMMENT_START))
+C_COMMENT_END_RE = re.compile(re.escape(C_COMMENT_END))
 
-    have_c_comment = 0
-    data = ''
-    while 1:
-        line = file.readline()
+C_COMMENT_START_SUB_RE = re.compile(r"%s.*$" % (re.escape(C_COMMENT_START)))
+C_COMMENT_END_SUB_RE = re.compile(r"%s.*$" % (re.escape(C_COMMENT_END)))
+
+C_MULTILINE_COMMENT_SUB_RE = re.compile(
+    r"%s.*?%s" % (re.escape(C_COMMENT_START), re.escape(C_COMMENT_END))
+)
+CPP_CONDITIONAL_BLOCK_RE = re.compile(r"#(if( |def)|endif)")
+INCLUDE_RE = re.compile(r'#include (".+"|<.+>)')
+
+
+def GetNextStruct(filep):
+    global CPP_DIRECT
+    global LINE_COUNT
+
+    got_struct = False
+    have_c_comment = False
+
+    data = ""
+
+    while True:
+        line = filep.readline()
         if not line:
             break
 
-        line_count += 1
+        LINE_COUNT += 1
         line = line[:-1]
 
-        if not have_c_comment and re.search(r'/\*', line):
-            if re.search(r'/\*.*?\*/', line):
-                line = re.sub(r'/\*.*?\*/', '', line)
+        if not have_c_comment and C_COMMENT_START_RE.search(line):
+            if C_MULTILINE_COMMENT_SUB_RE.search(line):
+                line = C_MULTILINE_COMMENT_SUB_RE.sub("", line)
             else:
-                line = re.sub(r'/\*.*$', '', line)
-                have_c_comment = 1
+                line = C_COMMENT_START_SUB_RE.sub("", line)
+                have_c_comment = True
 
         if have_c_comment:
-            if not re.search(r'\*/', line):
+            if not C_COMMENT_END_RE.search(line):
                 continue
-            have_c_comment = 0
-            line = re.sub(r'^.*\*/', '', line)
+            have_c_comment = False
+            line = C_COMMENT_END_SUB_RE.sub("", line)
 
         line = NormalizeLine(line)
 
@@ -1469,47 +1646,39 @@
             continue
 
         if not got_struct:
-            if re.match(r'#include ["<].*[>"]', line):
-                cppdirect.append(line)
-                continue
-
-            if re.match(r'^#(if( |def)|endif)', line):
-                cppdirect.append(line)
-                continue
-
-            if re.match(r'^#define', line):
-                headerdirect.append(line)
-                continue
-
-            if not structdef.match(line):
-                raise RpcGenError('Missing struct on line %d: %s'
-                                  % (line_count, line))
+            if INCLUDE_RE.match(line):
+                CPP_DIRECT.append(line)
+            elif CPP_CONDITIONAL_BLOCK_RE.match(line):
+                CPP_DIRECT.append(line)
+            elif PREPROCESSOR_DEF_RE.match(line):
+                HEADER_DIRECT.append(line)
+            elif not STRUCT_DEF_RE.match(line):
+                raise RpcGenError("Missing struct on line %d: %s" % (LINE_COUNT, line))
             else:
-                got_struct = 1
+                got_struct = True
                 data += line
             continue
 
         # We are inside the struct
-        tokens = line.split('}')
+        tokens = line.split("}")
         if len(tokens) == 1:
-            data += ' ' + line
+            data += " " + line
             continue
 
-        if len(tokens[1]):
-            raise RpcGenError('Trailing garbage after struct on line %d'
-                              % line_count)
+        if tokens[1]:
+            raise RpcGenError("Trailing garbage after struct on line %d" % LINE_COUNT)
 
         # We found the end of the struct
-        data += ' %s}' % tokens[0]
+        data += " %s}" % tokens[0]
         break
 
     # Remove any comments, that might be in there
-    data = re.sub(r'/\*.*\*/', '', data)
+    data = re.sub(r"/\*.*\*/", "", data)
 
     return data
 
 
-def Parse(factory, file):
+def Parse(factory, filep):
     """
     Parses the input file and returns C code and corresponding header file.
     """
@@ -1518,7 +1687,7 @@
 
     while 1:
         # Just gets the whole struct nicely formatted
-        data = GetNextStruct(file)
+        data = GetNextStruct(filep)
 
         if not data:
             break
@@ -1527,205 +1696,230 @@
 
     return entities
 
-class CCodeGenerator:
+
+class CCodeGenerator(object):
     def __init__(self):
         pass
 
-    def GuardName(self, name):
+    @staticmethod
+    def GuardName(name):
         # Use the complete provided path to the input file, with all
         # non-identifier characters replaced with underscores, to
         # reduce the chance of a collision between guard macros.
-        return 'EVENT_RPCOUT_' + nonident.sub('_', name).upper() + '_'
+        return "EVENT_RPCOUT_%s_" % (NONIDENT_RE.sub("_", name).upper())
 
     def HeaderPreamble(self, name):
         guard = self.GuardName(name)
-        pre = (
-            '/*\n'
-            ' * Automatically generated from %s\n'
-            ' */\n\n'
-            '#ifndef %s\n'
-            '#define %s\n\n' ) % (
-            name, guard, guard)
+        pre = """
+/*
+ * Automatically generated from %s
+ */
 
-        for statement in headerdirect:
-            pre += '%s\n' % statement
-        if headerdirect:
-            pre += '\n'
+#ifndef %s
+#define %s
 
-        pre += (
-            '#include <event2/util.h> /* for ev_uint*_t */\n'
-            '#include <event2/rpc.h>\n'
+""" % (
+            name,
+            guard,
+            guard,
         )
 
+        if HEADER_DIRECT:
+            for statement in HEADER_DIRECT:
+                pre += "%s\n" % statement
+            pre += "\n"
+
+        pre += """
+#include <event2/util.h> /* for ev_uint*_t */
+#include <event2/rpc.h>
+"""
+
         return pre
 
     def HeaderPostamble(self, name):
         guard = self.GuardName(name)
-        return '#endif  /* %s */' % guard
+        return "#endif  /* %s */" % (guard)
 
-    def BodyPreamble(self, name, header_file):
+    @staticmethod
+    def BodyPreamble(name, header_file):
         global _NAME
         global _VERSION
 
-        slash = header_file.rfind('/')
+        slash = header_file.rfind("/")
         if slash != -1:
-            header_file = header_file[slash+1:]
+            header_file = header_file[slash + 1 :]
 
-        pre = ( '/*\n'
-                ' * Automatically generated from %s\n'
-                ' * by %s/%s.  DO NOT EDIT THIS FILE.\n'
-                ' */\n\n' ) % (name, _NAME, _VERSION)
-        pre += ( '#include <stdlib.h>\n'
-                 '#include <string.h>\n'
-                 '#include <assert.h>\n'
-                 '#include <event2/event-config.h>\n'
-                 '#include <event2/event.h>\n'
-                 '#include <event2/buffer.h>\n'
-                 '#include <event2/tag.h>\n\n'
-                 '#if defined(EVENT__HAVE___func__)\n'
-                 '# ifndef __func__\n'
-                 '#  define __func__ __func__\n'
-                 '# endif\n'
-                 '#elif defined(EVENT__HAVE___FUNCTION__)\n'
-                 '# define __func__ __FUNCTION__\n'
-                 '#else\n'
-                 '# define __func__ __FILE__\n'
-                 '#endif\n\n'
-                 )
+        pre = """
+/*
+ * Automatically generated from %(name)s
+ * by %(script_name)s/%(script_version)s.  DO NOT EDIT THIS FILE.
+ */
 
-        for statement in cppdirect:
-            pre += '%s\n' % statement
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <event2/event-config.h>
+#include <event2/event.h>
+#include <event2/buffer.h>
+#include <event2/tag.h>
+
+#if defined(EVENT__HAVE___func__)
+# ifndef __func__
+#  define __func__ __func__
+# endif
+#elif defined(EVENT__HAVE___FUNCTION__)
+# define __func__ __FUNCTION__
+#else
+# define __func__ __FILE__
+#endif
+
+""" % {
+            "name": name,
+            "script_name": _NAME,
+            "script_version": _VERSION,
+        }
+
+        for statement in CPP_DIRECT:
+            pre += "%s\n" % statement
 
         pre += '\n#include "%s"\n\n' % header_file
 
-        pre += 'void event_warn(const char *fmt, ...);\n'
-        pre += 'void event_warnx(const char *fmt, ...);\n\n'
+        pre += "void event_warn(const char *fmt, ...);\n"
+        pre += "void event_warnx(const char *fmt, ...);\n\n"
 
         return pre
 
-    def HeaderFilename(self, filename):
-        return '.'.join(filename.split('.')[:-1]) + '.h'
+    @staticmethod
+    def HeaderFilename(filename):
+        return ".".join(filename.split(".")[:-1]) + ".h"
 
-    def CodeFilename(self, filename):
-        return '.'.join(filename.split('.')[:-1]) + '.gen.c'
+    @staticmethod
+    def CodeFilename(filename):
+        return ".".join(filename.split(".")[:-1]) + ".gen.c"
 
-    def Struct(self, name):
+    @staticmethod
+    def Struct(name):
         return StructCCode(name)
 
-    def EntryBytes(self, entry_type, name, tag, fixed_length):
+    @staticmethod
+    def EntryBytes(entry_type, name, tag, fixed_length):
         return EntryBytes(entry_type, name, tag, fixed_length)
 
-    def EntryVarBytes(self, entry_type, name, tag):
+    @staticmethod
+    def EntryVarBytes(entry_type, name, tag):
         return EntryVarBytes(entry_type, name, tag)
 
-    def EntryInt(self, entry_type, name, tag, bits=32):
+    @staticmethod
+    def EntryInt(entry_type, name, tag, bits=32):
         return EntryInt(entry_type, name, tag, bits)
 
-    def EntryString(self, entry_type, name, tag):
+    @staticmethod
+    def EntryString(entry_type, name, tag):
         return EntryString(entry_type, name, tag)
 
-    def EntryStruct(self, entry_type, name, tag, struct_name):
+    @staticmethod
+    def EntryStruct(entry_type, name, tag, struct_name):
         return EntryStruct(entry_type, name, tag, struct_name)
 
-    def EntryArray(self, entry):
+    @staticmethod
+    def EntryArray(entry):
         return EntryArray(entry)
 
-class Usage(RpcGenError):
-    def __init__(self, argv0):
-        RpcGenError.__init__("usage: %s input.rpc [[output.h] output.c]"
-                             % argv0)
 
-class CommandLine:
-    def __init__(self, argv):
+class CommandLine(object):
+    def __init__(self, argv=None):
         """Initialize a command-line to launch event_rpcgen, as if
            from a command-line with CommandLine(sys.argv).  If you're
            calling this directly, remember to provide a dummy value
            for sys.argv[0]
         """
+        global QUIETLY
+
         self.filename = None
         self.header_file = None
         self.impl_file = None
         self.factory = CCodeGenerator()
 
-        if len(argv) >= 2 and argv[1] == '--quiet':
-            global QUIETLY
-            QUIETLY = 1
-            del argv[1]
+        parser = argparse.ArgumentParser(
+            usage="%(prog)s [options] rpc-file [[h-file] c-file]"
+        )
+        parser.add_argument("--quiet", action="store_true", default=False)
+        parser.add_argument("rpc_file", type=argparse.FileType("r"))
 
-        if len(argv) < 2 or len(argv) > 4:
-            raise Usage(argv[0])
+        args, extra_args = parser.parse_known_args(args=argv)
 
-        self.filename = argv[1].replace('\\', '/')
-        if len(argv) == 3:
-            self.impl_file = argv[2].replace('\\', '/')
-        if len(argv) == 4:
-            self.header_file = argv[2].replace('\\', '/')
-            self.impl_file = argv[3].replace('\\', '/')
+        QUIETLY = args.quiet
 
-        if not self.filename:
-            raise Usage(argv[0])
+        if extra_args:
+            if len(extra_args) == 1:
+                self.impl_file = extra_args[0].replace("\\", "/")
+            elif len(extra_args) == 2:
+                self.header_file = extra_args[0].replace("\\", "/")
+                self.impl_file = extra_args[1].replace("\\", "/")
+            else:
+                parser.error("Spurious arguments provided")
+
+        self.rpc_file = args.rpc_file
 
         if not self.impl_file:
-            self.impl_file = self.factory.CodeFilename(self.filename)
+            self.impl_file = self.factory.CodeFilename(self.rpc_file.name)
 
         if not self.header_file:
             self.header_file = self.factory.HeaderFilename(self.impl_file)
 
-        if not self.impl_file.endswith('.c'):
-            raise RpcGenError("can only generate C implementation files")
-        if not self.header_file.endswith('.h'):
-            raise RpcGenError("can only generate C header files")
+        if not self.impl_file.endswith(".c"):
+            parser.error("can only generate C implementation files")
+        if not self.header_file.endswith(".h"):
+            parser.error("can only generate C header files")
 
     def run(self):
-        filename = self.filename
+        filename = self.rpc_file.name
         header_file = self.header_file
         impl_file = self.impl_file
         factory = self.factory
 
-        declare('Reading \"%s\"' % filename)
+        declare('Reading "%s"' % filename)
 
-        fp = open(filename, 'r')
-        entities = Parse(factory, fp)
-        fp.close()
+        with self.rpc_file:
+            entities = Parse(factory, self.rpc_file)
 
         declare('... creating "%s"' % header_file)
-        header_fp = open(header_file, 'w')
-        header_fp.write(factory.HeaderPreamble(filename))
+        with open(header_file, "w") as header_fp:
+            header_fp.write(factory.HeaderPreamble(filename))
 
-        # Create forward declarations: allows other structs to reference
-        # each other
-        for entry in entities:
-            entry.PrintForwardDeclaration(header_fp)
-        header_fp.write('\n')
+            # Create forward declarations: allows other structs to reference
+            # each other
+            for entry in entities:
+                entry.PrintForwardDeclaration(header_fp)
+            header_fp.write("\n")
 
-        for entry in entities:
-            entry.PrintTags(header_fp)
-            entry.PrintDeclaration(header_fp)
-        header_fp.write(factory.HeaderPostamble(filename))
-        header_fp.close()
+            for entry in entities:
+                entry.PrintTags(header_fp)
+                entry.PrintDeclaration(header_fp)
+            header_fp.write(factory.HeaderPostamble(filename))
 
         declare('... creating "%s"' % impl_file)
-        impl_fp = open(impl_file, 'w')
-        impl_fp.write(factory.BodyPreamble(filename, header_file))
-        for entry in entities:
-            entry.PrintCode(impl_fp)
-        impl_fp.close()
+        with open(impl_file, "w") as impl_fp:
+            impl_fp.write(factory.BodyPreamble(filename, header_file))
+            for entry in entities:
+                entry.PrintCode(impl_fp)
 
-if __name__ == '__main__':
+
+def main(argv=None):
     try:
-        CommandLine(sys.argv).run()
-        sys.exit(0)
-
+        CommandLine(argv=argv).run()
+        return 0
     except RpcGenError as e:
         sys.stderr.write(e)
-        sys.exit(1)
-
     except EnvironmentError as e:
         if e.filename and e.strerror:
             sys.stderr.write("%s: %s" % (e.filename, e.strerror))
-            sys.exit(1)
         elif e.strerror:
             sys.stderr.write(e.strerror)
-            sys.exit(1)
         else:
             raise
+    return 1
+
+
+if __name__ == "__main__":
+    sys.exit(main(argv=sys.argv[1:]))
diff --git a/evmap.c b/evmap.c
index ffc991f..e4e35c6 100644
--- a/evmap.c
+++ b/evmap.c
@@ -432,7 +432,7 @@
 	if (NULL == ctx)
 		return;
 	LIST_FOREACH(ev, &ctx->events, ev_io_next) {
-		if (ev->ev_events & events)
+		if (ev->ev_events & (events & ~EV_ET))
 			event_active_nolock_(ev, ev->ev_events & events, 1);
 	}
 }
diff --git a/evthread-internal.h b/evthread-internal.h
index 5fdf316..83e409f 100644
--- a/evthread-internal.h
+++ b/evthread-internal.h
@@ -38,7 +38,7 @@
 
 struct event_base;
 
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__CYGWIN__)
 /* On Windows, the way we currently make DLLs, it's not allowed for us to
  * have shared global structures.  Thus, we only do the direct-call-to-function
  * code path if we know that the local shared library system supports it.
diff --git a/evutil.c b/evutil.c
index 3412c2a..9817f08 100644
--- a/evutil.c
+++ b/evutil.c
@@ -41,6 +41,7 @@
 /* For structs needed by GetAdaptersAddresses */
 #define _WIN32_WINNT 0x0501
 #include <iphlpapi.h>
+#include <netioapi.h>
 #endif
 
 #include <sys/types.h>
@@ -74,6 +75,9 @@
 #endif
 #include <time.h>
 #include <sys/stat.h>
+#ifndef _WIN32
+#include <net/if.h>
+#endif
 #ifdef EVENT__HAVE_IFADDRS_H
 #include <ifaddrs.h>
 #endif
@@ -694,7 +698,7 @@
 	   "GetAdaptersInfo", but that's deprecated; let's just try
 	   GetAdaptersAddresses and fall back to connect+getsockname.
 	*/
-	HMODULE lib = evutil_load_windows_system_library_(TEXT("ihplapi.dll"));
+	HMODULE lib = evutil_load_windows_system_library_(TEXT("iphlpapi.dll"));
 	GetAdaptersAddresses_fn_t fn;
 	ULONG size, res;
 	IP_ADAPTER_ADDRESSES *addresses = NULL, *address;
@@ -990,6 +994,7 @@
     struct evutil_addrinfo *hints, struct evutil_addrinfo **res, int *portnum)
 {
 	int port = 0;
+	unsigned int if_index;
 	const char *pname;
 
 	if (nodename == NULL && servname == NULL)
@@ -1063,10 +1068,12 @@
 	if (hints->ai_family == PF_INET6 || hints->ai_family == PF_UNSPEC) {
 		struct sockaddr_in6 sin6;
 		memset(&sin6, 0, sizeof(sin6));
-		if (1==evutil_inet_pton(AF_INET6, nodename, &sin6.sin6_addr)) {
+		if (1 == evutil_inet_pton_scope(
+			AF_INET6, nodename, &sin6.sin6_addr, &if_index)) {
 			/* Got an ipv6 address. */
 			sin6.sin6_family = AF_INET6;
 			sin6.sin6_port = htons(port);
+			sin6.sin6_scope_id = if_index;
 			*res = evutil_new_addrinfo_((struct sockaddr*)&sin6,
 			    sizeof(sin6), hints);
 			if (!*res)
@@ -1982,6 +1989,41 @@
 }
 
 int
+evutil_inet_pton_scope(int af, const char *src, void *dst, unsigned *indexp)
+{
+	int r;
+	unsigned if_index;
+	char *check, *cp, *tmp_src;
+
+	*indexp = 0; /* Reasonable default */
+
+	/* Bail out if not IPv6 */
+	if (af != AF_INET6)
+		return evutil_inet_pton(af, src, dst);
+
+	cp = strchr(src, '%');
+
+	/* Bail out if no zone ID */
+	if (cp == NULL)
+		return evutil_inet_pton(af, src, dst);
+
+	if_index = if_nametoindex(cp + 1);
+	if (if_index == 0) {
+		/* Could be numeric */
+		if_index = strtoul(cp + 1, &check, 10);
+		if (check[0] != '\0')
+			return 0;
+	}
+	*indexp = if_index;
+	tmp_src = mm_strdup(src);
+	cp = strchr(tmp_src, '%');
+	*cp = '\0';
+	r = evutil_inet_pton(af, tmp_src, dst);
+	free(tmp_src);
+	return r;
+}
+
+int
 evutil_inet_pton(int af, const char *src, void *dst)
 {
 #if defined(EVENT__HAVE_INET_PTON) && !defined(USE_INTERNAL_PTON)
@@ -2097,6 +2139,7 @@
 evutil_parse_sockaddr_port(const char *ip_as_string, struct sockaddr *out, int *outlen)
 {
 	int port;
+	unsigned int if_index;
 	char buf[128];
 	const char *cp, *addr_part, *port_part;
 	int is_ipv6;
@@ -2166,10 +2209,13 @@
 #endif
 		sin6.sin6_family = AF_INET6;
 		sin6.sin6_port = htons(port);
-		if (1 != evutil_inet_pton(AF_INET6, addr_part, &sin6.sin6_addr))
+		if (1 != evutil_inet_pton_scope(
+			AF_INET6, addr_part, &sin6.sin6_addr, &if_index)) {
 			return -1;
+		}
 		if ((int)sizeof(sin6) > *outlen)
 			return -1;
+		sin6.sin6_scope_id = if_index;
 		memset(out, 0, *outlen);
 		memcpy(out, &sin6, sizeof(sin6));
 		*outlen = sizeof(sin6);
@@ -2323,7 +2369,7 @@
 #define IMPL_CTYPE_FN(name)						\
 	int EVUTIL_##name##_(char c) {					\
 		ev_uint8_t u = c;					\
-		return !!(EVUTIL_##name##_TABLE[(u >> 5) & 7] & (1 << (u & 31))); \
+		return !!(EVUTIL_##name##_TABLE[(u >> 5) & 7] & (1U << (u & 31))); \
 	}
 IMPL_CTYPE_FN(ISALPHA)
 IMPL_CTYPE_FN(ISALNUM)
diff --git a/evutil_time.c b/evutil_time.c
index c3a2358..c327218 100644
--- a/evutil_time.c
+++ b/evutil_time.c
@@ -65,6 +65,9 @@
 
 #ifndef EVENT__HAVE_GETTIMEOFDAY
 /* No gettimeofday; this must be windows. */
+
+typedef void (WINAPI *GetSystemTimePreciseAsFileTime_fn_t) (LPFILETIME);
+
 int
 evutil_gettimeofday(struct timeval *tv, struct timezone *tz)
 {
@@ -90,7 +93,22 @@
 	if (tv == NULL)
 		return -1;
 
-	GetSystemTimeAsFileTime(&ft.ft_ft);
+	static GetSystemTimePreciseAsFileTime_fn_t GetSystemTimePreciseAsFileTime_fn = NULL;
+	static int check_precise = 1;
+
+	if (EVUTIL_UNLIKELY(check_precise)) {
+		HMODULE h = evutil_load_windows_system_library_(TEXT("kernel32.dll"));
+		if (h != NULL)
+			GetSystemTimePreciseAsFileTime_fn =
+				(GetSystemTimePreciseAsFileTime_fn_t)
+					GetProcAddress(h, "GetSystemTimePreciseAsFileTime");
+		check_precise = 0;
+	}
+
+	if (GetSystemTimePreciseAsFileTime_fn != NULL)
+		GetSystemTimePreciseAsFileTime_fn(&ft.ft_ft);
+	else
+		GetSystemTimeAsFileTime(&ft.ft_ft);
 
 	if (EVUTIL_UNLIKELY(ft.ft_64 < EPOCH_BIAS)) {
 		/* Time before the unix epoch. */
@@ -126,8 +144,22 @@
 		return;
 #if defined(_WIN32)
 	{
-		long msec = evutil_tv_to_msec_(tv);
-		Sleep((DWORD)msec);
+		__int64 usec;
+		LARGE_INTEGER li;
+		HANDLE timer;
+
+		usec = tv->tv_sec * 1000000LL + tv->tv_usec;
+		if (!usec)
+			return;
+
+		li.QuadPart = -10LL * usec;
+		timer = CreateWaitableTimer(NULL, TRUE, NULL);
+		if (!timer)
+			return;
+
+		SetWaitableTimer(timer, &li, 0, NULL, NULL, 0);
+		WaitForSingleObject(timer, INFINITE);
+		CloseHandle(timer);
 	}
 #elif defined(EVENT__HAVE_NANOSLEEP)
 	{
@@ -158,18 +190,28 @@
 
 	time_t t = time(NULL);
 
-#ifndef _WIN32
+#if defined(EVENT__HAVE__GMTIME64_S) || !defined(_WIN32)
 	struct tm sys;
 #endif
 
 	/* If `tm` is null, set system's current time. */
 	if (tm == NULL) {
-#ifdef _WIN32
-		/** TODO: detect _gmtime64()/_gmtime64_s() */
-		tm = gmtime(&t);
-#else
+#if !defined(_WIN32)
 		gmtime_r(&t, &sys);
 		tm = &sys;
+		/** detect _gmtime64()/_gmtime64_s() */
+#elif defined(EVENT__HAVE__GMTIME64_S)
+		errno_t err;
+		err = _gmtime64_s(&sys, &t);
+		if (err) {
+			event_errx(1, "Invalid argument to _gmtime64_s");
+		} else {
+			tm = &sys;
+		}
+#elif defined(EVENT__HAVE__GMTIME64)
+		tm = _gmtime64(&t);
+#else
+		tm = gmtime(&t);
 #endif
 	}
 
diff --git a/http.c b/http.c
index 5331602..04f089b 100644
--- a/http.c
+++ b/http.c
@@ -177,7 +177,7 @@
 
 extern int debug;
 
-static evutil_socket_t bind_socket_ai(struct evutil_addrinfo *, int reuse);
+static evutil_socket_t create_bind_socket_nonblock(struct evutil_addrinfo *, int reuse);
 static evutil_socket_t bind_socket(const char *, ev_uint16_t, int reuse);
 static void name_from_addr(struct sockaddr *, ev_socklen_t, char **, char **);
 static struct evhttp_uri *evhttp_uri_parse_authority(char *source_uri);
@@ -358,6 +358,7 @@
 	return (req->response_code != HTTP_NOCONTENT &&
 		req->response_code != HTTP_NOTMODIFIED &&
 		(req->response_code < 100 || req->response_code >= 200) &&
+		req->type != EVHTTP_REQ_CONNECT &&
 		req->type != EVHTTP_REQ_HEAD);
 }
 
@@ -478,6 +479,9 @@
 static int
 evhttp_is_request_connection_close(struct evhttp_request *req)
 {
+	if (req->type == EVHTTP_REQ_CONNECT)
+		return 0;
+
 	return
 		evhttp_is_connection_close(req->flags, req->input_headers) ||
 		evhttp_is_connection_close(req->flags, req->output_headers);
@@ -778,6 +782,11 @@
 	/* We are trying the next request that was queued on us */
 	if (TAILQ_FIRST(&evcon->requests) != NULL)
 		evhttp_connection_connect_(evcon);
+	else
+		if ((evcon->flags & EVHTTP_CON_OUTGOING) &&
+		    (evcon->flags & EVHTTP_CON_AUTOFREE)) {
+			evhttp_connection_free(evcon);
+		}
 
 	/* The call to evhttp_connection_reset_ overwrote errno.
 	 * Let's restore the original errno, so that the user's
@@ -3277,6 +3286,7 @@
 	p = argument = line;
 	while (p != NULL && *p != '\0') {
 		char *key, *value, *decoded_value;
+		int err;
 		argument = strsep(&p, "&");
 
 		value = argument;
@@ -3292,8 +3302,10 @@
 		evhttp_decode_uri_internal(value, strlen(value),
 		    decoded_value, 1 /*always_decode_plus*/);
 		event_debug(("Query Param: %s -> %s\n", key, decoded_value));
-		evhttp_add_header_internal(headers, key, decoded_value);
+		err = evhttp_add_header_internal(headers, key, decoded_value);
 		mm_free(decoded_value);
+		if (err)
+			goto error;
 	}
 
 	result = 0;
@@ -4376,9 +4388,8 @@
 }
 
 /* Create a non-blocking socket and bind it */
-/* todo: rename this function */
 static evutil_socket_t
-bind_socket_ai(struct evutil_addrinfo *ai, int reuse)
+create_bind_socket_nonblock(struct evutil_addrinfo *ai, int reuse)
 {
 	evutil_socket_t fd;
 
@@ -4452,14 +4463,14 @@
 
 	/* just create an unbound socket */
 	if (address == NULL && port == 0)
-		return bind_socket_ai(NULL, 0);
+		return create_bind_socket_nonblock(NULL, 0);
 
 	aitop = make_addrinfo(address, port);
 
 	if (aitop == NULL)
 		return (-1);
 
-	fd = bind_socket_ai(aitop, reuse);
+	fd = create_bind_socket_nonblock(aitop, reuse);
 
 	evutil_freeaddrinfo(aitop);
 
diff --git a/include/event2/buffer.h b/include/event2/buffer.h
index 468588b..88af3ae 100644
--- a/include/event2/buffer.h
+++ b/include/event2/buffer.h
@@ -726,7 +726,8 @@
 
   @param buffer the evbuffer to store the result
   @param fd the file descriptor to read from
-  @param howmuch the number of bytes to be read
+  @param howmuch the number of bytes to be read. If the given number is negative
+  or out of maximum bytes per one read, as many bytes as we can will be read.
   @return the number of bytes read, or -1 if an error occurred
   @see evbuffer_write()
  */
diff --git a/include/event2/util.h b/include/event2/util.h
index e6df628..02aa7ba 100644
--- a/include/event2/util.h
+++ b/include/event2/util.h
@@ -612,6 +612,12 @@
 /** Replacement for inet_ntop for platforms which lack it. */
 EVENT2_EXPORT_SYMBOL
 const char *evutil_inet_ntop(int af, const void *src, char *dst, size_t len);
+/** Variation of inet_pton that also parses IPv6 scopes. Public for
+    unit tests. No reason to call this directly.
+ */
+EVENT2_EXPORT_SYMBOL
+int evutil_inet_pton_scope(int af, const char *src, void *dst,
+	unsigned *indexp);
 /** Replacement for inet_pton for platforms which lack it. */
 EVENT2_EXPORT_SYMBOL
 int evutil_inet_pton(int af, const char *src, void *dst);
diff --git a/kqueue.c b/kqueue.c
index d08f512..dfd7751 100644
--- a/kqueue.c
+++ b/kqueue.c
@@ -51,7 +51,10 @@
 /* Some platforms apparently define the udata field of struct kevent as
  * intptr_t, whereas others define it as void*.  There doesn't seem to be an
  * easy way to tell them apart via autoconf, so we need to use OS macros. */
-#if defined(EVENT__HAVE_INTTYPES_H) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__darwin__) && !defined(__APPLE__) && !defined(__CloudABI__)
+#if defined(__NetBSD__)
+#define PTR_TO_UDATA(x) ((typeof(((struct kevent *)0)->udata))(x))
+#define INT_TO_UDATA(x) ((typeof(((struct kevent *)0)->udata))(intptr_t)(x))
+#elif defined(EVENT__HAVE_INTTYPES_H) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__darwin__) && !defined(__APPLE__) && !defined(__CloudABI__)
 #define PTR_TO_UDATA(x)	((intptr_t)(x))
 #define INT_TO_UDATA(x) ((intptr_t)(x))
 #else
diff --git a/m4/ax_check_funcs_ex.m4 b/m4/ax_check_funcs_ex.m4
new file mode 100644
index 0000000..7aaa58b
--- /dev/null
+++ b/m4/ax_check_funcs_ex.m4
@@ -0,0 +1,22 @@
+# Check if the function is available.
+# HAVE_XXX will be defined if yes.
+
+# $1: the name of function
+# $2: the headers in where the function declared
+AC_DEFUN([AX_CHECK_DECL_EX], [dnl
+	AS_IF([test "x$2" = "x"], [AC_MSG_ERROR([header not privided])])
+	AS_VAR_PUSHDEF([have_func_var], [HAVE_[]m4_toupper($1)])
+	AC_CHECK_DECL([$1],dnl
+		[AC_DEFINE([have_func_var], [1], [Define to 1 if you have the `$1' function.])],,dnl
+		[$2]dnl
+	)
+	AS_VAR_POPDEF([have_func_var])dnl
+])
+
+AC_DEFUN([AX_CHECK_DECLS_EX], [dnl
+	AS_IF([test "x$2" = "x"], [AC_MSG_ERROR([header not privided])])
+	m4_foreach([decl],dnl
+		m4_split(m4_normalize($1)),dnl
+		[AX_CHECK_DECL_EX([decl], [$2])]dnl
+	)
+])
diff --git a/m4/ax_prog_doxygen.m4 b/m4/ax_prog_doxygen.m4
new file mode 100644
index 0000000..e5bdeb5
--- /dev/null
+++ b/m4/ax_prog_doxygen.m4
@@ -0,0 +1,600 @@
+# ===========================================================================
+#     https://www.gnu.org/software/autoconf-archive/ax_prog_doxygen.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   DX_INIT_DOXYGEN(PROJECT-NAME, [DOXYFILE-PATH], [OUTPUT-DIR], ...)
+#   DX_DOXYGEN_FEATURE(ON|OFF)
+#   DX_DOT_FEATURE(ON|OFF)
+#   DX_HTML_FEATURE(ON|OFF)
+#   DX_CHM_FEATURE(ON|OFF)
+#   DX_CHI_FEATURE(ON|OFF)
+#   DX_MAN_FEATURE(ON|OFF)
+#   DX_RTF_FEATURE(ON|OFF)
+#   DX_XML_FEATURE(ON|OFF)
+#   DX_PDF_FEATURE(ON|OFF)
+#   DX_PS_FEATURE(ON|OFF)
+#
+# DESCRIPTION
+#
+#   The DX_*_FEATURE macros control the default setting for the given
+#   Doxygen feature. Supported features are 'DOXYGEN' itself, 'DOT' for
+#   generating graphics, 'HTML' for plain HTML, 'CHM' for compressed HTML
+#   help (for MS users), 'CHI' for generating a separate .chi file by the
+#   .chm file, and 'MAN', 'RTF', 'XML', 'PDF' and 'PS' for the appropriate
+#   output formats. The environment variable DOXYGEN_PAPER_SIZE may be
+#   specified to override the default 'a4wide' paper size.
+#
+#   By default, HTML, PDF and PS documentation is generated as this seems to
+#   be the most popular and portable combination. MAN pages created by
+#   Doxygen are usually problematic, though by picking an appropriate subset
+#   and doing some massaging they might be better than nothing. CHM and RTF
+#   are specific for MS (note that you can't generate both HTML and CHM at
+#   the same time). The XML is rather useless unless you apply specialized
+#   post-processing to it.
+#
+#   The macros mainly control the default state of the feature. The use can
+#   override the default by specifying --enable or --disable. The macros
+#   ensure that contradictory flags are not given (e.g.,
+#   --enable-doxygen-html and --enable-doxygen-chm,
+#   --enable-doxygen-anything with --disable-doxygen, etc.) Finally, each
+#   feature will be automatically disabled (with a warning) if the required
+#   programs are missing.
+#
+#   Once all the feature defaults have been specified, call DX_INIT_DOXYGEN
+#   with the following parameters: a one-word name for the project for use
+#   as a filename base etc., an optional configuration file name (the
+#   default is '$(srcdir)/Doxyfile', the same as Doxygen's default), and an
+#   optional output directory name (the default is 'doxygen-doc'). To run
+#   doxygen multiple times for different configuration files and output
+#   directories provide more parameters: the second, forth, sixth, etc
+#   parameter are configuration file names and the third, fifth, seventh,
+#   etc parameter are output directories. No checking is done to catch
+#   duplicates.
+#
+#   Automake Support
+#
+#   The DX_RULES substitution can be used to add all needed rules to the
+#   Makefile. Note that this is a substitution without being a variable:
+#   only the @DX_RULES@ syntax will work.
+#
+#   The provided targets are:
+#
+#     doxygen-doc: Generate all doxygen documentation.
+#
+#     doxygen-run: Run doxygen, which will generate some of the
+#                  documentation (HTML, CHM, CHI, MAN, RTF, XML)
+#                  but will not do the post processing required
+#                  for the rest of it (PS, PDF).
+#
+#     doxygen-ps:  Generate doxygen PostScript documentation.
+#
+#     doxygen-pdf: Generate doxygen PDF documentation.
+#
+#   Note that by default these are not integrated into the automake targets.
+#   If doxygen is used to generate man pages, you can achieve this
+#   integration by setting man3_MANS to the list of man pages generated and
+#   then adding the dependency:
+#
+#     $(man3_MANS): doxygen-doc
+#
+#   This will cause make to run doxygen and generate all the documentation.
+#
+#   The following variable is intended for use in Makefile.am:
+#
+#     DX_CLEANFILES = everything to clean.
+#
+#   Then add this variable to MOSTLYCLEANFILES.
+#
+# LICENSE
+#
+#   Copyright (c) 2009 Oren Ben-Kiki <oren@ben-kiki.org>
+#   Copyright (c) 2015 Olaf Mandel <olaf@mandel.name>
+#
+#   Copying and distribution of this file, with or without modification, are
+#   permitted in any medium without royalty provided the copyright notice
+#   and this notice are preserved. This file is offered as-is, without any
+#   warranty.
+
+#serial 24
+
+## ----------##
+## Defaults. ##
+## ----------##
+
+DX_ENV=""
+AC_DEFUN([DX_FEATURE_doc],  OFF)
+AC_DEFUN([DX_FEATURE_dot],  OFF)
+AC_DEFUN([DX_FEATURE_man],  OFF)
+AC_DEFUN([DX_FEATURE_html], ON)
+AC_DEFUN([DX_FEATURE_chm],  OFF)
+AC_DEFUN([DX_FEATURE_chi],  OFF)
+AC_DEFUN([DX_FEATURE_rtf],  OFF)
+AC_DEFUN([DX_FEATURE_xml],  OFF)
+AC_DEFUN([DX_FEATURE_pdf],  ON)
+AC_DEFUN([DX_FEATURE_ps],   ON)
+
+## --------------- ##
+## Private macros. ##
+## --------------- ##
+
+# DX_ENV_APPEND(VARIABLE, VALUE)
+# ------------------------------
+# Append VARIABLE="VALUE" to DX_ENV for invoking doxygen and add it
+# as a substitution (but not a Makefile variable). The substitution
+# is skipped if the variable name is VERSION.
+AC_DEFUN([DX_ENV_APPEND],
+[AC_SUBST([DX_ENV], ["$DX_ENV $1='$2'"])dnl
+m4_if([$1], [VERSION], [], [AC_SUBST([$1], [$2])dnl
+AM_SUBST_NOTMAKE([$1])])dnl
+])
+
+# DX_DIRNAME_EXPR
+# ---------------
+# Expand into a shell expression prints the directory part of a path.
+AC_DEFUN([DX_DIRNAME_EXPR],
+         [[expr ".$1" : '\(\.\)[^/]*$' \| "x$1" : 'x\(.*\)/[^/]*$']])
+
+# DX_IF_FEATURE(FEATURE, IF-ON, IF-OFF)
+# -------------------------------------
+# Expands according to the M4 (static) status of the feature.
+AC_DEFUN([DX_IF_FEATURE], [ifelse(DX_FEATURE_$1, ON, [$2], [$3])])
+
+# DX_REQUIRE_PROG(VARIABLE, PROGRAM)
+# ----------------------------------
+# Require the specified program to be found for the DX_CURRENT_FEATURE to work.
+AC_DEFUN([DX_REQUIRE_PROG], [
+AC_PATH_TOOL([$1], [$2])
+if test "$DX_FLAG_[]DX_CURRENT_FEATURE$$1" = 1; then
+    if test "x$2" = "xdoxygen"; then
+        AC_MSG_ERROR([$2 not found - will not DX_CURRENT_DESCRIPTION])
+    else
+        AC_MSG_WARN([$2 not found - will not DX_CURRENT_DESCRIPTION])
+    fi
+    AC_SUBST(DX_FLAG_[]DX_CURRENT_FEATURE, 0)
+fi
+])
+
+# DX_TEST_FEATURE(FEATURE)
+# ------------------------
+# Expand to a shell expression testing whether the feature is active.
+AC_DEFUN([DX_TEST_FEATURE], [test "$DX_FLAG_$1" = 1])
+
+# DX_CHECK_DEPEND(REQUIRED_FEATURE, REQUIRED_STATE)
+# -------------------------------------------------
+# Verify that a required features has the right state before trying to turn on
+# the DX_CURRENT_FEATURE.
+AC_DEFUN([DX_CHECK_DEPEND], [
+test "$DX_FLAG_$1" = "$2" \
+|| AC_MSG_ERROR([doxygen-DX_CURRENT_FEATURE ifelse([$2], 1,
+                            requires, contradicts) doxygen-$1])
+])
+
+# DX_CLEAR_DEPEND(FEATURE, REQUIRED_FEATURE, REQUIRED_STATE)
+# ----------------------------------------------------------
+# Turn off the DX_CURRENT_FEATURE if the required feature is off.
+AC_DEFUN([DX_CLEAR_DEPEND], [
+test "$DX_FLAG_$1" = "$2" || AC_SUBST(DX_FLAG_[]DX_CURRENT_FEATURE, 0)
+])
+
+# DX_FEATURE_ARG(FEATURE, DESCRIPTION,
+#                CHECK_DEPEND, CLEAR_DEPEND,
+#                REQUIRE, DO-IF-ON, DO-IF-OFF)
+# --------------------------------------------
+# Parse the command-line option controlling a feature. CHECK_DEPEND is called
+# if the user explicitly turns the feature on (and invokes DX_CHECK_DEPEND),
+# otherwise CLEAR_DEPEND is called to turn off the default state if a required
+# feature is disabled (using DX_CLEAR_DEPEND). REQUIRE performs additional
+# requirement tests (DX_REQUIRE_PROG). Finally, an automake flag is set and
+# DO-IF-ON or DO-IF-OFF are called according to the final state of the feature.
+AC_DEFUN([DX_ARG_ABLE], [
+    AC_DEFUN([DX_CURRENT_FEATURE], [$1])
+    AC_DEFUN([DX_CURRENT_DESCRIPTION], [$2])
+    AC_ARG_ENABLE(doxygen-$1,
+                  [AS_HELP_STRING(DX_IF_FEATURE([$1], [--disable-doxygen-$1],
+                                                      [--enable-doxygen-$1]),
+                                  DX_IF_FEATURE([$1], [don't $2], [$2]))],
+                  [
+case "$enableval" in
+#(
+y|Y|yes|Yes|YES)
+    AC_SUBST([DX_FLAG_$1], 1)
+    $3
+;; #(
+n|N|no|No|NO)
+    AC_SUBST([DX_FLAG_$1], 0)
+;; #(
+*)
+    AC_MSG_ERROR([invalid value '$enableval' given to doxygen-$1])
+;;
+esac
+], [
+AC_SUBST([DX_FLAG_$1], [DX_IF_FEATURE([$1], 1, 0)])
+$4
+])
+if DX_TEST_FEATURE([$1]); then
+    $5
+    :
+fi
+if DX_TEST_FEATURE([$1]); then
+    $6
+    :
+else
+    $7
+    :
+fi
+])
+
+## -------------- ##
+## Public macros. ##
+## -------------- ##
+
+# DX_XXX_FEATURE(DEFAULT_STATE)
+# -----------------------------
+AC_DEFUN([DX_DOXYGEN_FEATURE], [AC_DEFUN([DX_FEATURE_doc],  [$1])])
+AC_DEFUN([DX_DOT_FEATURE],     [AC_DEFUN([DX_FEATURE_dot], [$1])])
+AC_DEFUN([DX_MAN_FEATURE],     [AC_DEFUN([DX_FEATURE_man],  [$1])])
+AC_DEFUN([DX_HTML_FEATURE],    [AC_DEFUN([DX_FEATURE_html], [$1])])
+AC_DEFUN([DX_CHM_FEATURE],     [AC_DEFUN([DX_FEATURE_chm],  [$1])])
+AC_DEFUN([DX_CHI_FEATURE],     [AC_DEFUN([DX_FEATURE_chi],  [$1])])
+AC_DEFUN([DX_RTF_FEATURE],     [AC_DEFUN([DX_FEATURE_rtf],  [$1])])
+AC_DEFUN([DX_XML_FEATURE],     [AC_DEFUN([DX_FEATURE_xml],  [$1])])
+AC_DEFUN([DX_XML_FEATURE],     [AC_DEFUN([DX_FEATURE_xml],  [$1])])
+AC_DEFUN([DX_PDF_FEATURE],     [AC_DEFUN([DX_FEATURE_pdf],  [$1])])
+AC_DEFUN([DX_PS_FEATURE],      [AC_DEFUN([DX_FEATURE_ps],   [$1])])
+
+# DX_INIT_DOXYGEN(PROJECT, [CONFIG-FILE], [OUTPUT-DOC-DIR], ...)
+# --------------------------------------------------------------
+# PROJECT also serves as the base name for the documentation files.
+# The default CONFIG-FILE is "$(srcdir)/Doxyfile" and OUTPUT-DOC-DIR is
+# "doxygen-doc".
+# More arguments are interpreted as interleaved CONFIG-FILE and
+# OUTPUT-DOC-DIR values.
+AC_DEFUN([DX_INIT_DOXYGEN], [
+
+# Files:
+AC_SUBST([DX_PROJECT], [$1])
+AC_SUBST([DX_CONFIG], ['ifelse([$2], [], [$(srcdir)/Doxyfile], [$2])'])
+AC_SUBST([DX_DOCDIR], ['ifelse([$3], [], [doxygen-doc], [$3])'])
+m4_if(m4_eval(3 < m4_count($@)), 1, [m4_for([DX_i], 4, m4_count($@), 2,
+      [AC_SUBST([DX_CONFIG]m4_eval(DX_i[/2]),
+                'm4_default_nblank_quoted(m4_argn(DX_i, $@),
+                                          [$(srcdir)/Doxyfile])')])])dnl
+m4_if(m4_eval(3 < m4_count($@)), 1, [m4_for([DX_i], 5, m4_count($@,), 2,
+      [AC_SUBST([DX_DOCDIR]m4_eval([(]DX_i[-1)/2]),
+                'm4_default_nblank_quoted(m4_argn(DX_i, $@),
+                                          [doxygen-doc])')])])dnl
+m4_define([DX_loop], m4_dquote(m4_if(m4_eval(3 < m4_count($@)), 1,
+          [m4_for([DX_i], 4, m4_count($@), 2, [, m4_eval(DX_i[/2])])],
+          [])))dnl
+
+# Environment variables used inside doxygen.cfg:
+DX_ENV_APPEND(SRCDIR, $srcdir)
+DX_ENV_APPEND(PROJECT, $DX_PROJECT)
+DX_ENV_APPEND(VERSION, $PACKAGE_VERSION)
+
+# Doxygen itself:
+DX_ARG_ABLE(doc, [generate any doxygen documentation],
+            [],
+            [],
+            [DX_REQUIRE_PROG([DX_DOXYGEN], doxygen)
+             DX_REQUIRE_PROG([DX_PERL], perl)],
+            [DX_ENV_APPEND(PERL_PATH, $DX_PERL)])
+
+# Dot for graphics:
+DX_ARG_ABLE(dot, [generate graphics for doxygen documentation],
+            [DX_CHECK_DEPEND(doc, 1)],
+            [DX_CLEAR_DEPEND(doc, 1)],
+            [DX_REQUIRE_PROG([DX_DOT], dot)],
+            [DX_ENV_APPEND(HAVE_DOT, YES)
+             DX_ENV_APPEND(DOT_PATH, [`DX_DIRNAME_EXPR($DX_DOT)`])],
+            [DX_ENV_APPEND(HAVE_DOT, NO)])
+
+# Man pages generation:
+DX_ARG_ABLE(man, [generate doxygen manual pages],
+            [DX_CHECK_DEPEND(doc, 1)],
+            [DX_CLEAR_DEPEND(doc, 1)],
+            [],
+            [DX_ENV_APPEND(GENERATE_MAN, YES)],
+            [DX_ENV_APPEND(GENERATE_MAN, NO)])
+
+# RTF file generation:
+DX_ARG_ABLE(rtf, [generate doxygen RTF documentation],
+            [DX_CHECK_DEPEND(doc, 1)],
+            [DX_CLEAR_DEPEND(doc, 1)],
+            [],
+            [DX_ENV_APPEND(GENERATE_RTF, YES)],
+            [DX_ENV_APPEND(GENERATE_RTF, NO)])
+
+# XML file generation:
+DX_ARG_ABLE(xml, [generate doxygen XML documentation],
+            [DX_CHECK_DEPEND(doc, 1)],
+            [DX_CLEAR_DEPEND(doc, 1)],
+            [],
+            [DX_ENV_APPEND(GENERATE_XML, YES)],
+            [DX_ENV_APPEND(GENERATE_XML, NO)])
+
+# (Compressed) HTML help generation:
+DX_ARG_ABLE(chm, [generate doxygen compressed HTML help documentation],
+            [DX_CHECK_DEPEND(doc, 1)],
+            [DX_CLEAR_DEPEND(doc, 1)],
+            [DX_REQUIRE_PROG([DX_HHC], hhc)],
+            [DX_ENV_APPEND(HHC_PATH, $DX_HHC)
+             DX_ENV_APPEND(GENERATE_HTML, YES)
+             DX_ENV_APPEND(GENERATE_HTMLHELP, YES)],
+            [DX_ENV_APPEND(GENERATE_HTMLHELP, NO)])
+
+# Separate CHI file generation.
+DX_ARG_ABLE(chi, [generate doxygen separate compressed HTML help index file],
+            [DX_CHECK_DEPEND(chm, 1)],
+            [DX_CLEAR_DEPEND(chm, 1)],
+            [],
+            [DX_ENV_APPEND(GENERATE_CHI, YES)],
+            [DX_ENV_APPEND(GENERATE_CHI, NO)])
+
+# Plain HTML pages generation:
+DX_ARG_ABLE(html, [generate doxygen plain HTML documentation],
+            [DX_CHECK_DEPEND(doc, 1) DX_CHECK_DEPEND(chm, 0)],
+            [DX_CLEAR_DEPEND(doc, 1) DX_CLEAR_DEPEND(chm, 0)],
+            [],
+            [DX_ENV_APPEND(GENERATE_HTML, YES)],
+            [DX_TEST_FEATURE(chm) || DX_ENV_APPEND(GENERATE_HTML, NO)])
+
+# PostScript file generation:
+DX_ARG_ABLE(ps, [generate doxygen PostScript documentation],
+            [DX_CHECK_DEPEND(doc, 1)],
+            [DX_CLEAR_DEPEND(doc, 1)],
+            [DX_REQUIRE_PROG([DX_LATEX], latex)
+             DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex)
+             DX_REQUIRE_PROG([DX_DVIPS], dvips)
+             DX_REQUIRE_PROG([DX_EGREP], egrep)])
+
+# PDF file generation:
+DX_ARG_ABLE(pdf, [generate doxygen PDF documentation],
+            [DX_CHECK_DEPEND(doc, 1)],
+            [DX_CLEAR_DEPEND(doc, 1)],
+            [DX_REQUIRE_PROG([DX_PDFLATEX], pdflatex)
+             DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex)
+             DX_REQUIRE_PROG([DX_EGREP], egrep)])
+
+# LaTeX generation for PS and/or PDF:
+if DX_TEST_FEATURE(ps) || DX_TEST_FEATURE(pdf); then
+    DX_ENV_APPEND(GENERATE_LATEX, YES)
+else
+    DX_ENV_APPEND(GENERATE_LATEX, NO)
+fi
+
+# Paper size for PS and/or PDF:
+AC_ARG_VAR(DOXYGEN_PAPER_SIZE,
+           [a4wide (default), a4, letter, legal or executive])
+case "$DOXYGEN_PAPER_SIZE" in
+#(
+"")
+    AC_SUBST(DOXYGEN_PAPER_SIZE, "")
+;; #(
+a4wide|a4|letter|legal|executive)
+    DX_ENV_APPEND(PAPER_SIZE, $DOXYGEN_PAPER_SIZE)
+;; #(
+*)
+    AC_MSG_ERROR([unknown DOXYGEN_PAPER_SIZE='$DOXYGEN_PAPER_SIZE'])
+;;
+esac
+
+# Rules:
+AS_IF([[test $DX_FLAG_html -eq 1]],
+[[DX_SNIPPET_html="## ------------------------------- ##
+## Rules specific for HTML output. ##
+## ------------------------------- ##
+
+DX_CLEAN_HTML = \$(DX_DOCDIR)/html]dnl
+m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
+                \$(DX_DOCDIR]DX_i[)/html]])[
+
+"]],
+[[DX_SNIPPET_html=""]])
+AS_IF([[test $DX_FLAG_chi -eq 1]],
+[[DX_SNIPPET_chi="
+DX_CLEAN_CHI = \$(DX_DOCDIR)/\$(PACKAGE).chi]dnl
+m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
+               \$(DX_DOCDIR]DX_i[)/\$(PACKAGE).chi]])["]],
+[[DX_SNIPPET_chi=""]])
+AS_IF([[test $DX_FLAG_chm -eq 1]],
+[[DX_SNIPPET_chm="## ------------------------------ ##
+## Rules specific for CHM output. ##
+## ------------------------------ ##
+
+DX_CLEAN_CHM = \$(DX_DOCDIR)/chm]dnl
+m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
+               \$(DX_DOCDIR]DX_i[)/chm]])[\
+${DX_SNIPPET_chi}
+
+"]],
+[[DX_SNIPPET_chm=""]])
+AS_IF([[test $DX_FLAG_man -eq 1]],
+[[DX_SNIPPET_man="## ------------------------------ ##
+## Rules specific for MAN output. ##
+## ------------------------------ ##
+
+DX_CLEAN_MAN = \$(DX_DOCDIR)/man]dnl
+m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
+               \$(DX_DOCDIR]DX_i[)/man]])[
+
+"]],
+[[DX_SNIPPET_man=""]])
+AS_IF([[test $DX_FLAG_rtf -eq 1]],
+[[DX_SNIPPET_rtf="## ------------------------------ ##
+## Rules specific for RTF output. ##
+## ------------------------------ ##
+
+DX_CLEAN_RTF = \$(DX_DOCDIR)/rtf]dnl
+m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
+               \$(DX_DOCDIR]DX_i[)/rtf]])[
+
+"]],
+[[DX_SNIPPET_rtf=""]])
+AS_IF([[test $DX_FLAG_xml -eq 1]],
+[[DX_SNIPPET_xml="## ------------------------------ ##
+## Rules specific for XML output. ##
+## ------------------------------ ##
+
+DX_CLEAN_XML = \$(DX_DOCDIR)/xml]dnl
+m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
+               \$(DX_DOCDIR]DX_i[)/xml]])[
+
+"]],
+[[DX_SNIPPET_xml=""]])
+AS_IF([[test $DX_FLAG_ps -eq 1]],
+[[DX_SNIPPET_ps="## ----------------------------- ##
+## Rules specific for PS output. ##
+## ----------------------------- ##
+
+DX_CLEAN_PS = \$(DX_DOCDIR)/\$(PACKAGE).ps]dnl
+m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
+              \$(DX_DOCDIR]DX_i[)/\$(PACKAGE).ps]])[
+
+DX_PS_GOAL = doxygen-ps
+
+doxygen-ps: \$(DX_CLEAN_PS)
+
+]m4_foreach([DX_i], [DX_loop],
+[[\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).ps: \$(DX_DOCDIR]DX_i[)/\$(PACKAGE).tag
+	\$(DX_V_LATEX)cd \$(DX_DOCDIR]DX_i[)/latex; \\
+	rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \\
+	\$(DX_LATEX) refman.tex; \\
+	\$(DX_MAKEINDEX) refman.idx; \\
+	\$(DX_LATEX) refman.tex; \\
+	countdown=5; \\
+	while \$(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \\
+	                  refman.log > /dev/null 2>&1 \\
+	   && test \$\$countdown -gt 0; do \\
+	    \$(DX_LATEX) refman.tex; \\
+            countdown=\`expr \$\$countdown - 1\`; \\
+	done; \\
+	\$(DX_DVIPS) -o ../\$(PACKAGE).ps refman.dvi
+
+]])["]],
+[[DX_SNIPPET_ps=""]])
+AS_IF([[test $DX_FLAG_pdf -eq 1]],
+[[DX_SNIPPET_pdf="## ------------------------------ ##
+## Rules specific for PDF output. ##
+## ------------------------------ ##
+
+DX_CLEAN_PDF = \$(DX_DOCDIR)/\$(PACKAGE).pdf]dnl
+m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
+               \$(DX_DOCDIR]DX_i[)/\$(PACKAGE).pdf]])[
+
+DX_PDF_GOAL = doxygen-pdf
+
+doxygen-pdf: \$(DX_CLEAN_PDF)
+
+]m4_foreach([DX_i], [DX_loop],
+[[\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).pdf: \$(DX_DOCDIR]DX_i[)/\$(PACKAGE).tag
+	\$(DX_V_LATEX)cd \$(DX_DOCDIR]DX_i[)/latex; \\
+	rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \\
+	\$(DX_PDFLATEX) refman.tex; \\
+	\$(DX_MAKEINDEX) refman.idx; \\
+	\$(DX_PDFLATEX) refman.tex; \\
+	countdown=5; \\
+	while \$(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \\
+	                  refman.log > /dev/null 2>&1 \\
+	   && test \$\$countdown -gt 0; do \\
+	    \$(DX_PDFLATEX) refman.tex; \\
+	    countdown=\`expr \$\$countdown - 1\`; \\
+	done; \\
+	mv refman.pdf ../\$(PACKAGE).pdf
+
+]])["]],
+[[DX_SNIPPET_pdf=""]])
+AS_IF([[test $DX_FLAG_ps -eq 1 -o $DX_FLAG_pdf -eq 1]],
+[[DX_SNIPPET_latex="## ------------------------------------------------- ##
+## Rules specific for LaTeX (shared for PS and PDF). ##
+## ------------------------------------------------- ##
+
+DX_V_LATEX = \$(_DX_v_LATEX_\$(V))
+_DX_v_LATEX_ = \$(_DX_v_LATEX_\$(AM_DEFAULT_VERBOSITY))
+_DX_v_LATEX_0 = @echo \"  LATEX \" \$][@;
+
+DX_CLEAN_LATEX = \$(DX_DOCDIR)/latex]dnl
+m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
+                 \$(DX_DOCDIR]DX_i[)/latex]])[
+
+"]],
+[[DX_SNIPPET_latex=""]])
+
+AS_IF([[test $DX_FLAG_doc -eq 1]],
+[[DX_SNIPPET_doc="## --------------------------------- ##
+## Format-independent Doxygen rules. ##
+## --------------------------------- ##
+
+${DX_SNIPPET_html}\
+${DX_SNIPPET_chm}\
+${DX_SNIPPET_man}\
+${DX_SNIPPET_rtf}\
+${DX_SNIPPET_xml}\
+${DX_SNIPPET_ps}\
+${DX_SNIPPET_pdf}\
+${DX_SNIPPET_latex}\
+DX_V_DXGEN = \$(_DX_v_DXGEN_\$(V))
+_DX_v_DXGEN_ = \$(_DX_v_DXGEN_\$(AM_DEFAULT_VERBOSITY))
+_DX_v_DXGEN_0 = @echo \"  DXGEN \" \$<;
+
+.PHONY: doxygen-run doxygen-doc \$(DX_PS_GOAL) \$(DX_PDF_GOAL)
+
+.INTERMEDIATE: doxygen-run \$(DX_PS_GOAL) \$(DX_PDF_GOAL)
+
+doxygen-run:]m4_foreach([DX_i], [DX_loop],
+                         [[ \$(DX_DOCDIR]DX_i[)/\$(PACKAGE).tag]])[
+
+doxygen-doc: doxygen-run \$(DX_PS_GOAL) \$(DX_PDF_GOAL)
+
+]m4_foreach([DX_i], [DX_loop],
+[[\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).tag: \$(DX_CONFIG]DX_i[) \$(pkginclude_HEADERS)
+	\$(A""M_V_at)rm -rf \$(DX_DOCDIR]DX_i[)
+	\$(DX_V_DXGEN)\$(DX_ENV) DOCDIR=\$(DX_DOCDIR]DX_i[) \$(DX_DOXYGEN) \$(DX_CONFIG]DX_i[)
+	\$(A""M_V_at)echo Timestamp >\$][@
+
+]])dnl
+[DX_CLEANFILES = \\]
+m4_foreach([DX_i], [DX_loop],
+[[	\$(DX_DOCDIR]DX_i[)/doxygen_sqlite3.db \\
+	\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).tag \\
+]])dnl
+[	-r \\
+	\$(DX_CLEAN_HTML) \\
+	\$(DX_CLEAN_CHM) \\
+	\$(DX_CLEAN_CHI) \\
+	\$(DX_CLEAN_MAN) \\
+	\$(DX_CLEAN_RTF) \\
+	\$(DX_CLEAN_XML) \\
+	\$(DX_CLEAN_PS) \\
+	\$(DX_CLEAN_PDF) \\
+	\$(DX_CLEAN_LATEX)
+DX_INSTALL_DOCS = \\
+	\$(DX_CLEAN_HTML) \\
+	\$(DX_CLEAN_CHM) \\
+	\$(DX_CLEAN_CHI) \\
+	\$(DX_CLEAN_RTF) \\
+	\$(DX_CLEAN_XML) \\
+	\$(DX_CLEAN_PS) \\
+	\$(DX_CLEAN_PDF) \\
+	\$(DX_CLEAN_LATEX)
+    "]],
+[[DX_SNIPPET_doc=""]])
+AC_SUBST([DX_RULES],
+["${DX_SNIPPET_doc}"])dnl
+AM_SUBST_NOTMAKE([DX_RULES])
+
+#For debugging:
+#echo DX_FLAG_doc=$DX_FLAG_doc
+#echo DX_FLAG_dot=$DX_FLAG_dot
+#echo DX_FLAG_man=$DX_FLAG_man
+#echo DX_FLAG_html=$DX_FLAG_html
+#echo DX_FLAG_chm=$DX_FLAG_chm
+#echo DX_FLAG_chi=$DX_FLAG_chi
+#echo DX_FLAG_rtf=$DX_FLAG_rtf
+#echo DX_FLAG_xml=$DX_FLAG_xml
+#echo DX_FLAG_pdf=$DX_FLAG_pdf
+#echo DX_FLAG_ps=$DX_FLAG_ps
+#echo DX_ENV=$DX_ENV
+])
diff --git a/m4/libevent_openssl.m4 b/m4/libevent_openssl.m4
index 1981198..a5ea676 100644
--- a/m4/libevent_openssl.m4
+++ b/m4/libevent_openssl.m4
@@ -47,6 +47,11 @@
     AC_SUBST(OPENSSL_LIBS)
     case "$have_openssl" in
      yes)  AC_DEFINE(HAVE_OPENSSL, 1, [Define if the system has openssl]) ;;
+     *) AC_MSG_ERROR([openssl is a must but can not be found. You should add the \
+directory containing `openssl.pc' to the `PKG_CONFIG_PATH' environment variable, \
+or set `CFLAGS' and `LDFLAGS' directly for openssl, or use `--disable-openssl' \
+to disable support for openssl encryption])
+	;;
     esac
     ;;
 esac
diff --git a/m4/libtool.m4 b/m4/libtool.m4
index b55a6e5..2b73e38 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -728,7 +728,6 @@
     cat <<_LT_EOF >> "$cfgfile"
 #! $SHELL
 # Generated automatically by $as_me ($PACKAGE) $VERSION
-# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
 # NOTE: Changes made to this file will be lost: look at ltmain.sh.
 
 # Provide generalized library-building support services.
diff --git a/m4/ltversion.m4 b/m4/ltversion.m4
index 86b2ad7..7f9a3ad 100644
--- a/m4/ltversion.m4
+++ b/m4/ltversion.m4
@@ -12,11 +12,11 @@
 # serial 4221 ltversion.m4
 # This file is part of GNU Libtool
 
-m4_define([LT_PACKAGE_VERSION], [2.4.6.42-b88ce])
+m4_define([LT_PACKAGE_VERSION], [2.4.6.42-b88ce-dirty])
 m4_define([LT_PACKAGE_REVISION], [2.4.6.42])
 
 AC_DEFUN([LTVERSION_VERSION],
-[macro_version='2.4.6.42-b88ce'
+[macro_version='2.4.6.42-b88ce-dirty'
 macro_revision='2.4.6.42'
 _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?])
 _LT_DECL(, macro_revision, 0)
diff --git a/openssl-compat.h b/openssl-compat.h
index 5d91ac6..a23e342 100644
--- a/openssl-compat.h
+++ b/openssl-compat.h
@@ -34,6 +34,9 @@
 
 #define TLS_method SSLv23_method
 
+#define X509_getm_notBefore X509_get_notBefore
+#define X509_getm_notAfter X509_get_notAfter
+
 #endif /* (OPENSSL_VERSION_NUMBER < 0x10100000L) || \
 	(defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L) */
 
diff --git a/poll.c b/poll.c
index fe44071..c3c9aac 100644
--- a/poll.c
+++ b/poll.c
@@ -53,6 +53,17 @@
 #include "evthread-internal.h"
 #include "time-internal.h"
 
+/* Since Linux 2.6.17, poll is able to report about peer half-closed connection
+   using special POLLRDHUP flag on a read event.
+*/
+#if !defined(POLLRDHUP)
+#define POLLRDHUP 0
+#define EARLY_CLOSE_IF_HAVE_RDHUP 0
+#else
+#define EARLY_CLOSE_IF_HAVE_RDHUP EV_FEATURE_EARLY_CLOSE
+#endif
+
+
 struct pollidx {
 	int idxplus1;
 };
@@ -79,8 +90,8 @@
 	poll_del,
 	poll_dispatch,
 	poll_dealloc,
-	0, /* doesn't need_reinit */
-	EV_FEATURE_FDS,
+	1, /* need_reinit */
+	EV_FEATURE_FDS|EARLY_CLOSE_IF_HAVE_RDHUP,
 	sizeof(struct pollidx),
 };
 
@@ -204,6 +215,8 @@
 			res |= EV_READ;
 		if (what & POLLOUT)
 			res |= EV_WRITE;
+		if (what & POLLRDHUP)
+			res |= EV_CLOSED;
 		if (res == 0)
 			continue;
 
@@ -222,7 +235,7 @@
 	int i;
 
 	EVUTIL_ASSERT((events & EV_SIGNAL) == 0);
-	if (!(events & (EV_READ|EV_WRITE)))
+	if (!(events & (EV_READ|EV_WRITE|EV_CLOSED)))
 		return (0);
 
 	poll_check_ok(pop);
@@ -265,6 +278,8 @@
 		pfd->events |= POLLOUT;
 	if (events & EV_READ)
 		pfd->events |= POLLIN;
+	if (events & EV_CLOSED)
+		pfd->events |= POLLRDHUP;
 	poll_check_ok(pop);
 
 	return (0);
@@ -283,7 +298,7 @@
 	int i;
 
 	EVUTIL_ASSERT((events & EV_SIGNAL) == 0);
-	if (!(events & (EV_READ|EV_WRITE)))
+	if (!(events & (EV_READ|EV_WRITE|EV_CLOSED)))
 		return (0);
 
 	poll_check_ok(pop);
@@ -297,6 +312,8 @@
 		pfd->events &= ~POLLIN;
 	if (events & EV_WRITE)
 		pfd->events &= ~POLLOUT;
+	if (events & EV_CLOSED)
+		pfd->events &= ~POLLRDHUP;
 	poll_check_ok(pop);
 	if (pfd->events)
 		/* Another event cares about that fd. */
diff --git a/sample/dns-example.c b/sample/dns-example.c
index 21a75de..2d07c38 100644
--- a/sample/dns-example.c
+++ b/sample/dns-example.c
@@ -225,8 +225,8 @@
 			res = evdns_base_resolv_conf_parse(evdns_base,
 			    DNS_OPTION_NAMESERVERS, o.resolv_conf);
 
-		if (res < 0) {
-			fprintf(stderr, "Couldn't configure nameservers");
+		if (res) {
+			fprintf(stderr, "Couldn't configure nameservers\n");
 			return 1;
 		}
 	}
diff --git a/sample/event-read-fifo.c b/sample/event-read-fifo.c
index 27b0b53..a17b9bd 100644
--- a/sample/event-read-fifo.c
+++ b/sample/event-read-fifo.c
@@ -129,10 +129,10 @@
 
 	fprintf(stderr, "Write data to %s\n", fifo);
 #endif
-	/* Initalize the event library */
+	/* Initialize the event library */
 	base = event_base_new();
 
-	/* Initalize one event */
+	/* Initialize one event */
 #ifdef _WIN32
 	evfifo = event_new(base, (evutil_socket_t)socket, EV_READ|EV_PERSIST, fifo_read,
                            event_self_cbarg());
diff --git a/sample/hello-world.c b/sample/hello-world.c
index 2023cd6..a13e06a 100644
--- a/sample/hello-world.c
+++ b/sample/hello-world.c
@@ -42,7 +42,7 @@
 	struct evconnlistener *listener;
 	struct event *signal_event;
 
-	struct sockaddr_in sin;
+	struct sockaddr_in sin = {0};
 #ifdef _WIN32
 	WSADATA wsa_data;
 	WSAStartup(0x0201, &wsa_data);
@@ -54,7 +54,6 @@
 		return 1;
 	}
 
-	memset(&sin, 0, sizeof(sin));
 	sin.sin_family = AF_INET;
 	sin.sin_port = htons(PORT);
 
diff --git a/sample/http-connect.c b/sample/http-connect.c
index af2c86a..53f816d 100644
--- a/sample/http-connect.c
+++ b/sample/http-connect.c
@@ -23,15 +23,44 @@
 	struct evhttp_uri *location;
 };
 
+static struct evhttp_uri* uri_parse(const char *str)
+{
+	struct evhttp_uri *uri;
+	VERIFY(uri = evhttp_uri_parse(str));
+	VERIFY(evhttp_uri_get_host(uri));
+	VERIFY(evhttp_uri_get_port(uri) > 0);
+	return uri;
+}
+static char* uri_path(struct evhttp_uri *uri, char buffer[URL_MAX])
+{
+	struct evhttp_uri *path;
+
+	VERIFY(evhttp_uri_join(uri, buffer, URL_MAX));
+
+	path = evhttp_uri_parse(buffer);
+	evhttp_uri_set_scheme(path, NULL);
+	evhttp_uri_set_userinfo(path, 0);
+	evhttp_uri_set_host(path, NULL);
+	evhttp_uri_set_port(path, -1);
+	VERIFY(evhttp_uri_join(path, buffer, URL_MAX));
+	return buffer;
+}
+static char* uri_hostport(struct evhttp_uri *uri, char buffer[URL_MAX])
+{
+	VERIFY(evhttp_uri_join(uri, buffer, URL_MAX));
+	VERIFY(evhttp_uri_get_host(uri));
+	VERIFY(evhttp_uri_get_port(uri) > 0);
+	evutil_snprintf(buffer, URL_MAX, "%s:%d",
+		evhttp_uri_get_host(uri), evhttp_uri_get_port(uri));
+	return buffer;
+}
+
 static void get_cb(struct evhttp_request *req, void *arg)
 {
 	ev_ssize_t len;
 	struct evbuffer *evbuf;
-	struct evhttp_connection *evcon;
 
 	VERIFY(req);
-	evcon = evhttp_request_get_connection(req);
-	VERIFY(evcon);
 
 	evbuf = evhttp_request_get_input_buffer(req);
 	len = evbuffer_get_length(evbuf);
@@ -41,26 +70,26 @@
 
 static void connect_cb(struct evhttp_request *proxy_req, void *arg)
 {
-	char buffer[URL_MAX];
-
 	struct connect_base *base = arg;
 	struct evhttp_connection *evcon = base->evcon;
 	struct evhttp_uri *location = base->location;
+	struct evhttp_request *req;
+	char buffer[URL_MAX];
 
 	VERIFY(proxy_req);
-	if (evcon) {
-		struct evhttp_request *req = evhttp_request_new(get_cb, NULL);
-		evhttp_add_header(req->output_headers, "Connection", "close");
-		VERIFY(!evhttp_make_request(evcon, req, EVHTTP_REQ_GET,
-			evhttp_uri_join(location, buffer, URL_MAX)));
-	}
+	VERIFY(evcon);
+
+	req = evhttp_request_new(get_cb, NULL);
+	evhttp_add_header(req->output_headers, "Connection", "close");
+	evhttp_add_header(req->output_headers, "Host", evhttp_uri_get_host(location));
+	VERIFY(!evhttp_make_request(evcon, req, EVHTTP_REQ_GET,
+		uri_path(location, buffer)));
 }
 
 int main(int argc, const char **argv)
 {
-	char buffer[URL_MAX];
+	char hostport[URL_MAX];
 
-	struct evhttp_uri *host_port;
 	struct evhttp_uri *location;
 	struct evhttp_uri *proxy;
 
@@ -75,28 +104,8 @@
 		return 1;
 	}
 
-	{
-		VERIFY(proxy = evhttp_uri_parse(argv[1]));
-		VERIFY(evhttp_uri_get_host(proxy));
-		VERIFY(evhttp_uri_get_port(proxy) > 0);
-	}
-	{
-		host_port = evhttp_uri_parse(argv[2]);
-		evhttp_uri_set_scheme(host_port, NULL);
-		evhttp_uri_set_userinfo(host_port, NULL);
-		evhttp_uri_set_path(host_port, NULL);
-		evhttp_uri_set_query(host_port, NULL);
-		evhttp_uri_set_fragment(host_port, NULL);
-		VERIFY(evhttp_uri_get_host(host_port));
-		VERIFY(evhttp_uri_get_port(host_port) > 0);
-	}
-	{
-		location = evhttp_uri_parse(argv[2]);
-		evhttp_uri_set_scheme(location, NULL);
-		evhttp_uri_set_userinfo(location, 0);
-		evhttp_uri_set_host(location, NULL);
-		evhttp_uri_set_port(location, -1);
-	}
+	proxy    = uri_parse(argv[1]);
+	location = uri_parse(argv[2]);
 
 	VERIFY(base = event_base_new());
 	VERIFY(evcon = evhttp_connection_base_new(base, NULL,
@@ -105,17 +114,18 @@
 	connect_base.location = location;
 	VERIFY(req = evhttp_request_new(connect_cb, &connect_base));
 
+	uri_hostport(location, hostport);
 	evhttp_add_header(req->output_headers, "Connection", "keep-alive");
 	evhttp_add_header(req->output_headers, "Proxy-Connection", "keep-alive");
-	evutil_snprintf(buffer, URL_MAX, "%s:%d",
-		evhttp_uri_get_host(host_port), evhttp_uri_get_port(host_port));
-	evhttp_make_request(evcon, req, EVHTTP_REQ_CONNECT, buffer);
+	evhttp_add_header(req->output_headers, "Host", hostport);
+	evhttp_make_request(evcon, req, EVHTTP_REQ_CONNECT, hostport);
 
 	event_base_dispatch(base);
+
 	evhttp_connection_free(evcon);
 	event_base_free(base);
 	evhttp_uri_free(proxy);
-	evhttp_uri_free(host_port);
 	evhttp_uri_free(location);
+
 	return 0;
 }
diff --git a/sample/http-server.c b/sample/http-server.c
index cedb2af..049aabc 100644
--- a/sample/http-server.c
+++ b/sample/http-server.c
@@ -99,14 +99,14 @@
 	{ NULL, NULL },
 };
 
-struct options
-{
+struct options {
 	int port;
 	int iocp;
 	int verbose;
 
 	int unlink;
 	const char *unixsock;
+	const char *docroot;
 };
 
 /* Try to guess a good content-type for 'path' */
@@ -182,7 +182,7 @@
 send_document_cb(struct evhttp_request *req, void *arg)
 {
 	struct evbuffer *evb = NULL;
-	const char *docroot = arg;
+	struct options *o = arg;
 	const char *uri = evhttp_request_get_uri(req);
 	struct evhttp_uri *decoded = NULL;
 	const char *path;
@@ -222,12 +222,12 @@
 	if (strstr(decoded_path, ".."))
 		goto err;
 
-	len = strlen(decoded_path)+strlen(docroot)+2;
+	len = strlen(decoded_path)+strlen(o->docroot)+2;
 	if (!(whole_path = malloc(len))) {
 		perror("malloc");
 		goto err;
 	}
-	evutil_snprintf(whole_path, len, "%s/%s", docroot, decoded_path);
+	evutil_snprintf(whole_path, len, "%s/%s", o->docroot, decoded_path);
 
 	if (stat(whole_path, &st)<0) {
 		goto err;
@@ -346,12 +346,13 @@
 static void
 print_usage(FILE *out, const char *prog, int exit_code)
 {
-	fprintf(out, "Syntax: [ OPTS ] %s <docroot>\n", prog);
-	fprintf(out, " -p      - port\n");
-	fprintf(out, " -U      - bind to unix socket\n");
-	fprintf(out, " -u      - unlink unix socket before bind\n");
-	fprintf(out, " -I      - IOCP\n");
-	fprintf(out, " -v      - verbosity, enables libevent debug logging too\n");
+	fprintf(out,
+		"Syntax: %s [ OPTS ] <docroot>\n"
+		" -p      - port\n"
+		" -U      - bind to unix socket\n"
+		" -u      - unlink unix socket before bind\n"
+		" -I      - IOCP\n"
+		" -v      - verbosity, enables libevent debug logging too\n", prog);
 	exit(exit_code);
 }
 static struct options
@@ -374,9 +375,10 @@
 		}
 	}
 
-	if (optind >= argc || (argc-optind) > 1) {
+	if (optind >= argc || (argc - optind) > 1) {
 		print_usage(stdout, argv[0], 1);
 	}
+	o.docroot = argv[optind];
 
 	return o;
 }
@@ -504,7 +506,7 @@
 
 	/* We want to accept arbitrary requests, so we need to set a "generic"
 	 * cb.  We can also add callbacks for specific paths. */
-	evhttp_set_gencb(http, send_document_cb, argv[1]);
+	evhttp_set_gencb(http, send_document_cb, &o);
 
 	if (o.unixsock) {
 #ifdef EVENT__HAVE_STRUCT_SOCKADDR_UN
diff --git a/sample/https-client.c b/sample/https-client.c
index 58e449b..5136ace 100644
--- a/sample/https-client.c
+++ b/sample/https-client.c
@@ -118,7 +118,6 @@
 	exit(1);
 }
 
-#ifndef _WIN32
 /* See http://archives.seul.org/libevent/users/Jan-2013/msg00039.html */
 static int cert_verify_callback(X509_STORE_CTX *x509_ctx, void *arg)
 {
@@ -181,6 +180,35 @@
 		return 0;
 	}
 }
+
+#ifdef _WIN32
+static int
+add_cert_for_store(X509_STORE *store, const char *name)
+{
+	HCERTSTORE sys_store = NULL;
+	PCCERT_CONTEXT ctx = NULL;
+	int r = 0;
+
+	sys_store = CertOpenSystemStore(0, name);
+	if (!sys_store) {
+		err("failed to open system certificate store");
+		return -1;
+	}
+	while ((ctx = CertEnumCertificatesInStore(sys_store, ctx))) {
+		X509 *x509 = d2i_X509(NULL, (unsigned char const **)&ctx->pbCertEncoded,
+			ctx->cbCertEncoded);
+		if (x509) {
+			X509_STORE_add_cert(store, x509);
+			X509_free(x509);
+		} else {
+			r = -1;
+			err_openssl("d2i_X509");
+			break;
+		}
+	}
+	CertCloseStore(sys_store, 0);
+	return r;
+}
 #endif
 
 int
@@ -335,17 +363,22 @@
 		goto error;
 	}
 
-#ifndef _WIN32
-	/* TODO: Add certificate loading on Windows as well */
-
 	if (crt == NULL) {
 		X509_STORE *store;
 		/* Attempt to use the system's trusted root certificates. */
 		store = SSL_CTX_get_cert_store(ssl_ctx);
+#ifdef _WIN32
+		if (add_cert_for_store(store, "CA") < 0 ||
+		    add_cert_for_store(store, "AuthRoot") < 0 ||
+		    add_cert_for_store(store, "ROOT") < 0) {
+			goto error;
+		}
+#else // _WIN32
 		if (X509_STORE_set_default_paths(store) != 1) {
 			err_openssl("X509_STORE_set_default_paths");
 			goto error;
 		}
+#endif // _WIN32
 	} else {
 		if (SSL_CTX_load_verify_locations(ssl_ctx, crt, NULL) != 1) {
 			err_openssl("SSL_CTX_load_verify_locations");
@@ -376,9 +409,6 @@
 	 * "wrapping" OpenSSL's routine, not replacing it. */
 	SSL_CTX_set_cert_verify_callback(ssl_ctx, cert_verify_callback,
 					  (void *) host);
-#else // _WIN32
-	(void)crt;
-#endif // _WIN32
 
 	// Create event base
 	base = event_base_new();
diff --git a/sample/include.am b/sample/include.am
index cc003b7..b6894d4 100644
--- a/sample/include.am
+++ b/sample/include.am
@@ -25,6 +25,9 @@
 	sample/hostcheck.c \
 	sample/openssl_hostname_validation.c
 sample_https_client_LDADD = libevent.la libevent_openssl.la $(OPENSSL_LIBS) $(OPENSSL_LIBADD)
+if BUILD_WIN32
+sample_https_client_LDADD += -lcrypt32
+endif
 sample_https_client_CPPFLAGS = $(AM_CPPFLAGS) $(OPENSSL_INCS)
 noinst_HEADERS += \
 	sample/hostcheck.h \
diff --git a/sample/signal-test.c b/sample/signal-test.c
index 1866835..4aef420 100644
--- a/sample/signal-test.c
+++ b/sample/signal-test.c
@@ -44,8 +44,9 @@
 int
 main(int argc, char **argv)
 {
-	struct event *signal_int;
+	struct event *signal_int = NULL;
 	struct event_base* base;
+	int ret = 0;
 #ifdef _WIN32
 	WORD wVersionRequested;
 	WSADATA wsaData;
@@ -55,18 +56,28 @@
 	(void) WSAStartup(wVersionRequested, &wsaData);
 #endif
 
-	/* Initalize the event library */
+	/* Initialize the event library */
 	base = event_base_new();
+	if (!base) {
+		ret = 1;
+		goto out;
+	}
 
-	/* Initalize one event */
+	/* Initialize one event */
 	signal_int = evsignal_new(base, SIGINT, signal_cb, event_self_cbarg());
-
+	if (!signal_int) {
+		ret = 2;
+		goto out;
+	}
 	event_add(signal_int, NULL);
 
 	event_base_dispatch(base);
-	event_free(signal_int);
-	event_base_free(base);
 
-	return (0);
+out:
+	if (signal_int)
+		event_free(signal_int);
+	if (base)
+		event_base_free(base);
+	return ret;
 }
 
diff --git a/sample/time-test.c b/sample/time-test.c
index 8d0fd91..671a1d2 100644
--- a/sample/time-test.c
+++ b/sample/time-test.c
@@ -88,10 +88,10 @@
 		flags = 0;
 	}
 
-	/* Initalize the event library */
+	/* Initialize the event library */
 	base = event_base_new();
 
-	/* Initalize one event */
+	/* Initialize one event */
 	event_assign(&timeout, base, -1, flags, timeout_cb, (void*) &timeout);
 
 	evutil_timerclear(&tv);
diff --git a/select.c b/select.c
index 8ae53cc..b1db0e4 100644
--- a/select.c
+++ b/select.c
@@ -98,7 +98,7 @@
 	select_del,
 	select_dispatch,
 	select_dealloc,
-	0, /* doesn't need reinit. */
+	1, /* need_reinit. */
 	EV_FEATURE_FDS,
 	0,
 };
diff --git a/test/bench.c b/test/bench.c
index 3a6886d..f2af4d3 100644
--- a/test/bench.c
+++ b/test/bench.c
@@ -70,6 +70,7 @@
 static evutil_socket_t *pipes;
 static int num_pipes, num_active, num_writes;
 static struct event *events;
+static struct event_base *base;
 
 
 static void
@@ -105,11 +106,11 @@
 	for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) {
 		if (event_initialized(&events[i]))
 			event_del(&events[i]);
-		event_set(&events[i], cp[0], EV_READ | EV_PERSIST, read_cb, (void *)(ev_intptr_t) i);
+		event_assign(&events[i], base, cp[0], EV_READ | EV_PERSIST, read_cb, (void *)(ev_intptr_t) i);
 		event_add(&events[i], NULL);
 	}
 
-	event_loop(EVLOOP_ONCE | EVLOOP_NONBLOCK);
+	event_base_loop(base, EVLOOP_ONCE | EVLOOP_NONBLOCK);
 
 	fired = 0;
 	space = num_pipes / num_active;
@@ -123,7 +124,7 @@
 		int xcount = 0;
 		evutil_gettimeofday(&ts, NULL);
 		do {
-			event_loop(EVLOOP_ONCE | EVLOOP_NONBLOCK);
+			event_base_loop(base, EVLOOP_ONCE | EVLOOP_NONBLOCK);
 			xcount++;
 		} while (count != fired);
 		evutil_gettimeofday(&te, NULL);
@@ -147,6 +148,9 @@
 	int i, c;
 	struct timeval *tv;
 	evutil_socket_t *cp;
+	const char **methods;
+	const char *method = NULL;
+	struct event_config *cfg = NULL;
 
 #ifdef _WIN32
 	WSADATA WSAData;
@@ -155,7 +159,7 @@
 	num_pipes = 100;
 	num_active = 1;
 	num_writes = num_pipes;
-	while ((c = getopt(argc, argv, "n:a:w:")) != -1) {
+	while ((c = getopt(argc, argv, "n:a:w:m:l")) != -1) {
 		switch (c) {
 		case 'n':
 			num_pipes = atoi(optarg);
@@ -166,6 +170,16 @@
 		case 'w':
 			num_writes = atoi(optarg);
 			break;
+		case 'm':
+			method = optarg;
+			break;
+		case 'l':
+			methods = event_get_supported_methods();
+			fprintf(stdout, "Using Libevent %s. Available methods are:\n",
+				event_get_version());
+			for (i = 0; methods[i] != NULL; ++i)
+				printf("    %s\n", methods[i]);
+			exit(0);
 		default:
 			fprintf(stderr, "Illegal argument \"%c\"\n", c);
 			exit(1);
@@ -187,7 +201,16 @@
 		exit(1);
 	}
 
-	event_init();
+	if (method != NULL) {
+		cfg = event_config_new();
+		methods = event_get_supported_methods();
+		for (i = 0; methods[i] != NULL; ++i)
+			if (strcmp(methods[i], method))
+				event_config_avoid_method(cfg, methods[i]);
+		base = event_base_new_with_config(cfg);
+		event_config_free(cfg);
+	} else
+		base = event_base_new();
 
 	for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) {
 #ifdef USE_PIPES
diff --git a/test/regress.c b/test/regress.c
index 0ebadcb..08c30fa 100644
--- a/test/regress.c
+++ b/test/regress.c
@@ -31,10 +31,6 @@
 #include <windows.h>
 #endif
 
-#ifdef EVENT__HAVE_PTHREADS
-#include <pthread.h>
-#endif
-
 #include "event2/event-config.h"
 
 #include <sys/types.h>
@@ -73,6 +69,7 @@
 #include "time-internal.h"
 
 #include "regress.h"
+#include "regress_thread.h"
 
 #ifndef _WIN32
 #include "regress.gen.h"
@@ -390,7 +387,7 @@
 }
 
 static void
-test_simpleclose(void *ptr)
+test_simpleclose_rw(void *ptr)
 {
 	/* Test that a close of FD is detected as a read and as a write. */
 	struct event_base *base = event_base_new();
@@ -472,6 +469,56 @@
 		event_base_free(base);
 }
 
+static void
+test_simpleclose(void *ptr)
+{
+	struct basic_test_data *data = ptr;
+	struct event_base *base      = data->base;
+	evutil_socket_t *pair        = data->pair;
+	const char *flags            = (const char *)data->setup_data;
+	int et                       = !!strstr(flags, "ET");
+	int persist                  = !!strstr(flags, "persist");
+	short events                 = EV_CLOSED | (et ? EV_ET : 0) | (persist ? EV_PERSIST : 0);
+	struct event *ev = NULL;
+	short got_event;
+
+	if (!(event_base_get_features(data->base) & EV_FEATURE_EARLY_CLOSE))
+		tt_skip();
+
+	/* XXX: should this code moved to regress_et.c ? */
+	if (et && !(event_base_get_features(data->base) & EV_FEATURE_ET))
+		tt_skip();
+
+	ev = event_new(base, pair[0], events, record_event_cb, &got_event);
+	tt_assert(ev);
+	tt_assert(!event_add(ev, NULL));
+
+	got_event = 0;
+	if (strstr(flags, "close")) {
+		tt_assert(!evutil_closesocket(pair[1]));
+		/* avoid closing in setup routines */
+		pair[1] = -1;
+	} else if (strstr(flags, "shutdown")) {
+		tt_assert(!shutdown(pair[1], EVUTIL_SHUT_WR));
+	} else {
+		tt_abort_msg("unknown flags");
+	}
+
+	/* w/o edge-triggerd but w/ persist it will not stop */
+	if (!et && persist) {
+		struct timeval tv;
+		tv.tv_sec = 0;
+		tv.tv_usec = 10000;
+		tt_assert(!event_base_loopexit(base, &tv));
+	}
+
+	tt_int_op(event_base_loop(base, EVLOOP_NONBLOCK), ==, !persist);
+	tt_int_op(got_event, ==, (events & ~EV_PERSIST));
+
+end:
+	if (ev)
+		event_free(ev);
+}
 
 static void
 test_multiple(void)
@@ -979,7 +1026,7 @@
 		evutil_closesocket(child_pair[1]);
 }
 
-#ifdef EVENT__HAVE_PTHREADS
+#ifdef EVTHREAD_USE_PTHREADS_IMPLEMENTED
 static void* del_wait_thread(void *arg)
 {
 	struct timeval tv_start, tv_end;
@@ -1007,14 +1054,14 @@
 test_del_wait(void)
 {
 	struct event ev;
-	pthread_t thread;
+	THREAD_T thread;
 
 	setup_test("event_del will wait: ");
 
 	event_set(&ev, pair[1], EV_READ|EV_PERSIST, del_wait_cb, &ev);
 	event_add(&ev, NULL);
 
-	pthread_create(&thread, NULL, del_wait_thread, NULL);
+	THREAD_START(thread, del_wait_thread, NULL);
 
 	if (write(pair[0], TEST1, strlen(TEST1)+1) < 0) {
 		tt_fail_perror("write");
@@ -1033,7 +1080,7 @@
 		test_timeval_diff_eq(&tv_start, &tv_end, 270);
 	}
 
-	pthread_join(thread, NULL);
+	THREAD_JOIN(thread);
 
 	tt_int_op(test_ok, ==, 1);
 
@@ -1051,14 +1098,14 @@
 test_del_notify(void)
 {
 	struct event ev;
-	pthread_t thread;
+	THREAD_T thread;
 
 	test_ok = 1;
 
 	event_set(&ev, -1, EV_READ, null_cb, &ev);
 	event_add(&ev, NULL);
 
-	pthread_create(&thread, NULL, test_del_notify_thread, NULL);
+	THREAD_START(thread, test_del_notify_thread, NULL);
 
 	{
 		struct timeval delay = { 0, 1000 };
@@ -1066,7 +1113,7 @@
 	}
 
 	event_del(&ev);
-	pthread_join(thread, NULL);
+	THREAD_JOIN(thread);
 }
 #endif
 
@@ -3464,8 +3511,35 @@
 	LEGACY(simpleread, TT_ISOLATED),
 	LEGACY(simpleread_multiple, TT_ISOLATED),
 	LEGACY(simplewrite, TT_ISOLATED),
-	{ "simpleclose", test_simpleclose, TT_FORK, &basic_setup,
-	  NULL },
+	{ "simpleclose_rw", test_simpleclose_rw, TT_FORK, &basic_setup, NULL },
+	/* simpleclose */
+	{ "simpleclose_close", test_simpleclose,
+	  TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE,
+	  &basic_setup, (void *)"close" },
+	{ "simpleclose_shutdown", test_simpleclose,
+	  TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE,
+	  &basic_setup, (void *)"shutdown" },
+	/* simpleclose_*_persist */
+	{ "simpleclose_close_persist", test_simpleclose,
+	  TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE,
+	  &basic_setup, (void *)"close_persist" },
+	{ "simpleclose_shutdown_persist", test_simpleclose,
+	  TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE,
+	  &basic_setup, (void *)"shutdown_persist" },
+	/* simpleclose_*_et */
+	{ "simpleclose_close_et", test_simpleclose,
+	  TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE,
+	  &basic_setup, (void *)"close_ET" },
+	{ "simpleclose_shutdown_et", test_simpleclose,
+	  TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE,
+	  &basic_setup, (void *)"shutdown_ET" },
+	/* simpleclose_*_persist_et */
+	{ "simpleclose_close_persist_et", test_simpleclose,
+	  TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE,
+	  &basic_setup, (void *)"close_persist_ET" },
+	{ "simpleclose_shutdown_persist_et", test_simpleclose,
+	  TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE,
+	  &basic_setup, (void *)"shutdown_persist_ET" },
 	LEGACY(multiple, TT_ISOLATED),
 	LEGACY(persistent, TT_ISOLATED),
 	LEGACY(combined, TT_ISOLATED),
@@ -3505,8 +3579,8 @@
 #ifndef _WIN32
 	LEGACY(fork, TT_ISOLATED),
 #endif
-#ifdef EVENT__HAVE_PTHREADS
-	/** TODO: support win32 */
+
+#ifdef EVTHREAD_USE_PTHREADS_IMPLEMENTED
 	LEGACY(del_wait, TT_ISOLATED|TT_NEED_THREADS|TT_RETRIABLE),
 	LEGACY(del_notify, TT_ISOLATED|TT_NEED_THREADS),
 #endif
diff --git a/test/regress.gen.c b/test/regress.gen.c
index 09f4674..611ec8a 100644
--- a/test/regress.gen.c
+++ b/test/regress.gen.c
@@ -1,3 +1,4 @@
+
 /*
  * Automatically generated from ../test/regress.rpc
  * by event_rpcgen.py/0.1.  DO NOT EDIT THIS FILE.
@@ -91,7 +92,8 @@
     return -1;
   msg->run_data = new_data;
   msg->run_num_allocated = tobe_allocated;
-  return 0;}
+  return 0;
+}
 
 struct run* 
 msg_run_add(struct msg *msg)
@@ -173,7 +175,7 @@
 
 int
 msg_run_assign(struct msg *msg, int off,
-    const struct run* value)
+  const struct run* value)
 {
   if (!msg->run_set || off < 0 || off >= msg->run_length)
     return (-1);
@@ -193,7 +195,8 @@
       had_error = 1;
       goto done;
     }
-    done:if (tmp != NULL)
+    done:
+    if (tmp != NULL)
       evbuffer_free(tmp);
     if (had_error) {
       run_clear(msg->run_data[off]);
@@ -300,7 +303,7 @@
 }
 
 void
-msg_marshal(struct evbuffer *evbuf, const struct msg *tmp){
+msg_marshal(struct evbuffer *evbuf, const struct msg *tmp) {
   evtag_marshal_string(evbuf, MSG_FROM_NAME, tmp->from_name_data);
   evtag_marshal_string(evbuf, MSG_TO_NAME, tmp->to_name_data);
   if (tmp->attack_set) {
@@ -317,7 +320,7 @@
 }
 
 int
-msg_unmarshal(struct msg *tmp,  struct evbuffer *evbuf)
+msg_unmarshal(struct msg *tmp, struct evbuffer *evbuf)
 {
   ev_uint32_t tag;
   while (evbuffer_get_length(evbuf) > 0) {
@@ -349,7 +352,8 @@
         tmp->attack_data = kill_new();
         if (tmp->attack_data == NULL)
           return (-1);
-        if (evtag_unmarshal_kill(evbuf, MSG_ATTACK, tmp->attack_data) == -1) {
+        if (evtag_unmarshal_kill(evbuf, MSG_ATTACK, 
+            tmp->attack_data) == -1) {
           event_warnx("%s: failed to unmarshal attack", __func__);
           return (-1);
         }
@@ -364,7 +368,8 @@
         tmp->run_data[tmp->run_length] = run_new();
         if (tmp->run_data[tmp->run_length] == NULL)
           return (-1);
-        if (evtag_unmarshal_run(evbuf, MSG_RUN, tmp->run_data[tmp->run_length]) == -1) {
+        if (evtag_unmarshal_run(evbuf, MSG_RUN, 
+            tmp->run_data[tmp->run_length]) == -1) {
           event_warnx("%s: failed to unmarshal run", __func__);
           return (-1);
         }
@@ -401,7 +406,8 @@
 }
 
 int
-evtag_unmarshal_msg(struct evbuffer *evbuf, ev_uint32_t need_tag, struct msg *msg)
+evtag_unmarshal_msg(struct evbuffer *evbuf, ev_uint32_t need_tag,
+  struct msg *msg)
 {
   ev_uint32_t tag;
   int res = -1;
@@ -422,13 +428,14 @@
 }
 
 void
-evtag_marshal_msg(struct evbuffer *evbuf, ev_uint32_t tag, const struct msg *msg)
+evtag_marshal_msg(struct evbuffer *evbuf, ev_uint32_t tag,
+    const struct msg *msg)
 {
   struct evbuffer *buf_ = evbuffer_new();
   assert(buf_ != NULL);
   msg_marshal(buf_, msg);
   evtag_marshal_buffer(evbuf, tag, buf_);
-   evbuffer_free(buf_);
+  evbuffer_free(buf_);
 }
 
 /*
@@ -489,7 +496,8 @@
     return -1;
   msg->how_often_data = new_data;
   msg->how_often_num_allocated = tobe_allocated;
-  return 0;}
+  return 0;
+}
 
 ev_uint32_t *
 kill_how_often_add(struct kill *msg, const ev_uint32_t value)
@@ -532,7 +540,7 @@
 
 int
 kill_how_often_assign(struct kill *msg, int off,
-    const ev_uint32_t value)
+  const ev_uint32_t value)
 {
   if (!msg->how_often_set || off < 0 || off >= msg->how_often_length)
     return (-1);
@@ -612,7 +620,7 @@
 }
 
 void
-kill_marshal(struct evbuffer *evbuf, const struct kill *tmp){
+kill_marshal(struct evbuffer *evbuf, const struct kill *tmp) {
   evtag_marshal_string(evbuf, KILL_WEAPON, tmp->weapon_data);
   evtag_marshal_string(evbuf, KILL_ACTION, tmp->action_data);
   if (tmp->how_often_set) {
@@ -626,7 +634,7 @@
 }
 
 int
-kill_unmarshal(struct kill *tmp,  struct evbuffer *evbuf)
+kill_unmarshal(struct kill *tmp, struct evbuffer *evbuf)
 {
   ev_uint32_t tag;
   while (evbuffer_get_length(evbuf) > 0) {
@@ -686,7 +694,8 @@
 }
 
 int
-evtag_unmarshal_kill(struct evbuffer *evbuf, ev_uint32_t need_tag, struct kill *msg)
+evtag_unmarshal_kill(struct evbuffer *evbuf, ev_uint32_t need_tag,
+  struct kill *msg)
 {
   ev_uint32_t tag;
   int res = -1;
@@ -707,13 +716,14 @@
 }
 
 void
-evtag_marshal_kill(struct evbuffer *evbuf, ev_uint32_t tag, const struct kill *msg)
+evtag_marshal_kill(struct evbuffer *evbuf, ev_uint32_t tag,
+    const struct kill *msg)
 {
   struct evbuffer *buf_ = evbuffer_new();
   assert(buf_ != NULL);
   kill_marshal(buf_, msg);
   evtag_marshal_buffer(evbuf, tag, buf_);
-   evbuffer_free(buf_);
+  evbuffer_free(buf_);
 }
 
 /*
@@ -794,7 +804,8 @@
     return -1;
   msg->notes_data = new_data;
   msg->notes_num_allocated = tobe_allocated;
-  return 0;}
+  return 0;
+}
 
 char * *
 run_notes_add(struct run *msg, const char * value)
@@ -831,7 +842,8 @@
     return -1;
   msg->other_numbers_data = new_data;
   msg->other_numbers_num_allocated = tobe_allocated;
-  return 0;}
+  return 0;
+}
 
 ev_uint32_t *
 run_other_numbers_add(struct run *msg, const ev_uint32_t value)
@@ -884,7 +896,7 @@
 
 int
 run_notes_assign(struct run *msg, int off,
-    const char * value)
+  const char * value)
 {
   if (!msg->notes_set || off < 0 || off >= msg->notes_length)
     return (-1);
@@ -911,7 +923,7 @@
 
 int
 run_other_numbers_assign(struct run *msg, int off,
-    const ev_uint32_t value)
+  const ev_uint32_t value)
 {
   if (!msg->other_numbers_set || off < 0 || off >= msg->other_numbers_length)
     return (-1);
@@ -1047,7 +1059,7 @@
 }
 
 void
-run_marshal(struct evbuffer *evbuf, const struct run *tmp){
+run_marshal(struct evbuffer *evbuf, const struct run *tmp) {
   evtag_marshal_string(evbuf, RUN_HOW, tmp->how_data);
   if (tmp->some_bytes_set) {
     evtag_marshal(evbuf, RUN_SOME_BYTES, tmp->some_bytes_data, tmp->some_bytes_length);
@@ -1075,7 +1087,7 @@
 }
 
 int
-run_unmarshal(struct run *tmp,  struct evbuffer *evbuf)
+run_unmarshal(struct run *tmp, struct evbuffer *evbuf)
 {
   ev_uint32_t tag;
   while (evbuffer_get_length(evbuf) > 0) {
@@ -1172,7 +1184,8 @@
 }
 
 int
-evtag_unmarshal_run(struct evbuffer *evbuf, ev_uint32_t need_tag, struct run *msg)
+evtag_unmarshal_run(struct evbuffer *evbuf, ev_uint32_t need_tag,
+  struct run *msg)
 {
   ev_uint32_t tag;
   int res = -1;
@@ -1193,12 +1206,13 @@
 }
 
 void
-evtag_marshal_run(struct evbuffer *evbuf, ev_uint32_t tag, const struct run *msg)
+evtag_marshal_run(struct evbuffer *evbuf, ev_uint32_t tag,
+    const struct run *msg)
 {
   struct evbuffer *buf_ = evbuffer_new();
   assert(buf_ != NULL);
   run_marshal(buf_, msg);
   evtag_marshal_buffer(evbuf, tag, buf_);
-   evbuffer_free(buf_);
+  evbuffer_free(buf_);
 }
 
diff --git a/test/regress.gen.h b/test/regress.gen.h
index 5a657f5..b3683bd 100644
--- a/test/regress.gen.h
+++ b/test/regress.gen.h
@@ -1,3 +1,4 @@
+
 /*
  * Automatically generated from ../test/regress.rpc
  */
@@ -5,6 +6,7 @@
 #ifndef EVENT_RPCOUT____TEST_REGRESS_RPC_
 #define EVENT_RPCOUT____TEST_REGRESS_RPC_
 
+
 #include <event2/util.h> /* for ev_uint*_t */
 #include <event2/rpc.h>
 struct msg;
diff --git a/test/regress.h b/test/regress.h
index 643b82b..43cb4ea 100644
--- a/test/regress.h
+++ b/test/regress.h
@@ -95,6 +95,7 @@
 #define TT_NO_LOGS		(TT_FIRST_USER_FLAG<<5)
 #define TT_ENABLE_IOCP_FLAG	(TT_FIRST_USER_FLAG<<6)
 #define TT_ENABLE_IOCP		(TT_ENABLE_IOCP_FLAG|TT_NEED_THREADS)
+#define TT_ENABLE_DEBUG_MODE	(TT_ENABLE_IOCP_FLAG<<7)
 
 /* All the flags that a legacy test needs. */
 #define TT_ISOLATED TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE
diff --git a/test/regress_buffer.c b/test/regress_buffer.c
index 8ac4b6e..f259b92 100644
--- a/test/regress_buffer.c
+++ b/test/regress_buffer.c
@@ -426,6 +426,36 @@
 }
 
 static void
+test_evbuffer_pullup_with_empty(void *ptr)
+{
+	struct evbuffer *buf = NULL;
+
+	buf = evbuffer_new();
+	evbuffer_add(buf, "foo", 3);
+	evbuffer_add_reference(buf, NULL, 0, NULL, NULL);
+	evbuffer_validate(buf);
+	tt_int_op(evbuffer_get_length(buf), ==, 3);
+	tt_mem_op(evbuffer_pullup(buf, -1), ==, "foo", 3);
+
+	evbuffer_free(buf);
+	buf = evbuffer_new();
+	evbuffer_validate(buf);
+	tt_int_op(evbuffer_get_length(buf), ==, 0);
+	tt_int_op(evbuffer_pullup(buf, -1), ==, NULL);
+
+	evbuffer_free(buf);
+	buf = evbuffer_new();
+	evbuffer_add(buf, "foo", 3);
+	evbuffer_add_reference(buf, NULL, 0, NULL, NULL);
+	evbuffer_validate(buf);
+	tt_mem_op(evbuffer_pullup(buf, 3), ==, "foo", 3);
+
+ end:
+	if (buf)
+		evbuffer_free(buf);
+}
+
+static void
 test_evbuffer_remove_buffer_with_empty_front(void *ptr)
 {
 	struct evbuffer *buf1 = NULL, *buf2 = NULL;
@@ -2327,7 +2357,7 @@
 	tt_assert(!strncmp((char *)evbuffer_pullup(buf2, -1), "foo", 3));
 	evbuffer_validate(buf2);
 
-	tt_assert(!strncmp((char *)evbuffer_pullup(buf1, -1), "", 0));
+	tt_assert(evbuffer_pullup(buf1, -1) == NULL);
 	evbuffer_validate(buf2);
 
 end:
@@ -2494,28 +2524,37 @@
 static void
 test_evbuffer_freeze(void *ptr)
 {
-	struct evbuffer *buf = NULL, *tmp_buf=NULL;
+	struct basic_test_data *testdata = ptr;
+	evutil_socket_t *pair = testdata->pair;
+	struct evbuffer *buf = NULL, *buf_two = NULL, *tmp_buf = NULL;
 	const char string[] = /* Year's End, Richard Wilbur */
 	    "I've known the wind by water banks to shake\n"
 	    "The late leaves down, which frozen where they fell\n"
 	    "And held in ice as dancers in a spell\n"
 	    "Fluttered all winter long into a lake...";
-	const int start = !strcmp(ptr, "start");
+	const int start = !strcmp(testdata->setup_data, "start");
+	const char tmpfilecontent[] = "file_freeze_test_file";
 	char *cp;
 	char charbuf[128];
+	char *tmpfilename = NULL;
+	int fd = -1;
 	int r;
-	size_t orig_length;
+	size_t orig_length, len;
 	struct evbuffer_iovec v[1];
 
 	if (!start)
-		tt_str_op(ptr, ==, "end");
+		tt_str_op(testdata->setup_data, ==, "end");
 
 	buf = evbuffer_new();
+	buf_two = evbuffer_new();
 	tmp_buf = evbuffer_new();
 	tt_assert(tmp_buf);
 
 	evbuffer_add(buf, string, strlen(string));
+	evbuffer_add(buf_two, "abc", 3);
+	evbuffer_add(tmp_buf, "xyz", 3);
 	evbuffer_freeze(buf, start); /* Freeze the start or the end.*/
+	evbuffer_freeze(buf_two, start);
 
 #define FREEZE_EQ(a, startcase, endcase)		\
 	do {						\
@@ -2544,7 +2583,22 @@
 	FREEZE_EQ(r, 0, -1);
 	r = evbuffer_add_printf(buf, "Hello %s", "world");
 	FREEZE_EQ(r, 11, -1);
-	/* TODO: test add_buffer, add_file, read */
+
+	r = evbuffer_add_buffer(buf, tmp_buf);
+	FREEZE_EQ(r, 0, -1);
+	len = strlen(tmpfilecontent);
+	fd = regress_make_tmpfile(tmpfilecontent, len, &tmpfilename);
+	r = evbuffer_add_file(buf, fd, 0, len);
+	FREEZE_EQ(r, 0, -1);
+
+	if (start)
+		evbuffer_add(tmp_buf, "xyz", 3);
+
+	tt_assert(evbuffer_get_length(tmp_buf));
+	len = evbuffer_get_length(tmp_buf);
+	evbuffer_write(tmp_buf, pair[0]);
+	r = evbuffer_read(buf, pair[1], -1);
+	FREEZE_EQ(r, len, -1);
 
 	if (!start)
 		tt_int_op(orig_length, ==, evbuffer_get_length(buf));
@@ -2562,7 +2616,24 @@
 	FREEZE_EQ(cp==NULL, 1, 0);
 	if (cp)
 		free(cp);
-	/* TODO: Test remove_buffer, add_buffer, write, prepend_buffer */
+
+	evbuffer_add(tmp_buf, "xyz", 3);
+	tt_assert(evbuffer_get_length(tmp_buf));
+	r = evbuffer_remove_buffer(buf, tmp_buf, 3);
+	FREEZE_EQ(r, -1, 3);
+	r = evbuffer_drain(buf, 3);
+	FREEZE_EQ(r, -1, 0);
+	r = evbuffer_prepend_buffer(buf, tmp_buf);
+	FREEZE_EQ(r, -1, 0);
+
+	len = evbuffer_get_length(buf);
+	r = evbuffer_write(buf, pair[0]);
+	evbuffer_read(tmp_buf, pair[1], -1);
+	FREEZE_EQ(r, -1, len);
+	len = evbuffer_get_length(buf_two);
+	r = evbuffer_write_atmost(buf_two, pair[0], -1);
+	evbuffer_read(tmp_buf, pair[1], -1);
+	FREEZE_EQ(r, -1, len);
 
 	if (start)
 		tt_int_op(orig_length, ==, evbuffer_get_length(buf));
@@ -2571,8 +2642,16 @@
 	if (buf)
 		evbuffer_free(buf);
 
+	if (buf_two)
+		evbuffer_free(buf_two);
+
 	if (tmp_buf)
 		evbuffer_free(tmp_buf);
+
+	if (tmpfilename) {
+		unlink(tmpfilename);
+		free(tmpfilename);
+	}
 }
 
 static void
@@ -2756,11 +2835,12 @@
 	{ "empty_reference_prepend_buffer", test_evbuffer_empty_reference_prepend_buffer, TT_FORK, NULL, NULL },
 	{ "peek", test_evbuffer_peek, 0, NULL, NULL },
 	{ "peek_first_gt", test_evbuffer_peek_first_gt, 0, NULL, NULL },
-	{ "freeze_start", test_evbuffer_freeze, 0, &nil_setup, (void*)"start" },
-	{ "freeze_end", test_evbuffer_freeze, 0, &nil_setup, (void*)"end" },
+	{ "freeze_start", test_evbuffer_freeze, TT_NEED_SOCKETPAIR, &basic_setup, (void*)"start" },
+	{ "freeze_end", test_evbuffer_freeze, TT_NEED_SOCKETPAIR, &basic_setup, (void*)"end" },
 	{ "add_iovec", test_evbuffer_add_iovec, 0, NULL, NULL},
 	{ "copyout", test_evbuffer_copyout, 0, NULL, NULL},
 	{ "file_segment_add_cleanup_cb", test_evbuffer_file_segment_add_cleanup_cb, 0, NULL, NULL },
+	{ "pullup_with_empty", test_evbuffer_pullup_with_empty, 0, NULL, NULL },
 
 #define ADDFILE_TEST(name, parameters)					\
 	{ name, test_evbuffer_add_file, TT_FORK|TT_NEED_BASE,		\
diff --git a/test/regress_bufferevent.c b/test/regress_bufferevent.c
index d4208c2..c276a0e 100644
--- a/test/regress_bufferevent.c
+++ b/test/regress_bufferevent.c
@@ -29,6 +29,19 @@
 /* The old tests here need assertions to work. */
 #undef NDEBUG
 
+/**
+ * - clang supports __has_feature
+ * - gcc supports __SANITIZE_ADDRESS__
+ *
+ * Let's set __SANITIZE_ADDRESS__ if __has_feature(address_sanitizer)
+ */
+#ifndef __has_feature
+#define __has_feature(x) 0
+#endif
+#if !defined(__SANITIZE_ADDRESS__) && __has_feature(address_sanitizer)
+#define __SANITIZE_ADDRESS__
+#endif
+
 #ifdef _WIN32
 #include <winsock2.h>
 #include <windows.h>
@@ -203,7 +216,7 @@
 static void test_bufferevent_pair_flush_flush(void) { test_bufferevent_impl(1, BEV_FLUSH); }
 static void test_bufferevent_pair_flush_finished(void) { test_bufferevent_impl(1, BEV_FINISHED); }
 
-#if defined(EVTHREAD_USE_PTHREADS_IMPLEMENTED)
+#if defined(EVTHREAD_USE_PTHREADS_IMPLEMENTED) && !defined(__SANITIZE_ADDRESS__)
 /**
  * Trace lock/unlock/alloc/free for locks.
  * (More heavier then evthread_debug*)
@@ -788,15 +801,28 @@
 }
 
 static void
+close_socket_cb(evutil_socket_t fd, short what, void *arg)
+{
+	evutil_socket_t *fdp = arg;
+	if (*fdp >= 0) {
+		evutil_closesocket(*fdp);
+		*fdp = -1;
+	}
+}
+
+static void
 test_bufferevent_connect_fail_eventcb(void *arg)
 {
 	struct basic_test_data *data = arg;
 	int flags = BEV_OPT_CLOSE_ON_FREE | (long)data->setup_data;
+	struct event close_listener_event;
 	struct bufferevent *bev = NULL;
 	struct evconnlistener *lev = NULL;
 	struct sockaddr_in localhost;
+	struct timeval close_timeout = { 0, 300000 };
 	ev_socklen_t slen = sizeof(localhost);
 	evutil_socket_t fake_listener = -1;
+	int r;
 
 	fake_listener = fake_listener_create(&localhost);
 
@@ -809,10 +835,22 @@
 	bufferevent_enable(bev, EV_READ|EV_WRITE);
 	tt_int_op(n_events_invoked, ==, 0);
 	tt_int_op(n_reads_invoked, ==, 0);
+
 	/** @see also test_bufferevent_connect_fail() */
-	bufferevent_socket_connect(bev, (struct sockaddr *)&localhost, slen);
+	r = bufferevent_socket_connect(bev, (struct sockaddr *)&localhost, slen);
+	/* XXXX we'd like to test the '0' case everywhere, but FreeBSD tells
+	 * detects the error immediately, which is not really wrong of it. */
+	tt_want(r == 0 || r == -1);
+
 	tt_int_op(n_events_invoked, ==, 0);
 	tt_int_op(n_reads_invoked, ==, 0);
+
+	/* Close the listener socket after a delay. This should trigger
+	   "connection refused" on some other platforms, including OSX. */
+	evtimer_assign(&close_listener_event, data->base, close_socket_cb,
+	    &fake_listener);
+	event_add(&close_listener_event, &close_timeout);
+
 	event_base_dispatch(data->base);
 	tt_int_op(n_events_invoked, ==, 1);
 	tt_int_op(n_reads_invoked, ==, 0);
@@ -847,23 +885,13 @@
 }
 
 static void
-close_socket_cb(evutil_socket_t fd, short what, void *arg)
-{
-	evutil_socket_t *fdp = arg;
-	if (*fdp >= 0) {
-		evutil_closesocket(*fdp);
-		*fdp = -1;
-	}
-}
-
-static void
 test_bufferevent_connect_fail(void *arg)
 {
 	struct basic_test_data *data = (struct basic_test_data *)arg;
 	struct bufferevent *bev=NULL;
 	struct event close_listener_event;
 	int close_listener_event_added = 0;
-	struct timeval one_second = { 1, 0 };
+	struct timeval close_timeout = { 0, 300000 };
 	struct sockaddr_in localhost;
 	ev_socklen_t slen = sizeof(localhost);
 	evutil_socket_t fake_listener = -1;
@@ -882,11 +910,11 @@
 	 * detects the error immediately, which is not really wrong of it. */
 	tt_want(r == 0 || r == -1);
 
-	/* Close the listener socket after a second. This should trigger
+	/* Close the listener socket after a delay. This should trigger
 	   "connection refused" on some other platforms, including OSX. */
 	evtimer_assign(&close_listener_event, data->base, close_socket_cb,
 	    &fake_listener);
-	event_add(&close_listener_event, &one_second);
+	event_add(&close_listener_event, &close_timeout);
 	close_listener_event_added = 1;
 
 	event_base_dispatch(data->base);
@@ -1336,7 +1364,7 @@
 	LEGACY(bufferevent_pair_flush_normal, TT_ISOLATED),
 	LEGACY(bufferevent_pair_flush_flush, TT_ISOLATED),
 	LEGACY(bufferevent_pair_flush_finished, TT_ISOLATED),
-#if defined(EVTHREAD_USE_PTHREADS_IMPLEMENTED)
+#if defined(EVTHREAD_USE_PTHREADS_IMPLEMENTED) && !defined(__SANITIZE_ADDRESS__)
 	{ "bufferevent_pair_release_lock", test_bufferevent_pair_release_lock,
 	  TT_FORK|TT_ISOLATED|TT_NEED_THREADS|TT_NEED_BASE|TT_LEGACY|TT_NO_LOGS,
 	  &basic_setup, NULL },
diff --git a/test/regress_dns.c b/test/regress_dns.c
index d2084b7..9a8bff4 100644
--- a/test/regress_dns.c
+++ b/test/regress_dns.c
@@ -1265,27 +1265,9 @@
 	int n_accept=0, n_dns=0;
 	char buf[128];
 	int emfile = data->setup_data && !strcmp(data->setup_data, "emfile");
-	int success = BEV_EVENT_CONNECTED;
-	int default_error = 0;
 	unsigned i;
 	int ret;
 
-	if (emfile) {
-		success = BEV_EVENT_ERROR;
-#if defined(__linux__)
-		/* on linux glibc/musl reports EAI_SYSTEM, when getaddrinfo() cannot
-		 * open file for resolving service. */
-		default_error = EVUTIL_EAI_SYSTEM;
-#elif defined(__sun__)
-		/* on solaris it returns EAI_FAIL */
-		default_error = EVUTIL_EAI_FAIL;
-		/** the DP_POLL can also fail with EINVAL under EMFILE */
-#else
-		/* on osx/freebsd it returns EAI_NONAME */
-		default_error = EVUTIL_EAI_NONAME;
-#endif
-	}
-
 	be_connect_hostname_base = data->base;
 
 	/* Bind an address and figure out what port it's on. */
@@ -1376,12 +1358,16 @@
 
 	tt_int_op(be_outcome[0].what, ==, BEV_EVENT_ERROR);
 	tt_int_op(be_outcome[0].dnserr, ==, EVUTIL_EAI_NONAME);
-	tt_int_op(be_outcome[1].what, ==, success);
+	tt_int_op(be_outcome[1].what, ==, !emfile ? BEV_EVENT_CONNECTED : BEV_EVENT_ERROR);
 	tt_int_op(be_outcome[1].dnserr, ==, 0);
-	tt_int_op(be_outcome[2].what, ==, success);
+	tt_int_op(be_outcome[2].what, ==, !emfile ? BEV_EVENT_CONNECTED : BEV_EVENT_ERROR);
 	tt_int_op(be_outcome[2].dnserr, ==, 0);
-	tt_int_op(be_outcome[3].what, ==, success);
-	tt_int_op(be_outcome[3].dnserr, ==, default_error);
+	tt_int_op(be_outcome[3].what, ==, !emfile ? BEV_EVENT_CONNECTED : BEV_EVENT_ERROR);
+	if (!emfile) {
+		tt_int_op(be_outcome[3].dnserr, ==, 0);
+	} else {
+		tt_int_op(be_outcome[3].dnserr, !=, 0);
+	}
 	if (expect_err) {
 		tt_int_op(be_outcome[4].what, ==, BEV_EVENT_ERROR);
 		tt_int_op(be_outcome[4].dnserr, ==, expect_err);
@@ -1822,7 +1808,8 @@
 
 #define GAIC_MAGIC 0x1234abcd
 
-static int pending = 0;
+static int gaic_pending = 0;
+static int gaic_freed = 0;
 
 static void
 gaic_cancel_request_cb(evutil_socket_t fd, short what, void *arg)
@@ -1867,7 +1854,13 @@
 	free(status);
 
 end:
-	if (--pending <= 0)
+	if (res)
+	{
+		TT_BLATHER(("evutil_freeaddrinfo(%p)", res));
+		evutil_freeaddrinfo(res);
+		++gaic_freed;
+	}
+	if (--gaic_pending <= 0)
 		event_base_loopexit(base, NULL);
 }
 
@@ -1885,7 +1878,7 @@
 	    "foobar.bazquux.example.com", "80", NULL, gaic_getaddrinfo_cb,
 	    status);
 	event_add(&status->cancel_event, &tv);
-	++pending;
+	++gaic_pending;
 }
 
 #ifdef EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
@@ -2108,6 +2101,9 @@
 
 	event_base_dispatch(base);
 
+	// at least some was canceled via external event
+	tt_int_op(gaic_freed, !=, 1000);
+
 end:
 	if (dns_base)
 		evdns_base_free(dns_base, 1);
@@ -2124,6 +2120,7 @@
 {
 	struct basic_test_data *data = arg;
 	struct event_base *base = data->base;
+	int limit_inflight = data->setup_data && !strcmp(data->setup_data, "limit-inflight");
 	struct evdns_base *dns = NULL;
 	struct evdns_server_port *dns_port = NULL;
 	ev_uint16_t portnum = 0;
@@ -2141,6 +2138,9 @@
 	dns = evdns_base_new(base, EVDNS_BASE_DISABLE_WHEN_INACTIVE);
 	tt_assert(!evdns_base_nameserver_ip_add(dns, buf));
 
+	if (limit_inflight)
+		tt_assert(!evdns_base_set_option(dns, "max-inflight:", "11"));
+
 	for (i = 0; i < 20; ++i)
 		evdns_base_resolve_ipv4(dns, "foof.example.com", 0, generic_dns_callback, &r[i]);
 
@@ -2372,6 +2372,71 @@
 		evdns_base_free(dns_base, 0);
 }
 
+static void
+test_set_option(void *arg)
+{
+#define SUCCESS 0
+#define FAIL -1
+	struct basic_test_data *data = arg;
+	struct evdns_base *dns_base;
+	size_t i;
+	/* Option names are allowed to have ':' at the end.
+	 * So all test option names come in pairs.
+	 */
+	const char *int_options[] = {
+		"ndots", "ndots:",
+		"max-timeouts", "max-timeouts:",
+		"max-inflight", "max-inflight:",
+		"attempts", "attempts:",
+		"randomize-case", "randomize-case:",
+		"so-rcvbuf", "so-rcvbuf:",
+		"so-sndbuf", "so-sndbuf:",
+	};
+	const char *timeval_options[] = {
+		"timeout", "timeout:",
+		"getaddrinfo-allow-skew", "getaddrinfo-allow-skew:",
+		"initial-probe-timeout", "initial-probe-timeout:",
+	};
+	const char *addr_port_options[] = {
+		"bind-to", "bind-to:",
+	};
+
+	dns_base = evdns_base_new(data->base, 0);
+	tt_assert(dns_base);
+
+	for (i = 0; i < ARRAY_SIZE(int_options); ++i) {
+		tt_assert(SUCCESS == evdns_base_set_option(dns_base, int_options[i], "0"));
+		tt_assert(SUCCESS == evdns_base_set_option(dns_base, int_options[i], "1"));
+		tt_assert(SUCCESS == evdns_base_set_option(dns_base, int_options[i], "10000"));
+		tt_assert(FAIL == evdns_base_set_option(dns_base, int_options[i], "foo"));
+		tt_assert(FAIL == evdns_base_set_option(dns_base, int_options[i], "3.14"));
+	}
+
+	for (i = 0; i < ARRAY_SIZE(timeval_options); ++i) {
+		tt_assert(SUCCESS == evdns_base_set_option(dns_base, timeval_options[i], "1"));
+		tt_assert(SUCCESS == evdns_base_set_option(dns_base, timeval_options[i], "0.001"));
+		tt_assert(SUCCESS == evdns_base_set_option(dns_base, timeval_options[i], "3.14"));
+		tt_assert(SUCCESS == evdns_base_set_option(dns_base, timeval_options[i], "10000"));
+		tt_assert(FAIL == evdns_base_set_option(dns_base, timeval_options[i], "0"));
+		tt_assert(FAIL == evdns_base_set_option(dns_base, timeval_options[i], "foo"));
+	}
+
+	for (i = 0; i < ARRAY_SIZE(addr_port_options); ++i) {
+		tt_assert(SUCCESS == evdns_base_set_option(dns_base, addr_port_options[i], "8.8.8.8:80"));
+		tt_assert(SUCCESS == evdns_base_set_option(dns_base, addr_port_options[i], "1.2.3.4"));
+		tt_assert(SUCCESS == evdns_base_set_option(dns_base, addr_port_options[i], "::1:82"));
+		tt_assert(SUCCESS == evdns_base_set_option(dns_base, addr_port_options[i], "3::4"));
+		tt_assert(FAIL == evdns_base_set_option(dns_base, addr_port_options[i], "3.14"));
+		tt_assert(FAIL == evdns_base_set_option(dns_base, addr_port_options[i], "foo"));
+	}
+
+#undef SUCCESS
+#undef FAIL
+end:
+	if (dns_base)
+		evdns_base_free(dns_base, 0);
+}
+
 #define DNS_LEGACY(name, flags)					       \
 	{ #name, run_legacy_test_fn, flags|TT_LEGACY, &legacy_setup,   \
 		    dns_##name }
@@ -2432,6 +2497,8 @@
 
 	{ "client_fail_requests", dns_client_fail_requests_test,
 	  TT_FORK|TT_NEED_BASE|TT_NO_LOGS, &basic_setup, NULL },
+	{ "client_fail_waiting_requests", dns_client_fail_requests_test,
+	  TT_FORK|TT_NEED_BASE|TT_NO_LOGS, &basic_setup, (char*)"limit-inflight" },
 	{ "client_fail_requests_getaddrinfo",
 	  dns_client_fail_requests_getaddrinfo_test,
 	  TT_FORK|TT_NEED_BASE|TT_NO_LOGS, &basic_setup, NULL },
@@ -2443,6 +2510,8 @@
 
 	{ "set_SO_RCVBUF_SO_SNDBUF", test_set_so_rcvbuf_so_sndbuf,
 	  TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
+	{ "set_options", test_set_option,
+	  TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
 
 	END_OF_TESTCASES
 };
diff --git a/test/regress_et.c b/test/regress_et.c
index 5fa87a3..1b1f819 100644
--- a/test/regress_et.c
+++ b/test/regress_et.c
@@ -102,7 +102,7 @@
 				"support edge-triggering", event_base_get_method(base),
 				supports_et?"":"not "));
 
-	/* Initalize one event */
+	/* Initialize one event */
 	ev = event_new(base, pair[1], EV_READ|EV_ET|EV_PERSIST, read_cb, &ev);
 	tt_assert(ev != NULL);
 	tt_int_op(event_add(ev, NULL), ==, 0);
diff --git a/test/regress_finalize.c b/test/regress_finalize.c
index 552210f..9e57188 100644
--- a/test/regress_finalize.c
+++ b/test/regress_finalize.c
@@ -290,6 +290,53 @@
 	;
 }
 
+static void
+event_finalize_callback_free(struct event *ev, void *arg)
+{
+	struct event_base *base = arg;
+	int err;
+	if (base) {
+		err = event_assign(ev, base, -1, EV_TIMEOUT, NULL, NULL);
+		tt_int_op(err, ==, 0);
+		test_ok += 1;
+	} else {
+		free(ev);
+		test_ok += 1;
+	}
+
+end:
+	;
+}
+static void
+test_fin_debug_use_after_free(void *arg)
+{
+	struct basic_test_data *data = arg;
+	struct event_base *base = data->base;
+	struct event *ev;
+
+	tt_ptr_op(ev = event_new(base, -1, EV_TIMEOUT, NULL, base), !=, NULL);
+	tt_int_op(event_add(ev, NULL), ==, 0);
+	tt_int_op(event_finalize(0, ev, event_finalize_callback_free), ==, 0);
+
+	// Dispatch base to trigger callbacks
+	event_base_dispatch(base);
+	event_base_assert_ok_(base);
+	tt_int_op(test_ok, ==, 1);
+
+	// Now add again, since we did event_assign in event_finalize_callback_free
+	// This used to fail in event_debug_assert_is_setup_
+	tt_int_op(event_add(ev, NULL), ==, 0);
+
+	// Finalize and dispatch again
+	tt_int_op(event_finalize(0, ev, event_finalize_callback_free), ==, 0);
+	event_base_dispatch(base);
+	event_base_assert_ok_(base);
+	tt_int_op(test_ok, ==, 2);
+
+end:
+	;
+}
+
 #if 0
 static void
 timer_callback_3(evutil_socket_t *fd, short what, void *arg)
@@ -339,6 +386,7 @@
 	TEST(cb_invoked, TT_FORK|TT_NEED_BASE),
 	TEST(free_finalize, TT_FORK),
 	TEST(within_cb, TT_FORK|TT_NEED_BASE),
+	TEST(debug_use_after_free, TT_FORK|TT_NEED_BASE|TT_ENABLE_DEBUG_MODE),
 //	TEST(many, TT_FORK|TT_NEED_BASE),
 
 
diff --git a/test/regress_http.c b/test/regress_http.c
index 8f30b57..4493907 100644
--- a/test/regress_http.c
+++ b/test/regress_http.c
@@ -66,6 +66,8 @@
 #include "regress.h"
 #include "regress_testutils.h"
 
+#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
+
 /* set if a test needs to call loopexit on a base */
 static struct event_base *exit_base;
 
@@ -230,6 +232,8 @@
 		return -1;
 
 	d = evbuffer_pullup(buf, s_sz);
+	if (!d)
+		d = (unsigned char *)"";
 	if ((r = memcmp(d, s, s_sz)))
 		return r;
 
@@ -457,9 +461,9 @@
 }
 
 static struct bufferevent *
-create_bev(struct event_base *base, evutil_socket_t fd, int ssl_mask)
+create_bev(struct event_base *base, evutil_socket_t fd, int ssl_mask, int flags_)
 {
-	int flags = BEV_OPT_DEFER_CALLBACKS;
+	int flags = BEV_OPT_DEFER_CALLBACKS | flags_;
 	struct bufferevent *bev = NULL;
 
 	if (!ssl_mask) {
@@ -522,7 +526,7 @@
 	fd = http_connect("127.0.0.1", port);
 
 	/* Stupid thing to send a request */
-	bev = create_bev(data->base, fd, ssl);
+	bev = create_bev(data->base, fd, ssl, BEV_OPT_CLOSE_ON_FREE);
 	bufferevent_setcb(bev, http_readcb, http_half_writecb,
 	    http_errorcb, data->base);
 	out = bufferevent_get_output(bev);
@@ -538,12 +542,11 @@
 
 	/* connect to the second port */
 	bufferevent_free(bev);
-	evutil_closesocket(fd);
 
 	fd = http_connect("127.0.0.1", port2);
 
 	/* Stupid thing to send a request */
-	bev = create_bev(data->base, fd, ssl);
+	bev = create_bev(data->base, fd, ssl, BEV_OPT_CLOSE_ON_FREE);
 	bufferevent_setcb(bev, http_readcb, http_writecb,
 	    http_errorcb, data->base);
 	out = bufferevent_get_output(bev);
@@ -560,12 +563,11 @@
 
 	/* Connect to the second port again. This time, send an absolute uri. */
 	bufferevent_free(bev);
-	evutil_closesocket(fd);
 
 	fd = http_connect("127.0.0.1", port2);
 
 	/* Stupid thing to send a request */
-	bev = create_bev(data->base, fd, ssl);
+	bev = create_bev(data->base, fd, ssl, BEV_OPT_CLOSE_ON_FREE);
 	bufferevent_setcb(bev, http_readcb, http_writecb,
 	    http_errorcb, data->base);
 
@@ -1283,6 +1285,7 @@
 	struct evhttp_connection *evcon = NULL;
 	struct evhttp_request *req[2] = { NULL };
 	struct evhttp *http = http_setup(&port, data->base, 0);
+	size_t i;
 
 	test_ok = 0;
 
@@ -1297,19 +1300,14 @@
 	req[1] = evhttp_request_new(http_request_empty_done, data->base);
 
 	/* Add the information that we care about */
-	evhttp_add_header(evhttp_request_get_output_headers(req[0]), "Host", "somehost");
-	evhttp_add_header(evhttp_request_get_output_headers(req[0]), "Connection", "close");
-	evhttp_add_header(evhttp_request_get_output_headers(req[0]), "Empty", "itis");
-	evhttp_add_header(evhttp_request_get_output_headers(req[1]), "Host", "somehost");
-	evhttp_add_header(evhttp_request_get_output_headers(req[1]), "Connection", "close");
-	evhttp_add_header(evhttp_request_get_output_headers(req[1]), "Empty", "itis");
+	for (i = 0; i < ARRAY_SIZE(req); ++i) {
+		evhttp_add_header(evhttp_request_get_output_headers(req[i]), "Host", "somehost");
+		evhttp_add_header(evhttp_request_get_output_headers(req[i]), "Connection", "close");
+		evhttp_add_header(evhttp_request_get_output_headers(req[i]), "Empty", "itis");
 
-	/* We give ownership of the request to the connection */
-	if (evhttp_make_request(evcon, req[0], EVHTTP_REQ_GET, "/test") == -1) {
-		tt_abort_msg("couldn't make request");
-	}
-	if (evhttp_make_request(evcon, req[1], EVHTTP_REQ_GET, "/test") == -1) {
-		tt_abort_msg("couldn't make request");
+		if (evhttp_make_request(evcon, req[i], EVHTTP_REQ_GET, "/test") == -1) {
+			tt_abort_msg("couldn't make request");
+		}
 	}
 
 	/*
@@ -1320,7 +1318,8 @@
 	evhttp_connection_free_on_completion(evcon);
 	evcon = NULL;
 
-	event_base_dispatch(data->base);
+	for (i = 0; i < ARRAY_SIZE(req); ++i)
+		event_base_dispatch(data->base);
 
 	/* at this point, the http server should have no connection */
 	tt_assert(TAILQ_FIRST(&http->connections) == NULL);
@@ -3119,7 +3118,7 @@
 	tt_assert(fd != EVUTIL_INVALID_SOCKET);
 
 	/* Stupid thing to send a request */
-	bev = create_bev(data->base, fd, ssl);
+	bev = create_bev(data->base, fd, ssl, 0);
 	bufferevent_setcb(bev,
 	    http_incomplete_readcb, http_incomplete_writecb,
 	    http_incomplete_errorcb, use_timeout ? NULL : &fd);
@@ -3319,7 +3318,7 @@
 http_chunk_out_test_impl(void *arg, int ssl)
 {
 	struct basic_test_data *data = arg;
-	struct bufferevent *bev;
+	struct bufferevent *bev = NULL;
 	evutil_socket_t fd;
 	const char *http_request;
 	ev_uint16_t port = 0;
@@ -3336,7 +3335,7 @@
 	tt_assert(fd != EVUTIL_INVALID_SOCKET);
 
 	/* Stupid thing to send a request */
-	bev = create_bev(data->base, fd, ssl);
+	bev = create_bev(data->base, fd, ssl, BEV_OPT_CLOSE_ON_FREE);
 	bufferevent_setcb(bev,
 	    http_chunked_readcb, http_chunked_writecb,
 	    http_chunked_errorcb, data->base);
@@ -3354,6 +3353,7 @@
 	event_base_dispatch(data->base);
 
 	bufferevent_free(bev);
+	bev = NULL;
 
 	evutil_gettimeofday(&tv_end, NULL);
 	evutil_timersub(&tv_end, &tv_start, &tv_end);
@@ -3363,7 +3363,7 @@
 	tt_int_op(test_ok, ==, 2);
 
 	/* now try again with the regular connection object */
-	bev = create_bev(data->base, -1, ssl);
+	bev = create_bev(data->base, -1, ssl, BEV_OPT_CLOSE_ON_FREE);
 	evcon = evhttp_connection_base_bufferevent_new(
 		data->base, NULL, bev, "127.0.0.1", port);
 	tt_assert(evcon);
@@ -3371,14 +3371,13 @@
 	/* make two requests to check the keepalive behavior */
 	for (i = 0; i < 2; i++) {
 		test_ok = 0;
-		req = evhttp_request_new(http_chunked_request_done,data->base);
+		req = evhttp_request_new(http_chunked_request_done, data->base);
 
 		/* Add the information that we care about */
 		evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
 
 		/* We give ownership of the request to the connection */
-		if (evhttp_make_request(evcon, req,
-			EVHTTP_REQ_GET, "/chunked") == -1) {
+		if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/chunked") == -1) {
 			tt_abort_msg("Couldn't make request");
 		}
 
@@ -3409,7 +3408,7 @@
 	test_ok = 0;
 	exit_base = data->base;
 
-	bev = create_bev(data->base, -1, ssl);
+	bev = create_bev(data->base, -1, ssl, 0);
 	evcon = evhttp_connection_base_bufferevent_new(
 		data->base, NULL, bev, "127.0.0.1", port);
 	tt_assert(evcon);
@@ -3609,7 +3608,7 @@
 	/* auto detect a port */
 	evhttp_free(http);
 
-	bev = create_bev(data->base, -1, ssl);
+	bev = create_bev(data->base, -1, ssl, 0);
 	/* Pick an unroutable address. This administratively scoped multicast
 	 * address should do when working with TCP. */
 	evcon = evhttp_connection_base_bufferevent_new(
@@ -3681,7 +3680,7 @@
 	exit_base = data->base;
 	test_ok = 0;
 
-	bev = create_bev(data->base, -1, ssl);
+	bev = create_bev(data->base, -1, ssl, 0);
 #ifdef EVENT__HAVE_OPENSSL
 	bufferevent_openssl_set_allow_dirty_shutdown(bev, dirty);
 #endif
@@ -3728,7 +3727,7 @@
 	/* auto detect a port */
 	evhttp_free(http);
 
-	bev = create_bev(data->base, -1, ssl);
+	bev = create_bev(data->base, -1, ssl, 0);
 	evcon = evhttp_connection_base_bufferevent_new(data->base, dns_base, bev, addr, hs.port);
 	tt_assert(evcon);
 	if (dns_base)
@@ -4516,7 +4515,7 @@
 
 	fd = http_connect("127.0.0.1", port);
 	tt_assert(fd != EVUTIL_INVALID_SOCKET);
-	bev = create_bev(data->base, fd, 0);
+	bev = create_bev(data->base, fd, 0, 0);
 	bufferevent_setcb(bev, NULL, NULL, NULL, data->base);
 	bufferevent_disable(bev, EV_READ);
 
@@ -4588,7 +4587,7 @@
 	tt_assert(fd != EVUTIL_INVALID_SOCKET);
 
 	/* Stupid thing to send a request */
-	bev = create_bev(base, fd, 0);
+	bev = create_bev(base, fd, 0, 0);
 	bufferevent_setcb(bev, http_readcb, http_writecb,
 	    http_errorcb, base);
 	out = bufferevent_get_output(bev);
diff --git a/test/regress_main.c b/test/regress_main.c
index c937282..2665612 100644
--- a/test/regress_main.c
+++ b/test/regress_main.c
@@ -33,6 +33,14 @@
 #include <fcntl.h>
 #endif
 
+/* move_pthread_to_realtime_scheduling_class() */
+#ifdef EVENT__HAVE_MACH_MACH_H
+#include <mach/mach.h>
+#endif
+#ifdef EVENT__HAVE_MACH_MACH_TIME_H
+#include <mach/mach_time.h>
+#endif
+
 #if defined(__APPLE__) && defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
 #if (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1060 && \
     __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1070)
@@ -81,10 +89,12 @@
 
 #include "event2/event-config.h"
 #include "regress.h"
+#include "regress_thread.h"
 #include "tinytest.h"
 #include "tinytest_macros.h"
 #include "../iocp-internal.h"
 #include "../event-internal.h"
+#include "../evthread-internal.h"
 
 struct evutil_weakrand_state test_weakrand_state;
 
@@ -186,6 +196,45 @@
 {
 }
 
+/**
+ * Put into the real time scheduling class for better timers latency.
+ * https://developer.apple.com/library/archive/technotes/tn2169/_index.html#//apple_ref/doc/uid/DTS40013172-CH1-TNTAG6000
+ */
+#if defined(__APPLE__)
+static void move_pthread_to_realtime_scheduling_class(pthread_t pthread)
+{
+	mach_timebase_info_data_t info;
+	mach_timebase_info(&info);
+
+	const uint64_t NANOS_PER_MSEC = 1000000ULL;
+	double clock2abs =
+		((double)info.denom / (double)info.numer) * NANOS_PER_MSEC;
+
+	thread_time_constraint_policy_data_t policy;
+	policy.period      = 0;
+	policy.computation = (uint32_t)(5 * clock2abs); // 5 ms of work
+	policy.constraint  = (uint32_t)(10 * clock2abs);
+	policy.preemptible = FALSE;
+
+	int kr = thread_policy_set(pthread_mach_thread_np(pthread),
+		THREAD_TIME_CONSTRAINT_POLICY,
+		(thread_policy_t)&policy,
+		THREAD_TIME_CONSTRAINT_POLICY_COUNT);
+	if (kr != KERN_SUCCESS) {
+		mach_error("thread_policy_set:", kr);
+		exit(1);
+	}
+}
+
+void thread_setup(THREAD_T pthread)
+{
+	move_pthread_to_realtime_scheduling_class(pthread);
+}
+#else /** \__APPLE__ */
+void thread_setup(THREAD_T pthread) {}
+#endif /** \!__APPLE__ */
+
+
 void *
 basic_test_setup(const struct testcase_t *testcase)
 {
@@ -193,11 +242,19 @@
 	evutil_socket_t spair[2] = { -1, -1 };
 	struct basic_test_data *data = NULL;
 
+	thread_setup(THREAD_SELF());
+
 #ifndef _WIN32
 	if (testcase->flags & TT_ENABLE_IOCP_FLAG)
 		return (void*)TT_SKIP;
 #endif
 
+	if (testcase->flags & TT_ENABLE_DEBUG_MODE &&
+		!libevent_tests_running_in_debug_mode) {
+		event_enable_debug_mode();
+		libevent_tests_running_in_debug_mode = 1;
+	}
+
 	if (testcase->flags & TT_NEED_THREADS) {
 		if (!(testcase->flags & TT_FORK))
 			return NULL;
diff --git a/test/regress_ssl.c b/test/regress_ssl.c
index 68c2811..37dc334 100644
--- a/test/regress_ssl.c
+++ b/test/regress_ssl.c
@@ -148,9 +148,9 @@
 	X509_set_issuer_name(x509, name);
 	X509_NAME_free(name);
 
-	X509_time_adj(X509_get_notBefore(x509), 0, &now);
+	X509_time_adj(X509_getm_notBefore(x509), 0, &now);
 	now += 3600;
-	X509_time_adj(X509_get_notAfter(x509), 0, &now);
+	X509_time_adj(X509_getm_notAfter(x509), 0, &now);
 	X509_set_pubkey(x509, key);
 	tt_assert(0 != X509_sign(x509, key, EVP_sha1()));
 
@@ -469,8 +469,8 @@
 	type = (enum regress_openssl_type)data->setup_data;
 
 	if (type & REGRESS_OPENSSL_RENEGOTIATE) {
-		if (SSLeay() >= 0x10001000 &&
-		    SSLeay() <  0x1000104f) {
+		if (OPENSSL_VERSION_NUMBER >= 0x10001000 &&
+		    OPENSSL_VERSION_NUMBER <  0x1000104f) {
 			/* 1.0.1 up to 1.0.1c has a bug where TLS1.1 and 1.2
 			 * can't renegotiate with themselves. Disable. */
 			disable_tls_11_and_12 = 1;
@@ -974,6 +974,7 @@
 
 	tt_int_op(client.get, ==, client.limit);
 	tt_int_op(server.get, ==, server.limit);
+
 end:
 	free(payload);
 	evbuffer_free(client.data);
@@ -981,6 +982,10 @@
 	evconnlistener_free(listener);
 	bufferevent_free(client.bev);
 	bufferevent_free(server.bev);
+
+	/* XXX: by some reason otherise there is a leak */
+	if (!(type & REGRESS_OPENSSL_FILTER))
+		event_base_loop(base, EVLOOP_ONCE);
 }
 
 struct testcase_t ssl_testcases[] = {
diff --git a/test/regress_testutils.c b/test/regress_testutils.c
index 959347e..b0ce7db 100644
--- a/test/regress_testutils.c
+++ b/test/regress_testutils.c
@@ -110,7 +110,7 @@
 	memset(&my_addr, 0, sizeof(my_addr));
 	my_addr.sin_family = AF_INET;
 	my_addr.sin_port = htons(*portnum);
-	my_addr.sin_addr.s_addr = htonl(0x7f000001UL);
+	my_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
 	if (bind(sock, (struct sockaddr*)&my_addr, sizeof(my_addr)) < 0) {
 		evutil_closesocket(sock);
 		tt_abort_perror("bind");
diff --git a/test/regress_thread.h b/test/regress_thread.h
index db0d8d1..a954fef 100644
--- a/test/regress_thread.h
+++ b/test/regress_thread.h
@@ -27,23 +27,30 @@
 #ifndef REGRESS_THREAD_H_INCLUDED_
 #define REGRESS_THREAD_H_INCLUDED_
 
-#ifdef EVENT__HAVE_PTHREADS
+#if defined(_WIN32) /** _WIN32 */
+#define THREAD_T void * /* HANDLE */
+#define THREAD_FN unsigned __stdcall
+#define THREAD_RETURN() return (0)
+#define THREAD_SELF() GetCurrentThreadId()
+#define THREAD_START(threadvar, fn, arg) do {                         \
+	uintptr_t threadhandle = _beginthreadex(NULL,0,fn,(arg),0,NULL);  \
+	(threadvar) = (THREAD_T)threadhandle;                             \
+	thread_setup(threadvar);                                          \
+} while (0)
+#define THREAD_JOIN(th) WaitForSingleObject(th, INFINITE)
+#else /* !_WIN32 */
 #include <pthread.h>
 #define THREAD_T pthread_t
 #define THREAD_FN void *
 #define THREAD_RETURN() return (NULL)
-#define THREAD_START(threadvar, fn, arg) \
-	pthread_create(&(threadvar), NULL, fn, arg)
+#define THREAD_SELF() pthread_self()
+#define THREAD_START(threadvar, fn, arg) do {          \
+	if (!pthread_create(&(threadvar), NULL, fn, arg))  \
+		thread_setup(threadvar);                       \
+} while (0)
 #define THREAD_JOIN(th) pthread_join(th, NULL)
-#else
-#define THREAD_T HANDLE
-#define THREAD_FN unsigned __stdcall
-#define THREAD_RETURN() return (0)
-#define THREAD_START(threadvar, fn, arg) do {		\
-	uintptr_t threadhandle = _beginthreadex(NULL,0,fn,(arg),0,NULL); \
-	(threadvar) = (HANDLE) threadhandle; \
-	} while (0)
-#define THREAD_JOIN(th) WaitForSingleObject(th, INFINITE)
-#endif
+#endif /* \!_WIN32 */
+
+void thread_setup(THREAD_T pthread);
 
 #endif
diff --git a/test/regress_util.c b/test/regress_util.c
index 3da2070..45caa27 100644
--- a/test/regress_util.c
+++ b/test/regress_util.c
@@ -211,6 +211,65 @@
 #endif
 }
 
+static struct ipv6_entry_scope {
+	const char *addr;
+	ev_uint32_t res[4];
+	unsigned scope;
+	enum entry_status status;
+} ipv6_entries_scope[] = {
+	{ "2001:DB8::", { 0x20010db8, 0, 0 }, 0, NORMAL },
+	{ "2001:DB8::%0", { 0x20010db8, 0, 0, 0 }, 0, NORMAL },
+	{ "2001:DB8::%1", { 0x20010db8, 0, 0, 0 }, 1, NORMAL },
+	{ "foobar.", { 0, 0, 0, 0 }, 0, BAD },
+	{ "2001:DB8::%does-not-exist", { 0, 0, 0, 0 }, 0, BAD },
+	{ NULL, { 0, 0, 0, 0,  }, 0, BAD },
+};
+static void
+regress_ipv6_parse_scope(void *ptr)
+{
+#ifdef AF_INET6
+	int i, j;
+	unsigned if_scope;
+
+	for (i = 0; ipv6_entries_scope[i].addr; ++i) {
+		struct ipv6_entry_scope *ent = &ipv6_entries_scope[i];
+		struct in6_addr in6;
+		int r;
+		r = evutil_inet_pton_scope(AF_INET6, ent->addr, &in6,
+			&if_scope);
+		if (r == 0) {
+			if (ent->status != BAD)
+				TT_FAIL(("%s did not parse, but it's a good address!",
+					ent->addr));
+			continue;
+		}
+		if (ent->status == BAD) {
+			TT_FAIL(("%s parsed, but we expected an error", ent->addr));
+			continue;
+		}
+		for (j = 0; j < 4; ++j) {
+			/* Can't use s6_addr32 here; some don't have it. */
+			ev_uint32_t u =
+			    ((ev_uint32_t)in6.s6_addr[j*4  ] << 24) |
+			    ((ev_uint32_t)in6.s6_addr[j*4+1] << 16) |
+			    ((ev_uint32_t)in6.s6_addr[j*4+2] << 8) |
+			    ((ev_uint32_t)in6.s6_addr[j*4+3]);
+			if (u != ent->res[j]) {
+				TT_FAIL(("%s did not parse as expected.", ent->addr));
+				continue;
+			}
+		}
+		if (if_scope != ent->scope) {
+			TT_FAIL(("%s did not parse as expected.", ent->addr));
+			continue;
+		}
+	}
+#else
+	TT_BLATHER(("Skipping IPv6 address parsing."));
+#endif
+}
+
+
 static struct sa_port_ent {
 	const char *parse;
 	int safamily;
@@ -926,6 +985,16 @@
 }
 
 static void
+test_EVUTIL_IS_(void *arg)
+{
+	tt_int_op(EVUTIL_ISDIGIT_('0'), ==, 1);
+	tt_int_op(EVUTIL_ISDIGIT_('a'), ==, 0);
+	tt_int_op(EVUTIL_ISDIGIT_('\xff'), ==, 0);
+end:
+	;
+}
+
+static void
 test_evutil_getaddrinfo(void *arg)
 {
 	struct evutil_addrinfo *ai = NULL, *a;
@@ -1121,6 +1190,41 @@
 		evutil_freeaddrinfo(ai);
 }
 
+static void
+test_evutil_getaddrinfo_AI_ADDRCONFIG(void *arg)
+{
+	struct evutil_addrinfo *ai = NULL;
+	struct evutil_addrinfo hints;
+	int r;
+
+	memset(&hints, 0, sizeof(hints));
+	hints.ai_family = AF_UNSPEC;
+	hints.ai_socktype = SOCK_STREAM;
+	hints.ai_flags = EVUTIL_AI_PASSIVE|EVUTIL_AI_ADDRCONFIG;
+
+	/* IPv4 */
+	r = evutil_getaddrinfo("127.0.0.1", "80", &hints, &ai);
+	tt_int_op(r, ==, 0);
+	tt_assert(ai);
+	tt_ptr_op(ai->ai_next, ==, NULL);
+	test_ai_eq(ai, "127.0.0.1:80", SOCK_STREAM, IPPROTO_TCP);
+	evutil_freeaddrinfo(ai);
+	ai = NULL;
+
+	/* IPv6 */
+	r = evutil_getaddrinfo("::1", "80", &hints, &ai);
+	tt_int_op(r, ==, 0);
+	tt_assert(ai);
+	tt_ptr_op(ai->ai_next, ==, NULL);
+	test_ai_eq(ai, "[::1]:80", SOCK_STREAM, IPPROTO_TCP);
+	evutil_freeaddrinfo(ai);
+	ai = NULL;
+
+end:
+	if (ai)
+		evutil_freeaddrinfo(ai);
+}
+
 #ifdef _WIN32
 static void
 test_evutil_loadsyslib(void *arg)
@@ -1539,6 +1643,7 @@
 struct testcase_t util_testcases[] = {
 	{ "ipv4_parse", regress_ipv4_parse, 0, NULL, NULL },
 	{ "ipv6_parse", regress_ipv6_parse, 0, NULL, NULL },
+	{ "ipv6_parse_scope", regress_ipv6_parse_scope, 0, NULL, NULL },
 	{ "sockaddr_port_parse", regress_sockaddr_port_parse, 0, NULL, NULL },
 	{ "sockaddr_port_format", regress_sockaddr_port_format, 0, NULL, NULL },
 	{ "sockaddr_predicates", test_evutil_sockaddr_predicates, 0,NULL,NULL },
@@ -1551,8 +1656,10 @@
 	{ "upcast", test_evutil_upcast, 0, NULL, NULL },
 	{ "integers", test_evutil_integers, 0, NULL, NULL },
 	{ "rand", test_evutil_rand, TT_FORK, NULL, NULL },
+	{ "EVUTIL_IS_", test_EVUTIL_IS_, 0, NULL, NULL },
 	{ "getaddrinfo", test_evutil_getaddrinfo, TT_FORK, NULL, NULL },
 	{ "getaddrinfo_live", test_evutil_getaddrinfo_live, TT_FORK|TT_OFF_BY_DEFAULT, NULL, NULL },
+	{ "getaddrinfo_AI_ADDRCONFIG", test_evutil_getaddrinfo_AI_ADDRCONFIG, TT_FORK|TT_OFF_BY_DEFAULT, NULL, NULL },
 #ifdef _WIN32
 	{ "loadsyslib", test_evutil_loadsyslib, TT_FORK, NULL, NULL },
 #endif
diff --git a/test/test-changelist.c b/test/test-changelist.c
index 6e2466d..fd1a17f 100644
--- a/test/test-changelist.c
+++ b/test/test-changelist.c
@@ -182,11 +182,11 @@
 	if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
 		return (1);
 
-	/* Initalize the event library */
+	/* Initialize the event library */
 	if (!(base = event_base_new()))
 		return (1);
 
-	/* Initalize a timeout to terminate the test */
+	/* Initialize a timeout to terminate the test */
 	timeout = evtimer_new(base,timeout_cb,&timeout);
 	/* and watch for writability on one end of the pipe */
 	ev = event_new(base,pair[1],EV_WRITE | EV_PERSIST, write_cb, &ev);
diff --git a/test/test-closed.c b/test/test-closed.c
index 1dd9885..9e60504 100644
--- a/test/test-closed.c
+++ b/test/test-closed.c
@@ -104,6 +104,7 @@
 	event_base_dispatch(base);
 
 	/* Finalize library */
+	event_free(ev);
 	event_base_free(base);
 	return 0;
 }
diff --git a/test/test-eof.c b/test/test-eof.c
index 284ead7..de2fd88 100644
--- a/test/test-eof.c
+++ b/test/test-eof.c
@@ -102,10 +102,10 @@
 		return (1);
 	shutdown(pair[0], EVUTIL_SHUT_WR);
 
-	/* Initalize the event library */
+	/* Initialize the event library */
 	event_init();
 
-	/* Initalize one event */
+	/* Initialize one event */
 	event_set(&ev, pair[1], EV_READ | EV_TIMEOUT, read_cb, &ev);
 
 	event_add(&ev, &timeout);
diff --git a/test/test-init.c b/test/test-init.c
index 92fbc6b..aea49ee 100644
--- a/test/test-init.c
+++ b/test/test-init.c
@@ -57,7 +57,7 @@
 	(void) WSAStartup(wVersionRequested, &wsaData);
 #endif
 
-	/* Initalize the event library */
+	/* Initialize the event library */
 	event_init();
 
 	return (0);
diff --git a/test/test-ratelim.c b/test/test-ratelim.c
index 9ee989b..34112e3 100644
--- a/test/test-ratelim.c
+++ b/test/test-ratelim.c
@@ -50,6 +50,10 @@
 #include "event2/listener.h"
 #include "event2/thread.h"
 
+#ifndef MIN
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#endif
+
 static struct evutil_weakrand_state weakrand_state;
 
 static int cfg_verbose = 0;
@@ -85,6 +89,18 @@
 };
 static const struct timeval *ms100_common=NULL;
 
+/* Timers bias for slow CPUs, affects:
+ * - cfg_connlimit_tolerance  (--check-connlimit)
+ * - cfg_grouplimit_tolerance (--check-grouplimit)
+ * - cfg_stddev_tolerance     (--check-stddev)
+ */
+static int timer_bias_events;
+static struct timeval timer_bias_start;
+double timer_bias_spend;
+/* Real cost is less (approximately ~5 usec),
+ * this macros adjusted to make the bias less */
+#define TIMER_MAX_COST_USEC 10
+
 /* info from check_bucket_levels_cb */
 static int total_n_bev_checks = 0;
 static ev_int64_t total_rbucket_level=0;
@@ -244,6 +260,64 @@
 	bufferevent_rate_limit_group_decrement_write(ratelim_group, cfg_group_drain);
 }
 
+static void
+timer_bias_cb(evutil_socket_t fd, short events, void *arg)
+{
+	struct event *event = arg;
+	struct timeval end;
+	struct timeval diff;
+
+	/** XXX: use rdtsc? (portability issues?) */
+	evutil_gettimeofday(&end, NULL);
+	evutil_timersub(&end, &timer_bias_start, &diff);
+	timer_bias_spend += diff.tv_sec + diff.tv_usec * 1e6;
+	timer_bias_start = end;
+
+	if (++timer_bias_events == 100)
+		event_del(event);
+}
+static double
+timer_bias_calculate(void)
+{
+	struct event_config *cfg = NULL;
+	struct event_base *base = NULL;
+	struct event *timer = NULL;
+	struct timeval tv = { 0, 1 };
+	int done = 0;
+
+	cfg = event_config_new();
+	if (!cfg)
+		goto err;
+	if (event_config_set_flag(cfg, EVENT_BASE_FLAG_PRECISE_TIMER))
+		goto err;
+	base = event_base_new_with_config(cfg);
+	if (!base)
+		goto err;
+
+	timer = event_new(base, -1, EV_PERSIST, timer_bias_cb, event_self_cbarg());
+	if (!timer || event_add(timer, &tv)) {
+		goto err;
+	}
+
+	evutil_gettimeofday(&timer_bias_start, NULL);
+	event_base_dispatch(base);
+	done = 1;
+
+err:
+	if (cfg)
+		event_config_free(cfg);
+	if (timer)
+		event_free(timer);
+	if (base)
+		event_base_free(base);
+
+	if (done)
+		return MIN(timer_bias_spend / 1e6 / timer_bias_events / TIMER_MAX_COST_USEC, 5);
+
+	fprintf(stderr, "Couldn't create event for CPU cycle counter bias\n");
+	return -1;
+}
+
 static int
 test_ratelimiting(void)
 {
@@ -266,6 +340,7 @@
 	struct event_config *base_cfg;
 	struct event *periodic_level_check;
 	struct event *group_drain_event=NULL;
+	double timer_bias;
 
 	memset(&sin, 0, sizeof(sin));
 	sin.sin_family = AF_INET;
@@ -275,6 +350,16 @@
 	if (0)
 		event_enable_debug_mode();
 
+	timer_bias = timer_bias_calculate();
+	if (timer_bias > 1) {
+		fprintf(stderr, "CPU is slow, timers bias is %f\n", timer_bias);
+		cfg_connlimit_tolerance  *= timer_bias;
+		cfg_grouplimit_tolerance *= timer_bias;
+		cfg_stddev_tolerance     *= timer_bias;
+	} else {
+		printf("CPU is fast enough, timers bias is %f\n", timer_bias);
+	}
+
 	base_cfg = event_config_new();
 
 #ifdef _WIN32
@@ -376,7 +461,7 @@
 	ratelim_group = NULL; /* So no more responders get added */
 	event_free(periodic_level_check);
 	if (group_drain_event)
-		event_del(group_drain_event);
+		event_free(group_drain_event);
 
 	for (i = 0; i < cfg_n_connections; ++i) {
 		bufferevent_free(bevs[i]);
diff --git a/test/test-time.c b/test/test-time.c
index c4d031e..a8b3846 100644
--- a/test/test-time.c
+++ b/test/test-time.c
@@ -81,8 +81,10 @@
 int
 main(int argc, char **argv)
 {
+	struct event_base *base;
 	struct timeval tv;
 	int i;
+
 #ifdef _WIN32
 	WORD wVersionRequested;
 	WSADATA wsaData;
@@ -94,23 +96,28 @@
 
 	evutil_weakrand_seed_(&weakrand_state, 0);
 
-	/* Initalize the event library */
-	event_init();
+	if (getenv("EVENT_DEBUG_LOGGING_ALL")) {
+		event_enable_debug_logging(EVENT_DBG_ALL);
+	}
+
+	base = event_base_new();
 
 	for (i = 0; i < NEVENT; i++) {
-		ev[i] = malloc(sizeof(struct event));
-
-		/* Initalize one event */
-		evtimer_set(ev[i], time_cb, ev[i]);
+		ev[i] = evtimer_new(base, time_cb, event_self_cbarg());
 		tv.tv_sec = 0;
 		tv.tv_usec = rand_int(50000);
 		evtimer_add(ev[i], &tv);
 	}
 
-	event_dispatch();
+	i = event_base_dispatch(base);
 
+	printf("event_base_dispatch=%d, called=%d, EVENT=%d\n",
+		i, called, NEVENT);
 
-	printf("%d, %d\n", called, NEVENT);
-	return (called < NEVENT);
+	if (i == 1 && called >= NEVENT) {
+		return EXIT_SUCCESS;
+	} else {
+		return EXIT_FAILURE;
+	}
 }
 
diff --git a/test/test-weof.c b/test/test-weof.c
index 52c7afb..68e7cd4 100644
--- a/test/test-weof.c
+++ b/test/test-weof.c
@@ -99,10 +99,10 @@
 	if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
 		return (1);
 
-	/* Initalize the event library */
+	/* Initialize the event library */
 	event_init();
 
-	/* Initalize one event */
+	/* Initialize one event */
 	event_set(&ev, pair[1], EV_WRITE, write_cb, &ev);
 
 	event_add(&ev, NULL);
diff --git a/test/tinytest.c b/test/tinytest.c
index a94fb9d..85dfe74 100644
--- a/test/tinytest.c
+++ b/test/tinytest.c
@@ -60,12 +60,8 @@
 #include "tinytest_macros.h"
 
 #define LONGEST_TEST_NAME 16384
-
-#ifndef _WIN32
 #define DEFAULT_TESTCASE_TIMEOUT 30U
-#else
-#define DEFAULT_TESTCASE_TIMEOUT 0U
-#endif
+#define MAGIC_EXITCODE 42
 
 static int in_tinytest_main = 0; /**< true if we're in tinytest_main().*/
 static int n_ok = 0; /**< Number of tests that have passed */
@@ -86,33 +82,73 @@
 /** Name of the current test, if we haven't logged is yet. Used for --quiet */
 const char *cur_test_name = NULL;
 
+static void usage(struct testgroup_t *groups, int list_groups)
+	__attribute__((noreturn));
+static int process_test_option(struct testgroup_t *groups, const char *test);
+
 #ifdef _WIN32
 /* Copy of argv[0] for win32. */
 static char commandname[MAX_PATH+1];
-#endif
 
-static void usage(struct testgroup_t *groups, int list_groups)
-  __attribute__((noreturn));
-static int process_test_option(struct testgroup_t *groups, const char *test);
+struct timeout_thread_args {
+	const testcase_fn *fn;
+	void *env;
+};
 
+static DWORD WINAPI
+timeout_thread_proc_(LPVOID arg)
+{
+	struct timeout_thread_args *args = arg;
+	(*(args->fn))(args->env);
+	ExitThread(cur_test_outcome == FAIL ? 1 : 0);
+}
+
+static enum outcome
+testcase_run_in_thread_(const struct testcase_t *testcase, void *env)
+{
+	/* We will never run testcase in a new thread when the
+	timeout is set to zero */
+	assert(opt_timeout);
+	DWORD ret, tid;
+	HANDLE handle;
+	struct timeout_thread_args args = {
+		&(testcase->fn),
+		env
+	};
+
+	handle =CreateThread(NULL, 0, timeout_thread_proc_,
+		(LPVOID)&args, 0, &tid);
+	ret = WaitForSingleObject(handle, opt_timeout * 1000U);
+	if (ret == WAIT_OBJECT_0) {
+		ret = 0;
+		if (!GetExitCodeThread(handle, &ret)) {
+			printf("GetExitCodeThread failed\n");
+			ret = 1;
+		}
+	} else if (ret == WAIT_TIMEOUT)	{
+		printf("timeout\n");
+	} else {
+		printf("Wait failed\n");
+	}
+	CloseHandle(handle);
+	if (ret == 0)
+		return OK;
+	else if (ret == MAGIC_EXITCODE)
+		return SKIP;
+	else
+		return FAIL;
+}
+#else
 static unsigned int testcase_set_timeout_(void)
 {
-	if (!opt_timeout)
-		return 0;
-#ifndef _WIN32
 	return alarm(opt_timeout);
-#else
-	/** TODO: win32 support */
-	fprintf(stderr, "You cannot set alarm on windows\n");
-	exit(1);
-#endif
 }
+
 static unsigned int testcase_reset_timeout_(void)
 {
-#ifndef _WIN32
 	return alarm(0);
-#endif
 }
+#endif
 
 static enum outcome
 testcase_run_bare_(const struct testcase_t *testcase)
@@ -129,9 +165,17 @@
 
 	cur_test_outcome = OK;
 	{
-		testcase_set_timeout_();
-		testcase->fn(env);
-		testcase_reset_timeout_();
+		if (opt_timeout) {
+#ifdef _WIN32
+			cur_test_outcome = testcase_run_in_thread_(testcase, env);
+#else
+			testcase_set_timeout_();
+			testcase->fn(env);
+			testcase_reset_timeout_();
+#endif
+		} else {
+			testcase->fn(env);
+		}
 	}
 	outcome = cur_test_outcome;
 
@@ -143,7 +187,6 @@
 	return outcome;
 }
 
-#define MAGIC_EXITCODE 42
 
 #ifndef NO_FORKING
 
@@ -164,7 +207,7 @@
 	char buffer[LONGEST_TEST_NAME+256];
 	STARTUPINFOA si;
 	PROCESS_INFORMATION info;
-	DWORD exitcode;
+	DWORD ret;
 
 	if (!in_tinytest_main) {
 		printf("\nERROR.  On Windows, testcase_run_forked_ must be"
@@ -174,7 +217,7 @@
 	if (opt_verbosity>0)
 		printf("[forking] ");
 
-	snprintf(buffer, sizeof(buffer), "%s --RUNNING-FORKED %s %s%s",
+	snprintf(buffer, sizeof(buffer), "%s --RUNNING-FORKED %s --timeout 0 %s%s",
 		 commandname, verbosity_flag, group->prefix, testcase->name);
 
 	memset(&si, 0, sizeof(si));
@@ -185,15 +228,23 @@
 			   0, NULL, NULL, &si, &info);
 	if (!ok) {
 		printf("CreateProcess failed!\n");
-		return 0;
+		return FAIL;
 	}
-	WaitForSingleObject(info.hProcess, INFINITE);
-	GetExitCodeProcess(info.hProcess, &exitcode);
+	ret = WaitForSingleObject(info.hProcess,
+		(opt_timeout ? opt_timeout * 1000U : INFINITE));
+
+	if (ret == WAIT_OBJECT_0) {
+		GetExitCodeProcess(info.hProcess, &ret);
+	} else if (ret == WAIT_TIMEOUT) {
+		printf("timeout\n");
+	} else {
+		printf("Wait failed\n");
+	}
 	CloseHandle(info.hProcess);
 	CloseHandle(info.hThread);
-	if (exitcode == 0)
+	if (ret == 0)
 		return OK;
-	else if (exitcode == MAGIC_EXITCODE)
+	else if (ret == MAGIC_EXITCODE)
 		return SKIP;
 	else
 		return FAIL;
@@ -228,7 +279,7 @@
 		return FAIL; /* unreachable */
 	} else {
 		/* parent */
-		int status, r;
+		int status, r, exitcode;
 		char b[1];
 		/* Close this now, so that if the other side closes it,
 		 * our read fails. */
@@ -236,12 +287,20 @@
 		r = (int)read(outcome_pipe[0], b, 1);
 		if (r == 0) {
 			printf("[Lost connection!] ");
-			return 0;
+			return FAIL;
 		} else if (r != 1) {
 			perror("read outcome from pipe");
 		}
 		waitpid(pid, &status, 0);
+		exitcode = WEXITSTATUS(status);
 		close(outcome_pipe[0]);
+		if (opt_verbosity>1)
+			printf("%s%s: exited with %i (%i)\n", group->prefix, testcase->name, exitcode, status);
+		if (exitcode != 0)
+		{
+			printf("[atexit failure!] ");
+			return FAIL;
+		}
 		return b[0]=='Y' ? OK : (b[0]=='S' ? SKIP : FAIL);
 	}
 #endif
@@ -520,7 +579,7 @@
 		printf("%s%s: ", cur_test_prefix, cur_test_name);
 		cur_test_name = NULL;
 	}
-	cur_test_outcome = 0;
+	cur_test_outcome = FAIL;
 }
 
 void
diff --git a/test/tinytest_macros.h b/test/tinytest_macros.h
index e34e74e..e01f5d5 100644
--- a/test/tinytest_macros.h
+++ b/test/tinytest_macros.h
@@ -113,8 +113,8 @@
 #define tt_assert_test_fmt_type(a,b,str_test,type,test,printf_type,printf_fmt, \
     setup_block,cleanup_block,die_on_fail)				\
 	TT_STMT_BEGIN							\
-	type val1_ = (a);						\
-	type val2_ = (b);						\
+	type val1_ = (type)(a);						\
+	type val2_ = (type)(b);						\
 	int tt_status_ = (test);					\
 	if (!tt_status_ || tinytest_get_verbosity_()>1)	{		\
 		printf_type print_;					\
diff --git a/win32select.c b/win32select.c
index 0ddfe4b..d005b58 100644
--- a/win32select.c
+++ b/win32select.c
@@ -352,7 +352,6 @@
 		}
 	}
 	if (win32op->writeset_out->fd_count) {
-		SOCKET s;
 		i = evutil_weakrand_range_(&base->weakrand_seed,
 		    win32op->writeset_out->fd_count);
 		for (j=0; j<win32op->writeset_out->fd_count; ++j) {