# Autogenerated wrapper script for mdbtools_jll for i686-linux-gnu
export libmdb, libmdbsql, mbd_ver, mdb_array, mdb_count, mdb_export, mdb_header, mdb_hexdump, mdb_parsecsv, mdb_prop, mdb_schema, mdb_sql, mdb_tables

using Glib_jll
## Global variables
PATH = ""
LIBPATH = ""
LIBPATH_env = "LD_LIBRARY_PATH"
LIBPATH_default = ""

# Relative path to `libmdb`
const libmdb_splitpath = ["lib", "libmdb.so"]

# This will be filled out by __init__() for all products, as it must be done at runtime
libmdb_path = ""

# libmdb-specific global declaration
# This will be filled out by __init__()
libmdb_handle = C_NULL

# This must be `const` so that we can use it with `ccall()`
const libmdb = "libmdb.so.2"


# Relative path to `libmdbsql`
const libmdbsql_splitpath = ["lib", "libmdbsql.so"]

# This will be filled out by __init__() for all products, as it must be done at runtime
libmdbsql_path = ""

# libmdbsql-specific global declaration
# This will be filled out by __init__()
libmdbsql_handle = C_NULL

# This must be `const` so that we can use it with `ccall()`
const libmdbsql = "libmdbsql.so.2"


# Relative path to `mbd_ver`
const mbd_ver_splitpath = ["bin", "mdb-ver"]

# This will be filled out by __init__() for all products, as it must be done at runtime
mbd_ver_path = ""

# mbd_ver-specific global declaration
function mbd_ver(f::Function; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
    global PATH, LIBPATH
    env_mapping = Dict{String,String}()
    if adjust_PATH
        if !isempty(get(ENV, "PATH", ""))
            env_mapping["PATH"] = string(PATH, ':', ENV["PATH"])
        else
            env_mapping["PATH"] = PATH
        end
    end
    if adjust_LIBPATH
        LIBPATH_base = get(ENV, LIBPATH_env, expanduser(LIBPATH_default))
        if !isempty(LIBPATH_base)
            env_mapping[LIBPATH_env] = string(LIBPATH, ':', LIBPATH_base)
        else
            env_mapping[LIBPATH_env] = LIBPATH
        end
    end
    withenv(env_mapping...) do
        f(mbd_ver_path)
    end
end


# Relative path to `mdb_array`
const mdb_array_splitpath = ["bin", "mdb-array"]

# This will be filled out by __init__() for all products, as it must be done at runtime
mdb_array_path = ""

# mdb_array-specific global declaration
function mdb_array(f::Function; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
    global PATH, LIBPATH
    env_mapping = Dict{String,String}()
    if adjust_PATH
        if !isempty(get(ENV, "PATH", ""))
            env_mapping["PATH"] = string(PATH, ':', ENV["PATH"])
        else
            env_mapping["PATH"] = PATH
        end
    end
    if adjust_LIBPATH
        LIBPATH_base = get(ENV, LIBPATH_env, expanduser(LIBPATH_default))
        if !isempty(LIBPATH_base)
            env_mapping[LIBPATH_env] = string(LIBPATH, ':', LIBPATH_base)
        else
            env_mapping[LIBPATH_env] = LIBPATH
        end
    end
    withenv(env_mapping...) do
        f(mdb_array_path)
    end
end


# Relative path to `mdb_count`
const mdb_count_splitpath = ["bin", "mdb-count"]

# This will be filled out by __init__() for all products, as it must be done at runtime
mdb_count_path = ""

# mdb_count-specific global declaration
function mdb_count(f::Function; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
    global PATH, LIBPATH
    env_mapping = Dict{String,String}()
    if adjust_PATH
        if !isempty(get(ENV, "PATH", ""))
            env_mapping["PATH"] = string(PATH, ':', ENV["PATH"])
        else
            env_mapping["PATH"] = PATH
        end
    end
    if adjust_LIBPATH
        LIBPATH_base = get(ENV, LIBPATH_env, expanduser(LIBPATH_default))
        if !isempty(LIBPATH_base)
            env_mapping[LIBPATH_env] = string(LIBPATH, ':', LIBPATH_base)
        else
            env_mapping[LIBPATH_env] = LIBPATH
        end
    end
    withenv(env_mapping...) do
        f(mdb_count_path)
    end
end


# Relative path to `mdb_export`
const mdb_export_splitpath = ["bin", "mdb-export"]

# This will be filled out by __init__() for all products, as it must be done at runtime
mdb_export_path = ""

# mdb_export-specific global declaration
function mdb_export(f::Function; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
    global PATH, LIBPATH
    env_mapping = Dict{String,String}()
    if adjust_PATH
        if !isempty(get(ENV, "PATH", ""))
            env_mapping["PATH"] = string(PATH, ':', ENV["PATH"])
        else
            env_mapping["PATH"] = PATH
        end
    end
    if adjust_LIBPATH
        LIBPATH_base = get(ENV, LIBPATH_env, expanduser(LIBPATH_default))
        if !isempty(LIBPATH_base)
            env_mapping[LIBPATH_env] = string(LIBPATH, ':', LIBPATH_base)
        else
            env_mapping[LIBPATH_env] = LIBPATH
        end
    end
    withenv(env_mapping...) do
        f(mdb_export_path)
    end
end


# Relative path to `mdb_header`
const mdb_header_splitpath = ["bin", "mdb-header"]

# This will be filled out by __init__() for all products, as it must be done at runtime
mdb_header_path = ""

# mdb_header-specific global declaration
function mdb_header(f::Function; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
    global PATH, LIBPATH
    env_mapping = Dict{String,String}()
    if adjust_PATH
        if !isempty(get(ENV, "PATH", ""))
            env_mapping["PATH"] = string(PATH, ':', ENV["PATH"])
        else
            env_mapping["PATH"] = PATH
        end
    end
    if adjust_LIBPATH
        LIBPATH_base = get(ENV, LIBPATH_env, expanduser(LIBPATH_default))
        if !isempty(LIBPATH_base)
            env_mapping[LIBPATH_env] = string(LIBPATH, ':', LIBPATH_base)
        else
            env_mapping[LIBPATH_env] = LIBPATH
        end
    end
    withenv(env_mapping...) do
        f(mdb_header_path)
    end
end


# Relative path to `mdb_hexdump`
const mdb_hexdump_splitpath = ["bin", "mdb-hexdump"]

# This will be filled out by __init__() for all products, as it must be done at runtime
mdb_hexdump_path = ""

# mdb_hexdump-specific global declaration
function mdb_hexdump(f::Function; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
    global PATH, LIBPATH
    env_mapping = Dict{String,String}()
    if adjust_PATH
        if !isempty(get(ENV, "PATH", ""))
            env_mapping["PATH"] = string(PATH, ':', ENV["PATH"])
        else
            env_mapping["PATH"] = PATH
        end
    end
    if adjust_LIBPATH
        LIBPATH_base = get(ENV, LIBPATH_env, expanduser(LIBPATH_default))
        if !isempty(LIBPATH_base)
            env_mapping[LIBPATH_env] = string(LIBPATH, ':', LIBPATH_base)
        else
            env_mapping[LIBPATH_env] = LIBPATH
        end
    end
    withenv(env_mapping...) do
        f(mdb_hexdump_path)
    end
end


# Relative path to `mdb_parsecsv`
const mdb_parsecsv_splitpath = ["bin", "mdb-parsecsv"]

# This will be filled out by __init__() for all products, as it must be done at runtime
mdb_parsecsv_path = ""

# mdb_parsecsv-specific global declaration
function mdb_parsecsv(f::Function; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
    global PATH, LIBPATH
    env_mapping = Dict{String,String}()
    if adjust_PATH
        if !isempty(get(ENV, "PATH", ""))
            env_mapping["PATH"] = string(PATH, ':', ENV["PATH"])
        else
            env_mapping["PATH"] = PATH
        end
    end
    if adjust_LIBPATH
        LIBPATH_base = get(ENV, LIBPATH_env, expanduser(LIBPATH_default))
        if !isempty(LIBPATH_base)
            env_mapping[LIBPATH_env] = string(LIBPATH, ':', LIBPATH_base)
        else
            env_mapping[LIBPATH_env] = LIBPATH
        end
    end
    withenv(env_mapping...) do
        f(mdb_parsecsv_path)
    end
end


# Relative path to `mdb_prop`
const mdb_prop_splitpath = ["bin", "mdb-prop"]

# This will be filled out by __init__() for all products, as it must be done at runtime
mdb_prop_path = ""

# mdb_prop-specific global declaration
function mdb_prop(f::Function; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
    global PATH, LIBPATH
    env_mapping = Dict{String,String}()
    if adjust_PATH
        if !isempty(get(ENV, "PATH", ""))
            env_mapping["PATH"] = string(PATH, ':', ENV["PATH"])
        else
            env_mapping["PATH"] = PATH
        end
    end
    if adjust_LIBPATH
        LIBPATH_base = get(ENV, LIBPATH_env, expanduser(LIBPATH_default))
        if !isempty(LIBPATH_base)
            env_mapping[LIBPATH_env] = string(LIBPATH, ':', LIBPATH_base)
        else
            env_mapping[LIBPATH_env] = LIBPATH
        end
    end
    withenv(env_mapping...) do
        f(mdb_prop_path)
    end
end


# Relative path to `mdb_schema`
const mdb_schema_splitpath = ["bin", "mdb-schema"]

# This will be filled out by __init__() for all products, as it must be done at runtime
mdb_schema_path = ""

# mdb_schema-specific global declaration
function mdb_schema(f::Function; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
    global PATH, LIBPATH
    env_mapping = Dict{String,String}()
    if adjust_PATH
        if !isempty(get(ENV, "PATH", ""))
            env_mapping["PATH"] = string(PATH, ':', ENV["PATH"])
        else
            env_mapping["PATH"] = PATH
        end
    end
    if adjust_LIBPATH
        LIBPATH_base = get(ENV, LIBPATH_env, expanduser(LIBPATH_default))
        if !isempty(LIBPATH_base)
            env_mapping[LIBPATH_env] = string(LIBPATH, ':', LIBPATH_base)
        else
            env_mapping[LIBPATH_env] = LIBPATH
        end
    end
    withenv(env_mapping...) do
        f(mdb_schema_path)
    end
end


# Relative path to `mdb_sql`
const mdb_sql_splitpath = ["bin", "mdb-sql"]

# This will be filled out by __init__() for all products, as it must be done at runtime
mdb_sql_path = ""

# mdb_sql-specific global declaration
function mdb_sql(f::Function; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
    global PATH, LIBPATH
    env_mapping = Dict{String,String}()
    if adjust_PATH
        if !isempty(get(ENV, "PATH", ""))
            env_mapping["PATH"] = string(PATH, ':', ENV["PATH"])
        else
            env_mapping["PATH"] = PATH
        end
    end
    if adjust_LIBPATH
        LIBPATH_base = get(ENV, LIBPATH_env, expanduser(LIBPATH_default))
        if !isempty(LIBPATH_base)
            env_mapping[LIBPATH_env] = string(LIBPATH, ':', LIBPATH_base)
        else
            env_mapping[LIBPATH_env] = LIBPATH
        end
    end
    withenv(env_mapping...) do
        f(mdb_sql_path)
    end
end


# Relative path to `mdb_tables`
const mdb_tables_splitpath = ["bin", "mdb-tables"]

# This will be filled out by __init__() for all products, as it must be done at runtime
mdb_tables_path = ""

# mdb_tables-specific global declaration
function mdb_tables(f::Function; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
    global PATH, LIBPATH
    env_mapping = Dict{String,String}()
    if adjust_PATH
        if !isempty(get(ENV, "PATH", ""))
            env_mapping["PATH"] = string(PATH, ':', ENV["PATH"])
        else
            env_mapping["PATH"] = PATH
        end
    end
    if adjust_LIBPATH
        LIBPATH_base = get(ENV, LIBPATH_env, expanduser(LIBPATH_default))
        if !isempty(LIBPATH_base)
            env_mapping[LIBPATH_env] = string(LIBPATH, ':', LIBPATH_base)
        else
            env_mapping[LIBPATH_env] = LIBPATH
        end
    end
    withenv(env_mapping...) do
        f(mdb_tables_path)
    end
end


"""
Open all libraries
"""
function __init__()
    global artifact_dir = abspath(artifact"mdbtools")

    # Initialize PATH and LIBPATH environment variable listings
    global PATH_list, LIBPATH_list
    # From the list of our dependencies, generate a tuple of all the PATH and LIBPATH lists,
    # then append them to our own.
    foreach(p -> append!(PATH_list, p), (Glib_jll.PATH_list,))
    foreach(p -> append!(LIBPATH_list, p), (Glib_jll.LIBPATH_list,))

    global libmdb_path = normpath(joinpath(artifact_dir, libmdb_splitpath...))

    # Manually `dlopen()` this right now so that future invocations
    # of `ccall` with its `SONAME` will find this path immediately.
    global libmdb_handle = dlopen(libmdb_path)
    push!(LIBPATH_list, dirname(libmdb_path))

    global libmdbsql_path = normpath(joinpath(artifact_dir, libmdbsql_splitpath...))

    # Manually `dlopen()` this right now so that future invocations
    # of `ccall` with its `SONAME` will find this path immediately.
    global libmdbsql_handle = dlopen(libmdbsql_path)
    push!(LIBPATH_list, dirname(libmdbsql_path))

    global mbd_ver_path = normpath(joinpath(artifact_dir, mbd_ver_splitpath...))

    push!(PATH_list, dirname(mbd_ver_path))
    global mdb_array_path = normpath(joinpath(artifact_dir, mdb_array_splitpath...))

    push!(PATH_list, dirname(mdb_array_path))
    global mdb_count_path = normpath(joinpath(artifact_dir, mdb_count_splitpath...))

    push!(PATH_list, dirname(mdb_count_path))
    global mdb_export_path = normpath(joinpath(artifact_dir, mdb_export_splitpath...))

    push!(PATH_list, dirname(mdb_export_path))
    global mdb_header_path = normpath(joinpath(artifact_dir, mdb_header_splitpath...))

    push!(PATH_list, dirname(mdb_header_path))
    global mdb_hexdump_path = normpath(joinpath(artifact_dir, mdb_hexdump_splitpath...))

    push!(PATH_list, dirname(mdb_hexdump_path))
    global mdb_parsecsv_path = normpath(joinpath(artifact_dir, mdb_parsecsv_splitpath...))

    push!(PATH_list, dirname(mdb_parsecsv_path))
    global mdb_prop_path = normpath(joinpath(artifact_dir, mdb_prop_splitpath...))

    push!(PATH_list, dirname(mdb_prop_path))
    global mdb_schema_path = normpath(joinpath(artifact_dir, mdb_schema_splitpath...))

    push!(PATH_list, dirname(mdb_schema_path))
    global mdb_sql_path = normpath(joinpath(artifact_dir, mdb_sql_splitpath...))

    push!(PATH_list, dirname(mdb_sql_path))
    global mdb_tables_path = normpath(joinpath(artifact_dir, mdb_tables_splitpath...))

    push!(PATH_list, dirname(mdb_tables_path))
    # Filter out duplicate and empty entries in our PATH and LIBPATH entries
    filter!(!isempty, unique!(PATH_list))
    filter!(!isempty, unique!(LIBPATH_list))
    global PATH = join(PATH_list, ':')
    global LIBPATH = join(vcat(LIBPATH_list, [joinpath(Sys.BINDIR, Base.LIBDIR, "julia"), joinpath(Sys.BINDIR, Base.LIBDIR)]), ':')

    
end  # __init__()

