Skip to content

Commit 875bc59

Browse files
committed
Makefile.mk: use Makefile.inc from example and tests
Instead of assembling the list using `$(wildcard ...)`. Also split off a `tests/Makefile.inc` from `tests/Makefile.am`. With its simpler syntax, this also allows to delete some complexity from the CMake loader. Cherry-picked from libssh2#1017
1 parent 8270633 commit 875bc59

File tree

7 files changed

+95
-96
lines changed

7 files changed

+95
-96
lines changed

CMakeLists.txt

+1-9
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,7 @@ endif()
384384

385385
# Convert GNU Make assignments into CMake ones.
386386
function(transform_makefile_inc INPUT_FILE OUTPUT_FILE)
387-
file(STRINGS ${INPUT_FILE} LINES)
388-
389-
unset(MAKEFILE_INC_CMAKE)
390-
foreach(LINE IN LISTS LINES)
391-
if(NOT LINE MATCHES " \\+= " AND
392-
NOT LINE MATCHES "^(if|endif)")
393-
set(MAKEFILE_INC_CMAKE "${MAKEFILE_INC_CMAKE}\n${LINE}")
394-
endif()
395-
endforeach()
387+
file(READ ${INPUT_FILE} MAKEFILE_INC_CMAKE)
396388

397389
string(REGEX REPLACE "\\\\\n" "" MAKEFILE_INC_CMAKE ${MAKEFILE_INC_CMAKE})
398390
string(REGEX REPLACE "([A-Za-z_]+) *= *([^\n]*)" "set(\\1 \\2)" MAKEFILE_INC_CMAKE ${MAKEFILE_INC_CMAKE})

Makefile.mk

+6-2
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ ifdef WIN32
194194
LIBSSH2_LDFLAGS_DYN += -Wl,--output-def,$(libssh2_def_LIBRARY),--out-implib,$(libssh2_dyn_a_LIBRARY)
195195
endif
196196

197+
# Get noinst_PROGRAMS define
198+
include example/Makefile.am
197199
TARGETS_EXAMPLES := $(patsubst %.c,%$(BIN_EXT),$(strip $(wildcard example/*.c)))
198200

199201
all: lib dyn
@@ -209,9 +211,11 @@ prebuild: $(OBJ_DIR) $(OBJ_DIR)/version.inc
209211

210212
example: $(TARGETS_EXAMPLES)
211213

214+
# Get DOCKER_TESTS, STANDALONE_TESTS, SSHD_TESTS, librunner_la_SOURCES defines
215+
include tests/Makefile.inc
212216
TARGETS_RUNNER := $(TARGET)-runner.a
213-
TARGETS_RUNNER_OBJS := $(addprefix $(OBJ_DIR)/,$(patsubst %.c,%.o,runner.c session_fixture.c openssh_fixture.c))
214-
TARGETS_TESTS := $(patsubst %.c,%$(BIN_EXT),$(strip $(wildcard tests/test_*.c)))
217+
TARGETS_RUNNER_OBJS := $(addprefix $(OBJ_DIR)/,$(patsubst %.c,%.o,$(filter %.c,$(librunner_la_SOURCES))))
218+
TARGETS_TESTS := $(patsubst %.c,%$(BIN_EXT),$(addprefix tests/,$(addsuffix .c,$(DOCKER_TESTS) $(STANDALONE_TESTS) $(SSHD_TESTS))))
215219

216220
test: $(TARGETS_RUNNER) $(TARGETS_TESTS)
217221

tests/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
*.gcda
55
Makefile
66
Makefile.in
7-
Makefile.am.cmake
7+
Makefile.inc.cmake

tests/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ include(CopyRuntimeDependencies)
3737

3838
list(APPEND LIBRARIES ${SOCKET_LIBRARIES})
3939

40-
transform_makefile_inc("Makefile.am" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake")
40+
transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
4141
# Get 'DOCKER_TESTS', 'STANDALONE_TESTS', 'SSHD_TESTS', 'librunner_la_SOURCES' variables
42-
include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake)
42+
include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
4343

4444
if(CMAKE_COMPILER_IS_GNUCC)
4545
find_program(GCOV_PATH gcov)

tests/Makefile.am

+2-80
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,8 @@ SUBDIRS = ossfuzz
22

33
AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src -I$(top_srcdir)/include
44

5-
# Keep this list sorted
6-
#
7-
# NOTE: test_auth_keyboard_info_request does not use the network, but when
8-
# run as Windows standalone test, it intermittently fails on GHA with:
9-
# `Terminate batch job (Y/N)?`
10-
DOCKER_TESTS = \
11-
test_aa_warmup \
12-
test_agent_forward_ok \
13-
test_auth_keyboard_fail \
14-
test_auth_keyboard_info_request \
15-
test_auth_keyboard_ok \
16-
test_auth_password_fail_password \
17-
test_auth_password_fail_username \
18-
test_auth_password_ok \
19-
test_auth_pubkey_fail \
20-
test_auth_pubkey_ok_dsa \
21-
test_auth_pubkey_ok_ecdsa \
22-
test_auth_pubkey_ok_ecdsa_signed \
23-
test_auth_pubkey_ok_ed25519 \
24-
test_auth_pubkey_ok_ed25519_encrypted \
25-
test_auth_pubkey_ok_ed25519_mem \
26-
test_auth_pubkey_ok_rsa \
27-
test_auth_pubkey_ok_rsa_encrypted \
28-
test_auth_pubkey_ok_rsa_openssh \
29-
test_auth_pubkey_ok_rsa_signed \
30-
test_hostkey \
31-
test_hostkey_hash \
32-
test_read
33-
34-
STANDALONE_TESTS = \
35-
test_simple
36-
37-
SSHD_TESTS = \
38-
test_ssh2 \
39-
test_auth_pubkey_ok_ed25519
5+
# Get DOCKER_TESTS, STANDALONE_TESTS, SSHD_TESTS, librunner_la_SOURCES defines
6+
include Makefile.inc
407

418
# FIXME: Exported by autotools with the same value by default anyway?
429
TESTS_ENVIRONMENT = srcdir=$(top_srcdir)/tests builddir=$(top_builddir)/tests
@@ -66,10 +33,6 @@ TESTS += test_read_algos.test
6633
check_PROGRAMS = $(DOCKER_TESTS) $(STANDALONE_TESTS) $(SSHD_TESTS)
6734

6835
# Internal library used by tests
69-
librunner_la_SOURCES = \
70-
runner.c runner.h \
71-
session_fixture.c session_fixture.h \
72-
openssh_fixture.c openssh_fixture.h
7336
LDADD = librunner.la
7437
check_LTLIBRARIES = librunner.la
7538

@@ -81,44 +44,3 @@ test_simple_LDFLAGS = -static
8144

8245
# This must be last in the list so it resolves symbols in previous libraries
8346
LDADD += ../src/libssh2.la
84-
85-
EXTRA_DIST = \
86-
CMakeLists.txt \
87-
key_dsa \
88-
key_dsa.pub \
89-
key_dsa_wrong \
90-
key_dsa_wrong.pub \
91-
key_ecdsa \
92-
key_ecdsa.pub \
93-
key_ecdsa_signed \
94-
key_ecdsa_signed-cert.pub \
95-
key_ecdsa_signed.pub \
96-
key_ed25519 \
97-
key_ed25519.pub \
98-
key_ed25519_encrypted \
99-
key_ed25519_encrypted.pub \
100-
key_rsa \
101-
key_rsa.pub \
102-
key_rsa_encrypted \
103-
key_rsa_encrypted.pub \
104-
key_rsa_openssh \
105-
key_rsa_openssh.pub \
106-
key_rsa_signed \
107-
key_rsa_signed-cert.pub \
108-
key_rsa_signed.pub \
109-
mansyntax.sh \
110-
openssh_server/Dockerfile \
111-
openssh_server/authorized_keys \
112-
openssh_server/ca_ecdsa \
113-
openssh_server/ca_ecdsa.pub \
114-
openssh_server/ca_rsa \
115-
openssh_server/ca_rsa.pub \
116-
openssh_server/ca_user_keys.pub \
117-
openssh_server/ssh_host_ecdsa_key \
118-
openssh_server/ssh_host_ed25519_key \
119-
openssh_server/ssh_host_rsa_key \
120-
openssh_server/sshd_config \
121-
test_read_algos.test \
122-
test_read_algos.txt \
123-
test_sshd.test \
124-
sshd_fixture.sh

tests/Makefile.inc

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Keep this list sorted
2+
#
3+
# NOTE: test_auth_keyboard_info_request does not use the network, but when
4+
# run as Windows standalone test, it intermittently fails on GHA with:
5+
# `Terminate batch job (Y/N)?`
6+
DOCKER_TESTS = \
7+
test_aa_warmup \
8+
test_agent_forward_ok \
9+
test_auth_keyboard_fail \
10+
test_auth_keyboard_info_request \
11+
test_auth_keyboard_ok \
12+
test_auth_password_fail_password \
13+
test_auth_password_fail_username \
14+
test_auth_password_ok \
15+
test_auth_pubkey_fail \
16+
test_auth_pubkey_ok_dsa \
17+
test_auth_pubkey_ok_ecdsa \
18+
test_auth_pubkey_ok_ecdsa_signed \
19+
test_auth_pubkey_ok_ed25519 \
20+
test_auth_pubkey_ok_ed25519_encrypted \
21+
test_auth_pubkey_ok_ed25519_mem \
22+
test_auth_pubkey_ok_rsa \
23+
test_auth_pubkey_ok_rsa_encrypted \
24+
test_auth_pubkey_ok_rsa_openssh \
25+
test_auth_pubkey_ok_rsa_signed \
26+
test_hostkey \
27+
test_hostkey_hash \
28+
test_read
29+
30+
STANDALONE_TESTS = \
31+
test_simple
32+
33+
SSHD_TESTS = \
34+
test_ssh2 \
35+
test_auth_pubkey_ok_ed25519
36+
37+
librunner_la_SOURCES = \
38+
runner.c runner.h \
39+
session_fixture.c session_fixture.h \
40+
openssh_fixture.c openssh_fixture.h
41+
42+
EXTRA_DIST = \
43+
CMakeLists.txt \
44+
key_dsa \
45+
key_dsa.pub \
46+
key_dsa_wrong \
47+
key_dsa_wrong.pub \
48+
key_ecdsa \
49+
key_ecdsa.pub \
50+
key_ecdsa_signed \
51+
key_ecdsa_signed-cert.pub \
52+
key_ecdsa_signed.pub \
53+
key_ed25519 \
54+
key_ed25519.pub \
55+
key_ed25519_encrypted \
56+
key_ed25519_encrypted.pub \
57+
key_rsa \
58+
key_rsa.pub \
59+
key_rsa_encrypted \
60+
key_rsa_encrypted.pub \
61+
key_rsa_openssh \
62+
key_rsa_openssh.pub \
63+
key_rsa_signed \
64+
key_rsa_signed-cert.pub \
65+
key_rsa_signed.pub \
66+
mansyntax.sh \
67+
openssh_server/Dockerfile \
68+
openssh_server/authorized_keys \
69+
openssh_server/ca_ecdsa \
70+
openssh_server/ca_ecdsa.pub \
71+
openssh_server/ca_rsa \
72+
openssh_server/ca_rsa.pub \
73+
openssh_server/ca_user_keys.pub \
74+
openssh_server/ssh_host_ecdsa_key \
75+
openssh_server/ssh_host_ed25519_key \
76+
openssh_server/ssh_host_rsa_key \
77+
openssh_server/sshd_config \
78+
test_read_algos.test \
79+
test_read_algos.txt \
80+
test_sshd.test \
81+
sshd_fixture.sh

tests/test_sshd.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set -u
88
d="$(dirname "$0")"
99
uname="$(uname)"
1010

11-
# Load list of SSHD tests from Makefile.am
11+
# Load list of SSHD tests from Makefile.inc
1212
tests=''
1313
load=0
1414
while read -r l; do
@@ -20,7 +20,7 @@ while read -r l; do
2020
# On Windows, subsequent tests may be flaky
2121
[[ "${uname}" = *'_NT'* ]] && break
2222
fi
23-
done <<< "$(tr -d $"\r" < "${d}/Makefile.am")"
23+
done <<< "$(tr -d $"\r" < "${d}/Makefile.inc")"
2424

2525
count=1
2626
total="$(echo "${tests}" | wc -w | tr -d ' ')"

0 commit comments

Comments
 (0)