[PATCH 04/14] Build static library
Valerie Aurora
val at versity.com
Thu Feb 27 06:16:13 PST 2025
Build a static library for use by various external binaries.
Signed-off-by: Valerie Aurora <val at versity.com>
---
.gitignore | 1 +
Makefile | 15 +++++++++++++--
lib/.gitkeep | 0
3 files changed, 14 insertions(+), 2 deletions(-)
create mode 100644 lib/.gitkeep
diff --git a/.gitignore b/.gitignore
index c718e69..0e89693 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ cscope.*
shared/generated-trace-inlines.h
cli/ngnfs-cli
devd/ngnfs-devd
+lib/libngnfs.a
diff --git a/Makefile b/Makefile
index 5fd3d85..e1eb5e7 100644
--- a/Makefile
+++ b/Makefile
@@ -23,6 +23,13 @@ DGH := shared/generated-trace-inlines.h
# source with main() is linked as a binary
BIN := $(patsubst %.c,%,$(shell grep -l "^int main" $(SRC)))
+# make a static library out of everything in shared
+LIB := lib/libngnfs.a
+LIB_DIR := shared shared/lk
+LIB_SRC := $(foreach d,$(LIB_DIR),$(wildcard $(d)/*.c))
+LIB_OBJ := $(patsubst %.c,%.o,$(LIB_SRC))
+LIB_DEP := $(foreach d,$(LIB_DIR),$(wildcard $(d)/*.d))
+
# binary names have ngnfs- prefixed
#binname = $(dir $1)ngnfs-$(notdir $1)
@@ -34,7 +41,7 @@ BIN := $(patsubst %.c,%,$(shell grep -l "^int main" $(SRC)))
PADCHECK := $(patsubst %.h,%.o.padcheck,$(wildcard shared/format-*.h))
.PHONY: all
-all: $(PADCHECK) $(BIN) $(DGH)
+all: $(PADCHECK) $(BIN) $(DGH) $(LIB)
ifneq ($(DEP),)
-include $(DEP)
@@ -60,9 +67,13 @@ $(PADCHECK): %.o.padcheck: %.h Makefile
$(DGH): scripts/generate-trace-events.awk shared/trace-events.txt Makefile
gawk -f $< < shared/trace-events.txt > $@
+$(LIB): $(LIB_OBJ) Makefile
+ ar rcs $@ $(LIB_OBJ)
+ ranlib $@
+
.PHONY: clean
clean:
- @rm -f $(BIN) $(OBJ) $(DEP) $(PADCHECK) $(DGH) \
+ @rm -f $(BIN) $(OBJ) $(DEP) $(PADCHECK) $(DGH) $(LIB)\
$(foreach d,$(DIR),$(wildcard $(d)/*.[is])) \
.sparse.gcc-defines.h .sparse.output
diff --git a/lib/.gitkeep b/lib/.gitkeep
new file mode 100644
index 0000000..e69de29
--
2.48.1
More information about the ngnfs-devel
mailing list