summaryrefslogtreecommitdiff
path: root/gnu/packages/patches/falcosecurity-libs-shared-build.patch
blob: d51a6596ad78188840c908edaa6c7cb3a1f47ada (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
Upstream-status: https://github.com/falcosecurity/libs/pull/1842

diff --git a/cmake/modules/BuildPkgConfigDependencies.cmake b/cmake/modules/BuildPkgConfigDependencies.cmake
index a597f18ac..d35506f5a 100644
--- a/cmake/modules/BuildPkgConfigDependencies.cmake
+++ b/cmake/modules/BuildPkgConfigDependencies.cmake
@@ -3,6 +3,7 @@
 # libsinsp.pc (which requires libscap.pc and pulls them in that way)
 function(add_pkgconfig_library LIBDIRS_VAR LIBS_VAR lib ignored)
 
+	message(DEBUG "[add_pkgconfig_library] processing lib \"${lib}\"")
 	# if it's not a target, it doesn't have dependencies we know or care about
 	if(NOT TARGET ${lib})
 		return()
@@ -14,14 +15,26 @@ function(add_pkgconfig_library LIBDIRS_VAR LIBS_VAR lib ignored)
 		return()
 	endif()
 
+	message(DEBUG "[add_pkgconfig_library] LINK_LIBRARIES property: \"${PKGCONFIG_LIBRARIES}\"")
+
 	get_property(
 		target_type
 		TARGET ${lib}
 		PROPERTY TYPE
 	)
+	message(DEBUG "[add_pkgconfig_library] ignored list: \"${ignored}\"")
 	foreach(dep ${PKGCONFIG_LIBRARIES})
-		# ignore dependencies in the list ${ignored}
-		if(${dep} IN_LIST "${ignored}")
+		# XXX: We use a (very) loose match as we are potentially comparing absolute library file
+		# names (dep) to pkg-config library names to be ignored.  The only alternative I can think
+		# of would be to maintain a map associating pkg-config names to their library file name.
+		get_filename_component(dep_base ${dep} NAME_WE)
+		string(REGEX REPLACE "^lib" "" dep_name ${dep_base})
+		# For CMake imported targets, keep only the suffix, e.g. gRPC::grpc -> grpc.
+		string(REGEX REPLACE "[^:]*::" "" dep_name ${dep_base})
+		message(DEBUG "[add_pkgconfig_library] processing dep ${dep}")
+		string(FIND "${ignored}" "${dep_name}" find_result)
+		if(NOT ${find_result} EQUAL -1)
+			message(DEBUG "[add_pkgconfig_library] \"${dep}\" ignored")
 			continue()
 		endif()
 
diff --git a/cmake/modules/libscap.cmake b/cmake/modules/libscap.cmake
index 346ac51b1..a8f50f071 100644
--- a/cmake/modules/libscap.cmake
+++ b/cmake/modules/libscap.cmake
@@ -91,16 +91,6 @@ if(NOT HAVE_LIBSCAP)
 		endif()
 	endforeach()
 
-	set(libscap_link_flags)
-	set(libscap_link_libdirs "")
-	add_pkgconfig_dependency(libscap_link_libdirs libscap_link_flags scap "")
-
-	string(REPLACE ";" " " LIBSCAP_LINK_LIBRARIES_FLAGS "${libscap_link_flags}")
-	string(REPLACE ";" " " LIBSCAP_LINK_LIBDIRS_FLAGS "${libscap_link_libdirs}")
-	configure_file(
-		${LIBS_DIR}/userspace/libscap/libscap.pc.in ${PROJECT_BINARY_DIR}/libscap/libscap.pc @ONLY
-	)
-
 	install(
 		TARGETS ${LIBSCAP_INSTALL_LIBS}
 		ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
diff --git a/driver/CMakeLists.txt b/driver/CMakeLists.txt
index 94f37ee2a..fc844da7b 100644
--- a/driver/CMakeLists.txt
+++ b/driver/CMakeLists.txt
@@ -158,6 +158,11 @@ set(DRIVER_SOURCES
 	ppm_consumer.h
 	capture_macro.h
 	socketcall_to_syscall.h
+	syscall_compat_loongarch64.h
+	syscall_compat_ppc64le.h
+	syscall_compat_riscv64.h
+	syscall_compat_s390x.h
+	syscall_compat_x86_64.h
 	syscall_ia32_64_map.c
 )
 
diff --git a/userspace/libpman/CMakeLists.txt b/userspace/libpman/CMakeLists.txt
index b5d982b0d..c9d71fe02 100644
--- a/userspace/libpman/CMakeLists.txt
+++ b/userspace/libpman/CMakeLists.txt
@@ -53,3 +53,8 @@ install(
 			COMPONENT "scap"
 			OPTIONAL
 )
+
+install(FILES include/libpman.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpman.pc.in ${PROJECT_BINARY_DIR}/libpman.pc @ONLY)
+
+install(FILES ${PROJECT_BINARY_DIR}/libpman.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
diff --git a/userspace/libpman/libpman.pc.in b/userspace/libpman/libpman.pc.in
new file mode 100644
index 000000000..e5373e87d
--- /dev/null
+++ b/userspace/libpman/libpman.pc.in
@@ -0,0 +1,11 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
+
+Name: libpman
+Description: Utility library for BPF probes
+Version: @FALCOSECURITY_LIBS_VERSION@
+
+Requires: libbpf zlib
+Libs: -L${libdir} -lpman -lscap_event_schema -lscap_platform
+Cflags: -I${includedir}
diff --git a/userspace/libscap/CMakeLists.txt b/userspace/libscap/CMakeLists.txt
index 20ac14cdf..0fec656d6 100644
--- a/userspace/libscap/CMakeLists.txt
+++ b/userspace/libscap/CMakeLists.txt
@@ -89,9 +89,11 @@ target_include_directories(
 )
 
 target_link_libraries(scap PRIVATE scap_error "${ZLIB_LIB}")
+set(SCAP_PKGCONFIG_REQUIRES "")
+set(SCAP_PKGCONFIG_REQUIRES_PRIVATE zlib)
 
 add_library(
-	scap_event_schema STATIC
+	scap_event_schema
 	scap_event.c
 	ppm_sc_names.c
 	scap_print_event.c
@@ -174,17 +176,20 @@ if(HAS_ENGINE_BPF)
 	add_subdirectory(engine/bpf)
 	target_link_libraries(scap PUBLIC scap_engine_bpf)
 	target_include_directories(scap_engine_bpf PRIVATE ${PROJECT_BINARY_DIR}/driver/src)
+	list(APPEND SCAP_PKGCONFIG_REQUIRES libelf)
 endif()
 
 if(HAS_ENGINE_MODERN_BPF)
 	add_subdirectory(engine/modern_bpf)
 	target_link_libraries(scap PUBLIC scap_engine_modern_bpf)
 	target_include_directories(scap_engine_modern_bpf PRIVATE ${PROJECT_BINARY_DIR}/driver/src)
+	list(APPEND SCAP_PKGCONFIG_REQUIRES libpman)
 endif()
 
 if(HAS_ENGINE_GVISOR)
 	add_subdirectory(engine/gvisor)
 	target_link_libraries(scap PUBLIC scap_engine_gvisor)
+	list(APPEND SCAP_PKGCONFIG_REQUIRES protobuf jsoncpp)
 endif()
 
 # ##################################################################################################
@@ -193,3 +198,22 @@ if(BUILD_LIBSCAP_EXAMPLES)
 	add_subdirectory(examples/01-open)
 	add_subdirectory(examples/02-validatebuffer)
 endif()
+
+set(libscap_link_flags)
+set(libscap_link_libdirs "")
+add_pkgconfig_dependency(
+	libscap_link_libdirs
+	libscap_link_flags
+	scap
+	# Avoid using these in libscap.pc Libs field, as they are already listed in Requires.  lbpf
+	# is transitively required via libpman.pc.
+	"${SCAP_PKGCONFIG_REQUIRES};${SCAP_PKGCONFIG_REQUIRES_PRIVATE}"
+)
+
+string(REPLACE ";" " " LIBSCAP_REQUIRES "${SCAP_PKGCONFIG_REQUIRES}")
+string(REPLACE ";" " " LIBSCAP_REQUIRES_PRIVATE "${SCAP_PKGCONFIG_REQUIRES_PRIVATE}")
+string(REPLACE ";" " " LIBSCAP_LINK_LIBRARIES_FLAGS "${libscap_link_flags}")
+string(REPLACE ";" " " LIBSCAP_LINK_LIBDIRS_FLAGS "${libscap_link_libdirs}")
+configure_file(
+	${LIBS_DIR}/userspace/libscap/libscap.pc.in ${PROJECT_BINARY_DIR}/libscap/libscap.pc @ONLY
+)
diff --git a/userspace/libscap/libscap.pc.in b/userspace/libscap/libscap.pc.in
index 520020691..935cddc73 100644
--- a/userspace/libscap/libscap.pc.in
+++ b/userspace/libscap/libscap.pc.in
@@ -1,4 +1,4 @@
-prefix=${pcfiledir}/../..
+prefix=@CMAKE_INSTALL_PREFIX@
 libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
 includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@LIBS_PACKAGE_NAME@
 
@@ -6,5 +6,7 @@ Name: libscap
 Description: lib for System CAPture
 Version: @FALCOSECURITY_LIBS_VERSION@
 
+Requires: @LIBSCAP_PKGCONFIG_REQUIRES@
+Requires.private: @LIBSCAP_PKGCONFIG_REQUIRES_PRIVATE@
 Libs: -L${libdir} @LIBSCAP_LINK_LIBDIRS_FLAGS@ @LIBSCAP_LINK_LIBRARIES_FLAGS@
-Cflags: -I${includedir}
+Cflags: -I${includedir} -I${includedir}/libscap -I${includedir}/driver -I@UTHASH_INCLUDE@
diff --git a/userspace/libscap/linux/CMakeLists.txt b/userspace/libscap/linux/CMakeLists.txt
index 435c8546c..3f47b7801 100644
--- a/userspace/libscap/linux/CMakeLists.txt
+++ b/userspace/libscap/linux/CMakeLists.txt
@@ -13,7 +13,7 @@
 # the License.
 #
 add_library(
-	scap_platform STATIC
+	scap_platform
 	scap_linux_platform.c
 	scap_linux_hostinfo_platform.c
 	scap_procs.c
diff --git a/userspace/libsinsp/CMakeLists.txt b/userspace/libsinsp/CMakeLists.txt
index f58b00962..501db7933 100644
--- a/userspace/libsinsp/CMakeLists.txt
+++ b/userspace/libsinsp/CMakeLists.txt
@@ -177,12 +177,17 @@ target_link_libraries(
 	PRIVATE "${CURL_LIBRARIES}" "${JSONCPP_LIB}" "${RE2_LIB}"
 )
 
+set(SINSP_PKGCONFIG_REQUIRES jsoncpp)
+set(SINSP_PKGCONFIG_REQUIRES_PRIVATE libcurl re2)
+
 if(NOT EMSCRIPTEN)
 	target_link_libraries(
 		sinsp
 		INTERFACE "${CARES_LIB}"
 		PRIVATE "${TBB_LIB}"
 	)
+	list(APPEND SINSP_PKGCONFIG_REQUIRES libcares)
+	list(APPEND SINSP_PKGCONFIG_REQUIRES_PRIVATE tbb)
 endif()
 
 if(USE_BUNDLED_VALIJSON)
@@ -275,6 +280,15 @@ if(NOT WIN32)
 			)
 
 			target_link_libraries(sinsp PRIVATE cri_v1alpha2 cri_v1 containerd_interface)
+			list(
+				APPEND
+				SINSP_PKGCONFIG_REQUIRES
+				gpr
+				grpc
+				grpc++
+				protobuf
+				libcares
+			)
 
 			if(NOT MUSL_OPTIMIZED_BUILD)
 				find_library(LIB_ANL anl)
@@ -290,6 +304,8 @@ if(NOT WIN32)
 		endif() # NOT MINIMAL_BUILD
 	endif() # NOT APPLE
 
+	list(APPEND SINSP_PKGCONFIG_REQUIRES libcrypto libssl)
+
 	target_link_libraries(sinsp INTERFACE dl pthread)
 
 	if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
@@ -329,7 +345,10 @@ add_definitions(-DSINSP_AGENT_CGROUP_MEM_PATH_ENV_VAR="${SINSP_AGENT_CGROUP_MEM_
 # https://github.com/curl/curl/blob/curl-7_84_0/CMakeLists.txt#L1539
 set(SINSP_PKG_CONFIG_LIBS)
 set(SINSP_PKG_CONFIG_LIBDIRS "")
-add_pkgconfig_dependency(SINSP_PKG_CONFIG_LIBDIRS SINSP_PKG_CONFIG_LIBS sinsp scap)
+add_pkgconfig_dependency(
+	SINSP_PKG_CONFIG_LIBDIRS SINSP_PKG_CONFIG_LIBS sinsp
+	"scap;${SINSP_PKGCONFIG_REQUIRES};${SINSP_PKGCONFIG_REQUIRES_PRIVATE}"
+)
 
 # Build our pkg-config "Cflags:" flags.
 set(SINSP_PKG_CONFIG_INCLUDES "")
@@ -337,6 +356,8 @@ foreach(sinsp_include_directory ${LIBSINSP_INCLUDE_DIRS})
 	list(APPEND SINSP_PKG_CONFIG_INCLUDES -I${sinsp_include_directory})
 endforeach()
 
+string(REPLACE ";" " " LIBSINSP_REQUIRES "${SINSP_PKGCONFIG_REQUIRES}")
+string(REPLACE ";" " " LIBSINSP_REQUIRES_PRIVATE "${SINSP_PKGCONFIG_REQUIRES_PRIVATE}")
 string(REPLACE ";" " " SINSP_PKG_CONFIG_LIBS "${SINSP_PKG_CONFIG_LIBS}")
 list(REMOVE_DUPLICATES SINSP_PKG_CONFIG_LIBDIRS)
 string(REPLACE ";" " " SINSP_PKG_CONFIG_LIBDIRS "${SINSP_PKG_CONFIG_LIBDIRS}")
diff --git a/userspace/libsinsp/libsinsp.pc.in b/userspace/libsinsp/libsinsp.pc.in
index 38e8e4e0d..9ab103ee1 100644
--- a/userspace/libsinsp/libsinsp.pc.in
+++ b/userspace/libsinsp/libsinsp.pc.in
@@ -1,4 +1,4 @@
-prefix=${pcfiledir}/../..
+prefix=@CMAKE_INSTALL_PREFIX@
 libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
 includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@LIBS_PACKAGE_NAME@
 
@@ -6,6 +6,7 @@ Name: libsinsp
 Description: lib for System INSPection
 Version: @FALCOSECURITY_LIBS_VERSION@
 
-Requires: libscap
-Libs: -L${libdir} -lsinsp @SINSP_PKG_CONFIG_LIBDIRS@ @SINSP_PKG_CONFIG_LIBS@
-Cflags: -I${includedir} @SINSP_PKG_CONFIG_INCLUDES@
+Requires: libscap @LIBSINSP_REQUIRES@
+Requires.private: @LIBSINSP_REQUIRES_PRIVATE@
+Libs: -L${libdir} @SINSP_PKG_CONFIG_LIBDIRS@ @SINSP_PKG_CONFIG_LIBS@
+Cflags: -I${includedir} -I${includedir}/libsinsp -I${includedir}/driver @SINSP_PKG_CONFIG_INCLUDES@
diff --git a/userspace/libsinsp/test/CMakeLists.txt b/userspace/libsinsp/test/CMakeLists.txt
index fb8c46754..be6420672 100644
--- a/userspace/libsinsp/test/CMakeLists.txt
+++ b/userspace/libsinsp/test/CMakeLists.txt
@@ -191,7 +191,13 @@ target_include_directories(
 )
 
 target_link_libraries(
-	unit-test-libsinsp sinsp "${GTEST_LIB}" "${GTEST_MAIN_LIB}" "${TBB_LIB}" "${JSONCPP_LIB}"
+	unit-test-libsinsp
+	sinsp
+	"${GRPCPP_LIB}"
+	"${GTEST_LIB}"
+	"${GTEST_MAIN_LIB}"
+	"${TBB_LIB}"
+	"${JSONCPP_LIB}"
 )
 
 # Add some additional include directories associated with `ADDITIONAL_SINSP_TESTS_SUITE`