# Author: Bernardo Innocenti <bernie@develer.com>
#
# $Log$
-# Revision 1.1 2006/03/22 09:51:53 bernie
-# Add build infrastructure.
-#
#
#
# Programmer type
-#
+# see local pgm_config.mk for programmer customization.
+-include pgm_config.mk
+DPROG ?= -V -c stk500 -P /dev/ttyS0
+
# AVR ISP dongle that blows up easily
-DPROG = -V -c stk500 -P /dev/ttyS0
+#DPROG = -V -c stk500 -P /dev/ttyS0
+#DPROG = -V -c jtag2slow
+#-P /dev/ttyUSB0
# STK200 parallel cable
#DPROG = -c stk200 -E noreset
+# JTAG ICE mkII
+#DPROG = avarice --mkII -j usb -l
+
# PonyProg serial programmer
#DPROG = -c dasa2
-#OPTCFLAGS = -O3 # DANGER - DO NOT USE - DOESN'T WORK WITH 3.4.1 & 3.5 (HEAD)
-OPTCFLAGS = -ffunction-sections -fdata-sections
+# Set to 1 to build for embedded devices.
+# e.g. produce target.elf instead of target and target_nostrip
+EMBEDDED_TARGET = 1
+#EMBEDDED_TARGET = 0
+
+OPTCFLAGS = -ffunction-sections -fdata-sections
+#OPTCFLAGS = -funsafe-loop-optimizations
# For AVRStudio
#DEBUGCFLAGS = -gdwarf-2
# For GDB
-DEBUGCFLAGS = -g
+DEBUGCFLAGS = -ggdb
#
# define some variables based on the AVR base path in $(AVR)
#
-CROSS =
-CC = $(CROSS)gcc
-AS = $(CROSS)$(CC) -x assembler-with-cpp
-LD = $(CROSS)$(CC)
-OBJCOPY = $(CROSS)objcopy
+#CROSS = avr-
+CC = gcc
+CXX = g++
+AS = $(CC) -x assembler-with-cpp
+LD = $(CC)
+OBJCOPY = objcopy
+STRIP = strip
INSTALL = cp -a
RM = rm -f
RM_R = rm -rf
RN = mv
MKDIR_P = mkdir -p
+SHELL = /bin/sh
+CHECKER = sparse
+DOXYGEN = doxygen
+AVRDUDE = avrdude
+FLEXCAT = $(top_srcdir)/tools/flexcat/flexcat
# For conversion from ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) \
LIBDIR = lib
OBJDIR = obj
OUTDIR = images
-SHELL = /bin/sh
-DOXYGEN = doxygen
-UISP = uisp
-AVRDUDE = avrdude
# output format can be srec, ihex (avrobj is always created)
FORMAT = srec
#FORMAT = ihex
+# Compiler flags for generating dependencies
+DEP_FLAGS = -MMD -MP
+
+# Compiler flags for generating source listings
+LIST_FLAGS = -Wa,-anhlmsd=$(@:.o=.lst)
+
+# Linker flags for generating map files
+ifeq ($(EMBEDDED_TARGET), 1)
+MAP_FLAGS = -Wl,-Map=$(@:%.elf=%.map),--cref
+else
+MAP_FLAGS =
+endif
+
+# Compiler warning flags for both C and C++
WARNFLAGS = \
-W -Wformat -Wall -Wundef -Wpointer-arith -Wcast-qual \
- -Wcast-align -Wwrite-strings -Wsign-compare -Wstrict-prototypes \
- -Wmissing-prototypes -Wmissing-noreturn
+ -Wcast-align -Wwrite-strings -Wsign-compare \
+ -Wmissing-noreturn \
+ -Wextra -Wstrict-aliasing=2 \
+# -Wunsafe-loop-optimizations
-# default compiler flags
-CFLAGS = $(INCDIR) $(OPTCFLAGS) $(DEBUGCFLAGS) $(WARNFLAGS) \
- -MMD -MP -Wa,-anhlmsd=$(@:.o=.lst) -std=gnu99
+# Compiler warning flags for C only
+C_WARNFLAGS = \
+ -Wmissing-prototypes -Wstrict-prototypes
-# default compiler assembly flags
+# Default C preprocessor flags (for C, C++ and cpp+as)
+CPPFLAGS = $(INCDIR)
+
+# Default C compiler flags
+CFLAGS = $(OPTCFLAGS) $(DEBUGCFLAGS) $(WARNFLAGS) $(C_WARNFLAGS) \
+ $(DEP_FLAGS) $(LIST_FLAGS) -std=gnu99
+
+# Default C++ compiler flags
+CXXFLAGS = $(OPTCFLAGS) $(DEBUGCFLAGS) $(WARNFLAGS) \
+ $(DEP_FLAGS) $(LIST_FLAGS)
+
+# Default compiler assembly flags
CPPAFLAGS = $(DEBUGCFLAGS) -MMD
-# default assembler flags
+# Default assembler flags
ASFLAGS = $(DEBUGCFLAGS)
-# default linker flags
-#LDFLAGS = -Wl,-Map=$(@:%.elf=%.map),--cref -Wl,--reduce-memory-overheads
-LDFLAGS = -Wl,-Map=$(@:%.elf=%.map),--cref -Wl,--gc-sections
+# Default linker flags
+#LDFLAGS = $(MAP_FLAGS)
+
+#bernie: does not complain for missing symbols!
+LDFLAGS = $(MAP_FLAGS) -Wl,--gc-sections
-# flags for avrdude
+# Flags for avrdude
AVRDUDEFLAGS = $(DPROG)
# additional libs