1#!/usr/local/bin/python3.8
2
3# Copyright (C) 2003-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
4#
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are
9# met:
10#
11#     * Redistributions of source code must retain the above copyright
12#       notice, this list of conditions and the following disclaimer.
13#     * Redistributions in binary form must reproduce the above copyright
14#       notice, this list of conditions and the following disclaimer in
15#       the documentation and/or other materials provided with the
16#       distribution.
17#     * Neither the author nor the names of any contributors may be used
18#       to endorse or promote products derived from this software without
19#       specific prior written permission.
20#
21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33import re, sys
34
35#----------------------------------------------------------------
36# These are all of the public functions exported from libsndfile.
37#
38# Its important not to change the order they are listed in or
39# the ordinal values in the second column.
40
41ALL_SYMBOLS = (
42	(	"sf_command",	 		1	),
43	(	"sf_open",				2	),
44	(	"sf_close",				3	),
45	(	"sf_seek",				4	),
46	(	"sf_error",				7	),
47	(	"sf_perror",			8	),
48	(	"sf_error_str",			9	),
49	(	"sf_error_number",		10	),
50	(	"sf_format_check",		11	),
51	(	"sf_read_raw",			16	),
52	(	"sf_readf_short",		17	),
53	(	"sf_readf_int",			18	),
54	(	"sf_readf_float",		19	),
55	(	"sf_readf_double",		20	),
56	(	"sf_read_short",		21	),
57	(	"sf_read_int",			22	),
58	(	"sf_read_float",		23	),
59	(	"sf_read_double",		24	),
60	(	"sf_write_raw",			32	),
61	(	"sf_writef_short",		33	),
62	(	"sf_writef_int",		34	),
63	(	"sf_writef_float",		35	),
64	(	"sf_writef_double",		36	),
65	(	"sf_write_short",		37	),
66	(	"sf_write_int",			38	),
67	(	"sf_write_float",		39	),
68	(	"sf_write_double",		40	),
69	(	"sf_strerror",			50	),
70	(	"sf_get_string",		60	),
71	(	"sf_set_string",		61	),
72	(	"sf_version_string",	68	),
73	(	"sf_open_fd",			70	),
74	(	"sf_wchar_open",		71  ),
75	(	"sf_open_virtual",		80	),
76	(	"sf_write_sync",		90	),
77	(	"sf_set_chunk",			100	),
78	(	"sf_get_chunk_size",	101 ),
79	(	"sf_get_chunk_data",	102 ),
80	(	"sf_get_chunk_iterator",	103 ),
81	(	"sf_next_chunk_iterator",	104 ),
82	(	"sf_current_byterate",	110 )
83	)
84
85#-------------------------------------------------------------------------------
86
87def linux_symbols (progname, version):
88	print ("# Auto-generated by %s\n" %progname)
89	print ("libsndfile.so.%s" % version)
90	print ("{")
91	print ("  global:")
92	for name, ordinal in ALL_SYMBOLS:
93		if  name == "sf_wchar_open":
94			continue
95		print ("    %s ;" % name)
96	print ("  local:")
97	print ("    * ;")
98	print ("} ;")
99	sys.stdout.write ("\n")
100	return
101
102def darwin_symbols (progname, version):
103	print ("# Auto-generated by %s\n" %progname)
104	for name, ordinal in ALL_SYMBOLS:
105		if  name == "sf_wchar_open":
106			continue
107		print ("_%s" % name)
108	sys.stdout.write ("\n")
109	return
110
111def win32_symbols (progname, version, name):
112	print ("; Auto-generated by %s\n" %progname)
113	print ("EXPORTS\n")
114	for name, ordinal in ALL_SYMBOLS:
115		print ("%-20s @%s" % (name, ordinal))
116	sys.stdout.write ("\n")
117	return
118
119def os2_symbols (progname, version, name):
120	print ("; Auto-generated by %s\n" %progname)
121	print ("LIBRARY %s%s" % (name, re.sub ("\..*", "", version)))
122	print ("INITINSTANCE TERMINSTANCE")
123	print ("CODE PRELOAD MOVEABLE DISCARDABLE")
124	print ("DATA PRELOAD MOVEABLE MULTIPLE NONSHARED")
125	print ("EXPORTS\n")
126	for name, ordinal in ALL_SYMBOLS:
127		if  name == "sf_wchar_open":
128			continue
129		print ("_%-20s @%s" % (name, ordinal))
130	sys.stdout.write ("\n")
131	return
132
133def plain_symbols (progname, version, name):
134	for name, ordinal in ALL_SYMBOLS:
135		print (name)
136
137def no_symbols (os_name):
138	sys.stdout.write ("\n")
139	print ("No known way of restricting exported symbols on '%s'." % os_name)
140	print ("If you know a way, please contact the author.")
141	sys.stdout.write ("\n")
142	return
143
144#-------------------------------------------------------------------------------
145
146progname = re.sub (".*[\\/]", "", sys.argv [0])
147
148if len (sys.argv) != 3:
149	sys.stdout.write ("\n")
150	print ("Usage : %s <target OS name> <libsndfile version>." % progname)
151	sys.stdout.write ("\n")
152	print ("    Currently supported values for target OS are:")
153	print ("          linux")
154	print ("          darwin     (ie MacOSX)")
155	print ("          win32      (ie wintendo)")
156	print ("          cygwin     (Cygwin on wintendo)")
157	print ("          os2        (OS/2)")
158	print ("          plain      (plain list of symbols)")
159	sys.stdout.write ("\n")
160	sys.exit (1)
161
162os_name = sys.argv [1]
163version = re.sub ("\.[a-z0-9]+$", "", sys.argv [2])
164
165if os_name == "linux" or os_name == "gnu" or os_name == "binutils":
166	linux_symbols (progname, version)
167elif os_name == "darwin":
168	darwin_symbols (progname, version)
169elif os_name == "win32":
170	win32_symbols (progname, version, "libsndfile")
171elif os_name == "cygwin":
172	win32_symbols (progname, version, "cygsndfile")
173elif os_name == "os2":
174	os2_symbols (progname, version, "sndfile")
175elif os_name == "static":
176	plain_symbols (progname, version, "")
177else:
178	no_symbols (os_name)
179
180sys.exit (0)
181
182