Hi,
I found a few nits and things which could be more user friendly in the
arduino example BSDmakefile. The diff below does the following:
- Adds the utility/ directory as an include path for each library imported.
Needed to build, for example, the SD library.
- Add example settings for an arduino mega.
- Add example of how to use the SD library.
- Use -ffunction-sections -fdata-sections and link with
-Wl,--gc-sections, as the official arduino toolchain does[1].
This makes smaller hex files. I put the -f stuff in CTUNING, which
was previously defined but unused. Commented the unused def out for now.
- Implement __cxa_pure_virtual so the user does not have to[1][2].
- Deal with the creation and removal of the utility/ directory
automatically. The comment that explained this was actually wrong
anyway. It said to create a 'utilities' directory, but it meant
'utility'. Anyway, manage this automatically, why not.
[1]
http://stackoverflow.com/questions/920500/what-is-the-purpose-of-cxa-pure-virtual
[2] http://playground.arduino.cc/OpenBSD/CLI
OK?
Index: Makefile
===
RCS file: /cvs/ports/devel/arduino/Makefile,v
retrieving revision 1.7
diff -u -p -u -r1.7 Makefile
--- Makefile11 Mar 2013 10:50:00 - 1.7
+++ Makefile3 May 2013 11:19:27 -
@@ -6,6 +6,7 @@ V= 1.0.2
PKGNAME= arduino-${V}
DISTNAME= arduino-${V}-src
EPOCH= 0
+REVISION = 0
CATEGORIES=devel
HOMEPAGE= http://www.arduino.cc/
Index: files/BSDmakefile
===
RCS file: /cvs/ports/devel/arduino/files/BSDmakefile,v
retrieving revision 1.5
diff -u -p -u -r1.5 BSDmakefile
--- files/BSDmakefile 13 Oct 2012 12:13:37 - 1.5
+++ files/BSDmakefile 3 May 2013 11:19:27 -
@@ -41,12 +41,16 @@ UPLOAD_RATE = 115200
PORT = /dev/cuaU0
AVRDUDE_PROGRAMMER = arduino
+## for an arduino mega
+#UPLOAD_RATE = 57600
+#MCU = atmega1280
+#AVRDUDE_PROGRAMMER = arduino
+
## or this for an older arduino
#UPLOAD_RATE = 19200
#PORT = /dev/cuaU0
#AVRDUDE_PROGRAMMER = stk500
-
## or this, if you have a usbtiny ISP
#PORT = usb
#AVRDUDE_PROGRAMMER = usbtiny
@@ -54,12 +58,15 @@ AVRDUDE_PROGRAMMER = arduino
MCU = atmega328p
F_CPU = 1600
-#If your sketch uses any libraries, list them here, eg.
-#LIBRARIES=EEPROM LiquidCrystal Wire
-# Or if you want to use the Ethernet library, use:
+# If your sketch uses any libraries, list them here, eg.
+# LIBRARIES=EEPROM LiquidCrystal Wire
+#
+# If you want to use the Ethernet library, use:
# LIBRARIES=SPI Ethernet IPAddress Dhcp Dns EthernetClient EthernetServer \
# EthernetUdp utility/w5100 utility/socket new
-# and run 'mkdir utilities'
+#
+# To use the SD library:
+# LIBRARIES=SD File utility/SdFile utility/SdVolume utility/Sd2Card
LIBRARIES=
# Arduino variant, one of: eightanaloginputs, leonardo, mega,
@@ -94,7 +101,9 @@ CDEFS = -DF_CPU=$(F_CPU)
CXXDEFS = -DF_CPU=$(F_CPU)
# Place -I options here
-LIBINC=${LIBRARIES:S|^|-I$(ARDUINO)/libraries/|g}
-I$(ARDUINO)/variants/$(VARIANT)
+ROOTLIBINCS=${LIBRARIES:S|^|-I$(ARDUINO)/libraries/|g}
+UTILITYLIBINCS=${ROOTLIBINCS:S|$|/utility/|g}
+LIBINC=${ROOTLIBINCS} ${UTILITYLIBINCS} -I$(ARDUINO)/variants/$(VARIANT)
CINCS = -I$(ARDUINO)/cores/arduino $(LIBINC) -I$(ARDUINO)/variants/$(VARIANT)
CXXINCS = -I$(ARDUINO)/cores/arduino $(LIBINC) -I$(ARDUINO)/variants/$(VARIANT)
@@ -106,13 +115,15 @@ CXXINCS = -I$(ARDUINO)/cores/arduino $(L
CSTANDARD = -std=gnu99
CDEBUG = -g$(DEBUG)
CWARN = -Wall -Wstrict-prototypes
-CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
+CTUNING = -ffunction-sections -fdata-sections
+#CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
#CEXTRA = -Wa,-adhlns=$(:.c=.lst)
-CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA)
+CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) \
+$(CSTANDARD) $(CEXTRA) $(CTUNING)
CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT)
#ASFLAGS = -Wa,-adhlns=$(:.S=.lst),-gstabs
-LDFLAGS = -lm
+LDFLAGS = -lm -Wl,--gc-sections
# Programming support using avrdude. Settings and variables.
@@ -132,6 +143,8 @@ SIZE = $(AVR_TOOLS_PATH)/avr-size
NM = $(AVR_TOOLS_PATH)/avr-nm
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude
REMOVE = rm -f
+REMOVEDIR = rmdir
+MKDIR = mkdir -p
MV = mv -f
# Define all object files.
@@ -150,11 +163,16 @@ ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assemb
# Default target.
all: applet_files build sizeafter
-build: elf hex
+build: mkdirs elf hex
+
+mkdirs:
+ $(MKDIR) utility
# Here is the preprocessing.
# It creates a .cpp file based with the same name as the .ino file.
# On top of the new .cpp file comes the Arduino.h header.
+# Then comes a stdc++ workaround, see:
+#