-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow all source files to be modified in configure_make when using co…
…nfigure_in_place = True (#856)
- Loading branch information
Showing
8 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"], | ||
) |
5 changes: 5 additions & 0 deletions
5
examples/configure_modify_input_source/simple_lib/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
filegroup( | ||
name = "simple_srcs", | ||
srcs = glob(["**"]), | ||
visibility = ["//visibility:public"], | ||
) |
11 changes: 11 additions & 0 deletions
11
examples/configure_modify_input_source/simple_lib/Makefile.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
28 changes: 28 additions & 0 deletions
28
examples/configure_modify_input_source/simple_lib/configure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
6 changes: 6 additions & 0 deletions
6
examples/configure_modify_input_source/simple_lib/include/simple.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef SIMPLE_H_ | ||
#define SIMPLE_H_ (1) | ||
|
||
int simpleFun(void); | ||
|
||
#endif // SIMPLE_H_ |
5 changes: 5 additions & 0 deletions
5
examples/configure_modify_input_source/simple_lib/src/simple.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "simple.h" | ||
|
||
int simpleFun(void) { | ||
return 42; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "simple.h" | ||
|
||
int main(int argc, char **argv) { | ||
return simpleFun(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters