Changes for compiling with mingw32
authorDave Murphy <davem@devkitpro.org>
Sat, 28 Apr 2012 21:55:23 +0000 (22:55 +0100)
committerDave Murphy <davem@devkitpro.org>
Sat, 28 Apr 2012 21:55:23 +0000 (22:55 +0100)
add mmap & pread functions when compiling for systems that don't provide them
don't use libtoolize, stick with static libraries

Makefile.am
autogen.sh
configure.ac
src/mmap.c [new file with mode: 0644]
src/mmap.h [new file with mode: 0644]
src/pread.c [new file with mode: 0644]
src/stlink-common.c
src/stlink-sg.c
src/stlink-usb.c

index 9aeec4a00f609895d748bd0a4fa063bf785ae14c..28e11d5e59a6e1589aad4b7c4bf75b194331c75a 100644 (file)
@@ -1,20 +1,37 @@
 # Makefile.am -- Process this file with automake to produce Makefile.in
+
+AUTOMAKE_OPTIONS = subdir-objects
+
 bin_PROGRAMS = st-flash st-util
 
-noinst_LTLIBRARIES      = libstlink.la
+noinst_LIBRARIES      = libstlink.a
 
 st_flash_SOURCES = flash/main.c
 st_util_SOURCES = gdbserver/gdb-remote.c gdbserver/gdb-remote.h gdbserver/gdb-server.c
 
-libstlink_la_SOURCES   =       src/stlink-common.c src/stlink-usb.c src/stlink-sg.c src/uglylogging.c \
-                               src/stlink-common.h src/stlink-usb.h src/stlink-sg.h src/uglylogging.h
+CFILES = \
+       src/stlink-common.c \
+       src/stlink-usb.c \
+       src/stlink-sg.c \
+       src/uglylogging.c
+
+HFILES = \
+       src/stlink-common.h \
+       src/stlink-usb.h \
+       src/stlink-sg.h \
+       src/uglylogging.h \
+       src/mmap.h
 
-libstlink_la_CPPFLAGS  = -std=gnu99 -Wall -Wextra -O2
+libstlink_a_SOURCES    =       $(CFILES) $(HFILES)
 
-st_flash_LDADD =       libstlink.la
+libstlink_a_CPPFLAGS   = -std=gnu99 -Wall -Wextra -O2
+libstlink_a_LIBADD = $(LIBOBJS)
+
+st_flash_LDADD =       libstlink.a
 st_flash_CPPFLAGS      = -std=gnu99 -Wall -Wextra -O2 -I$(top_srcdir)/src
 
-st_util_LDADD  =       libstlink.la
+st_util_LDADD  =       libstlink.a
 st_util_CPPFLAGS       = -std=gnu99 -Wall -Wextra -O2 -I$(top_srcdir)/src
 
 EXTRA_DIST = autogen.sh
+
index 3a76a1150d87f4a27600a235ab9c991a1167b4a1..2af5ccdac17f9f1b07fc98353d6affaac5afb308 100755 (executable)
@@ -1,11 +1,2 @@
 #!/bin/sh
-if test ! "x$(which libtoolize)" = "x"; then
-  echo "Running libtoolize"
-  libtoolize --copy --force --automake
-else
-  if test ! "x$(which gintltoolize)" = "x"; then
-    echo "Running glibtoolize"
-    glibtoolize --copy --force --automake
-  fi
-fi
 autoreconf --install --force --verbose
index fcfb37735c04c8f5d639c35e3a71db7983eef6c6..a19bba4f1a366f9d37b115352098c2e3805c1472 100644 (file)
@@ -2,9 +2,9 @@
 # Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.61)
-AC_INIT([stlink],[0.5.0],[davem@devkitpro.org])
+AC_INIT([stlink],[0.5.1],[davem@devkitpro.org])
 AC_CONFIG_SRCDIR([src/stlink-common.c])
-
+AC_CONFIG_LIBOBJ_DIR([src])
 AM_INIT_AUTOMAKE([1.10])
 
 
@@ -13,9 +13,14 @@ AC_PROG_CC
 AC_PROG_INSTALL
 AC_CANONICAL_HOST
 AC_CANONICAL_BUILD
-AC_PROG_LIBTOOL
+AC_PROG_RANLIB
+#AC_PROG_LIBTOOL
 AM_PROG_CC_C_O
 
+AC_CHECK_HEADERS(sys/mman.h)
+AC_CHECK_FUNCS(mmap)
+AC_REPLACE_FUNCS(mmap pread)
+
 # Checks for libraries.
 PKG_CHECK_MODULES(USB, libusb-1.0 >= 1.0.0,,
                  AC_MSG_ERROR([*** Required libusb-1.0 >= 1.0.0 not installed ***]))
diff --git a/src/mmap.c b/src/mmap.c
new file mode 100644 (file)
index 0000000..7316389
--- /dev/null
@@ -0,0 +1,69 @@
+/* mmap.c -- version of mmap for gold.  */
+
+/* Copyright 2009 Free Software Foundation, Inc.
+   Written by Vladimir Simonov <sv@sw.ru>.
+
+   This file is part of gold.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
+
+//#include "config.h"
+//#include "ansidecl.h"
+
+#include <string.h>
+#include <sys/types.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#include "mmap.h"
+
+extern ssize_t pread (int, void *, size_t, off_t);
+
+void *
+mmap (void *__addr, size_t __len, int __prot,
+       int __flags, int __fd, long long  __offset)
+{
+  void *ret;
+  ssize_t count;
+
+  if (__addr || (__fd != -1 && (__prot & PROT_WRITE))
+             || (__flags & MAP_SHARED))
+    return MAP_FAILED;
+
+  ret = malloc (__len);
+  if (!ret)
+    return MAP_FAILED;
+
+  if (__fd == -1)
+    return ret;
+
+  count = pread (__fd, ret, __len, __offset);
+  if ((size_t) count != __len)
+    {
+    free (ret);
+    return MAP_FAILED;
+    }
+
+  return ret;
+}
+
+int
+munmap (void *__addr, size_t __len)
+{
+  free (__addr);
+  return 0;
+}
diff --git a/src/mmap.h b/src/mmap.h
new file mode 100644 (file)
index 0000000..375eafb
--- /dev/null
@@ -0,0 +1,62 @@
+/* mmap.h -- mmap family functions prototypes for gold.  */
+
+/* Copyright 2009 Free Software Foundation, Inc.
+   Written by Vladimir Simonov <sv@sw.ru>
+
+   This file is part of gold.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
+
+#ifndef GOLD_MMAP_H
+#define GOLD_MMAP_H
+
+#ifdef HAVE_SYS_MMAN_H
+
+#include <sys/mman.h>
+
+/* Some BSD systems still use MAP_ANON instead of MAP_ANONYMOUS.  */
+
+#ifndef MAP_ANONYMOUS
+# define MAP_ANONYMOUS MAP_ANON
+#endif
+
+#else
+
+#define PROT_READ 0x1
+#define PROT_WRITE 0x2
+
+#define MAP_SHARED 0x01
+#define MAP_PRIVATE 0x02
+
+#define MAP_ANONYMOUS 0x20
+
+#define MAP_FAILED ((void *) -1)
+#endif /* HAVE_SYS_MMAN_H */
+
+#ifndef HAVE_MMAP
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern void *mmap (void *__addr, size_t __len, int __prot,
+                    int __flags, int __fd, long long __offset);
+extern int munmap (void *__addr, size_t __len);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAVE_MMAP */
+
+#endif /* GOLD_MMAP_H */
diff --git a/src/pread.c b/src/pread.c
new file mode 100644 (file)
index 0000000..4ac6115
--- /dev/null
@@ -0,0 +1,42 @@
+/* pread.c -- version of pread for gold.  */
+
+/* Copyright 2006, 2007, 2009 Free Software Foundation, Inc.
+   Written by Ian Lance Taylor <iant@google.com>.
+
+   This file is part of gold.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
+
+/* This file implements pread for systems which don't have it.  This
+   file is only compiled if pread is not present on the system.  This
+   is not an exact version of pread, as it does not preserve the
+   current file offset.  */
+
+//#include "config.h"
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+extern ssize_t pread (int, void *, size_t, off_t);
+
+ssize_t
+pread (int fd, void *buf, size_t count, off_t offset)
+{
+  if (lseek(fd, offset, SEEK_SET) != offset)
+    return -1;
+  return read(fd, buf, count);
+}
index 26b36cd24121cf8c8b77ecff059a3893f75c52f7..29640fd70222e5a1a035058e3c0b26a8a1f168f0 100644 (file)
@@ -9,8 +9,7 @@
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/mman.h>
-
+#include "mmap.h"
 
 #include "stlink-common.h"
 #include "uglylogging.h"
index 3d4a9b79882a9d3959732253b8d4dede9a82da27..4cae3ee119316a27bc61139df10179193ef0924d 100644 (file)
@@ -85,7 +85,7 @@
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/mman.h>
+#include "mmap.h"
 
 #include "stlink-common.h"
 #include "stlink-sg.h"
index 8f5c6c410c46420166f817bab8e781db8bc64d62..d945f66ecc391abf500160c9de78a507d57dcf7d 100644 (file)
 #define WLOG(format, args...)         ugly_log(UWARN, LOG_TAG, format, ## args)
 #define fatal(format, args...)        ugly_log(UFATAL, LOG_TAG, format, ## args)
 
+#ifndef timersub
+/* This is a copy from GNU C Library (GNU LGPL 2.1), sys/time.h. */
+# define timersub(a, b, result)                                               \
+  do {                                                                        \
+    (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;                             \
+    (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;                          \
+    if ((result)->tv_usec < 0) {                                              \
+      --(result)->tv_sec;                                                     \
+      (result)->tv_usec += 1000000;                                           \
+    }                                                                         \
+  } while (0)
+#endif
 
 enum SCSI_Generic_Direction {SG_DXFER_TO_DEV=0, SG_DXFER_FROM_DEV=0x80};