-LIBDIVECOMPUTERDIR = /usr/local
-LIBDIVECOMPUTERINCLUDES = $(LIBDIVECOMPUTERDIR)/include/libdivecomputer
-LIBDIVECOMPUTERARCHIVE = $(LIBDIVECOMPUTERDIR)/lib/libdivecomputer.a
+ifneq ($(strip $(libdc-local)),)
+ LIBDIVECOMPUTERDIR = /usr/local
+ LIBDIVECOMPUTERINCLUDES = $(LIBDIVECOMPUTERDIR)/include/libdivecomputer
+ LIBDIVECOMPUTERARCHIVE = -L$(LIBDIVECOMPUTERDIR)/lib -ldivecomputer
+else ifneq ($(strip $(libdc-usr)),)
+ LIBDIVECOMPUTERDIR = /usr
+ LIBDIVECOMPUTERINCLUDES = $(LIBDIVECOMPUTERDIR)/include/libdivecomputer
+ LIBDIVECOMPUTERARCHIVE = -ldivecomputer
+else
+$(error Cannot find libdivecomputer - please edit Makefile)
+endif
+
+# Libusb-1.0 is only required if libdivecomputer was built with it.
+# And libdivecomputer is only built with it if libusb-1.0 is
+# installed. So get libusb if it exists, but don't complain
+# about it if it doesn't.
+LIBUSB = $(shell pkg-config --libs libusb-1.0 2> /dev/null)
+
+LIBXML2 = $(shell xml2-config --libs)
+LIBGTK = $(shell pkg-config --libs gtk+-2.0 glib-2.0 gconf-2.0)
+LIBDIVECOMPUTER = $(LIBDIVECOMPUTERARCHIVE) $(LIBUSB)
+
+LIBS = $(LIBXML2) $(LIBGTK) $(LIBDIVECOMPUTER) -lpthread