aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 776c5e1ef96e80ccd8cdcafb6e7c3c4012f3005d (plain)
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
53
54
55
-include config.mk

VERSION=0.4
GIT_VERSION := $(shell [ -d .git ] && echo "-$$(git describe --always)")

CFLAGS ?= -g
CFLAGS += -DVERSION=\"$(VERSION)$(GIT_VERSION)\"

TARGETS = sircbot sircbot-send

ifneq (NOLUA,)
LUA_VERSION ?= 5.3
LUAPC ?= lua$(LUA_VERSION)
PKGCONFIG ?= pkg-config
TARGETS += lua/$(LUA_VERSION)/sircbot.so
LUA_CFLAGS = $(shell $(PKGCONFIG) --cflags $(LUAPC))
endif

prefix ?= /usr/local
bindir ?= $(prefix)/bin
DESTDIR ?=
LUA_LIBDIR ?= $(prefix)/lib/lua/$(LUA_VERSION)
LUA_LUADIR ?= $(prefix)/share/lua/$(LUA_VERSION)
INSTALL	?= install

all: $(TARGETS)

sircbot: sircbot.o irc.o
	$(CC) $(LDFLAGS) -o $@ $^

sircbot-send: sircbot-send.o
	$(CC) $(LDFLAGS) -o $@ $^

lua/$(LUA_VERSION)/sircbot.so: lua/$(LUA_VERSION)/lsircbot.o
	ln -sf $@ sircbot.so
	$(CC) -shared $(LDFLAGS) -o $@ $^ $(LUA_LIBS)

.c.o:
	$(CC) -fPIC $(CFLAGS) -c $^

lua/$(LUA_VERSION)/%.o: lua/%.c
	mkdir -p "$(dir $@)"
	$(CC) -fPIC $(CFLAGS) $(LUA_CFLAGS) -o $@ -c $^

clean:
	rm -f *.o $(TARGETS) sircbot.so

install: $(TARGETS)
	$(INSTALL) -d $(DESTDIR)$(bindir)
	$(INSTALL) sircbot $(DESTDIR)$(bindir)
	$(INSTALL) sircbot-send $(DESTDIR)$(bindir)

install-lua:
	$(INSTALL) -d $(DESTDIR)$(LUA_LIBDIR)
	$(INSTALL) lua/$(LUA_VERSION)/sircbot.so $(DESTDIR)$(LUA_LIBDIR)