@@ -37,6 +37,10 @@ endef
$(call allow-override,CC,$(CROSS_COMPILE)gcc)
$(call allow-override,AR,$(CROSS_COMPILE)ar)
$(call allow-override,PKG_CONFIG,pkg-config)
+$(call allow-override,LD_SO_CONF_PATH,/etc/ld.so.conf.d/)
+$(call allow-override,LDCONFIG,ldconfig)
+
+export LD_SO_CONF_PATH LDCONFIG
EXT = -std=gnu99
INSTALL = install
@@ -76,7 +80,7 @@ etcdir ?= /etc
etcdir_SQ = '$(subst ','\'',$(etcdir))'
export man_dir man_dir_SQ html_install html_install_SQ INSTALL
-export img_install img_install_SQ libdir_SQ includedir_SQ
+export img_install img_install_SQ libdir libdir_SQ includedir_SQ
export DESTDIR DESTDIR_SQ
ifeq ($(prefix),$(HOME))
@@ -3,6 +3,7 @@
include $(src)/scripts/utils.mk
bdir:=$(obj)/lib/trace-cmd
+ldir:=$(src)/lib/trace-cmd
DEFAULT_TARGET = $(LIBTRACECMD_STATIC)
@@ -59,11 +60,36 @@ $(DEPS): $(bdir)/.%.d: %.c
$(OBJS): $(bdir)/%.o : $(bdir)/.%.d
+ifeq ("$(DESTDIR)", "")
+# If DESTDIR is not defined, then test if after installing the library
+# and running ldconfig, if the library is visible by ld.so.
+# If not, add the path to /etc/ld.so.conf.d/trace.conf and run ldconfig again.
+define install_ld_config
+ $(LDCONFIG); \
+ if ! grep "^$(libdir)$$" $(LD_SO_CONF_PATH)/* &> /dev/null ; then \
+ $(CC) -o $(bdir)/test $(ldir)/test.c -I $(includedir_SQ) \
+ -L $(libdir_SQ) -ltracecmd > /dev/null; \
+ if ! $(bdir)/test &> /dev/null; then \
+ $(call print_install,trace.conf,$(LD_SO_CONF_PATH)) \
+ echo $(libdir_SQ) >> $(LD_SO_CONF_PATH)/trace.conf; \
+ $(LDCONFIG); \
+ fi; \
+ $(RM) $(bdir)/test; \
+ fi
+endef
+else
+# If installing to a location for another machine or package, do not bother
+# with running ldconfig.
+define install_ld_config
+endef
+endif # DESTDIR = ""
+
install_libs:
$(Q)$(call do_install,$(LIBTRACECMD_SHARED),$(libdir_SQ))
cp -fpR $(LIBTRACECMD_SHARED_VERSION) $(DESTDIR)$(libdir_SQ)
cp -fpR $(LIBTRACECMD_SHARED_SO) $(DESTDIR)$(libdir_SQ)
$(Q)$(call do_install,$(src)/include/trace-cmd/trace-cmd.h,$(includedir_SQ)/trace-cmd)
+ $(Q)$(call install_ld_config)
dep_includes := $(wildcard $(DEPS))
new file mode 100644
@@ -0,0 +1,7 @@
+#include <trace-cmd/trace-cmd.h>
+
+int main()
+{
+ tracecmd_open_head("trace.dat");
+ return 0;
+}