Subject: Shared object handling proposed change.
To: None <>
From: Christos Zoulas <>
List: tech-toolchain
Date: 05/15/2002 14:13:27
The motivation behind this change is to allow programs that like to create
shared objects of the form <objectname>.so easy.

The following changes are made:

1. Introduced ${LIBPREFIX}, which defaults to "lib" so that a Makefile can
   set it to empty if no prefix is desired.
2. Change shared object suffix from ".so" to ".lo" so that there is no conflict
   with the linker generated files.
3. Change host generated object files to ".ho" [".lo" was used before and
   not documented in bsd.README] and beautify the rule.
4. Allow SHLIB_FULLVERSION to be empty, creating ".so" files without a version.
5. Document changes.



Index: bsd.README
RCS file: /cvsroot/sharesrc/share/mk/bsd.README,v
retrieving revision 1.98
diff -u -u -r1.98 bsd.README
--- bsd.README	2002/04/26 15:02:02	1.98
+++ bsd.README	2002/05/15 18:08:19
@@ -56,7 +56,8 @@
 The profiled libraries are no longer built in a different directory than
 the regular libraries.  A new suffix, ".po", is used to denote a profiled
-object, and ".so" denotes a shared (position-independent) object.
+object, ".lo" denotes a shared (position-independent) object, and ".ho"
+denotes a host compiled object in a cross-compiling environment.
 There are various make variables used during the build.  Basic rule for
 the variable naming scheme is as follows:
@@ -642,6 +643,8 @@
 It sets/uses the following variables:
 LIB		The name of the library to build.
+LIBPREFIX	A prefix to add to the library name. Usually "lib".
 LIBDIR		Target directory for libraries.
RCS file: /cvsroot/sharesrc/share/mk/,v
retrieving revision 1.203
diff -u -u -r1.203
---	2002/05/07 02:06:32	1.203
+++	2002/05/15 18:08:19
@@ -12,6 +12,8 @@
 CPPFLAGS+=	${DESTDIR:D-nostdinc ${CPPFLAG_ISYSTEM} ${DESTDIR}/usr/include}
 CXXFLAGS+=	${DESTDIR:D-nostdinc++ ${CPPFLAG_ISYSTEM} ${DESTDIR}/usr/include/g++}
 .if !defined(SHLIB_MAJOR) && exists(${SHLIB_VERSION_FILE})
 SHLIB_MAJOR != . ${SHLIB_VERSION_FILE} ; echo $$major
 SHLIB_MINOR != . ${SHLIB_VERSION_FILE} ; echo $$minor
@@ -52,6 +54,7 @@
+.if !defined(SHLIB_FULLVERSION)
 .if defined(SHLIB_MAJOR) && !empty(SHLIB_MAJOR)
 .if defined(SHLIB_MINOR) && !empty(SHLIB_MINOR)
 .if defined(SHLIB_TEENY) && !empty(SHLIB_TEENY)
@@ -63,11 +66,12 @@
 # add additional suffixes not exported.
 # .po is used for profiling object files.
-# .so is used for PIC object files.
-.SUFFIXES: .out .a .ln .so .po .o .s .S .c .cc .C .m .F .f .r .y .l .cl .p .h
+# .lo is used for PIC object files.
+.SUFFIXES: .out .a .ln .lo .po .o .s .S .c .cc .C .m .F .f .r .y .l .cl .p .h
 .SUFFIXES: .sh .m4 .m
@@ -85,12 +89,12 @@
 #			with ELF, also set shared-lib version for
 # SHLIB_LDSTARTFILE:	support .o file, call C++ file-level constructors
 # SHLIB_LDENDFILE:	support .o file, call C++ file-level destructors
-# FPICFLAGS:		flags for ${FC} to compile .[fF] files to .so objects.
+# FPICFLAGS:		flags for ${FC} to compile .[fF] files to .lo objects.
 # CPPICFLAGS:		flags for ${CPP} to preprocess .[sS] files for ${AS}
-# CPICFLAGS:		flags for ${CC} to compile .[cC] files to .so objects.
+# CPICFLAGS:		flags for ${CC} to compile .[cC] files to .lo objects.
 # CAPICFLAGS		flags for {$CC} to compiling .[Ss] files
 #		 	(usually just ${CPPPICFLAGS} ${CPICFLAGS})
-# APICFLAGS:		flags for ${AS} to assemble .[sS] to .so objects.
+# APICFLAGS:		flags for ${AS} to assemble .[sS] to .lo objects.
 .if ${MACHINE_ARCH} == "alpha"
 		# Alpha-specific shared library flags
@@ -142,7 +146,11 @@
 # Platform-independent linker flags for ELF shared libraries
 .if ${OBJECT_FMT} == "ELF"
+.if !empty(SHLIB_SOVERSION)
 SHLIB_LDSTARTFILE?=	${DESTDIR}/usr/lib/crtbeginS.o
 SHLIB_LDENDFILE?=	${DESTDIR}/usr/lib/crtendS.o
@@ -170,7 +178,7 @@
 	@rm -f ${.TARGET}.o
 .if defined(COPTS) && !empty(COPTS:M*-g*)
@@ -203,7 +211,7 @@
 	@rm -f ${.TARGET}.o
 .endif .C.lo:
 .if defined(COPTS) && !empty(COPTS:M*-g*)
 	${} ${CPICFLAGS} ${.IMPSRC} -o ${.TARGET}
@@ -233,7 +241,7 @@
 	@rm -f ${.TARGET}.o
 .if defined(FOPTS) && !empty(FOPTS:M*-g*)
@@ -266,7 +274,7 @@
 	@rm -f ${.TARGET}.o
 .if defined(OBJCFLAGS) && !empty(OBJCFLAGS:M*-g*)
@@ -288,7 +296,7 @@
 	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
 	@rm -f ${.TARGET}.o
+.S.lo .s.lo:
 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
@@ -296,7 +304,7 @@
 .if ${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
 	|| ${MKLINKLIB} != "no"
@@ -304,20 +312,24 @@
 .if ${MKPROFILE} != "no"
 .if ${MKPIC} != "no"
 .if ${MKPICLIB} == "no"
+.if defined(SHLIB_FULLVERSION) 
@@ -355,19 +367,37 @@
 DPSRCS+=	${SRCS:M*.[ly]:C/\..$/.c/}
-lib${LIB}.a:: ${OBJS} __archivebuild
+${LIBPREFIX}${LIB}.a:: ${OBJS} __archivebuild
 	@echo building standard ${LIB} library
-lib${LIB}_p.a:: ${POBJS} __archivebuild
+${LIBPREFIX}${LIB}_p.a:: ${POBJS} __archivebuild
 	@echo building profiled ${LIB} library
-lib${LIB}_pic.a:: ${SOBJS} __archivebuild
+${LIBPREFIX}${LIB}_pic.a:: ${SOBJS} __archivebuild
 	@echo building shared object ${LIB} library
+	@echo building shared ${LIB} library
+	@rm -f ${LIBPREFIX}${LIB}.so
+.if defined(DESTDIR)
+	$(LD) -nostdlib -x -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \
+	    --whole-archive ${SOLIB} \
+	    --no-whole-archive ${LDADD} \
+	    -R${_LIBSODIR} -R${LIBDIR} \
+	$(LD) -x -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \
+	    --whole-archive ${SOLIB} --no-whole-archive ${LDADD} \
 	@echo building shared ${LIB} library \(version ${SHLIB_FULLVERSION}\)
-	@rm -f lib${LIB}.so.${SHLIB_FULLVERSION}
 .if defined(DESTDIR)
 	$(LD) -nostdlib -x -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \
@@ -386,10 +416,10 @@
 #  We don't use INSTALL_SYMLINK here because this is just
 #  happening inside the build directory/objdir. XXX Why does
 #  this spend so much effort on libraries that aren't live??? XXX
-	ln -sf lib${LIB}.so.${SHLIB_FULLVERSION} lib${LIB}.so.${SHLIB_MAJOR}.tmp
-	mv -f lib${LIB}.so.${SHLIB_MAJOR}.tmp lib${LIB}.so.${SHLIB_MAJOR}
-	ln -sf lib${LIB}.so.${SHLIB_FULLVERSION} lib${LIB}.so.tmp
-	mv -f lib${LIB}.so.tmp lib${LIB}.so
+	mv -f ${LIBPREFIX}${LIB}.so.tmp ${LIBPREFIX}${LIB}.so
 .if !empty(LOBJS)
@@ -402,15 +432,16 @@
 	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 ${LIBPREFIX}${LIB}.a ${OBJS}
+	rm -f ${LIBPREFIX}${LIB}_p.a ${POBJS}
+	rm -f ${LIBPREFIX}${LIB}_pic.a ${LIBPREFIX}${LIB}.so.*
+	rm -f ${LIBPREFIX}${LIB}.so ${SOBJS}
 	rm -f llib-l${LIB}.ln ${LOBJS}
 .if defined(SRCS)
 afterdepend: .depend
 	@(TMP=/tmp/_depend$$$$; \
-	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \ \1.ln:/' \
+	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.lo \1.ln:/' \
 	      < .depend > $$TMP; \
 	    mv $$TMP .depend)
@@ -420,101 +451,101 @@
 .if ${MKLINKLIB} != "no"
-libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.a
+libinstall:: ${DESTDIR}${LIBDIR}/${LIBPREFIX}${LIB}.a
 .if !defined(UPDATE)
-.if !defined(BUILD) && !make(all) && !make(lib${LIB}.a)
+.if !defined(BUILD) && !make(all) && !make(${LIBPREFIX}${LIB}.a)
-${DESTDIR}${LIBDIR}/lib${LIB}.a! lib${LIB}.a __archiveinstall
+${DESTDIR}${LIBDIR}/${LIBPREFIX}${LIB}.a! ${LIBPREFIX}${LIB}.a __archiveinstall
-.if !defined(BUILD) && !make(all) && !make(lib${LIB}.a)
+.if !defined(BUILD) && !make(all) && !make(${LIBPREFIX}${LIB}.a)
-${DESTDIR}${LIBDIR}/lib${LIB}.a: lib${LIB}.a __archiveinstall
+${DESTDIR}${LIBDIR}/${LIBPREFIX}${LIB}.a: ${LIBPREFIX}${LIB}.a __archiveinstall
 .if ${MKPROFILE} != "no"
-libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
+libinstall:: ${DESTDIR}${LIBDIR}/${LIBPREFIX}${LIB}_p.a
 .if !defined(UPDATE)
-.if !defined(BUILD) && !make(all) && !make(lib${LIB}_p.a)
-${DESTDIR}${LIBDIR}/lib${LIB}_p.a! .MADE
+.if !defined(BUILD) && !make(all) && !make(${LIBPREFIX}${LIB}_p.a)
-${DESTDIR}${LIBDIR}/lib${LIB}_p.a! lib${LIB}_p.a __archiveinstall
+${DESTDIR}${LIBDIR}/${LIBPREFIX}${LIB}_p.a! ${LIBPREFIX}${LIB}_p.a __archiveinstall
-.if !defined(BUILD) && !make(all) && !make(lib${LIB}_p.a)
-${DESTDIR}${LIBDIR}/lib${LIB}_p.a: .MADE
+.if !defined(BUILD) && !make(all) && !make(${LIBPREFIX}${LIB}_p.a)
-${DESTDIR}${LIBDIR}/lib${LIB}_p.a: lib${LIB}_p.a __archiveinstall
+${DESTDIR}${LIBDIR}/${LIBPREFIX}${LIB}_p.a: ${LIBPREFIX}${LIB}_p.a __archiveinstall
 .if ${MKPIC} != "no" && ${MKPICINSTALL} != "no"
-libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
+libinstall:: ${DESTDIR}${LIBDIR}/${LIBPREFIX}${LIB}_pic.a
 .if !defined(UPDATE)
-.if !defined(BUILD) && !make(all) && !make(lib${LIB}_pic.a)
-${DESTDIR}${LIBDIR}/lib${LIB}_pic.a! .MADE
+.if !defined(BUILD) && !make(all) && !make(${LIBPREFIX}${LIB}_pic.a)
 .if ${MKPICLIB} == "no"
-${DESTDIR}${LIBDIR}/lib${LIB}_pic.a! lib${LIB}.a __archivesymlinkpic
+${DESTDIR}${LIBDIR}/${LIBPREFIX}${LIB}_pic.a! ${LIBPREFIX}${LIB}.a __archivesymlinkpic
-${DESTDIR}${LIBDIR}/lib${LIB}_pic.a! lib${LIB}_pic.a __archiveinstall
+${DESTDIR}${LIBDIR}/${LIBPREFIX}${LIB}_pic.a! ${LIBPREFIX}${LIB}_pic.a __archiveinstall
-.if !defined(BUILD) && !make(all) && !make(lib${LIB}_pic.a)
-${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: .MADE
+.if !defined(BUILD) && !make(all) && !make(${LIBPREFIX}${LIB}_pic.a)
 .if ${MKPICLIB} == "no"
-${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: lib${LIB}.a __archivesymlinkpic
+${DESTDIR}${LIBDIR}/${LIBPREFIX}${LIB}_pic.a: ${LIBPREFIX}${LIB}.a __archivesymlinkpic
-${DESTDIR}${LIBDIR}/lib${LIB}_pic.a: lib${LIB}_pic.a __archiveinstall
+${DESTDIR}${LIBDIR}/${LIBPREFIX}${LIB}_pic.a: ${LIBPREFIX}${LIB}_pic.a __archiveinstall
 .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
-libinstall:: ${DESTDIR}${_LIBSODIR}/lib${LIB}.so.${SHLIB_FULLVERSION}
 .if !defined(UPDATE)
-.if !defined(BUILD) && !make(all) && !make(lib${LIB}.so.${SHLIB_FULLVERSION})
+.if !defined(BUILD) && !make(all) && !make(${LIBPREFIX}${LIB}.so.${SHLIB_FULLVERSION})
-.if !defined(BUILD) && !make(all) && !make(lib${LIB}.so.${SHLIB_FULLVERSION})
+.if !defined(BUILD) && !make(all) && !make(${LIBPREFIX}${LIB}.so.${SHLIB_FULLVERSION})
 		${.ALLSRC} ${.TARGET}
 .if ${_LIBSODIR} != ${LIBDIR}
 .if ${OBJECT_FMT} == "a.out" && !defined(DESTDIR)
 	/sbin/ldconfig -m ${_LIBSODIR} ${LIBDIR}
 .if ${OBJECT_FMT} == "ELF"
-	    ${DESTDIR}${_LIBSODIR}/lib${LIB}.so.${SHLIB_MAJOR}
 .if ${_LIBSODIR} != ${LIBDIR}
-	    ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
 .if ${MKLINKLIB} != "no"
-	    ${DESTDIR}${_LIBSODIR}/lib${LIB}.so
 .if ${_LIBSODIR} != ${LIBDIR}
-	    ${DESTDIR}${LIBDIR}/lib${LIB}.so
RCS file: /cvsroot/sharesrc/share/mk/,v
retrieving revision 1.77
diff -u -u -r1.77
---	2002/05/02 13:13:53	1.77
+++	2002/05/15 18:08:20
@@ -79,7 +79,7 @@
 RPCGEN?=	rpcgen
 STRIP?=		strip
-.SUFFIXES:	.m .o .ln .lo
+.SUFFIXES:	.m .o .ln .ho
 # Objective C
 # (Defined here rather than in <> because `.m' is not just
@@ -92,9 +92,10 @@
 # Host-compiled C objects
 # The intermediate step is necessary for Sun CC, which objects to calling
 # object files anything but *.o
-	${HOST_COMPILE.c} -o ${.TARGET}.o ${.IMPSRC}
-	mv ${.TARGET}.o ${.TARGET}
+	@echo ${HOST_COMPILE.c} ${.IMPSRC} -o ${.TARGET}
+	@${HOST_COMPILE.c} ${.IMPSRC} -o ${.TARGET}.o 
+	@mv ${.TARGET}.o ${.TARGET}
 # Lex