diff --git a/share/mk/bsd.sys.mk b/share/mk/bsd.sys.mk index 5f2007906f5..04e7b9de07b 100644 --- a/share/mk/bsd.sys.mk +++ b/share/mk/bsd.sys.mk @@ -109,6 +109,13 @@ CWARNFLAGS+= -Werror CWARNFLAGS+= -Wno-format .endif # NO_WFORMAT || NO_WFORMAT.${COMPILER_TYPE} +# How to handle FreeBSD custom printf format specifiers. +.if ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 30600 +FORMAT_EXTENSIONS= -D__printf__=__freebsd_kprintf__ +.else +FORMAT_EXTENSIONS= -fformat-extensions +.endif + .if defined(IGNORE_PRAGMA) CWARNFLAGS+= -Wno-unknown-pragmas .endif # IGNORE_PRAGMA diff --git a/sys/boot/efi/libefi/Makefile b/sys/boot/efi/libefi/Makefile index 3edeb22ea5a..55abffc3079 100644 --- a/sys/boot/efi/libefi/Makefile +++ b/sys/boot/efi/libefi/Makefile @@ -20,8 +20,7 @@ CFLAGS+= -I${.CURDIR}/../../common CFLAGS+= -DNO_PCI - -# Suppress warning from clang for FreeBSD %b and %D formats -CFLAGS+= -fformat-extensions +# Handle FreeBSD specific %b and %D printf format specifiers +CFLAGS+= ${FORMAT_EXTENSIONS} .include diff --git a/sys/boot/i386/libi386/Makefile b/sys/boot/i386/libi386/Makefile index 0f360e99ab8..3e61a1b9686 100644 --- a/sys/boot/i386/libi386/Makefile +++ b/sys/boot/i386/libi386/Makefile @@ -55,8 +55,8 @@ CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}/../common \ # the location of libstand CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/ -# Suppress warning from clang for FreeBSD %b and %D formats -CFLAGS+= -fformat-extensions +# Handle FreeBSD specific %b and %D printf format specifiers +CFLAGS+= ${FORMAT_EXTENSIONS} .if ${MACHINE_CPUARCH} == "amd64" CLEANFILES+= machine diff --git a/sys/boot/pc98/libpc98/Makefile b/sys/boot/pc98/libpc98/Makefile index e612205de46..6b11de9f699 100644 --- a/sys/boot/pc98/libpc98/Makefile +++ b/sys/boot/pc98/libpc98/Makefile @@ -44,7 +44,7 @@ CFLAGS+= -I${.CURDIR}/../../common \ # the location of libstand CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/ -# Suppress warning from clang for FreeBSD %b and %D formats -CFLAGS+= -fformat-extensions +# Handle FreeBSD specific %b and %D printf format specifiers +CFLAGS+= ${FORMAT_EXTENSIONS} .include diff --git a/sys/conf/kern.mk b/sys/conf/kern.mk index b964151437e..bfc447379a2 100644 --- a/sys/conf/kern.mk +++ b/sys/conf/kern.mk @@ -58,6 +58,8 @@ CWARNEXTRA?= -Wno-uninitialized # to be disabled. WARNING: format checking is disabled in this case. .if ${MK_FORMAT_EXTENSIONS} == "no" FORMAT_EXTENSIONS= -Wno-format +.elif ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 30600 +FORMAT_EXTENSIONS= -D__printf__=__freebsd_kprintf__ .else FORMAT_EXTENSIONS= -fformat-extensions .endif