libtool-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] tests: import variables for MSVC.


From: Peter Rosin
Subject: Re: [PATCH] tests: import variables for MSVC.
Date: Fri, 24 Sep 2010 14:44:25 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100802 Thunderbird/3.1.2

Hi Ralf,

Den 2010-09-24 07:21 skrev Ralf Wildenhues:
> * Peter Rosin wrote on Fri, Sep 24, 2010 at 12:25:14AM CEST:
>> Subject: [PATCH] tests: import variables for MSVC.
>>
>> * tests/depdemo/sysdep.h (EXTERN): New define, saying how to
>> declare variables that might need to be imported.
>> * tests/depdemo/l1/l1.h, tests/depdemo/l2/l2.h,
>> tests/depdemo/l3/l3.h, tests/depdemo/l4/l4.h: Use it.
>> * tests/demo/foo.h (EXTERN): New define, saying how to declare
>> variables that might need to be imported. Use it.
>> * tests/pdemo/foo.h (EXTERN) [MSVC]: Make MSVC import variables
>> if needed.
> 
> Patch is ok with me if it keeps GCC working, and Chuck is ok with it.
> You meant to use __declspec everywhere not declspec, even in your text
> part of the mail, right?

Yes indeed, I intended __declspec.  I have revised the patch so that it
handles "building" correctly (dllexport for dlls, not for static) and
"using" the best way possible (still dllimports from from both dlls and
static libs).  For Cygwin I removed some dead code in tests/pdemo,
similar code was deleted from tests/demo back in 2002 (see commit
45d16ee8bf4559d6b976bfd4d6482767f16eac95).  I have verified that the
Cygwin related cleanup does not affect the Cygwin testsuite results.

With this patch, the old testsuite SKIPs cdemo-undef and tagdemo-undef,
FAILs demo-deplibs(1) and all the rest PASS (on MSYS/MSVC).  So it is
looking really nice.

====================================
1 of 104 tests failed
(2 tests were not run)
See ./test-suite.log
Please report to bug-libtool_gnu.org
====================================

(1) http://lists.gnu.org/archive/html/automake/2010-09/msg00063.html

> A documentation addition describing the most general case of annotations
> (multiple libraries, mixed static/shared, full MSVC + everything else
> support) plus simplifications for common cases,
> - no MSVC,
> - no shared/static mixing,
> - rely on auto-import,
> - ...
> 
> would be good to have.  Something from which I can deduce that your
> patch must be correct.

That documentation would be nice, yes, and I plan to write something about
that eventually.  Is it a prerequisite for pushing this?

> Of course, if libtool can somehow help with this any more, so much the
> better.  But I'm less optimistic on this than I was those five years
> ago.  :-/

Yes, and with auto-import in place for gnu tools on w32, the itch is gone
for a whole bunch of people.

> Also, may I remind you that you promised a number of testsuite additions
> before the release.

I have been digging in the archives for quite a bit, but I'm only finding
http://lists.gnu.org/archive/html/libtool-patches/2010-09/msg00266.html

What else have I promised?

Cheers,
Peter



>From d51a0c0fe3a77fb186aa331088414b4a9304e333 Mon Sep 17 00:00:00 2001
From: Peter Rosin <address@hidden>
Date: Fri, 24 Sep 2010 14:38:21 +0200
Subject: [PATCH] tests: clean up importing and exporting on w32.

Makes the touched tests pass for MSVC when DLLs are built.

* tests/demo/Makefile.am, tests/pdemo/Makefile.am: Define
BUILDING_LIBHELLO when building libhello.la.
* tests/demo/foo.h, tests/pdemo/foo.h (nothing) <MSVC>: Export
variable when building the libhello dll and import when using
libhello.  For non-MSVC and when building a static libhello, leave
as an ordinary extern.
* tests/pdemo/foo.h [Cygwin]: Remove unneeded and "dead" export
and import logic (LIBFOO_DLL is always undefined).
* tests/pdemo/longer_file_name_foo.c,
tests/pdemo/longer_file_name_foo2.c (_LIBFOO_COMPILATION_): Not
useful before, even less so now.  Removed.
* tests/depdemo/l1/Makefile.am: Define BUILDING_LIBL1 when
building libl1.la.
* tests/depdemo/l2/Makefile.am: Define BUILDING_LIBL2 when
building libl2.la.
* tests/depdemo/l3/Makefile.am: Define BUILDING_LIBL3 when
building libl3.la.
* tests/depdemo/l4/Makefile.am: Define BUILDING_LIBL4 when
building libl4.la.
* tests/depdemo/l1/l1.h, tests/depdemo/l2/l2.h,
tests/depdemo/l3/l3.h, tests/depdemo/l4/l4.h <MSVC>: Export
variables when building the associated library dll and import
when using the library.  For non-MSVC and when building static
libraries, leave as an ordinary extern.

Signed-off-by: Peter Rosin <address@hidden>
---
 ChangeLog                           |   29 +++++++++++++++++++++++++++++
 tests/demo/Makefile.am              |    3 ++-
 tests/demo/foo.h                    |   15 ++++++++++++++-
 tests/depdemo/l1/Makefile.am        |    4 ++--
 tests/depdemo/l1/l1.h               |   17 +++++++++++++++--
 tests/depdemo/l2/Makefile.am        |    4 ++--
 tests/depdemo/l2/l2.h               |   17 +++++++++++++++--
 tests/depdemo/l3/Makefile.am        |    4 ++--
 tests/depdemo/l3/l3.h               |   17 +++++++++++++++--
 tests/depdemo/l4/Makefile.am        |    4 ++--
 tests/depdemo/l4/l4.h               |   17 +++++++++++++++--
 tests/pdemo/Makefile.am             |    3 ++-
 tests/pdemo/foo.h                   |   27 +++++++++++----------------
 tests/pdemo/longer_file_name_foo.c  |    4 +---
 tests/pdemo/longer_file_name_foo2.c |    4 +---
 15 files changed, 128 insertions(+), 41 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b5f183d..d4aba21 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+2010-09-24  Peter Rosin  <address@hidden>
+
+       tests: clean up importing and exporting on w32.
+       Makes the touched tests pass for MSVC when DLLs are built.
+       * tests/demo/Makefile.am, tests/pdemo/Makefile.am: Define
+       BUILDING_LIBHELLO when building libhello.la.
+       * tests/demo/foo.h, tests/pdemo/foo.h (nothing) <MSVC>: Export
+       variable when building the libhello dll and import when using
+       libhello.  For non-MSVC and when building a static libhello, leave
+       as an ordinary extern.
+       * tests/pdemo/foo.h [Cygwin]: Remove unneeded and "dead" export
+       and import logic (LIBFOO_DLL is always undefined).
+       * tests/pdemo/longer_file_name_foo.c,
+       tests/pdemo/longer_file_name_foo2.c (_LIBFOO_COMPILATION_): Not
+       useful before, even less so now.  Removed.
+       * tests/depdemo/l1/Makefile.am: Define BUILDING_LIBL1 when
+       building libl1.la.
+       * tests/depdemo/l2/Makefile.am: Define BUILDING_LIBL2 when
+       building libl2.la.
+       * tests/depdemo/l3/Makefile.am: Define BUILDING_LIBL3 when
+       building libl3.la.
+       * tests/depdemo/l4/Makefile.am: Define BUILDING_LIBL4 when
+       building libl4.la.
+       * tests/depdemo/l1/l1.h, tests/depdemo/l2/l2.h,
+       tests/depdemo/l3/l3.h, tests/depdemo/l4/l4.h <MSVC>: Export
+       variables when building the associated library dll and import
+       when using the library.  For non-MSVC and when building static
+       libraries, leave as an ordinary extern.
+
 2010-09-23  Peter Rosin  <address@hidden>
 
        msvc: don't try to export import descriptors.
diff --git a/tests/demo/Makefile.am b/tests/demo/Makefile.am
index 2aa2c0b..a3c6144 100644
--- a/tests/demo/Makefile.am
+++ b/tests/demo/Makefile.am
@@ -1,6 +1,6 @@
 ## Makefile.am -- Process this file with automake to produce Makefile.in
 ##
-##   Copyright (C) 2003, 2004, 2005 Free Software Foundation
+##   Copyright (C) 2003, 2004, 2005, 2010 Free Software Foundation
 ##   Written by Gary V. Vaughan, 2003
 ##
 ##   This file is part of GNU Libtool.
@@ -31,6 +31,7 @@ lib_LTLIBRARIES = libhello.la
 libhello_la_SOURCES = hello.c foo.c
 libhello_la_LIBADD = $(LIBM)
 libhello_la_LDFLAGS = -no-undefined -version-info 3:12:1
+libhello_la_AM_CPPFLAGS = $(AM_CPPFLAGS) -DBUILDING_LIBHELLO
 
 include_HEADERS = foo.h
 
diff --git a/tests/demo/foo.h b/tests/demo/foo.h
index 167096a..605dc97 100644
--- a/tests/demo/foo.h
+++ b/tests/demo/foo.h
@@ -37,6 +37,19 @@ or obtained by writing to the Free Software Foundation, Inc.,
 #  endif
 #endif
 
+#ifdef _MSC_VER
+# ifdef BUILDING_LIBHELLO
+#  ifdef DLL_EXPORT
+#   define LIBHELLO_SCOPE extern __declspec (dllexport)
+#  endif
+# else
+#  define LIBHELLO_SCOPE extern __declspec (dllimport)
+# endif
+#endif
+#ifndef LIBHELLO_SCOPE
+# define LIBHELLO_SCOPE extern
+#endif
+
 /* __BEGIN_DECLS should be used at the beginning of your declarations,
    so that C++ compilers don't mangle their names.  Use __END_DECLS at
    the end of C declarations. */
@@ -83,7 +96,7 @@ or obtained by writing to the Free Software Foundation, Inc.,
 __BEGIN_DECLS
 int foo LT_PARAMS((void));
 int hello LT_PARAMS((void));
-extern int nothing;
+LIBHELLO_SCOPE int nothing;
 __END_DECLS
 
 #endif /* !_FOO_H_ */
diff --git a/tests/depdemo/l1/Makefile.am b/tests/depdemo/l1/Makefile.am
index 7cca5c1..b2e7cb8 100644
--- a/tests/depdemo/l1/Makefile.am
+++ b/tests/depdemo/l1/Makefile.am
@@ -1,6 +1,6 @@
 ## Makefile.am -- Process this file with automake to produce Makefile.in
 ##
-##   Copyright (C) 2003 Free Software Foundation
+##   Copyright (C) 2003, 2010 Free Software Foundation
 ##   Written by Gary V. Vaughan, 2003
 ##
 ##   This file is part of GNU Libtool.
@@ -26,7 +26,7 @@ top_distdir = ../..
 
 AUTOMAKE_OPTIONS = no-dependencies foreign
 
-AM_CPPFLAGS = -I$(top_srcdir)
+AM_CPPFLAGS = -I$(top_srcdir) -DBUILDING_LIBL1
 
 lib_LTLIBRARIES = libl1.la
 libl1_la_SOURCES = l1.c l1.h
diff --git a/tests/depdemo/l1/l1.h b/tests/depdemo/l1/l1.h
index 8e773ca..df266b7 100644
--- a/tests/depdemo/l1/l1.h
+++ b/tests/depdemo/l1/l1.h
@@ -1,7 +1,7 @@
 /* l1.h -- interface to a trivial library
 
    Copyright (C) 1998-1999 Thomas Tanner
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2010 Free Software Foundation, Inc.
    Written by Thomas Tanner, 1998
 
    This file is part of GNU Libtool.
@@ -29,8 +29,21 @@ or obtained by writing to the Free Software Foundation, Inc.,
 
 #include "sysdep.h"
 
+#ifdef _MSC_VER
+# ifdef BUILDING_LIBL1
+#  ifdef DLL_EXPORT
+#   define LIBL1_SCOPE extern __declspec (dllexport)
+#  endif
+# else
+#  define LIBL1_SCOPE extern __declspec (dllimport)
+# endif
+#endif
+#ifndef LIBL1_SCOPE
+# define LIBL1_SCOPE extern
+#endif
+
 __BEGIN_DECLS
-extern int var_l1;
+LIBL1_SCOPE int var_l1;
 int    func_l1 __P((int));
 __END_DECLS
 
diff --git a/tests/depdemo/l2/Makefile.am b/tests/depdemo/l2/Makefile.am
index ddd57e2..2cb86c5 100644
--- a/tests/depdemo/l2/Makefile.am
+++ b/tests/depdemo/l2/Makefile.am
@@ -1,6 +1,6 @@
 ## Makefile.am -- Process this file with automake to produce Makefile.in
 ##
-##   Copyright (C) 2003 Free Software Foundation
+##   Copyright (C) 2003, 2010 Free Software Foundation
 ##   Written by Gary V. Vaughan, 2003
 ##
 ##   This file is part of GNU Libtool.
@@ -26,7 +26,7 @@ top_distdir = ../..
 
 AUTOMAKE_OPTIONS = no-dependencies foreign
 
-AM_CPPFLAGS = -I$(top_srcdir)
+AM_CPPFLAGS = -I$(top_srcdir) -DBUILDING_LIBL2
 
 lib_LTLIBRARIES = libl2.la
 libl2_la_SOURCES = l2.c l2.h
diff --git a/tests/depdemo/l2/l2.h b/tests/depdemo/l2/l2.h
index 728b1df..2cb0360 100644
--- a/tests/depdemo/l2/l2.h
+++ b/tests/depdemo/l2/l2.h
@@ -1,7 +1,7 @@
 /* l2.h -- interface to a trivial library
 
    Copyright (C) 1998-1999 Thomas Tanner
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2010 Free Software Foundation, Inc.
    Written by Thomas Tanner, 1998
 
    This file is part of GNU Libtool.
@@ -29,8 +29,21 @@ or obtained by writing to the Free Software Foundation, Inc.,
 
 #include "sysdep.h"
 
+#ifdef _MSC_VER
+# ifdef BUILDING_LIBL2
+#  ifdef DLL_EXPORT
+#   define LIBL2_SCOPE extern __declspec (dllexport)
+#  endif
+# else
+#  define LIBL2_SCOPE extern __declspec (dllimport)
+# endif
+#endif
+#ifndef LIBL2_SCOPE
+# define LIBL2_SCOPE extern
+#endif
+
 __BEGIN_DECLS
-extern int var_l2;
+LIBL2_SCOPE int var_l2;
 int    func_l2 __P((int));
 __END_DECLS
 
diff --git a/tests/depdemo/l3/Makefile.am b/tests/depdemo/l3/Makefile.am
index 2dc0805..341932f 100644
--- a/tests/depdemo/l3/Makefile.am
+++ b/tests/depdemo/l3/Makefile.am
@@ -1,6 +1,6 @@
 ## Makefile.am -- Process this file with automake to produce Makefile.in
 ##
-##   Copyright (C) 2003 Free Software Foundation
+##   Copyright (C) 2003, 2010 Free Software Foundation
 ##   Written by Gary V. Vaughan, 2003
 ##
 ##   This file is part of GNU Libtool.
@@ -27,7 +27,7 @@ extradir    = $(libdir)/extra
 
 AUTOMAKE_OPTIONS = no-dependencies foreign
 
-AM_CPPFLAGS = -I$(top_srcdir)
+AM_CPPFLAGS = -I$(top_srcdir) -DBUILDING_LIBL3
 
 lib_LTLIBRARIES = libl3.la
 libl3_la_SOURCES = l3.c l3.h
diff --git a/tests/depdemo/l3/l3.h b/tests/depdemo/l3/l3.h
index 6f0b446..4458397 100644
--- a/tests/depdemo/l3/l3.h
+++ b/tests/depdemo/l3/l3.h
@@ -1,7 +1,7 @@
 /* l3.h -- interface to a trivial library
 
    Copyright (C) 1998-1999 Thomas Tanner
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2010 Free Software Foundation, Inc.
    Written by Thomas Tanner, 1998
 
    This file is part of GNU Libtool.
@@ -29,8 +29,21 @@ or obtained by writing to the Free Software Foundation, Inc.,
 
 #include "sysdep.h"
 
+#ifdef _MSC_VER
+# ifdef BUILDING_LIBL3
+#  ifdef DLL_EXPORT
+#   define LIBL3_SCOPE extern __declspec (dllexport)
+#  endif
+# else
+#  define LIBL3_SCOPE extern __declspec (dllimport)
+# endif
+#endif
+#ifndef LIBL3_SCOPE
+# define LIBL3_SCOPE extern
+#endif
+
 __BEGIN_DECLS
-extern int var_l3;
+LIBL3_SCOPE int var_l3;
 int    func_l3 __P((int));
 __END_DECLS
 
diff --git a/tests/depdemo/l4/Makefile.am b/tests/depdemo/l4/Makefile.am
index d274b6d..fa0d4b2 100644
--- a/tests/depdemo/l4/Makefile.am
+++ b/tests/depdemo/l4/Makefile.am
@@ -1,6 +1,6 @@
 ## Makefile.am -- Process this file with automake to produce Makefile.in
 ##
-##   Copyright (C) 2003 Free Software Foundation
+##   Copyright (C) 2003, 2010 Free Software Foundation
 ##   Written by Gary V. Vaughan, 2003
 ##
 ##   This file is part of GNU Libtool.
@@ -26,7 +26,7 @@ top_distdir = ../..
 
 AUTOMAKE_OPTIONS = no-dependencies foreign
 
-AM_CPPFLAGS = -I$(top_srcdir)
+AM_CPPFLAGS = -I$(top_srcdir) -DBUILDING_LIBL4
 
 lib_LTLIBRARIES = libl4.la
 libl4_la_SOURCES = l4.c l4.h
diff --git a/tests/depdemo/l4/l4.h b/tests/depdemo/l4/l4.h
index bdf21d0..12d47b9 100644
--- a/tests/depdemo/l4/l4.h
+++ b/tests/depdemo/l4/l4.h
@@ -1,7 +1,7 @@
 /* l4.h -- interface to a trivial library
 
    Copyright (C) 1998-1999 Thomas Tanner
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2010 Free Software Foundation, Inc.
    Written by Thomas Tanner, 1998
 
    This file is part of GNU Libtool.
@@ -29,8 +29,21 @@ or obtained by writing to the Free Software Foundation, Inc.,
 
 #include "sysdep.h"
 
+#ifdef _MSC_VER
+# ifdef BUILDING_LIBL4
+#  ifdef DLL_EXPORT
+#   define LIBL4_SCOPE extern __declspec (dllexport)
+#  endif
+# else
+#  define LIBL4_SCOPE extern __declspec (dllimport)
+# endif
+#endif
+#ifndef LIBL4_SCOPE
+# define LIBL4_SCOPE extern
+#endif
+
 __BEGIN_DECLS
-extern int var_l4;
+LIBL4_SCOPE int var_l4;
 int    func_l4 __P((int));
 __END_DECLS
 
diff --git a/tests/pdemo/Makefile.am b/tests/pdemo/Makefile.am
index 0357e47..91fe1e2 100644
--- a/tests/pdemo/Makefile.am
+++ b/tests/pdemo/Makefile.am
@@ -1,6 +1,6 @@
 ## Makefile.am -- Process this file with automake to produce Makefile.in
 ##
-##   Copyright (C) 2003, 2004, 2005 Free Software Foundation
+##   Copyright (C) 2003, 2004, 2005, 2010 Free Software Foundation
 ##   Written by Gary V. Vaughan, 2003
 ##
 ##   This file is part of GNU Libtool.
@@ -31,6 +31,7 @@ lib_LTLIBRARIES = libhello.la
 libhello_la_SOURCES = longer_file_name_hello.c longer_file_name_foo.c 
longer_file_name_foo2.c
 libhello_la_LIBADD = $(LIBM)
 libhello_la_LDFLAGS = -no-undefined -version-info 3:12:1
+libhello_la_AM_CPPFLAGS = $(AM_CPPFLAGS) -DBUILDING_LIBHELLO
 
 include_HEADERS = foo.h
 
diff --git a/tests/pdemo/foo.h b/tests/pdemo/foo.h
index a2b2a4a..59ad838 100644
--- a/tests/pdemo/foo.h
+++ b/tests/pdemo/foo.h
@@ -73,22 +73,17 @@ or obtained by writing to the Free Software Foundation, 
Inc.,
 # define LT_DLSYM_CONST const
 #endif
 
-#ifdef __CYGWIN32__
-#  ifdef LIBFOO_DLL
-     /* need some (as yet non-existant) automake magic to tell
-      * the object whether the libfoo it will be linked with is
-      * a dll or not, ie whether LIBFOO_DLL is defined or not.
-      */
-#    ifdef _LIBFOO_COMPILATION_
-#      define EXTERN __declspec(dllexport)
-#    else
-#      define EXTERN extern __declspec(dllimport)
-#    endif
-#  else
-#    define EXTERN extern
+#ifdef _MSC_VER
+# ifdef BUILDING_LIBHELLO
+#  ifdef DLL_EXPORT
+#   define LIBHELLO_SCOPE extern __declspec (dllexport)
 #  endif
-#else
-#  define EXTERN extern
+# else
+#  define LIBHELLO_SCOPE extern __declspec (dllimport)
+# endif
+#endif
+#ifndef LIBHELLO_SCOPE
+# define LIBHELLO_SCOPE extern
 #endif
 
 /* Silly constants that the functions return. */
@@ -101,7 +96,7 @@ __BEGIN_DECLS
 int foo LT_PARAMS((void));
 int foo2 LT_PARAMS((void));
 int hello LT_PARAMS((void));
-EXTERN int nothing;
+LIBHELLO_SCOPE int nothing;
 __END_DECLS
 
 #endif /* !_FOO_H_ */
diff --git a/tests/pdemo/longer_file_name_foo.c 
b/tests/pdemo/longer_file_name_foo.c
index 5b10c61..9d92304 100644
--- a/tests/pdemo/longer_file_name_foo.c
+++ b/tests/pdemo/longer_file_name_foo.c
@@ -1,6 +1,6 @@
 /* foo.c -- trivial test function for libfoo
 
-   Copyright (C) 1996-1999, 2007 Free Software Foundation, Inc.
+   Copyright (C) 1996-1999, 2007, 2010 Free Software Foundation, Inc.
    Written by Gordon Matzigkeit, 1996
 
    This file is part of GNU Libtool.
@@ -22,9 +22,7 @@ or obtained by writing to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
 
-#define _LIBFOO_COMPILATION_
 #include "foo.h"
-#undef _LIBFOO_COMPILATION_
 
 #include <stdio.h>
 #include <math.h>
diff --git a/tests/pdemo/longer_file_name_foo2.c 
b/tests/pdemo/longer_file_name_foo2.c
index c7359d0..65d3bba 100644
--- a/tests/pdemo/longer_file_name_foo2.c
+++ b/tests/pdemo/longer_file_name_foo2.c
@@ -1,6 +1,6 @@
 /* foo.c -- trivial test function for libfoo
 
-   Copyright (C) 1996-1999, 2007 Free Software Foundation, Inc.
+   Copyright (C) 1996-1999, 2007, 2010 Free Software Foundation, Inc.
    Written by Gordon Matzigkeit, 1996
 
    This file is part of GNU Libtool.
@@ -22,9 +22,7 @@ or obtained by writing to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
 
-#define _LIBFOO_COMPILATION_
 #include "foo.h"
-#undef _LIBFOO_COMPILATION_
 
 #include <stdio.h>
 #include <math.h>
-- 
1.7.1



reply via email to

[Prev in Thread] Current Thread [Next in Thread]