summarylogtreecommitdiffstats
path: root/Makefile.replace
blob: ff5794cd11919e890f58001ab5fc91e15d56d2e5 (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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#
# This is the Makefile for compiling lumail2.
#
# It is tested to work upon Linux and Mac OS X, and may well work
# upon other systems.
#
# The main configuration you'll need to look at here is the version
# of Lua which you're compiling against.  We assume 5.2, but will support
# 5.1 too.
#
# If you struggle to compile this on a "common" system please do report
# a bug against the project:
#
#   https://github.com/lumail/lumail2
#
#
# Steve
# --
#
#


#
# The version of our code.
#
VERSION=2.8

#
# Install locations
#
DESTDIR?=
PREFIX?=/usr
SYSCONFDIR?=/etc
LUMAIL_HOME?=$(DESTDIR)$(SYSCONFDIR)/lumail2

#
# Load the flags if they're not already set - first look at the version
#
LUA_VERSION?=5.2
LVER?=lua$(LUA_VERSION)
UNAME := $(shell uname -s)
ifeq ($(UNAME),DragonFly)
	LVER=lua-$(LUA_VERSION)
endif
ifeq ($(UNAME),Darwin)
	LVER=lua #(use lua-52)
endif

#
# To ensure make finds the ncursesw.h header file,
# you may need to invoke it like this:
#   PKG_CONFIG_PATH=/usr/local/Cellar/ncurses/6.0_1/lib/pkgconfig make
# PKG_CONFIG_PATH should point to a directory containing a file
# named ncursesw.pc)
#
ifeq ($(UNAME),Darwin)
   C=clang
   CC=clang++
   CPPFLAGS+=-I /usr/include/malloc
endif

#
# Now we know the version of Lua we'll setup the flags here.
#
LUA_FLAGS ?= $(shell pkg-config --cflags ${LVER})
LUA_LIBS  ?= $(shell pkg-config --libs ${LVER})


#
# If you prefer you can use a manual set of flags, explicitly.
#
# This is useful for testing against local versions of Lua.
#
# If these lines are commented-out then we'll discover them dynamically
# via `pkg-config` setup above.
#
# LUA_FLAGS=-I/home/steve/Downloads/lua-5.3.2/src
# LUA_LIBS=-L/home/steve/Downloads/lua-5.3.2/install/lib -llua -ldl
#

#
# Finally if we prefer we can use luajit, via one of these options:
#
### Locally compiled version of luajit.
#LUA_FLAGS=-I/tmp/luajit/include/luajit-2.1/
#LUA_LIBS=-L/tmp/luajit/lib/ -lluajit-5.1
#
### Debian packaged-version of luajit.
#LUA_FLAGS = $(shell pkg-config --cflags luajit)
#LUA_LIBS  = $(shell pkg-config --libs luajit)



#
#  Source + Object + Binary directories
#
SRCDIR         = src
RELEASE_OBJDIR = obj.release
DEBUG_OBJDIR   = obj.debug


#
#  Basics
#
CC?=g++
LINKER=$(CC) -o



#
# Compilation flags and libraries we use.
#
CPPFLAGS+=${LUA_FLAGS} -std=c++0x -Wall -Werror  $(shell pcre-config --cflags) $(shell pkg-config --cflags ncursesw) -DLUMAIL_VERSION="\"${VERSION}\""
LDLIBS+=${LUA_LIBS} $(shell pkg-config --libs ncursesw) $(shell pkg-config --libs panelw) -lpcrecpp -lmagic -ldl -lstdc++ -lm

#
#  GMime is used for MIME handling.
#
GMIME_LIBS=$(shell pkg-config --libs  gmime-2.6)
GMIME_INC=$(shell pkg-config --cflags gmime-2.6)

#
#  Only build the release-target by default.
#
default: lumail2


#
#  Cleanup
#
clean:
	test -d docs/              && rm -rf docs              || true
	test -d $(RELEASE_OBJDIR)  && rm -rf $(RELEASE_OBJDIR) || true
	test -d $(DEBUG_OBJDIR)    && rm -rf $(DEBUG_OBJDIR)   || true
	rm -f gmon.out lumail2 lumail2-debug core              || true
	find . -name '*.orig' -delete                          || 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.
#
lumail2: $(RELEASE_OBJECTS)
	$(LINKER) $@ $(LFLAGS) $(RELEASE_OBJECTS) $(LDLIBS) $(GMIME_LIBS)

#
#  The debug-build.
#
lumail2-debug: $(DEBUG_OBJECTS)
	$(LINKER) $@ $(LFLAGS) -rdynamic -ggdb -pg $(DEBUG_OBJECTS) $(LDLIBS) $(GMIME_LIBS)


#
#  Build the objects for the release build.
#
$(RELEASE_OBJECTS): $(RELEASE_OBJDIR)/%.o : $(SRCDIR)/%.cc
	@mkdir $(RELEASE_OBJDIR) 2>/dev/null || true
	$(CC) $(CPPFLAGS) $(GMIME_INC) -O2 -c $< -o $@

#
#  Build the objects for the debug build - which has an extra definition and
# a different object directory.
#
$(DEBUG_OBJECTS): $(DEBUG_OBJDIR)/%.o : $(SRCDIR)/%.cc
	@mkdir $(DEBUG_OBJDIR) 2>/dev/null || true
	$(CC) -ggdb -DDEBUG=1 $(CPPFLAGS) $(GMIME_INC) -O2 -c $< -o $@


#
# Indent our C++ code in a consistent-style
#
.PHONY: indent
indent:
	astyle --style=allman -A1 --indent=spaces=4   --break-blocks --pad-oper --pad-header --unpad-paren --max-code-length=200 $(SRCDIR)/*.cc $(SRCDIR)/*.h


#
# Rebuild our (code) documentation.
#
.PHONY: docs
docs:
	doxygen

#
# Serve our documentation via a local python HTTP-server.
#
.PHONY: serve_docs
serve_docs: docs
	echo "Visit http://127.0.0.1:8000/"
	cd docs/html && python -m SimpleHTTPServer


#
# Run our test-cases, from the main binary.
#
test: lumail2
	./lumail2 --test


#
#  Install the binary, and our luarocks.d directory
#
install: lumail2
	mkdir -p $(DESTDIR)$(PREFIX)/bin || true
	install -m755 lumail2 $(DESTDIR)$(PREFIX)/bin/

    # make target-directories
	mkdir -p $(LUMAIL_HOME)/lib/  || true
	mkdir -p $(LUMAIL_HOME)/perl.d/  || true

    # copy our helpers
	cp lib/*.lua $(LUMAIL_HOME)/lib/
	cp perl.d/* $(LUMAIL_HOME)/perl.d/

    # cleanup old installs
	rm $(LUMAIL_HOME)/perl.d/delete-message || true
	rm $(LUMAIL_HOME)/perl.d/get-folders || true
	rm $(LUMAIL_HOME)/perl.d/get-messages || true
	rm $(LUMAIL_HOME)/perl.d/save-message || true
	rm $(LUMAIL_HOME)/perl.d/set-flags || true

    # if there is no config in-place, add the default
	if [ ! -e $(LUMAIL_HOME)/lumail2.lua ] ; then cp ./lumail2.lua $(LUMAIL_HOME)/lumail2.lua ; fi