Compiling via command line fails pins_arduino.o

I'm trying to compile and upload arduino sketches via the command line. The Java IDE doesn't play nice with Xmonad and since I do all my editing in vim anyways it'd be nice to cut out the extra step of firing up a GUI.

I keep getting an error about build-cli/pins_arduino.o with the example blink sketch. If I load the same program in the arduino Java IDE it compiles without an issue.

Here's what I have so far:

OS: Linux Mint Debian 64 bit
arduino and required libs installed from debian unstable repo
arduino java IDE works

Directory layout:

me@laptop ~/sketchbook/Blink $ find
.
./Blink.pde
./makefile
me@laptop ~/sketchbook/Blink $

Compile error:

me@laptop ~/sketchbook/Blink $ make --debug
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-pc-linux-gnu
Reading makefiles...
/usr/share/arduino/Arduino.mk:405: build-cli/depends.mk: No such file or directory
mkdir build-cli
echo \#include \"WProgram.h\" > build-cli/Blink.cpp
cat  Blink.pde >> build-cli/Blink.cpp
/usr/bin/avr-g++ -MM -mmcu=atmega328p -DF_CPU= -I. -I/usr/share/arduino//hardware/arduino/cores/arduino  -g -Os -w -Wall -ffunction-sections -fdata-sections -fno-exceptions build-cli/Blink.cpp -MF build-cli/Blink.d -MT build-cli/Blink.o
cat build-cli/Blink.d > build-cli/depends.mk
rm build-cli/Blink.cpp
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-pc-linux-gnu
Reading makefiles...
Updating goal targets....
 File `all' does not exist.
   File `build-cli/Blink.hex' does not exist.
     File `build-cli/Blink.elf' does not exist.
       File `build-cli/Blink.o' does not exist.
        File `build-cli/Blink.cpp' does not exist.
       Must remake target `build-cli/Blink.cpp'.
echo \#include \"WProgram.h\" > build-cli/Blink.cpp
cat  Blink.pde >> build-cli/Blink.cpp
       Successfully remade target file `build-cli/Blink.cpp'.
      Must remake target `build-cli/Blink.o'.
/usr/bin/avr-g++ -c -mmcu=atmega328p -DF_CPU= -I. -I/usr/share/arduino//hardware/arduino/cores/arduino  -g -Os -w -Wall -ffunction-sections -fdata-sections -fno-exceptions build-cli/Blink.cpp -o build-cli/Blink.o
      Successfully remade target file `build-cli/Blink.o'.
       File `build-cli/pins_arduino.o' does not exist.
      Must remake target `build-cli/pins_arduino.o'.
/usr/bin/avr-gcc -c -mmcu=atmega328p -DF_CPU= -I. -I/usr/share/arduino//hardware/arduino/cores/arduino  -g -Os -w -Wall -ffunction-sections -fdata-sections -std=gnu99 /usr/share/arduino//hardware/arduino/cores/arduino/pins_arduino.c -o build-cli/pins_arduino.o
In file included from /usr/lib/gcc/avr/4.5.3/../../../avr/include/avr/delay.h:37:0,
                 from /usr/share/arduino//hardware/arduino/cores/arduino/wiring_private.h:30,
                 from /usr/share/arduino//hardware/arduino/cores/arduino/pins_arduino.c:26:
/usr/lib/gcc/avr/4.5.3/../../../avr/include/util/delay.h: In function ‘_delay_ms’:
/usr/lib/gcc/avr/4.5.3/../../../avr/include/util/delay.h:140:17: error: expected expression before ‘)’ token
/usr/lib/gcc/avr/4.5.3/../../../avr/include/util/delay.h: In function ‘_delay_us’:
/usr/lib/gcc/avr/4.5.3/../../../avr/include/util/delay.h:217:17: error: expected expression before ‘)’ token
make: *** [build-cli/pins_arduino.o] Error 1
me@laptop ~/sketchbook/Blink $

Makefile:

me@laptop ~/sketchbook/Blink $ cat makefile 
ARDUINO_DIR = /usr/share/arduino/

TARGET       = Blink
MCU          = atmega328p
ARDUINO_PORT = /dev/ttyUSB0

include /usr/share/arduino/Arduino.mk
me@laptop ~/sketchbook/Blink $

Sketch:

me@laptop ~/sketchbook/Blink $ cat Blink.pde 
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */

void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);     
}

void loop() {
  digitalWrite(13, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(1000);              // wait for a second
}
me@laptop ~/sketchbook/Blink $

Can you show around line 140 in your copy of delay.h file?

I added in the line numbers with vim. I also included the comments above the subroutine because it seemed like it could be relevant.

 98 /**
 99    \ingroup util_delay
100 
101    Perform a delay of \c __ms milliseconds, using _delay_loop_2().
102 
103    The macro F_CPU is supposed to be defined to a
104    constant defining the CPU clock frequency (in Hertz).
105 
106    The maximal possible delay is 262.14 ms / F_CPU in MHz.
107 
108    When the user request delay which exceed the maximum possible one,
109    _delay_ms() provides a decreased resolution functionality. In this
110    mode _delay_ms() will work with a resolution of 1/10 ms, providing
111    delays up to 6.5535 seconds (independent from CPU frequency).  The
112    user will not be informed about decreased resolution.
113 
114    If the avr-gcc toolchain has __builtin_avr_delay_cycles(unsigned long)
115    support, maximal possible delay is 4294967.295 ms/ F_CPU in MHz. For
116    values greater than the maximal possible delay, overflows results in
117    no delay i.e., 0ms.
118 
119    Conversion of __us into clock cycles may not always result in integer.
120    By default, the clock cycles rounded up to next integer. This ensures th    at
121    the user gets atleast __us microseconds of delay.
122 
123    Alternatively, user can define __DELAY_ROUND_DOWN__ and __DELAY_ROUND_CL    OSEST__
124    to round down and round to closest integer.
125 
126    Note: The new implementation of _delay_ms(double __ms) with 
127     __builtin_avr_delay_cycles(unsigned long) support is not backward compa    tible. 
128    User can define __DELAY_BACKWARD_COMPATIBLE__ to get a backward compatib    le delay
129    although this will be deprecated in future.
130 
131  */
132 void
133 _delay_ms(double __ms)
134 {
135         uint16_t __ticks;
136         double __tmp ;
137 #if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__) && !defined(__DELAY_BACKWAR    D_COMPATIBLE__)
138         uint32_t __ticks_dc;
139         extern void __builtin_avr_delay_cycles(unsigned long);
140         __tmp = ((F_CPU) / 1e3) * __ms;
141 
142         #if defined(__DELAY_ROUND_DOWN__)
143                 __ticks_dc = (uint32_t)fabs(__tmp);
144 
145         #elif defined(__DELAY_ROUND_CLOSEST__)
146                 __ticks_dc = (uint32_t)(fabs(__tmp)+0.5);
147 
148         #else
149                 //round up by default
150                 __ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
151         #endif
152 
153         __builtin_avr_delay_cycles(__ticks_dc);

This line...

140         __tmp = ((F_CPU) / 1e3) * __ms;

... is not going to play nicely with this line ...

/usr/bin/avr-g++ -MM -mmcu=atmega328p -DF_CPU= -I. -I/usr/share/arduino//hardware/arduino/cores/arduino  -g -Os -w -Wall -ffunction-sections -fdata-sections -fno-exceptions build-cli/Blink.cpp -MF build-cli/Blink.d -MT build-cli/Blink.o
cat build-cli/Blink.d > build-cli/depends.mk

You're sending in "-DF_CPU=", that is defining F_CPU as nothing. Not surprising that a line with F_CPU won't compile. Try sending in a value for F_CPU, like "-DF_CPU=16000000".

maniacbug:
You're sending in "-DF_CPU=", that is defining F_CPU as nothing. Not surprising that a line with F_CPU won't compile. Try sending in a value for F_CPU, like "-DF_CPU=16000000".

Defined as nothing, but nevertheless defined, as delay.h contains:

#ifndef F_CPU
/* prevent compiler error by supplying a default */
# warning "F_CPU not defined for <util/delay.h>"
# define F_CPU 1000000UL
#endif

...which should have caught that one otherwise, right?

#ifndef F_CPU

This statement tests whether F_CPU has been defined, not what its value is. If the name has not been defined, it will be defined and associated with a valid value.

The conclusion that maniacbug draws is not necessarily valid, but, the problem that he found is real, and needs to be addressed by OP.

Upon further thought, having no value for F_CPU will cause that code he showed to look like

__tmp = (() / 1e3) * __ms;

which is something that the compiler will not like. So, maniacbug's conclusion IS correct.

I added
F_CPU = 16000000UL
to my makefile and it compiled without any errors. I'll test it on my arduino when I get home but right now it seems to be fixed.
Thanks!