--- ldbus-9f6db626600eb7e04000368da947e0c5cd175fb5.orig/src/Makefile
+++ ldbus-9f6db626600eb7e04000368da947e0c5cd175fb5/src/Makefile
@@ -1,22 +1,33 @@
-LUA_LIBDIR = /usr/local/lib/lua/5.3
+LUA_VERSION ?= 5.3
+LUA_LIBDIR = /usr/local/lib/lua/$(LUA_VERSION)
 
-CFLAGS += -Wall -Wextra --pedantic -Wno-long-long
-CFLAGS += `pkg-config --cflags lua5.3 dbus-1`
-CFLAGS += -fPIC
-CFLAGS += -I ../vendor/compat-5.3/c-api
+O = obj$(LUA_VERSION)
+MY_CFLAGS += $(CFLAGS)
+MY_CFLAGS += -Wall -Wextra --pedantic -Wno-long-long
+MY_CFLAGS += `pkg-config --cflags lua$(LUA_VERSION) dbus-1`
+MY_CFLAGS += -g -fPIC
+MY_CFLAGS += -I ../vendor/compat-5.3/c-api
 
 LIBS = `pkg-config --libs dbus-1`
 
-OBJS = ldbus.o error.o pending_call.o connection.o bus.o message.o message_iter.o timeout.o watch.o ../vendor/compat-5.3/c-api/compat-5.3.o
+OBJS = $(addprefix $(O)/, ldbus.o error.o pending_call.o connection.o bus.o message.o message_iter.o timeout.o watch.o compat-5.3.o)
 
-all:	ldbus.so
+all:	$(O)/ldbus.so
 
-ldbus.so: $(OBJS)
-	$(CC) -o ldbus.so -shared $(CFLAGS) $^ $(LIBS)
+$(O)/compat-5.3.o: ../vendor/compat-5.3/c-api/compat-5.3.c
+	@mkdir -p $(O)
+	$(CC) -c -o $@ $(MY_CFLAGS) $<
 
+$(O)/%.o: %.c
+	@mkdir -p $(O)
+	$(CC) -c -o $@ $(MY_CFLAGS) $<
+
+$(O)/ldbus.so: $(OBJS)
+	$(CC) -o $@ -shared $(MY_CFLAGS) $^ $(LIBS)
+
 clean:
 	rm -f -- ldbus.so $(OBJS)
 
-install: ldbus.so
+install: $(O)/ldbus.so
 	mkdir -p $(LUA_LIBDIR)
-	cp ldbus.so $(LUA_LIBDIR)
+	cp $(O)/ldbus.so $(LUA_LIBDIR)
