diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index a7f6c0669fae..9cc3c48f3288 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -349,7 +349,6 @@ ifeq ($(DEBUG),0)
   endif
 endif
 
-INC_FLAGS += -I$(srctree)/tools/lib/perf/include
 INC_FLAGS += -I$(src-perf)/util/include
 INC_FLAGS += -I$(src-perf)/arch/$(SRCARCH)/include
 INC_FLAGS += -I$(srctree)/tools/include/
@@ -367,7 +366,6 @@ endif
 
 INC_FLAGS += -I$(src-perf)/util
 INC_FLAGS += -I$(src-perf)
-INC_FLAGS += -I$(srctree)/tools/lib/
 
 CORE_CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
 
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 6c1a2a3ccc38..d71e728e7a5c 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -305,6 +305,7 @@ LIBTRACEEVENT_INCLUDE = $(LIBTRACEEVENT_DESTDIR)/include
 LIBTRACEEVENT = $(LIBTRACEEVENT_OUTPUT)/libtraceevent.a
 export LIBTRACEEVENT
 LIBTRACEEVENT_DYNAMIC_LIST = $(LIBTRACEEVENT_PLUGINS_OUTPUT)/libtraceevent-dynamic-list
+CFLAGS += -I$(LIBTRACEEVENT_OUTPUT)/include
 
 #
 # The static build has no dynsym table, so this does not work for
@@ -322,6 +323,13 @@ LIBAPI_DESTDIR = $(LIBAPI_OUTPUT)
 LIBAPI_INCLUDE = $(LIBAPI_DESTDIR)/include
 LIBAPI = $(LIBAPI_OUTPUT)/libapi.a
 export LIBAPI
+CFLAGS += -I$(LIBAPI_OUTPUT)/include
+$(LIBAPI_OUTPUT)/include/api/fs/fs.h \
+$(LIBAPI_OUTPUT)/include/api/fs/tracing_path.h \
+$(LIBAPI_OUTPUT)/include/api/io.h \
+$(LIBAPI_OUTPUT)/include/api/debug.h \
+$(LIBAPI_OUTPUT)/include/api/cpu.h \
+$(LIBAPI_OUTPUT)/include/api/fd/array.h: $(LIBAPI)
 
 ifneq ($(OUTPUT),)
   LIBBPF_OUTPUT = $(abspath $(OUTPUT))/libbpf
@@ -331,6 +339,20 @@ endif
 LIBBPF_DESTDIR = $(LIBBPF_OUTPUT)
 LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include
 LIBBPF = $(LIBBPF_OUTPUT)/libbpf.a
+CFLAGS += -I$(LIBBPF_OUTPUT)/include
+$(LIBBPF_OUTPUT)/include/bpf/bpf_helpers.h \
+$(LIBBPF_OUTPUT)/include/bpf/libbpf_legacy.h \
+$(LIBBPF_OUTPUT)/include/bpf/bpf_tracing.h \
+$(LIBBPF_OUTPUT)/include/bpf/usdt.bpf.h \
+$(LIBBPF_OUTPUT)/include/bpf/bpf_helper_defs.h \
+$(LIBBPF_OUTPUT)/include/bpf/libbpf_common.h \
+$(LIBBPF_OUTPUT)/include/bpf/bpf_core_read.h \
+$(LIBBPF_OUTPUT)/include/bpf/bpf.h \
+$(LIBBPF_OUTPUT)/include/bpf/libbpf.h \
+$(LIBBPF_OUTPUT)/include/bpf/skel_internal.h \
+$(LIBBPF_OUTPUT)/include/bpf/bpf_endian.h \
+$(LIBBPF_OUTPUT)/include/bpf/btf.h \
+$(LIBBPF_OUTPUT)/include/bpf/libbpf_version.h: $(LIBBPF)
 
 ifneq ($(OUTPUT),)
   LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd
@@ -340,6 +362,12 @@ endif
 LIBSUBCMD_DESTDIR = $(LIBSUBCMD_OUTPUT)
 LIBSUBCMD_INCLUDE = $(LIBSUBCMD_DESTDIR)/include
 LIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a
+CFLAGS += -I$(LIBSUBCMD_OUTPUT)/include
+$(LIBSUBCMD_OUTPUT)/include/subcmd/run-command.h \
+$(LIBSUBCMD_OUTPUT)/include/subcmd/exec-cmd.h \
+$(LIBSUBCMD_OUTPUT)/include/subcmd/help.h \
+$(LIBSUBCMD_OUTPUT)/include/subcmd/pager.h \
+$(LIBSUBCMD_OUTPUT)/include/subcmd/parse-options.h : $(LIBSUBCMD)
 
 ifneq ($(OUTPUT),)
   LIBSYMBOL_OUTPUT = $(abspath $(OUTPUT))/libsymbol
@@ -349,6 +377,8 @@ endif
 LIBSYMBOL_DESTDIR = $(LIBSYMBOL_OUTPUT)
 LIBSYMBOL_INCLUDE = $(LIBSYMBOL_DESTDIR)/include
 LIBSYMBOL = $(LIBSYMBOL_OUTPUT)/libsymbol.a
+CFLAGS += -I$(LIBSYMBOL_OUTPUT)/include
+$(LIBSYMBOL_OUTPUT)/symbol/kallsyms.h: $(LIBSYMBOL)
 
 ifneq ($(OUTPUT),)
   LIBPERF_OUTPUT = $(abspath $(OUTPUT))/libperf
@@ -359,6 +389,22 @@ LIBPERF_DESTDIR = $(LIBPERF_OUTPUT)
 LIBPERF_INCLUDE = $(LIBPERF_DESTDIR)/include
 LIBPERF = $(LIBPERF_OUTPUT)/libperf.a
 export LIBPERF
+CFLAGS += -I$(LIBPERF_OUTPUT)/include
+$(LIBPERF_OUTPUT)/include/perf/core.h \
+$(LIBPERF_OUTPUT)/include/perf/mmap.h \
+$(LIBPERF_OUTPUT)/include/perf/evsel.h \
+$(LIBPERF_OUTPUT)/include/perf/evlist.h \
+$(LIBPERF_OUTPUT)/include/perf/bpf_perf.h \
+$(LIBPERF_OUTPUT)/include/perf/event.h \
+$(LIBPERF_OUTPUT)/include/perf/cpumap.h \
+$(LIBPERF_OUTPUT)/include/perf/threadmap.h \
+$(LIBPERF_OUTPUT)/include/internal/mmap.h \
+$(LIBPERF_OUTPUT)/include/internal/evsel.h \
+$(LIBPERF_OUTPUT)/include/internal/lib.h \
+$(LIBPERF_OUTPUT)/include/internal/evlist.h \
+$(LIBPERF_OUTPUT)/include/internal/cpumap.h \
+$(LIBPERF_OUTPUT)/include/internal/xyarray.h \
+$(LIBPERF_OUTPUT)/include/internal/threadmap.h: $(LIBPERF)
 
 # python extension build directories
 PYTHON_EXTBUILD     := $(OUTPUT)python_ext_build/
