From 4f0f4bff5a92dce6a6cd7a5600a8ee5660402c3f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 10 Apr 2023 09:20:13 +0000 Subject: [PATCH] build: unify source lists - introduce `src/crypto.c` as an umbrella source that does nothing else than include the selected crypto backend source. Moving this job from the built-tool to the C preprocessor. - this allows dropping the various techniques to pick the correct crypto backend sources in autotools, CMake and other build method. Including the per-backend `Makefile..inc` makefiles. - copy a trick from curl and instead of maintaining duplicate source lists for CMake, convert the GNU Makefile kept for autotools automatically. Do this in `docs`, `examples` and `src`. Ref: https://github.com/curl/curl/blob/dfabe8bca218d2524af052bd551aa87e13b8a10b/CMakeLists.txt#L1399-L1413 Also fixes missing `libssh2_setup.h` from `src/CMakeFiles.txt` after 59666e03f04927e5fe3e8d8772d40729f63c570e. - move `Makefile.inc` from root to `src`. - reformat `src/Makefile.inc` to list each source in separate lines, re-align the continuation character and sort the lists alphabetically. - update `docs/HACKING-CRYPTO` accordingly. - autotools: update the way we add crypto-backends to `LIBS`. - delete old CSV headers, indent, and merge two lines in `docs/Makefile.am` and `src/Makefile.am`. - add `libssh2.pc` to `.gitignore`, while there. Closes #941 --- CMakeLists.txt | 18 ++-- Makefile.OpenSSL.inc | 3 - Makefile.WinCNG.inc | 3 - Makefile.am | 3 +- Makefile.inc | 9 -- Makefile.libgcrypt.inc | 3 - Makefile.mbedTLS.inc | 3 - Makefile.mk | 9 +- Makefile.os400qc3.inc | 2 - Makefile.wolfSSL.inc | 3 - NMakefile | 4 +- configure.ac | 14 +++- docs/.gitignore | 1 + docs/CMakeLists.txt | 184 +---------------------------------------- docs/HACKING-CRYPTO | 20 +++-- docs/Makefile.am | 4 +- example/.gitignore | 1 + example/CMakeLists.txt | 29 +------ os400/make-src.sh | 4 +- src/.gitignore | 2 + src/CMakeLists.txt | 46 ++--------- src/Makefile.am | 27 +----- src/Makefile.inc | 46 +++++++++++ src/crypto.c | 13 +++ 24 files changed, 124 insertions(+), 327 deletions(-) delete mode 100644 Makefile.OpenSSL.inc delete mode 100644 Makefile.WinCNG.inc delete mode 100644 Makefile.inc delete mode 100644 Makefile.libgcrypt.inc delete mode 100644 Makefile.mbedTLS.inc delete mode 100644 Makefile.os400qc3.inc delete mode 100644 Makefile.wolfSSL.inc create mode 100644 src/Makefile.inc create mode 100644 src/crypto.c diff --git a/CMakeLists.txt b/CMakeLists.txt index bd51aa89..ad2dcf8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -212,7 +212,6 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND) if(OPENSSL_FOUND) set(CRYPTO_BACKEND "OpenSSL") - set(CRYPTO_SOURCES openssl.c openssl.h) set(CRYPTO_BACKEND_DEFINE "LIBSSH2_OPENSSL") set(CRYPTO_BACKEND_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}) list(APPEND LIBRARIES ${OPENSSL_LIBRARIES}) @@ -274,7 +273,6 @@ if(CRYPTO_BACKEND STREQUAL "wolfSSL" OR NOT CRYPTO_BACKEND) if(WOLFSSL_FOUND) set(CRYPTO_BACKEND "wolfSSL") - set(CRYPTO_SOURCES openssl.c openssl.h) set(CRYPTO_BACKEND_DEFINE "LIBSSH2_WOLFSSL") set(CRYPTO_BACKEND_INCLUDE_DIR ${WOLFSSL_INCLUDE_DIR} ${WOLFSSL_INCLUDE_DIR}/wolfssl) list(APPEND LIBRARIES ${WOLFSSL_LIBRARIES}) @@ -302,7 +300,6 @@ if(CRYPTO_BACKEND STREQUAL "Libgcrypt" OR NOT CRYPTO_BACKEND) if(LIBGCRYPT_FOUND) set(CRYPTO_BACKEND "Libgcrypt") - set(CRYPTO_SOURCES libgcrypt.c libgcrypt.h) set(CRYPTO_BACKEND_DEFINE "LIBSSH2_LIBGCRYPT") set(CRYPTO_BACKEND_INCLUDE_DIR ${LIBGCRYPT_INCLUDE_DIRS}) list(APPEND LIBRARIES ${LIBGCRYPT_LIBRARIES}) @@ -316,7 +313,6 @@ if(CRYPTO_BACKEND STREQUAL "mbedTLS" OR NOT CRYPTO_BACKEND) if(MBEDTLS_FOUND) set(CRYPTO_BACKEND "mbedTLS") - set(CRYPTO_SOURCES mbedtls.c mbedtls.h) set(CRYPTO_BACKEND_DEFINE "LIBSSH2_MBEDTLS") set(CRYPTO_BACKEND_INCLUDE_DIR ${MBEDTLS_INCLUDE_DIR}) list(APPEND LIBRARIES ${MBEDTLS_LIBRARIES}) @@ -335,7 +331,6 @@ if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND) if(HAVE_BCRYPT_H) set(CRYPTO_BACKEND "WinCNG") - set(CRYPTO_SOURCES wincng.c wincng.h) set(CRYPTO_BACKEND_DEFINE "LIBSSH2_WINCNG") set(CRYPTO_BACKEND_INCLUDE_DIR "") @@ -346,6 +341,19 @@ if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND) endif() endif() +# Global functions + +# Convert GNU Make assignments into CMake ones. +function(transform_makefile_inc INPUT_FILE OUTPUT_FILE) + file(READ ${INPUT_FILE} MAKEFILE_INC_CMAKE) + + string(REGEX REPLACE "\\\\\n" "" MAKEFILE_INC_CMAKE ${MAKEFILE_INC_CMAKE}) + string(REGEX REPLACE "([A-Za-z_]+) *= *([^\n]*)" "set(\\1 \\2)" MAKEFILE_INC_CMAKE ${MAKEFILE_INC_CMAKE}) + + file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_CMAKE}) + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${INPUT_FILE}") +endfunction() + # add_subdirectory(src) diff --git a/Makefile.OpenSSL.inc b/Makefile.OpenSSL.inc deleted file mode 100644 index 1e4e8f0b..00000000 --- a/Makefile.OpenSSL.inc +++ /dev/null @@ -1,3 +0,0 @@ -CRYPTO_CSOURCES = openssl.c -CRYPTO_HHEADERS = openssl.h -CRYPTO_LTLIBS = $(LTLIBSSL) diff --git a/Makefile.WinCNG.inc b/Makefile.WinCNG.inc deleted file mode 100644 index 09e41096..00000000 --- a/Makefile.WinCNG.inc +++ /dev/null @@ -1,3 +0,0 @@ -CRYPTO_CSOURCES = wincng.c -CRYPTO_HHEADERS = wincng.h -CRYPTO_LTLIBS = $(LTLIBBCRYPT) diff --git a/Makefile.am b/Makefile.am index 5caa0553..abbefd5c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -33,8 +33,7 @@ OS400FILES = os400/README400 os400/initscript.sh os400/make.sh \ os400/libssh2rpg/libssh2.rpgle.in \ os400/libssh2rpg/libssh2_ccsid.rpgle.in \ os400/libssh2rpg/libssh2_publickey.rpgle \ - os400/libssh2rpg/libssh2_sftp.rpgle \ - Makefile.os400qc3.inc + os400/libssh2rpg/libssh2_sftp.rpgle EXTRA_DIST = $(WIN32FILES) get_ver.awk \ maketgz RELEASE-NOTES libssh2.pc.in $(VMSFILES) config.rpath \ diff --git a/Makefile.inc b/Makefile.inc deleted file mode 100644 index 1f23e66f..00000000 --- a/Makefile.inc +++ /dev/null @@ -1,9 +0,0 @@ -CSOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c misc.c \ - packet.c publickey.c scp.c session.c sftp.c userauth.c transport.c \ - userauth_kbd_packet.c \ - version.c knownhost.c agent.c $(CRYPTO_CSOURCES) pem.c keepalive.c global.c \ - bcrypt_pbkdf.c agent_win.c os400qc3.c - -HHEADERS = libssh2_priv.h libssh2_setup.h $(CRYPTO_HHEADERS) transport.h \ - channel.h comp.h mac.h misc.h packet.h userauth.h session.h sftp.h crypto.h \ - agent.h userauth_kbd_packet.h os400qc3.h diff --git a/Makefile.libgcrypt.inc b/Makefile.libgcrypt.inc deleted file mode 100644 index 0a3aae9a..00000000 --- a/Makefile.libgcrypt.inc +++ /dev/null @@ -1,3 +0,0 @@ -CRYPTO_CSOURCES = libgcrypt.c -CRYPTO_HHEADERS = libgcrypt.h -CRYPTO_LTLIBS = $(LTLIBGCRYPT) diff --git a/Makefile.mbedTLS.inc b/Makefile.mbedTLS.inc deleted file mode 100644 index b9f19fce..00000000 --- a/Makefile.mbedTLS.inc +++ /dev/null @@ -1,3 +0,0 @@ -CRYPTO_CSOURCES = mbedtls.c -CRYPTO_HHEADERS = mbedtls.h -CRYPTO_LTLIBS = $(LTLIBMBEDCRYPTO) diff --git a/Makefile.mk b/Makefile.mk index 2cfd0a8d..3ce5059e 100644 --- a/Makefile.mk +++ b/Makefile.mk @@ -105,29 +105,24 @@ ifdef OPENSSL_PATH _LDFLAGS += -L"$(OPENSSL_LIBPATH)" OPENSSL_LIBS ?= -lssl -lcrypto _LIBS += $(OPENSSL_LIBS) - include Makefile.OpenSSL.inc else ifdef WOLFSSL_PATH CPPFLAGS += -DLIBSSH2_WOLFSSL CPPFLAGS += -I"$(WOLFSSL_PATH)/include" CPPFLAGS += -I"$(WOLFSSL_PATH)/include/wolfssl" _LDFLAGS += -L"$(WOLFSSL_PATH)/lib" _LIBS += -lwolfssl - include Makefile.wolfSSL.inc else ifdef LIBGCRYPT_PATH CPPFLAGS += -DLIBSSH2_LIBGCRYPT CPPFLAGS += -I"$(LIBGCRYPT_PATH)/include" _LDFLAGS += -L"$(LIBGCRYPT_PATH)/lib" _LIBS += -lgcrypt - include Makefile.libgcrypt.inc else ifdef MBEDTLS_PATH CPPFLAGS += -DLIBSSH2_MBEDTLS CPPFLAGS += -I"$(MBEDTLS_PATH)/include" _LDFLAGS += -L"$(MBEDTLS_PATH)/lib" _LIBS += -lmbedtls -lmbedx509 -lmbedcrypto - include Makefile.mbedTLS.inc else ifdef WIN32 CPPFLAGS += -DLIBSSH2_WINCNG - include Makefile.WinCNG.inc else $(error No suitable cryptography backend found) endif @@ -177,8 +172,8 @@ ifdef WIN32 vpath %.rc src endif -# include Makefile.inc to get CSOURCES define -include Makefile.inc +# Get CSOURCES define +include src/Makefile.inc OBJS := $(addprefix $(OBJ_DIR)/,$(patsubst %.c,%.o,$(CSOURCES))) diff --git a/Makefile.os400qc3.inc b/Makefile.os400qc3.inc deleted file mode 100644 index e55094d9..00000000 --- a/Makefile.os400qc3.inc +++ /dev/null @@ -1,2 +0,0 @@ -CRYPTO_CSOURCES = os400qc3.c -CRYPTO_HHEADERS = os400qc3.h diff --git a/Makefile.wolfSSL.inc b/Makefile.wolfSSL.inc deleted file mode 100644 index 24fed511..00000000 --- a/Makefile.wolfSSL.inc +++ /dev/null @@ -1,3 +0,0 @@ -CRYPTO_CSOURCES = openssl.c -CRYPTO_HHEADERS = openssl.h -CRYPTO_LTLIBS = -lwolfssl diff --git a/NMakefile b/NMakefile index 19756816..a7be7c11 100644 --- a/NMakefile +++ b/NMakefile @@ -16,11 +16,9 @@ CFLAGS=/nologo /GL /Zi /EHsc $(CFLAGS) /Iinclude !if "$(OPENSSL_PATH)" != "" CFLAGS=$(CFLAGS) /DLIBSSH2_OPENSSL /I$(OPENSSL_PATH)\include LIBS=$(LIBS) $(OPENSSL_PATH)\lib\crypto.lib $(OPENSSL_PATH)\lib\ssl.lib -!include "Makefile.OpenSSL.inc" !else CFLAGS=$(CFLAGS) /DLIBSSH2_WINCNG LIBS=crypt32.lib bcrypt.lib -!include "Makefile.WinCNG.inc" !endif !if "$(ZLIB_PATH)" != "" @@ -34,7 +32,7 @@ INTDIR=$(TARGET) SUBDIR=src -!include "Makefile.inc" +!include "src/Makefile.inc" OBJECTS=$(CSOURCES:.c=.obj) diff --git a/configure.ac b/configure.ac index f5ae8571..742c9b0f 100644 --- a/configure.ac +++ b/configure.ac @@ -120,9 +120,17 @@ else test "$found_crypto_str" = "" && found_crypto_str="$found_crypto" fi -m4_set_foreach([crypto_backends], [backend], - [AM_CONDITIONAL(m4_toupper(backend), test "$found_crypto" = "backend")] -) +if test "$found_crypto" = "openssl"; then + LIBS="${LIBS} ${LTLIBSSL}" +elif test "$found_crypto" = "wolfssl"; then + LIBS="${LIBS} ${LTLIBWOLFSSL}" +elif test "$found_crypto" = "libgcrypt"; then + LIBS="${LIBS} ${LTLIBGCRYPT}" +elif test "$found_crypto" = "wincng"; then + LIBS="${LIBS} ${LTLIBBCRYPT}" +elif test "$found_crypto" = "mbedtls"; then + LIBS="${LIBS} ${LTLIBMBEDCRYPTO}" +fi # libz diff --git a/docs/.gitignore b/docs/.gitignore index 3aed7632..6fc54d7c 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -1,3 +1,4 @@ Makefile Makefile.in +Makefile.am.cmake coverage diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index cb11db6c..d64dfe06 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -33,185 +33,9 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. -set(MAN_PAGES - libssh2_agent_connect.3 - libssh2_agent_disconnect.3 - libssh2_agent_free.3 - libssh2_agent_get_identity.3 - libssh2_agent_get_identity_path.3 - libssh2_agent_init.3 - libssh2_agent_list_identities.3 - libssh2_agent_set_identity_path.3 - libssh2_agent_userauth.3 - libssh2_banner_set.3 - libssh2_base64_decode.3 - libssh2_channel_close.3 - libssh2_channel_direct_tcpip.3 - libssh2_channel_direct_tcpip_ex.3 - libssh2_channel_eof.3 - libssh2_channel_exec.3 - libssh2_channel_flush.3 - libssh2_channel_flush_ex.3 - libssh2_channel_flush_stderr.3 - libssh2_channel_forward_accept.3 - libssh2_channel_forward_cancel.3 - libssh2_channel_forward_listen.3 - libssh2_channel_forward_listen_ex.3 - libssh2_channel_free.3 - libssh2_channel_get_exit_signal.3 - libssh2_channel_get_exit_status.3 - libssh2_channel_handle_extended_data.3 - libssh2_channel_handle_extended_data2.3 - libssh2_channel_ignore_extended_data.3 - libssh2_channel_open_ex.3 - libssh2_channel_open_session.3 - libssh2_channel_process_startup.3 - libssh2_channel_read.3 - libssh2_channel_read_ex.3 - libssh2_channel_read_stderr.3 - libssh2_channel_receive_window_adjust.3 - libssh2_channel_receive_window_adjust2.3 - libssh2_channel_request_auth_agent.3 - libssh2_channel_request_pty.3 - libssh2_channel_request_pty_ex.3 - libssh2_channel_request_pty_size.3 - libssh2_channel_request_pty_size_ex.3 - libssh2_channel_send_eof.3 - libssh2_channel_set_blocking.3 - libssh2_channel_setenv.3 - libssh2_channel_setenv_ex.3 - libssh2_channel_shell.3 - libssh2_channel_subsystem.3 - libssh2_channel_wait_closed.3 - libssh2_channel_wait_eof.3 - libssh2_channel_window_read.3 - libssh2_channel_window_read_ex.3 - libssh2_channel_window_write.3 - libssh2_channel_window_write_ex.3 - libssh2_channel_write.3 - libssh2_channel_write_ex.3 - libssh2_channel_write_stderr.3 - libssh2_channel_x11_req.3 - libssh2_channel_x11_req_ex.3 - libssh2_crypto_engine.3 - libssh2_exit.3 - libssh2_free.3 - libssh2_hostkey_hash.3 - libssh2_init.3 - libssh2_keepalive_config.3 - libssh2_keepalive_send.3 - libssh2_knownhost_add.3 - libssh2_knownhost_addc.3 - libssh2_knownhost_check.3 - libssh2_knownhost_checkp.3 - libssh2_knownhost_del.3 - libssh2_knownhost_free.3 - libssh2_knownhost_get.3 - libssh2_knownhost_init.3 - libssh2_knownhost_readfile.3 - libssh2_knownhost_readline.3 - libssh2_knownhost_writefile.3 - libssh2_knownhost_writeline.3 - libssh2_poll.3 - libssh2_poll_channel_read.3 - libssh2_publickey_add.3 - libssh2_publickey_add_ex.3 - libssh2_publickey_init.3 - libssh2_publickey_list_fetch.3 - libssh2_publickey_list_free.3 - libssh2_publickey_remove.3 - libssh2_publickey_remove_ex.3 - libssh2_publickey_shutdown.3 - libssh2_scp_recv.3 - libssh2_scp_recv2.3 - libssh2_scp_send.3 - libssh2_scp_send64.3 - libssh2_scp_send_ex.3 - libssh2_session_abstract.3 - libssh2_session_banner_get.3 - libssh2_session_banner_set.3 - libssh2_session_block_directions.3 - libssh2_session_callback_set.3 - libssh2_session_disconnect.3 - libssh2_session_disconnect_ex.3 - libssh2_session_flag.3 - libssh2_session_free.3 - libssh2_session_get_blocking.3 - libssh2_session_get_read_timeout.3 - libssh2_session_get_timeout.3 - libssh2_session_handshake.3 - libssh2_session_hostkey.3 - libssh2_session_init.3 - libssh2_session_init_ex.3 - libssh2_session_last_errno.3 - libssh2_session_last_error.3 - libssh2_session_method_pref.3 - libssh2_session_methods.3 - libssh2_session_set_blocking.3 - libssh2_session_set_last_error.3 - libssh2_session_set_read_timeout.3 - libssh2_session_set_timeout.3 - libssh2_session_startup.3 - libssh2_session_supported_algs.3 - libssh2_sftp_close.3 - libssh2_sftp_close_handle.3 - libssh2_sftp_closedir.3 - libssh2_sftp_fsetstat.3 - libssh2_sftp_fstat.3 - libssh2_sftp_fstat_ex.3 - libssh2_sftp_fstatvfs.3 - libssh2_sftp_fsync.3 - libssh2_sftp_get_channel.3 - libssh2_sftp_init.3 - libssh2_sftp_last_error.3 - libssh2_sftp_lstat.3 - libssh2_sftp_mkdir.3 - libssh2_sftp_mkdir_ex.3 - libssh2_sftp_open.3 - libssh2_sftp_open_ex.3 - libssh2_sftp_opendir.3 - libssh2_sftp_read.3 - libssh2_sftp_readdir.3 - libssh2_sftp_readdir_ex.3 - libssh2_sftp_readlink.3 - libssh2_sftp_realpath.3 - libssh2_sftp_rename.3 - libssh2_sftp_rename_ex.3 - libssh2_sftp_rewind.3 - libssh2_sftp_rmdir.3 - libssh2_sftp_rmdir_ex.3 - libssh2_sftp_seek.3 - libssh2_sftp_seek64.3 - libssh2_sftp_setstat.3 - libssh2_sftp_shutdown.3 - libssh2_sftp_stat.3 - libssh2_sftp_stat_ex.3 - libssh2_sftp_statvfs.3 - libssh2_sftp_symlink.3 - libssh2_sftp_symlink_ex.3 - libssh2_sftp_tell.3 - libssh2_sftp_tell64.3 - libssh2_sftp_unlink.3 - libssh2_sftp_unlink_ex.3 - libssh2_sftp_write.3 - libssh2_sign_sk.3 - libssh2_trace.3 - libssh2_trace_sethandler.3 - libssh2_userauth_authenticated.3 - libssh2_userauth_banner.3 - libssh2_userauth_hostbased_fromfile.3 - libssh2_userauth_hostbased_fromfile_ex.3 - libssh2_userauth_keyboard_interactive.3 - libssh2_userauth_keyboard_interactive_ex.3 - libssh2_userauth_list.3 - libssh2_userauth_password.3 - libssh2_userauth_password_ex.3 - libssh2_userauth_publickey.3 - libssh2_userauth_publickey_fromfile.3 - libssh2_userauth_publickey_fromfile_ex.3 - libssh2_userauth_publickey_frommemory.3 - libssh2_userauth_publickey_sk.3 - libssh2_version.3) +transform_makefile_inc("Makefile.am" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake") +# Get 'dist_man_MANS' variable +include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake) include(GNUInstallDirs) -install(FILES ${MAN_PAGES} DESTINATION ${CMAKE_INSTALL_MANDIR}/man3) +install(FILES ${dist_man_MANS} DESTINATION ${CMAKE_INSTALL_MANDIR}/man3) diff --git a/docs/HACKING-CRYPTO b/docs/HACKING-CRYPTO index c4149524..233cb325 100644 --- a/docs/HACKING-CRYPTO +++ b/docs/HACKING-CRYPTO @@ -31,18 +31,20 @@ LIBSSH2_LIB_HAVE_LINKFLAGS from LIBSSH2_CRYPTO_CHECK, which automatically creates and handles a --with-$newname-prefix option and sets an LTLIBNEWNAME variable on success. -0.3) Create Makefile.newname.inc in the top-level directory +0.3) Add new header to src/Makefile.inc -This must set CRYPTO_CSOURCES, CRYPTO_HHEADERS and CRYPTO_LTLIBS. -Set CRYPTO_CSOURCES and CRYPTO_HHEADERS to the new backend source files -and set CRYPTO_LTLIBS to the required library linking parameters, e.g. -$(LTLIBNEWNAME) as generated by by LIBSSH2_LIB_HAVE_LINKFLAGS. +0.4) Include new source in src/crypto.c -0.4) Add a new block in src/Makefile.am +0.5) Add a new block in configure.ac -if NEWNAME -include ../Makefile.newname.inc -endif +``` +elif test "$found_crypto" = "newname"; then + LIBS="${LIBS} ${LTLIBNEWNAME}" +``` + +0.6) Add CMake detection logic to CMakeLists.txt + +0.7) Add manual config logic to Makefile.mk 1) Crypto library initialization/termination. diff --git a/docs/Makefile.am b/docs/Makefile.am index 5efd370e..b2f2e5c9 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -1,7 +1,5 @@ -# $Id: Makefile.am,v 1.37 2009/03/26 15:41:15 bagder Exp $ - EXTRA_DIST = template.3 BINDINGS INSTALL_AUTOTOOLS INSTALL_CMAKE.md HACKING TODO \ - AUTHORS CMakeLists.txt HACKING-CRYPTO SECURITY.md + AUTHORS CMakeLists.txt HACKING-CRYPTO SECURITY.md dist_man_MANS = \ libssh2_agent_connect.3 \ diff --git a/example/.gitignore b/example/.gitignore index 4d26823d..f9603da0 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -2,6 +2,7 @@ .libs Makefile Makefile.in +Makefile.am.cmake *.gcno *.gcda stamp-h2 diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 72ca9489..a8661e93 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -39,31 +39,10 @@ list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) add_definitions(-DHAVE_CONFIG_H) -set(EXAMPLES - direct_tcpip - scp - scp_nonblock - scp_write - scp_write_nonblock - sftp - sftp_RW_nonblock - sftp_append - sftp_mkdir - sftp_mkdir_nonblock - sftp_nonblock - sftp_write - sftp_write_nonblock - sftp_write_sliding - sftpdir - sftpdir_nonblock - ssh2 - ssh2_agent - ssh2_agent_forwarding - ssh2_echo - ssh2_exec - subsystem_netconf - tcpip-forward - x11) +transform_makefile_inc("Makefile.am" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake") +# Get 'noinst_PROGRAMS' variable +include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake) +set(EXAMPLES ${noinst_PROGRAMS}) foreach(example ${EXAMPLES}) add_executable(example-${example} ${example}.c) diff --git a/os400/make-src.sh b/os400/make-src.sh index 2e9a3c43..3d352cbe 100644 --- a/os400/make-src.sh +++ b/os400/make-src.sh @@ -78,7 +78,7 @@ fi # Get source list. -cat ../Makefile.inc ../Makefile.os400qc3.inc | +cat Makefile.inc | sed -e ':begin' \ -e '/\\$/{' \ -e 's/\\$/ /' \ @@ -98,7 +98,7 @@ cat ../Makefile.inc ../Makefile.os400qc3.inc | INCLUDES="'`pwd`'" for SRC in "${TOPDIR}/os400/os400sys.c" "${TOPDIR}/os400/ccsid.c" \ - ${CSOURCES} ${CRYPTO_CSOURCES} macros.c + ${CSOURCES} macros.c do MODULE=`db2_name "${SRC}"` make_module "${MODULE}" "${SRC}" done diff --git a/src/.gitignore b/src/.gitignore index 2c86ec73..91aa7f0b 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,5 +1,7 @@ .deps .libs +Makefile.inc.cmake +libssh2.pc libssh2_config.h libssh2_config.h.in stamp-h1 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ec556fc2..60176c45 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -96,47 +96,15 @@ if(MSVC) set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /DEBUG") endif() -## Library definition +## Sources include(GNUInstallDirs) -set(SOURCES - ${CRYPTO_SOURCES} - agent.c - agent_win.c - bcrypt_pbkdf.c - channel.c - channel.h - comp.c - comp.h - crypt.c - crypto.h - global.c - hostkey.c - keepalive.c - kex.c - knownhost.c - libssh2_priv.h - mac.c - mac.h - misc.c - misc.h - os400qc3.c - packet.c - packet.h - pem.c - publickey.c - scp.c - session.c - session.h - sftp.c - sftp.h - transport.c - transport.h - userauth_kbd_packet.c - userauth_kbd_packet.h - userauth.c - userauth.h - version.c) +transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake") +# Get 'CSOURCES' and 'HHEADERS' variables +include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake) +set(SOURCES ${CSOURCES} ${HHEADERS}) + +## Library definition # we want it to be called libssh2 on all platforms if(BUILD_STATIC_LIBS) diff --git a/src/Makefile.am b/src/Makefile.am index 240bed14..1bb8a7d8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,30 +1,11 @@ -# $Id: Makefile.am,v 1.21 2009/05/07 17:21:56 bagder Exp $ AUTOMAKE_OPTIONS = foreign nostdinc -# Get the CRYPTO_CSOURCES, CRYPTO_HHEADERS and CRYPTO_LTLIBS defines -if OPENSSL -include ../Makefile.OpenSSL.inc -endif -if WOLFSSL -include ../Makefile.wolfSSL.inc -endif -if LIBGCRYPT -include ../Makefile.libgcrypt.inc -endif -if WINCNG -include ../Makefile.WinCNG.inc -endif -if MBEDTLS -include ../Makefile.mbedTLS.inc -endif - -# Makefile.inc provides the CSOURCES and HHEADERS defines -include ../Makefile.inc +# Get the CSOURCES and HHEADERS defines +include Makefile.inc libssh2_la_SOURCES = $(CSOURCES) $(HHEADERS) -EXTRA_DIST = libssh2_config.h.in libssh2_config_cmake.h.in -EXTRA_DIST += CMakeLists.txt +EXTRA_DIST = libssh2_config.h.in libssh2_config_cmake.h.in CMakeLists.txt lib_LTLIBRARIES = libssh2.la @@ -65,4 +46,4 @@ VERSION=-version-info 1:1:0 libssh2_la_LDFLAGS = $(VERSION) -no-undefined \ -export-symbols-regex '^libssh2_.*' \ - $(CRYPTO_LTLIBS) $(LTLIBZ) + $(LTLIBZ) diff --git a/src/Makefile.inc b/src/Makefile.inc new file mode 100644 index 00000000..1614271e --- /dev/null +++ b/src/Makefile.inc @@ -0,0 +1,46 @@ +CSOURCES = \ + agent.c \ + agent_win.c \ + bcrypt_pbkdf.c \ + channel.c \ + comp.c \ + crypt.c \ + crypto.c \ + global.c \ + hostkey.c \ + keepalive.c \ + kex.c \ + knownhost.c \ + mac.c \ + misc.c \ + packet.c \ + pem.c \ + publickey.c \ + scp.c \ + session.c \ + sftp.c \ + transport.c \ + userauth.c \ + userauth_kbd_packet.c \ + version.c + +HHEADERS = \ + agent.h \ + channel.h \ + comp.h \ + crypto.h \ + libgcrypt.h \ + libssh2_priv.h \ + libssh2_setup.h \ + mac.h \ + mbedtls.h \ + misc.h \ + openssl.h \ + os400qc3.h \ + packet.h \ + session.h \ + sftp.h \ + transport.h \ + userauth.h \ + userauth_kbd_packet.h \ + wincng.h diff --git a/src/crypto.c b/src/crypto.c new file mode 100644 index 00000000..789fcc41 --- /dev/null +++ b/src/crypto.c @@ -0,0 +1,13 @@ +#include "libssh2_priv.h" + +#if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL) +#include "openssl.c" +#elif defined(LIBSSH2_LIBGCRYPT) +#include "libgcrypt.c" +#elif defined(LIBSSH2_MBEDTLS) +#include "mbedtls.c" +#elif defined(LIBSSH2_OS400QC3) +#include "os400qc3.c" +#elif defined(LIBSSH2_WINCNG) +#include "wincng.c" +#endif