Chris@39: import os.path, sys
Chris@39: 
Chris@39: def _PackageOption(pkgName, default=1):
Chris@39:     """ Allow user to choose whether a package should be used if available. This results in a commandline option use<Pkgname>,
Chris@39:     where Pkgname is the name of the package with a capitalized first letter.
Chris@39:     @param pkgName: Name of package.
Chris@39:     @param default: The default value for this option ("yes"/"no").
Chris@39:     """
Chris@39:     return BoolOption("use%s" % pkgName[0].upper() + pkgName[1:], "use %s if available" % (pkgName), default)
Chris@39: 
Chris@39: def _BoolOption(opt, explanation, default=1):
Chris@39:     """ Allow user to enable/disable a certain option. This results in a commandline option enable<Option>, where Option
Chris@39:     is the name of the option with a capitalized first letter.
Chris@39:     @param opt: Name of option.
Chris@39:     @param explanation: Explanation of option.
Chris@39:     @param default: The default value for this option (1/0).
Chris@39:     """
Chris@39:     return BoolOption("enable%s" % opt[0].upper() + opt[1:], explanation, default)
Chris@39: 
Chris@39: def _EnumOption(opt, explanation, allowedValues, default):
Chris@39:     """ Allow the user to choose among a set of values for an option. This results in a commandline option with<Option>,
Chris@39:     where Option is the name of the option with a capitalized first letter.
Chris@39:     @param opt: The name of the option.
Chris@39:     @param explanation: Explanation of option.
Chris@39:     @param allowedValues: The set of values to choose from.
Chris@39:     @param default: The default value.
Chris@39:     """
Chris@39:     assert default in allowedValues
Chris@39:     return EnumOption("with%s" % opt[0].upper() + opt[1:], explanation, default, allowed_values=allowedValues)
Chris@39: 
Chris@39: def _DirectoryOption(opt, explanation, default):
Chris@39:     """ Allow the user to configure the location for a certain directory, for instance the prefix. This results in a
Chris@39:     commandline option which is simply the name of this option.
Chris@39:     @param opt: The configurable directory, for instance "prefix".
Chris@39:     @param explanation: Explanation of option.
Chris@39:     @param default: The default value for this option.
Chris@39:     """
Chris@39:     return PathOption(opt, explanation, default)
Chris@39:     # Incompatible with the latest stable SCons
Chris@39:     # return PathOption(path, help, default, PathOption.PathIsDir)
Chris@39: 
Chris@39: import SCons.Errors
Chris@39: try:
Chris@39:     Import("Platform", "Posix")
Chris@39: except SCons.Errors.UserError:
Chris@39:     # The common objects must be exported first
Chris@39:     SConscript("SConscript_common")
Chris@39:     Import("Platform", "Posix")
Chris@39: 
Chris@39: # Expose the options as a dictionary of sets of options
Chris@39: opts = {}
Chris@39: 
Chris@39: if Platform in Posix:
Chris@39:     opts["Installation Dirs"] = [_DirectoryOption("prefix", "installation prefix", "/usr/local")]
Chris@39: elif Platform in Windows:
Chris@39:     if Platform == "cygwin":
Chris@39:         opts["Installation Dirs"] = [_DirectoryOption("prefix", "installation prefix", "/usr/local")]
Chris@39: 
Chris@39: opts["Build Targets"] = [_BoolOption("shared", "create shared library"), _BoolOption("static", "create static library"),
Chris@39:         _BoolOption("tests", "build test programs")]
Chris@39: 
Chris@39: apis = []
Chris@39: if Platform in Posix:
Chris@39:     apis.append(_PackageOption("OSS"))
Chris@39:     apis.append(_PackageOption("JACK"))
Chris@39:     apis.append(_PackageOption("ALSA", Platform == "linux"))
Chris@39:     apis.append(_PackageOption("ASIHPI", Platform == "linux"))
Chris@39:     apis.append(_PackageOption("COREAUDIO", Platform == "darwin"))
Chris@39: elif Platform in Windows:
Chris@39:     if Platform == "cygwin":
Chris@39:         apis.append(_EnumOption("winAPI", "Windows API to use", ("wmme", "directx", "asio"), "wmme"))
Chris@39: 
Chris@39: opts["Host APIs"] = apis
Chris@39: 
Chris@39: opts["Build Parameters"] = [\
Chris@39:         _BoolOption("debug", "compile with debug symbols"),
Chris@39:         _BoolOption("optimize", "compile with optimization", default=0),
Chris@39:         _BoolOption("asserts", "runtime assertions are helpful for debugging, but can be detrimental to performance",
Chris@39:                 default=1),
Chris@39:         _BoolOption("debugOutput", "enable debug output", default=0),
Chris@39:         # _BoolOption("python", "create Python binding"),
Chris@39:         ("customCFlags", "customize compilation of C code", ""),
Chris@39:         ("customCxxFlags", "customize compilation of C++ code", ""),
Chris@39:         ("customLinkFlags", "customize linking", ""),
Chris@39:         ]
Chris@39: 
Chris@39: opts["Bindings"] = [\
Chris@39:         _BoolOption("cxx", "build Merlijn Blaauw's PA C++ wrapper", default=0)
Chris@39:         ]
Chris@39:     
Chris@39: Return("opts")