1# from: @(#)bsd.lib.mk 5.26 (Berkeley) 5/2/91 2# $FreeBSD$ 3# 4 5.include <bsd.init.mk> 6 7.if defined(LIB_CXX) || defined(SHLIB_CXX) 8_LD= ${CXX} 9.else 10_LD= ${CC} 11.endif 12.if defined(LIB_CXX) 13LIB= ${LIB_CXX} 14.endif 15.if defined(SHLIB_CXX) 16SHLIB= ${SHLIB_CXX} 17.endif 18 19LIB_PRIVATE= ${PRIVATELIB:Dprivate} 20# Set up the variables controlling shared libraries. After this section, 21# SHLIB_NAME will be defined only if we are to create a shared library. 22# SHLIB_LINK will be defined only if we are to create a link to it. 23# INSTALL_PIC_ARCHIVE will be defined only if we are to create a PIC archive. 24.if defined(NO_PIC) 25.undef SHLIB_NAME 26.undef INSTALL_PIC_ARCHIVE 27.else 28.if !defined(SHLIB) && defined(LIB) 29SHLIB= ${LIB} 30.endif 31.if !defined(SHLIB_NAME) && defined(SHLIB) && defined(SHLIB_MAJOR) 32SHLIB_NAME= lib${LIB_PRIVATE}${SHLIB}.so.${SHLIB_MAJOR} 33.endif 34.if defined(SHLIB_NAME) && !empty(SHLIB_NAME:M*.so.*) 35SHLIB_LINK?= ${SHLIB_NAME:R} 36.endif 37SONAME?= ${SHLIB_NAME} 38.endif 39 40.if defined(CRUNCH_CFLAGS) 41CFLAGS+= ${CRUNCH_CFLAGS} 42.endif 43 44.if ${MK_ASSERT_DEBUG} == "no" 45CFLAGS+= -DNDEBUG 46NO_WERROR= 47.endif 48 49.if defined(DEBUG_FLAGS) 50CFLAGS+= ${DEBUG_FLAGS} 51 52.if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != "" 53CTFFLAGS+= -g 54.endif 55.else 56STRIP?= -s 57.endif 58 59.if ${SHLIBDIR:M*lib32*} 60TAGS+= lib32 61.endif 62 63.if defined(NO_ROOT) 64.if !defined(TAGS) || ! ${TAGS:Mpackage=*} 65TAGS+= package=${PACKAGE:Uruntime} 66.endif 67TAG_ARGS= -T ${TAGS:[*]:S/ /,/g} 68.endif 69 70.if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \ 71 empty(DEBUG_FLAGS:M-gdwarf*) 72SHARED_CFLAGS+= -g 73SHARED_CXXFLAGS+= -g 74CTFFLAGS+= -g 75.endif 76 77.include <bsd.libnames.mk> 78 79# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries 80# .So used for PIC object files 81.SUFFIXES: 82.SUFFIXES: .out .o .po .So .S .asm .s .c .cc .cpp .cxx .C .f .y .l .ln 83 84.if !defined(PICFLAG) 85.if ${MACHINE_CPUARCH} == "sparc64" 86PICFLAG=-fPIC 87.else 88PICFLAG=-fpic 89.endif 90.endif 91 92PO_FLAG=-pg 93 94.c.o: 95 ${CC} ${STATIC_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 96 ${CTFCONVERT_CMD} 97 98.c.po: 99 ${CC} ${PO_FLAG} ${STATIC_CFLAGS} ${PO_CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 100 ${CTFCONVERT_CMD} 101 102.c.So: 103 ${CC} ${PICFLAG} -DPIC ${SHARED_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 104 ${CTFCONVERT_CMD} 105 106.cc.o .C.o .cpp.o .cxx.o: 107 ${CXX} ${STATIC_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 108 109.cc.po .C.po .cpp.po .cxx.po: 110 ${CXX} ${PO_FLAG} ${STATIC_CXXFLAGS} ${PO_CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 111 112.cc.So .C.So .cpp.So .cxx.So: 113 ${CXX} ${PICFLAG} -DPIC ${SHARED_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 114 115.f.po: 116 ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 117 ${CTFCONVERT_CMD} 118 119.f.So: 120 ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 121 ${CTFCONVERT_CMD} 122 123.s.po .s.So: 124 ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC} 125 ${CTFCONVERT_CMD} 126 127.asm.po: 128 ${CC:N${CCACHE_BIN}} -x assembler-with-cpp -DPROF ${PO_CFLAGS} \ 129 ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET} 130 ${CTFCONVERT_CMD} 131 132.asm.So: 133 ${CC:N${CCACHE_BIN}} -x assembler-with-cpp ${PICFLAG} -DPIC \ 134 ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET} 135 ${CTFCONVERT_CMD} 136 137.S.po: 138 ${CC:N${CCACHE_BIN}} -DPROF ${PO_CFLAGS} ${ACFLAGS} -c ${.IMPSRC} \ 139 -o ${.TARGET} 140 ${CTFCONVERT_CMD} 141 142.S.So: 143 ${CC:N${CCACHE_BIN}} ${PICFLAG} -DPIC ${CFLAGS} ${ACFLAGS} \ 144 -c ${.IMPSRC} -o ${.TARGET} 145 ${CTFCONVERT_CMD} 146 147_LIBDIR:=${LIBDIR} 148_SHLIBDIR:=${SHLIBDIR} 149 150.if defined(SHLIB_NAME) 151.if ${MK_DEBUG_FILES} != "no" 152SHLIB_NAME_FULL=${SHLIB_NAME}.full 153# Use ${DEBUGDIR} for base system debug files, else .debug subdirectory 154.if ${_SHLIBDIR} == "/boot" ||\ 155 ${SHLIBDIR:C%/lib(/.*)?$%/lib%} == "/lib" ||\ 156 ${SHLIBDIR:C%/usr/(tests/)?lib(32|exec)?(/.*)?%/usr/lib%} == "/usr/lib" 157DEBUGFILEDIR=${DEBUGDIR}${_SHLIBDIR} 158.else 159DEBUGFILEDIR=${_SHLIBDIR}/.debug 160.endif 161.if !exists(${DESTDIR}${DEBUGFILEDIR}) 162DEBUGMKDIR= 163.endif 164.else 165SHLIB_NAME_FULL=${SHLIB_NAME} 166.endif 167.endif 168 169.include <bsd.symver.mk> 170 171# Allow libraries to specify their own version map or have it 172# automatically generated (see bsd.symver.mk above). 173.if ${MK_SYMVER} == "yes" && !empty(VERSION_MAP) 174${SHLIB_NAME_FULL}: ${VERSION_MAP} 175LDFLAGS+= -Wl,--version-script=${VERSION_MAP} 176.endif 177 178.if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME) 179OBJS+= ${SRCS:N*.h:R:S/$/.o/} 180CLEANFILES+= ${OBJS} ${STATICOBJS} 181.endif 182 183.if defined(LIB) && !empty(LIB) 184_LIBS= lib${LIB_PRIVATE}${LIB}.a 185 186lib${LIB_PRIVATE}${LIB}.a: ${OBJS} ${STATICOBJS} 187 @${ECHO} building static ${LIB} library 188 @rm -f ${.TARGET} 189 ${AR} ${ARFLAGS} ${.TARGET} `NM='${NM}' NMFLAGS='${NMFLAGS}' lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD} 190 ${RANLIB} ${RANLIBFLAGS} ${.TARGET} 191.endif 192 193.if !defined(INTERNALLIB) 194 195.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB) 196_LIBS+= lib${LIB_PRIVATE}${LIB}_p.a 197POBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po} 198DEPENDOBJS+= ${POBJS} 199CLEANFILES+= ${POBJS} 200 201lib${LIB_PRIVATE}${LIB}_p.a: ${POBJS} 202 @${ECHO} building profiled ${LIB} library 203 @rm -f ${.TARGET} 204 ${AR} ${ARFLAGS} ${.TARGET} `NM='${NM}' NMFLAGS='${NMFLAGS}' lorder ${POBJS} | tsort -q` ${ARADD} 205 ${RANLIB} ${RANLIBFLAGS} ${.TARGET} 206.endif 207 208.if defined(SHLIB_NAME) || \ 209 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 210SOBJS+= ${OBJS:.o=.So} 211DEPENDOBJS+= ${SOBJS} 212CLEANFILES+= ${SOBJS} 213.endif 214 215.if defined(SHLIB_NAME) 216_LIBS+= ${SHLIB_NAME} 217 218SOLINKOPTS+= -shared -Wl,-x 219.if defined(LD_FATAL_WARNINGS) && ${LD_FATAL_WARNINGS} == "no" 220SOLINKOPTS+= -Wl,--no-fatal-warnings 221.else 222SOLINKOPTS+= -Wl,--fatal-warnings 223.endif 224SOLINKOPTS+= -Wl,--warn-shared-textrel 225 226.if target(beforelinking) 227beforelinking: ${SOBJS} 228${SHLIB_NAME_FULL}: beforelinking 229.endif 230 231.if defined(SHLIB_LINK) 232.if defined(SHLIB_LDSCRIPT) && !empty(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT}) 233${SHLIB_LINK:R}.ld: ${.CURDIR}/${SHLIB_LDSCRIPT} 234 sed -e 's,@@SHLIB@@,${_SHLIBDIR}/${SHLIB_NAME},g' \ 235 -e 's,@@LIBDIR@@,${_LIBDIR},g' \ 236 ${.ALLSRC} > ${.TARGET} 237 238${SHLIB_NAME_FULL}: ${SHLIB_LINK:R}.ld 239CLEANFILES+= ${SHLIB_LINK:R}.ld 240.endif 241CLEANFILES+= ${SHLIB_LINK} 242.endif 243 244${SHLIB_NAME_FULL}: ${SOBJS} 245 @${ECHO} building shared library ${SHLIB_NAME} 246 @rm -f ${SHLIB_NAME} ${SHLIB_LINK} 247.if defined(SHLIB_LINK) && !commands(${SHLIB_LINK:R}.ld) 248 @${INSTALL_SYMLINK} ${TAG_ARGS:D${TAG_ARGS},development} ${SHLIB_NAME} ${SHLIB_LINK} 249.endif 250 ${_LD:N${CCACHE_BIN}} ${LDFLAGS} ${SSP_CFLAGS} ${SOLINKOPTS} \ 251 -o ${.TARGET} -Wl,-soname,${SONAME} \ 252 `NM='${NM}' NMFLAGS='${NMFLAGS}' lorder ${SOBJS} | tsort -q` ${LDADD} 253.if ${MK_CTF} != "no" 254 ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SOBJS} 255.endif 256 257.if ${MK_DEBUG_FILES} != "no" 258CLEANFILES+= ${SHLIB_NAME_FULL} ${SHLIB_NAME}.debug 259${SHLIB_NAME}: ${SHLIB_NAME_FULL} ${SHLIB_NAME}.debug 260 ${OBJCOPY} --strip-debug --add-gnu-debuglink=${SHLIB_NAME}.debug \ 261 ${SHLIB_NAME_FULL} ${.TARGET} 262 263${SHLIB_NAME}.debug: ${SHLIB_NAME_FULL} 264 ${OBJCOPY} --only-keep-debug ${SHLIB_NAME_FULL} ${.TARGET} 265.endif 266.endif #defined(SHLIB_NAME) 267 268.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no" 269_LIBS+= lib${LIB_PRIVATE}${LIB}_pic.a 270 271lib${LIB_PRIVATE}${LIB}_pic.a: ${SOBJS} 272 @${ECHO} building special pic ${LIB} library 273 @rm -f ${.TARGET} 274 ${AR} ${ARFLAGS} ${.TARGET} ${SOBJS} ${ARADD} 275 ${RANLIB} ${RANLIBFLAGS} ${.TARGET} 276.endif 277 278.if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB) 279LINTLIB= llib-l${LIB}.ln 280_LIBS+= ${LINTLIB} 281LINTOBJS+= ${SRCS:M*.c:.c=.ln} 282CLEANFILES+= ${LINTOBJS} 283 284${LINTLIB}: ${LINTOBJS} 285 @${ECHO} building lint library ${.TARGET} 286 @rm -f ${.TARGET} 287 ${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 288.endif 289 290.endif # !defined(INTERNALLIB) 291 292.if defined(_SKIP_BUILD) 293all: 294.else 295.if defined(_LIBS) && !empty(_LIBS) 296all: ${_LIBS} 297CLEANFILES+= ${_LIBS} 298.endif 299 300.if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY) 301all: all-man 302.endif 303.endif 304 305_EXTRADEPEND: 306.if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME) 307.if defined(DPADD) && !empty(DPADD) 308 echo ${SHLIB_NAME_FULL}: ${DPADD} >> ${DEPENDFILE} 309.endif 310.endif 311 312.if !target(install) 313 314.if defined(PRECIOUSLIB) 315.if !defined(NO_FSCHG) 316SHLINSTALLFLAGS+= -fschg 317.endif 318SHLINSTALLFLAGS+= -S 319.endif 320 321_INSTALLFLAGS:= ${INSTALLFLAGS} 322.for ie in ${INSTALLFLAGS_EDIT} 323_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 324.endfor 325_SHLINSTALLFLAGS:= ${SHLINSTALLFLAGS} 326.for ie in ${INSTALLFLAGS_EDIT} 327_SHLINSTALLFLAGS:= ${_SHLINSTALLFLAGS${ie}} 328.endfor 329 330.if !defined(INTERNALLIB) 331realinstall: _libinstall 332.ORDER: beforeinstall _libinstall 333_libinstall: 334.if defined(LIB) && !empty(LIB) && ${MK_INSTALLLIB} != "no" 335 ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},development} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 336 ${_INSTALLFLAGS} lib${LIB_PRIVATE}${LIB}.a ${DESTDIR}${_LIBDIR}/ 337.endif 338.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB) 339 ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},profile} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 340 ${_INSTALLFLAGS} lib${LIB_PRIVATE}${LIB}_p.a ${DESTDIR}${_LIBDIR}/ 341.endif 342.if defined(SHLIB_NAME) 343 ${INSTALL} ${TAG_ARGS} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 344 ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \ 345 ${SHLIB_NAME} ${DESTDIR}${_SHLIBDIR}/ 346.if ${MK_DEBUG_FILES} != "no" 347.if defined(DEBUGMKDIR) 348 ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},debug} -d ${DESTDIR}${DEBUGFILEDIR}/ 349.endif 350 ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},debug} -o ${LIBOWN} -g ${LIBGRP} -m ${DEBUGMODE} \ 351 ${_INSTALLFLAGS} \ 352 ${SHLIB_NAME}.debug ${DESTDIR}${DEBUGFILEDIR}/ 353.endif 354.if defined(SHLIB_LINK) 355.if commands(${SHLIB_LINK:R}.ld) 356 ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},development} -S -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 357 ${_INSTALLFLAGS} ${SHLIB_LINK:R}.ld \ 358 ${DESTDIR}${_LIBDIR}/${SHLIB_LINK} 359.for _SHLIB_LINK_LINK in ${SHLIB_LDSCRIPT_LINKS} 360 ${INSTALL_SYMLINK} ${SHLIB_LINK} ${DESTDIR}${_LIBDIR}/${_SHLIB_LINK_LINK} 361.endfor 362.else 363.if ${_SHLIBDIR} == ${_LIBDIR} 364.if ${SHLIB_LINK:Mlib*} 365 ${INSTALL_RSYMLINK} ${TAG_ARGS:D${TAG_ARGS},development} ${SHLIB_NAME} ${DESTDIR}${_LIBDIR}/${SHLIB_LINK} 366.else 367 ${INSTALL_RSYMLINK} ${TAG_ARGS} ${DESTDIR}${_SHLIBDIR}/${SHLIB_NAME} \ 368 ${DESTDIR}${_LIBDIR}/${SHLIB_LINK} 369.endif 370.else 371.if ${SHLIB_LINK:Mlib*} 372 ${INSTALL_RSYMLINK} ${TAG_ARGS:D${TAG_ARGS},development} ${DESTDIR}${_SHLIBDIR}/${SHLIB_NAME} \ 373 ${DESTDIR}${_LIBDIR}/${SHLIB_LINK} 374.else 375 ${INSTALL_RSYMLINK} ${TAG_ARGS} ${DESTDIR}${_SHLIBDIR}/${SHLIB_NAME} \ 376 ${DESTDIR}${_LIBDIR}/${SHLIB_LINK} 377.endif 378.if exists(${DESTDIR}${_LIBDIR}/${SHLIB_NAME}) 379 -chflags noschg ${DESTDIR}${_LIBDIR}/${SHLIB_NAME} 380 rm -f ${DESTDIR}${_LIBDIR}/${SHLIB_NAME} 381.endif 382.endif 383.endif # SHLIB_LDSCRIPT 384.endif # SHLIB_LINK 385.endif # SHIB_NAME 386.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no" 387 ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},development} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 388 ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${_LIBDIR}/ 389.endif 390.if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB) 391 ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},development} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 392 ${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR}/ 393.endif 394.endif # !defined(INTERNALLIB) 395 396.if !defined(LIBRARIES_ONLY) 397.include <bsd.nls.mk> 398.include <bsd.files.mk> 399.include <bsd.incs.mk> 400.include <bsd.confs.mk> 401.endif 402 403.include <bsd.links.mk> 404 405.if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY) 406realinstall: maninstall 407.ORDER: beforeinstall maninstall 408.endif 409 410.endif 411 412.if !target(lint) 413lint: ${SRCS:M*.c} 414 ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 415.endif 416 417.if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY) 418.include <bsd.man.mk> 419.endif 420 421.if defined(LIB) && !empty(LIB) 422OBJS_DEPEND_GUESS+= ${SRCS:M*.h} 423.for _S in ${SRCS:N*.[hly]} 424OBJS_DEPEND_GUESS.${_S:R}.po= ${_S} 425.endfor 426.endif 427.if defined(SHLIB_NAME) || \ 428 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 429.for _S in ${SRCS:N*.[hly]} 430OBJS_DEPEND_GUESS.${_S:R}.So= ${_S} 431.endfor 432.endif 433 434.include <bsd.dep.mk> 435.include <bsd.clang-analyze.mk> 436.include <bsd.obj.mk> 437.include <bsd.sys.mk> 438