Skip to content
Browse files

added support for mingw32

  • Loading branch information...
1 parent d440d4f commit f854a40a932614cae319196d3ff8f11d71e294e7 Aliaksey Kandratsenka committed Mar 9, 2011
View
8 configure.ac
@@ -3,6 +3,7 @@ AC_INIT(libsigar, 1.6.2)
AC_CONFIG_SRCDIR(src/sigar.c)
dnl AC_CONFIG_HEADERS(src/config.h)
AM_INIT_AUTOMAKE([foreign])
+LT_INIT([win32-dll])
AC_CANONICAL_HOST
dnl for sigar_version_autoconf.c.in
@@ -17,14 +18,19 @@ AC_SUBST(VERSION_MAINT)
AC_SUBST(VERSION_BUILD)
AC_PROG_CC
+AC_PROG_CXX
AC_PROG_LN_S
AC_PROG_INSTALL
AC_PROG_MAKE_SET
-AC_PROG_LIBTOOL
AC_MSG_CHECKING([for os type ($host_os)])
FRAMEWORK=
case $host_os in
+ *mingw*)
+ SRC_OS="win32"
+ SIGAR_INCLUDES="-DSIGAR_SHARED -D_WIN32_WINNT=0x0501"
+ SIGAR_LIBS="-lws2_32 -lnetapi32 -lversion"
+ ;;
*aix*)
SRC_OS="aix"
AC_DEFINE(SIGAR_TEST_OS_AIX, [1], [for the tests])
View
2 examples/Makefile.am
@@ -1,5 +1,3 @@
-LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
-
INCLUDES = @INCLUDES@
noinst_PROGRAMS = cpuinfo sigar_ps
View
2 examples/cpuinfo.c
@@ -30,7 +30,7 @@ int main(int argc, char **argv) {
if (status != SIGAR_OK) {
printf("cpu_list error: %d (%s)\n",
status, sigar_strerror(sigar, status));
- exit(1);
+ return 1;
}
for (i=0; i<cpulist.number; i++) {
View
2 examples/sigar_ps.c
@@ -30,7 +30,7 @@ int main(int argc, char **argv) {
if (status != SIGAR_OK) {
printf("proc_list error: %d (%s)\n",
status, sigar_strerror(sigar, status));
- exit(1);
+ return 1;
}
for (i=0; i<proclist.number; i++) {
View
2 include/sigar.h
@@ -91,7 +91,7 @@ typedef long long sigar_int64_t;
# define SIGAR_ENXIO ENXIO
#endif
-#ifdef WIN32
+#if defined(WIN32) && !defined(NO_DLLEXPORT)
# define SIGAR_DECLARE(type) \
__declspec(dllexport) type __stdcall
#else
View
2 src/Makefile.am
@@ -4,7 +4,7 @@ INCLUDES = @INCLUDES@
lib_LTLIBRARIES = libsigar.la
-libsigar_la_LDFLAGS = $(SIGAR_LIBS)
+libsigar_la_LDFLAGS = $(SIGAR_LIBS) -no-undefined
libsigar_la_LIBADD = $(top_builddir)/src/os/@SRC_OS@/libsigar_os.la
View
33 src/os/win32/Makefile.am
@@ -1,8 +1,33 @@
-EXTRA_DIST=\
+WIN32_EXTRA_DIST=\
build-cpu.bat \
counter_names.txt \
- peb.c \
sigar.rc.in \
+ wmi.cpp
+
+SIGAR_OS_SRCS=\
+ peb.c \
+ wmi_stubs.c \
+ win32_sigar.c
+
+SIGAR_OS_HDRS=\
sigar_os.h \
- sigar_pdh.h \
- win32_sigar.c
+ sigar_pdh.h
+
+INCLUDES = @INCLUDES@
+
+if OS_WIN32
+noinst_LTLIBRARIES = libsigar_os.la
+
+libsigar_os_la_SOURCES = ${SIGAR_OS_SRCS}
+
+noinst_HEADERS = ${SIGAR_OS_HDRS}
+
+EXTRA_DIST=${WIN32_EXTRA_DIST}
+
+else
+
+EXTRA_DIST=\
+ ${SIGAR_OS_SRCS} \
+ ${SIGAR_OS_HDRS} \
+ ${WIN32_EXTRA_DIST}
+endif
View
15 src/os/win32/sigar_os.h
@@ -19,15 +19,17 @@
#ifndef SIGAR_OS_H
#define SIGAR_OS_H
+#ifndef __GNUC__
#if _MSC_VER <= 1200
#define SIGAR_USING_MSC6 /* Visual Studio version 6 */
#endif
+#endif
#define WIN32_LEAN_AND_MEAN
+#include <winsock2.h>
#include <windows.h>
#include <winreg.h>
#include <winperf.h>
-#include <winsock2.h>
#include <ws2tcpip.h>
#include <stddef.h>
#include <sys/types.h>
@@ -36,12 +38,19 @@
#include <errno.h>
#include <tlhelp32.h>
+#include <iptypes.h>
+#include <iphlpapi.h>
+
#include "sigar_util.h"
#define INT64_C(val) val##i64
+#ifndef __GNUC__
/* see apr/include/arch/win32/atime.h */
#define EPOCH_DELTA INT64_C(11644473600000000)
+#else
+#define EPOCH_DELTA 11644473600000000LL
+#endif
#define SIGAR_CMDLINE_MAX 4096
@@ -460,8 +469,8 @@ typedef BOOL (CALLBACK *mpr_get_net_connection)(LPCTSTR,
#define SIGAR_DLLFUNC(api, name) \
struct { \
const char *name; \
- ##api##_##name func; \
- } ##name
+ api##_##name func; \
+ } name
typedef struct {
sigar_dll_handle_t handle;
View
20 src/os/win32/win32_sigar.c
@@ -237,7 +237,7 @@ static PERF_OBJECT_TYPE *get_perf_object_inst(sigar_t *sigar,
static int get_mem_counters(sigar_t *sigar, sigar_swap_t *swap, sigar_mem_t *mem)
{
- int status;
+ DWORD status;
PERF_OBJECT_TYPE *object =
get_perf_object_inst(sigar, PERF_TITLE_MEM_KEY, 0, &status);
PERF_INSTANCE_DEFINITION *inst;
@@ -375,13 +375,13 @@ static sigar_mpr_t sigar_mpr = {
};
#define DLLMOD_COPY(name) \
- memcpy(&(sigar->##name), &sigar_##name, sizeof(sigar_##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)
+ sigar_dllmod_init(sigar, (sigar_dll_module_t *)&(sigar->name), all)
#define DLLMOD_FREE(name) \
- sigar_dllmod_free((sigar_dll_module_t *)&(sigar->##name))
+ sigar_dllmod_free((sigar_dll_module_t *)&(sigar->name))
static void sigar_dllmod_free(sigar_dll_module_t *module)
{
@@ -1005,7 +1005,7 @@ SIGAR_DECLARE(int) sigar_cpu_list_get(sigar_t *sigar,
SIGAR_DECLARE(int) sigar_uptime_get(sigar_t *sigar,
sigar_uptime_t *uptime)
{
- int status;
+ DWORD status;
PERF_OBJECT_TYPE *object =
get_perf_object_inst(sigar, PERF_TITLE_SYS_KEY, 0, &status);
PERF_INSTANCE_DEFINITION *inst;
@@ -1274,7 +1274,7 @@ SIGAR_DECLARE(int) sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
}
#define FILETIME2MSEC(ft) \
- NS100_2MSEC(((ft.dwHighDateTime << 32) | ft.dwLowDateTime))
+ NS100_2MSEC((((long long)ft.dwHighDateTime << 32) | ft.dwLowDateTime))
sigar_int64_t sigar_time_now_millis(void)
{
@@ -1348,7 +1348,7 @@ SIGAR_DECLARE(int) sigar_proc_state_get(sigar_t *sigar, sigar_pid_t pid,
return SIGAR_OK;
}
-static int get_proc_info(sigar_t *sigar, sigar_pid_t pid)
+int get_proc_info(sigar_t *sigar, sigar_pid_t pid)
{
PERF_OBJECT_TYPE *object;
PERF_INSTANCE_DEFINITION *inst;
@@ -1492,7 +1492,7 @@ static int sigar_proc_env_parse(UCHAR *ptr, sigar_proc_env_t *procenv,
int multi)
{
while (*ptr) {
- char *val;
+ UCHAR *val;
int klen, vlen, status;
char key[128]; /* XXX is there a max key size? */
@@ -2637,11 +2637,11 @@ static int get_mib_ifrow(sigar_t *sigar,
return SIGAR_OK;
}
-static int netif_hash(char *s)
+int netif_hash(char *s)
{
int hash = 0;
while (*s) {
- hash = 31*hash + *s++;
+ hash = 31*hash + *s++;
}
return hash;
}
View
19 src/os/win32/wmi_stubs.c
@@ -0,0 +1,19 @@
+#include "sigar.h"
+#include "sigar_private.h"
+#include "sigar_pdh.h"
+#include "sigar_os.h"
+#include "sigar_util.h"
+#include "sigar_format.h"
+
+int sigar_proc_args_wmi_get(sigar_t *sigar, sigar_pid_t pid,
+ sigar_proc_args_t *procargs)
+{
+ return ERROR_NOT_FOUND;
+}
+
+int sigar_proc_exe_wmi_get(sigar_t *sigar, sigar_pid_t pid,
+ sigar_proc_exe_t *procexe)
+{
+ return ERROR_NOT_FOUND;
+}
+
View
4 src/sigar_fileinfo.c
@@ -415,8 +415,8 @@ static int fileattrs_get(sigar_t *sigar,
if (handle != INVALID_HANDLE_VALUE) {
if (GetFileInformationByHandle(handle, &info)) {
fileattrs->inode =
- info.nFileIndexLow |
- (info.nFileIndexHigh << 32);
+ (long long)info.nFileIndexLow |
+ ((long long)info.nFileIndexHigh << 32);
fileattrs->device = info.dwVolumeSerialNumber;
fileattrs->nlink = info.nNumberOfLinks;
}

0 comments on commit f854a40

Please sign in to comment.
Something went wrong with that request. Please try again.