From: Juho Vähä-Herttua Date: Tue, 13 Mar 2012 20:24:21 +0000 (+0200) Subject: Add some really ugly scons scripts to compile libraries X-Git-Tag: upstream/0.9.0~4^2~115 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=112f0c66cddc65ce07a4eb4ef7bb75c62b108d25;p=deb_shairplay.git Add some really ugly scons scripts to compile libraries --- diff --git a/.gitignore b/.gitignore index c9c2803..24b7486 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,10 @@ *.swp project.xcworkspace xcuserdata + +# SCons specific +build +.sconf_temp +.sconsign.dblite +config.log + diff --git a/SConstruct b/SConstruct new file mode 100644 index 0000000..6de24c8 --- /dev/null +++ b/SConstruct @@ -0,0 +1,62 @@ + +AddOption('--force-mingw32', + action='store_true', dest='mingw32', default=False, + help='Cross compile using MinGW for Windows') + +AddOption('--force-mingw64', + action='store_true', dest='mingw64', default=False, + help='Cross compile using MinGW for Windows 64-bit') + +AddOption('--force-32bit', + action='store_true', dest='gcc32', default=False, + help='Always compile using 32-bit compiler flags') + +AddOption('--force-64bit', + action='store_true', dest='gcc64', default=False, + help='Always compile using 64-bit compiler flags') + +AddOption('--build-universal', + action='store_true', dest='universal', default=False, + help='Create Mac 32-bit and 64-bit universal binaries') + +VariantDir('build', 'src') +env = Environment() + +if env['PLATFORM'] == 'win32' or GetOption('mingw32') or GetOption('mingw64'): + env.Append(CPPDEFINES = ['WINVER=0x0501']) + +if GetOption('mingw32'): + env.Tool('crossmingw', toolpath = ['scons-tools']) + +if GetOption('mingw64'): + env.Tool('crossmingw64', toolpath = ['scons-tools']) + +if GetOption('gcc32'): + env.Append(CFLAGS = ['-m32']) + env.Append(CPPFLAGS = ['-m32']) + env.Append(CXXFLAGS = ['-m32']) + env.Append(LINKFLAGS = ['-m32']) + +if GetOption('gcc64'): + env.Append(CFLAGS = ['-m64']) + env.Append(CPPFLAGS = ['-m64']) + env.Append(CXXFLAGS = ['-m64']) + env.Append(LINKFLAGS = ['-m64']) + +env.Append(CFLAGS = ['-Wall', '-Werror', '-O2']) + +conf = Configure(env) +conf.CheckLib('socket') +if conf.CheckFunc('getaddrinfo'): + env.Append(CPPDEFINES = ['HAVE_GETADDRINFO']) +else: + if conf.CheckLibWithHeader('ws2_32', 'ws2tcpip.h','c','getaddrinfo(0,0,0,0);'): + env.Append(CPPDEFINES = ['HAVE_GETADDRINFO']) + else: + if conf.CheckLib('ws2_32'): + # We have windows socket lib without getaddrinfo, disable IPv6 + env.Append(CPPDEFINES = ['DISABLE_IPV6']) +env = conf.Finish() + +env.SConscript('build/SConscript', exports='env') + diff --git a/scons-tools/crossmingw.py b/scons-tools/crossmingw.py new file mode 100644 index 0000000..f52bd15 --- /dev/null +++ b/scons-tools/crossmingw.py @@ -0,0 +1,179 @@ +"""SCons.Tool.gcc + +Tool-specific initialization for MinGW (http://www.mingw.org/) + +There normally shouldn't be any need to import this module directly. +It will usually be imported through the generic SCons.Tool.Tool() +selection method. + +""" + +# +# Copyright (c) 2001, 2002, 2003, 2004 The SCons Foundation +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "/home/scons/scons/branch.0/branch.96/baseline/src/engine/SCons/Tool/mingw.py 0.96.90.D001 2005/02/15 20:11:37 knight" + +import os +import os.path +import string + +import SCons.Action +import SCons.Builder +import SCons.Tool +import SCons.Util + +# This is what we search for to find mingw: +prefixes = SCons.Util.Split(""" + mingw32- + mingw32msvc- + i386-mingw32- + i486-mingw32- + i586-mingw32- + i686-mingw32- + i386-mingw32msvc- + i486-mingw32msvc- + i586-mingw32msvc- + i686-mingw32msvc- +""") + +def find(env): + for prefix in prefixes: + # First search in the SCons path and then the OS path: + if env.WhereIs(prefix + 'gcc') or SCons.Util.WhereIs(prefix + 'gcc'): + return prefix + + return '' + +def shlib_generator(target, source, env, for_signature): + cmd = SCons.Util.CLVar(['$SHLINK', '$SHLINKFLAGS']) + + dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX') + if dll: cmd.extend(['-o', dll]) + + cmd.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS']) + + implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX') + if implib: cmd.append('-Wl,--out-implib,'+implib.get_string(for_signature)) + + def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX') + if def_target: cmd.append('-Wl,--output-def,'+def_target.get_string(for_signature)) + + return [cmd] + +def shlib_emitter(target, source, env): + dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX') + no_import_lib = env.get('no_import_lib', 0) + + if not dll: + raise SCons.Errors.UserError, "A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX") + + if not no_import_lib and \ + not env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX'): + + # Append an import library to the list of targets. + target.append(env.ReplaceIxes(dll, + 'SHLIBPREFIX', 'SHLIBSUFFIX', + 'LIBPREFIX', 'LIBSUFFIX')) + + # Append a def file target if there isn't already a def file target + # or a def file source. There is no option to disable def file + # target emitting, because I can't figure out why someone would ever + # want to turn it off. + def_source = env.FindIxes(source, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX') + def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX') + if not def_source and not def_target: + target.append(env.ReplaceIxes(dll, + 'SHLIBPREFIX', 'SHLIBSUFFIX', + 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')) + + return (target, source) + + +shlib_action = SCons.Action.Action(shlib_generator, generator=1) + +res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR') + +res_builder = SCons.Builder.Builder(action=res_action, suffix='.o', + source_scanner=SCons.Tool.SourceFileScanner) +SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan) + +def generate(env): + mingw_prefix = find(env) + + if mingw_prefix: + dir = os.path.dirname(env.WhereIs(mingw_prefix + 'gcc') or SCons.Util.WhereIs(mingw_prefix + 'gcc')) + + # The mingw bin directory must be added to the path: + path = env['ENV'].get('PATH', []) + if not path: + path = [] + if SCons.Util.is_String(path): + path = string.split(path, os.pathsep) + + env['ENV']['PATH'] = string.join([dir] + path, os.pathsep) + + # Most of mingw is the same as gcc and friends... + gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas'] + for tool in gnu_tools: + SCons.Tool.Tool(tool)(env) + + #... but a few things differ: + env['CC'] = mingw_prefix + 'gcc' + env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS') + env['CPP'] = mingw_prefix + 'g++' + env['CXX'] = mingw_prefix + 'g++' + env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS') + env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared') + env['SHLINKCOM'] = shlib_action + env.Append(SHLIBEMITTER = [shlib_emitter]) + env['LINK_CC'] = mingw_prefix + 'gcc' + env['LINK_CXX'] = mingw_prefix + 'g++' + env['AS'] = mingw_prefix + 'as' + env['AR'] = mingw_prefix + 'ar' + env['RANLIB'] = mingw_prefix + 'ranlib' + env['WIN32DEFPREFIX'] = '' + env['WIN32DEFSUFFIX'] = '.def' + env['SHOBJSUFFIX'] = '.o' + env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1 + + env['RC'] = mingw_prefix + 'windres' + env['RCFLAGS'] = SCons.Util.CLVar('') + env['RCCOM'] = '$RC $_CPPDEFFLAGS $_CPPINCFLAGS ${INCPREFIX}${SOURCE.dir} $RCFLAGS -i $SOURCE -o $TARGET' + env['BUILDERS']['RES'] = res_builder + + # Some setting from the platform also have to be overridden: + env['OBJPREFIX'] = '' + env['OBJSUFFIX'] = '.o' + env['SHOBJPREFIX'] = '$OBJPREFIX' + env['SHOBJSUFFIX'] = '$OBJSUFFIX' + env['PROGPREFIX'] = '' + env['PROGSUFFIX'] = '.exe' + env['LIBPREFIX'] = '' + env['LIBSUFFIX'] = '.lib' + env['SHLIBPREFIX'] = '' + env['SHLIBSUFFIX'] = '.dll' + env['LIBPREFIXES'] = [ '$LIBPREFIX' ] + env['LIBSUFFIXES'] = [ '$LIBSUFFIX' ] + +def exists(env): + return find(env) diff --git a/scons-tools/crossmingw64.py b/scons-tools/crossmingw64.py new file mode 100644 index 0000000..20518be --- /dev/null +++ b/scons-tools/crossmingw64.py @@ -0,0 +1,171 @@ +"""SCons.Tool.gcc + +Tool-specific initialization for MinGW (http://www.mingw.org/) + +There normally shouldn't be any need to import this module directly. +It will usually be imported through the generic SCons.Tool.Tool() +selection method. + +""" + +# +# Copyright (c) 2001, 2002, 2003, 2004 The SCons Foundation +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "/home/scons/scons/branch.0/branch.96/baseline/src/engine/SCons/Tool/mingw.py 0.96.90.D001 2005/02/15 20:11:37 knight" + +import os +import os.path +import string + +import SCons.Action +import SCons.Builder +import SCons.Tool +import SCons.Util + +# This is what we search for to find mingw: +prefixes = SCons.Util.Split(""" + amd64-mingw32- + amd64-mingw32msvc- +""") + +def find(env): + for prefix in prefixes: + # First search in the SCons path and then the OS path: + if env.WhereIs(prefix + 'gcc') or SCons.Util.WhereIs(prefix + 'gcc'): + return prefix + + return '' + +def shlib_generator(target, source, env, for_signature): + cmd = SCons.Util.CLVar(['$SHLINK', '$SHLINKFLAGS']) + + dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX') + if dll: cmd.extend(['-o', dll]) + + cmd.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS']) + + implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX') + if implib: cmd.append('-Wl,--out-implib,'+implib.get_string(for_signature)) + + def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX') + if def_target: cmd.append('-Wl,--output-def,'+def_target.get_string(for_signature)) + + return [cmd] + +def shlib_emitter(target, source, env): + dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX') + no_import_lib = env.get('no_import_lib', 0) + + if not dll: + raise SCons.Errors.UserError, "A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX") + + if not no_import_lib and \ + not env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX'): + + # Append an import library to the list of targets. + target.append(env.ReplaceIxes(dll, + 'SHLIBPREFIX', 'SHLIBSUFFIX', + 'LIBPREFIX', 'LIBSUFFIX')) + + # Append a def file target if there isn't already a def file target + # or a def file source. There is no option to disable def file + # target emitting, because I can't figure out why someone would ever + # want to turn it off. + def_source = env.FindIxes(source, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX') + def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX') + if not def_source and not def_target: + target.append(env.ReplaceIxes(dll, + 'SHLIBPREFIX', 'SHLIBSUFFIX', + 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')) + + return (target, source) + + +shlib_action = SCons.Action.Action(shlib_generator, generator=1) + +res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR') + +res_builder = SCons.Builder.Builder(action=res_action, suffix='.o', + source_scanner=SCons.Tool.SourceFileScanner) +SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan) + +def generate(env): + mingw_prefix = find(env) + + if mingw_prefix: + dir = os.path.dirname(env.WhereIs(mingw_prefix + 'gcc') or SCons.Util.WhereIs(mingw_prefix + 'gcc')) + + # The mingw bin directory must be added to the path: + path = env['ENV'].get('PATH', []) + if not path: + path = [] + if SCons.Util.is_String(path): + path = string.split(path, os.pathsep) + + env['ENV']['PATH'] = string.join([dir] + path, os.pathsep) + + # Most of mingw is the same as gcc and friends... + gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas'] + for tool in gnu_tools: + SCons.Tool.Tool(tool)(env) + + #... but a few things differ: + env['CC'] = mingw_prefix + 'gcc' + env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS') + env['CPP'] = mingw_prefix + 'g++' + env['CXX'] = mingw_prefix + 'g++' + env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS') + env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared') + env['SHLINKCOM'] = shlib_action + env.Append(SHLIBEMITTER = [shlib_emitter]) + env['LINK_CC'] = mingw_prefix + 'gcc' + env['LINK_CXX'] = mingw_prefix + 'g++' + env['AS'] = mingw_prefix + 'as' + env['AR'] = mingw_prefix + 'ar' + env['RANLIB'] = mingw_prefix + 'ranlib' + env['WIN32DEFPREFIX'] = '' + env['WIN32DEFSUFFIX'] = '.def' + env['SHOBJSUFFIX'] = '.o' + env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1 + + env['RC'] = mingw_prefix + 'windres' + env['RCFLAGS'] = SCons.Util.CLVar('') + env['RCCOM'] = '$RC $_CPPDEFFLAGS $_CPPINCFLAGS ${INCPREFIX}${SOURCE.dir} $RCFLAGS -i $SOURCE -o $TARGET' + env['BUILDERS']['RES'] = res_builder + + # Some setting from the platform also have to be overridden: + env['OBJPREFIX'] = '' + env['OBJSUFFIX'] = '.o' + env['SHOBJPREFIX'] = '$OBJPREFIX' + env['SHOBJSUFFIX'] = '$OBJSUFFIX' + env['PROGPREFIX'] = '' + env['PROGSUFFIX'] = '.exe' + env['LIBPREFIX'] = '' + env['LIBSUFFIX'] = '.lib' + env['SHLIBPREFIX'] = '' + env['SHLIBSUFFIX'] = '.dll' + env['LIBPREFIXES'] = [ '$LIBPREFIX' ] + env['LIBSUFFIXES'] = [ '$LIBSUFFIX' ] + +def exists(env): + return find(env) diff --git a/src/SConscript b/src/SConscript new file mode 100644 index 0000000..c563498 --- /dev/null +++ b/src/SConscript @@ -0,0 +1,58 @@ +Import('env') + +files = [Glob('lib/*.c'),Glob('lib/alac/*.c'),Glob('lib/crypto/*.c')] + +env.Append(CPPPATH = ['include']) + +# Set up the environment for compiling the libraries +libenv = env.Clone() +libenv.Append(CPPPATH = ['lib']) + +# Make sure libraries are compiled with DLL_EXPORT on windows +if libenv['PLATFORM'] == 'win32' or GetOption('mingw32') or GetOption('mingw64'): + libenv.Append(CPPDEFINES = ['DLL_EXPORT']) + +# Prepare the libobj and shlibobj object files +libobj = libenv.Object(files) +if libenv['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME']: + shlibobj = libobj +else: + shlibobj = libenv.SharedObject(files) + +# Compile the static library into lib directory and shared library +# for the bindings +if not libenv['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME']: + libenv.Library('airplay', libobj, install=False) +libenv.SharedLibrary('airplay', shlibobj, install=False) + +# If we want to create universal binaries of the dynamic library on Mac, do it here +if GetOption('universal'): + libenv["ENV"]["MACOSX_DEPLOYMENT_TARGET"] = "10.4" + libenv.Append(CFLAGS = ['-arch', 'i386', '-arch', 'x86_64']) + libenv32 = libenv.Clone() + libenv64 = libenv.Clone() + + libenv32.Append(LINKFLAGS = ['-undefined', 'dynamic_lookup']) + libenv32.Append(LINKFLAGS = ['-arch', 'i386']) + libenv32.Append(LINKFLAGS = ['-install_name', 'libairplay32.dylib']) + libenv32.SharedLibrary('airplay32', shlibobj, install=False) + + libenv64.Append(LINKFLAGS = ['-undefined', 'dynamic_lookup']) + libenv64.Append(LINKFLAGS = ['-arch', 'x86_64']) + libenv64.Append(LINKFLAGS = ['-install_name', 'libairplay64.dylib']) + libenv64.SharedLibrary('airplay64', shlibobj, install=False) + + libenv.Append(LINKFLAGS = ['-undefined', 'dynamic_lookup']) + libenv.Append(LINKFLAGS = ['-arch', 'i386', '-arch', 'x86_64']) + libenv.Append(LINKFLAGS = ['-install_name', 'libairplay.dylib']) + +# Set up the environment for compiling the examples +appenv = env.Clone() +conf = Configure(appenv) +conf.CheckLib('pthread') +appenv = conf.Finish() +appenv.Append(LIBPATH = ['.']) +appenv.Prepend(LIBS = ['airplay']) + +exampleobj = appenv.Object(['test/example.c']) +appenv.Program('example', exampleobj, install=False)