Skip to content

Commit

Permalink
Add example to modify input source
Browse files Browse the repository at this point in the history
  • Loading branch information
jsharpe committed Mar 31, 2021
1 parent 5686d0f commit 62efa2f
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 0 deletions.
18 changes: 18 additions & 0 deletions examples/configure_modify_input_source/BUILD.bazel
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 examples/configure_modify_input_source/simple_lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filegroup(
name = "simple_srcs",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
7 changes: 7 additions & 0 deletions examples/configure_modify_input_source/simple_lib/Makefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
simple: ./src/simple.c
$(CC) $(CPPFLAGS) $(LDFLAGS) -o simple.a -c ./src/simple.c -I./include -I.
install:
mkdir -p simple
mkdir -p simple/lib
cp simple.a ./simple/lib/simple.a
cp -r ./include ./simple
15 changes: 15 additions & 0 deletions examples/configure_modify_input_source/simple_lib/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

# Slightly contrived example of a tool
# that resolves the symlinks to the real file
# and attempts to modify it
# (Using perl here for replacement to avoid difference in in-place
# arguments on macOS sed)
# Note that perl -i would just replace the symlink
# if used directly

perl -i -pe 's/42/0/' $(readlink src/simple.c)
echo "CC = $CC" > Makefile
echo "CPPFLAGS = $CPPFLAGS" >> Makefile
echo "LDFLAGS = $LDFLAGS" >> Makefile
cat Makefile.in >> Makefile
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_
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "simple.h"

int simpleFun(void) {
return 42;
}
5 changes: 5 additions & 0 deletions examples/configure_modify_input_source/testSimple.c
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();
}

0 comments on commit 62efa2f

Please sign in to comment.