Hello !

This is my first post on the forum :-) I didn't receive my gamebuino yet, but I've started to work with the emulator.

I'm here to share with you a Makefile for compiling a sketch without running arduino IDE. This makefile will automaticaly create the .bin and the .hex file, as arduino would have.

It assume that you already have configured correctly the arduino environment (actualy, the Makefile relies on the arduino binaries)



SKETCHBOOK_PATH=$(shell grep sketchbook $(LOCAL_PATH)/preferences.txt | cut -d= -f2)

.PHONY: clean

tmp/%.deps: $(LOCAL_PATH)/package_%_index.json tmp python3 config.py $(LOCAL_PATH) < $< > $@

%.bin %.hex: %.ino *.h tmp/gamebuino.deps | tmp

cp $&lt; tmp/sketch/
cp *.h tmp/sketch/

$(ARDUINO_PATH)/arduino-builder \
    -compile \
    -logger=machine \
    -hardware $(ARDUINO_PATH)/hardware \
    -hardware $(LOCAL_PATH)/packages \
    -hardware $(SKETCHBOOK_PATH)/hardware \
    -tools $(ARDUINO_PATH)/tools-builder \
    -tools $(ARDUINO_PATH)/hardware/tools/avr \
    -tools $(LOCAL_PATH)/packages \
    -built-in-libraries $(ARDUINO_PATH)/libraries \
    -libraries $(SKETCHBOOK_PATH)/libraries \
    -fqbn=gamebuino:samd:gamebuino_meta_native \
    -ide-version=10805 \
    -build-path $$(realpath tmp/build) \
    -warnings=none \
    -build-cache $$(realpath tmp/cache) \
    -prefs=build.warn_data_percentage=75 \
    $$(cat tmp/gamebuino.deps) \
    -verbose \

cp tmp/build/$&lt;.bin $*.bin
cp tmp/build/$&lt;.hex $*.hex

rm -r tmp/sketch/$&lt;

tmp: mkdir -p tmp/sketch mkdir -p tmp/build mkdir -p tmp/cache

clean: rm -r tmp

You have to edit the two first line in the Makefile according with the arduino installation directory.

There is also a python script which extract all the dependancies from the gamebuino configuration file :

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys, json

if name == "main": deps = json.load(sys.stdin)['packages'][0]['platforms'][0]['toolsDependencies'] for dep in deps: print("-prefs=runtime.tools.%s.path=%s/packages/%s/tools/%s/%s/" %
end=' ') sys.stdout.flush()

Just put the two files in the same directory as the ino project. Now you can run make sketch.binor make sketch.hex in order the compile your project.

The Makefile run for me (debian stable), and my fail for you. Please tell me if you encountered some trouble (and better, how to make this script better :) )

Last comments

1 year ago
Author :  drummyfish

Thank you kind sir, this is exactly what I need :-)

1 year ago
Author :  josephscade


Thanks for this tutorial, I think you forget to mention that you have to name the Python program "config.py".

Also, is there a way to use the version of GCC provided by your Distribution instead of the bundled one ? (Asking because Arduino IDE ships GCC 4.8 which is very old and not maintened, according to the GCC official website).

2 years ago
Author :  Chimrod

No, arduino-mk is in the Debian distribution, but the package is actualy so out-of-date that I didn't look to the source project (I may be wrong).

I've started with a simple bash shell, which became this Makefile : probably a lot simpler, but I exactly know what it does :)