Arduino-Makefile icon indicating copy to clipboard operation
Arduino-Makefile copied to clipboard

Add support for compiling through Arduino's command line

Open sudar opened this issue 12 years ago • 11 comments

In Arduino 1.5.x, Arduino executable can also be passed command line options.

When we add support for 1.5 (issue #45) we can look about adding support for this as well.

sudar avatar Jun 27 '13 05:06 sudar

I was just looking at this as well. It might be useful to compile through this, since that makes sure that all the hassle of parsing boards.txt, selecting stuff, etc. is handled by the arduino code. One particular advantage is that it also parses platform.txt, which can contain alternative compiler recipes (which Arduino-Makefile currently hardcodes).

However, a quick test shows that the commandline options aren't quite what you'd expect. For starters, passing a relative path didn't work (I suspect it looks inside the sketchbook, then). Furthermore, compiling actually seems to happen through creating a window and doing stuff there, instead of completely bypassing the GUI stuff (I learned that from the code, I didn't manage to actually compile anything due to some java exception...)

Having said that, I think that compiling through the arduino command might be the way to go, for reasons stated above... I might have a look at submitting some patches for the IDE if I can find the time. Probably something like a --batch option to prevent spawning a GUI and to output to stdout instead of the regular output window, but I guess that might require some refactoring of the Arduino IDE code.

matthijskooijman avatar Oct 25 '13 09:10 matthijskooijman

See also https://groups.google.com/a/arduino.cc/d/msg/developers/3WANmjH9Mwc/AS5Gsr3OuPoJ

matthijskooijman avatar Oct 25 '13 16:10 matthijskooijman

I think that compiling through the arduino command might be the way to go,

I agree with you. But it is just that arduino command-line is not mature enough :(

PS: I am also keeping an eye on your pull request to IDE https://github.com/arduino/Arduino/pull/1639

sudar avatar Oct 28 '13 06:10 sudar

arduino-builder is used by the ide now, however that does none of the boards.txt parsing

sej7278 avatar Mar 19 '17 09:03 sej7278

Huh? You pass a --fqbn (fully qualified board name) to arduino-builder and it then parses boards.txt and platform.txt to figure out what settings and options to use. One thing is that arduino-builder needs to be explicitly told in what directories to look for these files (e.g. the IDE passes the sketchbook, its installation directory and any downloaded cores in ~/.arduino15), but that's probably ok for the makefile.

Also, the CLI of the java IDE itself has also been improved significantly, it no longer requires X11 for example, accepts relative paths, etc.

matthijskooijman avatar Mar 19 '17 09:03 matthijskooijman

i meant you still need to come up with fqbn which is most of the work, there's no equivalent to "make show_boards" or whatever, and yes the various library/hardware/tools locations to look in are a pain but that's mainly due to the seemingly random versionned locations boards manager puts stuff

sej7278 avatar Mar 19 '17 10:03 sej7278

arduino-cli seems to have the same problem as arduino-builder - you still have to figure out the FQBN, generally by running the IDE once and grabbing it. if anyone's interested i made a wrapper Makefile that uses similar syntax to arduino-mk, but it still needs a make show_boards equivalent:

# pro mini 5v 16mhz
FQBN = arduino:avr:pro:cpu=16MHzatmega328

all:
	arduino-cli compile --fqbn $(FQBN) $(notdir $(CURDIR)).ino

upload:
	arduino-cli upload -b $(FQBN) -p $(MONITOR_PORT) $(CURDIR)

ispload:
	arduino-cli upload -b $(FQBN) -P usbasp $(CURDIR)

burn_bootloader:
	arduino-cli burn-bootloader -b $(FQBN) -P usbasp -v $(CURDIR)

clean:
	rm -rf $(CURDIR)/build

monitor:
	screen $(MONITOR_PORT) 115200

sej7278 avatar Sep 16 '20 12:09 sej7278

you still have to figure out the FQBN, generally by running the IDE once and grabbing it

Well, you'll always have to make a choice for the board you want to compile for, so that does not seem like a problem?

Or are you saying you need the Java IDE to get the FQBN because arduino-cli cannot tell you what boards are supported? If so, did you see arduino-cli board listall and arduino-cli board details?

matthijskooijman avatar Sep 16 '20 13:09 matthijskooijman

listall does most of it (think i missed that!) but the little options like this which is a simple esp01 are not listed:

esp8266:esp8266:generic:xtal=80,vt=flash,exception=legacy,ssl=all,ResetMethod=ck,CrystalFreq=26,FlashFreq=40,FlashMode=dout,eesz=512K128,led=2,sdk=nonosdk_190703,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=115200

you just get esp8266:esp8266:generic from listall, you'd have to mine through boards.txt to figure out the options - which is easier in the IDE menu's. not sure how you could duplicate that in arduino-cli, maybe some sort of listoptions but it would be a bit heavy i suspect.

details is pretty much useless to me, it never identifies correctly, probably as i'm not using arduino-badged devices.

sej7278 avatar Sep 16 '20 13:09 sej7278

details is pretty much useless to me, it never identifies correctly, probably as i'm not using arduino-badged devices.

Huh? You can give arduino board details a partial FQBN (such as listed by listall) and it will show you all the options and the possible values.

matthijskooijman avatar Sep 16 '20 14:09 matthijskooijman

ah crumbs sorry, found it now.....

arduino-cli board details -b esp8266:esp8266:generic

love that output!

think its board list that doesn't always work

sej7278 avatar Sep 16 '20 16:09 sej7278