Re: Developing against $HOME/lib libraries and LD_LIBRARY_PATH

"Paul \"LeoNerd\" Evans" <[email protected]>
Newsgroups gmane.comp.gnu.libtool.general
Message-ID <[email protected]>
On Fri, 1 Dec 2017 17:11:23 -0500
Nick Bowler <[email protected]> wrote:

> If library A is a libtool library then libtool should do the right
> thing automatically.  All you should need to do is add the libtool
> library to your link command.
> 
> If library A is not a libtool library then libtool won't necessarily
> know how to link it correctly, so it might need some help...

I admit I'm really not entirely sure what the-above means. Both of my
libraries use libtool-based commands internally in their Makefiles to
do their things.

> It's hard to say more without knowing what libtool commands you are
> running and in what way they are not behaving as you expect.

OK, so I'll now attach (and expand sections below) the two Makefiles
concerned.

The lower-level library (termkey) builds a .pc file and installs
that as part of its target:

  install-inc: termkey.h
          install -d $(DESTDIR)$(INCDIR)
          install -m644 termkey.h $(DESTDIR)$(INCDIR)
          install -d $(DESTDIR)$(LIBDIR)/pkgconfig
          LIBDIR=$(LIBDIR) INCDIR=$(INCDIR) sh termkey.pc.sh \
            >$(DESTDIR)$(LIBDIR)/pkgconfig/termkey.pc

The .pc file contains the libs and cflags arguments that others will
link against:

  cat <<EOF
  libdir=$LIBDIR
  includedir=$INCDIR

  Name: termkey
  Description: Abstract terminal key input library
  Version: @VERSION@
  Libs: -L\${libdir} -ltermkey
  Cflags: -I\${includedir}
  EOF

The higher-level library (tickit) then uses pkg-config --cflags and
pkg-config --libs to find this:

  override CFLAGS +=$(shell pkg-config --cflags termkey)
  override LDFLAGS+=$(shell pkg-config --libs   termkey)

At no point in here has an -rpath argument been created.

> All you should need to do is add the libtool library to your link
> command.

I guess in summary I don't really understand what you mean by this
instruction. Is that not what I've done here? If not, what do I need to
change? (either with respect to the above pasted snippets or the
attached files)

-- 
Paul "LeoNerd" Evans

[email protected]      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

_______________________________________________
https://lists.gnu.org/mailman/listinfo/libtool
termkey-Makefile (text/x-makefile, 4.4 KB)
pkgconfig = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config $(1))

ifeq ($(shell uname),Darwin)
  LIBTOOL ?= glibtool
else
  LIBTOOL ?= libtool
endif

ifneq ($(VERBOSE),1)
  LIBTOOL +=--quiet
endif

override CFLAGS +=-Wall -std=c99

ifeq ($(DEBUG),1)
  override CFLAGS +=-ggdb -DDEBUG
endif

ifeq ($(PROFILE),1)
  override CFLAGS +=-pg
  override LDFLAGS+=-pg
endif

ifeq ($(call pkgconfig, --atleast-version=0.1.0 unibilium && echo 1),1)
  override CFLAGS +=$(call pkgconfig, --cflags unibilium) -DHAVE_UNIBILIUM
  override LDFLAGS+=$(call pkgconfig, --libs   unibilium)
else ifeq ($(call pkgconfig, tinfo && echo 1),1)
  override CFLAGS +=$(call pkgconfig, --cflags tinfo)
  override LDFLAGS+=$(call pkgconfig, --libs   tinfo)
else ifeq ($(call pkgconfig, ncursesw && echo 1),1)
  override CFLAGS +=$(call pkgconfig, --cflags ncursesw)
  override LDFLAGS+=$(call pkgconfig, --libs   ncursesw)
else
  override LDFLAGS+=-lncurses
endif

OBJECTS=termkey.lo driver-csi.lo driver-ti.lo
LIBRARY=libtermkey.la

DEMOS=demo demo-async

ifeq ($(call pkgconfig, glib-2.0 && echo 1),1)
  DEMOS+=demo-glib
endif

DEMO_OBJECTS=$(DEMOS:=.lo)

TESTSOURCES=$(wildcard t/[0-9]*.c)
TESTFILES=$(TESTSOURCES:.c=.t)

VERSION_MAJOR=0
VERSION_MINOR=20

VERSION_CURRENT=15
VERSION_REVISION=0
VERSION_AGE=14

PREFIX=/usr/local
LIBDIR=$(PREFIX)/lib
INCDIR=$(PREFIX)/include
MANDIR=$(PREFIX)/share/man
MAN3DIR=$(MANDIR)/man3
MAN7DIR=$(MANDIR)/man7

all: $(LIBRARY) $(DEMOS)

%.lo: %.c termkey.h termkey-internal.h
	$(LIBTOOL) --mode=compile --tag=CC $(CC) $(CFLAGS) -o $@ -c $<

$(LIBRARY): $(OBJECTS)
	$(LIBTOOL) --mode=link --tag=CC $(CC) -rpath $(LIBDIR) -version-info $(VERSION_CURRENT):$(VERSION_REVISION):$(VERSION_AGE) $(LDFLAGS) -o $@ $^

demo: $(LIBRARY) demo.lo
	$(LIBTOOL) --mode=link --tag=CC $(CC) -o $@ $^

demo-async: $(LIBRARY) demo-async.lo
	$(LIBTOOL) --mode=link --tag=CC $(CC) -o $@ $^

demo-glib.lo: demo-glib.c termkey.h
	$(LIBTOOL) --mode=compile --tag=CC $(CC) -o $@ -c $< $(call pkgconfig, glib-2.0 --cflags)

demo-glib: $(LIBRARY) demo-glib.lo
	$(LIBTOOL) --mode=link --tag=CC $(CC) -o $@ $^ $(call pkgconfig, glib-2.0 --libs)

t/%.t: t/%.c $(LIBRARY) t/taplib.lo
	$(LIBTOOL) --mode=link --tag=CC $(CC) -o $@ $^

t/taplib.lo: t/taplib.c
	$(LIBTOOL) --mode=compile --tag=CC $(CC) $(CFLAGS) -o $@ -c $^

.PHONY: test
test: $(TESTFILES)
	prove -e ""

.PHONY: clean-test
clean-test:
	$(LIBTOOL) --mode=clean rm -f $(TESTFILES) t/taplib.lo

.PHONY: clean
clean: clean-test
	$(LIBTOOL) --mode=clean rm -f $(OBJECTS) $(DEMO_OBJECTS)
	$(LIBTOOL) --mode=clean rm -f $(LIBRARY)
	$(LIBTOOL) --mode=clean rm -rf $(DEMOS)

.PHONY: install
install: install-inc install-lib install-man
	$(LIBTOOL) --mode=finish $(DESTDIR)$(LIBDIR)

install-inc: termkey.h
	install -d $(DESTDIR)$(INCDIR)
	install -m644 termkey.h $(DESTDIR)$(INCDIR)
	install -d $(DESTDIR)$(LIBDIR)/pkgconfig
	LIBDIR=$(LIBDIR) INCDIR=$(INCDIR) sh termkey.pc.sh >$(DESTDIR)$(LIBDIR)/pkgconfig/termkey.pc

install-lib: $(LIBRARY)
	install -d $(DESTDIR)$(LIBDIR)
	$(LIBTOOL) --mode=install install libtermkey.la $(DESTDIR)$(LIBDIR)/libtermkey.la

install-man:
	install -d $(DESTDIR)$(MAN3DIR)
	install -d $(DESTDIR)$(MAN7DIR)
	for F in man/*.3; do \
	  gzip <$$F >$(DESTDIR)$(MAN3DIR)/$${F#man/}.gz; \
	done
	for F in man/*.7; do \
	  gzip <$$F >$(DESTDIR)$(MAN7DIR)/$${F#man/}.gz; \
	done
	while read FROM EQ TO; do \
	  echo ln -sf $$TO.gz $(DESTDIR)$(MAN3DIR)/$$FROM.gz; \
	done < man/also

# DIST CUT

MANSOURCE=$(wildcard man/*.3.sh)
BUILTMAN=$(MANSOURCE:.3.sh=.3)

VERSION=$(VERSION_MAJOR).$(VERSION_MINOR)

all: doc

doc: $(BUILTMAN)

%.3: %.3.sh
	sh $< >$@

clean: clean-built

clean-built:
	rm -f $(BUILTMAN) termkey.h

termkey.h: termkey.h.in Makefile
	rm -f $@
	sed -e 's/@@VERSION_MAJOR@@/$(VERSION_MAJOR)/g' \
	    -e 's/@@VERSION_MINOR@@/$(VERSION_MINOR)/g' \
	    $< >$@
	chmod a-w $@

DISTDIR=libtermkey-$(VERSION)

distdir: all
	mkdir __distdir
	cp *.c *.h LICENSE __distdir
	mkdir __distdir/t
	cp t/*.c t/*.h __distdir/t
	mkdir __distdir/man
	cp man/*.[37] man/also __distdir/man
	sed "s,@VERSION@,$(VERSION)," <termkey.pc.sh >__distdir/termkey.pc.sh
	sed "/^# DIST CUT/Q" <Makefile >__distdir/Makefile
	mv __distdir $(DISTDIR)

TARBALL=$(DISTDIR).tar.gz

dist: distdir
	tar -czf $(TARBALL) $(DISTDIR)
	rm -rf $(DISTDIR)

HTMLDIR=html

htmldocs: $(BUILTMAN)
	perl $(HOME)/src/perl/Parse-Man/examples/man-to-html.pl -O $(HTMLDIR) --file-extension tmpl --link-extension html --template home_lou.tt2 --also man/also man/*.3 man/*.7 --index index.tmpl
tickit-Makefile (text/x-makefile, 3.6 KB)
ifeq ($(shell uname),Darwin)
  LIBTOOL ?= glibtool
else
  LIBTOOL ?= libtool
endif

ifneq ($(VERBOSE),1)
  LIBTOOL +=--quiet
endif

override CFLAGS +=-Wall -Iinclude -Isrc -std=c99

ifeq ($(DEBUG),1)
  override CFLAGS +=-ggdb -DDEBUG
endif

ifeq ($(PROFILE),1)
  override CFLAGS +=-pg
  override LDFLAGS+=-pg
endif

ifeq ($(shell pkg-config --atleast-version=1.1.0 unibilium && echo 1),1)
  override CFLAGS +=$(shell pkg-config --cflags unibilium) -DHAVE_UNIBILIUM
  override LDFLAGS+=$(shell pkg-config --libs   unibilium)
else ifeq ($(shell pkg-config ncursesw && echo 1),1)
  override CFLAGS +=$(shell pkg-config --cflags ncursesw)
  override LDFLAGS+=$(shell pkg-config --libs   ncursesw)
else
  override LDFLAGS+=-lncurses
endif

override CFLAGS +=$(shell pkg-config --cflags termkey)
override LDFLAGS+=$(shell pkg-config --libs   termkey)

CFILES=$(sort $(wildcard src/*.c))
HFILES=$(sort $(wildcard include/*.h))
OBJECTS=$(CFILES:.c=.lo)
LIBRARY=libtickit.la

HFILES_INT=$(sort $(wildcard src/*.h)) $(HFILES)

TESTSOURCES=$(sort $(wildcard t/[0-9]*.c))
TESTFILES=$(TESTSOURCES:.c=.t)

EXAMPLESOURCES=$(sort $(wildcard examples/*.c))

VERSION_CURRENT=0
VERSION_REVISION=0
VERSION_AGE=0

PREFIX=/usr/local
BINDIR=$(PREFIX)/bin
LIBDIR=$(PREFIX)/lib
INCDIR=$(PREFIX)/include
MANDIR=$(PREFIX)/share/man
MAN3DIR=$(MANDIR)/man3
MAN7DIR=$(MANDIR)/man7

all: $(LIBRARY)

$(LIBRARY): $(OBJECTS)
	$(LIBTOOL) --mode=link --tag=CC $(CC) -rpath $(LIBDIR) -version-info $(VERSION_CURRENT):$(VERSION_REVISION):$(VERSION_AGE) -o $@ $^ $(LDFLAGS)

src/%.lo: src/%.c $(HFILES_INT)
	$(LIBTOOL) --mode=compile --tag=CC $(CC) $(CFLAGS) -o $@ -c $<

src/term.lo: src/xterm-palette.inc
src/xterm-palette.inc: src/xterm-palette.inc.PL
	perl $^ > $@

src/renderbuffer.lo: src/linechars.inc
src/linechars.inc: src/linechars.inc.PL
	perl $^ > $@

t/%.t: t/%.c $(LIBRARY) t/taplib.lo t/mockterm.lo t/taplib-tickit.lo
	$(LIBTOOL) --mode=link --tag=CC gcc -o $@ -Iinclude -std=c99 -ggdb $^

t/%.lo: t/%.c
	$(LIBTOOL) --mode=compile --tag=CC gcc $(CFLAGS) -o $@ -c $^

.PHONY: test
test: $(TESTFILES)
	$(LIBTOOL) --mode=execute prove -e ""

.PHONY: clean-test
clean-test:
	$(LIBTOOL) --mode=clean rm -f $(TESTFILES) t/taplib.lo t/mockterm.lo

.PHONY: clean
clean: clean-test
	$(LIBTOOL) --mode=clean rm -f $(OBJECTS)
	$(LIBTOOL) --mode=clean rm -f $(LIBRARY)

.PHONY: examples
examples: $(EXAMPLESOURCES:.c=)

examples/%.lo: examples/%.c $(HFILES)
	$(LIBTOOL) --mode=compile --tag=CC $(CC) $(CFLAGS) -o $@ -c $<

examples/%: examples/%.lo $(LIBRARY)
	$(LIBTOOL) --mode=link --tag=CC gcc -o $@ $^

.PHONY: install
install: install-inc install-lib install-man
	$(LIBTOOL) --mode=finish $(DESTDIR)$(LIBDIR)

install-inc: $(HFILES)
	install -d $(DESTDIR)$(INCDIR)
	install -m644 $(HFILES) $(DESTDIR)$(INCDIR)
	install -d $(DESTDIR)$(LIBDIR)/pkgconfig
	sed "s,@LIBDIR@,$(LIBDIR),;s,@INCDIR@,$(INCDIR)," <tickit.pc.in >$(DESTDIR)$(LIBDIR)/pkgconfig/tickit.pc

# rm the old binary first in case it's still in use
install-lib: $(LIBRARY)
	install -d $(DESTDIR)$(LIBDIR)
	$(LIBTOOL) --mode=install install $(LIBRARY) $(DESTDIR)$(LIBDIR)/

install-man:
	install -d $(DESTDIR)$(MAN3DIR)
	install -d $(DESTDIR)$(MAN7DIR)
	for F in man/*.3; do \
	  gzip <$$F >$(DESTDIR)$(MAN3DIR)/$${F#man/}.gz; \
	done
	for F in man/*.7; do \
	  gzip <$$F >$(DESTDIR)$(MAN7DIR)/$${F#man/}.gz; \
	done
	while read FROM EQ TO; do \
	  ln -sf $$TO.gz $(DESTDIR)$(MAN3DIR)/$$FROM.gz; \
	done < man/also

HTMLDIR=html

htmldocs:
	perl $(HOME)/src/perl/Parse-Man/examples/man-to-html.pl -O $(HTMLDIR) --file-extension html --link-extension html --template home_lou.tt2 --also man/also man/*.3 man/*.7 --index html/index.html
termkey.pc.sh (application/x-shellscript, 185 B)
cat <<EOF
libdir=$LIBDIR
includedir=$INCDIR

Name: termkey
Description: Abstract terminal key input library
Version: @VERSION@
Libs: -L\${libdir} -ltermkey
Cflags: -I\${includedir}
EOF
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.