ifeq ($(wildcard $(objdir)/check-deps/clock_without_librt),)
  LDFLAGS_libmcount.so += -lrt
endif

ifneq ($(wildcard $(objdir)/check-deps/cc_has_mfentry),)
  export HAVE_CC_MFENTRY = 1
endif

ifneq ($(wildcard $(objdir)/check-deps/cxa_demangle),)
  COMMON_CFLAGS  += -DHAVE_CXA_DEMANGLE
  COMMON_LDFLAGS += -lstdc++
endif

ifneq ($(wildcard $(objdir)/check-deps/cc_has_mgeneral_regs_only),)
  LIB_CFLAGS += -mgeneral-regs-only
else ifneq ($(wildcard $(objdir)/check-deps/cc_has_mno_sse2),)
  LIB_CFLAGS += -mno-sse -mno-sse2
endif

ifneq ($(wildcard $(objdir)/check-deps/have_libpython3),)
  # libpython3 provides an embed version of pkg-config file since python3.8
  ifeq ($(shell pkg-config python3-embed --exists 2> /dev/null; echo $$?), 0)
    EMBED := -embed
  endif
  COMMON_CFLAGS += -DHAVE_LIBPYTHON3
  COMMON_CFLAGS += $(shell pkg-config python3$(EMBED) --cflags)
  COMMON_CFLAGS += -DLIBPYTHON_VERSION=$(shell pkg-config python3$(EMBED) --modversion)
  PYTHON_LDFLAGS = $(shell pkg-config python3$(EMBED) --libs)
else ifneq ($(wildcard $(objdir)/check-deps/have_libpython2.7),)
  COMMON_CFLAGS += -DHAVE_LIBPYTHON2
  COMMON_CFLAGS += -I/usr/include/python2.7
  COMMON_CFLAGS += -DLIBPYTHON_VERSION="2.7"
  PYTHON_LDFLAGS = -lpython2.7
endif

ifneq ($(wildcard $(objdir)/check-deps/have_libluajit),)
  COMMON_CFLAGS += -DHAVE_LIBLUAJIT
  COMMON_CFLAGS += $(shell pkg-config --cflags luajit)
endif

ifneq ($(wildcard $(objdir)/check-deps/perf_clockid),)
  COMMON_CFLAGS += -DHAVE_PERF_CLOCKID
endif

ifneq ($(wildcard $(objdir)/check-deps/perf_context_switch),)
  COMMON_CFLAGS += -DHAVE_PERF_CTXSW
endif

ifneq ($(wildcard $(objdir)/check-deps/arm_has_hardfp),)
  COMMON_CFLAGS += -DHAVE_ARM_HARDFP
endif

ifneq ($(wildcard $(objdir)/check-deps/have_libncurses),)
  COMMON_CFLAGS   += -DHAVE_LIBNCURSES $(shell pkg-config --cflags ncursesw)
  UFTRACE_LDFLAGS += $(shell pkg-config --libs ncursesw)
  TEST_LDFLAGS    += $(shell pkg-config --libs ncursesw)
endif

ifneq ($(wildcard $(objdir)/check-deps/have_libelf),)
  COMMON_CFLAGS  += -DHAVE_LIBELF
  COMMON_LDFLAGS += -lelf
endif

ifneq ($(wildcard $(objdir)/check-deps/have_libdw),)
  COMMON_CFLAGS  += -DHAVE_LIBDW
  COMMON_CFLAGS  += $(shell pkg-config --cflags libdw 2> /dev/null)
  COMMON_LDFLAGS += $(shell pkg-config --libs libdw 2> /dev/null || echo "-ldw")
endif

ifneq ($(wildcard $(objdir)/check-deps/have_libunwind),)
ifeq ($(DEBUG), 1)
  COMMON_CFLAGS  += -DHAVE_LIBUNWIND
  COMMON_CFLAGS  += $(shell pkg-config --cflags libunwind 2> /dev/null)
  COMMON_LDFLAGS += $(shell pkg-config --libs   libunwind 2> /dev/null)
endif
endif

ifneq ($(wildcard $(objdir)/check-deps/have_libcapstone),)
  COMMON_CFLAGS  += -DHAVE_LIBCAPSTONE
  COMMON_CFLAGS  += $(shell pkg-config --cflags capstone 2> /dev/null)
  COMMON_LDFLAGS += $(shell pkg-config --libs capstone 2> /dev/null)
endif

ifneq ($(wildcard $(objdir)/check-deps/cc_has_minline_all_stringops),)
  LIB_CFLAGS += -minline-all-stringops
endif

ifneq ($(wildcard $(objdir)/check-deps/have_libtraceevent),)
  COMMON_CFLAGS  += -DHAVE_LIBTRACEEVENT
  COMMON_CFLAGS  += $(shell pkg-config --cflags libtraceevent 2> /dev/null)
  COMMON_LDFLAGS += $(shell pkg-config --libs libtraceevent 2> /dev/null)
endif
