Editing MakeFile

Hello everyone,

I'm looking for some advice on a slightly offbeat topic related to the Nordic SDK.

I'd like to modify the Makefile of one of the SDK examples so that it displays a custom message at the end of the compilation process, similar to how STM32 does it (number of errors and warning, and time it took to compile).

Could someone guide me on how to achieve this? Should I edit the main Makefile, or is it necessary to adjust the common Makefile?

Thanks for your help!

Parents
  • Hi,

    There is no way to do this directly in the Makefile, but you can create a script for it.
    The easiest way to get a list of warnings and errors is to store the build log into a file, for example:

    west build -b nrf52840dk_nrf52840 > build_output.log

    Then you can use grep to find how many times "warning" and "error" shows up in the build log, for example:

    echo "Warnings: $(grep -i ": warning" build_output.log | wc -l)"
    echo "Errors: $(grep -i ": error" build_output.log | wc -l)"

    To get the time, you can use the time command when building:

    time west build -b nrf52840dk_nrf52840

    If you create a script for building, you can get the time before and after building and output this.
    Here is an example script that prints out warnings, errors, and time:

    #!/bin/bash
    
    start=$(date +%s)
    west build -b $1 > build_output.log
    end=$(date +%s)
    
    duration=$((end - start))
    
    warnings=$(grep -i ": warning" build_output.log | wc -l)
    errors=$(grep -i ": error" build_output.log | wc -l)
    
    echo "Warnings: $warnings"
    echo "Errors: $errors"
    echo "Build time: $duration seconds"

    This takes the board as an argument when running the file, so if the file is called count_build_issues.sh you can run it to build for nRF52840 DK as follows:

    ./count_build_issues.sh nrf52840dk_nrf52840

    Best regards,
    Marte

Reply
  • Hi,

    There is no way to do this directly in the Makefile, but you can create a script for it.
    The easiest way to get a list of warnings and errors is to store the build log into a file, for example:

    west build -b nrf52840dk_nrf52840 > build_output.log

    Then you can use grep to find how many times "warning" and "error" shows up in the build log, for example:

    echo "Warnings: $(grep -i ": warning" build_output.log | wc -l)"
    echo "Errors: $(grep -i ": error" build_output.log | wc -l)"

    To get the time, you can use the time command when building:

    time west build -b nrf52840dk_nrf52840

    If you create a script for building, you can get the time before and after building and output this.
    Here is an example script that prints out warnings, errors, and time:

    #!/bin/bash
    
    start=$(date +%s)
    west build -b $1 > build_output.log
    end=$(date +%s)
    
    duration=$((end - start))
    
    warnings=$(grep -i ": warning" build_output.log | wc -l)
    errors=$(grep -i ": error" build_output.log | wc -l)
    
    echo "Warnings: $warnings"
    echo "Errors: $errors"
    echo "Build time: $duration seconds"

    This takes the board as an argument when running the file, so if the file is called count_build_issues.sh you can run it to build for nRF52840 DK as follows:

    ./count_build_issues.sh nrf52840dk_nrf52840

    Best regards,
    Marte

Children
No Data
Related