-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
103 lines (81 loc) · 3.4 KB
/
Makefile
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
MANDIR ?= $(PREFIX)/share/man
MAN1DIR = $(MANDIR)/man1
MAN5DIR = $(MANDIR)/man5
DOCDIR ?= $(PREFIX)/share/doc/schaufel
INSTALL ?= install -D
PG_CONFIG ?= pg_config
libpq_srcdir := $(shell $(PG_CONFIG) --includedir)
CC ?= gcc
LD = $(CC)
CFLAGS += -Wall -Wextra -pedantic
CFLAGS += -std=c11
CFLAGS += -D_XOPEN_SOURCE=700
CFLAGS += -D_SCHAUFEL_VERSION='"$(SCHAUFEL_VERSION)"'
CFLAGS += -D_GNU_SOURCE
CFLAGS += -I$(libpq_srcdir)
LIB = $(LDFLAGS)
LIB += -lpthread -lhiredis -lrdkafka -lpq -lconfig -ljson-c
INC = -Isrc/
VALGRIND ?= valgrind -q --leak-check=full
OBJDIR = obj
OUT = bin/schaufel
SOURCES = $(wildcard src/*.c) $(wildcard src/utils/*.c) $(wildcard src/hooks/*.c)
TEST_SOURCES = $(wildcard t/*.c)
OBJ = $(patsubst src/%.c, $(OBJDIR)/%.o, $(SOURCES))
OBJ_TEST = $(patsubst $(OBJDIR)/main.o, ,$(OBJ))
OBJ_BIN_TEST = $(patsubst t/%.c, $(OBJDIR)/%.o, $(TEST_SOURCES))
DOCS = $(patsubst man/%, doc/%.pdf , $(wildcard man/*))
SCHAUFEL_VERSION ?= 0.11.1
ARCH = $(shell uname -m)
OS_ID = $(shell cat /etc/os-release | awk -F= '{if ($$1=="ID") print $$2}')
# OS_VERSION_ID = $(shell cat /etc/os-release | awk -F= '{if ($$1=="VERSION_ID") print $$2}')
OS_VERSION_ID_NUMERIC = $(shell cat /etc/os-release | awk -F= '{if ($$1=="VERSION_ID") print $$2}' | tr -d \"\.)
CC_VERSION = $(shell $(CC) -dumpversion | awk -F. '{print $$1}')
# PACKAGE_DEB_DIR = schaufel-$(SCHAUFEL_VERSION)-$(OS_ID)$(OS_VERSION_ID)-$(CC)$(CC_VERSION)-$(ARCH)
PACKAGE_DEB_DIR = schaufel-$(SCHAUFEL_VERSION)-$(CC)$(CC_VERSION)-$(ARCH)
all: release
docs: $(DOCS)
doc/%.pdf: man/*
groff -mandoc -f H -T ps $^ | ps2pdf - $@
release: before_release $(OBJ) out_release
test: clean_release before_release $(OBJ_TEST) $(OBJ_BIN_TEST)
before_release:
mkdir -p obj/utils obj/hooks bin $(PACKAGE_DEB_DIR)
clean: clean_release
clean_release:
rm -f $(OBJ) $(OUT)
rm -rf bin
rm -rf $(OBJDIR)
rm -rf doc/*.pdf
rm -rf $(PACKAGE_DEB_DIR)
out_release: $(OBJ)
$(LD) $(LIBDIR) $(OBJ) $(LIB) -o $(OUT)
$(OBJDIR)/%.o: src/%.c
$(CC) $(INC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/%.o: t/%.c
$(CC) $(INC) $(CFLAGS) -c $< -o $@
$(LD) $(LIBDIR) $(OBJ_TEST) $@ $(LIB) -o bin/$(subst .o, ,$(notdir $@))
$(VALGRIND) bin/$(subst .o, ,$(notdir $@))
install: all
$(INSTALL) bin/schaufel $(DESTDIR)$(BINDIR)/schaufel
$(INSTALL) -m 0644 -t $(DESTDIR)$(DOCDIR) doc/*
$(INSTALL) -m 0644 man/schaufel.1 $(DESTDIR)$(MAN1DIR)/schaufel.1
$(INSTALL) -m 0644 man/schaufel.conf.5 $(DESTDIR)$(MAN5DIR)/schaufel.conf.5
package-deb: all
$(INSTALL) bin/schaufel $(PACKAGE_DEB_DIR)$(DESTDIR)$(BINDIR)/schaufel
$(INSTALL) -m 0644 -t $(PACKAGE_DEB_DIR)$(DESTDIR)$(DOCDIR) doc/*
$(INSTALL) -m 0644 man/schaufel.1 $(PACKAGE_DEB_DIR)$(DESTDIR)$(MAN1DIR)/schaufel.1
$(INSTALL) -m 0644 man/schaufel.conf.5 $(PACKAGE_DEB_DIR)$(DESTDIR)$(MAN5DIR)/schaufel.conf.5
$(INSTALL) -m 0644 -t $(PACKAGE_DEB_DIR)/DEBIAN debian/*
$(INSTALL) -m 0775 debian/postinst $(PACKAGE_DEB_DIR)/DEBIAN/postinst
$(INSTALL) -m 0775 debian/rules $(PACKAGE_DEB_DIR)/DEBIAN/rules
$(INSTALL) -m 0644 ChangeLog $(PACKAGE_DEB_DIR)/DEBIAN/changelog
$(INSTALL) -m 0644 LICENSE $(PACKAGE_DEB_DIR)/DEBIAN/copyright
ln -s DEBIAN $(PACKAGE_DEB_DIR)/debian
cd $(PACKAGE_DEB_DIR) && dpkg-buildpackage --build=binary
cd ../
for _extension in buildinfo changes deb; do \
mv schaufel_${SCHAUFEL_VERSION}_amd64.$${_extension} schaufel_${SCHAUFEL_VERSION}_${OS_ID}${OS_VERSION_ID_NUMERIC}_amd64.$${_extension}; \
done