Message ID | 20200312214758.343212-2-Jes.Sorensen@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Split fsverity-utils into a shared library | expand |
On Thu, Mar 12, 2020 at 05:47:50PM -0400, Jes Sorensen wrote: > From: Jes Sorensen <jsorensen@fb.com> > > This introduces a dummy shared library to start moving things into. > > Signed-off-by: Jes Sorensen <jsorensen@fb.com> > --- > Makefile | 18 +++++++++++++++--- > libverity.c | 10 ++++++++++ > 2 files changed, 25 insertions(+), 3 deletions(-) > create mode 100644 libverity.c > > diff --git a/Makefile b/Makefile > index b9c09b9..bb85896 100644 > --- a/Makefile > +++ b/Makefile > @@ -1,20 +1,32 @@ > EXE := fsverity > +LIB := libfsverity.so > CFLAGS := -O2 -Wall > CPPFLAGS := -D_FILE_OFFSET_BITS=64 > LDLIBS := -lcrypto > DESTDIR := /usr/local > +LIBDIR := /usr/lib64 > SRC := $(wildcard *.c) > -OBJ := $(SRC:.c=.o) > +OBJ := fsverity.o hash_algs.o cmd_enable.o cmd_measure.o cmd_sign.o util.o > +SSRC := libverity.c > +SOBJ := libverity.so > HDRS := $(wildcard *.h) > > all:$(EXE) > > -$(EXE):$(OBJ) > +$(EXE):$(OBJ) $(LIB) > + $(CC) -o $@ $(OBJ) $(LDLIBS) -L . -l fsverity > > $(OBJ): %.o: %.c $(HDRS) > + $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ > + > +$(SOBJ): %.so: %.c $(HDRS) > + $(CC) -c -fPIC $(CFLAGS) $(CPPFLAGS) $< -o $@ > + > +libfsverity.so: $(SOBJ) > + $(CC) $(LDLIBS) -shared -o libfsverity.so $(SOBJ) > > clean: > - rm -f $(EXE) $(OBJ) > + rm -f $(EXE) $(OBJ) $(SOBJ) $(LIB) > > install:all > install -Dm755 -t $(DESTDIR)/bin $(EXE) > diff --git a/libverity.c b/libverity.c > new file mode 100644 > index 0000000..6821aa2 > --- /dev/null > +++ b/libverity.c > @@ -0,0 +1,10 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * The 'fsverity library' > + * > + * Copyright (C) 2018 Google LLC > + * Copyright (C) 2020 Facebook > + * > + * Written by Eric Biggers and Jes Sorensen. > + */ > + Could you preserve the option to build the 'fsverity' program as a statically linked binary? Having to deal with installing libfsverity.so in some environments can be annoying. We maybe should use proper build system that would handle things like this -- though, for small projects like this it's nice to just have a simple Makefile. What I've done in another project that uses just a Makefile is support building both a static library a shared library, where the static library is created from .o files and the shared library is built from .shlib.o files. Then the binaries can be linked to either one based on a 'make' variable. - Eric
On Thu, Mar 12, 2020 at 05:47:50PM -0400, Jes Sorensen wrote: > From: Jes Sorensen <jsorensen@fb.com> > > This introduces a dummy shared library to start moving things into. > > Signed-off-by: Jes Sorensen <jsorensen@fb.com> > --- > Makefile | 18 +++++++++++++++--- > libverity.c | 10 ++++++++++ > 2 files changed, 25 insertions(+), 3 deletions(-) > create mode 100644 libverity.c > > diff --git a/Makefile b/Makefile > index b9c09b9..bb85896 100644 > --- a/Makefile > +++ b/Makefile > @@ -1,20 +1,32 @@ > EXE := fsverity > +LIB := libfsverity.so > CFLAGS := -O2 -Wall > CPPFLAGS := -D_FILE_OFFSET_BITS=64 > LDLIBS := -lcrypto > DESTDIR := /usr/local > +LIBDIR := /usr/lib64 LIBDIR isn't used at all. I assume you meant for it to be location where the library gets installed? The proper way to handle installation locations (assuming we stay with a plain Makefile and not move to another build system) would be: PREFIX ?= /usr/local BINDIR ?= $(PREFIX)/bin INCDIR ?= $(PREFIX)/include LIBDIR ?= $(PREFIX)/lib then install binaries into $(DESTDIR)$(BINDIR), headers into $(DESTDIR)$(INCDIR), and libraries into $(DESTDIR)$(LIBDIR). This matches the conventions for autoconf. - Eric
On 3/22/20 1:33 AM, Eric Biggers wrote: > On Thu, Mar 12, 2020 at 05:47:50PM -0400, Jes Sorensen wrote: >> From: Jes Sorensen <jsorensen@fb.com> >> >> This introduces a dummy shared library to start moving things into. >> >> Signed-off-by: Jes Sorensen <jsorensen@fb.com> >> --- >> Makefile | 18 +++++++++++++++--- >> libverity.c | 10 ++++++++++ >> 2 files changed, 25 insertions(+), 3 deletions(-) >> create mode 100644 libverity.c >> >> diff --git a/Makefile b/Makefile >> index b9c09b9..bb85896 100644 >> --- a/Makefile >> +++ b/Makefile >> @@ -1,20 +1,32 @@ >> EXE := fsverity >> +LIB := libfsverity.so >> CFLAGS := -O2 -Wall >> CPPFLAGS := -D_FILE_OFFSET_BITS=64 >> LDLIBS := -lcrypto >> DESTDIR := /usr/local >> +LIBDIR := /usr/lib64 > > LIBDIR isn't used at all. I assume you meant for it to be location where the > library gets installed? The proper way to handle installation locations > (assuming we stay with a plain Makefile and not move to another build system) > would be: > > PREFIX ?= /usr/local > BINDIR ?= $(PREFIX)/bin > INCDIR ?= $(PREFIX)/include > LIBDIR ?= $(PREFIX)/lib > > then install binaries into $(DESTDIR)$(BINDIR), headers into > $(DESTDIR)$(INCDIR), and libraries into $(DESTDIR)$(LIBDIR). > This matches the conventions for autoconf. I pushed a change to git which addresses this, I still need to address the soname though. Long term it might be nice to switch to autoconf/automake, at the same time I love dealing with it about as much as going to the dentist for a root canal. Cheers, Jes
diff --git a/Makefile b/Makefile index b9c09b9..bb85896 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,32 @@ EXE := fsverity +LIB := libfsverity.so CFLAGS := -O2 -Wall CPPFLAGS := -D_FILE_OFFSET_BITS=64 LDLIBS := -lcrypto DESTDIR := /usr/local +LIBDIR := /usr/lib64 SRC := $(wildcard *.c) -OBJ := $(SRC:.c=.o) +OBJ := fsverity.o hash_algs.o cmd_enable.o cmd_measure.o cmd_sign.o util.o +SSRC := libverity.c +SOBJ := libverity.so HDRS := $(wildcard *.h) all:$(EXE) -$(EXE):$(OBJ) +$(EXE):$(OBJ) $(LIB) + $(CC) -o $@ $(OBJ) $(LDLIBS) -L . -l fsverity $(OBJ): %.o: %.c $(HDRS) + $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ + +$(SOBJ): %.so: %.c $(HDRS) + $(CC) -c -fPIC $(CFLAGS) $(CPPFLAGS) $< -o $@ + +libfsverity.so: $(SOBJ) + $(CC) $(LDLIBS) -shared -o libfsverity.so $(SOBJ) clean: - rm -f $(EXE) $(OBJ) + rm -f $(EXE) $(OBJ) $(SOBJ) $(LIB) install:all install -Dm755 -t $(DESTDIR)/bin $(EXE) diff --git a/libverity.c b/libverity.c new file mode 100644 index 0000000..6821aa2 --- /dev/null +++ b/libverity.c @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * The 'fsverity library' + * + * Copyright (C) 2018 Google LLC + * Copyright (C) 2020 Facebook + * + * Written by Eric Biggers and Jes Sorensen. + */ +