Autotools: Implement symbols visibility control

* Use symbol file under Win32 with MinGW only
* Use unified visibility control for other platforms
* Add recommended win32-dll option to LT_INIT macro

Closes: https://github.com/erikd/libsndfile/issues/213
This commit is contained in:
evpobr 2017-04-26 12:20:44 +05:00 committed by Erik de Castro Lopo
parent 54dc330215
commit 5c6129fce6
7 changed files with 22 additions and 473 deletions

2
.gitignore vendored
View File

@ -104,7 +104,7 @@ src/config.h
src/config.h.in
src/config.h.in~
src/libsndfile.so*
src/libsndfile-1.def
src/libsndfile-*.def
src/sndfile.h
src/stamp-h1
src/test_endswap.c

View File

@ -331,15 +331,19 @@ if (BUILD_SHARED_LIBS)
set (SNDFILE_SHARED_TARGET sndfile-shared)
if (WIN32)
set (VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR})
set (PACKAGE_NAME ${CPACK_PACKAGE_NAME})
set (GEN_TOOL cmake)
file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/src/version-metadata.rc")
configure_file(src/version-metadata.rc.in.cmake src/version-metadata.rc)
file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/src/${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.def")
configure_file (src/libsndfile.def.in.cmake src/${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.def)
file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/src/${PACKAGE_NAME}.def")
configure_file (src/libsndfile.def.in src/${PACKAGE_NAME}.def @ONLY)
list (APPEND libsndfile_SOURCES
src/version-metadata.rc
src/${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.def)
src/${PACKAGE_NAME}-${VERSION_MAJOR}.def)
endif (WIN32)
add_library(${SNDFILE_SHARED_TARGET} SHARED ${libsndfile_SOURCES})

View File

@ -31,7 +31,7 @@ MN_GCC_REALLY_IS_GCC
AC_PROG_SED
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
LT_INIT
LT_INIT([win32-dll])
LT_PROG_RC
AC_PROG_INSTALL
@ -58,9 +58,11 @@ AC_CHECK_PROG(HAVE_XCODE_SELECT, xcode-select, yes, no)
# to 0.
CLEAN_VERSION=`echo $PACKAGE_VERSION | $SED "s/p.*//"`
VERSION_MAJOR=`echo $PACKAGE_VERSION | $SED "s/\..*//"`
VERSION_MINOR=`echo $CLEAN_VERSION | $SED "s/.*\.//"`
GEN_TOOL="autoconf"
SHARED_VERSION_INFO="1:$VERSION_MINOR:0"
SHARED_VERSION_INFO="$VERSION_MAJOR:$VERSION_MINOR:0"
#------------------------------------------------------------------------------------
@ -540,26 +542,13 @@ if test x$ac_cv_c_compiler_gnu = xyes ; then
# OS specific tweaks.
case "$host_os" in
darwin* | rhapsody*)
# Disable -Wall, -pedantic and -Wshadow for Apple Darwin/Rhapsody.
# System headers on these systems are broken.
temp_CFLAGS=`echo $CFLAGS | $SED "s/-Wall -pedantic//" | $SED "s/-Wshadow//" | $SED "s/-Waggregate-return//"`
CFLAGS=$temp_CFLAGS
SHLIB_VERSION_ARG="-Wl,-exported_symbols_list -Wl,\$(srcdir)/Symbols.darwin"
;;
linux*|kfreebsd*-gnu*|gnu*)
SHLIB_VERSION_ARG="-Wl,--version-script=\$(srcdir)/Symbols.gnu-binutils"
;;
mingw*)
SHLIB_VERSION_ARG="-Wc,-static-libgcc -Wl,\$(srcdir)/libsndfile-1.def"
SHLIB_VERSION_ARG="-Wc,-static-libgcc -Wl,\$(srcdir)/libsndfile.def"
win32_target_dll=1
if test x"$enable_shared" = xno ; then
win32_target_dll=0
fi
;;
os2*)
SHLIB_VERSION_ARG="-Wl,-export-symbols \$(srcdir)/Symbols.os2"
;;
*)
;;
esac
@ -618,6 +607,9 @@ AC_SUBST(HTML_FGCOLOUR)
AC_SUBST(SHLIB_VERSION_ARG)
AC_SUBST(SHARED_VERSION_INFO)
AC_SUBST(CLEAN_VERSION)
AC_SUBST(VERSION_MAJOR)
AC_SUBST(GEN_TOOL)
AC_SUBST(WIN_RC_VERSION)
AC_SUBST(HAVE_EXTERNAL_XIPH_LIBS)
@ -637,7 +629,7 @@ AC_CONFIG_FILES([ \
Makefile \
src/version-metadata.rc tests/test_wrapper.sh tests/pedantic-header-test.sh \
doc/libsndfile.css Scripts/build-test-tarball.mk libsndfile.spec sndfile.pc \
src/sndfile.h \
src/sndfile.h src/libsndfile.def \
echo-install-dirs
])
AC_OUTPUT

View File

@ -8,14 +8,14 @@ nodist_include_HEADERS = sndfile.h
noinst_LTLIBRARIES = GSM610/libgsm.la G72x/libg72x.la ALAC/libalac.la libcommon.la
SYMBOL_FILES = Symbols.gnu-binutils Symbols.darwin libsndfile-1.def Symbols.os2 Symbols.static
SYMBOL_FILES = libsndfile.def
EXTRA_DIST = sndfile.h.in config.h.in test_endswap.c test_endswap.tpl test_endswap.def \
$(SYMBOL_FILES) create_symbols_file.py binheader_writef_check.py \
$(SYMBOL_FILES) binheader_writef_check.py \
GSM610/README GSM610/COPYRIGHT GSM610/ChangeLog \
G72x/README G72x/README.original G72x/ChangeLog \
make-static-lib-hidden-privates.sh \
config.h.cmake libsndfile.def.in.cmake version-metadata.rc.in.cmake
config.h.cmake version-metadata.rc.in.cmake
noinst_HEADERS = common.h sfconfig.h sfendian.h wavlike.h sf_unistd.h ogg.h chanmap.h
@ -98,26 +98,6 @@ check :
# Need this target to force building of test programs.
checkprograms : $(check_PROGRAMS)
#======================================================================
# Generate an OS specific Symbols files. This is done when the author
# builds the distribution tarball. There should be not need for the
# end user to create these files.
Symbols.gnu-binutils: create_symbols_file.py
python $(srcdir)/create_symbols_file.py linux $(VERSION) > $@
Symbols.darwin: create_symbols_file.py
python $(srcdir)/create_symbols_file.py darwin $(VERSION) > $@
libsndfile-1.def: create_symbols_file.py
python $(srcdir)/create_symbols_file.py win32 $(VERSION) > $@
Symbols.os2: create_symbols_file.py
python $(srcdir)/create_symbols_file.py os2 $(VERSION) > $@
Symbols.static: create_symbols_file.py
python $(srcdir)/create_symbols_file.py static $(VERSION) > $@
#======================================================================
# Building windows resource files (if needed).

View File

@ -1,245 +0,0 @@
// Copyright (C) 2003-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the author nor the names of any contributors may be used
// to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
//----------------------------------------------------------------
// These are all of the public functions exported from libsndfile.
//
// Its important not to change the order they are listed in or
// the ordinal values in the second column.
typedef struct
{ const char * name ;
int ordinal ;
} SYMBOL ;
static SYMBOL all_symbols [] =
{
{ "sf_command", 1 },
{ "sf_open", 2 },
{ "sf_close", 3 },
{ "sf_seek", 4 },
{ "sf_error", 7 },
{ "sf_perror", 8 },
{ "sf_error_str", 9 },
{ "sf_error_number", 10 },
{ "sf_format_check", 11 },
{ "sf_read_raw", 16 },
{ "sf_readf_short", 17 },
{ "sf_readf_int", 18 },
{ "sf_readf_float", 19 },
{ "sf_readf_double", 20 },
{ "sf_read_short", 21 },
{ "sf_read_int", 22 },
{ "sf_read_float", 23 },
{ "sf_read_double", 24 },
{ "sf_write_raw", 32 },
{ "sf_writef_short", 33 },
{ "sf_writef_int", 34 },
{ "sf_writef_float", 35 },
{ "sf_writef_double", 36 },
{ "sf_write_short", 37 },
{ "sf_write_int", 38 },
{ "sf_write_float", 39 },
{ "sf_write_double", 40 },
{ "sf_strerror", 50 },
{ "sf_get_string", 60 },
{ "sf_set_string", 61 },
{ "sf_version_string", 68 },
{ "sf_open_fd", 70 },
{ "sf_wchar_open", 71 },
{ "sf_open_virtual", 80 },
{ "sf_write_sync", 90 },
{ "sf_set_chunk", 100 },
{ "sf_get_chunk_size", 101 },
{ "sf_get_chunk_data", 102 },
{ "sf_get_chunk_iterator", 103 },
{ "sf_next_chunk_iterator", 104 },
{ "sf_current_byterate", 110 },
{ NULL, 0 }
} ;
//-------------------------------------------------------------------------------
static void
linux_symbols (FILE * file, const char * progname, const char * version)
{ unsigned k ;
fprintf (file, "# Auto-generated by %s\n", progname) ;
fprintf (file, "libsndfile.so.%s\n", version) ;
fprintf (file, "{\n") ;
fprintf (file, " global:\n") ;
for (k = 0 ; all_symbols [k].name != NULL ; k++)
{ if (strcmp (all_symbols [k].name, "sf_wchar_open") == 0)
continue ;
fprintf (file, " %s ;\n", all_symbols [k].name) ;
} ;
fprintf (file, " local:\n") ;
fprintf (file, " * ;\n") ;
fprintf (file, "} ;\n\n") ;
} /* linux_symbols */
static void
darwin_symbols (FILE * file, const char * progname)
{ unsigned k ;
fprintf (file, "// Auto-generated by %s\n", progname) ;
for (k = 0 ; all_symbols [k].name != NULL ; k++)
{ if (strcmp (all_symbols [k].name, "sf_wchar_open") == 0)
continue ;
fprintf (file, "_%s\n", all_symbols [k].name) ;
} ;
fprintf (file, "\n") ;
} /* darwin_symbols */
static void
win32_symbols (FILE * file, const char * progname, const char * major_version, const char * libname)
{ unsigned k ;
fprintf (file, "; Auto-generated by %s\n\n", progname) ;
fprintf (file, "LIBRARY %s-%s.dll\n", libname, major_version) ;
fprintf (file, "EXPORTS\n\n") ;
for (k = 0 ; all_symbols [k].name != NULL ; k++)
fprintf (file, "%-24s @%d\n", all_symbols [k].name, all_symbols [k].ordinal) ;
fprintf (file, "\n") ;
} /* win32_symbols */
static void
os2_symbols (FILE * file, const char * progname, const char * major_version, const char * libname)
{ unsigned k ;
fprintf (file, "; Auto-generated by %s\n\n", progname) ;
fprintf (file, "LIBRARY %s%s\n", libname, major_version) ;
fprintf (file, "INITINSTANCE TERMINSTANCE\n") ;
fprintf (file, "CODE PRELOAD MOVEABLE DISCARDABLE\n") ;
fprintf (file, "DATA PRELOAD MOVEABLE MULTIPLE NONSHARED\n") ;
fprintf (file, "EXPORTS\n\n") ;
for (k = 0 ; all_symbols [k].name != NULL ; k++)
{ if (strcmp (all_symbols [k].name, "sf_wchar_open") == 0)
continue ;
fprintf (file, "_%-24s @%d\n", all_symbols [k].name, all_symbols [k].ordinal) ;
} ;
fprintf (file, "\n") ;
} /* os2_symbols */
static void
plain_symbols (FILE * file)
{ unsigned k ;
for (k = 0 ; all_symbols [k].name != NULL ; k++)
fprintf (file, "%s\n", all_symbols [k].name) ;
} /* plain_symbols */
static void
no_symbols (const char * os_name)
{ printf ("\n") ;
printf ("No known way of restricting exported symbols on '%s'.\n", os_name) ;
printf ("If you know a way, please contact the author.\n\n") ;
exit (1) ;
} /* no_symbols */
//-------------------------------------------------------------------------------
int
main (int argc, char *argv [])
{
FILE * file ;
const char *cptr, *progname, *os_name, *version ;
char major_version [256] ;
unsigned k ;
if ((cptr = strrchr (argv [0], '/')) != NULL)
progname = cptr + 1 ;
else if ((cptr = strrchr (argv [0], '\\')) != NULL)
progname = cptr + 1 ;
else
progname = argv [0] ;
if (argc != 4)
{ printf (
"\n"
"Usage : %s <target OS name> <libsndfile version> <output file>.\n"
"\n"
" Currently supported values for target OS are:\n"
" linux\n"
" darwin (ie MacOSX)\n"
" win32 (ie wintendo)\n"
" cygwin (Cygwin on wintendo)\n"
" os2 (OS/2)\n"
" plain (plain list of symbols)\n"
"\n", progname) ;
exit (1) ;
} ;
os_name = argv [1] ;
version = argv [2] ;
strncpy (major_version, argv [2], sizeof (major_version)) ;
for (k = 0 ; k < sizeof (major_version) ; k++)
if (! isdigit (major_version [k]))
{ major_version [k] = 0 ;
break ;
} ;
if ((file = fopen (argv [3], "w")) == NULL)
{ printf ("Error: Not able to open output file '%s'.\n", argv [3]) ;
exit (1) ;
}
if (strcmp (os_name, "linux") == 0 || strcmp (os_name, "gnu") == 0 || strcmp (os_name, "binutils") == 0)
linux_symbols (file, progname, version) ;
else if (strcmp (os_name, "darwin") == 0)
darwin_symbols (file, progname) ;
else if (strcmp (os_name, "win32") == 0)
win32_symbols (file, progname, major_version, "libsndfile") ;
else if (strcmp (os_name, "os2") == 0)
os2_symbols (file, progname, major_version, "sndfile") ;
else if (strcmp (os_name, "static") == 0)
plain_symbols (file) ;
else
{ no_symbols (os_name) ;
fclose (file) ;
exit (1) ;
} ;
fclose (file) ;
return 0 ;
} /* main */

View File

@ -1,182 +0,0 @@
#!/usr/bin/python
# Copyright (C) 2003-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the author nor the names of any contributors may be used
# to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import re, sys
#----------------------------------------------------------------
# These are all of the public functions exported from libsndfile.
#
# Its important not to change the order they are listed in or
# the ordinal values in the second column.
ALL_SYMBOLS = (
( "sf_command", 1 ),
( "sf_open", 2 ),
( "sf_close", 3 ),
( "sf_seek", 4 ),
( "sf_error", 7 ),
( "sf_perror", 8 ),
( "sf_error_str", 9 ),
( "sf_error_number", 10 ),
( "sf_format_check", 11 ),
( "sf_read_raw", 16 ),
( "sf_readf_short", 17 ),
( "sf_readf_int", 18 ),
( "sf_readf_float", 19 ),
( "sf_readf_double", 20 ),
( "sf_read_short", 21 ),
( "sf_read_int", 22 ),
( "sf_read_float", 23 ),
( "sf_read_double", 24 ),
( "sf_write_raw", 32 ),
( "sf_writef_short", 33 ),
( "sf_writef_int", 34 ),
( "sf_writef_float", 35 ),
( "sf_writef_double", 36 ),
( "sf_write_short", 37 ),
( "sf_write_int", 38 ),
( "sf_write_float", 39 ),
( "sf_write_double", 40 ),
( "sf_strerror", 50 ),
( "sf_get_string", 60 ),
( "sf_set_string", 61 ),
( "sf_version_string", 68 ),
( "sf_open_fd", 70 ),
( "sf_wchar_open", 71 ),
( "sf_open_virtual", 80 ),
( "sf_write_sync", 90 ),
( "sf_set_chunk", 100 ),
( "sf_get_chunk_size", 101 ),
( "sf_get_chunk_data", 102 ),
( "sf_get_chunk_iterator", 103 ),
( "sf_next_chunk_iterator", 104 ),
( "sf_current_byterate", 110 )
)
#-------------------------------------------------------------------------------
def linux_symbols (progname, version):
print ("# Auto-generated by %s\n" %progname)
print ("libsndfile.so.%s" % version)
print ("{")
print (" global:")
for name, ordinal in ALL_SYMBOLS:
if name == "sf_wchar_open":
continue
print (" %s ;" % name)
print (" local:")
print (" * ;")
print ("} ;")
sys.stdout.write ("\n")
return
def darwin_symbols (progname, version):
print ("# Auto-generated by %s\n" %progname)
for name, ordinal in ALL_SYMBOLS:
if name == "sf_wchar_open":
continue
print ("_%s" % name)
sys.stdout.write ("\n")
return
def win32_symbols (progname, version, name):
print ("; Auto-generated by %s\n" %progname)
print ("LIBRARY %s-%s.dll" % (name, re.sub ("\..*", "", version)))
print ("EXPORTS\n")
for name, ordinal in ALL_SYMBOLS:
print ("%-20s @%s" % (name, ordinal))
sys.stdout.write ("\n")
return
def os2_symbols (progname, version, name):
print ("; Auto-generated by %s\n" %progname)
print ("LIBRARY %s%s" % (name, re.sub ("\..*", "", version)))
print ("INITINSTANCE TERMINSTANCE")
print ("CODE PRELOAD MOVEABLE DISCARDABLE")
print ("DATA PRELOAD MOVEABLE MULTIPLE NONSHARED")
print ("EXPORTS\n")
for name, ordinal in ALL_SYMBOLS:
if name == "sf_wchar_open":
continue
print ("_%-20s @%s" % (name, ordinal))
sys.stdout.write ("\n")
return
def plain_symbols (progname, version, name):
for name, ordinal in ALL_SYMBOLS:
print (name)
def no_symbols (os_name):
sys.stdout.write ("\n")
print ("No known way of restricting exported symbols on '%s'." % os_name)
print ("If you know a way, please contact the author.")
sys.stdout.write ("\n")
return
#-------------------------------------------------------------------------------
progname = re.sub (".*[\\/]", "", sys.argv [0])
if len (sys.argv) != 3:
sys.stdout.write ("\n")
print ("Usage : %s <target OS name> <libsndfile version>." % progname)
sys.stdout.write ("\n")
print (" Currently supported values for target OS are:")
print (" linux")
print (" darwin (ie MacOSX)")
print (" win32 (ie wintendo)")
print (" cygwin (Cygwin on wintendo)")
print (" os2 (OS/2)")
print (" plain (plain list of symbols)")
sys.stdout.write ("\n")
sys.exit (1)
os_name = sys.argv [1]
version = re.sub ("\.[a-z0-9]+$", "", sys.argv [2])
if os_name == "linux" or os_name == "gnu" or os_name == "binutils":
linux_symbols (progname, version)
elif os_name == "darwin":
darwin_symbols (progname, version)
elif os_name == "win32":
win32_symbols (progname, version, "libsndfile")
elif os_name == "cygwin":
win32_symbols (progname, version, "cygsndfile")
elif os_name == "os2":
os2_symbols (progname, version, "sndfile")
elif os_name == "static":
plain_symbols (progname, version, "")
else:
no_symbols (os_name)
sys.exit (0)

View File

@ -1,6 +1,6 @@
; Auto-generated by cmake
; Auto-generated by @GEN_TOOL@
LIBRARY ${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.dll
LIBRARY @PACKAGE_NAME@-@VERSION_MAJOR@.dll
EXPORTS
sf_command @1