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