<commit_before>load(":cc_toolchain_util.bzl", "absolutize_path_in_str")
load(":framework.bzl", "get_foreign_cc_dep")

def create_configure_script(
        workspace_name,
        target_os,
        tools,
        flags,
        root,
        user_options,
        user_vars,
        is_debug,
        configure_command,
        deps,
        inputs,
        configure_in_place,
        autoreconf,
        autoreconf_options,
        autoreconf_env_vars,
        autogen,
        autogen_command,
        autogen_options,
        autogen_env_vars):
    env_vars_string = get_env_vars(workspace_name, tools, flags, user_vars, deps, inputs)

    script = []
    for ext_dir in inputs.ext_build_dirs:
        script.append("##increment_pkg_config_path## $$EXT_BUILD_ROOT$$/" + ext_dir.path)

    script.append("echo \"PKG_CONFIG_PATH=$$PKG_CONFIG_PATH$$\"")

    root_path = "$$EXT_BUILD_ROOT$$/{}".format(root)
    configure_path = "{}/{}".format(root_path, configure_command)
    if configure_in_place:
        script.append("##symlink_contents_to_dir## $$EXT_BUILD_ROOT$$/{} $$BUILD_TMPDIR$$".format(root))
        root_path = "$$BUILD_TMPDIR$$"
        configure_path = "{}/{}".format(root_path, configure_command)

    if autogen and configure_in_place:
        # NOCONFIGURE is pseudo standard and tells the script to not invoke configure.
        # We explicitly invoke configure later.
        autogen_env_vars = _get_autogen_env_vars(autogen_env_vars)
        script.append("{} \"{}/{}\" {}".format(
            " ".join(["{}=\"{}\"".format(key, autogen_env_vars[key]) for key in autogen_env_vars]),
            root_path,
            autogen_command,
            " ".join(autogen_options),
        ).lstrip())

    if autoreconf and configure_in_place:
        script.append("{} autoreconf {}".format(
            " ".join(["{}=\"{}\"".format(key, autoreconf_env_vars[key]) for key in autoreconf_env_vars]),
            " ".join(autoreconf_options),
        ).lstrip())

    script.append("{env_vars} \"{configure}\" --prefix=$$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$ {user_options}".format(
        env_vars = env_vars_string,
        configure = configure_path,
        user_options = " ".join(user_options),
    ))
    return "\n".join(script)

def create_make_script(
        workspace_name,
        tools,
        flags,
        root,
        user_vars,
        deps,
        inputs,
        make_commands,
        prefix):
    env_vars_string = get_env_vars(workspace_name, tools, flags, user_vars, deps, inputs)
    script = []
    for ext_dir in inputs.ext_build_dirs:
        script.append("##increment_pkg_config_path## $$EXT_BUILD_ROOT$$/" + ext_dir.path)

    script.append("echo \"PKG_CONFIG_PATH=$$PKG_CONFIG_PATH$$\"")

    script.append("##symlink_contents_to_dir## $$EXT_BUILD_ROOT$$/{} $$BUILD_TMPDIR$$".format(root))
    script.append("" + " && ".join(make_commands))
    return "\n".join(script)

def get_env_vars(
        workspace_name,
        tools,
        flags,
        user_vars,
        deps,
        inputs):
    vars = _get_configure_variables(tools, flags, user_vars)
    deps_flags = _define_deps_flags(deps, inputs)

    vars["LDFLAGS"] = vars["LDFLAGS"] + deps_flags.libs

    # -I flags should be put into preprocessor flags, CPPFLAGS
    # https://www.gnu.org/software/autoconf/manual/autoconf-2.63/html_node/Preset-Output-Variables.html
    vars["CPPFLAGS"] = deps_flags.flags

    return " ".join(["{}=\"{}\""
        .format(key, _join_flags_list(workspace_name, vars[key])) for key in vars])

def _get_autogen_env_vars(autogen_env_vars):
    # Make a copy if necessary so we can set NOCONFIGURE.
    if autogen_env_vars.get("NOCONFIGURE"):
        return autogen_env_vars
    vars = {}
    for key in autogen_env_vars:
        vars[key] = autogen_env_vars.get(key)
    vars["NOCONFIGURE"] = "1"
    return vars
<commit_msg>Handle case where LDFLAGS is undefined (#407)<commit_after>load(":cc_toolchain_util.bzl", "absolutize_path_in_str")
load(":framework.bzl", "get_foreign_cc_dep")

def create_configure_script(
        workspace_name,
        target_os,
        tools,
        flags,
        root,
        user_options,
        user_vars,
        is_debug,
        configure_command,
        deps,
        inputs,
        configure_in_place,
        autoreconf,
        autoreconf_options,
        autoreconf_env_vars,
        autogen,
        autogen_command,
        autogen_options,
        autogen_env_vars):
    env_vars_string = get_env_vars(workspace_name, tools, flags, user_vars, deps, inputs)

    script = []
    for ext_dir in inputs.ext_build_dirs:
        script.append("##increment_pkg_config_path## $$EXT_BUILD_ROOT$$/" + ext_dir.path)

    script.append("echo \"PKG_CONFIG_PATH=$$PKG_CONFIG_PATH$$\"")

    root_path = "$$EXT_BUILD_ROOT$$/{}".format(root)
    configure_path = "{}/{}".format(root_path, configure_command)
    if configure_in_place:
        script.append("##symlink_contents_to_dir## $$EXT_BUILD_ROOT$$/{} $$BUILD_TMPDIR$$".format(root))
        root_path = "$$BUILD_TMPDIR$$"
        configure_path = "{}/{}".format(root_path, configure_command)

    if autogen and configure_in_place:
        # NOCONFIGURE is pseudo standard and tells the script to not invoke configure.
        # We explicitly invoke configure later.
        autogen_env_vars = _get_autogen_env_vars(autogen_env_vars)
        script.append("{} \"{}/{}\" {}".format(
            " ".join(["{}=\"{}\"".format(key, autogen_env_vars[key]) for key in autogen_env_vars]),
            root_path,
            autogen_command,
            " ".join(autogen_options),
        ).lstrip())

    if autoreconf and configure_in_place:
        script.append("{} autoreconf {}".format(
            " ".join(["{}=\"{}\"".format(key, autoreconf_env_vars[key]) for key in autoreconf_env_vars]),
            " ".join(autoreconf_options),
        ).lstrip())

    script.append("{env_vars} \"{configure}\" --prefix=$$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$ {user_options}".format(
        env_vars = env_vars_string,
        configure = configure_path,
        user_options = " ".join(user_options),
    ))
    return "\n".join(script)

def create_make_script(
        workspace_name,
        tools,
        flags,
        root,
        user_vars,
        deps,
        inputs,
        make_commands,
        prefix):
    env_vars_string = get_env_vars(workspace_name, tools, flags, user_vars, deps, inputs)
    script = []
    for ext_dir in inputs.ext_build_dirs:
        script.append("##increment_pkg_config_path## $$EXT_BUILD_ROOT$$/" + ext_dir.path)

    script.append("echo \"PKG_CONFIG_PATH=$$PKG_CONFIG_PATH$$\"")

    script.append("##symlink_contents_to_dir## $$EXT_BUILD_ROOT$$/{} $$BUILD_TMPDIR$$".format(root))
    script.append("" + " && ".join(make_commands))
    return "\n".join(script)

def get_env_vars(
        workspace_name,
        tools,
        flags,
        user_vars,
        deps,
        inputs):
    vars = _get_configure_variables(tools, flags, user_vars)
    deps_flags = _define_deps_flags(deps, inputs)

    if "LDFLAGS" in vars.keys():
      vars["LDFLAGS"] = vars["LDFLAGS"] + deps_flags.libs
    else:
      vars["LDFLAGS"] = deps_flags.libs

    # -I flags should be put into preprocessor flags, CPPFLAGS
    # https://www.gnu.org/software/autoconf/manual/autoconf-2.63/html_node/Preset-Output-Variables.html
    vars["CPPFLAGS"] = deps_flags.flags

    return " ".join(["{}=\"{}\""
        .format(key, _join_flags_list(workspace_name, vars[key])) for key in vars])

def _get_autogen_env_vars(autogen_env_vars):
    # Make a copy if necessary so we can set NOCONFIGURE.
    if autogen_env_vars.get("NOCONFIGURE"):
        return autogen_env_vars
    vars = {}
    for key in autogen_env_vars:
        vars[key] = autogen_env_vars.get(key)
    vars["NOCONFIGURE"] = "1"
    return vars

{'fraction_non_alphanumeric': 0.13380909901873328, 'fraction_numerical': 0.0014018096087676818, 'mean_word_length': 2.9377822378324137, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7644055', 'n_tokens_mistral': 2621, 'n_tokens_neox': 2596, 'n_words': 453}