1# from: @(#)bsd.lib.mk 5.26 (Berkeley) 5/2/91 2# $FreeBSD: src/share/mk/bsd.lib.mk,v 1.91.2.15 2002/08/07 16:31:50 ru Exp $ 3# 4 5.include <bsd.init.mk> 6 7# Set up the variables controlling shared libraries. After this section, 8# SHLIB_NAME will be defined only if we are to create a shared library. 9# SHLIB_LINK will be defined only if we are to create a link to it. 10# INSTALL_PIC_ARCHIVE will be defined only if we are to create a PIC archive. 11.if defined(NOPIC) 12.undef SHLIB_NAME 13.undef INSTALL_PIC_ARCHIVE 14.else 15.if !defined(SHLIB_NAME) && defined(LIB) && defined(SHLIB_MAJOR) 16SHLIB_NAME= lib${LIB}.so.${SHLIB_MAJOR} 17.endif 18.if defined(SHLIB_NAME) && ${SHLIB_NAME:M*.so.*} 19SHLIB_LINK?= ${SHLIB_NAME:R} 20.endif 21SONAME?= ${SHLIB_NAME} 22.endif 23 24.if defined(DEBUG_FLAGS) 25CFLAGS+= ${DEBUG_FLAGS} 26.endif 27 28.if !defined(DEBUG_FLAGS) 29STRIP?= -s 30.endif 31 32.include <bsd.libnames.mk> 33 34TARGET_LIBDIR?= ${LIBDIR} 35TARGET_DEBUGLIBDIR?= ${DEBUGLIBDIR} 36TARGET_PROFLIBDIR?= ${PROFLIBDIR} 37TARGET_SHLIBDIR?= ${SHLIBDIR} 38 39# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries 40# .So used for PIC object files 41.SUFFIXES: 42.SUFFIXES: .out .o .po .So .S .s .c .cc .cpp .cxx .m .C .f .y .l 43 44.if !defined(PICFLAG) 45PICFLAG=-fpic 46.endif 47 48PO_FLAG=-pg 49PO_CFLAGS=${CFLAGS:N-ffunction-sections} 50PO_CXXFLAGS=${CXXFLAGS:N-ffunction-sections} 51 52.c.o: 53 ${CC} ${_${.IMPSRC:T}_FLAGS} ${STATIC_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 54 55.c.po: 56 ${CC} ${_${.IMPSRC:T}_FLAGS} ${PO_FLAG} ${STATIC_CFLAGS} ${PO_CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 57 58.c.So: 59 ${CC} ${_${.IMPSRC:T}_FLAGS} ${PICFLAG} -DPIC ${SHARED_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 60 61.cc.o .C.o .cpp.o .cxx.o: 62 ${CXX} ${_${.IMPSRC:T}_FLAGS} ${STATIC_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 63 64.cc.po .C.po .cpp.po .cxx.po: 65 ${CXX} ${_${.IMPSRC:T}_FLAGS} ${PO_FLAG} ${STATIC_CXXFLAGS} ${PO_CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 66 67.cc.So .C.So .cpp.So .cxx.So: 68 ${CXX} ${_${.IMPSRC:T}_FLAGS} ${PICFLAG} -DPIC ${SHARED_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 69 70.f.o: 71 ${FC} ${_${.IMPSRC:T}_FLAGS} ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 72 73.f.po: 74 ${FC} ${_${.IMPSRC:T}_FLAGS} ${PO_FLAG} ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 75 76.f.So: 77 ${FC} ${_${.IMPSRC:T}_FLAGS} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 78 79.m.o: 80 ${OBJC} ${_${.IMPSRC:T}_FLAGS} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET} 81 82.m.po: 83 ${OBJC} ${_${.IMPSRC:T}_FLAGS} ${OBJCFLAGS} ${PO_FLAG} -c ${.IMPSRC} -o ${.TARGET} 84 85.m.So: 86 ${OBJC} ${_${.IMPSRC:T}_FLAGS} ${PICFLAG} -DPIC ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET} 87 88.s.o: 89 ${CC} ${_${.IMPSRC:T}_FLAGS} -x assembler-with-cpp ${CFLAGS} -c \ 90 ${.IMPSRC} -o ${.TARGET} 91 92.s.po: 93 ${CC} ${_${.IMPSRC:T}_FLAGS} -x assembler-with-cpp -DPROF ${CFLAGS} -c \ 94 ${.IMPSRC} -o ${.TARGET} 95 96.s.So: 97 ${CC} ${_${.IMPSRC:T}_FLAGS} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} \ 98 -c ${.IMPSRC} -o ${.TARGET} 99 100.S.o: 101 ${CC} ${_${.IMPSRC:T}_FLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 102 103.S.po: 104 ${CC} ${_${.IMPSRC:T}_FLAGS} -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 105 106.S.So: 107 ${CC} ${_${.IMPSRC:T}_FLAGS} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} \ 108 -o ${.TARGET} 109 110all: objwarn 111 112.include <bsd.symver.mk> 113 114# Allow libraries to specify their own version map or have it 115# automatically generated (see bsd.symver.mk above). 116.if !defined(NO_SYMVER) && !empty(VERSION_MAP) 117${SHLIB_NAME}: ${VERSION_MAP} 118LDFLAGS+= -Wl,--version-script=${VERSION_MAP} 119.endif 120 121.include <bsd.patch.mk> 122 123.if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME) 124. if !empty(SRCS) 125OBJS+= ${SRCS:N*.h:N*.patch:R:S/$/.o/g} 126. endif 127.endif 128 129.if defined(LIB) && !empty(LIB) 130_LIBS= lib${LIB}.a 131 132.if ! target(lib${LIB}.a) 133lib${LIB}.a: ${OBJS} ${STATICOBJS} 134 @${ECHO} building static ${LIB} library 135 rm -f ${.TARGET} 136 ${AR} cq ${.TARGET} `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD} 137 ${RANLIB} ${.TARGET} 138. endif 139.endif 140 141.if !defined(INTERNALLIB) && !defined(NOPROFILE) && defined(LIB) && !empty(LIB) 142_LIBS+= lib${LIB}_p.a 143POBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po} 144 145lib${LIB}_p.a: ${POBJS} 146 @${ECHO} building profiled ${LIB} library 147 rm -f ${.TARGET} 148 ${AR} cq ${.TARGET} `lorder ${POBJS} | tsort -q` ${ARADD} 149 ${RANLIB} ${.TARGET} 150.endif 151 152.if !defined(INTERNALLIB) && defined(SHLIB_NAME) || \ 153 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 154SOBJS+= ${OBJS:.o=.So} 155.endif 156 157.if !defined(INTERNALLIB) && defined(SHLIB_NAME) 158_LIBS+= ${SHLIB_NAME} 159 160${SHLIB_NAME}: ${SOBJS} 161 @${ECHO} building shared library ${SHLIB_NAME} 162 rm -f ${.TARGET} ${SHLIB_LINK} 163.if defined(SHLIB_LINK) 164 ${LN} -fs ${.TARGET} ${SHLIB_LINK} 165.endif 166 ${CC_LINK} ${LDFLAGS} -shared -Wl,-x \ 167 -o ${.TARGET} -Wl,-soname,${SONAME} \ 168 `lorder ${SOBJS} | tsort -q` ${LDADD} 169.endif 170 171.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 172_LIBS+= lib${LIB}_pic.a 173 174lib${LIB}_pic.a: ${SOBJS} 175 @${ECHO} building special pic ${LIB} library 176 rm -f ${.TARGET} 177 ${AR} cq ${.TARGET} ${SOBJS} ${ARADD} 178 ${RANLIB} ${.TARGET} 179.endif 180 181all: ${_LIBS} 182 183.if !defined(NOMAN) 184all: _manpages 185.endif 186 187_EXTRADEPEND: 188 @TMP=_depend$$$$; \ 189 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \ 190 > $$TMP; \ 191 mv $$TMP ${DEPENDFILE} 192.if !defined(NOEXTRADEPEND) && defined(SHLIB_NAME) 193.if defined(DPADD) && !empty(DPADD) 194 echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE} 195.endif 196.endif 197 198.if !target(install) 199 200.if defined(PRECIOUSLIB) && !defined(NOFSCHG) 201SHLINSTALLFLAGS+= -fschg 202.endif 203 204_INSTALLFLAGS:= ${INSTALLFLAGS} 205.for ie in ${INSTALLFLAGS_EDIT} 206_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 207.endfor 208_SHLINSTALLFLAGS:= ${SHLINSTALLFLAGS} 209.for ie in ${INSTALLFLAGS_EDIT} 210_SHLINSTALLFLAGS:= ${_SHLINSTALLFLAGS${ie}} 211.endfor 212 213.if !defined(INTERNALLIB) 214realinstall: _libinstall 215.ORDER: beforeinstall _libinstall 216_libinstall: 217.if defined(LIB) && !empty(LIB) && !defined(NOINSTALLLIB) 218 ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 219 ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${TARGET_LIBDIR} 220.endif 221.if !defined(NOPROFILE) && defined(LIB) && !empty(LIB) 222 ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 223 ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${TARGET_PROFLIBDIR}/lib${LIB}.a 224.endif 225.if defined(SHLIB_NAME) 226 ${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 227 ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \ 228 ${SHLIB_NAME} ${DESTDIR}${TARGET_SHLIBDIR} 229.if defined(SHLIB_LINK) 230.if ${SHLIBDIR} == ${LIBDIR} 231 ${LN} -fs ${SHLIB_NAME} ${DESTDIR}${TARGET_SHLIBDIR}/${SHLIB_LINK} 232.else 233 ${LN} -fs ${_SHLIBDIRPREFIX}${TARGET_SHLIBDIR}/${SHLIB_NAME} \ 234 ${DESTDIR}${TARGET_LIBDIR}/${SHLIB_LINK} 235.endif 236.endif 237.endif 238.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 239 ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 240 ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${TARGET_LIBDIR} 241.endif 242.endif # !defined(INTERNALLIB) 243 244.include <bsd.nls.mk> 245.include <bsd.files.mk> 246.include <bsd.incs.mk> 247.include <bsd.links.mk> 248 249.if !defined(NOMAN) 250realinstall: _maninstall 251.ORDER: beforeinstall _maninstall 252.endif 253 254.endif 255 256.if !defined(NOMAN) 257.include <bsd.man.mk> 258.endif 259 260.include <bsd.dep.mk> 261 262.if !exists(${.OBJDIR}/${DEPENDFILE}) 263.if defined(LIB) && !empty(LIB) 264${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h} 265.endif 266.if defined(SHLIB_NAME) || \ 267 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 268${SOBJS}: ${SRCS:M*.h} 269.endif 270.endif 271 272.if !target(clean) 273clean: 274.if defined(CLEANFILES) && !empty(CLEANFILES) 275 rm -f ${CLEANFILES} 276.endif 277.if defined(LIB) && !empty(LIB) 278 rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS} 279.endif 280.if defined(SHLIB_NAME) || \ 281 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 282 rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/} 283.endif 284.if !defined(INTERNALLIB) 285.if !defined(NOPROFILE) && defined(LIB) && !empty(LIB) 286 rm -f ${POBJS} ${POBJS:S/$/.tmp/} 287.endif 288.if defined(SHLIB_NAME) 289.if defined(SHLIB_LINK) 290 rm -f ${SHLIB_LINK} 291.endif 292.if defined(LIB) && !empty(LIB) 293 rm -f lib${LIB}.so.* lib${LIB}.so 294.endif 295.endif 296.endif # !defined(INTERNALLIB) 297.if defined(_LIBS) && !empty(_LIBS) 298 rm -f ${_LIBS} 299.endif 300.if defined(CLEANDIRS) && !empty(CLEANDIRS) 301 rm -rf ${CLEANDIRS} 302.endif 303.endif 304 305.include <bsd.obj.mk> 306 307.include <bsd.sys.mk> 308 309