summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: ca0b6b52e9803303a7337bdf797e6a971b06e95e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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

LUA_VERSION = 5.1
PREFIX      = /usr/local
LIBDIR      = $(PREFIX)/lib/lua/$(LUA_VERSION)/lem

programs = postgres.so
scripts  = queued.lua

ifdef NDEBUG
DEFINES+=-DNDEBUG
endif

.PHONY: all strip install indent clean
.PRECIOUS: %.o

all: $(programs)

%.o: %.c
	@echo '  CC $@'
	@$(CC) $(CFLAGS) -I$(PREFIX)/include -fPIC -nostartfiles $(DEFINES) -c $< -o $@

%.so: %.o
	@echo '  LD $@'
	@$(CC) -shared -lpq $(LDFLAGS) $^ -o $@

%-strip: %
	@echo '  STRIP $<'
	@$(STRIP) $<

strip: $(programs:%=%-strip)

libdir-install:
	@echo "  INSTALL -d $(LIBDIR)"
	@$(INSTALL) -d $(DESTDIR)$(LIBDIR)/postgres

%.lua-install: %.lua libdir-install
	@echo "  INSTALL $<"
	@$(INSTALL) $< $(DESTDIR)$(LIBDIR)/postgres/$<

%.so-install: %.so libdir-install
	@echo "  INSTALL $<"
	@$(INSTALL) $< $(DESTDIR)$(LIBDIR)/$<

install: $(programs:%=%-install) $(scripts:%=%-install)

clean:
	rm -f $(programs) *.o *.c~ *.h~