-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
171 lines (123 loc) · 3.84 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
#PACKAGE := e3dtree
#PACKAGE := ekdarbo
#PACKAGE := etannenbaum
PACKAGE := yalinka
VERSION := $(shell cat version)
RELEASE := $(shell cat release)
REVISION := $(shell git --no-pager log --max-count=1 --format=format:%H)
DESTDIR ?= install-dir
UID := $(shell id -u)
ARCH := $(shell uname -m)
#DEBUG := true
SONIF := priv/lib/$(PACKAGE).so
COBJ := $(patsubst c_src/%.c, obj/%.o, $(wildcard c_src/*.c))
ERLS := $(wildcard src/*.erl)
BEAMS := $(patsubst src/%.erl, ebin/%.beam, $(ERLS))
ERL_FLAGS := +warn_unused_function \
+warn_bif_clash \
+warn_deprecated_function \
+warn_obsolete_guard \
+warn_shadow_vars \
+warn_export_vars \
+warn_unused_records \
+warn_unused_import \
-Werror
ERL_LIBS := ${ERL_LIBS}:~/lib/erl
C_OPTS := -c -Wall -Wextra -pedantic -fpic -std=c99
L_OPTS := -lm
GCC := $(shell which colorgcc || which gcc || which clang || echo cc)
ifneq ($(wildcard /usr/pbi/erlang-amd64/local/lib/erlang/usr/include/erl_nif.h),)
C_OPTS += -I/usr/pbi/erlang-amd64/local/lib/erlang/usr/include
endif
ifneq ($(wildcard /usr/local/lib/erlang/usr/include/erl_nif.h),)
C_OPTS += -I/usr/local/lib/erlang/usr/include
endif
ifdef DEBUG
C_OPTS += -DDEBUG
ERL_FLAGS += +debug_info
endif
.PHONY: clean
all: $(PACKAGE)
$(PACKAGE): $(SONIF) ebin/$(PACKAGE).app $(BEAMS)
#
# bake edoc, erlang documentation
#
doc: doc/overview.edoc doc/index.html
doc/index.html: doc/overview.edoc
erl -noinput -eval "edoc:application($(PACKAGE), \".\", [])" -s erlang halt
doc/overview.edoc: version tools/parse.pl
@mkdir -p doc
perl tools/parse.pl README.md doc/overview.edoc $(VERSION)
doc-install: doc
mkdir -p $(DESTDIR)/$(PACKAGE)
install --mode=644 doc/*.html doc/*.css doc/*.png $(DESTDIR)/$(PACKAGE)
#
# main shared object file with NIF
#
$(SONIF): privlib obj $(COBJ)
$(GCC) -o $(SONIF) -shared $(L_OPTS) $(COBJ)
obj:
mkdir -p obj
obj/%.o: c_src/%.c
$(GCC) -o $@ $(C_OPTS) $<
privlib:
mkdir -p priv/lib
#
# Erlang wrapper application and modules
#
ebin:
mkdir -p ebin
ebin/%.beam: src/%.erl
erlc -o ebin -I include $(ERL_FLAGS) $<
ebin/$(PACKAGE).app: ebin src/$(PACKAGE).app.in
sed "s/{{VERSION}}/$(VERSION)/" \
src/$(PACKAGE).app.in >ebin/$(PACKAGE).app
#
# testing framework. Using eunit and proper.
#
$(PACKAGE)_test: test/$(PACKAGE)_test.erl
ERL_LIBS=$(ERL_LIBS) erlc -o ebin -I include test/$(PACKAGE)_test.erl
eunit: $(PACKAGE) $(PACKAGE)_test
erl -noinput -pa ebin \
-eval 'ok = eunit:test($(PACKAGE)_test, [verbose])' \
-s erlang halt
proper: $(PACKAGE) $(PACKAGE)_test
ERL_LIBS=$(ERL_LIBS):~/lib/erl erl -noinput -pa ebin \
-s $(PACKAGE)_test start \
-s erlang halt
oolong: $(PACKAGE) $(PACKAGE)_test
ERL_LIBS=$(ERL_LIBS):~/lib/erl erl -noinput -pa ebin \
-eval 'true = not is_tuple('$(PACKAGE)'_test:start([verbose, {numtests, 10000}]))' \
-s erlang halt
measure: $(PACKAGE) $(PACKAGE)_test
erl -noinput -pa ebin \
-s $(PACKAGE)_test measure \
-s erlang halt
test: clean eunit proper
longtest: clean eunit oolong
t4d: clean $(PACKAGE) test/hidim_test.erl
ERL_LIBS=$(ERL_LIBS) erlc -o ebin -I include test/hidim_test.erl
erl -noinput -pa ebin -eval 'ok = eunit:test(hidim_test, [verbose])' \
-s erlang halt
#
# helpers, algo debug, auxiliary targets
#
obj/pure.o: tools/pure.c
$(GCC) -o $@ $(C_OPTS) $<
pure: obj obj/pure.o
$(GCC) -o pure $(L_OPTS) obj/pure.o
spec: opensuse.spec.in
@echo "Creating rpm spec files..."
sed "s,{{VERSION}},$(VERSION),g; \
s,{{RELEASE}},$(RELEASE),g; \
s,{{REVISION}},$(REVISION),g" opensuse.spec.in >opensuse.spec
tags: c_src/*.c
ctags -e -f c_src/TAGS c_src/*
shell: priv/lib/yalinka.so ebin/yalinka.beam
erl -pa ebin -eval "code:load_file(yalinka)"
#
# cleanup target
#
clean:
@rm -f pure *.o erl_crash.dump opensuse.spec c_src/TAGS $(SONIF) testfile-* test/data/*.dump
@rm -rf ebin doc .eunit priv/lib obj $(DESTDIR)/$(PACKAGE)