From f24ee1733e63e6f2e817797d428bc636025ae45f Mon Sep 17 00:00:00 2001
From: Matt Arsenault <arsenm2@rpi.edu>
Date: Wed, 22 Jun 2011 21:56:41 -0400
Subject: [PATCH 5/6] Fix autotools build with recent OS X versions
---
client/Makefile.am | 15 +++++---
client/cs_platforms.cpp | 23 +++++-------
client/hostinfo_unix.cpp | 84 +++++++++++++++++++++++++--------------------
3 files changed, 66 insertions(+), 56 deletions(-)
diff --git a/client/Makefile.am b/client/Makefile.am
index 20b1194..f72d971 100644
a
|
b
|
endif ## ENABLE_CLIENT_RELEASE |
19 | 19 | LIBS += $(CLIENTLIBS) |
20 | 20 | |
21 | 21 | if OS_DARWIN |
22 | | LIBS += -framework IOKit -framework Foundation -framework ScreenSaver -framework Cocoa |
| 22 | LIBS += -framework IOKit -framework Foundation -framework ScreenSaver -framework Cocoa -framework CoreServices |
23 | 23 | endif |
24 | 24 | |
25 | 25 | bin_PROGRAMS = boinc_client switcher boinccmd |
26 | 26 | |
27 | 27 | boinccmd_SOURCES = boinc_cmd.cpp |
28 | | boinccmd_DEPENDENCIES = $(LIBBOINC) |
| 28 | boinccmd_DEPENDENCIES = $(LIBBOINC) |
29 | 29 | boinccmd_CPPFLAGS = $(AM_CPPFLAGS) |
30 | | boinccmd_LDFLAGS = $(AM_LDFLAGS) -L../lib |
| 30 | boinccmd_LDFLAGS = $(AM_LDFLAGS) -L../lib |
31 | 31 | boinccmd_LDADD = $(LIBBOINC) $(BOINC_EXTRA_LIBS) $(PTHREAD_LIBS) |
32 | 32 | |
33 | 33 | boinc_client_SOURCES = \ |
… |
… |
boinc_client_SOURCES = \ |
79 | 79 | |
80 | 80 | boinc_client_DEPENDENCIES = $(LIBBOINC) |
81 | 81 | boinc_client_CPPFLAGS = $(AM_CPPFLAGS) |
82 | | boinc_client_LDFLAGS = $(AM_LDFLAGS) -L../lib |
83 | | boinc_client_LDADD = $(LIBBOINC) $(LIBBOINC_CRYPT) $(BOINC_EXTRA_LIBS) $(PTHREAD_LIBS) |
| 82 | boinc_client_LDFLAGS = $(AM_LDFLAGS) -L../lib |
| 83 | if OS_DARWIN |
| 84 | boinc_client_LDFLAGS += -Wl,-flat_namespace,-undefined,dynamic_lookup |
| 85 | endif |
| 86 | boinc_client_LDADD = $(LIBBOINC) $(LIBBOINC_CRYPT) $(BOINC_EXTRA_LIBS) $(PTHREAD_LIBS) |
84 | 87 | |
85 | 88 | boinc_clientdir = $(bindir) |
86 | 89 | |
87 | 90 | switcher_SOURCES = switcher.cpp |
88 | | switcher_LDFLAGS = $(AM_LDFLAGS) -L../lib |
| 91 | switcher_LDFLAGS = $(AM_LDFLAGS) -L../lib |
89 | 92 | switcher_LDADD = $(LIBBOINC) |
90 | 93 | |
91 | 94 | ## since we are using libtool we need some magic to get boinc and boinc_client |
diff --git a/client/cs_platforms.cpp b/client/cs_platforms.cpp
index 3b7290f..fd92d5b 100644
a
|
b
|
LPFN_ISWOW64PROCESS fnIsWow64Process; |
40 | 40 | #endif |
41 | 41 | #endif |
42 | 42 | |
| 43 | #if defined(__APPLE__) && (defined(__i386__) || defined(__x86_64__)) |
| 44 | #include <CoreServices/CoreServices.h> |
| 45 | #include <sys/sysctl.h> |
| 46 | #endif |
| 47 | |
| 48 | |
| 49 | |
43 | 50 | #include "client_types.h" |
44 | 51 | #include "client_state.h" |
45 | 52 | #include "error_numbers.h" |
… |
… |
LPFN_ISWOW64PROCESS fnIsWow64Process; |
49 | 56 | #include "str_replace.h" |
50 | 57 | #include "util.h" |
51 | 58 | |
52 | | #if (defined (__APPLE__) && (defined(__i386__) || defined(__x86_64__))) |
53 | | #include <sys/sysctl.h> |
54 | | #include <Carbon/Carbon.h> |
55 | | |
56 | | char *HOSTTYPE = ""; |
57 | | #endif |
58 | | |
59 | 59 | // return the primary platform id. |
60 | 60 | // |
61 | 61 | const char* CLIENT_STATE::get_primary_platform() { |
… |
… |
void CLIENT_STATE::detect_platforms() { |
109 | 109 | err = Gestalt(gestaltSystemVersion, &version); |
110 | 110 | retval = sysctlbyname("hw.optional.x86_64", &response, &len, NULL, 0); |
111 | 111 | if ((err == noErr) && (version >= 0x1050) && response && (!retval)) { |
112 | | HOSTTYPE = "x86_64-apple-darwin"; |
113 | 112 | add_platform("x86_64-apple-darwin"); |
114 | | } else { |
115 | | HOSTTYPE = "i686-apple-darwin"; |
116 | 113 | } |
117 | 114 | |
118 | 115 | // Supported on both Mac Intel architectures |
119 | 116 | add_platform("i686-apple-darwin"); |
120 | 117 | #else |
121 | | // We no longer request PowerPC applications on Intel Macs |
122 | | // because all projects supporting Macs should have Intel |
123 | | // applications by now, and PowerPC emulation ("Rosetta") |
| 118 | // We no longer request PowerPC applications on Intel Macs |
| 119 | // because all projects supporting Macs should have Intel |
| 120 | // applications by now, and PowerPC emulation ("Rosetta") |
124 | 121 | // is not always supported in newer versions of OS X. |
125 | 122 | add_platform("powerpc-apple-darwin"); |
126 | 123 | #endif |
diff --git a/client/hostinfo_unix.cpp b/client/hostinfo_unix.cpp
index afd6f14..ed56da0 100644
a
|
b
|
|
16 | 16 | // along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | |
18 | 18 | // There is a reason that having a file called "cpp.h" that includes config.h |
19 | | // and some of the C++ header files is bad. That reason is because there are |
20 | | // #defines that alter the behiour of the standard C and C++ headers. In |
21 | | // this case we need to use the "small files" environment on some unix |
| 19 | // and some of the C++ header files is bad. That reason is because there are |
| 20 | // #defines that alter the behiour of the standard C and C++ headers. In |
| 21 | // this case we need to use the "small files" environment on some unix |
22 | 22 | // systems. That can't be done if we include "cpp.h" |
23 | 23 | |
24 | | // copied directly from cpp.h |
25 | | #if defined(_WIN32) && !defined(__CYGWIN32__) |
26 | | |
27 | | #if defined(_WIN64) && defined(_M_X64) |
28 | | #define HOSTTYPE "windows_x86_64" |
29 | | #define HOSTTYPEALT "windows_intelx86" |
30 | | #else |
31 | | #define HOSTTYPE "windows_intelx86" |
32 | | #endif |
33 | | |
34 | 24 | #include "version.h" // version numbers from autoconf |
35 | | #endif |
36 | 25 | |
| 26 | #include "cpp.h" |
37 | 27 | #include "config.h" |
38 | 28 | |
39 | 29 | #if !defined(_WIN32) || defined(__CYGWIN32__) |
40 | 30 | |
41 | 31 | // Access to binary files in /proc filesystem doesn't work in the 64bit |
42 | | // files environment on some systems. None of the functions here need |
| 32 | // files environment on some systems. None of the functions here need |
43 | 33 | // 64bit file functions, so we'll undefine _FILE_OFFSET_BITS and _LARGE_FILES. |
44 | 34 | #undef _FILE_OFFSET_BITS |
45 | 35 | #undef _LARGE_FILES |
… |
… |
|
110 | 100 | #include "client_types.h" |
111 | 101 | #include "client_msgs.h" |
112 | 102 | #include "hostinfo_network.h" |
| 103 | #include "hostinfo.h" |
113 | 104 | |
114 | 105 | using std::string; |
115 | 106 | |
116 | 107 | #ifdef __APPLE__ |
| 108 | #include <IOKit/IOKitLib.h> |
117 | 109 | #include <Carbon/Carbon.h> |
118 | 110 | #include <CoreFoundation/CoreFoundation.h> |
| 111 | |
119 | 112 | #ifdef __cplusplus |
120 | 113 | extern "C" { |
121 | 114 | #endif |
… |
… |
bool HOST_INFO::host_is_running_on_batteries() { |
208 | 201 | CFStringRef psState; |
209 | 202 | int i; |
210 | 203 | bool retval = false; |
211 | | |
| 204 | |
212 | 205 | CFTypeRef blob = IOPSCopyPowerSourcesInfo(); |
213 | 206 | CFArrayRef list = IOPSCopyPowerSourcesList(blob); |
214 | 207 | |
… |
… |
static void get_cpu_info_maxosx(HOST_INFO& host) { |
637 | 630 | #if defined(__i386__) || defined(__x86_64__) |
638 | 631 | char brand_string[256]; |
639 | 632 | int family, stepping, model; |
640 | | |
| 633 | |
641 | 634 | len = sizeof(host.p_vendor); |
642 | 635 | sysctlbyname("machdep.cpu.vendor", host.p_vendor, &len, NULL, 0); |
643 | 636 | |
… |
… |
static void get_cpu_info_maxosx(HOST_INFO& host) { |
658 | 651 | |
659 | 652 | snprintf( |
660 | 653 | host.p_model, sizeof(host.p_model), |
661 | | "%s [x86 Family %d Model %d Stepping %d]", |
| 654 | "%s [x86 Family %d Model %d Stepping %d]", |
662 | 655 | brand_string, family, model, stepping |
663 | 656 | ); |
664 | 657 | #else // PowerPC |
… |
… |
static void get_cpu_info_maxosx(HOST_INFO& host) { |
670 | 663 | if (response && (!retval)) { |
671 | 664 | safe_strcpy(host.p_features, "AltiVec"); |
672 | 665 | } |
673 | | |
| 666 | |
674 | 667 | len = sizeof(model); |
675 | 668 | sysctlbyname("hw.model", model, &len, NULL, 0); |
676 | 669 | |
… |
… |
static void get_cpu_info_haiku(HOST_INFO& host) { |
703 | 696 | cpuid_info cpuInfo; |
704 | 697 | int32 maxStandardFunction; |
705 | 698 | int32 maxExtendedFunction = 0; |
706 | | |
| 699 | |
707 | 700 | char brand_string[256]; |
708 | 701 | |
709 | 702 | if (get_system_info(&sys_info) != B_OK) { |
… |
… |
static void get_cpu_info_haiku(HOST_INFO& host) { |
718 | 711 | |
719 | 712 | snprintf(host.p_vendor, sizeof(host.p_vendor), "%.12s", |
720 | 713 | cpuInfo.eax_0.vendor_id); |
721 | | |
| 714 | |
722 | 715 | maxStandardFunction = cpuInfo.eax_0.max_eax; |
723 | 716 | if (maxStandardFunction >= 500) |
724 | 717 | maxStandardFunction = 0; /* old Pentium sample chips has |
… |
… |
int get_network_usage_totals(unsigned int& total_received, unsigned int& total_s |
855 | 848 | |
856 | 849 | total_received = 0; |
857 | 850 | total_sent = 0; |
858 | | |
| 851 | |
859 | 852 | if (sysctl(mib, 6, NULL, ¤tSize, NULL, 0) != 0) return errno; |
860 | 853 | if (!sysctlBuffer || (currentSize > sysctlBufferSize)) { |
861 | 854 | if (sysctlBuffer) free(sysctlBuffer); |
… |
… |
kern_return_t SMCClose() |
996 | 989 | return kIOReturnSuccess; |
997 | 990 | } |
998 | 991 | |
999 | | |
1000 | 992 | kern_return_t SMCReadKey(UInt32 key, SMCBytes_t val) { |
1001 | 993 | kern_return_t result; |
1002 | 994 | SMCKeyData_t inputStructure; |
1003 | 995 | SMCKeyData_t outputStructure; |
1004 | | size_t structureInputSize; |
1005 | | size_t structureOutputSize; |
| 996 | size_t structureOutputSize = 0; |
1006 | 997 | |
1007 | | memset(&inputStructure, 0, sizeof(SMCKeyData_t)); |
1008 | | memset(&outputStructure, 0, sizeof(SMCKeyData_t)); |
| 998 | memset(&inputStructure, 0, sizeof(inputStructure)); |
| 999 | memset(&outputStructure, 0, sizeof(outputStructure)); |
1009 | 1000 | memset(val, 0, sizeof(val)); |
1010 | 1001 | |
1011 | 1002 | inputStructure.key = key; |
1012 | | inputStructure.data8 = SMC_CMD_READ_KEYINFO; |
1013 | | |
1014 | | structureInputSize = sizeof(inputStructure); |
1015 | | structureOutputSize = sizeof(outputStructure); |
1016 | | result = IOConnectMethodStructureIStructureO( |
1017 | | conn, KERNEL_INDEX_SMC, structureInputSize, &structureOutputSize, |
1018 | | &inputStructure, &outputStructure |
1019 | | ); |
| 1003 | inputStructure.data8 = SMC_CMD_READ_KEYINFO; |
| 1004 | |
| 1005 | #if MAC_OS_X_VERSION_10_5 |
| 1006 | result = IOConnectCallStructMethod(conn, |
| 1007 | KERNEL_INDEX_SMC, |
| 1008 | &inputStructure, |
| 1009 | sizeof(inputStructure), |
| 1010 | &inputStructure, |
| 1011 | &structureOutputSize); |
| 1012 | #else |
| 1013 | result = IOConnectMethodStructureIStructureO(conn, |
| 1014 | KERNEL_INDEX_SMC, |
| 1015 | sizeof(inputStructure), |
| 1016 | &structureOutputSize, |
| 1017 | &inputStructure, |
| 1018 | &outputStructure); |
| 1019 | #endif |
1020 | 1020 | if (result != kIOReturnSuccess) { |
1021 | 1021 | return result; |
1022 | 1022 | } |
… |
… |
kern_return_t SMCReadKey(UInt32 key, SMCBytes_t val) { |
1024 | 1024 | inputStructure.keyInfo.dataSize = outputStructure.keyInfo.dataSize; |
1025 | 1025 | inputStructure.data8 = SMC_CMD_READ_BYTES; |
1026 | 1026 | |
| 1027 | #if MAC_OS_X_VERSION_10_5 |
| 1028 | result = IOConnectCallStructMethod(conn, |
| 1029 | KERNEL_INDEX_SMC, |
| 1030 | &inputStructure, |
| 1031 | sizeof(inputStructure), |
| 1032 | &inputStructure, |
| 1033 | &structureOutputSize); |
| 1034 | #else |
1027 | 1035 | result = IOConnectMethodStructureIStructureO( |
1028 | | conn, KERNEL_INDEX_SMC, structureInputSize, &structureOutputSize, |
| 1036 | conn, KERNEL_INDEX_SMC, sizeof(inputStructure), &structureOutputSize), |
1029 | 1037 | &inputStructure, &outputStructure |
1030 | 1038 | ); |
1031 | | if (result != kIOReturnSuccess) |
| 1039 | #endif |
| 1040 | if (result != kIOReturnSuccess) { |
1032 | 1041 | return result; |
| 1042 | } |
1033 | 1043 | |
1034 | 1044 | memcpy(val, outputStructure.bytes, sizeof(outputStructure.bytes)); |
1035 | 1045 | |