1#
2#  Copyright (c) 2016, The OpenThread Authors.
3#  All rights reserved.
4#
5#  Redistribution and use in source and binary forms, with or without
6#  modification, are permitted provided that the following conditions are met:
7#  1. Redistributions of source code must retain the above copyright
8#     notice, this list of conditions and the following disclaimer.
9#  2. Redistributions in binary form must reproduce the above copyright
10#     notice, this list of conditions and the following disclaimer in the
11#     documentation and/or other materials provided with the distribution.
12#  3. Neither the name of the copyright holder nor the
13#     names of its contributors may be used to endorse or promote products
14#     derived from this software without specific prior written permission.
15#
16#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26#  POSSIBILITY OF SUCH DAMAGE.
27#
28
29include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
30
31#----------------------------------------
32#
33# This library on the face of it, appears to be identical
34# for both the MTD and FTD variants, however ...
35#
36# The source code here includes numerous OpenThread internal headers.
37# Due to the "domino-effect" other internal headers are included.
38#
39# For example:
40#     cli.cpp includes:
41#            src/core/common/instance.hpp
42# Which Includes:
43#            src/core/therad/thread_netif.hpp
44# Which Includes:
45#            src/core/meshcop/dataset_manager.hpp
46# Which Includes:
47#            src/core/threadnetwork_data_leader.hpp
48#
49# That header (and others) is either an MTD or FTD class flavor.
50#
51# The FTD flavor has many private components (class variables).
52# The MTD flavor has no private components.
53#
54# Bottom line: The Class(structs) are thus different in the downstream
55# libs. At this level (in the CLI, and likewise in the NCP) they are
56# functionally identical.
57#
58# ORIGINALLY (historical note about how things are/where built):
59#
60#     The difference between MTD and FTD was a define..  -DOPENTHREAD_MTD
61#     There was no "FTD" define, it is/was assumed that FTD is the default.
62#
63#     Historically this library -DOPENTHREAD_MTD was not defined/set.
64#     (it is set via a commandline define in 'lib-openthread')
65#
66#     Thus, the existing(previous) way *THIS* library was compiled is
67#     exactly the FTD path. Meaning the "cli" library always sees
68#     the FTD variants of various headers/classes.
69#
70#     The same is true of the "ncp" library.
71#
72# HOWEVER there are two variants of the CLI application, CLI-MTD
73# and CLI-FTD (and likewise, two variants of the ncp application)
74# These applications link against two different OpenThread libraries.
75#
76# Which flavor, you get depends upon which library: "mtd" or "ftd" is linked.
77#
78# Which on the surface appear to link fine against the MTD/FTD library.
79#
80# In this description/example we focus on the  "network_data_leader"
81# header file. The FTD variant has many private variables, functions
82# and other things of "FTD" (ie: full) implementation items.
83#
84# In contrast the MTD is generally stubbed out with stub-functions
85# inlined in the header that return "error not implemented" or similar.
86#
87# Thus it works... here ... With this file and this example.
88#
89# The unknown:
90#    What about the other files?
91#    What about the other c++ classes?
92#    Is this true always? Is this robust?
93#    Or is there a hidden "got-ya" that will snag the next person?
94#
95# This also fails static analysis, checks.
96#    Application - with MTD vrs FTD class.
97#    Library #1  (cli-lib) with FTD selected.
98#    Library #2  (openthread) with two different class flavors.
99#
100# The static analysis tools will say: "NOPE" different classes!
101# Perhaps this will change if/when nothing is implemented in the 'mtd-header'
102#
103# Additionally, tools that perform "whole program optimization" will
104# throw errors because the data structures differ greatly.
105#
106# Hence, CLI library (and NCP) must exist in two flavors.
107#
108# Unless and until these libraries do not "accidentally" suck in
109# a "flavored" header file somewhere.
110
111lib_LIBRARIES                       = $(NULL)
112
113if OPENTHREAD_ENABLE_FTD
114lib_LIBRARIES                      += libopenthread-cli-ftd.a
115endif
116
117if OPENTHREAD_ENABLE_MTD
118lib_LIBRARIES                      += libopenthread-cli-mtd.a
119endif
120
121if OPENTHREAD_ENABLE_RADIO_CLI
122lib_LIBRARIES                      += libopenthread-cli-radio.a
123endif
124
125CPPFLAGS_COMMON =                     \
126    -I$(top_srcdir)/include           \
127    -I$(top_srcdir)/src               \
128    -I$(top_srcdir)/src/core          \
129    $(OPENTHREAD_TARGET_DEFINES)      \
130    $(NULL)
131
132libopenthread_cli_ftd_a_CPPFLAGS =    \
133    -DOPENTHREAD_MTD=0                \
134    -DOPENTHREAD_FTD=1                \
135    -DOPENTHREAD_RADIO=0              \
136    $(CPPFLAGS_COMMON)                \
137    $(NULL)
138
139libopenthread_cli_mtd_a_CPPFLAGS =    \
140    -DOPENTHREAD_MTD=1                \
141    -DOPENTHREAD_FTD=0                \
142    -DOPENTHREAD_RADIO=0              \
143    $(CPPFLAGS_COMMON)                \
144    $(NULL)
145
146libopenthread_cli_radio_a_CPPFLAGS =  \
147    -DOPENTHREAD_MTD=0                \
148    -DOPENTHREAD_FTD=0                \
149    -DOPENTHREAD_RADIO=1              \
150    -DOPENTHREAD_RADIO_CLI=1          \
151    $(CPPFLAGS_COMMON)                \
152    $(NULL)
153
154SOURCES_COMMON =                      \
155    cli.cpp                           \
156    cli_br.cpp                        \
157    cli_coap.cpp                      \
158    cli_coap_secure.cpp               \
159    cli_commissioner.cpp              \
160    cli_dataset.cpp                   \
161    cli_history.cpp                   \
162    cli_joiner.cpp                    \
163    cli_network_data.cpp              \
164    cli_output.cpp                    \
165    cli_srp_client.cpp                \
166    cli_srp_server.cpp                \
167    cli_tcp.cpp                       \
168    cli_udp.cpp                       \
169    $(NULL)
170
171libopenthread_cli_ftd_a_SOURCES =     \
172    $(SOURCES_COMMON)                 \
173    $(NULL)
174
175libopenthread_cli_mtd_a_SOURCES =     \
176    $(SOURCES_COMMON)                 \
177    $(NULL)
178
179libopenthread_cli_radio_a_SOURCES =   \
180    cli.cpp                           \
181    cli_output.cpp                    \
182    $(NULL)
183
184noinst_HEADERS                      = \
185    cli.hpp                           \
186    cli_br.hpp                        \
187    cli_coap.hpp                      \
188    cli_coap_secure.hpp               \
189    cli_commissioner.hpp              \
190    cli_config.h                      \
191    cli_dataset.hpp                   \
192    cli_history.hpp                   \
193    cli_joiner.hpp                    \
194    cli_network_data.hpp              \
195    cli_output.hpp                    \
196    cli_srp_client.hpp                \
197    cli_srp_server.hpp                \
198    cli_tcp.hpp                       \
199    cli_udp.hpp                       \
200    x509_cert_key.hpp                 \
201    $(NULL)
202
203if OPENTHREAD_BUILD_COVERAGE
204CLEANFILES                          = $(wildcard *.gcda *.gcno)
205endif # OPENTHREAD_BUILD_COVERAGE
206
207include $(abs_top_nlbuild_autotools_dir)/automake/post.am
208