Go Down

Topic: A "simple" makefile for Arduino (Read 13 times) previous topic - next topic

alejandroerickson

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 :).  

#
# 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(;;);  // do nothing until hard reset
# }
#
# void setup(){
#    //code...
# }
#
# void loop(){
#    \\code...
# }
#
# int main(){
#    init();
#   setup();
#   for(;;) loop();
#   return 0;
# }

#***************************** HARDWARE
#these things are specific to the board.  Try finding the parameters
#for yours on the Internet ^_^
#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

Marius

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: [Select]
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: [Select]

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
Rather people think you to be a fool than you open your mouth and confirm it.

MikeSmith

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

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.

Code: [Select]

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.
Rather people think you to be a fool than you open your mouth and confirm it.

Graynomad

#4
Aug 03, 2011, 11:06 am Last Edit: Aug 03, 2011, 11:09 am by Graynomad Reason: 1
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
Rob Gray aka the GRAYnomad www.robgray.com

Go Up