From 4207f41f914beec4747e28bf35083cadf8a40f48 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 12 Feb 2018 11:27:16 -0800 Subject: [PATCH] [makefile] update example platform makefiles This commit makes the following changes to (platform) makefiles: - Removes conditional source file inclusions in Makefiles and adopts the model where the source files themselves would add `#if` check for the config option (this is the model adopted in OpenThread core). - Defines `PLATFORM_SOURCES` to include all the sources files - Adds `PRETTY_FILES` to specify files for "make pretty-check" This commit also adds `PRETTY_FILES` in unit test makefile. --- .../libopenthread-windows.vcxproj | 3 ++- examples/platforms/cc2538/Makefile.am | 14 +++++++---- examples/platforms/cc2538/diag.c | 4 +++ examples/platforms/cc2650/Makefile.am | 19 ++++++++------ examples/platforms/cc2650/diag.c | 7 +++++- examples/platforms/cc2652/Makefile.am | 18 +++++++------ examples/platforms/cc2652/diag.c | 5 ++++ examples/platforms/efr32/Makefile.am | 8 ++---- examples/platforms/efr32/diag.c | 4 +++ examples/platforms/gp712/Makefile.am | 24 ++++++++++-------- examples/platforms/gp712/diag.c | 4 +++ examples/platforms/kw41z/Makefile.am | 7 +----- examples/platforms/kw41z/diag.c | 5 ++++ examples/platforms/posix/Makefile.am | 21 ++++++++-------- examples/platforms/posix/diag.c | 4 +++ examples/platforms/posix/spi-stubs.c | 5 ++++ examples/platforms/samr21/Makefile.am | 7 +----- examples/platforms/samr21/diag.c | 5 ++++ tests/unit/Makefile.am | 25 +++++++++++++++++++ 19 files changed, 127 insertions(+), 62 deletions(-) diff --git a/etc/visual-studio/libopenthread-windows.vcxproj b/etc/visual-studio/libopenthread-windows.vcxproj index 07a1c0a55..e69071857 100644 --- a/etc/visual-studio/libopenthread-windows.vcxproj +++ b/etc/visual-studio/libopenthread-windows.vcxproj @@ -1,6 +1,6 @@  - + {30723C38-BA3B-44C9-8D64-C5861A26934F} StaticLibrary @@ -42,6 +42,7 @@ _CRT_SECURE_NO_WARNINGS; OPENTHREAD_CONFIG_FILE="openthread-windows-config.h"; OPENTHREAD_FTD=1; + OPENTHREAD_ENABLE_NCP_SPI=1; OTBUILD; diff --git a/examples/platforms/cc2538/Makefile.am b/examples/platforms/cc2538/Makefile.am index 73677169d..654fcc656 100644 --- a/examples/platforms/cc2538/Makefile.am +++ b/examples/platforms/cc2538/Makefile.am @@ -36,8 +36,9 @@ libopenthread_cc2538_a_CPPFLAGS = \ -I$(top_srcdir)/src/core \ $(NULL) -libopenthread_cc2538_a_SOURCES = \ +PLATFORM_SOURCES = \ alarm.c \ + diag.c \ flash.c \ misc.c \ platform.c \ @@ -48,11 +49,9 @@ libopenthread_cc2538_a_SOURCES = \ uart.c \ $(NULL) -if OPENTHREAD_ENABLE_DIAG -libopenthread_cc2538_a_SOURCES += \ - diag.c \ +libopenthread_cc2538_a_SOURCES = \ + $(PLATFORM_SOURCES) \ $(NULL) -endif noinst_HEADERS = \ cc2538-reg.h \ @@ -60,6 +59,11 @@ noinst_HEADERS = \ rom-utility.h \ $(NULL) +PRETTY_FILES = \ + $(PLATFORM_SOURCES) \ + $(noinst_HEADERS) \ + $(NULL) + Dash = - libopenthread_cc2538_a_LIBADD = \ $(shell find $(top_builddir)/examples/platforms/utils $(Dash)type f $(Dash)name "*.o") diff --git a/examples/platforms/cc2538/diag.c b/examples/platforms/cc2538/diag.c index b5e770d52..19987ce04 100644 --- a/examples/platforms/cc2538/diag.c +++ b/examples/platforms/cc2538/diag.c @@ -38,6 +38,8 @@ #include "platform-cc2538.h" +#if OPENTHREAD_ENABLE_DIAG + /** * Diagnostics mode variables. * @@ -83,3 +85,5 @@ void otPlatDiagAlarmCallback(otInstance *aInstance) { (void)aInstance; } + +#endif // OPENTHREAD_ENABLE_DIAG diff --git a/examples/platforms/cc2650/Makefile.am b/examples/platforms/cc2650/Makefile.am index 8f032acef..1917ec87a 100644 --- a/examples/platforms/cc2650/Makefile.am +++ b/examples/platforms/cc2650/Makefile.am @@ -34,7 +34,6 @@ lib_LIBRARIES = libopenthread-cc2650.a override CFLAGS := $(filter-out -pedantic-errors,$(CFLAGS)) override CXXFLAGS := $(filter-out -pedantic-errors,$(CXXFLAGS)) - libopenthread_cc2650_a_CPPFLAGS = \ -I$(top_srcdir)/include \ -I$(top_srcdir)/src \ @@ -46,8 +45,9 @@ libopenthread_cc2650_a_CPPFLAGS = \ $(MBEDTLS_CPPFLAGS) \ $(NULL) -libopenthread_cc2650_a_SOURCES = \ +PLATFORM_SOURCES = \ alarm.c \ + diag.c \ flash.c \ misc.c \ logging.c \ @@ -62,20 +62,23 @@ libopenthread_cc2650_a_SOURCES = \ cc2650_startup.c \ $(NULL) +libopenthread_cc2650_a_SOURCES = \ + $(PLATFORM_SOURCES) \ + $(NULL) + libopenthread_cc2650_a_DEPENDENCIES = \ $(top_srcdir)/third_party/ti/devices/cc26x0/driverlib/bin/gcc/driverlib.a \ $(NULL) -if OPENTHREAD_ENABLE_DIAG -libopenthread_cc2650_a_SOURCES += \ - diag.c \ - $(NULL) -endif - noinst_HEADERS = \ platform-cc2650.h \ $(NULL) +PRETTY_FILES = \ + $(PLATFORM_SOURCES) \ + $(noinst_HEADERS) \ + $(NULL) + Dash = - libopenthread_cc2650_a_LIBADD = \ $(shell find $(top_builddir)/examples/platforms/utils $(Dash)type f $(Dash)name "*.o") diff --git a/examples/platforms/cc2650/diag.c b/examples/platforms/cc2650/diag.c index 0c4bc307f..932bb8cc6 100644 --- a/examples/platforms/cc2650/diag.c +++ b/examples/platforms/cc2650/diag.c @@ -29,8 +29,11 @@ #include #include #include +#include #include +#if OPENTHREAD_ENABLE_DIAG + /** * Diagnostics mode variables. * @@ -39,7 +42,7 @@ static bool sDiagMode = false; void otPlatDiagProcess(otInstance *aInstance, int argc, char *argv[], char *aOutput, size_t aOutputMaxLen) { - // Add more plarform specific diagnostics features here. + // Add more platform specific diagnostics features here. if (argc > 1) { snprintf(aOutput, aOutputMaxLen, "diag feature '%s' is not supported\r\n", argv[0]); @@ -80,3 +83,5 @@ void otPlatDiagAlarmCallback(otInstance *aInstance) { (void)aInstance; } + +#endif // OPENTHREAD_ENABLE_DIAG diff --git a/examples/platforms/cc2652/Makefile.am b/examples/platforms/cc2652/Makefile.am index f5412ddac..b8ee60153 100644 --- a/examples/platforms/cc2652/Makefile.am +++ b/examples/platforms/cc2652/Makefile.am @@ -45,8 +45,9 @@ libopenthread_cc2652_a_CPPFLAGS = \ $(MBEDTLS_CPPFLAGS) \ $(NULL) -libopenthread_cc2652_a_SOURCES = \ +PLATFORM_SOURCES = \ alarm.c \ + diag.c \ flash.c \ logging.c \ misc.c \ @@ -60,20 +61,23 @@ libopenthread_cc2652_a_SOURCES = \ cxx_helpers.c \ $(NULL) +libopenthread_cc2652_a_SOURCES = \ + $(PLATFORM_SOURCES) \ + $(NULL) + libopenthread_cc2652_a_DEPENDENCIES = \ $(top_srcdir)/third_party/ti/devices/cc26x2/driverlib/bin/gcc/driverlib.a \ $(NULL) -if OPENTHREAD_ENABLE_DIAG -libopenthread_cc2652_a_SOURCES += \ - diag.c \ - $(NULL) -endif - noinst_HEADERS = \ platform-cc2652.h \ $(NULL) +PRETTY_FILES = \ + $(PLATFORM_SOURCES) \ + $(noinst_HEADERS) \ + $(NULL) + Dash = - libopenthread_cc2652_a_LIBADD = \ $(shell find $(top_builddir)/examples/platforms/utils $(Dash)type f $(Dash)name "*.o") diff --git a/examples/platforms/cc2652/diag.c b/examples/platforms/cc2652/diag.c index 28a694f05..ff00d80d4 100644 --- a/examples/platforms/cc2652/diag.c +++ b/examples/platforms/cc2652/diag.c @@ -32,12 +32,15 @@ #include #include +#include #include #include #include #include "platform-cc2652.h" +#if OPENTHREAD_ENABLE_DIAG + /** * Diagnostics mode variables. * @@ -86,3 +89,5 @@ void otPlatDiagAlarmCallback(otInstance *aInstance) { (void)aInstance; } + +#endif // OPENTHREAD_ENABLE_DIAG diff --git a/examples/platforms/efr32/Makefile.am b/examples/platforms/efr32/Makefile.am index ef51df882..6abd9e487 100644 --- a/examples/platforms/efr32/Makefile.am +++ b/examples/platforms/efr32/Makefile.am @@ -73,6 +73,7 @@ libopenthread_efr32_a_CPPFLAGS = PLATFORM_SOURCES = \ alarm.c \ + diag.c \ flash.c \ logging.c \ misc.c \ @@ -83,12 +84,6 @@ PLATFORM_SOURCES = uart.c \ $(NULL) -if OPENTHREAD_ENABLE_DIAG -PLATFORM_SOURCES += \ - diag.c \ - $(NULL) -endif - nodist_libopenthread_efr32_a_SOURCES = \ @top_builddir@/third_party/silabs/gecko_sdk_suite/v2.0/hardware/kit/common/bsp/bsp_bcc.c \ @top_builddir@/third_party/silabs/gecko_sdk_suite/v2.0/hardware/kit/common/bsp/bsp_init.c \ @@ -129,6 +124,7 @@ libopenthread_efr32_a_SOURCES = PRETTY_FILES = \ $(PLATFORM_SOURCES) \ + $(noinst_HEADERS) \ $(NULL) Dash = - diff --git a/examples/platforms/efr32/diag.c b/examples/platforms/efr32/diag.c index 956da5c41..8c5887f54 100644 --- a/examples/platforms/efr32/diag.c +++ b/examples/platforms/efr32/diag.c @@ -43,6 +43,8 @@ #include "platform-efr32.h" +#if OPENTHREAD_ENABLE_DIAG + /** * Diagnostics mode variables. * @@ -88,3 +90,5 @@ void otPlatDiagAlarmCallback(otInstance *aInstance) { (void)aInstance; } + +#endif // #if OPENTHREAD_ENABLE_DIAG diff --git a/examples/platforms/gp712/Makefile.am b/examples/platforms/gp712/Makefile.am index 666fa55f9..b10d6b885 100644 --- a/examples/platforms/gp712/Makefile.am +++ b/examples/platforms/gp712/Makefile.am @@ -38,12 +38,9 @@ libopenthread_gp712_a_CPPFLAGS = \ -lpthread \ $(NULL) -Dash = - -libopenthread_gp712_a_LIBADD = \ - $(shell find $(top_builddir)/examples/platforms/utils $(Dash)type f $(Dash)name "*.o") - -libopenthread_gp712_a_SOURCES = \ +PLATFORM_SOURCES = \ alarm.c \ + diag.c \ misc.c \ logging.c \ platform.c \ @@ -53,15 +50,20 @@ libopenthread_gp712_a_SOURCES = \ flash.c \ $(NULL) -# uart-socket.c \ +# uart-socket.c \ # -if OPENTHREAD_ENABLE_DIAG -libopenthread_gp712_a_SOURCES += \ - diag.c \ - $(NULL) -endif +Dash = - +libopenthread_gp712_a_LIBADD = \ + $(shell find $(top_builddir)/examples/platforms/utils $(Dash)type f $(Dash)name "*.o") +libopenthread_gp712_a_SOURCES = \ + $(PLATFORM_SORUCES) \ + $(NULL) + +PRETTY_FILES = \ + $(PLATFORM_SOURCES) \ + $(NULL) if OPENTHREAD_BUILD_COVERAGE CLEANFILES = $(wildcard *.gcda *.gcno) diff --git a/examples/platforms/gp712/diag.c b/examples/platforms/gp712/diag.c index 9517e5d5b..8148dc5fe 100644 --- a/examples/platforms/gp712/diag.c +++ b/examples/platforms/gp712/diag.c @@ -36,6 +36,8 @@ #include #include +#if OPENTHREAD_ENABLE_DIAG + /** * Diagnostics mode variables. * @@ -81,3 +83,5 @@ void otPlatDiagAlarmCallback(otInstance *aInstance) { (void)aInstance; } + +#endif // OPENTHREAD_ENABLE_DIAG diff --git a/examples/platforms/kw41z/Makefile.am b/examples/platforms/kw41z/Makefile.am index 7f9e5d4bf..b400935da 100644 --- a/examples/platforms/kw41z/Makefile.am +++ b/examples/platforms/kw41z/Makefile.am @@ -50,6 +50,7 @@ libopenthread_kw41z_a_CPPFLAGS PLATFORM_SOURCES = \ alarm.c \ + diag.c \ flash.c \ logging.c \ misc.c \ @@ -87,12 +88,6 @@ libopenthread_kw41z_a_SOURCES @top_builddir@/third_party/nxp/MKW41Z4/XCVR/cfgs_kw4x_3x_2x/fsl_xcvr_zgbe_config.c \ $(NULL) -if OPENTHREAD_ENABLE_DIAG -PLATFORM_SOURCES += \ - diag.c \ - $(NULL) -endif - libopenthread_kw41z_a_SOURCES += \ $(PLATFORM_SOURCES) \ $(NULL) diff --git a/examples/platforms/kw41z/diag.c b/examples/platforms/kw41z/diag.c index 2a592b084..81bb15c3a 100644 --- a/examples/platforms/kw41z/diag.c +++ b/examples/platforms/kw41z/diag.c @@ -36,11 +36,14 @@ #include #include #include +#include "openthread/config.h" #include "openthread/openthread.h" #include "openthread/platform/alarm-milli.h" #include "openthread/platform/radio.h" +#if OPENTHREAD_ENABLE_DIAG + /** * Diagnostics mode variables. * @@ -86,3 +89,5 @@ void otPlatDiagAlarmCallback(otInstance *aInstance) { (void)aInstance; } + +#endif // OPENTHREAD_ENABLE_DIAG diff --git a/examples/platforms/posix/Makefile.am b/examples/platforms/posix/Makefile.am index 397f0f9a9..61ffd0344 100644 --- a/examples/platforms/posix/Makefile.am +++ b/examples/platforms/posix/Makefile.am @@ -37,8 +37,9 @@ libopenthread_posix_a_CPPFLAGS = \ -D_GNU_SOURCE \ $(NULL) -libopenthread_posix_a_SOURCES = \ +PLATFORM_SOURCES = \ alarm.c \ + diag.c \ misc.c \ logging.c \ platform.c \ @@ -46,27 +47,25 @@ libopenthread_posix_a_SOURCES = \ random.c \ uart-posix.c \ flash.c \ + spi-stubs.c \ sim/alarm-sim.c \ sim/platform-sim.c \ sim/radio-sim.c \ $(NULL) -if OPENTHREAD_ENABLE_DIAG -libopenthread_posix_a_SOURCES += \ - diag.c \ +libopenthread_posix_a_SOURCES = \ + $(PLATFORM_SOURCES) \ $(NULL) -endif - -if OPENTHREAD_ENABLE_NCP_SPI -libopenthread_posix_a_SOURCES += \ - spi-stubs.c \ - $(NULL) -endif noinst_HEADERS = \ platform-posix.h \ $(NULL) +PRETTY_FILES = \ + $(PLATFORM_SOURCES) \ + $(noinst_HEADERS) \ + $(NULL) + Dash = - libopenthread_posix_a_LIBADD = \ $(shell find $(top_builddir)/examples/platforms/utils $(Dash)type f $(Dash)name "*.o") diff --git a/examples/platforms/posix/diag.c b/examples/platforms/posix/diag.c index 0c16685f6..7a49dd91a 100644 --- a/examples/platforms/posix/diag.c +++ b/examples/platforms/posix/diag.c @@ -38,6 +38,8 @@ #include #include +#if OPENTHREAD_ENABLE_DIAG + /** * Diagnostics mode variables. * @@ -83,3 +85,5 @@ void otPlatDiagAlarmCallback(otInstance *aInstance) { (void)aInstance; } + +#endif // OPENTHREAD_ENABLE_DIAG diff --git a/examples/platforms/posix/spi-stubs.c b/examples/platforms/posix/spi-stubs.c index d0070bf91..c50713e9d 100644 --- a/examples/platforms/posix/spi-stubs.c +++ b/examples/platforms/posix/spi-stubs.c @@ -31,9 +31,12 @@ #include #include +#include #include #include +#if OPENTHREAD_ENABLE_NCP_SPI + // Spi-slave stubs otError otPlatSpiSlaveEnable(otPlatSpiSlaveTransactionCompleteCallback aCompleteCallback, @@ -80,3 +83,5 @@ void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength) (void)aBuf; (void)aBufLength; } + +#endif // OPENTHREAD_ENABLE_NCP_SPI diff --git a/examples/platforms/samr21/Makefile.am b/examples/platforms/samr21/Makefile.am index 17ae78ca9..f8f5bb0e3 100644 --- a/examples/platforms/samr21/Makefile.am +++ b/examples/platforms/samr21/Makefile.am @@ -97,6 +97,7 @@ libopenthread_samr21_a_CPPFLAGS PLATFORM_SOURCES = \ alarm.c \ + diag.c \ cxx_helpers.c \ flash.c \ logging.c \ @@ -107,12 +108,6 @@ PLATFORM_SOURCES uart.c \ $(NULL) -if OPENTHREAD_ENABLE_DIAG -PLATFORM_SOURCES += \ - diag.c \ - $(NULL) -endif - libopenthread_samr21_a_SOURCES = \ $(PLATFORM_SOURCES) \ $(NULL) diff --git a/examples/platforms/samr21/diag.c b/examples/platforms/samr21/diag.c index 5a74c9d8c..6013624a9 100644 --- a/examples/platforms/samr21/diag.c +++ b/examples/platforms/samr21/diag.c @@ -34,8 +34,11 @@ #include +#include #include +#if OPENTHREAD_ENABLE_DIAG + /** * Diagnostics mode variables. * @@ -82,3 +85,5 @@ void otPlatDiagAlarmCallback(otInstance *aInstance) { (void)aInstance; } + +#endif // OPENTHREAD_ENABLE_DIAG \ No newline at end of file diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index a160f4d57..66f50dd42 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -208,6 +208,31 @@ test_diag_LDADD = $(top_builddir)/src/diag/libopenthread-diag.a test_diag_SOURCES = test_diag.cpp endif +PRETTY_FILES = \ + $(test_address_sanitizer_SOURCES) \ + $(test_aes_SOURCES) \ + $(test_child_SOURCES) \ + $(test_heap_SOURCES) \ + $(test_hmac_sha256_SOURCES) \ + $(test_link_quality_SOURCES) \ + $(test_lowpan_SOURCES) \ + $(test_network_data_SOURCES) \ + $(test_mac_frame_SOURCES) \ + $(test_message_SOURCES) \ + $(test_message_queue_SOURCES) \ + $(test_ncp_buffer_SOURCES) \ + $(test_priority_queue_SOURCES) \ + $(test_pskc_SOURCES) \ + $(test_strlcat_SOURCES) \ + $(test_strlcpy_SOURCES) \ + $(test_strnlen_SOURCES) \ + $(test_spinel_decoder_SOURCES) \ + $(test_spinel_encoder_SOURCES) \ + $(test_timer_SOURCES) \ + $(test_toolchain_SOURCES) \ + $(test_diag_SOURCES) \ + $(NULL) + if OPENTHREAD_BUILD_COVERAGE CLEANFILES = $(wildcard *.gcda *.gcno) endif # OPENTHREAD_BUILD_COVERAGE