Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools build feature: Check if get_current_dir_name() is available

As the namespace support code will use this, which is not available in
some non _GNU_SOURCE libraries such as Android's bionic used in my
container build tests (r12b and r15c at the moment).

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-x56ypm940pwclwu45d7jfj47@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+48
+1
tools/build/Makefile.feature
··· 33 33 dwarf_getlocations \ 34 34 fortify-source \ 35 35 sync-compare-and-swap \ 36 + get_current_dir_name \ 36 37 glibc \ 37 38 gtk2 \ 38 39 gtk2-infobar \
+4
tools/build/feature/Makefile
··· 7 7 test-dwarf_getlocations.bin \ 8 8 test-fortify-source.bin \ 9 9 test-sync-compare-and-swap.bin \ 10 + test-get_current_dir_name.bin \ 10 11 test-glibc.bin \ 11 12 test-gtk2.bin \ 12 13 test-gtk2-infobar.bin \ ··· 101 100 102 101 $(OUTPUT)test-libelf.bin: 103 102 $(BUILD) -lelf 103 + 104 + $(OUTPUT)test-get_current_dir_name.bin: 105 + $(BUILD) 104 106 105 107 $(OUTPUT)test-glibc.bin: 106 108 $(BUILD)
+5
tools/build/feature/test-all.c
··· 34 34 # include "test-libelf-mmap.c" 35 35 #undef main 36 36 37 + #define main main_test_get_current_dir_name 38 + # include "test-get_current_dir_name.c" 39 + #undef main 40 + 37 41 #define main main_test_glibc 38 42 # include "test-glibc.c" 39 43 #undef main ··· 178 174 main_test_hello(); 179 175 main_test_libelf(); 180 176 main_test_libelf_mmap(); 177 + main_test_get_current_dir_name(); 181 178 main_test_glibc(); 182 179 main_test_dwarf(); 183 180 main_test_dwarf_getlocations();
+10
tools/build/feature/test-get_current_dir_name.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #define _GNU_SOURCE 3 + #include <unistd.h> 4 + #include <stdlib.h> 5 + 6 + int main(void) 7 + { 8 + free(get_current_dir_name()); 9 + return 0; 10 + }
+5
tools/perf/Makefile.config
··· 299 299 endif 300 300 endif 301 301 302 + ifeq ($(feature-get_current_dir_name), 1) 303 + CFLAGS += -DHAVE_GET_CURRENT_DIR_NAME 304 + endif 305 + 306 + 302 307 ifdef NO_LIBELF 303 308 NO_DWARF := 1 304 309 NO_DEMANGLE := 1
+1
tools/perf/util/Build
··· 10 10 libperf-y += evsel.o 11 11 libperf-y += evsel_fprintf.o 12 12 libperf-y += find_bit.o 13 + libperf-y += get_current_dir_name.o 13 14 libperf-y += kallsyms.o 14 15 libperf-y += levenshtein.o 15 16 libperf-y += llvm-utils.o
+18
tools/perf/util/get_current_dir_name.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // Copyright (C) 2018, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> 3 + // 4 + #ifndef HAVE_GET_CURRENT_DIR_NAME 5 + #include "util.h" 6 + #include <unistd.h> 7 + #include <stdlib.h> 8 + #include <stdlib.h> 9 + 10 + /* Android's 'bionic' library, for one, doesn't have this */ 11 + 12 + char *get_current_dir_name(void) 13 + { 14 + char pwd[PATH_MAX]; 15 + 16 + return getcwd(pwd, sizeof(pwd)) == NULL ? NULL : strdup(pwd); 17 + } 18 + #endif // HAVE_GET_CURRENT_DIR_NAME
+4
tools/perf/util/util.h
··· 59 59 60 60 const char *perf_tip(const char *dirpath); 61 61 62 + #ifndef HAVE_GET_CURRENT_DIR_NAME 63 + char *get_current_dir_name(void); 64 + #endif 65 + 62 66 #ifndef HAVE_SCHED_GETCPU_SUPPORT 63 67 int sched_getcpu(void); 64 68 #endif