From: Andre Noll Date: Sun, 31 Mar 2019 13:32:42 +0000 (+0200) Subject: Create a dynamic library. X-Git-Tag: v1.0.3~1^2 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=c23d59fc4b6d75a7255f0341c68c9142460f9642;p=lopsub.git Create a dynamic library. As pointed out by Adam Borowski, static linking makes updates tedious. This patch switches the package over to create a dynamic library instead. We have to specify -fPIC for compiling and --shared for linking. The shared object is called liblopsub.so.X.Y.Z, where X, Y, and Z are the digits of the version string as created from the git revision by the version-gen.sh script. The soname for the linker to put into each executable which is linked against lopsub is liblopsub.so.$X. The install target is modified to install liblopsub.so.X.Y.Z instead of liblopsub.a, and it also creates the usual symbolic links for shared libraries. It does not run ldconfig, though. Requested-by: Adam Borowski --- diff --git a/.gitignore b/.gitignore index 3dc13ed..e7965bb 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ config_file.c lopsubgen.c version.c lopsub.h -liblopsub.a +liblopsub.* lopsubex lopsubgen lopsubgen-stage1 diff --git a/Makefile b/Makefile index 7e44330..408e3a5 100644 --- a/Makefile +++ b/Makefile @@ -23,9 +23,14 @@ ZCAT := zcat DATE := $(shell date '+%B %Y') GIT_VERSION := $(shell ./version-gen.sh) +PLAIN_VERSION := $(firstword $(subst -, , $(GIT_VERSION))) +MAJOR_VERSION := $(firstword $(subst ., , $(PLAIN_VERSION))) +SONAME := liblopsub.so.$(MAJOR_VERSION) +REALNAME := liblopsub.so.$(PLAIN_VERSION) +LINKERNAME:=liblopsub.so m4_man_pages := lopsub-suite.5.gz lopsub.7.gz -all := $(m4_man_pages) liblopsub.a lopsubgen lopsubgen.1.gz \ +all := $(m4_man_pages) $(REALNAME) lopsubgen lopsubgen.1.gz \ lopsubex lopsubex.1.gz all: $(all) @@ -64,25 +69,25 @@ lopsubgen.lsg.c lopsubgen.lsg.h: lopsubgen.suite lopsubgen-stage1 \ lsg1_objs := lopsubgen.o lsg1.o version.o lsg_objs := lopsubgen.o lsg.o lopsubgen.lsg.o lopsub.o version.o liblopsub_objs := config_file.o lopsub.o version.o -lopsubex_objs := lopsubex.o lopsubex.lsg.o version.o +lopsubex_objs := lopsubex.o lopsubex.lsg.o $(liblopsub_objs) $(lsg_objs) $(liblopsub_objs) $(lopsubex_objs): %.o: %.c lopsubgen.o config_file.o: - $(CC) -g -c -o $@ ${@:.o=.c} + $(CC) -g -c -fPIC -o $@ ${@:.o=.c} lsg1.o: lsg.c lsg.h $(CC) -g -DSTAGE1 -Wall -g -c $< -o $@ %.o: %.c - $(CC) -Wall -I. -g -c -o $@ $< + $(CC) -Wall -I. -g -c -fPIC -o $@ $< # linking lopsubgen-stage1: $(lsg1_objs) $(CC) -Wall -g $(lsg1_objs) -o $@ lopsubgen: $(lsg_objs) $(CC) -Wall -g -o $@ $(lsg_objs) -liblopsub.a: $(liblopsub_objs) - $(AR) -rcs $@ $^ -lopsubex: $(lopsubex_objs) liblopsub.a - $(CC) -Wall -g -o $@ $^ +$(REALNAME): $(liblopsub_objs) + $(CC) --shared -Wl,-soname,liblopsub.so.$(MAJOR_VERSION) -o $@ $^ +lopsubex: $(lopsubex_objs) $(REALNAME) + $(CC) -Wall -g -o $@ $(lopsubex_objs) # web html := $(addprefix web/, $(addsuffix .html, \ @@ -104,7 +109,9 @@ install: $(all) $(INSTALL) -d $(DESTDIR)$(PREFIX)/lib $(DESTDIR)$(PREFIX)/include \ $(DESTDIR)$(PREFIX)/share/man/man1 $(DESTDIR)$(PREFIX)/share/man/man5 \ $(DESTDIR)$(PREFIX)/share/man/man7 $(DESTDIR)$(PREFIX)/bin - $(INSTALL) -m 644 liblopsub.a $(DESTDIR)$(PREFIX)/lib + $(INSTALL) -m 644 $(REALNAME) $(DESTDIR)$(PREFIX)/lib + $(LN) -s $(REALNAME) $(DESTDIR)$(PREFIX)/lib/$(SONAME) + $(LN) -s $(SONAME) $(DESTDIR)$(PREFIX)/lib/$(LINKERNAME) $(INSTALL) -m 755 lopsubgen $(DESTDIR)$(PREFIX)/bin $(INSTALL) -m 644 lopsub.h $(DESTDIR)$(PREFIX)/include $(INSTALL) -m 644 lopsub-internal.h $(DESTDIR)$(PREFIX)/include