[mingw-sigar: 2/12] Initial import
Kalev Lember
kalev at fedoraproject.org
Wed Mar 7 17:38:56 UTC 2012
commit fb9ae3478a32ba556a3a519e378b2fc6d230720e
Author: Andrew Beekhof <andrew at beekhof.net>
Date: Tue Dec 21 21:17:51 2010 +0100
Initial import
.gitignore | 1 +
mingw32-sigar.spec | 96 ++++++++++++++++++++
sigar-mingw.patch | 244 ++++++++++++++++++++++++++++++++++++++++++++++++++++
sources | 1 +
4 files changed, 342 insertions(+), 0 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index e69de29..901fb1c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/sigar-1.6.5-833ca18.tbz2
diff --git a/mingw32-sigar.spec b/mingw32-sigar.spec
new file mode 100644
index 0000000..08dc918
--- /dev/null
+++ b/mingw32-sigar.spec
@@ -0,0 +1,96 @@
+%global __strip %{_mingw32_strip}
+%global __objdump %{_mingw32_objdump}
+%global _use_internal_dependency_generator 0
+%global __find_requires %{_mingw32_findrequires}
+%global __find_provides %{_mingw32_findprovides}
+
+%global shortname sigar
+
+Name: mingw32-%{shortname}
+Version: 1.6.5
+Release: 0.3.git833ca18%{?dist}
+Summary: MinGW Windows sigar library
+
+%global sigar_suffix 0-g4b67f57
+%global sigar_hash 833ca18
+
+Group: Development/Libraries
+License: ASL 2.0
+URL: http://sigar.hyperic.com/
+
+# Once 1.6.5 is released, we can use tarballs from GitHub:
+# Source0: http://download.github.com/hyperic-sigar-{name}-{version}-{sigar_suffix}.tar.gz
+#
+# Until then the tarball can be re-generated with:
+# git clone git://github.com/hyperic/sigar.git
+# cd sigar
+# git archive --prefix=sigar-1.6.5/ 833ca18 | bzip2 > sigar-1.6.5-833ca18.tbz2
+#
+# The diff from 1.6.4 is too huge to contemplate cherrypicking from
+Source0: %{shortname}-%{version}-%{sigar_hash}.tbz2
+Patch1: sigar-mingw.patch
+BuildRoot: %{_tmppath}/%{shortname}-%{version}-%{release}-root-%(%{__id_u} -n)
+
+BuildRequires: mingw32-gcc cmake
+BuildRequires: redhat-rpm-config make
+BuildRequires: mingw32-filesystem >= 57
+
+BuildArch: noarch
+
+%description
+The Sigar API provides a portable interface for gathering system
+information such as:
+- System memory, swap, CPU, load average, uptime, logins
+- Per-process memory, CPU, credential info, state, arguments,
+ environment, open files
+- File system detection and metrics
+- Network interface detection, configuration info and metrics
+- Network route and connection tables
+
+This information is available in most operating systems, but each OS
+has their own way(s) providing it. SIGAR provides developers with one
+API to access this information regardless of the underlying platform.
+
+#The core API is implemented in pure C with bindings currently
+#implemented for Java, Perl and C#.
+
+%prep
+# When using the GitHub tarballs, use:
+# setup -q -n hyperic-{shortname}-{sigar_hash}
+%setup -q -n %{shortname}-%{version}
+%patch1 -p1
+
+%build
+PATH=%{_mingw32_bindir}:$PATH
+
+mkdir build
+pushd build
+%{_mingw32_cmake} ..
+make %{?_smp_mflags}
+popd
+
+%install
+rm -rf $RPM_BUILD_ROOT
+pushd build
+make install DESTDIR=$RPM_BUILD_ROOT
+popd
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%files
+%defattr(-,root,root,-)
+%doc ChangeLog README LICENSE NOTICE AUTHORS
+%{_mingw32_bindir}/libsigar.dll
+%{_mingw32_libdir}/libsigar.dll.a
+%{_mingw32_includedir}/sigar*.h
+
+%changelog
+* Wed Dec 21 2010 Andrew Beekhof <andrew at beekhof.net> - 1.6.5-0.3.git833ca18
+- Minor tweaks before import: summary and use of spaces
+
+* Wed Dec 21 2010 Andrew Beekhof <andrew at beekhof.net> - 1.6.5-0.2.git833ca18
+- Incorporate review feedback, include dependencies generator macro
+
+* Wed Dec 1 2010 Andrew Beekhof <andrew at beekhof.net> - 1.6.5-0.1.git833ca18
+- Initial checkin
diff --git a/sigar-mingw.patch b/sigar-mingw.patch
new file mode 100644
index 0000000..8a3e395
--- /dev/null
+++ b/sigar-mingw.patch
@@ -0,0 +1,244 @@
+diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
+index 83548d1..d9f80eb 100644
+--- a/src/CMakeLists.txt
++++ b/src/CMakeLists.txt
+@@ -4,6 +4,29 @@ MESSAGE(STATUS "CMAKE_SYSTEM_NAME is ${CMAKE_SYSTEM_NAME}")
+
+ INCLUDE_DIRECTORIES(../include/)
+
++INCLUDE(CheckCSourceCompiles)
++
++MACRO (CHECK_STRUCT_MEMBER _STRUCT _MEMBER _HEADER _RESULT)
++ SET(_INCLUDE_FILES)
++ FOREACH (it ${_HEADER})
++ SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n")
++ ENDFOREACH (it)
++
++ SET(_CHECK_STRUCT_MEMBER_SOURCE_CODE "
++${_INCLUDE_FILES}
++int main()
++{
++ static ${_STRUCT} tmp;
++ if (sizeof(tmp.${_MEMBER}))
++ return 0;
++ return 0;
++}
++")
++ CHECK_C_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" ${_RESULT})
++
++ENDMACRO (CHECK_STRUCT_MEMBER)
++
++
+ ## linux
+ IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ SET(SIGAR_SRC os/linux/linux_sigar.c)
+@@ -60,6 +83,8 @@ IF(WIN32)
+ ADD_DEFINITIONS(-DSIGAR_SHARED)
+ SET(SIGAR_SRC os/win32/peb.c os/win32/win32_sigar.c)
+ INCLUDE_DIRECTORIES(os/win32)
++ CHECK_STRUCT_MEMBER(MIB_IPADDRROW wType "windows.h;iphlpapi.h" wType_in_MIB_IPADDRROW)
++ add_definitions(-DHAVE_MIB_IPADDRROW_WTYPE=${wType_in_MIB_IPADDRROW})
+ ENDIF(WIN32)
+
+ SET(SIGAR_SRC ${SIGAR_SRC}
+diff --git a/src/os/win32/sigar_os.h b/src/os/win32/sigar_os.h
+index ff2de7c..cd3c7e8 100755
+--- a/src/os/win32/sigar_os.h
++++ b/src/os/win32/sigar_os.h
+@@ -19,11 +19,15 @@
+ #ifndef SIGAR_OS_H
+ #define SIGAR_OS_H
+
++#ifdef MSVC
+ #if _MSC_VER <= 1200
+ #define SIGAR_USING_MSC6 /* Visual Studio version 6 */
+ #endif
++#else
++/* Cross compiling */
++#define _WIN32_WINNT 0x0501
++#endif
+
+-#define WIN32_LEAN_AND_MEAN
+ #include <windows.h>
+ #include <winreg.h>
+ #include <winperf.h>
+@@ -38,7 +42,22 @@
+
+ #include "sigar_util.h"
+
+-#define INT64_C(val) val##i64
++#ifdef MSVC
++# define INT64_C(val) val##i64
++# define SIGAR_DLLFUNC(api, name) \
++ struct { \
++ const char *name; \
++ ##api##_##name func; \
++ } ##name
++#else
++/* The GCC compiler doesn't require/accept the ## prefix */
++# define INT64_C(val) val##L
++# define SIGAR_DLLFUNC(api, name) \
++ struct { \
++ const char *name; \
++ api##_##name func; \
++ } name
++#endif
+
+ /* see apr/include/arch/win32/atime.h */
+ #define EPOCH_DELTA INT64_C(11644473600000000)
+@@ -457,12 +476,6 @@ typedef BOOL (CALLBACK *mpr_get_net_connection)(LPCTSTR,
+ LPTSTR,
+ LPDWORD);
+
+-#define SIGAR_DLLFUNC(api, name) \
+- struct { \
+- const char *name; \
+- ##api##_##name func; \
+- } ##name
+-
+ typedef struct {
+ sigar_dll_handle_t handle;
+
+diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c
+index b9a5669..74bf874 100755
+--- a/src/os/win32/win32_sigar.c
++++ b/src/os/win32/win32_sigar.c
+@@ -23,6 +23,7 @@
+ #include "sigar_util.h"
+ #include "sigar_format.h"
+ #include <shellapi.h>
++#include <iphlpapi.h>
+
+ #define USING_WIDE_S(s) (s)->using_wide
+ #define USING_WIDE() USING_WIDE_S(sigar)
+@@ -124,6 +125,9 @@ typedef enum {
+ #define MS_LOOPBACK_ADAPTER "Microsoft Loopback Adapter"
+ #define NETIF_LA "la"
+
++static int get_proc_info(sigar_t *sigar, sigar_pid_t pid);
++static int netif_hash(char *s);
++
+ sigar_uint64_t sigar_FileTimeToTime(FILETIME *ft)
+ {
+ sigar_uint64_t time;
+@@ -374,6 +378,7 @@ static sigar_mpr_t sigar_mpr = {
+ { NULL, NULL }
+ };
+
++#ifdef MSVC
+ #define DLLMOD_COPY(name) \
+ memcpy(&(sigar->##name), &sigar_##name, sizeof(sigar_##name))
+
+@@ -382,6 +387,18 @@ static sigar_mpr_t sigar_mpr = {
+
+ #define DLLMOD_FREE(name) \
+ sigar_dllmod_free((sigar_dll_module_t *)&(sigar->##name))
++#else
++/* The GCC compiler doesn't require/accept the ## prefix */
++#define DLLMOD_COPY(name) \
++ memcpy(&(sigar->name), &sigar_##name, sizeof(sigar_##name))
++
++#define DLLMOD_INIT(name, all) \
++ sigar_dllmod_init(sigar, (sigar_dll_module_t *)&(sigar->name), all)
++
++#define DLLMOD_FREE(name) \
++ sigar_dllmod_free((sigar_dll_module_t *)&(sigar->name))
++#endif
++
+
+ static void sigar_dllmod_free(sigar_dll_module_t *module)
+ {
+@@ -1470,7 +1487,9 @@ static int sigar_remote_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
+ }
+
+ /* likely we are 32-bit, pid process is 64-bit */
++#ifdef MSVC
+ status = sigar_proc_args_wmi_get(sigar, pid, procargs);
++#endif
+ if (status == ERROR_NOT_FOUND) {
+ status = SIGAR_NO_SUCH_PROCESS;
+ }
+@@ -1507,7 +1526,7 @@ static int sigar_proc_env_parse(UCHAR *ptr, sigar_proc_env_t *procenv,
+ break; /*XXX*/
+ }
+
+- klen = val - ptr;
++ klen = val - (char*)ptr;
+ SIGAR_SSTRCPY(key, ptr);
+ key[klen] = '\0';
+ ++val;
+@@ -1640,6 +1659,7 @@ SIGAR_DECLARE(int) sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
+ }
+
+ status = sigar_proc_exe_peb_get(sigar, proc, procexe);
++#ifdef MSVC
+ if (procexe->name[0] == '\0') {
+ /* likely we are 32-bit, pid process is 64-bit */
+ /* procexe->cwd[0] = XXX where else can we try? */
+@@ -1648,7 +1668,7 @@ SIGAR_DECLARE(int) sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
+ status = SIGAR_NO_SUCH_PROCESS;
+ }
+ }
+-
++#endif
+ if (procexe->cwd[0] != '\0') {
+ /* strip trailing '\' */
+ int len = strlen(procexe->cwd);
+@@ -2394,10 +2414,10 @@ static int sigar_get_netif_ipaddr(sigar_t *sigar,
+ MIB_IPADDRROW *row = &mib->table[i];
+ short type;
+
+-#ifdef SIGAR_USING_MSC6
+- type = row->unused2;
+-#else
++#if HAVE_MIB_IPADDRROW_WTYPE
+ type = row->wType;
++#else
++ type = row->unused2;
+ #endif
+ if (!(type & MIB_IPADDR_PRIMARY)) {
+ continue;
+diff --git a/tests/t_sigar_fs.c b/tests/t_sigar_fs.c
+index f298a08..7a554de 100644
+--- a/tests/t_sigar_fs.c
++++ b/tests/t_sigar_fs.c
+@@ -39,7 +39,7 @@
+ #include <stdio.h>
+ #include <string.h>
+ #include <errno.h>
+-#if defined(_WIN32)
++#if defined(MSVC)
+ #include <WinError.h>
+ #endif
+
+@@ -85,7 +85,7 @@ TEST(test_sigar_file_system_list_get) {
+ } else {
+ switch (ret) {
+ /* track the expected error code */
+-#if defined(_WIN32)
++#if defined(MSVC)
+ case ERROR_NOT_READY:
+ break;
+ #endif
+diff --git a/tests/t_sigar_proc.c b/tests/t_sigar_proc.c
+index 88a9ac7..334bae3 100644
+--- a/tests/t_sigar_proc.c
++++ b/tests/t_sigar_proc.c
+@@ -39,7 +39,7 @@
+ #include <stdio.h>
+ #include <string.h>
+ #include <errno.h>
+-#if defined(_WIN32)
++#if defined(MSVC)
+ #include <WinError.h>
+ #endif
+
+@@ -127,7 +127,7 @@ TEST(test_sigar_proc_list_get) {
+ switch (ret) {
+ case EPERM:
+ case ESRCH:
+-#if (defined(_WIN32))
++#if (defined(MSVC))
+ /* OpenProcess() may return ERROR_ACCESS_DENIED */
+ case ERROR_ACCESS_DENIED:
+ #endif
diff --git a/sources b/sources
index e69de29..3682c6b 100644
--- a/sources
+++ b/sources
@@ -0,0 +1 @@
+e862b3e9eff9a1b4274c2a639149f1ec sigar-1.6.5-833ca18.tbz2
More information about the scm-commits
mailing list