简体   繁体   中英

Makefile Customizing Variables

I have an arduino board with a WIFI shield. I am assembling and testing my units at home and deploying them at a test-site.

These are the sets of parameters that I am using now:

Home: 
String WIFI_SSID = "myssid";
String WIFI_PASSWORD = "123";
bool USE_IP = true;
int PORT = 8080;
String IP = "192.168.1.140";
String DOMAIN = null;

Test-site:
String WIFI_SSID = "Test-siteSSID";
String WIFI_PASSWORD = "456";
bool USE_IP = false;
int PORT = 80;
String IP = null;
String DOMAIN = "www.google.com";

I find it very annoying that I have to change these variables manually in the Arduino IDE whenever I am switching locations (which happens quite frequently). So I took a look at https://github.com/sudar/Arduino-Makefile which could allow me to use command line to build and compile arduino code.

This is what I plan to do:

  1. Create 2 header files with their own sets of variables inside
  2. pass in a custom argument to make, ie make HOME or make DEPLOY
  3. Figure out how to include the right header file at compile time
  4. compile, which is taken care by the make file itself.

My questions are:

  1. How can I pass in an additional parameter HOME or DEPLOY in step 2?
  2. Based on the argument supplied, how can the Arduino compiler figure out which header file to include in step 3?

This goes in your makefile:

TARGET?=DEPLOY

all: build ...

build:
\tgcc ... -D$(TARGET) ...

.PHONY: all build ...

This goes in your source code:

#ifdef DEPLOY
#include "defs_deploy.h"
#else
#ifdef HOME
#include "defs_home.h"
#else
#error Neither DEPLOY nor HOME is defined
#endif /* HOME */
#endif /* DEPLOY */

One of these goes on your command line:

make TARGET=DEPLOY
make TARGET=HOME

Not pretty, but it will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM