A "simple" makefile for Arduino

I haven't used it for a while (been busy with hardware) but I think that's the story. I also so far have only used it for single-file projects and that's handled by the

PROJECT_NAME = test

line, where "test" is the main .c file.

I too am not a makefile expert, I cleaned up the original, got it to a useable state, and left it at that.

I will be getting back into the software side of things soon though so am happy to work with you to get a simple (and understandable to mortals) makefile up and running.


Rob

Thanks Rob, I will keep an eye out for that.

Hi all,

Just to say that I also posted my version of a Makefile (Makefile_0022_sdaau) on Arduino playground - CommandLine; works on me for Arduino IDE 0022 and Ubuntu 11.04 - should also have some limited handling of libraries, and should save output files in a sketch subdirectory ...

Cheers!

All the contributions are really very nice but - not one has worked on windows 7 yet. Am I the only bugger on windows?

I take it mine didn't work either. I converted it from a MAC version for Windows (Vista but that shouldn't matter).

IIRC I had to compile one sketch in the IDE to create all the core .o files and then the .a file. I could not get the makefile to compile the cores itself.


Rob

Rob,
No, I am afraid not. There are issues with paths on most of these makefiles. But the most common problem is the included files or defines for the compiled file is not found.
I did manage to get the cores compiled. There again it was a path issue on the version I used. Yours however had the path correct but could not find a rule to compile for adruino_pins.o. Which means it could not see the file, I think.
I will use a smaller project to test on today. I am sure that there must be something small with the windows setup. Once I have made some sense (i hope ) of it all, I will give some feedback. I will be taking a small break soon so it might be a week or so from now.

Guys,
It would seem that the borrowed sketch that I am trying to compile suffers from the decease that the Adruino IDE causes. People do not code properly. Things are not defined in all the correct places etc etc. I think a good enhancement to the Aruino IDE would be enforcing correct header file usage. And this has been my gripe with the Arduino IDE from the word go. I started coding in such a manner that I could not move my sketch to another IDE. It was a mess and hence the decision to use Visual C++ with a makefile for borrowed sketches and Eclipse for project from scratch.

So most of the Makefiles that I have tested over the last two days would probably work fine if the code was written in any decent manner. I am going to attempt to fix the code and then report back.

Marius:
Mike,
I tried the makefile you suggested. Man how confusing. I always believed that the creators of makefiles are not from here. Now I am convinced. A normal guy like me will have no hope to fix any problems. As it is, it does not work for me. I get this error no matter what I try.

C:\arduino-0022\projects\Firmware>make

/usr/bin/sh: cd: C:/arduino-0022/projects/Firmware/../../../..: No such file or directory
makefile:56: *** ERROR: cannot determine sketchbook location - please specify on the commandline with SKETCHBOOK=.  Stop.




And when I specify on the command line I get the same.

It will be really magic if we could get a makefile that compiles Arduino sketches form a decent editor.

Marius,

As it stands the Makefile will not work on Windows due to a number of issues:

  • There seems to be no built-in interface to the Windows filesystem indexing tools, so there is no way for the tools to find Arduino on your system.
  • The sketch processor relies on awk and sed, as well as the behaviour of the shell. These are standard tools on developer-friendly systems like Linux and Mac OS, but Windows has no direct equivalents, so you end up needing to install cygwin.
  • WinAVR does not know how to handle paths generated by the cygwin version of make.

Short version - Windows is not a good place for this sort of software development. If you want better Arduino tools integration, consider running Linux in a VM.

MikeSmith:

Marius:
Mike,
I tried the makefile you suggested. Man how confusing. I always believed that the creators of makefiles are not from here. Now I am convinced. A normal guy like me will have no hope to fix any problems. As it is, it does not work for me. I get this error no matter what I try.

C:\arduino-0022\projects\Firmware>make

/usr/bin/sh: cd: C:/arduino-0022/projects/Firmware/../../../..: No such file or directory
makefile:56: *** ERROR: cannot determine sketchbook location - please specify on the commandline with SKETCHBOOK=.  Stop.




And when I specify on the command line I get the same.

It will be really magic if we could get a makefile that compiles Arduino sketches form a decent editor.

Marius,

As it stands the Makefile will not work on Windows due to a number of issues:

  • There seems to be no built-in interface to the Windows filesystem indexing tools, so there is no way for the tools to find Arduino on your system.
  • The sketch processor relies on awk and sed, as well as the behaviour of the shell. These are standard tools on developer-friendly systems like Linux and Mac OS, but Windows has no direct equivalents, so you end up needing to install cygwin.
  • WinAVR does not know how to handle paths generated by the cygwin version of make.

Short version - Windows is not a good place for this sort of software development. If you want better Arduino tools integration, consider running Linux in a VM.

I can't speak about Windows7 but I use the Arduino supplied unix bin utils with my own makefiles and
bash shell scripts on XP.
(Haven't yet tried the specific makefiles referenced above)
make, awk, sed, find, sh, and tons of other unix tools are shipped with the arduino package for windows
so there is no need to install cygwin or anything else.
I will admit I had all kinds of issues on Vista and eventually had to disable the silly UAC to
finally get some of the tools work correctly. Especially SVN and patch.

After two years of suffering with Vista, I upgraded back to XP for any windows needs,
which I now run in a VirtualBox VM on Linux.

What I've done just lately is have a windows batch file wrapper that locates the arduino unix tools or
WinAVR on the machine than sets up a few environment variables then calls make or sh depending
on what I need and leave windows behind. Works pretty good.
The key to automatically locating the Arduino tools is to put the makefile in the arduino tree.
Then the tools can be located from a relative path.
But I also have an enviornment variable that can be used to directly point to the unix tools.

The biggest issue I've run into is stupid windows file/directory names.
"Documents and Settings" and "My Documents" were just plain dumb names.
The use of in file names is really tough to flush out. It requires escaping. While painful,
it eventually it can be made to work so the resulting makefiles or scripts
can work on Windoze as well as *nix systems.
Then there is a nasty issue of paths longer than about 254 characters. While lots of places
claim higher, (and it shouldn't be an issue) there are multiple places where this creates issues.

To work around that there are some other techniques you have to use.
Sometimes you have to cd to a directory and use relative paths.
Sometimes you may have to create a subst drive and map the longer path
to a drive.

There are times where I literally spent the better part of a few weeks
chasing down some stupid windows tool issue.

Yep, Windoze sucks for any sort of real development especially for development environments
that have to build in multiple OS environments.

--- bill

Thanks for all the replies. Not good news for me as I intended to do some work on borrowed sketches in VC++. Just for the context sensitivity of the IDE. I use it like that with makefiles but the Arduino files is a bit of a challenge. I might still try one more thing and that is to make a local copy of the core and the libraries that are used by the sketches.

Hello guys,
yes, there are a lot of Makefiles there -- some work, some don't, some with limitations.
I think we should stop adapting and posting a lot of Makefiles with a lot of characteristics so I decided to create a comprehensive list of these Makefiles and try to create the most simple Makefile for Arduino ever -- that works!
For now we can compile sketches only that use standard functions and libraries (sketches with "#include" won't work, but I'm working on this).

If you want to contribute, please visit:

Thanks for that Justen. Please keep us posted here.

Hi, just to chime in here...I also prefer Make to using the IDE. Related to my post here: http://arduino.cc/forum/index.php/topic,69016.0.html -- I also built a simple Make build system for Arduino sketches that was based off a number of sample Makefiles I found, and my own tweaks.

I describe the build process for our stuff here: http://daisyworks.com/docs.html#tutorials -- and the Makefiles, etc. are all online at the github repo if you want to take them, hack them, modify them or whatever, feel free: GitHub - davisford/dw-firmwares: Open Firmwares for DaisyWorks Products

I didn't spend a LOT of time on this, and I'm sure it can be improved -- happy to hear any suggestions.

Before I go off and test another makefile, does it work for Windows?

Nope, sorry. I didn't bother trying to port it to Windows. Why not just grab a free Linux virtual machine and use one of those? VMWare has a ton -- you can download them and be up and running in minutes.

Anyway, it wouldn't be that hard to port the Makefile to Windows, but I probably am not going to get to that myself.

I have got Cygwin installed. Does that help any? I will have a look at the VM route.

I had a look at your makefile and I have the feeling it might just be doable in Windows. I will give it a try.

Yes, cygwin will definitely help. Trying to build it for native Windows cmd env. would really be a pain. If you need any help or have questions about it, shoot me a mail @ davis 'at' daisyworks.com -- and if you do get it to work on Windows, maybe we can post a copy back to github so other people can grab it.

FYI: If you get the free vmware player: http://downloads.vmware.com/d/info/desktop_downloads/vmware_player/3_0

...then you could grab one of these: http://www.vmware.com/appliances/directory/cat/508?k=ubuntu+11&c=508

I use Ubuntu b/c it is stable and works well and it has a large repository of software. You could get a Linux VM that has XWindows or one that doesn't. Either way, you could turn your Windows PC into full-screen Linux in a few minutes, and hardly notice the difference, and be able to switch back and forth with ALT+TAB. Just another option to consider.

Thanks for the links, i am on it already. Is there a context sensitive IDE for Ubuntu?

I will let you know about the windows version once I gave it a bash.

Zenocon
Can you be more specific about the Ubuntu version. I don't want to download the wrong thing again. It is rather large as well. I am looking at the Gnome version 11.04 . Is this OK?

Gnome means you're going to have a UI front end -- i.e. windowing system for it -- similar to windows. It will probably be easier for you to deal with coming from windows, but strictly speaking, a windowing system isn't necessary for doing Linux builds of arduino projects. You could even have VMware create a shared folder between your host (windows) and guest -- and do all your editing in windows, and then switch over to linux to run the makefile on the cmd line.

Or you could use Gnome on Linux and edit your projects in something like gedit (gnome's more capable version of notepad -- trust me, it's much better).

So, if you do go with an X-Windows system, you have two main choices: Gnome or KDE -- it probably doesn't matter which you choose at this point...gnome is a little more popular I think. There are other variants, as well, but this reply is already too long winded. Using an X-windows system on your VM will definitely make your image size blow up. You can download very simple little ubuntu VMs that have no X-Windows installed for a couple hundred meg.

The nice thing about VMs is that if you don't like it or you screw it up, you can just delete the 700MB file, and start over or get another one. You also need some reasonable hardware to make them run ok -- your PC should have at least 2GB RAM, and a decent processor or multi-core.

One of the things I look for is to see if they have VMWare Tools installed. This is kind of important b/c it allows you to do things like drag/drop files between the host/guest, and has better mouse/keyboard support. I usually just create my own VMs -- so I'm not sure which one to pick exactly. The VMWare site isn't the only place to find them. You can google for them, or find them on torrent sites.

This is an older Ubuntu distro, but it has VMWare Tools installed: http://www.visoracle.com/vm/ubuntu810/
I take it you are looking at this one: http://www.trendsigma.net/vmware/ubuntu1104.html -- the latter will probably be fine, but it doesn't look like it has tools installed, and AFAIK, you can't install them with VMWare Player.

I'd suggest just experimenting with one or two, and see what fits for you. If you have any questions, you can ping me direct at davis at daisyworks dot com, and I'll do my best to help out -- not sure if the forums here care so much about virtual machines.