aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: c76415b61d51c1cbcaf35051bbcb47732f695bdc (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
CC=gcc
LIBCFLAGS =-c -fPIC -DBROCCOLI
CFLAGS =-c -DBROCCOLI
INC =-I/usr/local/include -I/usr/local/include -I./includes
LDFLAGS =  -L/usr/local/lib -lbroccoli -pthread
SRC = midbro.c broevent.c fifoqueue.c
OBJ = $(patsubst %.c, build/%.o, $(SRC))

PREFIX = $(DESTDIR)/usr/local

ifneq ($(DEBUG), 1)
	CFLAGS += -O2
	CPPFLAGS += -DNDEBUG
else
	CFLAGS += -g
	CPPFLAGS += -DDEBUG
endif

.PHONY: all dirs clean install uninstall bin/tests

all: dirs lib/libmidbro.so

dirs:
	mkdir -p build bin lib

lib/libmidbro.so: $(OBJ)
	$(CC) -shared $^ -o "$@" $(LDFLAGS)

bin/midbro_test:
	$(CC) test/midbro_test.c -I./includes -o bin/midbro_test -L./lib -lmidbro

build/%.o: src/%.c
	$(CC) $(LIBCFLAGS) $(INC) $< -o $@

bin/tests: build/fifoqueue.o build/tests.o
	$(CC) $^ -o bin/tests $(LDFLAGS)

build/tests.o: test/tests.c
	$(CC) $(CFLAGS) $(INC) $< -o $@

clean:
	rm build/* bin/*

install: lib/libmidbro.so
	mkdir -p "$(PREFIX)/include"
	mkdir -p "$(PREFIX)/lib"
	mkdir -p "$(PREFIX)/share/midbro"
	cp -p includes/midbro.h "$(PREFIX)/include/"
	cp -p lib/libmidbro.so "$(PREFIX)/lib/"
	cp -p script/mid.bro "$(PREFIX)/share/midbro"
	cp -p etc/midbro.service "/etc/systemd/system"

uninstall:
	rm -f "$(PREFIX)/include/midbro.h"
	rm -f "$(PREFIX)/lib/libmidbro.so"