Rewrite upper half of the Makefile.

We have now Makefile-AVR - AVR specific stuff - and
Makefile-common - common build instructions.

This effort is the begin of preparing Teacup for ARM targets.
To build the target, copy or link Makefile-AVR or Makefile-ARM
(depending on your target) to Makefile.
This commit is contained in:
Markus Hitter 2013-01-02 18:11:34 +01:00
parent b10b3db4f8
commit 19066069a5
3 changed files with 172 additions and 134 deletions

1
.gitignore vendored
View File

@ -18,5 +18,6 @@ temporal.png
temporal_data
config.h
ThermistorTable.h
Makefile
sim
doc

View File

@ -1,11 +1,12 @@
##############################################################################
# #
# Teacup - alternative firmware for repraps #
# Teacup - Lean and efficient firmware for RepRap printers #
# #
# by Triffid Hunter, Traumflug, jakepoz, Markus Hitter, many others #
# #
# #
# This firmware is Copyright (C) 2009-2010 Michael Moon aka Triffid_Hunter #
# This firmware is Copyright (c) ... #
# 2009 - 2010 Michael Moon aka Triffid_Hunter #
# 2010 - 2013 Markus "Traumflug" Hitter <mah@jump-ing.de> #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
@ -23,6 +24,16 @@
# #
##############################################################################
##############################################################################
# #
# Makefile for AVR (ATmega-based) targets. Use it with #
# #
# make -f Makefile-AVR #
# #
# or copy/link it to Makefile for convenience. #
# #
##############################################################################
##############################################################################
# #
# Change these to suit your hardware #
@ -40,7 +51,17 @@ MCU_TARGET = atmega644p
# CPU clock rate
F_CPU = 16000000L
# F_CPU = 8000000L
DEFS = -DF_CPU=$(F_CPU)
##############################################################################
# #
# Where to find your compiler and linker. Later, this is completed like #
# CC = $(TOOLCHAIN)gcc #
# #
##############################################################################
TOOLCHAIN = avr-
# TOOLCHAIN = /usr/bin/avr-
# TOOLCHAIN = <path-to-arduino-folder>/hardware/tools/avr/bin/avr-
##############################################################################
# #
@ -48,156 +69,76 @@ DEFS = -DF_CPU=$(F_CPU)
# #
##############################################################################
AVRDUDE = avrdude
AVRDUDECONF = /etc/avrdude.conf
# avrdude, typical for AVR-based architectures.
#
# Flags:
# -c <programmer-type> Typically stk500 or stk500v2.
# -b <baudrate> Upload baud rate. Depends on the bootloader in
# use. Not used for USB programmers.
# -p <mcu type> See MCU_TARGET above.
# -P <port> Serial port the electronics is connected to.
# -C <config file> Optional, default is /etc/avrdude.conf.
UPLOADER = avrdude
# UPLOADER = <path-to-arduino-folder>/hardware/tools/avrdude
UPLOADER_FLAGS = -c stk500v2
# UPLOADER_FLAGS += -b 19200
# UPLOADER_FLAGS += -b 57600
UPLOADER_FLAGS += -b 115200
UPLOADER_FLAGS += -p $(MCU_TARGET)
# UPLOADER_FLAGS += -P COM1
# UPLOADER_FLAGS += -P /dev/ttyACM0
UPLOADER_FLAGS += -P /dev/ttyUSB0
# UPLOADER_FLAGS += -C <path-to-arduino-folder>/hardware/tools/avrdude.conf
##############################################################################
# #
# udev rule for /dev/arduino (insert into /etc/udev/rules.d/99-local.rules) #
# SUBSYSTEMS=="usb", ATTRS{idProduct}=="6001", ATTRS{idVendor}=="0403", #
# NAME="%k", SYMLINK+="arduino", SYMLINK+="arduino_$attr{serial}", #
# MODE="0660" #
# Below here, defaults should be ok. #
# #
##############################################################################
PROGPORT = /dev/arduino
# PROGPORT = /dev/ttyUSB0
PROGRAM = teacup
##############################################################################
# #
# This depends on the bootloader (or programmer) in use. #
# Examples: #
# #
# Arduino Diecimilia with genuine bootloader: 19200 #
# Sanguino bootloader: 57600 #
# Gen7 bootloader: 115200 #
# #
# Set PROGBAUD to 0 (Zero) for programmers. #
# #
##############################################################################
# Arduino IDE takes the "compile everything available"-approach, so we have
# to keep this working and can take a shortcut:
SOURCES = $(wildcard *.c)
PROGBAUD = 115200
##############################################################################
# #
# Firmware upload device type. Typically stk500 or stk500v2. #
# #
##############################################################################
PROGID = stk500v2
##############################################################################
# #
# These defaults should be ok, change if you need to #
# #
##############################################################################
PROGRAM = mendel
SOURCES = $(PROGRAM).c gcode_parse.c gcode_process.c dda.c dda_maths.c
SOURCES += dda_queue.c timer.c temp.c sermsg.c watchdog.c debug.c sersendf.c
SOURCES += heater.c analog.c intercom.c pinio.c clock.c home.c crc.c delay.c
SOURCES += serial.c usb_serial.c
ARCH = avr-
CC = $(ARCH)gcc
OBJDUMP = $(ARCH)objdump
OBJCOPY = $(ARCH)objcopy
OPTIMIZE = -Os -ffunction-sections -finline-functions-called-once -mcall-prologues
# OPTIMIZE = -O0
CFLAGS = -g -Wall -Wstrict-prototypes $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS) -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -save-temps -Winline
CFLAGS = -DF_CPU=$(F_CPU)
CFLAGS += -mmcu=$(MCU_TARGET)
CFLAGS += -g
CFLAGS += -Wall
CFLAGS += -Wstrict-prototypes
CFLAGS += -std=gnu99
CFLAGS += -funsigned-char
CFLAGS += -funsigned-bitfields
CFLAGS += -fpack-struct
CFLAGS += -fshort-enums
CFLAGS += -Winline
CFLAGS += -fno-move-loop-invariants
CFLAGS += -fno-tree-scev-cprop
LDFLAGS = -Wl,--as-needed -Wl,--gc-sections
CFLAGS += -Os
CFLAGS += -ffunction-sections
CFLAGS += -finline-functions-called-once
CFLAGS += -mcall-prologues
LDFLAGS = -Wl,--as-needed
LDFLAGS += -Wl,--gc-sections
LIBS = -lm
LIBDEPS =
SUBDIRS =
ifeq ($(PROGBAUD),0)
PROGBAUD_FLAG =
else
PROGBAUD_FLAG = -b$(PROGBAUD)
endif
-include Makefile-common
OBJ = $(patsubst %.c,%.o,${SOURCES})
# Architecture specific targets
.PHONY: all program clean size subdirs doc functionsbysize depend
.PRECIOUS: %.o %.elf
all: config.h subdirs $(PROGRAM).hex $(PROGRAM).lst $(PROGRAM).sym size
$(PROGRAM).elf: $(LIBDEPS)
subdirs:
@for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir; \
done
.PHONY: program size
program: $(PROGRAM).hex config.h
stty $(PROGBAUD) raw ignbrk hup < $(PROGPORT)
@sleep 0.1
@stty $(PROGBAUD) raw ignbrk hup < $(PROGPORT)
$(AVRDUDE) -c$(PROGID) $(PROGBAUD_FLAG) -p$(MCU_TARGET) -P$(PROGPORT) -C$(AVRDUDECONF) -U flash:w:$^
stty 115200 raw ignbrk -hup -echo ixoff < $(PROGPORT)
clean: clean-subdirs
rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex *.al *.i *.s *~ .depend
clean-subdirs:
@for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir clean; \
done
$(UPLOADER) $(UPLOADER_FLAGS) -U flash:w:$^
size: $(PROGRAM).elf
@echo " SIZES ATmega... '168 '328(P) '644(P) '1280"
@$(OBJDUMP) -h $^ | perl -MPOSIX -ne '/.(text)\s+([0-9a-f]+)/ && do { $$a += eval "0x$$2" }; END { printf " FLASH : %5d bytes %3d%% %3d%% %3d%% %3d%%\n", $$a, ceil($$a * 100 / (14 * 1024)), ceil($$a * 100 / (30 * 1024)),ceil($$a * 100 / (62 * 1024)), ceil($$a * 100 / (126 * 1024)) }'
@$(OBJDUMP) -h $^ | perl -MPOSIX -ne '/.(data|bss)\s+([0-9a-f]+)/ && do { $$a += eval "0x$$2" }; END { printf " RAM : %5d bytes %3d%% %3d%% %3d%% %3d%%\n", $$a, ceil($$a * 100 / (1 * 1024)), ceil($$a * 100 / (2 * 1024)),ceil($$a * 100 / (4 * 1024)), ceil($$a * 100 / (8 * 1024)) }'
@$(OBJDUMP) -h $^ | perl -MPOSIX -ne '/.(eeprom)\s+([0-9a-f]+)/ && do { $$a += eval "0x$$2" }; END { printf " EEPROM: %5d bytes %3d%% %3d%% %3d%% %3d%%\n", $$a, ceil($$a * 100 / (1 * 1024)), ceil($$a * 100 / (2 * 1024)), ceil($$a * 100 / (2 * 1024)), ceil($$a * 100 / (4 * 1024)) }'
config.h: config.default.h
@echo "config.default.h is more recent than config.h. You likely want to"
@echo "review (edit) config.h to match new features in config.default.h."
@echo "To view the differences, run: diff -bBEu config.h config.default.h"
@echo "If you just want to get rid of this message, run: touch config.h"
@false
doc: Doxyfile *.c *.h
doxygen $<
functionsbysize: $(OBJ)
@avr-objdump -h $^ | grep '\.text\.' | perl -ne '/\.text\.(\S+)\s+([0-9a-f]+)/ && printf "%u\t%s\n", eval("0x$$2"), $$1;' | sort -n
depend: .depend
@true
.depend: $(SOURCES)
rm -f .depend
$(CC) $(CFLAGS) -MM $^ > .depend;
# pull in dependency info
-include .depend
%.o: %.c config.h Makefile
@echo " CC $@"
@$(CC) -c $(CFLAGS) -Wa,-adhlns=$(<:.c=.al) -o $@ $(subst .o,.c,$@)
%.elf: $(OBJ)
@echo " LINK $@"
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
%.lst: %.elf
@echo " OBJDUMP $@"
@$(OBJDUMP) -h -S $< > $@
%.hex: %.elf
@echo " OBJCOPY $@"
@$(OBJCOPY) -j .text -j .data -O ihex -R .eeprom -R .fuse -R .lock $< $@
%.bin: %.elf
@echo " OBJCOPY $@"
@$(OBJCOPY) -j .text -j .data -O binary $< $@
%.sym: %.elf
@echo " SYM $@"
@$(OBJDUMP) -t $< | perl -ne 'BEGIN { printf " ADDR NAME SIZE\n"; } /([0-9a-f]+)\s+(\w+)\s+O\s+\.(bss|data)\s+([0-9a-f]+)\s+(\w+)/ && printf "0x%04x %-20s +%d\n", eval("0x$$1") & 0xFFFF, $$5, eval("0x$$4")' | sort -k1 > $@

96
Makefile-common Normal file
View File

@ -0,0 +1,96 @@
##############################################################################
# #
# Teacup - Lean and efficient firmware for RepRap printers #
# #
# by Triffid Hunter, Traumflug, jakepoz, Markus Hitter, many others #
# #
# This firmware is Copyright (c) ... #
# 2009 - 2010 Michael Moon aka Triffid_Hunter #
# 2010 - 2013 Markus "Traumflug" Hitter <mah@jump-ing.de> #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #
# #
##############################################################################
##############################################################################
# #
# This file isn't sufficient on its own. Use the target-specific Makefile #
# instead, which -includes this file. #
# #
##############################################################################
CFLAGS += -save-temps
OBJ = $(patsubst %.c,%.o,$(SOURCES))
CC = $(TOOLCHAIN)gcc
OBJDUMP = $(TOOLCHAIN)objdump
OBJCOPY = $(TOOLCHAIN)objcopy
.PHONY: all clean doc functionsbysize depend
.PRECIOUS: %.o %.elf
all: config.h $(PROGRAM).hex $(PROGRAM).lst $(PROGRAM).sym size
clean:
rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex *.al *.i *.s *~ .depend
config.h: config.default.h
@echo "config.default.h is more recent than config.h. You likely want to"
@echo "review (edit) config.h to match new features in config.default.h."
@echo "To view the differences, run: diff -bBEu config.h config.default.h"
@echo "If you just want to get rid of this message, run: touch config.h"
@false
doc: Doxyfile *.c *.h
doxygen $<
functionsbysize: $(OBJ)
@$(OBJDUMP) -h $^ | grep '\.text\.' | perl -ne '/\.text\.(\S+)\s+([0-9a-f]+)/ && printf "%u\t%s\n", eval("0x$$2"), $$1;' | sort -n
depend: .depend
@true
.depend: $(SOURCES)
rm -f .depend
$(CC) $(CFLAGS) -MM $^ > .depend;
# pull in dependency info
-include .depend
%.o: %.c config.h Makefile
@echo " CC $@"
@$(CC) -c $(CFLAGS) -Wa,-adhlns=$(<:.c=.al) -o $@ $(subst .o,.c,$@)
%.elf: $(OBJ)
@echo " LINK $@"
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
%.lst: %.elf
@echo " OBJDUMP $@"
@$(OBJDUMP) -h -S $< > $@
%.hex: %.elf
@echo " OBJCOPY $@"
@$(OBJCOPY) -j .text -j .data -O ihex -R .eeprom -R .fuse -R .lock $< $@
%.bin: %.elf
@echo " OBJCOPY $@"
@$(OBJCOPY) -j .text -j .data -O binary $< $@
%.sym: %.elf
@echo " SYM $@"
@$(OBJDUMP) -t $< | perl -ne 'BEGIN { printf " ADDR NAME SIZE\n"; } /([0-9a-f]+)\s+(\w+)\s+O\s+\.(bss|data)\s+([0-9a-f]+)\s+(\w+)/ && printf "0x%04x %-20s +%d\n", eval("0x$$1") & 0xFFFF, $$5, eval("0x$$4")' | sort -k1 > $@