libc: Update makefiles

Added includes and sources of libc to the makefiles.

Change-Id: I8e84db9634e0df7d51caa5c5858311672dd3a8d1
Signed-off-by: Ambroise Vincent <ambroise.vincent@arm.com>
diff --git a/Makefile b/Makefile
index 7456858..0179bbf 100644
--- a/Makefile
+++ b/Makefile
@@ -26,11 +26,11 @@
 CHECKCODE_ARGS		:=	--no-patch
 # Do not check the coding style on imported library files or documentation files
 INC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
-					include/lib/stdlib,		\
+					include/lib/libc,		\
 					$(wildcard include/lib/*)))
 LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
 					lib/compiler-rt			\
-					lib/stdlib,			\
+					lib/libc,			\
 					$(wildcard lib/*)))
 ROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
 					lib				\
@@ -117,12 +117,16 @@
 include spm/cactus/cactus.mk
 include spm/ivy/ivy.mk
 
+################################################################################
+# Include libc
+################################################################################
+include lib/libc/libc.mk
+
 # Include platform specific makefile last because:
 # - the platform makefile may use all previous definitions in this file.
 # - the platform makefile may wish overwriting some of them.
 include ${PLAT_MAKEFILE_FULL}
 
-
 .SUFFIXES:
 
 ################################################################################
@@ -175,7 +179,8 @@
 
 COMMON_ASFLAGS		+=	-nostdinc -ffreestanding -Wa,--fatal-warnings	\
 				-Werror -Wmissing-include-dirs			\
-				-D__ASSEMBLY__ $(COMMON_ASFLAGS_$(ARCH))
+				-D__ASSEMBLY__ $(COMMON_ASFLAGS_$(ARCH))	\
+				${INCLUDES}
 COMMON_CFLAGS		+=	-nostdinc -ffreestanding -Wall	-Werror 	\
 				-Wmissing-include-dirs $(COMMON_CFLAGS_$(ARCH))	\
 				-std=gnu99 -Os
@@ -183,7 +188,7 @@
 
 # Get the content of CFLAGS user defined value last so they are appended after
 # the options defined in the Makefile
-COMMON_CFLAGS 		+=	${CFLAGS}
+COMMON_CFLAGS 		+=	${CFLAGS} ${INCLUDES}
 
 COMMON_LDFLAGS		+=	--fatal-warnings -O1 --gc-sections --build-id=none
 
@@ -199,29 +204,31 @@
 
 ################################################################################
 
-TFTF_SOURCES		:= ${FRAMEWORK_SOURCES}	${TESTS_SOURCES} ${PLAT_SOURCES}
+TFTF_SOURCES		:= ${FRAMEWORK_SOURCES}	${TESTS_SOURCES} ${PLAT_SOURCES} ${LIBC_SRCS}
 TFTF_INCLUDES		+= ${PLAT_INCLUDES}
 TFTF_CFLAGS		+= ${COMMON_CFLAGS}
 TFTF_ASFLAGS		+= ${COMMON_ASFLAGS}
 TFTF_LDFLAGS		+= ${COMMON_LDFLAGS}
 
-NS_BL1U_SOURCES		+= ${PLAT_SOURCES}
+NS_BL1U_SOURCES		+= ${PLAT_SOURCES} ${LIBC_SRCS}
 NS_BL1U_INCLUDES	+= ${PLAT_INCLUDES}
 NS_BL1U_CFLAGS		+= ${COMMON_CFLAGS}
 NS_BL1U_ASFLAGS		+= ${COMMON_ASFLAGS}
 NS_BL1U_LDFLAGS		+= ${COMMON_LDFLAGS}
 
-NS_BL2U_SOURCES		+= ${PLAT_SOURCES}
+NS_BL2U_SOURCES		+= ${PLAT_SOURCES} ${LIBC_SRCS}
 NS_BL2U_INCLUDES	+= ${PLAT_INCLUDES}
 NS_BL2U_CFLAGS		+= ${COMMON_CFLAGS}
 NS_BL2U_ASFLAGS		+= ${COMMON_ASFLAGS}
 NS_BL2U_LDFLAGS		+= ${COMMON_LDFLAGS}
 
+CACTUS_SOURCES		+= ${LIBC_SRCS}
 CACTUS_INCLUDES		+= ${PLAT_INCLUDES}
 CACTUS_CFLAGS		+= ${COMMON_CFLAGS}
 CACTUS_ASFLAGS		+= ${COMMON_ASFLAGS}
 CACTUS_LDFLAGS		+= ${COMMON_LDFLAGS}
 
+IVY_SOURCES		+= ${LIBC_SRCS}
 IVY_INCLUDES		+= ${PLAT_INCLUDES}
 IVY_CFLAGS		+= ${COMMON_CFLAGS}
 IVY_ASFLAGS		+= ${COMMON_ASFLAGS}
@@ -254,14 +261,14 @@
 checkcodebase:		locate-checkpatch
 	@echo "  CHECKING STYLE"
 	@if test -d .git ; then						\
-		git ls-files | grep -E -v 'stdlib|docs|\.md|\.rst' |	\
+		git ls-files | grep -E -v 'libc|docs|\.md|\.rst' |	\
 		while read GIT_FILE ;					\
 		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
 		done ;							\
 	else								\
 		 find . -type f -not -iwholename "*.git*"		\
 		 -not -iwholename "*build*"				\
-		 -not -iwholename "*stdlib*"				\
+		 -not -iwholename "*libc*"				\
 		 -not -iwholename "*docs*"				\
 		 -not -iwholename "*.md"				\
 		 -not -iwholename "*.rst"				\
diff --git a/docs/design.rst b/docs/design.rst
index edb3c95..5a13d79 100644
--- a/docs/design.rst
+++ b/docs/design.rst
@@ -66,7 +66,7 @@
 
 -  **Library code.**
 
-   Firstly, there is ``include/stdlib/`` which provides standard C library
+   Firstly, there is ``include/libc/`` which provides standard C library
    functions like ``memcpy()``, ``printf()`` and so on.
    Additionally, various other APIs are provided under ``include/lib/``. The
    below list gives some examples but might not be exhaustive.
diff --git a/fwu/ns_bl1u/ns_bl1u.mk b/fwu/ns_bl1u/ns_bl1u.mk
index edc77be..7a6b65b 100644
--- a/fwu/ns_bl1u/ns_bl1u.mk
+++ b/fwu/ns_bl1u/ns_bl1u.mk
@@ -15,8 +15,6 @@
 	-Iinclude/common/${ARCH}			\
 	-Iinclude/lib					\
 	-Iinclude/lib/${ARCH}				\
-	-Iinclude/lib/stdlib				\
-	-Iinclude/lib/stdlib/sys			\
 	-Iinclude/lib/utils				\
 	-Iinclude/lib/xlat_tables			\
 	-Iinclude/plat/common				\
@@ -39,7 +37,6 @@
 			lib/locks/${ARCH}/spinlock.S			\
 			lib/smc/${ARCH}/asm_smc.S			\
 			lib/smc/${ARCH}/smc.c				\
-			${STD_LIB_SOURCES}				\
 			lib/utils/mp_printf.c				\
 			lib/utils/uuid.c				\
 			${XLAT_TABLES_LIB_SRCS}				\
diff --git a/fwu/ns_bl2u/ns_bl2u.mk b/fwu/ns_bl2u/ns_bl2u.mk
index 8c3924d..0351e55 100644
--- a/fwu/ns_bl2u/ns_bl2u.mk
+++ b/fwu/ns_bl2u/ns_bl2u.mk
@@ -15,8 +15,6 @@
 	-Iinclude/common/${ARCH}			\
 	-Iinclude/lib					\
 	-Iinclude/lib/${ARCH}				\
-	-Iinclude/lib/stdlib				\
-	-Iinclude/lib/stdlib/sys			\
 	-Iinclude/lib/utils				\
 	-Iinclude/lib/xlat_tables			\
 	-Iinclude/plat/common				\
@@ -37,7 +35,6 @@
 			lib/locks/${ARCH}/spinlock.S			\
 			lib/smc/${ARCH}/asm_smc.S			\
 			lib/smc/${ARCH}/smc.c				\
-			${STD_LIB_SOURCES}				\
 			lib/utils/mp_printf.c				\
 			lib/utils/uuid.c				\
 			${XLAT_TABLES_LIB_SRCS}				\
diff --git a/readme.rst b/readme.rst
index 1512545..8a788ac 100644
--- a/readme.rst
+++ b/readme.rst
@@ -41,8 +41,9 @@
 This project contains code from other projects as listed below. The original
 license text is included in those source files.
 
--  The libc source code is derived from `FreeBSD`_ code, which uses various BSD
-   licenses, including BSD-3-Clause and BSD-2-Clause.
+-  The libc source code is derived from `FreeBSD`_ and `SCC`_. FreeBSD uses
+   various BSD licenses, including BSD-3-Clause and BSD-2-Clause. The SCC code
+   is used under the BSD-3-Clause license with the author's permission.
 
 -  The `LLVM compiler-rt`_ source code is disjunctively dual licensed
    (NCSA OR MIT). It is used by this project under the terms of the NCSA
@@ -138,7 +139,7 @@
 
 --------------
 
-*Copyright (c) 2018, Arm Limited. All rights reserved.*
+*Copyright (c) 2018-2019, Arm Limited. All rights reserved.*
 
 .. _Contributing Guidelines: contributing.rst
 .. _license: license.rst
@@ -151,6 +152,7 @@
 .. _Juno Arm Development Platform: https://developer.arm.com/products/system-design/development-boards/juno-development-board
 
 .. _FreeBSD: http://www.freebsd.org
+.. _SCC: http://www.simple-cc.org/
 .. _LLVM compiler-rt: https://compiler-rt.llvm.org/
 
 .. _Power State Coordination Interface (PSCI): PSCI_
diff --git a/spm/cactus/cactus.mk b/spm/cactus/cactus.mk
index 056b4a7..d964ab1 100644
--- a/spm/cactus/cactus.mk
+++ b/spm/cactus/cactus.mk
@@ -14,8 +14,6 @@
 	-Iinclude/common/${ARCH}			\
 	-Iinclude/lib					\
 	-Iinclude/lib/${ARCH}				\
-	-Iinclude/lib/stdlib				\
-	-Iinclude/lib/stdlib/sys			\
 	-Iinclude/lib/sprt				\
 	-Iinclude/lib/utils				\
 	-Iinclude/lib/xlat_tables			\
@@ -38,16 +36,6 @@
 		sp_helpers.c				\
 	)						\
 
-STDLIB_SOURCES	:=	$(addprefix lib/stdlib/,	\
-	assert.c					\
-	mem.c						\
-	putchar.c					\
-	printf.c					\
-	rand.c						\
-	strlen.c					\
-	subr_prf.c					\
-)
-
 # TODO: Remove dependency on TFTF files.
 CACTUS_SOURCES	+=					\
 	tftf/framework/debug.c				\
@@ -58,7 +46,6 @@
 			lib/${ARCH}/misc_helpers.S			\
 			lib/locks/${ARCH}/spinlock.S			\
 			lib/utils/mp_printf.c				\
-			${STDLIB_SOURCES}				\
 			${SPRT_LIB_SOURCES}
 
 CACTUS_LINKERFILE	:=	spm/cactus/cactus.ld.S
diff --git a/spm/ivy/ivy.mk b/spm/ivy/ivy.mk
index 244d209..5a6ccf0 100644
--- a/spm/ivy/ivy.mk
+++ b/spm/ivy/ivy.mk
@@ -14,8 +14,6 @@
 	-Iinclude/common/${ARCH}			\
 	-Iinclude/lib					\
 	-Iinclude/lib/${ARCH}				\
-	-Iinclude/lib/stdlib				\
-	-Iinclude/lib/stdlib/sys			\
 	-Iinclude/lib/sprt				\
 	-Iinclude/lib/utils				\
 	-Iinclude/lib/xlat_tables			\
@@ -35,16 +33,6 @@
 		sp_helpers.c				\
 	)						\
 
-STDLIB_SOURCES	:=	$(addprefix lib/stdlib/,	\
-	assert.c					\
-	mem.c						\
-	putchar.c					\
-	printf.c					\
-	rand.c						\
-	strlen.c					\
-	subr_prf.c					\
-)
-
 # TODO: Remove dependency on TFTF files.
 IVY_SOURCES	+=					\
 	tftf/framework/debug.c				\
@@ -55,7 +43,6 @@
 			lib/${ARCH}/misc_helpers.S			\
 			lib/locks/${ARCH}/spinlock.S			\
 			lib/utils/mp_printf.c				\
-			${STDLIB_SOURCES}				\
 			${SPRT_LIB_SOURCES}
 
 IVY_LINKERFILE	:=	spm/ivy/ivy.ld.S
diff --git a/tftf/framework/framework.mk b/tftf/framework/framework.mk
index 36b29b2..d51a246 100644
--- a/tftf/framework/framework.mk
+++ b/tftf/framework/framework.mk
@@ -18,8 +18,6 @@
 	-Iinclude/lib					\
 	-Iinclude/lib/${ARCH}				\
 	-Iinclude/lib/extensions			\
-	-Iinclude/lib/stdlib				\
-	-Iinclude/lib/stdlib/sys			\
 	-Iinclude/lib/utils				\
 	-Iinclude/lib/xlat_tables			\
 	-Iinclude/plat/common				\
@@ -29,21 +27,6 @@
 	-Ispm/cactus					\
 	-Ispm/ivy
 
-# Standard C library source files
-STD_LIB_SOURCES		:=	lib/stdlib/abort.c			\
-				lib/stdlib/assert.c			\
-				lib/stdlib/mem.c			\
-				lib/stdlib/printf.c			\
-				lib/stdlib/putchar.c			\
-				lib/stdlib/puts.c			\
-				lib/stdlib/rand.c			\
-				lib/stdlib/strchr.c			\
-				lib/stdlib/strcmp.c			\
-				lib/stdlib/strlen.c			\
-				lib/stdlib/strncmp.c			\
-				lib/stdlib/strncpy.c			\
-				lib/stdlib/subr_prf.c
-
 FRAMEWORK_SOURCES	:=	${AUTOGEN_DIR}/tests_list.c
 
 FRAMEWORK_SOURCES	+=	$(addprefix tftf/,			\
@@ -76,7 +59,6 @@
 	lib/sdei/sdei.c							\
 	lib/smc/${ARCH}/asm_smc.S					\
 	lib/smc/${ARCH}/smc.c						\
-	${STD_LIB_SOURCES}						\
 	lib/trusted_os/trusted_os.c					\
 	lib/utils/mp_printf.c						\
 	lib/utils/uuid.c						\