-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
178 lines (140 loc) · 4.98 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
### -*- tab-width: 2 -*-
### ===========================================================================
### @doc Rebar Makefile Helper & Enhancmenter
### @author Damian T. Dobroczy\\'nski <qoocku@gmail.com>
### @since 2011-04-10
### ===========================================================================
## --- macros --
var-set = echo "$($(1))" > priv/config/${subst .,/,$(1)} ; echo variable \<$(1)\> set to "$($(1))". ;
var-get = cat priv/config/${subst .,/,$(1)}
var-del = rm -f priv/config/${subst .,/,$(1)} ; echo deleting \"$(1)\" done.
var-edit = $(EDITOR) priv/config/${subst .,/,$(1)}
## --- variables ---
ifeq ("$(EDITOR)","")
EDITOR = vim
warnings += warn-editor
endif
app-id = ${shell ${call var-get,app.appid}}
app-config = ${filter-out priv/config/app/-%,${wildcard priv/config/app/*}}
app-config-vars = ${foreach v,appid description modules vsn,priv/config/app/$(v)}
module-files = ${wildcard src/*.erl}
modules = ${foreach f,$(module-files),${notdir ${basename $(f)}}}
effective-modules = ${filter-out ${shell cat priv/config/app/-modules},$(modules)}
overlay-vars = ${foreach v,$(app-config), ${notdir $(v)}="${shell cat $(v)}"} modules="${shell cat priv/config/app/modules}"
ifneq ("$(del-var)","")
override .DEFAULT_GOAL := del-var
else
ifneq ("$(get-var)","")
override .DEFAULT_GOAL := get-var
else
ifneq ("$(edit-var)","")
override .DEFAULT_GOAL := edit-var
else
ifneq ("$(app.appid)","")
var-to-set = app.appid
else
ifneq ("$(app.vsn)","")
var-to-set = app.vsn
else
ifneq ("$(app.description)","")
var-to-set = app.description
else
what-to-set = dont-know-what-to-set
endif
endif
endif
endif
endif
endif
## --- get the arguments for eunit if any
ifneq ($(eunit),)
test-types := eunit
ifeq ($(eunit),true)
eunit-suite :=
else
eunit-suite := "suite=$(eunit)"
endif
sbt-args := "eunit=$(eunit)"
endif
## --- get the arguments for common_test server if any
ifneq ($(ct),)
test-types += ct
ifeq ($(ct),true)
ct-suite :=
else
ct-suite := "suite=$(ct)"
endif
sbt-args += "ct=$(ct)"
endif
sbt-args := test $(sbt-args)
## --- debug helpers & macros --
ifeq ("$(dbg)","true")
show-list = dbg> $(1):\n${foreach i,$($(1)),\t'$(i)'\n}
dbg-vars = echo "${call show-list,app-id}${call show-list,app-config}${call show-list,module-files}${call show-list,modules}${call show-list,effective-modules}${call show-list,overlay-vars}"
override dbg := dbg-vars
endif
## --- targets & rules ---
.PHONY: all get-var del-var edit-var
all: priv/config/app/appid src/vsn src/$(app-id).app.src $(dbg) compile test doc
help:
@echo Generic Rebar-friendly Makefile ; \
echo Usage: make [TARGET] [VAR=\<value\>] ; \
echo ; \
echo TARGET is: ; \
echo \\tset-var VAR=\<value\>\\t-- sets a config variable VAR to value \<value\> ; \
echo \\t\\tVAR may be: app.appid, app.description, app.vsn ; \
echo \\tcompile\\t\\t\\t-- rebar compile ; \
echo \\tdoc\\t\\t\\t-- rebar doc ; \
echo \\ttest\\t\\t\\t-- rebar eunit \; rebar ct ; \
echo \\n\'make\' without any target and parameter is equivalent to do compile, test and doc.
compile: src/vsn
@./rebar compile
test: src/vsn $(test-types)
eunit:
@./rebar eunit $(eunit-suite)
ct:
@./rebar ct $(ct-suite)
doc: src/vsn
@./rebar doc
dont-know-what-to-set:
${error I do not know wht to set. Specify the variable.}
set-version: priv/config/app/appid priv/config/app/vsn
@rm -f ebin/$(app-id).app ; rm -f src/$(app-id).app.src
@if [ "$(app.vsn)" != "" ] ; then \
./rebar create template=vsn template_dir=priv/templates force=1 skip_deps=true vsn='$(app.vsn)'; \
echo "$(app.vsn)" > priv/config/app/vsn ; \
else \
if [ -d priv/config/app ] ; then \
./rebar create template=vsn template_dir=priv/templates force=1 skip_deps=true $(overlay-vars) ; \
else \
echo "need 'vsn' parameter or 'priv/config/app/vsn' file with 'vsn' value set."; \
exit 1; \
fi; \
fi
set-var: $(what-to-set)
@${call var-set,$(var-to-set)}
del-var:
@${call var-del,$(del-var)}
get-var:
@${call var-get,$(get-var)}
edit-var: $(warnings)
@${call var-edit,$(edit-var)}
sbt:
@priv/fmon.sh --command make --args "$(sbt-args)" --files Makefile rebar.config src include test
## --- warning phony targets ---
warn-editor:
${warning EDITOR variable not set.}
## --- rules ---
priv/config/app/appid:
$(error "You must create $@ file to do anything by this Makefile")
src/$(app-id).app.src: priv/templates/app.src priv/templates/app.src.template $(app-config-vars)
@./rebar create template=app.src template_dir=priv/templates force=1 $(overlay-vars)
src/vsn: priv/templates/vsn priv/templates/vsn.template priv/config/app/vsn
@make set-version
priv/config/app/modules : $(module-files) priv/config/app/-modules
@echo ${foreach m,${wordlist 2,1000,$(effective-modules)},,$(m)}
@echo "${firstword $(effective-modules)}${foreach m,${wordlist 2,1000,$(effective-modules)},,$(m)}" > $@
priv/config/app/-modules: # if not exists
@touch $@
dbg-vars:
@$(dbg-vars)