1#
2# %CopyrightBegin%
3#
4# Copyright Ericsson AB 2010-2016. All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18# %CopyrightEnd%
19
20include $(ERL_TOP)/make/target.mk
21include $(ERL_TOP)/make/$(TARGET)/otp.mk
22
23# ----------------------------------------------------
24# Application version
25# ----------------------------------------------------
26
27include ../vsn.mk
28
29VSN = $(DIAMETER_VSN)
30
31# ----------------------------------------------------
32# Release directory specification
33# ----------------------------------------------------
34
35RELSYSDIR = $(RELEASE_PATH)/diameter_test
36
37# ----------------------------------------------------
38# Target Specs
39# ----------------------------------------------------
40
41include modules.mk
42
43ERL_FILES    = $(MODULES:%=%.erl)
44TARGET_FILES = $(MODULES:%=%.$(EMULATOR))
45
46SUITE_MODULES = $(filter diameter_%_SUITE, $(MODULES))
47SUITES        = $(SUITE_MODULES:diameter_%_SUITE=%)
48
49DATA_DIRS = $(sort $(dir $(DATA)))
50
51# ----------------------------------------------------
52# FLAGS
53# ----------------------------------------------------
54
55# This is only used to compile suite locally when running with a
56# target like 'all' below. Target release_tests only installs source.
57ERL_COMPILE_FLAGS += +warn_export_vars \
58                     +warn_unused_vars \
59                     -I ../include \
60                     -I ../src/gen \
61                     $(STRICT_FLAGS)
62
63# ----------------------------------------------------
64# Targets
65# ----------------------------------------------------
66
67all debug opt: $(TARGET_FILES)
68
69strict:
70	$(MAKE) opt STRICT_FLAGS=-Werror
71
72# Require success ...
73run: $(SUITES)
74
75# ... or not.
76any: opt
77	$(MAKE) -i $(SUITES)
78
79clean:
80	rm -f $(TARGET_FILES)
81	rm -f depend.mk coverspec
82
83realclean: clean
84	rm -rf log
85
86docs:
87
88list = echo $(1):; echo $($(1)) | tr ' ' '\n' | sort | sed 's@^@  @'
89
90info:
91	@echo ========================================
92	@$(call list,MODULES)
93	@echo
94	@$(call list,HRL_FILES)
95	@echo
96	@$(call list,SUITES)
97	@echo
98	@echo erl = $(shell which erl)
99	@erl -noinput \
100	     -eval 'io:format("diameter = ~s~n", [code:lib_dir(diameter)])' \
101	     -s init stop
102	@echo ========================================
103
104help:
105	@echo ========================================
106	@echo "Useful targets:"
107	@echo
108	@echo "    all:"
109	@echo "        Compile all test suites."
110	@echo
111	@echo "    run:"
112	@echo "        Compile and run all test suites, stop on failure."
113	@echo
114	@echo "    any:"
115	@echo "        Compile and run all test suites, ignore any failures."
116	@echo
117	@echo "    $(SUITES):"
118	@echo "        Compile and run a specific test suite."
119	@echo
120	@echo "    clean | realclean:"
121	@echo "        Remove generated files."
122	@echo
123	@echo "    info:"
124	@echo "        Echo some relevant variables."
125	@echo ========================================
126
127.PHONY: all any run clean debug docs help info opt realclean strict
128
129# ----------------------------------------------------
130# Special Targets
131# ----------------------------------------------------
132
133# Exit with a non-zero status if the output looks to indicate failure.
134# diameter_ct:run/1 itself can't tell (it seems). The absolute -pa is
135# because ct will change directories.
136$(SUITES): log opt
137	$(ERL) -noinput \
138	       -pa $(realpath ../ebin) \
139	       -sname diameter_test_$@ \
140	       -s diameter_ct run diameter_$@_SUITE \
141	       -s init stop \
142	| awk '{print} / FAILED /{rc=1} END{exit rc}' rc=0
143# Shorter in sed but requires a GNU extension (ie. Q).
144
145cover: log opt coverspec
146	$(ERL) -noinput \
147	       -pa $(realpath ../ebin) \
148	       -sname diameter_cover \
149	       -s diameter_ct cover \
150	       -s init stop \
151	| awk '{print} / FAILED /{rc=1} END{exit rc}' rc=0
152
153coverspec: diameter.cover
154	sed -f $@.sed $< > $@
155
156log:
157	mkdir $@
158
159.PHONY: $(SUITES) cover
160
161# ----------------------------------------------------
162# Release Targets
163# ----------------------------------------------------
164
165/%: % force
166	sed -f release.sed $< > "$(RELSYSDIR)$@"
167
168include $(ERL_TOP)/make/otp_release_targets.mk
169
170release_spec release_docs_spec:
171
172release_tests_spec:
173	$(INSTALL_DIR)  "$(RELSYSDIR)"
174	$(INSTALL_DATA) $(TEST_SPEC_FILE) \
175	                $(COVER_SPEC_FILE) \
176	                $(HRL_FILES) \
177	                "$(RELSYSDIR)"
178	$(MAKE) $(DATA_DIRS:%/=release_data_%)
179	$(MAKE) $(ERL_FILES:%=/%)
180
181$(DATA_DIRS:%/=release_data_%): release_data_%:
182	$(INSTALL_DIR) "$(RELSYSDIR)/$*"
183	$(INSTALL_DATA) $(filter $*/%, $(DATA)) "$(RELSYSDIR)/$*"
184
185force:
186
187.PHONY: release_spec release_docs_spec release_test_specs
188.PHONY: force
189.PHONY: $(DATA_DIRS:%/=release_data_%)
190
191# Can't just make $(ERL_FILES:%=/%) phony since then implicit rule
192# searching is skipped.
193
194# ----------------------------------------------------
195
196depend: depend.mk
197
198# Generate dependencies makefile.
199depend.mk: depend.sed $(MODULES:%=%.erl) Makefile
200	(for f in $(MODULES); do \
201	     (echo $$f; cat $$f.erl) | sed -f $<; \
202	 done) \
203	> $@
204
205-include depend.mk
206
207.PHONY: depend
208