Compile Esp8266/Esp32 Arduino Code with gmake on FreeBSD

This is inspired by Raffeale from FreeBSD forum. The original link is here.

Yet when following the step of Raffeale's post, I bumped into some trouble. So, with a little trial and error myself. I\'v figured out a way to compile code for Esp8266 with gmake.

System and Board

This is tested on FreeBSD 12.2 release amd64. No problem at all.

The board I\'m using is NodeMcuv2.

Other system or board is not tested.

Steps

I\'m dealing with Uno boards and Esp at the same time, so I installed the following packages.

# gives u both ability to compile code for arduino uno series and esp series
sudo pkg install arduino-mk arduino-core uarduno arduino-builder

Next step is to clone the Esp8266 official repo. You can put it anywhere you want, just modify makefile accordingly. I\'m going to put it in arduino system folder.

mkdir -p /usr/local/arduino/hardware/espressif 
cd /usr/local/arduino/hardware/espressif 
git clone https://github.com/esp8266/Arduino.git esp8266
cd esp8266
# !This is important, checkout the release tags, otherwise the compile will fail
git checkout tags/2.7.4
git submodule update --init --recursive

Now, as described by Raffeale in his post, a slight modification of the get.py file is needed because FreeBSD is not supported by Esp8266. Just change to tools directory and add the following line to the file (near line 102). Added line is marked with +++.

def identify_platform():
    arduino_platform_names = {'Darwin'  : {32 : 'i386-apple-darwin',   64 : 'x86_64-apple-darwin'},
                    +++       'FreeBSD' : {32 : 'i686-pc-linux-gnu',   64 : 'x86_64-pc-linux-gnu'},
                              'Linux'   : {32 : 'i686-pc-linux-gnu',   64 : 'x86_64-pc-linux-gnu'},
                              'LinuxARM': {32 : 'arm-linux-gnueabihf', 64 : 'aarch64-linux-gnu'},
                              'Windows' : {32 : 'i686-mingw32',        64 : 'x86_64-mingw32'}}
    bits = 32

Next, run the get.py script.

chmod -R 0755 $CUR_FILE/esp8266
python get.py

The last step would be to delete the esptool directory, and replace it with the newest version from github repo.

rm -rf esptool
git clone https://github.com/espressif/esptool.git esptool

Now, grab mk file and makefile from my github, put it wherever you want (modify makefile to include the mk file and change the path to wherever the esp8266 github repo is).

Then you're good to go.

Write some code, plug in your esp board, compile and upload the code with the following command.

gmake upload clean

That\'s it. Don\'t have to install arduino18 package, don\'t have to patch and recompile arduino-builder from port. You\'ve got the code up and running.

Modify the Makefile and mk file freely to suit your needs.