diff mbox series

[20/20] Fixup Makefile

Message ID 20200424205504.2586682-21-Jes.Sorensen@gmail.com (mailing list archive)
State Superseded
Headers show
Series Split fsverity-utils into a shared library | expand

Commit Message

Jes Sorensen April 24, 2020, 8:55 p.m. UTC
From: Jes Sorensen <jsorensen@fb.com>

Set soname for libfsverity, install shared library and header file,
and make clean handle shared library too.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
---
 Makefile | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 5bbcd87..0b82c82 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,5 @@ 
 EXE := fsverity
 STATIC := fsverity-static
-LIB := libfsverity.so
 INC := libfsverity.h
 CFLAGS := -O2 -Wall
 CPPFLAGS := -D_FILE_OFFSET_BITS=64
@@ -15,12 +14,17 @@  SSRC := libverity.c hash_algs.c
 SHOBJ := libverity.so hash_algs.so
 STOBJ := libverity.o hash_algs.o
 HDRS := $(wildcard *.h)
+LIB_MAJOR := 1
+LIB_MINOR := 0.0
+LIB_SO := libfsverity.so
+LIB_SONAME := $(LIB_SO).$(LIB_MAJOR)
+LIB_FULL := $(LIB_SONAME).$(LIB_MINOR)
 
 all:$(EXE)
 
 static:$(STATIC)
 
-$(EXE):$(OBJ) $(LIB)
+$(EXE):$(OBJ) $(LIB_FULL)
 	$(CC) -o $@ $(OBJ) $(LDLIBS) -L . -l fsverity
 
 $(STATIC):$(OBJ) $(STOBJ)
@@ -35,16 +39,21 @@  $(STOBJ): %.o: %.c $(HDRS)
 $(SHOBJ): %.so: %.c $(HDRS)
 	$(CC) -c -fPIC $(CFLAGS) $(CPPFLAGS) $< -o $@
 
-libfsverity.so: $(SHOBJ)
-	$(CC) $(LDLIBS) -shared -o $@ $(SHOBJ)
+$(LIB_FULL): $(SHOBJ)
+	$(CC) $(LDLIBS) -shared -Wl,-soname,$(LIB_SONAME) -o $@ $(SHOBJ)
+	rm -f $(LIB_SONAME) $(LIB_SO)
+	ln -s $(LIB_FULL) $(LIB_SONAME)
+	ln -s $(LIB_SONAME) $(LIB_SO)
 
 clean:
-	rm -f $(EXE) $(OBJ) $(SHOBJ) $(LIB) $(STOBJ) $(STATIC)
+	rm -f $(EXE) $(OBJ) $(SHOBJ) $(LIB_SONAME) $(LIB_SO) $(LIB_FULL) $(STOBJ) $(STATIC)
 
 install:all
-	install -Dm755 -t $(BINDIR) $(EXE)
-	install -Dm755 -t $(LIBDIR) $(LIB)
-	install -Dm644 -t $(INCDIR) $(INC)
+	install -Dm755 -t $(DESTDIR)$(BINDIR) $(EXE)
+	install -Dm755 -t $(DESTDIR)$(LIBDIR) $(LIB_FULL)
+	ln -s $(LIB_FULL) $(DESTDIR)$(LIBDIR)/$(LIB_SONAME)
+	ln -s $(LIB_SONAME) $(DESTDIR)$(LIBDIR)/$(LIB_SO)
+	install -Dm644 -t $(DESTDIR)$(INCDIR) $(INC)
 
 install-static:static
 	install -Dm755 -t $(BINDIR) $(STATIC)