This repository has been archived by the owner on Feb 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
200 lines (165 loc) · 4.75 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
##
## This is the Makefile for lumail.
##
## It is a little more complex than it should be because of the main requirement
## that we build both "lumail" and "lumail-debug" with the same sources.
##
## Because the debug-version of the code requires different CPPFLAGS we cannot
## just compile once. So instead we must have two object directories; one for each
## set of flags.
##
## To cut down on manual updates though we look for src/*.cc and compile everything
## en mass.
##
## If you're running `ccache` then the overhead of double-compilation
## should be insignificant.
##
## Steve
## --
##
#
# Features which can be compiled in/out
#
FEATURES=-DDOMAIN_SOCKET=1
#
# We've tested compilation with Lua 5.1 and 5.2.
#
LUA_VERSION=5.1
#
# Source + Object + Binary directories
#
SRCDIR = src
RELEASE_OBJDIR = obj.release
DEBUG_OBJDIR = obj.debug
#
# Used solely for building a new release tarball. ("make release").
#
# The version comes from the convention that Steve tags the releases
# with "release-N.N".
#
TMP?=/tmp
BASE=lumail
DIST_PREFIX=${TMP}
VERSION=$(shell sh -c 'git describe --abbrev=0 --tags | tr -d "release-"')
#
# Basics
#
C=gcc
CC=g++
LINKER=$(CC) -o
#
# The name of the library we'll link against differs on different
# systems, which is fun.
#
LVER=lua$(LUA_VERSION)
UNAME := $(shell uname -s)
ifeq ($(UNAME),DragonFly)
LVER=lua-$(LUA_VERSION)
endif
ifeq ($(UNAME),Darwin)
LVER=lua #(use lua-52)
LFLAGS=-std=c++11
endif
#
# Compilation flags and libraries we use.
#
CPPFLAGS+=-std=gnu++0x -Wall -Werror $(shell pkg-config --cflags ${LVER}) $(shell pcre-config --cflags) $(shell pkg-config --cflags ncursesw)
LDLIBS+=$(shell pkg-config --libs ${LVER}) $(shell pkg-config --libs ncursesw) -lpcrecpp
#
# GMime is used for MIME handling.
#
GMIME_LIBS=$(shell pkg-config --libs gmime-2.6)
GMIME_INC=$(shell pkg-config --cflags gmime-2.6)
#
# UTF-8-aware string handling.
#
GLIBMM_LIBS=$(shell pkg-config --libs glibmm-2.4)
GLIBMM_INC=$(shell pkg-config --cflags glibmm-2.4)
#
# Build both targets by default, along with the helper.
#
default: lumail lumail-debug lumailctl
#
# Install all of our binaries, along with the associated help file
#
PREFIX ?= /usr
bindir=${DESTDIR}${PREFIX}/bin/
sharedir=${DESTDIR}${PREFIX}/share/lumail/
install: default
mkdir -p $(sharedir) || true
mkdir -p $(bindir) || true
cp ./lumail.help $(sharedir)
cp ./lumail $(bindir)
cp ./lumailctl $(bindir)
cp ./lumail-debug $(bindir)
chmod 755 $(bindir)/lumail $(bindir)/lumailctl $(bindir)/lumail-debug
#
# Style-check our code
#
.PHONY: style
style:
prove --shuffle ./style/
#
# Make a release
#
release: clean style
rm -rf $(DIST_PREFIX)/$(BASE)-$(VERSION)
rm -f $(DIST_PREFIX)/$(BASE)-$(VERSION).tar.gz
cp -R . $(DIST_PREFIX)/$(BASE)-$(VERSION)
rm -rf $(DIST_PREFIX)/$(BASE)-$(VERSION)/debian
rm -rf $(DIST_PREFIX)/$(BASE)-$(VERSION)/.git*
rm -rf $(DIST_PREFIX)/$(BASE)-$(VERSION)/.depend || true
perl -pi -e "s/__UNRELEASED__/$(VERSION)/g" $(DIST_PREFIX)/$(BASE)-$(VERSION)/src/version.h
perl -pi -e "s/__UNRELEASED__/$(VERSION)/g" $(DIST_PREFIX)/$(BASE)-$(VERSION)/lumail.help
cd $(DIST_PREFIX) && tar -cvf $(DIST_PREFIX)/$(BASE)-$(VERSION).tar $(BASE)-$(VERSION)/
gzip $(DIST_PREFIX)/$(BASE)-$(VERSION).tar
mv $(DIST_PREFIX)/$(BASE)-$(VERSION).tar.gz .
rm -rf $(DIST_PREFIX)/$(BASE)-$(VERSION)
#
# Cleanup
#
clean:
test -d $(RELEASE_OBJDIR) && rm -rf $(RELEASE_OBJDIR) || true
test -d $(DEBUG_OBJDIR) && rm -rf $(DEBUG_OBJDIR) || true
rm -f gmon.out lumail lumail-debug lumailctl core || true
@cd util && make clean || true
#
# Sources + objects.
#
SOURCES := $(wildcard $(SRCDIR)/*.cc)
RELEASE_OBJECTS := $(SOURCES:$(SRCDIR)/%.cc=$(RELEASE_OBJDIR)/%.o)
DEBUG_OBJECTS := $(SOURCES:$(SRCDIR)/%.cc=$(DEBUG_OBJDIR)/%.o)
#
# The release-build.
#
lumail: $(RELEASE_OBJECTS)
$(LINKER) $@ $(LFLAGS) $(RELEASE_OBJECTS) $(LDLIBS) $(GMIME_LIBS) $(GLIBMM_LIBS)
#
# The debug-build.
#
lumail-debug: $(DEBUG_OBJECTS)
$(LINKER) $@ $(LFLAGS) -rdynamic -ggdb -pg $(DEBUG_OBJECTS) $(LDLIBS) $(GMIME_LIBS) $(GLIBMM_LIBS)
#
# The domain-socket helper
#
lumailctl: util/lumailctl.c
$(C) -Wall -Isrc/ util/lumailctl.c -o lumailctl
#
# Build the objects for the release build.
#
$(RELEASE_OBJECTS): $(RELEASE_OBJDIR)/%.o : $(SRCDIR)/%.cc
@mkdir $(RELEASE_OBJDIR) 2>/dev/null || true
$(CC) $(FEATURES) $(CPPFLAGS) $(GMIME_INC) $(GLIBMM_INC) -O2 -c $< -o $@
#
# Build the objects for the debug build.
#
# Just define "LUMAIL_DEBUG=1", otherwise share the flags.
#
$(DEBUG_OBJECTS): $(DEBUG_OBJDIR)/%.o : $(SRCDIR)/%.cc
@mkdir $(DEBUG_OBJDIR) 2>/dev/null || true
$(CC) $(FEATURES) -ggdb -DLUMAIL_DEBUG=1 $(CPPFLAGS) $(GMIME_INC) $(GLIBMM_INC) -O2 -c $< -o $@
#
# Run tests
#
test: lumail
make -C tests LUMAIL=../lumail