diff --git a/examples/configure_modify_input_source/BUILD.bazel b/examples/configure_modify_input_source/BUILD.bazel new file mode 100644 index 000000000..2a07d47e2 --- /dev/null +++ b/examples/configure_modify_input_source/BUILD.bazel @@ -0,0 +1,18 @@ +load("@rules_cc//cc:defs.bzl", "cc_test") +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +configure_make( + name = "simple", + configure_in_place = True, + lib_source = "//configure_modify_input_source/simple_lib:simple_srcs", + targets = [ + "simple", + "install", + ], +) + +cc_test( + name = "test", + srcs = ["testSimple.c"], + deps = [":simple"], +) diff --git a/examples/configure_modify_input_source/simple_lib/BUILD.bazel b/examples/configure_modify_input_source/simple_lib/BUILD.bazel new file mode 100644 index 000000000..0b9819c95 --- /dev/null +++ b/examples/configure_modify_input_source/simple_lib/BUILD.bazel @@ -0,0 +1,5 @@ +filegroup( + name = "simple_srcs", + srcs = glob(["**"]), + visibility = ["//visibility:public"], +) diff --git a/examples/configure_modify_input_source/simple_lib/Makefile.in b/examples/configure_modify_input_source/simple_lib/Makefile.in new file mode 100644 index 000000000..e765171fc --- /dev/null +++ b/examples/configure_modify_input_source/simple_lib/Makefile.in @@ -0,0 +1,11 @@ +simple: $(OUTPUT) + +$(OUTPUT): ./src/simple.c + $(CC) $(CPPFLAGS) -o $(OBJECT) -c ./src/simple.c -I./include -I. + $(AR) $(LDFLAGS) + +install: $(OUTPUT) + mkdir -p simple + mkdir -p simple/lib + cp $(OUTPUT) ./simple/lib/$(OUTPUT) + cp -r ./include ./simple diff --git a/examples/configure_modify_input_source/simple_lib/configure b/examples/configure_modify_input_source/simple_lib/configure new file mode 100755 index 000000000..a67c76b5d --- /dev/null +++ b/examples/configure_modify_input_source/simple_lib/configure @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# (Using perl here for replacement to avoid difference in in-place +# arguments on macOS sed) + +perl -i -pe 's/42/0/' src/simple.c + +echo "CC = $CC" > Makefile +echo "LDFLAGS = $LDFLAGS" >> Makefile +if [[ "$(uname)" == *"NT"* ]]; then + echo "AR = ${AR}" >> Makefile + echo "OBJECT = simple.obj" >> Makefile + echo "OUTPUT = simple.lib" >> Makefile + + ESCAPED_CPPFLAGS="$(echo ${CFLAGS} | sed 's@\\@/@g')" + ESCAPED_LDFLAGS="$(echo ${LDFLAGS} | sed 's@\\@/@g')" + echo "CPPFLAGS = /c ${ESCAPED_CPPFLAGS}" >> Makefile + echo "LDFLAGS = \$(OBJECT) ${ESCAPED_LDFLAGS} /OUT:\$(OUTPUT)" >> Makefile +else + echo "AR = \"ar\"" >> Makefile + echo "OBJECT = simple.o" >> Makefile + echo "OUTPUT = simple.a" >> Makefile + echo "CPPFLAGS = ${CFLAGS}" >> Makefile + echo "LDFLAGS = rcs \$(OUTPUT) \$(OBJECT)" >> Makefile +fi +cat Makefile.in >> Makefile diff --git a/examples/configure_modify_input_source/simple_lib/include/simple.h b/examples/configure_modify_input_source/simple_lib/include/simple.h new file mode 100644 index 000000000..fb62eebf8 --- /dev/null +++ b/examples/configure_modify_input_source/simple_lib/include/simple.h @@ -0,0 +1,6 @@ +#ifndef SIMPLE_H_ +#define SIMPLE_H_ (1) + +int simpleFun(void); + +#endif // SIMPLE_H_ \ No newline at end of file diff --git a/examples/configure_modify_input_source/simple_lib/src/simple.c b/examples/configure_modify_input_source/simple_lib/src/simple.c new file mode 100644 index 000000000..0602ad6fb --- /dev/null +++ b/examples/configure_modify_input_source/simple_lib/src/simple.c @@ -0,0 +1,5 @@ +#include "simple.h" + +int simpleFun(void) { + return 42; +} \ No newline at end of file diff --git a/examples/configure_modify_input_source/testSimple.c b/examples/configure_modify_input_source/testSimple.c new file mode 100644 index 000000000..507b20a17 --- /dev/null +++ b/examples/configure_modify_input_source/testSimple.c @@ -0,0 +1,5 @@ +#include "simple.h" + +int main(int argc, char **argv) { + return simpleFun(); +} diff --git a/foreign_cc/private/configure_script.bzl b/foreign_cc/private/configure_script.bzl index 295565847..dce885a29 100644 --- a/foreign_cc/private/configure_script.bzl +++ b/foreign_cc/private/configure_script.bzl @@ -33,7 +33,7 @@ def create_configure_script( 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)) + script.append("##copy_dir_contents_to_dir## $$EXT_BUILD_ROOT$$/{} $$BUILD_TMPDIR$$".format(root)) root_path = "$$BUILD_TMPDIR$$" configure_path = "{}/{}".format(root_path, configure_command)