Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libut]support shared build and more #84

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions libut/Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
OBJS=libut.a
all: $(OBJS)
SOURCES = src/libut.c src/ringbuf.c src/utmm.c src/utvector.c
HEADERS = include/libut.h include/ringbuf.h include/utarray.h include/uthash.h include/utlist.h include/utmm.h include/utringbuffer.h include/utstring.h include/utvector.h
OBJS=$(SOURCES:.c=.o)
all: libut.a libut.so.2.0.1
INCDIR=./include
LIBDIR=/usr/lib
CFLAGS+=-I$(INCDIR)
CFLAGS+=-Wall -Wextra
CFLAGS+=-Wall -Wextra -Werror -fPIC
CFLAGS+=-g
CFLAGS+=$(OPTFLAGS)

libut.a: libut.o utvector.o utmm.o ringbuf.o
libut.a: $(OBJS)
ar r $@ $^

libut.o: src/libut.c $(INCDIR)/libut.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<

utvector.o: src/utvector.c $(INCDIR)/utvector.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<

utmm.o: src/utmm.c $(INCDIR)/utmm.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<

ringbuf.o: src/ringbuf.c $(INCDIR)/ringbuf.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
libut.so.2.0.1: $(OBJS)
$(CC) $(CFLAGS) -shared -Wl,-soname,libut.so.2 $^ -o $@

.PHONY: clean tests install

clean:
rm -f $(OBJS) *.o
rm -f *.o *.a *.so*
make -C tests clean

tests: libut.a
make -C tests

install: libut.a
cp $< /usr/local/lib
install: libut.a libut.so.2.0.1
mkdir -p $(DESTDIR)$(LIBDIR)
mkdir -p $(DESTDIR)$(LIBDIR)/pkgconfig
mkdir -p $(DESTDIR)/usr/include
cp libut.a $(DESTDIR)$(LIBDIR)
cp libut.so.2.0.1 $(DESTDIR)$(LIBDIR)
ln -sf $(LIBDIR)/libut.so.2.0.1 $(DESTDIR)$(LIBDIR)/libut.so.2
ln -sf $(LIBDIR)/libut.so.2.0.1 $(DESTDIR)$(LIBDIR)/libut.so
cp ./include/*.h $(DESTDIR)/usr/include
sed -i -e "s|VERSION|2.0.1|" uthash.pc.in
sed -i -e "s|LIBDIR|$(LIBDIR)|" uthash.pc.in
cp uthash.pc.in $(DESTDIR)$(LIBDIR)/pkgconfig/uthash.pc
3 changes: 2 additions & 1 deletion libut/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ OBJS=$(patsubst %,%.o,$(PROGS))

CFLAGS += -I../include
CFLAGS += -g
CFLAGS += -Wall -Wextra
CFLAGS += -Wall -Wextra -Werror -fPIC
CFLAGS += $(OPTFLAGS)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes seem unwanted: I don't think OPTFLAGS is defined anywhere, and I'm not convinced that -fPIC is sufficiently portable/correct (as opposed to just letting the compiler do whatever it'd do by default).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OPTFLAGS is an environment variable $RPM_OPT_FLAGS visible when building a RPM. that is, packager can pass it make OPTFLAGS="$RPM_OPT_FLAGS" in specfile (like debian rules). On non-RPM system, it will be nothing. It will not harm. And packagers will create such downstream patches anyway if we don't add it upstream.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding $(OPTFLAGS) seems harmless, I think (if no version of Make really complains about undefined variables). I'm still leery of messing with -fPIC, though.
Also, I just checked, and the Debian package doesn't install libut.a at all. I don't think the corresponding SUSE package should try to install libut.{a,so} either, unless some user is actually demanding it (see again: extraordinary evidence).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, SUSE/openSUSE didn't install libut.a either. The build has it, but we deleted it later. I think it's common that Linux distributions don't ship static libraries. But things may be different under other cases.

About fPIC, I have little knowledge of it. But I think it's almost a common principle across distribution (position independent codes). I saw many downstream patches adding this in my packaging life. I found this explains it well: http://stackoverflow.com/questions/5311515/gcc-fpic-option

LDFLAGS += -L.. -lut

TEST_TARGET=run_tests
Expand Down
9 changes: 9 additions & 0 deletions libut/uthash.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
prefix=/usr
libdir=LIBDIR
includedir=/usr/include

Name: uthash
Description: C macros for hash tables and more
Version: VERSION
Libs: -L${libdir} -lut
Cflags: -I${includedir}
1 change: 1 addition & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ CFLAGS += -I$(HASHDIR)
#CFLAGS += -DHASH_BLOOM=16
#CFLAGS += -O2
CFLAGS += -g
CFLAGS += $(OPTFLAGS)
#CFLAGS += -Wstrict-aliasing=2
CFLAGS += -Wall
#CFLAGS += -Wextra
Expand Down