From 2bdcdddd76e5c97c7bff8b51284186164d6bdc44 Mon Sep 17 00:00:00 2001
From: Francisco Acosta <fco.ja.ac@gmail.com>
Date: Tue, 15 May 2018 00:21:09 +0200
Subject: [PATCH] cpu/atmega*: make use of common atmega.inc.mk and remove
 redundancies

Everything is now defined in atmega.inc.mk, following the common
RIOT-like reusability of rules and variables (e.g. cortexm.inc.mk).
---
 cpu/atmega256rfr2/periph/Makefile  |  2 +-
 cpu/atmega328p/Makefile.include    |  2 +-
 cpu/atmega_common/Makefile.include | 39 ++----------------------------
 3 files changed, 4 insertions(+), 39 deletions(-)

diff --git a/cpu/atmega256rfr2/periph/Makefile b/cpu/atmega256rfr2/periph/Makefile
index 48422e909a..a36df249ac 100644
--- a/cpu/atmega256rfr2/periph/Makefile
+++ b/cpu/atmega256rfr2/periph/Makefile
@@ -1 +1 @@
-include $(RIOTBASE)/Makefile.base
+include $(RIOTMAKE)/periph.mk
diff --git a/cpu/atmega328p/Makefile.include b/cpu/atmega328p/Makefile.include
index 058b45a115..20119203dd 100644
--- a/cpu/atmega328p/Makefile.include
+++ b/cpu/atmega328p/Makefile.include
@@ -5,4 +5,4 @@ RAM_LEN = 2K
 ROM_LEN = 32K
 
 # CPU depends on the atmega common module, so include it
-include $(RIOTCPU)/atmega_common/Makefile.include
\ No newline at end of file
+include $(RIOTCPU)/atmega_common/Makefile.include
diff --git a/cpu/atmega_common/Makefile.include b/cpu/atmega_common/Makefile.include
index 4d3ed2832d..5c02288d19 100644
--- a/cpu/atmega_common/Makefile.include
+++ b/cpu/atmega_common/Makefile.include
@@ -1,44 +1,9 @@
-# Target architecture for the build. Use avr if you are unsure.
-export TARGET_ARCH ?= avr
-
-export CFLAGS_CPU = -mmcu=$(CPU) $(CFLAGS_FPU)
-export CFLAGS_LINK  = -ffunction-sections -fdata-sections -fno-builtin -fshort-enums
-export CFLAGS_DBG  ?= -ggdb -g3
-export CFLAGS_OPT  ?= -Os
-
-export CFLAGS += $(CFLAGS_CPU) $(CFLAGS_LINK) $(CFLAGS_DBG) $(CFLAGS_OPT)
-export ASFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG)
-LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) -static -lgcc -e reset_handler -Wl,--gc-sections
-
-# export the peripheral drivers to be linked into the final binary
-export USEMODULE += atmega_common_periph
-export USEMODULE += periph_common
-
-# the atmel port uses stdio_uart
-export USEMODULE += stdio_uart
-
 # include module specific includes
 export INCLUDES += -I$(RIOTCPU)/atmega_common/include \
                    -isystem$(RIOTCPU)/atmega_common/avr_libc_extra/include \
                    -isystem$(RIOTCPU)/atmega_common/avr_libc_extra/include/vendor
 
-ifeq ($(LTO),1)
-  # avr-gcc <4.8.3 has a bug when using LTO which causes a warning to be printed always:
-  # '_vector_25' appears to be a misspelled signal handler [enabled by default]
-  # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59396
-  LINKFLAGS += -Wno-error
-endif
-
-# Use ROM_LEN and RAM_LEN during link
-$(if $(ROM_LEN),,$(error ROM_LEN is not defined))
-$(if $(RAM_LEN),,$(error RAM_LEN is not defined))
-LINKFLAGS += $(LINKFLAGPREFIX)--defsym=__TEXT_REGION_LENGTH__=$(ROM_LEN)$(if $(ROM_RESERVED),-$(ROM_RESERVED))
-LINKFLAGS += $(LINKFLAGPREFIX)--defsym=__DATA_REGION_LENGTH__=$(RAM_LEN)
-
-# Use newer linker script to have ROM/RAM configuration symbols in binutils<2.26
-LDSCRIPT_COMPAT = $(if $(shell $(TARGET_ARCH)-ld --verbose | grep __TEXT_REGION_LENGTH__),,\
-                    -T$(RIOTCPU)/$(CPU)/ldscripts_compat/avr_2.26.ld)
-LINKFLAGS += $(LDSCRIPT_COMPAT)
-
 # avr libc needs some RIOT-specific support code
 USEMODULE += avr_libc_extra
+
+include $(RIOTMAKE)/arch/atmega.inc.mk
-- 
GitLab