From 6771f6848493a17c694b3c9e83f6b7b8b3cb1aac Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Thu, 12 Dec 2024 09:51:31 +0100 Subject: [PATCH] Repair and upgrade example chapter16_08 --- .../target/micros/avr/make/avr_flags.gmk | 4 +- examples/chapter16_08/chapter16_08.vcxproj | 34 +- .../chapter16_08/chapter16_08.vcxproj.filters | 135 ++++---- .../math_test_independent_test_system_base.h | 6 +- .../math_test_independent_test_system_boost.h | 31 +- .../miller_rabin/miller_rabin_base.h | 13 +- .../miller_rabin/miller_rabin_digits.h | 33 ++ .../miller_rabin/miller_rabin_single.h | 117 ------- .../miller_rabin/miller_rabin_state.h | 8 +- .../mcal_math_independent_test_system.cpp | 3 +- .../chapter16_08/src/mcal_lcd/mcal_lcd_base.h | 9 +- .../src/mcal_lcd/mcal_lcd_console.h | 23 +- .../src/mcal_lcd/mcal_lcd_generic_st7066.h | 41 ++- .../src/sys/idle/sys_idle_miller_rabin.cpp | 9 +- examples/chapter16_08/src/util/STL/array | 48 +-- examples/chapter16_08/src/util/STL/cmath | 2 +- examples/chapter16_08/src/util/STL/span | 2 +- .../target/app/make/app_files.gmk | 2 +- .../chapter16_08/target/app/make/app_make.gmk | 295 ++++++++++++++---- .../target/app/make/app_rules.gmk | 48 ++- .../target/micros/avr/make/avr_flags.gmk | 33 +- 21 files changed, 538 insertions(+), 358 deletions(-) create mode 100644 examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_digits.h delete mode 100644 examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_single.h diff --git a/examples/chapter04_04/target/micros/avr/make/avr_flags.gmk b/examples/chapter04_04/target/micros/avr/make/avr_flags.gmk index 5713636b5..3c8533379 100644 --- a/examples/chapter04_04/target/micros/avr/make/avr_flags.gmk +++ b/examples/chapter04_04/target/micros/avr/make/avr_flags.gmk @@ -10,7 +10,7 @@ # ------------------------------------------------------------------------------ ifneq ($(MAKE),make) -GCC_VERSION = 13.2.0 +GCC_VERSION = 14.2.0 endif GCC_TARGET = avr GCC_PREFIX = avr @@ -24,7 +24,7 @@ TGT_ALLFLAGS = -O2 -finline-limit=32 \ -fsigned-char -ifeq ($(GCC_VERSION),13.2.0) +ifeq ($(GCC_VERSION),14.2.0) TGT_ALLFLAGS := $(TGT_ALLFLAGS) \ -mdouble=32 \ -mlong-double=64 diff --git a/examples/chapter16_08/chapter16_08.vcxproj b/examples/chapter16_08/chapter16_08.vcxproj index 8f6e9ee6c..0a07f5c90 100644 --- a/examples/chapter16_08/chapter16_08.vcxproj +++ b/examples/chapter16_08/chapter16_08.vcxproj @@ -54,12 +54,12 @@ - $(SolutionDir)\src;$(SolutionDir)\src\mcal\win32;C:\boost\boost_1_85_0;$(IncludePath) + $(SolutionDir)\src;$(SolutionDir)\src\mcal\win32;C:\boost\boost_1_86_0;$(IncludePath) $(SolutionDir)$(Configuration)\ $(Configuration)\ - $(SolutionDir)\src;$(SolutionDir)\src\mcal\win32;C:\boost\boost_1_85_0;$(IncludePath) + $(SolutionDir)\src;$(SolutionDir)\src\mcal\win32;C:\boost\boost_1_86_0;$(IncludePath) $(SolutionDir)$(Configuration)\ $(Configuration)\ @@ -246,15 +246,27 @@ true true + + true + true + + + true + true + + + true + true + + - true @@ -492,6 +504,14 @@ true true + + true + true + + + true + true + true true @@ -568,6 +588,10 @@ true true + + true + true + true true @@ -588,6 +612,10 @@ true true + + true + true + diff --git a/examples/chapter16_08/chapter16_08.vcxproj.filters b/examples/chapter16_08/chapter16_08.vcxproj.filters index 9f122d58f..4b9f1b577 100644 --- a/examples/chapter16_08/chapter16_08.vcxproj.filters +++ b/examples/chapter16_08/chapter16_08.vcxproj.filters @@ -198,11 +198,17 @@ src\mcal\win32 + + src\util\STL\impl\avr + + + src\util\STL\impl + + + src\util\STL\impl + - - src\util\STL\impl\avr - src\os @@ -212,18 +218,6 @@ src\os - - src\util\STL\impl - - - src\util\STL\impl - - - src\util\STL\impl - - - src\util\STL - src\util\STL_C++XX_stdfloat @@ -464,9 +458,6 @@ src\math\wide_integer\miller_rabin - - src\math\wide_integer\miller_rabin - src\math\wide_integer\miller_rabin @@ -521,126 +512,156 @@ src\mcal_led - + + src\math\test + + + src\math\wide_integer\miller_rabin + + + src\util\STL\impl\avr + + src\util\STL\impl src\util\STL\impl + + src\util\STL\impl + + + src\util\STL\impl + src\util\STL\impl - - src\math\test + + src\util\STL\impl + + + src\util\STL - + + src\util\STL_C++XX_stdfloat + + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - - src\util\STL_C++XX_stdfloat + + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + src\util\STL - + + src\util\STL + + + src\util\STL + + src\util\STL src\util\STL - + + src\util\STL + + src\util\STL diff --git a/examples/chapter16_08/src/math/test/math_test_independent_test_system_base.h b/examples/chapter16_08/src/math/test/math_test_independent_test_system_base.h index a026112b1..86a7e48f2 100644 --- a/examples/chapter16_08/src/math/test/math_test_independent_test_system_base.h +++ b/examples/chapter16_08/src/math/test/math_test_independent_test_system_base.h @@ -12,15 +12,15 @@ namespace WIDE_INTEGER_NAMESPACE { namespace math { namespace test { - class independent_test_system_base : private util::noncopyable + class independent_test_system_base : private ::util::noncopyable { public: - virtual ~independent_test_system_base() noexcept { } + virtual ~independent_test_system_base() noexcept = default; virtual bool is_prime(const char* const pstr_prime_candidate) const = 0; protected: - independent_test_system_base() noexcept { } + independent_test_system_base() noexcept = default; }; } // namespace test diff --git a/examples/chapter16_08/src/math/test/math_test_independent_test_system_boost.h b/examples/chapter16_08/src/math/test/math_test_independent_test_system_boost.h index 1fc5f0dcf..6e463bae7 100644 --- a/examples/chapter16_08/src/math/test/math_test_independent_test_system_boost.h +++ b/examples/chapter16_08/src/math/test/math_test_independent_test_system_boost.h @@ -18,38 +18,45 @@ namespace WIDE_INTEGER_NAMESPACE { namespace math { namespace test { + template class independent_test_system_boost : public math::test::independent_test_system_base { private: - using uint128_t = boost::multiprecision::uint128_t; + static constexpr unsigned boost_uint_digits { Width2 }; + + using boost_uint_backend_type = + boost::multiprecision::cpp_int_backend; + + using boost_uint_type = boost::multiprecision::number; + + using random_engine_type = std::mt19937_64; public: - independent_test_system_boost() noexcept - : my_gen (std::clock()), - my_seed_count(0U) { } + independent_test_system_boost() noexcept = default; - virtual ~independent_test_system_boost() noexcept { } + ~independent_test_system_boost() noexcept override { } - virtual bool is_prime(const char* const pstr_prime_candidate) const override + auto is_prime(const char* const pstr_prime_candidate) const -> bool override { - const uint128_t p(std::string("0x") + pstr_prime_candidate); + const boost_uint_type p { std::string("0x") + pstr_prime_candidate }; - const bool is_prime_says_boost_miller_rabin = - boost::multiprecision::miller_rabin_test(p, 25, my_gen); + const bool is_prime_says_boost_miller_rabin = boost::multiprecision::miller_rabin_test(p, 25, my_gen); ++my_seed_count; if((my_seed_count % 0x1000U) == 0U) { - my_gen.seed(std::clock()); + my_gen.seed(static_cast(std::clock())); } return is_prime_says_boost_miller_rabin; } private: - mutable std::mt19937 my_gen; - mutable std::uint32_t my_seed_count; + mutable random_engine_type my_gen { static_cast(std::clock()) }; + mutable std::uint32_t my_seed_count { }; }; } // namespace test diff --git a/examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_base.h b/examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_base.h index b935ac667..aaaa9c0e4 100644 --- a/examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_base.h +++ b/examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2020 - 2022. +// Copyright Christopher Kormanyos 2020 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -8,16 +8,7 @@ #ifndef MILLER_RABIN_BASE_2020_05_30_H_ #define MILLER_RABIN_BASE_2020_05_30_H_ - #define WIDE_INTEGER_DISABLE_IOSTREAM - #define WIDE_INTEGER_DISABLE_TO_STRING - #define WIDE_INTEGER_DISABLE_FLOAT_INTEROP - #define WIDE_INTEGER_DISABLE_IMPLEMENT_UTIL_DYNAMIC_ARRAY - #define WIDE_INTEGER_DISABLE_TRIVIAL_COPY_AND_STD_LAYOUT_CHECKS - - // Note that -DWIDE_INTEGER_NAMESPACE=ckormanyos is defined - // on the compiler command line. - - #include + #include WIDE_INTEGER_NAMESPACE_BEGIN diff --git a/examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_digits.h b/examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_digits.h new file mode 100644 index 000000000..d46a3fc12 --- /dev/null +++ b/examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_digits.h @@ -0,0 +1,33 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2024. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MILLER_RABIN_DIGITS_2024_12_12_H + #define MILLER_RABIN_DIGITS_2024_12_12_H + + #define WIDE_INTEGER_DISABLE_IOSTREAM + #define WIDE_INTEGER_DISABLE_TO_STRING + #define WIDE_INTEGER_DISABLE_FLOAT_INTEROP + #define WIDE_INTEGER_DISABLE_IMPLEMENT_UTIL_DYNAMIC_ARRAY + #define WIDE_INTEGER_DISABLE_TRIVIAL_COPY_AND_STD_LAYOUT_CHECKS + + // Note that -DWIDE_INTEGER_NAMESPACE=ckormanyos is defined + // on the compiler command line. + + #include + + WIDE_INTEGER_NAMESPACE_BEGIN + + namespace math { namespace wide_integer { + + constexpr unsigned miller_rabin_digits { static_cast(UINT16_C(128)) }; + + } // namespace wide_integer + } // namespace math + + WIDE_INTEGER_NAMESPACE_END + +#endif // MILLER_RABIN_DIGITS_2024_12_12_H diff --git a/examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_single.h b/examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_single.h deleted file mode 100644 index 759de6377..000000000 --- a/examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_single.h +++ /dev/null @@ -1,117 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2020 - 2022. -// Distributed under the Boost Software License, -// Version 1.0. (See accompanying file LICENSE_1_0.txt -// or copy at http://www.boost.org/LICENSE_1_0.txt) -// - -#ifndef MILLER_RABIN_SINGLE_2020_05_30_H_ - #define MILLER_RABIN_SINGLE_2020_05_30_H_ - - #include - - WIDE_INTEGER_NAMESPACE_BEGIN - - namespace math { namespace wide_integer { - - template - class miller_rabin_single : public miller_rabin_base - { - private: - using base_class_type = miller_rabin_base; - - public: - constexpr miller_rabin_single(const typename base_class_type::generator1_type::result_type seed1 = typename base_class_type::generator1_type::result_type(), - const typename base_class_type::generator2_type::result_type seed2 = typename base_class_type::generator2_type::result_type()) - : base_class_type(seed1, seed2) { } - - virtual ~miller_rabin_single() = default; - - virtual bool search() - { - while(base_class_type::set_n() == false) - { - ; - } - - calculate(); - - if(base_class_type::my_n_trial_is_probably_prime) - { - base_class_type::my_n_is_probably_prime = true; - } - - return true; - } - - private: - void calculate() - { - // This Miller-Rabin primality test is loosely based on - // an adaptation of some code from Boost.Multiprecision. - // The Boost.Multiprecision code can be found here: - // https://www.boost.org/doc/libs/1_73_0/libs/multiprecision/doc/html/boost_multiprecision/tut/primetest.html - - // Note: Some comments in this subroutine use the Wolfram Language(TM). - - // Check small prime factors. - if(base_class_type::exclude_small_factors_1_0()) { return; } - if(base_class_type::exclude_small_factors_2_0()) { return; } - if(base_class_type::exclude_small_factors_3_0()) { return; } - if(base_class_type::exclude_small_factors_4_0()) { return; } - if(base_class_type::exclude_small_factors_5_0()) { return; } - if(base_class_type::exclude_small_factors_5_1()) { return; } - if(base_class_type::exclude_small_factors_5_2()) { return; } - if(base_class_type::exclude_small_factors_5_3()) { return; } - if(base_class_type::exclude_small_factors_5_4()) { return; } - if(base_class_type::exclude_small_factors_5_5()) { return; } - - // Perform a single Fermat test. - base_class_type::my_n_m1 = base_class_type::my_n_trial; - --base_class_type::my_n_m1; - - const typename base_class_type::wide_integer_type fn = - powm(typename base_class_type::wide_integer_type(typename base_class_type::limb_type(228U)), - base_class_type::my_n_m1, - base_class_type::my_n_trial); - - const typename base_class_type::limb_type fn0 = static_cast(fn); - - if((fn0 != 1U) && (fn != 1U)) - { - base_class_type::my_n_trial_is_probably_prime = false; - - return; - } - - // Prepare the random trials. - base_class_type::prepare_random_trials(); - - std::uint_fast32_t i = 0U; - - // Execute the random trials. - while( (i < base_class_type::my_number_of_trials) - && (base_class_type::my_n_trial_is_probably_prime == true)) - { - base_class_type::execute_one_trial(); - - ++i; - } - } - }; - - } // namespace wide_integer - } // namespace math - - WIDE_INTEGER_NAMESPACE_END - -#endif // MILLER_RABIN_SINGLE_2020_05_30_H_ diff --git a/examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_state.h b/examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_state.h index cec58754f..78d1dd254 100644 --- a/examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_state.h +++ b/examples/chapter16_08/src/math/wide_integer/miller_rabin/miller_rabin_state.h @@ -1,12 +1,12 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2020 - 2022. +// Copyright Christopher Kormanyos 2020 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef MILLER_RABIN_STATE_2020_05_31_H_ - #define MILLER_RABIN_STATE_2020_05_31_H_ +#ifndef MILLER_RABIN_STATE_2020_05_31_H + #define MILLER_RABIN_STATE_2020_05_31_H #include @@ -449,4 +449,4 @@ WIDE_INTEGER_NAMESPACE_END -#endif // MILLER_RABIN_STATE_2020_05_31_H_ +#endif // MILLER_RABIN_STATE_2020_05_31_H diff --git a/examples/chapter16_08/src/mcal/win32/mcal_math_independent_test_system.cpp b/examples/chapter16_08/src/mcal/win32/mcal_math_independent_test_system.cpp index 19c674a28..56e17b7a5 100644 --- a/examples/chapter16_08/src/mcal/win32/mcal_math_independent_test_system.cpp +++ b/examples/chapter16_08/src/mcal/win32/mcal_math_independent_test_system.cpp @@ -12,6 +12,7 @@ #include #else #include +#include #endif #if defined(MCAL_MATH_USE_INDEPENDENT_TEST_SYSTEM_MATHLINK) @@ -28,7 +29,7 @@ WIDE_INTEGER_NAMESPACE::math::test::independent_test_system_base& mcal::math::in #if defined(MCAL_MATH_USE_INDEPENDENT_TEST_SYSTEM_MATHLINK) using test_system_type = WIDE_INTEGER_NAMESPACE::math::test::independent_test_system_mathlink; #else - using test_system_type = WIDE_INTEGER_NAMESPACE::math::test::independent_test_system_boost; + using test_system_type = WIDE_INTEGER_NAMESPACE::math::test::independent_test_system_boost; #endif static test_system_type ts0; diff --git a/examples/chapter16_08/src/mcal_lcd/mcal_lcd_base.h b/examples/chapter16_08/src/mcal_lcd/mcal_lcd_base.h index a56d90e44..20e7d3a51 100644 --- a/examples/chapter16_08/src/mcal_lcd/mcal_lcd_base.h +++ b/examples/chapter16_08/src/mcal_lcd/mcal_lcd_base.h @@ -1,3 +1,10 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2020 - 2024. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + #ifndef MCAL_LCD_BASE_2020_06_10_H_ #define MCAL_LCD_BASE_2020_06_10_H_ @@ -13,7 +20,7 @@ virtual bool init() = 0; virtual bool write(const char* pstr, - const std::uint_fast8_t length, + const std::uint_fast16_t length, const std::uint_fast8_t line_index) = 0; protected: diff --git a/examples/chapter16_08/src/mcal_lcd/mcal_lcd_console.h b/examples/chapter16_08/src/mcal_lcd/mcal_lcd_console.h index 2500ed5ac..c28f1981a 100644 --- a/examples/chapter16_08/src/mcal_lcd/mcal_lcd_console.h +++ b/examples/chapter16_08/src/mcal_lcd/mcal_lcd_console.h @@ -1,11 +1,18 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2020 - 2024. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + #ifndef MCAL_LCD_CONSOLE_2020_06_10_H_ #define MCAL_LCD_CONSOLE_2020_06_10_H_ + #include + #include #include - #include - namespace mcal { namespace lcd { class lcd_console : public mcal::lcd::lcd_base @@ -13,11 +20,11 @@ public: lcd_console() = default; - virtual ~lcd_console() = default; + ~lcd_console() override = default; - virtual bool write(const char* pstr, - const std::uint_fast8_t length, - const std::uint_fast8_t line_index) + auto write(const char* pstr, + const std::uint_fast16_t length, + const std::uint_fast8_t line_index) -> bool override { static_cast(line_index); @@ -25,7 +32,7 @@ if((pstr != nullptr) && (length > 0U)) { - const std::string str(pstr, pstr + length); + const std::string str { pstr, pstr + length }; std::cout << str << std::endl; @@ -39,7 +46,7 @@ return write_is_ok; } - virtual bool init() { return true; } + auto init() -> bool override { return true; } }; } } // namespace mcal::lcd diff --git a/examples/chapter16_08/src/mcal_lcd/mcal_lcd_generic_st7066.h b/examples/chapter16_08/src/mcal_lcd/mcal_lcd_generic_st7066.h index 828f7ff24..398ca0207 100644 --- a/examples/chapter16_08/src/mcal_lcd/mcal_lcd_generic_st7066.h +++ b/examples/chapter16_08/src/mcal_lcd/mcal_lcd_generic_st7066.h @@ -1,15 +1,22 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2020 - 2024. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + #ifndef MCAL_LCD_GENERIC_ST7066_2020_05_07_H_ #define MCAL_LCD_GENERIC_ST7066_2020_05_07_H_ - #include - #include - #include - #include #include #include + #include + #include + #include + namespace mcal { namespace lcd { template + const std::uint_fast16_t LcdLineWidth> class lcd_generic_st7066 final : public mcal::lcd::lcd_base { private: + static constexpr std::uint_fast16_t lcd_line_width { LcdLineWidth }; + using timer_type = util::timer; static void blocking_delay(const typename timer_type::tick_type blocking_delay_value) @@ -37,9 +46,9 @@ public: lcd_generic_st7066() = default; - virtual ~lcd_generic_st7066() = default; + ~lcd_generic_st7066() override = default; - virtual bool init(void) + auto init(void) -> bool override { port_pin_rs__type::set_pin_low(); port_pin_rw__type::set_pin_low(); @@ -67,16 +76,14 @@ command(UINT8_C(0x0C)); // Display ON; Cursor ON command(UINT8_C(0x06)); // Entry mode set - const bool write_clear_lines_is_ok = ( write(nullptr, 0U, 0U) - && write(nullptr, 0U, 1U)); - + const bool write_clear_lines_is_ok { write(nullptr, 0U, 0U) && write(nullptr, 0U, 1U) }; return write_clear_lines_is_ok; } - virtual bool write(const char* pstr, - const std::uint_fast8_t length, - const std::uint_fast8_t line_index) + auto write(const char* pstr, + const std::uint_fast16_t length, + const std::uint_fast8_t line_index) -> bool override { std::uint_fast8_t char_index = 0U; @@ -100,7 +107,7 @@ } private: - void write(const std::uint8_t i) + static auto write(const std::uint8_t i) -> void { P1_set(i); // P1 = i; // Put data on the output Port port_pin_rs__type::set_pin_high(); // D_I =1; // D/I=HIGH : send data @@ -110,7 +117,7 @@ port_pin_e___type::set_pin_low(); // E = 0; // Clock enable: falling edge } - void command(std::uint8_t i) + static auto command(std::uint8_t i) -> void { P1_set(i); // P1 = i; // Put data on output Port port_pin_rs__type::set_pin_low(); // D_I =0; // D/I=LOW : send instruction @@ -121,7 +128,7 @@ blocking_delay(timer_type::microseconds(40U)); // Command execution delay } - void P1_set(const std::uint8_t c) + static auto P1_set(const std::uint8_t c) -> void { std::uint_fast8_t(c & UINT8_C(0x01)) != UINT8_C(0) ? port_pin_db0_type::set_pin_high() : port_pin_db0_type::set_pin_low(); std::uint_fast8_t(c & UINT8_C(0x02)) != UINT8_C(0) ? port_pin_db1_type::set_pin_high() : port_pin_db1_type::set_pin_low(); @@ -133,7 +140,7 @@ std::uint_fast8_t(c & UINT8_C(0x80)) != UINT8_C(0) ? port_pin_db7_type::set_pin_high() : port_pin_db7_type::set_pin_low(); } - static void P1_set_direction_output() + static auto P1_set_direction_output() -> void { port_pin_db0_type::set_direction_output(); port_pin_db1_type::set_direction_output(); diff --git a/examples/chapter16_08/src/sys/idle/sys_idle_miller_rabin.cpp b/examples/chapter16_08/src/sys/idle/sys_idle_miller_rabin.cpp index 7c31d1805..630f31624 100644 --- a/examples/chapter16_08/src/sys/idle/sys_idle_miller_rabin.cpp +++ b/examples/chapter16_08/src/sys/idle/sys_idle_miller_rabin.cpp @@ -1,10 +1,11 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2020 - 2022. +// Copyright Christopher Kormanyos 2020 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // +#include #include #include #include @@ -20,7 +21,7 @@ namespace { - using sys_idle_miller_rabin_uint_type = WIDE_INTEGER_NAMESPACE::math::wide_integer::uintwide_t; + using sys_idle_miller_rabin_uint_type = WIDE_INTEGER_NAMESPACE::math::wide_integer::uintwide_t; using sys_idle_miller_rabin_random_engine1_type = mcal::random::default_random_engine; using sys_idle_miller_rabin_random_engine2_type = std::minstd_rand; @@ -30,8 +31,8 @@ namespace sys_idle_miller_rabin_uint_type::my_width2, typename sys_idle_miller_rabin_uint_type::limb_type>; - constexpr std::uint_fast8_t sys_idle_miller_rabin_prime_width_base16 - = util::narrow_cast(std::numeric_limits::digits / 4); + constexpr std::uint_fast16_t sys_idle_miller_rabin_prime_width_base16 + = util::narrow_cast(std::numeric_limits::digits / 4); using sys_idle_miller_rabin_gen1_result_type = typename sys_idle_miller_rabin_miller_rabin_type::generator1_type::result_type; diff --git a/examples/chapter16_08/src/util/STL/array b/examples/chapter16_08/src/util/STL/array index 85d33818a..334327a5f 100644 --- a/examples/chapter16_08/src/util/STL/array +++ b/examples/chapter16_08/src/util/STL/array @@ -41,8 +41,8 @@ static STL_LOCAL_CONSTEXPR size_type static_size = N; - STL_LOCAL_CONSTEXPR_ALGORITHMS iterator begin() { return elems; } - STL_LOCAL_CONSTEXPR_ALGORITHMS iterator end () { return elems + N; } + STL_LOCAL_CONSTEXPR iterator begin() { return elems; } + STL_LOCAL_CONSTEXPR iterator end () { return elems + N; } STL_LOCAL_CONSTEXPR const_iterator begin() const { return elems; } STL_LOCAL_CONSTEXPR const_iterator end () const { return elems + N; } @@ -50,8 +50,8 @@ STL_LOCAL_CONSTEXPR const_iterator cbegin() const { return elems; } STL_LOCAL_CONSTEXPR const_iterator cend () const { return elems + N; } - STL_LOCAL_CONSTEXPR_ALGORITHMS reverse_iterator rbegin() { return reverse_iterator(elems + N); } - STL_LOCAL_CONSTEXPR_ALGORITHMS reverse_iterator rend () { return reverse_iterator(elems); } + STL_LOCAL_CONSTEXPR reverse_iterator rbegin() { return reverse_iterator(elems + N); } + STL_LOCAL_CONSTEXPR reverse_iterator rend () { return reverse_iterator(elems); } STL_LOCAL_CONSTEXPR const_reverse_iterator rbegin() const { return const_reverse_iterator(elems + N); } STL_LOCAL_CONSTEXPR const_reverse_iterator rend () const { return const_reverse_iterator(elems); } @@ -59,54 +59,54 @@ STL_LOCAL_CONSTEXPR const_reverse_iterator crbegin() const { return const_reverse_iterator(elems + N); } STL_LOCAL_CONSTEXPR const_reverse_iterator crend () const { return const_reverse_iterator(elems); } - STL_LOCAL_CONSTEXPR_ALGORITHMS reference operator[](const size_type i) { return elems[i]; } - STL_LOCAL_CONSTEXPR const_reference operator[](const size_type i) const { return elems[i]; } + STL_LOCAL_CONSTEXPR reference operator[](const size_type i) { return elems[i]; } + STL_LOCAL_CONSTEXPR const_reference operator[](const size_type i) const { return elems[i]; } - STL_LOCAL_CONSTEXPR_ALGORITHMS reference at(const size_type i) { return elems[i]; } - STL_LOCAL_CONSTEXPR const_reference at(const size_type i) const { return elems[i]; } + STL_LOCAL_CONSTEXPR reference at(const size_type i) { return elems[i]; } + STL_LOCAL_CONSTEXPR const_reference at(const size_type i) const { return elems[i]; } - STL_LOCAL_CONSTEXPR_ALGORITHMS reference front() { return elems[0U]; } - STL_LOCAL_CONSTEXPR const_reference front() const { return elems[0U]; } + STL_LOCAL_CONSTEXPR reference front() { return elems[0U]; } + STL_LOCAL_CONSTEXPR const_reference front() const { return elems[0U]; } - STL_LOCAL_CONSTEXPR_ALGORITHMS reference back() { return elems[N - 1U]; } - STL_LOCAL_CONSTEXPR const_reference back() const { return elems[N - 1U]; } + STL_LOCAL_CONSTEXPR reference back() { return elems[N - 1U]; } + STL_LOCAL_CONSTEXPR const_reference back() const { return elems[N - 1U]; } static STL_LOCAL_CONSTEXPR size_type size() { return N; } static STL_LOCAL_CONSTEXPR bool empty() { return false; } static STL_LOCAL_CONSTEXPR size_type max_size() { return N; } template - STL_LOCAL_CONSTEXPR_ALGORITHMS void swap(array& y) + STL_LOCAL_CONSTEXPR void swap(array& y) { std::swap_ranges(begin(), end(), y.begin()); } - STL_LOCAL_CONSTEXPR const_pointer data() const { return elems; } - STL_LOCAL_CONSTEXPR_ALGORITHMS pointer data() { return elems; } + STL_LOCAL_CONSTEXPR const_pointer data() const { return elems; } + STL_LOCAL_CONSTEXPR pointer data() { return elems; } pointer c_array() { return elems; } template - STL_LOCAL_CONSTEXPR_ALGORITHMS array& operator=(const array& y) + STL_LOCAL_CONSTEXPR array& operator=(const array& y) { std::copy(y.begin(), y.end(), begin()); return *this; } - STL_LOCAL_CONSTEXPR_ALGORITHMS void assign(const value_type& value) + STL_LOCAL_CONSTEXPR void assign(const value_type& value) { std::fill_n(elems, N, value); } - STL_LOCAL_CONSTEXPR_ALGORITHMS void fill(const value_type& value) + STL_LOCAL_CONSTEXPR void fill(const value_type& value) { std::fill_n(elems, N, value); } }; template - STL_LOCAL_CONSTEXPR_ALGORITHMS bool operator==(const array& left, const array& right) + STL_LOCAL_CONSTEXPR bool operator==(const array& left, const array& right) { return std::equal(left.begin(), left.end(), right.begin()); } @@ -121,31 +121,31 @@ } template - STL_LOCAL_CONSTEXPR_ALGORITHMS bool operator!=(const array& left, const array& right) + STL_LOCAL_CONSTEXPR bool operator!=(const array& left, const array& right) { return (!(left == right)); } template - STL_LOCAL_CONSTEXPR_ALGORITHMS bool operator>(const array& left, const array& right) + STL_LOCAL_CONSTEXPR bool operator>(const array& left, const array& right) { return (right < left); } template - STL_LOCAL_CONSTEXPR_ALGORITHMS bool operator>=(const array& left, const array& right) + STL_LOCAL_CONSTEXPR bool operator>=(const array& left, const array& right) { return (!(left < right)); } template - STL_LOCAL_CONSTEXPR_ALGORITHMS bool operator<=(const array& left, const array& right) + STL_LOCAL_CONSTEXPR bool operator<=(const array& left, const array& right) { return (!(right < left)); } template - STL_LOCAL_CONSTEXPR_ALGORITHMS void swap(array& x, array& y) + STL_LOCAL_CONSTEXPR void swap(array& x, array& y) { swap_ranges(x.begin(), x.end(), y.begin()); } diff --git a/examples/chapter16_08/src/util/STL/cmath b/examples/chapter16_08/src/util/STL/cmath index 23088fa62..2945c01d6 100644 --- a/examples/chapter16_08/src/util/STL/cmath +++ b/examples/chapter16_08/src/util/STL/cmath @@ -304,7 +304,7 @@ inline float atan2 (float y, float x) { return __BUILTIN_ATAN2F(y, x); } inline double atan2 (double y, double x) { return __BUILTIN_ATAN2 (y, x); } inline long double atan2 (long double y, long double x) { return __BUILTIN_ATAN2L(y, x); } - inline float expf (float x) { return __BUILTIN_EXPF (x); } + inline float exp (float x) { return __BUILTIN_EXPF (x); } inline double exp (double x) { return __BUILTIN_EXP (x); } inline long double exp (long double x) { return __BUILTIN_EXPL (x); } inline float pow (float x, float a) { return __BUILTIN_POWF (x, a); } diff --git a/examples/chapter16_08/src/util/STL/span b/examples/chapter16_08/src/util/STL/span index 62fcd2bfd..1c5d121e3 100644 --- a/examples/chapter16_08/src/util/STL/span +++ b/examples/chapter16_08/src/util/STL/span @@ -27,7 +27,7 @@ using byte = unsigned char; STL_LOCAL_CONSTEXPR std::size_t dynamic_extent = - (std::numeric_limits::max)(); + static_cast((std::numeric_limits::max)()); template diff --git a/examples/chapter16_08/target/app/make/app_files.gmk b/examples/chapter16_08/target/app/make/app_files.gmk index 182e6eb06..7bc11ce1f 100644 --- a/examples/chapter16_08/target/app/make/app_files.gmk +++ b/examples/chapter16_08/target/app/make/app_files.gmk @@ -1,5 +1,5 @@ # -# Copyright Christopher Kormanyos 2007 - 2018. +# Copyright Christopher Kormanyos 2007 - 2024. # Distributed under the Boost Software License, # Version 1.0. (See accompanying file LICENSE_1_0.txt # or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/examples/chapter16_08/target/app/make/app_make.gmk b/examples/chapter16_08/target/app/make/app_make.gmk index 5019821b3..b99d84f99 100644 --- a/examples/chapter16_08/target/app/make/app_make.gmk +++ b/examples/chapter16_08/target/app/make/app_make.gmk @@ -6,7 +6,7 @@ # # ------------------------------------------------------------------------------ -# +# # Makefile # # Build file for the reference application using the GNU tools @@ -15,24 +15,57 @@ # # 07-April-2010 # +# See also a definitive list of GCC command line options +# (for numerous target systems) here: +# https://man7.org/linux/man-pages/man1/gcc.1.html +# # ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ -# compiler location, build from GCC version and GCC target +# operating system # ------------------------------------------------------------------------------ -COMPILER_DIRECTORY = gcc-$(GCC_VERSION)-$(GCC_TARGET) + +ifeq ($(TYP_OS),) + +ifeq ($(OS),Windows_NT) +TYP_OS := WIN +else +TYP_OS := NIX +endif + +endif # ------------------------------------------------------------------------------ -# paths +# punctuation # ------------------------------------------------------------------------------ -PATH_TOOLS = tools -PATH_TOOLS_UTIL = $(PATH_TOOLS)\Util -PATH_TOOLS_MINGW = $(PATH_TOOLS_UTIL)\msys64\usr -PATH_TOOLS_MINGW_BIN = $(PATH_TOOLS_MINGW)\bin -PATH_TOOLS_CC = $(PATH_TOOLS_MINGW)\local\gcc-$(GCC_VERSION)-$(GCC_TARGET)\bin +DQUOTE := \" +$(DQUOTE) := \" + +SEMICOLON := ; +$(SEMICOLON) := ; + +DOLLAR := $$ +$(DOLLAR) := $$ + +# ------------------------------------------------------------------------------ +# null device +# ------------------------------------------------------------------------------ + +ifeq ($(TYP_OS),WIN) +NULL_DEVICE := NUL +$(NULL_DEVICE) := NUL +else +NULL_DEVICE := /dev/null +$(NULL_DEVICE) := /dev/null +endif + + +# ------------------------------------------------------------------------------ +# paths +# ------------------------------------------------------------------------------ PATH_APP = src PATH_TGT = target/micros/$(TGT) PATH_APP_MAKE = target/app/make @@ -40,16 +73,41 @@ PATH_TGT_MAKE = $(PATH_TGT)/make PATH_BIN = bin PATH_TMP = tmp PATH_OBJ = $(PATH_TMP)/obj -PATH_SRC = $(PATH_TMP)/src +PATH_LST = $(PATH_TMP)/lst PATH_ERR = $(PATH_TMP)/err # ------------------------------------------------------------------------------ -# include files +# standard shell tools # ------------------------------------------------------------------------------ -include $(PATH_APP_MAKE)/app_files.gmk # Application file list -include $(PATH_TGT_MAKE)/$(TGT)_files.gmk # Target filelist -include $(PATH_TGT_MAKE)/$(TGT)_flags.gmk # Target compiler flags + +ifeq ($(TYP_OS),WIN) + +PATH_TOOLS = tools +PATH_TOOLS_UTIL = $(PATH_TOOLS)\Util +PATH_TOOLS_MINGW = $(PATH_TOOLS_UTIL)\msys64\usr +PATH_TOOLS_MINGW_BIN = $(PATH_TOOLS_MINGW)\bin +PATH_TOOLS_CC = $(PATH_TOOLS_MINGW)\local\gcc-$(GCC_VERSION)-$(GCC_TARGET)\bin + +ECHO = $(PATH_TOOLS_MINGW_BIN)\echo.exe +MAKE = $(PATH_TOOLS_MINGW_BIN)\make.exe +MKDIR = $(PATH_TOOLS_MINGW_BIN)\mkdir.exe +RM = $(PATH_TOOLS_MINGW_BIN)\rm.exe +SED = $(PATH_TOOLS_MINGW_BIN)\sed.exe + +else + +ECHO = echo +MAKE = make +MKDIR = mkdir +RM = rm +SED = sed + +ifneq ($(MY_GMAKE),) +MAKE := $(MY_GMAKE) +endif + +endif # ------------------------------------------------------------------------------ @@ -57,17 +115,32 @@ include $(PATH_TGT_MAKE)/$(TGT)_flags.gmk # Target compiler flags # ------------------------------------------------------------------------------ APP = $(PATH_BIN)/chapter16_08 +IMAGE_FILE = $(APP).bin + +RULE_SPECIAL_MAKE_IMAGE_FILE = +RULE_SPECIAL_MAKE_FLASH_BATCH = + +WARN_FLAGS := + # ------------------------------------------------------------------------------ -# object files +# linker definition file # ------------------------------------------------------------------------------ -FILES_TMP = $(FILES_CPP) $(FILES_TGT) -FILES_O = $(addprefix $(PATH_OBJ)/, $(notdir $(addsuffix .o, $(FILES_TMP)))) +LINKER_DEFINITION_FILE := $(PATH_TGT_MAKE)/$(TGT).ld # ------------------------------------------------------------------------------ -# linker definition file +# include the target-specific make files # ------------------------------------------------------------------------------ -LINKER_DEFINITION_FILE = $(PATH_TGT_MAKE)/$(TGT).ld +include $(PATH_APP_MAKE)/app_files.gmk # Application file list +include $(PATH_TGT_MAKE)/$(TGT)_files.gmk # Target filelist +include $(PATH_TGT_MAKE)/$(TGT)_flags.gmk # Target compiler flags + + +# ------------------------------------------------------------------------------ +# object files +# ------------------------------------------------------------------------------ +FILES_TMP = $(FILES_CPP) $(FILES_TGT) +FILES_O = $(addprefix $(PATH_OBJ)/, $(notdir $(addsuffix .o, $(FILES_TMP)))) # ------------------------------------------------------------------------------ @@ -85,21 +158,76 @@ VPATH := $(sort $(dir $(FILES_TMP))) # ------------------------------------------------------------------------------ # Development tools # ------------------------------------------------------------------------------ -AR = $(PATH_TOOLS_CC)\$(GCC_TARGET)-ar.exe -AS = $(PATH_TOOLS_CC)\$(GCC_TARGET)-g++.exe -CC = $(PATH_TOOLS_CC)\$(GCC_TARGET)-g++.exe -CPPFILT = $(PATH_TOOLS_CC)\$(GCC_TARGET)-c++filt.exe -NM = $(PATH_TOOLS_CC)\$(GCC_TARGET)-nm.exe -OBJDUMP = $(PATH_TOOLS_CC)\$(GCC_TARGET)-objdump.exe -OBJCOPY = $(PATH_TOOLS_CC)\$(GCC_TARGET)-objcopy.exe -READELF = $(PATH_TOOLS_CC)\$(GCC_TARGET)-readelf.exe -SIZE = $(PATH_TOOLS_CC)\$(GCC_TARGET)-size.exe +ifeq ($(TYP_OS),WIN) -ECHO = $(PATH_TOOLS_MINGW_BIN)\echo.exe -MAKE = $(PATH_TOOLS_MINGW_BIN)\make.exe -MKDIR = $(PATH_TOOLS_MINGW_BIN)\mkdir.exe -RM = $(PATH_TOOLS_MINGW_BIN)\rm.exe -SED = $(PATH_TOOLS_MINGW_BIN)\sed.exe +ifeq ($(GCC_PREFIX),) + +ifeq ($(AR),) +AR := $(PATH_TOOLS_CC)\ar.exe +endif +ifeq ($(AS),) +AS := $(PATH_TOOLS_CC)\g++.exe +endif +ifeq ($(CC),) +CC := $(PATH_TOOLS_CC)\g++.exe +endif +ifeq ($(CPPFILT),) +CPPFILT := $(PATH_TOOLS_CC)\c++filt.exe +endif +ifeq ($(NM),) +NM := $(PATH_TOOLS_CC)\nm.exe +endif +ifeq ($(OBJDUMP),) +OBJDUMP := $(PATH_TOOLS_CC)\objdump.exe +endif +ifeq ($(OBJCOPY),) +OBJCOPY := $(PATH_TOOLS_CC)\objcopy.exe +endif +ifeq ($(READELF),) +READELF := $(PATH_TOOLS_CC)\readelf.exe +endif +ifeq ($(SIZE),) +SIZE := $(PATH_TOOLS_CC)\size.exe +endif + +else + +AR := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-ar.exe +AS := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-g++.exe +CC := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-g++.exe +CPPFILT := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-c++filt.exe +NM := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-nm.exe +OBJDUMP := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-objdump.exe +OBJCOPY := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-objcopy.exe +READELF := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-readelf.exe +SIZE := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-size.exe +endif + +else + +ifeq ($(GCC_PREFIX),) +AR := ar +AS := g++ +CC := g++ +CPPFILT := c++filt +NM := nm +OBJDUMP := objdump +OBJCOPY := objcopy +READELF := readelf +SIZE := size +else +AR := $(GCC_PREFIX)-ar +AS := $(GCC_PREFIX)-g++ +CC := $(GCC_PREFIX)-g++ +CPPFILT := $(GCC_PREFIX)-c++filt +NM := $(GCC_PREFIX)-nm +OBJDUMP := $(GCC_PREFIX)-objdump +OBJCOPY := $(GCC_PREFIX)-objcopy +READELF := $(GCC_PREFIX)-readelf +SIZE := $(GCC_PREFIX)-size +endif + +endif # ------------------------------------------------------------------------------ @@ -109,14 +237,15 @@ C_INCLUDES = $(TGT_INCLUDES) \ -I$(PATH_APP) \ -I$(PATH_APP)/mcal/$(TGT) -GCCFLAGS = $(TGT_CFLAGS) \ - -Wall \ +ifeq ($(WARN_FLAGS),) + +WARN_FLAGS = -Wall \ -Wextra \ - -pedantic \ + -Wpedantic \ -Wmain \ -Wundef \ - -Wsign-conversion \ -Wconversion \ + -Wsign-conversion \ -Wunused-parameter \ -Wuninitialized \ -Wmissing-declarations \ @@ -128,39 +257,39 @@ GCCFLAGS = $(TGT_CFLAGS) \ -Wmissing-include-dirs \ -Winit-self \ -Wfloat-equal \ - -Wdouble-promotion \ + -Wdouble-promotion + +endif + +GCCFLAGS = -g \ + $(WARN_FLAGS) \ + -Wno-comment \ -gdwarf-2 \ -fno-exceptions \ - -ffunction-sections \ - -fdata-sections + -fdata-sections \ + -ffunction-sections CFLAGS = $(GCCFLAGS) \ - -Wunsuffixed-float-constants \ - -x c \ - -std=c99 + $(TGT_CFLAGS) \ + -x c -CPPFLAGS = $(GCCFLAGS) \ - $(TGT_CPPFLAGS) \ +CXXFLAGS = $(GCCFLAGS) \ + $(TGT_CXXFLAGS) \ -x c++ \ -fno-rtti \ - -fstrict-enums \ -fno-use-cxa-atexit \ - -fno-use-cxa-get-exception-ptr \ - -fno-nonansi-builtins \ -fno-threadsafe-statics \ - -fno-enforce-eh-specs \ - -ftemplate-depth=32 \ + -ftemplate-depth=128 \ -Wzero-as-null-pointer-constant AFLAGS = $(GCCFLAGS) \ - $(TGT_CFLAGS) \ + $(TGT_CXXFLAGS) \ $(TGT_AFLAGS) \ -x assembler -LDFLAGS = $(GCCFLAGS) \ +LDFLAGS = $(CXXFLAGS) \ $(TGT_LDFLAGS) \ -x none \ - -Wl,-Map,$(APP).map \ -Wl,--print-memory-usage # ------------------------------------------------------------------------------ @@ -186,8 +315,8 @@ clean_prj: @-$(MKDIR) -p $(PATH_BIN) @-$(MKDIR) -p $(PATH_OBJ) @-$(MKDIR) -p $(PATH_ERR) - @-$(MKDIR) -p $(PATH_SRC) - @-$(RM) -r $(PATH_BIN) > NUL 2> NUL + @-$(MKDIR) -p $(PATH_LST) + @-$(RM) -r $(PATH_BIN) 2>$(NULL_DEVICE) @-$(MKDIR) -p $(PATH_BIN) @@ -200,11 +329,11 @@ clean_all: @-$(MKDIR) -p $(PATH_BIN) @-$(MKDIR) -p $(PATH_OBJ) @-$(MKDIR) -p $(PATH_ERR) - @-$(MKDIR) -p $(PATH_SRC) - @-$(RM) -r $(PATH_OBJ) > NUL 2> NUL - @-$(RM) -r $(PATH_ERR) > NUL 2> NUL - @-$(RM) -r $(PATH_SRC) > NUL 2> NUL - @-$(RM) -r $(PATH_BIN) > NUL 2> NUL + @-$(MKDIR) -p $(PATH_LST) + @-$(RM) -r $(PATH_OBJ) 2>$(NULL_DEVICE) + @-$(RM) -r $(PATH_ERR) 2>$(NULL_DEVICE) + @-$(RM) -r $(PATH_LST) 2>$(NULL_DEVICE) + @-$(RM) -r $(PATH_BIN) 2>$(NULL_DEVICE) @-$(MKDIR) -p $(PATH_BIN) @@ -214,21 +343,27 @@ clean_all: .PHONY: version version: # Print the GNU make version and the compiler version + @$(ECHO) @$(ECHO) +++ Print GNUmake version @$(MAKE) --version @$(ECHO) - @$(ECHO) +++ Print GCC version + @$(ECHO) +++ Print compiler version @$(CC) -v @$(ECHO) @$(ECHO) +++ Print compiler include paths @$(ECHO) $(C_INCLUDES) @$(ECHO) +ifeq ($(TYP_OS),WIN) @$(ECHO) +++ Print compiler include paths (for VisualStudio(R) browsing) - @$(ECHO) $(subst /,\, $(subst -I,$$\(SolutionDir\), $(C_INCLUDES))) + @$(ECHO) $(addsuffix $(SEMICOLON),$(subst -I,$$\(ProjectDir\)/, $(C_INCLUDES))) @$(ECHO) +endif @$(ECHO) +++ Print compiler definitions @$(ECHO) $(C_DEFINES) @$(ECHO) + @$(ECHO) +++ Print compiler CXXFLAGS flags + @$(ECHO) $(CXXFLAGS) + @$(ECHO) # ------------------------------------------------------------------------------ @@ -237,8 +372,6 @@ version: $(APP).$(TGT_SUFFIX) : $(LINKER_DEFINITION_FILE) $(FILES_O) @-$(ECHO) +++ linking application to generate: $(APP).$(TGT_SUFFIX) @-$(CC) $(LDFLAGS) $(FILES_O) -o $(APP).$(TGT_SUFFIX) - @-$(ECHO) +++ generating assembly list file: $(APP).lss - @-$(OBJDUMP) -disassemble -S $(APP).$(TGT_SUFFIX) > $(APP).lss # ------------------------------------------------------------------------------ @@ -250,7 +383,11 @@ $(APP)_nm.txt : $(APP).$(TGT_SUFFIX) @-$(ECHO) +++ demangling symbols with c++filt to generate: $(APP)_cppfilt.txt @-$(NM) --numeric-sort --print-size $(APP).$(TGT_SUFFIX) | $(CPPFILT) > $(APP)_cppfilt.txt @-$(ECHO) +++ parsing symbols with readelf to generate: $(APP)_readelf.txt +ifeq ($(TGT_SUFFIX),elf) @-$(READELF) --syms $(APP).$(TGT_SUFFIX) > $(APP)_readelf.txt +else + @-$(ECHO) +++ not available for: $(APP).$(TGT_SUFFIX). +endif @-$(ECHO) +++ creating size summary table with size to generate: $(APP)_size.txt @-$(SIZE) -A -t $(APP).$(TGT_SUFFIX) > $(APP)_size.txt @@ -259,9 +396,31 @@ $(APP)_nm.txt : $(APP).$(TGT_SUFFIX) # create hex mask # ------------------------------------------------------------------------------ $(APP)_flash.hex : $(APP).$(TGT_SUFFIX) - @-$(ECHO) +++ creating hex module: $(APP).hex. - @-$(OBJCOPY) -O ihex $(APP).$(TGT_SUFFIX) $(APP).hex - @-$(OBJCOPY) -S -O binary $(APP).$(TGT_SUFFIX) $(APP).bin + @-$(ECHO) +++ creating hex module: $(APP).$(TGT_SUFFIX) +ifeq ($(TGT_SUFFIX),elf) + @-$(ECHO) +++ creating hex module: $(APP).hex + @-$(OBJCOPY) $(APP).$(TGT_SUFFIX) -O ihex $(APP).hex + @-$(ECHO) +++ creating srec module: $(APP).s19 + @-$(OBJCOPY) $(APP).$(TGT_SUFFIX) -O srec $(APP).s19 + @-$(ECHO) +++ creating disassembly listing: $(APP)_disassembly.txt + @-$(OBJDUMP) -D $(APP).$(TGT_SUFFIX) > $(APP)_disassembly.txt +else + @-$(ECHO) +++ creating hex module disabled for non-ELF absolute objet file. +endif +ifeq ($(RULE_SPECIAL_MAKE_IMAGE_FILE),) + @-$(ECHO) +++ creating special image file + @-$(ECHO) +++ disabled because there is no special image file +else + @-$(ECHO) +++ creating special image file + @-$(RULE_SPECIAL_MAKE_IMAGE_FILE) +endif +ifeq ($(RULE_SPECIAL_MAKE_FLASH_BATCH),) + @-$(ECHO) +++ creating special flash batch file + @-$(ECHO) +++ disabled because there is no special flash batch file +else + @-$(ECHO) +++ creating special flash batch file + @-$(RULE_SPECIAL_MAKE_FLASH_BATCH) +endif # ------------------------------------------------------------------------------ # Dependencyfile include (build) @@ -270,7 +429,7 @@ $(APP)_flash.hex : $(APP).$(TGT_SUFFIX) # If the files do not exist then the includes will be ignored. # ------------------------------------------------------------------------------ ifneq ($(MAKECMDGOALS),rebuild) --include $(subst .o,.d,$(FILES_O)) # for example tmp/obj/sys_start.d, tmp/obj/mcal_cpu.d, etc +-include $(subst .o,.d,$(FILES_O)) endif diff --git a/examples/chapter16_08/target/app/make/app_rules.gmk b/examples/chapter16_08/target/app/make/app_rules.gmk index 9a0de5e83..8737bc559 100644 --- a/examples/chapter16_08/target/app/make/app_rules.gmk +++ b/examples/chapter16_08/target/app/make/app_rules.gmk @@ -1,5 +1,5 @@ # -# Copyright Christopher Kormanyos 2007 - 2018. +# Copyright Christopher Kormanyos 2007 - 2024. # Distributed under the Boost Software License, # Version 1.0. (See accompanying file LICENSE_1_0.txt # or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -11,13 +11,20 @@ # # Generic pattern rules # -# Based on GNU Make 3.81 +# Based on GNU Make 4.2.1 # # 07-April-2010 # # ------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ +# GCC dependency flags. +# ------------------------------------------------------------------------------ + +DEP_FLAGS := -MMD -MF $(PATH_OBJ)/$(basename $(@F)).d + + # ------------------------------------------------------------------------------ # Rule to compile C++ source file (*.cpp) to object file (*.o). # ------------------------------------------------------------------------------ @@ -30,12 +37,29 @@ $(PATH_OBJ)/%.o : %.cpp # ...and create an assembly listing using objdump, # ...and generate a dependency file (using the -MM flag), # ...and be sure to include the path in the dependency file. - @-$(CC) $(CPPFLAGS) $(C_INCLUDES) $< -c -o $(PATH_OBJ)/$(basename $(@F)).o 2> $(PATH_ERR)/$(basename $(@F)).err - @-$(SED) -e 's|.h:\([0-9]*\),|.h(\1) :|' -e 's|:\([0-9]*\):|(\1) :|' $(PATH_ERR)/$(basename $(@F)).err - @-$(OBJDUMP) -S -C $(PATH_OBJ)/$(basename $(@F)).o > $(PATH_SRC)/$(basename $(@F)).lst - @-$(ECHO) -n $(PATH_OBJ)/ > $(PATH_OBJ)/$(basename $(@F)).d - @-$(CC) $(CPPFLAGS) $< -MM >> $(PATH_OBJ)/$(basename $(@F)).d + @-$(CC) $(CXXFLAGS) $(C_INCLUDES) $(DEP_FLAGS) $< -c -o $(PATH_OBJ)/$(basename $(@F)).o 2> $(PATH_ERR)/$(basename $(@F)).err + @-$(SED) -e 's|.h:\([0-9]*\),|.h(\1) :|' -e 's|.hpp:\([0-9]*\),|.hpp(\1) :|' -e 's|.cpp:\([0-9]*\),|.cpp(\1) :|' $(PATH_ERR)/$(basename $(@F)).err +ifneq ($(findstr risc,$(GCC_TARGET)),) + @-$(OBJDUMP) -S $(PATH_OBJ)/$(basename $(@F)).o > $(PATH_LST)/$(basename $(@F)).lst +endif + +# ------------------------------------------------------------------------------ +# Rule to compile C++ source file (*.cc) to object file (*.o). +# ------------------------------------------------------------------------------ +$(PATH_OBJ)/%.o : %.cc + @$(ECHO) +++ compile: $< to $@ + # Compile the source file, + # ...and reformat (using sed) any possible error/warning messages + # for the VisualStudio(R) output window, + # ...and create an assembly listing using objdump, + # ...and generate a dependency file (using the -MM flag), + # ...and be sure to include the path in the dependency file. + @-$(CC) $(CXXFLAGS) $(C_INCLUDES) $(DEP_FLAGS) $< -c -o $(PATH_OBJ)/$(basename $(@F)).o 2> $(PATH_ERR)/$(basename $(@F)).err + @-$(SED) -e 's|.h:\([0-9]*\),|.h(\1) :|' -e 's|.hpp:\([0-9]*\),|.hpp(\1) :|' -e 's|.cc:\([0-9]*\),|.cc(\1) :|' $(PATH_ERR)/$(basename $(@F)).err +ifneq ($(findstr risc,$(GCC_TARGET)),) + @-$(OBJDUMP) -S $(PATH_OBJ)/$(basename $(@F)).o > $(PATH_LST)/$(basename $(@F)).lst +endif # ------------------------------------------------------------------------------ # Rule to compile C source file (*.c) to object file (*.o). @@ -49,11 +73,9 @@ $(PATH_OBJ)/%.o : %.c # ...and create an assembly listing using objdump, # ...and generate a dependency file (using the -MM flag), # ...and be sure to include the path in the dependency file. - @-$(CC) $(CFLAGS) $(C_INCLUDES) $< -c -o $(PATH_OBJ)/$(basename $(@F)).o 2> $(PATH_ERR)/$(basename $(@F)).err - @-$(SED) -e 's|.h:\([0-9]*\),|.h(\1) :|' -e 's|:\([0-9]*\):|(\1) :|' $(PATH_ERR)/$(basename $(@F)).err - @-$(OBJDUMP) -S $(PATH_OBJ)/$(basename $(@F)).o > $(PATH_SRC)/$(basename $(@F)).lst - @-$(ECHO) -n $(PATH_OBJ)/ > $(PATH_OBJ)/$(basename $(@F)).d - @-$(CC) $(CFLAGS) $< -MM >> $(PATH_OBJ)/$(basename $(@F)).d + @-$(CC) $(CFLAGS) $(C_INCLUDES) $(DEP_FLAGS) $< -c -o $(PATH_OBJ)/$(basename $(@F)).o 2> $(PATH_ERR)/$(basename $(@F)).err + @-$(SED) -e 's|.h:\([0-9]*\),|.h(\1) :|' -e 's|.c:\([0-9]*\),|.c(\1) :|' $(PATH_ERR)/$(basename $(@F)).err + @-$(OBJDUMP) -S $(PATH_OBJ)/$(basename $(@F)).o > $(PATH_LST)/$(basename $(@F)).lst # ------------------------------------------------------------------------------ @@ -68,4 +90,4 @@ $(PATH_OBJ)/%.o : %.s # ...and create an assembly listing using objdump @-$(CC) $(AFLAGS) $(C_INCLUDES) $< -c -o $(PATH_OBJ)/$(basename $(@F)).o 2> $(PATH_ERR)/$(basename $(@F)).err @-$(SED) -e 's|:\([0-9]*\):|(\1) :|' $(PATH_ERR)/$(basename $(@F)).err - @-$(OBJDUMP) -S $(PATH_OBJ)/$(basename $(@F)).o > $(PATH_SRC)/$(basename $(@F)).lst + @-$(OBJDUMP) -S $(PATH_OBJ)/$(basename $(@F)).o > $(PATH_LST)/$(basename $(@F)).lst diff --git a/examples/chapter16_08/target/micros/avr/make/avr_flags.gmk b/examples/chapter16_08/target/micros/avr/make/avr_flags.gmk index 9492cc2c0..0fbe20f6f 100644 --- a/examples/chapter16_08/target/micros/avr/make/avr_flags.gmk +++ b/examples/chapter16_08/target/micros/avr/make/avr_flags.gmk @@ -9,28 +9,41 @@ # compiler flags for the target architecture # ------------------------------------------------------------------------------ +ifneq ($(MAKE),make) GCC_VERSION = 14.2.0 +endif GCC_TARGET = avr GCC_PREFIX = avr TGT_SUFFIX = elf -TGT_CFLAGS = -Os \ - -mmcu=atmega328p \ - -fsigned-char \ - -mrelax \ - -finline-functions \ - -finline-limit=64 \ +TGT_ALLFLAGS = -Os \ + -mmcu=atmega328p \ + -mrelax \ + -finline-functions \ + -finline-limit=64 \ + -fsigned-char \ -DWIDE_INTEGER_NAMESPACE=ckormanyos -TGT_CPPFLAGS = -std=c++14 +ifeq ($(GCC_VERSION),14.2.0) +TGT_ALLFLAGS := $(TGT_ALLFLAGS) \ + -mdouble=32 \ + -mlong-double=64 +endif + +TGT_CFLAGS = -std=c99 \ + $(TGT_ALLFLAGS) + +TGT_CXXFLAGS = -std=c++14 \ + $(TGT_ALLFLAGS) TGT_INCLUDES = -I$(PATH_APP)/util/STL TGT_AFLAGS = -TGT_LDFLAGS = -nostdlib \ - -nostartfiles \ - -Wl,--gc-sections \ +TGT_LDFLAGS = -nostdlib \ + -nostartfiles \ + -Wl,--gc-sections \ + -Wl,-Map,$(APP).map \ -T $(LINKER_DEFINITION_FILE)