This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to automate compilation by including all necessary files

Hi, 

I wanna automate the processing of compilation, my idea is to point all path-related files (*.c and *.h), I wrote script which is looking for all *.c and *.h files and includes them into makefile

#!/bin/bash

src_file=Sources.mk
header_file=Headers.mk

if [ -f "$src_file" ]
then
	echo "$src_file found."
else
	echo "# Source files common to all targets" >> $src_file && echo "SRC_FILES += \\" >> $src_file && find . -path ./examples -prune -o -type f -name *.[c] | sed 's/.\//  \$(SDK_ROOT)\//' | sed 's/$/ \\/' >> $src_file
fi

if [ -f "$header_file" ]
then
	echo "$header_file found."
else
	echo "# Include folders common to all targets" >> $header_file && echo "INC_FOLDERS += \\" >> $header_file && find . -path ./examples -prune -o -type f -name *.[h] -exec dirname {} \; | sed 's/.\//  \$(SDK_ROOT)\//' | sed 's/*.h//g' | sed 's/$/ \\/' >> $header_file	
fi

They were included into main Makefile as

include Source.mk

include Headers.mk

But when I try to compile something I get some errors, i.e.

Compiling file: ant_stack_config.c
Compiling file: ant_bpwr_simulator.c
In file included from /nrf51/12.3.0/components/ant/ant_profiles/ant_bpwr/simulator/ant_bpwr_simulator.h:65:0,
                 from /nrf51/12.3.0/components/ant/ant_profiles/ant_bpwr/simulator/ant_bpwr_simulator.c:41:
/nrf51/12.3.0/components/ant/ant_profiles/ant_bpwr/ant_bpwr.h:55:10: fatal error: ant_parameters.h: No such file or directory
 #include "ant_parameters.h"
          ^~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [_build/nrf51422_xxac_ant_bpwr_simulator.c.o] Error 1

Means that script missed some files, is it possible to automate it or to compile SDK as static library?

  • Hi,

     

    Headers (and binary) for ANT enabled Softdevices is distributed by Dynastream, so you'll have to contact them via. www.thisisant.com in order to obtain.

    If you are not using the ANT protocol, I recommend excluding it from your library.

     

    Best regards,

    Håkon

  • Yes, I commented out ANT headers and sources, but got another one. My question is how to automate the proccess of linking all necessary files. For example, I have a dir with all *.c and *.h files and have main.c with included *.h files, my script has to read all includes, finds all necessary files and compiles it

  • Have you gotten everything to compile properly? If yes, then the next step is to create a library using arm-none-eabi-ar, like we do in the makefile's for micro-ecc (external/ folder of the SDK). There should be plenty of examples on how to do that on stackoverflow and similar forums.

     

    Cheers,

    Håkon

  • Yes, but when I compile I get error, that gcc can't find some files or variables, for example I exclude ./examples and ./components/ant folders from sources and headers path.

    In file included from /nrf51/12.3.0/components/ble/ble_services/ble_escs/nrf_ble_escs.h:49:0,
                     from /nrf51/12.3.0/components/ble/ble_services/ble_escs/nrf_ble_escs.c:41:
    /nrf51/12.3.0/config/es_app_config.h:81:2: error: #error MISSING ETLM DELAY TIMING
     #error MISSING ETLM DELAY TIMING
      ^~~~~
    make: *** [_build/nrf51422_xxac_nrf_ble_escs.c.o] Error 1

    I see this code is related to NRF52, if I have NRF51 only how can I config to compile only all files for NRF51? Or in general to prevent the same errors

  • Hi,

    In order to compile all the files in components/ folder, you have to also have the configuration for some of the those libraries. It might be of more benefit for you just to compile the source and headers in with your project instead. Creating an archive of it all is likely to be a back-and-forth situation wrt. different configurations and preprocessor definitions.

    Is there a specific reason why you want to create an archive of the SDK?

     

    Best regards,

    Håkon

Related