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

Makefile syntax in SDK examples

Hi !

I've seen that the Makefile given with the examples changed a lot between SDK11 and SDK12, lots of improvements ! However there's still something I don't get. Why do you use this syntax :

SRC_FILES += \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_serial.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_frontend.c \
$(SDK_ROOT)/components/libraries/button/app_button.c \

Instead of this one ?

SRC_FILES += $(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_serial.c 
SRC_FILES += $(SDK_ROOT)/components/libraries/log/src/nrf_log_frontend.c 
SRC_FILES += $(SDK_ROOT)/components/libraries/button/app_button.c 

In my opinion the second one is better, mainly because it allows to do that :

SRC_FILES += $(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_serial.c 
SRC_FILES += $(SDK_ROOT)/components/libraries/log/src/nrf_log_frontend.c 
SRC_FILES += $(SDK_ROOT)/components/libraries/button/app_button.c 
# Conditionally adding some_file to the build
ifeq($(SOME_MAKEFILE_VAR),1)
SRC_FILES += $(SDK_ROOT)/components/libraries/button/some_file.c 
endif

To conditionally add a file to the build, a folder to the include paths, a parameter to the compiler, etc.

By example you could use Makefile variables to add RTT files to the build, as well as defining (or not) NRF_LOG_USES_RTT.

Is there a reason for using the first syntax ?

Parents
  • I don't think it's necessary since the syntax used is totally valid. It's probably arbitrary if I find the other one better. Since I write a lot of Makefiles I was curious if the SDK team had a good reason to prefer a syntax I personally dislike over the other one. Anyway as andxnor mentioned it's also possible to combine both syntaxes, but then we end up with a mix of syntax which, IMHO, would be the worst.

    What kind of tools could they use ? At some point you have to specify which files to build, don't you ? Aside of the standard Makefile template we find in all projects, this plus the compiler/linker flags are the main content of the Makefile. Maybe they are extracted from the Keil project ? Their workflow may be interesting for me since I also have to maintain both a Makefile and a Keil project file for the same project.

Reply
  • I don't think it's necessary since the syntax used is totally valid. It's probably arbitrary if I find the other one better. Since I write a lot of Makefiles I was curious if the SDK team had a good reason to prefer a syntax I personally dislike over the other one. Anyway as andxnor mentioned it's also possible to combine both syntaxes, but then we end up with a mix of syntax which, IMHO, would be the worst.

    What kind of tools could they use ? At some point you have to specify which files to build, don't you ? Aside of the standard Makefile template we find in all projects, this plus the compiler/linker flags are the main content of the Makefile. Maybe they are extracted from the Keil project ? Their workflow may be interesting for me since I also have to maintain both a Makefile and a Keil project file for the same project.

Children
No Data
Related