# You should have received a copy of the GNU General Public License
# along with simavr. If not, see <http://www.gnu.org/licenses/>.
+CFLAGS += -g --std=gnu99 -O2
+CFLAGS += ${patsubst %,-I%,${subst :, ,${IPATH}}}
+LDFLAGS += -lelf
+
+ifeq (${shell uname}, Darwin)
+AVR_ROOT := "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/"
+AVR_INC := ${AVR_ROOT}/avr-4/
+AVR := ${AVR_ROOT}/bin/avr-
+else
+AVR_ROOT := /usr/lib/avr
+AVR_INC := ${AVR_ROOT}
+AVR := avr-
+endif
+
%.hex: %.axf
@${AVR}objcopy -j .text -j .data -O ihex ${<} ${@}
# --mcall-prologues
%.axf: %.c
- @echo CC ${<}
+ @echo AVR-CC ${<}
@part=${<} ; part=$${part/_*}; \
${AVR}gcc -Wall -gdwarf-2 -Os -std=gnu99 \
-mmcu=$$part \
-ffunction-sections -fdata-sections \
-Wl,--relax,--gc-sections \
-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000 \
- -I../include \
+ -I../include -I../../include \
${<} -o ${@}
@${AVR}size ${@}|sed '1d'
+
+OBJ = obj
+
+${OBJ}/%.o: %.c
+ @gcc $(CFLAGS) -MD \
+ $< -c -o $@
+ @echo CC $<
+
+${OBJ}:
+ mkdir -p ${OBJ}
+
+# include the dependency files generated by gcc, if any
+-include ${wildcard ${OBJ}/*.d}