Skip to content

Commit 691e9af

Browse files
committed
Changes for compiling with mingw32
add mmap & pread functions when compiling for systems that don't provide them don't use libtoolize, stick with static libraries
1 parent 087a359 commit 691e9af

9 files changed

+218
-21
lines changed

Makefile.am

+23-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
# Makefile.am -- Process this file with automake to produce Makefile.in
2+
3+
AUTOMAKE_OPTIONS = subdir-objects
4+
25
bin_PROGRAMS = st-flash st-util
36

4-
noinst_LTLIBRARIES = libstlink.la
7+
noinst_LIBRARIES = libstlink.a
58

69
st_flash_SOURCES = flash/main.c
710
st_util_SOURCES = gdbserver/gdb-remote.c gdbserver/gdb-remote.h gdbserver/gdb-server.c
811

9-
libstlink_la_SOURCES = src/stlink-common.c src/stlink-usb.c src/stlink-sg.c src/uglylogging.c \
10-
src/stlink-common.h src/stlink-usb.h src/stlink-sg.h src/uglylogging.h
12+
CFILES = \
13+
src/stlink-common.c \
14+
src/stlink-usb.c \
15+
src/stlink-sg.c \
16+
src/uglylogging.c
17+
18+
HFILES = \
19+
src/stlink-common.h \
20+
src/stlink-usb.h \
21+
src/stlink-sg.h \
22+
src/uglylogging.h \
23+
src/mmap.h
1124

12-
libstlink_la_CPPFLAGS = -std=gnu99 -Wall -Wextra -O2
25+
libstlink_a_SOURCES = $(CFILES) $(HFILES)
1326

14-
st_flash_LDADD = libstlink.la
27+
libstlink_a_CPPFLAGS = -std=gnu99 -Wall -Wextra -O2
28+
libstlink_a_LIBADD = $(LIBOBJS)
29+
30+
st_flash_LDADD = libstlink.a
1531
st_flash_CPPFLAGS = -std=gnu99 -Wall -Wextra -O2 -I$(top_srcdir)/src
1632

17-
st_util_LDADD = libstlink.la
33+
st_util_LDADD = libstlink.a
1834
st_util_CPPFLAGS = -std=gnu99 -Wall -Wextra -O2 -I$(top_srcdir)/src
1935

2036
EXTRA_DIST = autogen.sh
37+

autogen.sh

-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,2 @@
11
#!/bin/sh
2-
if test ! "x$(which libtoolize)" = "x"; then
3-
echo "Running libtoolize"
4-
libtoolize --copy --force --automake
5-
else
6-
if test ! "x$(which gintltoolize)" = "x"; then
7-
echo "Running glibtoolize"
8-
glibtoolize --copy --force --automake
9-
fi
10-
fi
112
autoreconf --install --force --verbose

configure.ac

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# Process this file with autoconf to produce a configure script.
33

44
AC_PREREQ(2.61)
5-
AC_INIT([stlink],[0.5.0],[[email protected]])
5+
AC_INIT([stlink],[0.5.1],[[email protected]])
66
AC_CONFIG_SRCDIR([src/stlink-common.c])
7-
7+
AC_CONFIG_LIBOBJ_DIR([src])
88
AM_INIT_AUTOMAKE([1.10])
99

1010

@@ -13,9 +13,14 @@ AC_PROG_CC
1313
AC_PROG_INSTALL
1414
AC_CANONICAL_HOST
1515
AC_CANONICAL_BUILD
16-
AC_PROG_LIBTOOL
16+
AC_PROG_RANLIB
17+
#AC_PROG_LIBTOOL
1718
AM_PROG_CC_C_O
1819

20+
AC_CHECK_HEADERS(sys/mman.h)
21+
AC_CHECK_FUNCS(mmap)
22+
AC_REPLACE_FUNCS(mmap pread)
23+
1924
# Checks for libraries.
2025
PKG_CHECK_MODULES(USB, libusb-1.0 >= 1.0.0,,
2126
AC_MSG_ERROR([*** Required libusb-1.0 >= 1.0.0 not installed ***]))

src/mmap.c

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* mmap.c -- version of mmap for gold. */
2+
3+
/* Copyright 2009 Free Software Foundation, Inc.
4+
Written by Vladimir Simonov <[email protected]>.
5+
6+
This file is part of gold.
7+
8+
This program is free software; you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation; either version 3 of the License, or
11+
(at your option) any later version.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with this program; if not, write to the Free Software
20+
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21+
MA 02110-1301, USA. */
22+
23+
//#include "config.h"
24+
//#include "ansidecl.h"
25+
26+
#include <string.h>
27+
#include <sys/types.h>
28+
#ifdef HAVE_STDLIB_H
29+
#include <stdlib.h>
30+
#endif
31+
32+
#include "mmap.h"
33+
34+
extern ssize_t pread (int, void *, size_t, off_t);
35+
36+
void *
37+
mmap (void *__addr, size_t __len, int __prot,
38+
int __flags, int __fd, long long __offset)
39+
{
40+
void *ret;
41+
ssize_t count;
42+
43+
if (__addr || (__fd != -1 && (__prot & PROT_WRITE))
44+
|| (__flags & MAP_SHARED))
45+
return MAP_FAILED;
46+
47+
ret = malloc (__len);
48+
if (!ret)
49+
return MAP_FAILED;
50+
51+
if (__fd == -1)
52+
return ret;
53+
54+
count = pread (__fd, ret, __len, __offset);
55+
if ((size_t) count != __len)
56+
{
57+
free (ret);
58+
return MAP_FAILED;
59+
}
60+
61+
return ret;
62+
}
63+
64+
int
65+
munmap (void *__addr, size_t __len)
66+
{
67+
free (__addr);
68+
return 0;
69+
}

src/mmap.h

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* mmap.h -- mmap family functions prototypes for gold. */
2+
3+
/* Copyright 2009 Free Software Foundation, Inc.
4+
Written by Vladimir Simonov <[email protected]>
5+
6+
This file is part of gold.
7+
8+
This program is free software; you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation; either version 3 of the License, or
11+
(at your option) any later version.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with this program; if not, write to the Free Software
20+
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21+
MA 02110-1301, USA. */
22+
23+
#ifndef GOLD_MMAP_H
24+
#define GOLD_MMAP_H
25+
26+
#ifdef HAVE_SYS_MMAN_H
27+
28+
#include <sys/mman.h>
29+
30+
/* Some BSD systems still use MAP_ANON instead of MAP_ANONYMOUS. */
31+
32+
#ifndef MAP_ANONYMOUS
33+
# define MAP_ANONYMOUS MAP_ANON
34+
#endif
35+
36+
#else
37+
38+
#define PROT_READ 0x1
39+
#define PROT_WRITE 0x2
40+
41+
#define MAP_SHARED 0x01
42+
#define MAP_PRIVATE 0x02
43+
44+
#define MAP_ANONYMOUS 0x20
45+
46+
#define MAP_FAILED ((void *) -1)
47+
#endif /* HAVE_SYS_MMAN_H */
48+
49+
#ifndef HAVE_MMAP
50+
#ifdef __cplusplus
51+
extern "C" {
52+
#endif
53+
extern void *mmap (void *__addr, size_t __len, int __prot,
54+
int __flags, int __fd, long long __offset);
55+
extern int munmap (void *__addr, size_t __len);
56+
#ifdef __cplusplus
57+
}
58+
#endif
59+
60+
#endif /* HAVE_MMAP */
61+
62+
#endif /* GOLD_MMAP_H */

src/pread.c

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* pread.c -- version of pread for gold. */
2+
3+
/* Copyright 2006, 2007, 2009 Free Software Foundation, Inc.
4+
Written by Ian Lance Taylor <[email protected]>.
5+
6+
This file is part of gold.
7+
8+
This program is free software; you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation; either version 3 of the License, or
11+
(at your option) any later version.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with this program; if not, write to the Free Software
20+
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21+
MA 02110-1301, USA. */
22+
23+
/* This file implements pread for systems which don't have it. This
24+
file is only compiled if pread is not present on the system. This
25+
is not an exact version of pread, as it does not preserve the
26+
current file offset. */
27+
28+
//#include "config.h"
29+
30+
#include <stdio.h>
31+
#include <sys/types.h>
32+
#include <unistd.h>
33+
34+
extern ssize_t pread (int, void *, size_t, off_t);
35+
36+
ssize_t
37+
pread (int fd, void *buf, size_t count, off_t offset)
38+
{
39+
if (lseek(fd, offset, SEEK_SET) != offset)
40+
return -1;
41+
return read(fd, buf, count);
42+
}

src/stlink-common.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#include <fcntl.h>
1010
#include <sys/types.h>
1111
#include <sys/stat.h>
12-
#include <sys/mman.h>
13-
12+
#include "mmap.h"
1413

1514
#include "stlink-common.h"
1615
#include "uglylogging.h"

src/stlink-sg.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
#include <fcntl.h>
8686
#include <sys/types.h>
8787
#include <sys/stat.h>
88-
#include <sys/mman.h>
88+
#include "mmap.h"
8989

9090
#include "stlink-common.h"
9191
#include "stlink-sg.h"

src/stlink-usb.c

+12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616
#define WLOG(format, args...) ugly_log(UWARN, LOG_TAG, format, ## args)
1717
#define fatal(format, args...) ugly_log(UFATAL, LOG_TAG, format, ## args)
1818

19+
#ifndef timersub
20+
/* This is a copy from GNU C Library (GNU LGPL 2.1), sys/time.h. */
21+
# define timersub(a, b, result) \
22+
do { \
23+
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
24+
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
25+
if ((result)->tv_usec < 0) { \
26+
--(result)->tv_sec; \
27+
(result)->tv_usec += 1000000; \
28+
} \
29+
} while (0)
30+
#endif
1931

2032
enum SCSI_Generic_Direction {SG_DXFER_TO_DEV=0, SG_DXFER_FROM_DEV=0x80};
2133

0 commit comments

Comments
 (0)