summaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile45
1 files changed, 25 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index ca0b6b5..978ac73 100644
--- a/Makefile
+++ b/Makefile
@@ -1,32 +1,33 @@
-CC = gcc
-CFLAGS ?= -O2 -pipe -Wall -Wextra -Wno-variadic-macros -Wno-strict-aliasing -I$(shell pg_config --includedir)
-LDFLAGS ?= -L$(shell pg_config --libdir)
-STRIP = strip
-INSTALL = install
+CC = gcc
+CFLAGS ?= -O2 -pipe -Wall -Wextra -Wno-variadic-macros -Wno-strict-aliasing
+PKGCONFIG = pkg-config
+STRIP = strip
+INSTALL = install
-LUA_VERSION = 5.1
-PREFIX = /usr/local
-LIBDIR = $(PREFIX)/lib/lua/$(LUA_VERSION)/lem
+CFLAGS += $(shell $(PKGCONFIG) --cflags lem)
+LUA_PATH = $(shell $(PKGCONFIG) --variable=path lem)
+LUA_CPATH = $(shell $(PKGCONFIG) --variable=cpath lem)
programs = postgres.so
scripts = queued.lua
ifdef NDEBUG
-DEFINES+=-DNDEBUG
+CFLAGS += -DNDEBUG
endif
-.PHONY: all strip install indent clean
+.PHONY: all strip install clean
.PRECIOUS: %.o
all: $(programs)
%.o: %.c
@echo ' CC $@'
- @$(CC) $(CFLAGS) -I$(PREFIX)/include -fPIC -nostartfiles $(DEFINES) -c $< -o $@
+ @$(CC) $(CFLAGS) -fPIC -nostartfiles -c $< -o $@
-%.so: %.o
+postgres.so: CFLAGS += -I$(shell pg_config --includedir)
+postgres.so: postgres.o
@echo ' LD $@'
- @$(CC) -shared -lpq $(LDFLAGS) $^ -o $@
+ @$(CC) -shared -L$(shell pg_config --libdir) -lpq $(LDFLAGS) $^ -o $@
%-strip: %
@echo ' STRIP $<'
@@ -34,17 +35,21 @@ all: $(programs)
strip: $(programs:%=%-strip)
-libdir-install:
- @echo " INSTALL -d $(LIBDIR)"
- @$(INSTALL) -d $(DESTDIR)$(LIBDIR)/postgres
+path-install:
+ @echo " INSTALL -d $(LUA_PATH)/lem/postgres"
+ @$(INSTALL) -d $(DESTDIR)$(LUA_PATH)/lem/postgres
-%.lua-install: %.lua libdir-install
+%.lua-install: %.lua path-install
@echo " INSTALL $<"
- @$(INSTALL) $< $(DESTDIR)$(LIBDIR)/postgres/$<
+ @$(INSTALL) -m644 $< $(DESTDIR)$(LUA_PATH)/lem/postgres/$<
-%.so-install: %.so libdir-install
+cpath-install:
+ @echo " INSTALL -d $(LUA_CPATH)/lem"
+ @$(INSTALL) -d $(DESTDIR)$(LUA_CPATH)/lem
+
+%.so-install: %.so cpath-install
@echo " INSTALL $<"
- @$(INSTALL) $< $(DESTDIR)$(LIBDIR)/$<
+ @$(INSTALL) $< $(DESTDIR)$(LUA_CPATH)/lem/$<
install: $(programs:%=%-install) $(scripts:%=%-install)