Subject: not a shared library...but sort of
To: None <tech-toolchain@netbsd.org>
From: Andrew Brown <atatat@atatdot.net>
List: tech-toolchain
Date: 05/14/2002 12:53:30
--k+w/mQv8wyuph6w0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

i found myself in a situation where i needed to make something like a
.so library, but without the "lib" in front of the name, or the
convolutions of the major of minor (or teeny) numbers.  for example,
what i have now as libwrap.so.0.2 (and which calls itself
libwrap.so.0), i want instead as wrap.so (which calls itself wrap.so).

i hacked on bsd.lib.mk for about five minutes and came up with the
attached.  now i can set SHLIB_ONEOBJECT to yes (it actually just
needs to be defined in the changes that i made, but perhaps checking
for yes/no would be better) and i get what i want.

does anyone have a use for this?  any reasons not to commit this?  

-- 
|-----< "CODE WARRIOR" >-----|
codewarrior@daemon.org             * "ah!  i see you have the internet
twofsonet@graffiti.com (Andrew Brown)                that goes *ping*!"
andrew@crossbar.com       * "information is power -- share the wealth."

--k+w/mQv8wyuph6w0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="bsd.lib.mk.patch"

--- bsd.lib.mk-orig	Tue May  7 06:45:39 2002
+++ bsd.lib.mk	Tue May 14 12:21:41 2002
@@ -128,6 +128,7 @@
 # Platform-independent flags for NetBSD a.out shared libraries
 SHLIB_SOVERSION=${SHLIB_FULLVERSION}
 SHLIB_SHFLAGS=
+SHLIB_OBJFLAGS=
 FPICFLAGS ?= -fPIC
 CPICFLAGS?= -fPIC -DPIC
 CPPPICFLAGS?= -DPIC 
@@ -142,6 +143,7 @@
 .if ${OBJECT_FMT} == "ELF"
 SHLIB_SOVERSION=	${SHLIB_MAJOR}
 SHLIB_SHFLAGS=		-soname lib${LIB}.so.${SHLIB_SOVERSION}
+SHLIB_OBJFLAGS=		-soname ${LIB}.so
 SHLIB_LDSTARTFILE?=	${DESTDIR}/usr/lib/crtbeginS.o
 SHLIB_LDENDFILE?=	${DESTDIR}/usr/lib/crtendS.o
 .endif
@@ -318,6 +320,9 @@
 .if defined(SHLIB_FULLVERSION)
 _LIBS+=lib${LIB}.so.${SHLIB_FULLVERSION}
 .endif
+.if defined(SHLIB_ONEOBJECT)
+_LIBS+=${LIB}.so
+.endif
 .endif
 
 LOBJS+=${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
@@ -391,6 +396,24 @@
 	mv -f lib${LIB}.so.tmp lib${LIB}.so
 .endif
 
+${LIB}.so: ${SOLIB} ${DPADD} ${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
+	@echo building shared ${LIB} object
+	@rm -f ${LIB}.so
+.if defined(DESTDIR)
+	$(LD) -nostdlib -x -shared ${SHLIB_OBJFLAGS} -o ${.TARGET} \
+	    ${SHLIB_LDSTARTFILE} \
+	    --whole-archive ${SOLIB} \
+	    --no-whole-archive ${LDADD} \
+	    -L${DESTDIR}${_LIBSODIR} -L${DESTDIR}${LIBDIR} \
+	    -R${_LIBSODIR} -R${LIBDIR} \
+	    ${SHLIB_LDENDFILE}
+.else
+	$(LD) -x -shared ${SHLIB_OBJFLAGS} -o ${.TARGET} \
+	    ${SHLIB_LDSTARTFILE} \
+	    --whole-archive ${SOLIB} --no-whole-archive ${LDADD} \
+	    ${SHLIB_LDENDFILE}
+.endif
+
 .if !empty(LOBJS)
 LLIBS?=		-lc
 llib-l${LIB}.ln: ${LOBJS}
@@ -403,7 +426,7 @@
 	rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
 	rm -f lib${LIB}.a ${OBJS}
 	rm -f lib${LIB}_p.a ${POBJS}
-	rm -f lib${LIB}_pic.a lib${LIB}.so.* lib${LIB}.so ${SOBJS}
+	rm -f lib${LIB}_pic.a lib${LIB}.so.* lib${LIB}.so ${LIB}.so ${SOBJS}
 	rm -f llib-l${LIB}.ln ${LOBJS}
 
 .if defined(SRCS)

--k+w/mQv8wyuph6w0--