tcpdump mailing list archives

[PATCH][RFC] Allow linking from custom staticlib.a instead of list of object files


From: Christian Bell <csbell () myri com>
Date: Thu, 7 Jan 2010 15:22:01 -0500

From: Christian Bell <christian () myri com>

This patch allows libpcap.a and libpcap.so to include object files from a
static library archive instead of just a list of .o files.

I'm only including the Makefile.in part because I just want feedback on whether
this would be acceptable practice.  I'm preparing a larger submission (new pcap
device) and we would like our object files to be included in libpcap.a
(including them in libpcap.so is not strictly necessary but would be nice if
we're going to do it for the libpcap.a).  It looks like other vendors have been
building a list of .o files and putting them in ADDLARCHIVEOBJS.  

The patch below is not the prettiest but constructing a list of .o files in
configure makes it harder to maintain the port over time (what if the file name
changes?).  I could have a myapi.o that #includes all of our .c files but then
line numbers become out of whack if bugs are reported against our library.

Tested on Linux and FreeBSD.

---
 Makefile.in |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 53801c1..8cdd0f7 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -50,7 +50,9 @@ CCOPT = @V_CCOPT@
 INCLS = -I. @V_INCLS@
 DEFS = @DEFS@ @V_DEFS@
 ADDLOBJS = @ADDLOBJS@
+ADDLARCHIVES = @ADDLARCHIVES@
 ADDLARCHIVEOBJS = @ADDLARCHIVEOBJS@
+ADDLPICARCHIVES = @ADDLPICARCHIVES@
 LIBS = @LIBS@
 LDFLAGS = @LDFLAGS@
 DYEXT = @DYEXT@
@@ -322,7 +324,11 @@ all: libpcap.a shared pcap-config
 
 libpcap.a: $(OBJ)
        @rm -f $@
-       ar rc $@ $(OBJ) $(ADDLARCHIVEOBJS)
+       if test -n "$(ADDLARCHIVES)"; then \
+           EXTRA_OBJS=`ar t $(ADDLARCHIVES) | tr '\n' ' '`; \
+           ar x $(ADDLARCHIVES); \
+       fi; \
+       ar rc $@ $(OBJ) $$EXTRA_OBJS $(ADDLARCHIVEOBJS)
        $(RANLIB) $@
 
 shared: libpcap.$(DYEXT)
@@ -331,8 +337,12 @@ libpcap.so: $(OBJ)
        @rm -f $@
        VER=`cat $(srcdir)/VERSION`; \
        MAJOR_VER=`sed 's/\([0-9][0-9]*\)\..*/\1/' $(srcdir)/VERSION`; \
+       if test -n "$(ADDLPICARCHIVES)"; then \
+           EXTRA_OBJS=`ar t $(ADDLPICARCHIVES) | tr '\n' ' '`; \
+           ar x $(ADDLPICARCHIVES); \
+       fi; \
        @V_SHLIB_CMD@ @V_SHLIB_OPT@ @V_SONAME_OPT@$@.$$MAJOR_VER $(LDFLAGS) \
-           -o $@.$$VER $(OBJ) $(ADDLOBJS) $(LIBS)
+           -o $@.$$VER $(OBJ) $$EXTRA_OBJS $(ADDLOBJS) $(LIBS)
 
 #
 # The following rule succeeds, but the result is untested.
-- 
1.6.4

-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.


Current thread: