Windows command line build

Because the Arduino Makefile command line build is not very friendly for Windows programmers, I have started a project to make Windows batch files to compile and upload Arduino sketches. Here is what I have so far...

http://www.arduino.cc/playground/Code/WindowsCommandLine

Be sure to read the instructions carefully so you know what the issues are. Please post any questions, comments, and bug reports to this thread. Thanks!

  • Don

New and improved! Now the Windows command-line build will parse your preferences.txt file just like the Arduino IDE does to determine your MCU type, programmer type, etc. Look here for download and documentation:

http://www.arduino.cc/playground/Code/WindowsCommandLine

hey cosine,
that looks great, I started playing with the makefile but couldn't solve it in 5 minutes..

thanks also for all the contributions and addition to the playground :wink:

b.

This is great.

If there was a top-level batch file called "make" then the windows command line build would start to look more like the unix one.

Has anyone looked into using a windows version of "make"? I know there are several out there, and it might be easier to just crib one .exe than to have a whole system of batch files. Just a thought.

If there was a top-level batch file called "make" then the windows command line build would start to look more like the unix one.

Feel free to rename abuild.bat to make.bat ... it's YOUR computer, after all! :slight_smile:
Seriously, I didn't want to call it "make" because I didn't want to introduce conflicts with somebody who had a genuine make utility already there.

it might be easier to just crib one .exe than to have a whole system of batch files.

The reason I did all this work was because I was going to use the makefile, so I started looking for a Windows version of make. Then I realized I needed grep and sed also, which meant I was going to need to find them, hope they were compatible, blah blah blah. It seemed like too much hassle for every single Windows user of Arduino to have to go through. So now you don't have to search for anything; just download 3 batch files, put them in your path, set your ARDUINO_PATH environment variable, and you're done. Run abuild.bat and it will call the other 2 batch files as needed.

Oh, and did I mention your binaries will be smaller than with the ones the Makefile or the IDE will produce?

The reason I did all this work was because I was going to use the makefile, so I started looking for a Windows version of make. Then I realized I needed grep and sed also, which meant I was going to need to find them, hope they were compatible, blah blah blah. It seemed like too much hassle for every single Windows user of Arduino to have to go through. So now you don't have to search for anything; just download 3 batch files, put them in your path, set your ARDUINO_PATH environment variable, and you're done. Run abuild.bat and it will call the other 2 batch files as needed.

Well, I decided to see just how hard it was to do it the other way. I noticed that the arduino root directory contained cygwin1.dll - cygwin is a port of gnu utilities to Windoze. The avr-tools binaries are based on cygwin. So I downloaded the base cygwin utilities and "make". This is very easy via the cygwin setup program. Once I had the actual files installed, I copied make, grep and sed from the cygwin bin directory to arduino/tools/avr/bin. It turns out that a couple of other dlls are needed to get them working: cygpcre-0.dll and cygiconv-2.dll. Just copy the to the same directory that cygwin1.dll is in. Now you can run make, sed and grep just like you run, say avr-size.

As far as I can tell, these are gnu compatible utilities and should not have any problems with standard uses.

Given that we already are using cygwin style tools, I don't think it would be that hard to add these utilities to the arduino-win distribution. I'll play around and see if I can build all the examples from the command line using the cygwin make utility.

Oh, and did I mention your binaries will be smaller than with the ones the Makefile or the IDE will produce?

Bonus!

Given that we already are using cygwin style tools, I don't think it would be that hard to add these utilities to the arduino-win distribution.

That would be great! In the meantime, you and I could assemble links and instructions into a page on the Playground so that people could use either method.

Another thing to consider: I am proposing changes to Arduino 0008 that will make many sketches compile to much smaller binaries. This requires changing some Java code in the Arduino IDE, splitting up lib/targets/arduino source code into smaller source files, and (relevant to this discussion) reworking the build process to link in the runtime as a library instead of object files. It would be nice to see if we can change the makefile to work with my library patch... see here:
http://www.arduino.cc/playground/Code/LibPatch0007

The windows batch files I wrote are designed to work with either the original Arduino 0007 distribution, or with the library patch above.

Incidentally, that is why my batch files make smaller binaries; and if you use the library patch also, they get a LOT smaller!

Well, I got the cygwin windows make working. It's not quite as intuitive as I had hoped. Actually, the make program itself is fine, it's just that full windows path names (eg C:\something with spaces) don't play well with makefile syntax. You have to use the "8.3 safe" file names to avoid the spaces, and I haven't figured out how to handle the drive spec yet. When I used relative path names with no spaces, it worked just like the unix version. The cygwin core programs may have a solution for this - I'll have to do some research.

The Makefile itself could probably use a few tweaks if it's going to build a library. What I would like to be able to do is go to the top-level sketch directory and type "make SKETCH=foo" and have it automatically build the sketch in directory foo without having to do much, or any, editing. For both unix and Windows.

If we have a compatible command line build process for both windows and unix (Mac too?) then the IDE could be simplified. Instead of issuing a bunch of compiler commands, it could just go to the right directory and run "make" with the appropriate targets, capturing the output. This has the advantages of unifying the command line and IDE build process, making the IDE simpler, and allowing modifications to the build process by just editing the Makefile (instead of hacking the java code for the IDE).

eh?

The first versions of Arduino worked by simply running "make" against an appropriate Makefile, but it was more work than doing the compilation from within the IDE. For one, we had all sorts of weird problems with things working differently on different platforms (e.g. some Windows machine needed forward slashes in the Makefile, others double-backslashes). Plus, we're doing a reasonable amount of pre-processing in Java (like automatically generating function prototypes) that seem like they'd be more difficult to do with a Makefile (nor does distributing Perl or Python or whatever with Arduino seem like a good idea). At this point, so few people use the command line build that I'm reluctant to put more work into it. But don't let me stop you from playing around.

I am having a problem with running these batch files. I run the following in a batch file:

SET ARDUINO_PATH="C:\Program Files\arduino-0007"
Call abuild.bat MCcode_temp.cpp

Where MCcode_temp.cpp is the file I want to compile and upload to the Arduino. However, I always receive the following error dialog box:
"This application has failed to start because cygwin1.dll was not found. Reinstalling the application may fix this problem" with a dialog box heading name "avr-g++.exe -Unable to locate component".

The commandline reports the following: "abuild.bat: ***ERROR: cannot compile MCCode_temp.cpp"

Is there something obvious I am missing? The above mentioned DLL file is located in the arduino folder, as expected.

Any help would be greatly appreciated.

Cheers

Hmmm... I am not sure, but I would try changing the line:

SET ARDUINO_PATH="C:\Program Files\arduino-0007"

to:

SET ARDUINO_PATH=C:\Program Files\arduino-0007

Make absolutely sure you have NO SPACES at the end of this line also.

Wait... never mind. I see what the problem is: my batch files cannot cope with spaces in the ARDUINO_PATH, with or without quotes. I am working on a fix, but in the mean time, you could try moving the entire directory "c:\program files\arduino-0007" to "c:\arduino-0007", then do:

set ARDUINO_PATH=c:\arduino-0007

When I get the spaces issue fixed, I will update the batch files on the Playground and post a message here. (It may take me a couple of days to get around to it.)

  • Don

OK, actually it turned out to be a lot simpler to fix than I thought! :slight_smile:

I have fixed the batch file abuild.bat in the Playground:

http://www.arduino.cc/playground/uploads/Code/abuild.txt

Delete your existing abuild.bat, download the above, then rename it from abuild.txt to abuild.bat.

You will need to remove the double-quotes (") from your calling batch file:

set ARDUINO_PATH=c:\Program Files\arduino-0007

Let me know how it works...

  • Don

Hi,

I'm trying to use the command line/batch utility and keep getting the error: "Missing build.f_cpu in file preferences.txt"

Here is the output:
C:>abuild.bat C:\arduino-0010\examples\Communication\PhysicalPixel\PhysicalPixe
l.pde
Missing build.f_cpu in file "C:\Documents and Settings\sweddle\Application Data
arduino\preferences.txt"

I looked over the preferences.txt file and no such luck, does this utility work with VER 10?

Thanks
Shane

please update the batch files to work with arduino-0011. agetpref.bat does not work anymore, because the preference file changed, as it seems.

cheers, stahl

You could also try installing cygwin and using the command line version.

After fiddling with the makefile using cygwin and/or nmake for a few hours to try and sort whitespace and frontslash/backslash problems as well as conflicts between an installed copy of cygwin, win32 ports of popular unix utilities and arduino's own cygwin tools, I stumbled upon this set of batch files and decided to try them out. As evidenced by the two above posts, they were a bit outdated for 0011, but it was relatively simple to get them working again. It seems as though some of the settings that used to be extracted from the preferences.txt file are no longer available from there, however, so I simply resorted to defining more environment variables - it's a tad longer to setup, but everything works again.

Begin new around here, I'm not sure whether I should just go and update the referring wiki page (Arduino Playground - WindowsCommandLine) with the new batch files and an explanation, or whether I should try to send the modifications to other people for testing first. Thoughts? The page hasn't been updated in over a year and the batch files are clearly out of date, so I figure it can't cause much harm to update and sort out any resulting problems in this forum.

Many thanks to Don Cross for the original files.

(First post, have to add this: Arduino is great - good job guys. A great step in providing access to physical computing to the masses. Even though I have a computer engineering background and am not afraid of getting lost in the world of mcu's, I really appreciate the simplicity and "packaging" of your system. A better tool results in better productivity, and that is true of software as well as hardware.)

You could always post an updated version, but keep a reference to the previous one somewhere.

(Sorry I haven't gotten around to this yet - I haven't fallen off the face of the earth. I've been away and just got back straight into a rush at work, so I haven't had much time to mess around with the arduino lately. Hoping to get this done some time over the next few days.)

Alright, I've updated the page with the new directives and batch files. The original batch files are still linked from the bottom of the page. Hopefully that works for everybody!