From bc525acebe8dbe4ec89e73703906b46fa6206d89 Mon Sep 17 00:00:00 2001 From: Emil Renner Berthing Date: Fri, 6 Jan 2012 17:54:40 +0100 Subject: update for LEM 0.3 --- Makefile | 87 ++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 46 insertions(+), 41 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 978ac73..58305c6 100644 --- a/Makefile +++ b/Makefile @@ -1,57 +1,62 @@ -CC = gcc -CFLAGS ?= -O2 -pipe -Wall -Wextra -Wno-variadic-macros -Wno-strict-aliasing -PKGCONFIG = pkg-config +CC = gcc -std=gnu99 +CFLAGS ?= -O2 -pipe -Wall -Wextra +PKG_CONFIG = pkg-config +PG_CONFIG = pg_config STRIP = strip INSTALL = install +UNAME = uname + +OS = $(shell $(UNAME)) +CFLAGS += $(shell $(PKG_CONFIG) --cflags lem) +lmoddir = $(shell $(PKG_CONFIG) --variable=INSTALL_LMOD lem) +cmoddir = $(shell $(PKG_CONFIG) --variable=INSTALL_CMOD lem) + +ifeq ($(OS),Darwin) +SHARED = -dynamiclib -Wl,-undefined,dynamic_lookup +STRIP += -x +else +SHARED = -shared +endif -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 +llibs = lem/postgres/queued.lua +clibs = lem/postgres.so -ifdef NDEBUG -CFLAGS += -DNDEBUG +ifdef V +E=@\# +Q= +else +E=@echo +Q=@ endif -.PHONY: all strip install clean -.PRECIOUS: %.o +.PHONY: all debug strip install clean -all: $(programs) +all: CFLAGS += -DNDEBUG +all: $(clibs) -%.o: %.c - @echo ' CC $@' - @$(CC) $(CFLAGS) -fPIC -nostartfiles -c $< -o $@ +debug: $(clibs) -postgres.so: CFLAGS += -I$(shell pg_config --includedir) -postgres.so: postgres.o - @echo ' LD $@' - @$(CC) -shared -L$(shell pg_config --libdir) -lpq $(LDFLAGS) $^ -o $@ +lem/postgres.so: CFLAGS += -I$(shell $(PG_CONFIG) --includedir) +lem/postgres.so: LDFLAGS += -L$(shell $(PG_CONFIG) --libdir) +lem/postgres.so: LIBS += -lpq +lem/postgres.so: lem/postgres.c + $E ' CCLD $@' + $Q$(CC) $(CFLAGS) -fPIC -nostartfiles $(SHARED) $^ -o $@ $(LDFLAGS) $(LIBS) %-strip: % - @echo ' STRIP $<' - @$(STRIP) $< - -strip: $(programs:%=%-strip) - -path-install: - @echo " INSTALL -d $(LUA_PATH)/lem/postgres" - @$(INSTALL) -d $(DESTDIR)$(LUA_PATH)/lem/postgres - -%.lua-install: %.lua path-install - @echo " INSTALL $<" - @$(INSTALL) -m644 $< $(DESTDIR)$(LUA_PATH)/lem/postgres/$< + $E ' STRIP $<' + $Q$(STRIP) $< -cpath-install: - @echo " INSTALL -d $(LUA_CPATH)/lem" - @$(INSTALL) -d $(DESTDIR)$(LUA_CPATH)/lem +strip: $(clibs:%=%-strip) -%.so-install: %.so cpath-install - @echo " INSTALL $<" - @$(INSTALL) $< $(DESTDIR)$(LUA_CPATH)/lem/$< +$(DESTDIR)$(lmoddir)/% $(DESTDIR)$(cmoddir)/%: % + $E ' INSTALL $@' + $Q$(INSTALL) -d $(dir $@) + $Q$(INSTALL) -m 644 $< $@ -install: $(programs:%=%-install) $(scripts:%=%-install) +install: \ + $(llibs:%=$(DESTDIR)$(lmoddir)/%) \ + $(clibs:%=$(DESTDIR)$(cmoddir)/%) clean: - rm -f $(programs) *.o *.c~ *.h~ + rm -f $(clibs) -- cgit v1.2.1