### Project Definition and Library Setup Source: https://github.com/libtom/libtommath/blob/develop/demo/CMakeLists.txt Configures the project name and library name. It handles both included and stand-alone usage scenarios, finding the library and setting the build type. ```cmake if(PROJECT_NAME) set(LIBRARY_NAME ${PROJECT_NAME}) else() # Define an independent project and all the necessary stuff around project(${LTM_TEST} LANGUAGES C) set(LIBRARY_NAME libtommath) find_package(${LIBRARY_NAME}) include(CTest) if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Release") endif() endif() ``` -------------------------------- ### Verify GNU Libtool Version Source: https://github.com/libtom/libtommath/wiki/Successes-and-Failures-of-Building-LibTomMath Command to check the version of the GNU libtool installed, differentiating it from the native libtool. ```shell $ /usr/local/bin/libtool --version libtool (GNU libtool) 2.4.2 Written by Gordon Matzigkeit , 1996 Copyright (C) 2011 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ``` -------------------------------- ### Build LibTomMath with CMake Source: https://github.com/libtom/libtommath/blob/develop/README.md Clone the repository, create a build directory, and use CMake to configure the build. Use 'make -j$(nproc)' to compile. A shared library can be built by setting -DBUILD_SHARED_LIBS=On. ```bash git clone https://github.com/libtom/libtommath.git mkdir -p libtommath/build cd libtommath/build cmake .. make -j$(nproc) ``` -------------------------------- ### Build Shared Library with Libtool Source: https://github.com/libtom/libtommath/wiki/Successes-and-Failures-of-Building-LibTomMath Use this command to build the shared library of LibTomMath when libtool is available. ```bash LIBTOOL="/usr/local/bin/libtool" gmake -f makefile.shared ``` -------------------------------- ### S390x CPU Information Source: https://github.com/libtom/libtommath/wiki/Successes-and-Failures-of-Building-LibTomMath Displays vendor information for an S390x system running Debian. ```bash user@debians390x:~/GITHUB/libtommath$ cat /proc/cpuinfo vendor_id : IBM/S390 ``` -------------------------------- ### OpenBSD Make Parse Errors Source: https://github.com/libtom/libtommath/wiki/Successes-and-Failures-of-Building-LibTomMath Illustrates common parse errors encountered when using the wrong 'make' utility on OpenBSD, preventing shared library builds. ```makefile *** Parse error in /home/user/GITHUB/libtommath: Need an operator in 'LIBNAME' ) *** Parse error: Need an operator in 'endif' (makefile.shared:8) *** Parse error: Need an operator in 'CROSS_COMPILE' (makefile_include.mk:16) *** Parse error: Need an operator in 'endif' (makefile_include.mk:18) *** Parse error: Missing dependency operator (makefile_include.mk:22) *** Parse error: Missing dependency operator (makefile_include.mk:23) ``` -------------------------------- ### MIPS CPU and System Information Source: https://github.com/libtom/libtommath/wiki/Successes-and-Failures-of-Building-LibTomMath Displays CPU information, kernel version, and byte order for a MIPS Malta system running Debian. ```bash $ cat /proc/cpuinfo system type : MIPS Malta machine : mti,malta processor : 0 cpu model : MIPS 24Kc V0.0 FPU V0.0 BogoMIPS : 688.12 wait instruction : yes microsecond timers : yes tlb_entries : 16 extra interrupt vector : yes hardware watchpoint : yes, count: 1, address/irw mask: [0x0ff8] isa : mips1 mips2 mips32r1 mips32r2 ASEs implemented : mips16 shadow register sets : 1 kscratch registers : 0 package : 0 core : 0 VCED exceptions : not available VCEI exceptions : not available $ uname -a Linux debianmips32 4.9.0-8-4kc-malta #1 Debian 4.9.144-3.1 (2019-02-19) mips GNU/Linux $ gcc -dM -E -x c /dev/null | grep BYTE_ORDER #define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__ $ gcc -dM -E -x c /dev/null | grep LDBL #define __LDBL_MAX__ 1.7976931348623157e+308L #define __LDBL_MAX_EXP__ 1024 #define __LDBL_HAS_INFINITY__ 1 #define __LDBL_MIN__ 2.2250738585072014e-308L #define __LDBL_HAS_QUIET_NAN__ 1 #define __LDBL_HAS_DENORM__ 1 #define __LDBL_EPSILON__ 2.2204460492503131e-16L #define __LDBL_MANT_DIG__ 53 #define __LDBL_MIN_EXP__ (-1021) #define __LDBL_MAX_10_EXP__ 308 #define __LDBL_DENORM_MIN__ 4.9406564584124654e-324L #define __LDBL_MIN_10_EXP__ (-307) #define __LDBL_DIG__ 15 ``` -------------------------------- ### Find and Configure Valgrind for Memory Checking Source: https://github.com/libtom/libtommath/blob/develop/demo/CMakeLists.txt Locates the 'valgrind' executable and sets options for memory checking, including tracing child processes and performing a full leak check. ```cmake find_program(MEMORYCHECK_COMMAND valgrind) set(MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full") ``` -------------------------------- ### Sparc64 Debian Build Information Source: https://github.com/libtom/libtommath/wiki/Successes-and-Failures-of-Building-LibTomMath Shows system information and GCC preprocessor definitions for long double on a Sparc64 Debian system. Useful for understanding floating-point representation. ```shell cpu : TI UltraSparc IIi (Sabre) fpu : UltraSparc IIi integrated FPU pmu : ultra12 prom : OBP 3.10.24 1999/01/01 01:01 type : sun4u ncpus probed : 1 ncpus active : 1 D$ parity tl1 : 0 I$ parity tl1 : 0 Cpu0ClkTck : 0000000005f5e100 cpucaps : flush,stbar,swap,muldiv,v9,mul32,div32,v8plus,vis MMU Type : Spitfire MMU PGSZs : 8K,64K,512K,4MB ``` ```shell $ uname -a Linux debiansparc64 4.15.0-2-sparc64 #1 Debian 4.15.11-1 (2018-03-20) sparc64 GNU/Linux ``` ```shell $ gcc -dM -E -x c /dev/null | grep BYTE_ORDER #define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__ ``` ```shell $ gcc -dM -E -x c /dev/null | grep LDBL #define __LDBL_MAX__ 1.18973149535723176508575932662800702e+4932L #define __LDBL_MAX_EXP__ 16384 #define __LDBL_HAS_INFINITY__ 1 #define __LDBL_MIN__ 3.36210314311209350626267781732175260e-4932L #define __LDBL_HAS_QUIET_NAN__ 1 #define __LDBL_HAS_DENORM__ 1 #define __LDBL_DECIMAL_DIG__ 36 #define __LDBL_EPSILON__ 1.92592994438723585305597794258492732e-34L #define __LDBL_MANT_DIG__ 113 #define __LDBL_MIN_EXP__ (-16381) #define __LDBL_MAX_10_EXP__ 4932 #define __LDBL_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966L #define __LDBL_MIN_10_EXP__ (-4931) #define __LDBL_DIG__ ``` -------------------------------- ### Verify Native Libtool Version Source: https://github.com/libtom/libtommath/wiki/Successes-and-Failures-of-Building-LibTomMath Command to check the version of the native libtool, distinguishing it from the GNU version. ```shell $ libtool --version libtool (not (GNU libtool)) 1.5.26 ``` -------------------------------- ### Set Include Directories for Test Executable Source: https://github.com/libtom/libtommath/blob/develop/demo/CMakeLists.txt Configures include directories for the test executable. It includes the current source directory and a conditional include for the parent directory when the project name matches the test name. ```cmake target_include_directories(${LTM_TEST} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} $<$:${CMAKE_CURRENT_SOURCE_DIR}/..> ) ``` -------------------------------- ### Link Test Executable to Library Source: https://github.com/libtom/libtommath/blob/develop/demo/CMakeLists.txt Links the test executable against the main library, specified by LIBRARY_NAME. This makes the library's functionality available to the test program. ```cmake target_link_libraries(${LTM_TEST} PRIVATE ${LIBRARY_NAME} ) ``` -------------------------------- ### Create Test Executable Target Source: https://github.com/libtom/libtommath/blob/develop/demo/CMakeLists.txt Defines an executable target named by LTM_TEST, linking the shared.c and test.c source files. ```cmake add_executable(${LTM_TEST} ${CMAKE_CURRENT_SOURCE_DIR}/shared.c ${CMAKE_CURRENT_SOURCE_DIR}/test.c ) ``` -------------------------------- ### OpenBSD Libtool Linking Errors Source: https://github.com/libtom/libtommath/wiki/Successes-and-Failures-of-Building-LibTomMath Shows typical linking errors that occur when the incorrect 'libtool' is used on OpenBSD, leading to build failures for shared libraries. ```shell cc -I./ -Wall -Wsign-compare -Wextra -Wshadow -Wsystem-headers -Wdeclaration-afo... cc -I./ -Wall -Wsign-compare -Wextra -Wshadow -Wsystem-headers -Wdeclaration-afo... cc -I./ -Wall -Wsign-compare -Wextra -Wshadow -Wsystem-headers -Wdeclaration-afo... libtool --mode=link --tag=CC cc bn_error.lo bn_fast_mp_invmod.lo bn_fast_mp_mo libtool: link: cc bn_error.lo bn_fast_mp_invmod.lo bn_fast_mp_montgomery_reduce0 bn_error.lo: file not recognized: File format not recognized cc: error: linker command failed with exit code 1 (use -v to see invocation) Error while executing cc bn_error.lo bn_fast_mp_invmod.lo bn_fast_mp_montgomery0 gmake: *** [makefile.shared:64: libtommath.la] Error 1 ``` -------------------------------- ### Set Linker Options for Test Executable Source: https://github.com/libtom/libtommath/blob/develop/demo/CMakeLists.txt Adds linker flags to the test executable. These flags are applied before other public link options. ```cmake target_link_options(${LTM_TEST} BEFORE PUBLIC ${LTM_LD_FLAGS} ) ``` -------------------------------- ### Check Byte Order Source: https://github.com/libtom/libtommath/wiki/Successes-and-Failures-of-Building-LibTomMath This command checks the byte order of the system using GCC preprocessor directives. It is useful for understanding endianness which can affect binary data handling. ```bash user@debians390x:~/GITHUB/libtommath$ gcc -dM -E -x c /dev/null | grep BYTE_ORDER #define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__ ``` -------------------------------- ### Set Compile Options for Test Executable Source: https://github.com/libtom/libtommath/blob/develop/demo/CMakeLists.txt Applies compile-time options to the test executable. It conditionally defines LTM_TEST_DYNAMIC if the library is a shared library. ```cmake target_compile_options(${LTM_TEST} PRIVATE $<$,SHARED_LIBRARY>:-DLTM_TEST_DYNAMIC> ${LTM_C_FLAGS} ) ``` -------------------------------- ### Error Handling with Goto Source: https://github.com/libtom/libtommath/wiki/The-Sourcecode:-Formatting-and-Style Error handling is typically done using a goto statement to a common error-handling section at the end of the function. The goto statement should be on the same line as the error check and aligned. ```c if ((err = mp_add(&a, &b, &c) != MP_OKAY) goto LTM_ERR; if ((err = mp_incr(&c) != MP_OKAY) goto LTM_ERR; ``` -------------------------------- ### Set Minimum CMake Version Source: https://github.com/libtom/libtommath/blob/develop/demo/CMakeLists.txt Specifies the minimum version of CMake required for this project. Ensures compatibility with required features. ```cmake cmake_minimum_required(VERSION 3.10) ``` -------------------------------- ### Intel Compiler Warnings Source: https://github.com/libtom/libtommath/wiki/Successes-and-Failures-of-Building-LibTomMath This output shows diagnostic warnings from the Intel compiler (ICC) regarding unsupported GCC diagnostic options. It suggests a workaround to suppress these warnings. ```text icc: command line warning #10148: option '-Wbad-function-cast' not supported icc: command line warning #10148: option '-Wcast-align' not supported ``` -------------------------------- ### Define Test Executable Name Source: https://github.com/libtom/libtommath/blob/develop/demo/CMakeLists.txt Sets a variable for the name of the test executable. This is used later when creating the executable target. ```cmake set(LTM_TEST test-ltm) ``` -------------------------------- ### Add CTest Test Source: https://github.com/libtom/libtommath/blob/develop/demo/CMakeLists.txt Defines a CTest test case that runs the compiled test executable. This integrates the test into the CMake testing framework. ```cmake add_test(NAME ${LTM_TEST} COMMAND ${LTM_TEST}) ``` -------------------------------- ### Check Double/Long Double Precision on Debian ARM Source: https://github.com/libtom/libtommath/wiki/Successes-and-Failures-of-Building-LibTomMath Verifies if double and long double have the same precision on a Debian ARM system. This is relevant for platforms where `double == long double`. ```c #include #include #include int main (void) { printf("%d == %d %d == %d\n", LDBL_MANT_DIG, DBL_MANT_DIG, LDBL_MAX_EXP, DBL_MAX_EXP); exit(EXIT_SUCCESS); } ``` ```shell $ ./dbl_print 53 == 53 1024 == 1024 ``` ```shell $ uname -a Linux debian 3.16.0-6-versatile #1 Debian 3.16.57-2 (2018-07-14) armv5tejl GNU/Linux ``` ```shell $ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 8.11 (jessie) Release: 8.11 Codename: jessie ``` ```shell $ cat /proc/cpuinfo processor : 0 model name : ARM926EJ-S rev 5 (v5l) BogoMIPS : 500.22 Features : swp half thumb fastmult vfp edsp java CPU implementer : 0x41 CPU architecture: 5TEJ CPU variant : 0x0 CPU part : 0x926 CPU revision : 5 Hardware : ARM-Versatile PB Revision : 0000 Serial : 0000000000000000 ``` -------------------------------- ### Configure Debug CFLAGS Source: https://github.com/libtom/libtommath/blob/develop/demo/CMakeLists.txt Sets compiler flags for debug builds, specifically for non-MSVC compilers. Includes debug symbols and optimization level 1. ```cmake if(NOT MSVC) set(CMAKE_C_FLAGS_DEBUG "-g3 -O1") endif() ``` -------------------------------- ### Conditional Statement Parentheses Source: https://github.com/libtom/libtommath/wiki/The-Sourcecode:-Formatting-and-Style Use parentheses for individual statements within an if expression for clarity. This applies to complex boolean conditions. ```c if ((a > 0) && (a < 42) && ((a & 0x1) == 0)) ... ``` -------------------------------- ### Check Long Double Max Value Source: https://github.com/libtom/libtommath/wiki/Successes-and-Failures-of-Building-LibTomMath This command uses GCC to display the maximum value and related properties of the long double type. This information is relevant for understanding the precision and range of floating-point calculations. ```bash user@debians390x:~/GITHUB/libtommath$ gcc -dM -E -x c /dev/null | grep LDBL #define __LDBL_MAX__ 1.18973149535723176508575932662800702e+4932L #define __LDBL_MAX_EXP__ 16384 #define __LDBL_HAS_INFINITY__ 1 #define __LDBL_MIN__ 3.36210314311209350626267781732175260e-4932L #define __LDBL_HAS_QUIET_NAN__ 1 #define __LDBL_HAS_DENORM__ 1 #define __LDBL_EPSILON__ 1.92592994438723585305597794258492732e-34L #define __LDBL_MANT_DIG__ 113 #define __LDBL_MIN_EXP__ (-16381) #define __LDBL_MAX_10_EXP__ 4932 #define __LDBL_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966L #define __LDBL_MIN_10_EXP__ (-4931) #define __LDBL_DIG__ 33 ``` -------------------------------- ### Excessive Parentheses Avoidance Source: https://github.com/libtom/libtommath/wiki/The-Sourcecode:-Formatting-and-Style Avoid overly nested or redundant parentheses in arithmetic expressions. Keep expressions clear and concise. ```c a = x + (y * z); b = (((a + (b / c)) - (d * e)) + (3 / 2)); c = (x - y) - z; ``` -------------------------------- ### Assignment in If Clause for Error Handling Source: https://github.com/libtom/libtommath/wiki/The-Sourcecode:-Formatting-and-Style Assignments within an if() clause are permitted only for error checking during error handling. This is an exception to the general rule against assignments in if conditions. ```c if ((err = mp_add(&a, &b, &c) != MP_OKAY) goto LTM_ERR; ``` -------------------------------- ### Ternary Operator Parentheses Source: https://github.com/libtom/libtommath/wiki/The-Sourcecode:-Formatting-and-Style Enclose the conditional statement in a ternary operator within parentheses. This ensures correct evaluation order. ```c a = (b < 0) ? -1 : 1; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.