diff --git a/avr-libc/configure.ac b/avr-libc/configure.ac
index 50ee032..23347e8 100644
--- a/avr-libc/configure.ac
+++ b/avr-libc/configure.ac
@@ -170,6 +170,25 @@ AC_PROG_INSTALL
 AC_PROG_LN_S
 AC_PROG_MAKE_SET
 
+dnl Check if avr-gcc >= 5.0.0 as they expect device library
+GCC_VER=`${CC} -dumpversion`
+AS_VERSION_COMPARE(${GCC_VER},"5.0.0",[DEV_LIB="no"],[DEV_LIB="yes"],[DEV_LIB="yes"])
+AM_CONDITIONAL(HAS_GCC_5_1, test "x${GCC_VER}" = "x5.1.0")
+
+dnl Enable device library when specified. If not specified and
+dnl gcc expects (e.g. >= 5) device lib then enable device library.
+AC_ARG_ENABLE(device-lib,
+[  --enable-device-lib     build separate device library],
+[enable_device_lib=true],
+[case "${DEV_LIB}" in
+  yes) enable_device_lib=true
+       AC_MSG_NOTICE(Enabled device library) ;;
+  *) ;;
+ esac])
+
+dnl define HAS_DEV_LIB if device library enabled
+AM_CONDITIONAL(HAS_DEV_LIB, [test x$enable_device_lib = xtrue])
+
 dnl TODO: Check for various tools used to build the documentation. If anything
 dnl is missing, don't build the docs by default.
 
diff --git a/avr-libc/devtools/Device.am b/avr-libc/devtools/Device.am
index 70fb1a7..136e3e8 100644
--- a/avr-libc/devtools/Device.am
+++ b/avr-libc/devtools/Device.am
@@ -29,15 +29,27 @@
 #
 
 AVR_TARGET          = <<dev>>
+if HAS_DEV_LIB
+if HAS_GCC_5_1
+AVR_TARGET_CRT      = crt1.o
+AVR_INSTALL_DIR     = dev/<<dev>>
+else
+AVR_TARGET_CRT      = crt<<dev>>.o
+AVR_INSTALL_DIR     = <<install_dir>>
+endif
+else
 AVR_TARGET_CRT      = <<crt>>
+AVR_INSTALL_DIR     = <<install_dir>>
+endif
 AVR_TARGET_DEFS     = <<crt_defs>>
 AVR_TARGET_CFLAGS   = <<crt_cflags>>
 AVR_TARGET_ASFLAGS  = <<crt_asflags>>
-AVR_INSTALL_DIR     = <<install_dir>>
 
 VPATH = $(top_srcdir)/crt1:$(top_srcdir)/libc/misc
 
+if HAS_DEV_LIB
 include $(top_srcdir)/libc/misc/Rules.am
+endif
 
 if HAS_<<dev>>
 
@@ -58,8 +70,16 @@ avrlibdir = $(__install_dir)
 
 noinst_LIBRARIES = libcrt.a
 nodist_libcrt_a_SOURCES = gcrt1.S
+
+if HAS_DEV_LIB
+if HAS_GCC_5_1
+avr_LIBRARIES = libdev.a
+libdev_a_SOURCES = $(eeprom_asm_sources)
+else
 avr_LIBRARIES = lib<<dev>>.a
 lib<<dev>>_a_SOURCES = $(eeprom_asm_sources)
+endif
+endif
 
 avr_DATA = $(AVR_TARGET_CRT)
 
diff --git a/avr-libc/devtools/gen-avr-lib-tree.sh b/avr-libc/devtools/gen-avr-lib-tree.sh
index fc6349d..2c68fd7 100755
--- a/avr-libc/devtools/gen-avr-lib-tree.sh
+++ b/avr-libc/devtools/gen-avr-lib-tree.sh
@@ -431,7 +431,7 @@ do
 	for dev_crt in $DEV_INFO
 	do
 		dev=`echo $dev_crt | cut -d ':' -f 1`
-		crt=crt`echo $dev_crt | cut -d ':' -f 1`.o
+		crt=`echo $dev_crt | cut -d ':' -f 2`
 		crt_defs=`echo $dev_crt | cut -d ':' -f 3`
 		crt_cflags=`echo $dev_crt | cut -d ':' -f 4`
 		crt_asflags=`echo $dev_crt | cut -d ':' -f 5`
diff --git a/avr-libc/libc/Makefile.am b/avr-libc/libc/Makefile.am
index 30fc125..4a60870 100644
--- a/avr-libc/libc/Makefile.am
+++ b/avr-libc/libc/Makefile.am
@@ -29,5 +29,11 @@
 # $Id$
 #
 
-SUBDIRS = stdlib pmstring string misc stdio time
-DIST_SUBDIRS = stdlib pmstring string misc stdio time
+# do not include misc (eeprom) in libc if device library enabled
+if HAS_DEV_LIB
+MISC=
+else
+MISC=misc
+endif
+SUBDIRS = stdlib pmstring string ${MISC} stdio time
+DIST_SUBDIRS = stdlib pmstring string ${MISC} stdio time
diff --git a/avr-libc/libc/misc/Rules.am b/avr-libc/libc/misc/Rules.am
index b2bb7a7..5912a30 100644
--- a/avr-libc/libc/misc/Rules.am
+++ b/avr-libc/libc/misc/Rules.am
@@ -31,4 +31,44 @@
 
 include $(top_srcdir)/libc/misc/Files.am
 
+if !HAS_DEV_LIB
+# Example:
+#   eeprom_asm_sources --> eerd_byte.S eerd_word.S
+#   basename           --> eerd_byte eerd_word
+#   addsuffix          --> eerd_byte_ eerd_word_
+#   foreach            --> eerd_byte_atmega48 eerd_byte_atmega8
+#                          eerd_word_atmega48 eerd_word_atmega8
+#   addsuffix          --> eerd_byte_atmega48.o eerd_byte_atmega8.o
+#                          eerd_word_atmega48.o eerd_word_atmega8.o
+#
+eeprom_asm_basenames = $(basename $(eeprom_asm_sources))
+eeprom_asm_basenames2 = $(addsuffix _,$(eeprom_asm_basenames))
+eeprom_asm_baselist = $(foreach dev,$(AVRLIB_DEVLIST),\
+    $(addsuffix $(dev),$(eeprom_asm_basenames2)))
+eeprom_asm_objlist = $(addsuffix .o,$(eeprom_asm_baselist))
+
+misc_a_libadd = \
+	$(eeprom_asm_objlist)
+
+# Example of '-mmcu' arg generation:
+#   $@          --> eerd_byte_atmega48.o
+#   basename    --> eerd_byte_atmega48
+#   subst       --> eerd byte atmega48
+#   lastword    --> atmega48
+#
+# Example of source file generation:
+#   $@          --> eerd_byte_atmega48.o
+#   basename    --> eerd_byte_atmega48
+#   subst       --> eerd.byte.atmega48
+#   basename    --> eerd.byte
+#   subst       --> eerd_byte
+#   addsuffix   --> eerd_byte.S
+#
+$(eeprom_asm_objlist):	$(eeprom_asm_sources)
+	$(filter-out -mmcu=%,$(COMPILE) $(AVRLIB_ASFLAGS)) -c -o $@	\
+	    -mmcu=$(lastword $(subst _, ,$(basename $@)))		\
+	    $(<D)/$(addsuffix .S,\
+	    	    $(subst .,_,$(basename $(subst _,.,$(basename $@)))))
+endif
+
 # vim: set ft=make:
