Custom Makefile and <application.h>

The company I work for uses a variety of device types (argon, boron) for the same application, depending on the cell service/wifi availability at each of our customers’ sites. Currently, we have 4 “products” with very similar firmware to each other to accommodate our general need. We manage our firmware source code on github as 4 separate, independent code bases that contain essentially the same code (except for product id, and a few minor differences here and there).

I am interested in consolidating the firmware into one code base to make feature development easier, but being a beginner c++ programmer I’m not sure the correct approach for this.

In order to compile our firmware to 4 different products, I’m attempting to write a custom makefile to build the firmware. I’m having trouble getting it to work, because make can’t find the “application.h” included in each file.

Is a custom makefile the correct approach, or is there a better way to handle compiling the same firmware to different products? If a makefile is the correct approach, how do I accommodate the Spark core stuff (“application.h”) in my makefile?

This is my first exposure to writing makefiles, so more beginner friendly explanations are appreciated. I’ve been mainly working by consulting the particle-core-communication repo (it was referenced on a forum post I found)


It might be easier and make more sense to utilize the definitions made in spark_wiring_platform.h to conditionally enable blocks of code for each device.

However, you could also create a src/ file in your project to customize the build and continue using the master Makefile used by Workbench and neopo.

# Standard behavior must be included here
INCLUDE_DIRS += $(SOURCE_PATH)/$(USRSRC)  # add user sources to include path
CPPSRC += $(call target_files,$(USRSRC_SLASH),*.cpp)
CSRC += $(call target_files,$(USRSRC_SLASH),*.c)

APPSOURCES=$(call target_files,$(USRSRC_SLASH),*.cpp)
APPSOURCES+=$(call target_files,$(USRSRC_SLASH),*.c)

# Custom stuff can be added here


You can also forget about application.h. It has been replaced by Particle.h (for Spark Core too) for years now.

Also when you have distinct product IDs for each variation of your code you could use that throughout your code in #if (_YOUR_PRODUCT_ID_ == 123456) ... #endif blocks for conditional compiling as @nrobinson2000 suggested already.


Thank you, this is exactly what I was look for. Appreciate it!