Sorry I didn't reply to your individual message. A lot of the time when things say that I'm "online" it really just means that somewhere behind a stack of other windows is a web browser page with the arduino site displayed, and I'm working on one of the front windows, or off at dinner, or whatever....
In any case, yes, I think it would be a good idea to have a tutorial on how to extract the arduino core libraries and manipulate them so that they could be used more easily my C and C++ programs built outside of the Arduino framework itself. I wouldn't think that this would be particularly difficult - there are two paths: copy out from a local arduino installation, and copy over the net from the source repository. Unfortunately, I have this feeling that the tutorial part rapidly becomes different for the three possible operating system environments, so it gets a bit messy. And with the relatively frequent changes in the details of how the core is structured (Serial recently moved from mostly C to mostly C++, for instance), it sort of a moving target. (also, the "makefile" got de-supported.) Maybe things will settle down after 1.0?
The basic process goes like:
- Compile everything in hardware/cores/arduino/ with the switches set for your particular board and processor. For example:
bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -mmcu=atmega168 -DF_CPU=16000000L -DARDUINO=18 -I.../hardware/arduino/cores/arduino .../hardware/arduino/cores/arduino/pins_arduino.c -o/tmp/pins_arduino.c.o
Then merge these into a library using "ar"
/bin/avr-ar rcs /tmp/core.a /tmp/pins_arduino.c.o
/bin/avr-ar rcs /tmp/core.a /tmp/WInterrupts.c.o
/bin/avr-ar rcs /tmp/core.a /tmp/wiring.c.o
/bin/avr-ar rcs /tmp/core.a /tmp/wiring_analog.c.o
/bin/avr-ar rcs /tmp/core.a /tmp/wiring_digital.c.o
/bin/avr-ar rcs /tmp/core.a /tmp/wiring_pulse.c.o
/bin/avr-ar rcs /tmp/core.a /tmp/wiring_shift.c.o
/bin/avr-ar rcs /tmp/core.a /tmp/HardwareSerial.cpp.o
/bin/avr-ar rcs /tmp/core.a /tmp/main.cpp.o
/bin/avr-ar rcs /tmp/core.a /tmp/Print.cpp.o
/bin/avr-ar rcs /tmp/core.a /tmp/Tone.cpp.o
/bin/avr-ar rcs /tmp/core.a /tmp/WMath.cpp.o
Then all you need to do is link those libraries with your program, and call the bits of initialization needed from main. In the IDE case, the appropriate main() and such will have been added to your sketch, along with some forward reference function pre-declarations, and it all gets compiled and link agains the core.a library:
#compile modified sketch
/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega168 -DF_CPU=16000000L -DARDUINO=18 -I.../hardware/arduino/cores/arduino /tmp/primes.cpp -o/tmp/primes.cpp.o
# and do the big link
/bin/avr-gcc -Os -Wl,--gc-sections -mmcu=atmega168 -o /tmp/primes.cpp.elf /tmp/primes.cpp.o /tmp/core.a -L/tmp -lm
The tricky bits are getting/finding all the files you need into core.a, recognizing and correcting for the bits that are options (core.a here probably should have been called core-168-16.a or something) and keeping up with whatever changes.