sudar / Arduino-Makefile

Makefile for Arduino sketches. It defines the workflows for compiling code, flashing it to Arduino and even communicating through Serial.
http://hardwarefun.com/tutorials/compiling-arduino-sketches-using-makefile
GNU Lesser General Public License v2.1
2.02k stars 449 forks source link

Add support for compiling through Arduino's command line #92

Open sudar opened 11 years ago

sudar commented 11 years ago

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.

matthijskooijman commented 10 years ago

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 commented 10 years ago

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

sudar commented 10 years ago

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

sej7278 commented 7 years ago

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

matthijskooijman commented 7 years ago

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.

sej7278 commented 7 years ago

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 commented 4 years ago

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
matthijskooijman commented 4 years ago

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?

sej7278 commented 4 years ago

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.

matthijskooijman commented 4 years ago

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.

sej7278 commented 4 years ago

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