Build with Arduino-Makefile


By alxm, 1 year ago

This is a short tutorial for building games with Arduino-Makefile from the command line, instead of with the Arduino IDE. I ran these steps on 64bit Linux, but Arduino-Makefile is compatible with Mac and Windows too!

Why? I was already using an external code editor, so why not bypass the IDE all the way? Building this way is a lot faster too, I'm able to compile example sketches in 4 sec vs 14 sec with the IDE!

I first wrote this article on my website, check it out for a bit of extra content like customizing your project's structure.

1. Install Arduino

Install the Gamebuino META dev environment as normal, so you can build your game with the IDE.

2. Install Arduino-Makefile

I cloned the latest version to my home folder:

$ cd ~
$ git clone

3. Choose a Project

Pick a sketch you want to build, and create a new file called Makefile in its source folder (where the .ino file is). I'll use the Gamebuino META a_Hello example here:

$ cd ~/Arduino/libraries/Gamebuino_META/examples/1.Basics/a_Hello
$ touch Makefile
$ ls
a_Hello.ino Makefile

4. Edit Makefile

Note that the ARDUINO_DIR, ARDMK_DIR, and ALTERNATE_CORE_PATH paths below may be different on your system. You can check what they are by building with the IDE and looking at the output (remember to turn Verbose On from File > Preferences).

# Paths to Arduino IDE and cloned Arduino-Makefile
ARDUINO_DIR = $(HOME)/arduino
ARDMK_DIR = $(HOME)/Arduino-Makefile

# Specify the custom Gamebuino board and where it's installed BOARD_TAG = gamebuino_meta_native ALTERNATE_CORE_PATH =

# The Arduino libraries the game uses ARDUINO_LIBS = Gamebuino_META SPI

# The META lib expects SKETCH_NAME to be defined CFLAGS += -D__SKETCH_NAME__="$(TARGET).ino" CXXFLAGS += -D__SKETCH_NAME__="$(TARGET).ino"

# Now that everything is configured, include Arduino-Makefile include $(ARDMK_DIR)/

5. Build & Upload

$ make # Compile code and build .BIN file $ make upload # Flash to Gamebuino $ make clean # Remove all build files

All of these just work, even upload! You can build even faster with make -j, which runs commands in parallel.