Go Down

Topic: Build Process Driving Me Insane.... (Read 10662 times) previous topic - next topic

nickgammon

If you look in the temporary build directory, it copies over (most) of the required files, all except, I think, the C++ libraries.

I think you can make a simple makefile without too many problems.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

RayLivingston

If you look in the temporary build directory, it copies over (most) of the required files, all except, I think, the C++ libraries.

I think you can make a simple makefile without too many problems.
Well, except that the specific problem I'm having is that is isn't correctly copying all the necessary files!  :-)

If I wanted to take a crack at building with make, do you know what I'd need to find/install, in addition to make, and where to get it?  The Arduino install doesn't seem to include make.  Is Cygwin the way to go?

I've found a sample make file:  http://volker.top.geek.nz/arduino/Makefile-Arduino-v1.8

It looks fairly manageable.....

Regards,
Ray L.

nickgammon

Quote
Well, except that the specific problem I'm having is that is isn't correctly copying all the necessary files!  :-)
Well, you wouldn't use the temporary directory, would you? Just build in situ like people normally do.

If you capture a build session by turning on verbose compiling it shouldn't be too hard to replicate.

Cygwin would be a way of getting make, if you are on Windows.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

RayLivingston

No, I would build in-place.

I'm off to a bad start - I can't even get the compiler to run.  When I open a cmd shell, and run avr-g++.exe, it complains that it cant find cygwin1.dll.  Obviously I'm missing some part or other environment setup.  any idea where I can find documentation on the environment used for doing builds?

Regards,
Ray L.

nickgammon

You need to open a Bash shell, not a command shell. The Bash shell will have the appropriate paths set up.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

RayLivingston

There does not appear to be a bash shell in the  (limited) cygwin install done by the IDE.  So, I installed full Cygwin.  Oddly, I can't run ANY of the Arduino tools from it either.  No error message - they just do nothing....

Starting to feel really stupid here....

Regards,
Ray L.

nickgammon

Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

RayLivingston

I installed gnu make with Cygwin, and it works fine.

Regards,
Ray L.

nickgammon

#38
Mar 18, 2015, 05:15 am Last Edit: Mar 18, 2015, 05:21 am by Nick Gammon Reason: Removed multiple occurrences of Blink.cpp, fixed bug about MCU
I've made up a simple Makefile based on the compiler output of compiling Blink.

Code: [Select]
#
# Simple Arduino Makefile
#
# Author: Nick Gammon
# Date: 18th March 2015

# where you installed the Arduino app
ARDUINO_DIR = C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/

# various programs
CC = "$(ARDUINO_DIR)hardware/tools/avr/bin/avr-gcc"
CPP = "$(ARDUINO_DIR)hardware/tools/avr/bin/avr-g++"
AR = "$(ARDUINO_DIR)hardware/tools/avr/bin/avr-ar"
OBJ_COPY = "$(ARDUINO_DIR)hardware/tools/avr/bin/avr-objcopy"

MAIN_SKETCH = Blink.cpp

# compile flags for g++ and gcc

# may need to change these
F_CPU = 16000000
MCU = atmega328p

# compile flags
GENERAL_FLAGS = -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=$(MCU) -DF_CPU=$(F_CPU)L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106
CPP_FLAGS = $(GENERAL_FLAGS) -fno-exceptions
CC_FLAGS  = $(GENERAL_FLAGS)

# location of include files
INCLUDE_FILES = "-I$(ARDUINO_DIR)hardware/arduino/cores/arduino" "-I$(ARDUINO_DIR)hardware/arduino/variants/standard"

# library sources
LIBRARY_DIR = "$(ARDUINO_DIR)hardware/arduino/cores/arduino/"

build:

$(CPP) $(CPP_FLAGS) $(INCLUDE_FILES) $(MAIN_SKETCH) -o $(MAIN_SKETCH).o
$(CC) $(CC_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)avr-libc/malloc.c -o malloc.c.o
$(CC) $(CC_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)avr-libc/realloc.c -o realloc.c.o
$(CC) $(CC_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)WInterrupts.c -o WInterrupts.c.o
$(CC) $(CC_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)wiring.c -o wiring.c.o
$(CC) $(CC_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)wiring_analog.c -o wiring_analog.c.o
$(CC) $(CC_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)wiring_digital.c -o wiring_digital.c.o
$(CC) $(CC_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)wiring_pulse.c -o wiring_pulse.c.o
$(CC) $(CC_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)wiring_shift.c -o wiring_shift.c.o
$(CPP) $(CPP_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)CDC.cpp -o CDC.cpp.o
$(CPP) $(CPP_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)HardwareSerial.cpp -o HardwareSerial.cpp.o
$(CPP) $(CPP_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)HID.cpp -o HID.cpp.o
$(CPP) $(CPP_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)IPAddress.cpp -o IPAddress.cpp.o
$(CPP) $(CPP_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)main.cpp -o main.cpp.o
$(CPP) $(CPP_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)new.cpp -o new.cpp.o
$(CPP) $(CPP_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)Print.cpp -o Print.cpp.o
$(CPP) $(CPP_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)Stream.cpp -o Stream.cpp.o
$(CPP) $(CPP_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)Tone.cpp -o Tone.cpp.o
$(CPP) $(CPP_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)USBCore.cpp -o USBCore.cpp.o
$(CPP) $(CPP_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)WMath.cpp -o WMath.cpp.o
$(CPP) $(CPP_FLAGS) $(INCLUDE_FILES) $(LIBRARY_DIR)WString.cpp -o WString.cpp.o
rm core.a
$(AR) rcs core.a malloc.c.o
$(AR) rcs core.a realloc.c.o
$(AR) rcs core.a WInterrupts.c.o
$(AR) rcs core.a wiring.c.o
$(AR) rcs core.a wiring_analog.c.o
$(AR) rcs core.a wiring_digital.c.o
$(AR) rcs core.a wiring_pulse.c.o
$(AR) rcs core.a wiring_shift.c.o
$(AR) rcs core.a CDC.cpp.o
$(AR) rcs core.a HardwareSerial.cpp.o
$(AR) rcs core.a HID.cpp.o
$(AR) rcs core.a IPAddress.cpp.o
$(AR) rcs core.a main.cpp.o
$(AR) rcs core.a new.cpp.o
$(AR) rcs core.a Print.cpp.o
$(AR) rcs core.a Stream.cpp.o
$(AR) rcs core.a Tone.cpp.o
$(AR) rcs core.a USBCore.cpp.o
$(AR) rcs core.a WMath.cpp.o
$(AR) rcs core.a WString.cpp.o
$(CC) -Os -Wl,--gc-sections -mmcu=$(MCU) -o $(MAIN_SKETCH).elf $(MAIN_SKETCH).o core.a -lm
$(OBJ_COPY) -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $(MAIN_SKETCH).elf $(MAIN_SKETCH).eep
$(OBJ_COPY) -O ihex -R .eeprom $(MAIN_SKETCH).elf $(MAIN_SKETCH).hex


I don't know if it will be preserved, but every line after the build: line starts with a tab, not just multiple spaces. This tab must be preserved.

I did this with IDE 1.0.6 under Windows (running under Cygwin).

You'll probably need to change the line "ARDUINO_DIR" to reflect where your Arduino install is.

Now you need to rename Blink.ino to Blink.cpp and add an include for Arduino.h, like this:

Code: [Select]
#include <Arduino.h>

void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}


Now, changing to that directory (where you saved Blink.cpp) and typing "make" it should compile, like this:

Code: [Select]
$ make
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-g++" -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -fno-exceptions "-IC:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/arduino/cores/arduino" "-IC:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/arduino/variants/standard" Blink.cpp -o Blink.cpp.o

< lines omitted due to posting limit >

"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-g++" -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -fno-exceptions "-IC:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/arduino/cores/arduino" "-IC:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/arduino/variants/standard" "C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/arduino/cores/arduino/"WString.cpp -o WString.cpp.o
rm core.a
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a malloc.c.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a realloc.c.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a WInterrupts.c.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a wiring.c.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a wiring_analog.c.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a wiring_digital.c.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a wiring_pulse.c.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a wiring_shift.c.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a CDC.cpp.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a HardwareSerial.cpp.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a HID.cpp.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a IPAddress.cpp.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a main.cpp.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a new.cpp.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a Print.cpp.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a Stream.cpp.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a Tone.cpp.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a USBCore.cpp.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a WMath.cpp.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-ar" rcs core.a WString.cpp.o
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-gcc" -Os -Wl,--gc-sections -mmcu=atmega328p -o Blink.cpp.elf Blink.cpp.o core.a -lm
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 Blink.cpp.elf Blink.cpp.eep
"C:/Documents and Settings/Nick/Desktop/arduino-1.0.6/hardware/tools/avr/bin/avr-objcopy" -O ihex -R .eeprom Blink.cpp.elf Blink.cpp.hex


The resulting .hex file compared exactly to the one created by the IDE.

Now obviously there is work to be done if you want to add more files. But the above should be a nice basis for getting started.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

nickgammon

And you could make a lot of improvements about not compiling stuff that doesn't need recompiling, as Make is designed to do. However the above actually produces an object file.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

nickgammon

I amended it to replace Blink.cpp throughout with $(MAIN_SKETCH) to make it easier to change to another file.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

nickgammon

With your own Makefile you now have the option of passing down your own compiler flags, which will be respected by each module you compile, which is a big win if you want to control things like whether debugging is on or not.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

nickgammon

#42
Mar 18, 2015, 05:39 am Last Edit: Mar 18, 2015, 05:43 am by Nick Gammon
I should point out that compiling is really quite simple. In that build file I set up some variables (like where the compiler is) to save repeating it on every line.

Having done that:

  • Compile everything with avr-gcc or avr-g++ as required
  • Combine all the libraries into one file: core.a
  • Link the main sketch with the combined libraries (giving a .elf file) - the linker will omit unused modules
  • Produce a .eep file (whatever that is, presumably for the EEPROM)
  • Produce a .hex file - for uploading
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

RayLivingston

Nick,

I have several sample make files I'm sure I could hack up, if I could get the Arduino tools to work at all...

I'm amazed there doesn't seem to be hardly any information out there on the environment necessary to make the tools work.  Most of what little I've found is from 2008 or so, so very out of date.

Regards,
Ray L.

nickgammon

Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Go Up