tools build: Implement libzstd feature check, LIBZSTD_DIR and NO_LIBZSTD defines
authorAlexey Budankov <alexey.budankov@linux.intel.com>
Mon, 18 Mar 2019 17:39:49 +0000 (20:39 +0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 1 Apr 2019 18:18:10 +0000 (15:18 -0300)
Implement libzstd feature check, NO_LIBZSTD and LIBZSTD_DIR defines to
override Zstd library sources or disable the feature from the command
line:

  $ make -C tools/perf LIBZSTD_DIR=/path/to/zstd/sources/ clean all
  $ make -C tools/perf NO_LIBZSTD=1 clean all

Auto detection feature status is reported just before compilation
starts.  If your system has some version of the zstd library
preinstalled then the build system finds and uses it during the build.

If you still prefer to compile with some other version of zstd library
you have capability to refer the compilation to that version using
LIBZSTD_DIR define.

Signed-off-by: Alexey Budankov <alexey.budankov@linux.intel.com>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/9b4cd8b0-10a3-1f1e-8d6b-5922a7ca216b@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/build/Makefile.feature
tools/build/feature/Makefile
tools/build/feature/test-all.c
tools/build/feature/test-libzstd.c [new file with mode: 0644]
tools/perf/Makefile.config
tools/perf/Makefile.perf
tools/perf/builtin-version.c

index 8d3864b061f3879c2bb93a8aeffbe8b105863d4b..361207387b1b7efc4f6175af0208514f5cd591a8 100644 (file)
@@ -67,6 +67,7 @@ FEATURE_TESTS_BASIC :=                  \
         sdt                            \
         setns                          \
         libaio                         \
+        libzstd                                \
         disassembler-four-args
 
 # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
@@ -120,6 +121,7 @@ FEATURE_DISPLAY ?=              \
          get_cpuid              \
          bpf                   \
          libaio                        \
+         libzstd               \
          disassembler-four-args
 
 # Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
index 7ceb4441b6277729215ea4ea26193e60d0095f2e..4b8244ee65ce65a8e6b4907db53ee326ee057f92 100644 (file)
@@ -62,7 +62,8 @@ FILES=                                          \
          test-clang.bin                                \
          test-llvm.bin                         \
          test-llvm-version.bin                 \
-         test-libaio.bin
+         test-libaio.bin                       \
+         test-libzstd.bin
 
 FILES := $(addprefix $(OUTPUT),$(FILES))
 
@@ -301,6 +302,9 @@ $(OUTPUT)test-clang.bin:
 $(OUTPUT)test-libaio.bin:
        $(BUILD) -lrt
 
+$(OUTPUT)test-libzstd.bin:
+       $(BUILD) -lzstd
+
 ###############################
 
 clean:
index 7853e6d91090cd7170db0ddc4ba26f2c49108894..a59c537050934b0d4bc9b773a7c2ac826dd01233 100644 (file)
 # include "test-disassembler-four-args.c"
 #undef main
 
+#define main main_test_zstd
+# include "test-libzstd.c"
+#undef main
+
 int main(int argc, char *argv[])
 {
        main_test_libpython();
@@ -224,6 +228,7 @@ int main(int argc, char *argv[])
        main_test_libaio();
        main_test_reallocarray();
        main_test_disassembler_four_args();
+       main_test_libzstd();
 
        return 0;
 }
diff --git a/tools/build/feature/test-libzstd.c b/tools/build/feature/test-libzstd.c
new file mode 100644 (file)
index 0000000..55268c0
--- /dev/null
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <zstd.h>
+
+int main(void)
+{
+       ZSTD_CStream    *cstream;
+
+       cstream = ZSTD_createCStream();
+       ZSTD_freeCStream(cstream);
+
+       return 0;
+}
index fe3f97e342fae6789d09a2fb8cd9a78fe7e72b2b..beb8b48b44e61d0e53e3ca8d1fd4e0e86e2276de 100644 (file)
@@ -152,6 +152,13 @@ endif
 FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
 FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
 
+ifdef LIBZSTD_DIR
+  LIBZSTD_CFLAGS  := -I$(LIBZSTD_DIR)/lib
+  LIBZSTD_LDFLAGS := -L$(LIBZSTD_DIR)/lib
+endif
+FEATURE_CHECK_CFLAGS-libzstd := $(LIBZSTD_CFLAGS)
+FEATURE_CHECK_LDFLAGS-libzstd := $(LIBZSTD_LDFLAGS)
+
 FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi -I$(srctree)/tools/include/uapi
 # include ARCH specific config
 -include $(src-perf)/arch/$(SRCARCH)/Makefile
@@ -787,6 +794,19 @@ ifndef NO_LZMA
   endif
 endif
 
+ifndef NO_LIBZSTD
+  ifeq ($(feature-libzstd), 1)
+    CFLAGS += -DHAVE_ZSTD_SUPPORT
+    CFLAGS += $(LIBZSTD_CFLAGS)
+    LDFLAGS += $(LIBZSTD_LDFLAGS)
+    EXTLIBS += -lzstd
+    $(call detected,CONFIG_ZSTD)
+  else
+    msg := $(warning No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR);
+    NO_LIBZSTD := 1
+  endif
+endif
+
 ifndef NO_BACKTRACE
   ifeq ($(feature-backtrace), 1)
     CFLAGS += -DHAVE_BACKTRACE_SUPPORT
index e8c9f77e9010748fc81695965441439cd15780c5..c706548d5b105088f19e8b319fed0ea592aa291b 100644 (file)
@@ -108,6 +108,9 @@ include ../scripts/utilities.mak
 # streaming for record mode. Currently Posix AIO trace streaming is
 # supported only when linking with glibc.
 #
+# Define NO_LIBZSTD if you do not want support of Zstandard based runtime
+# trace compression in record mode.
+#
 
 # As per kernel Makefile, avoid funny character set dependencies
 unexport LC_ALL
index 50df168be326d84cba4e5cfbc26ea8a119d392cf..f470144d1a7043ecf9fbcc3467d15c6df148b3d1 100644 (file)
@@ -78,6 +78,8 @@ static void library_status(void)
        STATUS(HAVE_LZMA_SUPPORT, lzma);
        STATUS(HAVE_AUXTRACE_SUPPORT, get_cpuid);
        STATUS(HAVE_LIBBPF_SUPPORT, bpf);
+       STATUS(HAVE_AIO_SUPPORT, aio);
+       STATUS(HAVE_ZSTD_SUPPORT, zstd);
 }
 
 int cmd_version(int argc, const char **argv)