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(NO_PIC) 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 ${MK_ASSERT_DEBUG} == "no" 32CFLAGS+= -DNDEBUG 33NO_WERROR= 34.endif 35 36.if defined(DEBUG_FLAGS) 37CFLAGS+= ${DEBUG_FLAGS} 38 39.if !defined(NO_CTF) && (${DEBUG_FLAGS:M-g} != "") 40CTFFLAGS+= -g 41.endif 42.endif 43 44.if !defined(DEBUG_FLAGS) 45STRIP?= -s 46.endif 47 48.include <bsd.libnames.mk> 49 50# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries 51# .So used for PIC object files 52.SUFFIXES: 53.SUFFIXES: .out .o .po .So .S .asm .s .c .cc .cpp .cxx .m .C .f .y .l .ln 54 55.if !defined(PICFLAG) 56.if ${MACHINE_ARCH} == "sparc64" 57PICFLAG=-fPIC 58.else 59PICFLAG=-fpic 60.endif 61.endif 62 63.if ${CC} == "icc" 64PO_FLAG=-p 65.else 66PO_FLAG=-pg 67.endif 68 69.c.po: 70 ${CC} ${PO_FLAG} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 71.if defined(CTFCONVERT) 72 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} 73.endif 74 75.c.So: 76 ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 77.if defined(CTFCONVERT) 78 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} 79.endif 80 81.cc.po .C.po .cpp.po .cxx.po: 82 ${CXX} ${PO_FLAG} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 83 84.cc.So .C.So .cpp.So .cxx.So: 85 ${CXX} ${PICFLAG} -DPIC ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 86 87.f.po: 88 ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 89.if defined(CTFCONVERT) 90 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} 91.endif 92 93.f.So: 94 ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 95.if defined(CTFCONVERT) 96 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} 97.endif 98 99.m.po: 100 ${OBJC} ${OBJCFLAGS} -pg -c ${.IMPSRC} -o ${.TARGET} 101.if defined(CTFCONVERT) 102 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} 103.endif 104 105.m.So: 106 ${OBJC} ${PICFLAG} -DPIC ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET} 107.if defined(CTFCONVERT) 108 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} 109.endif 110 111.s.po .s.So: 112 ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC} 113.if defined(CTFCONVERT) 114 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} 115.endif 116 117.asm.po: 118 ${CC} -x assembler-with-cpp -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 119.if defined(CTFCONVERT) 120 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} 121.endif 122 123.asm.So: 124 ${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} \ 125 -c ${.IMPSRC} -o ${.TARGET} 126.if defined(CTFCONVERT) 127 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} 128.endif 129 130.S.po: 131 ${CC} -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 132.if defined(CTFCONVERT) 133 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} 134.endif 135 136.S.So: 137 ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 138.if defined(CTFCONVERT) 139 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} 140.endif 141 142all: objwarn 143 144.include <bsd.symver.mk> 145 146# Allow libraries to specify their own version map or have it 147# automatically generated (see bsd.symver.mk above). 148.if ${MK_SYMVER} == "yes" && !empty(VERSION_MAP) 149${SHLIB_NAME}: ${VERSION_MAP} 150LDFLAGS+= -Wl,--version-script=${VERSION_MAP} 151.endif 152 153.if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME) 154OBJS+= ${SRCS:N*.h:R:S/$/.o/} 155.endif 156 157.if defined(LIB) && !empty(LIB) 158_LIBS= lib${LIB}.a 159 160lib${LIB}.a: ${OBJS} ${STATICOBJS} 161 @${ECHO} building static ${LIB} library 162 @rm -f ${.TARGET} 163.if !defined(NM) 164 @${AR} cq ${.TARGET} `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD} 165.else 166 @${AR} cq ${.TARGET} `NM='${NM}' lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD} 167.endif 168 ${RANLIB} ${.TARGET} 169.endif 170 171.if !defined(INTERNALLIB) 172 173.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB) 174_LIBS+= lib${LIB}_p.a 175POBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po} 176 177lib${LIB}_p.a: ${POBJS} 178 @${ECHO} building profiled ${LIB} library 179 @rm -f ${.TARGET} 180.if !defined(NM) 181 @${AR} cq ${.TARGET} `lorder ${POBJS} | tsort -q` ${ARADD} 182.else 183 @${AR} cq ${.TARGET} `NM='${NM}' lorder ${POBJS} | tsort -q` ${ARADD} 184.endif 185 ${RANLIB} ${.TARGET} 186.endif 187 188.if defined(SHLIB_NAME) || \ 189 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 190SOBJS+= ${OBJS:.o=.So} 191.endif 192 193.if defined(SHLIB_NAME) 194_LIBS+= ${SHLIB_NAME} 195 196${SHLIB_NAME}: ${SOBJS} 197 @${ECHO} building shared library ${SHLIB_NAME} 198 @rm -f ${.TARGET} ${SHLIB_LINK} 199.if defined(SHLIB_LINK) 200 @ln -fs ${.TARGET} ${SHLIB_LINK} 201.endif 202.if !defined(NM) 203 @${CC} ${LDFLAGS} -shared -Wl,-x \ 204 -o ${.TARGET} -Wl,-soname,${SONAME} \ 205 `lorder ${SOBJS} | tsort -q` ${LDADD} 206.else 207 @${CC} ${LDFLAGS} -shared -Wl,-x \ 208 -o ${.TARGET} -Wl,-soname,${SONAME} \ 209 `NM='${NM}' lorder ${SOBJS} | tsort -q` ${LDADD} 210.endif 211.if defined(CTFMERGE) 212 ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SOBJS} 213.endif 214.endif 215 216.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no" 217_LIBS+= lib${LIB}_pic.a 218 219lib${LIB}_pic.a: ${SOBJS} 220 @${ECHO} building special pic ${LIB} library 221 @rm -f ${.TARGET} 222 @${AR} cq ${.TARGET} ${SOBJS} ${ARADD} 223 ${RANLIB} ${.TARGET} 224.endif 225 226.if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB) 227LINTLIB= llib-l${LIB}.ln 228_LIBS+= ${LINTLIB} 229LINTOBJS+= ${SRCS:M*.c:.c=.ln} 230 231${LINTLIB}: ${LINTOBJS} 232 @${ECHO} building lint library ${.TARGET} 233 @rm -f ${.TARGET} 234 ${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 235.endif 236 237.endif # !defined(INTERNALLIB) 238 239all: ${_LIBS} 240 241.if ${MK_MAN} != "no" 242all: _manpages 243.endif 244 245_EXTRADEPEND: 246 @TMP=_depend$$$$; \ 247 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \ 248 > $$TMP; \ 249 mv $$TMP ${DEPENDFILE} 250.if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME) 251.if defined(DPADD) && !empty(DPADD) 252 echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE} 253.endif 254.endif 255 256.if !target(install) 257 258.if defined(PRECIOUSLIB) 259.if !defined(NO_FSCHG) 260SHLINSTALLFLAGS+= -fschg 261.endif 262SHLINSTALLFLAGS+= -S 263.endif 264 265_INSTALLFLAGS:= ${INSTALLFLAGS} 266.for ie in ${INSTALLFLAGS_EDIT} 267_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 268.endfor 269_SHLINSTALLFLAGS:= ${SHLINSTALLFLAGS} 270.for ie in ${INSTALLFLAGS_EDIT} 271_SHLINSTALLFLAGS:= ${_SHLINSTALLFLAGS${ie}} 272.endfor 273 274.if !defined(INTERNALLIB) 275realinstall: _libinstall 276.ORDER: beforeinstall _libinstall 277_libinstall: 278.if defined(LIB) && !empty(LIB) && ${MK_INSTALLLIB} != "no" 279 ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 280 ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${LIBDIR} 281.endif 282.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB) 283 ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 284 ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${LIBDIR} 285.endif 286.if defined(SHLIB_NAME) 287 ${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 288 ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \ 289 ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR} 290.if defined(SHLIB_LINK) 291.if ${SHLIBDIR} == ${LIBDIR} 292 ln -fs ${SHLIB_NAME} ${DESTDIR}${LIBDIR}/${SHLIB_LINK} 293.else 294 ln -fs ${_SHLIBDIRPREFIX}${SHLIBDIR}/${SHLIB_NAME} \ 295 ${DESTDIR}${LIBDIR}/${SHLIB_LINK} 296.if exists(${DESTDIR}${LIBDIR}/${SHLIB_NAME}) 297 -chflags noschg ${DESTDIR}${LIBDIR}/${SHLIB_NAME} 298 rm -f ${DESTDIR}${LIBDIR}/${SHLIB_NAME} 299.endif 300.endif 301.endif 302.endif 303.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no" 304 ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 305 ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR} 306.endif 307.if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB) 308 ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 309 ${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR} 310.endif 311.endif # !defined(INTERNALLIB) 312 313.include <bsd.nls.mk> 314.include <bsd.files.mk> 315.include <bsd.incs.mk> 316.include <bsd.links.mk> 317 318.if ${MK_MAN} != "no" 319realinstall: _maninstall 320.ORDER: beforeinstall _maninstall 321.endif 322 323.endif 324 325.if !target(lint) 326lint: ${SRCS:M*.c} 327 ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 328.endif 329 330.if ${MK_MAN} != "no" 331.include <bsd.man.mk> 332.endif 333 334.include <bsd.dep.mk> 335 336.if !exists(${.OBJDIR}/${DEPENDFILE}) 337.if defined(LIB) && !empty(LIB) 338${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h} 339.for _S in ${SRCS:N*.[hly]} 340${_S:R}.po: ${_S} 341.endfor 342.endif 343.if defined(SHLIB_NAME) || \ 344 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 345${SOBJS}: ${SRCS:M*.h} 346.for _S in ${SRCS:N*.[hly]} 347${_S:R}.So: ${_S} 348.endfor 349.endif 350.endif 351 352.if !target(clean) 353clean: 354.if defined(CLEANFILES) && !empty(CLEANFILES) 355 rm -f ${CLEANFILES} 356.endif 357.if defined(LIB) && !empty(LIB) 358 rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS} 359.endif 360.if !defined(INTERNALLIB) 361.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB) 362 rm -f ${POBJS} ${POBJS:S/$/.tmp/} 363.endif 364.if defined(SHLIB_NAME) || \ 365 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 366 rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/} 367.endif 368.if defined(SHLIB_NAME) 369.if defined(SHLIB_LINK) 370 rm -f ${SHLIB_LINK} 371.endif 372.if defined(LIB) && !empty(LIB) 373 rm -f lib${LIB}.so.* lib${LIB}.so 374.endif 375.endif 376.if defined(WANT_LINT) && defined(LIB) && !empty(LIB) 377 rm -f ${LINTOBJS} 378.endif 379.endif # !defined(INTERNALLIB) 380.if defined(_LIBS) && !empty(_LIBS) 381 rm -f ${_LIBS} 382.endif 383.if defined(CLEANDIRS) && !empty(CLEANDIRS) 384 rm -rf ${CLEANDIRS} 385.endif 386.if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS) 387 rm -f ${VERSION_MAP} 388.endif 389.endif 390 391.include <bsd.obj.mk> 392 393.include <bsd.sys.mk> 394