Hi!

This is a repost of an old patch.  Ralf said a long time ago that I should
drop the fixes for the old testsuite, but since I'm short of problems in
the new testsuite and the old one isn't going away, I'm revisiting this.

This was first posted here as part of a much bigger patch:
http://lists.gnu.org/archive/html/libtool-patches/2005-07/msg00033.html

Ralf didn't like it here:
http://lists.gnu.org/archive/html/libtool-patches/2005-08/msg00069.html

Some words from me on the subject:
http://lists.gnu.org/archive/html/libtool-patches/2005-08/msg00076.html

I don't know how to set up the defines so that EXTERN becomes

1. "extern" when you use a static library
2. "extern" when you build a static library
3. "extern declspec(dllimport)" when you use a shared library
4. "extern declspec(dllexport)" when you build a shared library

I could fix 2 and 4, but separating 1 and 3 is not possible. Since
extern declspec(dllimport) works everywhere with MSVC I'm taking the
easy option with this patch.

Or should I add -DBUILDING_FOO to Makefile.am and variations of the below
to the code?

#ifdef _MSC_VER
# ifdef BUILDING_FOO
#  ifdef DLL_EXPORT
#   define EXTERN extern declspec(dllexport)
#  endif
# else
#  define EXTERN extern declspec(dllimport)
# endif
#endif
#ifndef EXTERN
# define EXTERN extern
#endif

Cheers,
Peter


>From 044c0e8de4c98da753e7b17d87f03c8eebe2bcbe Mon Sep 17 00:00:00 2001
From: Peter Rosin <p...@lysator.liu.se>
Date: Thu, 23 Sep 2010 22:55:04 +0200
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.

Signed-off-by: Peter Rosin <p...@lysator.liu.se>
---
 ChangeLog              |   12 ++++++++++++
 tests/demo/foo.h       |    8 +++++++-
 tests/depdemo/l1/l1.h  |    2 +-
 tests/depdemo/l2/l2.h  |    2 +-
 tests/depdemo/l3/l3.h  |    2 +-
 tests/depdemo/l4/l4.h  |    2 +-
 tests/depdemo/sysdep.h |    6 ++++++
 tests/pdemo/foo.h      |    2 ++
 8 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 647c151..af99b0c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-09-23  Peter Rosin  <p...@lysator.liu.se>
+
+       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.
+
 2010-09-22  Ralf Wildenhues  <ralf.wildenh...@gmx.de>
 
        Fix regression in command-line length computation.
diff --git a/tests/demo/foo.h b/tests/demo/foo.h
index 167096a..b0a1a47 100644
--- a/tests/demo/foo.h
+++ b/tests/demo/foo.h
@@ -37,6 +37,12 @@ or obtained by writing to the Free Software Foundation, Inc.,
 #  endif
 #endif
 
+#ifdef _MSC_VER
+# define EXTERN extern __declspec(dllimport)
+#else
+# define EXTERN 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 +89,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;
+EXTERN int nothing;
 __END_DECLS
 
 #endif /* !_FOO_H_ */
diff --git a/tests/depdemo/l1/l1.h b/tests/depdemo/l1/l1.h
index 8e773ca..47f7be0 100644
--- a/tests/depdemo/l1/l1.h
+++ b/tests/depdemo/l1/l1.h
@@ -30,7 +30,7 @@ or obtained by writing to the Free Software Foundation, Inc.,
 #include "sysdep.h"
 
 __BEGIN_DECLS
-extern int var_l1;
+EXTERN int var_l1;
 int    func_l1 __P((int));
 __END_DECLS
 
diff --git a/tests/depdemo/l2/l2.h b/tests/depdemo/l2/l2.h
index 728b1df..500049d 100644
--- a/tests/depdemo/l2/l2.h
+++ b/tests/depdemo/l2/l2.h
@@ -30,7 +30,7 @@ or obtained by writing to the Free Software Foundation, Inc.,
 #include "sysdep.h"
 
 __BEGIN_DECLS
-extern int var_l2;
+EXTERN int var_l2;
 int    func_l2 __P((int));
 __END_DECLS
 
diff --git a/tests/depdemo/l3/l3.h b/tests/depdemo/l3/l3.h
index 6f0b446..59eff6d 100644
--- a/tests/depdemo/l3/l3.h
+++ b/tests/depdemo/l3/l3.h
@@ -30,7 +30,7 @@ or obtained by writing to the Free Software Foundation, Inc.,
 #include "sysdep.h"
 
 __BEGIN_DECLS
-extern int var_l3;
+EXTERN int var_l3;
 int    func_l3 __P((int));
 __END_DECLS
 
diff --git a/tests/depdemo/l4/l4.h b/tests/depdemo/l4/l4.h
index bdf21d0..a78be74 100644
--- a/tests/depdemo/l4/l4.h
+++ b/tests/depdemo/l4/l4.h
@@ -30,7 +30,7 @@ or obtained by writing to the Free Software Foundation, Inc.,
 #include "sysdep.h"
 
 __BEGIN_DECLS
-extern int var_l4;
+EXTERN int var_l4;
 int    func_l4 __P((int));
 __END_DECLS
 
diff --git a/tests/depdemo/sysdep.h b/tests/depdemo/sysdep.h
index 4430b61..c910a70 100644
--- a/tests/depdemo/sysdep.h
+++ b/tests/depdemo/sysdep.h
@@ -50,4 +50,10 @@ or obtained by writing to the Free Software Foundation, Inc.,
 # define __P(protos) ()
 #endif
 
+#ifdef _MSC_VER
+# define EXTERN extern __declspec(dllimport)
+#else
+# define EXTERN extern
+#endif
+
 #endif /* !_SYSDEP_H_ */
diff --git a/tests/pdemo/foo.h b/tests/pdemo/foo.h
index a2b2a4a..037e95e 100644
--- a/tests/pdemo/foo.h
+++ b/tests/pdemo/foo.h
@@ -87,6 +87,8 @@ or obtained by writing to the Free Software Foundation, Inc.,
 #  else
 #    define EXTERN extern
 #  endif
+#elif defined _MSC_VER
+#  define EXTERN extern __declspec(dllimport)
 #else
 #  define EXTERN extern
 #endif
-- 
1.7.1

Reply via email to