Branimir Karadžić 8 years ago
parent
commit
8cda5da3b8
5 changed files with 46 additions and 30 deletions
  1. 5 0
      scripts/genie.lua
  2. 33 25
      scripts/toolchain.lua
  3. 4 1
      src/crtnone.cpp
  4. 2 2
      tests/macros_test.cpp
  5. 2 2
      tests/simd_test.cpp

+ 5 - 0
scripts/genie.lua

@@ -8,6 +8,11 @@ newoption {
 	description = "Enable amalgamated build.",
 }
 
+newoption {
+	trigger = "with-crtnone",
+	description = "Enable build without CRT.",
+}
+
 solution "bx"
 	configurations {
 		"Debug",

+ 33 - 25
scripts/toolchain.lua

@@ -6,6 +6,36 @@
 local bxDir = path.getabsolute("..")
 local naclToolchain = ""
 
+local function crtNone()
+
+	if _OPTIONS["with-crtnone"] then
+		defines { "BX_CRT_NONE" }
+
+		buildoptions {
+			"-nostdlib",
+			"-nodefaultlibs",
+			"-nostartfiles",
+			"-Wa,--noexecstack",
+			"-ffreestanding",
+
+			"-mpreferred-stack-boundary=4",
+			"-mstackrealign",
+		}
+
+		linkoptions {
+			"-nostdlib",
+			"-nodefaultlibs",
+			"-nostartfiles",
+			"-Wa,--noexecstack",
+			"-ffreestanding",
+
+			"-mpreferred-stack-boundary=4",
+			"-mstackrealign",
+		}
+	end
+
+end
+
 function toolchain(_buildDir, _libDir)
 
 	newoption {
@@ -711,6 +741,9 @@ function toolchain(_buildDir, _libDir)
 		}
 		buildoptions { "-m64" }
 
+	configuration { "linux-*" }
+		crtNone()
+
 	configuration { "linux-clang" }
 
 	configuration { "linux-gcc-6" }
@@ -730,31 +763,6 @@ function toolchain(_buildDir, _libDir)
 		buildoptions {
 			"-mfpmath=sse",
 		}
---[[
-		defines { "BX_CRT_NONE" }
-
-		buildoptions {
-			"-nostdlib",
-			"-nodefaultlibs",
-			"-nostartfiles",
-			"-Wa,--noexecstack",
-			"-ffreestanding",
-
-			"-mpreferred-stack-boundary=4",
-			"-mstackrealign",
-		}
-
-		linkoptions {
-			"-nostdlib",
-			"-nodefaultlibs",
-			"-nostartfiles",
-			"-Wa,--noexecstack",
-			"-ffreestanding",
-
-			"-mpreferred-stack-boundary=4",
-			"-mstackrealign",
-		}
---]]
 
 	configuration { "linux-gcc* or linux-clang*" }
 		buildoptions {

+ 4 - 1
src/crtnone.cpp

@@ -9,6 +9,9 @@
 
 #if BX_CRT_NONE
 
+typedef int64_t off64_t;
+typedef int32_t pid_t;
+
 extern "C" void* memcpy(void* _dst, const void* _src, size_t _numBytes)
 {
 	bx::memCopy(_dst, _src, _numBytes);
@@ -80,7 +83,7 @@ extern "C" const char* strstr(const char* _str, const char* _find)
 	return bx::strnstr(_str, _find);
 }
 
-extern "C" void qsort(void* _base, size_t _num, size_t _size, ComparisonFn _fn)
+extern "C" void qsort(void* _base, size_t _num, size_t _size, bx::ComparisonFn _fn)
 {
 	BX_CHECK(_num <= UINT32_MAX && _size <= UINT32_MAX, "");
 	return bx::quickSort(_base, _num, _size, _fn);

+ 2 - 2
tests/macros_test.cpp

@@ -4,8 +4,8 @@
  */
 
 #include "test.h"
-#include <string.h>
 #include <bx/bx.h>
+#include <bx/string.h>
 
 BX_STATIC_ASSERT(false
 	|| BX_CRT_BIONIC
@@ -61,5 +61,5 @@ TEST(macros)
 	CHECK_EQUAL(5, BX_VA_ARGS_COUNT(1, 2, 3, 4, 5) );
 	CHECK_EQUAL(6, BX_VA_ARGS_COUNT(1, 2, 3, 4, 5, 6) );
 
-	CHECK_EQUAL(0, strcmp(BX_STRINGIZE(TEST 1234 %^&*), "TEST 1234 %^&*") );
+	CHECK_EQUAL(0, bx::strncmp(BX_STRINGIZE(TEST 1234 %^&*), "TEST 1234 %^&*") );
 }

+ 2 - 2
tests/simd_test.cpp

@@ -6,7 +6,7 @@
 #include "test.h"
 #include <bx/simd_t.h>
 #include <bx/fpumath.h>
-#include <string.h>
+#include <bx/string.h>
 
 #if 0
 #	define SIMD_DBG DBG
@@ -206,7 +206,7 @@ void simd_check_string(const char* _str, bx::simd128_t _a)
 
 	SIMD_DBG("%s %s", _str, test);
 
-	CHECK(0 == strcmp(_str, test) );
+	CHECK(0 == bx::strncmp(_str, test) );
 }
 
 TEST_CASE("simd_swizzle", "")