From 7df412ae252b133251e9033fe8c387b058705c8c Mon Sep 17 00:00:00 2001 From: pancake Date: Thu, 10 Mar 2011 11:36:16 +0100 Subject: [PATCH] * Fix build on W32 * Added --without-magic flag --- configure | 9 +++++++-- configure.acr | 2 ++ doc/windows | 4 ++-- libr/cons/cons.c | 2 +- libr/fs/p/fs_posix.c | 1 + libr/fs/p/grub/Makefile | 4 ++++ libr/fs/p/grub/kern/mm.c | 2 +- libr/io/p/Makefile | 2 +- libr/io/p/io_gdb.c | 2 +- libr/io/p/io_haret.c | 4 ---- libr/io/p/io_shm.c | 14 ++++++++++---- libr/io/p/io_w32dbg.c | 9 ++++----- libr/rules.mk | 2 +- libr/socket/socket.c | 2 ++ libr/util/sys.c | 5 +++-- mk/gcc.mk | 1 + mk/i486-mingw32-gcc.mk | 1 + mk/i586-mingw32msvc-gcc.mk | 1 + mk/tcc.mk | 1 + 19 files changed, 44 insertions(+), 24 deletions(-) diff --git a/configure b/configure index ee22d7a972..54df917ab8 100755 --- a/configure +++ b/configure @@ -20,6 +20,7 @@ trap control_c 2 DEBUGGER=1 HAVE_EWF=1 HAVE_GMP=1 +HAVE_MAGIC=1 HAVE_OPENSSL=1 [ -z "${USERCC}" ] && USERCC="gcc" [ -z "${USEROSTYPE}" ] && USEROSTYPE="auto" @@ -147,6 +148,7 @@ printf "\nOptional Features: --without-debugger disable native debugger features --without-ewf disable EWF dependency --without-gmp disable GMP dependency + --without-magic disable magic dependency --without-ssl disable openssl dependency --with-compiler Define compiler to use (see mk/) (USERCC=gcc) --with-ostype Choose OS type ( gnulinux windows darwin ) (USEROSTYPE=auto) @@ -195,7 +197,7 @@ echo "VERSION: 0.7" echo "LANGS: c" echo "REQUIRED: libdl" echo "OPTIONAL: libewf" -echo "FLAGS: --without-debugger --without-ewf --without-gmp --without-ssl --with-compiler=gcc --with-ostype=auto --without-pic --with-nonpic" +echo "FLAGS: --without-debugger --without-ewf --without-gmp --without-magic --without-ssl --with-compiler=gcc --with-ostype=auto --without-pic --with-nonpic" exit 0 ;; "--cache-file") @@ -240,6 +242,7 @@ echo "FLAGS: --without-debugger --without-ewf --without-gmp --without-ssl -- "--without-debugger") DEBUGGER="0"; ;; "--without-ewf") HAVE_EWF="0"; ;; "--without-gmp") HAVE_GMP="0"; ;; +"--without-magic") HAVE_MAGIC="0"; ;; "--without-ssl") HAVE_OPENSSL="0"; ;; --with-compiler) if [ -z "${value}" ]; then USERCC="gcc"; else USERCC="${value}" ; fi ;; --with-ostype) if [ -z "${value}" ]; then USEROSTYPE="auto"; else USEROSTYPE="${value}" ; fi ;; @@ -262,7 +265,7 @@ parse_options $1 shift done -ENVWORDS="MANDIR INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR SYSCONFDIR DATADIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU PKGNAME VPATH VERSION CONTACT CONTACT_NAME CONTACT_MAIL CC CFLAGS LDFLAGS HAVE_LANG_C DEBUGGER HAVE_LIB_DL DL_LIBS LIL_ENDIAN BIG_ENDIAN BYTEORDER HAVE_LIB_EWF HAVE_EWF HAVE_LIB_GMP HAVE_GMP HAVE_LIB_MAGIC HAVE_LIB_SSL HAVE_OPENSSL HAVE_LIB_LUA5_1 HAVE_LIB_TCC USERCC USEROSTYPE WITHPIC WITHNONPIC" +ENVWORDS="MANDIR INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR SYSCONFDIR DATADIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU PKGNAME VPATH VERSION CONTACT CONTACT_NAME CONTACT_MAIL CC CFLAGS LDFLAGS HAVE_LANG_C DEBUGGER HAVE_LIB_DL DL_LIBS LIL_ENDIAN BIG_ENDIAN BYTEORDER HAVE_LIB_EWF HAVE_EWF HAVE_LIB_GMP HAVE_GMP HAVE_LIB_MAGIC HAVE_MAGIC HAVE_LIB_SSL HAVE_OPENSSL HAVE_LIB_LUA5_1 HAVE_LIB_TCC USERCC USEROSTYPE WITHPIC WITHNONPIC" create_environ @@ -351,6 +354,8 @@ check_library HAVE_LIB_GMP gmp 0 if [ "$HAVE_GMP" = "0" ]; then HAVE_LIB_GMP="0"; fi check_library HAVE_LIB_MAGIC magic 0 +if [ "$HAVE_MAGIC" = "0" ]; then +HAVE_LIB_MAGIC="0"; fi check_library HAVE_LIB_SSL ssl 0 if [ "$HAVE_OPENSSL" = "0" ]; then HAVE_LIB_SSL="0"; fi diff --git a/configure.acr b/configure.acr index c979f79a61..53adf598b0 100644 --- a/configure.acr +++ b/configure.acr @@ -19,6 +19,8 @@ ARG_WITHOUT HAVE_GMP gmp disable GMP dependency ; IFNOT HAVE_GMP { HAVE_LIB_GMP = 0 ; } CHKLIB magic +ARG_WITHOUT HAVE_MAGIC magic disable magic dependency ; +IFNOT HAVE_MAGIC { HAVE_LIB_MAGIC = 0 ; } CHKLIB ssl ARG_WITHOUT HAVE_OPENSSL ssl disable openssl dependency ; diff --git a/doc/windows b/doc/windows index 7c3cc67af2..f5523a4e9e 100644 --- a/doc/windows +++ b/doc/windows @@ -9,7 +9,7 @@ Crosscompilation ArchLinux --------- - ./configure --without-gmp --with-compiler=i486-mingw32-gcc --with-ostype=windows --host=i486-unknown-windows + ./configure --without-gmp --with-compiler=i486-mingw32-gcc --with-ostype=windows --host=i486-unknown-windows --without-magic make make w32dist @@ -26,7 +26,7 @@ Crosscompilation Ubuntu ------ sudo apt-get install mingw32 - ./configure --without-gmp --with-compiler=i586-mingw32msvc-gcc --with-ostype=windows --host=i586-unknown-windows + ./configure --without-gmp --with-compiler=i586-mingw32msvc-gcc --with-ostype=windows --host=i586-unknown-windows --without-magic make make w32dist diff --git a/libr/cons/cons.c b/libr/cons/cons.c index 24b9b63156..f5b8399efe 100644 --- a/libr/cons/cons.c +++ b/libr/cons/cons.c @@ -291,7 +291,7 @@ R_API int r_cons_get_size(int *rows) { } #else const char *str = r_sys_getenv ("COLUMNS"); - if (str != NULL) + if (str != NULL) { I.columns = atoi (str); I.rows = 23; // XXX. windows must get console size } else { diff --git a/libr/fs/p/fs_posix.c b/libr/fs/p/fs_posix.c index cb9559128c..bae5658351 100644 --- a/libr/fs/p/fs_posix.c +++ b/libr/fs/p/fs_posix.c @@ -2,6 +2,7 @@ #include #include +#include static RFSFile* fs_posix_open(RFSRoot *root, const char *path) { FILE *fd; diff --git a/libr/fs/p/grub/Makefile b/libr/fs/p/grub/Makefile index db3d9f8c59..04e0ec741f 100644 --- a/libr/fs/p/grub/Makefile +++ b/libr/fs/p/grub/Makefile @@ -1,4 +1,7 @@ include ../../../config.mk + +CC?=i486-mingw32-gcc +RANLIB?=i486-mingw32-ranlib #CC?=gcc OSTYPE=$(shell uname -s) @@ -64,6 +67,7 @@ lib: all libgrubfs.a libgrubfs.a: ${KERNOBJS} rm -f libgrubfs.a ar -q libgrubfs.a ${KERNOBJS} + ${RANLIB} libgrubfs.a clean: rm -f ${KERNOBJS} ${BIN} main.o diff --git a/libr/fs/p/grub/kern/mm.c b/libr/fs/p/grub/kern/mm.c index af72b77ee1..3dd98e5ff0 100644 --- a/libr/fs/p/grub/kern/mm.c +++ b/libr/fs/p/grub/kern/mm.c @@ -386,7 +386,7 @@ void *grub_zalloc (grub_size_t size) { void *ret; ret = malloc(size); - bzero(ret,size); + memset (ret, 0, size); return ret; } diff --git a/libr/io/p/Makefile b/libr/io/p/Makefile index dd360e4faa..844f3a2af1 100644 --- a/libr/io/p/Makefile +++ b/libr/io/p/Makefile @@ -13,7 +13,7 @@ endif foo: all ALL_TARGETS= -PLUGINS=ptrace.mk debug.mk gdb.mk malloc.mk shm.mk mach.mk w32dbg.mk procpid.mk +PLUGINS=ptrace.mk debug.mk gdb.mk malloc.mk shm.mk mach.mk w32dbg.mk procpid.mk haret.mk #PLUGINS=ptrace.mk debug.mk gdb.mk malloc.mk mach.mk w32dbg.mk procpid.mk include ${PLUGINS} diff --git a/libr/io/p/io_gdb.c b/libr/io/p/io_gdb.c index fad2104fa1..60562734b4 100644 --- a/libr/io/p/io_gdb.c +++ b/libr/io/p/io_gdb.c @@ -40,7 +40,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { riog = R_NEW (RIOGdb); riog->fd = _fd; riog->desc = gdbwrap_init (_fd); - return r_io_desc_new (&r_io_plugin_shm, _fd, file, rw, mode, riog); + return r_io_desc_new (&r_io_plugin_gdb, _fd, file, rw, mode, riog); } static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { diff --git a/libr/io/p/io_haret.c b/libr/io/p/io_haret.c index 3f58a4ea6e..1a2b23da01 100644 --- a/libr/io/p/io_haret.c +++ b/libr/io/p/io_haret.c @@ -1,7 +1,5 @@ /* radare - LGPL - Copyright 2008-2011 pancake */ -#if __UNIX__ - #include "r_io.h" #include "r_lib.h" #include "r_socket.h" @@ -136,5 +134,3 @@ struct r_lib_struct_t radare_plugin = { .data = &r_io_plugin_haret }; #endif - -#endif diff --git a/libr/io/p/io_shm.c b/libr/io/p/io_shm.c index d1fb5221c0..b607b7d34a 100644 --- a/libr/io/p/io_shm.c +++ b/libr/io/p/io_shm.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2008-2011 pancake */ -#if __UNIX__ - #include "r_io.h" #include "r_lib.h" #include + +#if __UNIX__ #include #include @@ -117,11 +117,17 @@ struct r_io_plugin_t r_io_plugin_shm = { .write = shm__write, }; +#else +struct r_io_plugin_t r_io_plugin_shm = { + //void *plugin; + .name = "shm", + .desc = "shared memory resources (not for w32)", +}; +#endif + #ifndef CORELIB struct r_lib_struct_t radare_plugin = { .type = R_LIB_TYPE_IO, .data = &r_io_plugin_shm }; #endif - -#endif diff --git a/libr/io/p/io_w32dbg.c b/libr/io/p/io_w32dbg.c index 6de913d4d3..faa56ba20b 100644 --- a/libr/io/p/io_w32dbg.c +++ b/libr/io/p/io_w32dbg.c @@ -23,7 +23,7 @@ typedef struct { extern int errno; static int debug_os_read_at(RIOW32Dbg *dbg, void *buf, int len, ut64 addr) { - PDWORD ret; + DWORD ret; ReadProcessMemory (dbg->pi.hProcess, (PCVOID)(ULONG)addr, buf, len, &ret); // if (len != ret) // eprintf ("Cannot read 0x%08llx\n", addr); @@ -37,9 +37,9 @@ static int __read(struct r_io_t *io, RIODesc *fd, ut8 *buf, int len) { } static int w32dbg_write_at(RIODesc *fd, const ut8 *buf, int len, ut64 addr) { - PDWORD ret; + DWORD ret; RIOW32Dbg *dbg = fd->data; - WriteProcessMemory (dbg->pi.hProcess, (PCVOID)(ULONG)addr, buf, len, &ret); + WriteProcessMemory (dbg->pi.hProcess, (LPVOID)(ULONG)addr, buf, len, &ret); return (int)ret; } @@ -55,14 +55,13 @@ static int __plugin_open(struct r_io_t *io, const char *file) { static int __attach (RIOW32Dbg *dbg) { eprintf ("---> attach to %d\n", dbg->pid); - dbg->pi.hProcess = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid); + dbg->pi.hProcess = OpenProcess (PROCESS_ALL_ACCESS, FALSE, dbg->pid); if (dbg->pi.hProcess == NULL) return -1; return dbg->pid; } static RIODesc *__open(struct r_io_t *io, const char *file, int rw, int mode) { - int ret = -1; if (__plugin_open (io, file)) { RIOW32Dbg *dbg = R_NEW (RIOW32Dbg); if (dbg == NULL) diff --git a/libr/rules.mk b/libr/rules.mk index d5553cc653..1e8695cf43 100644 --- a/libr/rules.mk +++ b/libr/rules.mk @@ -39,7 +39,7 @@ ${LIBSO}: $(EXTRA_TARGETS) waitfordeps ${OBJ} test $$a -nt ${LIBSO} && do=1 ; \ if [ $$do = 1 ]; then \ echo "${CC_LIB} ${LIBNAME} ${OBJ} ${LDFLAGS} ${LINK}" ; \ - ${CC_LIB} ${LIBNAME} ${OBJ} ${LDFLAGS} ${LINK} ; \ + ${CC_LIB} ${LIBNAME} ${OBJ} ${LDFLAGS} ${LINK}; \ if [ -f "../stripsyms.sh" ]; then sh ../stripsyms.sh ${LIBSO} ${NAME} ; fi ; \ break ; \ fi ; done diff --git a/libr/socket/socket.c b/libr/socket/socket.c index dcc8ce179d..6a08940cc2 100644 --- a/libr/socket/socket.c +++ b/libr/socket/socket.c @@ -199,7 +199,9 @@ R_API int r_socket_listen(int port) { close (s); return -1; } +#if __UNIX_ signal (SIGPIPE, SIG_IGN); +#endif if (listen (s, 1) < 0) { close (s); return -1; diff --git a/libr/util/sys.c b/libr/util/sys.c index 900f05e33f..ff0e8f7014 100644 --- a/libr/util/sys.c +++ b/libr/util/sys.c @@ -1,5 +1,7 @@ -/* radare - LGPL - Copyright 2009-2010 pancake */ +/* radare - LGPL - Copyright 2009-2011 pancake */ +#include +#include #include #include #if __UNIX__ @@ -13,7 +15,6 @@ #elif __WINDOWS__ #include #endif -#include /* TODO: import stuff fron bininfo/p/bininfo_addr2line */ /* TODO: check endianness issues here */ diff --git a/mk/gcc.mk b/mk/gcc.mk index bc994ec7f7..34f05d57b8 100644 --- a/mk/gcc.mk +++ b/mk/gcc.mk @@ -1,5 +1,6 @@ CC?=gcc LINK= +RANLIB=ranlib ONELIB=0 CC_AR=ar qf ${LIBAR} PIC_CFLAGS=-fPIC diff --git a/mk/i486-mingw32-gcc.mk b/mk/i486-mingw32-gcc.mk index 5820c8b05b..7d93c8ba77 100644 --- a/mk/i486-mingw32-gcc.mk +++ b/mk/i486-mingw32-gcc.mk @@ -1,4 +1,5 @@ CC=i486-mingw32-gcc +RANLIB=i486-mingw32-ranlib OSTYPE=windows ONELIB=0 LINK=-shared diff --git a/mk/i586-mingw32msvc-gcc.mk b/mk/i586-mingw32msvc-gcc.mk index 8975896c6b..a8297e72ee 100644 --- a/mk/i586-mingw32msvc-gcc.mk +++ b/mk/i586-mingw32msvc-gcc.mk @@ -1,4 +1,5 @@ CC=i586-mingw32msvc-gcc +RANLIB=i586-mingw32msvc-gcc ONELIB=0 OSTYPE=windows LINK= diff --git a/mk/tcc.mk b/mk/tcc.mk index ba32c00457..2e55b1218c 100644 --- a/mk/tcc.mk +++ b/mk/tcc.mk @@ -1,4 +1,5 @@ CC=tcc +RANLIB=ranlib LINK= ONELIB=0 CC_AR=ar -r ${LIBAR}