4646print_targets=0
4747
4848while getopts " p" arg; do
49- case $arg in
50- p)
49+ case $arg in
50+ p)
5151 print_targets=1
5252 shift ;;
53- esac
53+ esac
5454done
5555
5656if [ $# -eq 0 ]
@@ -92,6 +92,10 @@ pass_cnt=0
9292# Get all TARGETS from selftests Makefile
9393targets=$( grep -E " ^TARGETS +|^TARGETS =" Makefile | cut -d " =" -f2)
9494
95+ # Initially, in LDLIBS related lines, the dep checker needs
96+ # to ignore lines containing the following strings:
97+ filter=" \$ (VAR_LDLIBS)\|pkg-config\|PKG_CONFIG\|IOURING_EXTRA_LIBS"
98+
9599# Single test case
96100if [ $# -eq 2 ]
97101then
100104 l1_test $test
101105 l2_test $test
102106 l3_test $test
107+ l4_test $test
108+ l5_test $test
103109
104110 print_results $1 $2
105111 exit $?
113119# Append space at the end of the list to append more tests.
114120
115121l1_tests=$( grep -r --include=Makefile " ^LDLIBS" | \
116- grep -v " VAR_LDLIBS " | awk -F: ' {print $1}' )
122+ grep -v " $filter " | awk -F: ' {print $1}' | uniq )
117123
118124# Level 2: LDLIBS set dynamically.
119125#
@@ -126,7 +132,7 @@ l1_tests=$(grep -r --include=Makefile "^LDLIBS" | \
126132# Append space at the end of the list to append more tests.
127133
128134l2_tests=$( grep -r --include=Makefile " : LDLIBS" | \
129- grep -v " VAR_LDLIBS " | awk -F: ' {print $1}' )
135+ grep -v " $filter " | awk -F: ' {print $1}' | uniq )
130136
131137# Level 3
132138# memfd and others use pkg-config to find mount and fuse libs
@@ -138,11 +144,32 @@ l2_tests=$(grep -r --include=Makefile ": LDLIBS" | \
138144# VAR_LDLIBS := $(shell pkg-config fuse --libs 2>/dev/null)
139145
140146l3_tests=$( grep -r --include=Makefile " ^VAR_LDLIBS" | \
141- grep -v " pkg-config" | awk -F: ' {print $1}' )
147+ grep -v " pkg-config\|PKG_CONFIG " | awk -F: ' {print $1}' | uniq )
142148
143- # echo $l1_tests
144- # echo $l2_1_tests
145- # echo $l3_tests
149+ # Level 4
150+ # some tests may fall back to default using `|| echo -l<libname>`
151+ # if pkg-config doesn't find the libs, instead of using VAR_LDLIBS
152+ # as per level 3 checks.
153+ # e.g:
154+ # netfilter/Makefile
155+ # LDLIBS += $(shell $(HOSTPKG_CONFIG) --libs libmnl 2>/dev/null || echo -lmnl)
156+ l4_tests=$( grep -r --include=Makefile " ^LDLIBS" | \
157+ grep " pkg-config\|PKG_CONFIG" | awk -F: ' {print $1}' | uniq)
158+
159+ # Level 5
160+ # some tests may use IOURING_EXTRA_LIBS to add extra libs to LDLIBS,
161+ # which in turn may be defined in a sub-Makefile
162+ # e.g.:
163+ # mm/Makefile
164+ # $(OUTPUT)/gup_longterm: LDLIBS += $(IOURING_EXTRA_LIBS)
165+ l5_tests=$( grep -r --include=Makefile " LDLIBS +=.*\$ (IOURING_EXTRA_LIBS)" | \
166+ awk -F: ' {print $1}' | uniq)
167+
168+ # echo l1_tests $l1_tests
169+ # echo l2_tests $l2_tests
170+ # echo l3_tests $l3_tests
171+ # echo l4_tests $l4_tests
172+ # echo l5_tests $l5_tests
146173
147174all_tests
148175print_results $1 $2
@@ -164,24 +191,32 @@ all_tests()
164191 for test in $l3_tests ; do
165192 l3_test $test
166193 done
194+
195+ for test in $l4_tests ; do
196+ l4_test $test
197+ done
198+
199+ for test in $l5_tests ; do
200+ l5_test $test
201+ done
167202}
168203
169204# Use same parsing used for l1_tests and pick libraries this time.
170205l1_test ()
171206{
172207 test_libs=$( grep --include=Makefile " ^LDLIBS" $test | \
173- grep -v " VAR_LDLIBS " | \
208+ grep -v " $filter " | \
174209 sed -e ' s/\:/ /' | \
175210 sed -e ' s/+/ /' | cut -d " =" -f 2)
176211
177212 check_libs $test $test_libs
178213}
179214
180- # Use same parsing used for l2__tests and pick libraries this time.
215+ # Use same parsing used for l2_tests and pick libraries this time.
181216l2_test ()
182217{
183218 test_libs=$( grep --include=Makefile " : LDLIBS" $test | \
184- grep -v " VAR_LDLIBS " | \
219+ grep -v " $filter " | \
185220 sed -e ' s/\:/ /' | sed -e ' s/+/ /' | \
186221 cut -d " =" -f 2)
187222
@@ -197,6 +232,24 @@ l3_test()
197232 check_libs $test $test_libs
198233}
199234
235+ l4_test ()
236+ {
237+ test_libs=$( grep --include=Makefile " ^VAR_LDLIBS\|^LDLIBS" $test | \
238+ grep " \(pkg-config\|PKG_CONFIG\).*|| echo " | \
239+ sed -e ' s/.*|| echo //' | sed -e ' s/)$//' )
240+
241+ check_libs $test $test_libs
242+ }
243+
244+ l5_test ()
245+ {
246+ tests=$( find $( dirname " $test " ) -type f -name " *.mk" )
247+ test_libs=$( grep " ^IOURING_EXTRA_LIBS +\?=" $tests | \
248+ cut -d " =" -f 2)
249+
250+ check_libs $test $test_libs
251+ }
252+
200253check_libs ()
201254{
202255
0 commit comments