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