Skip to content

Commit d7a7c20

Browse files
authored
Support compilation on and for Mac OS X systems (#1) (canonical#54)
1 parent 98b60a4 commit d7a7c20

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,18 @@ Follows the common `./bootstrap && ./configure && make` convention.
5050
Note that autotools scripts require the following prerequisite packages: `autoconf-archive`, `pkg-config`, and sometimes `build-essential` and `automake`. Their absence is not automatically detected. The build also needs `gcc` and `libssl-dev` packages.
5151

5252
Similarly to the Windows build, if you enable SM{2,3,4} algorithms in `TpmProfile.h`, the build may fail because of missing `SM{2,3,4}.h` headers. In this case you will need to manually copy them over from OpenSSL’s `include/crypt` folder.
53+
54+
## Mac OS X build
55+
56+
As with the Linux build, use `./bootstrap`, `./configure`, and `make`.
57+
If you used Homebrew to install OpenSSL, you may need to include its path in `PKG_CONFIG_PATH`.
58+
OS X compilers treat uninitialized global variables as
59+
[common symbols](https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/MachOTopics/1-Articles/executing_files.html),
60+
which can be eliminated with the `-fno-common` compiler option.
61+
Future updates to the autotools configurations may automate one or both of these steps.
62+
63+
```
64+
./bootstrap
65+
PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig" EXTRA_CFLAGS=-fno-common ./configure
66+
make
67+
```

TPMCmd/Simulator/include/prototypes/Simulator_fp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
//** From TcpServer.c
4444

4545
#ifdef _MSC_VER
46-
#elif defined(__unix__)
46+
#elif defined(__unix__) || defined(__APPLE__)
4747
#endif
4848

4949
//*** PlatformServer()
@@ -156,7 +156,7 @@ TpmServer(
156156
//** From TPMCmdp.c
157157

158158
#ifdef _MSC_VER
159-
#elif defined(__unix__)
159+
#elif defined(__unix__) || defined(__APPLE__)
160160
#endif
161161

162162
//*** Signal_PowerOn()

TPMCmd/Simulator/src/TPMCmdp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
# include <windows.h>
4949
# include <winsock.h>
5050
# pragma warning(pop)
51-
#elif defined(__unix__)
51+
#elif defined(__unix__) || defined(__APPLE__)
5252
# include "BaseTypes.h" // on behalf of TpmFail_fp.h
5353
typedef int SOCKET;
5454
#else

TPMCmd/Simulator/src/TPMCmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
# include <windows.h>
5151
# include <winsock.h>
5252
# pragma warning(pop)
53-
#elif defined(__unix__)
53+
#elif defined(__unix__) || defined(__APPLE__)
5454
# define _strcmpi strcasecmp
5555
typedef int SOCKET;
5656
#else

TPMCmd/Simulator/src/TcpServer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
# include <winsock.h>
4949
# pragma warning(pop)
5050
typedef int socklen_t;
51-
#elif defined(__unix__)
51+
#elif defined(__unix__) || defined(__APPLE__)
5252
# include <string.h>
5353
# include <unistd.h>
5454
# include <errno.h>

TPMCmd/bootstrap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ ${AUTORECONF} --install --sym
6060
# A freshly checked out source tree will not build. VendorString.h must have
6161
# these symbols defined to build.
6262
echo "Setting default vendor strings"
63-
sed -i 's&^\/\/\(#define[[:space:]]\+FIRMWARE_V1.*\)&\1&;
63+
sed -i.bak 's&^\/\/\(#define[[:space:]]\+FIRMWARE_V1.*\)&\1&;
6464
s&^\/\/\(#define[[:space:]]\+MANUFACTURER.*\)&\1&;
6565
s&^\/\/\(#define[[:space:]]\+VENDOR_STRING_1.*\)&\1&' \
66-
tpm/include/VendorString.h
66+
tpm/include/VendorString.h && rm tpm/include/VendorString.h.bak

0 commit comments

Comments
 (0)