From b5db591eda27b4481f243e06d2e31fae380e91e4 Mon Sep 17 00:00:00 2001 From: Oystein Eftevaag Date: Wed, 1 Feb 2023 23:52:58 +0000 Subject: Enable Windows host compilation of tpm2-tss Bug: 261908998 Test: Builds using MinGW Change-Id: I3c399ced01c212e4600d392621160ee033aaeaf2 --- Android.bp | 25 +++++++++++++++++++++++-- src/tss2-tcti/tctildr-nodl.c | 2 +- src/tss2-tcti/tctildr.c | 6 ++++-- src/util/io.h | 4 +++- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Android.bp b/Android.bp index 711ef7cc..b35ded7b 100644 --- a/Android.bp +++ b/Android.bp @@ -40,6 +40,15 @@ cc_defaults { "include", ], host_supported: true, + target: { + windows: { + enabled: true, + cflags: [ + "-DNOGDI", + "-Wno-format", + ], + }, + }, } cc_library { @@ -115,11 +124,17 @@ cc_library { local_include_dirs: [ "include/tss2", "src", - "src/util", ], shared_libs: [ "libbase", ], + target: { + windows: { + host_ldlibs: [ + "-lws2_32", + ], + }, + }, } cc_library { @@ -127,7 +142,6 @@ cc_library { defaults: [ "tpm2-tss-defaults" ], srcs: [ "src/tss2-tcti/tcti-common.c", - "src/tss2-tcti/tcti-device.c", "src/tss2-tcti/tctildr.c", "src/tss2-tcti/tctildr-nodl.c", ], @@ -140,6 +154,13 @@ cc_library { "tpm2-tss2-mu", "tpm2-tss2-util", ], + target: { + not_windows: { + srcs: [ + "src/tss2-tcti/tcti-device.c", + ], + }, + }, } cc_library { diff --git a/src/tss2-tcti/tctildr-nodl.c b/src/tss2-tcti/tctildr-nodl.c index ca18e585..772178c5 100644 --- a/src/tss2-tcti/tctildr-nodl.c +++ b/src/tss2-tcti/tctildr-nodl.c @@ -57,7 +57,7 @@ struct { char *conf; char *description; } tctis [] = { -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) { .names = { "libtss2-tcti-tbs.so.0", diff --git a/src/tss2-tcti/tctildr.c b/src/tss2-tcti/tctildr.c index a0567aec..614b4d74 100644 --- a/src/tss2-tcti/tctildr.c +++ b/src/tss2-tcti/tctildr.c @@ -13,11 +13,13 @@ #include #if defined(__linux__) #include -#elif defined(_MSC_VER) +#elif defined(_MSC_VER) || defined(__MINGW32__) #include #include + #ifndef PATH_MAX #define PATH_MAX MAX_PATH +#endif static char *strndup(const char* s, size_t n) { @@ -34,7 +36,7 @@ static char *strndup(const char* s, size_t n) memcpy(dst, s, n); return dst; } -#endif + #else #include #endif diff --git a/src/util/io.h b/src/util/io.h index f20ff3e8..7586e07a 100644 --- a/src/util/io.h +++ b/src/util/io.h @@ -7,10 +7,12 @@ #define UTIL_IO_H #ifdef _WIN32 -#include +#include #include #include +#ifdef _MSC_VER typedef SSIZE_T ssize_t; +#endif #define _HOST_NAME_MAX MAX_COMPUTERNAME_LENGTH #else -- cgit v1.2.3