Pages: [1] 2 3   Go Down
Author Topic: A "simple" makefile for Arduino  (Read 13022 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I wrote a makefile for arduino using various sources on the net.  Part of the makefile's text is here (but the whole thing is too long for the forum) and a bit more info, including a sample project with the BlinkM LEDs is posted on my site at http://alejandroerickson.com/joomla/personal-projects/73-a-makefile-for-arduino-v-0021 smiley.  

#
# A basic makefile for compiling .c and .cpp files for Arduino
# By Alejandro Erickson alejandro.erickson@gmail.com
# and some ideas snarfed from the Internet,
# Especially
#    David Wolever
#    http://blog.codekills.net/
# and
# eighthave, oli.keller,
# alex norman [with help from http://code.google.com/p/arduino/issues/detail?id=65#c5]
# also
# mimicking the output from Verbose Verify and Verbose Upload in the Arduino IDE 0021
#
# Disclaimer:  I am a GNUmake and Arduino newbie.  Suggestions and improvments are
# welcome.  This makefile does not deal with list files or assembly (except
# where I used a few lines from makefiles that do and was afraid to delete
# something).  Also, note that this builds the core library files in the
# Arduino IDE directory instead of this directory.
# Sorry if it messes up another project you have going...
#
# Instructions:
#
# This makefile assumes you are using Mac OS X and Arduino IDE.  You may
# have to specify a different location for the Arduino IDE and even for
# it's internal file structure.  I've tried to indicate where that might come up.
#
# Make a project folder for your code and add to it your main.cpp along with (this)
# Makefile.  You can also include library files there, but you don't have to.
#
# I think your main.cpp file should look more less like this:
#
# #include "WProgram.h"
# //#include <other library headers>
#
# //<#defines and globals>
#
# extern "C" void __cxa_pure_virtual()
# {
#     cli();    // disable interrupts
#     for(;smiley-wink;  // do nothing until hard reset
# }
#
# void setup(){
#    //code...
# }
#
# void loop(){
#    \\code...
# }
#
# int main(){
#    init();
#   setup();
#   for(;smiley-wink loop();
#   return 0;
# }

#***************************** HARDWARE
#these things are specific to the board.  Try finding the parameters
#for yours on the Internet smiley-kitty
#I've used the ones for the Arduino Duemilanove (or Nano w/ ATmega328)
#UPLOAD_SPEED = 57600
#UPLOAD_PROTOCOL = stk500
#BUILD_MCU = atmega328p
#F_CPU = 16000000


#I've used the ones for the Arduino UNO (or Nano w/ ATmega328)
#UPLOAD_SPEED = 115200
#UPLOAD_PROTOCOL = stk500v1
#BUILD_MCU = atmega328p
# why *L?  I don't know but that's what shows up in the Arduino IDE output
#F_CPU = 16000000L

#Seeeduino Mega
UPLOAD_SPEED = 57600
UPLOAD_PROTOCOL = stk500v1
BUILD_MCU = atmega1280
# why *L?  I don't know but that's what shows up in the Arduino IDE output
F_CPU = 16000000L



#this is where your Arduino is plugged in.  You can check it's exact
#location by plugging the board into your computer and typing cd /dev/tty. <tab>
#it might show up as a usb modem instead...
PORT = /dev/tty.usbserial-A7004J48
#PORT = /dev/tty.usbmodem1d11
#/dev/tty.usbserial*
#*********************************** END HARDWARE

#********************* PATHS TO IMPORTANT STUFF
#your main() should be in main.cpp.  don't change this, you'll mess things up
TARGET = main.cpp
 
Logged

Centurion RSA
Offline Offline
Full Member
***
Karma: 0
Posts: 166
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Alejandro
I did send this to your website,but it might be more beneficial for more people if we report on the forum.

I compiled using the latest make file and received the following error

Code:
make: *** No rule to make target `c:\Arduino/hardware/arduino/cores/arduino/pins_arduino.o', needed by `tmplib.a'.  Stop.

this is the path specified in the make file

Code:
CORE_LIB_SRC =  \
$(ARDUINO)/pins_arduino.c \
$(ARDUINO)/wiring.c \
$(ARDUINO)/wiring_analog.c \
$(ARDUINO)/wiring_digital.c \
$(ARDUINO)/wiring_pulse.c \
$(ARDUINO)/wiring_shift.c \
$(ARDUINO)/WInterrupts.c
Logged

Rather people think you to be a fool than you open your mouth and confirm it.

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can find a much more comprehensive Makefile that will work with regular sketches and libraries here:

  http://code.google.com/p/arducopter/source/browse/trunk/libraries/AP_Common/Arduino.mk

It includes some fairly hairy awk that is quite faithful to the processing that Arduino performs on sketches; you can break it but not easily.

The ArdupilotMega/ArducopterMega project uses this as part of their automated build testing, and it's also suitable for calling from Eclipse (why I built it in the first place).

 = Mike
Logged

Centurion RSA
Offline Offline
Full Member
***
Karma: 0
Posts: 166
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Code:
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=<path>.  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.
Logged

Rather people think you to be a fool than you open your mouth and confirm it.

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8626
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's one I use

www.robgray.com/temp/makefile

It works for me (and at least one other forum member IIRC) but YMMV.

It still has too much crap I think and every now and then I remove a bit. One day it will be nice and simple.

______
Rob
« Last Edit: August 03, 2011, 04:09:50 am by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Centurion RSA
Offline Offline
Full Member
***
Karma: 0
Posts: 166
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Rob,
Do you add project related c and cpp files under your C_MODULES macro. Will it not interfere with the library build?
Logged

Rather people think you to be a fool than you open your mouth and confirm it.

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8626
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Centurion RSA
Offline Offline
Full Member
***
Karma: 0
Posts: 166
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Rather people think you to be a fool than you open your mouth and confirm it.

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Centurion RSA
Offline Offline
Full Member
***
Karma: 0
Posts: 166
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Rather people think you to be a fool than you open your mouth and confirm it.

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8626
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Centurion RSA
Offline Offline
Full Member
***
Karma: 0
Posts: 166
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Rather people think you to be a fool than you open your mouth and confirm it.

Centurion RSA
Offline Offline
Full Member
***
Karma: 0
Posts: 166
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Rather people think you to be a fool than you open your mouth and confirm it.

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Code:
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=<path>.  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.
Logged

Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 70
Posts: 2766
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Code:
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=<path>.  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 <SPACE> 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
Logged

Pages: [1] 2 3   Go Up
Jump to: