diff options
-rw-r--r-- | ChangeLog | 22 | ||||
-rw-r--r-- | Makefile.am | 5 | ||||
-rwxr-xr-x | autogen.sh | 10 | ||||
-rw-r--r-- | configure.ac | 24 | ||||
-rw-r--r-- | gnulib-local/Makefile.am | 1 | ||||
-rw-r--r-- | gnulib-local/lib/unictype.h.diff | 13 | ||||
-rw-r--r-- | gnulib-local/lib/uninorm.h.diff | 14 | ||||
-rw-r--r-- | lib/Makefile.am | 15 | ||||
-rw-r--r-- | lib/unistring/woe32dll.in.h | 30 | ||||
-rw-r--r-- | woe32dll/export.h | 106 | ||||
-rw-r--r-- | woe32dll/unistring-exports.c | 141 |
11 files changed, 371 insertions, 10 deletions
@@ -1,5 +1,27 @@ 2008-04-19 Bruno Haible <bruno@clisp.org> + Add support for building as shared library on Cygwin and mingw. + * autogen.sh: Insert LIBUNISTRING_DLL_VARIABLE tokens into + lib/unictype.h and lib/uninorm.h. + * gnulib-local/lib/unictype.h.diff: Add an include of + <unistring/woe32dll.h>. + * gnulib-local/lib/uninorm.h.diff: New file. + * gnulib-local/Makefile.am (EXTRA_DIST): Add it. + * lib/unistring/woe32dll.in.h: New file. + * woe32dll/unistring-exports.c: New file. + * woe32dll/export.h: New file, from GNU gettext. + * Makefile.am (EXTRA_DIST): Add it. + * configure.ac (WOE32DLL): New conditional. + (DLL_VARIABLE): New substituted variable. + (AC_CONFIG_FILES): Add lib/unistring/woe32dll.h. + * lib/Makefile.am (nobase_include_HEADERS): Add unistring/woe32dll.h. + (libunistring_la_SOURCES) [WOE32DLL]: Add unistring-exports.c. + (libunistring_la_LDFLAGS) [WOE32DLL]: Add --export-all-symbols linker + flag. + (config.h): Remove unused macro DLL_VARIABLE. + +2008-04-19 Bruno Haible <bruno@clisp.org> + Don't use unreliable linker options on native Windows. * m4/woe32-dll.m4: New file, from GNU gettext. * configure.ac: Invoke gl_WOE32_DLL. diff --git a/Makefile.am b/Makefile.am index 1add17c..4730a58 100644 --- a/Makefile.am +++ b/Makefile.am @@ -29,3 +29,8 @@ EXTRA_DIST = \ # Allow users to use "gnulib-tool --update". EXTRA_DIST += gnulib-m4/gnulib-cache.m4 + + +# Cygwin support. + +EXTRA_DIST += woe32dll/export.h @@ -408,6 +408,16 @@ if test $skip_gnulib = false; then < lib/unistr.h \ > lib/unistr.h.tmp \ && mv lib/unistr.h.tmp lib/unistr.h + # Change lib/unictype.h and lib/uninorm.h for shared libraries on Woe32 systems. + sed -e 's/extern const uc_general_category_t UC_/extern LIBUNISTRING_DLL_VARIABLE const uc_general_category_t UC_/' \ + -e 's/extern const uc_property_t UC_/extern LIBUNISTRING_DLL_VARIABLE const uc_property_t UC_/' \ + < lib/unictype.h \ + > lib/unictype.h.tmp \ + && mv lib/unictype.h.tmp lib/unictype.h + sed -e 's/extern const struct unicode_normalization_form /extern LIBUNISTRING_DLL_VARIABLE const struct unicode_normalization_form /' \ + < lib/uninorm.h \ + > lib/uninorm.h.tmp \ + && mv lib/uninorm.h.tmp lib/uninorm.h $GNULIB_TOOL --copy-file build-aux/config.guess; chmod a+x build-aux/config.guess $GNULIB_TOOL --copy-file build-aux/config.sub; chmod a+x build-aux/config.sub # If we got no texinfo.tex so far, take the snapshot from gnulib. diff --git a/configure.ac b/configure.ac index 8bfd2b4..bcea482 100644 --- a/configure.ac +++ b/configure.ac @@ -57,6 +57,29 @@ dnl Checks for types, header files, functions and declarations. gl_INIT +dnl Compilation on mingw and Cygwin needs special Makefile rules, because +dnl 1. when we install a shared library, we must arrange to export +dnl auxiliary pointer variables for every exported variable, +dnl 2. when we install a shared library and a static library simultaneously, +dnl the include file specifies __declspec(dllimport) and therefore we +dnl must arrange to define the auxiliary pointer variables for the +dnl exported variables _also_ in the static library. +if test "$enable_shared" = yes; then + case "$host_os" in + mingw* | cygwin*) is_woe32dll=yes ;; + *) is_woe32dll=no ;; + esac +else + is_woe32dll=no +fi +AM_CONDITIONAL([WOE32DLL], [test $is_woe32dll = yes]) +if test $is_woe32dll = yes; then + DLL_VARIABLE='__declspec (dllimport)' +else + DLL_VARIABLE= +fi +AC_SUBST([DLL_VARIABLE]) + dnl Check for prerequisites of exported.sh. gt_GLOBAL_SYMBOL_PIPE @@ -72,5 +95,6 @@ AC_CONFIG_FILES([doc/Makefile], AC_CONFIG_FILES([gnulib-local/Makefile]) AC_CONFIG_FILES([lib/Makefile]) AC_CONFIG_FILES([lib/exported.sh]) +AC_CONFIG_FILES([lib/unistring/woe32dll.h:lib/unistring/woe32dll.in.h]) AC_CONFIG_FILES([tests/Makefile]) AC_OUTPUT diff --git a/gnulib-local/Makefile.am b/gnulib-local/Makefile.am index 025c108..42fe703 100644 --- a/gnulib-local/Makefile.am +++ b/gnulib-local/Makefile.am @@ -23,6 +23,7 @@ lib/unicase.h.diff \ lib/uniconv.h.diff \ lib/unictype.h.diff \ lib/unilbrk.h.diff \ +lib/uninorm.h.diff \ lib/unistr.h.diff \ lib/unitypes.h.diff \ lib/uniwidth.h.diff diff --git a/gnulib-local/lib/unictype.h.diff b/gnulib-local/lib/unictype.h.diff index cee4482..14347bc 100644 --- a/gnulib-local/lib/unictype.h.diff +++ b/gnulib-local/lib/unictype.h.diff @@ -1,7 +1,8 @@ -*** unictype.h.orig 2009-04-05 19:30:27.000000000 +0200 ---- unictype.h 2009-04-10 16:21:33.000000000 +0200 +*** unictype.h.orig 2009-04-05 12:15:57.000000000 +0200 +--- unictype.h 2009-04-12 04:31:36.000000000 +0200 *************** -*** 20,26 **** +*** 19,26 **** + #include "unitypes.h" /* Get bool. */ @@ -9,9 +10,13 @@ /* Get size_t. */ #include <stddef.h> ---- 20,26 ---- +--- 19,29 ---- + #include "unitypes.h" ++ /* Get LIBUNISTRING_DLL_VARIABLE. */ ++ #include <unistring/woe32dll.h> ++ /* Get bool. */ ! #include <unistring/stdbool.h> diff --git a/gnulib-local/lib/uninorm.h.diff b/gnulib-local/lib/uninorm.h.diff new file mode 100644 index 0000000..89d8995 --- /dev/null +++ b/gnulib-local/lib/uninorm.h.diff @@ -0,0 +1,14 @@ +*** uninorm.h.orig 2009-04-05 12:38:24.000000000 +0200 +--- uninorm.h 2009-04-12 04:31:52.000000000 +0200 +*************** +*** 18,23 **** +--- 18,26 ---- + #ifndef _UNINORM_H + #define _UNINORM_H + ++ /* Get LIBUNISTRING_DLL_VARIABLE. */ ++ #include <unistring/woe32dll.h> ++ + /* Get size_t. */ + #include <stddef.h> + diff --git a/lib/Makefile.am b/lib/Makefile.am index 6eaed43..463d272 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -39,7 +39,8 @@ nobase_include_HEADERS = \ unilbrk.h \ uninorm.h \ unicase.h \ - unistring/inline.h + unistring/inline.h \ + unistring/woe32dll.h noinst_HEADERS = \ unistring-notinline.h @@ -169,21 +170,23 @@ MOSTLYCLEANFILES += libunistring.sym-t MAINTAINERCLEANFILES += libunistring.sym EXTRA_DIST += libunistring.sym +# Tell the mingw or Cygwin linker which symbols to export. +if WOE32DLL +libunistring_la_SOURCES += ../woe32dll/unistring-exports.c +libunistring_la_LDFLAGS += -Wl,--export-all-symbols +endif + # Hide undesired symbols that are defined by libunistring_la_SOURCES or # libunistring_la_LIBADD from the global namespace, by prefixing them with # "libunistring_". all check install: config.h config.h: $(BUILT_SOURCES) libunistring.sym { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ - : "Avoid double inclusion, to avoid a warning about redefinition of DLL_VARIABLE."; \ + : "Avoid double inclusion, to avoid a warning about redefinitions."; \ echo '#ifndef UNISTRING_CONFIG_H'; \ echo '#define UNISTRING_CONFIG_H'; \ echo; \ echo '#include "../config.h"'; \ - : "All code is collected in a single library,"; \ - : "No references to variables in other libraries exist."; \ - echo '#undef DLL_VARIABLE'; \ - echo '#define DLL_VARIABLE'; \ echo; \ echo '#endif /* UNISTRING_CONFIG_H */'; \ } > config.h && \ diff --git a/lib/unistring/woe32dll.in.h b/lib/unistring/woe32dll.in.h new file mode 100644 index 0000000..7764c86 --- /dev/null +++ b/lib/unistring/woe32dll.in.h @@ -0,0 +1,30 @@ +/* Support for variables in shared libraries on Windows platforms. + Copyright (C) 2009 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU Lesser 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2009. */ + +#ifndef _UNISTRING_WOE32DLL_H +#define _UNISTRING_WOE32DLL_H + +#ifdef IN_LIBUNISTRING +/* All code is collected in a single library, */ +# define LIBUNISTRING_DLL_VARIABLE +#else +/* References from outside of libunistring. */ +# define LIBUNISTRING_DLL_VARIABLE @DLL_VARIABLE@ +#endif + +#endif /* _UNISTRING_WOE32DLL_H */ diff --git a/woe32dll/export.h b/woe32dll/export.h new file mode 100644 index 0000000..3e8a21f --- /dev/null +++ b/woe32dll/export.h @@ -0,0 +1,106 @@ +/* Exporting symbols from Cygwin shared libraries. + Copyright (C) 2006 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 2006. + + 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, see <http://www.gnu.org/licenses/>. */ + +/* There are four ways to build shared libraries on Cygwin: + + - Export only functions, no variables. + This has the drawback of severely affecting the programming style in use. + It does not let the programmer use full ANSI C. It lets one platform + dictate the code style on all platforms. This is unacceptable. + + - Use the GNU ld --enable-auto-import option. It is the default on Cygwin + since July 2005. But it has three fatal drawbacks: + - It produces executables and shared libraries with relocations in the + .text segment, defeating the principles of virtual memory. + - For some constructs such as + extern int var; + int * const b = &var; + it creates an executable that will give an error at runtime, rather + than either a compile-time or link-time error or a working executable. + (This is with both gcc and g++.) Whereas this code, not relying on + auto-import: + extern __declspec (dllimport) int var; + int * const b = &var; + gives a compile-time error with gcc and works with g++. + - It doesn't work in some cases (references to a member field of an + exported struct variable, or to a particular element of an exported + array variable), requiring code modifications. Again one platform + dictates code modifications on all platforms. + + This is unacceptable. Therefore we disable this option, through the + woe32-dll.m4 autoconf macro. + + - Define a macro that expands to __declspec(dllexport) when building + the library and to __declspec(dllimport) when building code outside + the library, and use it in all header files of the library. + This is acceptable if + 1. the header files are unique to this library (not shared with + other packages), and + 2. the library sources are contained in one directory, making it easy + to define a -DBUILDING_LIBXYZ flag for the library. + Example: + #ifdef BUILDING_LIBASPRINTF + #define LIBASPRINTF_DLL_EXPORTED __declspec(dllexport) + #else + #define LIBASPRINTF_DLL_EXPORTED __declspec(dllimport) + #endif + + We use this technique for the libintl and the libasprintf libraries. + + - Define a macro that expands to __declspec(dllimport) always, and use + it in all header files of the library. Use an explicit export list for + the library. + This is acceptable if + 1. the programming language is not C++ (because the name mangling of + static struct/class fields and of variables in namespaces makes it + hard to maintain an export list). + The benefit of this approach is that the partitioning of the source files + into libraries (which source file goes into which library) does not + affect the source code; only the Makefiles reflect it. + The performance loss due to the unnecessary indirection for references + to variables from within the library defining the variable is acceptable. + + We use this technique for libgettextlib (because it contains many gnulib + modules) and for libgettextsrc (because this makes it easy to move source + code from an msg* program to libgettextsrc). The macro is called + DLL_VARIABLE. + + This file allows building an explicit export list. You can either + - specify the variables to be exported, and use the GNU ld option + --export-all-symbols to export all function names, or + - specify the variables and functions to be exported explicitly. + + Note: --export-all-symbols is the default when no other symbol is explicitly + exported. This means, the use of an explicit export on the variables has + the effect of no longer exporting the functions! - until the option + --export-all-symbols is used. */ + + /* IMP(x) is a symbol that contains the address of x. */ +#define IMP(x) _imp__##x + + /* Ensure that the variable x is exported from the library, and that a + pseudo-variable IMP(x) is available. */ +#define VARIABLE(x) \ + /* Export x without redefining x. This code was found by compiling a \ + snippet: \ + extern __declspec(dllexport) int x; int x = 42; */ \ + asm (".section .drectve\n"); \ + asm (".ascii \" -export:" #x ",data\"\n"); \ + asm (".data\n"); \ + /* Allocate a pseudo-variable IMP(x). */ \ + extern int x; \ + void * IMP(x) = &x; diff --git a/woe32dll/unistring-exports.c b/woe32dll/unistring-exports.c new file mode 100644 index 0000000..d10bd7e --- /dev/null +++ b/woe32dll/unistring-exports.c @@ -0,0 +1,141 @@ +/* List of exported symbols of libunistring on Cygwin. + Copyright (C) 2006, 2009 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 2006. + + 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, see <http://www.gnu.org/licenses/>. */ + +#include "woe32dll/export.h" + +/* Variables declared in unictype.h */ +VARIABLE(UC_CATEGORY_C) +VARIABLE(UC_CATEGORY_Cc) +VARIABLE(UC_CATEGORY_Cf) +VARIABLE(UC_CATEGORY_Cn) +VARIABLE(UC_CATEGORY_Co) +VARIABLE(UC_CATEGORY_Cs) +VARIABLE(UC_CATEGORY_L) +VARIABLE(UC_CATEGORY_Ll) +VARIABLE(UC_CATEGORY_Lm) +VARIABLE(UC_CATEGORY_Lo) +VARIABLE(UC_CATEGORY_Lt) +VARIABLE(UC_CATEGORY_Lu) +VARIABLE(UC_CATEGORY_M) +VARIABLE(UC_CATEGORY_Mc) +VARIABLE(UC_CATEGORY_Me) +VARIABLE(UC_CATEGORY_Mn) +VARIABLE(UC_CATEGORY_N) +VARIABLE(UC_CATEGORY_Nd) +VARIABLE(UC_CATEGORY_Nl) +VARIABLE(UC_CATEGORY_No) +VARIABLE(UC_CATEGORY_P) +VARIABLE(UC_CATEGORY_Pc) +VARIABLE(UC_CATEGORY_Pd) +VARIABLE(UC_CATEGORY_Pe) +VARIABLE(UC_CATEGORY_Pf) +VARIABLE(UC_CATEGORY_Pi) +VARIABLE(UC_CATEGORY_Po) +VARIABLE(UC_CATEGORY_Ps) +VARIABLE(UC_CATEGORY_S) +VARIABLE(UC_CATEGORY_Sc) +VARIABLE(UC_CATEGORY_Sk) +VARIABLE(UC_CATEGORY_Sm) +VARIABLE(UC_CATEGORY_So) +VARIABLE(UC_CATEGORY_Z) +VARIABLE(UC_CATEGORY_Zl) +VARIABLE(UC_CATEGORY_Zp) +VARIABLE(UC_CATEGORY_Zs) +VARIABLE(UC_PROPERTY_ALPHABETIC) +VARIABLE(UC_PROPERTY_ASCII_HEX_DIGIT) +VARIABLE(UC_PROPERTY_BIDI_ARABIC_DIGIT) +VARIABLE(UC_PROPERTY_BIDI_ARABIC_RIGHT_TO_LEFT) +VARIABLE(UC_PROPERTY_BIDI_BLOCK_SEPARATOR) +VARIABLE(UC_PROPERTY_BIDI_BOUNDARY_NEUTRAL) +VARIABLE(UC_PROPERTY_BIDI_COMMON_SEPARATOR) +VARIABLE(UC_PROPERTY_BIDI_CONTROL) +VARIABLE(UC_PROPERTY_BIDI_EMBEDDING_OR_OVERRIDE) +VARIABLE(UC_PROPERTY_BIDI_EUROPEAN_DIGIT) +VARIABLE(UC_PROPERTY_BIDI_EUR_NUM_SEPARATOR) +VARIABLE(UC_PROPERTY_BIDI_EUR_NUM_TERMINATOR) +VARIABLE(UC_PROPERTY_BIDI_HEBREW_RIGHT_TO_LEFT) +VARIABLE(UC_PROPERTY_BIDI_LEFT_TO_RIGHT) +VARIABLE(UC_PROPERTY_BIDI_NON_SPACING_MARK) +VARIABLE(UC_PROPERTY_BIDI_OTHER_NEUTRAL) +VARIABLE(UC_PROPERTY_BIDI_PDF) +VARIABLE(UC_PROPERTY_BIDI_SEGMENT_SEPARATOR) +VARIABLE(UC_PROPERTY_BIDI_WHITESPACE) +VARIABLE(UC_PROPERTY_COMBINING) +VARIABLE(UC_PROPERTY_COMPOSITE) +VARIABLE(UC_PROPERTY_CURRENCY_SYMBOL) +VARIABLE(UC_PROPERTY_DASH) +VARIABLE(UC_PROPERTY_DECIMAL_DIGIT) +VARIABLE(UC_PROPERTY_DEFAULT_IGNORABLE_CODE_POINT) +VARIABLE(UC_PROPERTY_DEPRECATED) +VARIABLE(UC_PROPERTY_DIACRITIC) +VARIABLE(UC_PROPERTY_EXTENDER) +VARIABLE(UC_PROPERTY_FORMAT_CONTROL) +VARIABLE(UC_PROPERTY_GRAPHEME_BASE) +VARIABLE(UC_PROPERTY_GRAPHEME_EXTEND) +VARIABLE(UC_PROPERTY_GRAPHEME_LINK) +VARIABLE(UC_PROPERTY_HEX_DIGIT) +VARIABLE(UC_PROPERTY_HYPHEN) +VARIABLE(UC_PROPERTY_IDEOGRAPHIC) +VARIABLE(UC_PROPERTY_IDS_BINARY_OPERATOR) +VARIABLE(UC_PROPERTY_IDS_TRINARY_OPERATOR) +VARIABLE(UC_PROPERTY_ID_CONTINUE) +VARIABLE(UC_PROPERTY_ID_START) +VARIABLE(UC_PROPERTY_IGNORABLE_CONTROL) +VARIABLE(UC_PROPERTY_ISO_CONTROL) +VARIABLE(UC_PROPERTY_JOIN_CONTROL) +VARIABLE(UC_PROPERTY_LEFT_OF_PAIR) +VARIABLE(UC_PROPERTY_LINE_SEPARATOR) +VARIABLE(UC_PROPERTY_LOGICAL_ORDER_EXCEPTION) +VARIABLE(UC_PROPERTY_LOWERCASE) +VARIABLE(UC_PROPERTY_MATH) +VARIABLE(UC_PROPERTY_NON_BREAK) +VARIABLE(UC_PROPERTY_NOT_A_CHARACTER) +VARIABLE(UC_PROPERTY_NUMERIC) +VARIABLE(UC_PROPERTY_OTHER_ALPHABETIC) +VARIABLE(UC_PROPERTY_OTHER_DEFAULT_IGNORABLE_CODE_POINT) +VARIABLE(UC_PROPERTY_OTHER_GRAPHEME_EXTEND) +VARIABLE(UC_PROPERTY_OTHER_ID_CONTINUE) +VARIABLE(UC_PROPERTY_OTHER_ID_START) +VARIABLE(UC_PROPERTY_OTHER_LOWERCASE) +VARIABLE(UC_PROPERTY_OTHER_MATH) +VARIABLE(UC_PROPERTY_OTHER_UPPERCASE) +VARIABLE(UC_PROPERTY_PAIRED_PUNCTUATION) +VARIABLE(UC_PROPERTY_PARAGRAPH_SEPARATOR) +VARIABLE(UC_PROPERTY_PATTERN_SYNTAX) +VARIABLE(UC_PROPERTY_PATTERN_WHITE_SPACE) +VARIABLE(UC_PROPERTY_PRIVATE_USE) +VARIABLE(UC_PROPERTY_PUNCTUATION) +VARIABLE(UC_PROPERTY_QUOTATION_MARK) +VARIABLE(UC_PROPERTY_RADICAL) +VARIABLE(UC_PROPERTY_SENTENCE_TERMINAL) +VARIABLE(UC_PROPERTY_SOFT_DOTTED) +VARIABLE(UC_PROPERTY_SPACE) +VARIABLE(UC_PROPERTY_TERMINAL_PUNCTUATION) +VARIABLE(UC_PROPERTY_TITLECASE) +VARIABLE(UC_PROPERTY_UNASSIGNED_CODE_VALUE) +VARIABLE(UC_PROPERTY_UNIFIED_IDEOGRAPH) +VARIABLE(UC_PROPERTY_UPPERCASE) +VARIABLE(UC_PROPERTY_VARIATION_SELECTOR) +VARIABLE(UC_PROPERTY_WHITE_SPACE) +VARIABLE(UC_PROPERTY_XID_CONTINUE) +VARIABLE(UC_PROPERTY_XID_START) +VARIABLE(UC_PROPERTY_ZERO_WIDTH) +/* Variables declared in uninorm.h */ +VARIABLE(uninorm_nfc) +VARIABLE(uninorm_nfd) +VARIABLE(uninorm_nfkc) +VARIABLE(uninorm_nfkd) |