diff --git a/foreign_cc/configure.bzl b/foreign_cc/configure.bzl index a0e0519c1..1dc06d08e 100644 --- a/foreign_cc/configure.bzl +++ b/foreign_cc/configure.bzl @@ -78,12 +78,19 @@ def _create_configure_script(configureParameters): configure_prefix = "{} ".format(expand_locations_and_make_variables(ctx, ctx.attr.configure_prefix, "configure_prefix", data)) if ctx.attr.configure_prefix else "" configure_options = [expand_locations_and_make_variables(ctx, option, "configure_option", data) for option in ctx.attr.configure_options] if ctx.attr.configure_options else [] + if ctx.attr.experimental_absolute_install_prefix: + destdir_arg = 'DESTDIR="$$BUILD_TMPDIR$$/" ' + else: + destdir_arg = "" + for target in ctx.attr.targets: # Configure will have generated sources into `$BUILD_TMPDIR` so make sure we `cd` there make_commands.append("{prefix}{make} {target} {args}".format( prefix = prefix, make = attrs.make_path, - args = args, + # https://www.gnu.org/prep/standards/html_node/DESTDIR.html + # DESTDIR only applies to INSTALL or UNINSTALL targets + args = destdir_arg + args if target.startswith("install") or target.startswith("uninstall") else args, target = target, )) @@ -100,6 +107,7 @@ def _create_configure_script(configureParameters): env_vars = user_env, configure_in_place = ctx.attr.configure_in_place, prefix_flag = ctx.attr.prefix_flag, + absolute_prefix = ctx.attr.experimental_absolute_install_prefix, autoconf = ctx.attr.autoconf, autoconf_options = ctx.attr.autoconf_options, autoreconf = ctx.attr.autoreconf, @@ -187,6 +195,14 @@ def _attrs(): "configure_prefix": attr.string( doc = "A prefix for the call to the `configure_command`.", ), + "experimental_absolute_install_prefix": attr.bool( + doc = ( + "Allows the install_prefix to be an absolute path, and relies on DESTDIR to place" + + "the installation files into the correct output directory when calling `make install`" + ), + mandatory = False, + default = False, + ), "install_prefix": attr.string( doc = ( "Install prefix, i.e. relative path to where to install the result of the build. " + diff --git a/foreign_cc/private/configure_script.bzl b/foreign_cc/private/configure_script.bzl index 06c516ea5..2aeddcc4f 100644 --- a/foreign_cc/private/configure_script.bzl +++ b/foreign_cc/private/configure_script.bzl @@ -16,6 +16,7 @@ def create_configure_script( env_vars, configure_in_place, prefix_flag, + absolute_prefix, autoconf, autoconf_options, autoreconf, @@ -69,11 +70,12 @@ def create_configure_script( ).lstrip()) script.append("##mkdirs## $$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$") - script.append("{env_vars} {prefix}\"{configure}\" {prefix_flag}$$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$ {user_options}".format( + script.append("{env_vars} {prefix}\"{configure}\" {prefix_flag}{prefix_dir} {user_options}".format( env_vars = get_make_env_vars(workspace_name, tools, flags, env_vars, deps, inputs), prefix = configure_prefix, configure = configure_path, prefix_flag = prefix_flag, + prefix_dir = "$$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$" if not absolute_prefix else "$$INSTALL_PREFIX$$", user_options = " ".join(user_options), ))