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?

Parents
  • 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

Reply
  • 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

Children
  • Hi, thanks for your reply)

    The reason to simplify adding files to the Makefile. Cause sometimes I missed some files when I compile project, the same case when I edit nrf_config.h file

    I thought there was easy way to build static library and include it into my project every time

    I like, for example Xcode, way when I don't care about including libraries files and able to build my project, editing only my files and include some headers

  • The problem is that the SDK is not really setup to be compiled as a full library, so there's a lot of things that you'll need to handle in order to make that happen, in terms of preprocessor defines, compiler settings, architecture (nrf51x22, nrf52832, nrf52810, nrf52840), etc. It's likely easier to manage the sources directly using a project file (makefile or an IDE)

  • I know it is an old thread but I wanted to mention the one of the reasons would be to speed up compilation times which are too often very long. I know GNU make is taking take of it in many cases but it still unnecessarily happens anyways (f.ex: whenever something is changed in the project's makefile).

    Having SDK as a library or being able to configure it to precompile once could save plenty of time.

Related