-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
305 lines (232 loc) · 7.76 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
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# Copyright (c) 2016 Robert Virding
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Makefile for LFE
BINDIR = bin
EBINDIR = ebin
SRCDIR = src
CSRCDIR = c_src
LSRCDIR = src
INCDIR = include
EMACSDIR = emacs
PREFIX ?= /usr/local
INSTALL = install
INSTALL_DIR = $(INSTALL) -m755 -d
INSTALL_DATA = $(INSTALL) -m644
INSTALL_BIN = $(INSTALL) -m755
DESTLIBDIR := $(PREFIX)/lib/lfe
DESTEBINDIR := $(DESTLIBDIR)/$(EBINDIR)
DESTBINDIR := $(DESTLIBDIR)/$(BINDIR)
VPATH = $(SRCDIR)
MANDB = $(shell which mandb)
ERLCFLAGS = -W1 +debug_info
ERLC = erlc
LFECFLAGS = -pa ../lfe +debug-info
LFEC = $(BINDIR)/lfe $(BINDIR)/lfec
APP_DEF = lfe.app
LIB=lfe
# To run erl as bash
FINISH=-run init stop -noshell
# Scripts to be evaluated
GET_VERSION = '{ok,[App]}=file:consult("src/$(LIB).app.src"), \
V=proplists:get_value(vsn,element(3,App)), \
io:format("~p~n",[V])' \
$(FINISH)
## The .erl, .xrl, .yrl and .beam files
ESRCS = $(notdir $(wildcard $(SRCDIR)/*.erl))
XSRCS = $(notdir $(wildcard $(SRCDIR)/*.xrl))
YSRCS = $(notdir $(wildcard $(SRCDIR)/*.yrl))
LSRCS = $(notdir $(wildcard $(LSRCDIR)/*.lfe))
EBINS = $(ESRCS:.erl=.beam) $(XSRCS:.xrl=.beam) $(YSRCS:.yrl=.beam)
LBINS = $(LSRCS:.lfe=.beam)
CSRCS = $(notdir $(wildcard $(CSRCDIR)/*.c))
BINS = $(CSRCS:.c=)
EMACSRCS = $(notdir $(wildcard $(EMACSDIR)/*.el))
ELCS = $(EMACSRCS:.el=.elc)
.SUFFIXES: .erl .beam
$(BINDIR)/%: $(CSRCDIR)/%.c
cc -o $@ $<
$(EBINDIR)/%.beam: $(SRCDIR)/%.erl
@$(INSTALL_DIR) $(EBINDIR)
$(ERLC) -I $(INCDIR) -o $(EBINDIR) $(COMP_OPTS) $(ERLCFLAGS) $<
%.erl: %.xrl
$(ERLC) -o $(SRCDIR) $<
%.erl: %.yrl
$(ERLC) -o $(SRCDIR) $<
$(EBINDIR)/%.beam: $(LSRCDIR)/%.lfe
$(LFEC) -I $(INCDIR) -o $(EBINDIR) $(LFECFLAGS) $<
all: compile
.PHONY: compile erlc-compile lfec-compile erlc-lfec emacs install install-beam install-bin install-man docs clean docker-build docker-push docker update-mandb
compile: comp_opts.mk
$(MAKE) $(MFLAGS) erlc-lfec
## Compile Erlang files using erlc
erlc-compile: $(addprefix $(EBINDIR)/, $(EBINS)) $(addprefix $(BINDIR)/, $(BINS))
## Compile LFE files using lfec
lfec-compile: $(addprefix $(EBINDIR)/, $(LBINS))
$(addprefix $(EBINDIR)/, $(LBINS)): $(addprefix $(EBINDIR)/, $(EBINS))
$(EBINDIR)/$(APP_DEF): $(SRCDIR)/$(APP_DEF).src
cp $(SRCDIR)/$(APP_DEF).src $(EBINDIR)/$(APP_DEF)
## Compile Erlang files using erlc and LFE files using lfec
erlc-lfec: erlc-compile $(EBINDIR)/$(APP_DEF) lfec-compile
emacs:
cd $(EMACSDIR) ; \
emacs -L . -batch -f batch-byte-compile inferior-lfe.el lfe-mode.el lfe-indent.el
comp_opts.mk:
escript get_comp_opts.escript
-include comp_opts.mk
install: compile install-beam install-bin install-man
install-beam:
rm -Rf $(DESTEBINDIR)
$(INSTALL_DIR) $(DESTEBINDIR)
$(INSTALL_DATA) \
$(EBINDIR)/$(APP_DEF) \
$(addprefix $(EBINDIR)/, $(EBINS)) \
$(addprefix $(EBINDIR)/, $(LBINS)) \
$(DESTEBINDIR)
install-bin:
$(INSTALL_DIR) $(DESTBINDIR)
$(INSTALL_BIN) \
$(BINDIR)/lfe \
$(BINDIR)/lfec \
$(BINDIR)/lfedoc \
$(BINDIR)/lfescript \
$(DESTBINDIR)
$(INSTALL_DIR) $(PREFIX)/bin
ln -sf $(DESTBINDIR)/* $(PREFIX)/bin/
clean:
rm -rf $(EBINDIR)/*.beam erl_crash.dump comp_opts.mk
echo:
@ echo $(ESRCS)
@ echo $(XSRCS)
@ echo $(YSRCS)
@ echo $(EBINS)
get-version:
@echo
@echo "Getting version info ..."
@echo
@echo -n app.src: ''
@erl -eval $(GET_VERSION)
# Target to regenerate the src/lfe_parse.erl file from its original
# src/lfe_parse.spell1 definition. You will need to have spell1
# installed somewhere in your $ERL_LIBS path.
regenerate-parser:
erl -noshell -eval 'spell1:file("src/lfe_parse", [report,verbose,{outdir,"./src/"},{includefile,code:lib_dir(spell1,include) ++ "/spell1inc.hrl"}]), init:stop().'
# Targets for generating docs and man pages
DOCDIR = doc
DOCSRC = $(DOCDIR)/src
MANDIR = $(DOCDIR)/man
PDFDIR = $(DOCDIR)/pdf
EPUBDIR = $(DOCDIR)/epub
MANINSTDIR ?= $(PREFIX)/share/man
MAN1_SRCS = $(notdir $(wildcard $(DOCSRC)/*1.md))
MAN1S = $(MAN1_SRCS:.1.md=.1)
TXT1S = $(MAN1_SRCS:.1.md=.txt)
PDF1S = $(MAN1_SRCS:.1.md=.pdf)
EPUB1S = $(MAN1_SRCS:.1.md=.epub)
MAN3_SRCS = $(notdir $(wildcard $(DOCSRC)/*3.md))
MAN3S = $(MAN3_SRCS:.3.md=.3)
TXT3S = $(MAN3_SRCS:.3.md=.txt)
PDF3S = $(MAN3_SRCS:.3.md=.pdf)
EPUB3S = $(MAN3_SRCS:.3.md=.epub)
MAN7_SRCS = $(notdir $(wildcard $(DOCSRC)/*7.md))
MAN7S = $(MAN7_SRCS:.7.md=.7)
TXT7S = $(MAN7_SRCS:.7.md=.txt)
PDF7S = $(MAN7_SRCS:.7.md=.pdf)
EPUB7S = $(MAN7_SRCS:.7.md=.epub)
# Just generate the docs that are tracked in git
docs: docs-txt
# Generate all docs, even those not tracked in git
docs-all: docs docs-epub docs-pdf
docs-man: \
$(addprefix $(MANDIR)/, $(MAN1S)) \
$(addprefix $(MANDIR)/, $(MAN3S)) \
$(addprefix $(MANDIR)/, $(MAN7S))
$(MANDIR)/%.1: $(DOCSRC)/%.1.md
pandoc -f markdown -s -t man -o $@ $<
$(MANDIR)/%.3: $(DOCSRC)/%.3.md
pandoc -f markdown -s -t man -o $@ $<
$(MANDIR)/%.7: $(DOCSRC)/%.7.md
pandoc -f markdown -s -t man -o $@ $<
clean-docs:
rm -f $(DOCDIR)/*.txt $(MANDIR)/*.[0-9] $(PDFDIR)/*.pdf $(EPUBDIR)/*.epub
docs-txt: docs-man \
$(addprefix $(DOCDIR)/, $(TXT1S)) \
$(addprefix $(DOCDIR)/, $(TXT3S)) \
$(addprefix $(DOCDIR)/, $(TXT7S))
@if [ -f $(DOCDIR)/lfe_guide.txt ]; then \
cp $(DOCDIR)/lfe_guide.txt $(DOCDIR)/user_guide.txt ; \
fi
$(DOCDIR)/%.txt: export GROFF_NO_SGR=1
$(DOCDIR)/%.txt: $(MANDIR)/%.1
groff -t -e -mandoc -Tutf8 -Kutf8 $< | col -bx > $@
$(DOCDIR)/%.txt: $(MANDIR)/%.3
groff -t -e -mandoc -Tutf8 -Kutf8 $< | col -bx > $@
$(DOCDIR)/%.txt: $(MANDIR)/%.7
groff -t -e -mandoc -Tutf8 -Kutf8 $< | col -bx > $@
$(PDFDIR):
@$(INSTALL_DIR) $(PDFDIR)
docs-pdf: $(PDFDIR) \
$(addprefix $(PDFDIR)/, $(PDF1S)) \
$(addprefix $(PDFDIR)/, $(PDF3S)) \
$(addprefix $(PDFDIR)/, $(PDF7S))
$(PDFDIR)/%.pdf: $(DOCSRC)/%.1.md
pandoc -f markdown --latex-engine=xelatex -o $@ $<
$(PDFDIR)/%.pdf: $(DOCSRC)/%.3.md
pandoc -f markdown --latex-engine=xelatex -o $@ $<
$(PDFDIR)/%.pdf: $(DOCSRC)/%.7.md
pandoc -f markdown --latex-engine=xelatex -o $@ $<
$(EPUBDIR):
@$(INSTALL_DIR) $(EPUBDIR)
docs-epub: $(EPUBDIR) \
$(addprefix $(EPUBDIR)/, $(EPUB1S)) \
$(addprefix $(EPUBDIR)/, $(EPUB3S)) \
$(addprefix $(EPUBDIR)/, $(EPUB7S))
$(EPUBDIR)/%.epub: $(DOCSRC)/%.1.md
pandoc -f markdown -t epub -o $@ $<
$(EPUBDIR)/%.epub: $(DOCSRC)/%.3.md
pandoc -f markdown -t epub -o $@ $<
$(EPUBDIR)/%.epub: $(DOCSRC)/%.7.md
pandoc -f markdown -t epub -o $@ $<
$(MANINSTDIR)/man%:
@$(INSTALL_DIR) $@
ifeq (,$(findstring mandb,$(MANDB)))
install-man: $(MANINSTDIR)/man1 $(MANINSTDIR)/man3 $(MANINSTDIR)/man7
else
install-man: $(MANINSTDIR)/man1 $(MANINSTDIR)/man3 $(MANINSTDIR)/man7 update-mandb
endif
$(INSTALL_DATA) $(MANDIR)/*.1 $(MANINSTDIR)/man1/
$(INSTALL_DATA) $(MANDIR)/*.3 $(MANINSTDIR)/man3/
$(INSTALL_DATA) $(MANDIR)/*.7 $(MANINSTDIR)/man7/
update-mandb:
@echo "Updating man page database ..."
$(MANDB) $(MANINSTDIR)
# Targets for working with Docker
docker-build:
docker build -t lfex/lfe:latest .
docker build -t lfex/lfe-docs:latest ./doc
docker-push:
docker push lfex/lfe:latest
docker push lfex/lfe-docs:latest
docker: docker-build docker-push
docker-run:
docker run -i -t lfex/lfe:latest lfe
docker-docs:
docker run -v `pwd`/doc:/docs -t lfex/lfe-docs:latest
sudo chown -R $(USER):$(USER) doc/*
docker-docs-bash:
docker run -i -v `pwd`/doc:/docs -t lfex/lfe-docs:latest bash
# For travis
travis:
$(MAKE) $(MFLAGS) install PREFIX=$$(mktemp -d)
@rebar3 eunit -m clj-tests,prop_lfe_doc
@rebar3 ct