1#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. 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,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18#
19
20AUTOMAKE_OPTIONS = serial-tests
21
22SUBDIRS = .
23
24if WITH_TESTS
25SUBDIRS += test
26endif
27
28#
29# Enumeration of all the public and private modules.
30#
31# We unconditionally install all of them, even if libevent or OpenSSL are
32# not available, but build the respective libraries only if the Deimos headers
33# could be found.
34#
35d_thriftmodules = $(addprefix thrift/, base)
36d_thriftdir = $(D_IMPORT_PREFIX)/thrift
37d_thrift_DATA = $(addprefix src/, $(addsuffix .d, $(d_thriftmodules)))
38
39d_asyncmodules = $(addprefix thrift/async/, base libevent socket ssl)
40d_asyncdir = $(d_thriftdir)/async
41d_async_DATA = $(addprefix src/, $(addsuffix .d, $(d_asyncmodules)))
42
43d_codegenmodules = $(addprefix thrift/codegen/, async_client \
44	async_client_pool base client client_pool processor)
45#d_codegenmodules = $(addprefix thrift/codegen/, async_client \
46#	async_client_pool base client client_pool idlgen processor)
47
48d_codegendir = $(d_thriftdir)/codegen
49d_codegen_DATA = $(addprefix src/, $(addsuffix .d, $(d_codegenmodules)))
50
51d_protocolmodules = $(addprefix thrift/protocol/, base binary compact json \
52	processor)
53d_protocoldir = $(d_thriftdir)/protocol
54d_protocol_DATA = $(addprefix src/, $(addsuffix .d, $(d_protocolmodules)))
55
56d_servermodules = $(addprefix thrift/server/, base simple nonblocking \
57	taskpool threaded)
58d_serverdir = $(d_thriftdir)/server
59d_server_DATA = $(addprefix src/, $(addsuffix .d, $(d_servermodules)))
60
61d_servertransportmodules = $(addprefix thrift/server/transport/, base socket ssl)
62d_servertransportdir = $(d_thriftdir)/server/transport
63d_servertransport_DATA = $(addprefix src/, $(addsuffix .d, \
64	$(d_servertransportmodules)))
65
66d_transportmodules = $(addprefix thrift/transport/, base buffered file \
67	framed http memory piped range socket ssl zlib)
68d_transportdir = $(d_thriftdir)/transport
69d_transport_DATA = $(addprefix src/, $(addsuffix .d, $(d_transportmodules)))
70
71d_utilmodules = $(addprefix thrift/util/, awaitable cancellation future \
72	hashset)
73d_utildir = $(d_thriftdir)/util
74d_util_DATA = $(addprefix src/, $(addsuffix .d, $(d_utilmodules)))
75
76d_internalmodules = $(addprefix thrift/internal/, algorithm codegen ctfe \
77	endian resource_pool socket ssl ssl_bio traits)
78d_internaldir = $(d_thriftdir)/internal
79d_internal_DATA = $(addprefix src/, $(addsuffix .d, $(d_internalmodules)))
80
81d_testmodules = $(addprefix thrift/internal/test/, protocol server)
82d_testdir = $(d_internaldir)/test
83d_test_DATA = $(addprefix src/, $(addsuffix .d, $(d_testmodules)))
84
85d_publicmodules = $(d_thriftmodules) $(d_asyncmodules) \
86	$(d_codegenmodules) $(d_protocolmodules) $(d_servermodules) \
87	$(d_servertransportmodules) $(d_transportmodules) $(d_utilmodules)
88d_publicsources = $(addprefix src/, $(addsuffix .d, $(d_publicmodules)))
89
90d_modules = $(d_publicmodules) $(d_internalmodules) $(d_testmodules)
91
92# List modules with external dependencies and remove them from the main list
93d_libevent_dependent_modules = thrift/async/libevent thrift/server/nonblocking
94d_openssl_dependent_modules = thrift/async/ssl thrift/internal/ssl \
95	thrift/internal/ssl_bio thrift/transport/ssl thrift/server/transport/ssl
96d_main_modules = $(filter-out $(d_libevent_dependent_modules) \
97	$(d_openssl_dependent_modules),$(d_modules))
98
99
100d_lib_flags = -w -wi -Isrc -lib
101all_targets =
102
103#
104# libevent-dependent modules.
105#
106if HAVE_DEIMOS_EVENT2
107$(D_EVENT_LIB_NAME): $(addprefix src/, $(addsuffix .d, $(d_libevent_dependent_modules)))
108	$(DMD) -of$(D_EVENT_LIB_NAME) $(d_lib_flags) $^
109all_targets += $(D_EVENT_LIB_NAME)
110endif
111
112#
113# OpenSSL-dependent modules.
114#
115if HAVE_DEIMOS_OPENSSL
116$(D_SSL_LIB_NAME): $(addprefix src/, $(addsuffix .d, $(d_openssl_dependent_modules)))
117	$(DMD) -of$(D_SSL_LIB_NAME) $(d_lib_flags) $^
118all_targets += $(D_SSL_LIB_NAME)
119endif
120
121#
122# Main library target.
123#
124$(D_LIB_NAME): $(addprefix src/, $(addsuffix .d, $(d_main_modules)))
125	$(DMD) -of$(D_LIB_NAME) $(d_lib_flags) $^
126all_targets += $(D_LIB_NAME)
127
128
129#
130# Documentation target (requires Dil).
131#
132docs: $(d_publicsources) src/thrift/index.d
133	dil ddoc docs -hl --kandil $^
134
135
136#
137# Hook custom library targets into the automake all/install targets.
138#
139all-local: $(all_targets)
140
141install-exec-local:
142	$(INSTALL_PROGRAM) $(all_targets) $(DESTDIR)$(libdir)
143
144clean-local:
145	$(RM) -r docs
146	$(RM) $(D_LIB_NAME)
147	$(RM) $(D_EVENT_LIB_NAME)
148	$(RM) $(D_SSL_LIB_NAME)
149	$(RM) -r test/gen-d
150	$(RM) -r unittest
151
152
153#
154# Unit tests (built both in debug and release mode).
155#
156d_test_flags = -unittest -w -wi -I$(top_srcdir)/lib/d/src
157
158# There just must be some way to reassign a variable without warnings in
159# Automake...
160d_test_modules__ = $(d_modules)
161
162if WITH_D_EVENT_TESTS
163d_test_flags += $(DMD_LIBEVENT_FLAGS)
164d_test_modules_ = $(d_test_modules__)
165else
166d_test_modules_ = $(filter-out $(d_libevent_dependent_modules), $(d_test_modules__))
167endif
168
169if WITH_D_SSL_TESTS
170d_test_flags += $(DMD_OPENSSL_FLAGS)
171d_test_modules = $(d_test_modules_)
172else
173d_test_modules = $(filter-out $(d_openssl_dependent_modules), $(d_test_modules_))
174endif
175
176unittest/emptymain.d: unittest/.directory
177	@echo 'void main(){}' >$@
178
179unittest/.directory:
180	mkdir -p unittest || exists unittest
181	touch $@
182
183unittest/debug/%: src/%.d $(all_targets) unittest/emptymain.d
184	$(DMD) -g -of$(subst /,$(DMD_OF_DIRSEP),$@) $(d_test_flags) $^
185
186unittest/release/%: src/%.d $(all_targets) unittest/emptymain.d
187	$(DMD) -O -release -of$(subst /,$(DMD_OF_DIRSEP),$@) $(d_test_flags) $^
188
189TESTS = $(addprefix unittest/debug/, $(d_test_modules)) \
190	$(addprefix unittest/release/, $(d_test_modules))
191
192precross: all-local
193	$(MAKE) -C test precross
194
195EXTRA_DIST = \
196	src \
197	test \
198	README.md
199