summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmil Renner Berthing <esmil@mailme.dk>2011-03-11 12:15:30 +0100
committerEmil Renner Berthing <esmil@mailme.dk>2011-03-11 13:35:51 +0100
commita646b691b54cdb44fd404ab1a1332ee1bc8d7d25 (patch)
tree2eca04100deb9cdb523576230ba5caeb0977aac4
parent3a4878e7e6aa8b973497c28eec6104be89a7c00d (diff)
downloadlem-postgres-a646b691b54cdb44fd404ab1a1332ee1bc8d7d25.tar.gz
lem-postgres-a646b691b54cdb44fd404ab1a1332ee1bc8d7d25.tar.xz
lem-postgres-a646b691b54cdb44fd404ab1a1332ee1bc8d7d25.zip
Makefile: use pkg-config
-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)