Merge pull request #71 from Patater/remove-non-crypto

Remove non-crypto code
diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt
index 72b113b..61bc13d 100644
--- a/library/CMakeLists.txt
+++ b/library/CMakeLists.txt
@@ -29,7 +29,6 @@
     ecp_curves.c
     entropy.c
     entropy_poll.c
-    error.c
     gcm.c
     havege.c
     hkdf.c
@@ -65,11 +64,27 @@
     sha512.c
     threading.c
     timing.c
-    version.c
-    version_features.c
     xtea.c
 )
 
+# For files generated by the parent project (Mbed TLS) when building Mbed
+# Crypto as a submodule, ensure that the parent project instance is used.
+if(USE_CRYPTO_SUBMODULE)
+set(src_crypto
+    ${src_crypto}
+    ${CMAKE_SOURCE_DIR}/library/version.c
+    ${CMAKE_SOURCE_DIR}/library/version_features.c
+    ${CMAKE_SOURCE_DIR}/library/error.c
+)
+else()
+set(src_crypto
+    ${src_crypto}
+    version.c
+    version_features.c
+    error.c
+)
+endif()
+
 if(CMAKE_COMPILER_IS_GNUCC)
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes")
 endif(CMAKE_COMPILER_IS_GNUCC)
diff --git a/library/Makefile b/library/Makefile
index b79bc6b..30bc96f 100644
--- a/library/Makefile
+++ b/library/Makefile
@@ -71,7 +71,7 @@
 		dhm.o		ecdh.o		ecdsa.o		\
 		ecjpake.o	ecp.o				\
 		ecp_curves.o	entropy.o	entropy_poll.o	\
-		error.o		gcm.o		havege.o	\
+		gcm.o		havege.o			\
 		hkdf.o						\
 		hmac_drbg.o	md.o		md2.o		\
 		md4.o		md5.o		md_wrap.o	\
@@ -86,8 +86,20 @@
 		psa_its_file.o					\
 		ripemd160.o	rsa_internal.o	rsa.o  		\
 		sha1.o		sha256.o	sha512.o	\
-		threading.o	timing.o	version.o	\
-		version_features.o		xtea.o
+		threading.o	timing.o			\
+		xtea.o
+
+# For files generated by the parent project (Mbed TLS) when building Mbed
+# Crypto as a submodule, ensure that the parent project instance is used.
+ifeq ($(USE_CRYPTO_SUBMODULE), 1)
+OBJS_CRYPTO += ../../library/error.o
+OBJS_CRYPTO += ../../library/version.o
+OBJS_CRYPTO += ../../library/version_features.o
+else
+OBJS_CRYPTO += error.o
+OBJS_CRYPTO += version.o
+OBJS_CRYPTO += version_features.o
+endif
 
 .SILENT:
 
@@ -132,7 +144,7 @@
 
 .c.o:
 	echo "  CC    $<"
-	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) -c $<
+	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) -c $< -o $@
 
 clean:
 ifndef WINDOWS