From 35da877479aaa632c9bd37284ecf3d66a6701a1e Mon Sep 17 00:00:00 2001 From: Oystein Eftevaag Date: Wed, 1 Feb 2023 23:51:45 +0000 Subject: Enable Windows host compilation of ms-tpm-20-ref Bug: 261908998 Test: gflags builds with MinGW Change-Id: I292ce2c0d654f8c1d30275e14d94d5972a1c51c1 --- Android.bp | 15 +++++++++++++-- TPMCmd/Simulator/src/TPMCmdp.c | 2 +- TPMCmd/Simulator/src/TPMCmds.c | 2 +- TPMCmd/Simulator/src/TcpServer.c | 16 ++++++++-------- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Android.bp b/Android.bp index 355aaaf..7400a27 100644 --- a/Android.bp +++ b/Android.bp @@ -76,7 +76,7 @@ cc_defaults { ], } -cc_library { +cc_library_static { name: "ms-tpm-20-ref-lib", srcs: [ "TPMCmd/Platform/src/*.c", @@ -100,6 +100,17 @@ cc_library { "TPMCmd/tpm/include/Ossl", "TPMCmd/tpm/include/prototypes", ], + target: { + windows: { + enabled: true, + cflags: [ + "-Wno-unknown-pragmas", + ], + host_ldlibs: [ + "-lws2_32", + ], + }, + }, defaults: [ "ms-tpm-20-ref-defaults" ], } @@ -108,7 +119,7 @@ cc_binary_host { srcs: [ "TPMCmd/Simulator/src/TPMCmds.c", ], - shared_libs: [ + static_libs: [ "ms-tpm-20-ref-lib", ], defaults: [ "ms-tpm-20-ref-defaults" ], diff --git a/TPMCmd/Simulator/src/TPMCmdp.c b/TPMCmd/Simulator/src/TPMCmdp.c index b776c59..6e5c22b 100644 --- a/TPMCmd/Simulator/src/TPMCmdp.c +++ b/TPMCmd/Simulator/src/TPMCmdp.c @@ -43,7 +43,7 @@ #include #include "TpmBuildSwitches.h" -#ifdef _MSC_VER +#ifdef _WIN32 # pragma warning(push, 3) # include # include diff --git a/TPMCmd/Simulator/src/TPMCmds.c b/TPMCmd/Simulator/src/TPMCmds.c index 0aca528..ade1c23 100644 --- a/TPMCmd/Simulator/src/TPMCmds.c +++ b/TPMCmd/Simulator/src/TPMCmds.c @@ -45,7 +45,7 @@ #include #include -#ifdef _MSC_VER +#ifdef _WIN32 # pragma warning(push, 3) # include # include diff --git a/TPMCmd/Simulator/src/TcpServer.c b/TPMCmd/Simulator/src/TcpServer.c index c12b6c6..5adb90a 100644 --- a/TPMCmd/Simulator/src/TcpServer.c +++ b/TPMCmd/Simulator/src/TcpServer.c @@ -42,7 +42,7 @@ #include #include -#ifdef _MSC_VER +#ifdef _WIN32 # pragma warning(push, 3) # include # include @@ -110,7 +110,7 @@ CreateSocket( int res; // // Initialize Winsock -#ifdef _MSC_VER +#ifdef _WIN32 WSADATA wsaData; res = WSAStartup(MAKEWORD(2, 2), &wsaData); if(res != 0) @@ -297,7 +297,7 @@ PlatformSignalService( int PortNumber ) { -#if defined(_MSC_VER) +#if defined(_WIN32) HANDLE hPlatformSvc; int ThreadId; int port = PortNumber; @@ -324,7 +324,7 @@ PlatformSignalService( printf("pthread_create failed: %s", strerror(ret)); } return ret; -#endif // _MSC_VER +#endif // _WIN32 } //*** RegularCommandService() @@ -394,13 +394,13 @@ SimulatorTimeServiceRoutine( { uint64_t curTime; -#if defined(_MSC_VER) +#if defined(_WIN32) Sleep((DWORD)timeout); #else struct timespec req = { timeout / 1000, (timeout % 1000) * 1000 }; struct timespec rem; nanosleep(&req, &rem); -#endif // _MSC_VER +#endif // _WIN32 curTime = _plat__RealTime(); // May need to issue several ticks if the Sleep() took longer than asked, @@ -435,7 +435,7 @@ ActTimeService( int ret = 0; if(!running) { -#if defined(_MSC_VER) +#if defined(_WIN32) HANDLE hThr; int ThreadId; // @@ -456,7 +456,7 @@ ActTimeService( // ret = pthread_create(&thread_id, NULL, (void*)SimulatorTimeServiceRoutine, (LPVOID)(INT_PTR)NULL); -#endif // _MSC_VER +#endif // _WIN32 if(ret != 0) printf("ACT thread Creation failed\n"); -- cgit v1.2.3