Build with Arduino-Makefile

Creations

alxm

1 month 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 https://github.com/sudar/Arduino-Makefile

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 = \
    $(HOME)/.arduino15/packages/gamebuino/hardware/samd/1.2.1

# 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)/Sam.mk

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.

View full creation

Steph

NEW 1 month ago

Thank you Alex for this contribution. I am sure it will be very useful for many budding coders in the community. And considering the decrease in activity on the site, it is reassuring to note that our most esteemed coders are still there to deliver interesting things from time to time :-)

alxm

1 month ago

Thanks for the kind words Steph!

This is something I always wanted to do, so I can build my games for Gamebuino the same way I build them for other platforms, with make -f Makefile.gamebuino.

Also, going through this stuff really made me appreciate how Meta is compatible with Arduino Zero, things like Arduino-Makefile "just work" with minimal config :-)

alxm

NEW 1 month ago

Steph Steph

Thanks for the kind words Steph!

This is something I always wanted to do, so I can build my games for Gamebuino the same way I build them for other platforms, with make -f Makefile.gamebuino.

Also, going through this stuff really made me appreciate how Meta is compatible with Arduino Zero, things like Arduino-Makefile "just work" with minimal config :-)

jicehel

NEW 1 month ago

Great, i haven't install my stuff to developp in my new house atm but i like that i have read and gain of time is a very good thing  ;)

Sorunome

NEW 1 month ago

This is cool! Just saw that you hard-coded the version of the arduino boards in your description which was just updated to 1.2.2 though, to work with the newest samd board definitions. so yeah ^^